Sfoglia il codice sorgente

低配增加json 用户管理,网页用户登录,控制板部分修改。

liyi 3 mesi fa
parent
commit
5c6690d380
30 ha cambiato i file con 3949 aggiunte e 2357 eliminazioni
  1. 1686 1140
      f407/applications/html_h/index_html.h
  2. 0 4
      f427/applications/cascade.c
  3. 84 15
      f427/applications/datadef.h
  4. 3 0
      f427/applications/dflt.c
  5. 1 1
      f427/applications/main.c
  6. 1 1
      f427/applications/net.c
  7. 12 2
      f427/applications/paras.c
  8. 1 0
      f427/applications/paras.h
  9. 1 1
      f427/applications/rtconfig.h
  10. 68 0
      f427/applications/sys.c
  11. 2 0
      f427/applications/sys.h
  12. 302 14
      f427/applications/web.c
  13. 23 0
      f427/applications/web.h
  14. 1 1
      f427/rt-thread/components/fal/samples/porting/fal_cfg.h
  15. 3 3
      f427/rt-thread/components/fal/samples/porting/fal_flash_sfud_port.c
  16. 1677 1133
      nor_web/AC3-AC1/index.html
  17. 7 3
      truing_control/PDU-3-ADA/common/common.c
  18. 14 7
      truing_control/PDU-3-ADA/hardware/detection/detection.c
  19. 1 1
      truing_control/PDU-3-ADA/hardware/eeprom/eeprom.c
  20. 10 8
      truing_control/PDU-3-ADA/hardware/electricity/electricity.c
  21. 8 8
      truing_control/PDU-3-ADA/hardware/hlw8110/Hlw8110.c
  22. 9 5
      truing_control/PDU-3-ADA/modbus/BARE/port/port.c
  23. 4 1
      truing_control/PDU-3-ADA/modbus/BARE/port/portserial.c
  24. 1 0
      truing_control/PDU-3-ADA/modbus/mb.c
  25. 3 0
      truing_control/PDU-3-ADA/modbus/rtu/mbrtu.c
  26. 16 5
      truing_control/PDU-3-ADA/user/board_cfg.h
  27. 5 2
      truing_control/PDU-3-ADA/user/main.c
  28. 4 1
      truing_control/PDU-AC_ADA_NEW_6/hardware/electricity/electricity.c
  29. 1 1
      truing_control/PDU-AC_ADA_NEW_6/user/board_cfg.h
  30. 1 0
      truing_control/PDU-AC_ADA_NEW_6/user/main.c

File diff suppressed because it is too large
+ 1686 - 1140
f407/applications/html_h/index_html.h


+ 0 - 4
f427/applications/cascade.c

@@ -770,10 +770,6 @@ void cascade_reset_new(uint8_t mode,uint8_t addr,uint32_t baund)
 	paras_save();
 	paras_save();
 	slave_info.switch_flag = 0;
 	slave_info.switch_flag = 0;
 	
 	
-
-	
-	
-	
 #endif
 #endif
 }
 }
 
 

+ 84 - 15
f427/applications/datadef.h

