浏览代码

修改 : 开出接口;

lch 8 月之前
父节点
当前提交
69b0c7187c

+ 4 - 1
README.md

@@ -57,4 +57,7 @@
 02. 增加 : ch423s驱动;
 03. 修改 : 按照南网文件修改自动化参数;
 04. 增加 : 遥信点表点号;
-5.  增加 : led函数;
+5.  增加 : led函数;
+
+# 202601(04-11)
+01. 修改 : 开出接口;

+ 1 - 0
app_public/fuxi_public/fuxi_bsp/include/dido.h

@@ -94,6 +94,7 @@ struct do_struct
 /*------------------------------ È«¾Ö±äÁ¿ -------------------------------------
 */
 extern u8 g_di_slot;
+extern u8 g_do_slot;
 extern struct di g_di[];
 extern u8 dido_buf[128];
 extern struct di_struct g_di_st[EQU_SLOT_NUM_MAX][DIDO_MAX_DI_PER_SLOT];  

+ 8 - 6
app_public/fuxi_public/fuxi_bsp/include/equ_fuxi.h

@@ -23,19 +23,21 @@
 */
 extern int 	g_ui_freq[CFG_FREQ_NUM];	// 记录频率对应UI通道的索引值
 
-int equ_init_di(void);
+extern int equ_init_di(void);
+
+extern int equ_config_do_keeptime(void);
 
 #ifdef BSP_CAN_ENABLE
-int equ_board_info_update(int can_bus,u8 * frame);
+extern int equ_board_info_update(int can_bus,u8 * frame);
 #endif
 
-int equ_ac_channel_is_ok(u32 index);
+extern int equ_ac_channel_is_ok(u32 index);
 
-int equ_slot_check(u32 slot);
+extern int equ_slot_check(u32 slot);
 
-int equ_get_ac_slot(u32 owner, u32 type);
+extern int equ_get_ac_slot(u32 owner, u32 type);
 
-int equ_get_do_channel(u32 index);
+extern int equ_get_do_channel(u32 index);
 
 #endif //_EQU_DTU_H
 

+ 1 - 1
app_public/fuxi_public/fuxi_bsp/include/gpio.h

@@ -60,7 +60,7 @@ unsigned short gpio_di_fj(unsigned char index);
 #else
 unsigned short gpio_di_fj(void);
 #endif
-void gpio_kout_do(int on, unsigned int kout);
+int gpio_kout_do(int on, unsigned int kout);
 					
 #endif
 /*------------------------------ Îļþ½áÊø -------------------------------------

+ 13 - 34
app_public/fuxi_public/fuxi_bsp/source/dido.c

@@ -25,11 +25,7 @@
 
 /*------------------------------- 宏定义 --------------------------------------
  */
-#define DO_PWM_SW_HZ 0
-#define DO_PWM_SW_QD 1
-#define DO_PWM_SW_NULL 2
-#define DO_PWM_SW_FZ 3
-#define DO_QD_KC DO_OUT4
+#define DO_QD_KC DO_OUT_PRESET
 
 /*------------------------------ 类型结构 -------------------------------------
  */
@@ -42,10 +38,10 @@ u16 g_do_status; // 
 u32 g_do_start_time;
 int g_do_flag;
 u8 g_di_slot = 0;// 开入板卡配置槽位
+u8 g_do_slot = 0;// 开入板卡配置槽位
 
 struct di g_di[EQU_SLOT_NUM_MAX];
-struct _do g_do[EQU_SLOT_NUM_MAX];
-struct di_struct g_di_st[EQU_SLOT_NUM_MAX][DIDO_MAX_DI_PER_SLOT];
+struct _do g_do[EQU_SLOT_NUM_MAX];struct di_struct g_di_st[EQU_SLOT_NUM_MAX][DIDO_MAX_DI_PER_SLOT];
 struct do_struct g_do_st[DO_NUM];
 
 struct rt_stat g_stat_di_delay;
@@ -99,7 +95,7 @@ static inline void _io_do_status_update(int on, unsigned int i)
  */
 static int _dido_do(u32 slot, u16 v, int is_on)
 {
-    int i;
+    int i, l_ret = -1;
 
     // 循环检查开出位
     for (i = 0; i < g_board_info[slot].do_num; i++)
@@ -107,14 +103,10 @@ static int _dido_do(u32 slot, u16 v, int is_on)
         // 如果对应开出位有效,开出。
         if (((v >> i) & 0x1))
         {
-            dido_do_kz(is_on, equ_get_do_channel(i));
+            l_ret = dido_do_kz(is_on, equ_get_do_channel(i));
         }
     }
-    if (((v >> g_board_info[slot].do_num) & 0x1)) // 启动继电器
-    {
-        dido_do_kz(is_on, DO_QD_KC);
-    }
-    return 0;
+    return l_ret;
 }
 
 #if !defined CPU_FUXI
@@ -399,21 +391,6 @@ void io_do_check(void)
     {
         now |= 0x01;
     }
-#else
-    // 取返校值,必须在下面时间点检查之
-    fj = gpio_di_fj() & 0x02;
-
-    // 返回值只判断启动、分闸、合闸
-    now = 0;
-    if (g_do_status & (1 << DO_PWM_SW_QD))
-    {
-        // now |= 0x01;
-    }
-
-    if (g_do_status & ((1 << DO_PWM_SW_FZ) | (1 << DO_PWM_SW_HZ)))
-    {
-        now |= 0x02;
-    }
 #endif
     // 开出动作20ms内不进行开出自检,
     // 经实测启动继电器因为是继电器触点返校,其返回时间最长,但也小于10ms。
@@ -529,6 +506,7 @@ void dido_do_poll(void)
 void dido_qd_set_keeptime(u32 us)
 {
     g_do_st[DO_QD_KC].us_keep = us;
+    dp_err_n_c_rt("us = %ld", us);
 }
 
 #if !defined CPU_FUXI
@@ -646,11 +624,12 @@ int dido_di_is_on_ts(u8 slot, u8 index, u32 ts)
 
 int dido_do_kz(int on, unsigned int i)
 {
+    int l_ret = -1;
     if (on) // 开出,需启动启动继电器打开电源
     {
         if (i == DO_OUT0 || i == DO_OUT1 || i == DO_OUT2 || i == DO_OUT3)
         {
-            gpio_kout_do(on, DO_QD_KC - DO_OUT0); // 对应X4端子的DO0~DO7
+            l_ret = gpio_kout_do(on, DO_QD_KC - DO_OUT0);
             _io_do_status_update(1, DO_QD_KC);
         }
     }
@@ -668,19 +647,19 @@ int dido_do_kz(int on, unsigned int i)
                 return -3;
             }
         }
-        gpio_kout_do(on, i - DO_OUT0); // 对应X4端子的DO0~DO7
+        l_ret = gpio_kout_do(on, i - DO_OUT0); // 对应X4端子的DO0~DO7
         _io_do_status_update(on, i);
     }
     else if ((i >= DO_OUT0) && (i <= DO_OUT7))
     {
-        gpio_kout_do(on, i - DO_OUT0); // 对应X4端子的DO0~DO7
+        l_ret = gpio_kout_do(on, i - DO_OUT0); // 对应X4端子的DO0~DO7
         _io_do_status_update(on, i);
     }
     else
     {
-        rt_printf("dido_do_kz err(on=%d,i=%d).\r\n", on, i);
+        dp_err_n_c_rt("dido_do_kz err(on = %d, i = %d).", on, i);
     }
-    return 0;
+    return l_ret;
 }
 
 #if !defined CPU_FUXI

+ 158 - 158
app_public/fuxi_public/fuxi_bsp/source/equ_fuxi.c

@@ -59,12 +59,11 @@ s8 g_change_di_index[BOARD_TYPE_KZ_NUM][EQU_DB_YX_NUM] =
 // 开出对应关系
 static const s8 g_do_index[BOARD_TYPE_KZ_NUM][DO_NUM] = 
 {
-	{-1,-1,-1,-1-1,-1,-1,-1-1,-1,-1,-1},
+	{0, 1, 2, 3, 4, 5, 6, 7, 8, -1},
 };
 
