ソースを参照

1、更新web到9.28版本
2、适配阿里云mqtt
3、整理文件导入/出接口

guohui 2 年 前
親
コミット
eb945c78ec
共有13 個のファイルを変更した、340 個の追加 と 152 個の削除を含む
  1. 0 1
      output/push/push.bat
  2. 0 43
      output/push/push2.bat
  3. 4 4
      pro/config/cfg.h
  4. 196 87
      pro/src/appweb_handle.c
  5. 13 4
      pro/src/common.h
  6. 25 1
      pro/src/dflt.c
  7. 3 3
      pro/src/json_handle.c
  8. 1 1
      pro/src/json_handle.h
  9. 1 1
      pro/src/language_common.c
  10. 57 0
      pro/src/mqtt.c
  11. 1 0
      pro/src/mqtt.h
  12. 33 1
      pro/src/sqlite_handle.c
  13. 6 6
      pub

+ 0 - 1
output/push/push.bat

@@ -10,7 +10,6 @@ SET  OUTDIR=%CURDIR%
 SET  DEVDIR=/root
 
 SET PSCP=%CURDIR%\tools\pscp 
-SET PUTTY=%CURDIR%\tools\putty
 SET PLINK=%CURDIR%\tools\plink
 
 SET USR=root

+ 0 - 43
output/push/push2.bat

@@ -1,43 +0,0 @@
-@ECHO OFF
-
-SET TARGET=pdutar
-SET IP1=192.168.1.132
-SET IP2=192.168.1.188
-
-SET CURDIR=%~dp0
-SET CURDIR=%CURDIR:~0,-1%
-
-SET  USRDIR=%CURDIR%\user
-SET  TMPDIR=data
-SET  DEVDIR=/root
-
-SET PSCP=%CURDIR%\tools\pscp 
-SET PLINK=%CURDIR%\tools\plink
-
-SET ERR=0
-SET USR=root
-SET FBAT=%CURDIR%\tools\script.sh
-SET PWD=123456
-
-::copy files
-MKDIR /Y %TMPDIR%
-DEL /Y %TMPDIR%\*
-COPY /Y %TARGET% %TMPDIR%
-COPY /Y %USRDIR%\*  %DATADIR%
-
-for %ip in (a,b,c) do (
-::send files
-ECHO send %TARGET% to device ...
-ECHO  y  | %PSCP% -r %DATADIR% %USR%@%IP%:%DEVDIR%
-IF %ERRORLEVEL% EQU 0 (
-    ECHO pull finished!) 
-ELSE (
-    ECHO pull failed!)
-
-ECHO release %TARGET% now ...
-::ECHO  y  | %PLINK%  -ssh -t  -pw %PWD% %USR%@%IP% -m %FBAT%
-IF %ERRORLEVEL% EQU 0 (
-    ECHO exec bash ok!) 
-ELSE (
-    ECHO exec bash failed!)
-)

+ 4 - 4
pro/config/cfg.h

@@ -20,7 +20,7 @@
 //#define PRJ_INSPUR_DC_I_DC_O
 //#define PRJ_ANDERSON_AC_I3_O3
 //#define PRJ_HYPERTEC_AC_I3_O1
-//#define PRJ_SG24016
+//#define PRJ_SG_I3_O3
 #define PRJ_TEST
 
 
@@ -175,7 +175,7 @@
     #define SMTP_SEND_BUILTIN
 
     #define PROD_POWER_TYPE                     1
-#elif defined PRJ_SG24016
+#elif defined PRJ_SG_I3_O3
     #define LANGUAGE                            0           //english
     #define SMPLE_TIME                          30          //ms
     #define SAVE_TIME                           60000       //ms
@@ -188,7 +188,7 @@
     #define USE_SMTP
     #define SMTP_SEND_BUILTIN
 
-    #define PROD_POWER_TYPE                     0
+    #define PROD_POWER_TYPE                     3
 #elif defined PRJ_TEST
     #define LANGUAGE                            0           //chinese
     #define SMPLE_TIME                          30          //ms
