浏览代码

解决F407单相3相读数据,和通道控制与网页显示的问题。

liyi 1 年之前
父节点
当前提交
cf40c32072

+ 2 - 2
f407/applications/cfg.h

@@ -49,8 +49,8 @@
     
     #define CHANNEL_DELAY                       8
 
-    //#define PROD_TYPE                           PDU_AC_I3O3
-    #define PROD_TYPE                           PDU_AC_I1O1
+    #define PROD_TYPE                           PDU_AC_I3O3
+    //#define PROD_TYPE                           PDU_AC_I1O1
     
     #define USE_UI
     #define ROTATE                             90

+ 1 - 1
f407/applications/dflt.c

@@ -32,7 +32,7 @@ const paras_data_t DFLT_PARAS={
         
         .netwk = {
             .mode = 1,                                   //0:dhcp   1:static
-            .ipaddr = "192.168.1.132",
+            .ipaddr = "192.168.1.166",
             .mask = "255.255.255.0",
             .gateway = "192.168.1.1",
             .dns1 = "8.8.8.8",

+ 2 - 2
f407/applications/main.c

@@ -98,10 +98,10 @@ static int user_init(void)
     paras_data_t *p=paras_get();
     modbus_data_t *cas=&p->cas;
     
-    //power_init();
+    power_init();
     //cascade_init(cas->mode, cas->addr, cas->baud);
     
-    //web_init();
+    web_init();
     
     return 0;
 }

+ 231 - 27
f407/applications/power.c

@@ -184,6 +184,10 @@ static int get_key(power_handle_t *h, uint8_t addr, board_key_t *key)
         if(r==0) {
             key->type = (tmp[0]>>8)&0xFF;
             key->chs = tmp[0]&0xFF;
+					if(h->prod->type == PDU_AC_I3O3)			
+					{
+						key->chs /= 3;
+					}
             return 0;
         }
     }
@@ -462,6 +466,7 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                 }
 
                 offset = POWER_AC_STAT_INFO_L;
+								memset(tmp,0,sizeof(tmp));
                 r = read_reg(h, pbrd->addr, offset, tmp, pbrd->chs);
                 if (r<0) {
                     LOGE("read_reg failed, addr:%d reg:0x%04x/%d cnt:%d\n", pbrd->addr, offset, offset, pbrd->chs);
@@ -489,6 +494,21 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                 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.val = ((buffer[1]<<16)|buffer[0])/1000;
+									pch->thr.v_lower.val = ((buffer[3]<<16)|buffer[2])/1000;
+									pch->thr.c_upper.val = ((buffer[5]<<16)|buffer[4])/1000;
+									pch->thr.p_upper.val = ((buffer[9]<<16)|buffer[8])/1000;
+									pch->thr.w_upper.val = ((buffer[13]<<16)|buffer[12])/1000;
+								}
             }
             break;
 
@@ -576,18 +596,25 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                 }
                 
                 for (i=0; i<pbrd->chs; i++) {
-                    int Index = i * 16;
-                    
-                    if(h->prod->type==PDU_AC_I3O3) {
-                        int ch_idx = pbrd->ch0+i/3;
-                        int ph_idx = i%3;
-                        pwr = &pbrd->pch[ch_idx].power[ph_idx];
-                    }
-                    else {
-                        pwr = &pbrd->pch[i].power[0];
-                    }
-                    
+
+                   if(h->prod->type==PDU_AC_I3O3) {
+										 int index_2 = 0;
+										 for(int j = 0; j < 3;j++)
+										 {
+											 pwr = &pbrd->pch[i].power[j];
+											 index_2 = (j*16) + (48*i);
+											 pwr->voltage = ((tmp[1+index_2] << 16) + tmp[0+index_2])/1000.0f;
+											 pwr->current = ((tmp[3+index_2] << 16) + tmp[2+index_2])/1000.0f;
+											 pwr->power 	= ((tmp[5+index_2] << 16) + tmp[4+index_2])/1000.0f;
+											 pwr->freq 		= ((tmp[11+index_2] << 16) + tmp[10+index_2])/1000.0f;
+											 pwr->consump = ((tmp[13+index_2] << 16) + tmp[12+index_2])/1000.0f;
+											 pwr->factor 	= ((tmp[15+index_2] << 16) + tmp[14+index_2])/1000.0f;
+										 }
+									 }else{
+										int Index = i * 16;
+                    pwr = &pbrd->pch[i].power[0];
                     float value = (tmp[1+Index] << 16) + tmp[0+Index];
+
                     pwr->voltage = value / 1000.0f;
                     
                     value = (tmp[3+Index] << 16) + tmp[2+Index];
@@ -609,7 +636,8 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     value = (tmp[15+Index] << 16) + tmp[14+Index];
                     pwr->factor = value / 1023.0f;
                     
-                    pbrd->pch[i].time = tm;
+                    pbrd->pch[i].time = tm;										
+									}
                 }
                 
                 //获取通道开关状态及零线状态 