-
 /*------------------------------ 函数声明 -------------------------------------
-*/
+ */
 unsigned int change_di_ch(unsigned int di)
 {
     register int i, rts = 0;
@@ -96,7 +95,7 @@ unsigned int change_di_ch(unsigned int di)
  * @brief          远动参数投入之后 遥信防抖时间的更新
  * @return         * int
  * @retval         none
- * 
+ *
  * @warning        none
  * @note           none
  */
@@ -118,46 +117,45 @@ int equ_config_di_yd(void)
 
 int equ_config_do_yd(void)
 {
-	#if 0
-	int i,index;
-	struct equ_config_do *ecd;
-	// 用户配置的保持时间
-	ecd = g_equ_config_do;
-	for(i=0;i<g_equ_config->do_num;i++)
-	{
-		u32 dotime=(u32)ecd->time_pulse;				
-		if(ecd->slot == EQU_SLOT_KZ)
-		{
-			// 如果定值参数中设置了分闸时间,覆盖
-			if(ecd->owner&&((ecd->type == (SW_DO_FZ+1))||(ecd->type == (SW_DO_BHT+1))||(ecd->type == (SW_DO_YKT+1))))
-			{
-				if(pRunSet->bTT_RmtPara)
-				{
-					dotime=tRunPara.wFZMC;
-				}
-			}			
-			// 如果定值参数中设置了合闸时间,覆盖
-			if(ecd->owner&&((ecd->type == (SW_DO_HZ+1))||(ecd->type == (SW_DO_BHH+1))||(ecd->type == (SW_DO_YKH+1))))
-			{
-				if(pRunSet->bTT_RmtPara)
-				{
-					dotime=tRunPara.wHZMC;
-				}
-			}
-			index = equ_get_do_channel(ecd->index);
-			g_do_st[index].us_keep = (u32)dotime;
-			g_do_st[index].us_keep *= 1000;		//ms转换为us
-		}
-		ecd++;
-	}
-	#endif
-	return 0;
+    int i, index;
+    struct equ_config_do *ecd;
+    // 用户配置的保持时间
+    ecd = g_equ_config_do;
+    for (i = 0; i < g_equ_config->do_num; i++)
+    {
+        u32 dotime = (u32)ecd->time_pulse;
+        if (ecd->slot == g_do_slot)
+        {
+            // 如果定值参数中设置了分闸时间,覆盖
+            if (ecd->owner && ((ecd->type == (SW_DO_BHT + 1)) || (ecd->type == (SW_DO_YKT + 1))))
+            {
+                if (pRunSet->bTT_RmtPara)
+                {
+                    dotime = tRunPara.wFZMC;
+                }
+            }
+            // 如果定值参数中设置了合闸时间,覆盖
+            if (ecd->owner && ((ecd->type == (SW_DO_BHH + 1)) || (ecd->type == (SW_DO_YKH + 1))))
+            {
+                if (pRunSet->bTT_RmtPara)
+                {
+                    dotime = tRunPara.wHZMC;
+                }
+            }
+            index = equ_get_do_channel(ecd->index);
+            g_do_st[index].us_keep = (u32)dotime;
+            g_do_st[index].us_keep *= 1000; // ms转换为us
+            dp_err_n_c("g_do_st[%d].us_keep = %d", index, g_do_st[index].us_keep);
+        }
+        ecd++;
+    }
+    return 0;
 }
 
 int equ_init_di(void)
 {
-	int i,ui;
-	struct equ_config_di *ecd;
+    int i, ui;
+    struct equ_config_di *ecd;
 
     // 采样板起始槽位
     g_ac_slot_begin = EQU_SLOT_AC_BEGIN;
@@ -207,17 +205,29 @@ int equ_init_di(void)
         g_di_st[ecd->slot][ecd->index].type = ecd->type;
         ecd++;
     }
+    return 0;
+}
+
+int equ_config_do_keeptime(void)
+{
+    u32 i, index;
+    struct equ_config_do *ecd;
 
-    // 找到配置为开入板的板卡号
-    for (i = 0; i < g_equ_config->equ_slot_num; i++)
+    memset(&g_do_st, 0, sizeof(struct do_struct) * DO_NUM);
+
+    // 用户配置的保持时间
+    ecd = g_equ_config_do;
+    for (i = 0; i < g_equ_config->do_num; i++)
     {
-        if (g_board_info[i].type == BOARD_TYPE_FUXI_DI)
+        if (ecd->slot == g_do_slot)
         {
-            g_di_slot = i;
-            break;
+            index = equ_get_do_channel(ecd->index);
+            g_do_st[index].us_keep = (u32)ecd->time_pulse;
+            g_do_st[index].us_keep *= 1000; // ms转换为us
         }
+        ecd++;
     }
-	// rt_printf("g_di_slot = %d\r\n", g_di_slot);
+
     return 0;
 }
 
@@ -229,61 +239,60 @@ int equ_init_di(void)
 创建日期:	2013-08-08
 函数说明:	接收到子板的对时应答帧后,更新子板信息
 参数说明:
-	can_bus 从哪条can总线接收到的帧。
-	frame	接收帧的buf指针
-返回值:	
-	0:		成功
-	其它:	失败
-修改记录:	
+    can_bus 从哪条can总线接收到的帧。
+    frame	接收帧的buf指针
+返回值:
+    0:		成功
+    其它:	失败
+修改记录:
 */
-int equ_board_info_update(int can_bus,u8 * frame)
+int equ_board_info_update(int can_bus, u8 *frame)
 {
-	struct can_frame_head 	*cfh;
-	struct board_info_frame *bif;
-	struct board_info		*bi;
-
-
-	// 检查帧内容
-	cfh = (struct can_frame_head *)frame;
-#ifdef CAN_SLAVE_BOARD	
-	if(cfh->src >= (EQU_SLOT_NUM_MAX+CAN_BOARD_NUM))
+    struct can_frame_head *cfh;
+    struct board_info_frame *bif;
+    struct board_info *bi;
+
+    // 检查帧内容
+    cfh = (struct can_frame_head *)frame;
+#ifdef CAN_SLAVE_BOARD
+    if (cfh->src >= (EQU_SLOT_NUM_MAX + CAN_BOARD_NUM))
 #else
-	if(cfh->src >= EQU_SLOT_NUM_MAX)
+    if (cfh->src >= EQU_SLOT_NUM_MAX)
 #endif
-	{
-		return -1;
-	}
+    {
+        return -1;
+    }
 
-	if(cfh->len != 8)
-	{
-		return -2;
-	}
+    if (cfh->len != 8)
+    {
+        return -2;
+    }
 
-	// 比较子板类型
-	bi = &g_board_info[cfh->src];
-	bif = (struct board_info_frame *)(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);
-	//	print_mem("frame",frame,16);
-		return -3;
-	}
+    // 比较子板类型
+    bi = &g_board_info[cfh->src];
+    bif = (struct board_info_frame *)(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);
+        //	print_mem("frame",frame,16);
+        return -3;
+    }
 
-	// 得到子板信息
-	bi->status  = bif->status;
-	bi->errcode = bif->errcode;
-	bi->crc 	= bif->crc;
-	bi->version = bif->version;
-	//rt_printf("%02d\t%02d\t%02d\t%04x\t%08x\t",bi->type,bi->status,bi->errcode,bi->crc,bi->version);
+    // 得到子板信息
+    bi->status = bif->status;
+    bi->errcode = bif->errcode;
+    bi->crc = bif->crc;
+    bi->version = bif->version;
+    // rt_printf("%02d\t%02d\t%02d\t%04x\t%08x\t",bi->type,bi->status,bi->errcode,bi->crc,bi->version);
 
-	// 得到子板时间
-	clk_time_get(&bi->update_time);
-	bi->us0 = ustimer_get_origin();
-	bi->is_ok = 1;
+    // 得到子板时间
+    clk_time_get(&bi->update_time);
+    bi->us0 = ustimer_get_origin();
+    bi->is_ok = 1;
 
-	bi->can_bus = can_bus;
+    bi->can_bus = can_bus;
 
-	return 0;
+    return 0;
 }
 #endif
 
@@ -294,25 +303,24 @@ int equ_board_info_update(int can_bus,u8 * frame)
 创建日期:	2013-08-08
 函数说明:	得到插槽中子板的模拟量通道对应的ADC采样通道。
 参数说明:
-	slot	插槽索引号
-	index	子板上模拟量通道索引号
+    slot	插槽索引号
+    index	子板上模拟量通道索引号
 返回值:	ADC采样通道索引号
-修改记录:	
+修改记录:
 */
 int equ_ac_channel_is_ok(u32 index)
 {
-	// 检查参数
-	if(index >= CFG_ADC_CHANNEL)
-	{
-		return 0;
-	}
+    // 检查参数
+    if (index >= CFG_ADC_CHANNEL)
+    {
+        return 0;
+    }
 
-	//  直接返回ok 板卡没有配置检测io
-	return 1;
-//	return g_ac_slot_is_ok[index/EQU_SLOT_AC_CHN];
+    //  直接返回ok 板卡没有配置检测io
+    return 1;
+    //	return g_ac_slot_is_ok[index/EQU_SLOT_AC_CHN];
 }
 
