Просмотр исходного кода

F427 处理读取控制板状态慢,网页显示等问题。

liyi месяцев назад: 10
Родитель
Сommit
889873735a

+ 8 - 6
f407/applications/html_h/index_html.h

@@ -1,7 +1,7 @@
 /* 自动生成的文本数据头文件 */
 /* 源文件: index.html */
-/* 文件大小: 68489 字节 */
-/* 生成时间: 2025-09-16 05:47:07 */
+/* 文件大小: 68563 字节 */
+/* 生成时间: 2025-11-21 06:01:53 */
 /* 编码: utf-8 */
 #ifndef P_INDEX_HTML_H
 #define P_INDEX_HTML_H
@@ -74,7 +74,7 @@ const char *p_index_html =
     "          <tr>\n"
     "            <th>总电压(V)</th>\n"
     "            <th>总电流(A)</th>\n"
-    "            <th>总功率(W)</th>\n"
+    "            <th>总功率(KW)</th>\n"
     "            <!--<th>总频率(HZ)</th>-->\n"
     "            <th>总耗电量(Kwh)</th>\n"
     "          </tr>\n"
@@ -1230,9 +1230,11 @@ const char *p_index_html =
     "                        this.queryTotalStatus4();\n"
     "                    }else if(tabId=='tab5'){\n"
     "                        this.queryTotalStatus5();\n"
+    "                        var js={};\n"
+    "                        on_ws_msg(js);\n"
     "                    }\n"
     
-    "                }, 1000);\n"
+    "                }, 100);\n"
     "            },\n"
     "            // 总体监控赋值\n"
     "            async queryTotalStatus(){\n"
@@ -1704,9 +1706,9 @@ const char *p_index_html =
 ;
 
 // 文本数据大小(包括null终止符)
-const size_t p_index_html_size = 68490;
+const size_t p_index_html_size = 68564;
 
 // 文本长度(字符数)
-const size_t p_index_html_length = 66291;
+const size_t p_index_html_length = 66365;
 
 #endif /* P_INDEX_HTML_H */

+ 4 - 0
f427/applications/board.h

@@ -80,6 +80,10 @@ extern "C"
     #define BSP_UART1_RX_PIN            "PA10"
     #define BSP_UART1_RX_BUFSIZE        1024
     #define BSP_UART1_TX_BUFSIZE        1024
+		
+//    #define BSP_UART1_RX_USING_DMA
+//    #define BSP_UART1_TX_USING_DMA
+		
 
     #define BSP_USING_UART2
     #define BSP_UART2_TX_PIN            "PD5"

+ 1 - 1
f427/applications/datadef.h

@@ -10,7 +10,7 @@
 
 #define POWER_CH_MAX                12
 #define POWER_BOARD_MAX             32
-#define POWER_BOARD_TIMEOUT         100
+#define POWER_BOARD_TIMEOUT         50
 #define POWER_RETRY_TIMES           3
 #define POWER_SLAVE_CH_MAX          32
 #define POWER_CASCADE_MAX           32

+ 1 - 1
f427/applications/main.c

@@ -119,7 +119,7 @@ int main(void)
     sys_init();
     user_init();
     while (1) {
-			sensor_query();
+			//sensor_query();
 			sleep(1);
     }
 }

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

@@ -346,6 +346,82 @@ WEAK void cs_log_set_level(enum cs_log_level level) {
 
 #include <string.h>
 
+
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#define MG_TIMER_CALLED 4
+
+void mg_timer_init(struct mg_timer **head, struct mg_timer *t, uint64_t ms,
+                   unsigned flags, void (*fn)(void *), void *arg) {
+  t->id = 0, t->period_ms = ms, t->expire = 0;
+  t->flags = flags, t->fn = fn, t->arg = arg, t->next = *head;
+  *head = t;
+}
+
+void mg_timer_free(struct mg_timer **head, struct mg_timer *t) {
+  while (*head && *head != t) head = &(*head)->next;
+  if (*head) *head = t->next;
+}
+
+// t: expiration time, prd: period, now: current time. Return true if expired
+bool mg_timer_expired(uint64_t *t, uint64_t prd, uint64_t now) {
+  if (now + prd < *t) *t = 0;                    // Time wrapped? Reset timer
+  if (*t == 0) *t = now + prd;                   // Firt poll? Set expiration
+  if (*t > now) return false;                    // Not expired yet, return
+  *t = (now - *t) > prd ? now + prd : *t + prd;  // Next expiration time
+  return true;                                   // Expired, return true
+}
+
+void mg_timer_poll(struct mg_timer **head, uint64_t now_ms) {
+  struct mg_timer *t, *tmp;
+  for (t = *head; t != NULL; t = tmp) {
+    bool once = t->expire == 0 && (t->flags & MG_TIMER_RUN_NOW) &&
+                !(t->flags & MG_TIMER_CALLED);  // Handle MG_TIMER_NOW only once
+    bool expired = mg_timer_expired(&t->expire, t->period_ms, now_ms);
+    tmp = t->next;
+    if (!once && !expired) continue;
+    if ((t->flags & MG_TIMER_REPEAT) || !(t->flags & MG_TIMER_CALLED)) {
+      t->fn(t->arg);
+    }
+    t->flags |= MG_TIMER_CALLED;
+  }
+}
+
+
+
+struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
+                              unsigned flags, void (*fn)(void *), void *arg) {
+  struct mg_timer *t = (struct mg_timer *) calloc(1, sizeof(*t));
+  if (t != NULL) {
+    mg_timer_init(&mgr->timers, t, milliseconds, flags, fn, arg);
+    t->id = mgr->timerid++;
+  }
+  return t;
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 /* Amalgamated: #include "common/cs_dbg.h" */
 
 /* ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ */
@@ -2162,6 +2238,55 @@ enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
 }
 #endif
 
