Przeglądaj źródła

添加web文件

guohui 1 rok temu
rodzic
commit
258b923d11

+ 100 - 4
f407/applications/data.js

@@ -6,6 +6,8 @@ var PKT_TYPE=function(){
         PKT_TYPE_PARAS:len++,             
         PKT_TYPE_POWER_CH:len++,          //power_ch_t
         PKT_TYPE_POWER_TOTAL:len++,       //power_total_t
+        PKT_TYPE_CH_ALL:len++,
+        PKT_TYPE_ALARM:len++,
         PKT_TYPE_SENSOR:len++,
         PKT_TYPE_BREAKER:len++,
         PKT_TYPE_STAT:len++,
@@ -211,7 +213,6 @@ function bin_to_thr(bin) {
 
     this.len = length;
 }
-
 function bin_to_powerc(bin) {
     var tmp, bin2, length=0;
 
@@ -233,6 +234,10 @@ function bin_to_powerc(bin) {
     tmp = new DataView(bin, length);
     this.time = tmp.getUint32(0,true);
     length += this.time.len;
+    
+    tmp = new DataView(bin, length);
+    this.pbrd = tmp.getUint32(0,true);
+    length += this.pbrd.len;
 
     this.len = length;
 }
@@ -288,6 +293,31 @@ function bin_to_powert(bin) {
     
     this.len = length;
 }
+function bin_to_chall(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    var chall = tmp.getUint8(0,true);
+    length += 1;
+
+    return chall;
+}
+function bin_to_alarmd(bin) {
+    var tmp, length=0;
+    
+    tmp = new DataView(bin, length);
+    this.ch = tmp.getUint8(0,true);
+    length += 1;
+    
+    this.alarm = new bin_to_alarm(bin.slice(leng));
+    length += this.alarm.len;
+    
+    tmp = new DataView(bin, length);
+    this.time = tmp.getUint32(0,true);
+    length += 1;
+
+    this.len = length;
+}
 ///////////////////////////////////////////////////
 function hdr_to_bin(js) {
     var tmp, length=0;
@@ -467,13 +497,14 @@ function powerc_to_bin(js) {
     
     tmp = thr_to_bin(js.thr);
     bin = array_cat(bin, tmp);
-    
+
     tmp = alarm_to_bin(js.alarm);
     bin = array_cat(bin, tmp);
     
-    var buf = new ArrayBuffer(4);
+    var buf = new ArrayBuffer(8);
     tmp = new DataView(buf, 0);
     tmp.setUint32(0,js.time,true);
+    tmp.setUint32(4,js.pbrd,true);
     
     bin = array_cat(bin, buf);
 
@@ -533,6 +564,32 @@ function powert_to_bin(js) {
 
     return bin;
 }
+function chall_to_bin(js) {
+    var tmp, length=0;
+    var bin = new ArrayBuffer(1);
+
+    tmp = new DataView(bin, length);
+    tmp.setUint8(0,js,true);
+    length += 1;
+
+    return bin;
+}
+function alarmd_to_bin(js) {
+    var tmp, length=0;
+    var bin,buffer = new ArrayBuffer(1);
+
+    tmp = new DataView(buffer, 0);
+    tmp.setUint8(0,js.ch,true);
+    
+    var alarm = alarm_to_bin(js.alarm);
+    bin = array_cat(buffer, alarm);
+
+    buffer = new ArrayBuffer(4);
+    tmp = new DataView(buffer, 0);
+    tmp.setUint32(0,js.time,true);
+
+    return array_cat(bin, buffer);
+}
 //////////////////////////////////////////////////////////////
 
 var XXX ={};
@@ -549,6 +606,17 @@ XXX.hdr = function() {
             case PKT_TYPE.PKT_TYPE_POWER_TOTAL:
                 tmp = BIN.powert.j2b(js.powert);
                 break;
+                
+           case PKT_TYPE.PKT_TYPE_CH_ALL:
+                tmp = BIN.chall.j2b(js);
+                break;
+               
+           case PKT_TYPE.PKT_TYPE_ALARM:
+                tmp = BIN.alarm.j2b(js);
+                break;
+                
+           default:
+           return tmp;
         }
         return array_cat(hdr,tmp);
     };
@@ -572,7 +640,15 @@ XXX.hdr = function() {
             case PKT_TYPE.PKT_TYPE_POWER_TOTAL:
                 hdr.powert = BIN.powert.b2j(data);
                 break;
-
+            
+            case PKT_TYPE.PKT_TYPE_CH_ALL:
+                hdr.chall = BIN.chall.b2j(data);
+                break;
+               
+           case PKT_TYPE.PKT_TYPE_ALARM:
+                hdr.alarm = BIN.alarm.b2j(data);
+                break;
+            
             default :
                 console.log("wrong hdr type: "+hdr.type);
         }
@@ -606,6 +682,24 @@ XXX.powert=function() {
         return new bin_to_powert(bin);
     }
 };
+XXX.chall=function() {
+    this.j2b = function (js) {
+        return new chall_to_bin(js);
+    }
+
+    this.b2j = function (bin) {
+        return new bin_to_chall(bin);
+    }
+};
+XXX.alarmd=function() {
+    this.j2b = function (js) {
+        return new alarmd_to_bin(js);
+    }
+
+    this.b2j = function (bin) {
+        return new bin_to_alarmd(bin);
+    }
+};
 
 
 var BIN=new function() {
@@ -613,6 +707,8 @@ var BIN=new function() {
     this.paras = new XXX.paras();
     this.powerc = new XXX.powerc();
     this.powert = new XXX.powert();
+    this.chall = new XXX.chall();
+    this.alarmd = new XXX.alarmd();
 }();
 
 

+ 25 - 16
f407/applications/datadef.h

@@ -264,6 +264,12 @@ typedef struct {
     
     uint8_t             ph_loss;                //缺相
 }alarm_t;
+typedef struct {
+    uint8_t             ch;
+    alarm_t             alarm;
+    uint32_t            time;
+}alarm_data_t;
+
 typedef struct {
     uint8_t             type;
     uint8_t             addr;
@@ -280,23 +286,24 @@ typedef struct {
     thr_t               thr;                      //阈值
     alarm_t             alarm;
     uint32_t            time;
+    void                *pbrd;
 }power_ch_t;
 
 typedef struct {
-    uint8_t (*get_elec_data)(power_ch_t *pch);
-    uint8_t (*get_waning)(power_ch_t *pch);                          //参数后续补齐
-    uint8_t (*open_chn)    (power_ch_t *pch);                        //参数后续补齐
-    uint8_t (*close_chn)(power_ch_t *pch);                           //参数后续补齐
-    uint8_t (*set_open_delay)(power_ch_t *pch);                      //参数后续补齐
-    uint8_t (*set_close_delay)(power_ch_t *pch);                     //参数后续补齐
-    uint8_t (*set_meter)(power_ch_t *pch);                           //参数后续补齐
-    uint8_t (*over_func)(power_ch_t *pch);
-    uint8_t (*reset_consumer)(power_ch_t *pch);
-
-    uint8_t (*get_info)(uint8_t addr);
-    uint8_t (*detect)(uint8_t addr);                                 //参数后续补齐
-    uint8_t (*open_all)(uint8_t addr);                                
-    uint8_t (*close_all)(uint8_t addr);
+    int (*get_power)(power_ch_t *pch);
+    int (*get_alarm)(power_ch_t *pch, alarm_t *alarm);
+    int (*open_ch)(power_ch_t *pch);
+    int (*close_ch)(power_ch_t *pch);
+    int (*set_open_delay)(power_ch_t *pch);
+    int (*set_close_delay)(power_ch_t *pch);
+    int (*set_kb_value)(power_ch_t *pch);
+    int (*set_threshold)(power_ch_t *pch);
+    int (*reset_consump)(power_ch_t *pch);
+
+    int (*detect)(uint8_t addr);
+    int (*get_info)(uint8_t addr);
+    int (*open_all)(uint8_t addr);                                
+    int (*close_all)(uint8_t addr);
 }board_fn_t;
 
 typedef struct {
@@ -460,7 +467,7 @@ typedef struct {
 typedef struct {
     uint8_t             mode;
     uint8_t             version;
-    char                public[64];
+    char                publics[64];
     uint8_t             trapmode;
 
     crypt_t             crypt;
@@ -531,8 +538,10 @@ typedef struct {
 enum {
     PKT_TYPE_ACK=0,             
     PKT_TYPE_PARAS,             
-    PKT_TYPE_POWER_CH,          //all_ch_t
+    PKT_TYPE_POWER_CH,          //power_ch_t
     PKT_TYPE_POWER_TOTAL,       //power_total_t
+    PKT_TYPE_CH_ALL,            //uint8_t, 0:all close  1:all open
+    PKT_TYPE_ALARM,
     PKT_TYPE_SENSOR,
     PKT_TYPE_BREAKER,
     PKT_TYPE_STAT,

+ 2 - 0
f407/applications/log.h

@@ -1,7 +1,9 @@
 #ifndef __LOG_Hx__
 #define __LOG_Hx__
 
+#ifndef _WIN32
 #include <rtdbg.h>
+#endif
 
 #define LOGD   LOG_D
 #define LOGW   LOG_W

+ 28 - 58
f407/applications/power.c

@@ -52,7 +52,7 @@ static int get_info(power_handle_t *h, int addr, ch_info_t *info)
         return 0;
     }
 
-    r = read_reg(h->mb, addr, POWER_DC_GET_INFO, &tmp, 1);
+    r = read_reg(h->mb, addr, POWER_DC_INFO, &tmp, 1);
     if(r==0) {
         info->type = (tmp>>8)&0xFF;
         info->chs = tmp&0xFF;
@@ -262,7 +262,7 @@ static int set_switch(power_handle_t *h, power_ch_t *pch)
         case DCPDU_TYPE:
         {
             uint16_t mask;
-            offset = POWER_DC_GET_STAT_INFO+pch->info.ch;
+            offset = POWER_DC_STAT_INFO+pch->info.ch;
             
             mask = ~(1 << pch->info.ch);
             tmp[0] &= mask;
@@ -294,37 +294,7 @@ static int set_switch(power_handle_t *h, power_ch_t *pch)
     
     return r;
 }
-static int get_thr(power_handle_t *h, power_ch_t *pch)
-{
-    int r=-1;
-    
-    switch(pch->info.type) {
-        case AC_SINGLE_S_TYPE:
-        case AC_SINGLE_B_TYPE:
-        {
-            
-        }
-        break;
-
-        case DCPDU_TYPE:
-        {
-            
-        }
-        break;
-        
-        case TREE_AC_TYPE:
-        {
-            
-        }
-        break;
-        
-        default:
-        return -1;
-    }
-    
-    return r;
-}
-static int set_thr(power_handle_t *h, power_ch_t *pch)
+static int set_threshold(power_handle_t *h, power_ch_t *pch)
 {
     int r=-1;
     
@@ -360,6 +330,7 @@ static int set_thr(power_handle_t *h, power_ch_t *pch)
 static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
 {
     int r,i,j;
+    alarm_t alarm;
     uint16_t offset,tmp[144];
     
     switch(pbrd->type) {
@@ -407,8 +378,7 @@ static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
                     pbrd->pch[i].alarm.c_upper   = tmp[i] & ALARM_C_UPPER;
                     pbrd->pch[i].alarm.p_upper   = tmp[i] & ALARM_P_UPPER;
                     pbrd->pch[i].alarm.w_upper   = tmp[i] & ALARM_W_UPPER;
-                                                 
-                    pbrd->pch[i].alarm.ph_loss  = 0;
+                    pbrd->pch[i].alarm.ph_loss   = 0;
                 }
             }
         }
@@ -417,7 +387,7 @@ static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
         case DCPDU_TYPE:
         {
             uint32_t flag;
-            offset = POWER_DC_GET_OUT_INFO + 16;
+            offset = POWER_DC_OUT_INFO + 16;
             uint16_t *ptmp = tmp + 32;
             r = read_reg(h, pbrd->addr, offset, ptmp, 32);
             if (r < 0) {
@@ -444,7 +414,7 @@ static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
                 pbrd->pch[i].power[0].factor = 1;
             }
 
-            offset = POWER_DC_GET_STAT_INFO;
+            offset = POWER_DC_STAT_INFO;
             
             r = read_reg(h, pbrd->addr, offset, tmp, 2);
             if (r < 0) {
@@ -457,7 +427,7 @@ static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
                 pbrd->pch[i].power[0].status = (flag >> i) & 0x1;
             }
             // 获取报警状态
-            offset = POWER_DC_GET_WARNING;
+            offset = POWER_DC_WARNING;
             r = read_reg(h, pbrd->addr, offset, tmp, 16);
             if (r < 0) {
                 LOGE("get_board, addr:%d offset:%d r=%d\n", pbrd->addr, offset, r);
@@ -466,11 +436,11 @@ static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
             
             for (i = 0; i < pbrd->chs; i++) {
                 int Index = i * 2;
-                pbrd->pch[i].alarm.v_upper = tmp[0+Index] & (1<<0);
-                pbrd->pch[i].alarm.v_lower = tmp[0+Index] & (1<<1);
-                pbrd->pch[i].alarm.c_upper = tmp[0+Index] & (1<<2);
-                pbrd->pch[i].alarm.p_upper = tmp[0+Index] & (1<<3);
-                pbrd->pch[i].alarm.w_upper = tmp[0+Index] & (1<<4);
+                pbrd->pch[i].alarm.v_upper = tmp[0+Index] & BIT(0);
+                pbrd->pch[i].alarm.v_lower = tmp[0+Index] & BIT(1);
+                pbrd->pch[i].alarm.c_upper = tmp[0+Index] & BIT(2);
+                pbrd->pch[i].alarm.p_upper = tmp[0+Index] & BIT(3);
+                pbrd->pch[i].alarm.w_upper = tmp[0+Index] & BIT(4);
             }
         }
         break;
@@ -542,11 +512,11 @@ static int get_board(power_handle_t *h, uint8_t addr, board_data_t *pbrd)
             }
             for (i=0; i<pbrd->chs; i++) {
                 int Index = i * 2;
-                pbrd->pch[i].alarm.v_upper = tmp[0+Index] & (1<<0);
-                pbrd->pch[i].alarm.v_lower = tmp[0+Index] & (1<<1);
-                pbrd->pch[i].alarm.c_upper = tmp[0+Index] & (1<<2);
-                pbrd->pch[i].alarm.p_upper = tmp[0+Index] & (1<<3);
-                pbrd->pch[i].alarm.w_upper = tmp[0+Index] & (1<<4);
+                pbrd->pch[i].alarm.v_upper = tmp[0+Index] & BIT(0);
+                pbrd->pch[i].alarm.v_lower = tmp[0+Index] & BIT(1);
+                pbrd->pch[i].alarm.c_upper = tmp[0+Index] & BIT(2);
+                pbrd->pch[i].alarm.p_upper = tmp[0+Index] & BIT(3);
+                pbrd->pch[i].alarm.w_upper = tmp[0+Index] & BIT(4);
             }
             
             offset = POWER_AC3_ALARM_MISSING_PH;
@@ -673,11 +643,11 @@ int power_set(int ch, power_ch_t *pch)
     power_handle_t *h=&pwrHandle;
     
     lock_d_hold(h->lck);
-    if(!pch || !h->all.pch || !h->all.chs || !h->all.pch[ch]) {
+    if(!pch || !h->all.pch || !h->all.chs || !h->all.pch[pch->info.ch]) {
         lock_d_release(h->lck);
         return -1;
     }
-    *h->all.pch[ch] = *pch;
+    *h->all.pch[pch->info.ch] = *pch;
     lock_d_release(h->lck);
     
     return 0;
@@ -793,7 +763,7 @@ int power_reset(int addr)
         
         case DCPDU_TYPE:
         {
-            offset = POWER_DC_SET_ALARM_CTRL_TOTAL;
+            offset = POWER_DC_ALARM_CTRL_TOTAL;
         }
         break;
         
@@ -935,10 +905,10 @@ int power_set_alarm(int ch, alarm_t *alarm)
         case DCPDU_TYPE:
         {
             if (ch == -1) {
-                offset = POWER_DC_SET_ALARM_CTRL_TOTAL;
+                offset = POWER_DC_ALARM_CTRL_TOTAL;
             }
             else {
-                offset = POWER_DC_SET_ALARM_CTRL + ch;
+                offset = POWER_DC_ALARM_CTRL + ch;
             }
         }
         break;
@@ -1041,31 +1011,31 @@ int power_set_thr(int ch, thr_t *thr)
             uint16_t data_temp[4];
             uint32_t value;
             
-            offset = (ch<0)?POWER_DC_SET_THRESHOLD_TOTAL_VOL_MAX:POWER_DC_SET_THRESHOLD_VOL_MAX;
+            offset = (ch<0)?POWER_DC_THRESHOLD_TOTAL_VOL_MAX:POWER_DC_THRESHOLD_VOL_MAX;
             value = thr->v_upper.val * 1000;
             data_temp[0] = value & 0XFFFF;
             data_temp[1] = (value >> 16) & 0xFFFF;
             r = write_reg(h, pc.info.addr, offset, data_temp, 2);
             
-            offset = (ch<0)?POWER_DC_SET_THRESHOLD_TOTAL_VOL_MIN:POWER_DC_SET_THRESHOLD_VOL_MIN;
+            offset = (ch<0)?POWER_DC_THRESHOLD_TOTAL_VOL_MIN:POWER_DC_THRESHOLD_VOL_MIN;
             value = thr->v_lower.val * 1000;
             data_temp[0] = value & 0XFFFF;
             data_temp[1] = (value >> 16) & 0xFFFF;
             r = write_reg(h, pc.info.addr, offset, data_temp, 2);
             
-            offset = (ch<0)?POWER_DC_SET_THRESHOLD_TOTAL_CUR_MAX:POWER_DC_SET_THRESHOLD_CUR_MAX;
+            offset = (ch<0)?POWER_DC_THRESHOLD_TOTAL_CUR_MAX:POWER_DC_THRESHOLD_CUR_MAX;
             value = thr->c_upper.val * 1000;
             data_temp[0] = value & 0XFFFF;
             data_temp[1] = (value >> 16) & 0xFFFF;
             r = write_reg(h, pc.info.addr, offset, data_temp, 2);
             
-            offset = (ch<0)?POWER_DC_SET_THRESHOLD_TOTAL_PWR_MAX:POWER_DC_SET_THRESHOLD_POWER_MAX;
+            offset = (ch<0)?POWER_DC_THRESHOLD_TOTAL_PWR_MAX:POWER_DC_THRESHOLD_POWER_MAX;
             value = thr->p_upper.val * 1000;
             data_temp[0] = value & 0XFFFF;
             data_temp[1] = (value >> 16) & 0xFFFF;
             r = write_reg(h, pc.info.addr, offset, data_temp, 2);
             
-            offset = (ch<0)?POWER_DC_SET_THRESHOLD_TOTAL_PWRCON_MAX:POWER_DC_SET_THRESHOLD_POWERCON_MAX;
+            offset = (ch<0)?POWER_DC_THRESHOLD_TOTAL_PWRCON_MAX:POWER_DC_THRESHOLD_POWERCON_MAX;
             value = thr->w_upper.val * 1000;
             data_temp[0] = value & 0XFFFF;
             data_temp[1] = (value >> 16) & 0xFFFF;

+ 25 - 25
f407/applications/power.h

@@ -34,31 +34,31 @@
 #define POWER_DC_SET_STAT_INFO                    0x1097          //直流继电器电路控制板开关状态,采集一路输出
 #define POWER_DC_SET_IN_INFO                      0x105F          //直流总电流电压采集控制板,采集设备输入电压和输入电流
 
-#define POWER_DC_GET_INFO                         0x1770          //获取直流PDU类型通道
-#define POWER_DC_GET_TOTAL_ALARM                  0x1776          //直流PDU总报警信息 2024.11.12
-#define POWER_DC_GET_OUT_INFO                     0x177A          //直流PDU输出
-#define POWER_DC_GET_STAT_INFO                    0x17E2          //直流PDU开关状
-#define POWER_DC_GET_WARNING                      0x179A          //直流PDU报警信息
-#define POWER_DC_GET_STAT_ERROR                   0x17E4          //直流PDU故障状态
-#define POWER_DC_GET_IN_INFO                      0x1772          //直流PDU采集输入电压与输入电
-#define POWER_DC_GET_START_DELAY                  0x17E6          //直流PDU延时
-#define POWER_DC_GET_STOP_DELAY                   0x17F6          //直流PDU延时
-#define POWER_DC_SET_THRESHOLD_VOL_MAX            0x17A2          //max voltage threshold
-#define POWER_DC_SET_THRESHOLD_VOL_MIN            0x17B2          //min voltage threshold
-#define POWER_DC_SET_THRESHOLD_CUR_MAX            0x17C2          //max current threshold
-#define POWER_DC_SET_THRESHOLD_CUR_MIN            0x17D2          //max current threshold
-#define POWER_DC_SET_THRESHOLD_POWER_MAX          0x1810          //max power threshold
-#define POWER_DC_SET_THRESHOLD_POWERCON_MAX       0x181A          //max powercon threshold
-#define POWER_DC_SET_ALL_OPEN_INFO                0x1806          //ALL OPEN直流PDU开关状
-#define POWER_DC_SET_ALL_CLOSE_INFO               0x1807          //ALL OPEN直流PDU开关状
-#define POWER_DC_SET_ALARM_CTRL                   0x182E          //超限动作
-#define POWER_DC_SET_CONSUMP_CLEAR   	          0x1838          //重置直流耗电量
-#define POWER_DC_SET_THRESHOLD_TOTAL_VOL_MAX      0x184C          //max total voltage threshold 2024.11.12
-#define POWER_DC_SET_THRESHOLD_TOTAL_VOL_MIN      0x184D          //min total voltage threshold 2024.11.12
-#define POWER_DC_SET_THRESHOLD_TOTAL_CUR_MAX      0x184E          //max total current threshold 2024.11.12
-#define POWER_DC_SET_THRESHOLD_TOTAL_PWR_MAX      0x184F          //max total power threshold 2024.11.12
-#define POWER_DC_SET_THRESHOLD_TOTAL_PWRCON_MAX   0x1850          //max total powercon threshold 2024.11.12
-#define POWER_DC_SET_ALARM_CTRL_TOTAL             0x1856          //总体超限动作   2024.11.12       
+#define POWER_DC_INFO                             0x1770          //获取直流PDU类型通道
+#define POWER_DC_TOTAL_ALARM                      0x1776          //直流PDU总报警信息 2024.11.12
+#define POWER_DC_OUT_INFO                         0x177A          //直流PDU输出
+#define POWER_DC_STAT_INFO                        0x17E2          //直流PDU开关状
+#define POWER_DC_WARNING                          0x179A          //直流PDU报警信息
+#define POWER_DC_STAT_ERROR                       0x17E4          //直流PDU故障状态
+#define POWER_DC_IN_INFO                          0x1772          //直流PDU采集输入电压与输入电
+#define POWER_DC_START_DELAY                      0x17E6          //直流PDU延时
+#define POWER_DC_STOP_DELAY                       0x17F6          //直流PDU延时
+#define POWER_DC_THRESHOLD_VOL_MAX                0x17A2          //max voltage threshold
+#define POWER_DC_THRESHOLD_VOL_MIN                0x17B2          //min voltage threshold
+#define POWER_DC_THRESHOLD_CUR_MAX                0x17C2          //max current threshold
+#define POWER_DC_THRESHOLD_CUR_MIN                0x17D2          //max current threshold
+#define POWER_DC_THRESHOLD_POWER_MAX              0x1810          //max power threshold
+#define POWER_DC_THRESHOLD_POWERCON_MAX           0x181A          //max powercon threshold
+#define POWER_DC_ALL_OPEN_INFO                    0x1806          //ALL OPEN直流PDU开关状
+#define POWER_DC_ALL_CLOSE_INFO                   0x1807          //ALL OPEN直流PDU开关状
+#define POWER_DC_ALARM_CTRL                       0x182E          //超限动作
+#define POWER_DC_CONSUMP_CLEAR   	              0x1838          //重置直流耗电量
+#define POWER_DC_THRESHOLD_TOTAL_VOL_MAX          0x184C          //max total voltage threshold 2024.11.12
+#define POWER_DC_THRESHOLD_TOTAL_VOL_MIN          0x184D          //min total voltage threshold 2024.11.12
+#define POWER_DC_THRESHOLD_TOTAL_CUR_MAX          0x184E          //max total current threshold 2024.11.12
+#define POWER_DC_THRESHOLD_TOTAL_PWR_MAX          0x184F          //max total power threshold 2024.11.12
+#define POWER_DC_THRESHOLD_TOTAL_PWRCON_MAX       0x1850          //max total powercon threshold 2024.11.12
+#define POWER_DC_ALARM_CTRL_TOTAL                 0x1856          //总体超限动作   2024.11.12       
 
 #define POWER_AC3_GET_INFO                        0x1770          //获取三项类型通道
 #define POWER_AC3_IN_INFO                         0x1771          //三项交流输入

+ 828 - 0
f407/tools/web/data.js

@@ -0,0 +1,828 @@
+
+var PKT_TYPE=function(){
+    var len = 0;
+    return {
+        PKT_TYPE_ACK:len++,             
+        PKT_TYPE_PARAS:len++,             
+        PKT_TYPE_POWER_CH:len++,          //power_ch_t
+        PKT_TYPE_POWER_TOTAL:len++,       //power_total_t
+        PKT_TYPE_CH_ALL:len++,
+        PKT_TYPE_ALARM:len++,
+        PKT_TYPE_SENSOR:len++,
+        PKT_TYPE_BREAKER:len++,
+        PKT_TYPE_STAT:len++,
+        PKT_TYPE_MESG:len++,
+        PKT_TYPE_FILE:len++,
+    }
+}();
+
+
+///////////////////////////////////////////////////////
+function array_to_string(data){
+    var s = "";
+    for(var i=0;i<data.length  && data[i] !=0;i++){
+        s +=String.fromCharCode(data[i]);
+    }
+    return s;
+}
+
+function string_to_array(data,attr){
+    for(var i=0;i<data.length;i++){
+        attr[i] = data.charCodeAt(i);
+    }
+    return attr;
+}
+function array_cat(a1,a2){
+    var tlen=a1.byteLength+a2.byteLength;
+    var buffer = new ArrayBuffer(tlen);
+    var vw = new Uint8Array(buffer);
+    
+    var vw1 = new Uint8Array(a1);
+    for(var i=0; i<a1.byteLength; i++) {
+        vw[i] = vw1[i];
+    }
+    
+    var vw2 = new Uint8Array(a2);
+    for(var i=0; i<a2.byteLength; i++) {
+        vw[i+a1.byteLength] = vw2[i];
+    }
+    return buffer;
+}
+///////////////////////////////////////////////////
+function bin_to_hdr(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    this.magic = tmp.getUint32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.type = tmp.getUint32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.nack = tmp.getUint32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.dlen = tmp.getUint32(0,true);
+    length += 4;
+
+    this.len = length;
+}
+function bin_to_info(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    this.type = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.addr = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.ch = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.sch = tmp.getUint8(0,true);
+    length += 1;
+    
+    tmp = new DataView(bin, length);
+    this.pid = tmp.getUint8(0,true);
+    length += 1;
+    
+    tmp = new DataView(bin, length);
+    this.start_delay = tmp.getUint16(0,true);
+    length += 2;
+    
+    tmp = new DataView(bin, length);
+    this.stop_delay = tmp.getUint16(0,true);
+    length += 2;
+
+    this.len = length;
+}
+function bin_to_power(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    this.voltage = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.current = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.power = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.freq = tmp.getFloat32(0,true);
+    length += 4;
+    
+    tmp = new DataView(bin, length);
+    this.factor = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.consump = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.status = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.nwire = tmp.getUint8(0,true);
+    length += 1;
+
+    this.len = length;
+}
+function bin_to_alarm(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    this.v_upper = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.v_lower = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.c_upper = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.p_upper = tmp.getUint8(0,true);
+    length += 1;
+    
+    tmp = new DataView(bin, length);
+    this.w_upper = tmp.getUint8(0,true);
+    length += 1;
+    
+    tmp = new DataView(bin, length);
+    this.ph_loss = tmp.getUint8(0,true);
+    length += 1;
+
+    this.len = length;
+}
+function bin_to_thrval(bin) {
+    var tmp, length=0;
+    
+    tmp = new DataView(bin, length);
+    this.en = tmp.getUint8(0,true);
+    length += 1;
+
+    tmp = new DataView(bin, length);
+    this.val = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.act = tmp.getUint8(0,true);
+    length += 1;
+
+    this.act_para = [];
+    tmp = new DataView(bin, length);
+    for(var i=0; i<14; i++) {
+        this.act_para[i] = tmp.getUint8(i,true);
+    }
+    length += 14;
+
+    this.len = length;
+}
+function bin_to_thr(bin) {
+    var tmp, length=0;
+    
+    this.v_upper = new bin_to_thrval(bin.slice(length));
+    length += this.v_upper.len;
+    
+    this.v_lower = new bin_to_thrval(bin.slice(length));
+    length += this.v_lower.len;
+    
+    this.c_upper = new bin_to_thrval(bin.slice(length));
+    length += this.c_upper.len;
+    
+    this.p_upper = new bin_to_thrval(bin.slice(length));
+    length += this.p_upper.len;
+    
+    this.w_upper = new bin_to_thrval(bin.slice(length));
+    length += this.w_upper.len;
+
+    this.len = length;
+}
+function bin_to_powerc(bin) {
+    var tmp, bin2, length=0;
+
+    this.info = new bin_to_info(bin);
+    length += this.info.len;
+    
+    this.power = [];
+    for(var i=0; i<3; i++) {
+        this.power[i] = new bin_to_power(bin.slice(length));
+        length += this.power[i].len;
+    }
+    
+    this.thr = new bin_to_thr(bin.slice(length));
+    length += this.thr.len;
+    
+    this.alarm = new bin_to_alarm(bin.slice(length));
+    length += this.alarm.len;
+    
+    tmp = new DataView(bin, length);
+    this.time = tmp.getUint32(0,true);
+    length += this.time.len;
+    
+    tmp = new DataView(bin, length);
+    this.pbrd = tmp.getUint32(0,true);
+    length += this.pbrd.len;
+
+    this.len = length;
+}
+function bin_to_total(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    this.voltage = tmp.getFloat32 (0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.current = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.power = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.freq = tmp.getFloat32(0,true);
+    length += 4;
+    
+    tmp = new DataView(bin, length);
+    this.consump = tmp.getFloat32 (0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.active = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.reactive = tmp.getFloat32(0,true);
+    length += 4;
+
+    tmp = new DataView(bin, length);
+    this.apparent = tmp.getFloat32(0,true);
+    length += 4;
+    
+    this.len = length;
+}
+function bin_to_powert(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    this.type = tmp.getUint8(0,true);
+    length += 1;
+
+    this.total = [];
+    for(var i=0; i<3; i++) {
+        this.total[i] = new bin_to_total(bin.slice(length));
+        length += this.total[i].len;
+    }
+    
+    this.len = length;
+}
+function bin_to_chall(bin) {
+    var tmp, length=0;
+
+    tmp = new DataView(bin, length);
+    var chall = tmp.getUint8(0,true);
+    length += 1;
+
+    return chall;
+}
+function bin_to_alarmd(bin) {
+    var tmp, length=0;
+    
+    tmp = new DataView(bin, length);
+    this.ch = tmp.getUint8(0,true);
+    length += 1;
+    
+    this.alarm = new bin_to_alarm(bin.slice(leng));
+    length += this.alarm.len;
+    
+    tmp = new DataView(bin, length);
+    this.time = tmp.getUint32(0,true);
+    length += 1;
+
+    this.len = length;
+}
+///////////////////////////////////////////////////
+function hdr_to_bin(js) {
+    var tmp, length=0;
+    var buffer = new ArrayBuffer(js.len);
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint32(0,js.magic,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint32(0,js.type,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint32(0,js.nack,true);
+    length += 4;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint32(0,js.dlen,true);
+    length += 4;
+
+    return buffer;
+}
+function info_to_bin(js) {
+    var tmp, length=0;
+    var buffer = new ArrayBuffer(js.len);
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.type,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.addr,true);
+    length += 1;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.ch,true);
+    length += 1;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.sch,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.pid,true);
+    length += 1;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint16(0,js.start_delay,true);
+    length += 2;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint16(0,js.stop_delay,true);
+    length += 2;
+
+    return buffer;
+}
+function power_to_bin(js) {
+    var tmp, length=0;
+    var buffer = new ArrayBuffer(js.len);
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.voltage,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.current,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.power,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.freq,true);
+    length += 4;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.factor,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.consump,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.status,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.nwire,true);
+    length += 1;
+
+    return buffer;
+}
+function alarm_to_bin(js) {
+    var tmp, length=0;
+    var buffer = new ArrayBuffer(js.len);
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.v_upper,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.v_lower,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.c_upper,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.p_upper,true);
+    length += 1;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.w_upper,true);
+    length += 1;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.ph_loss,true);
+    length += 1;
+
+    return buffer;
+}
+function thrval_to_js(js) {
+    var tmp, length=0;
+    var buffer = new ArrayBuffer(js.len);
+    
+    tmp = new DataView(buffer, length);
+    tmp.setUint8(0,js.en,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.val,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.getUint8(0,js.act,true);
+    length += 1;
+
+    tmp = new DataView(buffer, length);
+    for(var i=0; i<14; i++) {
+        tmp.setUint8(i,js.act_para[i],true);
+    }
+    length += 14;
+
+    return buffer;
+}
+function thr_to_bin(js) {
+    var bin,tmp, length=0;
+    
+    bin = thrval_to_js(js.v_upper);
+    tmp = thrval_to_js(js.v_lower);
+    
+    bin = array_cat(bin, tmp);
+    tmp = thrval_to_js(js.c_upper);
+    bin = array_cat(bin, tmp);
+    
+    tmp = thrval_to_js(js.p_upper);
+    bin = array_cat(bin, tmp);
+    
+    tmp = thrval_to_js(js.w_upper);
+    bin = array_cat(bin, tmp);
+
+    return bin;
+}
+function powerc_to_bin(js) {
+    var bin,tmp, length=0;
+    
+    bin = info_to_bin(js.info);
+    
+    for(var i=0; i<3; i++) {
+        tmp = power_to_bin(js.power[i]);
+        bin = array_cat(bin, tmp);
+    }
+    
+    tmp = thr_to_bin(js.thr);
+    bin = array_cat(bin, tmp);
+
+    tmp = alarm_to_bin(js.alarm);
+    bin = array_cat(bin, tmp);
+    
+    var buf = new ArrayBuffer(8);
+    tmp = new DataView(buf, 0);
+    tmp.setUint32(0,js.time,true);
+    tmp.setUint32(4,js.pbrd,true);
+    
+    bin = array_cat(bin, buf);
+
+    return bin;
+}
+function total_to_bin(js) {
+    var tmp, length=0;
+    var buffer = new ArrayBuffer(js.len);
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.voltage,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.current,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.power,true);
+    length += 4;
+
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.freq,true);
+    length += 4;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.consump,true);
+    length += 4;
+    
+    ///
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.active,true);
+    length += 4;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.reactive,true);
+    length += 4;
+    
+    tmp = new DataView(buffer, length);
+    tmp.setFloat32(0,js.apparent,true);
+    length += 4;
+
+    return buffer;
+}
+function powert_to_bin(js) {
+    var tmp,bin2,length=0;
+    var bin = new ArrayBuffer(1);
+
+    tmp = new DataView(bin, length);
+    tmp.setUint8(0,js.type,true);
+    length += 4;
+
+    for(var i=0; i<3; i++) {
+        bin2 = total_to_bin(js.total[i]);
+        bin = array_cat(bin, bin2);
+    }
+
+    return bin;
+}
+function chall_to_bin(js) {
+    var tmp, length=0;
+    var bin = new ArrayBuffer(1);
+
+    tmp = new DataView(bin, length);
+    tmp.setUint8(0,js,true);
+    length += 1;
+
+    return bin;
+}
+function alarmd_to_bin(js) {
+    var tmp, length=0;
+    var bin,buffer = new ArrayBuffer(1);
+
+    tmp = new DataView(buffer, 0);
+    tmp.setUint8(0,js.ch,true);
+    
+    var alarm = alarm_to_bin(js.alarm);
+    bin = array_cat(buffer, alarm);
+
+    buffer = new ArrayBuffer(4);
+    tmp = new DataView(buffer, 0);
+    tmp.setUint32(0,js.time,true);
+
+    return array_cat(bin, buffer);
+}
+//////////////////////////////////////////////////////////////
+
+var XXX ={};
+XXX.hdr = function() {
+    this.j2b = function (js) {
+        var tmp;
+        var hdr = new hdr_to_bin(js);
+
+        switch(js.type){
+            case PKT_TYPE.PKT_TYPE_POWER_CH:
+                tmp = BIN.powerc.j2b(js.powerc);
+                break;
+
+            case PKT_TYPE.PKT_TYPE_POWER_TOTAL:
+                tmp = BIN.powert.j2b(js.powert);
+                break;
+                
+           case PKT_TYPE.PKT_TYPE_CH_ALL:
+                tmp = BIN.chall.j2b(js);
+                break;
+               
+           case PKT_TYPE.PKT_TYPE_ALARM:
+                tmp = BIN.alarm.j2b(js);
+                break;
+                
+           default:
+           return tmp;
+        }
+        return array_cat(hdr,tmp);
+    };
+
+    this.b2j = function (bin) {
+        var tmp;
+        var hdr = new bin_to_hdr(bin);
+        
+        if(hdr.nack == 1){
+            //tmp = myBinary.ack.bin2js(bin,this.hdr.len,true);
+            //myLog('log',tmp);
+            //var data = tmp.data;
+        }
+        
+        var data = bin.slice(hdr.len);
+        switch(hdr.type) {
+            case PKT_TYPE.PKT_TYPE_POWER_CH:
+                hdr.powerc = BIN.powerc.b2j(data);
+                break;
+
+            case PKT_TYPE.PKT_TYPE_POWER_TOTAL:
+                hdr.powert = BIN.powert.b2j(data);
+                break;
+            
+            case PKT_TYPE.PKT_TYPE_CH_ALL:
+                hdr.chall = BIN.chall.b2j(data);
+                break;
+               
+           case PKT_TYPE.PKT_TYPE_ALARM:
+                hdr.alarm = BIN.alarm.b2j(data);
+                break;
+            
+            default :
+                console.log("wrong hdr type: "+hdr.type);
+        }
+        return hdr;
+    }
+};
+XXX.paras=function() {
+    this.j2b = function (js) {
+        
+    }
+    
+    this.b2j = function (bin) {
+        
+    }
+};
+XXX.powerc=function() {
+    this.j2b = function (js) {
+        return new powerc_to_bin(js);
+    }
+
+    this.b2j = function (bin) {
+        return new bin_to_powerc(bin);
+    }
+};
+XXX.powert=function() {
+    this.j2b = function (js) {
+        return new powert_to_bin(js);
+    }
+
+    this.b2j = function (bin) {
+        return new bin_to_powert(bin);
+    }
+};
+XXX.chall=function() {
+    this.j2b = function (js) {
+        return new chall_to_bin(js);
+    }
+
+    this.b2j = function (bin) {
+        return new bin_to_chall(bin);
+    }
+};
+XXX.alarmd=function() {
+    this.j2b = function (js) {
+        return new alarmd_to_bin(js);
+    }
+
+    this.b2j = function (bin) {
+        return new bin_to_alarmd(bin);
+    }
+};
+
+
+var BIN=new function() {
+    this.hdr = new XXX.hdr();
+    this.paras = new XXX.paras();
+    this.powerc = new XXX.powerc();
+    this.powert = new XXX.powert();
+    this.chall = new XXX.chall();
+    this.alarmd = new XXX.alarmd();
+}();
+
+
+//////////////////////////////////////////
+function LOG(){
+    var data = [];
+    for(var i= 1,len=arguments.length;i<len;i++){
+        data.push(arguments[i])
+    }
+    console.log(data);
+
+}
+
+var PKT_TYPE=function(){
+    var len = 0;
+    return {
+        PKT_TYPE_ACK:len++,             
+        PKT_TYPE_PARAS:len++,             
+        PKT_TYPE_POWER_CH:len++,          //power_ch_t
+        PKT_TYPE_POWER_TOTAL:len++,       //power_total_t
+        PKT_TYPE_SENSOR:len++,
+        PKT_TYPE_BREAKER:len++,
+        PKT_TYPE_STAT:len++,
+        PKT_TYPE_MESG:len++,
+        PKT_TYPE_FILE:len++,
+    }
+}();
+
+
+function WS(url,fn) {
+    this.url = url;
+    this.name = 'myWebs';
+    this.open = _open;
+    this.reopen = _reopen;
+    this.close = _close;
+    this.send = _send;
+    this.state = _state;
+    this.setcb = _setcb;
+    this.closeCount = 0;
+    this.maxConnect = 100;
+    var his = this;
+    this.open();
+    function _open() {
+        console.log("____ url: \n", his.url);
+        his.ws = new WebSocket(his.url);
+        his.ws.binaryType = 'arraybuffer';
+        his.ws.onopen = _onopen;
+        his.ws.onclose = _onclose;
+        his.ws.onmessage = _onmsg;
+        his.ws.onerror = _onerror;
+    }
+
+    function _reopen() {
+        _close();
+        _open(his.url);
+    }
+
+    function _close() {
+        his.ws.close();
+    }
+
+    function _send(msg) {
+        if (his.ws.readyState != WebSocket.OPEN)
+            return;
+        his.ws.send(msg);
+    }
+
+    function _state() {
+        return his.ws.readyState;
+    }
+
+    function _setcb(tp, f) {
+        switch (tp) {
+            case "open":
+                his.ws.onopen = f;
+                break;
+
+            case "close":
+                his.ws.onclose = f;
+                break;
+
+            case "msg":
+                his.ws.onmessage = f;
+                break;
+
+            case "err":
+                his.ws.onerror = f;
+                break;
+        }
+    }
+
+    function _onopen(evt) {
+        his.closeCount = 0;
+        console.log("___ ws.onopen");
+    }
+
+    function _onclose(evt) {
+        LOG("ws.onclose");
+        setTimeout(_reopen, 3000);
+        his.closeCount += 1;
+    }
+
+    function _onmsg(evt) {
+        console.log("___ ws.onmsg");
+        if (evt.data instanceof ArrayBuffer) {
+            fn(evt.data);
+        }
+    }
+
+    function _onerror(evt) {
+        console.log("___ ws.onerror");
+        //write_scr('<span style="color: red;">ERROR:</span> '+ evt.data);
+    }
+
+}
+
+

+ 40 - 0
f407/tools/web/index.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>ws test</title>
+    <script src="data.js"></script>
+</head>
+    
+<body>
+    <script>
+    
+    function on_ws_msg(bin){
+        var j = BIN.hdr.b2j(bin);
+        
+        console.log(j);
+        var b = BIN.hdr.j2b(j);
+        
+        console.log(b);
+        ws.send(b);
+        
+    }
+    function ws_hdr(){
+        var proto = window.location.protocol,ws;
+        if (proto == 'https:'){
+            ws = 'wss://';
+        }else{
+            ws = 'ws://';
+        }
+        return ws;
+    }
+
+    ws = new WS("ws://localhost:8888/websocket",on_ws_msg);
+
+    
+    
+    
+    </script>
+</body>
+
+</html>

BIN
f407/tools/webServer/EasyWebSvr.exe


+ 27 - 0
f407/tools/webServer/EasyWebSvr.ini

@@ -0,0 +1,27 @@
+[WebServer]
+RootDir=..\web
+ListenPort=80
+MaxThreadNum=100
+Timeout=5000
+bAutoRun=0
+bIconStartStop=0
+MaxContentLength=16777216
+MaxHeaderLength=4096
+[Cgi]
+EnableCgi=1
+EnableIsapi=1
+IsapiCache=1
+EnablePhp=1
+[Docs]
+DefaultHtml=index.htm,index.html,default.htm,index.php
+EnableDirBrowse=0
+ShowDirAlways=0
+[ScriptEngine]
+[Log]
+LogToWindow=1
+LogWndMaxLine=5000
+LogToFile=0
+LogFileName=
+[StartParam]
+bShowWnd=0
+bStartRun=0

+ 224 - 0
f407/tools/wsServer/mg.cpp

@@ -0,0 +1,224 @@
+// Copyright (c) 2020 Cesanta Software Limited
+// All rights reserved
+//
+// Example Websocket server. See https://mongoose.ws/tutorials/websocket-server/
+
+#include "mongoose.h"
+#include "datadef.h"
+
+#define PWR_TYPE PDU_AC_I3O3
+
+
+static const char *s_listen_on = "ws://localhost:8888";
+static const char *s_web_root = ".";
+static void send_powerc(struct mg_connection* c);
+
+static int ws_send(struct mg_connection* c, int type, void *data, int len)
+{
+    pkt_hdr_t* h = (pkt_hdr_t*)malloc(sizeof(pkt_hdr_t)+len);
+    if (!h) {
+        return -1;
+    }
+    h->magic = PKT_MAGIC;
+    h->type = type;
+    h->nack = 3;
+    h->dlen = len;
+    memcpy(h->data, data, len);
+    mg_ws_send(c, (const void*)h, sizeof(pkt_hdr_t) + len, WEBSOCKET_OP_BINARY);
+
+    return 0;
+}
+
+
+// This RESTful server implements the following endpoints:
+//   /websocket - upgrade to Websocket, and implement websocket echo server
+//   /rest - respond with JSON string {"result": 123}
+//   any other URI serves static files from s_web_root
+static void fn(struct mg_connection *c, int ev, void *ev_data) {
+  if (ev == MG_EV_WS_OPEN) {
+      
+  } else if (ev == MG_EV_HTTP_MSG) {
+        struct mg_http_message *hm = (struct mg_http_message *) ev_data;
+        if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
+            // Upgrade to websocket. From now on, a connection is a full-duplex
+            // Websocket connection, which will receive MG_EV_WS_MSG events.
+            mg_ws_upgrade(c, hm, NULL);
+        } else if (mg_match(hm->uri, mg_str("/rest"), NULL)) {
+            // Serve REST response
+            mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);
+        } else {
+            // Serve static files
+            struct mg_http_serve_opts opts = {.root_dir = s_web_root};
+            mg_http_serve_dir(c, (struct mg_http_message*)ev_data, &opts);
+        }
+  } else if (ev == MG_EV_WS_MSG) {
+    // Got websocket frame. Received data is wm->data. Echo it back!
+    struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
+     pkt_hdr_t *h= (pkt_hdr_t*)wm->data.buf;
+     power_total_t* pt = (power_total_t*)h->data;
+
+    //mg_ws_send(c, wm->data.buf, wm->data.len, WEBSOCKET_OP_TEXT);
+  }
+}
+
+static float rand_float(float min, float max) {
+    return ((float)rand()/(float)RAND_MAX) * (max - min) + min;
+}
+static void powert_rand(power_total_t *pt)
+{
+    int i,cnt = 1;
+#if 0
+    pt->voltage = 1.1f;
+    pt->current = 2.2f;
+    pt->freq = 3.3f;
+    pt->power = 4.4f;
+    pt->consump = 5.5f;
+    pt->active = 6.6f;
+    pt->reactive = 7.7f;
+    pt->apparent = 8.8f;
+#else
+    if (pt->type >= PDU_AC_I3O3) {
+        cnt = 3;
+    }
+    for (i = 0; i < cnt; i++) {
+        pt->total[i].voltage = rand_float(1.0f, 100.0f);
+        pt->total[i].current = rand_float(1.0f, 100.0f);
+        pt->total[i].freq = rand_float(1.0f, 100.0f);
+        pt->total[i].power = rand_float(1.0f, 100.0f);
+        pt->total[i].consump = rand_float(1.0f, 100.0f);
+        pt->total[i].active = rand_float(1.0f, 100.0f);
+        pt->total[i].reactive = rand_float(1.0f, 100.0f);
+        pt->total[i].apparent = rand_float(1.0f, 100.0f);
+    }
+#endif
+}
+
+
+static void thrval_set(thr_val_t* tv)
+{
+    tv->en = 0;
+    tv->val = 100.0f;
+    tv->act = 0;
+    memset(tv->para, 0, 14);
+}
+static void thr_set(thr_t *thr)
+{
+    thrval_set(&thr->v_upper);
+    thrval_set(&thr->v_lower);
+    thrval_set(&thr->c_upper);
+    thrval_set(&thr->p_upper);
+    thrval_set(&thr->w_upper);
+}
+static void alarm_set(alarm_t* a)
+{
+    a->v_upper = 0;
+    a->v_lower = 0;
+    a->c_upper = 0;
+    a->p_upper = 0;
+    a->w_upper = 0;
+}
+static void powerc_rand(power_ch_t* pc, uint8_t addr, uint8_t ch, uint8_t sch)
+{
+    int i,cnt = 1;
+
+    pc->info.type = PWR_TYPE;
+    pc->info.addr = addr;
+    pc->info.ch = ch;
+    pc->info.sch = sch;
+    pc->info.pid = 0;
+    pc->info.start_delay = 0;
+    pc->info.stop_delay = 0;
+    
+    thr_set(&pc->thr);
+    alarm_set(&pc->alarm);
+
+    if (pc->info.type >= PDU_AC_I3O3) {
+        cnt = 3;
+    }
+
+    for (i = 0; i < cnt; i++) {
+        pc->power[i].voltage = rand_float(100.0f, 400.0f);
+        pc->power[i].current = rand_float(1.0f, 100.0f);
+        pc->power[i].freq = 50.0f;
+        pc->power[i].power = rand_float(1.0f, 100.0f);
+        pc->power[i].consump = rand_float(1.0f, 100.0f);
+        pc->power[i].factor = rand_float(0.0f, 1.0f);
+        pc->power[i].status = 1;
+        pc->power[i].nwire = 0;
+    }
+
+    pc->time = 0;
+}
+static void send_powerc(struct mg_connection *c)
+{
+    int i,j,ch=0;
+    power_ch_t pc;
+#if 1
+    #define BOARD_CNT       5
+    #define BOARC_CH_CNT    5
+
+    uint8_t addr[BOARD_CNT] = {2,4,6,7,8};
+#else
+    #define BOARD_CNT       1
+    #define BOARC_CH_CNT    1
+
+    uint8_t addr[BOARD_CNT] = { 2 };
+#endif
+    for (i = 0; i < BOARD_CNT; i++) {
+        for (j = 0; j < BOARC_CH_CNT; j++) {
+            powerc_rand(&pc, addr[i], ch, j);
+            ws_send(c, PKT_TYPE_POWER_CH , &pc, sizeof(pc));
+            ch++;
+        }
+    }
+}
+static void send_powert(struct mg_connection* c)
+{
+    power_total_t pt;
+    
+    powert_rand(&pt);
+    ws_send(c, PKT_TYPE_POWER_TOTAL , &pt, sizeof(pt));
+}
+static void send_alarm(struct mg_connection* c)
+{
+    alarm_data_t a;
+
+    a.ch = 0;
+    a.alarm.v_upper = 1;
+    a.alarm.v_lower = 0;
+    a.alarm.c_upper = 0;
+    a.alarm.p_upper = 0;
+    a.alarm.w_upper = 0;
+    a.time = 0;
+    ws_send(c, PKT_TYPE_ALARM, &a, sizeof(a));
+}
+
+static void timer_fn(void* arg)
+{
+    static uint32_t cnt = 0;
+    struct mg_mgr* mgr = (struct mg_mgr*)arg;
+
+    cnt++;
+    for (struct mg_connection* c = mgr->conns; c != NULL; c = c->next) {
+        send_powerc(c);
+        send_powert(c);
+
+        if (cnt%10==0) {
+            send_alarm(c);
+        }
+    }
+}
+
+
+int main(void) {
+  struct mg_mgr mgr;  // Event manager
+
+  srand((uint32_t)time(NULL));
+  mg_mgr_init(&mgr);  // Initialise event manager
+  printf("ws server on %s/websocket\n", s_listen_on);
+  mg_timer_add(&mgr, 1000, MG_TIMER_REPEAT, timer_fn, &mgr);
+  mg_http_listen(&mgr, s_listen_on, fn, NULL);  // Create HTTP listener
+  for (;;) mg_mgr_poll(&mgr, 200);             // Infinite event loop
+  mg_mgr_free(&mgr);
+  return 0;
+}

