协处理器能完成上下两端数据的识别

This commit is contained in:
起床就犯困 2024-08-19 15:01:40 +08:00
parent 869d006b94
commit d9c0372cc9
23 changed files with 11648 additions and 11565 deletions

View File

@ -13,12 +13,18 @@
#include <rthw.h>
#include "drivers/pin.h"
/* PE3控制智能模块的电源开关 */
#define android_PowerCtrl_Pin 2
/* PE2拉低7 ~10S智能模块系统会强制复位 */
#define android_PowerKey_Pin 1
void android_PowerCtrl_Init(void);
void android_PowerCtrl_Open(void);
void android_PowerCtrl_Close(void);
void android_PowerKey_Init(void);
void android_PowerKey_Rest(void);
#endif /* SOFTWARE_POWER_CTRL_ANDROID_H_ */

View File

@ -12,6 +12,7 @@
void android_PowerCtrl_Init(void)
{
rt_pin_mode(android_PowerCtrl_Pin, PIN_MODE_OUTPUT);
android_PowerCtrl_Open();
}
void android_PowerCtrl_Open(void)
{
@ -22,6 +23,17 @@ void android_PowerCtrl_Close(void)
rt_pin_write(android_PowerCtrl_Pin, close);
}
void android_PowerKey_Init(void)
{
rt_pin_mode(android_PowerKey_Pin, PIN_MODE_OUTPUT);
}
void android_PowerKey_Rest(void)
{
rt_pin_write(android_PowerKey_Pin, PIN_LOW);
rt_thread_mdelay(10000);
rt_pin_write(android_PowerKey_Pin, PIN_HIGH);
}

View File