@@ -620,9 +648,15 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                     break;
                 }
                 for (i=0; i<pbrd->chs; i++) {
+									if(h->prod->type==PDU_AC_I3O3) {
+									for(int j = 0; j < 3;j++)
+										pbrd->pch[i].power[j].status = tmp[0+(j*2)+ (i*6)] & 0x01;
+									pbrd->pch[i].power[0].nwire  = tmp[18] & 0x01;
+									}else {
                     int Index = i * 2;
                     pbrd->pch[i].power[0].status = tmp[0+Index] & 0x01;
                     pbrd->pch[i].power[0].nwire  = tmp[18] & 0x01;
+									}
                 }
                 
                 //获取故障状态
@@ -665,6 +699,89 @@ static int board_read(power_handle_t *h, board_data_t *pbrd)
                 }
                 pbrd->brk[0].samp.sw = (tmp[0]&BIT(0))?1:0;
                 pbrd->brk[0].samp.time = tm;
+								
+								// read v max
+								offset = POWER_AC3_THRESHOLD_VOL_MAX;
+								
+								r = read_reg(h, pch->info.addr, offset, tmp, 18);
+								for (i=0; i<pbrd->chs; i++)
+								{
+									 
+                   if(h->prod->type==PDU_AC_I3O3) {
+											int Index = i * 3;
+                      int ch_idx = pbrd->ch0-1+i/3;
+                      pch = &pbrd->pch[ch_idx];
+											pch->thr.v_upper.val = ((tmp[Index+1] << 16) + (tmp[Index+0])) / 1000;
+                    }
+                    else {
+											pch = &pbrd->pch[i];
+											pch->thr.v_upper.val = ((tmp[i+1] << 16) + (tmp[i+0])) / 1000;               
+                    }
+								}
+								offset = POWER_AC3_THRESHOLD_VOL_MIN;
+								r = read_reg(h, pch->info.addr, offset, tmp, 18);		
+								for (i=0; i<pbrd->chs; i++)
+								{
+									 
+                   if(h->prod->type==PDU_AC_I3O3) {
+											int Index = i * 3;
+                      int ch_idx = pbrd->ch0-1+i/3;
+                      pch = &pbrd->pch[ch_idx];
+											pch->thr.v_lower.val = ((tmp[Index+1] << 16) + (tmp[Index+0])) / 1000;
+                    }
+                    else {
+											pch = &pbrd->pch[i];
+											pch->thr.v_lower.val = ((tmp[i+1] << 16) + (tmp[i+0])) / 1000;               
+                    }
+								}								
+								offset = POWER_AC3_THRESHOLD_CUR_MAX;
+								r = read_reg(h, pch->info.addr, offset, tmp, 18);		
+								for (i=0; i<pbrd->chs; i++)
+								{
+									 
+                   if(h->prod->type==PDU_AC_I3O3) {
+											int Index = i * 3;
+                      int ch_idx = pbrd->ch0-1+i/3;
+                      pch = &pbrd->pch[ch_idx];
+											pch->thr.c_upper.val = ((tmp[Index+1] << 16) + (tmp[Index+0])) / 1000;
+                    }
+                    else {
+											pch = &pbrd->pch[i];
+											pch->thr.c_upper.val = ((tmp[i+1] << 16) + (tmp[i+0])) / 1000;               
+                    }
+								}		
+								offset = POWER_AC3_THRESHOLD_PWR_MAX;
+								r = read_reg(h, pch->info.addr, offset, tmp, 18);		
+								for (i=0; i<pbrd->chs; i++)
+								{
+									 
+                   if(h->prod->type==PDU_AC_I3O3) {
+											int Index = i * 3;
+                      int ch_idx = pbrd->ch0-1+i/3;
+                      pch = &pbrd->pch[ch_idx];
+											pch->thr.p_upper.val = ((tmp[Index+1] << 16) + (tmp[Index+0])) / 1000;
+                    }
+                    else {
+											pch = &pbrd->pch[i];
+											pch->thr.p_upper.val = ((tmp[i+1] << 16) + (tmp[i+0])) / 1000;               
+                    }
+								}
+								offset = POWER_AC3_THRESHOLD_PWRCON_MAX;
+								r = read_reg(h, pch->info.addr, offset, tmp, 18);		
+								for (i=0; i<pbrd->chs; i++)
+								{
+									 
+                   if(h->prod->type==PDU_AC_I3O3) {
+											int Index = i * 3;
+                      int ch_idx = pbrd->ch0-1+i/3;
+                      pch = &pbrd->pch[ch_idx];
+											pch->thr.w_upper.val = ((tmp[Index+1] << 16) + (tmp[Index+0])) / 1000;
+                    }
+                    else {
+											pch = &pbrd->pch[i];
+											pch->thr.w_upper.val = ((tmp[i+1] << 16) + (tmp[i+0])) / 1000;               
+                    }
+								}									
             }
             break;
             
