|
@@ -150,83 +150,80 @@ static void httpAddCallback(char *uri, http_fn_t f)
|
|
|
h->cnt++;
|
|
h->cnt++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-static int power_to_csv(char *path, status_data_t *data, int ftype)
|
|
|
|
|
|
|
+
|
|
|
|
|
+static time_t gettime(char *timestr)
|
|
|
{
|
|
{
|
|
|
- int i=0;
|
|
|
|
|
- FILE *fp=NULL;
|
|
|
|
|
- _OverAllPwrAckInfo *info=((ftype==FILE_POWER_ALL)?(&data->all):(&data->chn));
|
|
|
|
|
-
|
|
|
|
|
- fp = fopen(path, "wt");
|
|
|
|
|
- if(!fp) {
|
|
|
|
|
|
|
+ int r;
|
|
|
|
|
+ struct tm tm={0};
|
|
|
|
|
+ //2024-10-29 05:19:09
|
|
|
|
|
+ r = sscanf(timestr, "%d-%d-%d %d:%d:%d", &tm.tm_year,&tm.tm_mon,&tm.tm_mday,&tm.tm_hour,&tm.tm_min,&tm.tm_sec);
|
|
|
|
|
+ if(r<6) {
|
|
|
return -1;
|
|
return -1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total voltage time,");
|
|
|
|
|
- fprintf(fp, "%s,", info->_total_voltage.xAxis[i]);
|
|
|
|
|
- } fprintf(fp, "\n");
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total voltage value,");
|
|
|
|
|
- fprintf(fp, "%.8f,", info->_total_voltage.ydata[i]);
|
|
|
|
|
- } fprintf(fp, "\n\n");
|
|
|
|
|
-
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total current time,");
|
|
|
|
|
- fprintf(fp, "%s,", info->_total_current.xAxis[i]);
|
|
|
|
|
- } fprintf(fp, "\n");
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total current value,");
|
|
|
|
|
- fprintf(fp, "%.8f,", info->_total_current.ydata[i]);
|
|
|
|
|
- } fprintf(fp, "\n\n");
|
|
|
|
|
-
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total power time,");
|
|
|
|
|
- fprintf(fp, "%s,", info->_total_power.xAxis[i]);
|
|
|
|
|
- } fprintf(fp, "\n");
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total power value,");
|
|
|
|
|
- fprintf(fp, "%.8f,", info->_total_power.ydata[i]);
|
|
|
|
|
- } fprintf(fp, "\n\n");
|
|
|
|
|
-
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total consum time,");
|
|
|
|
|
- fprintf(fp, "%s,", info->_total_consumption.xAxis[i]);
|
|
|
|
|
- } fprintf(fp, "\n");
|
|
|
|
|
- for(i=0; i<TOTAL_COUNT; i++) {
|
|
|
|
|
- if(i==0) fprintf(fp, "total consum value,");
|
|
|
|
|
- fprintf(fp, "%.8f,", info->_total_consumption.ydata[i]);
|
|
|
|
|
- } fprintf(fp, "\n\n");
|
|
|
|
|
-
|
|
|
|
|
- fclose(fp);
|
|
|
|
|
|
|
+ tm.tm_year -= 1900;
|
|
|
|
|
+ tm.tm_mon -= 1;
|
|
|
|
|
+ return mktime(&tm);
|
|
|
|
|
+}
|
|
|
|
|
+static int gettime2(char *buf, char *tok, char *timestr)
|
|
|
|
|
+{
|
|
|
|
|
+ char *p=strstr(buf, tok);
|
|
|
|
|
+ if(!p) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ p += strlen(tok);
|
|
|
|
|
+ memcpy(timestr, p, 10); timestr[10] = ' ';
|
|
|
|
|
+ memcpy(timestr+11, p+13, 8); timestr[19] = 0;
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-static int get_range(time_t *from, time_t *to, int days)
|
|
|
|
|
|
|
+static int get_range(time_t *from, time_t *to, char *start, char *end, int max_days)
|
|
|
{
|
|
{
|
|
|
- struct timeval tv;
|
|
|
|
|
- struct timezone tz;
|
|
|
|
|
- time_t cur=time(NULL);
|
|
|
|
|
- struct tm *tm=localtime(&cur);
|
|
|
|
|
- time_t start=mktime0(),secs=3600*24*days;
|
|
|
|
|
|
|
+ time_t cur=gettime(start);
|
|
|
|
|
+ time_t pre=gettime(end);
|
|
|
|
|
+ time_t sss=mktime0(),secs=3600*24*max_days;
|
|
|
|
|
+
|
|
|
|
|
+ if(cur<=sss) {
|
|
|
|
|
+ cur = sss;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if((cur-start)<=secs) {
|
|
|
|
|
- *from = start;
|
|
|
|
|
- printf("____ 1111 %ld\n", *from);
|
|
|
|
|
|
|
+ if(pre<=sss) {
|
|
|
|
|
+ pre = sss;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(abs(cur-pre)>=secs) {
|
|
|
|
|
+ if(cur>pre) {
|
|
|
|
|
+ *from = cur-secs;
|
|
|
|
|
+ *to = cur;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ *from = pre-secs;
|
|
|
|
|
+ *to = pre;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- *from = cur-secs-1;
|
|
|
|
|
- printf("____ 2222 %ld\n", *from);
|
|
|
|
|
|
|
+ if(cur>pre) {
|
|
|
|
|
+ *from = pre;
|
|
|
|
|
+ *to = cur;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ *from = cur;
|
|
|
|
|
+ *to = pre;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- *to = cur;
|
|
|
|
|
|
|
+
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
-static int power_export(char *path)
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+static int power_export(char *path, char *start, char *end)
|
|
|
{
|
|
{
|
|
|
int r,type=0;
|
|
int r,type=0;
|
|
|
time_t from,to;
|
|
time_t from,to;
|
|
|
char tmp1[100],tmp2[100];
|
|
char tmp1[100],tmp2[100];
|
|
|
GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
GlobalDeviceManager *dm=&__globalDeviceManage;
|
|
|
|
|
|
|
|
- get_range(&from, &to, 7);
|
|
|
|
|
|
|
+ get_range(&from, &to, start, end, 7);
|
|
|
get_time_str2(tmp1,sizeof(tmp1),from);
|
|
get_time_str2(tmp1,sizeof(tmp1),from);
|
|
|
get_time_str2(tmp2,sizeof(tmp2),to);
|
|
get_time_str2(tmp2,sizeof(tmp2),to);
|
|
|
sprintf(path, "/tmp/power_%s_%s.csv", tmp1, tmp2);
|
|
sprintf(path, "/tmp/power_%s_%s.csv", tmp1, tmp2);
|
|
@@ -237,7 +234,7 @@ static int power_export(char *path)
|
|
|
return dev_power_xport(type, from, to, path);
|
|
return dev_power_xport(type, from, to, path);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static int file_io(void *conn, int ftype, int io)
|
|
|
|
|
|
|
+static int file_io(void *conn, int ftype, int io, char *buf)
|
|
|
{
|
|
{
|
|
|
int r,flag=0;
|
|
int r,flag=0;
|
|
|
char tmp[200],path[200];
|
|
char tmp[200],path[200];
|
|
@@ -300,36 +297,18 @@ static int file_io(void *conn, int ftype, int io)
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case FILE_POWER_ALL:
|
|
case FILE_POWER_ALL:
|
|
|
- {
|
|
|
|
|
- if(io==FILE_EXPORT) {
|
|
|
|
|
- char *ftmp="overall.csv";
|
|
|
|
|
- r = power_to_csv(ftmp, &wh->stt, ftype);
|
|
|
|
|
- if(r==0) {
|
|
|
|
|
- download_file(conn, ftmp);
|
|
|
|
|
- file_remove(ftmp);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
case FILE_POWER_CHN:
|
|
case FILE_POWER_CHN:
|
|
|
{
|
|
{
|
|
|
if(io==FILE_EXPORT) {
|
|
if(io==FILE_EXPORT) {
|
|
|
-#if 0
|
|
|
|
|
- r = power_export(path);
|
|
|
|
|
|
|
+ char start[100],end[100];
|
|
|
|
|
+
|
|
|
|
|
+ gettime2(buf, "startTime=", start);
|
|
|
|
|
+ gettime2(buf, "endTime=", end);
|
|
|
|
|
+ r = power_export(path, start, end);
|
|
|
if(r==0) {
|
|
if(r==0) {
|
|
|
download_file(conn, path);
|
|
download_file(conn, path);
|
|
|
file_remove(path);
|
|
file_remove(path);
|
|
|
}
|
|
}
|
|
|
-#else
|
|
|
|
|
- char *ftmp="channel.csv";
|
|
|
|
|
- r = power_to_csv(ftmp, &wh->stt, ftype);
|
|
|
|
|
- if(r==0) {
|
|
|
|
|
- download_file(conn, ftmp);
|
|
|
|
|
- file_remove(ftmp);
|
|
|
|
|
- }
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -696,7 +675,7 @@ static void overallStatusMonitoring(void* conn)
|
|
|
if(cjson==NULL)
|
|
if(cjson==NULL)
|
|
|
{
|
|
{
|
|
|
if (strstr(hm->uri.buf,"type=export")) {
|
|
if (strstr(hm->uri.buf,"type=export")) {
|
|
|
- file_io(conn, FILE_POWER_ALL, FILE_EXPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_POWER_ALL, FILE_EXPORT, hm->uri.buf);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
http_reply(conn, 400, NULL);
|
|
http_reply(conn, 400, NULL);
|
|
@@ -1300,7 +1279,7 @@ static void channelStatusMonitoring(void* conn)
|
|
|
if(cjson==NULL)
|
|
if(cjson==NULL)
|
|
|
{
|
|
{
|
|
|
if (strstr(hm->uri.buf,"type=export")) {
|
|
if (strstr(hm->uri.buf,"type=export")) {
|
|
|
- file_io(conn, FILE_POWER_CHN, FILE_EXPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_POWER_CHN, FILE_EXPORT, hm->uri.buf);
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -5629,22 +5608,22 @@ static void equipmentMintenanceUpload(void *conn)
|
|
|
char path[200],tmp[60];
|
|
char path[200],tmp[60];
|
|
|
|
|
|
|
|
if(strstr(hm->uri.buf, "uploadType=gjsj")) { //firmware upload
|
|
if(strstr(hm->uri.buf, "uploadType=gjsj")) { //firmware upload
|
|
|
- file_io(conn, FILE_HOST_FW, FILE_IMPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_HOST_FW, FILE_IMPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=shfw")) { //logo upload
|
|
else if(strstr(hm->uri.buf, "uploadType=shfw")) { //logo upload
|
|
|
- file_io(conn, FILE_LOGO, FILE_IMPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_LOGO, FILE_IMPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=0")) {
|
|
else if(strstr(hm->uri.buf, "uploadType=0")) {
|
|
|
- file_io(conn, FILE_ALARM_CFG, FILE_IMPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_ALARM_CFG, FILE_IMPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=1")) {
|
|
else if(strstr(hm->uri.buf, "uploadType=1")) {
|
|
|
- file_io(conn, FILE_SERV_CFG, FILE_IMPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_SERV_CFG, FILE_IMPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=2")) {
|
|
else if(strstr(hm->uri.buf, "uploadType=2")) {
|
|
|
- file_io(conn, FILE_SENSOR_CFG, FILE_IMPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_SENSOR_CFG, FILE_IMPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "uploadType=3")) {
|
|
else if(strstr(hm->uri.buf, "uploadType=3")) {
|
|
|
- file_io(conn, FILE_SYS_CFG, FILE_IMPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_SYS_CFG, FILE_IMPORT, NULL);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ack_str = ctrl_sts_ack_to_json();
|
|
ack_str = ctrl_sts_ack_to_json();
|
|
@@ -5660,18 +5639,17 @@ static void equipmentMintenanceExport(void *conn)
|
|
|
struct mg_http_message *hm=s->ev_data;
|
|
struct mg_http_message *hm=s->ev_data;
|
|
|
|
|
|
|
|
if(strstr(hm->uri.buf, "export=0")) {
|
|
if(strstr(hm->uri.buf, "export=0")) {
|
|
|
- file_io(conn, FILE_ALARM_CFG, FILE_EXPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_ALARM_CFG, FILE_EXPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "export=1")) {
|
|
else if(strstr(hm->uri.buf, "export=1")) {
|
|
|
- file_io(conn, FILE_SERV_CFG, FILE_EXPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_SERV_CFG, FILE_EXPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "export=2")) {
|
|
else if(strstr(hm->uri.buf, "export=2")) {
|
|
|
- file_io(conn, FILE_SENSOR_CFG, FILE_EXPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_SENSOR_CFG, FILE_EXPORT, NULL);
|
|
|
}
|
|
}
|
|
|
else if(strstr(hm->uri.buf, "export=3")) {
|
|
else if(strstr(hm->uri.buf, "export=3")) {
|
|
|
- file_io(conn, FILE_SYS_CFG, FILE_EXPORT);
|
|
|
|
|
|
|
+ file_io(conn, FILE_SYS_CFG, FILE_EXPORT, NULL);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int webSetCallback(void)
|
|
static int webSetCallback(void)
|