@ -692,8 +692,6 @@ void J9_PWR_Close(void)
}
/*
* @brief UART4对应的LORA串口
* @param baud

View File

@ -15,10 +15,12 @@
/* 功能码 */
typedef enum
{
SL_Function_Code_Read_Register = 0x30, /* 读寄存器数据 */
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
SL_Function_Code_Broadcast_Scan = 0xA0, /* 广播扫描 */
SL_Function_Code_Registration_request = 0xA1, /* 注册请求 */
SL_Function_Code_Read_Register = 0x30, /* 读寄存器数据 */
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
SL_Function_Code_Broadcast_Scan = 0xA0, /* 广播扫描 */
SL_Function_Code_Registration_request = 0xA1, /* 注册请求 */
SL_Function_Code_Update_Profile = 0xD0, /* 配置文件 */
SL_Function_Code_Remote_Upgrade = 0xD1, /* 远程升级 */
}SL_MsgFunctionCode;
/* 寄存器地址 */
@ -152,6 +154,29 @@ typedef struct _SL_Mppt_RegistrationReply_pack{
}SL_Mppt_RegistrationReply_pack;
#define SL_MPPT_REGISTRATIONREPLY_PACK_SIZE (sizeof(SL_Mppt_RegistrationReply_pack))
/* 发送其他帧 (汇聚网关->接入节点) */
typedef struct _SL_Mppt_SOther_pack{
uint8_t start_Flag[2]; /* 起始标志 */
uint8_t address[7]; /* 地址 */
uint8_t function_Code; /* 功能码 */
uint8_t check_Bit_H; /* 校验位高八位 */
uint8_t check_Bit_L; /* 校验位低八位 */
uint8_t end_Flag; /* 结束标志 */
}SL_Mppt_SOther_pack;
#define SL_MPPT_SOTHER_PACK_SIZE (sizeof(SL_Mppt_SOther_pack))
/* 收到的其他帧(接入节点->汇聚网关) */
typedef struct _SL_Mppt_ROther_pack{
uint8_t start_Flag[2]; /* 起始标志 */
uint8_t address[7]; /* 地址 */
uint8_t function_Code; /* 功能码 */
uint8_t State; /* 准备状态 */
uint8_t check_Bit_H; /* 校验位高八位 */
uint8_t check_Bit_L; /* 校验位低八位 */
uint8_t end_Flag; /* 结束标志 */
}SL_Mppt_ROther_pack;
#define SL_MPPT_ROTHER_PACK_SIZE (sizeof(SL_Mppt_ROther_pack))
/* */
#define RECV_LENGTH 20
typedef struct _SL_Mppt_Recv_pack{
@ -161,6 +186,85 @@ typedef struct _SL_Mppt_Recv_pack{
uint8_t recv_Data[RECV_LENGTH]; /* 其他部分 */
}SL_Mppt_Recv_pack;
/* 智能模块与协处理器之间传输数据时的包头 */
typedef struct _SL_HEAD_pack{
uint8_t start_Flag[2]; /* 起始标志 */
uint8_t uart; /* 串口号1对应uart1 */
uint8_t Channel; /* 通道,分时复用时使用 */
}SL_Head_pack;
/* 智能模块与协处理器之间传输数据时的包尾 */
typedef struct _SL_TAIL_pack{
uint8_t end_Flag; /* 结束标志 */
}SL_Tail_pack;
/* 读时接收到的帧格式(智能模块->协处理器) */
typedef struct _SL_Mppt_Rorecv_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_Rorecv_pack rpack;
SL_Tail_pack tail; /* 包尾 */
}SL_Mppt_Rorecv_pack1;
#define SL_MPPT_RORECV_PACK_SIZE1 (sizeof(SL_Mppt_Rorecv_pack1))
/* 写时接收到的回复帧格式(智能模块->协处理器) */
typedef struct _SL_Mppt_WOReply_pack1{
SL_Head_pack head; /* 包头 */
uint8_t start_Flag[2]; /* 起始标志 */
uint8_t address[7]; /* 地址 */
uint8_t function_Code; /* 功能码 */
uint8_t write_Register_Start_Address_H; /* 写入寄存器起始地址高八位 */
uint8_t write_Register_Start_Address_L; /* 写入寄存器起始地址低八位 */
uint8_t write_Register_Number_H; /* 写入寄存器个数高八位 */
uint8_t write_Register_Number_L; /* 写入寄存器个数低八位 */
}SL_Mppt_WOReply_pack1;
/* 扫描广播帧F1智能模块->协处理器) */
typedef struct _SL_Mppt_ScanBroadcast_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_Scan_Broadcast_pack bpack;
SL_Tail_pack tail; /* 包尾 */
}SL_Mppt_Scan_Broadcast_pack1;
#define SL_MPPT_SCAN_BROADCAST_PACK_SIZE1 (sizeof(SL_Mppt_Scan_Broadcast_pack1))
/* 注册请求帧F2协处理器->智能模块) */
typedef struct _SL_Mppt_RegistrationRequest_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_RegistrationRequest_pack rpack;
SL_Tail_pack tail; /* 包尾 */
}SL_Mppt_RegistrationRequest_pack1;
#define SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE1 (sizeof(SL_Mppt_RegistrationRequest_pack1))
/* 注册回复帧F3智能模块->协处理器) */
typedef struct _SL_Mppt_RegistrationReply_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_RegistrationReply_pack rpack;
SL_Tail_pack tail; /* 包尾 */
}SL_Mppt_RegistrationReply_pack1;
#define SL_MPPT_REGISTRATIONREPLY_PACK_SIZE1 (sizeof(SL_Mppt_RegistrationReply_pack1))
/* 发送其他帧(智能模块->协处理器) */
typedef struct _SL_Mppt_SOther_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_SOther_pack spack;
SL_Tail_pack tail; /* 包尾 */
}SL_Mppt_SOther_pack1;
#define SL_MPPT_SOTHER_PACK_SIZE1 (sizeof(SL_Mppt_SOther_pack1))
/* 收到的其他帧(协处理器->智能模块) */
typedef struct _SL_Mppt_ROther_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_ROther_pack rpack;
SL_Tail_pack tail; /* 包尾 */
}SL_Mppt_ROther_pack1;
#define SL_MPPT_ROTHER_PACK_SIZE1 (sizeof(SL_Mppt_ROther_pack1))
/* */
typedef struct _SL_Mppt_Recv_pack1{
SL_Head_pack head; /* 包头 */
SL_Mppt_Recv_pack rpack;
}SL_Mppt_Recv_pack1;
//const uint8_t head_len = sizeof(SL_Head_pack);
/* 功能码处理函数 */
typedef void (*MsgProcFunc)(device_handle device, void*, uint32_t MsgLen);
typedef struct _SL_FunctionMsgProcTable{
@ -173,7 +277,8 @@ typedef struct _SL_FunctionMsgProcTable{
extern SL_Mppt_Scan_Broadcast_pack g_Scan_Broadcast_pack;
void read_and_process_uart_data(device_handle device);
void send_data(uint8_t *buff);
void read_and_process_sensorUart_data(device_handle device);
void read_and_process_intelligentModuleUart_data(device_handle device);
void send_uart_data(uint8_t *buff);
#endif /* SOFTWARE_PROTOCOL_COMMUNICATION_PROTOCOL_H_ */

View File

@ -15,16 +15,10 @@
#define UART_MQ_SEND_LENGTH 20
typedef struct _SL_UartSend_pack{
device_handle device; /* 串口 */
rt_uint8_t direction; /* 方向 */
rt_uint8_t len; /* 长度 */
rt_uint8_t recv_Data[UART_MQ_SEND_LENGTH]; /* 其他部分 */
}SL_UartSend_pack;
typedef enum{
up = 0, /* 往智能模块传传输数据 */
down = 1, /* 向下往传感器传输数据 */
}UartSend_pack_direction;
extern SL_UartSend_pack MqUartSend_pack;
extern rt_mq_t mqSend;

View File

@ -10,6 +10,17 @@
#include <string.h>
#include "thread_communication.h"
/* 用于解析串口包时的长度 */
#define readSensorAnalyzeStartFlag 2 //长度为2时解析起始标志
#define readSensorAnalyzeFunctionCode 10 //长度为10时解析功能码
#define readIntelligentModuleAnalyzeHeader 4 //长度为4时解析包尾
#define readIntelligentModuleAnalyzeStartFlag 6 //长度为6时解析起始标志
#define readIntelligentMOduleAnalyzeFunctionCode 14 //长度为14时解析功能码
SL_Mppt_Scan_Broadcast_pack g_Scan_Broadcast_pack = {
.start_Flag = "SL",
.address = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
@ -24,14 +35,36 @@ static uint8_t uart_buff[50]={0x00};
/* 静态函数申明 */
static void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadSensor_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadSensor_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadSensor_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadSensor_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen);
/* 功能码处理表 */
SL_FuncionMsgProcTable g_MsgTbl[] =
static void SL_MsgProcFuncReadIntelligentModule_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadIntelligentModule_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadIntelligentModule_Broadcast_Scan(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadIntelligentModule_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadIntelligentModule_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
static void SL_MsgProcFuncReadIntelligentModule_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen);
/* 传感器发送上来的数据功能码处理表 */
SL_FuncionMsgProcTable g_MsgReadSensorTbl[] =
{
{SL_Function_Code_Read_Register, SL_MsgProcFunc_Read_Register},
{SL_Function_Code_Registration_request, SL_MsgProcFunc_Registration_request},
{SL_Function_Code_Read_Register, SL_MsgProcFuncReadSensor_Read_Register},
{SL_Function_Code_Registration_request, SL_MsgProcFuncReadSensor_Registration_request},
{SL_Function_Code_Update_Profile, SL_MsgProcFuncReadSensor_Update_Profile},
{SL_Function_Code_Remote_Upgrade, SL_MsgProcFuncReadSensor_Remote_Upgrade},
};
/* 智能模组发送下来的数据功能码处理表 */
SL_FuncionMsgProcTable g_MsgReadIntelligentModuleTbl[] =
{
{SL_Function_Code_Read_Register, SL_MsgProcFuncReadIntelligentModule_Read_Register},
{SL_Function_Code_Write_Register, SL_MsgProcFuncReadIntelligentModule_Write_Register},
{SL_Function_Code_Broadcast_Scan, SL_MsgProcFuncReadIntelligentModule_Broadcast_Scan},
{SL_Function_Code_Registration_request, SL_MsgProcFuncReadIntelligentModule_Registration_request},
{SL_Function_Code_Update_Profile, SL_MsgProcFuncReadIntelligentModule_Update_Profile},
{SL_Function_Code_Remote_Upgrade, SL_MsgProcFuncReadIntelligentModule_Remote_Upgrade},
};
/**
@ -84,69 +117,118 @@ uint8_t Check_485_bus_busy(device_handle device)
return 1;
}
void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen)
void SL_MsgProcFuncReadSensor_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen)
{
memset(&MqUartSend_pack, 0, sizeof(MqUartSend_pack));
MqUartSend_pack.device = device;
MqUartSend_pack.direction = up;
MqUartSend_pack.len = MsgLen;
uint8_t *buf = (uint8_t *)pMsg;
for (uint8_t var = 0; var < MsgLen; ++var) {
MqUartSend_pack.recv_Data[var] = buf[var];
}
/* 发 送 消 息 到 消 息 队 列 中 */
if (rt_mq_send(mqSend, &MqUartSend_pack, MsgLen) != RT_EOK) {
rt_kprintf("rt_mq_send ERR\n");
}
}
void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
{
memset(&MqUartSend_pack, 0, sizeof(MqUartSend_pack));
MqUartSend_pack.device = device;
MqUartSend_pack.direction = down;
MqUartSend_pack.len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
// memset(&MqUartSend_pack, 0, sizeof(MqUartSend_pack));
// MqUartSend_pack.device = device;
// MqUartSend_pack.len = MsgLen;
//
// uint8_t *buf = (uint8_t *)pMsg;
// for (uint8_t var = 0; var < MsgLen; ++var) {
// MqUartSend_pack.recv_Data[var] = buf[var];
// }
//
// /* 发 送 消 息 到 消 息 队 列 中 */
// if (rt_mq_send(mqSend, &MqUartSend_pack, MsgLen) != RT_EOK) {
// rt_kprintf("rt_mq_send ERR\n");
// }
SL_Mppt_RegistrationReply_pack *rrpack = (SL_Mppt_RegistrationReply_pack *)MqUartSend_pack.recv_Data;
SL_Mppt_RegistrationRequest_pack *rpack = (SL_Mppt_RegistrationRequest_pack *)pMsg;
rt_kprintf(" in Sensor_Read_Register \n ");
rrpack->start_Flag[0] = rpack->start_Flag[0];
rrpack->start_Flag[1] = rpack->start_Flag[1];
}
rrpack->address[0] = rpack->access_Node_ID[0];
rrpack->address[1] = rpack->access_Node_ID[1];
rrpack->address[2] = rpack->access_Node_ID[2];
rrpack->address[3] = rpack->access_Node_ID[3];
rrpack->address[4] = rpack->access_Node_ID[4];
rrpack->address[5] = rpack->access_Node_ID[5];
rrpack->address[6] = rpack->access_Node_ID[6];
rrpack->address[7] = rpack->access_Node_ID[7];
void SL_MsgProcFuncReadSensor_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
{
// memset(&MqUartSend_pack, 0, sizeof(MqUartSend_pack));
// MqUartSend_pack.device = device;
// MqUartSend_pack.len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
//
//// uint8_t *buf = (uint8_t *)pMsg;
//// for (uint8_t var = 0; var < MsgLen; ++var) {
//// MqUartSend_pack.recv_Data[var] = buf[var];
//// }
//
// SL_Mppt_RegistrationReply_pack *rrpack = (SL_Mppt_RegistrationReply_pack *)MqUartSend_pack.recv_Data;
// SL_Mppt_RegistrationRequest_pack *rpack = (SL_Mppt_RegistrationRequest_pack *)pMsg;
//
// rrpack->start_Flag[0] = rpack->start_Flag[0];
// rrpack->start_Flag[1] = rpack->start_Flag[1];
//
// rrpack->address[0] = rpack->access_Node_ID[0];
// rrpack->address[1] = rpack->access_Node_ID[1];
// rrpack->address[2] = rpack->access_Node_ID[2];
// rrpack->address[3] = rpack->access_Node_ID[3];
// rrpack->address[4] = rpack->access_Node_ID[4];
// rrpack->address[5] = rpack->access_Node_ID[5];
// rrpack->address[6] = rpack->access_Node_ID[6];
// rrpack->address[7] = rpack->access_Node_ID[7];
//
// rrpack->function_Code = rpack->function_Code;
//
// rrpack->register_Length_H = rpack->register_Length_H;
// rrpack->register_Length_L = rpack->register_Length_L;
//
// rrpack->registration_Status_H = 0x00;
// rrpack->registration_Status_L = 0x02;
//
// uint16_t crc_16 = CheckFunc(MqUartSend_pack.recv_Data, SL_MPPT_REGISTRATIONREPLY_PACK_SIZE - 3);
// rrpack->check_Bit_H = crc_16 >> 8;
// rrpack->check_Bit_L = crc_16;
//
// rrpack->end_Flag = 0x16;
//
// /* 发 送 消 息 到 消 息 队 列 中 */
// if (rt_mq_send(mqSend, &MqUartSend_pack, sizeof(MqUartSend_pack)) != RT_EOK) {
// rt_kprintf("rt_mq_send ERR\n");
// }
rrpack->function_Code = rpack->function_Code;
rt_kprintf(" in Sensor_Registration_request \n ");
rrpack->register_Length_H = rpack->register_Length_H;
rrpack->register_Length_L = rpack->register_Length_L;
}
rrpack->registration_Status_H = 0x00;
rrpack->registration_Status_L = 0x02;
uint16_t crc_16 = CheckFunc(MqUartSend_pack.recv_Data, SL_MPPT_REGISTRATIONREPLY_PACK_SIZE - 3);
rrpack->check_Bit_H = crc_16 >> 8;
rrpack->check_Bit_L = crc_16;
void SL_MsgProcFuncReadSensor_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen)
{
rrpack->end_Flag = 0x16;
rt_kprintf(" in Sensor_Update_Profile \n ");
/* 发 送 消 息 到 消 息 队 列 中 */
if (rt_mq_send(mqSend, &MqUartSend_pack, sizeof(MqUartSend_pack)) != RT_EOK) {
rt_kprintf("rt_mq_send ERR\n");
}
}
void SL_MsgProcFuncReadSensor_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Sensor_Remote_Upgrade \n ");
}
void SL_MsgProcFuncReadIntelligentModule_Read_Register(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Read_Register \n ");
}
void SL_MsgProcFuncReadIntelligentModule_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Write_Register \n ");
}
void SL_MsgProcFuncReadIntelligentModule_Broadcast_Scan(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Broadcast_Scan \n ");
}
void SL_MsgProcFuncReadIntelligentModule_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Registration_request \n ");
}
void SL_MsgProcFuncReadIntelligentModule_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Update_Profile \n ");
}
void SL_MsgProcFuncReadIntelligentModule_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen)
{
rt_kprintf(" in Remote_Upgrade \n ");
}
@ -165,41 +247,114 @@ static int Match_Startflag(uint8_t start_buff[2])
return 0;
}
///**
// * @brief 匹配广播地址
// * @param address 地址
// * @retval 1 匹配成功
// * 0 匹配失败
// */
//static int Match_Broadcastaddress(uint8_t address[7])
//{
// if (address[0] == 0xFF && \
// address[1] == 0xFF && \
// address[2] == 0xFF && \
// address[3] == 0xFF && \
// address[4] == 0xFF && \
// address[5] == 0xFF && \
// address[6] == 0xFF) {
//
// return 1;
// }
// return 0;
//}
/**
* @brief
* @brief
* @param uart_handle
* @param buff
* @param buff_size
* @retval
*/
static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
static int uart_read_sensor_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
{
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)buff;
uint32_t offset = 0;
uint32_t len = 0;
uint8_t r_Flag = 0; /* 读的标志位 */
uint8_t flag_run = 0;
char c = 0;
buff_size--; //预留一个'\0'位置
for (; offset < buff_size;){
if (ring_queue_length(uart_handle) == 0) {
break;
}
c = uart_dev_in_char(uart_handle);
buff[offset++] = c;
/* 匹配起始标志位 */
if (offset == readSensorAnalyzeStartFlag || (flag_run > 0)) {
if (!Match_Startflag(pack->start_Flag)) {
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
// rt_kprintf("start_Flag success \n");
}
/* 匹配功能码 */
if ((offset == readSensorAnalyzeFunctionCode) || (flag_run > 2)) {
/* 读寄存器数据 */
if (pack->function_Code == SL_Function_Code_Read_Register) {
}
/* 注册请求 */
else if ((pack->function_Code == SL_Function_Code_Registration_request)) {
len = SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE;
}
/* 远程升级或配置文件更改 */
else if ((pack->function_Code == SL_Function_Code_Update_Profile)
|| (pack->function_Code == SL_Function_Code_Remote_Upgrade)) {
len = SL_MPPT_ROTHER_PACK_SIZE;
}
else {
if (flag_run < 2) {
flag_run = 2;
}
// rt_kprintf("function_Code error : %x \n", pack->function_Code);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
if ((offset == 12) && (pack->function_Code == SL_Function_Code_Read_Register)) {
SL_Mppt_ROReply_pack *rpack = (SL_Mppt_ROReply_pack *)buff;
uint8_t Register_Number = (rpack->reply_Register_Number_H << 8) | rpack->reply_Register_Number_L;
// rt_kprintf("Register_Number : %d \n", Register_Number);
len = Register_Number * 2 + SL_MPPT_ROReply_PACK_SIZE - 4;
continue;
}
if (offset == len) {
uint16_t crc_16 = buff[offset - 2] | (buff[offset - 3] << 8);
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
if (flag_run < 3) {
flag_run = 3;
}
// rt_kprintf("crc: %x, end_Flag: %x \n", CheckFunc(buff, offset - 3), buff[offset - 1]);
memcpy(buff, buff+1, offset-1);
offset--;
} else {
// rt_kprintf("success return offset : %d \n", offset);
return offset;
}
}
}
return 0;
}
/**
* @brief
* @param uart_handle
* @param buff
* @param buff_size
* @retval
*/
static int uart_read_intelligentModule_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
{
SL_Mppt_Recv_pack1 *pack = (SL_Mppt_Recv_pack1 *)buff;
uint32_t offset = 0;
uint32_t len = 0;
uint8_t flag_run = 0;
char c = 0;
@ -215,134 +370,196 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
buff[offset++] = c;
/* 匹配起始标志位 */
if (offset == sizeof(pack->start_Flag) || (flag_run > 0)) {
if (!Match_Startflag(pack->start_Flag)) {
if (offset == sizeof(SL_Head_pack)) {
}
/* 匹配包头 */
if ((offset == readIntelligentModuleAnalyzeHeader) || (flag_run > 0)) {
if (!Match_Startflag(pack->head.start_Flag)) {
// rt_kprintf("header error1 : %s \n", pack->head.start_Flag);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
// /* 匹配地址 */
// if (offset == (sizeof(pack->start_Flag) + sizeof(pack->address)) || (flag_run > 1)) {
// /* 匹配广播地址,设备地址不做匹配 */
// if (Match_Broadcastaddress(pack->address)) {
// b_Flag = 1;
// }
//
// }
/* 匹配功能码 */
if ((offset == (sizeof(pack->start_Flag) + sizeof(pack->address) + sizeof(pack->function_Code))) || (flag_run > 2)) {
/* 读寄存器数据 */
if (pack->function_Code == SL_Function_Code_Read_Register) {
r_Flag = 1;
if (!((pack->head.uart > 0) && (pack->head.uart < 9))) {
// rt_kprintf("header error2 : %d \n", pack->head.uart);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
/* 注册请求 */
else if ((pack->function_Code == SL_Function_Code_Registration_request)) {
len = SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE;
r_Flag = 0;
if (!(((pack->head.uart == 3) && ((pack->head.Channel == 0) ||
(pack->head.Channel < 10 && pack->head.Channel > 4)))
|| (pack->head.uart != 3))) {
// rt_kprintf("header error3 : %d \n", pack->head.Channel);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
// rt_kprintf("header success \n");
}
/* 匹配起始标志位 */
if (offset == readIntelligentModuleAnalyzeStartFlag || (flag_run > 1)) {
if (!Match_Startflag(pack->rpack.start_Flag)) {
if (flag_run < 1) {
flag_run = 1;
}
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
// rt_kprintf("start_Flag success \n");
}
/* 匹配功能码 */
if ((offset == readIntelligentMOduleAnalyzeFunctionCode) || (flag_run > 2)) {
/* 读寄存器数据 */
if (pack->rpack.function_Code == SL_Function_Code_Read_Register) {
len = SL_MPPT_RORECV_PACK_SIZE1;
}
/* 写寄存器数据 */
else if (pack->rpack.function_Code == SL_Function_Code_Write_Register) {
// len = SL_MPPT_RORECV_PACK_SIZE1;
}
/* 广播请求 */
else if (pack->rpack.function_Code == SL_Function_Code_Broadcast_Scan) {
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE1;
}
/* 注册回复 */
else if ((pack->rpack.function_Code == SL_Function_Code_Registration_request)) {
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE1;
}
/* 远程升级或配置文件更改 */
else if ((pack->rpack.function_Code == SL_Function_Code_Update_Profile)
|| (pack->rpack.function_Code == SL_Function_Code_Remote_Upgrade)) {
len = SL_MPPT_SOTHER_PACK_SIZE1;
}
else {
if (flag_run < 2) {
flag_run = 2;
}
r_Flag = 0;
// rt_kprintf("function_Code error : %x \n", pack->rpack.function_Code);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
if ((1 == r_Flag) && (offset == 12)) {
SL_Mppt_ROReply_pack *rpack = (SL_Mppt_ROReply_pack *)buff;
uint8_t Register_Number = (rpack->reply_Register_Number_H << 8) | rpack->reply_Register_Number_L;
len = Register_Number * 2 + SL_MPPT_ROReply_PACK_SIZE - 4;
if ((offset == 18) && (pack->rpack.function_Code == SL_Function_Code_Write_Register)) {
SL_Mppt_WOReply_pack1 *rpack = (SL_Mppt_WOReply_pack1 *)buff;
uint16_t Register_Number = (rpack->write_Register_Number_H << 8) | rpack->write_Register_Number_L;
// rt_kprintf("Register_Number : %d \n", Register_Number);
len = Register_Number * 2 + 22;
continue;
}
if (offset == len) {
/* 读寄存器数据 */
if (pack->function_Code == SL_Function_Code_Read_Register) {
uint16_t crc_16 = buff[offset - 2] | (buff[offset - 3] << 8);
uint16_t crc_16 = buff[offset - 3] | (buff[offset - 4] << 8);
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
if (flag_run < 3) {
flag_run = 3;
}
memcpy(buff, buff+1, offset-1);
offset--;
} else {
return offset;
}
}
else {
SL_Mppt_RegistrationRequest_pack *rpack = (SL_Mppt_RegistrationRequest_pack *)buff;
uint16_t crc_16 = rpack->check_Bit_L | (rpack->check_Bit_H << 8);
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
if (flag_run < 3) {
flag_run = 3;
}
memcpy(buff, buff+1, offset-1);
offset--;
} else {
return offset;
}
if ((CheckFunc(buff + 4, offset - 8) != crc_16) || (buff[offset - 2] != 0x16) || (buff[offset - 1] != 0x17)) {
if (flag_run < 3) {
flag_run = 3;
}
// rt_kprintf("crc: %x, end_Flag: %x, tail.end_Flag: %x \n", CheckFunc(buff + 4, offset - 8), buff[offset - 2], buff[offset - 1]);
memcpy(buff, buff+1, offset-1);
offset--;
} else {
// rt_kprintf("success return offset : %d \n", offset);
return offset;
}
}
}
return 0;
}
/**
* @brief
* @brief
* @param
* @retval
*
*/
void FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
void FRT_SensorMsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
{
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)pMsg;
for (u_int16_t i = 0; i < sizeof(g_MsgTbl) / sizeof(SL_FuncionMsgProcTable); i++) {
if (pack->function_Code == g_MsgTbl[i].msgId) {
g_MsgTbl[i].pMsgProc(device, pMsg, MsgLen);
for (u_int16_t i = 0; i < sizeof(g_MsgReadSensorTbl) / sizeof(SL_FuncionMsgProcTable); i++) {
if (pack->function_Code == g_MsgReadSensorTbl[i].msgId) {
g_MsgReadSensorTbl[i].pMsgProc(device, pMsg, MsgLen);
}
}
}
/**
* @brief
* @brief
* @param
* @retval
*/
void read_and_process_uart_data(device_handle device)
void FRT_IntelligentModuleMsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
{
if (uart_dev_char_present(device)) {
rt_thread_mdelay(30);
rt_kprintf("ring_queue_length = %d \n", ring_queue_length(device));
memset(uart_buff, 0, sizeof(uart_buff));
int ret = uart_read_climate_pack(device, uart_buff, sizeof(uart_buff));
if(ret > 0){
FRT_MsgHandler(device, uart_buff, ret);
SL_Mppt_Recv_pack1 *pack = (SL_Mppt_Recv_pack1 *)pMsg;
for (u_int16_t i = 0; i < sizeof(g_MsgReadIntelligentModuleTbl) / sizeof(SL_FuncionMsgProcTable); i++) {
if (pack->rpack.function_Code == g_MsgReadIntelligentModuleTbl[i].msgId) {
// rt_kprintf("function_Code error : %x \n", pack->rpack.function_Code);
g_MsgReadIntelligentModuleTbl[i].pMsgProc(device, pMsg, MsgLen);
}
}
}
/**
* @brief
* @param
* @retval
*/
void read_and_process_sensorUart_data(device_handle device)
{
if (uart_dev_char_present(device)) {
rt_thread_mdelay(30);
// rt_kprintf("ring_queue_length = %d \n", ring_queue_length(device));
memset(uart_buff, 0, sizeof(uart_buff));
int ret = uart_read_sensor_pack(device, uart_buff, sizeof(uart_buff));
if(ret > 0){
FRT_SensorMsgHandler(device, uart_buff, ret);
}
}
}
/**
* @brief
* @param
* @retval
*/
void read_and_process_intelligentModuleUart_data(device_handle device)
{
if (uart_dev_char_present(device)) {
rt_thread_mdelay(10);
rt_kprintf("ring_queue_length = %d \n", ring_queue_length(device));
memset(uart_buff, 0, sizeof(uart_buff));
int ret = uart_read_intelligentModule_pack(device, uart_buff, sizeof(uart_buff));
if(ret > 0){
FRT_IntelligentModuleMsgHandler(device, uart_buff, ret);
}
}
}
/**
* @brief
* @param
* @retval
*/
static void send_uart_data(uint8_t *buff)
void send_uart_data(uint8_t *buff)
{
SL_UartSend_pack *upack = (SL_UartSend_pack *)buff;
@ -350,19 +567,4 @@ static void send_uart_data(uint8_t *buff)
}
/**
* @brief
* @param
* @retval
*/
void send_data(uint8_t *buff)
{
SL_UartSend_pack *upack = (SL_UartSend_pack *)buff;
if (upack->direction == down) {
send_uart_data(buff);
}
}

View File

@ -72,30 +72,28 @@ void Send_thread_Init(void)
void Recv_thread_entry(void* parameter)
{
rt_kprintf("\n Recv \n");
while (1) {
read_and_process_uart_data(g_J1RS485_UART6_handle);
read_and_process_uart_data(g_J2RS485_UART7_handle);
read_and_process_uart_data(g_J3RS485_USART2_handle);
read_and_process_uart_data(g_J4RS485_UART8_handle);
read_and_process_uart_data(g_J50RS485_USART3_handle);
read_and_process_uart_data(g_LORA_UART4_handle);
read_and_process_uart_data(g_Upward_UART5_handle);
rt_thread_mdelay(100);
read_and_process_sensorUart_data(g_J1RS485_UART6_handle);
read_and_process_sensorUart_data(g_J2RS485_UART7_handle);
read_and_process_sensorUart_data(g_J3RS485_USART2_handle);
read_and_process_sensorUart_data(g_J4RS485_UART8_handle);
read_and_process_sensorUart_data(g_J50RS485_USART3_handle);
read_and_process_sensorUart_data(g_LORA_UART4_handle);
read_and_process_intelligentModuleUart_data(g_Upward_UART5_handle);
// rt_thread_mdelay(100);
}
}
void Send_thread_entry(void* parameter)
{
uint8_t buff[100];
rt_kprintf("\n Send \n");
// uint8_t buff[100];
while (1) {
// memset(buff, 0, sizeof(buff));
// rt_mq_recv(mqSend, buff, sizeof(buff), RT_WAITING_FOREVER);
// rt_kprintf("\n Send buff \n");
// send_data(buff);
// send_uart_data(buff);
uart_dev_write(g_Upward_UART5_handle, "hello world\n", sizeof("hello world\n"));
rt_thread_mdelay(1000);
// uart_dev_write(g_Upward_UART5_handle, "hello world\n", sizeof("hello world\n"));
// rt_thread_mdelay(1000);
}
}

View File

@ -443,6 +443,8 @@ void uart_dev_write(device_handle device, void *data, int len)
J50RS485_tx_disenabla();
}
#endif
rt_thread_mdelay(1);
}
/**

View File

@ -36,7 +36,6 @@ int main(void)
rt_kprintf(" ChipID: %08x\r\n",DBGMCU_GetCHIPID());
app_star();
}

View File

@ -1,6 +1,5 @@
#include <start.h>
#include "inc/Android.h"
#include "inc/Flash.h"
#include "inc/UART.h"
@ -13,36 +12,46 @@
/*
*
*
* @brief
* @param
* @retval
*
*/
void hareware_init()
{
android_PowerCtrl_Init();
android_PowerCtrl_Open();
android_PowerKey_Init();
// android_PowerKey_Rest();
// rt_kprintf("\nandroid_PowerKey_Rest OK\n");
J4_PWR_Open();
// SPI_Flash_TEST();
}
/*
* 线
*
* @brief 线
* @param
* @retval
*
*/
void software_init()
{
uart_all_dev_init();
Send_mq_Init();
// Send_mq_Init();
Recv_thread_Init();
Send_thread_Init();
// Send_thread_Init();
// while (1) {
//// uart_dev_write(g_J4RS485_UART8_handle, "hello world\n", sizeof("hello world\n"));
// rt_thread_delay(1000);
// }
}
/*
*
*
* @brief
* @param
* @retval
*
*/
void app_star()

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.