Ver código fonte

1、修改数据结构
2、改数据库数据类型(blob和bool改为int)
3、解决用户编辑操作崩溃问题

guohui 1 ano atrás
pai
commit
44f4ce10ce

BIN
cust_data/db/pdu_dat.db


BIN
cust_data/db/pdu_dat_itk.db


BIN
output/t113i/root/run/app/Qt_Test


+ 1 - 14
pro/src/appweb_handle.c

@@ -212,10 +212,6 @@ static int get_range(time_t *from, time_t *to, char *start, char *end, int max_d
     
     return 0;
 }
-
-
-
-
 static int power_export(char *path, char *start, char *end)
 {
     int r,type=0;
@@ -269,7 +265,7 @@ static int file_io(void *conn, int ftype, int io, char *buf)
         }
         break;
 
-#if 0
+#ifdef CONFIG_XPORT
         case FILE_SERV_CFG:
         {
             sprintf(path, "/tmp/service.ini");
@@ -5050,11 +5046,6 @@ static void systemManagent(void *conn)
 
                 dev_insert_user_info(__globalDeviceManage.db, new_user);
 
-                free(new_user->userName);
-                free(new_user->userPW);
-                free(new_user->nickName);
-                free(new_user->createTime);
-
                 char temp[100];
                 // sprintf(temp, "$添加$|$用户$|%s", _UserRoleManageRequestInfo.userName);
                 sprintf(temp, "Add user %s", _UserRoleManageRequestInfo.userName);
@@ -5097,10 +5088,6 @@ static void systemManagent(void *conn)
 
         dev_update_user_info(__globalDeviceManage.db, new_user);
 
-        free(new_user->userName);
-        free(new_user->userPW);
-        free(new_user->nickName);
-        free(new_user->createTime);
         free(new_user);
         char temp[100];
         //sprintf(temp, "$修改$|$用户$|%s", _UserRoleManageRequestInfo.userName);

+ 2 - 2
pro/src/common.c

@@ -493,12 +493,12 @@ int set_time_zone(struct tm *t, int zone)
         log_e("__1__ set_zone failed\n");
     }
 
-    print_time("111", t);
+    //print_time("111", t);
     r = set_time(t, zone);
     if(r) {
         log_e("__1__ set_time failed\n");
     }
-    print_utc("222", time(NULL));
+    //print_utc("222", time(NULL));
 
     return r;
 }

+ 15 - 15
pro/src/common.h

@@ -342,27 +342,27 @@ typedef struct
 //超限管理表
 typedef struct
 {
-    char            product_vol_upper_enable                   ;//电压上限使能
+    int             product_vol_upper_enable                   ;//电压上限使能
     float           product_vol_upper_threshold                ;//电压上限值
-    char            product_vol_over_upper_threshold_ctrl      ;//电压超限动作
-    char            product_vol_over_upper_threshold_ctrl_para ;//电压超限关联参数
-    char            product_vol_lower_enable                   ;//电压下限使能
+    int             product_vol_over_upper_threshold_ctrl      ;//电压超限动作
+    int             product_vol_over_upper_threshold_ctrl_para ;//电压超限关联参数
+    int             product_vol_lower_enable                   ;//电压下限使能
     float           product_vol_lower_threshold                ;//电压下限值
-    char            product_vol_over_lower_threshold_ctrl      ;//电压超限动作 
-    char            product_vol_over_lower_threshold_ctrl_para ;//电压超限动作   
-    char            product_cur_upper_enable                   ;//电流下限使能
+    int             product_vol_over_lower_threshold_ctrl      ;//电压超限动作 
+    int             product_vol_over_lower_threshold_ctrl_para ;//电压超限动作   
+    int             product_cur_upper_enable                   ;//电流下限使能
     float           product_cur_upper_threshold                ;//电流下限值
     float           product_cur_lower_threshold;                //
-    char            product_cur_over_upper_threshold_ctrl      ;//电流超限动作 
-    char            product_cur_over_upper_threshold_ctrl_para ;//电流超限动作   
-    char            product_pwr_upper_enable                   ;//功率上限使能
+    int             product_cur_over_upper_threshold_ctrl      ;//电流超限动作 
+    int             product_cur_over_upper_threshold_ctrl_para ;//电流超限动作   
+    int             product_pwr_upper_enable                   ;//功率上限使能
     float           product_pwr_upper_threshold                ;//功率上限值
-    char            product_pwr_over_upper_threshold_ctrl      ;//功率超限动作 
-    char            product_pwr_over_upper_threshold_ctrl_para ;//功率超限动作      
-    char            product_pwrcon_upper_enable                ;//耗电量上限使能
+    int             product_pwr_over_upper_threshold_ctrl      ;//功率超限动作 
+    int             product_pwr_over_upper_threshold_ctrl_para ;//功率超限动作      
+    int             product_pwrcon_upper_enable                ;//耗电量上限使能
     float           product_pwrcon_upper_threshold             ;//耗电量上限值
-    char            product_pwrcon_over_upper_threshold_ctrl   ;//耗电量超限动作   
-    char            product_pwrcon_over_upper_threshold_ctrl_para   ;//耗电量超限动作   
+    int             product_pwrcon_over_upper_threshold_ctrl   ;//耗电量超限动作   
+    int             product_pwrcon_over_upper_threshold_ctrl_para   ;//耗电量超限动作   
 }GlobalOverManager;
 
 