@@ -1067,6 +1184,65 @@ int power_reset(void)
     return r;
 }
 
+int power_set_ch_sw_n(power_ch_t *pch)
+{
+		int r;
+		uint16_t	st= pch->power[0].status,offset,tmp[2]={0};
+		power_handle_t *h=&pwrHandle;
+    lock_on(h->lck);		
+    if (pch->thr.v_upper.en == 1)
+        st |= ENABLE_AC3_V_UP;
+    if (pch->thr.v_lower.en == 1)
+        st |= ENABLE_AC3_V_DOWN;
+    if (pch->thr.c_upper.en == 1)
+        st |= ENABLE_AC3_C_UP;
+    if (pch->thr.p_upper.en == 1)
+        st |= ENABLE_AC3_P_UP;
+    if (pch->thr.w_upper.en == 1)
+        st |= ENABLE_AC3_W_UP;
+		switch(pch->info.type) {
+
+        case AC_SINGLE_S_TYPE:
+        case AC_SINGLE_B_TYPE:
+        {
+            offset = POWER_AC_CH_STAT_L + pch->info.ch-1;
+            tmp[0] = st;
+            r = write_reg(h, pch->info.addr, offset, tmp, 1);
+        }
+        break;			
+			  case DCPDU_TYPE:
+        {
+            uint16_t mask;
+            offset = POWER_DC_STAT_INFO+pch->info.ch-1;
+            
+            mask = ~(1 << (pch->info.ch-1));
+            tmp[0] &= mask;
+            tmp[0] |= (st << (pch->info.ch-1));
+            r = write_reg(h, pch->info.addr, offset, tmp, 2);
+        }
+        break;
+        
+        case TREE_AC_TYPE:
+        {
+            uint16_t reg;
+            uint8_t type=paras_get()->prod.type;
+            if(type==PDU_AC_I3O3 || type==PDU_AC_I3O1) {
+                reg = POWER_AC3_CH_OUT_ENABLE;
+            }
+            else {
+                reg = POWER_AC3_OUT_ENABLE;
+            }
+            
+            tmp[0] = st;
+            offset = reg+pch->info.ch-1;
+            r = write_reg(h, pch->info.addr, offset, tmp, 2);
+        }
+        break;
+		}
+		lock_off(h->lck);
+}
+
+
 
 int power_set_ch_sw(uint8_t ch, uint8_t on)
 {
@@ -1098,8 +1274,8 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
         case AC_SINGLE_B_TYPE:
         {
             offset = POWER_AC_CH_STAT_L + pch->info.ch-1;
-            tmp[0] = st; tmp[1] = 0;
-            r = write_reg(h, pch->info.addr, offset, tmp, 2);
+            tmp[0] = st;;
+            r = write_reg(h, pch->info.addr, offset, tmp, 1);
         }
         break;
         
@@ -1120,10 +1296,10 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
             uint16_t reg;
             uint8_t type=paras_get()->prod.type;
             if(type==PDU_AC_I3O3 || type==PDU_AC_I3O1) {
-                reg = POWER_AC3_OUT_ENABLE;
+                reg = POWER_AC3_CH_OUT_ENABLE;
             }
             else {
-                reg = POWER_AC3_CH_OUT_ENABLE;
+                reg = POWER_AC3_OUT_ENABLE;
             }
             
             tmp[0] = st;
@@ -1389,11 +1565,11 @@ int power_set_threshold(power_ch_t *pch)
             data_buf[0] = data_temp;
             data_buf[1] = data_temp>>16;
             //电压下限
-            data_temp =  (pch->thr.v_upper.val*1000);
+            data_temp =  (pch->thr.v_lower.val*1000);
             data_buf[2] = data_temp;
             data_buf[3] = data_temp>>16;
             //电流上限
-            data_temp =  (pch->thr.v_upper.val*1000);
+            data_temp =  (pch->thr.c_upper.val*1000);
             data_buf[4] = data_temp;
             data_buf[5] = data_temp>>16;
             //电流下限
@@ -1402,7 +1578,7 @@ int power_set_threshold(power_ch_t *pch)
             data_buf[7] = data_temp>>16;
 
             //功率上限
-            data_temp =  (pch->thr.v_upper.val*1000);
+            data_temp =  (pch->thr.p_upper.val*1000);
             data_buf[8] = data_temp;
             data_buf[9] = data_temp>>16;
             //功率下限
@@ -1411,7 +1587,7 @@ int power_set_threshold(power_ch_t *pch)
             data_buf[11] = data_temp>>16;
 
             //电能上限
-            data_temp =  (pch->thr.v_upper.val*1000);
+            data_temp =  (pch->thr.w_upper.val*1000);
             data_buf[12] = data_temp;
             data_buf[13] = data_temp>>16;
             //电能下限
@@ -1505,36 +1681,64 @@ int power_set_threshold(power_ch_t *pch)
                 data_temp[1] = (value >> 16) & 0xFFFF;
                 r = write_reg(h, pch->info.addr, offset+4, data_temp, 2);
             }
