#include "cascade_freemodbus.h" #include "paras.h" #include "mb_f.h" #include "pthread.h" #include "stdio.h" #include #include "stdio.h" #include "string.h" #include #include "thread.h" #define AC_DC_START 4000 #define AC_3_START 6000 enum { FREE_MB_MODE_MASTER=0, FREE_MB_MODE_SLAVE, }; static cascade_freemodbus_t cascade={0}; static void mb_poll(void *para) { thread_handle_t *th=(thread_handle_t*)para; cascade_freemodbus_t *cas=(cascade_freemodbus_t*)th->attr->arg; if(cas->model == FREE_MB_MODE_SLAVE) { eMBInit(MB_RTU, cas->saddr, 2, cas->baund, MB_PAR_NONE); eMBEnable(); } printf("start poll_thead\n"); while(1) { eMBPoll(); rt_thread_mdelay(10); } pthread_exit(NULL); } static void thread_entry(void *arg) { while(1) { printf("start thread_entry\n"); cascade.cache->north.data.ac_dc.dev_cnt = (1 << 8) + 8; sleep(1); } pthread_exit(NULL); } static void mb_scan() { while(1) { sleep(1); } pthread_exit(NULL); } void cascade_freemodbus_init(void) { paras_data_t* p_d = paras_get(); if(p_d->cas.mode == FREE_MB_MODE_MASTER) { }else if(p_d->cas.mode == FREE_MB_MODE_SLAVE) { cascade.lock = lock_init(); if(p_d->prod.type == PDU_AC_I1O1 || PDU_DC_I1O1 == p_d->prod.type) { cascade.north_reg_start = AC_DC_START; cascade.north_reg_max = 2000; } else { cascade.north_reg_start = AC_3_START; cascade.north_reg_max = 3000; } cascade.model = FREE_MB_MODE_SLAVE; cascade.baund = p_d->cas.baud; cascade.cascade_max = 10; cascade.cascade_start = 10; cascade.saddr = p_d->cas.addr; cascade.cache = (cascade_data_cache *)malloc(sizeof(cascade_data_cache)); if(cascade.cache == NULL) return; thread_start(THREAD_ID_CAS_FREE_POLL,mb_poll,&cascade); thread_start(THREAD_ID_CAS_FREE_ENTRY,thread_entry,NULL); }else { return; } } cascade_freemodbus_t * get_cascade_freemodbus(void) { return &cascade; }