+ 25 - 0
pro/src/mail.c

@@ -79,6 +79,30 @@ static void fill_send_buff(char *dst_buf, const char *to,const char *from,const
                     "%s\r\n"
                     "\r\n",subject,from,to,asctime(tblock),body);
 }
+static int curl_add_files(curl_mimepart *part, char *attach)
+{
+    int nlen=strlen(attach);
+    char *p,*tmp=strdup(attach),*p2;
+
+    if(!tmp) {
+        return -1;
+    }
+
+    p = tmp;
+    p2 = tmp+nlen;
+    while((*p)==';') {
+        *p=0; p++;
+    }
+
+    p = tmp;
+    while(1) {
+        if(p>=p2) break;
+        curl_mime_filedata(part, p);
+        p += strlen(p)+1;
+    }
+    free(tmp);
+    return 0;
+}
 static int send_mail(mail_send_t *send, void *addr, char *sub, char *body, char *attach, int multi)
 {
     int i=0;
@@ -167,6 +191,7 @@ static int send_mail(mail_send_t *send, void *addr, char *sub, char *body, char
         part = curl_mime_addpart(mm);
         //curl_mime_name(part, "file");
         curl_mime_filedata(part, attach);
+        //curl_add_files(part, attach);
         curl_easy_setopt(curl, CURLOPT_MIMEPOST, mm);
     }
 

+ 71 - 35
pro/src/sqlite_handle.c

@@ -4849,6 +4849,7 @@ const char *tabNamePool[TAB_ID_MAX]={
     "Table_PowerInfo",
     "Table_PhasePowerInfo",
 };
+
 static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to, handle_t l)
 {
     int r=-1;
@@ -4934,13 +4935,31 @@ static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to,
 
         case TAB_ID_LOG_INFO:
         {
-            //
+            
         }
         break;
 
         case TAB_ID_ALARM_INFO:
         {
-            //
+            alarm_data_t tmp;
+            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE (alarmType=%d || alarmType=%d) AND product_samp_time BETWEEN '%s' AND '%s';", 
+                                         tabNamePool[tab_id], ALARM_TYPE_OPRATION, ALARM_TYPE_RUNNING, time_s, time_e);
+            
+            r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
+            if (r != SQLITE_OK) {
+                log_e("___db_requery TAB_ID_POWER_INFO, sqlite3_prepare_v2 failed\n");
+                return -1;
+            }
+        
+            while (sqlite3_step(stmt) == SQLITE_ROW) {  //column start from 0
+                tmp.id = sqlite3_column_int(stmt, 0);
+                tmp.type =  sqlite3_column_int(stmt, 2);
+                strcpy(tmp.date, (char*)sqlite3_column_text(stmt, 1));
+                strcpy(tmp.content, (char*)sqlite3_column_text(stmt, 4));
+
+                xlist_append(l, tab_id, &tmp, sizeof(tmp));
+            }
+            sqlite3_finalize(stmt);
         }
         break;
 
@@ -5310,36 +5329,57 @@ int dev_serv_xport(int io_type, char *path)
     return 0;
 }
 ////////////////////////////////////////////////////////////////////