-
 /******************************************************************************
 函数名称:	equ_get_ac_channel
 函数版本:	01.01
@@ -320,27 +328,27 @@ int equ_ac_channel_is_ok(u32 index)
 创建日期:	2013-08-08
 函数说明:	得到插槽中子板的模拟量通道对应的ADC采样通道。
 参数说明:
-	slot	插槽索引号
-	index	子板上模拟量通道索引号
+    slot	插槽索引号
+    index	子板上模拟量通道索引号
 返回值:	ADC采样通道索引号
-修改记录:	
+修改记录:
 */
-int equ_get_ac_channel(u32 slot,u32 index)
+int equ_get_ac_channel(u32 slot, u32 index)
 {
-	// 检查参数
+    // 检查参数
 #if (0) /* 不检查 插槽索引号 lch 2025年12月5日17:29:28 */
-	if(slot != BOARD_TYPE_FUXI_AC)
-	{
-		return -1;
-	}
+    if (slot != BOARD_TYPE_FUXI_AC)
+    {
+        return -1;
+    }
 #endif
 
-	if(index >= CFG_ADC_CHANNEL)
-	{
-		return -2;
-	}
+    if (index >= CFG_ADC_CHANNEL)
+    {
+        return -2;
+    }
 
-	return g_ac_index[g_brd_type_kz][index];
+    return g_ac_index[g_brd_type_kz][index];
 }
 
 /******************************************************************************
@@ -350,23 +358,23 @@ int equ_get_ac_channel(u32 slot,u32 index)
 创建日期:	2014-10-09
 函数说明:	得到采样通道对应的板卡
 参数说明:
-	owner	归属公共、开关
-	type	采样类型
+    owner	归属公共、开关
+    type	采样类型
 返回值:	ADC采样通道索引号
-修改记录:	
+修改记录:
 */
 int equ_get_ac_slot(u32 owner, u32 type)
 {
-	u32 no;
-	if (owner)
-	{
-		no = g_sw[owner].ac_cfg_index[type];
-	}
-	else
-	{
-		no = g_sw_pub.ac_cfg_index[type];
-	}
-	return g_equ_config_ac[no].slot;
+    u32 no;
+    if (owner)
+    {
+        no = g_sw[owner].ac_cfg_index[type];
+    }
+    else
+    {
+        no = g_sw_pub.ac_cfg_index[type];
+    }
+    return g_equ_config_ac[no].slot;
 }
 
 /******************************************************************************
@@ -376,18 +384,18 @@ int equ_get_ac_slot(u32 owner, u32 type)
 创建日期:	2013-08-08
 函数说明:	将采样板索引号(和ADC通道号对应)转换为插槽号。
 参数说明:
-	ac_index	采样板索引号
+    ac_index	采样板索引号
 返回值:	插槽号
-修改记录:	
+修改记录:
 */
 int equ_ac_index_to_slot(int ac_index)
 {
-	if((u32)ac_index >= EQU_SLOT_AC_NUM)
-	{
-		return 0;
-	}	
+    if ((u32)ac_index >= EQU_SLOT_AC_NUM)
+    {
+        return 0;
+    }
 
-	return g_ac_index_to_slot[ac_index];
+    return g_ac_index_to_slot[ac_index];
 }
 
 /******************************************************************************
@@ -397,15 +405,15 @@ int equ_ac_index_to_slot(int ac_index)
 创建日期:	2013-08-08
 函数说明:	配置子板上的开出资源
 参数说明:
-	slot	插槽索引号
+    slot	插槽索引号
 返回值:	插槽号
-	0:		成功
-	其它:	失败
-修改记录:	
+    0:		成功
+    其它:	失败
+修改记录:
 */
 int equ_get_do_channel(u32 index)
 {
-	return g_do_index[g_brd_type_kz][index];
+    return g_do_index[g_brd_type_kz][index];
 }
 
 #ifdef CPU_FUXI
@@ -416,14 +424,14 @@ int equ_get_do_channel(u32 index)
  * @date           20251222
  * @return         * int
  * @retval         none
- * 
+ *
  * @warning        none
  * @note           none
  */
 int equ_init_rv_di(void)
 {
-	struct t_shmdata_di_astime t_di_cfg = {0};
-	struct equ_config_di *ecd;
+    struct t_shmdata_di_astime t_di_cfg = {0};
+    struct equ_config_di *ecd;
 
     ecd = g_equ_config_di;
     // rt_printf("g_equ_config->di_num = %d\r\n", g_equ_config->di_num);
@@ -432,7 +440,7 @@ int equ_init_rv_di(void)
         t_di_cfg.us_as_time[i] = ecd->filter_time;
         ecd++;
     }
-	return shm_packet_write_v2(SHM_ADDR_R_DI_ASTIME, (uint8_t *)&t_di_cfg, sizeof(struct t_shmdata_di_astime));
+    return shm_packet_write_v2(SHM_ADDR_R_DI_ASTIME, (uint8_t *)&t_di_cfg, sizeof(struct t_shmdata_di_astime));
 }
 
 /**
@@ -442,37 +450,29 @@ int equ_init_rv_di(void)
  * @date           20251222
  * @return         * int
  * @retval         none
- * 
+ *
  * @warning        none
  * @note           none
  */
 int equ_reinit_rv_di(void)
 {
-	struct t_shmdata_di_astime t_di_cfg = {0};
+    struct t_shmdata_di_astime t_di_cfg = {0};
     for (int i = 0; i < g_equ_config->di_num; i++)
     {
         t_di_cfg.us_as_time[i] = tRunPara.wYXFD;
     }
-	return shm_packet_write_v2(SHM_ADDR_R_DI_ASTIME, (uint8_t *)&t_di_cfg, sizeof(struct t_shmdata_di_astime));
+    return shm_packet_write_v2(SHM_ADDR_R_DI_ASTIME, (uint8_t *)&t_di_cfg, sizeof(struct t_shmdata_di_astime));
 }
 #endif
 
-
-
-
-
 /*------------------------------ 内部函数 -------------------------------------
 内部函数以下划线‘_’开头,不需要检查参数的合法性.
 */
 
-
 /*------------------------------ 测试函数 -------------------------------------
 一个实体文件必须带一个本模块的测试函数来进行单元测试,如果的确不方便在本模块中
 进行单元测试,必须在此注明实际的测试位置(例如在哪个实体文件中使用哪个测试函数).
 */
 
-
 /*------------------------------ 文件结束 -------------------------------------
-*/
-
-
+ */

+ 113 - 77
app_public/fuxi_public/fuxi_bsp/source/gpio.c

@@ -43,6 +43,8 @@ T536 end   
 
 #endif
 
+#define GPIO_LOW 0
+
 /*------------------------------ 全局变量 -------------------------------------
  */
 typedef enum
@@ -205,7 +207,6 @@ int sysfs_gpio_set_value(int gpio, int value)
 
 int sysfs_gpio_init(int gpio, int direction)
 {
-#define GPIO_LOW 0
     int ret;
     ret = sysfs_gpio_export(gpio);
     if (ret < 0)
@@ -240,7 +241,6 @@ int rt_write(int fd, char *buf, int len)
     {
         return -1;
     }
-
     if (is_rtdm_device(fd) == 1)
     {
         // Xenomai RTDM设备:需要转换为二进制值
@@ -259,9 +259,69 @@ int rt_write(int fd, char *buf, int len)
     }
 }
 
+int rt_read(int fd, char *buf, int len)
+{
+    int ret = 0;
+    
+    if (is_rtdm_device(fd) == 1)
+    {
+        dp_info_n_c("fd = %d", fd);
+        // Xenomai RTDM设备:读取二进制值
+        int value = 0;
+        
+        // 从RTDM设备读取二进制状态(通常是4字节的int)
+        ret = read(fd, &value, sizeof(value));
+        dp_info_n_c("ret = %d", ret);
+        if (ret != sizeof(value))
+        {
+            dp_err_n_c("Failed to read from RTDM device, ret=%d", ret);
+            return -1;
+        }
+        
+        // 将二进制值转换为字符'0'或'1'
+        if (value == 0)
+        {
+            buf[0] = '0';
+        }
+        else if (value == 1)
+        {
+            buf[0] = '1';
+        }
+        else
+        {
+            dp_err_n_c("Unexpected value from RTDM device: %d", value);
+            return -1;
+        }
+        
+        buf[1] = '\0';  // 字符串结束符
+        return 1;       // 读取到的字符数
+    }
+    else
+    {
+        // 常规系统设备:直接读取字符串
+        ret = read(fd, buf, len);
+        dp_err_n_c("ret=%d", ret);
+        if (ret < 0)
+        {
+            dp_err_n_c("Failed to read from regular device");
+            return -1;
+        }
+        
+        buf[ret] = '\0';  // 确保字符串正确结束
+        
+        // 移除可能的换行符
+        if (ret > 0 && buf[ret - 1] == '\n')
+        {
+            buf[ret - 1] = '\0';
+            ret--;
+        }
+        
+        return ret;  // 返回读取的字符数
+    }
+}
+
 int rtdm_gpio_init(int gpio, int direction)
 {
-#define GPIO_LOW 0
     char path[64];
     int fd = -1, ret;
     int value = 1;
@@ -275,6 +335,7 @@ int rtdm_gpio_init(int gpio, int direction)
 
     if (113 == gpio) /* 预置返校是开入 */
     {
+        dp_info_n_c("gpio = %d, fd = %d", gpio, fd);
         ret = ioctl(fd, GPIO_RTIOC_DIR_IN, &value);
     }
     else
@@ -288,7 +349,6 @@ int rtdm_gpio_init(int gpio, int direction)
         return -1;
     }
 
