|
|
@@ -18,6 +18,30 @@
|
|
|
|
|
|
#define TOTAL_COUNT 60
|
|
|
#define FN_MAX 30
|
|
|
+
|
|
|
+enum {
|
|
|
+ FILE_IMPORT=0,
|
|
|
+ FILE_EXPORT,
|
|
|
+};
|
|
|
+enum {
|
|
|
+ FILE_SYS_CFG=0,
|
|
|
+ FILE_SERV_CFG,
|
|
|
+ FILE_ALARM_CFG,
|
|
|
+ FILE_SENDOR_CFG,
|
|
|
+
|
|
|
+ FILE_POWER_ALL,
|
|
|
+ FILE_POWER_CHN,
|
|
|
+
|
|
|
+ FILE_LOG_RUN,
|
|
|
+ FILE_LOG_OPERA,
|
|
|
+ FILE_LOG_ALARM,
|
|
|
+
|
|
|
+ FILE_LOGO,
|
|
|
+ FILE_HOST_FW,
|
|
|
+ FILE_POWER_FW,
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
typedef void (*http_fn_t)(void *arg);
|
|
|
|
|
|
typedef struct {
|
|
|
@@ -95,14 +119,13 @@ static int upload_file(void *conn, char *path)
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
-static int download_file(void *conn, char *path, int remove)
|
|
|
+static int download_file(void *conn, char *path)
|
|
|
{
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
|
|
|
|
|
|
struct mg_http_serve_opts opts = {.root_dir = NULL};
|
|
|
mg_http_serve_file(s->c, hm, path, &opts);
|
|
|
- if(remove) file_remove(path);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -125,11 +148,11 @@ static void httpAddCallback(char *uri, http_fn_t f)
|
|
|
h->cnt++;
|
|
|
}
|
|
|
}
|
|
|
-static int save_to_csv(char *path, status_data_t *data, int flag)
|
|
|
+static int power_to_csv(char *path, status_data_t *data, int ftype)
|
|
|
{
|
|
|
int i=0;
|
|
|
FILE *fp=NULL;
|
|
|
- _OverAllPwrAckInfo *info=(flag==0)?&data->all:&data->chn;
|
|
|
+ _OverAllPwrAckInfo *info=(ftype==FILE_POWER_ALL)?&data->all:&data->chn;
|
|
|
|
|
|
fp = fopen(path, "wt");
|
|
|
if(!fp) {
|
|
|
@@ -175,88 +198,177 @@ static int save_to_csv(char *path, status_data_t *data, int flag)
|
|
|
fclose(fp);
|
|
|
return 0;
|
|
|
}
|
|
|
-static int export_power(void *conn, int flag)
|
|
|
+static int file_io(void *conn, int ftype, int io)
|
|
|
{
|
|
|
int r;
|
|
|
char path[200];
|
|
|
web_handle_t *wh=&webHandle;
|
|
|
-
|
|
|
- sprintf(path, "%s.csv", (flag==0)?"overall":"channel");
|
|
|
- r = save_to_csv(path, &wh->stt, flag);
|
|
|
- if(r==0) {
|
|
|
- download_file(conn, path, 1);
|
|
|
- }
|
|
|
-
|
|
|
- return r;
|
|
|
-}
|
|
|
-
|
|
|
-static int import_misc(void *conn, int flag)
|
|
|
-{
|
|
|
- char path[200];
|
|
|
- web_handle_t *wh=&webHandle;
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
|
|
|
+return -1;
|
|
|
+ switch(ftype) {
|
|
|
+ case FILE_SYS_CFG:
|
|
|
+ {
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ sys_get_path(path, "tmp.ini");
|
|
|
+ r = upload_file(conn, path);
|
|
|
+ if(r==0) {
|
|
|
+ r = paras_check(path);
|
|
|
+ if(r==0) {
|
|
|
+ r = paras_load(path);
|
|
|
+ if(r==0) {
|
|
|
+ //clear some database table
|
|
|
+ //exit(0); //restart smartPDU
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ file_remove(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sys_get_path(path, INI_FILE_NAME);
|
|
|
+ download_file(conn, path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- switch(flag) {
|
|
|
- case 0: //sensor
|
|
|
+ case FILE_SERV_CFG:
|
|
|
{
|
|
|
- //upload_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //download_file(path);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 1: //alarm
|
|
|
+ case FILE_ALARM_CFG:
|
|
|
{
|
|
|
- //upload_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //download_file(path);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 2: //service
|
|
|
+ case FILE_SENDOR_CFG:
|
|
|
{
|
|
|
- //upload_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //download_file(path);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 3: //config
|
|
|
+ case FILE_POWER_ALL:
|
|
|
{
|
|
|
- //upload_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sprintf(path, "%s.csv", "overall");
|
|
|
+ r = power_to_csv(path, &wh->stt, ftype);
|
|
|
+ if(r==0) {
|
|
|
+ download_file(conn, path);
|
|
|
+ file_remove(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
- }
|
|
|
|
|
|
- return 0;
|
|
|
-}
|
|
|
+ case FILE_POWER_CHN:
|
|
|
+ {
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sprintf(path, "%s.csv", "channel");
|
|
|
+ r = power_to_csv(path, &wh->stt, ftype);
|
|
|
+ if(r==0) {
|
|
|
+ download_file(conn, path);
|
|
|
+ file_remove(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case FILE_LOG_RUN:
|
|
|
+ {
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //download_file(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
-static int export_misc(void *conn, int flag)
|
|
|
-{
|
|
|
- char path[200];
|
|
|
- web_handle_t *wh=&webHandle;
|
|
|
- mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
- struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
|
|
|
+ case FILE_LOG_OPERA:
|
|
|
+ {
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //download_file(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- switch(flag) {
|
|
|
- case 0: //sensor
|
|
|
+ case FILE_LOG_ALARM:
|
|
|
{
|
|
|
- //download_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ //upload_file(path);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //download_file(path);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 1: //alarm
|
|
|
+ case FILE_LOGO:
|
|
|
{
|
|
|
- //download_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ char tmp[100];
|
|
|
+ sprintf(tmp, "%s/%s", IMAGE_FOLDER, LOGO_FILE);
|
|
|
+ sys_get_path(path, tmp);
|
|
|
+ upload_file(conn, path);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 2: //service
|
|
|
+ case FILE_HOST_FW:
|
|
|
{
|
|
|
- //download_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ sprintf(path, "%s/%s", DOWN_FOLDER, UPG_PKG_NAME);
|
|
|
+ r = upload_file(conn, path);
|
|
|
+ if(r==0) {
|
|
|
+ printf("_____ upg_start\n");
|
|
|
+ upg_start();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case 3: //config
|
|
|
+ case FILE_POWER_FW:
|
|
|
{
|
|
|
- //download_file(path);
|
|
|
+ if(io==FILE_IMPORT) {
|
|
|
+ sprintf(path, "%s/%s", DOWN_FOLDER, "power.bin");
|
|
|
+ r = upload_file(conn, path);
|
|
|
+ if(r==0) {
|
|
|
+ printf("_____ power upgrade now ...\n");
|
|
|
+ //power_upgrade(path);
|
|
|
+ //file_remove(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
@@ -536,7 +648,7 @@ static void overallStatusMonitoring(void* conn)
|
|
|
if(cjson==NULL)
|
|
|
{
|
|
|
if (strstr(hm->uri.buf,"type=export")) {
|
|
|
- export_power(conn, 0);
|
|
|
+ file_io(conn, FILE_POWER_ALL, FILE_EXPORT);
|
|
|
|
|
|
}
|
|
|
else {
|
|
|
@@ -1139,7 +1251,7 @@ static void channelStatusMonitoring(void* conn)
|
|
|
if(cjson==NULL)
|
|
|
{
|
|
|
if (strstr(hm->uri.buf,"type=export")) {
|
|
|
- export_power(conn, 1);
|
|
|
+ file_io(conn, FILE_POWER_CHN, FILE_EXPORT);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
@@ -3293,7 +3405,7 @@ static void logInformation(void *conn)
|
|
|
INIT_LIST_HEAD(&_alarm_ack_info.list);
|
|
|
|
|
|
|
|
|
- if(__logInformationRequestInfo.beginTime==NULL || __logInformationRequestInfo.endtime==NULL)
|
|
|
+ if(__logInformationRequestInfo.startTime==NULL || __logInformationRequestInfo.endtime==NULL)
|
|
|
{
|
|
|
struct tm* t ;
|
|
|
struct timeval tv;
|
|
|
@@ -3334,7 +3446,7 @@ static void logInformation(void *conn)
|
|
|
dev_search_alarm_info(__globalDeviceManage.db,
|
|
|
__globalDeviceManage._globalDevInfo.product.id,
|
|
|
0, //注意注意 此处需要查询的参数是0 1 2
|
|
|
- __logInformationRequestInfo.beginTime,//启动时间
|
|
|
+ __logInformationRequestInfo.startTime,//开始时间
|
|
|
__logInformationRequestInfo.endtime, //结束时间
|
|
|
__logInformationRequestInfo.pagenum-1, //页
|
|
|
__logInformationRequestInfo.pagesize, //条
|
|
|
@@ -3354,17 +3466,14 @@ static void logInformation(void *conn)
|
|
|
//转换参数
|
|
|
//ack_str = alarm_type_info_to_json(&_alarm_ack_info);
|
|
|
}
|
|
|
- else if(strcmp(__logInformationRequestInfo.type,"exportJgrz")==0) //导出告警日志
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
+
|
|
|
else if(strcmp(__logInformationRequestInfo.type,"listCzrzQuery")==0) //操作日志
|
|
|
{
|
|
|
//初始化表
|
|
|
INIT_LIST_HEAD(&_alarm_ack_info.list);
|
|
|
|
|
|
//默认查当天日志
|
|
|
- if(__logInformationRequestInfo.beginTime==NULL || __logInformationRequestInfo.endtime==NULL)
|
|
|
+ if(__logInformationRequestInfo.startTime==NULL || __logInformationRequestInfo.endtime==NULL)
|
|
|
{
|
|
|
struct tm* t ;
|
|
|
struct timeval tv;
|
|
|
@@ -3393,7 +3502,7 @@ static void logInformation(void *conn)
|
|
|
dev_search_alarm_info(__globalDeviceManage.db,
|
|
|
__globalDeviceManage._globalDevInfo.product.id,
|
|
|
ALARM_TYPE_OPRATION,// alarm_type, 操作日志
|
|
|
- __logInformationRequestInfo.beginTime,
|
|
|
+ __logInformationRequestInfo.startTime,
|
|
|
__logInformationRequestInfo.endtime,
|
|
|
__logInformationRequestInfo.pagenum-1,
|
|
|
__logInformationRequestInfo.pagesize,
|
|
|
@@ -3411,16 +3520,12 @@ static void logInformation(void *conn)
|
|
|
free(node);
|
|
|
}
|
|
|
}
|
|
|
- else if(strcmp(__logInformationRequestInfo.type,"exportCzrz")==0) //导出操作日志
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
else if(strcmp(__logInformationRequestInfo.type,"listYxrzQuery")==0) //运行日志
|
|
|
{
|
|
|
//初始化表
|
|
|
INIT_LIST_HEAD(&_alarm_ack_info.list);
|
|
|
//默认查当天日志
|
|
|
- if(__logInformationRequestInfo.beginTime==NULL || __logInformationRequestInfo.endtime==NULL)
|
|
|
+ if(__logInformationRequestInfo.startTime==NULL || __logInformationRequestInfo.endtime==NULL)
|
|
|
{
|
|
|
struct tm *t;
|
|
|
struct timeval tv;
|
|
|
@@ -3449,7 +3554,7 @@ static void logInformation(void *conn)
|
|
|
dev_search_alarm_info(__globalDeviceManage.db,
|
|
|
__globalDeviceManage._globalDevInfo.product.id,
|
|
|
ALARM_TYPE_RUNNING, // alarm_type, 运行日志
|
|
|
- __logInformationRequestInfo.beginTime,
|
|
|
+ __logInformationRequestInfo.startTime,
|
|
|
__logInformationRequestInfo.endtime,
|
|
|
__logInformationRequestInfo.pagenum - 1,
|
|
|
__logInformationRequestInfo.pagesize,
|
|
|
@@ -3466,10 +3571,18 @@ static void logInformation(void *conn)
|
|
|
free(node);
|
|
|
}
|
|
|
}
|
|
|
- else if(strcmp(__logInformationRequestInfo.type,"exportYxrz")==0) //导出运行日志 导出方式->
|
|
|
+ else if(strcmp(__logInformationRequestInfo.type,"exportCzrz")==0) //导出操作日志
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(strcmp(__logInformationRequestInfo.type,"exportYxrz")==0) //导出运行日志
|
|
|
{
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+ else if(strcmp(__logInformationRequestInfo.type,"exportJgrz")==0) //导出告警日志
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
|
|
|
cJSON_Delete(cjson);
|
|
|
http_reply(conn, 200, ack_str);
|
|
|
@@ -3667,6 +3780,7 @@ static void serviceManagement(void *conn)
|
|
|
dev_smtp_update_recv(gdm->db, &recv[i]);
|
|
|
}
|
|
|
}
|
|
|
+#ifdef USE_MQTT
|
|
|
else if(strcmp(_serviceManageRequestInfo.type,"listMqttQuery")==0)
|
|
|
{
|
|
|
ack_str = service_mqtt_ack_to_json(&gdm->mqttInfo);
|
|
|
@@ -3700,6 +3814,7 @@ static void serviceManagement(void *conn)
|
|
|
dev_mqtt_update_ser(gdm->db, ser);
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
else if(strcmp(_serviceManageRequestInfo.type,"listSnmpQuery")==0)
|
|
|
{
|
|
|
// 查询SNMP信息
|
|
|
@@ -5321,23 +5436,19 @@ static void equipmentMintenance(void *conn)
|
|
|
static void equipmentMintenanceUpload(void *conn)
|
|
|
{
|
|
|
int r = -1 ;
|
|
|
- char* ack_str = NULL ;
|
|
|
+ char* ack_str=NULL ;
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *hm=s->ev_data;
|
|
|
char path[200],tmp[60];
|
|
|
|
|
|
if(strstr(hm->uri.buf, "uploadType=gjsj")) { //firmware upload
|
|
|
- sprintf(path, "%s/%s", DOWN_FOLDER, UPG_PKG_NAME);
|
|
|
- r = upload_file(conn, path);
|
|
|
- if(r==0) {
|
|
|
- printf("_____ upg_start\n");
|
|
|
- upg_start();
|
|
|
- }
|
|
|
+ file_io(conn, FILE_HOST_FW, FILE_IMPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=shfw")) { //logo upload
|
|
|
- sprintf(tmp, "%s/%s", IMAGE_PATH, LOGO_FILE);
|
|
|
- sys_get_path(path, tmp);
|
|
|
- upload_file(conn, path);
|
|
|
+ file_io(conn, FILE_LOGO, FILE_IMPORT);
|
|
|
+ }
|
|
|
+ else if(strstr(hm->uri.buf, "uploadType=2")) { //sensor config
|
|
|
+ //file_io(conn, FILE_SENDOR_CFG, FILE_IMPORT);
|
|
|
}
|
|
|
|
|
|
ack_str = ctrl_sts_ack_to_json();
|
|
|
@@ -5348,35 +5459,33 @@ static void equipmentMintenanceUpload(void *conn)
|
|
|
static void equipmentMintenanceExport(void *conn)
|
|
|
{
|
|
|
int r = -1 ;
|
|
|
- char* ack_str = NULL ;
|
|
|
+ char* ack_str=NULL ;
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *hm=s->ev_data;
|
|
|
- char *rx_body_buf = (char*)hm->body.buf;
|
|
|
- char path[200];
|
|
|
|
|
|
- if(strstr(hm->uri.buf, "export=0")) {
|
|
|
- export_misc(conn, 0);
|
|
|
+ if(strstr(hm->uri.buf, "export=2")) {
|
|
|
+ file_io(conn, FILE_SENDOR_CFG, FILE_EXPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "export=1")) {
|
|
|
- export_misc(conn, 1);
|
|
|
+ file_io(conn, FILE_ALARM_CFG, FILE_EXPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "export=2")) {
|
|
|
- export_misc(conn, 2);
|
|
|
+ file_io(conn, FILE_SERV_CFG, FILE_EXPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "export=3")) {
|
|
|
- export_misc(conn, 3);
|
|
|
+ file_io(conn, FILE_SYS_CFG, FILE_EXPORT);
|
|
|
}
|
|
|
- else if(strstr(hm->uri.buf, "uploadType=0")) {
|
|
|
- import_misc(conn, 0);
|
|
|
+ else if(strstr(hm->uri.buf, "uploadType=7")) {
|
|
|
+ file_io(conn, FILE_SENDOR_CFG, FILE_IMPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=1")) {
|
|
|
- import_misc(conn, 1);
|
|
|
+ file_io(conn, FILE_ALARM_CFG, FILE_IMPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=2")) {
|
|
|
- import_misc(conn, 2);
|
|
|
+ file_io(conn, FILE_SERV_CFG, FILE_IMPORT);
|
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=3")) {
|
|
|
- import_misc(conn, 3);
|
|
|
+ file_io(conn, FILE_SYS_CFG, FILE_IMPORT);
|
|
|
}
|
|
|
}
|
|
|
|