Browse Source

增加双火线,与三相进单相出的相配置信息,替换mongoose websocket库。

liyi 10 months ago
parent
commit
76cb4e06a1

+ 16 - 0
f427/applications/datadef.h

@@ -49,6 +49,7 @@ enum {
     PDU_AC_I3O3=3,
     PDU_AC_I3O1,
     PDU_AC_I3O1_H,
+		PDU_AC_I3O2,
 };
 
 enum {
@@ -238,6 +239,17 @@ typedef struct {
     uint16_t    ch_delay;                   //通道延时
 }product_data_t;
 
+
+typedef struct {
+	char phase_seq[32];
+}phase_seq_3_1_t;
+
+typedef struct {
+	char phase_left[32];
+	char phase_right[32];
+}phase_seq_3_2_t;
+
+
 typedef struct {
     uint8_t             watchdog;
     int32_t             flip_time;
@@ -319,6 +331,8 @@ typedef struct {
     network_data_t      netwk;
 		sensor_th_t      sensor[3];
 		snmp_data_t         snmp;
+		phase_seq_3_1_t     phase_seq;
+		phase_seq_3_2_t     phase_seq_2;
 }paras_data_t;
 
 typedef struct {
@@ -868,6 +882,8 @@ typedef struct {
 #define DB_NAME         "smartPDU"
 #define INI_NAME        "smartPDU.ini"
 #define INF_NAME        "PDUInfo.txt"
+#define INF_PH_3_1      "PH_3_1.ini"
+#define INF_PH_3_2      "PH_3_2.ini"
 
 #if 1
 #define DB_PATH         SD_PATH

+ 6 - 1
f427/applications/dflt.c

@@ -80,7 +80,12 @@ const paras_data_t DFLT_PARAS={
 					.publics = "public",
 					.trapmode = 1,
 					.nms_ip = "127.0.0.1",
-				}
+				},
+				.phase_seq="11111111222222223333333311111111",
+				.phase_seq_2={
+					.phase_left="11111111222222223333333311111111",
+					.phase_right="22222222333333331111111122222222",				
+				},
 };
 
 

+ 1 - 0
f427/applications/main.c

@@ -101,6 +101,7 @@ __exit:
 
 static int user_init(void)
 {
+		sleep(1);								
     paras_data_t *p=paras_get();
     modbus_data_t *cas=&p->cas;
 		wanning_init();

+ 3 - 3
f427/applications/packages/mongoose-v6.7/7.14/mongoose.c

@@ -18,6 +18,7 @@
 // SPDX-License-Identifier: GPL-2.0-only or commercial
 
 #include "mongoose.h"
+#include "dfs_posix.h"
 
 #ifdef MG_ENABLE_LINES
 #line 1 "src/base64.c"
@@ -2701,8 +2702,7 @@ int mg_http_reply2(struct mg_connection *c, int code, const char *headers,
     "X-Frame-0ptions:: SAMEORIGIN\n"
     "X-Xss-Protection: 1: mode=block\n"
     "Accept-Ranges: bytes\n"
-    "Vary: Accept-Encoding\n\n"
-    "%s\n", code, mg_http_status_code_str(code),strlen(fmt == NULL ? "" : fmt), fmt == NULL ? "" : fmt);
+    "Vary: Accept-Encoding\n\n", code, mg_http_status_code_str(code),strlen(fmt == NULL ? "" : fmt));
 
     len = c->send.len;
     va_start(ap, fmt);
@@ -6161,7 +6161,7 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
   struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) mgr->priv;
   struct mg_connection *c, *tmp;
   uint64_t now = mg_millis();
-  mg_timer_poll(&mgr->timers, now);
+  //mg_timer_poll(&mgr->timers, now);
   if (ifp == NULL || ifp->driver == NULL) return;
   mg_tcpip_poll(ifp, now);
   for (c = mgr->conns; c != NULL; c = tmp) {

+ 8 - 5
f427/applications/packages/mongoose-v6.7/7.14/mongoose.h

@@ -43,6 +43,9 @@ extern "C" {
 #define MG_ARCH_CMSIS_RTOS2 13  // CMSIS-RTOS API v2 (Keil RTX5, FreeRTOS)
 #define MG_ARCH_RTTHREAD 14     // RT-Thread RTOS
 
+
+#define MG_ARCH MG_ARCH_RTTHREAD
+
 #if !defined(MG_ARCH)
 #if defined(__unix__) || defined(__APPLE__)
 #define MG_ARCH MG_ARCH_UNIX
@@ -662,11 +665,11 @@ struct timeval {
 #endif
 
 #ifndef MG_ENABLE_TCPIP
-#define MG_ENABLE_TCPIP 0  // Mongoose built-in network stack
+#define MG_ENABLE_TCPIP 0 // Mongoose built-in network stack
 #endif
 
 #ifndef MG_ENABLE_LWIP
-#define MG_ENABLE_LWIP 0  // lWIP network stack
+#define MG_ENABLE_LWIP 1  // lWIP network stack
 #endif
 
 #ifndef MG_ENABLE_FREERTOS_TCP
@@ -711,11 +714,11 @@ struct timeval {
 
 // Set MG_ENABLE_WINSOCK=0 for Win32 builds with external IP stack (like LWIP)
 #ifndef MG_ENABLE_WINSOCK
-#define MG_ENABLE_WINSOCK 1
+#define MG_ENABLE_WINSOCK 0
 #endif
 
 #ifndef MG_ENABLE_DIRLIST
-#define MG_ENABLE_DIRLIST 0
+#define MG_ENABLE_DIRLIST 1
 #endif
 
 #ifndef MG_ENABLE_CUSTOM_RANDOM
@@ -727,7 +730,7 @@ struct timeval {
 #endif
 
 #ifndef MG_ENABLE_PACKED_FS
-#define MG_ENABLE_PACKED_FS 1
+#define MG_ENABLE_PACKED_FS 0
 #endif
 
 #ifndef MG_ENABLE_ASSERT

+ 2 - 1
f427/applications/packages/mongoose-v6.7/7.16/mongoose.c

@@ -18,6 +18,7 @@
 // SPDX-License-Identifier: GPL-2.0-only or commercial
 
 #include "mongoose.h"
+#include "dfs_posix.h"
 
 #ifdef MG_ENABLE_LINES
 #line 1 "src/base64.c"
@@ -2969,7 +2970,7 @@ long mg_json_get_long(struct mg_str json, const char *path, long dflt) {
 
 
 
-int mg_log_level = MG_LL_INFO;
+int mg_log_level = MG_LL_ERROR;
 static mg_pfn_t s_log_func = mg_pfn_stdout;
 static void *s_log_func_param = NULL;
 

+ 2 - 2
f427/applications/packages/mongoose-v6.7/7.16/mongoose.h

@@ -786,7 +786,7 @@ struct timeval {
 #endif
 
 #ifndef MG_ENABLE_DIRLIST
-#define MG_ENABLE_DIRLIST 0
+#define MG_ENABLE_DIRLIST 1
 #endif
 
 #ifndef MG_ENABLE_CUSTOM_RANDOM
@@ -842,7 +842,7 @@ struct timeval {
 #endif
 
 #ifndef MG_ENABLE_POSIX_FS
-#define MG_ENABLE_POSIX_FS 0
+#define MG_ENABLE_POSIX_FS 1
 #endif
 
 #ifndef MG_INVALID_SOCKET

+ 149 - 2
f427/applications/paras.c

@@ -499,6 +499,121 @@ static int proc_modbus(dictionary *dic, int op, modbus_data_t *mb)
     return r;
 }
 
+
+
+static int proc_phase_3_1(dictionary *dic,int op,phase_seq_3_1_t *ph_1)
+{
+    int r=0;
+    char temp[100];
+    char *p,*token=NULL;
+
+    if(op==PARAS_CHECK) {
+			return 0;
+    }
+    else if (op==PARAS_CREATE) {
+			return 0;
+    }
+    else if (op==PARAS_WRITE) {
+        r = proc_phase_3_1(dic, PARAS_CHECK, ph_1);
+        if(r) {
+            return -1;
+        }
+    }	
+		token = "ph_3_1:phase";
+    if(op==PARAS_READ) {
+        const char * str = iniparser_getstring(dic, token,NULL);
+        if(str == NULL) {
+            LOGE("___ iniparser_getstring %s failed\n", token);
+            return -1;
+        } else {
+            memcpy(&ph_1->phase_seq[0],str,strlen(str));
+        }
+    }
+    else {
+        sprintf(temp, "%s", ph_1->phase_seq);
+        r = iniparser_set(dic, token, temp);
+        if(r) {
+            LOGE("___ iniparser_set %s failed\n", token);
+            return -1;
+				}
+		}
+		
+	   r = 0;
+    if(op==PARAS_READ) {
+        r = proc_phase_3_1(dic, PARAS_CHECK, ph_1);
+    }
+
+    return r;			
+}
+
+static int proc_phase_3_2(dictionary *dic,int op,phase_seq_3_2_t *ph_2)
+{
+    int r=0;
+    char temp[100];
+    char *p,*token=NULL;
+
+    if(op==PARAS_CHECK) {
+			return 0;
+    }
+    else if (op==PARAS_CREATE) {
+			return 0;
+    }
+    else if (op==PARAS_WRITE) {
+        r = proc_phase_3_2(dic, PARAS_CHECK, ph_2);
+        if(r) {
+            return -1;
+        }
+    }	
+		token = "ph_3_2:phase_left";
+    if(op==PARAS_READ) {
+        const char * str = iniparser_getstring(dic, token,NULL);
+        if(str == NULL) {
+            LOGE("___ iniparser_getstring %s failed\n", token);
+            return -1;
+        } else {
+            memcpy(&ph_2->phase_left[0],str,strlen(str));
+        }
+    }
+    else {
+        sprintf(temp, "%s", ph_2->phase_left);
+        r = iniparser_set(dic, token, temp);
+        if(r) {
+            LOGE("___ iniparser_set %s failed\n", token);
+            return -1;
+				}
+		}
+		
+		token = "ph_3_2:phase_right";
+    if(op==PARAS_READ) {
+        const char * str = iniparser_getstring(dic, token,NULL);
+        if(str == NULL) {
+            LOGE("___ iniparser_getstring %s failed\n", token);
+            return -1;
+        } else {
+            memcpy(&ph_2->phase_right[0],str,strlen(str));
+        }
+    }
+    else {
+        sprintf(temp, "%s", ph_2->phase_right);
+        r = iniparser_set(dic, token, temp);
+        if(r) {
+            LOGE("___ iniparser_set %s failed\n", token);
+            return -1;
+				}
+		}
+				
+		
+	   r = 0;
+    if(op==PARAS_READ) {
+        r = proc_phase_3_2(dic, PARAS_CHECK, ph_2);
+    }
+
+    return r;		
+				
+}
+
+
+
 static int proc_sensor(dictionary *dic, int op, sensor_th_t sensor[])
 {
     int r=0;
@@ -3520,6 +3635,16 @@ static dictionary* ini_load(char *path, paras_data_t *info)
 		if(r){
 			LOGE("proc_snmp failed\n");
 		}
+		
+		r=proc_phase_3_1(dic,PARAS_READ,&info->phase_seq);
+		if(r){
+			LOGE("proc_phase_3_1 failed\n");
+		}	
+
+		r=proc_phase_3_2(dic,PARAS_READ,&info->phase_seq_2);
+		if(r){
+			LOGE("proc_phase_3_2 failed\n");
+		}			
     return dic;
 }
 static int ini_check(char *path)
@@ -3606,9 +3731,18 @@ static int ini_reset(paras_handle_t *h)
     fprintf(fp, "version     = \"%d\"\n", p->snmp.version);
     fprintf(fp, "public      = \"%s\"\n", p->snmp.publics);
     fprintf(fp, "trap_mode   = \"%d\"\n", p->snmp.trapmode);
-    fprintf(fp, "nms_ip      = \"%s\"\n", p->snmp.nms_ip);	
+    fprintf(fp, "nms_ip      = \"%s\"\n", p->snmp.nms_ip);
 		fprintf(fp, "\n");	
 		
+		fprintf(fp, "[ph_3_1]\n");
+		fprintf(fp, "phase       = \"%s\"\n", p->phase_seq.phase_seq);
+		fprintf(fp, "\n");
+		
+		fprintf(fp, "[ph_3_2]\n");
+		fprintf(fp, "phase_left  = \"%s\"\n", p->phase_seq_2.phase_left);
+		fprintf(fp, "phase_right = \"%s\"\n", p->phase_seq_2.phase_right);
+		fprintf(fp, "\n");
+		
     fclose(fp);
     if(h->dic) {
         iniparser_freedict(h->dic);
@@ -3647,7 +3781,20 @@ static int ini_save(paras_handle_t *h)
     if(r) {
         LOGE("___ini_w_snmp failed\n");
         return -1;
-    }				
+    }
+		r=proc_phase_3_1(h->dic,PARAS_WRITE,&h->paras.phase_seq);
+		if(r){
+			LOGE("proc_phase_3_1 failed\n");
+			return -1;
+		}	
+
+		r=proc_phase_3_2(h->dic,PARAS_WRITE,&h->paras.phase_seq_2);
+		if(r){
+			LOGE("proc_phase_3_2 failed\n");
+			return -1;
+		}		
+
+		
     FILE *fp=fopen(h->path, "w");
     if(!fp) {
         LOGE("___%s open failed\n", h->path);

+ 28 - 12
f427/applications/power.c

@@ -12,7 +12,7 @@
 #include "time.h"
 #include "snmp.h"
 
-#define  SECOND_MIL   200
+#define  SECOND_MIL   20
 
 enum 
 {
@@ -269,6 +269,7 @@ static int get_key(power_handle_t *h, uint8_t addr, board_key_t *key)
             key->type = (tmp[0]>>8)&0xFF;
             key->chs = tmp[0]&0xFF;
         }
+				
     }
     else {
         r = read_reg(h, addr, POWER_DC_INFO, tmp, 2);
@@ -279,7 +280,12 @@ static int get_key(power_handle_t *h, uint8_t addr, board_key_t *key)
 					{
 						key->chs /= 3;
 					}
-            return 0;
+					if(h->prod->type == PDU_AC_I3O2)
+					{
+						key->chs /= 2;
+					}
+					
+          return 0;
         }
     }
     
@@ -1365,7 +1371,7 @@ int power_scan(void)
     power_handle_t *h=&pwrHandle;
     uint16_t times,nGroups=h->prod->ch_delay;
 		uint16_t flag_full = 0;
-    
+    paras_data_t *p=paras_get();
     lock_on(h->lck);
     power_clear(h);
     
@@ -1375,6 +1381,7 @@ int power_scan(void)
     int ch_count = 0;		
     for(i=1; i<=h->brd_max; i++) {
         r = get_key(h, i, &h->key[i]);
+				
         if(r==0) {
             LOGD("___ power_scan addr %d ok, type: %d, chs: %d\n", i, h->key[i].type, h->key[i].chs);
             h->cnt++;
@@ -1426,12 +1433,21 @@ int power_scan(void)
                 pch[j].info.type = pkey->type;
                 
                 if(h->prod->type==PDU_AC_I3O3) {
-                    pch[j].info.ch  = ch_idx+j/3;       //序号从1开始, 发给控制板需从0开始
-                    pch[j].info.ph_id = j%3;
-                }
+                    pch[j].info.ch  = ch_idx;       //序号从1开始, 发给控制板需从0开始
+									pch[j].info.ph_id = j+1;				  //可以不使用
+                }else if(h->prod->type == PDU_AC_I3O2)
+								{
+									pch[j].info.ch  = ch_idx+j;
+									pch[j].info.ph_id = p->phase_seq_2.phase_left[ch_idx] -'0';
+									pch[j].info.ph_val = p->phase_seq_2.phase_right[ch_idx] -'0';						//作为双火线的右边相
+								}
                 else {
                     pch[j].info.ch  = ch_idx+j;         //序号从1开始, 发给控制板需从0开始
-                    pch[j].info.ph_id = 0;
+                    if(h->prod->type==PDU_AC_I3O1 || h->prod->type == PDU_AC_I3O1_H)
+										{
+											pch[j].info.ph_id = p->phase_seq.phase_seq[ch_idx] -'0';
+										}	else
+											pch[j].info.ph_id = 0;
                 }
                 
                 times = (pch[j].info.ch%nGroups)?pch[j].info.ch:nGroups;
@@ -1446,12 +1462,12 @@ int power_scan(void)
                 pbrd->brk[0].info.addr = pbrd->addr;
             }
             
-            if(h->prod->type==PDU_AC_I3O3) {
-                ch_idx += pkey->chs/3;
-            }
-            else {
+//            if(h->prod->type==PDU_AC_I3O3) {
+//                ch_idx += pkey->chs/3;
+//            }
+//            else {
                 ch_idx += pkey->chs;
-            }
+ //           }
 						
             brd_idx++;
             

+ 1 - 1
f427/applications/rtconfig.h

@@ -188,7 +188,7 @@
 #define RT_LWIP_UDP
 #define RT_LWIP_TCP
 #define RT_LWIP_RAW
-#define RT_MEMP_NUM_NETCONN 8
+#define RT_MEMP_NUM_NETCONN 14
 
 //#define MEM_USE_POOLS       1
 //#define PBUF_POOL_SIZE   4