更改串口发送和接收部分的内容,功能码增加配置文件和远程升级
This commit is contained in:
parent
6b9e8fae9c
commit
c63c185d85
|
@ -19,6 +19,8 @@ typedef enum
|
||||||
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
|
SL_Function_Code_Write_Register = 0x10, /* 写寄存器数据 */
|
||||||
SL_Function_Code_Broadcast_Scan = 0xA0, /* 广播扫描 */
|
SL_Function_Code_Broadcast_Scan = 0xA0, /* 广播扫描 */
|
||||||
SL_Function_Code_Registration_request = 0xA1, /* 注册请求 */
|
SL_Function_Code_Registration_request = 0xA1, /* 注册请求 */
|
||||||
|
SL_Function_Code_Update_Profile = 0xD0, /* 配置文件 */
|
||||||
|
SL_Function_Code_Remote_Upgrade = 0xD1, /* 远程升级 */
|
||||||
}SL_MsgFunctionCode;
|
}SL_MsgFunctionCode;
|
||||||
|
|
||||||
/* 寄存器地址 */
|
/* 寄存器地址 */
|
||||||
|
@ -122,6 +124,30 @@ typedef struct _SL_Mppt_RegistrationReply_pack{
|
||||||
}SL_Mppt_RegistrationReply_pack;
|
}SL_Mppt_RegistrationReply_pack;
|
||||||
#define SL_MPPT_REGISTRATIONREPLY_PACK_SIZE (sizeof(SL_Mppt_RegistrationReply_pack))
|
#define SL_MPPT_REGISTRATIONREPLY_PACK_SIZE (sizeof(SL_Mppt_RegistrationReply_pack))
|
||||||
|
|
||||||
|
/* 接收其他帧格式(汇聚网关->接入节点) */
|
||||||
|
typedef struct _SL_Mppt_ROther_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_ROther_pack;
|
||||||
|
#define SL_MPPT_ROTHER_PACK_SIZE (sizeof(SL_Mppt_ROther_pack))
|
||||||
|
|
||||||
|
/* 发送其他帧格式(接入节点->汇聚网关) */
|
||||||
|
typedef struct _SL_Mppt_SOther_pack{
|
||||||
|
uint8_t start_Flag[2]; /* 起始标志 */
|
||||||
|
uint8_t address[7]; /* 地址 */
|
||||||
|
uint8_t function_Code; /* 功能码 */
|
||||||
|
uint8_t state; /* 准备状态,01H准备完毕 */
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
/* */
|
/* */
|
||||||
#define RECV_LENGTH 20
|
#define RECV_LENGTH 20
|
||||||
typedef struct _SL_Mppt_Recv_pack{
|
typedef struct _SL_Mppt_Recv_pack{
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
#define CHG_CURR ADC_Channel_1
|
#define CHG_CURR ADC_Channel_1
|
||||||
#define PV_VOLT_OUT ADC_Channel_2
|
#define PV_VOLT_OUT ADC_Channel_2
|
||||||
|
@ -222,11 +225,11 @@ float get_PV_VOLT_IN1(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const float Rp = 10000.0; //10K
|
//const float Rp = 10000.0; //10K
|
||||||
const float T2 = (273.15+25.0);//T2
|
//const float T2 = (273.15+25.0);//T2
|
||||||
const float Bx = 3950.0;//B
|
//const float Bx = 3950.0;//B
|
||||||
//const float Bx = 3435.0;//B
|
////const float Bx = 3435.0;//B
|
||||||
const float Ka = 273.15;
|
//const float Ka = 273.15;
|
||||||
/**
|
/**
|
||||||
* @brief µÃµ½Î¶È
|
* @brief µÃµ½Î¶È
|
||||||
* @param
|
* @param
|
||||||
|
@ -238,19 +241,6 @@ float get_MOSFET_Temper(void)
|
||||||
uint16_t T_ADC;
|
uint16_t T_ADC;
|
||||||
|
|
||||||
T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper));
|
T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper));
|
||||||
// T_ADC = get_adc(MOSFET_Temper);
|
|
||||||
|
|
||||||
// float V = (float)(T_ADC) / 4095 * 3.3;
|
|
||||||
// float R = (float)(10 * V) / (3.3 - V);
|
|
||||||
//
|
|
||||||
// T = R / Rp;
|
|
||||||
// T = log(T);//ln(Rt/Rp)
|
|
||||||
// T /= Bx;//ln(Rt/Rp)/B
|
|
||||||
// T += (1.0 / T2);
|
|
||||||
// T = 1.0 / (T);
|
|
||||||
// T -= Ka;
|
|
||||||
|
|
||||||
float Res = 10.0 * T_ADC / (4094 - T_ADC);
|
|
||||||
|
|
||||||
for (int i = 0; i < mosTemperADCLen; ++i) {
|
for (int i = 0; i < mosTemperADCLen; ++i) {
|
||||||
if (T_ADC >= mosTemperADC[i]) {
|
if (T_ADC >= mosTemperADC[i]) {
|
||||||
|
@ -264,9 +254,14 @@ float get_MOSFET_Temper(void)
|
||||||
#ifdef enable_Printf_VI
|
#ifdef enable_Printf_VI
|
||||||
printf("\n MOSFET_Temper ADC : %d \n", T_ADC);
|
printf("\n MOSFET_Temper ADC : %d \n", T_ADC);
|
||||||
printf(" MOSFET_Temper T : %d /10 \n", (int)(T * 10));
|
printf(" MOSFET_Temper T : %d /10 \n", (int)(T * 10));
|
||||||
printf(" MOSFET_Temper Res : %d /10000 \n", (int)(Res * 10000));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// const uint16_t arr[] = {1, 2, 4, 5, 6, 8, 9};
|
||||||
|
// int size = sizeof(arr) / sizeof(arr[0]);
|
||||||
|
// int x = 3;
|
||||||
|
// int index = findNearest(arr, size, x);
|
||||||
|
// printf("The nearest element to %d is %d at index %d\n", x, arr[index], index);
|
||||||
|
|
||||||
return T;
|
return T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ static void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint3
|
||||||
static void SL_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen);
|
static void SL_MsgProcFunc_Write_Register(device_handle device, void *pMsg, uint32_t MsgLen);
|
||||||
static void SL_MsgProcFunc_Broadcast_Scan(device_handle device, void *pMsg, uint32_t MsgLen);
|
static void SL_MsgProcFunc_Broadcast_Scan(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_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen);
|
||||||
|
static void SL_MsgProcFunc_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen);
|
||||||
|
static void SL_MsgProcFunc_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen);
|
||||||
|
|
||||||
static uint16_t SL_ReadRegisterRegistrationStatus(void *pMsg);
|
static uint16_t SL_ReadRegisterRegistrationStatus(void *pMsg);
|
||||||
static uint16_t SL_ReadRegisteraddress(void *pMsg);
|
static uint16_t SL_ReadRegisteraddress(void *pMsg);
|
||||||
|
@ -43,12 +45,6 @@ static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage2(void *pMsg);
|
||||||
|
|
||||||
/* 读取串口数据时用该数组解析 */
|
/* 读取串口数据时用该数组解析 */
|
||||||
static uint8_t rs485_buff[50]={0x00};
|
static uint8_t rs485_buff[50]={0x00};
|
||||||
///* 存储剩余的字符 */
|
|
||||||
//typedef struct _save_buff{
|
|
||||||
// uint8_t save_rs485_buff[20];
|
|
||||||
// uint8_t len;
|
|
||||||
//}save_buff;
|
|
||||||
//static save_buff save_485buf = {0};
|
|
||||||
|
|
||||||
/* 一次最多读写的寄存器个数,由设备决定 */
|
/* 一次最多读写的寄存器个数,由设备决定 */
|
||||||
#define Register_Number_Max 5
|
#define Register_Number_Max 5
|
||||||
|
@ -57,8 +53,12 @@ static uint8_t rs485_buff[50]={0x00};
|
||||||
/* 读写的寄存器的最大起始位置,由设备决定 */
|
/* 读写的寄存器的最大起始位置,由设备决定 */
|
||||||
#define Register_Start_Address_Max 0x0200
|
#define Register_Start_Address_Max 0x0200
|
||||||
|
|
||||||
/* 注册成功是否接收扫描 */
|
/* 用于解析串口包时的长度 */
|
||||||
#define SuccessRegistrationAcceptScan
|
#define analyzeStartFlag 2 //长度为2时解析起始标志
|
||||||
|
#define analyzeAddress 9 //长度为9时解析地址
|
||||||
|
#define analyzeFunctionCode 10 //长度为10时解析功能码
|
||||||
|
#define analyzeWritelen 14 //功能码为写入寄存器且buffer长度为14时,可以解析出写入寄存器包的长度
|
||||||
|
|
||||||
|
|
||||||
/* 功能码处理表 */
|
/* 功能码处理表 */
|
||||||
SL_FuncionMsgProcTable g_MsgTbl[] =
|
SL_FuncionMsgProcTable g_MsgTbl[] =
|
||||||
|
@ -67,6 +67,8 @@ SL_FuncionMsgProcTable g_MsgTbl[] =
|
||||||
{SL_Function_Code_Write_Register, SL_MsgProcFunc_Write_Register},
|
{SL_Function_Code_Write_Register, SL_MsgProcFunc_Write_Register},
|
||||||
{SL_Function_Code_Broadcast_Scan, SL_MsgProcFunc_Broadcast_Scan},
|
{SL_Function_Code_Broadcast_Scan, SL_MsgProcFunc_Broadcast_Scan},
|
||||||
{SL_Function_Code_Registration_request, SL_MsgProcFunc_Registration_request},
|
{SL_Function_Code_Registration_request, SL_MsgProcFunc_Registration_request},
|
||||||
|
{SL_Function_Code_Update_Profile, SL_MsgProcFunc_Update_Profile},
|
||||||
|
{SL_Function_Code_Remote_Upgrade, SL_MsgProcFunc_Remote_Upgrade},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,7 +251,21 @@ void SL_MsgProcFunc_Read_Register(device_handle device, void *pMsg, uint32_t Msg
|
||||||
|
|
||||||
replay_pack += 1;
|
replay_pack += 1;
|
||||||
*replay_pack = g_slConfigInfo.end_Flag;
|
*replay_pack = g_slConfigInfo.end_Flag;
|
||||||
uart_dev_write(device, rs485_buff, (2 + 7 + 1 + 2 + Register_Number_16 * 2 + 2 + 2));
|
|
||||||
|
while (1) {
|
||||||
|
Delay_Ms(randomDelay());
|
||||||
|
if (!Check_485_bus_busy(device)) {
|
||||||
|
uart_dev_write(device, (uint8_t *)&replay_pack, 16 + Register_Number_16 * 2 + 1);
|
||||||
|
|
||||||
|
if (device == g_bat485_uart3_handle) {
|
||||||
|
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||||
|
} else {
|
||||||
|
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -295,9 +311,9 @@ void SL_MsgProcFunc_Broadcast_Scan(device_handle device, void *pMsg, uint32_t Ms
|
||||||
RegistrationRequestFlag = 1;
|
RegistrationRequestFlag = 1;
|
||||||
|
|
||||||
/* 任务创立后,立即执行一次 */
|
/* 任务创立后,立即执行一次 */
|
||||||
m_recvbroadcast.runFlag = 1;
|
|
||||||
TimeSliceOffset_Register(&m_recvbroadcast, Task_recvbroadcast \
|
TimeSliceOffset_Register(&m_recvbroadcast, Task_recvbroadcast \
|
||||||
, recvbroadcast_reloadVal, recvbroadcast_offset);
|
, recvbroadcast_reloadVal, recvbroadcast_offset);
|
||||||
|
m_recvbroadcast.runFlag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
|
void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint32_t MsgLen)
|
||||||
|
@ -315,6 +331,90 @@ void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg, uint3
|
||||||
TIM_Cmd(TIM2, ENABLE); //TIM2使能
|
TIM_Cmd(TIM2, ENABLE); //TIM2使能
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SL_MsgProcFunc_Update_Profile(device_handle device, void *pMsg, uint32_t MsgLen)
|
||||||
|
{
|
||||||
|
SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
|
||||||
|
|
||||||
|
SUpdateProfile_pack.start_Flag[0] = g_slConfigInfo.start_Flag[0];
|
||||||
|
SUpdateProfile_pack.start_Flag[1] = g_slConfigInfo.start_Flag[1];
|
||||||
|
|
||||||
|
SUpdateProfile_pack.address[0] = g_slConfigInfo.address[0];
|
||||||
|
SUpdateProfile_pack.address[1] = g_slConfigInfo.address[1];
|
||||||
|
SUpdateProfile_pack.address[2] = g_slConfigInfo.address[2];
|
||||||
|
SUpdateProfile_pack.address[3] = g_slConfigInfo.address[3];
|
||||||
|
SUpdateProfile_pack.address[4] = g_slConfigInfo.address[4];
|
||||||
|
SUpdateProfile_pack.address[5] = g_slConfigInfo.address[5];
|
||||||
|
SUpdateProfile_pack.address[6] = g_slConfigInfo.address[6];
|
||||||
|
|
||||||
|
SUpdateProfile_pack.function_Code = SL_Function_Code_Update_Profile;
|
||||||
|
|
||||||
|
SUpdateProfile_pack.state = 0x01;
|
||||||
|
|
||||||
|
uint16_t crc = CheckFunc((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
|
||||||
|
SUpdateProfile_pack.check_Bit_H = crc >> 8;
|
||||||
|
SUpdateProfile_pack.check_Bit_L = crc;
|
||||||
|
|
||||||
|
SUpdateProfile_pack.end_Flag = g_slConfigInfo.end_Flag;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
Delay_Ms(randomDelay());
|
||||||
|
if (!Check_485_bus_busy(device)) {
|
||||||
|
uart_dev_write(device, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE + 1);
|
||||||
|
|
||||||
|
if (device == g_bat485_uart3_handle) {
|
||||||
|
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||||
|
} else {
|
||||||
|
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SL_MsgProcFunc_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen)
|
||||||
|
{
|
||||||
|
SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
|
||||||
|
|
||||||
|
SUpdateProfile_pack.start_Flag[0] = g_slConfigInfo.start_Flag[0];
|
||||||
|
SUpdateProfile_pack.start_Flag[1] = g_slConfigInfo.start_Flag[1];
|
||||||
|
|
||||||
|
SUpdateProfile_pack.address[0] = g_slConfigInfo.address[0];
|
||||||
|
SUpdateProfile_pack.address[1] = g_slConfigInfo.address[1];
|
||||||
|
SUpdateProfile_pack.address[2] = g_slConfigInfo.address[2];
|
||||||
|
SUpdateProfile_pack.address[3] = g_slConfigInfo.address[3];
|
||||||
|
SUpdateProfile_pack.address[4] = g_slConfigInfo.address[4];
|
||||||
|
SUpdateProfile_pack.address[5] = g_slConfigInfo.address[5];
|
||||||
|
SUpdateProfile_pack.address[6] = g_slConfigInfo.address[6];
|
||||||
|
|
||||||
|
SUpdateProfile_pack.function_Code = SL_Function_Code_Remote_Upgrade;
|
||||||
|
|
||||||
|
SUpdateProfile_pack.state = 0x01;
|
||||||
|
|
||||||
|
uint16_t crc = CheckFunc((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
|
||||||
|
SUpdateProfile_pack.check_Bit_H = crc >> 8;
|
||||||
|
SUpdateProfile_pack.check_Bit_L = crc;
|
||||||
|
|
||||||
|
SUpdateProfile_pack.end_Flag = g_slConfigInfo.end_Flag;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
Delay_Ms(randomDelay());
|
||||||
|
if (!Check_485_bus_busy(device)) {
|
||||||
|
uart_dev_write(device, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE + 1);
|
||||||
|
|
||||||
|
if (device == g_bat485_uart3_handle) {
|
||||||
|
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||||
|
} else {
|
||||||
|
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 读取注册状态寄存器
|
* @brief 读取注册状态寄存器
|
||||||
* @param
|
* @param
|
||||||
|
@ -548,18 +648,9 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
|
||||||
{
|
{
|
||||||
uint32_t offset = 0;
|
uint32_t offset = 0;
|
||||||
uint32_t len = 0;
|
uint32_t len = 0;
|
||||||
uint8_t w_Flag = 0;
|
|
||||||
uint8_t flag_run = 0;
|
uint8_t flag_run = 0;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
|
|
||||||
// /* 将上次未解析完的放入当前buf中 */
|
|
||||||
// if (save_485buf.save_rs485_buff[0] == 'S') {
|
|
||||||
// printf("\n ******* \n");
|
|
||||||
// strlcpy(buff, save_485buf.save_rs485_buff, save_485buf.len);
|
|
||||||
// memcpy(save_485buf.save_rs485_buff, 0, sizeof(save_485buf.len));
|
|
||||||
// offset = save_485buf.len;
|
|
||||||
// }
|
|
||||||
|
|
||||||
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)buff;
|
SL_Mppt_Recv_pack *pack = (SL_Mppt_Recv_pack *)buff;
|
||||||
|
|
||||||
buff_size--; //预留一个'\0'位置
|
buff_size--; //预留一个'\0'位置
|
||||||
|
@ -573,117 +664,109 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
|
||||||
buff[offset++] = c;
|
buff[offset++] = c;
|
||||||
|
|
||||||
/* 匹配起始标志位 */
|
/* 匹配起始标志位 */
|
||||||
if (offset == sizeof(pack->start_Flag) || (flag_run > 0)) {
|
if (offset == analyzeStartFlag || (flag_run > 0)) {
|
||||||
if (!Match_Startflag(pack->start_Flag)) {
|
if (!Match_Startflag(pack->start_Flag)) {
|
||||||
memcpy(buff, buff+1, offset-1);
|
memcpy(buff, buff+1, offset-1);
|
||||||
offset--;
|
offset--;
|
||||||
// buff_size--;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 匹配地址 */
|
/* 匹配地址 */
|
||||||
if (offset == (sizeof(pack->start_Flag) + sizeof(pack->address)) || (flag_run > 1)) {
|
if (offset == analyzeAddress || (flag_run > 1)) {
|
||||||
/* 匹配设备地址,设备未注册,也可能匹配广播地址 */
|
if (!((((g_Mppt_Para.Registration_Status == 2) || RegistrationRequestFlag) && Match_address(pack->address))
|
||||||
if (!((((g_Mppt_Para.Registration_Status == 2) && Match_address(pack->address)) || RegistrationRequestFlag)
|
|| (run_Broadcast && Match_Broadcastaddress(pack->address)))) {
|
||||||
// if (!((Match_address(pack->address))
|
|
||||||
// || ((g_Mppt_Para.Registration_Status != 2) && Match_Broadcastaddress(pack->address)))) {
|
|
||||||
|| Match_Broadcastaddress(pack->address))) {
|
|
||||||
if (flag_run < 1) {
|
if (flag_run < 1) {
|
||||||
flag_run = 1;
|
flag_run = 1;
|
||||||
}
|
}
|
||||||
memcpy(buff, buff+1, offset-1);
|
memcpy(buff, buff+1, offset-1);
|
||||||
offset--;
|
offset--;
|
||||||
// buff_size--;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* 匹配功能码 */
|
/* 匹配功能码 */
|
||||||
if ((offset == (sizeof(pack->start_Flag) + sizeof(pack->address) + sizeof(pack->function_Code))) || (flag_run > 2)) {
|
if (offset == analyzeFunctionCode || (flag_run > 2)) {
|
||||||
/* 未注册时,不处理读写 */
|
/* 未注册时,不处理读写和其他帧 */
|
||||||
if (g_Mppt_Para.Registration_Status == 2) {
|
if (g_Mppt_Para.Registration_Status == 2) {
|
||||||
/* 读寄存器数据 */
|
/* 读寄存器数据 */
|
||||||
if (pack->function_Code == SL_Function_Code_Read_Register) {
|
if (pack->function_Code == SL_Function_Code_Read_Register) {
|
||||||
log_info("Read_Register\r\n");
|
log_info("Read_Register\r\n");
|
||||||
len = SL_MPPT_RORECV_PACK_SIZE;
|
len = SL_MPPT_RORECV_PACK_SIZE;
|
||||||
w_Flag = 0;
|
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 写寄存器数据 */
|
/* 写寄存器数据 */
|
||||||
else if (pack->function_Code == SL_Function_Code_Write_Register) {
|
else if (pack->function_Code == SL_Function_Code_Write_Register) {
|
||||||
log_info("Write_Register\r\n");
|
log_info("Write_Register\r\n");
|
||||||
w_Flag = 1;
|
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SuccessRegistrationAcceptScan
|
/* 其他帧格式 */
|
||||||
if (run_Broadcast) {
|
else if (pack->function_Code == SL_Function_Code_Update_Profile
|
||||||
|
|| pack->function_Code == SL_Function_Code_Remote_Upgrade) {
|
||||||
|
len = SL_MPPT_ROTHER_PACK_SIZE;
|
||||||
|
log_info("Other frames\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (run_Broadcast) {
|
||||||
/* 广播扫描 */
|
/* 广播扫描 */
|
||||||
if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
|
if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
|
||||||
log_info("Broadcast_Scan\r\n");
|
log_info("Broadcast_Scan\r\n");
|
||||||
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE;
|
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE;
|
||||||
w_Flag = 0;
|
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 注册请求 */
|
/* 注册请求 */
|
||||||
else if (pack->function_Code == SL_Function_Code_Registration_request) {
|
else if (pack->function_Code == SL_Function_Code_Registration_request) {
|
||||||
log_info("Registration_request\r\n");
|
log_info("Registration_request\r\n");
|
||||||
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
|
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
|
||||||
w_Flag = 0;
|
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
if (flag_run < 2) {
|
if (flag_run < 2) {
|
||||||
flag_run = 2;
|
flag_run = 2;
|
||||||
}
|
}
|
||||||
w_Flag = 0;
|
|
||||||
log_info("funcode error %x\r\n", pack->function_Code);
|
log_info("funcode error %x\r\n", pack->function_Code);
|
||||||
memcpy(buff, buff+1, offset-1);
|
memcpy(buff, buff+1, offset-1);
|
||||||
offset--;
|
offset--;
|
||||||
// buff_size--;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
else {
|
||||||
|
if (flag_run < 2) {
|
||||||
|
flag_run = 2;
|
||||||
|
}
|
||||||
|
log_info("funcode error %x\r\n", pack->function_Code);
|
||||||
|
memcpy(buff, buff+1, offset-1);
|
||||||
|
offset--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 广播扫描 */
|
/* 广播扫描 */
|
||||||
else if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
|
else if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
|
||||||
log_info("Broadcast_Scan\r\n");
|
log_info("Broadcast_Scan\r\n");
|
||||||
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE;
|
len = SL_MPPT_SCAN_BROADCAST_PACK_SIZE;
|
||||||
w_Flag = 0;
|
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 注册请求 */
|
/* 注册请求 */
|
||||||
else if (pack->function_Code == SL_Function_Code_Registration_request) {
|
else if (pack->function_Code == SL_Function_Code_Registration_request) {
|
||||||
log_info("Registration_request\r\n");
|
log_info("Registration_request\r\n");
|
||||||
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
|
len = SL_MPPT_REGISTRATIONREPLY_PACK_SIZE;
|
||||||
w_Flag = 0;
|
|
||||||
// continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
if (flag_run < 2) {
|
if (flag_run < 2) {
|
||||||
flag_run = 2;
|
flag_run = 2;
|
||||||
}
|
}
|
||||||
w_Flag = 0;
|
|
||||||
log_info("funcode error %x\r\n", pack->function_Code);
|
log_info("funcode error %x\r\n", pack->function_Code);
|
||||||
memcpy(buff, buff+1, offset-1);
|
memcpy(buff, buff+1, offset-1);
|
||||||
offset--;
|
offset--;
|
||||||
// buff_size--;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((1 == w_Flag) && (offset == 14)) {
|
if ((offset == 14) && (pack->function_Code == SL_Function_Code_Write_Register)) {
|
||||||
SL_Mppt_Worecv_pack *wpack = (SL_Mppt_Worecv_pack *)buff;
|
SL_Mppt_Worecv_pack *wpack = (SL_Mppt_Worecv_pack *)buff;
|
||||||
uint8_t Register_Number = (wpack->write_Register_Number_H << 8) | wpack->write_Register_Number_L;
|
uint8_t Register_Number = (wpack->write_Register_Number_H << 8) | wpack->write_Register_Number_L;
|
||||||
len = Register_Number * 2 + SL_MPPT_WORECV_PACK_SIZE - 4;
|
len = Register_Number * 2 + SL_MPPT_WORECV_PACK_SIZE - 4;
|
||||||
|
@ -691,27 +774,6 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset == len) {
|
if (offset == len) {
|
||||||
/* 读寄存器数据 */
|
|
||||||
if (pack->function_Code == SL_Function_Code_Read_Register) {
|
|
||||||
SL_Mppt_Rorecv_pack *rpack = (SL_Mppt_Rorecv_pack *)buff;
|
|
||||||
|
|
||||||
uint16_t crc_16 = chang_8_to_16(rpack->check_Bit_L, rpack->check_Bit_H);
|
|
||||||
|
|
||||||
if ((CheckFunc(buff, offset - 3) != crc_16) || (rpack->end_Flag != 0x16)) {
|
|
||||||
if (flag_run < 3) {
|
|
||||||
flag_run = 3;
|
|
||||||
}
|
|
||||||
memcpy(buff, buff+1, offset-1);
|
|
||||||
offset--;
|
|
||||||
// buff_size--;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 写寄存器数据 */
|
|
||||||
else if (pack->function_Code == SL_Function_Code_Write_Register) {
|
|
||||||
uint16_t crc_16 = chang_8_to_16(buff[offset - 2], buff[offset - 3]);
|
uint16_t crc_16 = chang_8_to_16(buff[offset - 2], buff[offset - 3]);
|
||||||
|
|
||||||
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
|
if ((CheckFunc(buff, offset - 3) != crc_16) || (buff[offset - 1] != 0x16)) {
|
||||||
|
@ -720,57 +782,11 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
|
||||||
}
|
}
|
||||||
memcpy(buff, buff+1, offset-1);
|
memcpy(buff, buff+1, offset-1);
|
||||||
offset--;
|
offset--;
|
||||||
// buff_size--;
|
|
||||||
} else {
|
} else {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 广播扫描 */
|
|
||||||
else if (pack->function_Code == SL_Function_Code_Broadcast_Scan) {
|
|
||||||
SL_Mppt_Scan_Broadcast_pack *bpack = (SL_Mppt_Scan_Broadcast_pack *)buff;
|
|
||||||
|
|
||||||
uint16_t crc_16 = chang_8_to_16(bpack->check_Bit_L, bpack->check_Bit_H);
|
|
||||||
if ((CheckFunc(buff, offset - 3) != crc_16) || (bpack->end_Flag != 0x16)) {
|
|
||||||
if (flag_run < 3) {
|
|
||||||
flag_run = 3;
|
|
||||||
}
|
|
||||||
memcpy(buff, buff+1, offset-1);
|
|
||||||
offset--;
|
|
||||||
// buff_size--;
|
|
||||||
} else {
|
|
||||||
if (uart_handle == g_bat485_uart3_handle) {
|
|
||||||
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
|
|
||||||
} else {
|
|
||||||
USART_ITConfig(USART4, USART_IT_RXNE, DISABLE);
|
|
||||||
}
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 注册请求 */
|
|
||||||
else if (pack->function_Code == SL_Function_Code_Registration_request) {
|
|
||||||
SL_Mppt_RegistrationReply_pack *rpack = (SL_Mppt_RegistrationReply_pack *)buff;
|
|
||||||
uint16_t crc_16 = chang_8_to_16(rpack->check_Bit_L, rpack->check_Bit_H);
|
|
||||||
if ((CheckFunc(buff, offset - 3) != crc_16) || (rpack->end_Flag != 0x16)) {
|
|
||||||
if (flag_run < 3) {
|
|
||||||
flag_run = 3;
|
|
||||||
}
|
|
||||||
memcpy(buff, buff+1, offset-1);
|
|
||||||
offset--;
|
|
||||||
// buff_size--;
|
|
||||||
} else {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// /* 处理完后无正确的选项剩余的字符 */
|
|
||||||
// if ((ring_queue_length(uart_handle) == 0) || (offset == buff_size - 1)) {
|
|
||||||
//// memcpy(save_485buf.save_rs485_buff, 0, sizeof(save_485buf.len));
|
|
||||||
// strlcpy(save_485buf.save_rs485_buff, buff, offset);
|
|
||||||
// save_485buf.len = offset;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,6 @@
|
||||||
STR_TimeSliceOffset m_runled;
|
STR_TimeSliceOffset m_runled;
|
||||||
void Task_RunLED(void)
|
void Task_RunLED(void)
|
||||||
{
|
{
|
||||||
// for (int i = 0; i < 200; ++i) {
|
|
||||||
// uart_sendstr(g_gw485_uart4_handle, "is gw485\n");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// uart_sendstr(g_gw485_uart4_handle, "\n\n\n\n\n");
|
// uart_sendstr(g_gw485_uart4_handle, "\n\n\n\n\n");
|
||||||
// uart_sendstr(g_gw485_uart4_handle, "is gw485\n");
|
// uart_sendstr(g_gw485_uart4_handle, "is gw485\n");
|
||||||
// uart_sendstr(g_bat485_uart3_handle, "is bat485\n");
|
// uart_sendstr(g_bat485_uart3_handle, "is bat485\n");
|
||||||
|
@ -55,7 +51,6 @@ STR_TimeSliceOffset m_mpptControl;
|
||||||
void Task_mpptControl(void)
|
void Task_mpptControl(void)
|
||||||
{
|
{
|
||||||
// test();
|
// test();
|
||||||
get_MOSFET_Temper();
|
|
||||||
|
|
||||||
// static uint8_t test_flag = 0;
|
// static uint8_t test_flag = 0;
|
||||||
// if (5 == ++test_flag) {
|
// if (5 == ++test_flag) {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Loading…
Reference in New Issue