@@ -325,6 +325,21 @@ typedef struct {
 typedef struct{
 typedef struct{
 	sensor_th_t      sens[3];
 	sensor_th_t      sens[3];
 }sensor_config_t;
 }sensor_config_t;
+typedef struct{
+	int  role_id;
+	char    user_name[32];
+	char    password_md5[33];
+	char    date[16];
+	char    time[16];
+}user_config_t;
+
+
+typedef struct{
+	uint32_t user_count;
+	user_config_t  config[10];
+}user_data_t;
+
+
 
 
 
 
 typedef struct {
 typedef struct {
@@ -339,6 +354,7 @@ typedef struct {
 		snmp_data_t         snmp;
 		snmp_data_t         snmp;
 		phase_seq_3_1_t     phase_seq;
 		phase_seq_3_1_t     phase_seq;
 		phase_seq_3_2_t     phase_seq_2;
 		phase_seq_3_2_t     phase_seq_2;
+	  user_data_t         user;
 }paras_data_t;
 }paras_data_t;
 
 
 typedef struct {
 typedef struct {
@@ -355,6 +371,9 @@ typedef struct {
 
 
 
 
 
 
+
+
+
 //designed over by liyi
 //designed over by liyi
 
 
 typedef struct {
 typedef struct {
@@ -545,6 +564,30 @@ typedef struct
 	float  v_min;
 	float  v_min;
 }web_sensor_config_t;
 }web_sensor_config_t;
 
 
+typedef struct{
+	char user[32];
+	char password[32];
+}web_login_t;
+
+typedef struct {
+	uint8_t permition;
+	char user[32];
+	char password[32];
+}web_user_add_t;
+
+typedef struct
+{
+	char user[32];
+}web_user_delete_t;
+
+typedef struct
+{
+	uint8_t role_id;
+	char user[32];
+	char old_password[32];
+	char new_password[32];
+}web_user_update_t;
+
 typedef union
 typedef union
 {
 {
 	web_chn_ctrl_t 			 cnt_ctrl;
 	web_chn_ctrl_t 			 cnt_ctrl;
@@ -559,14 +602,26 @@ typedef union
 	web_sensor_config_t     sensor;
 	web_sensor_config_t     sensor;
 	web_snmp_t              snmp;
 	web_snmp_t              snmp;
 	batch_thr_t             batch;
 	batch_thr_t             batch;
+	web_login_t             login;
+	web_user_add_t          user_add;
+	web_user_delete_t       user_delete;
+	web_user_update_t       user_update;
 }wed_set_t;
 }wed_set_t;
 
 
 
 
+typedef struct {
+	int  roul_id;
+	char user[32];
+	char date[16];
+	char time[16];
+}user_t;
 
 
 
 
 
 
-
-
+typedef struct{
+	uint32_t count;
+	user_t   users[10];
+}wb_send_user_t;
 
 
 
 
 typedef struct {
 typedef struct {
@@ -640,15 +695,15 @@ typedef struct {
 
 
 
 
 //////////////////////////////
 //////////////////////////////
-typedef struct 
-{
-    uint8_t             userID;                 //用户ID
-    char                name[32];               //用户名-登录
-    char                password[32];           //用户密码
-    char                nick[32];               //用户名称
-    uint8_t             roleID;                 //角色ID
-    uint32_t            time;                   //用户创建时间     
-}user_data_t;
+//typedef struct 
+//{
+//    uint8_t             userID;                 //用户ID
+//    char                name[32];               //用户名-登录
+//    char                password[32];           //用户密码
+//    char                nick[32];               //用户名称
+//    uint8_t             roleID;                 //角色ID
+//    uint32_t            time;                   //用户创建时间     
+//}user_data_t;
 typedef struct 
 typedef struct 
 {
 {
     uint8_t             roleID;                 //角色ID
     uint8_t             roleID;                 //角色ID
@@ -822,6 +877,8 @@ enum{
 	NEW_PKT_TYPE_SNMP,
 	NEW_PKT_TYPE_SNMP,
 	NEW_PKT_TYPE_WANNING,
 	NEW_PKT_TYPE_WANNING,
 	NEW_PKT_TYPE_NTP,
 	NEW_PKT_TYPE_NTP,
+	MEW_PKT_TYPE_LOGIN,
+	NEW_PKT_TYPE_USER,
 };
 };
 
 
 
 
@@ -851,6 +908,13 @@ enum{
 	NEW_SUB_PKT_TYPE_WANNING_SOUND_LIGHT_CLEAN,
 	NEW_SUB_PKT_TYPE_WANNING_SOUND_LIGHT_CLEAN,
 };
 };
 
 
+enum{
+	NEW_SUB_PKT_TYPE_USER_INFO = 0,
+	NEW_SUB_PKT_TYPE_USER_ADD,
+	NEW_SUB_PKT_TYPE_USER_UPDATE,
+	NEW_SUB_PKT_TYPE_USER_DELETE,
+};
+
 
 
 
 
 typedef struct{
 typedef struct{
@@ -866,6 +930,7 @@ typedef struct{
 
 
 
 
 
 
+
 typedef alarm_all_t  web_channel_wanning_t;
 typedef alarm_all_t  web_channel_wanning_t;
 
 
 
 
@@ -924,12 +989,16 @@ typedef struct {
 #define INF_PH_3_1      "PH_3_1.ini"
 #define INF_PH_3_1      "PH_3_1.ini"
 #define INF_PH_3_2      "PH_3_2.ini"
 #define INF_PH_3_2      "PH_3_2.ini"
 
 
+#define USER_NAME       "userInfo.csv"
+
+
+
 #if 1
 #if 1
-#define DB_PATH         SD_PATH
-#define CFG_PATH        NOR_PATH
+	#define DB_PATH         SD_PATH
+	#define CFG_PATH        NOR_PATH
 #else
 #else
-#define DB_PATH         ROOT_PATH
-#define CFG_PATH        ROOT_PATH
+	#define DB_PATH         ROOT_PATH
+	#define CFG_PATH        ROOT_PATH
 #endif
 #endif
 
 
 
 

+ 3 - 0
f427/applications/dflt.c

@@ -96,6 +96,9 @@ const paras_data_t DFLT_PARAS={
 };
 };
 
 
 
 
+
+
+
 mail_send_t DFLT_MAIL_SEND={
 mail_send_t DFLT_MAIL_SEND={
 
 
     .mode = 1,
     .mode = 1,

+ 1 - 1
f427/applications/main.c

@@ -164,7 +164,7 @@ int main(void)
 			if(count == 10)
 			if(count == 10)
 			{
 			{
 				count = 0;
 				count = 0;
-				list_thread();
+				//list_thread();
 			}
 			}
     }
     }
 }
 }

+ 1 - 1
f427/applications/net.c

@@ -491,7 +491,7 @@ int net_init(void)
 			
 			
 		}else
 		}else
 		{
 		{
-			LOGD("%s",ip4addr_ntoa(netif_ip4_addr(handle_net.netif)));
+			//LOGD("%s",ip4addr_ntoa(netif_ip4_addr(handle_net.netif)));
 		}
 		}
 		
 		
 	}else if(para->netwk.mode == 1)   //static
 	}else if(para->netwk.mode == 1)   //static

+ 12 - 2
f427/applications/paras.c

@@ -12,6 +12,7 @@
 #include "db.h"
 #include "db.h"
 #include "log.h"
 #include "log.h"
 
 
+#define USER_MAX     10
 
 
 
 
 #define MALLOC   malloc
 #define MALLOC   malloc
@@ -36,7 +37,7 @@ typedef struct {
     dictionary          *dic;
     dictionary          *dic;
     paras_data_t        paras;
     paras_data_t        paras;
     char                path[100];
     char                path[100];
-    
+		char                user_path[100];
     lock_t              lck;
     lock_t              lck;
 }paras_handle_t;
 }paras_handle_t;
 static paras_handle_t  paraHandle={0};
 static paras_handle_t  paraHandle={0};
@@ -3879,10 +3880,19 @@ int paras_init(void)
     sprintf(tmp, "%s/%s", CFG_PATH, INF_NAME);
     sprintf(tmp, "%s/%s", CFG_PATH, INF_NAME);
     sys_get_prod(tmp, &h->paras);
     sys_get_prod(tmp, &h->paras);
     sys_get_bldtime(pv->bldtime, sizeof(pv->bldtime));
     sys_get_bldtime(pv->bldtime, sizeof(pv->bldtime));
-    
+		
+		//USER_NAME
+    sprintf(tmp, "%s/%s", CFG_PATH, USER_NAME);
+		sys_get_user(tmp,&h->paras.user);
+		strcpy(h->user_path,tmp);
     return r;
     return r;
 }
 }
 
 
+int paras_user_save(void)
+{
+	paras_handle_t *h=&paraHandle;
+	sys_set_user(h->user_path,&h->paras.user);
+}
 
 
 int paras_deinit(void)
 int paras_deinit(void)
 {
 {

+ 1 - 0
f427/applications/paras.h

@@ -35,6 +35,7 @@ int paras_load(char *path);
 int paras_reset(void);
 int paras_reset(void);
 int paras_copy(char *dst, char *src);
 int paras_copy(char *dst, char *src);
 int paras_save(void);
 int paras_save(void);
+int paras_user_save(void);
 
 
 int paras_serv_xport(char *path, int io);
 int paras_serv_xport(char *path, int io);
 int paras_alarm_xport(char *path, int io);
 int paras_alarm_xport(char *path, int io);

+ 1 - 1
f427/applications/rtconfig.h

@@ -100,7 +100,7 @@
 #define FAL_DEBUG 1
 #define FAL_DEBUG 1
 #define FAL_PART_HAS_TABLE_CFG
 #define FAL_PART_HAS_TABLE_CFG
 #define FAL_USING_SFUD_PORT
 #define FAL_USING_SFUD_PORT
-#define FAL_FLASH_DEV_NAME "w25q32"
+#define FAL_FLASH_DEV_NAME "w25q16"
 #define RT_USING_MTD_NOR
 #define RT_USING_MTD_NOR
 
 
 
 

+ 68 - 0
f427/applications/sys.c

@@ -19,6 +19,7 @@
 #include "thread.h"
 #include "thread.h"
 #include "led.h"
 #include "led.h"
 #include "beep.h"
 #include "beep.h"
+#include "stdio.h"
 
 
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -102,6 +103,73 @@ static char *str_get(char *buf, char *tok, char *dst, int dstlen)
 
 
     return t;
     return t;
 }
 }
+
+
+user_config_t USER_ADMIN={
+						.role_id = 1,
+						.user_name="admin",
+						.password_md5="21232f297a57a5a743894a0e4a801fc3",		//md5 "admin"
+						.date="2026/05/29",
+						.time="09:34:47",
+};
+
+
+#define USER_CSV_FORMATE    "%d,%s,%s,%s,%s\n"
+
+
+int sys_get_user(char *path,user_data_t *user)
+{
+	int ret = 0;
+	FILE *fp = NULL;
+	char buff[128] = {0};
+	
+	if(!user || !path)
+		return -1;
+	ret = fs_length(path);
+	if(ret == -1)
+	{
+		fp = fopen(path, "w");
+		if(fp == NULL)
+			return -1;
+		sprintf(buff,USER_CSV_FORMATE,USER_ADMIN.role_id,USER_ADMIN.user_name,USER_ADMIN.password_md5,USER_ADMIN.date,USER_ADMIN.time);
+		fwrite(buff,strlen(buff),1,fp);
+		fclose(fp);
+		fp = NULL;
+	}
+	fp = fopen(path, "rb");
+	
+	if(fp == NULL)
+		return  -1;
+	int i = 0;
+	while(fgets(buff,128,fp) != NULL)
+	{
+		sscanf(buff,"%d,%[^,],%[^,],%[^,],%s",&user->config[i].role_id,user->config[i].user_name,user->config[i].password_md5,user->config[i].date,user->config[i].time);
+		i++;
+	}
+	user->user_count = i;
+	
+	fclose(fp);
+	
+	
+	return 0;
+}
+
+
+int sys_set_user(char *path,user_data_t *user)
+{
+	FILE *fp = NULL;
+	char buff[128] = {0};
+	fp = fopen(path, "w");
+	for(int i = 0; i < user->user_count;i++)
+	{
+		sprintf(buff,USER_CSV_FORMATE,user->config[i].role_id,user->config[i].user_name,user->config[i].password_md5,user->config[i].date,user->config[i].time);
+		fputs(buff,fp);
+		memset(buff,0,128);
+	}
+	fclose(fp);	
+	return 0;
+}
+
 int sys_get_prod(char *path, paras_data_t *info)
 int sys_get_prod(char *path, paras_data_t *info)
 {
 {
     int r;
     int r;

+ 2 - 0
f427/applications/sys.h

@@ -29,5 +29,7 @@ int sys_set_net(network_data_t *para, int ipVersion);
 int sys_get_mac(char *mac, int maclen);
 int sys_get_mac(char *mac, int maclen);
 int sys_get_chip_id(int *id);
 int sys_get_chip_id(int *id);
 int sys_ip_check(char *ip);
 int sys_ip_check(char *ip);
+int sys_get_user(char *path,user_data_t *user);
+int sys_set_user(char *path,user_data_t *user);
 
 
 #endif
 #endif

+ 302 - 14
f427/applications/web.c

@@ -21,6 +21,7 @@
 #include "time.h"
 #include "time.h"
 #include "cJSON.h"
 #include "cJSON.h"
 #include "json_handle.h"
 #include "json_handle.h"
+#include "mbedtls/md5.h"
 
 
 static char* g_product_t_ac_type_str[3] = {
 static char* g_product_t_ac_type_str[3] = {
     "L1",
     "L1",
@@ -156,6 +157,260 @@ static int ws_send(mg_conn_t *c, void *data, int len, int isbin)
     return 0;
     return 0;
 }
 }
 
 
+static void send_user_info(web_handle_t *h, mg_conn_t *c)
+{
+	pkt_hdr_t *hdr=NULL;
+	hdr = (pkt_hdr_t*)h->buf;
+	wb_send_user_t *data1 = (wb_send_user_t *)(&hdr->data);
+	memset(data1,0,sizeof(wb_send_user_t));
+	paras_data_t* para=paras_get();
+	
+	
+	user_data_t *data = &para->user;
+	
+	data1->count = data->user_count;
+	
+	
+	for(int i = 0; i < data->user_count;i++)
+	{
+		data1->users[i].roul_id = data->config[i].role_id;
+		strcpy(data1->users[i].user,data->config[i].user_name);
+		strcpy(data1->users[i].date,data->config[i].date);
+		strcpy(data1->users[i].time,data->config[i].time);
+	}
+
+	hdr->magic = PKT_MAGIC;
+	hdr->addr  = 0;
+	hdr->type  = NEW_PKT_TYPE_USER;
+	hdr->nack  = 0;
+	hdr->subtype = 0;
+	hdr->dlen = data1->count * sizeof(user_t) + sizeof(data1->count);
+
+	uint32_t xlen = hdr->dlen + sizeof(pkt_hdr_t);
+	ws_send(c, h->buf, xlen, 1);
+}
+
+static void send_add_user_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
+{
+	char date[32]={0};
+	char time_s[32] = {0};
+	unsigned char digest[16]={0};
+	char output[33] = {0};
+	mbedtls_md5_context ctx={0};
+	uint8_t flag = USER_SUCCESS;
+	
+	web_user_add_t * user_add = (web_user_add_t *)&(ctrl->user_add);
+	pkt_hdr_t *hdr=(pkt_hdr_t*)(h->buf);
+		
+	paras_data_t* para=paras_get();
+	
+	printf("hdr  = %x\n",(uint32_t)hdr);
+	time_t t=time(NULL);
+  struct tm *tm=localtime(&t);
+
+
+	
+	hdr->magic = PKT_MAGIC;
+	hdr->addr  = 0;
+	hdr->type  = NEW_PKT_TYPE_USER;
+	hdr->nack  = 0;
+	hdr->subtype = NEW_SUB_PKT_TYPE_USER_ADD;
+	hdr->dlen = 1;	
+	
+	sprintf(date,"%04d%/%02d/%02d",(tm->tm_year+1900), tm->tm_mon+1, tm->tm_mday);
+	sprintf(time_s,"%02d%:%02d:%02d",tm->tm_hour, tm->tm_min, tm->tm_sec);
+	
+	for(int i = 0; i < para->user.user_count;i++)
+	{
+		if(strcmp(user_add->user,para->user.config[i].user_name) == 0)
+		{
+			flag = USER_EXIST;			//user_add exist
+			break;
+		}
+	}
+	if(flag  == 0)
+	{
+		if(para->user.user_count >= 10)
+		{
+			flag = USER_OVER_TEN;
+		}else
+		{
+			para->user.user_count++;
+			strcpy(para->user.config[para->user.user_count-1].user_name,user_add->user);
+			para->user.config[para->user.user_count-1].role_id = user_add->permition;
+			strcpy(para->user.config[para->user.user_count-1].date,date);
+			strcpy(para->user.config[para->user.user_count-1].time,time_s);
+			mbedtls_md5_init(&ctx);
+			mbedtls_md5_starts(&ctx);
+			mbedtls_md5_update(&ctx, user_add->password, strlen(user_add->password));
+			mbedtls_md5_finish(&ctx, digest);
+			mbedtls_md5_free(&ctx);
+			for (int k = 0; k < 16; k++) {
+					sprintf(&output[k * 2], "%02x", digest[k]);
+			}
+			output[33] = '\0';
+			strcpy(para->user.config[para->user.user_count-1].password_md5,output);
+			paras_user_save();
+		}
+	}
+	uint8_t *data =  (uint8_t *)(&hdr->data);
+
+	*data = flag;
+	uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
+	ws_send(c, h->buf, xlen, 1);
+	
+	//printf("send len = %d\n",xlen);
+}
+
+
+
+static void send_user_delete_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
+{
+	web_user_delete_t * user_delete = &ctrl->user_delete;
+	pkt_hdr_t *hdr=NULL;
+	hdr = (pkt_hdr_t*)h->buf;
+	uint8_t flag = USER_DELETE_SUCCESS;
+	
+	paras_data_t* para=paras_get();	
+	user_data_t back_user = {0};
+	int j = 0;
+	
+	for(int i = 0;i < para->user.user_count;i++)
+	{
+		if(strcmp(para->user.config[i].user_name,user_delete->user) == 0)
+		{
+		}else
+		{
+			back_user.config[j++] = para->user.config[i];
+		}
+	}
+	back_user.user_count = j;
+	//memset(&para->user,0,sizeof(para->user));
+	para->user = back_user;
+	paras_user_save();
+	
+	uint8_t *data =  (uint8_t *)(&hdr->data);
+	hdr->magic = PKT_MAGIC;
+	hdr->addr  = 0;
+	hdr->type  = NEW_PKT_TYPE_USER;
+	hdr->nack  = 0;
+	hdr->subtype = NEW_SUB_PKT_TYPE_USER_DELETE;
+	hdr->dlen = 1;	
+	*data = flag;
+	uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
+	ws_send(c, h->buf, xlen, 1);
+}
+
+static void send_user_update_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
+{
+	web_user_update_t *user_update = &ctrl->user_update;
+	pkt_hdr_t *hdr=NULL;
+	hdr = (pkt_hdr_t*)h->buf;
+	uint8_t flag = USER_DELETE_SUCCESS;
+	paras_data_t* para=paras_get();
+	
+	unsigned char digest[16]={0};
+	char output[33] = {0};
+	mbedtls_md5_context ctx={0};
+	for(int i = 0; i < para->user.user_count;i++)
+	{
+		if(strcmp(user_update->user,para->user.config[i].user_name) == 0)
+		{
+			mbedtls_md5_init(&ctx);
+			mbedtls_md5_starts(&ctx);
+			mbedtls_md5_update(&ctx, user_update->old_password, strlen(user_update->old_password));
+			mbedtls_md5_finish(&ctx, digest);
+			mbedtls_md5_free(&ctx);
+			for (int k = 0; k < 16; k++) {
+					sprintf(&output[k * 2], "%02x", digest[k]);
+			}
+			output[33] = '\0';			
+			if(strcmp(output,para->user.config[i].password_md5) == 0)
+			{
+				mbedtls_md5_init(&ctx);
+				mbedtls_md5_starts(&ctx);
+				mbedtls_md5_update(&ctx, user_update->new_password, strlen(user_update->new_password));
+				mbedtls_md5_finish(&ctx, digest);
+				mbedtls_md5_free(&ctx);
+				for (int k = 0; k < 16; k++) {
+						sprintf(&output[k * 2], "%02x", digest[k]);
+				}
+				output[33] = '\0';					
+				strcpy(para->user.config[i].password_md5,output);
+				paras_user_save();
+			}else
+			{
+				flag = USER_UPDATE_PASSERR;
+			}
+			break;
+		}
+	}
+	
+	uint8_t *data =  (uint8_t *)(&hdr->data);
+	hdr->magic = PKT_MAGIC;
+	hdr->addr  = 0;
+	hdr->type  = NEW_PKT_TYPE_USER;
+	hdr->nack  = 0;
+	hdr->subtype = NEW_SUB_PKT_TYPE_USER_UPDATE;
+	hdr->dlen = 1;	
+	*data = flag;
+	uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
+	ws_send(c, h->buf, xlen, 1);
+}
+
+
+
+
+static void send_login_func(web_handle_t *h, mg_conn_t *c,wed_set_t *ctrl)
+{
+	pkt_hdr_t *hdr=NULL;
+	hdr = (pkt_hdr_t*)h->buf;
+	uint8_t flag = 0;
+	uint8_t *data =  (uint8_t *)(&hdr->data);
+	
+	paras_data_t* para=paras_get();
+	
+	unsigned char digest[16]={0};
+	char output[33] = {0};
+	mbedtls_md5_context ctx={0};
+
+	for(int i = 0; i < para->user.user_count;i++)
+	{
+		if(strcmp(ctrl->login.user,para->user.config[i].user_name) == 0)
+		{
+				mbedtls_md5_init(&ctx);
+				mbedtls_md5_starts(&ctx);
+				mbedtls_md5_update(&ctx, (const unsigned char *)ctrl->login.password, strlen(ctrl->login.password));
+				mbedtls_md5_finish(&ctx, digest);
+				mbedtls_md5_free(&ctx);
+
+				for (int k = 0; k < 16; k++) {
+					sprintf(&output[k * 2], "%02x", digest[k]);
+				}
+				output[33] = '\0';
+				if(strcmp(output,para->user.config[i].password_md5) == 0)
+				{
+					flag = 1;
+				}else
+				{
+					flag = 2;
+				}
+			//printf("user=%s output: %s\n",ctrl->login.user,output);
+			break;
+		}
+	}
+	hdr->magic = PKT_MAGIC;
+	hdr->addr  = 0;
+	hdr->type  = MEW_PKT_TYPE_LOGIN;
+	hdr->nack  = 0;
+	hdr->subtype = 0;
+	hdr->dlen = 1;
+	
+	*data = flag;
+	uint32_t xlen = sizeof(uint8_t) + sizeof(pkt_hdr_t);
+	ws_send(c, h->buf, xlen, 1);
+}
+
 
 
 static void send_sys(web_handle_t *h, mg_conn_t *c)
 static void send_sys(web_handle_t *h, mg_conn_t *c)
 {
 {
@@ -838,6 +1093,41 @@ static int ws_handle_new(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
 				}
 				}
 			}
 			}
 			break;
 			break;
+			case MEW_PKT_TYPE_LOGIN:
+			{
+				send_login_func(h,c,ctrl);
+			}
+			break;
+			case NEW_PKT_TYPE_USER:
+			{
+				if(hdr->dlen == 0)
+				{
+					send_user_info(h,c);
+				}else
+				{		
+					switch(hdr->subtype)
+					{
+						case NEW_SUB_PKT_TYPE_USER_ADD:
+						{
+							send_add_user_func(h,c,ctrl);
+						}
+							break;
+						case NEW_SUB_PKT_TYPE_USER_UPDATE:
+						{
+							send_user_update_func(h,c,ctrl);
+						}
+							break;
+						case NEW_SUB_PKT_TYPE_USER_DELETE:
+						{
+							send_user_delete_func(h,c,ctrl);
+						}
+							break;
+						default:
+							break;
+					}
+				}
+			}
+			break;
 			default:
 			default:
 				break;
 				break;
 		}
 		}
@@ -940,6 +1230,10 @@ static void overChannelStatusMonitoring(void* conn)
 			if(p_handle->product->type == PDU_AC_I3O1_H || p_handle->product->type == PDU_AC_I3O1)
 			if(p_handle->product->type == PDU_AC_I3O1_H || p_handle->product->type == PDU_AC_I3O1)
 			{
 			{
 				ph=pch->info.pse.ph-1;
 				ph=pch->info.pse.ph-1;
+				uint8_t wanning = 0;
+				uint32_t ph_all_wanning =  *(uint32_t*) (&pch->info.alarm);
+				wanning = (ph_all_wanning >> (ph*8)) & 0XFF;    //get phse wanning
+				wanning_type_t wan = *(wanning_type_t *)(&wanning);
 				sprintf(ack_str,CHANNEL_SINGLE_RES_TYPE,pch->info.name,req.pro_ch_id,pch->power[ph].voltage,
 				sprintf(ack_str,CHANNEL_SINGLE_RES_TYPE,pch->info.name,req.pro_ch_id,pch->power[ph].voltage,
 																							pch->power[ph].current,pch->power[ph].power,
 																							pch->power[ph].current,pch->power[ph].power,
 																							pch->power[ph].app_power,pch->power[ph].freq,
 																							pch->power[ph].app_power,pch->power[ph].freq,
@@ -947,8 +1241,9 @@ static void overChannelStatusMonitoring(void* conn)
 																							pch->thr.v_upper,pch->thr.v_lower,
 																							pch->thr.v_upper,pch->thr.v_lower,
 																							pch->thr.c_upper,pch->thr.p_upper,
 																							pch->thr.c_upper,pch->thr.p_upper,
 																							pch->thr.w_upper,
 																							pch->thr.w_upper,
-																							pch->info.open_delay,pch->info.close_delay,
-																							pch->info.status,g_product_t_ac_type_str[ph]);
+																							pch->info.open_delay,pch->info.close_delay,pch->info.status,
+																							wan.v_upper,wan.v_lower,wan.c_upper,wan.p_upper,wan.w_upper,
+																							g_product_t_ac_type_str[ph]);
 			}else 
 			}else 
 			{
 			{
 				sprintf(ack_str,CHANNEL_SINGLE_RES_TYPE,pch->info.name,req.pro_ch_id,pch->power[0].voltage,
 				sprintf(ack_str,CHANNEL_SINGLE_RES_TYPE,pch->info.name,req.pro_ch_id,pch->power[0].voltage,
@@ -959,7 +1254,11 @@ static void overChannelStatusMonitoring(void* conn)
 																							pch->thr.c_upper,pch->thr.p_upper,
 																							pch->thr.c_upper,pch->thr.p_upper,
 																							pch->thr.w_upper,
 																							pch->thr.w_upper,
 																							pch->info.open_delay,pch->info.close_delay,
 																							pch->info.open_delay,pch->info.close_delay,
-																							pch->info.status,"");
+																							pch->info.status,
+																							pch->info.alarm.l1_v_upper,
+																							pch->info.alarm.l1_v_lower,pch->info.alarm.l1_c_upper,
+																							pch->info.alarm.l1_p_upper,pch->info.alarm.l1_w_upper,				
+				"");
 			}
 			}
 		}
 		}
 	}else if(strcmp(req.type,"chnWanInfo")==0)
 	}else if(strcmp(req.type,"chnWanInfo")==0)
