Explorar o código

1.修复电压下限不报警问题.
2.重新加载通道功能上传

chenyuanjie %!s(int64=2) %!d(string=hai) anos
pai
achega
b7c7e59155
Modificáronse 3 ficheiros con 527 adicións e 146 borrados
  1. 4 4
      pro/src/app.c
  2. 8 3
      pro/src/appweb_handle.c
  3. 515 139
      pro/src/switch_ctrl.c

+ 4 - 4
pro/src/app.c

@@ -255,11 +255,11 @@ void* power_thread(void* arg)
                         /*高电压 */
                         dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_V_UP);
                     }
-                    if (_globalPowerWarningInfo.w_voltage_down!=_globalPowerMangerTemp->_PowerWarninginfo.w_voltage_down&&_globalPowerWarningInfo.w_voltage_up)
+                    if (_globalPowerWarningInfo.w_voltage_down!=_globalPowerMangerTemp->_PowerWarninginfo.w_voltage_down&&_globalPowerWarningInfo.w_voltage_down)
                     {
                         _globalPowerMangerTemp->_PowerWarninginfo.w_voltage_down=_globalPowerWarningInfo.w_voltage_down;
                         /*低电压 */
-                        dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_V_UP);
+                        dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_V_DOWN);
                     }
                     if (_globalPowerWarningInfo.w_current!=_globalPowerMangerTemp->_PowerWarninginfo.w_current&&_globalPowerWarningInfo.w_current)
                     {
@@ -611,11 +611,11 @@ void* power_thread(void* arg)
                         /*高电压 */
                         dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_V_UP);
                     }
-                    if (_globalPowerWarningInfo.w_voltage_down!=_globalPowerMangerTemp->_PowerWarninginfo.w_voltage_down&&_globalPowerWarningInfo.w_voltage_up)
+                    if (_globalPowerWarningInfo.w_voltage_down!=_globalPowerMangerTemp->_PowerWarninginfo.w_voltage_down&&_globalPowerWarningInfo.w_voltage_down)
                     {
                         _globalPowerMangerTemp->_PowerWarninginfo.w_voltage_down=_globalPowerWarningInfo.w_voltage_down;
                         /*低电压 */
-                        dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_V_UP);
+                        dev_Alarm_send_message(_globalDeviceManager,_globalPowerMangerTemp,WARNING_V_DOWN);
                     }
                     if (_globalPowerWarningInfo.w_current!=_globalPowerMangerTemp->_PowerWarninginfo.w_current&&_globalPowerWarningInfo.w_current)
                     {

+ 8 - 3
pro/src/appweb_handle.c

@@ -3553,10 +3553,15 @@ static void equipmentMintenance(void *conn)
 
         sys_set_factory();
     }
-    else {
-        
+    else if (strcmp(_Over_equipment_mintenance.type,"resetChannel") == 0)
+    {
+        //__globalDeviceManage._ReloadChm_flag=true;
+        pthread_mutex_lock(&__globalDeviceManage._power_update);
+        ResetChmData();
+        pthread_mutex_unlock(&__globalDeviceManage._power_update);
+        //__globalDeviceManage._ReloadChm_flag=false;
     }
-    
+
     cJSON_Delete(cjson);
     int r = http_reply(conn, 200, ack_str);
     cJSON_free((void*)ack_str);

+ 515 - 139
pro/src/switch_ctrl.c

@@ -2070,147 +2070,477 @@ int g_switch_get_gpio_status(int ngpio,int* nStatus)
   
     return 0;  
 }