-            else {
+            else 
+						{
+
                 offset = POWER_AC3_THRESHOLD_VOL_MAX;
                 value = pch->thr.v_upper.val * 1000;
                 data_temp[0] = value & 0XFFFF;
                 data_temp[1] = (value >> 16) & 0xFFFF;
                 r = write_reg(h, pch->info.addr, offset, data_temp, 2);
-                
+                if(h->prod->type==PDU_AC_I3O3) {
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+								}
                 offset = POWER_AC3_THRESHOLD_VOL_MIN;
                 value = pch->thr.v_lower.val * 1000;
                 data_temp[0] = value & 0XFFFF;
                 data_temp[1] = (value >> 16) & 0xFFFF;
                 r = write_reg(h, pch->info.addr, offset, data_temp, 2);
-                
+                if(h->prod->type==PDU_AC_I3O3) {
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+								}                
                 offset = POWER_AC3_THRESHOLD_CUR_MAX;
                 value = pch->thr.c_upper.val * 1000;
                 data_temp[0] = value & 0XFFFF;
                 data_temp[1] = (value >> 16) & 0xFFFF;
                 r = write_reg(h, pch->info.addr, offset, data_temp, 2);
-                
+                if(h->prod->type==PDU_AC_I3O3) {
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+								}                   
                 offset = POWER_AC3_THRESHOLD_PWR_MAX;
                 value = pch->thr.p_upper.val * 1000;
                 data_temp[0] = value & 0XFFFF;
                 data_temp[1] = (value >> 16) & 0xFFFF;
                 r = write_reg(h, pch->info.addr, offset, data_temp, 2);
-                
-                offset = POWER_AC3_THRESHOLD_VOL_MAX;
+                if(h->prod->type==PDU_AC_I3O3) {
+									offset +=1;;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+								}                   
+                offset = POWER_AC3_THRESHOLD_PWRCON_MAX;
                 value = pch->thr.w_upper.val * 1000;
                 data_temp[0] = value & 0XFFFF;
                 data_temp[1] = (value >> 16) & 0xFFFF;
-                r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+                r = write_reg(h, pch->info.addr, offset, data_temp, 2);	
+                if(h->prod->type==PDU_AC_I3O3) {
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+									offset +=1;
+									r = write_reg(h, pch->info.addr, offset, data_temp, 2);
+								}   									
                 if(r==0) {
                     r = power_set_alarm(pch);
                 }

+ 1 - 0
f407/applications/power.h

@@ -156,6 +156,7 @@ int power_get_ch(uint8_t ch, power_ch_t *pch);
 int power_get_board(board_data_t *pb);
 
 int power_set_ch_sw(uint8_t ch, uint8_t on);
+int power_set_ch_sw_n(power_ch_t *pch);
 int power_set_board_sw(uint8_t addr, uint8_t on);
 int power_set_all_sw(uint8_t on);
 int power_set_alarm(power_ch_t *pch);

+ 3 - 3
f407/applications/rtconfig.h

@@ -180,9 +180,9 @@
 #define IP_SOF_BROADCAST 1
 #define IP_SOF_BROADCAST_RECV 1
 
-#define RT_LWIP_IPADDR   "192.168.2.132"
-#define RT_LWIP_GWADDR   "192.168.2.1"
-#define RT_LWIP_MSKADDR  "255.255.2.0"
+#define RT_LWIP_IPADDR   "192.168.1.166"
+#define RT_LWIP_GWADDR   "192.168.1.1"
+#define RT_LWIP_MSKADDR  "255.255.255.0"
 #define RT_LWIP_UDP
 #define RT_LWIP_TCP
 #define RT_LWIP_RAW

+ 4 - 3
f407/applications/sys.c

@@ -180,14 +180,15 @@ static void poll_thread(void *arg)
 
 int sys_init(void)
 {
+	
     fs_init();
     //db_init();
     paras_init();
-    ui_init();
+   // ui_init();
     
     mb_init();
-    sensor_init();
-    breaker_init();
+    //sensor_init();
+    //breaker_init();
     thread_start(THREAD_ID_POLL, poll_thread, NULL);
 
     return 0;

+ 2 - 1
f407/applications/web.c

@@ -375,7 +375,8 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
                     case SUB_TYPE_POWER_SWITCH:
                     {
                         if(hdr->addr==0) {
-                            r = power_set_ch_sw(pch->info.ch, pch->power[0].status);
+                            //r = power_set_ch_sw(pch->info.ch, pch->power[0].status);
+														power_set_ch_sw_n(pch);
                         }
                         else {
                             

+ 2 - 2
f407/tools/web/JS/data.js

@@ -149,11 +149,11 @@ function mk_hdr_bin(addr,type,subtype,nack,flag,dlen)
     length += 1;
 
     tmp = new DataView(buffer, length);
-    tmp.setUint8(0,0,true);     //subtype
+    tmp.setUint8(0,subtype,true);     //subtype
     length += 1;
     
     tmp = new DataView(buffer, length);
-    tmp.setUint8(0,0,true);     //nack
+    tmp.setUint8(0,nack,true);     //nack
     length += 1;
     
     tmp = new DataView(buffer, length);

+ 2 - 2
f407/tools/web/JS/operation.js

@@ -1,11 +1,11 @@
 function all_open()
 {
-    ws.send(mk_hdr_bin(0,PKT_TYPE.PKT_TYPE_CH_ALL,0,1,0));
+    ws.send(mk_hdr_bin(0,PKT_TYPE.PKT_TYPE_CH_ALL,0,0,1,0));
 }
 
 function all_close()
 {
-    ws.send(mk_hdr_bin(0,PKT_TYPE.PKT_TYPE_CH_ALL,0,0,0));
+    ws.send(mk_hdr_bin(0,PKT_TYPE.PKT_TYPE_CH_ALL,0,0,0,0));
 }
 
 function single_open(j_data,channel_power_infro,j)

+ 1 - 1
f407/tools/web/JS/ws.js

@@ -36,5 +36,5 @@ function ws_hdr(){
 }
 
 //ws = new WS('ws://'+window.location.host+'/ws',on_ws_msg);
-ws = new WS('ws://192.168.2.132/ws',on_ws_msg);
+ws = new WS('ws://192.168.1.166/ws',on_ws_msg);
 

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

@@ -1,4 +1,7 @@
 <!DOCTYPE html>
+<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
+<meta http-equiv="Pragma" content="no-cache">
+<meta http-equiv="Expires" content="0">
 <html lang="en">
 <head>
     <meta charset="UTF-8">

+ 1 - 1
f407/tools/webServer/EasyWebSvr.ini

@@ -24,4 +24,4 @@ LogToFile=0
 LogFileName=
 [StartParam]
 bShowWnd=0
-bStartRun=1
+bStartRun=0