-    rt_write(gpio_val_fd[DO_OUT0], "0", 2); // 初始化IO为低电平
     return fd;
 }
 
@@ -303,6 +363,7 @@ int gpio_init(void)
         if (gpio_val_fd[i] < 0)
         {
             gpio_val_fd[i] = sysfs_gpio_init(gpio_val[i], GPIO_OUTPUT);
+            dp_info_n_c("gpio_val_fd[%02d] = %d", i, gpio_val_fd[i]);
             if (gpio_val_fd[i] < 0)
             {
                 dp_err_n_c("gpio_val_fd[%d] error", i);
@@ -323,7 +384,7 @@ int gpio_init(void)
 
     for (i = DO_OUT1; i < DO_NUM; i++)
     {
-        write(gpio_val_fd[i], "1", 2);
+        rt_write(gpio_val_fd[i], "1", 2);
     }
 
     return 0;
@@ -388,11 +449,9 @@ unsigned short gpio_di_fj(void)
 
     di = gpio_get_di();
 #ifdef DO_KOUT_CHECK
-    // V4-20;
-    // ret = (unsigned short)((di >>19) & 0x0001);
     ret = (unsigned short)((di >> index) & 0x0001);
 #else
-    ret = (unsigned short)((di >> 23) & 0x0001); // dtu
+    ret = (unsigned short)((di >> 23) & 0x0001);
 #endif
     return ret;
 }
@@ -440,19 +499,23 @@ int gpioio_get_perset_status(void)
 返回值:  无
 修改记录:
 */
-void gpio_kout_do(int on, unsigned int kout)
+int gpio_kout_do(int on, unsigned int kout)
 {
-    if (kout > (DO_NUM - DO_OUT_PRESET))
+    int l_ret = -1;
+    if (kout > DO_OUT_PRESET)
         return;
 
     if (on)
     {
-        write(gpio_val_fd[kout + DO_OUT0], "0", 2);
+        l_ret = rt_write(gpio_val_fd[kout + DO_OUT0], "0", 2);
+        // dp_info_n_c("kout = %d, on = %d, l_ret = %d", kout, on, l_ret);
     }
     else
     {
-        write(gpio_val_fd[kout + DO_OUT0], "1", 2);
+        l_ret = rt_write(gpio_val_fd[kout + DO_OUT0], "1", 2);
+        // dp_info_n_c("kout = %d, on = %d, l_ret = %d", kout, on, l_ret);
     }
+    return l_ret;
 }
 
 /******************************************************************************
@@ -539,100 +602,73 @@ void esam_power_ctrl(int on)
 #include "ustimer.h"
 #include "rt.h"
 
-int gpio_test(void)
-{
-    int ret = 0;
-    // unsigned int i;
-
-#if 1
-    while (1)
-    {
-
-        sleep(5);
-
-        gpio_kout_do(1, DO_OUT2 - DO_OUT0);
-        // gpio_kout_do(1,DO_OUT3-DO_OUT0);
-
-        sleep(5);
-
-        gpio_kout_do(0, DO_OUT2 - DO_OUT0);
-        // gpio_kout_do(0,DO_OUT3-DO_OUT0);
-
-        /*
-
-                for(i=DO_OUT0; i<DO_NUM; i++)
-                {
-                    rt_printf("kout number = %d!\r", i);
-                    //msleep();
-                    sleep(1);
-                    gpio_kout_do(1,i-DO_OUT0);
-                    sleep(1);
-                    gpio_kout_do(0,i-DO_OUT0);
-
-
-                }
-        */
-    }
-#endif
-    return ret;
-}
-
 int test_kc_function(void)
 {
-    write(gpio_val_fd[DO_OUT_PRESET], "0", 2); // 预置动作
+    rt_write(gpio_val_fd[DO_OUT_PRESET], "0", 2); // 预置动作
     char gpio_state[2];
     int ret;
+    sleep(1);
 
+#if (1)
     // 读取GPIO状态
-    ret = read(gpio_val_fd[DO_IN_PRESET], gpio_state, sizeof(gpio_state));
+    ret = rt_read(gpio_val_fd[DO_IN_PRESET], gpio_state, sizeof(gpio_state));
     printf("ret: %d\n", ret);
     if (ret > 0)
     {
         gpio_state[ret] = '\0';             // 添加字符串结束符
         printf("PRESET: %s\n", gpio_state); // 应该是"0"或"1"
     }
-
-    write(gpio_val_fd[DO_OUT0], "0", 2);
+#endif
+    rt_write(gpio_val_fd[DO_OUT0], "0", 2);
     sleep(1);
-    write(gpio_val_fd[DO_OUT0], "1", 2);
+    rt_write(gpio_val_fd[DO_OUT0], "1", 2);
 
-    write(gpio_val_fd[DO_OUT1], "0", 2);
+    rt_write(gpio_val_fd[DO_OUT1], "0", 2);
     sleep(1);
-    write(gpio_val_fd[DO_OUT1], "1", 2);
+    rt_write(gpio_val_fd[DO_OUT1], "1", 2);
 
-    write(gpio_val_fd[DO_OUT2], "0", 2);
-    sleep(1);
-    write(gpio_val_fd[DO_OUT2], "1", 2);
+#if (0)
 
-    write(gpio_val_fd[DO_OUT3], "0", 2);
-    sleep(1);
-    write(gpio_val_fd[DO_OUT3], "1", 2);
+    rt_write(gpio_val_fd[DO_OUT2], "0", 2);
+    sleep(5);
+    rt_write(gpio_val_fd[DO_OUT2], "1", 2);
+
+    rt_write(gpio_val_fd[DO_OUT3], "0", 2);
+    sleep(5);
+    rt_write(gpio_val_fd[DO_OUT3], "1", 2);
+#endif
 
-    write(gpio_val_fd[DO_OUT_PRESET], "1", 2); // 预置动作
+    rt_write(gpio_val_fd[DO_OUT_PRESET], "1", 2); // 预置动作
+    sleep(1);
+    
+#if (1)
     // 读取GPIO状态
-    ret = read(gpio_val_fd[DO_IN_PRESET], gpio_state, sizeof(gpio_state));
+    ret = rt_read(gpio_val_fd[DO_IN_PRESET], gpio_state, sizeof(gpio_state));
     printf("ret: %d\n", ret);
     if (ret > 0)
     {
         gpio_state[ret] = '\0';             // 添加字符串结束符
         printf("PRESET: %s\n", gpio_state); // 应该是"0"或"1"
     }
+#endif
 
-    write(gpio_val_fd[DO_OUT4], "0", 2);
-    sleep(1);
-    write(gpio_val_fd[DO_OUT4], "1", 2);
+#if (0)
+    rt_write(gpio_val_fd[DO_OUT4], "0", 2);
+    sleep(5);
+    rt_write(gpio_val_fd[DO_OUT4], "1", 2);
 
-    write(gpio_val_fd[DO_OUT5], "0", 2);
-    sleep(1);
-    write(gpio_val_fd[DO_OUT5], "1", 2);
+    rt_write(gpio_val_fd[DO_OUT5], "0", 2);
+    sleep(5);
+    rt_write(gpio_val_fd[DO_OUT5], "1", 2);
 
-    write(gpio_val_fd[DO_OUT6], "0", 2);
-    sleep(1);
-    write(gpio_val_fd[DO_OUT6], "1", 2);
+    rt_write(gpio_val_fd[DO_OUT6], "0", 2);
+    sleep(5);
+    rt_write(gpio_val_fd[DO_OUT6], "1", 2);
 
-    write(gpio_val_fd[DO_OUT7], "0", 2);
-    sleep(1);
-    write(gpio_val_fd[DO_OUT7], "1", 2);
+    rt_write(gpio_val_fd[DO_OUT7], "0", 2);
+    sleep(5);
+    rt_write(gpio_val_fd[DO_OUT7], "1", 2);
+#endif
 }
 
 #endif