+ 31 - 0
f407/tools/wsServer/mg.sln

@@ -0,0 +1,31 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.9.34728.123
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mg", "mg.vcxproj", "{B5693C82-AC11-41F2-8435-21840831EFD5}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Debug|x64.ActiveCfg = Debug|x64
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Debug|x64.Build.0 = Debug|x64
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Debug|x86.ActiveCfg = Debug|Win32
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Debug|x86.Build.0 = Debug|Win32
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Release|x64.ActiveCfg = Release|x64
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Release|x64.Build.0 = Release|x64
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Release|x86.ActiveCfg = Release|Win32
+		{B5693C82-AC11-41F2-8435-21840831EFD5}.Release|x86.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {89324FEA-995C-466E-B9A8-1AE4AE50BE8B}
+	EndGlobalSection
+EndGlobal

+ 139 - 0
f407/tools/wsServer/mg.vcxproj

@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <VCProjectVersion>17.0</VCProjectVersion>
+    <Keyword>Win32Proj</Keyword>
+    <ProjectGuid>{b5693c82-ac11-41f2-8435-21840831efd5}</ProjectGuid>
+    <RootNamespace>mg</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v143</PlatformToolset>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="Shared">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+      <LanguageStandard>stdcpp20</LanguageStandard>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <AdditionalIncludeDirectories>..\..\applications</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+      <SDLCheck>true</SDLCheck>
+      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <ConformanceMode>true</ConformanceMode>
+    </ClCompile>
+    <Link>
+      <SubSystem>Console</SubSystem>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="mg.cpp" />
+    <ClCompile Include="mongoose.c" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 25 - 0
f407/tools/wsServer/mg.vcxproj.filters

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="源文件">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="头文件">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
+    </Filter>
+    <Filter Include="资源文件">
+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="mg.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
+    <ClCompile Include="mongoose.c">
+      <Filter>源文件</Filter>
+    </ClCompile>
+  </ItemGroup>
+</Project>

+ 4 - 0
f407/tools/wsServer/mg.vcxproj.user

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup />
+</Project>

+ 20 - 0
f407/tools/wsServer/mg2.cpp

@@ -0,0 +1,20 @@
+// mg.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
+//
+
+#include <iostream>
+
+int main()
+{
+    std::cout << "Hello World!\n";
+}
+
+// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
+// 调试程序: F5 或调试 >“开始调试”菜单
+
+// 入门使用技巧: 
+//   1. 使用解决方案资源管理器窗口添加/管理文件
+//   2. 使用团队资源管理器窗口连接到源代码管理
+//   3. 使用输出窗口查看生成输出和其他消息
+//   4. 使用错误列表窗口查看错误
+//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
+//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

Plik diff jest za duży
+ 20300 - 0
f407/tools/wsServer/mongoose.c


Plik diff jest za duży
+ 3287 - 0
f407/tools/wsServer/mongoose.h