Explorar el Código

01. 合并: 共享内存处理。
02. 合并: ADC配置每周波256点处理。
03. 增加: aht20温湿度传感器驱动。
04. 修改: ADC采样通道索引排序。
05. 同步: DTUv4采样电阻系数。
06. 修改: can发送线程休眠时间。
07. 修改: 回退系统时区错误处理。
08. 修复: 维护工具获取故障信息时错误描述错位的问题。
09. 同步: DTUv4点表。
10. 修改: 开关定值读取异常问题处理。

EWen hace 11 meses
padre
commit
5cc3d682fc
Se han modificado 39 ficheros con 1619 adiciones y 213 borrados
  1. 16 1
      README.md
  2. 23 7
      app_public/fuxi_public/fuxi_bsp/include/ad7616.h
  3. 19 0
      app_public/fuxi_public/fuxi_bsp/include/aht20.h
  4. 2 0
      app_public/fuxi_public/fuxi_bsp/include/bsp.h
  5. 10 2
      app_public/fuxi_public/fuxi_bsp/include/bspconfig.h
  6. 227 0
      app_public/fuxi_public/fuxi_bsp/include/shm_api.h
  7. 34 0
      app_public/fuxi_public/fuxi_bsp/include/shmem.h
  8. 185 3
      app_public/fuxi_public/fuxi_bsp/source/ad7616.c
  9. 213 0
      app_public/fuxi_public/fuxi_bsp/source/aht20.c
  10. 10 5
      app_public/fuxi_public/fuxi_bsp/source/bsp.c
  11. 8 7
      app_public/fuxi_public/fuxi_bsp/source/equ_dtu.c
  12. 3 2
      app_public/fuxi_public/fuxi_bsp/source/factor.c
  13. 4 2
      app_public/fuxi_public/fuxi_bsp/source/flexcan.c
  14. 8 5
      app_public/fuxi_public/fuxi_bsp/source/freq.c
  15. 20 8
      app_public/fuxi_public/fuxi_bsp/source/gpio.c
  16. 1 7
      app_public/fuxi_public/fuxi_bsp/source/led_ftu.c
  17. 299 0
      app_public/fuxi_public/fuxi_bsp/source/shmem.c
  18. 1 1
      app_public/fuxi_public/fuxi_bsp/source/watchdog.c
  19. 3 3
      app_public/fuxi_public/rt_lite/include/rt.h
  20. 8 7
      app_public/fuxi_public/rt_lite/source/rt_error.c
  21. 146 0
      dtu/dtu_main_t536/app/Appconfig.c
  22. 154 0
      dtu/dtu_main_t536/app/Appconfig.h
  23. 8 2
      dtu/dtu_main_t536/app/Sys.c
  24. 2 6
      dtu/dtu_main_t536/app/UnitsLib.c
  25. 2 0
      dtu/dtu_main_t536/app/dcfactor.c
  26. 4 0
      dtu/dtu_main_t536/app/defineSys.h
  27. 1 1
      dtu/dtu_main_t536/app/equ.c
  28. 1 1
      dtu/dtu_main_t536/app/fuxi_shm_app.c
  29. 3 0
      dtu/dtu_main_t536/app/main.c
  30. 11 9
      dtu/dtu_main_t536/app/protect.c
  31. 4 4
      dtu/dtu_main_t536/app/reclose.c
  32. 2 0
      dtu/dtu_main_t536/app/run_status.c
  33. 124 123
      dtu/dtu_main_t536/app/set.c
  34. 3 3
      dtu/dtu_main_t536/app/set.h
  35. 20 2
      dtu/dtu_main_t536/app/switch.c
  36. 3 0
      dtu/dtu_main_t536/app/switch.h
  37. 1 1
      dtu/dtu_main_t536/app/sysTime.c
  38. 34 1
      dtu/dtu_main_t536/main_mod.c
  39. 2 0
      dtu/dtu_main_t536/sh/t536/Makefile

+ 16 - 1
README.md

@@ -20,4 +20,19 @@
 01. 合并: can收发处理,dido对接can收发数据。
 02. 修改: clk_time_get接口获取的时间修改回UTC+8时区。
 03. 修改: 采样板起始板卡宏修改。
-04. 修改: 线损维护串口切换io根据硬件修改为PM5。
+04. 修改: 线损维护串口切换io根据硬件修改为PM5。
+   
+# 20251110
+01. 增加: 共享内存对接。
+
+# 20251120
+01. 合并: 共享内存处理。
+02. 合并: ADC配置每周波256点处理。
+03. 增加: aht20温湿度传感器驱动。
+04. 修改: ADC采样通道索引排序。
+05. 同步: DTUv4采样电阻系数。
+06. 修改: can发送线程休眠时间。
+07. 修改: 回退系统时区错误处理。
+08. 修复: 维护工具获取故障信息时错误描述错位的问题。
+09. 同步: DTUv4点表。
+10. 修改: 开关定值读取异常问题处理。

+ 23 - 7
app_public/fuxi_public/fuxi_bsp/include/ad7616.h

@@ -81,15 +81,31 @@ extern s16 (*g_adc_dots)[CFG_ADC_DOTS_PER_CHANNEL*2];
 extern s16 (*g_adc_dots_rec)[CFG_ADC_CHANNEL];
 extern struct timespec ts_adc_dots[CFG_ADC_DOTS_PER_CHANNEL];
 
-#define ADC_REC_SAMPLE			128		// 录波每周采样点数
-#define ADC_REC_SAMPLE_RATE		4		// 录波128点,计算32点,比率为4
-#define ADC_REC_LEN				64		// 录波记录长度,以周波为单位,64周波约1.28s。
-#define ADC_REC_DOTS_CHANNEL	(ADC_REC_SAMPLE*ADC_REC_LEN)// 每通道点数
-#define ADC_REC_DOTS_MASK		(ADC_REC_DOTS_CHANNEL - 1)	// 录波索引屏蔽字
-
 #define AD7616_DC0_CHANNEL		14
 #define AD7616_DC1_CHANNEL		-1
 
+#ifdef CFG_256_DOTS_PER_PERIOD
+#define ADC_REC_SAMPLE            256        // 录波每周采样点数
+#define ADC_REC_SAMPLE_RATE        8        // 录波256点,计算32点,比率为8
+#else
+#define ADC_REC_SAMPLE            128        // 录波每周采样点数
+#define ADC_REC_SAMPLE_RATE        4        // 录波128点,计算32点,比率为4
+#endif
+#define ADC_REC_LEN                64        // 录波记录长度,以周波为单位,64周波约1.28s。
+#define ADC_REC_DOTS_CHANNEL    (ADC_REC_SAMPLE*ADC_REC_LEN)// 每通道点数
+#define ADC_REC_DOTS_MASK        (ADC_REC_DOTS_CHANNEL - 1)    // 录波索引屏蔽字
+ 
+extern volatile unsigned long g_adc_dots_count;
+#define g_adc_dots_index         (g_adc_dots_count&CFG_ADC_DOTS_MASK)
+#ifdef CFG_256_DOTS_PER_PERIOD
+#define g_adc_dots_index_rec    ((g_adc_dots_count<<3)&ADC_REC_DOTS_MASK)
+#else
+#define g_adc_dots_index_rec    ((g_adc_dots_count<<2)&ADC_REC_DOTS_MASK)
+#endif
+extern int g_adc_sync;
+extern float g_freq;
+
+
 
 extern volatile unsigned long g_adc_dots_count;
 
@@ -157,7 +173,7 @@ int adc_slot_is_ok(int slot);
 修改记录:
 */
 int adc_isr(int mod);
-
+int adc_isr_new(int mod);
 /******************************************************************************
 函数名称:	adc_stat_reset
 函数版本:	01.01

+ 19 - 0
app_public/fuxi_public/fuxi_bsp/include/aht20.h

@@ -0,0 +1,19 @@
+#ifndef _AHT20_H_
+#define _AHT20_H_
+#ifdef TMP_CHIP_AHT20
+struct aht20
+{
+    float temp;
+    float humi;
+
+    unsigned long us0;
+};
+
+int aht20_init(void);
+int aht20_exit(void);
+void aht20_task(void);
+float aht20_get_temp(void);
+float aht20_get_humi(void);
+#endif /* TMP_CHIP_AHT20 */
+
+#endif /* _AHT20_H_ */

+ 2 - 0
app_public/fuxi_public/fuxi_bsp/include/bsp.h

@@ -36,6 +36,8 @@
 #include <sched.h>
 #include "bsp_ccu.h"
 #include "bsp_ustimer.h"
+#include "aht20.h"
+#include "shmem.h"
 
 extern const char * szTool;
 

+ 10 - 2
app_public/fuxi_public/fuxi_bsp/include/bspconfig.h

@@ -50,12 +50,12 @@
 #define EQU_SLOT_HMI			2	// 面板
 
 #define EQU_SLOT_AC_BEGIN		1	// 采样板起始槽位
-#define EQU_SLOT_AC_NUM			1	// 一个装置支持AC板的最大槽数。
+#define EQU_SLOT_AC_NUM			2	// 一个装置支持AC板的最大槽数。1 -> 2 DTUv5采用两块采样板
 #define EQU_SLOT_AC_CHN			16   // 每个槽中支持的最大AC通道数
 #define EQU_DB_YX_NUM			32	// 数据总线长度
 
 #define	EQU_SLOT_NUM_06			6 // DTUv5 目前配置卡槽数量为6,后续根据需求修改
-#define EQU_SLOT_AC_BEGIN06		1 // 定义6卡槽DTUv5中AC采样板的卡槽开始位置
+#define EQU_SLOT_AC_BEGIN06		0 // 定义6卡槽DTUv5中AC采样板的卡槽开始位置
 
 //----------------------------- 线路开关  ---------------------------
 #define SWITCH_NUM_MAX			6  // 开关数量,本装置实际支持的开关数,不包含级联部分。
@@ -230,6 +230,14 @@
 
 //--------------------------------  ADC  --------------------------------
 //
+#define CFG_256_DOTS_PER_PERIOD        // 一周波采256点
+ 
+#ifdef    CFG_256_DOTS_PER_PERIOD
+#define CFG_ADC_MOD_NUM             8    //256采样时8个点抽一个,抽取32个计算,比率为8
+#else
+#define CFG_ADC_MOD_NUM             4
+#endif
+
 #define CFG_ADC_DOTS_PER_PERIOD		32						// 每个周波的采样点数。
 #define CFG_ADC_DOTS_PER_CHANNEL	256						// 每个ADC通道保存的采样点数(8个周波)。
 #define CFG_ADC_DOTS_MASK			(CFG_ADC_DOTS_PER_CHANNEL-1)// 每个ADC通道保存的采样点数的MASK。

+ 227 - 0
app_public/fuxi_public/fuxi_bsp/include/shm_api.h

@@ -0,0 +1,227 @@
+/**
+ * @file           shm_api.c
+ * @brief          共享内存接口文件
+ * @author         lch (lch_work@foxmail.com)
+ * @version        1.0
+ * @date           20250917
+ * 
+ * @copyright Copyright (c) 2025 by OLE, All Rights Reserved.
+ * 
+ * @par 修改日志:
+ * <table>
+ * <tr><th>Date        <th>Version         <th>Author          <th>Description
+ * <tr><td>20250917    <td>1.0             <td>lch             <td>内容
+ * </table>
+ */
+
+
+/***** 宏定义 *****/
+
+#ifndef DEF_SHM_API_H
+#define DEF_SHM_API_H
+
+#define MAX_SHMEM_RD_LEN	(CONFIG_SHARE_MEM_LENGTH / 2)
+#define MAX_SHMEM_WR_LEN	(CONFIG_SHARE_MEM_LENGTH / 2)
+#define MAX_SHMEM_RD_DATA_LEN	(MAX_SHMEM_RD_LEN)
+#define MAX_SHMEM_WR_DATA_LEN	(MAX_SHMEM_WR_LEN)
+
+/* 内存地址 */
+/* linux核写 RV核读 */
+#define SHM_ADDR_R_MACHINETYPE          0x00000000 /* 装置类型 */
+#define SHM_ADDR_R_DI_ASTIME            0x00001000 /* 开入防抖时间 */
+#define SHM_ADDR_R_TIMESTAMP            0x00002000 /* ms时间戳 */
+#define SHM_ADDR_R_MACHINEPARAM         0x00003000 /* 参数数据 */
+
+/* linux核读 RV核写 */
+#define SHM_ADDR_W_DI                   0x00000000 /* 开入量数据 */
+#define SHM_ADDR_W_FREQ                 0x00001000 /* 频率 */
+#define SHM_ADDR_W_U_ADC_1              0x00020000 /* 第一片ADC采样数据区 */
+#define SHM_ADDR_W_U_ADC_2              0x00040000 /* 第二片ADC采样数据区 */
+#define SHM_ADDR_W_U_ADC_3              0x00060000 /* 第三片ADC采样数据区 */
+#define SHM_ADDR_W_U_ADC_4              0x00080000 /* 第四片ADC采样数据区 */
+#define SHM_ADDR_W_U_ADC_5              0x000A0000 /* 第五片ADC采样数据区 */
+#define SHM_ADDR_W_FLAG                 0x000C0000 /* 标志数据 */
+
+#ifndef DI_MAX
+#define DI_MAX  (31)
+#endif
+
+#ifndef ADC_SAMPLEING_RATE  /* ADC采样率 0 : 6400(156.25us) 1 : 12800(78.125us)  */
+#define ADC_SAMPLEING_RATE 1
+#endif
+
+#define ADC_HARDWARE_NUM    5  /* ADC片数 先按最多的5个来 */
+#define ADC_CHANNEL         16 /* ADC采样的通道数 */
+
+#if (0 == ADC_SAMPLEING_RATE)
+
+#define ADC_SAMPLE_PER_CYCLE 128 /* 录波每周采样点数 */
+/* 每个ADC通道缓存的采样点数 理论上不会溢出 64  */
+#define TC_ADC_DOTS_PER_CHANNEL (ADC_SAMPLE_PER_CYCLE / 2)
+
+#else /* ADC_SAMPLEING_RATE */
+
+#define ADC_SAMPLE_PER_CYCLE 256 /* 录波每周采样点数 */
+/* 每个ADC通道缓存的采样点数 理论上不会溢出 96  */
+#define TC_ADC_DOTS_PER_CHANNEL ((ADC_SAMPLE_PER_CYCLE / 4) + ((ADC_SAMPLE_PER_CYCLE / 8)))
+
+#endif /* ADC_SAMPLEING_RATE */
+
+#define ADC_SAMPLE_UPDATA (ADC_SAMPLE_PER_CYCLE / 4) /* 录波更新点数 */
+
+/***** 头文件 *****/
+
+/*****  枚举  *****/
+
+enum e_shm_type
+{
+    e_shm_machinetype = 0,
+    e_shm_di_astime,
+    e_shm_timestamp,
+    
+    e_shm_type_max,
+};
+
+/***** 结构体 *****/
+
+/****************************** A核写, R核读 ******************************/
+
+/* 装置类型 */
+struct t_shmdata_machine_type
+{
+    uint16_t us_updata;       /* 数据更新标志 */
+    uint16_t us_op;           /* 操作标志 */
+    uint16_t us_op_bk;        /* 操作标志备份 */
+    uint16_t us_machine_type; /* 数据 */
+    uint16_t us_crc;          /* crc 应用不用处理 底层接口处理 */
+};
+
+/* 开入防抖时间 */
+struct t_shmdata_di_astime
+{
+    uint16_t us_updata;      /* 数据更新标志 */
+    uint16_t us_op;          /* 操作标志 */
+    uint16_t us_op_bk;       /* 操作标志备份 */
+    uint16_t us_as_time[32]; /* 数据 */
+    uint16_t us_crc;         /* crc 应用不用处理 底层接口处理 */
+};
+
+/* ms时间戳 */
+struct t_shmdata_timestamp
+{
+    uint16_t us_updata;      /* 数据更新标志 */
+    uint16_t us_op;          /* 操作标志 */
+    uint16_t us_op_bk;       /* 操作标志备份 */
+    uint64_t ull_timestamp;  /* 数据 */
+    uint16_t us_crc;         /* crc 应用不用处理 底层接口处理 */
+} __attribute__ ((packed)); /* 大小16个字节 */
+
+/****************************** A核读, R核写 ******************************/
+
+/* 开入量 */
+
+struct t_sd_di_status
+{
+    uint8_t uc_state;       // 开入量状态
+    uint64_t ull_timestamp; // 时间戳
+};
+
+struct t_shmdata_di
+{
+    uint16_t us_updata;               /* 数据更新标志 */
+    uint16_t us_op;                   /* 操作标志 */
+    uint16_t us_op_bk;                /* 操作标志备份 */
+    struct t_sd_di_status di[DI_MAX]; /* 数据 */
+    uint16_t us_crc;                  /* crc 应用不用处理 底层接口处理 */
+}__attribute__ ((packed)); /* 大小504个字节 */
+
+/* 频率 */
+struct t_shmdata_freq
+{
+    uint16_t us_updata; /* 数据更新标志 */
+    uint16_t us_op;     /* 操作标志 */
+    uint16_t us_op_bk;  /* 操作标志备份 */
+    uint16_t us_freq[2];/*放大1000倍*/
+    uint16_t us_crc;    /* crc 应用不用处理 底层接口处理 */
+};
+
+/**< 采样点结构体 */
+struct t_sampledata_mc
+{
+    uint16_t us_sample_idx;       /* 采样索引下标 */
+    uint16_t us_ft_idx;           /* 频率变化下标 */
+    uint16_t us_xdl_idx;          /* 小电流突变下标 */
+    uint16_t usa_sample_dots[ADC_CHANNEL][TC_ADC_DOTS_PER_CHANNEL];
+};
+
+/* 采样数据 */
+struct t_shmdata_adc
+{
+    uint16_t us_updata;          /* 数据更新标志 */
+    uint16_t us_op;              /* 操作标志 */
+    uint16_t us_op_bk;           /* 操作标志备份 */
+    struct t_sampledata_mc data; /* 数据 */
+    uint16_t us_crc;             /* crc 应用不用处理 底层接口处理 */
+}; /* 大小3086个字节 */
+
+/* 标志数据 */
+struct t_shmdata_flag
+{   
+    uint16_t us_updata;         /* 数据更新标志 */
+    uint16_t us_op;             /* 操作标志 */
+    uint16_t us_op_bk;          /* 操作标志备份 */
+    uint16_t us_cfg_adc_err;    /* ADC初始化错误 */
+    uint16_t us_crc;            /* crc 应用不用处理 底层接口处理 */
+};  /* 大小10个字节 */
+
+struct t_device_shm
+{
+    int (*init)             (void);
+    int (*read)             (uint32_t _ul_addr, uint32_t _ul_len, uint8_t *_puc_data_out, uint32_t _uc_data_out_size);
+    int (*write)            (uint32_t _ul_addr, uint8_t *_puc_data, uint32_t _ul_len);
+    int (*pack_read)        (uint32_t _ul_addr, uint32_t _ul_len, uint8_t *_puc_data_out, uint32_t _uc_data_out_size);
+    int (*pack_write)       (uint32_t _ul_addr, uint8_t *_puc_data, uint32_t _ul_len);
+    int (*scan_data)        (enum e_shm_type _e_type);
+};
+
+/***** 变量对外声明 *****/
+
+/**
+ * @brief       共享内存结构体
+ * 
+ * @note        gt_shm.init 初始化
+ * @note        gt_shm.read 从共享内存读取数据
+ *        -     {uint32_t} _ul_addr 读取共享内存的地址
+ *        -     {uint32_t} _ul_len 需要读取的数据长度
+ *        -     {uint8_t *} _puc_data_out 输出buf
+ *        -     {uint32_t} _uc_data_out_size 输出buf的长度
+ *        -     成功返回读取数据的长度, 失败返回-1
+ * 
+ * @note        gt_shm.write 往共享内存写入数据
+ *        -     {uint32_t} _ul_addr 共享内存的地址
+ *        -     {uint8_t *} _puc_data 需要写入的数据
+ *        -     {uint32_t} _ul_len 需要写入的数据长度
+ *        -     成功返回读取数据的长度, 失败返回-1
+ * 
+ * @note        gt_shm.pack_read 从共享内存读取数据 带读写标志
+ *        -     {uint32_t} _ul_addr 读取共享内存的地址
+ *        -     {uint32_t} _ul_len 需要读取的数据长度
+ *        -     {uint8_t *} _puc_data_out 输出buf
+ *        -     {uint32_t} _uc_data_out_size 输出buf的长度
+ *        -     成功返回读取数据的长度, 失败返回-1
+ * 
+ * @note        gt_shm.pack_write 往共享内存写入数据 带读写标志
+ *        -     {uint32_t} _ul_addr 共享内存的地址
+ *        -     {uint8_t *} _puc_data 需要写入的数据
+ *        -     {uint32_t} _ul_len 需要写入的数据长度
+ *        -     成功返回读取数据的长度, 失败返回-1
+ * 
+ * @note        gt_shm.scan_data 扫描共享内存数据更新
+ *        -     {enum e_shm_type} _e_type 共享内存的类型描述
+ *        -     有数据更新返回1
+ */
+extern struct t_device_shm gt_shm;
+
+/***** 函数对外声明 *****/
+
+#endif /* end of file */

