ソースを参照

传感器数据导出增加name!

liyi 10 ヶ月 前
親
コミット
b26f7492c2
共有2 個のファイルを変更した、35 個の追加 と 11 個の削除を含む
  1. 13 0
      pro/src/common.h
  2. 22 11
      pro/src/sqlite_handle.c

+ 13 - 0
pro/src/common.h

@@ -844,6 +844,19 @@ typedef struct
     struct list_head list;
 }GlobalSensorInfo;
 
+
+typedef struct 
+{
+    char     samp_time[64];
+    int      product_id;
+    char     sensor_id;
+    char     sensor_name[64];
+    float    val1;
+    float    val2;
+}download_sensor_Info_t;
+
+
+
 typedef struct
 {
     int                 sensor_val1_upper_enabled ;//

+ 22 - 11
pro/src/sqlite_handle.c

@@ -5633,9 +5633,14 @@ static int db_exec(sqlite3 *db, int tab_id, int type, time_t from, time_t to, ha
         
         case TAB_ID_SENSOR_INFO:
         {
-            GlobalSensorInfo tmp;
+            //GlobalSensorInfo tmp;
+
+            download_sensor_Info_t tmp;
+
+            snprintf(temp,sizeof(temp),"SELECT a.sensor_id,b.product_id,a.sensor_name,b.sensor_val1,b.sensor_val2,b.sensor_samp_time"
+                                        " FROM Table_sensorManage a left join Table_SensorInfo b on a.sensor_id=b.sensor_id" 
+                                        " where (a.sensor_type=%d and (b.sensor_samp_time between '%s' and '%s'));",type,time_s,time_e);
 
-            snprintf(temp,sizeof(temp),"SELECT * FROM Table_sensorInfo where (sensor_samp_time BETWEEN '%s' and '%s' ) and sensor_id in (SELECT a.sensor_id from Table_SensorManage a where (a.sensor_type=%d));",time_s, time_e,type);
             //snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE (sensor_samp_time BETWEEN '%s' AND '%s') ORDER BY sensor_samp_time DESC;", tabNamePool[tab_id], time_s, time_e);
             r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
             if (r != SQLITE_OK) {
@@ -5644,14 +5649,20 @@ static int db_exec(sqlite3 *db, int tab_id, int type, time_t from, time_t to, ha
             }
 
             while (sqlite3_step(stmt) == SQLITE_ROW) {
-                p = (char*)sqlite3_column_text(stmt, 1);
-                tmp.samp_time[0] = 0;
+                tmp.product_id = sqlite3_column_int(stmt, 1);
+                tmp.sensor_id = sqlite3_column_int(stmt, 0);
+                tmp.val1 = sqlite3_column_double(stmt, 3);
+                tmp.val2 = sqlite3_column_double(stmt, 4);     
+
+                p = (char*)sqlite3_column_text(stmt, 2);
+                memset(tmp.sensor_name,0,64);
+                if(p) strcpy(tmp.sensor_name, p);
+
+                p = (char*)sqlite3_column_text(stmt, 5);
+                memset(tmp.samp_time,0,64);
                 if(p) strcpy(tmp.samp_time, p);
 
-                tmp.product_id = sqlite3_column_int(stmt, 2);
-                tmp.sensor_id = sqlite3_column_int(stmt, 3);
-                tmp.val1 = sqlite3_column_double(stmt, 4);
-                tmp.val2 = sqlite3_column_double(stmt, 5);
+
 
                 xlist_append(l, tab_id, &tmp, sizeof(tmp));
                 cnt++;
@@ -5997,13 +6008,13 @@ static void replace_chr(char *buf, char a, char b)
 static int sensor_iterator_fn(handle_t l, node_t *node, node_t *xd, void *arg, int *act)
 {
     arg_t *parg=(arg_t*)arg;
-    GlobalSensorInfo *tmp = (GlobalSensorInfo*)xd->buf;
+    download_sensor_Info_t *tmp = (download_sensor_Info_t*)xd->buf;
     fprintf(parg->fp, "%d,", parg->id);
     fprintf(parg->fp, "%d,", tmp->product_id);
     fprintf(parg->fp, "%d,", tmp->sensor_id);
+    fprintf(parg->fp, "%s,", tmp->sensor_name);
     fprintf(parg->fp, "%0.2f,", tmp->val1);
     fprintf(parg->fp, "%0.2f,", tmp->val2);
-    
     replace_chr(tmp->samp_time, '-', '.');
     fprintf(parg->fp, "%s,", tmp->samp_time);
     fprintf(parg->fp, "\n");
@@ -6078,7 +6089,7 @@ int dev_sensor_info_xport(time_t from, time_t to, char *path,int type)
         xlist_free(l);
         return -1;
     }
-    fprintf(fp, "id,product_id,sensor_id,sensor_val1,sensor_val2,samp_time\n");
+    fprintf(fp, "id,product_id,sensor_id,sensor_name,sensor_val1,sensor_val2,samp_time\n");
     arg.fp = fp; arg.id = 1;
 
     xlist_iterator(l, NULL, sensor_iterator_fn, &arg);