소스 검색

整理代码,加一些打印

guohui 1 년 전
부모
커밋
3ccd31c0a0
7개의 변경된 파일과 132개의 추가작업 그리고 25개의 파일을 삭제
  1. 52 9
      pro/src/Cellular.c
  2. 27 2
      pro/src/Cellular.h
  3. 1 1
      pro/src/common.c
  4. 21 8
      pro/src/sqlite_handle.c
  5. 27 2
      pro/src/sys.c
  6. 1 0
      pro/src/sys.h
  7. 3 3
      pro/ui/timer.c

+ 52 - 9
pro/src/Cellular.c

@@ -481,10 +481,8 @@ int cellular_restart(void)
     cell_handle_t *h=&ceHandle;
 
 #ifdef USE_CELL
-    // 禁用模块
     if (send_cmd(h, "AT+CFUN=0\r\n", "OK", 2, 1)) // 禁用模块
     {
-        // 启用模块
         if (send_cmd(h, "AT+CFUN=1\r\n", "OK", 2, 1)) // 启用模块
         {
             ret=0;
@@ -497,12 +495,6 @@ int cellular_restart(void)
 
 
 
-
-/**
- * @brief 初始化蜂窝通信模块
- * 该函数用于初始化蜂窝通信模块。
- * @return 初始化结果。如果初始化成功,返回0;如果初始化失败,返回-1。
- */
 int cellular_init(void)
 {
     cell_handle_t *h=&ceHandle;
@@ -523,10 +515,61 @@ int cellular_init(void)
 
 int cellular_deinit(void)
 {
-    
+    cell_handle_t *h=&ceHandle;
+
+    return 0;
+}
+
+int cellular_get_info(cellular_info_t *info)
+{
+    cell_handle_t *h=&ceHandle;
+
     return 0;
 }
 
+
+int cellular_set_cb(int cell, cell_fn_t fn)
+{
+    cell_handle_t *h=&ceHandle;
+    return 0;
+}
+
+
+int cellular_send(int cell, void *data, int len)
+{
+    int r=0;
+    cell_handle_t *h=&ceHandle;
+
+    switch(cell) {
+        case CELL_UDP:
+        break;
+
+        case CELL_TCP:
+        break;
+
+        case CELL_SMS:
+        break;
+
+        case CELL_GNSS:
+        break;
+
+        case CELL_DIALOG:
+        break;
+
+        default:
+        r = -1;
+    }
+
+    return r;
+}
+
+
+
+
+
+
+
+
 #ifdef USE_CELL
 bool  EC200_CreateTCPSocket(char *pIP,int pPort,bool openflag)
 {

+ 27 - 2
pro/src/Cellular.h

@@ -1,7 +1,32 @@
-#ifndef __Cellular_Hx__
-#define __Cellular_Hx__
+#ifndef __CELLULAR_Hx__
+#define __CELLULAR_Hx__
+
+enum {
+    CELL_UDP=0,
+    CELL_TCP,
+    CELL_SMS,
+    CELL_GNSS,
+    CELL_DIALOG,
+    CELL_EXCEPT,
+
+    CELL_MAX
+};
+
+typedef struct {
+    int flag;
+}cellular_info_t;
+
+
+typedef int (*cell_fn_t)(int cell, void *data, int len);
 
 int cellular_init(void);
 int cellular_deinit(void);
 
+int cellular_get_info(cellular_info_t *info);
+int cellular_set_cb(int cell, cell_fn_t fn);
+int cellular_send(int cell, void *data, int len);
+
+
+
+
 #endif

+ 1 - 1
pro/src/common.c

@@ -517,7 +517,7 @@ int set_tzone(int tzone)
     system(buf);
 
     if(tz!=tzone) {
-        printf("old tzone: %d  new tzone %d\n",tz,tzone);
+        log_e("old tzone: %d  new tzone %d\n",tz,tzone);
         sys_reboot();
     }
     

+ 21 - 8
pro/src/sqlite_handle.c

@@ -5054,7 +5054,7 @@ static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to,
         case TAB_ID_POWER_INFO:
         {
             GlobalPowerInfo tmp;
-            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE product_samp_time BETWEEN '%s' AND '%s';", tabNamePool[tab_id], time_s, time_e);
+            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE product_samp_time BETWEEN '%s' AND '%s' ORDER BY product_samp_time DESC;", tabNamePool[tab_id], time_s, time_e);
             
             r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
             if (r != SQLITE_OK) {
@@ -5062,7 +5062,7 @@ static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to,
                 return -1;
             }
         
-            while (sqlite3_step(stmt) == SQLITE_ROW) {  //column start from 0
+            while (sqlite3_step(stmt)==SQLITE_ROW) {  //column start from 0
                 tmp.product_id = sqlite3_column_int(stmt, 1);
                 tmp.product_ch_id =  sqlite3_column_int(stmt, 2);
                 tmp.product_status =  sqlite3_column_int(stmt, 3);
@@ -5085,7 +5085,7 @@ static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to,
         {
             GlobalTreeACManager tmp;
 
-            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE (product_ph_samp_time BETWEEN '%s' AND '%s') ORDER BY product_index ASC;", tabNamePool[tab_id], time_s, time_e);
+            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE (product_ph_samp_time BETWEEN '%s' AND '%s') ORDER BY product_ph_samp_time DESC;", tabNamePool[tab_id], time_s, time_e);
             r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
             if (r != SQLITE_OK) {
                 log_e("___db_requery TAB_ID_POWER3_INFO, sqlite3_prepare_v2 failed\n");
@@ -5123,7 +5123,7 @@ static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to,
             alarm_data_t tmp;
             GlobalDeviceManager *dm=&__globalDeviceManage;
 
-            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE ((alarmType=%d) OR (alarmType=%d)) AND (alarmDate BETWEEN '%s' AND '%s');", 
+            snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE ((alarmType=%d) OR (alarmType=%d)) AND (alarmDate BETWEEN '%s' AND '%s') ORDER BY alarmDate DESC;", 
                                          tabNamePool[tab_id], ALARM_TYPE_OPRATION, ALARM_TYPE_RUNNING, time_s, time_e);
             
             r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
@@ -5555,18 +5555,25 @@ int dev_log_xport(int type, time_t from, time_t to, char *path)
     }
 
     l = xlist_init(&lc);
+
+    log_d("___ log export, query db start ...\n");
     db_exec(dm->db, TAB_ID_ALARM_INFO, IO_EXPORT, from, to, l);
+    log_d("___ log export, query db end ...\n");
 
     fp = fopen(path, "wt");
     if(!fp) {
-        printf("__%s open failed\n", path);
+        log_e("__%s open failed\n", path);
         xlist_free(l);
         return -1;
     }
 
     fprintf(fp, "id,date,content\n");
     arg.fp = fp; arg.id = 1; arg.type = stype;
+
+    log_d("___ log export, sz: %d, iterator start ...\n", xlist_size(l));
     xlist_iterator(l, NULL, log_iterator_fn, &arg);
+    log_d("___ log export, iterator end ...\n");
+
     fclose(fp);
     xlist_free(l);
 
@@ -5639,16 +5646,19 @@ int dev_power_xport(time_t from, time_t to, char *path)
         return 0;
     }
 
-    if(dm->_globalDevInfo.product.pwr_type>=SmartPDU_Tree_AC_Tree) {
+    if(dm->_globalDevInfo.product.pwr_type==SmartPDU_Tree_AC_Tree) {
         tab_id = TAB_ID_POWER3_INFO;
     }
 
     l = xlist_init(&lc);
+
+    log_d("___ power export, query db start ...\n");
     db_exec(dm->db, tab_id, IO_EXPORT, from, to, l);
+    log_d("___ power export, query db end ...\n");
 
     fp = fopen(path, "wt");
     if(!fp) {
-        printf("__%s open failed\n", path);
+        log_e("__%s open failed\n", path);
         xlist_free(l);
         return -1;
     }
@@ -5661,7 +5671,10 @@ int dev_power_xport(time_t from, time_t to, char *path)
     }
 
     arg.fp = fp; arg.id = 1;
+    log_d("___ pwr export, sz: %d, iterator start ...\n", xlist_size(l));
     xlist_iterator(l, NULL, pwr_iterator_fn, &arg);
+    log_d("___ pwr export,  iterator end ...\n");
+
     fclose(fp);
     xlist_free(l);
     
@@ -5672,7 +5685,7 @@ int dev_power_xport(time_t from, time_t to, char *path)
 int dev_clear_table(sqlite3 *db, int tab_id)
 {
     int r;
-    char temp[1024];
+    char temp[200];
 
     if(!db || tab_id<TAB_ID_NTP || tab_id>=TAB_ID_MAX) {
         return -1;

+ 27 - 2
pro/src/sys.c

@@ -70,7 +70,7 @@ static int is_mac_fixed(void)
 }
 static void nic_set_mac(void)
 {
-#if(CHIP_TYPE == CHIP_T113i)
+#if (CHIP_TYPE == CHIP_T113i)
     //if(is_mac_fixed()) return;     //如果是t113i新版镜像,mac地址跟id绑定,不需要写固定值进去
 #endif
     system("ip link set dev eth0 address `cat /sys/class/addr_mgt/addr_eth`");
@@ -1259,7 +1259,7 @@ static void send_by_mail(struct tm *tm, char *dir)
     int r=-1;
     char temp[200],sub[100];
     char tmp1[100],tmp2[100];
-    char path[1024];
+    char path[400];
     GlobalDeviceManager *dm=&__globalDeviceManage;
     ProductInfo_t *prod=&dm->_globalDevInfo.product;
     static time_t sended_id=0;
@@ -1275,18 +1275,30 @@ static void send_by_mail(struct tm *tm, char *dir)
         r = dev_log_xport(0, from, to, temp);
         if(r==0) {
             strcat(path, temp);strcat(path, ";");
+            log_d("___ run log export ok\n");
+        }
+        else {
+            log_d("___ run log export failed\n");
         }
 
         sprintf(temp, "%s/log_opr_%s_%s.txt", dir, tmp1, tmp2);
         r = dev_log_xport(1, from, to, temp);
         if(r==0) {
             strcat(path, temp);strcat(path, ";");
+            log_d("___ opr log export ok\n");
+        }
+        else {
+            log_e("___ opr log export failed\n");
         }
         
         sprintf(temp, "%s/power_%s_%s.csv", dir, tmp1, tmp2);
         r = dev_power_xport(from, to, temp);
         if(r==0) {
             strcat(path, temp);strcat(path, ";");
+            log_d("___ power export ok\n");
+        }
+        else {
+            log_e("___ power export failed\n");
         }
 
         if(r==0) {
@@ -1557,6 +1569,19 @@ int sys_chmod(void)
 }
 
 
+#include <sys/sysinfo.h>
+int sys_heap_remain(void)
+{
+    //long pages = sysconf(_SC_AVPHYS_PAGES); // 可用物理页数
+    //long page_size = sysconf(_SC_PAGESIZE); // 页面大小
+    //long memory_free = pages * page_size;
+
+    return 0;
+}
+
+
+
+
 int sys_get_ip_ver(char *addr)
 {
     return ip_check(addr);

+ 1 - 0
pro/src/sys.h

@@ -35,5 +35,6 @@ int sys_get_prod(GlobalDeviceInfo *info);
 int sys_kill(char *proc);
 int sys_restart_app(void);
 int sys_get_ip_ver(char *addr);
+int sys_heap_remain(void);
 
 #endif

+ 3 - 3
pro/ui/timer.c

@@ -87,7 +87,7 @@ int timer_deinit(int h)
     int r;
     timer_handle_t *th=(timer_handle_t*)h;
 
-    if(h==-1 || !th->inited) {
+    if((h==0)||(h==-1) || !th->inited) {
         return -1;
     }
     r = timer_delete(th->tid);
@@ -103,7 +103,7 @@ int timer_start(int h, int t, int times, timer_fn_t fn, void *arg)
     int r;
     timer_handle_t *th=(timer_handle_t*)h;
     
-    if(h==-1 || !th->inited) {
+    if((h==0)||(h==-1) || !th->inited) {
         return -1;
     }
     set_time(th, 0, 0);
@@ -122,7 +122,7 @@ int timer_stop(int h)
     int r;
     timer_handle_t *th=(timer_handle_t*)h;
     
-    if(h==-1 || !th->inited) {
+    if((h==0)||(h==-1) || !th->inited) {
         return -1;
     }