+ 34 - 0
app_public/fuxi_public/fuxi_bsp/include/shmem.h

@@ -0,0 +1,34 @@
+/**shmem.h*/
+#ifndef __SHMEM_H
+#define __SHMEM_H
+
+#include <unistd.h>
+#include <stdint.h>
+
+#include "shm_api.h"
+
+struct shmem_fd
+{
+	int fd;
+	int shmem_len;
+
+	uint8_t *linux_write;
+	uint8_t *linux_read;
+
+	int linux_write_len, linux_read_len;
+	int linux_write_data_len, linux_read_data_len;
+};
+
+#define max_shmem_wr_len(s) ((s) / 2)
+#define max_shmem_rd_len(s) ((s) / 2)
+
+int shm_write_data(uint32_t _ul_addr, uint8_t *_puc_data, uint32_t _ul_len);
+int shm_packet_write_v2(uint32_t _ul_addr, uint8_t *_puc_data, uint32_t _ul_len);
+
+int shm_read_data(uint32_t _ul_addr, uint32_t _ul_len, uint8_t *_puc_data_out, uint32_t _uc_data_out_size);
+int shm_packet_read_v2(uint32_t _ul_addr, uint32_t _ul_len, uint8_t *_puc_data_out, uint32_t _uc_data_out_size);
+
+int share_mem_init_v2(struct shmem_fd *shmem_fd);
+void share_mem_exit_v2(struct shmem_fd *shmem_fd);
+
+#endif // !__SHMEM_H

+ 185 - 3
app_public/fuxi_public/fuxi_bsp/source/ad7616.c

@@ -16,8 +16,9 @@
 #include "head.h"
 #include <malloc.h>
 #include "rt_printf.h"
-#include "shm_comm_packet.h"
+// #include "shm_comm_packet.h"
 #include <mb.h>
+#include "shmem.h"
 
 /*------------------------------ 宏定义 ---------------------------------------
 */
@@ -118,7 +119,7 @@ static int write_v_default(uint8_t no, uint8_t *data)
 		
     while(1)
     {
-    	ret = shm_comm_packet_write(SHM_ADDR_D_RFV_1+(SHM_ADDR_D_RFV_2-SHM_ADDR_D_RFV_1)*no, data, sizeof(SHM_RFV_T));
+    	// ret = shm_comm_packet_write(SHM_ADDR_D_RFV_1+(SHM_ADDR_D_RFV_2-SHM_ADDR_D_RFV_1)*no, data, sizeof(SHM_RFV_T));
 		if(ret > 0)	
 		{
 			break;
@@ -376,7 +377,13 @@ int adc_exit(void)
     return ret;
 }
 
-
+/**
+ * @brief 旧方式获取共享内存数据(已抛弃)
+ * 
+ * @param mod 
+ * @return int
+ * @author zhl
+ */
 int adc_isr(int mod)
 {
 
@@ -541,6 +548,181 @@ int adc_isr(int mod)
 	return 0;
 }
 
+static void updata_adc(struct t_shmdata_adc *sample_data0, uint16_t us_adc_dot_index0, struct t_shmdata_adc *sample_data1, uint16_t us_adc_dot_index1)
+{
+	int i = 0;
+	int index = 0;
+	int opt = ((g_adc_dots_data_count & (ADC_REC_SAMPLE_RATE - 1)) == 0) ? TRUE : FALSE;
+	//每片16路
+	for (uint8_t j = 0; j < 16; j++)
+	{
+		g_adc_dots_rec[g_adc_dots_index_rec][j] =
+			sample_data0->data.usa_sample_dots[j][us_adc_dot_index0];
+
+		if (opt == TRUE)
+		{
+			g_adc_dots[j][g_adc_dots_index] =
+				sample_data0->data.usa_sample_dots[j][us_adc_dot_index0];
+		}
+	}
+
+	for (uint8_t j = 16; j < CFG_ADC_CHANNEL; j++)
+	{
+		g_adc_dots_rec[g_adc_dots_index_rec][j] =
+			sample_data1->data.usa_sample_dots[j - 16][us_adc_dot_index1]; // 注意两片ADC为不同内存,j得减16
+
+		// if (j == 17) // 3_IA
+		// {
+		// 	int32_t physical_value1 = (int16_t)g_adc_dots_rec[g_adc_dots_index_rec][j];
+		// 	printf("%d, ", physical_value1);
+		// }
+
+		if (opt == TRUE)
+		{
+			g_adc_dots[j][g_adc_dots_index] =
+				sample_data1->data.usa_sample_dots[j - 16][us_adc_dot_index1]; // 注意两片ADC为不同内存,j得减16
+
+			// if (j == 17) // 3_IA
+			// {
+			// 	int32_t physical_value1 = (int16_t)g_adc_dots[j][g_adc_dots_index];
+			// 	printf("%d, ", physical_value1);
+			// }
+		
+		}
+	}
+
+	// 直流采样 国网集中式暂时不需要 zhl TODO
+	// g_adc_dots_dc[0][g_adc_dots_data_count & CFG_ADC_DOTS_MASK] =
+	// 	sample_data->data.usa_sample_dots[AD7616_DC0_CHANNEL][us_adc_dot_index];
+
+	if (opt == TRUE)
+	{
+		index = g_adc_dots_index;
+
+		// 统计数据
+		if (g_adc_stat_flag)
+		{
+			for (i = 0; i < CFG_ADC_CHANNEL; i++)
+			{
+				rt_stat_in(&g_stat_adc[i], (unsigned short)(g_adc_dots[i][index] + 32768));
+			}
+		}
+
+		// 通道取反
+		for (i = 0; i < g_equ_adc_inv_num; i++)
+		{
+			g_adc_dots[g_equ_adc_inv[i]][index] = -(g_adc_dots[g_equ_adc_inv[i]][index]);
+		}
+
+		// 全部BUFFER都是新数据,才能算同步好。
+		if (g_adc_sync < 1)
+		{
+			g_adc_sync++;
+		}
+
+		// 索引值加一
+		g_adc_dots_count++;
+		// 保护计数+突变量
+		{
+			dTCounter++;
+			if (dTCounter % 8 == 0)
+			{
+				prt_flag = true;
+			}
+			// 突变量
+			if (g_adc_sync == 1 && g_sw_init == 1)
+			{
+				protect_tbl_qd();
+			}
+		}
+	}
+
+	g_adc_dots_data_count++;
+}
+
+/**
+ * @brief 新方式获取共享内存数据
+ * 
+ * @param mod 
+ * @return int
+ * @author zhl
+ */
+int adc_isr_new(int mod)
+{
+	int cnt = 0;
+	struct t_shmdata_adc sample_data0 = {0};
+	struct t_shmdata_adc sample_data1 = {0};
+	int ret0 = 0;
+	int ret1 = 0;
+	static volatile uint16_t smus_sample_read_index0 = 0; /* 读取adc1索引 */
+	static volatile uint16_t smus_sample_read_index1 = 0; /* 读取adc2索引 */
+
+	ret0 = shm_packet_read_v2(SHM_ADDR_W_U_ADC_1, sizeof(sample_data0), (uint8_t *)&sample_data0, sizeof(sample_data0));
+    // printf("ret0=%d, sample_idx=%d, read_index=%d, us_updata=%d, us_op=%d, us_op_bk=%d\n", 
+	// 	ret0, sample_data0.data.us_sample_idx, smus_sample_read_index0, sample_data0.us_updata, sample_data0.us_op, sample_data0.us_op_bk);
+	
+	while (ret0 > 0)
+	{
+		ret1 = shm_packet_read_v2(SHM_ADDR_W_U_ADC_2 , sizeof(sample_data1), (uint8_t *)&sample_data1, sizeof(sample_data1));
+		if(ret1 > 0)
+			break;
+
+		if(++cnt > 5)
+			break;
+
+		usleep(300);
+	}
+    // printf("ret1=%d, sample_idx=%d, read_index=%d, us_updata=%d, us_op=%d, us_op_bk=%d\n", 
+	// 	ret1, sample_data1.data.us_sample_idx, smus_sample_read_index1, sample_data1.us_updata, sample_data1.us_op, sample_data1.us_op_bk);
+	
+	if((ret0 > 0 && (smus_sample_read_index0 != sample_data0.data.us_sample_idx))
+		 && (ret1 > 0 && (smus_sample_read_index1 != sample_data1.data.us_sample_idx)))
+    {
+		uint16_t us_adc_dot_num0 = 0;
+        if (sample_data0.data.us_sample_idx > smus_sample_read_index0)
+        {
+            us_adc_dot_num0 = sample_data0.data.us_sample_idx - smus_sample_read_index0;
+        }
+        else
+        {
+            us_adc_dot_num0 = (sample_data0.data.us_sample_idx + TC_ADC_DOTS_PER_CHANNEL) - smus_sample_read_index0;
+        }
+		// printf("us_adc_dot_num0:%d\n", us_adc_dot_num0);
+
+		uint16_t us_adc_dot_num1 = 0;
+        if (sample_data1.data.us_sample_idx > smus_sample_read_index1)
+        {
+            us_adc_dot_num1 = sample_data1.data.us_sample_idx - smus_sample_read_index1;
+        }
+        else
+        {
+            us_adc_dot_num1 = (sample_data1.data.us_sample_idx + TC_ADC_DOTS_PER_CHANNEL) - smus_sample_read_index1;
+        }
+		// printf("us_adc_dot_num1:%d\n\n", us_adc_dot_num1);
+
+		// us_adc_dot_num0 与 us_adc_dot_num1的数量一般相同
+        for (uint16_t i = 0; i < us_adc_dot_num0; i++)
+        {
+			/* 注意采样下标索引不能超过采样缓存 TC_ADC_DOTS_PER_CHANNEL  */
+            uint16_t us_adc_dot_index0 = (smus_sample_read_index0 + i) % TC_ADC_DOTS_PER_CHANNEL;
+			uint16_t us_adc_dot_index1 = (smus_sample_read_index1 + i) % TC_ADC_DOTS_PER_CHANNEL;
+			
+			// test zhl
+			// int32_t physical_value0 = (int16_t)(sample_data0.data.usa_sample_dots[9][us_adc_dot_index0]);
+			// printf("%d, ", physical_value0);
+			// int32_t physical_value1 = (int16_t)(sample_data1.data.usa_sample_dots[1][us_adc_dot_index1]);
+			// printf("%d, ", physical_value1);
+
+			updata_adc(&sample_data0, us_adc_dot_index0, &sample_data1, us_adc_dot_index1);
+		}
+
+		smus_sample_read_index0 = (smus_sample_read_index0 + us_adc_dot_num0) % TC_ADC_DOTS_PER_CHANNEL;
+		smus_sample_read_index1 = (smus_sample_read_index1 + us_adc_dot_num1) % TC_ADC_DOTS_PER_CHANNEL;
+    }
+
+	return 0;
+}
+
 /******************************************************************************
 函数名称:	adc_slot_is_ok
 函数版本:	01.01

+ 213 - 0
app_public/fuxi_public/fuxi_bsp/source/aht20.c

@@ -0,0 +1,213 @@
+/******************************************************************************
+版权所有:	
+文件名称:	aht20.c
+文件版本:	01.01
+创建作者:	Ewen
+创建日期:	2025-11-10
+功能说明:	aht20驱动程序。
+其它说明:
+修改记录:
+
+/*------------------------------ 头文件 ---------------------------------------
+*/
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/i2c.h>
+#include <linux/i2c-dev.h>
+#include <errno.h>
+#include "head.h"
+
+#ifdef TMP_CHIP_AHT20
+/*------------------------------ 宏定义 ---------------------------------------
+*/
+
+#define I2C_DEV         "/dev/i2c-5"
+// 以下定义见AHT20 datasheet
+// AHT20 设备地址
+#define AHT20_I2C_ADDR  0x38
+
+// AHT20 命令字
+#define AHT20_CMD_INIT  0xBE
+#define AHT20_CMD_MEAS  0xAC
+#define AHT20_CMD_RESET 0xBA
+
+/*------------------------------ 全局变量 -------------------------------------
+*/
+struct aht20 aht20;
+
+int g_aht20_fd;
+
+/*------------------------------ 函数声明 -------------------------------------
+*/
+
+// AHT20 初始化
+static int _aht20_init(int fd) {
+    uint8_t init_cmd[3] = {AHT20_CMD_INIT, 0x08, 0x00};
+    
+    if (write(fd, init_cmd, sizeof(init_cmd)) != sizeof(init_cmd)) 
+    {
+        printf("Failed to send init command: %s\n", strerror(errno));
+
+        return -1;
+    }
+    
+    return 0;
+}
+
+// AHT20 软复位
+static int _aht20_soft_reset(int fd) {
+    uint8_t reset_cmd = AHT20_CMD_RESET;
+    
+    if (write(fd, &reset_cmd, sizeof(reset_cmd)) != sizeof(reset_cmd)) 
+    {
+        printf("Failed to send reset command: %s\n", strerror(errno));
+        return -1;
+    }
+    
+    return 0;
+}
+
+// 读取温湿度数据
+static int _aht20_read_data(int fd, float* temperature, float* humidity) 
+{
+    uint8_t cmd[3] = {AHT20_CMD_MEAS, 0x33, 0x00};
+    uint8_t data[6] = {0};
+    uint32_t temp_raw = 0, humi_raw = 0;
+    
+    // 发送测量命令
+    if (write(fd, cmd, sizeof(cmd)) != sizeof(cmd)) {
+        printf("Failed to send measure command: %s\n", strerror(errno));
+
+        return -1;
+    }
+    
+    // 等待测量完成(最多100ms)
+    int timeout = 0;
+    while (timeout < 100) {
+        msleep(1);
+        if (read(fd, data, 1) == 1) {
+            if (!(data[0] & 0x80)) {  // 检查忙标志位
+                break;
+            }
+        }
+        timeout++;
+    }
+    
+    if (timeout >= 100) {
+        printf("AHT20 measurement timeout\r\n");
+        return -1;
+    }
+    
+    // 读取测量数据
+    if (read(fd, data, sizeof(data)) != sizeof(data)) {
+        printf("Failed to read measurement data: %s\r\n", strerror(errno));
+
+        return -1;
+    }
+    
+    // 检查数据状态位
+    if ((data[0] & 0x68) != 0x08) {
+        printf("AHT20 data not ready or invalid\r\n");
+        return -1;
+    }
+    
+    // 解析湿度数据(20位)
+    humi_raw = ((uint32_t)data[1] << 12) | 
+               ((uint32_t)data[2] << 4) | 
+               ((uint32_t)data[3] >> 4);
+    
+    // 解析温度数据(20位)
+    temp_raw = (((uint32_t)data[3] & 0x0F) << 16) | 
+               ((uint32_t)data[4] << 8) | 
+               data[5];
+    
+    // 转换为实际值
+    *humidity = (float)humi_raw * 100.0 / (1 << 20);
+    *temperature = (float)temp_raw * 200.0 / (1 << 20) - 50.0;
+    
+    return 0;
+}
+
+int aht20_init(void)
+{
+    memset(&aht20, 0, sizeof(aht20));
+
+    // 打开I2C设备
+    g_aht20_fd = open(I2C_DEV, O_RDWR);
+    if (g_aht20_fd < 0) {
+        printf("Failed to open I2C device %s: %s\n", I2C_DEV, strerror(errno));
+
+        return -1;
+    }
+
+    // 设置从设备地址
+    if (ioctl(g_aht20_fd, I2C_SLAVE, AHT20_I2C_ADDR) < 0) {
+        printf("Failed to set I2C slave address: %s\n", strerror(errno));
+        close(g_aht20_fd);
+
+        return -1;
+    }
+
+    _aht20_soft_reset(g_aht20_fd);
+    msleep(100);
+
+    if(_aht20_init(g_aht20_fd) == 0)
+    {
+        printf("aht20 init success!\r\n");
+    }
+    else
+    {
+        printf("aht20 init failed!\r\n");
+        close(g_aht20_fd);
+        g_aht20_fd = -1;
+
+        return -1;
+    }
+
+    aht20.us0 = bsp_ustimer_get_origin();
+
+    return 0;
+}
+
+int aht20_exit(void)
+{
+    if(g_aht20_fd >= 0)
+    {
+        close(g_aht20_fd);
+        g_aht20_fd = -1;
+    }
+
+    return 0;
+}
+
+
+void aht20_task(void)
+{
+    if(bsp_ustimer_get_duration(aht20.us0) < USTIMER_SEC*5 || g_aht20_fd < 0)
+    {
+        return;
+    }
+
+    aht20.us0 = bsp_ustimer_get_origin();
+    _aht20_read_data(g_aht20_fd, &aht20.temp, &aht20.humi);
+    // printf("aht20.temp=%.3f ℃, aht20.humi=%.3f %%RH\r\n", aht20.temp, aht20.humi);
+}
+
+float aht20_get_temp(void)
+{
+    if(g_aht20_fd < 0)
+    {
+        // 校准系数判断 温度低于-85℃时为异常状态,温度补偿系数默认改为1.0,
+        // 因此此处在初始化失败时返回-100.0℃
+        return -100.0;
+    }
+
+    return aht20.temp;
+}
+
+float aht20_get_humi(void)
+{
+    return aht20.humi;
+}
+
+#endif /* TMP_CHIP_AHT20 */

+ 10 - 5
app_public/fuxi_public/fuxi_bsp/source/bsp.c

@@ -25,8 +25,8 @@ struct init_t  g_bsp_init_func[]=
 	{ccu_init,ERR_CODE_INIT_SOFTWARE},	//初始化系统时钟CCU
 	{bsp_ustimer_init,ERR_CODE_INIT_SOFTWARE},	//初始化内核USTIMER
 	{ustimer_init,ERR_CODE_INIT_SOFTWARE},	//初始化USTIMER
-	{shm_init,ERR_CODE_INIT_SOFTWARE},	//初始化shm
-	{mb_init,ERR_CODE_INIT_SOFTWARE},	//初始化mb
+	// {shm_init,ERR_CODE_INIT_SOFTWARE},	//初始化shm
+	// {mb_init,ERR_CODE_INIT_SOFTWARE},	//初始化mb
 	{watchdog_init,ERR_CODE_INIT_SOFTWARE},	//初始化watchdog
 	{gpio_init,ERR_CODE_INIT_SOFTWARE},		//初始化GPIO
 	{i2c_init,ERR_CODE_INIT_SOFTWARE},		//初始化I2C模块
@@ -38,8 +38,11 @@ struct init_t  g_bsp_init_func[]=
 //	{mac_init,ERR_CODE_INIT_SOFTWARE},		//初始化MAC模块
 	{e2prom_init,ERR_CODE_INIT_E2PROM},		//初始化E2PROM模块
 #ifdef BSP_CAN_ENABLE
-	// {can_init,ERR_CODE_INIT_SOFTWARE},		//初始化CAN模块
-	// {can_app_init,ERR_CODE_INIT_SOFTWARE},	//初始化CAN_APP模块	
+	{can_init,ERR_CODE_INIT_SOFTWARE},		//初始化CAN模块
+	{can_app_init,ERR_CODE_INIT_SOFTWARE},	//初始化CAN_APP模块	
+#endif
+#ifdef TMP_CHIP_AHT20
+	{aht20_init,ERR_CODE_INIT_SOFTWARE},	//初始化温湿度传感器 TODO增加初始化错误代码
 #endif
 //	{uart_init,ERR_CODE_INIT_SOFTWARE},		//初始化UART模块,无需集中初始化,使用时再初始化,防止和通讯子站软件冲突
 //	{pit_init,ERR_CODE_UNKOWN}				//初始化PIT(可编程中断定时器)
@@ -64,7 +67,9 @@ INIT_FUNC g_bsp_exit_func[]=
 	can_app_exit,
 	can_exit,
 #endif
-
+#ifdef TMP_CHIP_AHT20
+	aht20_exit,
+#endif
 //	freq_exit,
 //	adc_exit,
 	gpio_exit,

+ 8 - 7
app_public/fuxi_public/fuxi_bsp/source/equ_dtu.c

@@ -34,11 +34,10 @@ struct board_info_frame
 */
 
 // 采样板硬件通道和ADC采样通道的对应关系
-// TODO EWen 实际对应关系还需确认,此定义为DTU4中的定义
 static const u8 g_adc_channel_index[EQU_SLOT_NUM_MAX][16] = 
 {
-	{0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF}, // 0
-	{0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF}, // 1
+	{0x09,0x0B,0x0D,0x0F,0x08,0x0A,0x0C,0x0E,0x00,0x02,0x04,0x06,0x11,0x13,0x15,0x17},	// DTUv5 采样板卡1
+	{0x19,0x1B,0x1D,0x1F,0x18,0x1A,0x1C,0x1E,0x10,0x12,0x14,0x16,0x01,0x03,0x05,0x07},	// DTUv5 采样板卡2 最后 1357通道因实际硬件没有接入所以排最后,没有用到
 	{0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF}, // 2
 	{0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF}, // 3
 	{0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF}, // 4
@@ -86,7 +85,7 @@ int equ_init_later(void)
 	{
 		// g_ac_slot_begin = EQU_SLOT_AC_BEGIN12;
         // 16回路需处理,开始做再说...
-        rt_printf("%s 未处理的卡槽数量与采样板其实卡槽!\r\n", __func__);
+        rt_printf("%s 未处理的卡槽数量与采样板起始卡槽!\r\n", __func__);
 	}
 
 	// 检查频率硬件通道对应的UI。
@@ -108,13 +107,15 @@ int equ_init_later(void)
 		
 		// 确定频率对应电压通道
         // EWen TODO DTUv5 暂时定义通道配置板卡1通道1为频率对应通道后面根据ADC数据对接再最终定义
+		// 测频放到了R核
 		if(	g_equ_config->equ_slot_num == EQU_SLOT_NUM_06 && ui < PUB_AC_NUM)
 		{
-			if(g_equ_config_ac[i].slot == 1 && g_equ_config_ac[i].index == 0)
+			if(g_equ_config_ac[i].slot == 0 && g_equ_config_ac[i].index == 0)
 			{
 				g_ui_freq[0] = ui;
 			}
-			if(g_equ_config_ac[i].slot == 2 && g_equ_config_ac[i].index == 0)
+			// 标准化只采了一路电压
+			if(g_equ_config_ac[i].slot == 1 && g_equ_config_ac[i].index == 0)
 			{
 				g_ui_freq[1] = ui;
 			}
@@ -189,7 +190,7 @@ int equ_board_info_update(int can_bus,u8 * frame)
 	bif = (struct board_info_frame *)(frame + sizeof(struct can_frame_head));//(frame + sizeof(cfh));
 	if(bif->type != bi->type)
 	{
-		rt_printf("board type error(no=%d,bi_type=%d,gbi_type=%d)\r\n",cfh->src,bif->type,bi->type);
+		//rt_printf("board type error(no=%d,bi_type=%d,gbi_type=%d)\r\n",cfh->src,bif->type,bi->type);
 		// print_mem("frame",frame,16);
 		return -3;
 	}

+ 3 - 2
app_public/fuxi_public/fuxi_bsp/source/factor.c

@@ -28,8 +28,9 @@
 #define SCALE_PT_120K		(1.032*32768/2.5*1.4142)	//153K
 #define SCALE_PT_150K		(1.0348*32768/2.5*1.4142)	//  开普测试,测量范围264 增加了电阻
 #define SCALE_PT_172K		(0.916*32768/2.5*1.4142)	// 加264V相电压二次用万用表测有效值为0.916v
-#define SCALE_PT_204K		(0.513*32768/2.5*1.4142)	// 次级电阻200k  最终版本
-
+// #define SCALE_PT_204K		(0.513*32768/2.5*1.4142)	// 次级电阻200k  最终版本
+// DTUv5与DTUv4同样硬件,系数一样
+#define SCALE_PT_204K		(0.1105*32768/2.5*1.4142)	// 加264V相电压二次用万用表测有效值为0.063v		初级241KΩ次级100Ω
 // 使用次级电阻标识
 #define SCALE_CT_100A_51	(2.526*32768/5.0*1.4142)	// 次级电阻51欧,,加5A相电流二次用万用表测有效值为0.127V
 #define SCALE_CT_10A_51	(0.254*32768/2.5*1.4142)	// 次级电阻51欧,加10A相电流二次用万用表测有效值为0.254V

+ 4 - 2
app_public/fuxi_public/fuxi_bsp/source/flexcan.c

@@ -382,7 +382,9 @@ static void *can_proc_send(void *arg)
 		default:
 		break;
 		}
-		usleep(10);
+		// xenomai内核中此处usleep(10)创建第二个线程会出问题
+		// 延时太短导致CPU占用?改为1ms就正常了需验证动作时间 
+		usleep(1000);
 	}
 
 }