-int  ResetChmData()
+
+/**
+ * @brief 清除全局电源管理器
+ *
+ * 清除指定的全局电源管理器对象,并释放相关资源。
+ *
+ * @param _globalDeviceManager 全局电源管理器对象指针
+ *
+ * @return 返回值表示操作是否成功,成功返回0,失败返回非0值
+ */
+int power_clear(GlobalPowerManger *globalPowerManager)
 {
-    //搜索子地址
-    int ret=0;
-    int chn = 1;
-    int type=0;
-    __globalDeviceManage.useSlaveCount=0;
 
+    GlobalPowerManger* _globalPowerMangerTemp,* pos;
+    GlobalTreeACManager *_pTreeACPowerPhData,*pos1;
+    _PowerDSManage_t* _powerDsManageTemp,*pos2;
+    if (globalPowerManager == NULL)
+    {
+        return -1;
+    }
+    list_for_each_entry_safe(_globalPowerMangerTemp, pos, &globalPowerManager->list, list)
+    {
+        if (_globalPowerMangerTemp == NULL)
+        {
+            continue;
+        }
+        
+        list_for_each_entry_safe(_powerDsManageTemp, pos2,&_globalPowerMangerTemp->list_DS, list)
+        {
+            list_del(&_powerDsManageTemp->list);
+            free(_powerDsManageTemp);
+        }
+        list_for_each_entry_safe(_pTreeACPowerPhData, pos1,&_globalPowerMangerTemp->list_Tree_AC, list_Tree_AC)
+        {
+            list_del(&_pTreeACPowerPhData->list_Tree_AC);
+            if(_pTreeACPowerPhData->global_over_manager) {
+                free(_pTreeACPowerPhData->global_over_manager);
+            }
+            free(_pTreeACPowerPhData);
+        }
+        list_del(&_globalPowerMangerTemp->list);
+        if (_globalPowerMangerTemp->global_over_manager)
+        {
+            free(_globalPowerMangerTemp->global_over_manager);
+        }
+        if (_globalPowerMangerTemp->_PowerSXManage)
+        {
+            free(_globalPowerMangerTemp->_PowerSXManage);
+        }
+        free(_globalPowerMangerTemp);
+    }
+    return 0;
+}
+
+int ResetChmData()
+{
+    // 搜索子地址
+    int ret = 0;
+    int chn = 1;
+    int type = 0;
+    int nTac_chn=3;
+    int nGroups=8;
+    GlobalDeviceManager* _globalDeviceManager=&__globalDeviceManage;    
+    __globalDeviceManage.useSlaveCount = 0;
+    power_clear(&_globalDeviceManager->_globalPowerManger);
     for (size_t i = 0; i < MAX_CHN_COUNT; i++)
     {
-        type = 0 ;
-        int nMaxChn=0;
+        type = 0;
+        int nMaxChn = 0;
         ret = g_switch_get_type(&__globalDeviceManage._globalRelaySampManger,
-                          i,
-                          &type,
-                          &nMaxChn,
-                          __globalDeviceManage._global_device_info->product_pwr_type);
-        log_d("ret:%d saddr:%d type:%d ch_num:%d.\n",ret,i,type,nMaxChn);
-        //int i =1 ;
-        //type = AC_SINGLE_S_TYPE ;
-        //chn = i ;
-
-        if(ret==0)
+                                i,
+                                &type,
+                                &nMaxChn,
+                                __globalDeviceManage._global_device_info->product_pwr_type);
+        log_d("ret:%d saddr:%d type:%d ch_num:%d.\n", ret, i, type, nMaxChn);
+        // 有效地址记录
+
+        if (ret == 0)
         {
-            //有效地址记录
-            __globalDeviceManage.useSlaveCount ++ ;
+            _globalDeviceManager->useSlaveCount ++ ;
+            _globalDeviceManager->_all_ctrl_board[i].product_saddr = i;
+            _globalDeviceManager->_all_ctrl_board[i].product_number = nMaxChn;
+            _globalDeviceManager->_all_ctrl_board[i].product_type = type;
             switch (type)
             {
-                case AC_SINGLE_S_TYPE://AC单相小电流 8路继电器
-                case AC_SINGLE_B_TYPE://AC单相大电流 4路继电器
+            case AC_SINGLE_S_TYPE: // AC单相小电流 8路继电器
+            case AC_SINGLE_B_TYPE:
+            {
+                log_i("Address=%d AC_SINGLE_S_TYPE!\n", i);
+                for (size_t j = 0; j < nMaxChn; j++)
                 {
-                    log_i("Address=%d AC_SINGLE_S_TYPE!\n",i);
-                    for (size_t j = 0; j < nMaxChn; j++)
+                    GlobalPowerManger *_globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
+                    if (_globalPowerMangerTemp == NULL)
+                    {
+                        // log_e("_globalPowerManger malloc error.\n");
+                        return -1;
+                    }
+                    memset(_globalPowerMangerTemp, 0, sizeof(GlobalPowerManger));
+                    _globalPowerMangerTemp->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                    if (_globalPowerMangerTemp->global_over_manager == NULL)
+                    {
+                        // log_e("_globalPowerManger->global_over_manager malloc error.\n");
+                        return -1;
+                    }
+                    memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
+                    // 查询是否由通道信息
+                    ret = dev_get_power_manage_info(_globalDeviceManager->db,
+                                                    _globalDeviceManager->_global_device_info->product_id,
+                                                    i,
+                                                    j + 1, // 1*8+j
+                                                    _globalPowerMangerTemp);
+                    // 未查询到信息 则插入
+                    if (ret == -1)
                     {
-                        bool isLoad=false ;
-                        GlobalPowerManger* _globalPowerMangerTemp=NULL;
-                        list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
+                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                        _globalPowerMangerTemp->product_saddr = i;
+                        _globalPowerMangerTemp->product_ch_id = chn;
+                        _globalPowerMangerTemp->product_ch_addr = j + 1;
+                        sprintf(_globalPowerMangerTemp->product_ch_name, "CH%d", _globalPowerMangerTemp->product_ch_id);
+                        _globalPowerMangerTemp->product_ch_type = type;
+                        _globalPowerMangerTemp->product_ch_status = 0;
+
+                        _globalPowerMangerTemp->product_ch_start_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+                        _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+
+                        if (dev_insert_power_manage_info(_globalDeviceManager->db,
+                                                         _globalDeviceManager->_global_device_info->product_id,
+                                                         _globalPowerMangerTemp->product_ch_id,
+                                                         _globalPowerMangerTemp) != 0)
                         {
-                            if (_globalPowerMangerTemp->product_saddr==i&&_globalPowerMangerTemp->product_ch_addr==j+1)
-                            {
-                                isLoad=true;
-                                break;
-                            }
+                            log_e("address %d chn %d data inserted error.\n", i, chn);
+                            return 0;
                         }
-                        if (!isLoad)
+                        /*
+                        else
                         {
-                            _globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
-                            if (_globalPowerMangerTemp == NULL)
+                            log_i("chn %d data inserted ok.\n",(i-1)*AC_SINGLE_S_CUR_CHN_NUM+j+1);
+                        }
+                        */
+                    }
+                        if ( _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One_B)
+                    {
+                        // 初始化三相子通道
+                        GlobalTreeACManager *_globalTACManager = NULL;
+                        INIT_LIST_HEAD(&_globalPowerMangerTemp->list_Tree_AC);
+                        for (size_t indexT = 0; indexT < 3; indexT++)
+                        {
+                            _globalTACManager = (GlobalTreeACManager *)malloc(sizeof(GlobalTreeACManager));
+                            memset(_globalTACManager, 0, sizeof(GlobalTreeACManager));
+                            if (_globalTACManager == NULL)
                             {
-                                // log_e("_globalPowerManger malloc error.\n");
+                                log_e("_globalTACManager malloc error.\n");
                                 return -1;
                             }
-                            memset(_globalPowerMangerTemp, 0, sizeof(GlobalPowerManger));
-                            _globalPowerMangerTemp->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
-                            if (_globalPowerMangerTemp->global_over_manager == NULL)
+                            _globalTACManager->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                            memset(_globalTACManager->global_over_manager, 0, sizeof(GlobalOverManager));
+                            if (_globalTACManager->global_over_manager == NULL)
                             {
-                                // log_e("_globalPowerManger->global_over_manager malloc error.\n");
+                                log_e("_globalTACManager->global_over_manager malloc error.\n");
                                 return -1;
                             }
-                            memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
-                        }
-                        //查询是否由通道信息
-                        ret = dev_get_power_manage_info(__globalDeviceManage.db,
-                                                        __globalDeviceManage._global_device_info->product_id,i,
-                                                        j+1, //1*8+j
-                                                        _globalPowerMangerTemp);
-                        //未查询到信息 则插入
-                        if(ret==-1)
-                        {
-                            _globalPowerMangerTemp->product_id = __globalDeviceManage._global_device_info->product_id;
-                            _globalPowerMangerTemp->product_saddr = i ;
-                            _globalPowerMangerTemp->product_ch_id = chn;
-                            _globalPowerMangerTemp->product_ch_addr = j+1;
-                            sprintf(_globalPowerMangerTemp->product_ch_name,"CH%d",_globalPowerMangerTemp->product_ch_id);
-                            _globalPowerMangerTemp->product_ch_type = type;
-                            _globalPowerMangerTemp->product_ch_status = 0;
-                            _globalPowerMangerTemp->product_ch_start_delay = 1000;
-                            _globalPowerMangerTemp->product_ch_stop_delay = 1000;
-                            if(dev_insert_power_manage_info(__globalDeviceManage.db,
-                                                        __globalDeviceManage._global_device_info->product_id,
-                                                        _globalPowerMangerTemp->product_ch_id,
-                                                        _globalPowerMangerTemp)!=0)
+                            ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
+                                                                 _globalDeviceManager->_global_device_info->product_id, i,
+                                                                 j + 1, // 1*8+j
+                                                                 nTac_chn,
+                                                                 _globalTACManager);
+                            _globalTACManager->product_ch_addr = j + 1;
+                            // 未查询到信息 则插入
+                            if (ret == -1)
                             {
-                                log_e("address %d chn %d data inserted error.\n",i,chn);
-                                return 0;
+                                _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalTACManager->product_saddr = i;
+                                _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
+                                _globalTACManager->product_ch_addr = j + 1;
+                                _globalTACManager->product_ph_id = nTac_chn;
+                                _globalTACManager->product_ph_type = indexT;
+                                _globalTACManager->product_ph_outputType = 2; // 1三相2单相
+                                if (indexT == ((nTac_chn-3)/(8*3)+3)%3)
+                                {
+                                    _globalTACManager->product_ph_outputStatus = 1; // 1输出2不输出
+                                }
+                                else
+                                {
+                                    _globalTACManager->product_ph_outputStatus = 2; // 1输出2不输出
+                                }
+
+                                if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
+                                                                      _globalDeviceManager->_global_device_info->product_id,
+                                                                      _globalTACManager->product_ch_id,
+                                                                      _globalTACManager) != 0)
+                                {
+                                    log_e("address %d ph_chn %d data inserted error.\n", i, nTac_chn);
+                                    return 0;
+                                }
                             }
-                            /*
-                            else
+                            // 绑定到三项通道
+                            _globalTACManager->product_saddr = i;
+                            _globalTACManager->product_ph_type = indexT;
+                            if (_globalPowerMangerTemp)
                             {
-                                log_i("chn %d data inserted ok.\n",(i-1)*AC_SINGLE_S_CUR_CHN_NUM+j+1);
+                                list_add_tail(&_globalTACManager->list_Tree_AC, &_globalPowerMangerTemp->list_Tree_AC);
                             }
-                            */
-                        }
-                        _globalPowerMangerTemp->product_saddr = i ;
-                        //添加到队尾
-                        if (!isLoad)
-                        {
-                            list_add_tail(&_globalPowerMangerTemp->list,&__globalDeviceManage._globalPowerManger.list);
+                            nTac_chn += 1;
                         }
-
-                        chn+=1;
                     }
+                    _globalPowerMangerTemp->product_saddr = i;
+                    // 添加到队尾
+                    list_add_tail(&_globalPowerMangerTemp->list, &_globalDeviceManager->_globalPowerManger.list);
+                    chn += 1;
                 }
+            }
+            break;
+            case AC_MULTI_S_TYPE: // 预留
                 break;
