|
|
@@ -1725,7 +1725,7 @@ int dev_update_t_ac_power_manage_over_info(sqlite3 *db,GlobalTreeACManager* _glo
|
|
|
/// @param product_id
|
|
|
/// @param _globalPowerManger
|
|
|
/// @return
|
|
|
-int dev_insert_t_ac_power_info(sqlite3 *db,GlobalTreeACManager* _globalPowerChnInfo,int* nIndex,char* pTimeData)
|
|
|
+int dev_insert_t_ac_power_info(sqlite3 *db,GlobalTreeACManager* _globalPowerChnInfo,int* nIndex)
|
|
|
{
|
|
|
int res ;
|
|
|
char select_sql[1024] = {0};
|
|
|
@@ -1753,7 +1753,7 @@ int dev_insert_t_ac_power_info(sqlite3 *db,GlobalTreeACManager* _globalPowerChnI
|
|
|
pInfo->_PowerInfo.freq,
|
|
|
pInfo->_PowerInfo.consumption,
|
|
|
pInfo->_PowerInfo.factor,
|
|
|
- pTimeData,
|
|
|
+ pInfo->samp_time,
|
|
|
table
|
|
|
);
|
|
|
}
|
|
|
@@ -1770,7 +1770,7 @@ int dev_insert_t_ac_power_info(sqlite3 *db,GlobalTreeACManager* _globalPowerChnI
|
|
|
pInfo->_PowerInfo.freq,
|
|
|
pInfo->_PowerInfo.consumption,
|
|
|
pInfo->_PowerInfo.factor,
|
|
|
- pTimeData
|
|
|
+ pInfo->samp_time
|
|
|
);
|
|
|
}
|
|
|
// if(_globalPowerChnInfo->product_ch_id==0)
|
|
|
@@ -4645,7 +4645,7 @@ int dev_sql_set_overwrite(int flag)
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
+#include "xlist.h"
|
|
|
const char *tabNamePool[TAB_ID_MAX]={
|
|
|
"Table_NTPManage",
|
|
|
"Table_Userinfo",
|
|
|
@@ -4666,96 +4666,225 @@ const char *tabNamePool[TAB_ID_MAX]={
|
|
|
"Table_AlarmManage",
|
|
|
"Table_PowerInfo",
|
|
|
"Table_PhasePowerInfo",
|
|
|
-
|
|
|
};
|
|
|
-
|
|
|
-
|
|
|
-static int db_requery(sqlite3 *db, int tab_id, time_t from, time_t to, handle_t l)
|
|
|
+static int db_exec(sqlite3 *db, int tab_id, int io_type, 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;
|
|
|
- GlobalTreeACManager pwr3;
|
|
|
|
|
|
get_time_str(time_s, sizeof(time_s), from);
|
|
|
get_time_str(time_e, sizeof(time_e), to);
|
|
|
|
|
|
- if(tab_id==TAB_ID_POWER_INFO) {
|
|
|
- snprintf(temp, sizeof(temp), "SELECT * FROM %s WHERE product_samp_time BETWEEN '%s' AND '%s';", tabNamePool[tab_id], time_s, time_e);
|
|
|
+ switch(tab_id) {
|
|
|
+
|
|
|
+ case TAB_ID_POWER:
|
|
|
+ {
|
|
|
+ //
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case TAB_ID_POWER3:
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
|
|
|
- r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
|
|
|
- if (r != SQLITE_OK) {
|
|
|
- log_e("___db_requery 1, sqlite3_prepare_v2 failed\n");
|
|
|
- return -1;
|
|
|
+ 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);
|
|
|
+ tmp._power_info.voltage = sqlite3_column_double(stmt, 4);
|
|
|
+ tmp._power_info.current = sqlite3_column_double(stmt, 5);
|
|
|
+ tmp._power_info.power = sqlite3_column_double(stmt, 6);
|
|
|
+ tmp._power_info.freq = sqlite3_column_double(stmt, 7);
|
|
|
+ tmp._power_info.consumption = sqlite3_column_double(stmt, 8);
|
|
|
+ tmp._power_info.factor = sqlite3_column_double(stmt, 9);
|
|
|
+ strcpy(tmp.samp_time, (char*)sqlite3_column_text(stmt, 0));
|
|
|
+
|
|
|
+ xlist_append(l, tab_id, &tmp, sizeof(tmp));
|
|
|
+ }
|
|
|
+ sqlite3_finalize(stmt);
|
|
|
}
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
- xlist_append(l, 0, &pwr, sizeof(pwr));
|
|
|
+ break;
|
|
|
+
|
|
|
+ case TAB_ID_POWER3_INFO:
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ 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");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (sqlite3_step(stmt)==SQLITE_ROW) {
|
|
|
+ tmp.product_id = sqlite3_column_int(stmt, 1);
|
|
|
+ tmp.product_ph_type = sqlite3_column_int(stmt, 2);
|
|
|
+ tmp.product_ch_id = sqlite3_column_int(stmt, 3);
|
|
|
+ tmp._PowerInfo.voltage = sqlite3_column_double(stmt, 4);
|
|
|
+ tmp._PowerInfo.current = sqlite3_column_double(stmt, 5);
|
|
|
+ tmp._PowerInfo.power = sqlite3_column_double(stmt, 6);
|
|
|
+ tmp._PowerInfo.freq = sqlite3_column_double(stmt, 7);
|
|
|
+ tmp._PowerInfo.consumption = sqlite3_column_double(stmt, 8);
|
|
|
+ tmp._PowerInfo.factor = sqlite3_column_double(stmt, 9);
|
|
|
+ strcpy(tmp.samp_time, (char*)sqlite3_column_text(stmt, 10));
|
|
|
+
|
|
|
+ xlist_append(l, tab_id, &tmp, sizeof(tmp));
|
|
|
+ }
|
|
|
+ sqlite3_finalize(stmt);
|
|
|
}
|
|
|
- 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);
|
|
|
+ break;
|
|
|
|
|
|
- r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
|
|
|
- if (r != SQLITE_OK) {
|
|
|
- log_e("___db_requery 2, sqlite3_prepare_v2 failed\n");
|
|
|
- return -1;
|
|
|
+ case TAB_ID_LOG_INFO:
|
|
|
+ {
|
|
|
+ //
|
|
|
}
|
|
|
+ break;
|
|
|
|
|
|
- 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);
|
|
|
-
|
|
|
- xlist_append(l, 0, &pwr3, sizeof(pwr3));
|
|
|
+ case TAB_ID_ALARM_INFO:
|
|
|
+ {
|
|
|
+ //
|
|
|
}
|
|
|
- sqlite3_finalize(stmt);
|
|
|
- }
|
|
|
- else if(tab_id==TAB_ID_LOG_INFO) {
|
|
|
- //
|
|
|
- }
|
|
|
- else if(tab_id==TAB_ID_ALARM_INFO) {
|
|
|
- //
|
|
|
- }
|
|
|
- else if(tab_id==TAB_ID_SENSOR) {
|
|
|
- //
|
|
|
- }
|
|
|
- else if(tab_id==TAB_ID_SENSOR_INFO) {
|
|
|
- //sprintf(select_sql,"SELECT* FROM Table_SensorInfo WHERE (sensor_id=%d) AND (sensor_samp_time BETWEEN '%s' AND '%s') ORDER BY sensor_samp_time DESC LIMIT %d OFFSET %d;",
|
|
|
- //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);
|
|
|
+ break;
|
|
|
|
|
|
- }
|
|
|
- else {
|
|
|
+ case TAB_ID_SENSOR:
|
|
|
+ {
|
|
|
+ GlobalSensorManger tmp;
|
|
|
+
|
|
|
+ snprintf(temp, sizeof(temp), "SELECT * FROM %s;", tabNamePool[tab_id]);
|
|
|
+ r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
|
|
|
+ if (r != SQLITE_OK) {
|
|
|
+ log_e("___db_requery TAB_ID_SENSOR, sqlite3_prepare_v2 failed\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
+ tmp.sensor_id = sqlite3_column_int(stmt, 1);
|
|
|
+ tmp.product_id = sqlite3_column_int(stmt, 2);
|
|
|
+ tmp.sensor_type = sqlite3_column_int(stmt, 3);
|
|
|
+ tmp.sensor_interface_type = sqlite3_column_int(stmt, 4);
|
|
|
+
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 5);
|
|
|
+ tmp.sensor_name[0] = 0;
|
|
|
+ if(p) strcpy(tmp.sensor_name, p);
|
|
|
+
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 6);
|
|
|
+ tmp.sensor_port_name[0] = 0;
|
|
|
+ if(p) strcpy(tmp.sensor_port_name, p);
|
|
|
+
|
|
|
+ tmp.sensor_baud = 0;
|
|
|
+ if(tmp.sensor_interface_type==1) {
|
|
|
+ tmp.sensor_baud = sqlite3_column_int(stmt, 7);
|
|
|
+ }
|
|
|
+ tmp.sensor_addr = sqlite3_column_int(stmt, 8);
|
|
|
+
|
|
|
+ tmp.sensor_status = 1;
|
|
|
+ tmp.sensor_val_count = sqlite3_column_int(stmt, 10);
|
|
|
+
|
|
|
+ tmp.over_manager->sensor_val1_upper_enabled = sqlite3_column_int(stmt, 11);
|
|
|
+ tmp.over_manager->sensor_val1_upper_threshold = sqlite3_column_double(stmt, 12);
|
|
|
+ tmp.over_manager->sensor_val1_upper_threshold_ctrl = sqlite3_column_int(stmt, 13);
|
|
|
+
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 14);
|
|
|
+ tmp.over_manager->sensor_val1_upper_threshold_ctrl_para[0] = 0;
|
|
|
+ if(p) strcpy(tmp.over_manager->sensor_val1_upper_threshold_ctrl_para, p);
|
|
|
+
|
|
|
+ tmp.over_manager->sensor_val1_lower_enabled = sqlite3_column_int(stmt, 15);
|
|
|
+ tmp.over_manager->sensor_val1_lower_threshold = sqlite3_column_double(stmt, 16);
|
|
|
+ tmp.over_manager->sensor_val1_lower_threshold_ctrl = sqlite3_column_int(stmt, 17);
|
|
|
+
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 18);
|
|
|
+ tmp.over_manager->sensor_val1_lower_threshold_ctrl_para[0] = 0;
|
|
|
+ if(p) strcpy(tmp.over_manager->sensor_val1_lower_threshold_ctrl_para, p);
|
|
|
+
|
|
|
+ tmp.over_manager->sensor_val2_upper_enabled = sqlite3_column_int(stmt, 19);
|
|
|
+ tmp.over_manager->sensor_val2_upper_threshold = sqlite3_column_double(stmt, 20);
|
|
|
+ tmp.over_manager->sensor_val2_upper_threshold_ctrl = sqlite3_column_int(stmt, 21);
|
|
|
+
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 22);
|
|
|
+ tmp.over_manager->sensor_val2_upper_threshold_ctrl_para[0] = 0;
|
|
|
+ if(p) strcpy(tmp.over_manager->sensor_val2_upper_threshold_ctrl_para, p);
|
|
|
+
|
|
|
+ tmp.over_manager->sensor_val2_lower_enabled = sqlite3_column_int(stmt, 23);
|
|
|
+ tmp.over_manager->sensor_val2_lower_threshold = sqlite3_column_double(stmt, 24);
|
|
|
+ tmp.over_manager->sensor_val2_lower_threshold_ctrl = sqlite3_column_int(stmt, 25);
|
|
|
+
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 26);
|
|
|
+ tmp.over_manager->sensor_val2_lower_threshold_ctrl_para[0] = 0;
|
|
|
+ if(p) strcpy(tmp.over_manager->sensor_val2_lower_threshold_ctrl_para, p);
|
|
|
+
|
|
|
+ xlist_append(l, tab_id, &tmp, sizeof(tmp));
|
|
|
+ }
|
|
|
+ sqlite3_finalize(stmt);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case TAB_ID_SENSOR_INFO:
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ r = sqlite3_prepare_v2(db, temp, -1, &stmt, 0);
|
|
|
+ if (r != SQLITE_OK) {
|
|
|
+ log_e("___db_requery 2, sqlite3_prepare_v2 failed\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
+ p = (char*)sqlite3_column_text(stmt, 2);
|
|
|
+ tmp.samp_time[0] = 0;
|
|
|
+ if(p) strcpy(tmp.samp_time, p);
|
|
|
+
|
|
|
+ tmp.product_id = sqlite3_column_int(stmt, 3);
|
|
|
+ tmp.sensor_id = sqlite3_column_int(stmt, 4);
|
|
|
+ tmp.val1 = sqlite3_column_double(stmt, 5);
|
|
|
+ tmp.val2 = sqlite3_column_double(stmt, 6);
|
|
|
+
|
|
|
+ xlist_append(l, tab_id, &tmp, sizeof(tmp));
|
|
|
+ }
|
|
|
+ sqlite3_finalize(stmt);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int db_data_io(sqlite3 *db, int tab_id, int io_type, time_t from, time_t to, void *data)
|
|
|
+static node_t* get_node2(handle_t l, int tp)
|
|
|
+{
|
|
|
+ int r;
|
|
|
+ node_t *nd=NULL;
|
|
|
+ list_node_t *ln=NULL;
|
|
|
+ for(int i=0;i<xlist_size(l); i++) {
|
|
|
+ r = xlist_get_node(l, &ln, i);
|
|
|
+ if(r==0 && ln->data.tp==tp) {
|
|
|
+ nd = &ln->data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nd;
|
|
|
+}
|
|
|
+int dev_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 || (io_type==IO_IMPORT && !data)) {
|
|
|
+ if(tab_id<TAB_ID_NTP || tab_id>=TAB_ID_MAX || io_type<0 || io_type>=IO_MAX) {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -4853,11 +4982,12 @@ static int db_data_io(sqlite3 *db, int tab_id, int io_type, time_t from, time_t
|
|
|
case TAB_ID_POWER:
|
|
|
{
|
|
|
if(io_type==IO_IMPORT) {
|
|
|
- //r = dev_update_t_ac_power_manage_info(db, 0, (NTPManager*)data);
|
|
|
- //dev_update_t_ac_power_manage_over_info(db, 0, (NTPManager*)data);
|
|
|
+ //r = dev_update_power_manage_genera_info(db, 0, (GlobalPowerManger*)data);
|
|
|
+ //r = dev_update_power_manage_genera_info_addr(db, 0, (GlobalPowerManger*)data);
|
|
|
+ //r = dev_update_power_manage_over_info(db, 0, (GlobalPowerManger*)data);
|
|
|
}
|
|
|
else {
|
|
|
- //r = dev_get_power_manage_info(db, (NTPManager*)data);
|
|
|
+ //r = dev_get_power_manage_info(db, (GlobalPowerManger*)data);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -4865,11 +4995,11 @@ static int db_data_io(sqlite3 *db, int tab_id, int io_type, time_t from, time_t
|
|
|
case TAB_ID_POWER3:
|
|
|
{
|
|
|
if(io_type==IO_IMPORT) {
|
|
|
- //r = dev_update_t_ac_power_manage_info(db, 0, (NTPManager*)data);
|
|
|
- //dev_update_t_ac_power_manage_over_info(db, 0, (NTPManager*)data);
|
|
|
+ //r = dev_update_t_ac_power_manage_info(db, 0, (GlobalTreeACManager*)data);
|
|
|
+ //r = dev_update_t_ac_power_manage_over_info(db, 0, (GlobalTreeACManager*)data);
|
|
|
}
|
|
|
else {
|
|
|
- //r = dev_get_t_ac_power_manage_info(db, (NTPManager*)data);
|
|
|
+ //r = dev_get_t_ac_power_manage_info(db, 0, (GlobalTreeACManager*)data);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -4916,7 +5046,7 @@ static int db_data_io(sqlite3 *db, int tab_id, int io_type, time_t from, time_t
|
|
|
{
|
|
|
if(io_type==IO_EXPORT) {
|
|
|
handle_t l=(handle_t)data;
|
|
|
- db_requery(db, tab_id, from, to, l);
|
|
|
+ db_exec(db, tab_id, io_type, from, to, l);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -4925,12 +5055,13 @@ static int db_data_io(sqlite3 *db, int tab_id, int io_type, time_t from, time_t
|
|
|
return 0;
|
|
|
}
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
-static int sensor_xport(sqlite3 *db, int io_type, char *path)
|
|
|
+int dev_sensor_xport(sqlite3 *db, int io_type, char *path)
|
|
|
{
|
|
|
int i,r;
|
|
|
handle_t l;
|
|
|
list_node_t *ln;
|
|
|
list_cfg_t lc={0,0,-1};
|
|
|
+ GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
|
|
|
l = xlist_init(&lc);
|
|
|
|
|
|
@@ -4948,12 +5079,13 @@ static int sensor_xport(sqlite3 *db, int io_type, char *path)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-static int alarm_xport(int io_type, char *path)
|
|
|
+int dev_alarm_xport(int io_type, char *path)
|
|
|
{
|
|
|
int i,r;
|
|
|
handle_t l;
|
|
|
list_node_t *ln;
|
|
|
list_cfg_t lc={0,0,-1};
|
|
|
+ GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
|
|
|
l = xlist_init(&lc);
|
|
|
|
|
|
@@ -4972,12 +5104,13 @@ static int alarm_xport(int io_type, char *path)
|
|
|
sprintf(path, "/tmp/alarm.ini");
|
|
|
return 0;
|
|
|
}
|
|
|
-static int serv_xport(int io_type, char *path)
|
|
|
+int dev_serv_xport(int io_type, char *path)
|
|
|
{
|
|
|
int i,r;
|
|
|
handle_t l;
|
|
|
list_node_t *ln;
|
|
|
list_cfg_t lc={0,0,-1};
|
|
|
+ GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
|
|
|
l = xlist_init(&lc);
|
|
|
|
|
|
@@ -4991,18 +5124,17 @@ static int serv_xport(int io_type, char *path)
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
sprintf(path, "/tmp/serv.ini");
|
|
|
return 0;
|
|
|
}
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
-static int log_xport(int period, char *path)
|
|
|
+int dev_log_xport(int type, time_t from, time_t to, char *path)
|
|
|
{
|
|
|
int i,r;
|
|
|
handle_t l;
|
|
|
list_node_t *ln;
|
|
|
list_cfg_t lc={0,0,-1};
|
|
|
+ GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
|
|
|
l = xlist_init(&lc);
|
|
|
|
|
|
@@ -5021,29 +5153,99 @@ static int log_xport(int period, char *path)
|
|
|
sprintf(path, "/tmp/log.txt");
|
|
|
return 0;
|
|
|
}
|
|
|
-static int power_xport(int period, char *path)
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ FILE *fp;
|
|
|
+ int id;
|
|
|
+}pwr_arg_t;
|
|
|
+static void replace_chr(char *buf, char a, char b)
|
|
|
{
|
|
|
- int i,r;
|
|
|
+ while(*buf) {
|
|
|
+ if((*buf)==a) {
|
|
|
+ *buf = b;
|
|
|
+ }
|
|
|
+ buf++;
|
|
|
+ }
|
|
|
+}
|
|
|
+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;
|
|
|
+ if(xd->tp==TAB_ID_POWER_INFO) {
|
|
|
+ GlobalPowerInfo *tmp=(GlobalPowerInfo*)xd->buf;
|
|
|
+
|
|
|
+ fprintf(parg->fp, "%d,", parg->id);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->product_id);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->product_ch_id);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_power_info.voltage);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_power_info.current);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_power_info.power);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_power_info.freq);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_power_info.consumption);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_power_info.factor);
|
|
|
+
|
|
|
+ replace_chr(tmp->samp_time, '-', '.');
|
|
|
+ fprintf(parg->fp, "%s,", tmp->samp_time);
|
|
|
+ fprintf(parg->fp, "\n");
|
|
|
+ parg->id++;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ GlobalTreeACManager *tmp=(GlobalTreeACManager*)xd->buf;
|
|
|
+ fprintf(parg->fp, "%d,", parg->id);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->product_id);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->product_ph_type);
|
|
|
+ fprintf(parg->fp, "%d,", tmp->product_ch_id);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_PowerInfo.voltage);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_PowerInfo.current);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_PowerInfo.power);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_PowerInfo.freq);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_PowerInfo.consumption);
|
|
|
+ fprintf(parg->fp, "%0.2f,", tmp->_PowerInfo.factor);
|
|
|
+
|
|
|
+ replace_chr(tmp->samp_time, '-', '.');
|
|
|
+ fprintf(parg->fp, "%s,", tmp->samp_time);
|
|
|
+ fprintf(parg->fp, "\n");
|
|
|
+ parg->id++;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+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;
|
|
|
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);
|
|
|
|
|
|
l = xlist_init(&lc);
|
|
|
-
|
|
|
- //
|
|
|
+ r = db_exec(dm->db, tab_id, IO_EXPORT, from, to, l);
|
|
|
|
|
|
- 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) {
|
|
|
+ if(tab_id==TAB_ID_POWER_INFO) {
|
|
|
+ fprintf(fp, "id,product_id,product_ch_id,voltage,current,power,freq,consumption,factor,samp_time\n");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ fprintf(fp, "id,product_id,product_ph_type,product_ch_id,voltage,current,power,freq,consumption,factor,samp_time\n");
|
|
|
}
|
|
|
|
|
|
+ arg.fp = fp; arg.id = 1;
|
|
|
+ xlist_iterator(l, NULL, pwr_iterator_fn, &arg);
|
|
|
+ fclose(fp);
|
|
|
+ r = 0;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- sprintf(path, "/tmp/log.txt");
|
|
|
- return 0;
|
|
|
+ else {
|
|
|
+ printf("__%s open failed\n", path);
|
|
|
+ }
|
|
|
+ xlist_free(l);
|
|
|
+
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
|