feat: 完成项目多模块功能迭代与配置更新
1. 新增sqlite文件、协议文档、调试截图、配置ini等各类辅助文件 2. 更新Keil开发包版本与工程配置,调整编译优化等级 3. 重构继电器控制逻辑、串口收发逻辑与线程优先级 4. 新增Modbus寄存器映射、校准结构体与Ymodem升级相关代码 5. 完善南北向协议解析、快充挡位配置与调试日志 6. 修复注释格式、数组越界与线程邮箱溢出问题 7. 新增屏幕控制、功率板调试与协议格式说明文档
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "chrg_eload.h"
|
||||
#include "chrg_gpio.h"
|
||||
#include "chrg_thread.h"
|
||||
#include "chrg_north_pkg.h"
|
||||
@@ -19,31 +19,328 @@
|
||||
#include "chrg_switch.h"
|
||||
#include "chrg_utils.h"
|
||||
#include "ulog.h"
|
||||
|
||||
#include "chrg_rel.h"
|
||||
//#define LOG_TAG "chrg.nor"
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
rt_uint16_t volt;
|
||||
uint16_t chrg_compare(rt_int16_t a, rt_int16_t b)
|
||||
{
|
||||
if(a>b) return a - b;
|
||||
else return b - a;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_source_stop
|
||||
功能描述: 南向功率源停止流程控制函数(分步执行停止操作)
|
||||
函数描述: 通过状态机分步执行南向功率停止流程:停止功率输出 -> 关闭北向继电器 -> 清空控制标志并禁用使能
|
||||
输入参数:
|
||||
frame_data :原始数据帧指针,用于提取当前电压值
|
||||
pSW :北向通道控制结构体指针
|
||||
idx :通道编号(功率通道/北向通道索引)
|
||||
enable :北向通道使能,停止后关掉使能
|
||||
返回说明: 无返回值
|
||||
*****************************************************************/
|
||||
void chrg_source_stop(rt_uint8_t *frame_data,struct chrg_switch_t *pSW,rt_uint8_t idx,rt_uint8_t *enable){
|
||||
switch(pSW->source.Stop_step_flag){
|
||||
case 0: // 停止工作
|
||||
chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_WORK, WORK_STOP);
|
||||
rt_thread_mdelay(50);
|
||||
rt_uint16_t volt_mv_Now = (frame_data[4] << 8) | frame_data[5];
|
||||
volt = volt_mv_Now;
|
||||
if(volt_mv_Now < 1000){
|
||||
pSW->source.Stop_step_flag = 1;
|
||||
}
|
||||
break;
|
||||
case 1: // 关闭北向继电器
|
||||
chrg_nor_sw_rel((eIDX_NOR_CH)idx,0);
|
||||
rt_thread_mdelay(50);
|
||||
pSW->source.Stop_step_flag = 2;
|
||||
break;
|
||||
case 2: // 状态2:已执行完停止操作,清空标志位
|
||||
pSW->source.Set_CV_Flag = 0;
|
||||
*enable = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_source_standard_output
|
||||
功能描述: 南向功率源标准输出控制函数
|
||||
函数描述: 根据CV标志位,分别设置电源输出电压或输出电流,实现标准模式下的恒压/恒流输出
|
||||
输入参数:
|
||||
idx :功率通道编号
|
||||
pSW :北向通道控制结构体指针,包含电压/电流设定值、CV控制标志等参数
|
||||
输出参数:
|
||||
pSW :更新CV控制标志位
|
||||
返回说明: 无返回值
|
||||
*****************************************************************/
|
||||
void chrg_source_standard_output(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
{
|
||||
if(pSW->source.Set_CV_Flag) {
|
||||
chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_VOLTAGE_OUT+1, pSW->source.max_vol);
|
||||
#if DEBUG_NORTH
|
||||
rt_kprintf("Volt_Set%d\r\n",pSW->source.vc.set_voltage);
|
||||
#endif
|
||||
pSW->source.Set_CV_Flag = 1;
|
||||
pSW->change_flag = 0;
|
||||
}
|
||||
// if(pSW->source.Set_CV_Flag==0){
|
||||
// chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_CURRENT_OUT+1, pSW->source.max_vol);
|
||||
//#if DEBUG_NORTH
|
||||
// rt_kprintf("Curr_set%d\r\n",Curr_mA);
|
||||
//#endif
|
||||
// pSW->source.Set_CV_Flag = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
//电源快充
|
||||
void chrg_source_fast_output(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
||||
struct chrg_switch_t *pSW, struct chrg_north_t *pNOR)
|
||||
{
|
||||
struct chrg_rollsou_t *pROLL = &chrgrollsou;
|
||||
rt_uint16_t volt_mv = (frame_data[8] << 8) | frame_data[9];
|
||||
rt_uint16_t Curr_mA = (frame_data[10] << 8) | frame_data[11];
|
||||
rt_uint16_t volt_mv_Now = (frame_data[4] << 8) | frame_data[5];
|
||||
rt_uint16_t Curr_mA_Now = (frame_data[6] << 8) | frame_data[7];
|
||||
rt_uint16_t volt_compare = chrg_compare(volt_mv, volt_mv_Now);
|
||||
rt_uint16_t Curr_compare = chrg_compare(Curr_mA, Curr_mA_Now);
|
||||
static rt_uint8_t number = 0;
|
||||
#if LCD_OPEN
|
||||
// rt_kprintf("volt_mv=%d,volt_mv_Now=%d,compare=%d\r\n",volt_mv,volt_mv_Now,volt_compare);
|
||||
if(volt_compare<5000){ //比较设定值与实际值差距,小于2V认为达成设定,允许屏幕开始变换
|
||||
number++;
|
||||
number = number%10;
|
||||
if(number == 9)
|
||||
{
|
||||
pSW->change_flag = 0;
|
||||
}
|
||||
}else { //没有达成设定,屏幕不允许变换
|
||||
pSW->change_flag = 0x01;
|
||||
}
|
||||
#endif
|
||||
// if(volt_mv_Now==0){
|
||||
// chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_WORK, WORK_START);
|
||||
// }
|
||||
// else{
|
||||
if (pSW->source.Set_CV_Flag == 0){
|
||||
{
|
||||
chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_VOLTAGE_OUT+1, volt_mv);
|
||||
}
|
||||
pSW->source.Set_CV_Flag = 1;
|
||||
#if DEBUG_NORTH
|
||||
rt_kprintf("Volt_Set%d\r\n",volt_mv);
|
||||
#endif
|
||||
}
|
||||
else if(pSW->source.Set_CV_Flag==1){
|
||||
chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_WORK, WORK_START);
|
||||
pSW->source.Set_CV_Flag = 0;
|
||||
}else{
|
||||
pSW->source.Set_CV_Flag=0;
|
||||
}
|
||||
}
|
||||
|
||||
//电源设置
|
||||
void chrg_source_setting(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
||||
struct chrg_switch_t *pSW, struct chrg_north_t *pNOR)
|
||||
{
|
||||
//执行输出调整
|
||||
if (pSW->source.On_Flag == 1) {
|
||||
if(pSW->source.protocol==0x00){//标准下输出设定值
|
||||
chrg_source_standard_output(idx, pSW);
|
||||
}
|
||||
else{ //快充部分按协商结果输出
|
||||
chrg_source_fast_output(frame_data, idx, pSW, pNOR);
|
||||
// rt_kprintf("set_end\r\n");
|
||||
}
|
||||
}else if(pSW->source.On_Flag == 0){
|
||||
//chrg_source_stop(frame_data,pSW,idx,&pNOR->enable[idx]);
|
||||
pSW->sub = IDX_SET_SOURCE_STOP_STATE;
|
||||
}
|
||||
}
|
||||
////解析负载返回数据
|
||||
//void chrg_sink_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
||||
// struct chrg_switch_t *pSW, struct chrg_north_t *pNOR)
|
||||
//{
|
||||
// rt_uint16_t volt_mv = ((frame_data[4] << 8) | frame_data[5])*10;
|
||||
// static uint8_t volt_low[TOTAL_SOU_CHS] = {0};
|
||||
// static uint8_t no_curr[TOTAL_SOU_CHS] = {0};
|
||||
// pSW->VZ = ((frame_data[14] << 8) | frame_data[15]);
|
||||
// pSW->VF = ((frame_data[16] << 8) | frame_data[17]);
|
||||
|
||||
//#if DEBUG_NORTH
|
||||
// LOG_D("Sink[%d] real volt: %d mV", idx, volt_mv);
|
||||
//#endif
|
||||
//
|
||||
// if(pSW->sink.On_work == 1) {
|
||||
// if(pSW->sink.test.test_mode == 0){
|
||||
// if (volt_mv <= WORK_MIN_VOLT) { // 电压过低,禁止进入工作状态机
|
||||
// volt_low[idx]++;
|
||||
// //if(volt_low[idx]>=5) pSW->sink.work_mode = SINK_WORK_LOW; // 复位工作状态机
|
||||
// }
|
||||
// else{ // 电压稳定时执行工作状态机(继电器/工作模式切换)
|
||||
// volt_low[idx] = 0;
|
||||
// pSW->change_flag = 0;
|
||||
// if((pSW->sink.pro_loadv - volt_mv) <= 2000){
|
||||
// pSW->sink.work_mode = SINK_WORK_RUNING;
|
||||
// if(pSW->Now_current<=200){
|
||||
// if(no_curr[idx]++>=5){
|
||||
// pSW->sink.work_mode = SINK_WORK_WAIT;
|
||||
// no_curr[idx] = 0;
|
||||
// }
|
||||
// }
|
||||
// else no_curr[idx] = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// volt_low[idx] = 0;
|
||||
//// pSW->sink.work_mode = SINK_WORK_STOP;
|
||||
// }
|
||||
// chrg_sink_work(idx,pSW);
|
||||
//}
|
||||
|
||||
//解析负载返回数据
|
||||
void chrg_sink_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
||||
struct chrg_switch_t *pSW, struct chrg_north_t *pNOR)
|
||||
{
|
||||
rt_uint16_t volt_mv = ((frame_data[4] << 8) | frame_data[5])*10;
|
||||
static uint8_t volt_low[TOTAL_SOU_CHS] = {0};
|
||||
static uint8_t no_curr[TOTAL_SOU_CHS] = {0};
|
||||
pSW->VZ = ((frame_data[14] << 8) | frame_data[15]);
|
||||
pSW->VF = ((frame_data[16] << 8) | frame_data[17]);
|
||||
|
||||
#if DEBUG_NORTH
|
||||
LOG_D("Sink[%d] real volt: %d mV", idx, volt_mv);
|
||||
#endif
|
||||
|
||||
if(pSW->sink.On_work == 1 && pSW->sink.test.test_mode == 0) {
|
||||
if (volt_mv <= WORK_MIN_VOLT) { // 电压过低,禁止进入工作状态机
|
||||
// volt_low[idx]++;
|
||||
// if(volt_low[idx]>=5) pSW->sink.work_on_step = SINK_WORK_LOW; // 复位工作状态机
|
||||
}
|
||||
else{ // 电压稳定时执行工作状态机(继电器/工作模式切换)
|
||||
volt_low[idx] = 0;
|
||||
pSW->change_flag = 0;
|
||||
if((pSW->sink.pro_loadv - volt_mv) <= 2000){
|
||||
pSW->sink.work_mode = SINK_WORK_RUNING;
|
||||
if(pSW->Now_current<=200){
|
||||
if(no_curr[idx]++>=5){
|
||||
pSW->sink.work_mode = SINK_WORK_WAIT;
|
||||
no_curr[idx] = 0;
|
||||
}
|
||||
}
|
||||
else no_curr[idx] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
volt_low[idx] = 0;
|
||||
// pSW->sink.work_on_step = SINK_WORK_STOP; // 复位工作状态机
|
||||
}
|
||||
chrg_sink_work(idx,pSW);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_handle_Seting_Volt
|
||||
功能描述: 处理设置电压/电流命令,解析命令数据并执行相应操作
|
||||
****************************************************/
|
||||
rt_uint8_t change_number = 0;
|
||||
static void chrg_north_handle_Seting_Volt(rt_uint8_t *frame_data, rt_uint16_t frame_len)
|
||||
{
|
||||
// 提取电压/电流值
|
||||
struct chrg_north_t *pNOR = &chrgnorth;
|
||||
rt_uint16_t idx = pNOR->idx;
|
||||
struct chrg_switch_t *pSW = &chrgnorth.sw[idx];
|
||||
|
||||
static uint8_t number = 0;
|
||||
//电源部分
|
||||
if(pSW->id==ID_SOURCE){
|
||||
chrg_source_setting(frame_data,(eIDX_SOU_CH)idx, pSW, pNOR);
|
||||
}
|
||||
else{
|
||||
chrg_sink_parse(frame_data,(eIDX_SOU_CH)idx, pSW, pNOR);
|
||||
}
|
||||
}
|
||||
|
||||
struct chrg_north_t chrgnorth = {
|
||||
.devname = DEV_NAME_NORTH,
|
||||
.tty = RT_NULL,
|
||||
.enable = {1, 1, 1, 1},
|
||||
.sw[IDX_NOR_CH1] = {
|
||||
.id = ID_SINK,
|
||||
},
|
||||
.sw[IDX_NOR_CH2] = {
|
||||
.id = ID_SINK,
|
||||
},
|
||||
.sw[IDX_NOR_CH3] = {
|
||||
.id = ID_SINK,
|
||||
},
|
||||
.sw[IDX_NOR_CH4] = {
|
||||
.id = ID_SINK,
|
||||
},
|
||||
.devname = DEV_NAME_NORTH, // 设备名
|
||||
.tty = RT_NULL, // 串口句柄初始为空
|
||||
.enable = {0, 0, 0, 0}, // 4个通道使能初始关闭
|
||||
.free_flag = 1,
|
||||
// 通道1(IDX_NOR_CH1)初始化
|
||||
.sw[IDX_NOR_CH1] = {
|
||||
.CV_mode = 2,
|
||||
.change_flag = 0,
|
||||
.show_step = 0,
|
||||
.id = ID_SINK, // 初始为负载模式
|
||||
.source = { // 电源侧参数初始化
|
||||
.On_Flag = 0, // 启动标志初始关闭
|
||||
.Set_CV_Flag = 1, // 启停控制初始置1
|
||||
.Set_Pro_Flag = 1 // 电压/电流切换初始置1
|
||||
}, // 关键:补充逗号分隔source和sink
|
||||
.sink = {
|
||||
.protocol = 0xFE,
|
||||
.work_mode= SINK_WORK_WAIT,
|
||||
.test.test_mode_old = 0,
|
||||
}
|
||||
|
||||
},
|
||||
// 通道2(IDX_NOR_CH2)初始化
|
||||
.sw[IDX_NOR_CH2] = {
|
||||
.show_step = 0,
|
||||
.id = ID_SINK,
|
||||
.CV_mode = 2,
|
||||
.change_flag = 0,
|
||||
.source = {
|
||||
.On_Flag = 0,
|
||||
.Set_CV_Flag = 1,
|
||||
.Set_Pro_Flag = 1
|
||||
},
|
||||
.sink = {
|
||||
.protocol = 0xFE,
|
||||
.work_mode= SINK_WORK_WAIT,
|
||||
.test.test_mode_old = 0,
|
||||
}
|
||||
},
|
||||
// 通道3(IDX_NOR_CH3)初始化
|
||||
.sw[IDX_NOR_CH3] = {
|
||||
.show_step = 0,
|
||||
.CV_mode = 2,
|
||||
.id = ID_SINK,
|
||||
.change_flag = 0,
|
||||
.source = {
|
||||
.On_Flag = 0,
|
||||
.Set_CV_Flag = 1,
|
||||
.Set_Pro_Flag = 1
|
||||
},
|
||||
.sink = {
|
||||
.protocol = 0xFE,
|
||||
.work_mode= SINK_WORK_WAIT,
|
||||
.test.test_mode_old = 0,
|
||||
}
|
||||
},
|
||||
// 通道4(IDX_NOR_CH4)初始化
|
||||
.sw[IDX_NOR_CH4] = {
|
||||
.show_step = 0,
|
||||
.CV_mode = 2,
|
||||
.id = ID_SINK,
|
||||
.change_flag = 0,
|
||||
.source = {
|
||||
.On_Flag = 0,
|
||||
.Set_CV_Flag = 1,
|
||||
.Set_Pro_Flag = 1
|
||||
},
|
||||
.sink = {
|
||||
.protocol = 0xFE,
|
||||
.work_mode= SINK_WORK_WAIT,
|
||||
.test.test_mode_old = 0,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_switch
|
||||
函数描述: 北向通道选择
|
||||
@@ -76,7 +373,9 @@ int chrg_north_send (rt_uint8_t *data, rt_size_t length)
|
||||
struct chrg_tty_t *pTTY = chrgnorth.tty;
|
||||
|
||||
if (RT_NULL != pTTY) {
|
||||
LOG_HEX("sendN", 32, data, length);
|
||||
#if DEBUG_NORTH //是否打印
|
||||
// LOG_HEX("sendN", 32, data, length);
|
||||
#endif
|
||||
ret = chrg_tty_send(pTTY, data, length);
|
||||
}
|
||||
|
||||
@@ -100,14 +399,30 @@ static int chrg_north_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eI
|
||||
rt_uint8_t len_frame = 0; // 帧长度
|
||||
|
||||
if (RT_NULL == rb) {
|
||||
rt_kprintf("len_rb=NULL%d\r\n",len_rb);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len_rb = rt_ringbuffer_data_len(rb);
|
||||
if (len_rb < LEN_FRAME_HEAD + 2) { // 最短5字节
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (len_rb < LEN_FRAME_HEAD + 2) { // 最短5字节
|
||||
// =============================
|
||||
// 简单版:打印错误帧 + 清空缓冲区
|
||||
// =============================
|
||||
rt_kprintf("[ERROR] 帧长度不足,len=%d, data: ", len_rb);
|
||||
|
||||
// 把所有数据读出来、打印、同时清空
|
||||
rt_uint8_t dummy;
|
||||
while (rt_ringbuffer_getchar(rb, &dummy) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("%02x ", dummy); // 打印每一个字节
|
||||
}
|
||||
|
||||
rt_kprintf("\r\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < len_rb - 2; i++) { // 找头三个字节 [帧长, 0x00, id]
|
||||
ret = rt_ringbuffer_getchar(rb, &data);
|
||||
if (0 == ret) {
|
||||
@@ -119,6 +434,7 @@ static int chrg_north_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eI
|
||||
head[0] = data;
|
||||
len_frame = data;
|
||||
if (data < MIN_FRAME_LENGTH) { // 长度不符
|
||||
|
||||
stage = 0;
|
||||
continue;
|
||||
}
|
||||
@@ -140,6 +456,13 @@ static int chrg_north_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eI
|
||||
if ((rt_uint8_t)id != data) {
|
||||
stage = 0;
|
||||
} else {
|
||||
// if (id == ID_SINK) {
|
||||
// rt_uint8_t ext1, ext2;
|
||||
// // 主动读取并丢弃2字节扩展字段
|
||||
// rt_ringbuffer_getchar(rb, &ext1);
|
||||
// rt_ringbuffer_getchar(rb, &ext2);
|
||||
// rt_kprintf("Sink:%02X %02X\r\n", ext1, ext2);
|
||||
// }
|
||||
return len_frame;
|
||||
}
|
||||
break;
|
||||
@@ -162,28 +485,29 @@ static int chrg_north_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eI
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int a_number;
|
||||
static int chrg_north_pickup_frame (struct rt_ringbuffer *rb,
|
||||
struct pickup_info_t *pFrame, eIDX_NOR_CH idx)
|
||||
{
|
||||
int cnt = 0;
|
||||
rt_size_t len_rb = 0;
|
||||
|
||||
if ((RT_NULL == rb)||(RT_NULL == pFrame)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct chrg_switch_t *pSW = &chrgnorth.sw[idx];
|
||||
|
||||
//rt_kprintf("north_idx=%d\r\n",idx);
|
||||
do {
|
||||
if (0 == pFrame->findhead) {
|
||||
//pFrame->len_msg = chrg_north_frame_head(pSW->id,rb, pFrame->head, pSW->id);
|
||||
pFrame->len_msg = chrg_north_frame_head(rb, pFrame->head, pSW->id);
|
||||
// rt_kprintf("msg=:%d",pFrame->len_msg);
|
||||
if (pFrame->len_msg > 0) {
|
||||
pFrame->pMB = (struct mb_msg_t *)rt_malloc(sizeof(struct mb_msg_t));
|
||||
if (RT_NULL == pFrame->pMB) {
|
||||
LOG_E("malloc mb failed.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
pFrame->pMB->length = pFrame->len_msg;
|
||||
if (pFrame->pMB->length >= SIZE_BUF_TTY) {
|
||||
rt_free(pFrame->pMB);
|
||||
@@ -191,23 +515,23 @@ static int chrg_north_pickup_frame (struct rt_ringbuffer *rb,
|
||||
LOG_E("too long msg.");
|
||||
return -3;
|
||||
}
|
||||
|
||||
pFrame->pMB->payload = (rt_uint8_t *)rt_malloc(pFrame->len_msg);
|
||||
if (RT_NULL == pFrame->pMB->payload) {
|
||||
LOG_E("malloc buf failed.");
|
||||
return -4;
|
||||
}
|
||||
|
||||
rt_memcpy(pFrame->pMB->payload, pFrame->head, LEN_FRAME_HEAD);
|
||||
|
||||
len_rb = rt_ringbuffer_data_len(rb);
|
||||
// rt_kprintf("len_rb=%d\r\n",len_rb);
|
||||
// rt_kprintf("len=%d",pFrame->len_msg - LEN_FRAME_HEAD);
|
||||
if (len_rb >= pFrame->len_msg - LEN_FRAME_HEAD) {
|
||||
rt_ringbuffer_get(rb, &pFrame->pMB->payload[LEN_FRAME_HEAD],
|
||||
pFrame->len_msg - LEN_FRAME_HEAD);
|
||||
|
||||
if(pFrame->pMB->length==21){
|
||||
chrg_north_handle_Seting_Volt(pFrame->pMB->payload, pFrame->pMB->length);
|
||||
}
|
||||
chrg_thread_mb_send(IDX_THR_NORTH, pFrame->pMB);
|
||||
//chrg_north_pkg_decode(pFrame->pMB->payload, pFrame->len_msg, pSW);
|
||||
|
||||
pFrame->length = 0;
|
||||
pFrame->len_msg = 0;
|
||||
cnt++;
|
||||
@@ -219,7 +543,6 @@ static int chrg_north_pickup_frame (struct rt_ringbuffer *rb,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
len_rb = rt_ringbuffer_data_len(rb);
|
||||
int len_need = pFrame->len_msg - LEN_FRAME_HEAD;
|
||||
@@ -240,8 +563,8 @@ static int chrg_north_pickup_frame (struct rt_ringbuffer *rb,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
len_rb = rt_ringbuffer_data_len(rb);
|
||||
|
||||
} while (len_rb >= LEN_FRAME_HEAD);
|
||||
|
||||
return cnt;
|
||||
@@ -266,16 +589,16 @@ void chrg_north_thread_entry (void *data)
|
||||
int len = 0;
|
||||
struct chrg_tty_t *pTTY = RT_NULL;
|
||||
struct chrg_north_t *pNOR = &chrgnorth;
|
||||
|
||||
//北向协议板线程体通道初始化为CH1,
|
||||
chrg_north_switch(IDX_NOR_CH1);
|
||||
|
||||
pTTY = chrg_tty_create(pNOR->devname, BAUD_RATE_921600, 0, -1, 1);
|
||||
|
||||
pTTY = chrg_tty_create(pNOR->devname, 230400, 0, -1, 1);
|
||||
if (RT_NULL == pTTY) {
|
||||
LOG_E("tty can't create.");
|
||||
return ;
|
||||
}
|
||||
|
||||
chrg_tty_set_recv_tmo(pTTY, 100);
|
||||
chrg_tty_set_recv_tmo(pTTY, 10);
|
||||
if (chrg_tty_connect(pTTY) != RT_EOK) {
|
||||
chrg_tty_destory(pTTY);
|
||||
return ;
|
||||
@@ -298,8 +621,9 @@ void chrg_north_thread_entry (void *data)
|
||||
}
|
||||
|
||||
rt_ringbuffer_put(pNOR->rb, pNOR->rx_buf, len);
|
||||
#if DEBUG_NORTH
|
||||
LOG_HEX("recvN", 32, pNOR->rx_buf, len);
|
||||
|
||||
#endif
|
||||
if (1 == pNOR->frame.findhead) {
|
||||
if (rt_tick_get() >= pNOR->frame.last_tick + 100) { // 100ms
|
||||
pNOR->frame.findhead = 0; // reset
|
||||
@@ -309,7 +633,6 @@ void chrg_north_thread_entry (void *data)
|
||||
|
||||
chrg_north_pickup_frame(pNOR->rb, &pNOR->frame, pNOR->idx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -333,4 +656,3 @@ MSH_CMD_EXPORT(north_ch, north channel select);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user