@@ -984,7 +986,7 @@ static int _can_set_bittiming(struct can_dev *dev)
 
 	/* 配置波特率为1M */
 	memset(cmd_buf, 0, sizeof(cmd_buf));
-	sprintf(cmd_buf, "ip link set can%d type can bitrate %d loopback off restart-ms %d", dev->no, 1000000, 10);
+	sprintf(cmd_buf, "ip link set can%d type can bitrate %d loopback off restart-ms %d", dev->no, 1000000, 100);
 	system(cmd_buf);
 
 	/* 启动can设备 */

+ 8 - 5
app_public/fuxi_public/fuxi_bsp/source/freq.c

@@ -71,7 +71,7 @@ int freq_exit(void)
 
 static int get_shm_f(uint8_t *out_data)
 {
-    SHM_F_T sample;
+    struct t_shmdata_freq sample;
 	int ret = 0;
 	int cnt = 0;
 
@@ -80,7 +80,7 @@ static int get_shm_f(uint8_t *out_data)
 		
     while(1)
     {
-		ret = shm_comm_packet_read(SHM_ADDR_U_FREQ, sizeof(sample), out_data, sizeof(sample));
+		ret = shm_packet_read_v2(SHM_ADDR_W_FREQ, sizeof(sample), out_data, sizeof(sample));
 		if(ret > 0)	
 		{
 			break;
@@ -108,7 +108,7 @@ float freq_get(unsigned int index)
 {
 	u32 e;
 	float 	freq = 50.0;
-	SHM_F_T shm_f;
+	struct t_shmdata_freq shm_f;
 	int ret = 0;
 	
 #ifdef DTIM_FREQ_DEBUG //added by sunxi: for FUXI
@@ -145,13 +145,16 @@ float freq_get(unsigned int index)
 
 	//从共享内存中读取频率到freq
 	ret = get_shm_f((uint8_t *)&shm_f);
+	// printf("ret=%d, us_updata=%u, us_op=%u, us_op_bk=%u, freq0=%u, freq0=%u, crc=%u\n\n",
+	// 	ret, shm_f.us_updata, shm_f.us_op, shm_f.us_op_bk, shm_f.us_freq[0], shm_f.us_freq[1], shm_f.us_crc);
+
 	if(ret < 0)
 		return 0.0;
 
-	freq = (float)shm_f.freq[index]/1000;
+	freq = (float)shm_f.us_freq[index]/1000;
 
 #ifdef DTIM_FREQ_DEBUG
-	rt_stat_in(&g_stat_freq[index],rt_round(shm_f.freq[index]*Q16_BASE));
+	rt_stat_in(&g_stat_freq[index],rt_round(shm_f.us_freq[index]*Q16_BASE));
 #endif
 	
 	//将频率范围限定在45hz到55hz。

+ 20 - 8
app_public/fuxi_public/fuxi_bsp/source/gpio.c

@@ -601,24 +601,36 @@ unsigned int gpio_get_addr(void)
 
 void _led_run_err(void)
 {
-	//运行指示灯,每隔0.5s改变状态一次
-	if(!gpio_run_led_val)
+	static bool berr_led = false;
+	
+	if(rt_err_count())
 	{
-		gpio_run_led_val = 1;
-		write(gpio_val_fd_other[RUN_LED], "0", 2);
-
-		//错误指示灯,跟随RUN灯闪动
-		if(rt_err_count())
+		//错误指示灯常亮且运行熄灭
+		if(!berr_led)
 		{
+			berr_led = false;
 			write(gpio_val_fd_other[ERR_LED], "0", 2);
+			write(gpio_val_fd_other[RUN_LED], "1", 2);
 		}
+		return;
+	}
 
+	if(berr_led)
+	{
+		berr_led = false;
+		write(gpio_val_fd_other[ERR_LED], "1", 2);
+	}
+
+	//运行指示灯,每隔1s改变状态一次
+	if(!gpio_run_led_val)
+	{
+		gpio_run_led_val = 1;
+		write(gpio_val_fd_other[RUN_LED], "0", 2);
 	}
 	else
 	{
 		gpio_run_led_val = 0;
 		write(gpio_val_fd_other[RUN_LED], "1", 2);
-		write(gpio_val_fd_other[ERR_LED], "1", 2);
 	}
 }
 

+ 1 - 7
app_public/fuxi_public/fuxi_bsp/source/led_ftu.c

@@ -16,14 +16,8 @@
 /*------------------------------- 宏定义 --------------------------------------
 */
 #define LED_NULL	(-1)
-#define EWEN_TEST //临时测试用
-#ifndef EWEN_TEST
 #define QUICK_FLASH	20		// 5Hz, 亮100ms,灭100ms。5ms一次,20次为100ms
-#define SLOW_FLASH	100		// 1Hz, 亮0.5s,灭0.5s
-#else
-#define QUICK_FLASH	100		// 5Hz, 亮100ms,灭100ms。5ms一次,20次为100ms
-#define SLOW_FLASH	500		// 1Hz, 亮0.5s,灭0.5s
-#endif
+#define SLOW_FLASH	200		// 间隔1s闪烁
 /*------------------------------ 类型结构 -------------------------------------
 */
 // 开出类型灯控制结构体

+ 299 - 0
app_public/fuxi_public/fuxi_bsp/source/shmem.c

@@ -0,0 +1,299 @@
+/**shmem.c*/
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "shmem.h"
+
+uint8_t *mlinux_shm_base_w;
+uint8_t *mlinux_shm_base_r;
+int linux_write_len, linux_read_len;
+
+/* CRC-16 表 */
+const static unsigned short Lookup_crc_16[256] = {
+	0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
+	0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
+	0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
+	0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
+	0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
+	0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
+	0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
+	0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
+	0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
+	0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
+	0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
+	0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
+	0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
+	0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
+	0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
+	0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
+	0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
+	0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
+	0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
+	0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
+	0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
+	0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
+	0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
+	0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
+	0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
+	0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
+	0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
+	0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
+	0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
+	0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
+	0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
+	0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040};
+
+static unsigned short crc16(unsigned char *p, int len)
+{
+	unsigned short crc = 0;
+	int zero = 1;
+
+	if (len <= 0)
+		return crc;
+
+	while (len-- > 0)
+	{
+		if (*p != 0)
+			zero = 0;
+		crc = Lookup_crc_16[(crc & 0xff) ^ (*p++)] ^ (crc >> 8);
+	}
+
+	if (zero)
+		crc = 0x5678; /* 若全为0,crc返回就不要为零 */
+	return crc;
+}
+
+
+int shm_write_data(uint32_t _ul_addr, uint8_t *_puc_data, uint32_t _ul_len)
+{
+	int i = 0;
+
+	if (mlinux_shm_base_w == NULL)
+		return -1;
+
+	if (_puc_data == NULL)
+		return -1;
+	if (_ul_len == 0)
+		return -1;
+
+	for (i = 0; i < _ul_len; i++)
+	{
+		if ((_ul_addr + i) >= linux_write_len)
+			return -1;
+
+		mlinux_shm_base_w[_ul_addr + i] = _puc_data[i];
+	}
+
+	return i;
+}
+
+int shm_packet_write_v2(uint32_t _ul_addr, uint8_t *_puc_data, uint32_t _ul_len)
+{
+	uint16_t us_updata = 0, us_data_a = 0, us_crc = 0;
+	int ret = 0;
+
+	if (_puc_data == NULL || _ul_len == 0)
+		return -1;
+
+	memcpy(&us_data_a, &mlinux_shm_base_w[_ul_addr + 2], 2);
+	us_data_a++;
+	memcpy(&mlinux_shm_base_w[_ul_addr + 2], &us_data_a, 2);
+
+	/* 写数据区 */
+	ret = shm_write_data(_ul_addr + 6, _puc_data + 6, _ul_len - 8);
+	if (ret == -1)
+		return -2;
+
+	/* crc */
+	us_crc = crc16(_puc_data + 6, _ul_len - 8);
+	memcpy(&mlinux_shm_base_w[_ul_addr + _ul_len - 2], &us_crc, 2);
+	// printf("cal us_crc = %04x\n", us_crc);
+
+#if (1)
+	// for (int i = 0; i < _ul_len + 6; i++)
+	// {
+	//     printf("data[%d]=%04x, ", i, *(_puc_data + i+ 6));
+	// }
+	for (int i = 0; i < _ul_len; i++)
+	{
+		printf("wbuf[%d]=0x%02x, ", i, *(mlinux_shm_base_w + _ul_addr + i));
+	}
+	printf("\n");
+#endif
+
+	memcpy(&mlinux_shm_base_w[_ul_addr + 4], &us_data_a, 2); // us_data_a和us_data_b保证一样
+	us_updata = 1;
+	memcpy(&mlinux_shm_base_w[_ul_addr], &us_updata, 2); // 数据更新
+
+	for (int i = 0; i < _ul_len; i++) // zhl add TODO
+		((uint8_t *)_puc_data)[i] = *(mlinux_shm_base_w + _ul_addr + i);
+
+	/* 加上us_data_a, us_data_b, crc的长度 */
+	return ret + 6;
+}
+
+/**
+ * @brief          读取共享内存的数据
+ * @version        1.0
+ * @param[in/out]  {uint32_t} _ul_addr 读取共享内存的地址
+ * @param[in/out]  {uint32_t} _ul_len 需要读取的数据长度
+ * @param[in/out]  {uint8_t *} _puc_data_out 输出buf
+ * @param[in/out]  {uint32_t} _uc_data_out_size 输出buf的长度
+ * @return         int
+ * @retval         成功返回读取数据的长度, 失败返回-1
+ *
+ * @warning        none
+ * @note           none
+ */
+int shm_read_data(uint32_t _ul_addr, uint32_t _ul_len, uint8_t *_puc_data_out, uint32_t _uc_data_out_size)
+{
+	int i = 0;
+	if (mlinux_shm_base_r == NULL)
+		return -1;
+
+	if (_puc_data_out == NULL)
+		return -2;
+
+	if ((_ul_len == 0) || (_uc_data_out_size == 0))
+		return -3;
+
+	for (i = 0; i < _ul_len; i++)
+	{
+		if ((_ul_addr + i) >= linux_read_len)
+			return -4;
+
+		if (i >= _uc_data_out_size)
+			return -5;
+
+		_puc_data_out[i] = mlinux_shm_base_r[_ul_addr + i];
+	}
+
+	return i;
+}
+
+/**
+ * @brief          读取共享内存的数据(自动处理us_data_a, us_data_b, crc).
+ * @version        1.0
+ * @param[in/out]  {uint32_t} _ul_addr 读取共享内存的地址
+ * @param[in/out]  {uint32_t} _ul_len 需要读取数据的长度
+ * @param[in/out]  {uint8_t *} _puc_data_out 输出buf
+ * @param[in/out]  {uint32_t} _uc_data_out_size 输出buf的长度
+ * @return         * int
+ * @retval         成功返回读取数据的长度 失败返回 < 0
+ *
+ * @warning        none
+ * @note           输入参数data为带有us_data_a, us_data_b和crc的结构体,len为整个结构体的长度
+ * @note           应用层不需要理会us_data_a, us_data_b和crc
+ */
+int shm_packet_read_v2(uint32_t _ul_addr, uint32_t _ul_len, uint8_t *_puc_data_out, uint32_t _uc_data_out_size)
+{
+	uint16_t us_updata = 0, us_data_a = 0, us_data_b = 0;
+	uint16_t us_crc = 0, read_crc = 0;
+	int ret = 0;
+	ret = shm_read_data(_ul_addr, _ul_len, _puc_data_out, _uc_data_out_size);
+	
+#if (0)
+	// for (int i = 0; i < _ul_len + 6; i++)
+	// {
+	//     printf("data[%d]=%04x, ", i, *(_puc_data + i+ 6));
+	// }
+	// printf("(mlinux_shm_base_r +_ul_addr:%X)->p: 0x%llX\n", _ul_addr, mlinux_shm_base_r + _ul_addr);
+	for (int i = 0; i < _ul_len; i++)
+	{
+		printf("rbuf[%d]=0x%02x, ", i, *(mlinux_shm_base_r + _ul_addr + i));
+	}
+	printf("\n\n");
+#endif
+
+	/* 没有数据更新 */
+	us_updata = _puc_data_out[0] + ((uint16_t)_puc_data_out[1] << 8);
+	if (0 == us_updata)
+		return -1;
+
+	us_data_a = _puc_data_out[2] + ((uint16_t)_puc_data_out[3] << 8);
+	us_data_b = _puc_data_out[4] + ((uint16_t)_puc_data_out[5] << 8);
+
+	/* 是否有在进行读写 */ //TODO 暂时注释
+	if ((us_data_a == us_data_b))
+	{
+		/* 在拷贝过程中,数据没有被修改 */
+		us_crc = crc16(_puc_data_out + 6, _ul_len - 8);
+		read_crc = _puc_data_out[_ul_len - 2] + ((uint16_t)_puc_data_out[_ul_len - 1] << 8);
+		// printf("cal us_crc = %04x, read us_crc = %04x\n", us_crc, read_crc);
+		if (us_crc != read_crc)
+		{
+			return -2;
+		}
+	}
+	else
+	{
+		return -3;
+	}
+
+	us_updata = 0;
+	memcpy(&mlinux_shm_base_r[_ul_addr], &us_updata, 2); // 数据读取完成
+
+	return ret;
+}
+
+#define ARV_SHMEM_REGION_LEN 0x10
+int share_mem_init_v2(struct shmem_fd *shmem_fd)
+{
+	int fd;
+	void *shmem;
+	int ret;
+
+	fd = open("/dev/arv-shmem", O_RDWR);
+	if (fd == -1)
+	{
+		printf("can not open file /dev/arv-shmem\n");
+		return -1;
+	}
+
+	ret = ioctl(fd, ARV_SHMEM_REGION_LEN, &shmem_fd->shmem_len);
+	if (ret)
+	{
+		printf("failed to get the len of shmem\n");
+		return -1;
+	}
+	printf("shmem len: 0x%x\n", shmem_fd->shmem_len);
+
+	shmem_fd->linux_write_len = max_shmem_wr_len(shmem_fd->shmem_len);
+	shmem_fd->linux_read_len = max_shmem_rd_len(shmem_fd->shmem_len);
+
+	shmem = mmap(NULL, shmem_fd->shmem_len, PROT_READ | PROT_WRITE,
+				 MAP_SHARED, fd, 0);
+	if (shmem <= 0)
+	{
+		printf("failed to get shmem\n");
+		return -1;
+	}
+	printf("mmap: 0x%llx\n", (unsigned long long)shmem);
+
+	shmem_fd->fd = fd;
+	shmem_fd->linux_write = (uint8_t *)shmem;
+	shmem_fd->linux_read = (uint8_t *)(shmem + shmem_fd->linux_write_len);
+	printf("shmem_fd->linux_write->p: 0x%llX, linux_write_len: %d\n", shmem_fd->linux_write, shmem_fd->linux_write_len);
+	printf("shmem_fd->linux_read->p: 0x%llX, linux_read_len: %d\n", shmem_fd->linux_read, shmem_fd->linux_read_len);
+
+	mlinux_shm_base_w = (uint8_t *)(shmem_fd->linux_write); // 共享内存---写(向R核写入数据)---开始地址
+	mlinux_shm_base_r = (uint8_t *)(shmem_fd->linux_read); // 共享内存---读(从R核读取数据)---开始地址
+	linux_write_len = shmem_fd->linux_write_len;
+	linux_read_len = shmem_fd->linux_read_len;
+
+	return 0;
+}
+
+void share_mem_exit_v2(struct shmem_fd *shmem_fd)
+{
+	munmap(shmem_fd->linux_write, shmem_fd->shmem_len);
+	close(shmem_fd->fd);
+}

+ 1 - 1
app_public/fuxi_public/fuxi_bsp/source/watchdog.c

@@ -258,7 +258,7 @@ static int write_freq_hb(uint8_t *data)
 		
     while(1)
     {
-    	ret = shm_comm_packet_write(SHM_ADDR_D_HB, data, sizeof(HB_T));
+    	// ret = shm_comm_packet_write(SHM_ADDR_D_HB, data, sizeof(HB_T));
 		if(ret > 0)	
 		{
 			break;

+ 3 - 3
app_public/fuxi_public/rt_lite/include/rt.h

@@ -76,9 +76,9 @@ int rt_exit(void);
 
 //#define rt_printf			printf
 #define sys_newstat 		stat
-// clock_gettime通过CLOCK_REALTIME获取的时间是UTC+0 的时间戳,要将其转为UTC+8
-#define clk_time_get(ts)	clock_gettime(CLOCK_REALTIME, ts); ((struct timespec*)(ts))->tv_sec += 8*60*60;
-// #define clk_time_get(ts)	clock_gettime(CLOCK_REALTIME, ts);
+
+// #define clk_time_get(ts)	clock_gettime(CLOCK_REALTIME, ts); ((struct timespec*)(ts))->tv_sec += 8*60*60;
+#define clk_time_get(ts)	clock_gettime(CLOCK_REALTIME, ts);
 
 #define rt_save_flags(x) do{}while(0)
 #define rt_irq_disable() do{}while(0)

+ 8 - 7
app_public/fuxi_public/rt_lite/source/rt_error.c

@@ -21,13 +21,14 @@
 
 
 // sunxi 20200817 added start
-#define BYTES_PER_LONG		sizeof(long)
-#define BITS_PER_LONG		(BYTES_PER_LONG*8)
-#define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
+// 64位架构上long为8字节会导致上位机获取故障信息错位此处改为int
+#define BYTES_PER_INT		sizeof(int)
+#define BITS_PER_INT		(BYTES_PER_INT*8)
+#define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_INT))
+#define BIT_WORD(nr)		((nr) / BITS_PER_INT)
 
 #define DIV_ROUND_UP(n, d) 		(((n) + (d) - 1) / (d))
-#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, 8 * sizeof(long))
+#define BITS_TO_INTS(nr)	DIV_ROUND_UP(nr, 8 * sizeof(int))
 
 static inline int test_and_set_bit(int nr, uint32_t *addr)
 {
@@ -51,7 +52,7 @@ static inline int test_and_clear_bit(int nr, uint32_t *addr)
 
 static inline int test_bit(int nr, const volatile uint32_t *addr)
 {
-	return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
+	return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_INT-1)));
 }
 // sunxi 20200817 added end
 
@@ -196,7 +197,7 @@ struct err_t g_err_entxt[] =
 atomic_uint g_err_cnt_hw; // 硬件错误计数
 atomic_uint g_err_cnt_sw; // 软件错误计数
 
-uint32_t  g_err_bit[BITS_TO_LONGS(ERR_CODE_NUM)];
+uint32_t  g_err_bit[BITS_TO_INTS(ERR_CODE_NUM)];
 
 #if 0 // sunxi 20180730 类型不正确
 int g_err_arg[ERR_CODE_NUM];

+ 146 - 0
dtu/dtu_main_t536/app/Appconfig.c

@@ -49,6 +49,9 @@ struct unit g_unit[UNIT_NUM] =
 	{"mΩ", 	1, 		0},			// UINT_mΩ
 	{"mA", 	1,		0}, 		// UINT_mA
 #endif
+#ifdef TMP_CHIP_AHT20
+	{"%RH",100,	0},			// UNIT_HUMI
+#endif
 };
  
 
@@ -138,7 +141,146 @@ const SOE_DEF tAllSOE[]=
 /*    代码         类型          参数1    参数2    参数3        名称            */
 /*保护专用事件*/
 	// 开关事件
+#ifdef GW_AREA_MAIN_2021
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流I段动作"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流I段动作"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流I段动作"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流I段动作"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流I段告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流I段告警"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流I段告警"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流I段告警"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流II段动作"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流II段动作"},
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流II段动作"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流II段动作"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流II段告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流II段告警"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流II段告警"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流II段告警"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流III段动作"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流III段动作"},
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流III段动作"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流III段动作"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流III段告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流III段告警"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流III段告警"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流III段告警"},
+	{0x84,		{EV_PARA_Ia,	EV_PARA_Ib,	EV_PARA_Ic},	"短路故障跳闸"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"A相短路跳闸"},
+	{0x0,		{EV_PARA_Ib,	0,			0},				"B相短路跳闸"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"C相短路跳闸"},
+	{0x84,		{EV_PARA_Ia,	EV_PARA_Ib,	EV_PARA_Ic},	"短路故障告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"A相短路告警"},
+	{0x0,		{EV_PARA_Ib,	0,			0},				"B相短路告警"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"C相短路告警"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"小电流接地启动"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"小电流接地动作"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"小电流接地告警"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序I段动作"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序I段告警"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序II段动作"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序II段告警"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序III段动作"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序III段告警"},
+	{0x84,		{EV_PARA_I0,	0,			0},				"零流跳闸"},
+	{0x84,		{EV_PARA_I0,	0,			0},				"零流告警"},
+	{0x05,		{EV_PARA_U0,	0,			0},				"零压跳闸"},
+	{0x05,		{EV_PARA_U0,	0,			0},				"零压告警"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"过流加速动作"},	
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过流加速"},
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过流加速"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过流加速"},
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"零序加速动作"},
+	{0x84,		{EV_PARA_U0,	0,			0},				"零压加速动作"},	
+	{0x00,		{0,				0,			0},				"重合闸启动"},
+	{0x04,		{0,				0,			0},				"一次重合动作"},
+	{0x04,		{0,				0,			0},				"二次重合动作"},
+	{0x04,		{0,				0,			0},				"三次重合动作"},
+	{0x84,		{EV_PARA_Us1,	EV_PARA_Us2,0},				"失压分闸"},
+	{0x84,		{0,				0,			0},				"闭锁失压分闸"},	
+	{0x84,		{EV_PARA_Us1,	EV_PARA_Us2,0},				"上电合闸"},
+	{0x84,		{EV_PARA_Us1,	EV_PARA_Us2,0},				"联络合闸"},
+	{0x84,		{EV_PARA_U0,	0,			0},				"合后接地跳闸"},	
+	{0x84,		{EV_PARA_U0,	0,			0},				"接地选线跳闸"},	
+	{0x84,		{0,				0,			0},				"闭锁合闸"},
+	{0x84,		{0,				0,			0},				"电源侧X闭锁"},
+	{0x84,		{0,				0,			0},				"负荷侧X闭锁"},
+	{0x84,		{0,				0,			0},				"电源侧Y闭锁"},
+	{0x84,		{0,				0,			0},				"负荷侧Y闭锁"},
+	{0x84,		{0,				0,			0},				"电源侧残压闭锁"},
+	{0x84,		{0,				0,			0},				"负荷侧残压闭锁"},
+	{0x84,		{0,				0,			0},				"合后零压闭锁合闸"},
+	{0x84,		{0,				0,			0},				"手动闭锁合闸"},
+	{0x84,		{0,				0,			0},				"双电源闭锁合闸"},
+	{0x04,		{0,				0,			0},				"合后故障"},	
+	{0x84,		{0,				0,			0},				"人工解锁"},
+	{0x84,		{0,				0,			0},				"合闸解锁"},
+	{0x84,		{0,				0,			0},				"单侧来电解锁"},
+	{0x84,		{0,				0,			0},				"联络有压解锁"},
+	{0x04,		{0,				0,			0},				"合环检测"},
+	{0x04,		{0,				0,			0},				"合环合闸"},
+	{0x04,		{0,				0,			0},				"合环闭锁"},	
+	{0x84,		{EV_PARA_Ia,	EV_PARA_Ib,	EV_PARA_Ic},	"遮断电流闭锁"},
+	{0x04,		{0,				0,		0},					"无流分闸"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"电流重载告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia重载告警"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib重载告警"}, 
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic重载告警"}, 
+
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"电流过载告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia过载告警"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib过载告警"}, 
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic过载告警"}, 
+
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"电流越限告警"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"Ia越限告警"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"Ib越限告警"}, 
+	{0x0,		{EV_PARA_Ic,	0,			0},				"Ic越限告警"}, 
+	
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"二次谐波越限"},
+	{0x04,		{0,				0,			0},				"跳闸失败"},
+	{0x04,		{0, 			0,			0}, 			"合闸失败"},
+	{0x04,		{0, 			0,			0}, 			"开关拒动"},
+	{0x04,		{0,				0,			0},				"跳位有流告警"},
+	{0x07,		{PARA_TYPE_YB|EV_PARA_YK,	0,	0},			"开出软压板  "},
+	{0x05,		{0,				0,			0},				"未储能告警"},
+
+	{0x84,		{EV_PARA_I0,	EV_PARA_U0,	0},				"接地故障总"},
+	{0x0,		{EV_PARA_Ia,	0,			0},				"A相接地故障"}, 
+	{0x0,		{EV_PARA_Ib,	0,			0},				"B相接地故障"},
+	{0x0,		{EV_PARA_Ic,	0,			0},				"C相接地故障"},
+
+	{0x00,		{0,				0,			0},				"故障停电"},
+	{0x00,		{0,				0,			0},				"计划停电"},
+	{0x00,		{0,				0,			0},				"恢复供电"},
+
+#if  1 //#if defined(SET_PROFE_ISPECTION)
+	{0x00,		{0,				0,			0},				"控回断线告警"},
+#else
+	{0x00,		{0,				0,			0},				"合闸控回断线"},
+	{0x00,		{0,				0,			0},				"分闸控回断线"},
+#endif
+
+	{0x04,		{EV_PARA_Uab,EV_PARA_Ubc,EV_PARA_Uca},	"PT断线告警"},
+	{0x04,		{EV_PARA_Uab,EV_PARA_Ubc,EV_PARA_Uca},	"PT断线跳闸"},
 
+#if (defined RECORD_SW_U0TB)
+	{0x00,		{0,				0,			0},				"零序电压突变"},
+#endif
+
+	{0x00,		{0,				0,			0},				"集中式FA投入"},
+	{0x00,		{0,				0,			0},				"常规保护投入"},
+	{0x00,		{0,				0,			0},				"间隔事故总"},
+	{0x00,		{0,				0,			0},				"功率方向"},
+	{0x00,		{0,				0,			0},				"故障指示"},
+	{0x00,		{0,				0,			0},				"重合闸充电完成"},
+	{0x00,		{0,				0,			0},				"录波生成成功"},
+	{0x00,		{0,				0,			0},				"二次谐波闭锁"},
+	{0x84,		{EV_PARA_Ia,EV_PARA_Ib,	EV_PARA_Ic},		"CT断线告警"},
+	{0x85,		{0,			0,			0},					"CT相序异常"},
+
+#else
 #ifdef GD_AREA_ECZD_MAOMING
 	{0x84,		{0,			0,					0},				"保护动作总"},
 #else
@@ -826,6 +968,8 @@ const SOE_DEF tAllSOE[]=
 	{0x00,		{0,				0,			0},				"间隔事故总"},
 	{0x04,		{0,				0,			0},				"合环检测"},
 	{0x04,		{0,				0,			0},				"合环闭锁"},	
+#endif
+
 #endif
 	// 公共事件
 
@@ -929,6 +1073,7 @@ const SOE_DEF tAllSOE[]=
 	{0x00,		{0,	0,	0},			"事故总"},
 	{0x04,		{0,			0,			0},					"电池自动活化投退"},
 	{0x04,		{0,			0,			0},					"备用电源投入"},
+#ifndef GW_AREA_MAIN_2021
 	{0x04,		{0,			0,			0},					"非电量1跳闸"},
 	{0x04,		{0,			0,			0},					"非电量2跳闸"},
 	{0x04,		{0,			0,			0},					"非电量3跳闸"},
@@ -945,6 +1090,7 @@ const SOE_DEF tAllSOE[]=
 	{0x04,		{0,			0,			0},					"非电量6告警"},
 	{0x04,		{0,			0,			0},					"非电量7告警"},
 	{0x04,		{0,			0,			0},					"非电量8告警"},
+#endif
 	{0x04,		{0,			0,			0},					"串口1通信异常"},
 	{0x04,		{0,			0,			0},					"串口2通信异常"},
 	{0x04,		{0,			0,			0},					"串口3通信异常"},

+ 154 - 0
dtu/dtu_main_t536/app/Appconfig.h

@@ -111,6 +111,9 @@ enum
 #ifdef BATTERY_BP_L500
 	UINT_mVperA,
 	UINT_mA,
+#endif
+#ifdef TMP_CHIP_AHT20
+	UNIT_HUMI,
 #endif
 	UNIT_NUM
 };
