|
|
@@ -1,10 +1,11 @@
|
|
|
#include "cascade.h"
|
|
|
#include "common.h"
|
|
|
#include "elog.h"
|
|
|
-#include "modbus_handle.h"
|
|
|
#include "cfg.h"
|
|
|
#include "thread.h"
|
|
|
#include "switch_ctrl.h"
|
|
|
+#include "modbus_handle.h"
|
|
|
+#include "sqlite_handle.h"
|
|
|
#include "paras.h"
|
|
|
|
|
|
#if 0
|
|
|
@@ -113,98 +114,56 @@ static int slave_find(cascade_handle_t *cas, int addr)
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-static int slave_get_info(cascade_handle_t *cas, int hardread)
|
|
|
+static int slave_get_info(cascade_handle_t *cas)
|
|
|
{
|
|
|
- int i,j,r;
|
|
|
- uint8_t type,maxChn;
|
|
|
- GlobalPowerManger *tmp=NULL;
|
|
|
+ int cnt=0,cnt2;
|
|
|
GlobalDeviceManager *dm=get_dm();
|
|
|
- board_info_t *info=&cas->info;
|
|
|
-
|
|
|
- info->cnt = 0;
|
|
|
-#ifdef SLAVE_DATA_SIM
|
|
|
- for(j=1; j<10; j++) {
|
|
|
- info->channel[info->cnt].addr = 1;
|
|
|
- info->channel[info->cnt].type = 3;
|
|
|
- info->channel[info->cnt].ch_addr = 4;
|
|
|
- info->cnt++;
|
|
|
- }
|
|
|
-#else
|
|
|
- if(hardread) {
|
|
|
- for(i=1; i<MAX_CHN_COUNT; i++) {
|
|
|
- r = g_switch_get_type(&dm->_globalRelaySampManger, i, &type, &maxChn,
|
|
|
- dm->_global_device_info->product_pwr_type);
|
|
|
- if(r==0) {
|
|
|
- for(j=0; j<maxChn; j++) {
|
|
|
- info->channel[info->cnt].addr = i;
|
|
|
- info->channel[info->cnt].type = type;
|
|
|
- info->channel[info->cnt].ch_addr = j+1;
|
|
|
- info->cnt++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- list_for_each_entry(tmp, &dm->_globalPowerManger.list, list)
|
|
|
- {
|
|
|
- if(tmp->product_saddr==0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- info->channel[info->cnt].addr = tmp->product_saddr;
|
|
|
- info->channel[info->cnt].type = tmp->product_ch_type;
|
|
|
- info->channel[info->cnt].ch_addr = tmp->product_ch_addr;
|
|
|
- info->cnt++;
|
|
|
- }
|
|
|
- }
|
|
|
-#endif
|
|
|
- LOGD("___ slave_get_info, cnt: %d\n", info->cnt);
|
|
|
+ GlobalPowerManger *tmp=NULL;
|
|
|
+ GlobalTreeACManager* tmp3=NULL;
|
|
|
+ slave_info_t *info=&cas->sInfo;
|
|
|
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int get_ac_info(int nCh, int nType, power_info_t *info)
|
|
|
-{
|
|
|
- GlobalDeviceManager *dm=get_dm();
|
|
|
- GlobalTreeACManager *tmp = NULL;
|
|
|
+ info->cnt=0;
|
|
|
+ info->prod.product_type = dm->_global_device_info->product_type;
|
|
|
+ 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_Tree_AC, list_Tree_AC)
|
|
|
+ list_for_each_entry(tmp, &dm->_globalPowerManger.list, list)
|
|
|
{
|
|
|
- if (tmp->product_ch_id != nCh ||tmp->product_ph_type!=nType){
|
|
|
+ if(tmp->product_saddr==0) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- info->pwrinfo = tmp->_PowerInfo;
|
|
|
- //info->start_delay = tmp->product_ch_start_delay;
|
|
|
- //info->stop_delay = tmp->product_ch_start_delay;
|
|
|
-
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- return -1;
|
|
|
-}
|
|
|
-
|
|
|
-static int slave_get_ch_data(cascade_handle_t *cas)
|
|
|
-{
|
|
|
- GlobalDeviceManager *dm=get_dm();
|
|
|
- GlobalPowerManger *tmp=NULL;
|
|
|
- power_info_t *power=cas->chInfo.power;
|
|
|
-
|
|
|
- cas->chInfo.cnt=0;
|
|
|
- list_for_each_entry(tmp, &dm->_globalPowerManger.list, list)
|
|
|
- {
|
|
|
- if(tmp) {
|
|
|
- power[cas->chInfo.cnt].pwrinfo = tmp->_PowerInfo;
|
|
|
- power[cas->chInfo.cnt].start_delay = tmp->product_ch_start_delay;
|
|
|
- power[cas->chInfo.cnt].stop_delay = tmp->product_ch_stop_delay;
|
|
|
- cas->chInfo.cnt++;
|
|
|
+ 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++;
|
|
|
}
|
|
|
+ info->cnt = cnt;
|
|
|
+ LOGD("___ slave_get_info, cnt: %d\n", info->cnt);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int get_pwr_info(board_info_t *info, int chId, GlobalPowerManger *power)
|
|
|
+static int get_pwr_info(int chId, GlobalPowerManger *power)
|
|
|
{
|
|
|
int i;
|
|
|
GlobalPowerManger *tmp=NULL;
|
|
|
@@ -237,7 +196,7 @@ static int slave_save(cascade_handle_t *cas)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- r = get_pwr_info(cas, cas->cmd.chId, &power);
|
|
|
+ r = get_pwr_info(cas->cmd.chId, &power);
|
|
|
if(r) {
|
|
|
LOGE("____ get_pwr_info failed\n");
|
|
|
return -1;
|
|
|
@@ -368,7 +327,7 @@ static int print_hdr(char *s, mb_hdr_t *h)
|
|
|
LOGD("____%s___ h.reg: %d\n", s, h->reg);
|
|
|
LOGD("____%s___ h.regcnt: %d\n", s, h->regcnt);
|
|
|
LOGD("____%s___ h.dlen: %d\n", s, h->dlen);
|
|
|
- LOGD("____%s___ h.data: %d\n", s, h->data);
|
|
|
+ LOGD("____%s___ h.data: %d\n", s, (int)h->data);
|
|
|
LOGD("\n");
|
|
|
|
|
|
return 0;
|
|
|
@@ -396,7 +355,7 @@ static int mb_read(cascade_handle_t *cas, int addr, data_t *d)
|
|
|
{
|
|
|
int r=0,finish=0;
|
|
|
int xlen,rlen=0,oncelen=MB_MAX_LEN;
|
|
|
- uint8_t buff[MODBUS_RTU_MAX_ADU_LENGTH];
|
|
|
+ uint16_t buff[MODBUS_RTU_MAX_ADU_LENGTH];
|
|
|
|
|
|
if(d->dlen<=0) {
|
|
|
//LOGE("___ mb_read dlen %d is wrong!\n", d->dlen);
|
|
|
@@ -440,7 +399,7 @@ static int mb_write(cascade_handle_t *cas, int addr, data_t *d)
|
|
|
{
|
|
|
int r=0;
|
|
|
int xlen,wlen=0,oncelen=MB_MAX_LEN;
|
|
|
- uint8_t buff[MODBUS_RTU_MAX_ADU_LENGTH];
|
|
|
+ uint16_t buff[MODBUS_RTU_MAX_ADU_LENGTH];
|
|
|
|
|
|
if(d->dlen<=0) {
|
|
|
//LOGE("___ mb_write dlen %d is wrong!\n", d->dlen);
|
|
|
@@ -557,8 +516,8 @@ static int mb_receive(cascade_handle_t *cas)
|
|
|
case CASCADE_CMD_GET_INFO:
|
|
|
{
|
|
|
LOGD("_____ slave CASCADE_CMD_GET_INFO\n");
|
|
|
- slave_get_info(cas, 0); //hardread will cost long time
|
|
|
- memcpy(cas->map2->tab_registers+(h.reg-CASCADE_REG_OFFSET), (char*)&cas->info+sendlen, h.regcnt*2);
|
|
|
+ slave_get_info(cas);
|
|
|
+ memcpy(cas->map2->tab_registers+(h.reg-CASCADE_REG_OFFSET), (char*)&cas->sInfo+sendlen, h.regcnt*2);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
@@ -566,8 +525,8 @@ static int mb_receive(cascade_handle_t *cas)
|
|
|
{
|
|
|
LOGD("___ slave CASCADE_CMD_QUERY_CH\n");
|
|
|
|
|
|
- slave_get_ch_data(cas);
|
|
|
- memcpy(cas->map2->tab_registers+(h.reg-CASCADE_REG_OFFSET), ((char*)&cas->chInfo)+sendlen, h.regcnt*2);
|
|
|
+ slave_get_info(cas);
|
|
|
+ memcpy(cas->map2->tab_registers+(h.reg-CASCADE_REG_OFFSET), ((char*)&cas->sInfo)+sendlen, h.regcnt*2);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
@@ -632,128 +591,150 @@ static int master_scan(cascade_handle_t *cas)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-static void power_init(void)
|
|
|
+///////////////////////////////////////////////////////////////////////////////////////
|
|
|
+static int power_init(void)
|
|
|
{
|
|
|
int nGroups=18,chn=1;
|
|
|
GlobalDeviceManager *dm=get_dm();
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
|
|
|
dm2->_global_device_info = (GlobalDeviceInfo*)malloc(sizeof(GlobalDeviceInfo));
|
|
|
- if(dm2->_global_device_info) {
|
|
|
- dm2->_global_device_info->product_pwr_type = dm->_global_device_info->product_pwr_type;
|
|
|
- dm2->_global_device_info->product_id = dm->_global_device_info->product_id;
|
|
|
- //dm2->_global_device_info->product_type_id = 2;
|
|
|
- strcpy(dm2->_global_device_info->product_name, dm->_global_device_info->product_name);
|
|
|
- strcpy(dm2->_global_device_info->product_number, dm->_global_device_info->product_number);
|
|
|
- strcpy(dm2->_global_device_info->product_status, dm->_global_device_info->product_status);
|
|
|
+ if(dm2->_global_device_info==NULL) {
|
|
|
+ LOGE("____ power_init, malloc failed\n");
|
|
|
+ return -1;
|
|
|
}
|
|
|
+
|
|
|
+ dm2->_global_device_info->product_pwr_type = dm->_global_device_info->product_pwr_type;
|
|
|
+ dm2->_global_device_info->product_id = dm->_global_device_info->product_id;
|
|
|
+ strcpy(dm2->_global_device_info->product_name, dm->_global_device_info->product_name);
|
|
|
+ strcpy(dm2->_global_device_info->product_number, dm->_global_device_info->product_number);
|
|
|
+ strcpy(dm2->_global_device_info->product_status, dm->_global_device_info->product_status);
|
|
|
|
|
|
INIT_LIST_HEAD(&dm2->_globalPowerManger.list);
|
|
|
+ return 0;
|
|
|
}
|
|
|
static int power_clear(cascade_handle_t *cas)
|
|
|
{
|
|
|
- GlobalPowerManger *pos,*tmp=NULL;
|
|
|
+ GlobalPowerManger *pos,*tmp;
|
|
|
+ GlobalTreeACManager *pos3,*tmp3;
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
|
|
|
if(list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-#if 0
|
|
|
- list_for_each_entry(tmp,&dm2->_globalPowerManger.list,list)
|
|
|
+ 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)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ list_for_each_entry_safe(tmp3,pos3,&tmp->list_Tree_AC,list_Tree_AC)
|
|
|
+ {
|
|
|
+ list_del(&tmp3->list_Tree_AC);
|
|
|
+ free(tmp3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
list_del(&tmp->list);
|
|
|
free(tmp);
|
|
|
}
|
|
|
-#else
|
|
|
- list_for_each_entry_safe(pos,tmp,&dm2->_globalPowerManger.list,list)
|
|
|
- {
|
|
|
- list_del(&pos->list);
|
|
|
- free(pos);
|
|
|
- }
|
|
|
-#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
static int power_add(cascade_handle_t *cas)
|
|
|
{
|
|
|
- int i,j,nGroups=18,chn=1;
|
|
|
+ int i,j;
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
- GlobalPowerManger* pm=NULL;
|
|
|
- board_info_t *info=&cas->info;
|
|
|
+ GlobalPowerManger *tmp=NULL;
|
|
|
+ GlobalTreeACManager *tmp3=NULL;
|
|
|
+ slave_info_t *info=&cas->sInfo;
|
|
|
|
|
|
LOGD("____ master add channel to the list, cnt: %d\n", info->cnt);
|
|
|
cascade_lock();
|
|
|
|
|
|
power_clear(cas);
|
|
|
+
|
|
|
for(i=0; i<info->cnt; i++) {
|
|
|
- pm = (GlobalPowerManger*)calloc(1, sizeof(GlobalPowerManger));
|
|
|
- if(!pm) {
|
|
|
+ tmp = (GlobalPowerManger*)calloc(1, sizeof(GlobalPowerManger));
|
|
|
+ if(!tmp) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- pm->product_id = dm2->_global_device_info->product_id;
|
|
|
- pm->product_saddr = info->channel[i].addr;
|
|
|
- pm->product_ch_id = i+1;
|
|
|
- pm->product_ch_addr = info->channel[i].ch_addr;
|
|
|
- sprintf(pm->product_ch_name,"CH%d",pm->product_ch_id);
|
|
|
- pm->product_ch_type = info->channel[i].type;
|
|
|
- pm->product_ch_status = 0;
|
|
|
-
|
|
|
- pm->product_ch_start_delay = 1000 * (chn%nGroups!=0?chn%nGroups:nGroups);
|
|
|
- pm->product_ch_stop_delay = 1000 * (chn%nGroups!=0?chn%nGroups:nGroups);
|
|
|
-
|
|
|
- list_add_tail(&pm->list,&dm2->_globalPowerManger.list);
|
|
|
- chn++;
|
|
|
- }
|
|
|
- cascade_unlock();
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-static int power_all_update(cascade_handle_t *cas)
|
|
|
-{
|
|
|
- GlobalPowerManger *tmp=NULL;
|
|
|
- GlobalDeviceManager *dm2=get_dm2();
|
|
|
- int type=cas->allInfo.type;
|
|
|
- //power_info_t *power=cas->chInfo.power;
|
|
|
-
|
|
|
- if(list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- list_for_each_entry(tmp, &dm2->_globalPowerManger.list, list)
|
|
|
- {
|
|
|
- if(tmp) {
|
|
|
-
|
|
|
+ tmp->product_id = info->prod.product_id;
|
|
|
+ tmp->product_saddr = info->ch[i].product_saddr;
|
|
|
+ tmp->product_ch_id = info->ch[i].product_ch_id;
|
|
|
+ tmp->product_ch_addr = info->ch[i].product_ch_addr;
|
|
|
+ sprintf(tmp->product_ch_name, "CH%d", tmp->product_ch_id);
|
|
|
+ tmp->product_ch_type = info->ch[i].product_ch_type;
|
|
|
+ tmp->product_ch_status = info->ch[i].product_ch_status;
|
|
|
+ tmp->product_ch_start_delay = info->ch[i].start_delay;
|
|
|
+ tmp->product_ch_stop_delay = info->ch[i].stop_delay;
|
|
|
+
|
|
|
+ if(info->ch[i].product_ch_type==TREE_AC_TYPE) {
|
|
|
+ INIT_LIST_HEAD(&tmp->list_Tree_AC);
|
|
|
+ for (j=0; j<3; j++) {
|
|
|
+ tmp3 = (GlobalTreeACManager *)malloc(sizeof(GlobalTreeACManager));
|
|
|
+ if (tmp3 == NULL) {
|
|
|
+ LOGE("tm malloc error.\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ memset(tmp3, 0, sizeof(GlobalTreeACManager));
|
|
|
+
|
|
|
+ tmp3->product_id = info->prod.product_id;
|
|
|
+ tmp3->product_saddr = info->ch[i].product_saddr;
|
|
|
+ tmp3->product_ch_id = tmp->product_ch_id;
|
|
|
+ tmp3->product_ch_addr = info->ch[i].product_ch_addr;
|
|
|
+ tmp3->product_ph_id = info->ch[i].pinfo[j].phase.product_ph_id;
|
|
|
+ tmp3->product_ph_type = info->ch[i].pinfo[j].phase.product_ph_type;
|
|
|
+ tmp3->product_ph_outputType = info->ch[i].pinfo[j].phase.product_ph_outputType;
|
|
|
+ tmp3->product_ph_outputStatus = info->ch[i].pinfo[j].phase.product_ph_outputStatus;
|
|
|
+ tmp3->_PowerInfo = info->ch[i].pinfo[j].power;
|
|
|
+
|
|
|
+ list_add_tail(&tmp3->list_Tree_AC, &tmp->list_Tree_AC);
|
|
|
+ }
|
|
|
}
|
|
|
+ else {
|
|
|
+ tmp->_PowerInfo = info->ch[i].pinfo[0].power;
|
|
|
+ }
|
|
|
+
|
|
|
+ list_add_tail(&tmp->list,&dm2->_globalPowerManger.list);
|
|
|
}
|
|
|
+ cascade_unlock();
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-static int power_ch_update(cascade_handle_t *cas)
|
|
|
+static int power_update(cascade_handle_t *cas)
|
|
|
{
|
|
|
int cnt=0;
|
|
|
GlobalPowerManger *tmp=NULL;
|
|
|
+ GlobalTreeACManager *tmp3=NULL;
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
- power_info_t *power=cas->chInfo.power;
|
|
|
+ slave_info_t *info=&cas->sInfo;
|
|
|
|
|
|
- if(cas->chInfo.cnt==0 || list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
- LOGE("___ chInfo.cnt is 0\n");
|
|
|
+ if(info->cnt==0 || list_empty(&dm2->_globalPowerManger.list)) {
|
|
|
+ LOGE("___ sInfo.cnt is 0\n");
|
|
|
return -1;
|
|
|
}
|
|
|
- //LOGD("___ chInfo.info[0].status: %d\n", power[0].pwrinfo.status);
|
|
|
|
|
|
list_for_each_entry(tmp, &dm2->_globalPowerManger.list, list)
|
|
|
{
|
|
|
- tmp->_PowerInfo = power[cnt].pwrinfo;
|
|
|
- tmp->product_ch_start_delay = power[cnt].start_delay;
|
|
|
- tmp->product_ch_stop_delay = power[cnt].stop_delay;
|
|
|
- cnt++;
|
|
|
+ int cnt2=0;
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ tmp3->_PowerInfo = info->ch[cnt].pinfo[cnt2++].power;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ tmp->_PowerInfo = info->ch[cnt].pinfo[0].power;
|
|
|
+ cnt++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
@@ -782,7 +763,7 @@ static void print_sensor(char *s, sensor_data_t *ss)
|
|
|
|
|
|
}
|
|
|
#define VALUE_OF(m,a,b) ((m[a]<<16)+m[b])
|
|
|
-static int power_get(cascade_handle_t *cas, int addr, sensor_data_t *ss)
|
|
|
+static int sensor_get(cascade_handle_t *cas, int addr, sensor_data_t *ss)
|
|
|
{
|
|
|
uint32_t offset = 6000;
|
|
|
uint32_t value = 0 ;
|
|
|
@@ -823,7 +804,7 @@ static int master_cmd(cascade_handle_t *cas, cmd_data_t *cmd)
|
|
|
GlobalPowerManger *tmp=NULL;
|
|
|
GlobalDeviceManager *dm=get_dm();
|
|
|
GlobalDeviceManager *dm2=get_dm2();
|
|
|
- GlobalDeviceInfo *dev=&dm2->_global_device_info;
|
|
|
+ GlobalDeviceInfo *dev=dm2->_global_device_info;
|
|
|
data_t rdata,wdata;
|
|
|
|
|
|
if(cur_dev_addr==0) {
|
|
|
@@ -850,14 +831,14 @@ static int master_cmd(cascade_handle_t *cas, cmd_data_t *cmd)
|
|
|
wdata.data = (uint8_t*)cmd;
|
|
|
|
|
|
rdata.dlen = 1;
|
|
|
- rdata.data = (uint8_t*)&cas->info.cnt;
|
|
|
+ rdata.data = (uint8_t*)&cas->sInfo.cnt;
|
|
|
|
|
|
LOGD("_____ master send CASCADE_CMD_GET_INFO\n");
|
|
|
r = mb_write_read(cas, cur_dev_addr, &wdata, &rdata);
|
|
|
if(r==0) {
|
|
|
- LOGD("______cas->info.cnt: %d\n", cas->info.cnt);
|
|
|
- rdata.dlen = sizeof(cas->info.cnt);
|
|
|
- rdata.data = (uint8_t*)&cas->info;
|
|
|
+ LOGD("______cas->info.cnt: %d\n", cas->sInfo.cnt);
|
|
|
+ rdata.dlen = sizeof(slave_info_t)-sizeof(channel_info_t)*(CH_MAX-cas->sInfo.cnt);
|
|
|
+ rdata.data = (uint8_t*)&cas->sInfo;
|
|
|
r = mb_write_read(cas, cur_dev_addr, &wdata, &rdata);
|
|
|
if(r==0) {
|
|
|
power_add(cas);
|
|
|
@@ -897,17 +878,16 @@ static int master_query(cascade_handle_t *cas)
|
|
|
case CASCADE_CMD_QUERY_CH:
|
|
|
{
|
|
|
//LOGD("____ master query CASCADE_CMD_QUERY_CH, cnt: %d\n", cas->info.cnt);
|
|
|
- if(cas->info.cnt==0) {
|
|
|
+ if(cas->sInfo.cnt==0) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- cas->chInfo.cnt = 0;
|
|
|
- rdata.dlen = sizeof(uint8_t)+sizeof(power_info_t)*cas->info.cnt;
|
|
|
- rdata.data = (uint8_t*)&cas->chInfo;
|
|
|
+ rdata.dlen = sizeof(slave_info_t)-sizeof(channel_info_t)*(CH_MAX-cas->sInfo.cnt);
|
|
|
+ rdata.data = (uint8_t*)&cas->sInfo;
|
|
|
|
|
|
r = mb_write_read(cas, cur_dev_addr, &wdata, &rdata);
|
|
|
if(r==0) {
|
|
|
- power_ch_update(cas);
|
|
|
+ power_update(cas);
|
|
|
}
|
|
|
else {
|
|
|
LOGE("____ master query CASCADE_CMD_QUERY_CH failed\n");
|
|
|
@@ -1081,7 +1061,7 @@ static void* cmd_thread(void *arg)
|
|
|
int i,t=0;
|
|
|
char temp[100];
|
|
|
cascade_handle_t *cas=&casHandle;
|
|
|
- board_info_t *info=&cas->info;
|
|
|
+ slave_info_t *info=&cas->sInfo;
|
|
|
GlobalDeviceManager *dm=get_dm();
|
|
|
cmd_data_t *pcmd=(cmd_data_t*)arg;
|
|
|
|
|
|
@@ -1096,17 +1076,17 @@ static void* cmd_thread(void *arg)
|
|
|
if(pcmd->chId == 0xff) {
|
|
|
int sendAddr = 0;
|
|
|
for(i=0; i<info->cnt; i++) {
|
|
|
- if(info->channel[i].addr>0) {
|
|
|
- if(info->channel[i].addr==sendAddr) {
|
|
|
+ if(info->ch[i].product_ch_addr>0) {
|
|
|
+ if(info->ch[i].product_ch_addr==sendAddr) {
|
|
|
continue;
|
|
|
}
|
|
|
else {
|
|
|
- sendAddr = info->channel[i].addr;
|
|
|
+ sendAddr = info->ch[i].product_ch_addr;
|
|
|
}
|
|
|
|
|
|
- t = g_switch_set_all_ctrl(&dm->_globalRelaySampManger, info->channel[i].type, info->channel[i].addr, flag);
|
|
|
+ t = g_switch_set_all_ctrl(&dm->_globalRelaySampManger, info->ch[i].product_ch_type, info->ch[i].product_ch_addr, flag);
|
|
|
if(t<0) {
|
|
|
- LOGE("___ %d %s failed\n", info->channel[i].addr, (pcmd->cmd==CASCADE_CMD_OPEN)?"open":"close");
|
|
|
+ LOGE("___ %d %s failed\n", info->ch[i].product_ch_addr, (pcmd->cmd==CASCADE_CMD_OPEN)?"open":"close");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1141,7 +1121,7 @@ static int set_modbus(cascade_handle_t *cas, ModbusInfo_t *info)
|
|
|
mb_deinit(cas);
|
|
|
}
|
|
|
cas->inited = 0;
|
|
|
- LOGD("master init modbus: port: %s, type: %d, baud: %d\n", CASCADE_MODBUS_PORT, info->product_modbus_type, info->product_modbus_baud);
|
|
|
+ //LOGD("master init modbus: port: %s, type: %d, baud: %d\n", CASCADE_MODBUS_PORT, info->product_modbus_type, info->product_modbus_baud);
|
|
|
|
|
|
r = mb_init(cas, CASCADE_MODBUS_PORT, info->product_modbus_type,
|
|
|
info->product_modbus_addr, info->product_modbus_baud);
|
|
|
@@ -1165,6 +1145,7 @@ int cascade_init(void)
|
|
|
power_init();
|
|
|
slave_init(cas);
|
|
|
pthread_mutex_init(&cas->mutex, NULL);
|
|
|
+ pthread_mutex_init(&cas->lock, NULL);
|
|
|
|
|
|
cas->scanAddr = 1;
|
|
|
cas->map2 = modbus_mapping_new_start_address(0,0,0,0,
|
|
|
@@ -1236,16 +1217,10 @@ int cascade_request(cmd_data_t *cmd)
|
|
|
if(!cmd) {
|
|
|
return -1;
|
|
|
}
|
|
|
-
|
|
|
- if(cmd->cmd==CASCADE_CMD_QUERY_CH) {
|
|
|
- cmd_data_t cmd2=*cmd;
|
|
|
- cmd2.cmd = CASCADE_CMD_GET_INFO;
|
|
|
- r = master_cmd(cas, &cmd2);
|
|
|
- }
|
|
|
|
|
|
- if(r==0) {
|
|
|
- r = master_cmd(cas, cmd);
|
|
|
- }
|
|
|
+ pthread_mutex_lock(&cas->lock);
|
|
|
+ r = master_cmd(cas, cmd);
|
|
|
+ pthread_mutex_unlock(&cas->lock);
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
@@ -1253,27 +1228,28 @@ int cascade_request(cmd_data_t *cmd)
|
|
|
|
|
|
int cascade_get(_OverChnPwrAckInfo *chInfo)
|
|
|
{
|
|
|
- GlobalPowerManger* pwr=NULL;
|
|
|
+ GlobalPowerManger *tmp=NULL;
|
|
|
+ GlobalTreeACManager *tmp3=NULL;
|
|
|
_OverChnPwrAckInfo *pch=NULL;
|
|
|
GlobalDeviceManager* dm2=get_dm2();
|
|
|
|
|
|
- list_for_each_entry(pwr, &dm2->_globalPowerManger.list, list)
|
|
|
+ list_for_each_entry(tmp, &dm2->_globalPowerManger.list, list)
|
|
|
{
|
|
|
- if (pwr->product_ch_type==TREE_AC_TYPE)
|
|
|
+ if (tmp->product_ch_type==TREE_AC_TYPE)
|
|
|
{
|
|
|
- GlobalTreeACManager* _TreeACTemp=NULL;
|
|
|
+
|
|
|
int nStatus=-1;//-1则状态不变,0、1则是子状态
|
|
|
//判断是否三相单输出情况下
|
|
|
- if(pwr->product_ch_type==TREE_AC_TYPE) {
|
|
|
- list_for_each_entry(_TreeACTemp, &pwr->list_Tree_AC, list_Tree_AC) {
|
|
|
- if (2 == _TreeACTemp->product_ph_outputType &&1==_TreeACTemp->product_ph_outputStatus)
|
|
|
+ if(tmp->product_ch_type==TREE_AC_TYPE) {
|
|
|
+ list_for_each_entry(tmp3, &tmp->list_Tree_AC, list_Tree_AC) {
|
|
|
+ if (2 == tmp3->product_ph_outputType &&1==tmp3->product_ph_outputStatus)
|
|
|
{//单项并且状态为输出
|
|
|
- nStatus=_TreeACTemp->_PowerInfo.status;
|
|
|
+ nStatus = tmp3->_PowerInfo.status;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- list_for_each_entry(_TreeACTemp, &pwr->list_Tree_AC, list_Tree_AC)
|
|
|
+ list_for_each_entry(tmp3, &tmp->list_Tree_AC, list_Tree_AC)
|
|
|
{
|
|
|
pch = (_OverChnPwrAckInfo *)malloc(sizeof(_OverChnPwrAckInfo));
|
|
|
if (pch == NULL) {
|
|
|
@@ -1283,27 +1259,27 @@ int cascade_get(_OverChnPwrAckInfo *chInfo)
|
|
|
pch->product_name = dm2->_global_device_info->product_name;
|
|
|
pch->product_number = dm2->_global_device_info->product_number;
|
|
|
pch->product_id = dm2->_global_device_info->product_id;
|
|
|
- pch->productChName = pwr->product_ch_name;
|
|
|
- pch->productChId = pwr->product_ch_id;
|
|
|
- pch->status = pwr->_PowerInfo.status;
|
|
|
- pch->voltage = pwr->_PowerInfo.voltage;
|
|
|
- pch->current = pwr->_PowerInfo.current;
|
|
|
- pch->power = pwr->_PowerInfo.power;
|
|
|
- pch->freq = pwr->_PowerInfo.freq;
|
|
|
- pch->consumption = pwr->_PowerInfo.consumption;
|
|
|
- pch->factor = pwr->_PowerInfo.factor;
|
|
|
- pch->product_ch_start_delay = pwr->product_ch_start_delay;
|
|
|
- pch->product_ch_stop_delay = pwr->product_ch_stop_delay;
|
|
|
- pch->product_type=pwr->product_ch_type;
|
|
|
- pch->product_phType = _TreeACTemp->product_ph_type;
|
|
|
- pch->ph_voltage = _TreeACTemp->_PowerInfo.voltage;
|
|
|
- pch->ph_current = _TreeACTemp->_PowerInfo.current;
|
|
|
- pch->ph_power = _TreeACTemp->_PowerInfo.power;
|
|
|
- pch->ph_consumption = _TreeACTemp->_PowerInfo.consumption;
|
|
|
- pch->ph_outputType = _TreeACTemp->product_ph_outputType;
|
|
|
- pch->ph_outputStatus = _TreeACTemp->product_ph_outputStatus;
|
|
|
+ pch->productChName = tmp->product_ch_name;
|
|
|
+ pch->productChId = tmp->product_ch_id;
|
|
|
+ pch->status = tmp->_PowerInfo.status;
|
|
|
+ pch->voltage = tmp->_PowerInfo.voltage;
|
|
|
+ pch->current = tmp->_PowerInfo.current;
|
|
|
+ pch->power = tmp->_PowerInfo.power;
|
|
|
+ pch->freq = tmp->_PowerInfo.freq;
|
|
|
+ pch->consumption = tmp->_PowerInfo.consumption;
|
|
|
+ pch->factor = tmp->_PowerInfo.factor;
|
|
|
+ pch->product_ch_start_delay = tmp->product_ch_start_delay;
|
|
|
+ pch->product_ch_stop_delay = tmp->product_ch_stop_delay;
|
|
|
+ pch->product_type=tmp->product_ch_type;
|
|
|
+ pch->product_phType = tmp3->product_ph_type;
|
|
|
+ pch->ph_voltage = tmp3->_PowerInfo.voltage;
|
|
|
+ pch->ph_current = tmp3->_PowerInfo.current;
|
|
|
+ pch->ph_power = tmp3->_PowerInfo.power;
|
|
|
+ pch->ph_consumption = tmp3->_PowerInfo.consumption;
|
|
|
+ pch->ph_outputType = tmp3->product_ph_outputType;
|
|
|
+ pch->ph_outputStatus = tmp3->product_ph_outputStatus;
|
|
|
if (dm2->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One &&
|
|
|
- _TreeACTemp->product_ph_outputType == 2 && _TreeACTemp->product_ph_outputStatus == 2) // 如果是单项输出并且则非输出通道数据为0
|
|
|
+ tmp3->product_ph_outputType == 2 && tmp3->product_ph_outputStatus == 2) // 如果是单项输出并且则非输出通道数据为0
|
|
|
{
|
|
|
// 3-1模式 单项状态,不输出则数据为空
|
|
|
pch->ph_voltage = 0.0;
|
|
|
@@ -1315,7 +1291,7 @@ int cascade_get(_OverChnPwrAckInfo *chInfo)
|
|
|
{
|
|
|
pch->status = nStatus;
|
|
|
}else {
|
|
|
- pch->status = pwr->_PowerInfo.status;
|
|
|
+ pch->status = tmp->_PowerInfo.status;
|
|
|
}
|
|
|
list_add_tail(&pch->list, &chInfo->list);
|
|
|
}
|
|
|
@@ -1331,17 +1307,17 @@ int cascade_get(_OverChnPwrAckInfo *chInfo)
|
|
|
pch->product_name = dm2->_global_device_info->product_name;
|
|
|
pch->product_number = dm2->_global_device_info->product_number;
|
|
|
pch->product_id = dm2->_global_device_info->product_id;
|
|
|
- pch->productChName = pwr->product_ch_name;
|
|
|
- pch->productChId = pwr->product_ch_id;
|
|
|
- pch->status = pwr->_PowerInfo.status;
|
|
|
- pch->voltage = pwr->_PowerInfo.voltage;
|
|
|
- pch->current = pwr->_PowerInfo.current;
|
|
|
- pch->power = pwr->_PowerInfo.power;
|
|
|
- pch->freq = pwr->_PowerInfo.freq;
|
|
|
- pch->consumption = pwr->_PowerInfo.consumption;
|
|
|
- pch->factor = pwr->_PowerInfo.factor;
|
|
|
- pch->product_ch_start_delay = pwr->product_ch_start_delay;
|
|
|
- pch->product_ch_stop_delay = pwr->product_ch_stop_delay;
|
|
|
+ pch->productChName = tmp->product_ch_name;
|
|
|
+ pch->productChId = tmp->product_ch_id;
|
|
|
+ pch->status = tmp->_PowerInfo.status;
|
|
|
+ pch->voltage = tmp->_PowerInfo.voltage;
|
|
|
+ pch->current = tmp->_PowerInfo.current;
|
|
|
+ pch->power = tmp->_PowerInfo.power;
|
|
|
+ pch->freq = tmp->_PowerInfo.freq;
|
|
|
+ pch->consumption = tmp->_PowerInfo.consumption;
|
|
|
+ pch->factor = tmp->_PowerInfo.factor;
|
|
|
+ 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, &chInfo->list);
|
|
|
}
|
|
|
}
|
|
|
@@ -1349,6 +1325,7 @@ int cascade_get(_OverChnPwrAckInfo *chInfo)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
int cascade_lock(void)
|
|
|
{
|
|
|
cascade_handle_t *cas=&casHandle;
|