|
|
@@ -147,35 +147,51 @@ static int slave_get_info(cascade_handle_t *cas)
|
|
|
info->prod.product_pwr_type = dm->_global_device_info->product_pwr_type;
|
|
|
info->prod.product_id = dm->_global_device_info->product_id;
|
|
|
|
|
|
- list_for_each_entry(tmp, &dm->_globalPowerManger.list, list)
|
|
|
- {
|
|
|
- if(tmp->product_saddr==0) {
|
|
|
- continue;
|
|
|
+ if(!list_empty(&dm->_globalPowerManger.list_Tree_AC)) {
|
|
|
+ cnt2 = 0;
|
|
|
+ list_for_each_entry(tmp3, &dm->_globalPowerManger.list_Tree_AC, list_Tree_AC)
|
|
|
+ {
|
|
|
+ if(tmp3->product_ph_type<0 || tmp3->product_ph_type>3) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(cnt2<3) {
|
|
|
+ info->all.power[cnt2++] = tmp3->_PowerInfo;
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- info->ch[cnt].product_saddr = tmp->product_saddr;
|
|
|
- info->ch[cnt].product_ch_type = tmp->product_ch_type;
|
|
|
- info->ch[cnt].product_ch_addr = tmp->product_ch_addr;
|
|
|
- info->ch[cnt].product_ch_id = tmp->product_ch_id;
|
|
|
- info->ch[cnt].product_ch_status = tmp->product_ch_status;
|
|
|
- info->ch[cnt].start_delay = tmp->product_ch_start_delay;
|
|
|
- info->ch[cnt].stop_delay = tmp->product_ch_stop_delay;
|
|
|
- if (tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
- cnt2 = 0;
|
|
|
- list_for_each_entry(tmp3, &tmp->list_Tree_AC, list_Tree_AC)
|
|
|
- {
|
|
|
- info->ch[cnt].pinfo[cnt2].power = tmp3->_PowerInfo;
|
|
|
- info->ch[cnt].pinfo[cnt2].phase.product_ph_id = tmp3->product_ph_id;
|
|
|
- info->ch[cnt].pinfo[cnt2].phase.product_ph_type = tmp3->product_ph_type;
|
|
|
- info->ch[cnt].pinfo[cnt2].phase.product_ph_outputType = tmp3->product_ph_outputType;
|
|
|
- info->ch[cnt].pinfo[cnt2].phase.product_ph_outputStatus = tmp3->product_ph_outputStatus;
|
|
|
- cnt2++;
|
|
|
+ if(!list_empty(&dm->_globalPowerManger.list)) {
|
|
|
+ cnt = 0;
|
|
|
+ list_for_each_entry(tmp, &dm->_globalPowerManger.list, list)
|
|
|
+ {
|
|
|
+ if(tmp->product_saddr==0) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+
|
|
|
+ info->ch[cnt].product_saddr = tmp->product_saddr;
|
|
|
+ info->ch[cnt].product_ch_type = tmp->product_ch_type;
|
|
|
+ info->ch[cnt].product_ch_addr = tmp->product_ch_addr;
|
|
|
+ info->ch[cnt].product_ch_id = tmp->product_ch_id;
|
|
|
+ info->ch[cnt].product_ch_status = tmp->product_ch_status;
|
|
|
+ info->ch[cnt].start_delay = tmp->product_ch_start_delay;
|
|
|
+ info->ch[cnt].stop_delay = tmp->product_ch_stop_delay;
|
|
|
+ if (tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
+ cnt2 = 0;
|
|
|
+ list_for_each_entry(tmp3, &tmp->list_Tree_AC, list_Tree_AC)
|
|
|
+ {
|
|
|
+ info->ch[cnt].pinfo[cnt2].power = tmp3->_PowerInfo;
|
|
|
+ info->ch[cnt].pinfo[cnt2].phase.product_ph_id = tmp3->product_ph_id;
|
|
|
+ info->ch[cnt].pinfo[cnt2].phase.product_ph_type = tmp3->product_ph_type;
|
|
|
+ info->ch[cnt].pinfo[cnt2].phase.product_ph_outputType = tmp3->product_ph_outputType;
|
|
|
+ info->ch[cnt].pinfo[cnt2].phase.product_ph_outputStatus = tmp3->product_ph_outputStatus;
|
|
|
+ cnt2++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ info->ch[cnt].pinfo[0].power = tmp->_PowerInfo;
|
|
|
+ }
|
|
|
+ cnt++;
|
|
|
}
|
|
|
- else {
|
|
|
- info->ch[cnt].pinfo[0].power = tmp->_PowerInfo;
|
|
|
- }
|
|
|
- cnt++;
|
|
|
}
|
|
|
info->cnt = cnt;
|
|
|
LOGD("___ slave_get_info, cnt: %d\n", info->cnt);
|
|
|
@@ -230,11 +246,10 @@ static int slave_save(cascade_handle_t *cas)
|
|
|
static int mb_init(cascade_handle_t *cas, char *path, int type, int addr, uint32_t baud)
|
|
|
{
|
|
|
int r;
|
|
|
- r = g_modbus_init(&cas->m, path, baud, type, addr, type?"master":"slave", 0);
|
|
|
- if(r==0 && type>0) {
|
|
|
+ r = g_modbus_init(&cas->m, path, baud, type, addr, (type>0)?"master":"slave", 0);
|
|
|
+ if(r==0) {
|
|
|
if(type>0) {
|
|
|
LOGD("___ set slave addr: %d\n", addr);
|
|
|
-
|
|
|
cas->addr = addr;
|
|
|
g_modbus_set_slave(&cas->m, addr);
|
|
|
cascade_slave_init();
|
|
|
@@ -248,7 +263,7 @@ static int mb_init(cascade_handle_t *cas, char *path, int type, int addr, uint32
|
|
|
LOGE("___ mb init failed, %s\n", modbus_strerror(errno));
|
|
|
}
|
|
|
|
|
|
- return 0;
|
|
|
+ return r;
|
|
|
}
|
|
|
static int mb_deinit(cascade_handle_t *cas)
|
|
|
{
|
|
|
@@ -612,7 +627,7 @@ static int master_scan(cascade_handle_t *cas)
|
|
|
slave_add(cas, cas->scanAddr);
|
|
|
}
|
|
|
else {
|
|
|
- // LOGW("____ scan %d fail, %s\n", cas->scanAddr, modbus_strerror(errno));
|
|
|
+ LOGW("____ scan %d fail, %s\n", cas->scanAddr, modbus_strerror(errno));
|
|
|
}
|
|
|
}
|
|
|
cas->scanAddr++;
|
|
|
@@ -623,7 +638,6 @@ static int master_scan(cascade_handle_t *cas)
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
|
static int power_init(void)
|
|
|
{
|
|
|
- int nGroups=18,chn=1;
|
|
|
GlobalDeviceManager *dm=get_dm();
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
|
|
|
@@ -640,41 +654,61 @@ static int power_init(void)
|
|
|
strcpy(dm2->_global_device_info->product_status, dm->_global_device_info->product_status);
|
|
|
|
|
|
INIT_LIST_HEAD(&dm2->_globalPowerManger.list);
|
|
|
+ INIT_LIST_HEAD(&dm2->_globalPowerManger.list_Tree_AC);
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
static int power_clear(cascade_handle_t *cas)
|
|
|
{
|
|
|
- GlobalPowerManger *pos,*tmp;
|
|
|
- GlobalTreeACManager *pos3,*tmp3;
|
|
|
+ GlobalPowerManger *tmp=NULL;
|
|
|
+ GlobalTreeACManager x,*tmp3=NULL;
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
|
|
|
- if(list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
- return -1;
|
|
|
+ if(!list_empty(&dm2->_globalPowerManger.list_Tree_AC)) {
|
|
|
+ list_for_each_entry(tmp3,&dm2->_globalPowerManger.list_Tree_AC,list_Tree_AC)
|
|
|
+ {
|
|
|
+ if(tmp3==NULL) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ list_del(&tmp3->list_Tree_AC);
|
|
|
+ free(tmp3);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- list_for_each_entry_safe(tmp,pos,&dm2->_globalPowerManger.list,list)
|
|
|
- {
|
|
|
- if(tmp && tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
- if(list_empty(&tmp->list_Tree_AC)) {
|
|
|
+ if(!list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
+ list_for_each_entry(tmp,&dm2->_globalPowerManger.list,list)
|
|
|
+ {
|
|
|
+ if(tmp==NULL) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- list_for_each_entry_safe(tmp3,pos3,&tmp->list_Tree_AC,list_Tree_AC)
|
|
|
- {
|
|
|
- list_del(&tmp3->list_Tree_AC);
|
|
|
- free(tmp3);
|
|
|
+
|
|
|
+ if (tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
+ if(list_empty(&tmp->list_Tree_AC)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ list_for_each_entry(tmp3,&tmp->list_Tree_AC,list_Tree_AC)
|
|
|
+ {
|
|
|
+ if(tmp3==NULL) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ list_del(&tmp3->list_Tree_AC);
|
|
|
+ free(tmp3);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- list_del(&tmp->list);
|
|
|
- free(tmp);
|
|
|
+ list_del(&tmp->list);
|
|
|
+ free(tmp);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
static int power_add(cascade_handle_t *cas)
|
|
|
{
|
|
|
- int i,j;
|
|
|
+ int i,j,nTac_chn=0,r=-1;
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
GlobalPowerManger *tmp=NULL;
|
|
|
GlobalTreeACManager *tmp3=NULL;
|
|
|
@@ -682,14 +716,42 @@ static int power_add(cascade_handle_t *cas)
|
|
|
|
|
|
LOGD("____ master add channel to the list, cnt: %d\n", info->cnt);
|
|
|
cascade_lock();
|
|
|
- dm2->_global_device_info->product_id=cur_dev_addr;
|
|
|
power_clear(cas);
|
|
|
|
|
|
+ dm2->_global_device_info->product_id = cur_dev_addr;
|
|
|
+
|
|
|
+ if(info->prod.product_pwr_type==SmartPDU_Tree_AC_Tree ||
|
|
|
+ info->prod.product_pwr_type==SmartPDU_Tree_AC_One ||
|
|
|
+ info->prod.product_pwr_type==SmartPDU_Tree_AC_One_B) {
|
|
|
+ for (int TreeACindex = 0; TreeACindex < 3; TreeACindex++)
|
|
|
+ {
|
|
|
+ tmp3 = (GlobalTreeACManager*)malloc(sizeof(GlobalTreeACManager));
|
|
|
+ if (tmp3 == NULL) {
|
|
|
+ LOGE("tmp3 malloc error.\n");
|
|
|
+ goto quit;
|
|
|
+ }
|
|
|
+ memset(tmp3, 0, sizeof(GlobalTreeACManager));
|
|
|
+
|
|
|
+ tmp3->product_ch_addr = TreeACindex + 1;
|
|
|
+ tmp3->product_id = info->prod.product_id;
|
|
|
+ tmp3->product_saddr = 0;
|
|
|
+ tmp3->product_ch_id = 0;
|
|
|
+ tmp3->product_ch_addr = TreeACindex + 1;
|
|
|
+ tmp3->product_ph_id = nTac_chn;
|
|
|
+ tmp3->product_ph_type = (TreeACindex + 3) % 3;
|
|
|
+
|
|
|
+ list_add_tail(&tmp3->list_Tree_AC, &dm2->_globalPowerManger.list_Tree_AC);
|
|
|
+ nTac_chn++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
for(i=0; i<info->cnt; i++) {
|
|
|
- tmp = (GlobalPowerManger*)calloc(1, sizeof(GlobalPowerManger));
|
|
|
+ tmp = (GlobalPowerManger*)malloc(sizeof(GlobalPowerManger));
|
|
|
if(!tmp) {
|
|
|
- return -1;
|
|
|
+ LOGE("tmp malloc error.\n");
|
|
|
+ goto quit;
|
|
|
}
|
|
|
+ memset(tmp, 0, sizeof(GlobalPowerManger));
|
|
|
|
|
|
tmp->product_id = info->prod.product_id;
|
|
|
tmp->product_saddr = info->ch[i].product_saddr;
|
|
|
@@ -706,8 +768,8 @@ static int power_add(cascade_handle_t *cas)
|
|
|
for (j=0; j<3; j++) {
|
|
|
tmp3 = (GlobalTreeACManager *)malloc(sizeof(GlobalTreeACManager));
|
|
|
if (tmp3 == NULL) {
|
|
|
- LOGE("tm malloc error.\n");
|
|
|
- return -1;
|
|
|
+ LOGE("tmp3 malloc error.\n");
|
|
|
+ goto quit;
|
|
|
}
|
|
|
memset(tmp3, 0, sizeof(GlobalTreeACManager));
|
|
|
|
|
|
@@ -731,8 +793,10 @@ static int power_add(cascade_handle_t *cas)
|
|
|
list_add_tail(&tmp->list,&dm2->_globalPowerManger.list);
|
|
|
}
|
|
|
cascade_unlock();
|
|
|
+ r = 0;
|
|
|
|
|
|
- return 0;
|
|
|
+quit:
|
|
|
+ return r;
|
|
|
}
|
|
|
static int power_update(cascade_handle_t *cas)
|
|
|
{
|
|
|
@@ -743,28 +807,44 @@ static int power_update(cascade_handle_t *cas)
|
|
|
slave_info_t *info=&cas->sInfo;
|
|
|
|
|
|
LOGD("______ power_update, %d\n", info->cnt);
|
|
|
- if(info->cnt==0 || list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
+ if(info->cnt==0) {
|
|
|
LOGE("___ sInfo.cnt is 0\n");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- list_for_each_entry(tmp, &dm2->_globalPowerManger.list, list)
|
|
|
- {
|
|
|
- if(tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
- if(list_empty(&tmp->list_Tree_AC)) {
|
|
|
+ if(!list_empty(&dm2->_globalPowerManger.list_Tree_AC)) {
|
|
|
+ cnt = 0;
|
|
|
+ list_for_each_entry(tmp3,&dm2->_globalPowerManger.list_Tree_AC,list_Tree_AC)
|
|
|
+ {
|
|
|
+ if(tmp3==NULL) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- int cnt2=0;
|
|
|
- list_for_each_entry(tmp3,&tmp->list_Tree_AC,list_Tree_AC)
|
|
|
- {
|
|
|
- tmp3->_PowerInfo = info->ch[cnt].pinfo[cnt2++].power;
|
|
|
+ if(cnt<3) {
|
|
|
+ tmp3->_PowerInfo = info->all.power[cnt++];
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- tmp->_PowerInfo = info->ch[cnt].pinfo[0].power;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
+ cnt = 0;
|
|
|
+ list_for_each_entry(tmp, &dm2->_globalPowerManger.list, list)
|
|
|
+ {
|
|
|
+ if(tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
+ if(list_empty(&tmp->list_Tree_AC)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ int cnt2=0;
|
|
|
+ list_for_each_entry(tmp3,&tmp->list_Tree_AC,list_Tree_AC)
|
|
|
+ {
|
|
|
+ tmp3->_PowerInfo = info->ch[cnt].pinfo[cnt2++].power;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ tmp->_PowerInfo = info->ch[cnt].pinfo[0].power;
|
|
|
+ }
|
|
|
+ cnt++;
|
|
|
}
|
|
|
- cnt++;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
@@ -860,8 +940,15 @@ static int master_cmd(cascade_handle_t *cas, cmd_data_t *cmd)
|
|
|
wdata.dlen = sizeof(cmd_data_t);
|
|
|
wdata.data = (uint8_t*)cmd;
|
|
|
|
|
|
- rdata.dlen = 1;
|
|
|
- rdata.data = (uint8_t*)&cas->sInfo.cnt;
|
|
|
+/*
|
|
|
+cas->sInfo.cnt = 6;
|
|
|
+cas->sInfo.prod.product_pwr_type = SmartPDU_Tree_AC_Tree;
|
|
|
+power_add(cas);
|
|
|
+return 0;
|
|
|
+*/
|
|
|
+
|
|
|
+ rdata.dlen = sizeof(slave_info_t)-sizeof(channel_info_t)*CH_MAX;
|
|
|
+ rdata.data = (uint8_t*)&cas->sInfo;
|
|
|
|
|
|
LOGD("_____ master send CASCADE_CMD_GET_INFO\n");
|
|
|
r = mb_write_read(cas, cur_dev_addr, &wdata, &rdata);
|
|
|
@@ -899,10 +986,10 @@ static int master_query(cascade_handle_t *cas)
|
|
|
if(cur_dev_addr==0) {
|
|
|
return -1;
|
|
|
}
|
|
|
-
|
|
|
+return 0;
|
|
|
wdata.dlen = sizeof(*cmd);
|
|
|
wdata.data = (uint8_t*)cmd;
|
|
|
-
|
|
|
+
|
|
|
switch(cmd->cmd) {
|
|
|
|
|
|
case CASCADE_CMD_QUERY_CH:
|
|
|
@@ -1176,8 +1263,15 @@ int cascade_init(void)
|
|
|
|
|
|
power_init();
|
|
|
slave_init(cas);
|
|
|
- pthread_mutex_init(&cas->mutex, NULL);
|
|
|
- pthread_mutex_init(&cas->lock, NULL);
|
|
|
+
|
|
|
+ r = pthread_mutex_init(&cas->mutex, NULL);
|
|
|
+ if(r) {
|
|
|
+ LOGE("___ cascade mutex init failed\n");
|
|
|
+ }
|
|
|
+ r = pthread_mutex_init(&cas->lock, NULL);
|
|
|
+ if(r) {
|
|
|
+ LOGE("___ cascade lock init failed\n");
|
|
|
+ }
|
|
|
|
|
|
cas->scanAddr = 1;
|
|
|
cas->map2 = modbus_mapping_new_start_address(0,0,0,0,
|
|
|
@@ -1357,7 +1451,6 @@ int cascade_get_ch(_OverChnPwrAckInfo *ch)
|
|
|
pch->product_ch_start_delay = tmp->product_ch_start_delay;
|
|
|
pch->product_ch_stop_delay = tmp->product_ch_stop_delay;
|
|
|
|
|
|
-
|
|
|
list_add_tail(&pch->list, &ch->list);
|
|
|
}
|
|
|
}
|