|
|
@@ -4669,14 +4669,16 @@ const char *tabNamePool[TAB_ID_MAX]={
|
|
|
|
|
|
};
|
|
|
|
|
|
-static int sql_requery(sqlite3 *db, int tab_id, time_t from, time_t to, void *data, int *cnt)
|
|
|
+
|
|
|
+static int db_requery(sqlite3 *db, int tab_id, time_t from, time_t to, handle_t l)
|
|
|
{
|
|
|
int r=-1;
|
|
|
+
|
|
|
char *p,temp[1024];
|
|
|
char time_s[64],time_e[64];
|
|
|
sqlite3_stmt *stmt=NULL;
|
|
|
- GlobalPowerInfo *pwr=NULL;
|
|
|
- GlobalTreeACManager *pwr3=NULL;
|
|
|
+ GlobalPowerInfo pwr;
|
|
|
+ GlobalTreeACManager pwr3;
|
|
|
|
|
|
get_time_str(time_s, sizeof(time_s), from);
|
|
|
get_time_str(time_e, sizeof(time_e), to);
|
|
|
@@ -4686,60 +4688,69 @@ static int sql_requery(sqlite3 *db, int tab_id, time_t from, time_t to, void *da
|
|
|
|
|
|
r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
|
|
|
if (r != SQLITE_OK) {
|
|
|
- log_e("___mqtt_load, sqlite3_prepare_v2 failed\n");
|
|
|
+ log_e("___db_requery 1, sqlite3_prepare_v2 failed\n");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
- pwr->product_id = sqlite3_column_int(stmt, 1);
|
|
|
- pwr->product_ch_id = sqlite3_column_int(stmt, 2);
|
|
|
- pwr->product_status = sqlite3_column_int(stmt, 3);
|
|
|
- pwr->_power_info.voltage = sqlite3_column_double(stmt, 4);
|
|
|
- pwr->_power_info.current = sqlite3_column_double(stmt, 5);
|
|
|
- pwr->_power_info.power = sqlite3_column_double(stmt, 6);
|
|
|
- pwr->_power_info.freq = sqlite3_column_double(stmt, 7);
|
|
|
- pwr->_power_info.consumption = sqlite3_column_double(stmt, 8);
|
|
|
- pwr->_power_info.factor = sqlite3_column_double(stmt, 9);
|
|
|
+ pwr.product_id = sqlite3_column_int(stmt, 1);
|
|
|
+ pwr.product_ch_id = sqlite3_column_int(stmt, 2);
|
|
|
+ pwr.product_status = sqlite3_column_int(stmt, 3);
|
|
|
+ pwr._power_info.voltage = sqlite3_column_double(stmt, 4);
|
|
|
+ pwr._power_info.current = sqlite3_column_double(stmt, 5);
|
|
|
+ pwr._power_info.power = sqlite3_column_double(stmt, 6);
|
|
|
+ pwr._power_info.freq = sqlite3_column_double(stmt, 7);
|
|
|
+ pwr._power_info.consumption = sqlite3_column_double(stmt, 8);
|
|
|
+ pwr._power_info.factor = sqlite3_column_double(stmt, 9);
|
|
|
+
|
|
|
+ xlist_append(l, 0, &pwr, sizeof(pwr));
|
|
|
}
|
|
|
sqlite3_finalize(stmt);
|
|
|
-
|
|
|
}
|
|
|
else if(tab_id==TAB_ID_POWER3_INFO) {
|
|
|
snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE (product_ph_samp_time BETWEEN '%s' AND '%s') ORDER BY product_index DESC;", tabNamePool[tab_id], time_s, time_e);
|
|
|
|
|
|
r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
|
|
|
if (r != SQLITE_OK) {
|
|
|
- log_e("___mqtt_load, sqlite3_prepare_v2 failed\n");
|
|
|
+ log_e("___db_requery 2, sqlite3_prepare_v2 failed\n");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
- /*
|
|
|
- pwr3->product_id = sqlite3_column_int(stmt, 1);
|
|
|
- pwr3->product_ph_type = sqlite3_column_int(stmt, 2);
|
|
|
- pwr3->product_ch_id = sqlite3_column_int(stmt, 3);
|
|
|
- pwr3->_PowerInfo.voltage = sqlite3_column_double(stmt, 4);
|
|
|
- pwr3->_PowerInfo.current = sqlite3_column_double(stmt, 5);
|
|
|
- pwr3->_PowerInfo.power = sqlite3_column_double(stmt, 6);
|
|
|
- pwr3->_PowerInfo.freq = sqlite3_column_double(stmt, 7);
|
|
|
- pwr3->_PowerInfo.consumption = sqlite3_column_double(stmt, 8);
|
|
|
- pwr3->_PowerInfo.factor = sqlite3_column_double(stmt, 9);
|
|
|
- */
|
|
|
+ pwr3.product_id = sqlite3_column_int(stmt, 1);
|
|
|
+ pwr3.product_ph_type = sqlite3_column_int(stmt, 2);
|
|
|
+ pwr3.product_ch_id = sqlite3_column_int(stmt, 3);
|
|
|
+ pwr3._PowerInfo.voltage = sqlite3_column_double(stmt, 4);
|
|
|
+ pwr3._PowerInfo.current = sqlite3_column_double(stmt, 5);
|
|
|
+ pwr3._PowerInfo.power = sqlite3_column_double(stmt, 6);
|
|
|
+ pwr3._PowerInfo.freq = sqlite3_column_double(stmt, 7);
|
|
|
+ pwr3._PowerInfo.consumption = sqlite3_column_double(stmt, 8);
|
|
|
+ pwr3._PowerInfo.factor = sqlite3_column_double(stmt, 9);
|
|
|
+
|
|
|
+ xlist_append(l, 0, &pwr3, sizeof(pwr3));
|
|
|
}
|
|
|
sqlite3_finalize(stmt);
|
|
|
}
|
|
|
-
|
|
|
- return r;
|
|
|
+ else if(tab_id==TAB_ID_LOG_INFO) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ else if(tab_id==TAB_ID_ALARM_INFO) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
-int dev_data_xport(sqlite3 *db, int tab_id, int io_type, uint32_t time_s, uint32_t time_e, void *data, int *cnt)
|
|
|
+static int data_io(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to, void *data)
|
|
|
{
|
|
|
int i,r=-1;
|
|
|
|
|
|
- if(tab_id<TAB_ID_NTP || tab_id>=TAB_ID_MAX || io_type<0 || io_type>=IO_MAX || !data || !cnt) {
|
|
|
+ if(tab_id<TAB_ID_NTP || tab_id>=TAB_ID_MAX || io_type<0 || io_type>=IO_MAX || (io_type==IO_IMPORT && !data)) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- *cnt = 1;
|
|
|
switch(tab_id) {
|
|
|
case TAB_ID_NTP:
|
|
|
{
|
|
|
@@ -4891,40 +4902,140 @@ int dev_data_xport(sqlite3 *db, int tab_id, int io_type, uint32_t time_s, uint32
|
|
|
break;
|
|
|
|
|
|
case TAB_ID_LOG_INFO:
|
|
|
+ case TAB_ID_ALARM_INFO:
|
|
|
+ case TAB_ID_POWER_INFO:
|
|
|
+ case TAB_ID_POWER3_INFO:
|
|
|
{
|
|
|
if(io_type==IO_EXPORT) {
|
|
|
- //r = dev_get_ntp_info(db, (NTPManager*)data);
|
|
|
+ handle_t l=(handle_t)data;
|
|
|
+ db_requery(db, tab_id, from, to, l);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+ }
|
|
|
|
|
|
- case TAB_ID_ALARM_INFO:
|
|
|
- {
|
|
|
- if(io_type==IO_EXPORT) {
|
|
|
- //r = dev_search_alarm_info(db, (NTPManager*)data);
|
|
|
- }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+//////////////////////////////////////////////////////////////////////////
|
|
|
+static int sensor_xport(int io_type, char *path)
|
|
|
+{
|
|
|
+ int i,r;
|
|
|
+ handle_t l;
|
|
|
+ list_node_t *ln;
|
|
|
+ list_cfg_t lc={0,0,-1};
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
- break;
|
|
|
|
|
|
- case TAB_ID_POWER_INFO:
|
|
|
- {
|
|
|
- if(io_type==IO_EXPORT) {
|
|
|
- //r = dev_search_time_power_info(db, 0, ch_id, 00, (GlobalPowerInfo*)data, "start", "end");
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ sprintf(path, "/tmp/log.txt");
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int alarm_xport(int io_type, char *path)
|
|
|
+{
|
|
|
+ int i,r;
|
|
|
+ handle_t l;
|
|
|
+ list_node_t *ln;
|
|
|
+ list_cfg_t lc={0,0,-1};
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
- break;
|
|
|
|
|
|
- case TAB_ID_POWER3_INFO:
|
|
|
- {
|
|
|
- if(io_type==IO_EXPORT) {
|
|
|
- //r = dev_search_time_t_ac_power_info(db, 0, ch_id, 00, (GlobalPowerInfo*)data, "start", "end");
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sprintf(path, "/tmp/alarm.ini");
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int serv_xport(int io_type, char *path)
|
|
|
+{
|
|
|
+ int i,r;
|
|
|
+ handle_t l;
|
|
|
+ list_node_t *ln;
|
|
|
+ list_cfg_t lc={0,0,-1};
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
- break;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ sprintf(path, "/tmp/serv.ini");
|
|
|
return 0;
|
|
|
}
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+static int log_xport(int period, char *path)
|
|
|
+{
|
|
|
+ int i,r;
|
|
|
+ handle_t l;
|
|
|
+ list_node_t *ln;
|
|
|
+ list_cfg_t lc={0,0,-1};
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sprintf(path, "/tmp/log.txt");
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int power_xport(int period, char *path)
|
|
|
+{
|
|
|
+ int i,r;
|
|
|
+ handle_t l;
|
|
|
+ list_node_t *ln;
|
|
|
+ list_cfg_t lc={0,0,-1};
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sprintf(path, "/tmp/log.txt");
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
|