Explorar o código

解决崩溃问题

guohui %!s(int64=2) %!d(string=hai) anos
pai
achega
d8932c8bda

+ 16 - 27
04-软件设计及源码/03-核心板/V1.0/05.src/smart_pdu/src/appweb_handle.c

@@ -9,7 +9,6 @@
 #include "cfg.h"
 
 
-#define WEB_DEBUG
 
 #if 0
 #define LOGD            log_d
@@ -62,19 +61,19 @@ typedef struct {
 static web_handle_t webHandle;
 
 
-static char* g_product_board_cpu[2] = {
+static char* g_product_board_cpu[] = {
     "xxx",
     "T113"
 };
 
-static char* g_product_type_str[4] = {
+static char* g_product_type_str[] = {
     "SmartPdu(DC)",
     "SmartPdu(AC)",
     "SmartPdu(Tree_AC_Tree)",
     "SmartPdu(Tree_AC_One)",
 };
 
-static char* g_product_pwr_type_str[5] = {
+static char* g_product_pwr_type_str[] = {
     "xxx",
     "直流",
     "交流单相",
@@ -111,8 +110,7 @@ static int http_reply(void *conn, int status, char *ack)
     httpFinalize(s);
 #else
     mg_stream_t *s=(mg_stream_t*)conn;
-    //mg_http_reply(s->c, status, ack, "");
-    mg_http_reply(s->c, status, hdr_str, "%s", ack);
+    mg_http_reply(s->c, status, "Content-Type: text/html\r\n", "%s", ack);
 #endif
 
     return r;
@@ -340,9 +338,13 @@ static void changeLanguages(void* conn)
 /// @param stream 
 static void loginFunc(void* conn)
 {
+    int ack_code=0;
     char* ack_str = NULL ;
     char g_token[64] = {0};
     cchar* rx_body_buf = NULL;
+
+    LOGD("___ loginFunc 000\n");
+
 #ifdef USE_WEBAPP
     HttpStream *s=(HttpStream*)conn;
     rx_body_buf = httpGetBodyInput(s);
@@ -398,7 +400,6 @@ static void loginFunc(void* conn)
     //记录token
     strcpy(_newUserLogin->user_token,g_token);
 
-    int ack_code=0;
     if (!LoginFlag) 
     {
         ack_str = log_LoginFailedinfo_to_json();
@@ -411,9 +412,9 @@ static void loginFunc(void* conn)
         ack_str = log_info_to_json(g_token);
         ack_code = 200;
     }
+
     http_reply(conn, ack_code, ack_str);
     cJSON_free((void*)ack_str);
-
 }
 
 /// @brief 注销信息
@@ -435,7 +436,7 @@ static void loginOutFunc(void* conn)
 #endif
 
     //转换json参数
-    if(json_to_User_loginOut_info(rx_body_buf,g_token)!=0)
+    if(json_to_User_loginOut_info(rx_body_buf,&g_token)!=0)
     {
         http_reply(conn, 400, NULL);
         return ;        
@@ -443,8 +444,7 @@ static void loginOutFunc(void* conn)
     
     ack_str = log_info_to_json(g_token);
     http_reply(conn, 200, ack_str);
-
-    cJSON_free((void*)ack_str);
+    free(g_token);
 }
 
 
@@ -471,7 +471,6 @@ static void getUserRouters(void* conn)
 
     ack_str = user_routers_info_to_json();
     http_reply(conn, 200, ack_str);
-
     cJSON_free((void*)ack_str);
 }
 
@@ -505,9 +504,6 @@ static void overallStatusMonitoring(void* conn)
         return ;        
     }
 
-    LOGD("___all.type: %s\n", all.type);
-    return;
-
     req.obj = OBJ_OVERALL;
     req.ch  = 0;
     req.prodChName[0] = 0;
@@ -655,14 +651,13 @@ static void channelStatusMonitoring(void* conn)
 #endif
 
     //转换json参数
-    memset(&ch,0,sizeof(_OverChnPwrRequest));
+    memset(&ch, 0, sizeof(ch));
+    
     if(json_to_chn_pwr_status_monitor(rx_body_buf,&ch)!=0)
     {
         http_reply(conn, 400, NULL);
         return ;        
     }
-    LOGD("___ch.type: %s\n", ch.type);
-    return;
     
     req.obj = OBJ_CHANNEL;
     req.ch  = ch.productChId;
@@ -1789,7 +1784,7 @@ static void communicationManagement(void *conn)
 
 /// @brief 服务管理
 /// @param stream 
-static void serviceManagement(HttpStream *stream)
+static void serviceManagement(void *conn)
 {
     __globalDeviceManage.view_page=-1;
     int ret = -1 ;
@@ -2613,12 +2608,12 @@ static void equipmentMintenance(void *conn)
         http_reply(conn, 400, NULL);
         return ;
     }
+
     //查询设备列表
     if(strcmp(_Over_equipment_mintenance.type,"listSbRestartQuery")==0)
     {
         int i,r;
         dev_list_t dl;
-
 #if 0
          r = cascade_get_devlist(&dl);
          if(r==0) {
@@ -2628,10 +2623,9 @@ static void equipmentMintenance(void *conn)
 #else
          strcpy(_over_back_sts_info.product_name, __globalDeviceManage._global_device_info.product_name);
          strcpy(_over_back_sts_info.product_number, __globalDeviceManage._global_device_info.product_number);
-         _over_back_sts_info.product_id = atoi(__globalDeviceManage._global_device_info.product_id);
+         _over_back_sts_info.product_id = __globalDeviceManage._global_device_info.product_id;
          strcpy(_over_back_sts_info.product_type, g_product_type_str[__globalDeviceManage._global_device_info.product_type]);
          strcpy(_over_back_sts_info.product_status, __globalDeviceManage._global_device_info.product_status);
-        
          ack_str = over_product_list_info_to_json(&_over_back_sts_info);
 #endif
 
@@ -2717,26 +2711,21 @@ static void equipmentMintenanceUpload(void *conn)
 static int webSetCallback(void)
 {
 	httpAddCallback("/login", loginFunc);//登录
-
     httpAddCallback("/logout", loginOutFunc);//登出
     httpAddCallback("/getInfo", getUserInfo);//获取用户信息
 	httpAddCallback("/pdu/changeLanguages", changeLanguages);//切换语言
-
     httpAddCallback("/pdu/systemConfiguration", systemConfiguration);//登录
     httpAddCallback("/getRouters", getUserRouters);//获取菜单接口
-
     httpAddCallback("/pdu/overallStatusMonitoring", overallStatusMonitoring);//设备电源监控信息
     httpAddCallback("/pdu/channelStatusMonitoring", channelStatusMonitoring);//设备通道电源监控信息
     httpAddCallback("/pdu/sensorStatusMonitoring", sensorStatusMonitoring);//传感器总体请求信息
     httpAddCallback("/pdu/alarmProtect", alarmProtect);//告警历史信息 
     httpAddCallback("/pdu/logInformation", logInformation);//日志
-
     httpAddCallback("/pdu/communicationManagement", communicationManagement);//通信设置
     httpAddCallback("/pdu/serviceManagement", serviceManagement);//服务管理
     httpAddCallback("/pdu/system", systemManagent);//用户管理
     httpAddCallback("/pdu/equipmentMintenance", equipmentMintenance);//设备重启 
     httpAddCallback("/pdu/equipmentMintenanceUpload", equipmentMintenanceUpload); //固件升级
-
 	
     return 0;
 }

+ 25 - 22
04-软件设计及源码/03-核心板/V1.0/05.src/smart_pdu/src/cascade.c

@@ -64,7 +64,7 @@ static int channel_close(dev_req_t *req);
 static int channel_save(dev_req_t *req);
 static int overall_request(dev_req_t *req, dev_data_t *data);
 
-static void info_to(_OverBackStsInfo *sts, GlobalDeviceInfo *dev);
+static void info_to(dev_info_t *info);
 static GlobalDeviceManager* get_dm(void);
 //////////////////////////////////////////////////////////////////////////////////
 static int overall_open(dev_req_t *req)
@@ -760,7 +760,7 @@ static int find_id_fn(handle_t l, node_t *node, node_t *xd, void *arg, int *act)
     slave_t *s1 = (slave_t*)node->buf;
     slave_t *s2 = (slave_t*)xd->buf;
     
-    if(s1->info.product_id==s2->info.product_id) {
+    if(s1->info.info.product_id==s2->info.info.product_id) {
         *act = LIST_ACT_STOP;
         return s2->addr;
     }
@@ -774,7 +774,7 @@ static int get_addr_by_id(cascade_handle_t *cas, int id)
         return 0;
     }
     else {
-        slave_t sl={0,0, {.product_id=id}};
+        slave_t sl={0,0, {.info.product_id=id}};
         node_t nod={0,&sl,sizeof(sl),sizeof(sl)};
 
         return xlist_iterator(cas->l, &nod, find_addr_fn, NULL);
@@ -885,10 +885,10 @@ static int slave_rceive(cascade_handle_t *cas)
         switch(h->reg) {
             case CASCADE_REG_INF:
             {
-                dev_info_t info={.version=VERSION, .bldtime=__DATE__};
+                dev_info_t dinf;
 
-                info.product_id = DFLT_PARAS.dev.product_id;
-                memcpy(map->tab_registers+h->reg, &info, sizeof(info));
+                info_to(&dinf);
+                memcpy(map->tab_registers+h->reg, &dinf, sizeof(dinf));
 
                 r = mbus_reply(cas, query, r, map);
             }
@@ -1019,41 +1019,44 @@ int cascade_reinit(void)
 }
 
 
-//get device list
-static void info_to(_OverBackStsInfo *sts, GlobalDeviceInfo *dev)
+static void info_to(dev_info_t *info)
 {
-    strcpy(sts->product_name, dev->product_name);
-    strcpy(sts->product_number, dev->product_number);
-    strcpy(sts->product_id, dev->product_id);
-    strcpy(sts->product_type, "xxx");
-    strcpy(sts->product_status, dev->product_status);
+    GlobalDeviceInfo *dev=get_dev();
+    _OverBackStsInfo *sta=&info->info;
+
+    strcpy(info->version, VERSION);
+    strcpy(info->bldtime, __DATE__);
+    strcpy(sta->product_name, dev->product_name);
+    strcpy(sta->product_number, dev->product_number);
+    strcpy(sta->product_id, dev->product_id);
+    strcpy(sta->product_type, "xxx");
+    strcpy(sta->product_status, dev->product_status);
 }
  static int devlist_fn(handle_t l, node_t *node, node_t *xd, void *arg, int *act)
 {
     slave_t *s=(slave_t*)xd->buf;
     dev_list_t *dl=(dev_list_t*)arg;
 
-    info_to(&dl->info[dl->cnt], &s->info);
-
+    dl->devi[dl->cnt++] = s->info;
     return 0;
 }
 int cascade_get_devlist(dev_list_t *dlist)
 {
     cascade_handle_t *cas=&casHandle;
-    _OverBackStsInfo *info;
+    dev_info_t *devi;
     int sz=xlist_size(cas->l);
 
     if(!dlist) {
         return -1;
     }
 
-    info = (_OverBackStsInfo*)malloc(sizeof(_OverBackStsInfo)*(sz+1));
-    if(!info){
+    devi = (dev_info_t*)malloc(sizeof(dev_info_t)*(sz+1));
+    if(!devi){
         return -1;
     }
-    info_to(&info[0], get_dev());
+    info_to(&devi[0]);
 
-    dlist->info = info;
+    dlist->devi = devi;
     dlist->cnt  = 1;
     xlist_iterator(cas->l, NULL, devlist_fn, dlist);
 
@@ -1065,7 +1068,7 @@ int cascade_free_devlist(dev_list_t *list)
         return -1;
     }
 
-    free(list->info);
+    free(list->devi);
     return 0;
 }
 
@@ -1075,7 +1078,7 @@ int cascade_request(dev_req_t *req, dev_data_t *data)
 {
     int r=-1,addr;
     cascade_handle_t *cas=&casHandle;
-
+return -1;
     if(!req || !data) {
         return -1;
     }

+ 0 - 9
04-软件设计及源码/03-核心板/V1.0/05.src/smart_pdu/src/cascade.h

@@ -55,15 +55,6 @@ enum {
 };
 
 #pragma pack (1)
-typedef struct {
-    
-}act_data_t;
-
-typedef struct {
-    char                    version[24];
-    char                    bldtime[24];
-    int                     product_id;
-}dev_info_t;
 
 typedef struct {
     _OverChnPwrAckInfo      ch;

+ 17 - 8
04-软件设计及源码/03-核心板/V1.0/05.src/smart_pdu/src/json_handle.c

@@ -711,8 +711,9 @@ int json_to_User_login_info(const char* str,_User_Log* _newUserLogin)
 /// @param _over_all_sts_ 
 /// @param  
 /// @return 
-int json_to_User_loginOut_info(const char* str,char* _UserLoginOutToken)
+int json_to_User_loginOut_info(const char* str,char** _UserLoginOutToken)
 {
+    char *p=NULL;
     cJSON* cjson = NULL;
     cjson = cJSON_Parse(str);
     if(cjson==NULL)
@@ -722,8 +723,16 @@ int json_to_User_loginOut_info(const char* str,char* _UserLoginOutToken)
     }
 
     cJSON *cjson_token= cJSON_GetObjectItem(cjson, "token");
-    if (cjson_token != NULL)
-    _UserLoginOutToken = cjson_token->valuestring;
+    if (cjson_token != NULL && _UserLoginOutToken!=NULL) {
+        int len=strlen(cjson_token->valuestring);
+        p = (char*)malloc(len+2);
+        if(p) {
+            strcpy(p, cjson_token->valuestring);
+        }
+        *_UserLoginOutToken = p;
+    }
+    cJSON_Delete(cjson);
+
     return 0 ;
 }
 
@@ -757,7 +766,7 @@ int json_to_overall_status_monitor(const char* str,_Over_All_Sts_Monitor* _over_
 
     cJSON *cjson_product_id = cJSON_GetObjectItem(cjson, "productId");
     if (cjson_product_id != NULL)
-        strcpy(_over_all_sts_monitor->product_id, cjson_product_id->valuestring);
+        _over_all_sts_monitor->product_id = cjson_product_id->valueint;
 
     cJSON *cjson_productNumber = cJSON_GetObjectItem(cjson, "productNumber");
     if (cjson_productNumber != NULL)
@@ -987,13 +996,13 @@ char* over_product_list_info_to_json2(dev_list_t *dl)
     for(i=0; i<dl->cnt; i++) {
         cJSON* data_filed = cJSON_CreateObject();
         if(data_filed) {
-            cJSON_AddStringToObject(data_filed,"productName",dl->info[i].product_name);
-            cJSON_AddNumberToObject(data_filed,"productId",dl->info[i].product_id);
+            cJSON_AddStringToObject(data_filed,"productName",dl->devi[i].info.product_name);
+            cJSON_AddNumberToObject(data_filed,"productId",dl->devi[i].info.product_id);
 
             // sprintf(_over_back_sts_info->product_number,"cccc");
-            cJSON_AddStringToObject(data_filed,"productNumber",dl->info[i].product_number);
+            cJSON_AddStringToObject(data_filed,"productNumber",dl->devi[i].info.product_number);
             // sprintf(strcc,"typeinfo");
-            cJSON_AddStringToObject(data_filed,"productType",dl->info[i].product_type);
+            cJSON_AddStringToObject(data_filed,"productType",dl->devi[i].info.product_type);
 
             cJSON_AddStringToObject(data_filed,"productStatus", "online");
             cJSON_AddItemToObject(data_root_array, "data", data_filed);

+ 10 - 4
04-软件设计及源码/03-核心板/V1.0/05.src/smart_pdu/src/json_handle.h

@@ -45,7 +45,7 @@ typedef struct
     char*  user_token;
     char   type[32];       //listInfoQuery listQuery open close listHisQuery
     char   product_name[PROD_NAME_LEN];
-    char   product_id[PROD_ID_LEN];
+    int    product_id;
     char   product_number[PROD_NUM_LEN];
     char   start_time[24];
     char   end_time[24];
@@ -444,11 +444,17 @@ typedef struct
     int     roleId;
     char*   roleName;
     char*   password;
-    int   userIds;
+    int     userIds;
 }_UserRoleManageInfo;
 
 typedef struct {
-    _OverBackStsInfo *info;
+    char     version[24];
+    char     bldtime[24];
+    _OverBackStsInfo info;
+}dev_info_t;
+
+typedef struct {
+    dev_info_t *devi;
     int cnt;
 }dev_list_t;
 
@@ -458,7 +464,7 @@ char* ctrl_sts_ack_to_json(void);
 
 void get_rand_str(char* s,int num);
 int json_to_User_login_info(const char* str,_User_Log* _newUserLogin);
-int json_to_User_loginOut_info(const char* str,char* _UserLoginOutToken);
+int json_to_User_loginOut_info(const char* str,char** _UserLoginOutToken);
 char* log_info_to_json(const char* token);
 char* log_LoginFailedinfo_to_json();