文件差异内容过多而无法显示
+ 1609 - 1680
dtu/dtu_main_t536/app/FA_g.c


+ 22 - 17
dtu/dtu_main_t536/app/Sys.c

@@ -1059,12 +1059,14 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
         if (g_yk_info[index].owner > 0)
         {
             owner = g_yk_info[index].owner - 1;
-            if (g_yk_info[index].no == (SW_DO_HZ + 1) || g_yk_info[index].no == (SW_DO_YKH + 1) || g_yk_info[index].no == (SW_DO_BHH + 1))
+            if (g_yk_info[index].no == (SW_DO_YKH + 1) ||
+                g_yk_info[index].no == (SW_DO_BHH + 1))
             {
                 g_tRelay[owner].uRmtSW.bYHExecute = false;
                 g_tRelay[owner].uRmtSW.bYHExecute_fa = false;
             }
-            if (g_yk_info[index].no == (SW_DO_FZ + 1) || g_yk_info[index].no == (SW_DO_YKT + 1) || g_yk_info[index].no == (SW_DO_BHT + 1))
+            if (g_yk_info[index].no == (SW_DO_YKT + 1) ||
+                g_yk_info[index].no == (SW_DO_BHT + 1))
             {
                 g_tRelay[owner].uRmtSW.bYTExecute = false;
                 g_tRelay[owner].uRmtSW.bYTExecute_fa = false;
@@ -1154,7 +1156,6 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
 #ifdef FUNC_DRIVE
                 else if (no == PUB_DRIVE_HZ + 1)
                 {
-                    ;
                 }
 #endif
 #ifdef FUNC_DRIVE_JY
@@ -1201,6 +1202,7 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
                 if (owner > g_sw_num || no > SW_DO_NUM)
                 {
                     // 超范围
+                    dp_err_n_c("owner = %d, no = %d, g_sw_num = %d, SW_DO_NUM = %d, ", owner, no, g_sw_num, SW_DO_NUM);
                     return -9;
                 }
                 else if ((no == SW_DO_BHH + 1) || (no == SW_DO_BHT + 1))
@@ -1208,25 +1210,25 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
                     return -9;
                 }
 #ifdef YK_SOFT_YB
-                else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_TZ && (no == SW_DO_YKT + 1 || no == SW_DO_FZ + 1))
+                else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_TZ && no == SW_DO_YKT + 1)
                 {
                     return -26;
                 }
-                else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_HZ && (no == SW_DO_YKH + 1 || no == SW_DO_HZ + 1))
+                else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_HZ && no == SW_DO_YKH + 1)
                 {
                     return -26;
                 }
 #endif
-                else if ((fa_bs_fz(owner - 1) || pR->bBSTZ) && ykval == YK_VAL_TZ && (no == SW_DO_YKT + 1 || no == SW_DO_FZ + 1))
+                else if ((fa_bs_fz(owner - 1) || pR->bBSTZ) && ykval == YK_VAL_TZ && no == SW_DO_YKT + 1)
                 {
                     // rt_printf("遮断闭锁,禁止分闸操作\r\n");
                     return -24;
                 }
-                else if (fa_bs_hz(owner - 1) && ykval == YK_VAL_HZ && (no == SW_DO_YKH + 1 || no == SW_DO_HZ + 1))
+                else if (fa_bs_hz(owner - 1) && ykval == YK_VAL_HZ && no == SW_DO_YKH + 1)
                 {
                     return -25;
                 }
-                else if (pR->run_stu.wcn && pRunSet->tSwSet[owner - 1].bTT_WCN && ykval == YK_VAL_HZ && (no == SW_DO_YKH + 1 || no == SW_DO_HZ + 1))
+                else if (pR->run_stu.wcn && pRunSet->tSwSet[owner - 1].bTT_WCN && ykval == YK_VAL_HZ && no == SW_DO_YKH + 1)
                 {
                     return -27;
                 }
@@ -1544,16 +1546,16 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
                     return -1;
                 }
 #ifdef YK_SOFT_YB
-                else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_HZ && (no == SW_DO_YKH + 1 || no == SW_DO_HZ + 1))
+                else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_HZ && no == SW_DO_YKH + 1)
                 {
                     return -26;
                 }
 #endif
-                else if (fa_bs_hz(owner - 1) && ykval == YK_VAL_HZ && (no == SW_DO_YKH + 1 || no == SW_DO_HZ + 1))
+                else if (fa_bs_hz(owner - 1) && ykval == YK_VAL_HZ && no == SW_DO_YKH + 1)
                 {
                     return -25;
                 }
-                else if (pR->run_stu.wcn && pRunSet->tSwSet[owner - 1].bTT_WCN && ykval == YK_VAL_HZ && (no == SW_DO_YKH + 1 || no == SW_DO_HZ + 1))
+                else if (pR->run_stu.wcn && pRunSet->tSwSet[owner - 1].bTT_WCN && ykval == YK_VAL_HZ && no == SW_DO_YKH + 1)
                 {
                     return -27;
                 }
@@ -1788,6 +1790,7 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
             else
             {
                 ret = sw_do_pub(no - 1, SW_DO_TYPE_ON);
+                dp_err_n_c("no = %dret = %d", no, no);
             }
         }
         // 线路开出执行
@@ -1805,7 +1808,7 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
                 {
                     return -1;
                 }
-                if ((no == SW_DO_HZ + 1) || (no == SW_DO_YKH + 1))
+                if ((no == SW_DO_YKH + 1))
                 {
                     if (g_tRelay[owner - 1].uBHDZ.bFlag.bBHT) // 正在保护出口,退出
                     {
@@ -1817,14 +1820,14 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
                         return 0;
                     }
                 }
-                if ((no == SW_DO_FZ + 1) || (no == SW_DO_YKT + 1))
+                if ((no == SW_DO_YKT + 1))
                 {
                     if (g_tRelay[owner - 1].tCHZ.sta.bFlag.bHz) // 正在重合闸出口,退出
                     {
                         return -17;
                     }
 #ifdef YK_SOFT_YB
-                    else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_TZ && (no == SW_DO_YKT + 1 || no == SW_DO_FZ + 1))
+                    else if (!pRunSet->bTT_SOFT_YK_YB && ykval == YK_VAL_TZ && no == SW_DO_YKT + 1)
                     {
                         return -26;
                     }
@@ -1846,7 +1849,7 @@ int _RemoteCtrl(BYTE yktype, BYTE index, BYTE ykval, WORD wID)
                     ret = BZT_ManualOnOffHandle(owner - 1, no - 1);
                 }
 #else
-            ret = sw_do(owner - 1, no - 1, SW_DO_TYPE_ON);
+                ret = sw_do(owner - 1, no - 1, SW_DO_TYPE_ON);
 #endif
                 if (ret == 0)
                 {
@@ -2305,12 +2308,14 @@ static void _yk_polling(void)
                 if (g_yk_info[i].owner > 0)
                 {
                     int owner = g_yk_info[i].owner - 1;
-                    if ((g_yk_info[i].no == (SW_DO_HZ + 1)) || (g_yk_info[i].no == (SW_DO_YKH + 1)) || (g_yk_info[i].no == (SW_DO_BHH + 1)))
+                    if ((g_yk_info[i].no == (SW_DO_YKH + 1)) ||
+                        (g_yk_info[i].no == (SW_DO_BHH + 1)))
                     {
                         g_tRelay[owner].uRmtSW.bYHExecute = false;
                         g_tRelay[owner].uRmtSW.bYHExecute_fa = false;
                     }
-                    if ((g_yk_info[i].no == (SW_DO_FZ + 1)) || (g_yk_info[i].no == (SW_DO_YKT + 1)) || (g_yk_info[i].no == (SW_DO_BHT + 1)))
+                    if ((g_yk_info[i].no == (SW_DO_YKT + 1)) ||
+                        (g_yk_info[i].no == (SW_DO_BHT + 1)))
                     {
                         g_tRelay[owner].uRmtSW.bYTExecute = false;
                         g_tRelay[owner].uRmtSW.bYTExecute_fa = false;

+ 2 - 2
dtu/dtu_main_t536/app/Sys.h

@@ -151,8 +151,8 @@ enum
 {
 	YK_VAL_HZ=1,
 	YK_VAL_TZ,
-	YK_TYPE_SEL,
-	YK_TYPE_EXE,
+	YK_TYPE_SEL, // Ñ¡Ôñ
+	YK_TYPE_EXE, // Ö´ÐÐ
 	YK_TYPE_CANCEL,	
 };
 

文件差异内容过多而无法显示
+ 574 - 575
dtu/dtu_main_t536/app/battery.c


+ 1 - 7
dtu/dtu_main_t536/app/bzt.c

@@ -989,13 +989,11 @@ void Out_BZT_ZTTZ(int sw,     bool bState,BYTE dl_x)
 				}
 				if(pRunSet->tSwSet[sw].bZF)
 				{
-					sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);	
 					sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);
 				}
 				else
 				{
 					sw_do(sw,SW_DO_DL1_FZ,SW_DO_TYPE_ON);
-					sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);
 				}
 				uBZT->bBZT.auto_tz = 1;
 #ifdef BZT_PRINTF_DEBUG					