+#if MG_ENABLE_CUSTOM_MILLIS
+#else
+uint64_t mg_millis(void) {
+#if MG_ARCH == MG_ARCH_WIN32
+  return GetTickCount();
+#elif MG_ARCH == MG_ARCH_RP2040
+  return time_us_64() / 1000;
+#elif MG_ARCH == MG_ARCH_ESP8266 || MG_ARCH == MG_ARCH_ESP32 || \
+    MG_ARCH == MG_ARCH_FREERTOS
+  return xTaskGetTickCount() * portTICK_PERIOD_MS;
+#elif MG_ARCH == MG_ARCH_AZURERTOS
+  return tx_time_get() * (1000 /* MS per SEC */ / TX_TIMER_TICKS_PER_SECOND);
+#elif MG_ARCH == MG_ARCH_TIRTOS
+  return (uint64_t) Clock_getTicks();
+#elif MG_ARCH == MG_ARCH_ZEPHYR
+  return (uint64_t) k_uptime_get();
+#elif MG_ARCH == MG_ARCH_CMSIS_RTOS1
+  return (uint64_t) rt_time_get();
+#elif MG_ARCH == MG_ARCH_CMSIS_RTOS2
+  return (uint64_t) ((osKernelGetTickCount() * 1000) / osKernelGetTickFreq());
+#elif MG_ARCH == MG_ARCH_RTTHREAD
+  return (uint64_t) ((rt_tick_get() * 1000) / RT_TICK_PER_SECOND);
+#elif MG_ARCH == MG_ARCH_UNIX && defined(__APPLE__)
+  // Apple CLOCK_MONOTONIC_RAW is equivalent to CLOCK_BOOTTIME on linux
+  // Apple CLOCK_UPTIME_RAW is equivalent to CLOCK_MONOTONIC_RAW on linux
+  return clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / 1000000;
+#elif MG_ARCH == MG_ARCH_UNIX
+  struct timespec ts = {0, 0};
+  // See #1615 - prefer monotonic clock
+#if defined(CLOCK_MONOTONIC_RAW)
+  // Raw hardware-based time that is not subject to NTP adjustment
+  clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
+#elif defined(CLOCK_MONOTONIC)
+  // Affected by the incremental adjustments performed by adjtime and NTP
+  clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+  // Affected by discontinuous jumps in the system time and by the incremental
+  // adjustments performed by adjtime and NTP
+  clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+  return ((uint64_t) ts.tv_sec * 1000 + (uint64_t) ts.tv_nsec / 1000000);
+#elif defined(ARDUINO)
+  return (uint64_t) millis();
+#else
+  return (uint64_t) (time(NULL) * 1000);
+#endif
+}
+#endif
+
 void mg_mgr_free(struct mg_mgr *m) {
   struct mg_connection *conn, *tmp_conn;
 
@@ -2175,7 +2300,7 @@ void mg_mgr_free(struct mg_mgr *m) {
   if (m->ctl[1] != INVALID_SOCKET) closesocket(m->ctl[1]);
   m->ctl[0] = m->ctl[1] = INVALID_SOCKET;
 #endif
-
+	
   for (conn = m->active_connections; conn != NULL; conn = tmp_conn) {
     tmp_conn = conn->next;
     mg_close_conn(conn);
@@ -2199,7 +2324,10 @@ time_t mg_mgr_poll(struct mg_mgr *m, int timeout_ms) {
     LOG(LL_ERROR, ("cannot poll: no interfaces"));
     return 0;
   }
-
+	uint64_t _now;
+	_now = mg_millis();
+  mg_timer_poll(&m->timers, _now);
+	
   for (i = 0; i < m->num_ifaces; i++) {
     now = m->ifaces[i]->vtable->poll(m->ifaces[i], timeout_ms);
   }

+ 47 - 0
f427/applications/packages/mongoose-v6.7/mongoose.h

@@ -37,6 +37,23 @@
 #ifndef CS_COMMON_PLATFORM_H_
 #define CS_COMMON_PLATFORM_H_
 
+
+#define MG_ARCH_CUSTOM 0        // User creates its own mongoose_config.h
+#define MG_ARCH_UNIX 1          // Linux, BSD, Mac, ...
+#define MG_ARCH_WIN32 2         // Windows
+#define MG_ARCH_ESP32 3         // ESP32
+#define MG_ARCH_ESP8266 4       // ESP8266
+#define MG_ARCH_FREERTOS 5      // FreeRTOS
+#define MG_ARCH_AZURERTOS 6     // MS Azure RTOS
+#define MG_ARCH_ZEPHYR 7        // Zephyr RTOS
+#define MG_ARCH_NEWLIB 8        // Bare metal ARM
+#define MG_ARCH_CMSIS_RTOS1 9   // CMSIS-RTOS API v1 (Keil RTX)
+#define MG_ARCH_TIRTOS 10       // Texas Semi TI-RTOS
+#define MG_ARCH_RP2040 11       // Raspberry Pi RP2040
+#define MG_ARCH_ARMCC 12        // Keil MDK-Core with Configuration Wizard
+#define MG_ARCH_CMSIS_RTOS2 13  // CMSIS-RTOS API v2 (Keil RTX5, FreeRTOS)
+#define MG_ARCH_RTTHREAD 14     // RT-Thread RTOS
+
 /*
  * For the "custom" platform, includes and dependencies can be
  * provided through mg_locals.h.
@@ -3261,6 +3278,8 @@ struct mg_mgr {
 #if MG_ENABLE_JAVASCRIPT
   struct v7 *v7;
 #endif
+	struct mg_timer *timers; 
+	unsigned long timerid;        // Next timer ID
 };
 
 /*
@@ -5832,4 +5851,32 @@ struct mg_connection *mg_sntp_get_time(struct mg_mgr *mgr,
 
 #endif
 
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct mg_timer {
+  unsigned long id;         // Timer ID
+  uint64_t period_ms;       // Timer period in milliseconds
+  uint64_t expire;          // Expiration timestamp in milliseconds
+  unsigned flags;           // Possible flags values below
+#define MG_TIMER_ONCE 0     // Call function once
+#define MG_TIMER_REPEAT 1   // Call function periodically
+#define MG_TIMER_RUN_NOW 2  // Call immediately when timer is set
+  void (*fn)(void *);       // Function to call
+  void *arg;                // Function argument
+  struct mg_timer *next;    // Linkage
+};
+
+void mg_timer_init(struct mg_timer **head, struct mg_timer *timer,
+                   uint64_t milliseconds, unsigned flags, void (*fn)(void *),
+                   void *arg);
+void mg_timer_free(struct mg_timer **head, struct mg_timer *);
+void mg_timer_poll(struct mg_timer **head, uint64_t new_ms);
+#include "stdbool.h"
+									 
+bool mg_timer_expired(uint64_t *expiration, uint64_t period, uint64_t now);
+struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
+                              unsigned flags, void (*fn)(void *), void *arg);
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
 #endif /* CS_MONGOOSE_SRC_SNTP_H_ */

+ 158 - 65
f427/applications/power.c

@@ -12,6 +12,43 @@
 #include "time.h"
 #include "snmp.h"
 
+#define  SECOND_MIL   400
+
+enum 
+{
+	STR_POWER_ID_OVER,
+	STR_POWER_ID_MAXS,
+	STR_POWER_ID_MIN,
+	STR_POWER_ID_VOL,
+	STR_POWER_ID_CUR,
+	STR_POWER_ID_POWER,
+	STR_POWER_ID_CONSUMER,
+	STR_POWER_ID_MAX
+};
+
+const char *lang_power_str[2][STR_POWER_ID_MAX]={
+	{
+		"超过",
+		"最大",
+		"最小",
+		"电压",
+		"电流",
+		"功率",
+		"耗电量",
+	},
+	{
+		"over",
+		"max",
+		"min",
+		"voltage",
+		"current",
+		"power",
+		"consumer",
+	},
+};
+
+
+
 extern AlarmTrapinfo data;
 
 #define LIMIT_HOF(x)  (x*1.1f)
@@ -449,9 +486,9 @@ static int total_proc(power_handle_t *h)
 				tmp[k].consump += (h->pch[i]->power[k].consump/1000.0);
 				tmp[k].voltage = (tmp[k].voltage > h->pch[i]->power[k].voltage/10.0 ) ? tmp[k].voltage : h->pch[i]->power[k].voltage/10.0;
 				tmp[k].current += ( h->pch[i]->power[k].current/10.0);
-				tmp[k].power   += chn_total_p;
-				tmp[k].active += h->pch[i]->power[k].power/1000.0;
-				tmp[k].reactive += (chn_total_p-(h->pch[i]->power[k].power/1000.0));
+				tmp[k].power   += h->pch[i]->power[k].power/1000.0; 
+				tmp[k].reactive += chn_total_p;
+				tmp[k].active +=(chn_total_p-(h->pch[i]->power[k].power/1000.0));
 			}
 		}
 		
@@ -493,12 +530,15 @@ static int total_proc(power_handle_t *h)
     
     return 0;
 }