@@ -1163,17 +1462,6 @@ static void sensorStatusMonitoring(void* conn)
 
 
 
 
 
 
-
-
-
-
-
-
-
-
-
-
-
 static int webSetCallback(void)
 static int webSetCallback(void)
 {
 {
   httpAddCallback("/pdu/channelStatusMonitoring", overChannelStatusMonitoring);
   httpAddCallback("/pdu/channelStatusMonitoring", overChannelStatusMonitoring);

+ 23 - 0
f427/applications/web.h

@@ -38,6 +38,11 @@
 																		 "\"openInterval\":%d,"\
 																		 "\"openInterval\":%d,"\
 																		 "\"closeInterval\":%d,"\
 																		 "\"closeInterval\":%d,"\
 																		 "\"chStatus\":%d,"\
 																		 "\"chStatus\":%d,"\
+																		 "\"chnWanVolMax\":%d,"\
+																		 "\"chnWanVolMin\":%d,"\
+																		 "\"chnWanCurMax\":%d,"\
+																		 "\"chnWanPwrMax\":%d,"\
+																		 "\"chnWanKwhMax\":%d,"\
 																		 "\"chPhOrder\":\"%s\""\
 																		 "\"chPhOrder\":\"%s\""\
 																		 "},"\
 																		 "},"\
 																		 "\"msg\":\"success\""\
 																		 "\"msg\":\"success\""\
@@ -80,6 +85,24 @@
 
 
 
 
 
 
+enum{
+	USER_SUCCESS,
+	USER_EXIST,
+	USER_OVER_TEN,
+};
+
+
+enum{
+	USER_DELETE_SUCCESS,
+	USER_DELETE_NO_EXIT,
+};
+
+enum{
+	USER_UPDATE_SUCCESS,
+	USER_UPDATE_PASSERR,
+};
+
+
 int web_init(void);
 int web_init(void);
 int web_post(int type, void *data, int len);
 int web_post(int type, void *data, int len);
 
 

+ 1 - 1
f427/rt-thread/components/fal/samples/porting/fal_cfg.h

@@ -29,7 +29,7 @@ extern struct fal_flash_dev nor_flash0;
 /* partition table */
 /* partition table */
 #define FAL_PART_TABLE                                                \
 #define FAL_PART_TABLE                                                \
 {                                                                     \
 {                                                                     \
-    {FAL_PART_MAGIC_WORD, "nor", FAL_FLASH_DEV_NAME,  1*MB, 3*MB, 0}, \
+    {FAL_PART_MAGIC_WORD, "nor", FAL_FLASH_DEV_NAME,  1*MB, 1*MB, 0}, \
 }
 }
 #endif /* FAL_PART_HAS_TABLE_CFG */
 #endif /* FAL_PART_HAS_TABLE_CFG */
 
 

+ 3 - 3
f427/rt-thread/components/fal/samples/porting/fal_flash_sfud_port.c

@@ -18,7 +18,7 @@
 #endif
 #endif
 
 
 #ifndef FAL_FLASH_DEV_NAME
 #ifndef FAL_FLASH_DEV_NAME
-#define FAL_FLASH_DEV_NAME             "w25q32"
+#define FAL_FLASH_DEV_NAME             "w25q16"
 #endif
 #endif
 
 
 static int init(void);
 static int init(void);
@@ -31,8 +31,8 @@ struct fal_flash_dev nor_flash0 =
 {
 {
     .name       = FAL_FLASH_DEV_NAME,
     .name       = FAL_FLASH_DEV_NAME,
     .addr       = 0,
     .addr       = 0,
-    .len        = 4 * 1024 * 1024,
-    .blk_size   = 64*1024,
+    .len        = 2 * 1024 * 1024,
+    .blk_size   = 4*1024,
     .ops        = {init, read, write, erase},
     .ops        = {init, read, write, erase},
     .write_gran = 1
     .write_gran = 1
 };
 };

File diff suppressed because it is too large
+ 1677 - 1133
nor_web/AC3-AC1/index.html


+ 7 - 3
truing_control/PDU-3-ADA/common/common.c

@@ -49,7 +49,7 @@ void read_config_from_eeprom(void)
 			
 			
 			
 			
 
 
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 			uint8_t count = 1;
 			uint8_t count = 1;
 			for(uint8_t i = 0; i < RelaySlaveChaNum;i += 3)
 			for(uint8_t i = 0; i < RelaySlaveChaNum;i += 3)
 			{
 			{
@@ -117,25 +117,29 @@ void read_config_from_eeprom(void)
 			{
 			{
 				for(int i =0 ;i < RelaySlaveChaNum;i++)
 				for(int i =0 ;i < RelaySlaveChaNum;i++)
 				{
 				{
+#if  SUPPORT_MON
+					board->md_data.r_data.status[i] = 1;
+#else
 					if(board->relay_staging_staus[i])
 					if(board->relay_staging_staus[i])
 					{
 					{
 						SET_RL_ON_DELAY_FLAG(board->relay_staging_staus[i]);
 						SET_RL_ON_DELAY_FLAG(board->relay_staging_staus[i]);
 						CLEAR_RL_OFF_DELAY_FLAG(board->relay_staging_staus[i]);
 						CLEAR_RL_OFF_DELAY_FLAG(board->relay_staging_staus[i]);
 						SET_RL_ORDER_FLAG(board->relay_staging_staus[i]);
 						SET_RL_ORDER_FLAG(board->relay_staging_staus[i]);
 					}
 					}
+#endif
 				}
 				}
 			}
 			}
 
 
 			board->read_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.delay_on[0],sizeof(rw_3_data_t));
 			board->read_eeprom_page(EEPROM_OTHER_ADDR,(uint8_t *)&board->md_data.rw_data.delay_on[0],sizeof(rw_3_data_t));
 
 
-			#if (AC_3_3 || AC_3_4)
+			#if (AC_3_3 || AC_3_4 ||AC_3_3_MON)
 					board->check_threshold(THRESHOLD_IN,0);
 					board->check_threshold(THRESHOLD_IN,0);
 			#else
 			#else
 					board->check_threshold(THRESHOLD_IN,0);
 					board->check_threshold(THRESHOLD_IN,0);
 			#endif	
 			#endif	
 
 
 
 
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 			board->read_eeprom_page(EEPROM_SET_V_K_ADDR,(uint8_t *)&board->v_k[0], 4*3);
 			board->read_eeprom_page(EEPROM_SET_V_K_ADDR,(uint8_t *)&board->v_k[0], 4*3);
 			board->read_eeprom_page(EEPROM_SET_K_I_ADDR,(uint8_t *)&board->i_k[0], 4*3);
 			board->read_eeprom_page(EEPROM_SET_K_I_ADDR,(uint8_t *)&board->i_k[0], 4*3);
 			for(int i = 0;i < 3;i++)
 			for(int i = 0;i < 3;i++)

+ 14 - 7
truing_control/PDU-3-ADA/hardware/detection/detection.c

@@ -165,12 +165,15 @@ void EXTI4_15_IRQHandler(void){
 
 
 	if(RESET != exti_interrupt_flag_get(DERECTION_IO_1_EXIT))
 	if(RESET != exti_interrupt_flag_get(DERECTION_IO_1_EXIT))
 	{
 	{
+		exti_interrupt_flag_clear(DERECTION_IO_1_EXIT);
 		if(board)
 		if(board)
 		{
 		{
-			board->detection_1_value = 1;
-			board->detection_1_count = 0;
+			if(gpio_input_bit_get(DERECTION_GPIO_1,DERECTION_IO_1) == 0)
+			{
+				board->detection_1_value = 1;
+				board->detection_1_count = 0;
+			}
 		}
 		}
-		exti_interrupt_flag_clear(DERECTION_IO_1_EXIT);
 	}
 	}
 
 
 }
 }
@@ -233,12 +236,16 @@ void EXTI2_3_IRQHandler(void)
 #if SURPPORT_2_PT
 #if SURPPORT_2_PT
 	if(RESET != exti_interrupt_flag_get(DERECTION_IO_2_EXIT))
 	if(RESET != exti_interrupt_flag_get(DERECTION_IO_2_EXIT))
 	{
 	{
+		exti_interrupt_flag_clear(DERECTION_IO_2_EXIT);
 		if(board)
 		if(board)
 		{
 		{
-			board->detection_2_value = 1;
-			board->detection_2_count = 0;
+			if(gpio_input_bit_get(DERECTION_GPIO_2,DERECTION_IO_2) == 0)
+			{
+				board->detection_2_value = 1;
+				board->detection_2_count = 0;
+			}
 		}
 		}
-		exti_interrupt_flag_clear(DERECTION_IO_2_EXIT);
+
 	}	
 	}	
 #endif
 #endif
 }
 }