-                case AC_MULTI_S_TYPE://预留
-                {
-
-                }
+            case AC_MULTI_B_TYPE: // 预留
                 break;
-                case AC_MULTI_B_TYPE://预留
-                {
-
-                }
+            case DC_OUT_TYPE: // DC输出继电器 1路
                 break;
-                case DC_OUT_TYPE:   //DC输出继电器 1路
+            case DC_IN_TYPE: // DC采集
+            {
+                log_i("Address=%d DC_IN_TYPE!\n", i);
+                for (size_t j = 0; j < nMaxChn; j++) // AC与DC长度一致
                 {
-
+                    GlobalPowerManger *_globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
+                    if (_globalPowerMangerTemp == NULL)
+                    {
+                        // log_e("_globalPowerManger malloc error.\n");
+                        return -1;
+                    }
+                    memset(_globalPowerMangerTemp, 0, sizeof(GlobalPowerManger));
+                    _globalPowerMangerTemp->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                    if (_globalPowerMangerTemp->global_over_manager == NULL)
+                    {
+                        // log_e("_globalPowerManger->global_over_manager malloc error.\n");
+                        return -1;
+                    }
+                    memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
+                    // 查询是否由通道信息
+                    ret = dev_get_power_manage_info(_globalDeviceManager->db,
+                                                    _globalDeviceManager->_global_device_info->product_id, i,
+                                                    j + 1, // 1*8+j
+                                                    _globalPowerMangerTemp);
+                    // 未查询到信息 则插入
+                    if (ret == -1)
+                    {
+                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                        _globalPowerMangerTemp->product_saddr = i;
+                        _globalPowerMangerTemp->product_ch_id = chn;
+                        _globalPowerMangerTemp->product_ch_addr = j + 1;
+                        sprintf(_globalPowerMangerTemp->product_ch_name, "CH%d", _globalPowerMangerTemp->product_ch_id);
+                        _globalPowerMangerTemp->product_ch_type = type;
+                        _globalPowerMangerTemp->product_ch_status = 0;
+                        _globalPowerMangerTemp->product_ch_start_delay = 1000;
+                        _globalPowerMangerTemp->product_ch_stop_delay = 1000;
+                        if (dev_insert_power_manage_info(_globalDeviceManager->db,
+                                                         _globalDeviceManager->_global_device_info->product_id,
+                                                         _globalPowerMangerTemp->product_ch_id,
+                                                         _globalPowerMangerTemp) != 0)
+                        {
+                            log_e("address %d chn %d data inserted error.\n", i, chn);
+                            return 0;
+                        }
+                        /*
+                        else
+                        {
+                            log_i("chn %d data inserted ok.\n",(i-1)*AC_SINGLE_S_CUR_CHN_NUM+j+1);
+                        }
+                        */
+                    }
+                    _globalPowerMangerTemp->product_saddr = i;
+                    // 添加到队尾
+                    list_add_tail(&_globalPowerMangerTemp->list, &_globalDeviceManager->_globalPowerManger.list);
+                    chn += 1;
                 }
-                break;
-                case DC_IN_TYPE:    // DC采集
+            }
+            break;
+            case DCPDU_TYPE: // DCPDU
+            {
+                log_i("DCPDU_TYPE!\n");
+                for (size_t j = 0; j < nMaxChn; j++)
                 {
+                    GlobalPowerManger *_globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
+                    if (_globalPowerMangerTemp == NULL)
+                    {
+                        // log_e("_globalPowerManger malloc error.\n");
+                        return -1;
+                    }
+                    memset(_globalPowerMangerTemp, 0, sizeof(GlobalPowerManger));
+                    _globalPowerMangerTemp->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                    if (_globalPowerMangerTemp->global_over_manager == NULL)
+                    {
+                        // log_e("_globalPowerManger->global_over_manager malloc error.\n");
+                        return -1;
+                    }
 
+                    memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
+                    // 查询是否由通道信息
+                    ret = dev_get_power_manage_info(_globalDeviceManager->db,
+                                                    _globalDeviceManager->_global_device_info->product_id, i,
+                                                    j + 1, // 1*8+j
+                                                    _globalPowerMangerTemp);
+                    _globalPowerMangerTemp->product_ch_addr = j + 1;
+                    // 未查询到信息 则插入
+                    if (ret == -1)
+                    {
+                        _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                        _globalPowerMangerTemp->product_saddr = i;
+                        _globalPowerMangerTemp->product_ch_id = chn;
+                        _globalPowerMangerTemp->product_ch_addr = j + 1;
+                        sprintf(_globalPowerMangerTemp->product_ch_name, "CH%d", _globalPowerMangerTemp->product_ch_id);
+                        _globalPowerMangerTemp->product_ch_type = type;
+                        _globalPowerMangerTemp->product_ch_status = 0;
 
+                        _globalPowerMangerTemp->product_ch_start_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+                        _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+
+                        if (dev_insert_power_manage_info(_globalDeviceManager->db,
+                                                         _globalDeviceManager->_global_device_info->product_id,
+                                                         _globalPowerMangerTemp->product_ch_id,
+                                                         _globalPowerMangerTemp) != 0)
+                        {
+                            log_e("address %d chn %d data inserted error.\n", i, chn);
+                            return 0;
+                        }
+                        /*
+                        else
+                        {
+                            log_i("chn %d data inserted ok.\n",(i-1)*AC_SINGLE_S_CUR_CHN_NUM+j+1);
+                        }
+                        */
+                    }
+                    _globalPowerMangerTemp->product_saddr = i;
+                    _globalPowerMangerTemp->product_ch_type = type;
+                    if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                    {
+                        log_e("update pwr general data err.");
+                    }
+                    // 添加到队尾
+                    list_add_tail(&_globalPowerMangerTemp->list, &_globalDeviceManager->_globalPowerManger.list);
+                    chn += 1;
                 }
-                break;
-                case DCPDU_TYPE:    // DCPDU
+            }
+            break;
+            case TREE_AC_TYPE: // 三相供电
+            {
+                log_i("TreeAC_TYPE!\n");
+                GlobalPowerManger *_globalPowerMangerTemp = NULL;
+                for (size_t j = 0; j < nMaxChn; j++)
                 {
-                    log_i("DCPDU_TYPE!\n");
-                    for (size_t j = 0; j < nMaxChn; j++)
+                    if (_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_Tree_AC_One)
                     {
-                        bool isLoad=false ;
-                        GlobalPowerManger* _globalPowerMangerTemp=NULL;
-                        list_for_each_entry(_globalPowerMangerTemp, &__globalDeviceManage._globalPowerManger.list, list)
+                        log_i("TreeAC_TYPE_3-1!\n");
+                        _globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
+                        if (_globalPowerMangerTemp == NULL)
+                        {
+                            log_e("_globalPowerManger malloc error.\n");
+                            return -1;
+                        }
+                        memset(_globalPowerMangerTemp, 0, sizeof(GlobalPowerManger));
+                        INIT_LIST_HEAD(&_globalPowerMangerTemp->list_Tree_AC);
+                        _globalPowerMangerTemp->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                        if (_globalPowerMangerTemp->global_over_manager == NULL)
+                        {
+                            log_e("_globalPowerManger->global_over_manager malloc error.\n");
+                            return -1;
+                        }
+                        memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
+                        // 查询是否由通道信息
+                        ret = dev_get_power_manage_info(_globalDeviceManager->db,
+                                                        _globalDeviceManager->_global_device_info->product_id, i,
+                                                        j + 1, // 1*8+j
+                                                        _globalPowerMangerTemp);
+                        _globalPowerMangerTemp->product_ch_addr = j + 1;
+                        // 未查询到信息 则插入
+                        if (ret == -1)
                         {
-                            if (_globalPowerMangerTemp->product_saddr==i&&_globalPowerMangerTemp->product_ch_addr==j+1)
+                            _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalPowerMangerTemp->product_saddr = i;
+                            _globalPowerMangerTemp->product_ch_id = chn;
+                            _globalPowerMangerTemp->product_ch_addr = j + 1;
+                            sprintf(_globalPowerMangerTemp->product_ch_name, "CH%d", _globalPowerMangerTemp->product_ch_id);
+                            _globalPowerMangerTemp->product_ch_type = type;
+                            _globalPowerMangerTemp->product_ch_status = 0;
+
+                            _globalPowerMangerTemp->product_ch_start_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+                            _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+
+                            if (dev_insert_power_manage_info(_globalDeviceManager->db,
+                                                             _globalDeviceManager->_global_device_info->product_id,
+                                                             _globalPowerMangerTemp->product_ch_id,
+                                                             _globalPowerMangerTemp) != 0)
                             {
-                                isLoad=true;
-                                break;
+                                log_e("address %d chn %d data inserted error.\n", i, chn);
+                                return 0;
                             }
                         }
-                        if (!isLoad)
+                        _globalPowerMangerTemp->product_saddr = i;
+                        _globalPowerMangerTemp->product_ch_type = type;
+                        if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                        {
+                            log_e("update pwr general data err.");
+                        }
+                        // 添加到队尾
+                        list_add_tail(&_globalPowerMangerTemp->list, &_globalDeviceManager->_globalPowerManger.list);
+                        chn += 1;
+                        // 初始化三相子通道三进1出
+                        GlobalTreeACManager *_globalTACManager = NULL;
+                        for (size_t indexT = 0; indexT < 3; indexT++)
+                        {
+                            _globalTACManager = (GlobalTreeACManager *)malloc(sizeof(GlobalTreeACManager));
+                            memset(_globalTACManager, 0, sizeof(GlobalTreeACManager));
+                            if (_globalTACManager == NULL)
+                            {
+                                log_e("_globalTACManager malloc error.\n");
+                                return -1;
+                            }
+                            _globalTACManager->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                            memset(_globalTACManager->global_over_manager, 0, sizeof(GlobalOverManager));
+                            if (_globalTACManager->global_over_manager == NULL)
+                            {
+                                log_e("_globalTACManager->global_over_manager malloc error.\n");
+                                return -1;
+                            }
+                            ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
+                                                                 _globalDeviceManager->_global_device_info->product_id, i,
+                                                                 j + 1, // 1*8+j
+                                                                 nTac_chn,
+                                                                 _globalTACManager);
+                            _globalTACManager->product_ch_addr = j + 1;
+                            // 未查询到信息 则插入
+                            if (ret == -1)
+                            {
+                                _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalTACManager->product_saddr = i;
+                                _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
+                                _globalTACManager->product_ch_addr = j + 1;
+                                _globalTACManager->product_ph_id = nTac_chn;
+                                _globalTACManager->product_ph_type = indexT;
+                                _globalTACManager->product_ph_outputType = 2; // 1三相2单相
+                                if (indexT == (j + 3) % 3)
+                                {
+                                    _globalTACManager->product_ph_outputStatus = 1; // 1输出2不输出
+                                }
+                                else
+                                {
+                                    _globalTACManager->product_ph_outputStatus = 2; // 1输出2不输出
+                                }
+
+                                if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
+                                                                      _globalDeviceManager->_global_device_info->product_id,
+                                                                      _globalTACManager->product_ch_id,
+                                                                      _globalTACManager) != 0)
+                                {
+                                    log_e("address %d ph_chn %d data inserted error.\n", i, nTac_chn);
+                                    return 0;
+                                }
+                            }
+                            // 绑定到三项通道
+                            _globalTACManager->product_saddr = i;
+                            _globalTACManager->product_ph_type = indexT;
+                            if (_globalPowerMangerTemp)
+                            {
+                                list_add_tail(&_globalTACManager->list_Tree_AC, &_globalPowerMangerTemp->list_Tree_AC);
+                            }
+                            nTac_chn += 1;
+                        }
+                    }
+                    else
+                    {
+                        log_i("TreeAC_TYPE_3-3!\n");
+                        if ((j + 3) % 3 == 0) // 线路段初始化
                         {
                             _globalPowerMangerTemp = (GlobalPowerManger *)malloc(sizeof(GlobalPowerManger));
                             if (_globalPowerMangerTemp == NULL)
@@ -2219,63 +2549,109 @@ int  ResetChmData()
                                 return -1;
                             }
                             memset(_globalPowerMangerTemp, 0, sizeof(GlobalPowerManger));
+                            INIT_LIST_HEAD(&_globalPowerMangerTemp->list_Tree_AC);
                             _globalPowerMangerTemp->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
                             if (_globalPowerMangerTemp->global_over_manager == NULL)
                             {
-                                // log_e("_globalPowerManger->global_over_manager malloc error.\n");
+                                log_e("_globalPowerManger->global_over_manager malloc error.\n");
                                 return -1;
                             }
-
                             memset(_globalPowerMangerTemp->global_over_manager, 0, sizeof(GlobalOverManager));
+                            // 查询是否由通道信息
+                            ret = dev_get_power_manage_info(_globalDeviceManager->db,
+                                                            _globalDeviceManager->_global_device_info->product_id, i,
+                                                            j / 3 + 1, // 1*8+j
+                                                            _globalPowerMangerTemp);
+                            _globalPowerMangerTemp->product_ch_addr = j / 3 + 1;
+                            // 未查询到信息 则插入
+                            if (ret == -1)
+                            {
+                                _globalPowerMangerTemp->product_id = _globalDeviceManager->_global_device_info->product_id;
+                                _globalPowerMangerTemp->product_saddr = i;
+                                _globalPowerMangerTemp->product_ch_id = chn;
+                                _globalPowerMangerTemp->product_ch_addr = j / 3 + 1;
+                                sprintf(_globalPowerMangerTemp->product_ch_name, "CH%d", _globalPowerMangerTemp->product_ch_id);
+                                _globalPowerMangerTemp->product_ch_type = type;
+                                _globalPowerMangerTemp->product_ch_status = 0;
+
+                                _globalPowerMangerTemp->product_ch_start_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+                                _globalPowerMangerTemp->product_ch_stop_delay = 1000 * (chn % nGroups != 0 ? chn % nGroups : nGroups);
+
+                                if (dev_insert_power_manage_info(_globalDeviceManager->db,
+                                                                 _globalDeviceManager->_global_device_info->product_id,
+                                                                 _globalPowerMangerTemp->product_ch_id,
+                                                                 _globalPowerMangerTemp) != 0)
+                                {
+                                    log_e("address %d chn %d data inserted error.\n", i, chn);
+                                    return 0;
+                                }
+                            }
+                            _globalPowerMangerTemp->product_saddr = i;
+                            _globalPowerMangerTemp->product_ch_type = type;
+                            if (dev_update_power_manage_genera_info(__globalDeviceManage.db, _globalDeviceManager->_global_device_info->product_id, chn, _globalPowerMangerTemp) != 0)
+                            {
+                                log_e("update pwr general data err.");
+                            }
+                            // 添加到队尾
+                            list_add_tail(&_globalPowerMangerTemp->list, &_globalDeviceManager->_globalPowerManger.list);
+                            chn += 1;
                         }