@@ -202,7 +202,7 @@
     #define USE_SMTP
     #define SMTP_SEND_BUILTIN
 
-    #define USE_MQTT
+    //#define USE_MQTT
     #define MQTT_SERVER_BUILTIN
 
     #define PROD_POWER_TYPE                     5

+ 196 - 87
pro/src/appweb_handle.c

@@ -18,6 +18,30 @@
 
 #define TOTAL_COUNT 60
 #define FN_MAX  30
+
+enum {
+    FILE_IMPORT=0,
+    FILE_EXPORT,
+};
+enum {
+    FILE_SYS_CFG=0,
+    FILE_SERV_CFG,
+    FILE_ALARM_CFG,
+    FILE_SENDOR_CFG,
+
+    FILE_POWER_ALL,
+    FILE_POWER_CHN,
+    
+    FILE_LOG_RUN,
+    FILE_LOG_OPERA,
+    FILE_LOG_ALARM,
+
+    FILE_LOGO,
+    FILE_HOST_FW,
+    FILE_POWER_FW,
+};
+
+
 typedef void (*http_fn_t)(void *arg);
 
 typedef struct {
@@ -95,14 +119,13 @@ static int upload_file(void *conn, char *path)
 
     return r;
 }
-static int download_file(void *conn, char *path, int remove)
+static int download_file(void *conn, char *path)
 {
     mg_stream_t *s=(mg_stream_t*)conn;
     struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
 
     struct mg_http_serve_opts opts = {.root_dir = NULL};
     mg_http_serve_file(s->c, hm, path, &opts);
-    if(remove) file_remove(path);
 
     return 0;
 }
@@ -125,11 +148,11 @@ static void httpAddCallback(char *uri, http_fn_t f)
         h->cnt++;
     }
 }
-static int save_to_csv(char *path, status_data_t *data, int flag)
+static int power_to_csv(char *path, status_data_t *data, int ftype)
 {
     int i=0;
     FILE *fp=NULL;
-    _OverAllPwrAckInfo *info=(flag==0)?&data->all:&data->chn;
+    _OverAllPwrAckInfo *info=(ftype==FILE_POWER_ALL)?&data->all:&data->chn;
     
     fp = fopen(path, "wt");
     if(!fp) {
@@ -175,88 +198,177 @@ static int save_to_csv(char *path, status_data_t *data, int flag)
     fclose(fp);
     return 0;
 }
-static int export_power(void *conn, int flag)
+static int file_io(void *conn, int ftype, int io)
 {
     int r;
     char path[200];
     web_handle_t *wh=&webHandle;
-
-    sprintf(path, "%s.csv", (flag==0)?"overall":"channel");
-    r = save_to_csv(path, &wh->stt, flag);
-    if(r==0) {
-        download_file(conn, path, 1);
-    }
-
-    return r;
-}
-
-static int import_misc(void *conn, int flag)
-{
-    char path[200];
-    web_handle_t *wh=&webHandle;
     mg_stream_t *s=(mg_stream_t*)conn;
     struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
+return -1;
+    switch(ftype) {
+        case FILE_SYS_CFG:
+        {
+            if(io==FILE_IMPORT) {
+                sys_get_path(path, "tmp.ini");
+                r = upload_file(conn, path);
+                if(r==0) {
+                    r = paras_check(path);
+                    if(r==0) {
+                        r = paras_load(path);
+                        if(r==0) {
+                            //clear some database table
+                            //exit(0); //restart smartPDU
+                        }
+                    }
+                }
+                file_remove(path);
+            }
+            else {
+                sys_get_path(path, INI_FILE_NAME);
+                download_file(conn, path);
+            }
+        }
+        break;
 
-    switch(flag) {
-        case 0:     //sensor
+        case FILE_SERV_CFG:
         {
-            //upload_file(path);
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                //download_file(path);
+            }
         }
         break;
 
-        case 1:     //alarm
+        case FILE_ALARM_CFG:
         {
-            //upload_file(path);
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                //download_file(path);
+            }
         }
         break;
 
-        case 2:     //service
+        case FILE_SENDOR_CFG:
         {
-            //upload_file(path);
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                //download_file(path);
+            }
         }
         break;
 
-        case 3:     //config
+        case FILE_POWER_ALL:
         {
-            //upload_file(path);
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                sprintf(path, "%s.csv", "overall");
+                r = power_to_csv(path, &wh->stt, ftype);
+                if(r==0) {
+                    download_file(conn, path);
+                    file_remove(path);
+                }
+            }
         }
         break;