@@ -1010,7 +1008,6 @@ void Out_BZT_ZTTZ(int sw,     bool bState,BYTE dl_x)
 				}
 				if(pRunSet->tSwSet[sw].bZF)
 				{
-					sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);	
 					sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);	
 				}
 				else
@@ -1090,14 +1087,12 @@ void Out_BZT_ZTHZ(int sw, bool bState,BYTE dl_x)
 					soe_record_ev(EV_ZT_HZ1+sw*EV_SW_NUM, 1, 0,0,0 );
 				}
 				if(pRunSet->tSwSet[sw].bZF)
-				{
-					sw_do(sw,SW_DO_HZ,SW_DO_TYPE_ON);		
+				{	
 					sw_do(sw,SW_DO_BHH,SW_DO_TYPE_ON);	
 				}
 				else
 				{
 					sw_do(sw,SW_DO_DL1_HZ,SW_DO_TYPE_ON);
-					sw_do(sw,SW_DO_HZ,SW_DO_TYPE_ON);
 				}
 #ifdef BZT_PRINTF_DEBUG					
 				rt_printf("\r\n #1Ïß·ºÏÕ¢");
@@ -1111,7 +1106,6 @@ void Out_BZT_ZTHZ(int sw, bool bState,BYTE dl_x)
 				}
 				if(pRunSet->tSwSet[sw].bZF)
 				{
-					sw_do(sw,SW_DO_HZ,SW_DO_TYPE_ON);	
 					sw_do(sw,SW_DO_BHH,SW_DO_TYPE_ON);	
 				}
 				else		

+ 3 - 2
dtu/dtu_main_t536/app/defineSys.h

@@ -12,7 +12,7 @@
 #ifndef _DEFINE_SYS_H
 #define _DEFINE_SYS_H
 
-#define DEVICE_VERSION_INFORMATION "NW24_20251231_005" // NW2022意思是按照22年南网标准文件(总调)来做的
+#define DEVICE_VERSION_INFORMATION "NW24_20260104_008" // NW2022意思是按照22年南网标准文件(总调)来做的
 
 #ifdef ___defineSys____//!!!此宏定义不开启,以下宏不直接开启,只用于注释显示
 
@@ -31,6 +31,7 @@
 #define YX_DI_ERROR                    // 遥信硬件自检错误
 #define HISTORY_DB                     // 历史文件数据库
 #define DO_KOUT_CHECK                  // 开出反校
+#define DO_KOUT_CHECK_PRESET           // 开出反校 单预置
 #define YB_STHD_CHECK                  // 软硬压板不对应检测
 #define FA_OC_COUNT                    // FA 过流脉冲计数功能
 #define YK_SOFT_YB                     // 遥控软压板
@@ -136,8 +137,8 @@
 #define FUNC_MORE_PRESET               // 支持遥调时多次预置,固化
 #define FUNC_PRINT_PT_ERR              // PT断线时应报相关打印信息
 #define SOE_PARA_ALL_SAVE              // 故障断面所有遥测全部显示
-#define DO_KOUT_CHECK                  // 开出反校
 #define IO_CHIP_CH423S                 // 扩展IO芯片
+#define DO_KOUT_CHECK_PRESET           // 开出反校 单预置
 
 //区分地区&客户个性化需求定义
 #if defined  GD_AREA_ECZD_2020    	//2020广东配网终端二次功能指导意见

+ 126 - 121
dtu/dtu_main_t536/app/equ.c