+typedef struct {
+    FILE *fp;
+    int  id;
+    int  type;
+}arg_t;
+
+static int log_iterator_fn(handle_t l, node_t *node, node_t *xd, void *arg, int *act)
+{
+    arg_t *parg=(arg_t*)arg;
+    alarm_data_t *tmp=(alarm_data_t*)xd->buf;
+
+    if(parg->type==tmp->type) {
+        fprintf(parg->fp, "%d,", parg->id);
+        fprintf(parg->fp, "%s,", tmp->date);
+        fprintf(parg->fp, "%s,", tmp->content);
+        fprintf(parg->fp, "\n");
+        parg->id++;
+    }
+
+    return 0;
+}
 int dev_log_xport(int type, time_t from, time_t to, char *path)
 {
-    int i,r;
+    int r;
     handle_t l;
-    list_node_t *ln;
+    FILE *fp;
+    arg_t arg;
     list_cfg_t lc={0,0,-1};
     GlobalDeviceManager *dm=&__globalDeviceManage;
+    int stype=((type==0)?ALARM_TYPE_OPRATION:ALARM_TYPE_RUNNING);
 
-    l = xlist_init(&lc);
-    
-    //
-
-    for(i=0; i<xlist_size(l); i++) {
-        r = xlist_take_node(l, &ln, 0);
-        if(r==0) {
-            node_t *nd=&ln->data;
-        }
-
+    fp = fopen(path, "wt");
+    if(!fp) {
+        printf("__%s open failed\n", path);
+        return -1;
     }
 
+    l = xlist_init(&lc);
+    r = db_exec(dm->db, TAB_ID_ALARM_INFO, IO_EXPORT, from, to, l);
+    if(r==0) {
+        fprintf(fp, "id,date,content\n");
+        arg.fp = fp; arg.id = 1; arg.type = stype;
+        xlist_iterator(l, NULL, log_iterator_fn, &arg); 
+    }
+    fclose(fp);
+    xlist_free(l);
 
-
-    sprintf(path, "/tmp/log.txt");
     return 0;
 }
 
-typedef struct {
-    FILE *fp;
-    int  id;
-}pwr_arg_t;
+
 static void replace_chr(char *buf, char a, char b)
 {
     while(*buf) {
@@ -5351,7 +5391,7 @@ static void replace_chr(char *buf, char a, char b)
 }
 static int pwr_iterator_fn(handle_t l, node_t *node, node_t *xd, void *arg, int *act)
 {
-    pwr_arg_t *parg=(pwr_arg_t*)arg;
+    arg_t *parg=(arg_t*)arg;
     if(xd->tp==TAB_ID_POWER_INFO) {
         GlobalPowerInfo *tmp=(GlobalPowerInfo*)xd->buf;
 
@@ -5396,20 +5436,20 @@ int dev_power_xport(int type, time_t from, time_t to, char *path)
     int i,r=-1;
     handle_t l;
     FILE *fp;
-    node_t *nd;
-    list_node_t *ln;
+    arg_t arg;
     list_cfg_t lc={0,0,-1};
-    GlobalPowerInfo *tmp;
-    pwr_arg_t arg;
-    GlobalTreeACManager *tmp3;
     GlobalDeviceManager *dm=&__globalDeviceManage;
     int tab_id=(type?TAB_ID_POWER3_INFO:TAB_ID_POWER_INFO);
 
+    fp = fopen(path, "wt");
+    if(!fp) {
+        printf("__%s open failed\n", path);
+        return -1;
+    }
+
     l = xlist_init(&lc);
     r = db_exec(dm->db, tab_id, IO_EXPORT, from, to, l);
-
-    fp = fopen(path, "wt");
-    if(fp) {
+    if(r==0) {
         if(tab_id==TAB_ID_POWER_INFO) {
             fprintf(fp, "id,product_id,product_ch_id,voltage,current,power,freq,consumption,factor,samp_time\n");
         }
@@ -5419,15 +5459,11 @@ int dev_power_xport(int type, time_t from, time_t to, char *path)
 
         arg.fp = fp; arg.id = 1;
         xlist_iterator(l, NULL, pwr_iterator_fn, &arg);
-        fclose(fp);
-        r = 0;
-    }
-    else {
-        printf("__%s open failed\n", path);
     }
+    fclose(fp);
     xlist_free(l);
     
-    return r;
+    return 0;
 }
 
 

+ 61 - 36
pro/src/sys.c

@@ -1179,7 +1179,7 @@ struct tm* get_curtime(void)
     time_t cur = time(NULL);
     return localtime(&cur);
 }
-static void send_power_data(struct tm *tm)
+static void send_power_data(struct tm *tm, char *dir)
 {
     int r,type=0;
     char path[200],sub[100];
@@ -1187,82 +1187,107 @@ static void send_power_data(struct tm *tm)
     GlobalDeviceManager *dm=&__globalDeviceManage;
     static time_t sended_id=0;
     
-    if(tm->tm_hour==0) {
-        time_t from,to;
-        get_range(tm, &from, &to, 1);
+    time_t from,to;
+    get_range(tm, &from, &to, 1);
 
-        if(sended_id != from) {
-            if(dm->_globalDevInfo.product.pwr_type>=SmartPDU_Tree_AC_Tree) {
-                type = 1;
-            }
-            get_time_str2(tmp1,sizeof(tmp1),from);
-            get_time_str2(tmp2,sizeof(tmp2),to);
-            sprintf(path, "/tmp/power_%s_%s.csv", tmp1, tmp2);
-            if(!file_exist(path)) {
-                dev_power_xport(type, from, to, path);
-            }
+    if(sended_id != from) {
+        if(dm->_globalDevInfo.product.pwr_type>=SmartPDU_Tree_AC_Tree) {
+            type = 1;
+        }
+        get_time_str2(tmp1,sizeof(tmp1),from);
+        get_time_str2(tmp2,sizeof(tmp2),to);
 
-            if(file_exist(path)) {
-                sprintf(sub, "%s %d power data", dm->_globalDevInfo.product.name, dm->_globalDevInfo.product.id);
-                r = mail_send(sub, NULL, path);
-                if(r==0) {
-                    file_remove(path);
-                    sended_id = from;
-                }
+        sprintf(path, "%s/power_%s_%s.csv", dir, tmp1, tmp2);
+        if(!file_exist(path)) {
+            dev_power_xport(type, from, to, path);
+        }
+
+        if(file_exist(path)) {
+            sprintf(sub, "%s %d power data", dm->_globalDevInfo.product.name, dm->_globalDevInfo.product.id);
+            r = mail_send(sub, NULL, path);
+            if(r==0) {
+                file_remove(path);
+                sended_id = from;
             }
         }
     }
 }
-static void send_log_data(struct tm *tm)
+static void send_log_data(struct tm *tm, char *dir)
 {
-    int r,type=0;
+    int i,r,type=0;
     char path[200],sub[100];
     char tmp1[100],tmp2[100];
     GlobalDeviceManager *dm=&__globalDeviceManage;
-    static time_t sended_id=0;
-    
-    if(tm->tm_hour==0) {
-        time_t from,to;
-        get_range(tm, &from, &to, 1);
+    static time_t sended_id[2]={0};
+    char *logname[2]={"run","opr"};
+
+#ifndef LOG_SEND_MAIL
+    return;
+#endif
+
+    time_t from,to;
+    get_range(tm, &from, &to, 1);
 
-        if(sended_id != from) {
+    for(i=0; i<2; i++) {
+        if(sended_id[i] != from) {
             get_time_str2(tmp1,sizeof(tmp1),from);
             get_time_str2(tmp2,sizeof(tmp2),to);
-            //sprintf(path, "/tmp/power_%s_%s.csv", tmp1, tmp2);
+
+            sprintf(path, "%s/log_%s_%s_%s.csv", dir, logname[i], tmp1, tmp2);
             if(!file_exist(path)) {
                 dev_log_xport(type, from, to, path);
             }
 
             if(file_exist(path)) {
-                //sprintf(sub, "%s %d power data", dm->_globalDevInfo.product.name, dm->_globalDevInfo.product.id);
+                sprintf(sub, "%s %d %s log", dm->_globalDevInfo.product.name, dm->_globalDevInfo.product.id, logname[i]);
                 r = mail_send(sub, NULL, path);
                 if(r==0) {
                     file_remove(path);
-                    sended_id = from;
+                    sended_id[i] = from;
                 }
             }
         }
     }
 }
 
-
+#define TMP_DIR  "/tmp/pdu"
+static int tmp_create(void)
+{
+    char cmd[100];
+    sprintf(cmd, "mkdir -p %s", TMP_DIR);
+    return system(cmd);
+}
+static int tmp_remove(void)
+{
+    char cmd[100];
+    sprintf(cmd, "rm -f %s/*.csv", TMP_DIR);
+    return system(cmd);
+}
 static void send_check(void)
 {
+    static int file_flag=0;
     static uint32_t send_cnt=0;
 
     send_cnt++;
     if(send_cnt%SEND_PERIOD==0) {
         struct tm *tm=get_curtime();
 
-        send_power_data(tm);
+        if(tm->tm_hour==0) {
+            send_power_data(tm, TMP_DIR);
+            send_log_data(tm, TMP_DIR);
+            file_flag = 1;
+        }
+        else if(tm->tm_hour==1 && file_flag) {
+            tmp_remove();
+            file_flag = 0;
+        }
     }
 }
-
-
 static void* polling_thread(void *arg)
 {
     thread_handle_t *h=(thread_handle_t*)arg;
 
+    //tmp_create();
     while(h->quit==0) {
         mem_check();
         send_check();