Files
chrg/apps/chrg/applications/bsp/chrg_rel.c
T
yhf c820aad809 feat: 完成项目多模块功能迭代与配置更新
1. 新增sqlite文件、协议文档、调试截图、配置ini等各类辅助文件
2. 更新Keil开发包版本与工程配置,调整编译优化等级
3. 重构继电器控制逻辑、串口收发逻辑与线程优先级
4. 新增Modbus寄存器映射、校准结构体与Ymodem升级相关代码
5. 完善南北向协议解析、快充挡位配置与调试日志
6. 修复注释格式、数组越界与线程邮箱溢出问题
7. 新增屏幕控制、功率板调试与协议格式说明文档
2026-07-18 15:32:54 +08:00

133 lines
3.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/****************************************************************************
文件名称 : chrg_rel.c
完成日期 :
当前版本号 : V1.0
主要功能 : sink/source 切换继电器操作。
版本历史 : 创建原始版本
说明 :
******************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <rtthread.h>
#include "chrg_gpio.h"
#include "chrg_north.h"
#include "chrg_rel.h"
struct chrg_rel_t chrgrel[TOTAL_NOR_CHS] = {
[IDX_NOR_CH1] = {GPO_PIN_CH1_P0, GPO_PIN_CH1_P1, GPO_PIN_CH1_P2},
[IDX_NOR_CH2] = {GPO_PIN_CH2_P0, GPO_PIN_CH2_P1, GPO_PIN_CH2_P2},
[IDX_NOR_CH3] = {GPO_PIN_CH3_P0, GPO_PIN_CH3_P1, GPO_PIN_CH3_P2},
[IDX_NOR_CH4] = {GPO_PIN_CH4_P0, GPO_PIN_CH4_P1, GPO_PIN_CH4_P2}
};
/*****************************************************************
函数名称: chrg_nor_sw_rel
函数描述: 北向继电器组 组合切换。P0=1 是sink,P1=1是source,P0和P1互斥
输入参数: ch: 通道索引 id: sink/source
输出参数: -
返回说明: -
其它说明: -
*****************************************************************/
void chrg_nor_sw_rel (eIDX_NOR_CH ch, eIDX_ID id)
{
if (ch >= TOTAL_NOR_CHS) {
return ;
}
if (ID_SOURCE == id) {
rt_pin_write(chrgrel[ch].p2, PIN_HIGH);//sw置1
rt_pin_write(chrgrel[ch].p1, PIN_HIGH);
rt_pin_write(chrgrel[ch].p0, PIN_LOW);
} else if (ID_SINK == id) {
rt_pin_write(chrgrel[ch].p2, PIN_LOW);
rt_pin_write(chrgrel[ch].p1, PIN_LOW);
rt_pin_write(chrgrel[ch].p0, PIN_HIGH);
} else {
rt_pin_write(chrgrel[ch].p2, PIN_LOW);
rt_pin_write(chrgrel[ch].p1, PIN_LOW);
rt_pin_write(chrgrel[ch].p0, PIN_LOW);
}
}
/*****************************************************************
函数名称: chrg_nor_rel_init
函数描述: 北向继电器组 初始化。
输入参数: -
输出参数: -
返回说明: -
其它说明: -
*****************************************************************/
static int chrg_nor_rel_init (void)
{
int i = 0;
for (i = 0; i < TOTAL_NOR_CHS; i++) {
rt_pin_write(chrgrel[i].p2, PIN_LOW);
rt_pin_write(chrgrel[i].p0, PIN_LOW);
rt_pin_write(chrgrel[i].p1, PIN_LOW);
}
return 0;
}
INIT_DEVICE_EXPORT(chrg_nor_rel_init);
#if 1
int rel_test (int argc, char **argv)
{
if (argc < 3) {
rt_kprintf("help : %s <get|set> <0|1|2|3> [1, 2]", argv[0]);
return -1;
}
int idx = atoi(argv[2]);
if ((idx > 3)||(idx < 0)) {
rt_kprintf("help : %s <get|set> <0|1|2|3> [1, 2]", argv[0]);
return -1;
}
if (strcmp(argv[1], "set") == 0) {
if (argc != 4) {
rt_kprintf("help : %s <get|set> <0|1|2|3> [1, 2]", argv[0]);
return -1;
}
rt_uint8_t val = (rt_uint8_t)atoi(argv[3]);
if ((idx > 3)||(idx < 0)) {
rt_kprintf("help : %s <get|set> <0|1|2|3> [1, 2]", argv[0]);
return -1;
}
chrg_nor_sw_rel((eIDX_NOR_CH)idx, (eIDX_ID)val);
} else if (strcmp(argv[1], "get") == 0) {
rt_uint8_t data[3] = {0};
data[0] = rt_pin_read(chrgrel[idx].p0);
data[1] = rt_pin_read(chrgrel[idx].p1);
data[2] = rt_pin_read(chrgrel[idx].p2);
if ((1 == data[0])&&(0 == data[1])&&(1 == data[2])) {
rt_kprintf("rel connect [%d] : sink\r\n", idx);
} else if ((0 == data[0])&&(1 == data[1])&&(1 == data[2])) {
rt_kprintf("rel connect [%d] : source\r\n", idx);
rt_kprintf("rel connect [%d] : p0=%d, p1=%d, p2=%d\r\n",idx, data[0], data[1], data[2]);
} else {
rt_kprintf("rel connect [%d] : p0=%d, p1=%d, p2=%d\r\n",
idx, data[0], data[1], data[2]);
}
} else {
return -1;
}
return 0;
}
MSH_CMD_EXPORT(rel_test, test rel connect.);
#endif