-static int board_read(power_handle_t *h, board_data_t *pbrd)
+
+
+static int board_read(power_handle_t *h, board_data_t *pbrd,uint8_t flag)
 {
     int i,j,r=-1;
     power_t *pwr,power;
     uint16_t offset,tmp[144];
     power_ch_t *pch=NULL;
+		uint8_t lang = paras_get()->sys.lang;
     
     lock_on(h->lck);
     if(pbrd) {
@@ -507,8 +547,9 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
             case AC_SINGLE_S_TYPE:
             case AC_SINGLE_B_TYPE:
             {
-                uint32_t val;
-                
+
+								uint32_t val;
+											
                 offset = POWER_AC_CUR_INFO_L;
                 r = read_reg(h, pbrd->addr, offset, tmp, pbrd->chs*12);
                 if (r<0) {
@@ -516,7 +557,8 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     break;
                 }
 
-                
+								
+								
                 for (i=0; i<pbrd->chs; i++) {
                     int idx = i * 12;
                     pwr = &pbrd->pch[i].power[0];
@@ -549,11 +591,12 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     LOGE("read_reg failed, addr:%d reg:0x%04x/%d cnt:%d\n", pbrd->addr, offset, offset, pbrd->chs);
                     break;
                 }
- 
+								
                 for (i=0; i<pbrd->chs; i++) {
                     pch = &pbrd->pch[i];
                     //pch->power[0].status = tmp[i] & (0x01);
 										pch->status = tmp[i] & (0x01);
+										time_t t=time(NULL);
 										uint8_t old_v_upper = pch->alarm.v_upper;
 										uint8_t old_v_lower = pch->alarm.v_lower;
 										uint8_t old_c_upper = pch->alarm.c_upper;
@@ -568,14 +611,17 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 										
 										waning_info_t info= {0};
 										info.type = ALARM_TYPE_POWER;
-										time_t t=time(NULL);
+										
 										struct tm *tm=localtime(&t);
 										if(!old_v_upper && pch->alarm.v_upper)
 										{
 											
 											memset(&info.waning_context,0,sizeof(64));
 											sprintf(info.date, "%04d%/%02d/%02d %2d:%2d:%2d", (tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday,tm->tm_hour, tm->tm_min, tm->tm_sec);
-											sprintf(info.waning_context,"%s over max voltage",pch->info.name);
+											sprintf(info.waning_context,"%s %s %s %s!",pch->info.name,
+																																lang_power_str[lang][STR_POWER_ID_OVER],
+																																lang_power_str[lang][STR_POWER_ID_MAXS],
+																																lang_power_str[lang][STR_POWER_ID_VOL]);
 											wanning_insert(info);
 
 											if(paras_get()->snmp.trapmode == 1)
@@ -596,7 +642,10 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 										{
 											memset(&info.waning_context,0,sizeof(64));
 											sprintf(info.date, "%04d%/%02d/%02d %2d:%2d:%2d", (tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday,tm->tm_hour, tm->tm_min, tm->tm_sec);
-											sprintf(info.waning_context,"%s over min voltage",pch->info.name);
+											sprintf(info.waning_context,"%s %s %s %s!",pch->info.name,
+																																lang_power_str[lang][STR_POWER_ID_OVER],
+																																lang_power_str[lang][STR_POWER_ID_MIN],
+																																lang_power_str[lang][STR_POWER_ID_VOL]);
 											wanning_insert(info);
 											if(paras_get()->snmp.trapmode == 1)
 											{
@@ -615,7 +664,10 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 										{
 											memset(&info.waning_context,0,sizeof(64));
 											sprintf(info.date, "%04d%/%02d/%02d %2d:%2d:%2d", (tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday,tm->tm_hour, tm->tm_min, tm->tm_sec);
-											sprintf(info.waning_context,"%s over max current",pch->info.name);
+											sprintf(info.waning_context,"%s %s %s %s!",pch->info.name,
+																																lang_power_str[lang][STR_POWER_ID_OVER],
+																																lang_power_str[lang][STR_POWER_ID_MAXS],
+																																lang_power_str[lang][STR_POWER_ID_CUR]);
 											wanning_insert(info);
 											beep_set(1);
 											if(paras_get()->snmp.trapmode == 1)
@@ -634,7 +686,10 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 										{
 											memset(&info.waning_context,0,sizeof(64));
 											sprintf(info.date, "%04d%/%02d/%02d %2d:%2d:%2d", (tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday,tm->tm_hour, tm->tm_min, tm->tm_sec);
-											sprintf(info.waning_context,"%s over max power",pch->info.name);
+											sprintf(info.waning_context,"%s %s %s %s!",pch->info.name,
+																																lang_power_str[lang][STR_POWER_ID_OVER],
+																																lang_power_str[lang][STR_POWER_ID_MAXS],
+																																lang_power_str[lang][STR_POWER_ID_POWER]);
 											wanning_insert(info);
 											beep_set(1);
 											if(paras_get()->snmp.trapmode == 1)
@@ -653,7 +708,10 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 										{
 											memset(&info.waning_context,0,sizeof(64));
 											sprintf(info.date, "%04d%/%02d/%02d %2d:%2d:%2d", (tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday,tm->tm_hour, tm->tm_min, tm->tm_sec);
-											sprintf(info.waning_context,"%s over max consumer",pch->info.name);
+											sprintf(info.waning_context,"%s %s %s %s!",pch->info.name,
+																																lang_power_str[lang][STR_POWER_ID_OVER],
+																																lang_power_str[lang][STR_POWER_ID_MAXS],
+																																lang_power_str[lang][STR_POWER_ID_CONSUMER]);
 											wanning_insert(info);
 											beep_set(1);
 											if(paras_get()->snmp.trapmode == 1)
@@ -667,52 +725,79 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
 												snmp_power_alarm_trap(&data);
 											}
 										}														
-                    //pch->alarm.ph_loss   = 0;
-                }
-                
-                offset = POWER_AC_BREAKER_INFO;
-                r = read_reg(h, pch->info.addr, offset, tmp, 1);
-                if (r < 0) {
-                    LOGE("read_reg failed, addr:%d reg:0x%04x/%d cnt:%d\n", pbrd->addr, offset, offset, pbrd->chs);
-                    break;
-                }
-                pbrd->brk[0].samp.sw = (tmp[0]&BIT(0))?1:0;
-               // pbrd->brk[0].samp.time = tm;
-                pbrd->brk[1].samp.sw = (tmp[0]&BIT(1))?1:0;
-               // pbrd->brk[1].samp.time = tm;
 
-								uint16_t buffer[16] = {0};
+                }
 
-								for (i=0; i<pbrd->chs; i++) {
-									pch = &pbrd->pch[i];
-									offset = POWER_AC_THRESHOLD_L+i*16;
-									r = read_reg(h, pch->info.addr, offset, buffer, 16);
-									if(r) break;
-            
-									pch->thr.v_upper = ((buffer[1]<<16)|buffer[0])/100;
-									pch->thr.v_lower = ((buffer[3]<<16)|buffer[2])/100;
-									pch->thr.c_upper = ((buffer[5]<<16)|buffer[4])/100;
-									pch->thr.p_upper = ((buffer[9]<<16)|buffer[8]);
-									pch->thr.w_upper = ((buffer[13]<<16)|buffer[12]);
-								}
-								//read channel delay
-								memset(buffer,0,16);
-								offset = POWER_AC_OPEN_DELAY_TIME_L;
-								r =read_reg(h, pch->info.addr, offset, buffer, pbrd->chs);
-								for(int i = 0; i < pbrd->chs;i++)
+								if(flag)
 								{
-									pch = &pbrd->pch[i];
-									pch->info.open_delay = buffer[i] / 1000;
+									offset = POWER_AC_BREAKER_INFO;
+									r = read_reg(h, pch->info.addr, offset, tmp, 1);
+									if (r < 0) {
+											LOGE("read_reg failed, addr:%d reg:0x%04x/%d cnt:%d\n", pbrd->addr, offset, offset, pbrd->chs);
+											break;
+									}
+
+									pbrd->brk[0].samp.sw = (tmp[0]&BIT(0))?1:0;
+									pbrd->brk[1].samp.sw = (tmp[0]&BIT(1))?1:0;
+
+									if(pbrd->chs < 8)
+									{
+										offset = POWER_AC_THRESHOLD_L;
+										r = read_reg(h, pch->info.addr, offset, tmp, pbrd->chs * 16);
+										if(r) break;
+										for (i=0; i<pbrd->chs; i++) {
+											pch = &pbrd->pch[i];
+											pch->thr.v_upper = ((tmp[1]<<16)|tmp[0])/100;
+											pch->thr.v_lower = ((tmp[3]<<16)|tmp[2])/100;
+											pch->thr.c_upper = ((tmp[5]<<16)|tmp[4])/100;
+											pch->thr.p_upper = ((tmp[9]<<16)|tmp[8]);
+											pch->thr.w_upper = ((tmp[13]<<16)|tmp[12]);
+										}
+									}else
+									{
+										offset = POWER_AC_THRESHOLD_L;
+										r = read_reg(h, pch->info.addr, offset, tmp, 7 * 16);
+										if(r) break;
+										for (i=0; i< 7; i++) {
+											pch = &pbrd->pch[i];
+											pch->thr.v_upper = ((tmp[1]<<16)|tmp[0])/100;
+											pch->thr.v_lower = ((tmp[3]<<16)|tmp[2])/100;
+											pch->thr.c_upper = ((tmp[5]<<16)|tmp[4])/100;
+											pch->thr.p_upper = ((tmp[9]<<16)|tmp[8]);
+											pch->thr.w_upper = ((tmp[13]<<16)|tmp[12]);										
+										}
+										offset = POWER_AC_THRESHOLD_L + (16*7);
+										
+										r = read_reg(h, pch->info.addr, offset, tmp, (pbrd->chs-7) * 16);
+										for (i=0; i< (pbrd->chs-7); i++) {
+											pch = &pbrd->pch[i+7];
+											pch->thr.v_upper = ((tmp[1]<<16)|tmp[0])/100;
+											pch->thr.v_lower = ((tmp[3]<<16)|tmp[2])/100;
+											pch->thr.c_upper = ((tmp[5]<<16)|tmp[4])/100;
+											pch->thr.p_upper = ((tmp[9]<<16)|tmp[8]);
+											pch->thr.w_upper = ((tmp[13]<<16)|tmp[12]);										
+										}
+										
+									}
+
+									offset = POWER_AC_OPEN_DELAY_TIME_L;
+									r =read_reg(h, pch->info.addr, offset, tmp, pbrd->chs);
+									for(int i = 0; i < pbrd->chs;i++)
+									{
+										pch = &pbrd->pch[i];
+										pch->info.open_delay = tmp[i] / 1000;
+									}
+									offset = POWER_AC_CLOSE_DELAY_TIME_L;
+									r =read_reg(h, pch->info.addr, offset, tmp, pbrd->chs);
+
+									
+									for(int i = 0; i < pbrd->chs;i++)
+									{
+										pch = &pbrd->pch[i];
+										pch->info.close_delay = tmp[i] / 1000;
+									}		
 								}
-								
-								memset(buffer,0,16);
-								offset = POWER_AC_CLOSE_DELAY_TIME_L;
-								r =read_reg(h, pch->info.addr, offset, buffer, pbrd->chs);
-								for(int i = 0; i < pbrd->chs;i++)
-								{
-									pch = &pbrd->pch[i];
-									pch->info.close_delay = buffer[i] / 1000;
-								}								
+			
             }
             break;
 
@@ -1080,32 +1165,40 @@ static int power_copy(power_handle_t *h)
 }
 
 
+static uint32_t count = 0;
 
 static int board_query(power_handle_t *h)
 {
     int i,r;
-
-		time_t t=time(NULL);
-		//printf("....................%ld\n",(uint32_t)t);
-    for(i=0; i<h->brd_max; i++) {
-        r = board_read(h, h->pbrd[i]);
+		count++;
+		uint8_t flag = 0;
+		if(count == SECOND_MIL)
+		{
+			flag =1;
+			count = 0;
+		}
+    for(i=1; i<(h->cnt+1); i++) {
+        r = board_read(h, h->pbrd[i],flag);
     }
     total_proc(h);
     power_copy(h);
-		 t=time(NULL);
-		//printf("____________________%ld\n",(uint32_t)t);
+		usleep(10000);
+
     return r;
 }
+
+//rt_tick_t start_tick = 0;
+
 static void power_thread(void *arg)
 {
     int r;
     board_data_t *pbrd=NULL;
     thread_handle_t *th=(thread_handle_t*)arg;
     power_handle_t *h=(power_handle_t*)th->attr->arg;;
+	 
     
     while(th->quit==0) {
-        board_query(h);
-        usleep(300000);
+        board_query(h);			
     }
 }
 

+ 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 12
 
 //#define MEM_USE_POOLS       1
 //#define PBUF_POOL_SIZE   4

+ 20 - 4
f427/applications/sensor.c

@@ -7,6 +7,7 @@
 #include "snmp.h"
 #include "beep.h"
 #include "wanning.h"
+#include "thread.h"
 
 
 
@@ -15,14 +16,14 @@
 
 
 #define RETRY_TIMES   3
-#define TIMEOUT       200
+#define TIMEOUT       50
 #define CHKECK_COUNT  3
 
 
 
 
 
-
+int sensor_query(void);
 
 typedef struct {
     lock_t        lck;
@@ -51,6 +52,17 @@ static int read_reg(uint8_t addr, uint16_t reg, uint16_t *data, int cnt)
 }
 
 
+static void sensor_thread(void *arg)
+{
+	//pthread_setname_np();
+	while(1)
+	{
+		sensor_query();
+		sleep(1);
+	}
+}
+
+
 int sensor_init(void)
 {
 		paras_data_t* p_d = paras_get();
@@ -149,8 +161,9 @@ int sensor_init(void)
 				ssHandle.all.data[2].val[1].thr.min = ((float)p_d->sensor[2].th_min_2 /100.0);
 				ssHandle.all.data[2].val[1].thr.en.th_sen_min_en = 1;
 			}			
-			
+			thread_start(THREAD_ID_SENSOR, sensor_thread, NULL);
 		}
+
     return 0;
 }
 
@@ -316,7 +329,7 @@ int sensor_query(void)
 							{
 									time_t t=time(NULL);
 										struct tm *tm=localtime(&t);
-									memset(&info.waning_context,0,sizeof(64));
+									memset(&info.waning_context,0,sizeof(64)); 
 									sprintf(info.date, "%04d%/%02d/%02d %2d:%2d:%2d", (tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday,tm->tm_hour, tm->tm_min, tm->tm_sec);
 									sprintf(info.waning_context,"%s value 1 over max threshold!!",ssHandle.all.data[i].info.name);
 									wanning_insert(info);
@@ -494,3 +507,6 @@ int sensor_data_free(sensor_all_t *all)
 }
 
 
+
+
+

+ 1 - 0
f427/applications/thread.c

@@ -13,6 +13,7 @@ static thread_attr_t thdAttrs[THREAD_ID_MAX]={
     {"ui",          NULL,           NULL,           3*KB,           20},
     {"cascade_scan",          NULL,           NULL,           1*KB,      20},
     {"cascade_thread",        NULL,           NULL,           2*KB,      20},
+		{"sensor_thread",        NULL,           NULL,            1*KB,      21},
 };
 static thread_handle_t thdHandles[THREAD_ID_MAX]={0};
 static void* thread_fn(void *arg)

+ 1 - 0
f427/applications/thread.h

@@ -23,6 +23,7 @@ enum {
     THREAD_ID_UI,
 		THREAD_ID_CAS_SCAN,
 		THREAD_ID_CAS_TH,
+		THREAD_ID_SENSOR,
     
     THREAD_ID_MAX
 };

+ 1 - 0
f427/applications/ui/menu.c

@@ -1631,6 +1631,7 @@ static int menu_net_key_handle(menu_handle_t *h, key_val_t *kv)
     if(h->menu.menu_lv==0) {
       //h->m_net.n_bak = paras_get()->netwk;
 			/// get new ip 
+			memset(&h->m_net.n_bak,0,sizeof(network_data_t));
 			net_get_ip(&h->m_net.n_bak);
     }
 		

+ 1 - 1
f427/applications/ui/ui.c

@@ -26,7 +26,7 @@ static void ui_thread(void *arg)
     menu_init();
     while(th->quit==0) {
         menu_handle();
-        msleep(50);
+        msleep(100);
     }
     menu_deinit();
 }

+ 61 - 11
f427/applications/web.c

@@ -18,6 +18,7 @@
 #include "cfg.h"
 #include "lcd.h"
 #include "wanning.h"
+#include "time.h"
 
 #define TIMER_INTERVAL      1000
 #define ONCE_SEND_CNT       13
@@ -128,6 +129,10 @@ static int ws_send_pkt(web_handle_t *h, mg_conn_t *c, uint8_t addr, uint8_t type
     return 0;
 }
 
+
+//static  uint8_t  l1_status = 0;
+//static  rt_tick_t   set_stick = 0;
+
 static void send_powerc(web_handle_t *h, mg_conn_t *c, uint8_t addr)
 {
     int i=0,j,xlen,offset,times,left;
@@ -165,6 +170,23 @@ static void send_powerc(web_handle_t *h, mg_conn_t *c, uint8_t addr)
 					offset = j*sizeof(power_ch_t);
 					memcpy(hdr->data+offset, &all.pch[i+j],sizeof(power_ch_t));
 					hdr->flag = (-1);
+//					if(l1_status != all.pch[1].status)
+//					{
+//						
+//						rt_tick_t end_tick = rt_tick_get();
+//						LOGD("web close_open.........%ld ms\n",((end_tick-set_stick)*1000)/RT_TICK_PER_SECOND);
+//						l1_status = all.pch[1].status;
+//					}
+//					if((i+j) == 3)
+//					{
+//						if(all.pch[i+j].status == 1)
+//						{
+//							extern rt_tick_t start_tick;
+//							
+//							rt_tick_t end_tick = rt_tick_get();
+//							LOGD("web close_open ms.........%ld\n",((end_tick-start_tick)*1000)/RT_TICK_PER_SECOND);
+//						}
+//					}
 				}
 				xlen = sizeof(power_ch_t) * count + sizeof(pkt_hdr_t);
 				hdr->dlen  = xlen-sizeof(pkt_hdr_t);
@@ -635,6 +657,7 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
                         if(hdr->addr==0) {
                             //r = power_set_ch_sw(pch->info.ch, pch->power[0].status);
 														power_set_ch_sw_n(pch);
+														//set_stick = rt_tick_get();
                         }
                         else {
                             
@@ -695,14 +718,18 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
             }
             else {
                 send_powerc(h, c, hdr->addr);
+								time_t t=time(NULL);
+								//LOGD("_____ send_powerc   time=%ld\n",t);
             }
         }
         break;
         
         case PKT_TYPE_POWER_TOTAL:
         {
-            LOGD("_____ send_powert\n");
+            
             send_powert(h, c, hdr->addr);
+						time_t t=time(NULL);
+						//LOGD("xxxxxxx send_powert   time=%ld\n",t);
         }
         break;
         
@@ -791,10 +818,15 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
     }
 }
 
+static int connect_count = 0;
+
+
+
 static void http_fn(mg_conn_t *c, int ev, void *ev_data)
 {
     int r,flag=0;
     web_handle_t *h=&webHandle;
+//		LOGD("connect --------%lx\n",c);
 
 #ifdef USE_MG716
     if (ev == MG_EV_HTTP_MSG) {
@@ -836,17 +868,31 @@ static void http_fn(mg_conn_t *c, int ev, void *ev_data)
         ws_handle(h, hdr, c);
     }
     else if(ev==MG_EV_TIMER) {
-        list_node_t *ln=NULL;
-        r = list_take_node(h->list, &ln, 0);
-        if(r==0) {
-            node_t *n=&ln->data;
-            ws_send_pkt(h, c, 0, n->tp, n->buf, n->dlen, 1);
-            list_back_node(h->list, ln);
-        }
+//        list_node_t *ln=NULL;
+//        r = list_take_node(h->list, &ln, 0);
+//        if(r==0) {
+//            node_t *n=&ln->data;
+//            ws_send_pkt(h, c, 0, n->tp, n->buf, n->dlen, 1);
+//            list_back_node(h->list, ln);
+//        }
+//			struct websocket_message *wm = (struct websocket_message *) ev_data;
+//			pkt_hdr_t *hdr=(pkt_hdr_t*)wm->data;
+//			send_powerc(h, c, hdr->addr);
+			//LOGD("send powerch!!!\n");
     }
 #endif
 }
 
+static void timer_fn(void *arg)
+{
+	LOGD("timer!!!!\n");
+	//web_handle_t *h=(web_handle_t*)arg;
+	//send_powerc(h, h->mgr.active_connections, 0);
+}
+
+
+
+
 static void web_thread(void *arg)
 {
     mg_conn_t *nc;
@@ -856,7 +902,8 @@ static void web_thread(void *arg)
     web_handle_t *h=(web_handle_t*)th->attr->arg;
 
     strcpy(h->rootDir, "/nor/web");
-
+		//cs_log_set_level(3);
+		
 #ifdef USE_MG716
     mg_log_set(MG_LL_VERBOSE);
     mg_mgr_init(&h->mgr);
@@ -876,14 +923,17 @@ static void web_thread(void *arg)
 #else
     mg_mgr_init(&h->mgr, NULL);
     nc = mg_bind(&h->mgr, "80", http_fn);
-
+		
     strcpy(h->rootDir, "/nor/web");
     
     mg_set_protocol_http_websocket(nc);
     h->opts.document_root = h->rootDir;
     h->opts.enable_directory_listing = "yes";
 #endif
-    
+		//mg_set_timer(nc,500);
+		//mg_timer_add(&h->mgr, 500, MG_TIMER_REPEAT, timer_fn, h);
+		
+		
     while(th->quit==0) {
         mg_mgr_poll(&h->mgr, 300);
     }

+ 8 - 6
nor_web/h_html/index_html.h

@@ -1,7 +1,7 @@
 /* 自动生成的文本数据头文件 */
 /* 源文件: index.html */
-/* 文件大小: 68489 字节 */
-/* 生成时间: 2025-09-16 05:47:07 */
+/* 文件大小: 68563 字节 */
+/* 生成时间: 2025-11-21 06:01:53 */
 /* 编码: utf-8 */
 #ifndef P_INDEX_HTML_H
 #define P_INDEX_HTML_H
@@ -74,7 +74,7 @@ const char *p_index_html =
     "          <tr>\n"
     "            <th>总电压(V)</th>\n"
     "            <th>总电流(A)</th>\n"
-    "            <th>总功率(W)</th>\n"
+    "            <th>总功率(KW)</th>\n"
     "            <!--<th>总频率(HZ)</th>-->\n"
     "            <th>总耗电量(Kwh)</th>\n"
     "          </tr>\n"
@@ -1230,9 +1230,11 @@ const char *p_index_html =
     "                        this.queryTotalStatus4();\n"
     "                    }else if(tabId=='tab5'){\n"
     "                        this.queryTotalStatus5();\n"
+    "                        var js={};\n"
+    "                        on_ws_msg(js);\n"
     "                    }\n"
     
-    "                }, 1000);\n"
+    "                }, 100);\n"
     "            },\n"
     "            // 总体监控赋值\n"
     "            async queryTotalStatus(){\n"
@@ -1704,9 +1706,9 @@ const char *p_index_html =
 ;
 
 // 文本数据大小(包括null终止符)
-const size_t p_index_html_size = 68490;
+const size_t p_index_html_size = 68564;
 
 // 文本长度(字符数)
-const size_t p_index_html_length = 66291;
+const size_t p_index_html_length = 66365;
 
 #endif /* P_INDEX_HTML_H */

+ 4 - 2
nor_web/index.html

@@ -62,7 +62,7 @@
           <tr>
             <th>总电压(V)</th>
             <th>总电流(A)</th>
-            <th>总功率(W)</th>
+            <th>总功率(KW)</th>
             <!--<th>总频率(HZ)</th>-->
             <th>总耗电量(Kwh)</th>
           </tr>
@@ -1218,9 +1218,11 @@
                         this.queryTotalStatus4();
                     }else if(tabId=='tab5'){
                         this.queryTotalStatus5();
+                        var js={};
+                        on_ws_msg(js);
                     }
 
-                }, 1000);
+                }, 100);
             },
             // 总体监控赋值
             async queryTotalStatus(){