-    }
 
-    return 0;
-}
+        case FILE_POWER_CHN:
+        {
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                sprintf(path, "%s.csv", "channel");
+                r = power_to_csv(path, &wh->stt, ftype);
+                if(r==0) {
+                    download_file(conn, path);
+                    file_remove(path);
+                }
+            }
+        }
+        break;
+        
+        case FILE_LOG_RUN:
+        {
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                //download_file(path);
+            }
+        }
+        break;
 
-static int export_misc(void *conn, int flag)
-{
-    char path[200];
-    web_handle_t *wh=&webHandle;
-    mg_stream_t *s=(mg_stream_t*)conn;
-    struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
+        case FILE_LOG_OPERA:
+        {
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                //download_file(path);
+            }
+        }
+        break;
 
-    switch(flag) {
-        case 0:     //sensor
+        case FILE_LOG_ALARM:
         {
-            //download_file(path);
+            if(io==FILE_IMPORT) {
+                //upload_file(path);
+            }
+            else {
+                //download_file(path);
+            }
         }
         break;
 
-        case 1:     //alarm
+        case FILE_LOGO:
         {
-            //download_file(path);
+            if(io==FILE_IMPORT) {
+                char tmp[100];
+                sprintf(tmp, "%s/%s", IMAGE_FOLDER, LOGO_FILE);
+                sys_get_path(path, tmp);
+                upload_file(conn, path);
+            }
         }
         break;
 
-        case 2:     //service
+        case FILE_HOST_FW:
         {
-            //download_file(path);
+            if(io==FILE_IMPORT) {
+                sprintf(path, "%s/%s", DOWN_FOLDER, UPG_PKG_NAME);
+                r = upload_file(conn, path);
+                if(r==0) {
+                    printf("_____ upg_start\n");
+                    upg_start();
+                }
+            }
         }
         break;
 
-        case 3:     //config
+        case FILE_POWER_FW:
         {
-            //download_file(path);
+            if(io==FILE_IMPORT) {
+                sprintf(path, "%s/%s", DOWN_FOLDER, "power.bin");
+                r = upload_file(conn, path);
+                if(r==0) {
+                    printf("_____ power upgrade now ...\n");
+                    //power_upgrade(path);
+                    //file_remove(path);
+                }
+            }
         }
         break;
+
+        default:
+        return -1;
     }
 
     return 0;
