|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
|