@@ -196,138 +196,134 @@ int equ_init_file_brd_res(void)
 */
 int equ_init_file_config(void)
 {
-	u32 len,i;
+    u32 len, i;
 
-	u8 *buf;
-	struct file * pfile;
-	loff_t pos;
-	struct equ_config 	*ec;
+    u8 *buf;
+    struct file *pfile;
+    loff_t pos;
+    struct equ_config *ec;
 
-	// 打开文件
-	pfile = rt_file_open("/app/data/equ_cfg.bin",O_RDONLY ,0);
-	if(IS_ERR(pfile))
-	{
-		return -1;
-	}
+    // 打开文件
+    pfile = rt_file_open("/app/data/equ_cfg.bin", O_RDONLY, 0);
+    if (IS_ERR(pfile))
+    {
+        return -1;
+    }
 
-	// 得到文件长度
-	len = rt_file_getfile_size(pfile);
-	if(len < sizeof(struct equ_config) + 2)
-	{
-		rt_file_close(pfile,0);
-		return -11; 	
-	}
-	
-	// 分配内存
-	buf = rt_malloc(len);
-	if((buf) == NULL)
-	{
-		rt_file_close(pfile,0);
-		return -2; 	
-	}
+    // 得到文件长度
+    len = rt_file_getfile_size(pfile);
+    if (len < sizeof(struct equ_config) + 2)
+    {
+        rt_file_close(pfile, 0);
+        return -11;
+    }
 
-	// 读出内容
-	pos = 0;
-	if(rt_file_read(pfile,buf,len,&pos) != len)
-	{
-		rt_file_close(pfile,0);
-		rt_free(buf);
-		return -3;
-	}
+    // 分配内存
+    buf = rt_malloc(len);
+    if ((buf) == NULL)
+    {
+        rt_file_close(pfile, 0);
+        return -2;
+    }
 
-	// 关闭文件
-	rt_file_close(pfile,0);
+    // 读出内容
+    pos = 0;
+    if (rt_file_read(pfile, buf, len, &pos) != len)
+    {
+        rt_file_close(pfile, 0);
+        rt_free(buf);
+        return -3;
+    }
 
-	// 检查CRC
-	g_crc_equ_cfg = CrcStr(buf,len-2);
-	if(g_crc_equ_cfg != *(u16*)(buf+len-2))
-	{
-		rt_free(buf);
-		return -4;
-	}
+    // 关闭文件
+    rt_file_close(pfile, 0);
 
-	// 检查文件签名
-	ec = (struct equ_config *)buf;
-	if(ec->cfh.signature != SIG_EQU_CFG_FILE)
-	{
-		rt_free(buf);
-		return -5;
-	}
+    // 检查CRC
+    g_crc_equ_cfg = CrcStr(buf, len - 2);
+    if (g_crc_equ_cfg != *(u16 *)(buf + len - 2))
+    {
+        rt_free(buf);
+        return -4;
+    }
 
-	// 文件比较内容赋值
- 	g_equ_contrast.version = ec->cfh.version;
-	g_equ_contrast.signature = ec->cfh.signature;
-	g_equ_contrast.length = len;
-	g_equ_contrast.crc = g_crc_equ_cfg;
-
-	//比对资源表文件
-	if ((ec->rsc_version != rsc_contrast.version)
-	|| (ec->rsc_signature != rsc_contrast.signature)
-	|| (ec->rsc_length != rsc_contrast.length)
-	|| (ec->rsc_crc != rsc_contrast.crc))
-	{
-		rt_printf("equ_version = 0x%x, rsc_version = 0x%x\r\n",ec->rsc_version, rsc_contrast.version);
-		rt_printf("equ_signature = 0x%x, rsc_signature = 0x%x\r\n",ec->rsc_signature, rsc_contrast.signature);
-		rt_printf("equ_length = 0x%x, rsc_length = 0x%x\r\n",ec->rsc_length, rsc_contrast.length);
-		rt_printf("equ_crc = 0x%x, rsc_crc = 0x%x\r\n",ec->rsc_crc, rsc_contrast.crc);
-		
-		rt_free(buf);
-		return -6;
-	}
-	
-	// 装载配置
-	g_equ_config   = ec;
-	g_equ_config_di = (struct equ_config_di *)(buf + g_equ_config->di_addr);
-	g_equ_config_do = (struct equ_config_do *)(buf + g_equ_config->do_addr);
-	g_equ_config_ac = (struct equ_config_ac *)(buf + g_equ_config->ac_addr);
-
-	// 得到开关数量
-	 g_sw_num = 0;
-	 for(i=0;i<g_equ_config->di_num;i++)
-	 {
-	 	if(g_equ_config_di[i].owner > g_sw_num && g_equ_config_di[i].index )
-	 	{
-	 		g_sw_num = g_equ_config_di[i].owner;
-	 	}
-	 }
-	 for(i=0;i<g_equ_config->do_num;i++)
-	 {
-	 	if(g_equ_config_do[i].owner > g_sw_num && g_equ_config_do[i].index )
-	 	{
-	 		g_sw_num = g_equ_config_do[i].owner;
-	 	}
-	 }
-	 for(i=0;i<g_equ_config->ac_num;i++)
-	 {
-		 if( g_equ_config_ac[i].type == 0)
-		{
-			continue;
-		}
-		 
-	 	if(g_equ_config_ac[i].owner > g_sw_num && g_equ_config_ac[i].index )
-	 	{
-	 		g_sw_num = g_equ_config_ac[i].owner;
-	 	}
-	 	
-		if( g_equ_config_ac[i].owner == 0)
-		{
-			g_pub_ac_num++;
-		}
-	 	else
-		{
-			g_sw_ac_num[ g_equ_config_ac[i].owner-1]++;
-	 	}
-		g_sw_ac_num[SWITCH_NUM_MAX]++;//总配置数
+    // 检查文件签名
+    ec = (struct equ_config *)buf;
+    if (ec->cfh.signature != SIG_EQU_CFG_FILE)
+    {
+        rt_free(buf);
+        return -5;
+    }
 
-	 }
+    // 文件比较内容赋值
+    g_equ_contrast.version = ec->cfh.version;
+    g_equ_contrast.signature = ec->cfh.signature;
+    g_equ_contrast.length = len;
+    g_equ_contrast.crc = g_crc_equ_cfg;
 
-	 rt_printf("线路开关数量:程序=%d,配置=%d.\r\n",SWITCH_NUM_MAX,g_sw_num);
-	 if(g_sw_num > SWITCH_NUM_MAX)
-	 {
-	 	return -7;
-	 }
+    // 比对资源表文件
+    if ((ec->rsc_version != rsc_contrast.version) || (ec->rsc_signature != rsc_contrast.signature) || (ec->rsc_length != rsc_contrast.length) || (ec->rsc_crc != rsc_contrast.crc))
+    {
+        rt_printf("equ_version = 0x%x, rsc_version = 0x%x\r\n", ec->rsc_version, rsc_contrast.version);
+        rt_printf("equ_signature = 0x%x, rsc_signature = 0x%x\r\n", ec->rsc_signature, rsc_contrast.signature);
+        rt_printf("equ_length = 0x%x, rsc_length = 0x%x\r\n", ec->rsc_length, rsc_contrast.length);
+        rt_printf("equ_crc = 0x%x, rsc_crc = 0x%x\r\n", ec->rsc_crc, rsc_contrast.crc);
 
-	return 0;
+        rt_free(buf);
+        return -6;
+    }
+
+    // 装载配置
+    g_equ_config = ec;
+    g_equ_config_di = (struct equ_config_di *)(buf + g_equ_config->di_addr);
+    g_equ_config_do = (struct equ_config_do *)(buf + g_equ_config->do_addr);
+    g_equ_config_ac = (struct equ_config_ac *)(buf + g_equ_config->ac_addr);
+
+    // 得到开关数量
+    g_sw_num = 0;
+    for (i = 0; i < g_equ_config->di_num; i++)
+    {
+        if (g_equ_config_di[i].owner > g_sw_num && g_equ_config_di[i].index)
+        {
+            g_sw_num = g_equ_config_di[i].owner;
+        }
+    }
+    for (i = 0; i < g_equ_config->do_num; i++)
+    {
+        if (g_equ_config_do[i].owner > g_sw_num && g_equ_config_do[i].index)
+        {
+            g_sw_num = g_equ_config_do[i].owner;
+        }
+    }
+    for (i = 0; i < g_equ_config->ac_num; i++)
+    {
+        if (g_equ_config_ac[i].type == 0)
+        {
+            continue;
+        }
+
+        if (g_equ_config_ac[i].owner > g_sw_num && g_equ_config_ac[i].index)
+        {
+            g_sw_num = g_equ_config_ac[i].owner;
+        }
+
+        if (g_equ_config_ac[i].owner == 0)
+        {
+            g_pub_ac_num++;
+        }
+        else
+        {
+            g_sw_ac_num[g_equ_config_ac[i].owner - 1]++;
+        }
+        g_sw_ac_num[SWITCH_NUM_MAX]++; // 总配置数
+    }
+
+    rt_printf("线路开关数量:程序=%d,配置=%d.\r\n", SWITCH_NUM_MAX, g_sw_num);
+    if (g_sw_num > SWITCH_NUM_MAX)
+    {
+        return -7;
+    }
+
+    return 0;
 }
 
 /******************************************************************************
@@ -518,6 +514,14 @@ int equ_init(void)
             g_board_info[i].crc = m_CodeCrc;
             g_board_info[i].version = VER_NUM;
         }
+        else if (g_board_info[i].type == BOARD_TYPE_FUXI_DI)
+        {
+            g_di_slot = i;
+        }
+        else if (g_board_info[i].type == BOARD_TYPE_FUXI_DO)
+        {
+            g_do_slot = i;
+        }
     }
 
     // 模拟通道配置
@@ -553,6 +557,7 @@ int equ_init(void)
     }
 
     equ_init_di();
+    equ_config_do_keeptime();
 
     return 0;
 }

+ 2 - 1
dtu/dtu_main_t536/app/main.c

@@ -156,7 +156,7 @@ int app_main (void *unused)
               	"app_main_loop", (int)getpid(), (int)syscall(SYS_gettid));
 #endif
 
-#if (1) /* 打印信息测试函数 */
+#if (0) /* 打印信息测试函数 */
 	dp_info_nt("最大定值个数 MAX_SET_NUMBER = %d", MAX_SET_NUMBER);
 	dp_info_nt("装置参数 EQUIP_PARA_NUMBER = %d, PARA_NUM = %d", EQUIP_PARA_NUMBER, PARA_NUM);
 	dp_info_nt("保护定值 SW_SET_NUMBER = %d, SW_SET_NUMBER = %d", SW_SET_NUMBER, SW_SET_NUMBER);
@@ -179,6 +179,7 @@ int app_main (void *unused)
     msleep(500);
     // extern int test_kc_function(void);
     // test_kc_function();