@@ -536,7 +648,7 @@ static void overallStatusMonitoring(void* conn)
     if(cjson==NULL)
     {
         if (strstr(hm->uri.buf,"type=export")) {
-            export_power(conn, 0);
+            file_io(conn, FILE_POWER_ALL, FILE_EXPORT);
 
         }
         else {
@@ -1139,7 +1251,7 @@ static void channelStatusMonitoring(void* conn)
     if(cjson==NULL)
     {
         if (strstr(hm->uri.buf,"type=export")) {
-            export_power(conn, 1);
+            file_io(conn, FILE_POWER_CHN, FILE_EXPORT);
         }
         return;     
     }
@@ -3293,7 +3405,7 @@ static void logInformation(void *conn)
         INIT_LIST_HEAD(&_alarm_ack_info.list);
 
 
-        if(__logInformationRequestInfo.beginTime==NULL || __logInformationRequestInfo.endtime==NULL)
+        if(__logInformationRequestInfo.startTime==NULL || __logInformationRequestInfo.endtime==NULL)
         {
             struct tm* t ;
             struct timeval tv;
@@ -3334,7 +3446,7 @@ static void logInformation(void *conn)
             dev_search_alarm_info(__globalDeviceManage.db,
                             __globalDeviceManage._globalDevInfo.product.id,
                             0,     //注意注意 此处需要查询的参数是0 1 2
-                            __logInformationRequestInfo.beginTime,//启动时间
+                            __logInformationRequestInfo.startTime,//开始时间
                             __logInformationRequestInfo.endtime,  //结束时间
                             __logInformationRequestInfo.pagenum-1,  //页
                             __logInformationRequestInfo.pagesize, //条
@@ -3354,17 +3466,14 @@ static void logInformation(void *conn)
         //转换参数
         //ack_str = alarm_type_info_to_json(&_alarm_ack_info);            
     }
-    else if(strcmp(__logInformationRequestInfo.type,"exportJgrz")==0) //导出告警日志
-    {
-
-    }   
+      
     else if(strcmp(__logInformationRequestInfo.type,"listCzrzQuery")==0) //操作日志
     {
         //初始化表
         INIT_LIST_HEAD(&_alarm_ack_info.list);
 
         //默认查当天日志
-        if(__logInformationRequestInfo.beginTime==NULL || __logInformationRequestInfo.endtime==NULL)
+        if(__logInformationRequestInfo.startTime==NULL || __logInformationRequestInfo.endtime==NULL)
         {
            struct tm* t ;
             struct timeval tv;
@@ -3393,7 +3502,7 @@ static void logInformation(void *conn)
             dev_search_alarm_info(__globalDeviceManage.db,
                                 __globalDeviceManage._globalDevInfo.product.id,
                                 ALARM_TYPE_OPRATION,// alarm_type,        操作日志
-                                __logInformationRequestInfo.beginTime,
+                                __logInformationRequestInfo.startTime,
                                 __logInformationRequestInfo.endtime,
                                 __logInformationRequestInfo.pagenum-1,
                                 __logInformationRequestInfo.pagesize,
@@ -3411,16 +3520,12 @@ static void logInformation(void *conn)
             free(node);
         } 
     }  
-    else if(strcmp(__logInformationRequestInfo.type,"exportCzrz")==0) //导出操作日志
-    {
-
-    }    
     else if(strcmp(__logInformationRequestInfo.type,"listYxrzQuery")==0) //运行日志
     {
                 //初始化表
         INIT_LIST_HEAD(&_alarm_ack_info.list);
                 //默认查当天日志
-        if(__logInformationRequestInfo.beginTime==NULL || __logInformationRequestInfo.endtime==NULL)
+        if(__logInformationRequestInfo.startTime==NULL || __logInformationRequestInfo.endtime==NULL)
         {
             struct tm *t;
             struct timeval tv;
@@ -3449,7 +3554,7 @@ static void logInformation(void *conn)
             dev_search_alarm_info(__globalDeviceManage.db,
                                   __globalDeviceManage._globalDevInfo.product.id,
                                   ALARM_TYPE_RUNNING, // alarm_type,        运行日志
-                                __logInformationRequestInfo.beginTime,
+                                __logInformationRequestInfo.startTime,
                                 __logInformationRequestInfo.endtime,
                                   __logInformationRequestInfo.pagenum - 1,
                                   __logInformationRequestInfo.pagesize,
@@ -3466,10 +3571,18 @@ static void logInformation(void *conn)
             free(node);
         } 
     }    
-    else if(strcmp(__logInformationRequestInfo.type,"exportYxrz")==0) //导出运行日志        导出方式->
+    else if(strcmp(__logInformationRequestInfo.type,"exportCzrz")==0) //导出操作日志
+    {
+
+    }
+    else if(strcmp(__logInformationRequestInfo.type,"exportYxrz")==0) //导出运行日志
     {
 
-    }       
+    }
+    else if(strcmp(__logInformationRequestInfo.type,"exportJgrz")==0) //导出告警日志
+    {
+        //
+    }
     
     cJSON_Delete(cjson);
     http_reply(conn, 200, ack_str);
@@ -3667,6 +3780,7 @@ static void serviceManagement(void *conn)
             dev_smtp_update_recv(gdm->db, &recv[i]);
         }
     }
+#ifdef USE_MQTT
     else if(strcmp(_serviceManageRequestInfo.type,"listMqttQuery")==0)
     {
         ack_str = service_mqtt_ack_to_json(&gdm->mqttInfo);
@@ -3700,6 +3814,7 @@ static void serviceManagement(void *conn)
             dev_mqtt_update_ser(gdm->db, ser);
         }
     }
+#endif
     else if(strcmp(_serviceManageRequestInfo.type,"listSnmpQuery")==0)
     {
         // 查询SNMP信息
@@ -5321,23 +5436,19 @@ static void equipmentMintenance(void *conn)
 static void equipmentMintenanceUpload(void *conn)
 {
     int r = -1 ;
-    char* ack_str = NULL ;
+    char* ack_str=NULL ;
     mg_stream_t *s=(mg_stream_t*)conn;
     struct mg_http_message *hm=s->ev_data;
     char path[200],tmp[60];
     
     if(strstr(hm->uri.buf, "uploadType=gjsj")) {        //firmware upload
-        sprintf(path, "%s/%s", DOWN_FOLDER, UPG_PKG_NAME);
-        r = upload_file(conn, path);
-        if(r==0) {
-            printf("_____ upg_start\n");
-            upg_start();
-        }
+        file_io(conn, FILE_HOST_FW, FILE_IMPORT);
     }
     else if(strstr(hm->uri.buf, "uploadType=shfw")) {   //logo upload
-        sprintf(tmp, "%s/%s", IMAGE_PATH, LOGO_FILE);
-        sys_get_path(path, tmp);
-        upload_file(conn, path);
+        file_io(conn, FILE_LOGO, FILE_IMPORT);
+    }
+    else if(strstr(hm->uri.buf, "uploadType=2")) {   //sensor config
+        //file_io(conn, FILE_SENDOR_CFG, FILE_IMPORT);
     }
 
     ack_str = ctrl_sts_ack_to_json();
@@ -5348,35 +5459,33 @@ static void equipmentMintenanceUpload(void *conn)
 static void equipmentMintenanceExport(void *conn)
 {
     int r = -1 ;
-    char* ack_str = NULL ;
+    char* ack_str=NULL ;
     mg_stream_t *s=(mg_stream_t*)conn;
     struct mg_http_message *hm=s->ev_data;
-    char *rx_body_buf = (char*)hm->body.buf;
-    char path[200];
     
-    if(strstr(hm->uri.buf, "export=0")) {
-        export_misc(conn, 0);
+    if(strstr(hm->uri.buf, "export=2")) {
+        file_io(conn, FILE_SENDOR_CFG, FILE_EXPORT);
     }
     else if(strstr(hm->uri.buf, "export=1")) {
-        export_misc(conn, 1);
+        file_io(conn, FILE_ALARM_CFG, FILE_EXPORT);
     }
     else if(strstr(hm->uri.buf, "export=2")) {
-        export_misc(conn, 2);
+        file_io(conn, FILE_SERV_CFG, FILE_EXPORT);
     }
     else if(strstr(hm->uri.buf, "export=3")) {
-        export_misc(conn, 3);
+        file_io(conn, FILE_SYS_CFG, FILE_EXPORT);
     }
-    else if(strstr(hm->uri.buf, "uploadType=0")) {
-        import_misc(conn, 0);
+    else if(strstr(hm->uri.buf, "uploadType=7")) {
+        file_io(conn, FILE_SENDOR_CFG, FILE_IMPORT);
     }
     else if(strstr(hm->uri.buf, "uploadType=1")) {
-        import_misc(conn, 1);
+        file_io(conn, FILE_ALARM_CFG, FILE_IMPORT);
     }
     else if(strstr(hm->uri.buf, "uploadType=2")) {
-        import_misc(conn, 2);
+        file_io(conn, FILE_SERV_CFG, FILE_IMPORT);
     }
     else if(strstr(hm->uri.buf, "uploadType=3")) {
-        import_misc(conn, 3);
+        file_io(conn, FILE_SYS_CFG, FILE_IMPORT);
     }
 }
 

+ 13 - 4
pro/src/common.h

@@ -53,7 +53,7 @@
 
 
 
-#define IMAGE_PATH          "image"
+#define IMAGE_FOLDER        "image"
 #define LOGO_FILE           "logo.png"
 #define QRCODE_FILE         "qrcode.png"
 #define CERT_FILE           "ca.cert"
@@ -661,16 +661,25 @@ typedef struct
     smtp_recv_t         recv[SMTP_RECV_MAX];      //接收账号列表
 }smtp_info_t;
 
+enum {
+    MQTT_EMQX=0,
+    MQTT_ALIYUN,
+    
+    MQTT_MAX
+};
+
+
 typedef struct {
     int                 id;    		                    //id
+    int                 type;                           //0: emqx   1: aliyun
     int                 mode;    				        //0: open   1: close
     char                proto[16];                      //mqtt, mqtts, ws, wss
     char                name[32];                       //server name
     char                server[512]; 		            //server ip
     char                port[10]; 			            //server port
-    char                cid[32];    		            //client ID
-    char                user[32];    			        //认证方式  
-    char                password[32];
+    char                cid[64];    		            //client ID
+    char                user[64];    			        //
+    char                password[64];
     char                cert[8192];
     int                 status;
 }mqtt_server_t;

+ 25 - 1
pro/src/dflt.c

@@ -1,4 +1,5 @@
 #include "common.h"
+#include "mqtt.h"
 #include "cfg.h"
 
 
@@ -59,6 +60,7 @@ smtp_send_t DFLT_SMTP_SEND={
 mqtt_info_t DFLT_MQTT={
     .ser[0] = {
         .id = 0,
+        .type = MQTT_EMQX,
         .mode = 0,
         .cid = "",
         .proto = "mqtts",
@@ -91,9 +93,31 @@ mqtt_info_t DFLT_MQTT={
         .password = "gowone100",
     },
 
-    .ser[1]={.id=-1},
+    .ser[1]={
+        .id = 1,
+        .type = MQTT_ALIYUN,
+        .mode = 1,
+        .cid = "",
+        .proto = "mqtts",
+        .name  = "server2",
+        .server = "post-cn-0w73xnchz01.mqtt.aliyuncs.com",
+        .port = "1883",
+        .cert = "",
+    },
     .ser[2]={.id=-1},
     .ser[3]={.id=-1},
     .ser[4]={.id=-1},
 };
 
+
+/*
+
+阿里云mqtt云消息队列:
+username:gowone100@1388027240948136.onaliyun.com
+password:TdlZk$0AE9CMeskIRqrr1qQECl0l}$B#
+
+AccessKey ID:LTAI5tAfuRj1JkB8ZjDS2p3i
+AccessKey Secret:p4FrWlrFim9zM9A5mYxjK99EqKrSHh
+
+*/
+

+ 3 - 3
pro/src/json_handle.c

@@ -103,7 +103,7 @@ static int image_to_base64(char *path, buf_t *buf)
 static int get_base64(buf_t *logo, buf_t *qrcode)
 {
     char path[200],temp[200];
-    sys_get_path(path, IMAGE_PATH);
+    sys_get_path(path, IMAGE_FOLDER);
 
     if(logo) {
         sprintf(temp, "%s/%s", path, LOGO_FILE);
@@ -4296,9 +4296,9 @@ cJSON* json_to_loginformation_manage(const char* str,_LogInformationRequestInfo*
     cJSON* cjson_params = cJSON_GetObjectItem(cjson,"params");
     // if(cjson_params!=NULL)
     // {
-        cJSON* cjson_begin_time = cJSON_GetObjectItem(cjson_params,"beginTime");
+        cJSON* cjson_begin_time = cJSON_GetObjectItem(cjson_params,"startTime");
         if(cjson_begin_time!=NULL)
-            _logInformationRequestInfo->beginTime = cjson_begin_time->valuestring ;  
+            _logInformationRequestInfo->startTime = cjson_begin_time->valuestring ;  
 
         cJSON* cjson_end_time = cJSON_GetObjectItem(cjson_params,"endTime");
         if(cjson_end_time!=NULL)

+ 1 - 1
pro/src/json_handle.h

@@ -489,7 +489,7 @@ typedef struct
     char* user_token;
     char* type;
     char* alarmType;
-    char* beginTime;
+    char* startTime;
     char* endtime;
     int pagenum;
     int pagesize;

+ 1 - 1
pro/src/language_common.c

@@ -646,7 +646,7 @@ const char* language_sensor_name[LANGUAGE_TYPE][8] =
         "烟雾传感器",
         "水浸传感器",
         "门禁传感器",
-        "燃气传感器",
+        "气体传感器",
         "气压传感器",
         "空调传感器",
         "温度传感器",

+ 57 - 0
pro/src/mqtt.c

@@ -116,6 +116,53 @@ static int send_stat(mqtt_conn_t *conn, int type);
 static int get_serv(char *json);
 static void* client_thread(void *arg);
 /////////////////////////////////////////////////////////
+
+typedef struct {
+    char user[64];
+    char passwd[64];
+}user_account_t;
+typedef struct {
+    char *instanceId;
+    char *host;
+    char *topic;
+    char *groupId;
+    char *clientId;
+
+    char *accessKey;
+    char *secretKey;
+    uint16_t port;
+}mqtt_account_t;
+static mqtt_account_t mqtt_aliyun={
+    "post-cn-0w73xnchz01",
+    "post-cn-0w73xnchz01.mqtt.aliyuncs.com",
+    "SmartPDU",
+    "GID_PDU",
+    "smartPDU_23542352",
+
+    "LTAI5tAfuRj1JkB8ZjDS2p3i",
+    "p4FrWlrFim9zM9A5mYxjK99EqKrSHh",
+    8883,
+};
+static int get_account(mqtt_account_t *host, user_account_t *user)
+{
+    unsigned int len=0;
+    char tempData[100];
+    char clientIdUrl[64];
+
+    //username和 Password 签名模式下的设置方法,参考文档 https://help.aliyun.com/document_detail/48271.html?spm=a2c4g.11186623.6.553.217831c3BSFry7
+    sprintf(clientIdUrl, "%s@@@%s", host->groupId, host->clientId);
+    HMAC(EVP_sha1(), host->secretKey, strlen(host->secretKey), (const unsigned char*)clientIdUrl, strlen(clientIdUrl), (unsigned char*)tempData, &len);
+
+    int passwdLen = EVP_EncodeBlock((unsigned char *) user->passwd, (const unsigned char*)tempData, len);
+    user->passwd[passwdLen] = '\0';
+    
+    sprintf(user->user,"Signature|%s|%s", host->accessKey, host->instanceId);
+
+    return 0;
+}
+
+
+
 static void set_status(mqtt_conn_t *conn, int flag)
 {
     mqtt_handle_t *h=(mqtt_handle_t*)conn->h;
@@ -311,6 +358,16 @@ static int conn_one(mqtt_conn_t *conn)
 
     if(!conn->c) {
         char url[1024];
+
+        if(conn->ser.type==MQTT_ALIYUN) {
+            user_account_t user;
+
+            mqtt_aliyun.clientId = conn->ser.cid;
+            get_account(&mqtt_aliyun, &user);
+            strcpy(conn->ser.user, user.user);
+            strcpy(conn->ser.password, user.passwd);
+        }
+
         mg_opts_t opts={
             .clean = true,
             .qos = 1,

+ 1 - 0
pro/src/mqtt.h

@@ -3,6 +3,7 @@
 
 #include <stdint.h>
 
+
 enum {
     MQTT_SUB_CMD_POWER_ALL=0,
     MQTT_SUB_CMD_POWER_CHN,

+ 33 - 1
pro/src/sqlite_handle.c

@@ -46,6 +46,27 @@ static int get_count(sqlite3 *db, char *table)
 
     return count;
 }
+static int get_count_ex(sqlite3 *db, char *sql)
+{
+    int r;
+    sqlite3_stmt *stmt=NULL;
+    
+    r = sqlite3_prepare_v2(db, sql, -1, &stmt, 0);
+    if (r != SQLITE_OK) {
+        log_e("Failed to prepare statement: %s\n", sqlite3_errmsg(db));
+        return -1;
+    }
+ 
+    int count = 0;
+    while (sqlite3_step(stmt) == SQLITE_ROW) {
+        count++;
+    }
+    sqlite3_finalize(stmt);
+
+    return count;
+}
+
+
 static int get_key(sqlite3 *db, char *table, char *key, int mm)
 {
     int r,id=-1;
@@ -2762,7 +2783,8 @@ int dev_search_alarm_info(sqlite3* db,
     char** pResult = NULL;  //用来指向sql执行结果的指针
     char* err_msg=NULL;
     char select_sql[1024] = {0};
-    
+
+
     //查询告警总数
     if (alarm_type<0)//小于0加载所有的
     {
@@ -2770,6 +2792,8 @@ int dev_search_alarm_info(sqlite3* db,
     }else{
         snprintf(select_sql,sizeof(select_sql),"SELECT count (*) FROM Table_AlarmManage where (alarmType=%d) and (alarmDate BETWEEN '%s' AND '%s');",alarm_type,start_time,end_time);
     }
+
+#if 1
     res = sqlite3_get_table(db, select_sql, &pResult, &nrow, &ncolumn, &err_msg);
     if(res != SQLITE_OK)
     {
@@ -2783,6 +2807,14 @@ int dev_search_alarm_info(sqlite3* db,
         return -1 ;
     }
     *nAlarmSum = atoi(pResult[1]);
+#else
+    int cnt - get_count_ex(0;)
+	if(cnt<0) {
+        return -1;
+    }
+    *nAlarmSum = cnt;
+#endif
+    
     if (!start_time||!start_time)
     {
         sprintf(select_sql, "SELECT* FROM Table_AlarmManage WHERE (product_id=%d) AND (alarmType=%d) order by alarmNumber LIMIT %d OFFSET %d;",

+ 6 - 6
pub

@@ -15,8 +15,8 @@ PRJS="PRJ_ITK_AC_I1_O1"
 #PRJS="PRJ_RELEASE_AC_I3_O1"
 #PRJS="PRJ_RELEASE_AC_I3_O3"
 #PRJS="PRJ_STSC_I3_O3"
-#PRJS="PRJ_SG24016"
-#PRJS="PRJ_TEST"
+#PRJS="PRJ_SG_I3_O3"
+PRJS="PRJ_TEST"
 
 #PRJS="PRJ_USASL_AC_I3_O1 PRJ_USASL_AC_I3_O3"
 #PRJS="PRJ_XIAN_AC_I1_O1_P4 PRJ_XIAN_AC_I1_O1_P8"
@@ -107,15 +107,15 @@ function do_copy()
     elif [ "$1" = "PRJ_INSPUR_DC_I_DC_O" ]; then
         name=dc_in1_out1_inspur
         cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png
-    elif [ "$1" = "PRJ_TEST" ]; then
-        name=ac_in3_out1_test
-        cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png
     elif [ "$1" = "PRJ_STSC_I3_O3" ]; then
         name=ac_in3_out3_stsc
         cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png
-    elif [ "$1" = "PRJ_SG24016" ]; then
+    elif [ "$1" = "PRJ_SG_I3_O3" ]; then
         name=ac_in2_out1_sg24016
     	cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png
+    elif [ "$1" = "PRJ_TEST" ]; then
+        name=ac_in3_out1_test
+        cp -f $custdir/logo/logo_neuter.png $curdir/output/t113i/root/run/app/image/logo.png
     else
         echo error! $RPJ not define!!!
         exit 1