|
|
@@ -5430,7 +5430,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)
|
|
|
+static int db_exec(sqlite3 *db, int tab_id, int type, time_t from, time_t to, handle_t l)
|
|
|
{
|
|
|
int r=-1,cnt=0;
|
|
|
char *p,temp[1024];
|
|
|
@@ -5635,7 +5635,8 @@ static int db_exec(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to,
|
|
|
{
|
|
|
GlobalSensorInfo tmp;
|
|
|
|
|
|
- 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);
|
|
|
+ snprintf(temp,sizeof(temp),"SELECT * FROM Table_sensorInfo where (sensor_samp_time BETWEEN '%s' and '%s' ) and sensor_id in (SELECT a.sensor_type 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) {
|
|
|
log_e("___db_requery 2, sqlite3_prepare_v2 failed\n");
|
|
|
@@ -5992,6 +5993,24 @@ static void replace_chr(char *buf, char a, char b)
|
|
|
buf++;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+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;
|
|
|
+ fprintf(parg->fp, "%d,", parg->id);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->product_id);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->sensor_id);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->val1);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->val2);
|
|
|
+ fprintf(parg->fp, "%s,", tmp->samp_time);
|
|
|
+ replace_chr(tmp->samp_time, '-', '.');
|
|
|
+ fprintf(parg->fp, "\n");
|
|
|
+ parg->id++;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
static int pwr_iterator_fn(handle_t l, node_t *node, node_t *xd, void *arg, int *act)
|
|
|
{
|
|
|
arg_t *parg=(arg_t*)arg;
|
|
|
@@ -6033,6 +6052,42 @@ static int pwr_iterator_fn(handle_t l, node_t *node, node_t *xd, void *arg, int
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+int dev_sensor_info_xport(time_t from, time_t to, char *path,int type)
|
|
|
+{
|
|
|
+ int i,r=-1;
|
|
|
+ handle_t l;
|
|
|
+ FILE *fp;
|
|
|
+ arg_t arg;
|
|
|
+ list_cfg_t lc={0,0,-1};
|
|
|
+ GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
+ int tab_id=TAB_ID_SENSOR_INFO;
|
|
|
+
|
|
|
+ if(file_exist(path)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ l = xlist_init(&lc);
|
|
|
+
|
|
|
+
|
|
|
+ db_exec(dm->db, tab_id, type, from, to, l);
|
|
|
+
|
|
|
+ fp = fopen(path, "wt");
|
|
|
+ if(!fp) {
|
|
|
+ log_e("__%s open failed\n", path);
|
|
|
+ xlist_free(l);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ fprintf(fp, "id,product_id,sensor_id,sensor_val1,sensor_val2,samp_time\n");
|
|
|
+ arg.fp = fp; arg.id = 1;
|
|
|
+
|
|
|
+ xlist_iterator(l, NULL, sensor_iterator_fn, &arg);
|
|
|
+
|
|
|
+ fclose(fp);
|
|
|
+ xlist_free(l);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
int dev_power_xport(time_t from, time_t to, char *path)
|
|
|
{
|
|
|
int i,r=-1;
|