+    // msleep(500);
 #endif
 
 	{

文件差异内容过多而无法显示
+ 454 - 464
dtu/dtu_main_t536/app/protect.c


+ 3 - 40
dtu/dtu_main_t536/app/switch.c

@@ -116,8 +116,6 @@ const s8 *g_sw_di_name[SW_DI_NUM] =
 // 开关开出名称
 const s8 * g_sw_do_name[SW_DO_NUM] =
 {
-	"合闸",
-	"跳闸",
 	"保护合闸",
 	"保护分闸",
 	"遥控合闸",
@@ -135,7 +133,6 @@ const s8 * g_sw_do_name[SW_DO_NUM] =
 	"备自投-#2进线分闸",
 	"备自投-分段合闸",
 	"备自投-分段分闸",
-
 	"备自投-进线1失压分闸",
 	"备自投-进线2失压分闸",
 #endif
@@ -1230,7 +1227,7 @@ int sw_do(u32 sw, u32 index, int type)
     u32 slot;
     TRELAY_T *pR = &g_tRelay[sw];
 
-    if ((index == SW_DO_HZ || index == SW_DO_YKH || index == SW_DO_BHH) && (type == SW_DO_TYPE_ON))
+    if ((index == SW_DO_YKH || index == SW_DO_BHH) && (type == SW_DO_TYPE_ON))
     {
         if (pR->run_stu.sw == 1)
         {
@@ -1244,7 +1241,7 @@ int sw_do(u32 sw, u32 index, int type)
         gb_drive.bTz_Doing = 0;
 #endif
     }
-    if ((index == SW_DO_FZ || index == SW_DO_YKT || index == SW_DO_BHT) && (type == SW_DO_TYPE_ON))
+    if ((index == SW_DO_YKT || index == SW_DO_BHT) && (type == SW_DO_TYPE_ON))
     {
         if (pR->run_stu.sw == 2)
         {
@@ -1264,7 +1261,7 @@ int sw_do(u32 sw, u32 index, int type)
     }
 
     // 气压低闭锁分合闸
-    if (pRunSet->tSwSet[sw].bTT_QYD_BS && (g_sw[sw].di[SW_DI_QYD_BS] == SW_DI_TYPE_ON) && (index == SW_DO_HZ || index == SW_DO_FZ || index == SW_DO_YKH || index == SW_DO_YKT || index == SW_DO_BHH || index == SW_DO_BHT))
+    if (pRunSet->tSwSet[sw].bTT_QYD_BS && (g_sw[sw].di[SW_DI_QYD_BS] == SW_DI_TYPE_ON) && (index == SW_DO_YKH || index == SW_DO_YKT || index == SW_DO_BHH || index == SW_DO_BHT))
     {
         return -2;
     }
@@ -1322,40 +1319,6 @@ int sw_do_pub(u32 index, int type)
     return ret;
 }
 
-/******************************************************************************
-函数名称:	sw_do_yk
-函数版本:	01.01
-创建作者:	sunxi
-创建日期:	2013-08-07
-函数说明:	预控继电器开出
-参数说明:
-    index	开出索引
-    type	开出类型
-返回值:
-    0:		成功
-    其它:	失败
-修改记录:
-*/
-int sw_do_yuk(int type)
-{
-    int ret;
-    u32 slot;
-    int index;
-
-    index = g_sw_pub.do_cfg_index[PUB_DO_YK];
-    if (index == INDEX_INVALLID || index >= g_equ_config->do_num)
-    {
-        return -2;
-    }
-
-    slot = g_equ_config_do[index].slot;
-    index = g_equ_config_do[index].index;
-
-    ret = _sw_do(slot, index, type);
-
-    return ret;
-}
-
 /******************************************************************************
 函数名称:	sw_v_m2_factor_k
 函数版本:	01.01

+ 23 - 27
dtu/dtu_main_t536/app/switch.h

@@ -112,42 +112,39 @@ enum
 
 enum
 {
-	SW_DO_HZ = 0,	// 合闸
-	SW_DO_FZ,		// 分闸
-	SW_DO_BHH,		
-	SW_DO_BHT,
-	SW_DO_YKH,
-	SW_DO_YKT,		
-	SW_RST_SY,		//瞬压复归
-	SW_RST_SY1,		//瞬压复归
-	SW_FBT_SY,		//瞬压闭锁
-	SW_DO_CN,		//储能信号		
-	SW_DO_BHDZ,		
-	SW_DO_TQBS,
-#ifdef	CUSTOMIZE_BZT //备自投
-	SW_DO_DL1_HZ,	
-	SW_DO_DL1_FZ,
-	SW_DO_DL2_HZ,
-	SW_DO_DL2_FZ,
-	SW_DO_FD_HZ,    //备自投-分段合闸
-	SW_DO_FD_FZ,	//备自投-分段分闸		
-	SW_DO_JX1_SY,   //备自投-进线1失压分闸
-	SW_DO_JX2_SY,	//备自投-进线2失压分闸
-#endif	
+    SW_DO_BHH = 0,   // 保护合闸
+    SW_DO_BHT,       // 保护分闸
+    SW_DO_YKH,       // 遥控合闸
+    SW_DO_YKT,       // 遥控分闸
+    SW_RST_SY,       // 瞬压复归
+    SW_RST_SY1,      // 瞬压复归
+    SW_FBT_SY,       // 瞬压闭锁
+    SW_DO_CN,        // 储能信号
+    SW_DO_BHDZ,      // 保护动作开出
+    SW_DO_TQBS,      // 同期合闸开出
+#ifdef CUSTOMIZE_BZT // 备自投
+    SW_DO_DL1_HZ,    // 备自投-#1进线合闸
+    SW_DO_DL1_FZ,    // 备自投-#1进线分闸
+    SW_DO_DL2_HZ,    // 备自投-#2进线合闸
+    SW_DO_DL2_FZ,    // 备自投-#2进线分闸
+    SW_DO_FD_HZ,     // 备自投-分段合闸
+    SW_DO_FD_FZ,     // 备自投-分段分闸
+    SW_DO_JX1_SY,    // 备自投-进线1失压分闸
+    SW_DO_JX2_SY,    // 备自投-进线2失压分闸
+#endif
 
 #if defined SW_FAIL_SINGLE_OUT
-	SW_DO_UNSTUCK_SINGLE,
+    SW_DO_UNSTUCK_SINGLE, // 开关失灵
 #endif
 
-	SW_DO_NUM
+    SW_DO_NUM
 };
 
-
 // 开关类LED类型
 enum
 {
     SW_LED_HW = 0,     // 合位灯
-    SW_LED_TW,         // 位灯
+    SW_LED_TW,         // 位灯
     SW_LED_WCN,        // 未储能灯
     SW_LED_GL,         // 过流灯
     SW_LED_JD,         // 接地灯
@@ -806,7 +803,6 @@ int sw_exit(void);
 
 int sw_di_set(u32 sw,u32 no,u8 v);
 int sw_di_get(u32 sw,u32 no);
-int sw_do_yuk(int type);
 int sw_do(u32 sw,u32 index,int type);
 int sw_do_pub(u32 index,int type);
 float sw_v_m2_factor_k(int id);

+ 1 - 4
dtu/dtu_main_t536/app/vol.c

@@ -443,8 +443,7 @@ void Pro_TQHz(int sw,DWORD  dStep)
 				{
 			       	pR->uRmtSW.bHandHz_fa = true;
 			    }
-			    	sw_do(sw,SW_DO_YKH,SW_DO_TYPE_ON);  //合环合闸开出遥控出口
-			    	sw_do(sw,SW_DO_HZ,SW_DO_TYPE_ON);  //合环合闸开出遥控出口
+                sw_do(sw,SW_DO_YKH,SW_DO_TYPE_ON);  //合环合闸开出遥控出口
 				soe_record_ev(EV_TQHZ+sw*EV_SW_NUM, 1, 0,0,0 );
 				pSW->uTQHz.bFlag.bEvent = true;
 			}
@@ -1346,11 +1345,9 @@ void vol_lost_tz(int sw, DWORD      dStep)  // 失压
 			rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	//录波类型:跳闸类
 			pvol->sta.bFlag.bEvent = true;
 			//pSW->uLostVot.bFlag.bTz=true;  //执行跳闸标志
-			sw_do(sw,SW_DO_HZ,SW_DO_TYPE_OFF);
 			sw_do(sw,SW_DO_BHH,SW_DO_TYPE_OFF);
 
 			sw_do(sw,SW_DO_BHDZ,SW_DO_TYPE_ON);
-			sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);
 			sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);
 	
 			if(uBZT->bBZT.bZF && pRunSet->tSwSet[sw].bBZT_TT)

+ 5 - 5
dtu/dtu_main_t536/app/xdljd.c

@@ -241,7 +241,7 @@ void xdl_ac_check(int sw,DWORD  dStep)
 		if (!bFZOut)				// 保证只动作一次未进行跳闸失败检测
 		{
 			DWORD U0;
-			sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);
+			sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);
 		
 			if(pRunSet->tSwSet[sw].bTT_Power_v2)
 			{
@@ -2157,7 +2157,7 @@ int xdl_proc_adc(u32 sw,u32 dt,struct timespec *ts)
 			g_xdl[sw].dz = 1;
 			// 提前打开启动继电器,以节省硬件耗用时间
 			// 并等待超时释放
-			sw_do(sw,SW_DO_FZ,SW_DO_TYPE_SELECT_ON);
+			sw_do(sw,SW_DO_BHT,SW_DO_TYPE_SELECT_ON);
 			
 			if(pSet->dT_xdl_T)  //暂态时间不为0时,才启动间歇性接地逻辑
 			{
@@ -2190,7 +2190,7 @@ int xdl_proc_adc(u32 sw,u32 dt,struct timespec *ts)
 				// 跳闸
 				if(pSet->bTT_xdltz)
 				{
-					sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);
+					sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);
 					soe_record_ev(EV_LX_XDL_TZ+sw*EV_SW_NUM, 1, i0,u0,0 );
 					soe_record_ev(EV_ABC_JDTZ+sw*EV_SW_NUM, 1, i0,u0,0 );
 					if ((Ia>Ib)&&(Ia>Ic))
@@ -2453,8 +2453,8 @@ static void _xdl_protect_TZ_FG(int sw, DWORD dStep)
 					// 跳闸
 					if(pRunSet->tSwSet[sw].bTT_xdltz)
 					{
-						sw_do(sw,SW_DO_FZ,SW_DO_TYPE_SELECT_ON);
-						sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);
+						sw_do(sw,SW_DO_BHT,SW_DO_TYPE_SELECT_ON);
+						sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);
 						// g_xdl[sw].dz_fh_us0 = ustimer_get_origin();
 						soe_record_ev(EV_LX_XDL_TZ+sw*EV_SW_NUM, 1, g_xdl[sw].dz_i0[1],g_xdl[sw].dz_u0[1],0 );
 

+ 0 - 1
dtu/dtu_main_t536/main_mod.c

@@ -239,7 +239,6 @@ int cal_thread (void *arg)
         // ¼ì²éÊÇ·ñÐèÒªÍ˳ö¡£
         if(g_exit_flag)
         {
-
 			//complete_and_exit(&exit_completion2, 1);
 			break;
 		}

部分文件因为文件数量过多而无法显示