-
-                        //查询是否由通道信息
-                        ret = dev_get_power_manage_info(__globalDeviceManage.db,
-                                                        __globalDeviceManage._global_device_info->product_id,i,
-                                                        j+1, //1*8+j
-                                                        _globalPowerMangerTemp);
-                        _globalPowerMangerTemp->product_ch_addr = j+1;
-                        //未查询到信息 则插入
-                        if(ret==-1)
+                        // 初始化三相子通道三进三出
+                        GlobalTreeACManager *_globalTACManager = NULL;
+                        _globalTACManager = (GlobalTreeACManager *)malloc(sizeof(GlobalTreeACManager));
+                        memset(_globalTACManager, 0, sizeof(GlobalTreeACManager));
+                        if (_globalTACManager == NULL)
                         {
-                            _globalPowerMangerTemp->product_id = __globalDeviceManage._global_device_info->product_id;
-                            _globalPowerMangerTemp->product_saddr = i ;
-                            _globalPowerMangerTemp->product_ch_id = chn;
-                            _globalPowerMangerTemp->product_ch_addr = j+1;
-                            sprintf(_globalPowerMangerTemp->product_ch_name,"CH%d",_globalPowerMangerTemp->product_ch_id);
-                            _globalPowerMangerTemp->product_ch_type = type;
-                            _globalPowerMangerTemp->product_ch_status = 0;
-                            _globalPowerMangerTemp->product_ch_start_delay = 1000;
-                            _globalPowerMangerTemp->product_ch_stop_delay = 1000;
-                            if(dev_insert_power_manage_info(__globalDeviceManage.db,
-                                                        __globalDeviceManage._global_device_info->product_id,
-                                                        _globalPowerMangerTemp->product_ch_id,
-                                                        _globalPowerMangerTemp)!=0)
+                            log_e("_globalTACManager malloc error.\n");
+                            return -1;
+                        }
+                        _globalTACManager->global_over_manager = (GlobalOverManager *)malloc(sizeof(GlobalOverManager));
+                        memset(_globalTACManager->global_over_manager, 0, sizeof(GlobalOverManager));
+                        if (_globalTACManager->global_over_manager == NULL)
+                        {
+                            log_e("_globalTACManager->global_over_manager malloc error.\n");
+                            return -1;
+                        }
+                        ret = dev_get_t_ac_power_manage_info(_globalDeviceManager->db,
+                                                             _globalDeviceManager->_global_device_info->product_id, i,
+                                                             j + 1, // 1*8+j
+                                                             nTac_chn,
+                                                             _globalTACManager);
+                        _globalTACManager->product_ch_addr = j + 1;
+                        // 未查询到信息 则插入
+                        if (ret == -1)
+                        {
+                            _globalTACManager->product_id = _globalDeviceManager->_global_device_info->product_id;
+                            _globalTACManager->product_saddr = i;
+                            _globalTACManager->product_ch_id = _globalPowerMangerTemp->product_ch_id;
+                            _globalTACManager->product_ch_addr = j + 1;
+                            _globalTACManager->product_ph_id = nTac_chn;
+                            _globalTACManager->product_ph_type = (j + 3) % 3;
+                            _globalTACManager->product_ph_outputType = 1;   // 1三相2单相
+                            _globalTACManager->product_ph_outputStatus = 1; // 1输出
+                            if (dev_insert_t_ac_power_manage_info(_globalDeviceManager->db,
+                                                                  _globalDeviceManager->_global_device_info->product_id,
+                                                                  _globalTACManager->product_ch_id,
+                                                                  _globalTACManager) != 0)
                             {
-                                log_e("address %d chn %d data inserted error.\n",i,chn);
+                                log_e("address %d ph_chn %d data inserted error.\n", i, nTac_chn);
                                 return 0;
                             }
                         }
-                        _globalPowerMangerTemp->product_saddr = i ;
-                        _globalPowerMangerTemp->product_ch_type = type;
-                        if (dev_update_power_manage_genera_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info->product_id,chn,_globalPowerMangerTemp) != 0)
+                        // 绑定到三项通道
+                        _globalTACManager->product_saddr = i;
+                        _globalTACManager->product_ph_type = (j + 3) % 3;
+                        if (_globalPowerMangerTemp)
                         {
-                            log_e("update pwr general data err.");
+                            list_add_tail(&_globalTACManager->list_Tree_AC, &_globalPowerMangerTemp->list_Tree_AC);
                         }
-                        //添加到队尾
-                        if (!isLoad)
-                        {
-                            list_add_tail(&_globalPowerMangerTemp->list,&__globalDeviceManage._globalPowerManger.list);
-                        }                        
-                        chn+=1;
+                        nTac_chn += 1;
                     }
                 }
-                break;
+            }
             }
         }
-        else
-            break;
     }
-
+    dev_get_power_ds(_globalDeviceManager->db,&_globalDeviceManager->_globalPowerManger,NULL);
     return ret;
 }