@@ -270,7 +277,7 @@ static void detection_opt(void)
 				async_data da = {0};
 				async_data da = {0};
 				da.w_eep_flag = FLAG_N_W_EEP;
 				da.w_eep_flag = FLAG_N_W_EEP;
 				da.fire_or_zero = _FIRE;
 				da.fire_or_zero = _FIRE;
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 	#if SUPPORT_RELAY_REMENBER
 	#if SUPPORT_RELAY_REMENBER
 					if(board->md_data.r_data.detection & 0x1)
 					if(board->md_data.r_data.detection & 0x1)
 					{
 					{

+ 1 - 1
truing_control/PDU-3-ADA/hardware/eeprom/eeprom.c

@@ -341,7 +341,7 @@ static void check_threshold(uint8_t in_out,uint8_t channel)
 {
 {
 	if(in_out == THRESHOLD_IN)
 	if(in_out == THRESHOLD_IN)
 	{
 	{
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 		board_t *board = get_board();
 		board_t *board = get_board();
 			if(board->md_data.rw_data.i_V_max > Default_Voltage_Max)  	board->md_data.rw_data.i_V_max  = 0;
 			if(board->md_data.rw_data.i_V_max > Default_Voltage_Max)  	board->md_data.rw_data.i_V_max  = 0;
 			if(board->md_data.rw_data.i_V_min > Default_Voltage_Max) 		board->md_data.rw_data.i_V_min  = 0;
 			if(board->md_data.rw_data.i_V_min > Default_Voltage_Max) 		board->md_data.rw_data.i_V_min  = 0;

+ 10 - 8
truing_control/PDU-3-ADA/hardware/electricity/electricity.c

@@ -54,7 +54,7 @@ static void read_ele(uint8_t channel)
 	if(channel < RelaySlaveChaNum)
 	if(channel < RelaySlaveChaNum)
 	{
 	{
 		select_channel(channel);
 		select_channel(channel);
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 		
 		
 		voltage_flag = channel;
 		voltage_flag = channel;
 #else
 #else
@@ -106,7 +106,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 {
 {
 	if(in_out == ELE_INPUT)
 	if(in_out == ELE_INPUT)
 	{
 	{
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 ||AC_3_3_MON)
 		
 		
 		board->md_data.r_data.i_voltage[A] = board->md_data.r_data.output[A].voltage;
 		board->md_data.r_data.i_voltage[A] = board->md_data.r_data.output[A].voltage;
 		board->md_data.r_data.i_voltage[B] = board->md_data.r_data.output[B].voltage;
 		board->md_data.r_data.i_voltage[B] = board->md_data.r_data.output[B].voltage;
@@ -190,7 +190,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 		uint32_t sort_buff[3] = {0};	
 		uint32_t sort_buff[3] = {0};	
 		sort_buff[0] = board->md_data.r_data.i_voltage[A];
 		sort_buff[0] = board->md_data.r_data.i_voltage[A];
 		sort_buff[1] = board->md_data.r_data.i_voltage[B];		
 		sort_buff[1] = board->md_data.r_data.i_voltage[B];		
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 ||AC_3_3_MON)
 		
 		
 		sort_buff[2] = board->md_data.r_data.i_voltage[C];
 		sort_buff[2] = board->md_data.r_data.i_voltage[C];
 		Vmax = (sort_buff[0] >= sort_buff[1]) ? sort_buff[0] :sort_buff[1];
 		Vmax = (sort_buff[0] >= sort_buff[1]) ? sort_buff[0] :sort_buff[1];
@@ -219,7 +219,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 				{
 				{
 					board->md_data.r_data.Lack_B = WANNING_SET;
 					board->md_data.r_data.Lack_B = WANNING_SET;
 				}
 				}
-#if(AC_3_3 || AC_3_4)
+#if(AC_3_3 || AC_3_4 ||AC_3_3_MON)
 				if(board->md_data.r_data.i_voltage[C] < v_mid)
 				if(board->md_data.r_data.i_voltage[C] < v_mid)
 				{
 				{
 					board->md_data.r_data.Lack_C = WANNING_SET;
 					board->md_data.r_data.Lack_C = WANNING_SET;
@@ -232,7 +232,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 		{
 		{
 			board->md_data.r_data.Lack_A = WANNING_UNSET;
 			board->md_data.r_data.Lack_A = WANNING_UNSET;
 			board->md_data.r_data.Lack_B = WANNING_UNSET;
 			board->md_data.r_data.Lack_B = WANNING_UNSET;
-#if(AC_3_3 || AC_3_4)
+#if(AC_3_3 || AC_3_4 ||AC_3_3_MON)
 			board->md_data.r_data.Lack_C = WANNING_UNSET;
 			board->md_data.r_data.Lack_C = WANNING_UNSET;
 #endif
 #endif
 			count = 0;
 			count = 0;
@@ -253,7 +253,7 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 		board->md_data.r_data.w_input.lack_A  = board->md_data.r_data.Lack_A;
 		board->md_data.r_data.w_input.lack_A  = board->md_data.r_data.Lack_A;
 		board->md_data.r_data.w_input.lack_B  = board->md_data.r_data.Lack_B;
 		board->md_data.r_data.w_input.lack_B  = board->md_data.r_data.Lack_B;
 		
 		
-#if(AC_3_3 || AC_3_4)
+#if(AC_3_3 || AC_3_4 ||AC_3_3_MON)
 		board->md_data.r_data.w_input.v_C_up  =	(board->md_data.r_data.i_voltage[C]  > board->md_data.rw_data.i_V_max) ? WANNING_SET : WANNING_UNSET;
 		board->md_data.r_data.w_input.v_C_up  =	(board->md_data.r_data.i_voltage[C]  > board->md_data.rw_data.i_V_max) ? WANNING_SET : WANNING_UNSET;
 		board->md_data.r_data.w_input.v_C_low =	(board->md_data.r_data.i_voltage[C]  < board->md_data.rw_data.i_V_min) ? WANNING_SET : WANNING_UNSET;
 		board->md_data.r_data.w_input.v_C_low =	(board->md_data.r_data.i_voltage[C]  < board->md_data.rw_data.i_V_min) ? WANNING_SET : WANNING_UNSET;
 		board->md_data.r_data.w_input.i_C_up  =	(board->md_data.r_data.i_current[C]  > board->md_data.rw_data.i_I_max) ? WANNING_SET : WANNING_UNSET;
 		board->md_data.r_data.w_input.i_C_up  =	(board->md_data.r_data.i_current[C]  > board->md_data.rw_data.i_I_max) ? WANNING_SET : WANNING_UNSET;
@@ -341,7 +341,9 @@ static void check_wanning(uint8_t in_out,uint8_t channel)
 
 
 static void opt_over_func(uint8_t channel)
 static void opt_over_func(uint8_t channel)
 {
 {
-#if (AC_3_3 || AC_3_4)
+#if (!SUPPORT_MON)
+	
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 	for(int i = 0; i < RelaySlaveChaNum ;i+=3)
 	for(int i = 0; i < RelaySlaveChaNum ;i+=3)
 	{
 	{
 		if(board->md_data.rw_data.channel_ctrl[i  ] == 0 && 
 		if(board->md_data.rw_data.channel_ctrl[i  ] == 0 && 
@@ -423,5 +425,5 @@ static void opt_over_func(uint8_t channel)
 	}	
 	}	
 	
 	
 #endif
 #endif
-
+#endif
 }
 }

+ 8 - 8
truing_control/PDU-3-ADA/hardware/hlw8110/Hlw8110.c

@@ -657,7 +657,7 @@ void Read_HLW8110_IA(void)
 		a  = a/0x800000;                     //电流计算出来的浮点数单位是mA,比如5003.12 
 		a  = a/0x800000;                     //电流计算出来的浮点数单位是mA,比如5003.12 
 		 
 		 
 		//a = a/1;  								// 1 = 电流系数
 		//a = a/1;  								// 1 = 电流系数
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		a /= ((float)board->i_k[voltage_flag]/10000.0);
 		a /= ((float)board->i_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -721,7 +721,7 @@ void Read_HLW8110_U(void)
   //a = a/0.31163;  						// 1 = 电压系数
   //a = a/0.31163;  						// 1 = 电压系数
 	// a= a * 3.189;
 	// a= a * 3.189;
 		
 		
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		a /= ((float)board->v_k[voltage_flag]/10000.0);
 		a /= ((float)board->v_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -784,7 +784,7 @@ void Read_HLW8110_PA(void)
     a = a/0x80000000;  
     a = a/0x80000000;  
 	 
 	 
     //a = a/1;  										// 1 = 电流系数
     //a = a/1;  										// 1 = 电流系数
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		a /= ((float)board->i_k[voltage_flag]/10000.0);
 		a /= ((float)board->i_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -801,7 +801,7 @@ void Read_HLW8110_PA(void)
 //		a = a/0.31163;  
 //		a = a/0.31163;  
 	 //a = a * 3.189;
 	 //a = a * 3.189;
     //a = a/1;  										// 1 = 电压系数
     //a = a/1;  										// 1 = 电压系数
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		 a /= ((float)board->v_k[voltage_flag]/10000.0);
 		 a /= ((float)board->v_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -873,7 +873,7 @@ void Read_HLW8110_PSA(void)
     //a = a/1;  										// 1 = 电流系数
     //a = a/1;  										// 1 = 电流系数
 		//a = a * 3.189;
 		//a = a * 3.189;
 	 
 	 
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		 a /= ((float)board->i_k[voltage_flag]/10000.0);
 		 a /= ((float)board->i_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -890,7 +890,7 @@ void Read_HLW8110_PSA(void)
 		//a = a/0.31163; 
 		//a = a/0.31163; 
 
 
 
 
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		 a /= ((float)board->v_k[voltage_flag]/10000.0);
 		 a /= ((float)board->v_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -954,7 +954,7 @@ void Read_HLW8110_EA(void)
   a = a*U16_EnergyAC_RegData;
   a = a*U16_EnergyAC_RegData;
   a = a/0x20000000;             //电量单位是0.001KWH,比如算出来是2.002,表示2.002KWH    
   a = a/0x20000000;             //电量单位是0.001KWH,比如算出来是2.002,表示2.002KWH    
   //a = a/1;  										// 1 = 电流系数
   //a = a/1;  										// 1 = 电流系数
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		 a /= ((float)board->i_k[voltage_flag]/10000.0);
 		 a /= ((float)board->i_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)
@@ -969,7 +969,7 @@ void Read_HLW8110_EA(void)
 	//a= a * 3.189;
 	//a= a * 3.189;
   //a = a/1;  										// 1 = 电压系数
   //a = a/1;  										// 1 = 电压系数
   //a = a/0.31163;  
   //a = a/0.31163;  
-#if (AC_3_3 || AC_3_4)		
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)		
 		 a /= ((float)board->v_k[voltage_flag]/10000.0);
 		 a /= ((float)board->v_k[voltage_flag]/10000.0);
 #else
 #else
 		if(voltage_flag == 1)
 		if(voltage_flag == 1)

+ 9 - 5
truing_control/PDU-3-ADA/modbus/BARE/port/port.c

@@ -284,10 +284,11 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 							w_eeprom_data_t data = {0};
 							w_eeprom_data_t data = {0};
 							if(usAddress >= REALAY_CTRL && (usAddress <= (REALAY_CTRL + REALAY_CTRL_LENTH)))
 							if(usAddress >= REALAY_CTRL && (usAddress <= (REALAY_CTRL + REALAY_CTRL_LENTH)))
 							{
 							{
+#if(!SUPPORT_MON)
 								async_data da = {0};
 								async_data da = {0};
 								da.fire_or_zero = _FIRE;
 								da.fire_or_zero = _FIRE;
 								da.w_eep_flag = FLAG_W_EEP;
 								da.w_eep_flag = FLAG_W_EEP;
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 #if SUPPORT_DETECTION
 #if SUPPORT_DETECTION
 								if(board->md_data.r_data.detection & 0x1)
 								if(board->md_data.r_data.detection & 0x1)
 #endif
 #endif
@@ -351,7 +352,7 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 								async_data da = {0};
 								async_data da = {0};
 								da.fire_or_zero = _FIRE;
 								da.fire_or_zero = _FIRE;
 								da.w_eep_flag = FLAG_W_EEP;
 								da.w_eep_flag = FLAG_W_EEP;
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 || AC_3_3_MON)
 		#if SUPPORT_DETECTION
 		#if SUPPORT_DETECTION
 								if(board->md_data.r_data.detection & 0x1)
 								if(board->md_data.r_data.detection & 0x1)
 		#endif
 		#endif
@@ -402,15 +403,16 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 //								}
 //								}
 							}
 							}
 #endif
 #endif
-								
+#endif
 							}
 							}
 							
 							
 							else if(usAddress == ALL_ON || usAddress == ALL_OFF)
 							else if(usAddress == ALL_ON || usAddress == ALL_OFF)
 							{
 							{
+#if (!SUPPORT_MON)
 								async_data da = {0};
 								async_data da = {0};
 								da.fire_or_zero = _FIRE;
 								da.fire_or_zero = _FIRE;
 								da.w_eep_flag = FLAG_W_EEP;
 								da.w_eep_flag = FLAG_W_EEP;
-#if (AC_3_3 || AC_3_4)				
+#if (AC_3_3 || AC_3_4 ||AC_3_3_MON)				
 	#if SUPPORT_DETECTION
 	#if SUPPORT_DETECTION
 								if(board->md_data.r_data.detection & 0x1)
 								if(board->md_data.r_data.detection & 0x1)
 	#endif
 	#endif
@@ -507,7 +509,9 @@ eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs, eMBRegi
 										}									
 										}									
 								}
 								}
 							}
 							}
-#endif								
+#endif				
+
+#endif
 							}else if(usAddress >= THR_INPUT && usAddress <=(THR_OUTPUT_C_MAX+ THR_OUTPUT_C_MAX_LENTH))
 							}else if(usAddress >= THR_INPUT && usAddress <=(THR_OUTPUT_C_MAX+ THR_OUTPUT_C_MAX_LENTH))
 							{
 							{
 								uint16_t rom_start;
 								uint16_t rom_start;

+ 4 - 1
truing_control/PDU-3-ADA/modbus/BARE/port/portserial.c

@@ -44,6 +44,8 @@ vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
 		{
 		{
 			usart_interrupt_disable(USART0,USART_INT_RBNE);
 			usart_interrupt_disable(USART0,USART_INT_RBNE);
 			usart_interrupt_disable(USART0,USART_INT_TC);
 			usart_interrupt_disable(USART0,USART_INT_TC);
+			usart_disable(USART0);
+			nvic_irq_disable(USART0_IRQn); 
 			gpio_bit_reset(GPIOA, GPIO_PIN_8);
 			gpio_bit_reset(GPIOA, GPIO_PIN_8);
 			return;
 			return;
 		}
 		}
@@ -71,6 +73,7 @@ vMBPortSerialEnable( BOOL xRxEnable, BOOL xTxEnable )
     }
     }
 }
 }
 
 
+
 BOOL
 BOOL
 xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
 xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
 {
 {
@@ -139,7 +142,7 @@ void USART0_IRQHandler(void)
   if(usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE) != RESET)  //接收缓冲区非空中断
   if(usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE) != RESET)  //接收缓冲区非空中断
   {   
   {   
 		usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE);  //清除USART1中断挂起   
 		usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE);  //清除USART1中断挂起   
-		prvvUARTRxISR();		                                                                                   
+		prvvUARTRxISR();
   }                                                         
   }                                                         
                                                             
                                                             
   if(usart_flag_get(USART0, USART_FLAG_ORERR) == SET) //溢出错误标志为1
   if(usart_flag_get(USART0, USART_FLAG_ORERR) == SET) //溢出错误标志为1

+ 1 - 0
truing_control/PDU-3-ADA/modbus/mb.c

@@ -313,6 +313,7 @@ eMBDisable( void )
     if( eMBState == STATE_ENABLED )
     if( eMBState == STATE_ENABLED )
     {
     {
         pvMBFrameStopCur(  );
         pvMBFrameStopCur(  );
+
         eMBState = STATE_DISABLED;
         eMBState = STATE_DISABLED;
         eStatus = MB_ENOERR;
         eStatus = MB_ENOERR;
     }
     }

+ 3 - 0
truing_control/PDU-3-ADA/modbus/rtu/mbrtu.c

@@ -247,6 +247,8 @@ xMBRTUReceiveFSM( void )
 		if(eSndState != STATE_TX_IDLE)
 		if(eSndState != STATE_TX_IDLE)
 		{
 		{
 			eMBDisable();
 			eMBDisable();
+			eSndState = STATE_TX_IDLE;
+			xMBPortSerialGetByte( ( CHAR * ) & ucByte );
 			return xTaskNeedSwitch;
 			return xTaskNeedSwitch;
 		}
 		}
 
 
@@ -311,6 +313,7 @@ xMBRTUTransmitFSM( void )
 		if(eRcvState != STATE_RX_IDLE)
 		if(eRcvState != STATE_RX_IDLE)
 		{
 		{
 			eMBDisable();
 			eMBDisable();
+			eRcvState = STATE_RX_IDLE;
 			return xNeedPoll;
 			return xNeedPoll;
 		}
 		}
 //		if(eRcvState != STATE_RX_IDLE)
 //		if(eRcvState != STATE_RX_IDLE)

+ 16 - 5
truing_control/PDU-3-ADA/user/board_cfg.h

@@ -15,8 +15,8 @@
 
 
 
 
 
 
-#define OPEN_WATCH_DOG  				0
-#define OPEN_NOT_READ_EN				0
+#define OPEN_WATCH_DOG  				1
+#define OPEN_NOT_READ_EN				1
 
 
 
 
 
 
@@ -26,7 +26,8 @@
 
 
 #define   AC_3_3                      0
 #define   AC_3_3                      0
 #define  	AC_3_2											0
 #define  	AC_3_2											0
-#define   AC_3_4                      1
+#define   AC_3_4                      0
+#define   AC_3_3_MON                  1
 
 
 
 
 
 
@@ -39,9 +40,9 @@
 #elif AC_3_4
 #elif AC_3_4
 	#define 	RelaySlaveChaNum 					3
 	#define 	RelaySlaveChaNum 					3
 	#define   PT_SUB_COUNT              RelaySlaveChaNum
 	#define   PT_SUB_COUNT              RelaySlaveChaNum
-//	#define 	SUPPORT_DETECTION					1
+	#define 	SUPPORT_DETECTION					1
 	#define 	ACSingCurrid              8
 	#define 	ACSingCurrid              8
-//	#define   SUPPORT_RELAY_REMENBER		1
+	#define   SUPPORT_RELAY_REMENBER		1
 	#define   SUPPORT_ZERO_CRTL         1
 	#define   SUPPORT_ZERO_CRTL         1
 #elif AC_3_2
 #elif AC_3_2
 	#define 	RelaySlaveChaNum 					8
 	#define 	RelaySlaveChaNum 					8
@@ -50,6 +51,16 @@
 	#define 	ACSingCurrid              9
 	#define 	ACSingCurrid              9
 	#define   SUPPORT_RELAY_REMENBER		1
 	#define   SUPPORT_RELAY_REMENBER		1
 	#define   SURPPORT_2_PT             1
 	#define   SURPPORT_2_PT             1
+	
+#elif AC_3_3_MON
+
+	#define 	RelaySlaveChaNum 					3
+	#define   PT_SUB_COUNT              RelaySlaveChaNum
+	#define 	SUPPORT_DETECTION					0
+	#define 	ACSingCurrid              8
+	#define   SUPPORT_RELAY_REMENBER		0
+	#define   SUPPORT_MON               1
+
 #endif
 #endif
 
 
 
 

+ 5 - 2
truing_control/PDU-3-ADA/user/main.c

@@ -82,7 +82,7 @@ int main(){
 	#endif
 	#endif
 	ac_board.detection();
 	ac_board.detection();
 
 
-#if (AC_3_3 || AC_3_4)
+#if (AC_3_3 || AC_3_4 ||AC_3_3_MON)
 	if((ac_board.md_data.r_data.detection & 0x1) == 0)
 	if((ac_board.md_data.r_data.detection & 0x1) == 0)
 	{
 	{
 		for(uint8_t i = 0; i < PT_SUB_COUNT;i++)
 		for(uint8_t i = 0; i < PT_SUB_COUNT;i++)
@@ -145,7 +145,9 @@ int main(){
 	{
 	{
 		if(eMBCheck())
 		if(eMBCheck())
 		{
 		{
+			eMBInit(MB_RTU, ac_board.haddr, 0, 115200, MB_PAR_NONE);
 			eMBEnable();
 			eMBEnable();
+			DelayNms(1);
 		}
 		}
 		ac_board.feed_dog();
 		ac_board.feed_dog();
 		task_query();
 		task_query();
@@ -235,6 +237,7 @@ static void task_10s(void)
 
 
 static void relay_ctrl(void)
 static void relay_ctrl(void)
 {
 {
+#if (!SUPPORT_MON)
 	for(uint8_t i = 0; i < RelaySlaveChaNum;i++)
 	for(uint8_t i = 0; i < RelaySlaveChaNum;i++)
 	{
 	{
 		if(IS_RL_ORDER_FLAG_EN(ac_board.relay_staging_staus[i]))
 		if(IS_RL_ORDER_FLAG_EN(ac_board.relay_staging_staus[i]))
@@ -370,5 +373,5 @@ static void relay_ctrl(void)
 	}
 	}
 
 
 #endif
 #endif
-	
+#endif
 }
 }

+ 4 - 1
truing_control/PDU-AC_ADA_NEW_6/hardware/electricity/electricity.c

@@ -69,7 +69,7 @@ static void read_ele(uint8_t channel)
 			reinit_hlw8110();
 			reinit_hlw8110();
 			Calculate_HLW8110_MeterData();
 			Calculate_HLW8110_MeterData();
 		}
 		}
-		if(F_AC_V < 1.0)
+		if(F_AC_V < 2.0)
 		{
 		{
 			F_AC_V = 0.0;
 			F_AC_V = 0.0;
 			F_AC_I = 0.0;
 			F_AC_I = 0.0;
@@ -81,6 +81,9 @@ static void read_ele(uint8_t channel)
 			F_AC_I = 0.0;
 			F_AC_I = 0.0;
 			F_AC_P = 0.0;
 			F_AC_P = 0.0;
 			F_AC_PF = 0.0;
 			F_AC_PF = 0.0;
+		}else if(F_AC_LINE_Freq > 100)
+		{
+			F_AC_LINE_Freq = 0.0;
 		}
 		}
 		board->md_data.r_data.ac_ele.ele_info[channel].voltage = F_AC_V * 1000;
 		board->md_data.r_data.ac_ele.ele_info[channel].voltage = F_AC_V * 1000;
 		board->md_data.r_data.ac_ele.ele_info[channel].current = F_AC_I * 1000;
 		board->md_data.r_data.ac_ele.ele_info[channel].current = F_AC_I * 1000;

+ 1 - 1
truing_control/PDU-AC_ADA_NEW_6/user/board_cfg.h

@@ -129,7 +129,7 @@
 	#define   PT_SUB_COUNT              (RelaySlaveChaNum)
 	#define   PT_SUB_COUNT              (RelaySlaveChaNum)
 	#define   SUPPORT_DETECTION         1
 	#define   SUPPORT_DETECTION         1
 	#define   SUPPORT_RELAY_REMENBER		1
 	#define   SUPPORT_RELAY_REMENBER		1
-	#define   SUPPORT_4_ON_FLASH        1
+//	#define   SUPPORT_4_ON_FLASH        1
 	#define   SUPPORT_ALL_ON_OFF    		1
 	#define   SUPPORT_ALL_ON_OFF    		1
 	
 	
 #elif PRJ_3_BASE
 #elif PRJ_3_BASE

+ 1 - 0
truing_control/PDU-AC_ADA_NEW_6/user/main.c

@@ -136,6 +136,7 @@ int main(){
 		{
 		{
 			eMBInit(MB_RTU, ac_board.haddr, 0, 115200, MB_PAR_NONE);
 			eMBInit(MB_RTU, ac_board.haddr, 0, 115200, MB_PAR_NONE);
 			eMBEnable();
 			eMBEnable();
+			DelayNms(1);
 		}
 		}
 		ac_board.feed_dog();
 		ac_board.feed_dog();
 		task_query();
 		task_query();