@@ -130,7 +133,157 @@ extern struct unit g_unit[UNIT_NUM];
 
 enum
 {
+#ifdef GW_AREA_MAIN_2021
+	EV_GL1TZ=0,			// 过流1动作
+	EV_GL1ATZ,			// 过流A相
+	EV_GL1BTZ,			// 过流B相
+	EV_GL1CTZ,			// 过流C相
+
+	EV_GL1GJ,			// 过流1告警
+	EV_GL1AGJ,			// 过流1A相告警
+	EV_GL1BGJ,			// 过流1B相告警
+	EV_GL1CGJ,			// 过流1C相告警
+
+
+	EV_GL2TZ,			// 过流2动作
+	EV_GL2ATZ,			// 过流A相
+	EV_GL2BTZ,			// 过流B相
+	EV_GL2CTZ,			// 过流C相
+
+	EV_GL2GJ,			// 过流2告警
+	EV_GL2AGJ,			// 过流2A相告警
+	EV_GL2BGJ,			// 过流2B相告警
+	EV_GL2CGJ,			// 过流2C相告警
+
+	EV_GL3TZ,			// 过流3动作
+	EV_GL3ATZ,			// 过流A相
+	EV_GL3BTZ,			// 过流B相
+	EV_GL3CTZ,			// 过流C相
+
+	EV_GL3GJ,			// 过流3告警
+	EV_GL3AGJ,			// 过流3A相告警
+	EV_GL3BGJ,			// 过流3B相告警
+	EV_GL3CGJ,			// 过流3C相告警
+
+	EV_DL_TZ,			// 短路故障跳闸		
+	EV_ADL_TZ,			// A相短路跳闸
+	EV_BDL_TZ,			// B相短路跳闸
+	EV_CDL_TZ,			// C相短路跳闸
+
+	EV_DL_GZ,			// 短路故障
+	EV_ADL_GZ,			// A相短路告警
+	EV_BDL_GZ,			// B相短路告警
+	EV_CDL_GZ,			// C相短路告警
+	
+	EV_LX_XDL_QD,		// 零序小电流启动		
+	EV_LX_XDL_TZ,		// 零序小电流跳闸		
+	EV_LX_XDL_GJ,		// 零序小电流告警
+
+	EV_LX1TZ,			// 零序1段动作
+	EV_LX1GJ,				
+	EV_LX2TZ,			// 零序2段动作
+	EV_LX2GJ,	
+	EV_LX3TZ,			// 零序3段动作
+	EV_LX3GJ,
+
+	EV_LLTZ,			
+	EV_LLGJ,	
+	EV_LYTZ,					// 零压跳闸			
+	EV_LYGJ,					// 零压告警
+
+	EV_GLJS,					// 过流加速
+	EV_GLJSA,					// IA过流加速
+	EV_GLJSB,					// IB过流加速
+	EV_GLJSC,					// IC过流加速
+	EV_LXJS,					// 零序加速
+	EV_U0JS,					// 零压加速动作
+	EV_AR_START,				// 重合闸启动
+	EV_AR1,						// 重合闸动作1
+	EV_AR2,						// 重合闸动作2
+	EV_AR3,						// 重合闸动作3
+	
+	EV_SYTZ,					// 失压分闸
+	EV_BSTZ_FA,	 				// 合后无故障闭锁失压分闸
+	EV_SDHZ,					// 上电合闸		
+	EV_LLHZ,					// 联络合闸
+	EV_OVERU0,					// 合后接地跳闸
+	EV_XXTZ,					// 接地选线跳闸
+	EV_BS_ALL,					// 闭锁合闸
+	EV_BS_X_P,					// 电源侧X闭锁
+	EV_BS_X_L,					// 负荷侧X闭锁
+	EV_BS_Y_P,					// 电源侧Y闭锁,
+	EV_BS_Y_L,					// 负荷侧Y闭锁
+	EV_BS_UF_P,					// 电源侧残压闭锁合闸
+	EV_BS_UF_L,					// 负荷侧残压闭锁合闸
+	EV_BS_U0,					// 合后零压闭锁合闸
+	EV_BS_HA,					// 手分闭锁合闸
+	EV_BS_DB,					// 双电源闭锁合闸
+	EV_HHGZ,	 				// 合后故障
+	EV_JS_HA,					// 就地按钮解锁
+	EV_JS_HZ,					// 人工合闸解锁
+	EV_JS_POWER,				// 对侧来电解锁
+	EV_JS_L,					// 联络有压解锁
+	EV_TQJC,					// 合环检测
+	EV_TQHZ,					// 合环合闸
+	EV_BSTQHZ,					// 合环闭锁
+	EV_BSTZ,					// 大电流闭锁分闸
+	EV_WLTZ,					// 无流计数分闸s
+	
+	EV_OVLOADI,					// 电流重载
+	EV_IAOV,					// IA电流重载
+	EV_IBOV,					// IB电流重载
+	EV_ICOV,					// IC电流重载
+	EV_DLGZ,					// 电流过载
+	EV_IAGZ,					// IA电流过载
+	EV_IBGZ,					// IB电流过载
+	EV_ICGZ,					// IC电流过载
+
+	EV_DLYX,					// 电流越限
+	EV_IAYX,					// IA电流越限
+	EV_IBYX,					// IB电流越限
+	EV_ICYX,					// IC电流越限
+	
+	EV_OVI2,					// IA2电流越上限
+	EV_TZFAIL,					// 跳闸失败
+	EV_HZFAIL,					// 合闸失败
+	EV_SWFAIL,					// 开关拒动	
+	EV_TWYL,					// 跳位有流
+	EV_YB_TT,					// 压板状态
+	EV_TH_WCN,					// 弹簧未储能
+
+	EV_ABC_JDTZ,				// 接地故障总
+	EV_A_JDTZ,					// A项接地
+	EV_B_JDTZ,					// B项接地
+	EV_C_JDTZ,					// C项接地
+
+	EV_POWRE_FAILURE,			//故障停电
+	EV_PLAN_OUTAGE,				//计划停电
+	EV_RESTORE_POWER,			//恢复供电
+
+	EV_HZ_DISCON,				// 合闸控回断线 (合并为单点时:控制回路断线告警)
+#if  0 //#(!defined SET_PROFE_ISPECTION)
+	EV_FZ_DISCON,				// 分闸控回断线
+#endif
+
+	EV_PTDX_GJ,					// PT断线告警
+	EV_PTDX_TZ,					// PT断线跳闸
+
+#if (defined RECORD_SW_U0TB)
+	EV_XDL_U0TB,				// 零压突变
+#endif
 
+	EV_CENTER_FA_TT,			// 集中式FA投退
+	EV_SW_BH_TT,				// 间隔常规保护投退
+	EV_SW_FAULT_ALL,			// 间隔事故总
+	EV_SW_DIR_PQ,				// 功率方向(0:流入母线; 1:流出母线)
+	EV_SW_FAULT_LED,			// 故障指示灯
+	EV_SW_AR_CHARGE_DONE,		// 重合闸充电完成
+	EV_SW_RECORD_WAVE,			// 录波完成信号
+	EV_SW_I2_LOCK,				// 二次谐波闭锁
+	EV_CTDX_GJ,					// CT断线告警
+	EV_CTXXYC,					//CT 相序异常
+	EV_SW_NUM,					//
+#else
 	EV_BH_FAULT=0,				// 保护总
 	EV_ALL_FAULT,				// 线路故障总
 
@@ -518,6 +671,7 @@ enum
 	EV_BSTQHZ,					// 合环闭锁
 #endif
 	EV_SW_NUM,					//
+#endif
 };  
 enum
 {

+ 8 - 2
dtu/dtu_main_t536/app/Sys.c

@@ -290,6 +290,7 @@ void app_yb_refresh(void)
 	int sw;
 	for(sw=0;sw<g_sw_num;sw++)
 	{
+#ifndef GW_AREA_MAIN_2021
 	#if defined GD_AREA_JIEYANG_2021 || defined GD_AREA_ECZD_CHAOZHOU_2021 || defined GD_AREA_ECZD_JIEYANG_2022
 		if(pRunSet->bTT_SOFT_BH_YB && !FA_ALL_EN(sw))
 		{
@@ -305,8 +306,9 @@ void app_yb_refresh(void)
 			fresh_set_soe(EV_TYPE_L, g_tRelay[sw].run_stu.fa_ls,0,sw);//联络模式
 		}
 		}
-						
+#endif						
 		//自供电功能投入
+	#ifndef GW_AREA_MAIN_2021
 		{
 			bool bll;
 			bll=(g_tRelay[sw].tgoc.tllcd.sta.bFlag.bCD&&BH_GOOSE_EN(sw));			
@@ -319,7 +321,7 @@ void app_yb_refresh(void)
 		//只关联软压板: EV_KZ_YB/EV_EDIT_YB		(出口/远方)		
 		fresh_set_soe(EV_KZ_YB, pRunSet->bTT_KZ_YB, 0,sw); 	
 		fresh_set_soe(EV_EDIT_YB, pRunSet->bTT_EDIT_YB, 0,sw); 
-
+	#endif
         //关联硬压板
         // EV_CHZ_YB (重合闸)
         //#ifdef GD_AREA_FOS
@@ -328,14 +330,18 @@ void app_yb_refresh(void)
 #elif defined GD_AREA_HEYUAN_KL
         fresh_set_soe(EV_CHZ_YB,!pRunSet->bTT_CHZ_YB, 0,sw);//重合闸投入
 #else
+	#ifndef GW_AREA_MAIN_2021
         fresh_set_soe(EV_CHZ_YB,!CHZ_ALL_EN(sw) , 0,sw);//停用重合闸
+	#endif
 #endif
 
         // EV_BH_YB (功能总)
 #ifdef GD_AREA_MAIN_2020
         fresh_set_soe(EV_BH_YB, !FUN_ALL_EN(sw), 0,sw);   //停用保护和FA
 #else
+	#ifndef GW_AREA_MAIN_2021
         fresh_set_soe(EV_BH_YB, FUN_ALL_EN(sw), 0,sw);
+	#endif
 #endif
 
 #if defined BHFAGS_YB_YK || defined GD_AREA_ZHONGSHAN || defined GD_AREA_ZHONGSHAN_2020 || defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_SHAOGUAN || defined GD_AREA_ECZD_2020 || defined BH_FA_INONE_PUBLIC

+ 2 - 6
dtu/dtu_main_t536/app/UnitsLib.c

@@ -456,7 +456,7 @@ void ProtectRelayInit(void)
 		InitTR(&pR->tTZZFG_5S0ms,  pRunSet->dT_ZZFG, 0);     	//无故障延时5s
 		// InitTR(&pR->thzbs.tBSHZTime, 	pSet->dT_hzbs,	T_20ms);  		// 分闸次数过多,闭锁合闸 // TODO EWen
 		InitTR(&pR->thzbs.tTw100ms100ms,T_100ms,T_100ms);	
-	#ifndef GW_AREA_MAIN_2021
+#ifndef GW_AREA_MAIN_2021
 		for(i=0;i<8;i++)
 		{
 			if(pRunSet->bTT_FDLTz[i])
@@ -469,10 +469,8 @@ void ProtectRelayInit(void)
 				InitTR(&pR->tFdl[i].tFdlTime,pRunSet->dTFDL[i], WRN_RET_TIME);  
 			}
 		}
-	#endif
 		fresh_set_soe(EV_TYPE_S, !g_tRelay[sw].run_stu.fa_ls,true,sw);
 		fresh_set_soe(EV_TYPE_L, g_tRelay[sw].run_stu.fa_ls,true,sw);
-
 		//自供电功能投入
 		{
 			//bool bll;
@@ -483,14 +481,12 @@ void ProtectRelayInit(void)
 		//soft_yb set		
 		fresh_set_soe(EV_KZ_YB, pRunSet->bTT_KZ_YB, true,sw); 	
 		fresh_set_soe(EV_EDIT_YB, pRunSet->bTT_EDIT_YB, true,sw); 
-		
 		//#ifdef GD_AREA_FOS
 		#if defined GD_AREA_FOS || defined GD_AREA_MAIN_2020 || defined GD_AREA_ECZD_2020 || defined GD_AREA_FOS_2021
 			fresh_set_soe(EV_CHZ_YB,CHZ_ALL_EN(sw) , true,sw);//重合闸投入
 		#else
 			fresh_set_soe(EV_CHZ_YB,!CHZ_ALL_EN(sw) , true,sw);//停用重合闸
 		#endif		
-
 #ifdef GD_AREA_MAIN_2020
         fresh_set_soe(EV_BH_YB, !FUN_ALL_EN(sw), true,sw);  //停用保护和FA
 #else
@@ -512,7 +508,7 @@ void ProtectRelayInit(void)
 	#ifdef JL_SOFT_YB
 		fresh_set_soe(EV_JL_YBTT,!JL_ALL_EN(sw),true,sw);//停用自动解列
 	#endif
-
+#endif
 	#ifdef FUNC_DRIVE_JY
 		InitTR(&gb_drive.tDriveUa1Time,pSet->dT_drive_ua1, 0);
 		InitTR(&gb_drive.tDriveUa2Time,pSet->dT_drive_ua2, 0);

+ 2 - 0
dtu/dtu_main_t536/app/dcfactor.c

@@ -119,6 +119,8 @@ int dcfactor_createfile(u8 *id, u8 *factor)
 	dcfactor_file.temp = ds18b20_get_temp();
 #elif defined TMP_CHIP_GX21M15
 	dcfactor_file.temp = gx21m15_get_temp();
+#elif defined  TMP_CHIP_AHT20
+	dcfactor_file.temp = aht20_get_temp();
 #endif
 
 	dcfactor_file.addr = FILE_ADDR_ALGIN(sizeof(dcfactor_file));

+ 4 - 0
dtu/dtu_main_t536/app/defineSys.h

@@ -1214,8 +1214,12 @@
 #if defined CPU_COLDFIRE || defined CPU_AM335X
 #define TMP_CHIP_DS18B20
 #else
+#if defined CPU_FUXI
+#define TMP_CHIP_AHT20
+#else
 #define TMP_CHIP_GX21M15
 #endif
+#endif
 
 #ifdef FUNC_JX_YK_ENABLE
 	#undef FORBID_YK

+ 1 - 1
dtu/dtu_main_t536/app/equ.c

@@ -413,7 +413,7 @@ int equ_config_check(void)
 		BOARD_TYPE_AC,
 		BOARD_TYPE_DI60,
 		BOARD_TYPE_DO_2,
-		BOARD_TYPE_RS_STATUS,
+		BOARD_TYPE_AUX,
 		BOARD_TYPE_MAIN,
 		-1,
 		-1,

+ 1 - 1
dtu/dtu_main_t536/app/fuxi_shm_app.c

@@ -13,7 +13,7 @@ int write_freq_tr(uint8_t *data)
 		
     while(1)
     {
-    	ret = shm_comm_packet_write(SHM_ADDR_D_FREQ_TR, data, sizeof(SHM_FREQ_TR_T));
+    	// ret = shm_comm_packet_write(SHM_ADDR_D_FREQ_TR, data, sizeof(SHM_FREQ_TR_T));
 		if(ret > 0)	
 		{
 			break;

+ 3 - 0
dtu/dtu_main_t536/app/main.c

@@ -244,6 +244,9 @@ int app_main (void *unused)
 		AppPolling();		// 设备状态处理,如点灯等
 		create_set_file();		
 
+	#ifdef TMP_CHIP_AHT20
+		aht20_task();
+	#endif
 	#ifdef  METERING_ENERGY
 		metering_yc_refresh();
 		DD_Calc();

+ 11 - 9
dtu/dtu_main_t536/app/protect.c

@@ -401,7 +401,7 @@ int protect_polling(void)
 		Pro_over_i0(g_protect.sw,dTDelta,BH_OVI0,EV_I0YX);		// 零序电流越限
 		#endif
 
-		Pro_over_i(dTDelta,OC_OVLOAD,EV_DLZZ);	// 电流重载
+		Pro_over_i(dTDelta,OC_OVLOAD,EV_IAOV);	// 电流重载
 		Pro_over_i(dTDelta,OC_DLGZ,EV_DLGZ);		// 电流过载
 		Pro_over_i(dTDelta,OC_DLYX,EV_DLYX);		// 电流越限
 
@@ -805,9 +805,8 @@ static int _protect_amp_qd(u32  dStep)
 
 		TOC_T *pSW = &g_tRelay[sw].tOC[i];
 		OC_SET *pSet = &pRunSet->tSwSet[sw].tOcSet[i];
-		bool bY1;
+		bool bY1=false;
  		// 幅值启动 		
-
 		if (BH_ALL_EN(sw) && (pSet->bTT_Tz || pSet->bTT_Gj))
 		{
 			if(i==OC_LX1||i==OC_LX2||i==OC_LX3||i==OC_LL||i==OC_LXJS)
@@ -1435,7 +1434,7 @@ static int _protect_zzfg(void)
 	pR->tCHZ.sta.wfFlag=0;
 	pR->tCHZ.wAR_ActTimes=0;	
    	ResetTR(&pR->tCHZ.tTCHJD_HJS);
-
+#ifndef GW_AREA_MAIN_2021
 	if(soe_check(EV_GOOSE_QC_QD+sw*EV_SW_NUM)==true)   // 故障隔离启动
 	{				
 		soe_record_ev( EV_GOOSE_QC_QD+sw*EV_SW_NUM,0, 0,0,0 ); 
@@ -1472,7 +1471,7 @@ static int _protect_zzfg(void)
 	{				
 		soe_record_ev( EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM,0, 0,0,0 ); 
 	}	
-
+#endif
 	//if(soe_check(EV_GOOSE_LL_UNOK+sw*EV_SW_NUM)==true)  // 自转电条件不满足返回
 	//{				
 	//	soe_record_ev( EV_GOOSE_LL_UNOK+sw*EV_SW_NUM,1, 0,0,0 ); 
@@ -1901,8 +1900,10 @@ void sw_op_fail(DWORD     dStep)
 		if(pSW->uSdhz_L.bFlag.bX_HZEvent)
 		{
 		#ifndef GD_AREA_ZHONGSHAN_2020 //中山2020不报分布式恢复失败SOE
+			#ifndef GW_AREA_MAIN_2021
 			if(soe_check(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM)==false)
-				soe_record_ev(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );	
+				soe_record_ev(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
+			#endif	
 		#endif	
 		}
 		pSW->uSdhz_L.bFlag.bX_HZEvent = false;
@@ -1947,9 +1948,10 @@ void sw_op_fail(DWORD     dStep)
 			soe_record_ev(EV_HZFAIL+sw*EV_SW_NUM, 0, 0,0,0 );
 		if(soe_check(EV_SWFAIL+sw*EV_SW_NUM)==true)
 			soe_record_ev(EV_SWFAIL+sw*EV_SW_NUM, 0, 0,0,0 );
+	#ifndef GW_AREA_MAIN_2021
 		if(soe_check(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM)==true)			
 			soe_record_ev( EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM,0, 0,0,0 ); 
-
+	#endif
 	#ifdef FUNC_DRIVE
 		if(soe_check(EV_DRIVE_HZ_FAIL+sw*EV_SW_NUM)==true)
 		{
@@ -2140,7 +2142,7 @@ static int _protect_alarm(void)
 
 	}
 
-
+#ifndef GW_AREA_MAIN_2021
 	if (pSW->uSWST.bFlag.bKZHL)
 	{
 		if(soe_check(EV_KZHL+sw*EV_SW_NUM)==false)
@@ -2155,7 +2157,7 @@ static int _protect_alarm(void)
 			soe_record_ev(EV_KZHL+sw*EV_SW_NUM, 0, 0,0,0 );
 		}
 	}		
-
+#endif
 
 	// 跳位有流告警
 	if (pSW->uSWST.bFlag.bTWYL && KZ_OUT_ALL_EN(sw))

+ 4 - 4
dtu/dtu_main_t536/app/reclose.c

@@ -176,9 +176,9 @@ static void AR_Recharge(DWORD  dStep)
 	if(pSW->sta.bFlag.bCDWC)
 	{
 	#if 1
-		if(soe_check(EV_ARCD+sw*EV_SW_NUM)==false)
+		if(soe_check(EV_SW_AR_CHARGE_DONE+sw*EV_SW_NUM)==false)
 		{
-			soe_record_ev(EV_ARCD+sw*EV_SW_NUM, 1, 0,0,0);
+			soe_record_ev(EV_SW_AR_CHARGE_DONE+sw*EV_SW_NUM, 1, 0,0,0);
 		}
 	#else
 		//TODO ³äµç±êÖ¾ÏÔʾ EWen
@@ -197,9 +197,9 @@ static void AR_Recharge(DWORD  dStep)
 	else
 	{
 	#if 1
-		if(soe_check(EV_ARCD+sw*EV_SW_NUM)==false)
+		if(soe_check(EV_SW_AR_CHARGE_DONE+sw*EV_SW_NUM)==true)
 		{
-			soe_record_ev(EV_ARCD+sw*EV_SW_NUM, 0, 0,0,0);
+			soe_record_ev(EV_SW_AR_CHARGE_DONE+sw*EV_SW_NUM, 0, 0,0,0);
 		}
 	#else
 		if((g_disp_flag.chz_cd & (1<<sw)))

+ 2 - 0
dtu/dtu_main_t536/app/run_status.c

@@ -1028,6 +1028,7 @@ int  run_status_check(u32 dStep)
 			}
 		}
 		// CT 异常判断 
+	#ifndef GW_AREA_MAIN_2021
 		{
 			bool bok,bCheck;
 			u16 soeno=EV_CTYC+sw*EV_SW_NUM;
@@ -1055,6 +1056,7 @@ int  run_status_check(u32 dStep)
 				}
 			}
 		}
+	#endif
 	#ifndef BAT_STATE_LED
 		{  //电池电压低判断:两路直流,任一路大于直流整定值的一半,小于整定值,3秒后报异常,若定值为0 ,退出判断
 			bool bCheck;

+ 124 - 123
dtu/dtu_main_t536/app/set.c

@@ -18,7 +18,8 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include "shm_comm_packet.h"
+// #include "shm_comm_packet.h"
+#include "shmem.h"
 #else
 #include "uart_user.h"
 #include <linux/kmod.h>
@@ -4764,12 +4765,12 @@ bool  MakeRunSet(bool bFirst)
 				if(i==OC_GL1)index=SET_GL1_GJ;
 				if(i==OC_GL2)index=SET_GL2_GJ;
 				if(i==OC_GL3)index=SET_GL3_GJ;
-				poc->bTT_Gj=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   			// 告警
-				poc->bTT_Tz=(((WORD)psetbuf[index+1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);    
-				poc->dIgl=GetSetSQR(psetbuf[index+2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI);		     				// 过流定值
-				poc->dTgl=GetSetTIME(psetbuf[index+3+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-				poc->bTT_Path=(((WORD)psetbuf[index+4+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   			// 方向
-				poc->bTT_Dir=(((WORD)psetbuf[index+5+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);  
+				poc->bTT_Gj=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER].ff==1 )?true:false);   			// 告警
+				poc->bTT_Tz=(((WORD)psetbuf[index+1+sw*SW_SET_NUMBER].ff==1 )?true:false);    
+				poc->dIgl=GetSetSQR(psetbuf[index+2+sw*SW_SET_NUMBER].ff,fKI);	
+				poc->dTgl=GetSetTIME(psetbuf[index+3+sw*SW_SET_NUMBER].ff);
+				poc->bTT_Path=(((WORD)psetbuf[index+4+sw*SW_SET_NUMBER].ff==1 )?true:false);   			// 方向
+				poc->bTT_Dir=(((WORD)psetbuf[index+5+sw*SW_SET_NUMBER].ff==1 )?true:false);  
 
 			}
 			
@@ -4780,18 +4781,18 @@ bool  MakeRunSet(bool bFirst)
 				if(i==OC_LX2)index=SET_LX2_GJ;
 				if(i==OC_LX3)index=SET_LX3_GJ;
 				if(i==OC_LL)index=SET_LX_GJ_TT;
-				poc->bTT_Gj=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   			// 告警
-				poc->bTT_Tz=(((WORD)psetbuf[index+1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   
+				poc->bTT_Gj=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER].ff==1 )?true:false);   			// 告警
+				poc->bTT_Tz=(((WORD)psetbuf[index+1+sw*SW_SET_NUMBER].ff==1 )?true:false);   
 				if(i == OC_DL) 
 				{
-					poc->dIgl=GetSetSQR(psetbuf[index+2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI);		     			// 过流定值
+					poc->dIgl=GetSetSQR(psetbuf[index+2+sw*SW_SET_NUMBER].ff,fKI);		     			// 过流定值
 				}
 				else
 				{
 					// 零序与相电流转换系数不一样,要区分
-					poc->dIgl=GetSetSQR(psetbuf[index+2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI0);		     			//
+					poc->dIgl=GetSetSQR(psetbuf[index+2+sw*SW_SET_NUMBER].ff,fKI0);		     			//
 				}
-				poc->dTgl=GetSetTIME(psetbuf[index+3+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+				poc->dTgl=GetSetTIME(psetbuf[index+3+sw*SW_SET_NUMBER].ff);
 
 			}
 
@@ -4801,25 +4802,25 @@ bool  MakeRunSet(bool bFirst)
 				if(i==OC_LXJS)index=SET_LXJS_TT;
 				if(i==OC_LYJS)index=SET_LYJS_TT;	
 				
-				poc->bTT_Tz=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   			// 跳闸投退
+				poc->bTT_Tz=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER].ff==1 )?true:false);   			// 跳闸投退
 				poc->bTT_Gj=poc->bTT_Tz;   
 				if (index==SET_LYJS_TT)
 				{
-					poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKU[PUB_AC_U01]);		     // 零压单独处理
-					poc->dTgl=GetSetTIME(psetbuf[index+2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+					poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER].ff,fKU[PUB_AC_U01]);		     // 零压单独处理
+					poc->dTgl=GetSetTIME(psetbuf[index+2+sw*SW_SET_NUMBER].ff);
 					ptSet->tSwSet[sw].dT_xdl_hjs = poc->dTgl;
 				}
 				else
 				{
 					if(i == OC_LXJS)
 					{
-						poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI0);		     			//
+						poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER].ff,fKI0);		     			//
 					}
 					else
 					{
-						poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI);		     			// 过流定值
+						poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER].ff,fKI);		     			// 过流定值
 					}
-					poc->dTgl=GetSetTIME(psetbuf[index+2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+					poc->dTgl=GetSetTIME(psetbuf[index+2+sw*SW_SET_NUMBER].ff);
 				}
 			}
 
@@ -4843,18 +4844,18 @@ bool  MakeRunSet(bool bFirst)
 					if(i==OC_OVLOAD)index=SET_OVLOAD_TT;
 					if(i==OC_DLGZ)index=SET_DLGZ_TT;	
 					if(i==OC_DLYX)index=SET_DLYX_TT;
-					poc->bTT_Tz=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   			// 跳闸投退
+					poc->bTT_Tz=(((WORD)psetbuf[index+0+sw*SW_SET_NUMBER].ff==1 )?true:false);   			// 跳闸投退
 					poc->bTT_Gj=poc->bTT_Tz;  
-					poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI);		     			// 过流定值
-					poc->dTgl=GetSetTIME(psetbuf[index+2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+					poc->dIgl=GetSetSQR(psetbuf[index+1+sw*SW_SET_NUMBER].ff,fKI);		     			// 过流定值
+					poc->dTgl=GetSetTIME(psetbuf[index+2+sw*SW_SET_NUMBER].ff);
 				}
 			}
 
 			if(i==OC_GLBS)
 			{
-				poc->bTT_Tz=(((WORD)psetbuf[SET_BSTZ_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);   		// 跳闸投退
+				poc->bTT_Tz=(((WORD)psetbuf[SET_BSTZ_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);   		// 跳闸投退
 				poc->bTT_Gj=poc->bTT_Tz;   
-				poc->dIgl=GetSetSQR(psetbuf[SET_BSTZ_I+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI);		     			// 过流定值
+				poc->dIgl=GetSetSQR(psetbuf[SET_BSTZ_I+sw*SW_SET_NUMBER].ff,fKI);		     			// 过流定值
 				poc->dTgl=0;
 			}
 			
@@ -4865,7 +4866,7 @@ bool  MakeRunSet(bool bFirst)
 		// 零压保护
 		{
 			VOL_SET *pu0 = &ptSet->tSwSet[sw].tU0Set;
-			buf_offset = sw*SW_SET_NUMBER+PUB_SET_NUMBER;
+			buf_offset = sw*SW_SET_NUMBER;
 			// buf_offset = 0*SW_SET_NUMBER + PUB_SET_NUMBER;  //由0开关来代替此项公共参数, 2022-03-07
 			pu0->bTT = (((WORD)psetbuf[SET_LY_GJ_TT + buf_offset].ff==1 )?true:false); // 零压告警
 			pu0->bTz = (((WORD)psetbuf[SET_LY_TZ_TT + buf_offset].ff==1 )?true:false); // 零压跳闸
@@ -4888,13 +4889,13 @@ bool  MakeRunSet(bool bFirst)
 
 			dT1 = 0; dT2 = 0; dT3 = 0;
 			if(bTT1)
-				dT1 = (DWORD)(psetbuf[SET_GL1_T + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff *1000);
+				dT1 = (DWORD)(psetbuf[SET_GL1_T + sw*SW_SET_NUMBER].ff *1000);
 
 			if(bTT2)
-				dT2 = (DWORD)(psetbuf[SET_GL2_T + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff *1000);
+				dT2 = (DWORD)(psetbuf[SET_GL2_T + sw*SW_SET_NUMBER].ff *1000);
 
 			if(bTT3)
-				dT3 = (DWORD)(psetbuf[SET_GL3_T + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff *1000);
+				dT3 = (DWORD)(psetbuf[SET_GL3_T + sw*SW_SET_NUMBER].ff *1000);
 
 			g_record_GL_waves[sw] = rcd_get_max_waves(dT1, dT2, dT3);
 
@@ -4905,13 +4906,13 @@ bool  MakeRunSet(bool bFirst)
 
 			dT1 = 0; dT2 = 0; dT3 = 0;
 			if(bTT1)
-				dT1 = (DWORD)(psetbuf[SET_LX1_T + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff *1000);
+				dT1 = (DWORD)(psetbuf[SET_LX1_T + sw*SW_SET_NUMBER].ff *1000);
 
 			if(bTT2)
-				dT2 = (DWORD)(psetbuf[SET_LX2_T + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff *1000);
+				dT2 = (DWORD)(psetbuf[SET_LX2_T + sw*SW_SET_NUMBER].ff *1000);
 
 			if(bTT3)
-				dT3 = (DWORD)(psetbuf[SET_LX3_T + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff *1000);
+				dT3 = (DWORD)(psetbuf[SET_LX3_T + sw*SW_SET_NUMBER].ff *1000);
 
 			g_record_LX_waves[sw] = rcd_get_max_waves(dT1, dT2, dT3);
 		#endif
@@ -4920,35 +4921,35 @@ bool  MakeRunSet(bool bFirst)
 		// 重合闸
 		{
 			bool bch1,bch2;
-			bch1	=(((WORD)psetbuf[SET_CH_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false); // 一次重合闸
-			bch2	=(((WORD)psetbuf[SET_CH2_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);// 多次重合闸
+			bch1	=(((WORD)psetbuf[SET_CH_TT+sw*SW_SET_NUMBER].ff==1 )?true:false); // 一次重合闸
+			bch2	=(((WORD)psetbuf[SET_CH2_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);// 多次重合闸
 			ptSet->tSwSet[sw].bTT_CHZ=bch1||bch2;														// 设置多次重合闸和非一次重合时间,完全是应付电科院测试,若多次不投,和以前一样			
-			ptSet->tSwSet[sw].dTCH[0]	= GetSetTIME(psetbuf[SET_CH_T1+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+			ptSet->tSwSet[sw].dTCH[0]	= GetSetTIME(psetbuf[SET_CH_T1+sw*SW_SET_NUMBER].ff);
 			if(bch2)
 			{
-				ptSet->tSwSet[sw].dTCH[1]	= GetSetTIME(psetbuf[SET_CH_TN+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-				ptSet->tSwSet[sw].dTCH[2]	= GetSetTIME(psetbuf[SET_CH_TN+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+				ptSet->tSwSet[sw].dTCH[1]	= GetSetTIME(psetbuf[SET_CH_TN+sw*SW_SET_NUMBER].ff);
+				ptSet->tSwSet[sw].dTCH[2]	= GetSetTIME(psetbuf[SET_CH_TN+sw*SW_SET_NUMBER].ff);
 			}
 			else
 			{
-				ptSet->tSwSet[sw].dTCH[1]	= GetSetTIME(psetbuf[SET_CH_T2+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-				ptSet->tSwSet[sw].dTCH[2]	= GetSetTIME(psetbuf[SET_CH_T3+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+				ptSet->tSwSet[sw].dTCH[1]	= GetSetTIME(psetbuf[SET_CH_T2+sw*SW_SET_NUMBER].ff);
+				ptSet->tSwSet[sw].dTCH[2]	= GetSetTIME(psetbuf[SET_CH_T3+sw*SW_SET_NUMBER].ff);
 			}
-			ptSet->tSwSet[sw].dTCHBS	= GetSetTIME(psetbuf[SET_CHBS_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-			ptSet->tSwSet[sw].dTCHOK	= GetSetTIME(psetbuf[SET_CHOK_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-			ptSet->tSwSet[sw].dARTimes=(WORD)psetbuf[SET_AR_TIMES+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;	//重合次数
-			ptSet->tSwSet[sw].bTT_TTCH	=(((WORD)psetbuf[SET_TTCH_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);		//偷跳启动重合
-			ptSet->tSwSet[sw].bTT_GZBSCH =(((WORD)psetbuf[SET_CH_DLBS_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);		//大电流闭锁重合
-			ptSet->tSwSet[sw].dICH = GetSetSQR(psetbuf[SET_CH_DLBS_I+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI);		     			//大电流闭锁定值
+			ptSet->tSwSet[sw].dTCHBS	= GetSetTIME(psetbuf[SET_CHBS_T+sw*SW_SET_NUMBER].ff);
+			ptSet->tSwSet[sw].dTCHOK	= GetSetTIME(psetbuf[SET_CHOK_T+sw*SW_SET_NUMBER].ff);
+			ptSet->tSwSet[sw].dARTimes=(WORD)psetbuf[SET_AR_TIMES+sw*SW_SET_NUMBER].ff;	//重合次数
+			ptSet->tSwSet[sw].bTT_TTCH	=(((WORD)psetbuf[SET_TTCH_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);		//偷跳启动重合
+			ptSet->tSwSet[sw].bTT_GZBSCH =(((WORD)psetbuf[SET_CH_DLBS_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);		//大电流闭锁重合
+			ptSet->tSwSet[sw].dICH = GetSetSQR(psetbuf[SET_CH_DLBS_I+sw*SW_SET_NUMBER].ff,fKI);		     			//大电流闭锁定值
 			ptSet->tSwSet[sw].dICH_fh = _Mul_Div_U(ptSet->tSwSet[sw].dICH,	96, 100);		     									//大电流闭锁定值返回值
-			ptSet->tSwSet[sw].dCKModes=(WORD)psetbuf[SET_CH_CKFS+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;	//重合闸出口方式
-			ptSet->tSwSet[sw].dTCHZK	= GetSetTIME(psetbuf[SET_JS_BH_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+			ptSet->tSwSet[sw].dCKModes=(WORD)psetbuf[SET_CH_CKFS+sw*SW_SET_NUMBER].ff;	//重合闸出口方式
+			ptSet->tSwSet[sw].dTCHZK	= GetSetTIME(psetbuf[SET_JS_BH_T+sw*SW_SET_NUMBER].ff);
 		}
 
 		//小电流接地
-		ptSet->tSwSet[sw].bTT_xdlgj =(((WORD)psetbuf[SET_XDLGJ_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);  
-		ptSet->tSwSet[sw].bTT_xdltz =(((WORD)psetbuf[SET_XDLTZ_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false); 
-		ptSet->tSwSet[sw].bTT_xdlsg =(((WORD)psetbuf[SET_XDLSG_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);  
+		ptSet->tSwSet[sw].bTT_xdlgj =(((WORD)psetbuf[SET_XDLGJ_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);  
+		ptSet->tSwSet[sw].bTT_xdltz =(((WORD)psetbuf[SET_XDLTZ_TT+sw*SW_SET_NUMBER].ff==1 )?true:false); 
+		ptSet->tSwSet[sw].bTT_xdlsg =(((WORD)psetbuf[SET_XDLSG_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);  
 
 		if(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].chn_index == CFG_ADC_CHANNEL_ZERO)
 		{
@@ -4957,22 +4958,22 @@ bool  MakeRunSet(bool bFirst)
 		else
 		{
 			// 定值由峰值改为有效值
-			// ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0*1.4142));
-			ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0));
+			// ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0*1.4142));
+			ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0));
 		}
-		ptSet->tSwSet[sw].dI_xdl 	= GetSetSQR(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKI0);		     			//过流定值
+		ptSet->tSwSet[sw].dI_xdl 	= GetSetSQR(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER].ff,fKI0);		     			//过流定值
 		ptSet->tSwSet[sw].dI_xdl_fh = _Mul_Div_U(ptSet->tSwSet[sw].dI_xdl,	96, 100);
-		ptSet->tSwSet[sw].dT_xdl_T  = psetbuf[SET_XDL_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;			// 由于未使用系统TICK 故采用实际时间 add by zhy 20210517
-		ptSet->tSwSet[sw].dT_xdl_GT  = psetbuf[SET_XDL_GT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;
+		ptSet->tSwSet[sw].dT_xdl_T  = psetbuf[SET_XDL_T+sw*SW_SET_NUMBER].ff;			// 由于未使用系统TICK 故采用实际时间 add by zhy 20210517
+		ptSet->tSwSet[sw].dT_xdl_GT  = psetbuf[SET_XDL_GT+sw*SW_SET_NUMBER].ff;
 #if (defined RECORD_SW_U0TB)
-		ptSet->tSwSet[sw].dU_xdl_u0TB    = GetSetSQR(psetbuf[SET_U0_TB + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff, fKU[PUB_AC_U01]);
+		ptSet->tSwSet[sw].dU_xdl_u0TB    = GetSetSQR(psetbuf[SET_U0_TB + sw*SW_SET_NUMBER].ff, fKU[PUB_AC_U01]);
 		ptSet->tSwSet[sw].dU_xdl_u0TB_fh = _Mul_Div_U(ptSet->tSwSet[sw].dU_xdl_u0TB, 96, 100);	//0.96=0.98*0.98
 #endif
 
 		// 零序电流反极性
-		ptSet->tSwSet[sw].bTT_lxpolar =(((WORD)psetbuf[SET_LXPOLAR_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);  
+		ptSet->tSwSet[sw].bTT_lxpolar =(((WORD)psetbuf[SET_LXPOLAR_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);  
 
-		ptSet->tSwSet[sw].bTT_BH	=((WORD)psetbuf[SET_BH_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff>=1 )?true:false;     //保护总投退
+		ptSet->tSwSet[sw].bTT_BH	=((WORD)psetbuf[SET_BH_TT+sw*SW_SET_NUMBER].ff>=1 )?true:false;     //保护总投退
 
 		if (!bTT_BH_Init[sw])
 		{
@@ -4986,69 +4987,69 @@ bool  MakeRunSet(bool bFirst)
 #if  0 //#if defined(SET_PROFE_ISPECTION)  //暂先各自投退, 2022-03-18
 		ptSet->tSwSet[sw].bTT_FA	= ptSet->tSwSet[sw].bTT_BH;
 #else
-		ptSet->tSwSet[sw].bTT_FA	= ((DWORD)psetbuf[SET_FA_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false; // FA功能
-#endif
-
-		ptSet->tSwSet[sw].bSW_F		= ((DWORD)psetbuf[SET_SL_F+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false; // 0=分段联络  1=分界选择
-		ptSet->tSwSet[sw].bSW_L		= ((DWORD)psetbuf[SET_S_L+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false; // 分段联络选择
-		ptSet->tSwSet[sw].bFA_auto	= ((DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==0)?true:false ; // 自适应
-		ptSet->tSwSet[sw].bFA_VI		= ((DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false;	//  电压型
-		ptSet->tSwSet[sw].bFA_VIT		= ((DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==2)?true:false ; //  电压电流型
-		ptSet->tSwSet[sw].FA_type 		= (DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;
-		ptSet->tSwSet[sw].bFTU		= ((DWORD)psetbuf[SET_FTU_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false ; // 
-		ptSet->tSwSet[sw].bauto_gl		=((DWORD)psetbuf[SET_AUTOGL_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false ; // 
-		ptSet->tSwSet[sw].bauto_lx		= ((DWORD)psetbuf[SET_AUTOLX_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1)?true:false ; // 
-
-		ptSet->tSwSet[sw].dT_X		= GetSetTIME(psetbuf[SET_X_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].dT_Y		= GetSetTIME(psetbuf[SET_Y_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].dT_C		= GetSetTIME(psetbuf[SET_C_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].dT_S		= GetSetTIME(psetbuf[SET_S_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-
-		//ptSet->tSwSet[sw].dT_Z		= GetSetTIME(psetbuf[SET_Y_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].CTDX_type = (DWORD)psetbuf[SET_CT_DX_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;				// CT断线类型
-		ptSet->tSwSet[sw].dCTDX_T	= GetSetTIME(psetbuf[SET_CT_DX_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);			// CT断线时间
+		ptSet->tSwSet[sw].bTT_FA	= ((DWORD)psetbuf[SET_FA_TT+sw*SW_SET_NUMBER].ff==1)?true:false; // FA功能
+#endif
+
+		ptSet->tSwSet[sw].bSW_F		= ((DWORD)psetbuf[SET_SL_F+sw*SW_SET_NUMBER].ff==1)?true:false; // 0=分段联络  1=分界选择
+		ptSet->tSwSet[sw].bSW_L		= ((DWORD)psetbuf[SET_S_L+sw*SW_SET_NUMBER].ff==1)?true:false; // 分段联络选择
+		ptSet->tSwSet[sw].bFA_auto	= ((DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER].ff==0)?true:false ; // 自适应
+		ptSet->tSwSet[sw].bFA_VI		= ((DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER].ff==1)?true:false;	//  电压型
+		ptSet->tSwSet[sw].bFA_VIT		= ((DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER].ff==2)?true:false ; //  电压电流型
+		ptSet->tSwSet[sw].FA_type 		= (DWORD)psetbuf[SET_FA_TYPE+sw*SW_SET_NUMBER].ff;
+		ptSet->tSwSet[sw].bFTU		= ((DWORD)psetbuf[SET_FTU_TT+sw*SW_SET_NUMBER].ff==1)?true:false ; // 
+		ptSet->tSwSet[sw].bauto_gl		=((DWORD)psetbuf[SET_AUTOGL_TT+sw*SW_SET_NUMBER].ff==1)?true:false ; // 
+		ptSet->tSwSet[sw].bauto_lx		= ((DWORD)psetbuf[SET_AUTOLX_TT+sw*SW_SET_NUMBER].ff==1)?true:false ; // 
+
+		ptSet->tSwSet[sw].dT_X		= GetSetTIME(psetbuf[SET_X_T+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dT_Y		= GetSetTIME(psetbuf[SET_Y_T+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dT_C		= GetSetTIME(psetbuf[SET_C_T+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dT_S		= GetSetTIME(psetbuf[SET_S_T+sw*SW_SET_NUMBER].ff);
+
+		//ptSet->tSwSet[sw].dT_Z		= GetSetTIME(psetbuf[SET_Y_T+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].CTDX_type = (DWORD)psetbuf[SET_CT_DX_TT+sw*SW_SET_NUMBER].ff;				// CT断线类型
+		ptSet->tSwSet[sw].dCTDX_T	= GetSetTIME(psetbuf[SET_CT_DX_T+sw*SW_SET_NUMBER].ff);			// CT断线时间
 		
 	
 		ptSet->tSwSet[sw].dIHH_GL = MIN_3(ptSet->tSwSet[sw].tOcSet[OC_GL1].dIgl,ptSet->tSwSet[sw].tOcSet[OC_GL2].dIgl,ptSet->tSwSet[sw].tOcSet[OC_GL3].dIgl);
 		ptSet->tSwSet[sw].dIHH_GLfh= MIN_3(ptSet->tSwSet[sw].tOcSet[OC_GL1].dIgl_fh,ptSet->tSwSet[sw].tOcSet[OC_GL2].dIgl_fh,ptSet->tSwSet[sw].tOcSet[OC_GL3].dIgl_fh);
 				
-		ptSet->tSwSet[sw].dT_xxtz		= GetSetTIME(psetbuf[SET_XXTZ_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].dT_xxch		= GetSetTIME(psetbuf[SET_XXCH_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dT_xxtz		= GetSetTIME(psetbuf[SET_XXTZ_T+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dT_xxch		= GetSetTIME(psetbuf[SET_XXCH_T+sw*SW_SET_NUMBER].ff);
 
-		ptSet->tSwSet[sw].bTT_LostVot =(((WORD)psetbuf[SET_LOST_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);
+		ptSet->tSwSet[sw].bTT_LostVot =(((WORD)psetbuf[SET_LOST_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);
 		ptSet->tSwSet[sw].bTT_LostVot &= ptSet->tSwSet[sw].bTT_FA;  //当就地FA退出时,失压分闸功能须退出
-		ptSet->tSwSet[sw].dlvTimes = (WORD)psetbuf[SET_LOST_TIMES+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;
-		ptSet->tSwSet[sw].dTlostvot	= GetSetTIME(psetbuf[SET_LOST_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-
-		ptSet->tSwSet[sw].bTT_InterJd =(((WORD)psetbuf[SET_JDGZ_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);
-		ptSet->tSwSet[sw].dNJDSNum    = (WORD)psetbuf[SET_JDGZ_SNUM+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;
-		ptSet->tSwSet[sw].dTJDSTimes  = GetSetTIME(psetbuf[SET_JDGZ_ST+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].dNJDLNum    = (WORD)psetbuf[SET_JDGZ_LNUM+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;
-		ptSet->tSwSet[sw].dTJDLTimes  = GetSetTIME(psetbuf[SET_JDGZ_LT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-		ptSet->tSwSet[sw].dJDTYPE     = (WORD)(psetbuf[SET_JDTYPE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
-
-		ptSet->tSwSet[sw].bTT_OverU0=(((WORD)psetbuf[SET_TT_OVERU0+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);
-
-		ptSet->tSwSet[sw].bTT_BSHH=(((WORD)psetbuf[SET_TT_TQ+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);	// 同期投退
-		ptSet->tSwSet[sw].bTT_TQ	=(((WORD)psetbuf[SET_TT_TQ+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==2 )?true:false);	// 同期投退
-		ptSet->tSwSet[sw].dTQ_U_FZ	= GetSetNormal(psetbuf[SET_TQ_U+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,fKU[PUB_AC_US1]);	
-		ptSet->tSwSet[sw].dT_TQ		= GetSetTIME(psetbuf[SET_TQ_T+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dlvTimes = (WORD)psetbuf[SET_LOST_TIMES+sw*SW_SET_NUMBER].ff;
+		ptSet->tSwSet[sw].dTlostvot	= GetSetTIME(psetbuf[SET_LOST_T+sw*SW_SET_NUMBER].ff);
+
+		ptSet->tSwSet[sw].bTT_InterJd =(((WORD)psetbuf[SET_JDGZ_TT+sw*SW_SET_NUMBER].ff==1 )?true:false);
+		ptSet->tSwSet[sw].dNJDSNum    = (WORD)psetbuf[SET_JDGZ_SNUM+sw*SW_SET_NUMBER].ff;
+		ptSet->tSwSet[sw].dTJDSTimes  = GetSetTIME(psetbuf[SET_JDGZ_ST+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dNJDLNum    = (WORD)psetbuf[SET_JDGZ_LNUM+sw*SW_SET_NUMBER].ff;
+		ptSet->tSwSet[sw].dTJDLTimes  = GetSetTIME(psetbuf[SET_JDGZ_LT+sw*SW_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].dJDTYPE     = (WORD)(psetbuf[SET_JDTYPE+sw*SW_SET_NUMBER].ff);
+
+		ptSet->tSwSet[sw].bTT_OverU0=(((WORD)psetbuf[SET_TT_OVERU0+sw*SW_SET_NUMBER].ff==1 )?true:false);
+
+		ptSet->tSwSet[sw].bTT_BSHH=(((WORD)psetbuf[SET_TT_TQ+sw*SW_SET_NUMBER].ff==1 )?true:false);	// 同期投退
+		ptSet->tSwSet[sw].bTT_TQ	=(((WORD)psetbuf[SET_TT_TQ+sw*SW_SET_NUMBER].ff==2 )?true:false);	// 同期投退
+		ptSet->tSwSet[sw].dTQ_U_FZ	= GetSetNormal(psetbuf[SET_TQ_U+sw*SW_SET_NUMBER].ff,fKU[PUB_AC_US1]);	
+		ptSet->tSwSet[sw].dT_TQ		= GetSetTIME(psetbuf[SET_TQ_T+sw*SW_SET_NUMBER].ff);
 		ptSet->tSwSet[sw].dTQ_U_FZ_fh= _Mul_Div_U(ptSet->tSwSet[sw].dTQ_U_FZ,	104,100);	
-		ptSet->tSwSet[sw].dTQ_ANGLE_FZ	= (qs16)(psetbuf[SET_TQ_ANGLE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff*65536);	// 合环角差
-		ptSet->tSwSet[sw].dTQ_FREQ_FZ	= (qs16)(psetbuf[SET_TQ_FREQ+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff*65536);	// 合环频差
+		ptSet->tSwSet[sw].dTQ_ANGLE_FZ	= (qs16)(psetbuf[SET_TQ_ANGLE+sw*SW_SET_NUMBER].ff*65536);	// 合环角差
+		ptSet->tSwSet[sw].dTQ_FREQ_FZ	= (qs16)(psetbuf[SET_TQ_FREQ+sw*SW_SET_NUMBER].ff*65536);	// 合环频差
 
 
-		ptSet->tSwSet[sw].bTT_TzZero=(((WORD)psetbuf[SET_GLZERO_TZ+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);  
-		ptSet->tSwSet[sw].bTT_WCN	=(((WORD)psetbuf[SET_TT_TWCN+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false);//&ptSet->bFUN_TWCN;	//弹簧未储能
-		ptSet->tSwSet[sw].bTT_Current_Inv =((WORD)psetbuf[SET_CURRENT_INV_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;   
-		ptSet->tSwSet[sw].bTT_Dir_Auto =((WORD)psetbuf[SET_DIR_AUTO_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;
-		ptSet->tSwSet[sw].bTT_Power_v2 =((WORD)psetbuf[SET_POWER_V2_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;   
-		ptSet->tSwSet[sw].bTT_QYD_BS =((WORD)psetbuf[SET_QYD_BS_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;   
+		ptSet->tSwSet[sw].bTT_TzZero=(((WORD)psetbuf[SET_GLZERO_TZ+sw*SW_SET_NUMBER].ff==1 )?true:false);  
+		ptSet->tSwSet[sw].bTT_WCN	=(((WORD)psetbuf[SET_TT_TWCN+sw*SW_SET_NUMBER].ff==1 )?true:false);//&ptSet->bFUN_TWCN;	//弹簧未储能
+		ptSet->tSwSet[sw].bTT_Current_Inv =((WORD)psetbuf[SET_CURRENT_INV_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;   
+		ptSet->tSwSet[sw].bTT_Dir_Auto =((WORD)psetbuf[SET_DIR_AUTO_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;
+		ptSet->tSwSet[sw].bTT_Power_v2 =((WORD)psetbuf[SET_POWER_V2_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;   
+		ptSet->tSwSet[sw].bTT_QYD_BS =((WORD)psetbuf[SET_QYD_BS_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;   
 
 		//录波
 		ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_SD] = 1;
 		ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_QD] = 1;
-		buf_offset = sw*SW_SET_NUMBER+PUB_SET_NUMBER;
+		buf_offset = sw*SW_SET_NUMBER;
 		ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_GLGZ] = ((WORD)psetbuf[SET_WAVE_GLGZ_TT + buf_offset].ff==1 )?true:false;
 		ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_XLSY] = ((WORD)psetbuf[SET_WAVE_XLSY_TT + buf_offset].ff==1 )?true:false;
 		ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_LXDY] = ((WORD)psetbuf[SET_WAVE_LXDY_TT + buf_offset].ff==1 )?true:false;
@@ -5061,17 +5062,17 @@ bool  MakeRunSet(bool bFirst)
 		// ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_JDGZ] = ((WORD)psetbuf[SET_WAVE_JDGZ_TT + buf_offset].ff==1 )?true:false;
 		// ptSet->tSwSet[sw].bTT_rcd_type[RECORD_TYPE_LYTB] = ((WORD)psetbuf[SET_WAVE_LYTB_TT + buf_offset].ff==1 )?true:false;
 
-		ptSet->tSwSet[sw].dU_u0TB = (DWORD)(psetbuf[SET_U0_TB + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff*65536);
-		ptSet->tSwSet[sw].dI_i0TB = (DWORD)(psetbuf[SET_I0_TB + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff*65536);
-		// ptSet->tSwSet[sw].dU_u0TB    = GetSetSQR(psetbuf[SET_U0_TB + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff, fKU[PUB_AC_U01]);
+		ptSet->tSwSet[sw].dU_u0TB = (DWORD)(psetbuf[SET_U0_TB + sw*SW_SET_NUMBER].ff*65536);
+		ptSet->tSwSet[sw].dI_i0TB = (DWORD)(psetbuf[SET_I0_TB + sw*SW_SET_NUMBER].ff*65536);
+		// ptSet->tSwSet[sw].dU_u0TB    = GetSetSQR(psetbuf[SET_U0_TB + sw*SW_SET_NUMBER].ff, fKU[PUB_AC_U01]);
 		// ptSet->tSwSet[sw].dU_u0TB_fh = _Mul_Div_U(ptSet->tSwSet[sw].dU_u0TB, 96, 100);	//0.96=0.98*0.98
-		// ptSet->tSwSet[sw].dI_i0TB    = GetSetSQR(psetbuf[SET_I0_TB + sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff, fKI0);
+		// ptSet->tSwSet[sw].dI_i0TB    = GetSetSQR(psetbuf[SET_I0_TB + sw*SW_SET_NUMBER].ff, fKI0);
 		// ptSet->tSwSet[sw].dI_i0TB_fh = _Mul_Div_U(ptSet->tSwSet[sw].dI_i0TB, 96, 100);	//0.96=0.98*0.98
 
 		{ //软压板状态处理
 			bool bYB;
-			WORD code=EV_YKYB_TT+EV_SW_NUM*sw;			
-			bYB=((WORD)psetbuf[SET_YB_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;   
+			WORD code=EV_YB_TT+EV_SW_NUM*sw;			
+			bYB=((WORD)psetbuf[SET_YB_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;   
 			ptSet->tSwSet[sw].bTT_YB=bYB;
 			if(bFirst)
 			{
@@ -5097,21 +5098,21 @@ bool  MakeRunSet(bool bFirst)
 			}
 		}
 		
-		ptSet->tSwSet[sw].bTT_HZ_BS=((WORD)psetbuf[SET_HZ_BS_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;  // 多次分闸闭锁合闸	modify by zhy 2021年6月22日
-		ptSet->tSwSet[sw].dFZNum = (WORD)psetbuf[SET_FZ_FRE+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff;
-		ptSet->tSwSet[sw].dFZTimes	= GetSetTIME(psetbuf[SET_FZ_TIME+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].bTT_HZ_BS=((WORD)psetbuf[SET_HZ_BS_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;  // 多次分闸闭锁合闸	modify by zhy 2021年6月22日
+		ptSet->tSwSet[sw].dFZNum = (WORD)psetbuf[SET_FZ_FRE+sw*SW_SET_NUMBER].ff;
+		ptSet->tSwSet[sw].dFZTimes	= GetSetTIME(psetbuf[SET_FZ_TIME+sw*SW_SET_NUMBER].ff);
 
 	#if defined (SET_PROFE_2XB_PERCENT)
-		ptSet->tSwSet[sw].dXBCOE 	= GetSetSQR(psetbuf[SET_2XBCOE +sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff/100, 256);  // 二次谐波制动系数
+		ptSet->tSwSet[sw].dXBCOE 	= GetSetSQR(psetbuf[SET_2XBCOE +sw*SW_SET_NUMBER].ff/100, 256);  // 二次谐波制动系数
 	#else
-	  	ptSet->tSwSet[sw].dXBCOE 	= GetSetSQR(psetbuf[SET_2XBCOE +sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff, 256);  	// 二次谐波制动系数
+	  	ptSet->tSwSet[sw].dXBCOE 	= GetSetSQR(psetbuf[SET_2XBCOE +sw*SW_SET_NUMBER].ff, 256);  	// 二次谐波制动系数
 	#endif
-		ptSet->tSwSet[sw].bTT_2XBBS=((WORD)psetbuf[SET_TT_2XB+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;  	// 二次谐波制动
+		ptSet->tSwSet[sw].bTT_2XBBS=((WORD)psetbuf[SET_TT_2XB+sw*SW_SET_NUMBER].ff==1 )?true:false;  	// 二次谐波制动
 
-		ptSet->tSwSet[sw].bTT_KH_JC=((WORD)psetbuf[SET_KHJC_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;  // 控回断线检测投退	modify by zhy 2021年7月1日
-		ptSet->tSwSet[sw].dKHJCTimes = GetSetTIME(psetbuf[SET_KH_TIME+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff);
+		ptSet->tSwSet[sw].bTT_KH_JC=((WORD)psetbuf[SET_KHJC_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;  // 控回断线检测投退	modify by zhy 2021年7月1日
+		ptSet->tSwSet[sw].dKHJCTimes = GetSetTIME(psetbuf[SET_KH_TIME+sw*SW_SET_NUMBER].ff);
 
-		ptSet->tSwSet[sw].bTT_TFD=((WORD)psetbuf[SET_TFD_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false;  // 湖南停复电投退	add by zhy 2021年12月9日
+		ptSet->tSwSet[sw].bTT_TFD=((WORD)psetbuf[SET_TFD_TT+sw*SW_SET_NUMBER].ff==1 )?true:false;  // 湖南停复电投退	add by zhy 2021年12月9日
 	}
 #else
 	for(sw=0;sw<SWITCH_NUM_MAX;sw++)
@@ -5673,7 +5674,7 @@ bool  MakeRunSet(bool bFirst)
 		else
 		{
 			// 定值由峰值改为有效值
-		//			ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0*1.4142));
+		//			ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0*1.4142));
 			ptSet->tSwSet[sw].dI_xdl_zt = GetSetNormal(psetbuf[SET_XDL_I+sw*SW_SET_NUMBER].ff,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0));
 			ptSet->tSwSet[sw].dI_xdl_300ma = GetSetNormal(0.2,1/(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].e_factor0));						// 200毫安,电流定值
 		}
@@ -5833,7 +5834,7 @@ bool  MakeRunSet(bool bFirst)
 			ptSet->tSwSet[sw].dU_UF 	=GetSetSQR(0.25*fUn,fKU[PUB_AC_UAB1]);	 //瞬压定值固定取25%额定值
 			ptSet->tSwSet[sw].dU_UF2		=GetSetSQR(0.25*ptSet->pt2_two,fKU[PUB_AC_UAB2]);	 //瞬压定值固定取25%额定值
 		#endif
-			ptSet->tSwSet[sw].hzbstimes =((DWORD)psetbuf[SET_HZBS_TIMES+sw*SW_SET_NUMBER].ff);//psetbuf[SET_HZBS_TIMES+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff)
+			ptSet->tSwSet[sw].hzbstimes =((DWORD)psetbuf[SET_HZBS_TIMES+sw*SW_SET_NUMBER].ff);//psetbuf[SET_HZBS_TIMES+sw*SW_SET_NUMBER].ff)
 			ptSet->tSwSet[sw].dT_hzbs   = GetSetTIME(psetbuf[SET_HZBS_T+sw*SW_SET_NUMBER].ff);
 			ptSet->tSwSet[sw].dT_wldz	=GetSetSQR(psetbuf[SET_FA_WLDZ].ff,fIn); 
 				
@@ -6124,7 +6125,7 @@ bool  MakeRunSet(bool bFirst)
 	//	ptSet->tSwSet[sw].bDJX   = ((WORD)psetbuf[SET_BZT_FS+sw*SW_SET_NUMBER].ff==3 )?true:false;
 		ptSet->tSwSet[sw].bZF   = ((WORD)psetbuf[SET_BZT_FS+sw*SW_SET_NUMBER].ff==3 )?true:false;
 		
-		//ptSet->tSwSet[sw].bZF 		= ((WORD)psetbuf[SET_BZF_TT+sw*SW_SET_NUMBER+PUB_SET_NUMBER].ff==1 )?true:false; 
+		//ptSet->tSwSet[sw].bZF 		= ((WORD)psetbuf[SET_BZF_TT+sw*SW_SET_NUMBER].ff==1 )?true:false; 
 		ptSet->tSwSet[sw].dT_BTTZ 	 	 = GetSetTIME(psetbuf[SET_BZTT_T+sw*SW_SET_NUMBER].ff); 
 		ptSet->tSwSet[sw].dT_BTHZ 	 	 = GetSetTIME(psetbuf[SET_BZTH_T+sw*SW_SET_NUMBER].ff); 
 		ptSet->tSwSet[sw].dT_BTCD 	 	 = GetSetTIME(psetbuf[SET_TCD+sw*SW_SET_NUMBER].ff);

+ 3 - 3
dtu/dtu_main_t536/app/set.h

@@ -1322,7 +1322,7 @@ enum
 	SET_SECTION,			//定值区
 
 	//电压参数
-	SET_LABLE_VOL=0,
+	SET_LABLE_VOL,
 	SET_POWER_U,			// 线路有压定值, 电源有压无压、上电合闸、失压分闸定值均使用此定值
 	SET_DOWN_U,				// 线路无压定值	   电源无压、失压分闸定值均使用此定值		  // add by zhy 20211209
 	SET_PHLED_U,			// 带电指示定值	   		  								   // add by zhy 20211209
@@ -1744,8 +1744,8 @@ enum
 	PARA_GATE_NET,			// 网关
 
 	//卫星模块组
-	PARA_LABEL_STATELLITE,	
-	PARA_STATELLITE_MODE,	// 卫星模块工作模式 
+	// PARA_LABEL_STATELLITE,	
+	// PARA_STATELLITE_MODE,	// 卫星模块工作模式 
 
 	//对时组
 	PARA_LABEL_TIME,		//列表名

+ 20 - 2
dtu/dtu_main_t536/app/switch.c

@@ -775,6 +775,9 @@ const struct mea_desc g_pub_ac_desc[PUB_AC_NUM_ALL] =
 	{"ArgUca",UNIT_ANG,UNIT_NULL},
 #endif
 	{"温度",UNIT_TEMP,UNIT_NULL},
+#ifdef TMP_CHIP_AHT20
+	{"湿度",UNIT_HUMI,UNIT_NULL},
+#endif
 	{"Ver",UNIT_NULL,UNIT_NULL},
 #ifdef BATTERY_WITH_COMM
 	{"活化放电时长",UINT_Hour,UNIT_NULL},
@@ -2460,6 +2463,8 @@ int sw_auto_adjust(int ui_angle0)
 							ds18b20_get_temp()
 					#elif defined TMP_CHIP_GX21M15
 							gx21m15_get_temp()
+					#elif defined TMP_CHIP_AHT20
+							aht20_get_temp()
 					#endif						
 						);
 		if(i < PUB_AC_NUM)
@@ -3891,11 +3896,16 @@ void _sw_cal_average(int cal_num)
 	// 直流、温度
 	{
 		float factor,t,f0,f1;
-
+	#ifdef TMP_CHIP_AHT20
+		float h=0.0;
+	#endif
 #if defined TMP_CHIP_DS18B20		
 		t = ds18b20_get_temp();
 #elif defined TMP_CHIP_GX21M15
 		t = gx21m15_get_temp();
+#elif defined TMP_CHIP_AHT20
+		t = aht20_get_temp();
+		h = aht20_get_humi();
 #endif
 
 		#ifdef DC_TEST_ONE
@@ -3926,7 +3936,9 @@ void _sw_cal_average(int cal_num)
 			f1 = 0.0;
 		}
 #endif
-
+	#ifdef TMP_CHIP_AHT20
+		g_sw_pub.ac_in[PUB_AC_IN_HUMI] = (qs16)(h*Q16_BASE);
+	#endif
 		g_sw_pub.ac_in[PUB_AC_IN_TEMP] = (qs16)(t*Q16_BASE);
 		g_sw_pub.ac_in[PUB_AC_IN_UZ1] = (qs16)(f0*Q16_BASE);
 		g_sw_pub.ac_in[PUB_AC_IN_UZ2] = (qs16)(f1*Q16_BASE);
@@ -4031,6 +4043,8 @@ void _sw_cal_zl(void)
 		t = ds18b20_get_temp();
 #elif defined TMP_CHIP_GX21M15
 		t = gx21m15_get_temp();
+#elif defined TMP_CHIP_AHT20
+		t = aht20_get_temp();
 #endif
 		f0 = (dc_get(0)-g_dcfactor[0].f_dcL)*g_dcfactor[0].f_dc+dc_adjust[0];
 		f1 = (dc_get(1)-g_dcfactor[1].f_dcL)*g_dcfactor[1].f_dc+dc_adjust[0];
@@ -4341,6 +4355,8 @@ void _sw_temp_factor(void)
 	t = ds18b20_get_temp();
 #elif defined TMP_CHIP_GX21M15
 	t = gx21m15_get_temp();
+#elif defined TMP_CHIP_AHT20
+	t = aht20_get_temp();
 #endif
 
 	if(t < -80.0 ||  t > 125.0)
@@ -4662,6 +4678,8 @@ int sw_ui_temp(void)
 		ds18b20_get_temp()
 #elif defined TMP_CHIP_GX21M15
 		gx21m15_get_temp()
+#elif defined TMP_CHIP_AHT20
+		aht20_get_temp()
 #endif		
 		);
 	

+ 3 - 0
dtu/dtu_main_t536/app/switch.h

@@ -651,6 +651,9 @@ enum
 	PUB_AC_IN_ARGUCA,
 #endif
 	PUB_AC_IN_TEMP,
+#ifdef TMP_CHIP_AHT20
+	PUB_AC_IN_HUMI,
+#endif
 	PUB_AC_IN_VER,
 #ifdef BATTERY_WITH_COMM
 	PUB_AC_BATT_ACT_T_MAX,  // µç³Ø»î»¯×î´ó·Åµçʱ³¤

+ 1 - 1
dtu/dtu_main_t536/app/sysTime.c

@@ -47,7 +47,7 @@ int sys_time_set(struct rtc_time_t *pct)
 	}
 
 	shm_ts.ts = ts;
-	shm_comm_packet_write(SHM_ADDR_D_TIME, (uint8_t *)&shm_ts, sizeof(SHM_TS_T));
+	// shm_comm_packet_write(SHM_ADDR_D_TIME, (uint8_t *)&shm_ts, sizeof(SHM_TS_T));
 	mb_notice_time_update();
 
 	sprintf(pchDT, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", pct->year + 2000, pct->month, pct->day, pct->hour, pct->min, pct->ms / 1000);

+ 34 - 1
dtu/dtu_main_t536/main_mod.c

@@ -313,6 +313,33 @@ int di_do_adc (void *unused)
 	rt_printf("Thread created successfully: %s, PID: %d LWP: %d\r\n", 
               	"di_do_adc", (int)getpid(), (int)syscall(SYS_gettid));
 #endif
+
+	// zhl add
+	struct shmem_fd shmem_fd;
+	if (share_mem_init_v2(&shmem_fd) < 0){
+		printf("--->shmem_init fail !!!\r\n");
+		return -1;
+	} else {
+		printf("--->shmem_init success !!!\r\n");
+	}
+
+	// 装置类型us_machine_type (分布式:1,集中式:2)
+	struct t_shmdata_machine_type machine_type = {0};
+	machine_type.us_machine_type = 2;
+	shm_packet_write_v2(SHM_ADDR_R_MACHINETYPE, (uint8_t *)&machine_type, sizeof(struct t_shmdata_machine_type));	
+	// printf("write SHM_ADDR_R_MACHINETYPE::0x%X -> us_updata: %d, us_op: %d, us_op_bk: %d, us_machine_type: %d, us_crc: 0x%04x\n\n", 
+	// 		SHM_ADDR_R_MACHINETYPE, machine_type.us_updata, machine_type.us_op, machine_type.us_op_bk, machine_type.us_machine_type, machine_type.us_crc);
+	
+	sleep(5); // 注:下发装置类型后,需要等待大于5s,才能读取到R核的ADC初始化标志信息
+	// ADC初始化标志信息
+	struct t_shmdata_flag adc_flag = {0};
+	int ret_flag = shm_packet_read_v2(SHM_ADDR_W_FLAG, sizeof(adc_flag), (uint8_t *)&adc_flag, sizeof(adc_flag));
+	if(adc_flag.us_cfg_adc_err == 1 && ret_flag > 0){
+		rt_err_set(ERR_CODE_INIT_ADC, 0);
+	}		
+	// printf("ret_flag: %d, read SHM_ADDR_W_FLAG:0x%X -> us_updata: %u, us_op: %u, us_op_bk: %u, us_cfg_adc_err: %u, us_crc: 0x%04x\n\n", 
+	// 		ret_flag, SHM_ADDR_W_FLAG, adc_flag.us_updata, adc_flag.us_op, adc_flag.us_op_bk, adc_flag.us_cfg_adc_err, adc_flag.us_crc);
+		
     while(1)
     {
 		static u8 flags = 0;
@@ -335,7 +362,13 @@ int di_do_adc (void *unused)
 		}
 		
 		watchdog_feed(wdt_id);
-        adc_isr(0);			
+
+        // adc_isr(0);
+		if(adc_flag.us_cfg_adc_err == 0 && ret_flag > 0)
+		{
+			adc_isr_new(0);	
+		}
+				
 		//保护计算
         if(prt_flag)     
         {

+ 2 - 0
dtu/dtu_main_t536/sh/t536/Makefile

@@ -78,6 +78,7 @@ OBJS =  main_mod.o \
 		tmp/fuxi_bsp/source/fourier.o \
 		tmp/fuxi_bsp/source/flexcan.o \
 		tmp/fuxi_bsp/source/can_app.o \
+		tmp/fuxi_bsp/source/aht20.o \
 		\
 		tmp/bsp_share/bsp_shm.o \
 		tmp/bsp_share/bsp_share.o \
@@ -179,6 +180,7 @@ OBJS =  main_mod.o \
 		tmp/app_public/bluetooth/bluetooth.o\
 		\
 		tmp/xenomai/lib/xenomai/bootstrap.o\
+		tmp/fuxi_bsp/source/shmem.o \
 
 #		tmp/lib61850.o\