mppt/App/src/hy_protocol.c

1363 lines
48 KiB
C
Raw Normal View History

2024-10-12 02:23:32 +00:00
/*
* hy_protocol.c
*
* Created on: 2024<EFBFBD><EFBFBD>10<EFBFBD><EFBFBD>11<EFBFBD><EFBFBD>
* Author: psx
*/
#include "hy_protocol.h"
#include <string.h>
#include "inflash.h"
#include "pdebug.h"
#include "mppt_control.h"
#include <stdlib.h>
#include "task.h"
#include "tim.h"
#include "sl_protocol.h"
#include "parameter.h"
2024-10-12 02:23:32 +00:00
/* <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD>ݱ<EFBFBD> */
static void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD> */
static void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ */
static void HY_MsgProcFunc_sensorNumberInquiry(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> */
static void HY_MsgProcFunc_chargingThresholdVoltageConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ѹ<EFBFBD><D1B9>ѯ */
static void HY_MsgProcFunc_chargingRangeVoltageQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><>λָ<CEBB><D6B8> */
static void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>ѯ */
static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
static void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen);
///* <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
//static void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD>ؿ<EFBFBD><D8BF>ƺе<C6BA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD> */
static void HY_MsgProcFunc_queryControlBoxConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD>ؿ<EFBFBD><D8BF>ƺ<EFBFBD><C6BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾 */
static void HY_MsgProcFunc_querySoftwareVersion(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ */
static void HY_MsgProcFunc_enterConfigurationMode(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD>ÿ<EFBFBD><C3BF>ƺ<EFBFBD>Ӳ<EFBFBD><D3B2>ID<49><44> */
static void HY_MsgProcFunc_configureHardwareID(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD>ƺ<EFBFBD>Ӳ<EFBFBD><D3B2>ID<49>ż<EFBFBD>ͨ<EFBFBD><CDA8>ID<49>ţ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>ѯ */
static void HY_MsgProcFunc_hardwareID_communicationIDQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20>޸<EFBFBD>ͨ<EFBFBD><CDA8>ID<49>ţ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD> */
static void HY_MsgProcFunc_modifyCommunicationID(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ */
static void HY_MsgProcFunc_checkMotherboardTemperature(device_handle device, void *pMsg, uint32_t MsgLen);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB4A6><EFBFBD><EFBFBD> */
HY_FuncionMsgProcTable g_hyMsgTbl[] =
{
{HY_batteryStatus, HY_MsgProcFunc_batteryStatus},
{HY_electricityStatistics, HY_MsgProcFunc_electricityStatistics},
{HY_sensorNumberConfiguration, HY_MsgProcFunc_sensorNumberConfiguration},
{HY_sensorNumberInquiry, HY_MsgProcFunc_sensorNumberInquiry},
{HY_chargingThresholdVoltageConfiguration, HY_MsgProcFunc_chargingThresholdVoltageConfiguration},
{HY_chargingRangeVoltageQuery, HY_MsgProcFunc_chargingRangeVoltageQuery},
{HY_resetInstruction, HY_MsgProcFunc_resetInstruction},
{HY_chargingControlConfiguration, HY_MsgProcFunc_chargingControlConfiguration},
{HY_chargingControlQuery, HY_MsgProcFunc_chargingControlQuery},
{HY_configureProtocolType, HY_MsgProcFunc_configureProtocolType},
// {HY_responseConfigureProtocolType, HY_MsgProcFunc_batteryStatus},
{HY_queryControlBoxConfiguration, HY_MsgProcFunc_queryControlBoxConfiguration},
{HY_querySoftwareVersion, HY_MsgProcFunc_querySoftwareVersion},
{HY_enterConfigurationMode, HY_MsgProcFunc_enterConfigurationMode},
{HY_configureHardwareID, HY_MsgProcFunc_configureHardwareID},
{HY_hardwareID_communicationIDQuery, HY_MsgProcFunc_hardwareID_communicationIDQuery},
{HY_modifyCommunicationID, HY_MsgProcFunc_modifyCommunicationID},
{HY_checkMotherboardTemperature, HY_MsgProcFunc_checkMotherboardTemperature},
};
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>485<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>æ
* @param
* @retval 1 <EFBFBD><EFBFBD>æ
* 0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t HY_Check_485_bus_busy(device_handle device)
2024-10-12 02:23:32 +00:00
{
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
uint16_t num_ago = ring_queue_length(device);
Delay_Ms(2);
uint16_t num_now = ring_queue_length(device);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, DISABLE);
}
if (num_now == num_ago) {
return 0;
}
return 1;
}
/**
* @brief У<EFBFBD><EFBFBD><EFBFBD>
* @param <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼӺ<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @retval
*/
uint8_t HY_CheckFunc(uint8_t *arr_buff, uint8_t len)
{
uint8_t temp = 0x00;
uint32_t sum = 0x00;
for(uint8_t i = 0; i < len; i++) {
sum += *arr_buff++;
}
temp = (~sum) & 0xff;
return temp;
}
/**
* @brief ƥ<EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD>ID
2024-10-12 02:23:32 +00:00
* @param address <EFBFBD><EFBFBD>ַ
* @retval 1 ƥ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
* 0 ƥ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
static int HY_matchHardwareID(u_int8_t hardwareID[6])
2024-10-12 02:23:32 +00:00
{
if ((hardwareID[0] == g_otherParameter.hardwareID[0]) && \
(hardwareID[1] == g_otherParameter.hardwareID[1]) && \
(hardwareID[2] == g_otherParameter.hardwareID[2]) && \
(hardwareID[3] == g_otherParameter.hardwareID[3]) && \
(hardwareID[4] == g_otherParameter.hardwareID[4]) && \
(hardwareID[5] == g_otherParameter.hardwareID[5])) {
log_info("Match_hardwareIDHY success \r\n");
return 1;
}
return 0;
}
/**
* @brief ƥ<EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD>ID
* @param address <EFBFBD><EFBFBD>ַ
* @retval 1 ƥ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
* 0 ƥ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
static int Match_BroadcastHardwareID(u_int8_t hardwareID[6])
{
if (hardwareID[0] == 0xFF && \
hardwareID[1] == 0xFF && \
hardwareID[2] == 0xFF && \
hardwareID[3] == 0xFF && \
hardwareID[4] == 0xFF && \
hardwareID[5] == 0xFF) {
log_info("Match_BroadcastHardwareID success\r\n");
return 1;
}
return 0;
}
/**
* @brief ƥ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ID
* @param address <EFBFBD><EFBFBD>ַ
* @retval 1 ƥ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
* 0 ƥ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
static int HY_matchCommunicationID(u_int8_t communicationID[4])
{
if ((communicationID[0] == g_otherParameter.communicationID[0]) && \
(communicationID[1] == g_otherParameter.communicationID[1]) && \
(communicationID[2] == g_otherParameter.communicationID[2]) && \
(communicationID[3] == g_otherParameter.communicationID[3])) {
log_info("Match_CommunicationIDHY success \r\n");
return 1;
}
2024-10-12 02:23:32 +00:00
return 0;
}
/**
* @brief ƥ<EFBFBD><EFBFBD><EFBFBD>ID
2024-10-12 02:23:32 +00:00
* @param address <EFBFBD><EFBFBD>ַ
* @retval 1 ƥ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
* 0 ƥ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
*/
static int Match_BroadcastCommunicationID(u_int8_t communicationID[4])
2024-10-12 02:23:32 +00:00
{
if (communicationID[0] == 0xFF && \
communicationID[1] == 0xFF && \
communicationID[2] == 0xFF && \
communicationID[3] == 0xFF) {
log_info("Match_BroadcastCommunicationID success\r\n");
2024-10-12 02:23:32 +00:00
return 1;
}
return 0;
}
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param uart_handle <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
* @param buff <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param buff_size <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @retval
*/
static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint32_t buff_size)
{
uint32_t offset = 0;
uint32_t len = 0;
uint8_t flag_run = 0;
/* <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>Ӳ<EFBFBD><D3B2>ID<49><44><EFBFBD><EFBFBD>
* 0x01 <EFBFBD>ID
* 0x02 Ӳ<EFBFBD><EFBFBD>ID
**/
uint8_t hardwordIDType = 0;
2024-10-12 02:23:32 +00:00
char c = 0;
HY_Recv_pack *pack = (HY_Recv_pack *)buff;
buff_size--; //Ԥ<><D4A4>һ<EFBFBD><D2BB>'\0'λ<><CEBB>
for (; offset < buff_size;){
if (ring_queue_length(uart_handle) == 0) {
break;
}
c = uart_dev_in_char(uart_handle);
buff[offset++] = c;
2024-10-26 01:07:30 +00:00
config_buff[cfig_len++] = c;
2024-10-12 02:23:32 +00:00
/* ƥ<><C6A5><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>־λ */
if (offset == HY_analyzeStartFlag || (flag_run > 0)) {
if (pack->start_Flag != g_otherParameter.startFlagHY) {
log_info(" Match_start_Flag error %x ", pack->start_Flag);
// printf("1 : %x \n", pack->start_Flag);
2024-10-12 02:23:32 +00:00
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
// log_info(" Match_start_Flag success ");
// printf("%x\n", pack->start_Flag);
2024-10-12 02:23:32 +00:00
}
/* ƥ<><C6A5>Ӳ<EFBFBD><D3B2>ID */
2024-10-12 02:23:32 +00:00
if (offset == HY_analyzeHardwareID || (flag_run > 1)) {
if (HY_matchHardwareID(pack->hardwareID)) {
hardwordIDType = 0x02;
}
else if (Match_BroadcastHardwareID(pack->hardwareID)) {
hardwordIDType = 0x01;
}
else {
2024-10-26 01:07:30 +00:00
log_info("Match_hardwordID error");
hardwordIDType = 0x00;
2024-10-12 02:23:32 +00:00
if (flag_run < 1) {
flag_run = 1;
}
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
/* ƥ<><C6A5>ͨ<EFBFBD><CDA8>ID */
if (offset == HY_analyzeCommunicationID || (flag_run > 2)) {
if (!(HY_matchCommunicationID(pack->communicationID) || Match_BroadcastCommunicationID(pack->communicationID))) {
if (flag_run < 2) {
flag_run = 2;
}
2024-10-26 01:07:30 +00:00
log_info("Match_CommunicationID error");
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
2024-10-12 02:23:32 +00:00
/* ƥ<><C6A5> */
if (offset == HY_analyzeControlWord || (flag_run > 3)) {
if (pack->controlWord == HY_batteryStatus && hardwordIDType == 0x02) {
len = HY_batteryStatusQuery_PACK_SIZE;
}
2024-10-12 02:23:32 +00:00
else if (pack->controlWord == HY_electricityStatistics && hardwordIDType == 0x02) {
len = HY_electricityStatisticsQuery_PACK_SIZE;
}
2024-10-12 02:23:32 +00:00
else if (pack->controlWord == HY_sensorNumberConfiguration && hardwordIDType == 0x02) {
len = HY_sensorNumberConfiguration_PACK_SIZE;
}
else if (pack->controlWord == HY_sensorNumberInquiry && hardwordIDType == 0x01) {
len = HY_sensorNumberInquiryQuery_PACK_SIZE;
}
else if (pack->controlWord == HY_chargingThresholdVoltageConfiguration && hardwordIDType == 0x02) {
len = HY_chargingThresholdVoltageConfig_PACK_SIZE;
}
else if (pack->controlWord == HY_chargingRangeVoltageQuery && hardwordIDType == 0x02) {
len = HY_chargRangeVoltageQuery_PACK_SIZE;
}
else if (pack->controlWord == HY_resetInstruction && hardwordIDType == 0x02) {
len = HY_resetInstructionQuery_PACK_SIZE;
}
else if (pack->controlWord == HY_chargingControlConfiguration && hardwordIDType == 0x02) {
len = HY_chargingControlConfig_PACK_SIZE;
}
else if (pack->controlWord == HY_chargingControlQuery && hardwordIDType == 0x02) {
len = HY_QueryChargingControl_PACK_SIZE;
}
else if (pack->controlWord == HY_configureProtocolType && hardwordIDType == 0x02) {
len = HY_configProtocolType_PACK_SIZE;
}
else if (pack->controlWord == HY_queryControlBoxConfiguration && hardwordIDType == 0x02) {
len = HY_queryControlBoxConfigurationQuery_PACK_SIZE;
}
else if (pack->controlWord == HY_querySoftwareVersion && hardwordIDType == 0x02) {
len = HY_SoftwareVersionQuery_PACK_SIZE;
}
else if (pack->controlWord == HY_enterConfigurationMode && hardwordIDType == 0x02) {
len = HY_enterConfigMode_PACK_SIZE;
}
else if (pack->controlWord == HY_configureHardwareID && hardwordIDType == 0x02) {
len = HY_configHardwareID_PACK_SIZE;
}
else if (pack->controlWord == HY_hardwareID_communicationIDQuery && hardwordIDType == 0x01) {
len = HY_QueryhardwareID_communicationID_PACK_SIZE;
}
else if (pack->controlWord == HY_modifyCommunicationID && hardwordIDType == 0x02) {
len = HY_modifyCommunicationIDChange_PACK_SIZE;
}
else if (pack->controlWord == HY_checkMotherboardTemperature && hardwordIDType == 0x02) {
len = HY_checkMotherboardTemperatureQuery_PACK_SIZE;
}
else {
if (flag_run < 3) {
flag_run = 3;
}
2024-10-26 01:07:30 +00:00
log_info("Match_controlWord error");
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
2024-10-26 01:07:30 +00:00
/* ƥ<><C6A5><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
if (offset == HY_analyzeDataLen || (flag_run > 4)) {
2024-10-26 01:07:30 +00:00
if (len != ((pack->dataLen[0] << 8 | pack->dataLen[1]) + 16)) {
if (flag_run < 4) {
flag_run = 4;
}
log_info("Match_dataLen error: %x", len);
2024-10-26 01:07:30 +00:00
log_info("Match_dataLen error: %x", (pack->dataLen[0] << 8 | pack->dataLen[1]) + 16);
log_info("Match_dataLen error: %x", pack->dataLen[0]);
log_info("Match_dataLen error: %x", pack->dataLen[1]);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
}
2024-10-12 02:23:32 +00:00
if (offset == len) {
if (buff[len - 2] != HY_CheckFunc(buff, len - 2)
&& buff[len - 1] != g_otherParameter.endFlagHY) {
if (flag_run < 5) {
flag_run = 5;
}
2024-10-26 01:07:30 +00:00
log_info("check: %x, %x", (HY_CheckFunc(buff, len - 2) & 0xff), buff[len - 2]);
memcpy(buff, buff+1, offset-1);
offset--;
continue;
}
2024-10-26 01:07:30 +00:00
memset(config_buff, 0, sizeof(config_buff));
cfig_len = 0;
return len;
}
}
2024-10-12 02:23:32 +00:00
return 0;
}
/**
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
* @param
* @retval
*/
static void HY_FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
{
HY_Recv_pack *pack = (HY_Recv_pack *)pMsg;
for (u_int16_t i = 0; i < sizeof(g_hyMsgTbl) / sizeof(HY_FuncionMsgProcTable); i++){
if (pack->controlWord == g_hyMsgTbl[i].msgId){
g_hyMsgTbl[i].pMsgProc(device, pMsg, MsgLen);
}
}
}
/**
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param
* @retval
*/
void HY_read_and_process_uart_data(device_handle device)
{
2024-10-26 01:07:30 +00:00
// if (uart_dev_char_present(device)) {
// Delay_Ms(20);
// memset(rs485_buff, 0, sizeof(rs485_buff));
// int ret = HY_uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
// if(ret > 0){
// HY_FRT_MsgHandler(device, rs485_buff, ret);
// }
// }
memset(rs485_buff, 0, sizeof(rs485_buff));
int ret = HY_uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
if(ret > 0){
HY_FRT_MsgHandler(device, rs485_buff, ret);
2024-10-12 02:23:32 +00:00
}
}
/* <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD>ݱ<EFBFBD> */
void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_batteryStatusResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = HY_batteryStatus;
pack.dataLen[0] = HY_batteryStatusResponse_dataLen >> 8;
pack.dataLen[1] = HY_batteryStatusResponse_dataLen;
2024-11-13 08:44:13 +00:00
pack.batteryVoltage = g_otherParameter.Battery_Voltage;
2024-11-13 08:44:13 +00:00
// pack.batteryVoltage = 6.66;
pack.dischargCurrent = g_otherParameter.Discharg_Current;
pack.chargCurrent1 = g_otherParameter.Charg_Current;
pack.SOC = g_otherParameter.SOC;
pack.openCircuitVoltage1 = g_otherParameter.Solar_In_Circuit_Voltage;
2024-11-13 08:44:13 +00:00
if (g_controlParameter.dutyRatio > 0 && g_otherParameter.Charg_Current > 0.05) {
pack.chargSwitchStatus1 = HY_switchON;
} else {
pack.chargSwitchStatus1 = HY_switchOFF;
}
2024-10-12 02:23:32 +00:00
pack.chargCurrent2 = pack.chargCurrent1;
pack.openCircuitVoltage2 = pack.openCircuitVoltage1;
2024-10-12 02:23:32 +00:00
pack.chargSwitchStatus2 = pack.chargSwitchStatus1;
2024-10-12 02:23:32 +00:00
pack.Mos_Temperature = g_otherParameter.HighSideMos_Temperature;
2024-10-12 02:23:32 +00:00
HY_batteryStatusQuery *Tpack = (HY_batteryStatusQuery *)pMsg;
pack.frameNumber = Tpack->frameNumber;
2024-10-12 02:23:32 +00:00
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_batteryStatusResponse_PACK_SIZE - 2);
2024-10-12 02:23:32 +00:00
pack.end_Flag = g_otherParameter.endFlagHY;
2024-10-12 02:23:32 +00:00
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE);
2024-10-12 02:23:32 +00:00
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
2024-10-12 02:23:32 +00:00
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD> */
void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_electricityStatisticsResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = HY_electricityStatistics;
pack.dataLen[0] = HY_electricityStatisticsResponse_dataLen >> 8;
pack.dataLen[1] = HY_electricityStatisticsResponse_dataLen;
pack.statisticalDuration = 0;
pack.totalChargCapacity = g_otherParameter.totalChargCapacity;
pack.totalElectricityConsumption = g_otherParameter.totalElectricityConsumption;
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
g_otherParameter.totalChargCapacity = 0;
g_otherParameter.totalElectricityConsumption = 0;
2024-11-08 08:51:14 +00:00
// saveTotalPower(&g_otherParameter.totalElectricityConsumption, &g_otherParameter.totalChargCapacity);
savetotalChargCapacity(&g_otherParameter.totalChargCapacity);
savetotalElectricityConsumption(&g_otherParameter.totalElectricityConsumption);
HY_electricityStatisticsQuery *Tpack = (HY_electricityStatisticsQuery *)pMsg;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_electricityStatisticsResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_electricityStatisticsResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
2024-10-12 02:23:32 +00:00
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_sensorNumberConfigurationResponse pack;
HY_sensorNumberConfig *Tpack = (HY_sensorNumberConfig *)pMsg;
if (HY_matchHardwareID(Tpack->newHardwareID)) {
g_otherParameter.communicationID[0] = Tpack->newCommunicationID[0];
g_otherParameter.communicationID[1] = Tpack->newCommunicationID[1];
g_otherParameter.communicationID[2] = Tpack->newCommunicationID[2];
g_otherParameter.communicationID[3] = Tpack->newCommunicationID[3];
2024-10-26 01:07:30 +00:00
config_info temp_configInfo;
read_config_info(&temp_configInfo);
temp_configInfo.communicationID[0] = Tpack->newCommunicationID[0];
temp_configInfo.communicationID[1] = Tpack->newCommunicationID[1];
temp_configInfo.communicationID[2] = Tpack->newCommunicationID[2];
temp_configInfo.communicationID[3] = Tpack->newCommunicationID[3];
temp_configInfo.crc = configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2);
save_config_info(&temp_configInfo);
pack.state = HY_success;
}
else {
pack.state = HY_fail;
}
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_sensorNumberConfigurationResponse_dataLen >> 8;
pack.dataLen[1] = HY_sensorNumberConfigurationResponse_dataLen;
pack.frameNumber = Tpack->frameNumber;
2024-10-12 02:23:32 +00:00
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_sensorNumberConfigurationResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_sensorNumberConfigurationResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ */
void HY_MsgProcFunc_sensorNumberInquiry(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_sensorNumberInquiryQuery *Tpack = (HY_sensorNumberInquiryQuery *)pMsg;
HY_sensorNumberInquiryResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_sensorNumberInquiryResponse_dataLen >> 8;
pack.dataLen[1] = HY_sensorNumberInquiryResponse_dataLen;
pack.hardwareIDR[0] = g_otherParameter.hardwareID[0];
pack.hardwareIDR[1] = g_otherParameter.hardwareID[1];
pack.hardwareIDR[2] = g_otherParameter.hardwareID[2];
pack.hardwareIDR[3] = g_otherParameter.hardwareID[3];
pack.hardwareIDR[4] = g_otherParameter.hardwareID[4];
pack.hardwareIDR[5] = g_otherParameter.hardwareID[5];
pack.communicationIDR[0] = g_otherParameter.communicationID[0];
pack.communicationIDR[1] = g_otherParameter.communicationID[1];
pack.communicationIDR[2] = g_otherParameter.communicationID[2];
pack.communicationIDR[3] = g_otherParameter.communicationID[3];
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_sensorNumberInquiryResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_sensorNumberInquiryResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
2024-10-12 02:23:32 +00:00
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD> */
void HY_MsgProcFunc_chargingThresholdVoltageConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ѹ<EFBFBD><D1B9>ѯ */
void HY_MsgProcFunc_chargingRangeVoltageQuery(device_handle device, void *pMsg, uint32_t MsgLen)
{
}
/* <20><>λָ<CEBB><D6B8> */
void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_resetInstructionQuery *Tpack = (HY_resetInstructionQuery *)pMsg;
HY_resetInstructionResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_resetInstructionResponse_dataLen >> 8;
pack.dataLen[1] = HY_resetInstructionResponse_dataLen;
pack.state = HY_success;
2024-10-12 02:23:32 +00:00
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_resetInstructionResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_resetInstructionResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-26 01:07:30 +00:00
/* <20><>λ */
NVIC_SystemReset();
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_chargingControlConfig *Tpack = (HY_chargingControlConfig *)pMsg;
2024-11-13 08:44:13 +00:00
if (Tpack->chargInterfaceControl == HY_cSwitchON) {
if (g_controlParameter.dutyRatio == 0) {
if (g_otherParameter.Output_Voltage > 11) {
g_otherParameter.batteryState = 1;
} else {
g_otherParameter.batteryState = 0;
}
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
}
2024-11-13 08:44:13 +00:00
if (Tpack->chargInterfaceControl == HY_cSwitchOFF) {
if (g_controlParameter.dutyRatio != 0) {
TIM_Cmd(TIM3, DISABLE);
TIM_SetCompare4(TIM4, 0);
g_controlParameter.dutyRatio = 0;
TimeSliceOffset_Unregister(&g_collectOpenCircuitVoltage);
}
}
HY_chargingControlConfigResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_chargingControlConfigResponse_dataLen >> 8;
pack.dataLen[1] = HY_chargingControlConfigResponse_dataLen;
pack.state = HY_success;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_chargingControlConfigResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_chargingControlConfigResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>ѯ */
static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_QueryChargingControl *Tpack = (HY_QueryChargingControl *)pMsg;
HY_QueryChargingControlResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_QueryChargingControlResponse_dataLen >> 8;
pack.dataLen[1] = HY_QueryChargingControlResponse_dataLen;
if (g_controlParameter.dutyRatio > 0 && g_otherParameter.Charg_Current > 0.05) {
pack.chargInterface1 = HY_switchON;
} else {
pack.chargInterface1 = HY_switchOFF;
}
pack.chargInterface2 = pack.chargInterface1;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_QueryChargingControlResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
2024-10-12 02:23:32 +00:00
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_QueryChargingControlResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_configProtocolType *Tpack = (HY_configProtocolType *)pMsg;
g_otherParameter.protocolType = Tpack->protocolType;
config_info temp_configInfo;
read_config_info(&temp_configInfo);
temp_configInfo.protocolType = Tpack->protocolType;
2024-10-12 02:23:32 +00:00
temp_configInfo.crc = configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2);
save_config_info(&temp_configInfo);
if (g_otherParameter.protocolType == 0x01) {
g_otherParameter.gw485_Baud = 9600;
} else if (g_otherParameter.protocolType == 0x02) {
g_otherParameter.gw485_Baud = 115200;
}
HY_chargingControlConfigResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = HY_responseConfigureProtocolType;
pack.dataLen[0] = HY_configProtocolTypeResponse_dataLen >> 8;
pack.dataLen[1] = HY_configProtocolTypeResponse_dataLen;
pack.state = HY_success;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_configProtocolTypeResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_configProtocolTypeResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
uart_dev_init();
2024-10-12 02:23:32 +00:00
}
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD>ؿ<EFBFBD><D8BF>ƺе<C6BA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD> */
void HY_MsgProcFunc_queryControlBoxConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_queryControlBoxConfigurationQuery *Tpack = (HY_queryControlBoxConfigurationQuery *)pMsg;
HY_queryControlBoxConfigurationResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
2024-10-12 02:23:32 +00:00
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_queryControlBoxConfigurationResponse_dataLen >> 8;
pack.dataLen[1] = HY_queryControlBoxConfigurationResponse_dataLen;
// pack.state = HY_success;
pack.protocolType = g_otherParameter.protocolType;
pack.voltageLevel = 0x00; //12V
pack.mainBoardTemperatureSensorType = 0xFF;
pack.batteryTemperatureSensorType = 0xFF;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_queryControlBoxConfigurationResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_queryControlBoxConfigurationResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD>ؿ<EFBFBD><D8BF>ƺ<EFBFBD><C6BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾 */
void HY_MsgProcFunc_querySoftwareVersion(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_SoftwareVersionQuery *Tpack = (HY_SoftwareVersionQuery *)pMsg;
HY_SoftwareVersionQueryResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_SoftwareVersionQueryResponse_dataLen >> 8;
pack.dataLen[1] = HY_SoftwareVersionQueryResponse_dataLen;
strlcpy(pack.versionInformation, g_otherParameter.versionInformation, 13);
pack.frameNumber = Tpack->frameNumber;
2024-10-12 02:23:32 +00:00
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_SoftwareVersionQueryResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_SoftwareVersionQueryResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ */
void HY_MsgProcFunc_enterConfigurationMode(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_enterConfigMode *Tpack = (HY_enterConfigMode *)pMsg;
HY_enterConfigModeResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_enterConfigModeResponse_dataLen >> 8;
pack.dataLen[1] = HY_enterConfigModeResponse_dataLen;
pack.state = HY_success;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_enterConfigModeResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_enterConfigModeResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
TimeSliceOffset_Register(&g_configurationModeDelayedExit, Task_configurationModeDelayedExit
, configurationModeDelayedExit_reloadVal, configurationModeDelayedExit_offset);
g_otherParameter.HYconfigModeState = 0xFF;
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD>ÿ<EFBFBD><C3BF>ƺ<EFBFBD>Ӳ<EFBFBD><D3B2>ID<49><44> */
void HY_MsgProcFunc_configureHardwareID(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_configHardwareIDResponse pack;
HY_configHardwareID *Tpack = (HY_configHardwareID *)pMsg;
if (g_otherParameter.HYconfigModeState == 0xFF) {
g_otherParameter.hardwareID[0] = Tpack->hardwareID[0];
g_otherParameter.hardwareID[1] = Tpack->hardwareID[1];
g_otherParameter.hardwareID[2] = Tpack->hardwareID[2];
g_otherParameter.hardwareID[3] = Tpack->hardwareID[3];
g_otherParameter.hardwareID[4] = Tpack->hardwareID[4];
g_otherParameter.hardwareID[5] = Tpack->hardwareID[5];
config_info temp_configInfo;
read_config_info(&temp_configInfo);
temp_configInfo.hardwareID[0] = Tpack->hardwareID[0];
temp_configInfo.hardwareID[1] = Tpack->hardwareID[1];
temp_configInfo.hardwareID[2] = Tpack->hardwareID[2];
temp_configInfo.hardwareID[3] = Tpack->hardwareID[3];
temp_configInfo.hardwareID[4] = Tpack->hardwareID[4];
temp_configInfo.hardwareID[5] = Tpack->hardwareID[5];
temp_configInfo.crc = configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2);
save_config_info(&temp_configInfo);
pack.state = HY_success;
}
else {
pack.state = HY_fail;
}
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_configHardwareIDResponse_dataLen >> 8;
pack.dataLen[1] = HY_configHardwareIDResponse_dataLen;
2024-10-12 02:23:32 +00:00
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_configHardwareIDResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_configHardwareIDResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><><EFBFBD>ƺ<EFBFBD>Ӳ<EFBFBD><D3B2>ID<49>ż<EFBFBD>ͨ<EFBFBD><CDA8>ID<49>ţ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD><C5A3><EFBFBD>ѯ */
void HY_MsgProcFunc_hardwareID_communicationIDQuery(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_QueryhardwareID_communicationID *Tpack = (HY_QueryhardwareID_communicationID *)pMsg;
HY_QueryhardwareID_communicationIDResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_QueryhardwareID_dataLen >> 8;
pack.dataLen[1] = HY_QueryhardwareID_dataLen;
pack.hardwareIDR[0] = g_otherParameter.hardwareID[0];
pack.hardwareIDR[1] = g_otherParameter.hardwareID[1];
pack.hardwareIDR[2] = g_otherParameter.hardwareID[2];
pack.hardwareIDR[3] = g_otherParameter.hardwareID[3];
pack.hardwareIDR[4] = g_otherParameter.hardwareID[4];
pack.hardwareIDR[5] = g_otherParameter.hardwareID[5];
pack.communicationIDR[0] = g_otherParameter.communicationID[0];
pack.communicationIDR[1] = g_otherParameter.communicationID[1];
pack.communicationIDR[2] = g_otherParameter.communicationID[2];
pack.communicationIDR[3] = g_otherParameter.communicationID[3];
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_QueryhardwareID_communicationIDResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_QueryhardwareID_communicationIDResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
2024-10-12 02:23:32 +00:00
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20>޸<EFBFBD>ͨ<EFBFBD><CDA8>ID<49>ţ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD> */
void HY_MsgProcFunc_modifyCommunicationID(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_modifyCommunicationIDChangeResponse pack;
HY_modifyCommunicationIDChange *Tpack = (HY_modifyCommunicationIDChange *)pMsg;
if (HY_matchHardwareID(Tpack->newHardwareID)) {
g_otherParameter.communicationID[0] = Tpack->newCommunicationID[0];
g_otherParameter.communicationID[1] = Tpack->newCommunicationID[1];
g_otherParameter.communicationID[2] = Tpack->newCommunicationID[2];
g_otherParameter.communicationID[3] = Tpack->newCommunicationID[3];
config_info temp_configInfo;
read_config_info(&temp_configInfo);
temp_configInfo.communicationID[0] = Tpack->newCommunicationID[0];
temp_configInfo.communicationID[1] = Tpack->newCommunicationID[1];
temp_configInfo.communicationID[2] = Tpack->newCommunicationID[2];
temp_configInfo.communicationID[3] = Tpack->newCommunicationID[3];
temp_configInfo.crc = configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2);
save_config_info(&temp_configInfo);
pack.state = HY_success1;
}
else {
pack.state = HY_fail;
}
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
2024-10-12 02:23:32 +00:00
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_modifyCommunicationIDChangeResponse_dataLen >> 8;
pack.dataLen[1] = HY_modifyCommunicationIDChangeResponse_dataLen;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_modifyCommunicationIDChangeResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_modifyCommunicationIDChangeResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}
/* <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ */
void HY_MsgProcFunc_checkMotherboardTemperature(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_checkMotherboardTemperatureQuery *Tpack = (HY_checkMotherboardTemperatureQuery *)pMsg;
HY_checkMotherboardTemperatureResponse pack;
pack.start_Flag = g_otherParameter.startFlagHY;
pack.hardwareID[0] = g_otherParameter.hardwareID[0];
pack.hardwareID[1] = g_otherParameter.hardwareID[1];
pack.hardwareID[2] = g_otherParameter.hardwareID[2];
pack.hardwareID[3] = g_otherParameter.hardwareID[3];
pack.hardwareID[4] = g_otherParameter.hardwareID[4];
pack.hardwareID[5] = g_otherParameter.hardwareID[5];
pack.communicationID[0] = g_otherParameter.communicationID[0];
pack.communicationID[1] = g_otherParameter.communicationID[1];
pack.communicationID[2] = g_otherParameter.communicationID[2];
pack.communicationID[3] = g_otherParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_checkMotherboardTemperatureResponse_dataLen >> 8;
pack.dataLen[1] = HY_checkMotherboardTemperatureResponse_dataLen;
pack.MotherboardTemperature = g_otherParameter.HighSideMos_Temperature;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_checkMotherboardTemperatureResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY;
while (1) {
if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_checkMotherboardTemperatureResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
} else {
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
}
2024-10-12 02:23:32 +00:00
break;
}
Delay_Ms(randomDelay());
}
2024-10-12 02:23:32 +00:00
}