|
@@ -122,6 +122,71 @@ static int str_replace(char *b, char *s1, char *s2)
|
|
|
}
|
|
}
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
+static char *str_get(char *buf, char *tok, char *dst, int dstlen)
|
|
|
|
|
+{
|
|
|
|
|
+ int n=0;
|
|
|
|
|
+ char *p=strstr(buf,tok);
|
|
|
|
|
+ if(!p) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ while((*p)!=':') {
|
|
|
|
|
+ if((*p)=='\r' || (*p)=='\n') {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ p++;
|
|
|
|
|
+ }
|
|
|
|
|
+ p++;
|
|
|
|
|
+
|
|
|
|
|
+ while((*p)!='"') {
|
|
|
|
|
+ if((*p)=='\r' || (*p)=='\n') {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ p++;
|
|
|
|
|
+ }
|
|
|
|
|
+ p++;
|
|
|
|
|
+
|
|
|
|
|
+ while((*p)!='"') {
|
|
|
|
|
+ if((*p)=='\r' || (*p)=='\n') {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ *dst++ = *p++;
|
|
|
|
|
+ n++;
|
|
|
|
|
+ if(n>=dstlen-1) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ *dst = 0;
|
|
|
|
|
+
|
|
|
|
|
+ return dst;
|
|
|
|
|
+}
|
|
|
|
|
+static int get_prod(ProductInfo_t *info)
|
|
|
|
|
+{
|
|
|
|
|
+ int r;
|
|
|
|
|
+ char *p;
|
|
|
|
|
+ buf_t fbuf;
|
|
|
|
|
+ char temp[100];
|
|
|
|
|
+
|
|
|
|
|
+ r = file_load(INFO_FILE_PATH, &fbuf);
|
|
|
|
|
+ if(r) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ p = get_str(fbuf.buf, "product_name", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "product_sn", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "device_name", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "device_date", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "device_batch", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "server_name", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "server_net", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "server_mail", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "server_address", temp, sizeof(temp));
|
|
|
|
|
+ p = get_str(fbuf.buf, "server_telephone", temp, sizeof(temp));
|
|
|
|
|
+
|
|
|
|
|
+ free(fbuf.buf);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
static int ini_dump(char *path, dictionary *dic)
|
|
static int ini_dump(char *path, dictionary *dic)
|
|
|
{
|
|
{
|
|
|
FILE *fp=fopen(path, "a+");
|
|
FILE *fp=fopen(path, "a+");
|
|
@@ -185,17 +250,19 @@ static int ini_read(dictionary *dic, char *key, void *val, int len, int type, in
|
|
|
else if(type==TYPE_STR) {
|
|
else if(type==TYPE_STR) {
|
|
|
((char*)val)[0] = 0;
|
|
((char*)val)[0] = 0;
|
|
|
char *p = (char*)iniparser_getstring(dic, key, NULL);
|
|
char *p = (char*)iniparser_getstring(dic, key, NULL);
|
|
|
- if(p) {
|
|
|
|
|
- int xlen=strlen(p);
|
|
|
|
|
- if(str_chk && xlen==0) {
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
- if(len<=xlen) {
|
|
|
|
|
- LOGE("___ %s val len %d longer than recv buf len %d\n", key, xlen, len);
|
|
|
|
|
- return -1;
|
|
|
|
|
- }
|
|
|
|
|
- strcpy((char*)val, p);
|
|
|
|
|
|
|
+ if(!p) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int xlen=strlen(p);
|
|
|
|
|
+ if(str_chk && xlen==0) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(len<=xlen) {
|
|
|
|
|
+ LOGE("___ %s val len %d longer than recv buf len %d\n", key, xlen, len);
|
|
|
|
|
+ return -1;
|
|
|
}
|
|
}
|
|
|
|
|
+ strcpy((char*)val, p);
|
|
|
}
|
|
}
|
|
|
else if(type==TYPE_FLOAT) {
|
|
else if(type==TYPE_FLOAT) {
|
|
|
double c=-10000.0;
|
|
double c=-10000.0;
|
|
@@ -1034,7 +1101,7 @@ static int proc_mqtt(char *path, int op, mqtt_info_t *mqtt)
|
|
|
r = -1;
|
|
r = -1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if(ser->id!=-1 || ser->id != i) {
|
|
|
|
|
|
|
+ if(ser->id!=-1 && ser->id != i) {
|
|
|
LOGE("___ check mqtt[%d], id %d is mismatch the index\n", i, ser->id);
|
|
LOGE("___ check mqtt[%d], id %d is mismatch the index\n", i, ser->id);
|
|
|
r = -1;
|
|
r = -1;
|
|
|
}
|
|
}
|
|
@@ -1064,7 +1131,6 @@ static int proc_mqtt(char *path, int op, mqtt_info_t *mqtt)
|
|
|
for(i=0; i<MQTT_SER_MAX; i++) {
|
|
for(i=0; i<MQTT_SER_MAX; i++) {
|
|
|
ser = &pmqtt->ser[i];
|
|
ser = &pmqtt->ser[i];
|
|
|
if(ser->id>=0) {
|
|
if(ser->id>=0) {
|
|
|
- fprintf(fp, "broker%d.plat = \"%d\"\n", i+1,ser->plat);
|
|
|
|
|
fprintf(fp, "broker%d.plat = \"%d\"\n", i+1,ser->plat);
|
|
fprintf(fp, "broker%d.plat = \"%d\"\n", i+1,ser->plat);
|
|
|
fprintf(fp, "broker%d.mode = \"%d\"\n", i+1,ser->mode);
|
|
fprintf(fp, "broker%d.mode = \"%d\"\n", i+1,ser->mode);
|
|
|
//fprintf(fp, "broker%d.proto = \"%s\"\n", i+1,ser->proto);
|
|
//fprintf(fp, "broker%d.proto = \"%s\"\n", i+1,ser->proto);
|
|
@@ -1095,7 +1161,7 @@ static int proc_mqtt(char *path, int op, mqtt_info_t *mqtt)
|
|
|
ser->id = -1;
|
|
ser->id = -1;
|
|
|
|
|
|
|
|
sprintf(token, "mqtt:broker%d.plat", i+1);
|
|
sprintf(token, "mqtt:broker%d.plat", i+1);
|
|
|
- r = ini_rw(dic, token, &ser->plat, sizeof(ser->plat), TYPE_INT, op, 1); if(r) goto quit;
|
|
|
|
|
|
|
+ r = ini_rw(dic, token, &ser->plat, sizeof(ser->plat), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
sprintf(token, "mqtt:broker%d.mode", i+1);
|
|
sprintf(token, "mqtt:broker%d.mode", i+1);
|
|
|
r = ini_rw(dic, token, &ser->mode, sizeof(ser->mode), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &ser->mode, sizeof(ser->mode), TYPE_INT, op, 1); if(r) break;
|
|
@@ -1148,8 +1214,10 @@ static int proc_mqtt(char *path, int op, mqtt_info_t *mqtt)
|
|
|
for(i=0; i<MQTT_SER_MAX; i++) {
|
|
for(i=0; i<MQTT_SER_MAX; i++) {
|
|
|
ser = &pmqtt->ser[i];
|
|
ser = &pmqtt->ser[i];
|
|
|
|
|
|
|
|
|
|
+ if(ser->id==-1) break;
|
|
|
|
|
+
|
|
|
sprintf(token, "mqtt:broker%d.plat", i+1);
|
|
sprintf(token, "mqtt:broker%d.plat", i+1);
|
|
|
- r = ini_rw(dic, token, &ser->plat, sizeof(ser->plat), TYPE_INT, op, 1); if(r) goto quit;
|
|
|
|
|
|
|
+ r = ini_rw(dic, token, &ser->plat, sizeof(ser->plat), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
sprintf(token, "mqtt:broker%d.mode", i+1);
|
|
sprintf(token, "mqtt:broker%d.mode", i+1);
|
|
|
r = ini_rw(dic, token, &ser->mode, sizeof(ser->mode), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &ser->mode, sizeof(ser->mode), TYPE_INT, op, 1); if(r) break;
|
|
@@ -1331,7 +1399,6 @@ static int proc_mail(char *path, int op, mail_info_t *mail)
|
|
|
recv->use = 1;
|
|
recv->use = 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- r = proc_mail(path, PARAS_CHECK, pmail); if(r) goto quit;
|
|
|
|
|
r = dev_clear_table(dm->db, TAB_ID_MAIL); if(r) goto quit;
|
|
r = dev_clear_table(dm->db, TAB_ID_MAIL); if(r) goto quit;
|
|
|
r = dev_mail_update_send(dm->db, &pmail->send); if(r) goto quit;
|
|
r = dev_mail_update_send(dm->db, &pmail->send); if(r) goto quit;
|
|
|
r = dev_mail_update_recv(dm->db, pmail->recv); if(r) goto quit;
|
|
r = dev_mail_update_recv(dm->db, pmail->recv); if(r) goto quit;
|
|
@@ -1346,7 +1413,6 @@ static int proc_mail(char *path, int op, mail_info_t *mail)
|
|
|
send = &pmail->send;
|
|
send = &pmail->send;
|
|
|
|
|
|
|
|
r = dev_mail_get(dm->db, pmail); if(r) return -1;
|
|
r = dev_mail_get(dm->db, pmail); if(r) return -1;
|
|
|
- r = proc_mail(path, PARAS_CHECK, pmail); if(r) return -1;
|
|
|
|
|
dic = dictionary_new(0); if(!dic) return -1;
|
|
dic = dictionary_new(0); if(!dic) return -1;
|
|
|
|
|
|
|
|
r = ini_rw(dic, "mail:send.mode", &send->mode, sizeof(send->mode), TYPE_INT, op, 1); if(r) goto quit;
|
|
r = ini_rw(dic, "mail:send.mode", &send->mode, sizeof(send->mode), TYPE_INT, op, 1); if(r) goto quit;
|
|
@@ -2594,29 +2660,29 @@ static int proc_power3(char *path, int op, GlobalTreeACManager *power)
|
|
|
///////////voltage//////////
|
|
///////////voltage//////////
|
|
|
GlobalOverManager *pover=&tmp->global_over_manager;
|
|
GlobalOverManager *pover=&tmp->global_over_manager;
|
|
|
//upper
|
|
//upper
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.en",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.en",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_enable, sizeof(pover->product_vol_upper_enable), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_enable, sizeof(pover->product_vol_upper_enable), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.val",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.val",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_threshold, sizeof(pover->product_vol_upper_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_threshold, sizeof(pover->product_vol_upper_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.act",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.act",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl, sizeof(pover->product_vol_over_upper_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl, sizeof(pover->product_vol_over_upper_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.para",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.para",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl_para, sizeof(pover->product_vol_over_upper_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl_para, sizeof(pover->product_vol_over_upper_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
//lower
|
|
//lower
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.en",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.en",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_enable, sizeof(pover->product_vol_lower_enable), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_enable, sizeof(pover->product_vol_lower_enable), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.val",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.val",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_threshold, sizeof(pover->product_vol_lower_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_threshold, sizeof(pover->product_vol_lower_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.act",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.act",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl, sizeof(pover->product_vol_over_lower_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl, sizeof(pover->product_vol_over_lower_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.para",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.para",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl_para, sizeof(pover->product_vol_over_lower_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl_para, sizeof(pover->product_vol_over_lower_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
///////////current//////////
|
|
///////////current//////////
|
|
@@ -2739,29 +2805,29 @@ static int proc_power3(char *path, int op, GlobalTreeACManager *power)
|
|
|
///////////voltage//////////
|
|
///////////voltage//////////
|
|
|
GlobalOverManager *pover=&tmp->global_over_manager;
|
|
GlobalOverManager *pover=&tmp->global_over_manager;
|
|
|
//upper
|
|
//upper
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.en",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.en",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_enable, sizeof(pover->product_vol_upper_enable), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_enable, sizeof(pover->product_vol_upper_enable), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.val",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.val",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_threshold, sizeof(pover->product_vol_upper_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_upper_threshold, sizeof(pover->product_vol_upper_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.act",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.act",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl, sizeof(pover->product_vol_over_upper_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl, sizeof(pover->product_vol_over_upper_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.up.para",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.up.para",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl_para, sizeof(pover->product_vol_over_upper_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_upper_threshold_ctrl_para, sizeof(pover->product_vol_over_upper_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
//lower
|
|
//lower
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.en",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.en",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_enable, sizeof(pover->product_vol_lower_enable), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_enable, sizeof(pover->product_vol_lower_enable), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.val",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.val",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_threshold, sizeof(pover->product_vol_lower_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_lower_threshold, sizeof(pover->product_vol_lower_threshold), TYPE_FLOAT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.act",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.act",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl, sizeof(pover->product_vol_over_lower_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl, sizeof(pover->product_vol_over_lower_threshold_ctrl), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
- sprintf(token, "power:channel%d.threshold.voltate.lo.para",channelID);
|
|
|
|
|
|
|
+ sprintf(token, "power:channel%d.threshold.voltage.lo.para",channelID);
|
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl_para, sizeof(pover->product_vol_over_lower_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
r = ini_rw(dic, token, &pover->product_vol_over_lower_threshold_ctrl_para, sizeof(pover->product_vol_over_lower_threshold_ctrl_para), TYPE_INT, op, 1); if(r) break;
|
|
|
|
|
|
|
|
///////////current//////////
|
|
///////////current//////////
|