完善通信协议部分,发现有概率flash出错

This commit is contained in:
起床就犯困 2024-11-08 09:05:42 +08:00
parent a83d788afb
commit 8f1a9d9b2b
29 changed files with 15574 additions and 13137 deletions

View File

@ -151,5 +151,5 @@
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
<storageModule moduleId="refreshScope"/>
</cproject> </cproject>

View File

@ -55,8 +55,17 @@ typedef enum
/* 执行状态 */ /* 执行状态 */
typedef enum typedef enum
{ {
/* 返回状态 */
HY_success = 0xFF, /* 成功 */ HY_success = 0xFF, /* 成功 */
HY_fail = 0x00, /* 失败 */ HY_fail = 0x00, /* 失败 */
/* 返回状态 */
HY_success1 = 0x01, /* 成功 */
/* 充电开关状态 */
HY_switchON = 0x00, /* 打开 */
HY_switchOFF = 0x01, /* 关闭 */
}HY_state; }HY_state;
/* 指定对齐方式为1字节 */ /* 指定对齐方式为1字节 */
@ -341,13 +350,14 @@ typedef struct _HY_QueryChargingControlResponse{
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */ uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */ uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */ uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t chargInterface; /* 充电接口状态 */ uint8_t chargInterface1; /* 充电接口1状态 */
uint8_t chargInterfaceControl; /* 充电接口状态 */ uint8_t chargInterface2; /* 充电接口2状态 */
uint32_t frameNumber; /* 帧序号 */ uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */ uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_QueryChargingControlResponse; }HY_QueryChargingControlResponse;
#define HY_QueryChargingControlResponse_PACK_SIZE (sizeof(HY_QueryChargingControlResponse)) #define HY_QueryChargingControlResponse_PACK_SIZE (sizeof(HY_QueryChargingControlResponse))
#define HY_QueryChargingControlResponse_dataLen 6
/* 配置协议类型 */ /* 配置协议类型 */
typedef struct _HY_configProtocolType{ typedef struct _HY_configProtocolType{
@ -376,6 +386,7 @@ typedef struct _HY_configProtocolTypeResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_configProtocolTypeResponse; }HY_configProtocolTypeResponse;
#define HY_configProtocolTypeResponse_PACK_SIZE (sizeof(HY_configProtocolTypeResponse)) #define HY_configProtocolTypeResponse_PACK_SIZE (sizeof(HY_configProtocolTypeResponse))
#define HY_configProtocolTypeResponse_dataLen 5
/* 查询电池控制盒当前配置 */ /* 查询电池控制盒当前配置 */
typedef struct _HY_queryControlBoxConfigurationQuery{ typedef struct _HY_queryControlBoxConfigurationQuery{
@ -406,6 +417,7 @@ typedef struct _HY_queryControlBoxConfigurationResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_queryControlBoxConfigurationResponse; }HY_queryControlBoxConfigurationResponse;
#define HY_queryControlBoxConfigurationResponse_PACK_SIZE (sizeof(HY_queryControlBoxConfigurationResponse)) #define HY_queryControlBoxConfigurationResponse_PACK_SIZE (sizeof(HY_queryControlBoxConfigurationResponse))
#define HY_queryControlBoxConfigurationResponse_dataLen 8
/* 查询电池控制盒软件版本 */ /* 查询电池控制盒软件版本 */
typedef struct _HY_SoftwareVersionQuery{ typedef struct _HY_SoftwareVersionQuery{
@ -420,7 +432,7 @@ typedef struct _HY_SoftwareVersionQuery{
}HY_SoftwareVersionQuery; }HY_SoftwareVersionQuery;
#define HY_SoftwareVersionQuery_PACK_SIZE (sizeof(HY_SoftwareVersionQuery)) #define HY_SoftwareVersionQuery_PACK_SIZE (sizeof(HY_SoftwareVersionQuery))
/* 查询电池控制盒软件版本 */ /* 查询电池控制盒软件版本响应 */
typedef struct _HY_SoftwareVersionQueryResponse{ typedef struct _HY_SoftwareVersionQueryResponse{
uint8_t start_Flag; /* 起始标志 */ uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */ uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
@ -433,6 +445,7 @@ typedef struct _HY_SoftwareVersionQueryResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_SoftwareVersionQueryResponse; }HY_SoftwareVersionQueryResponse;
#define HY_SoftwareVersionQueryResponse_PACK_SIZE (sizeof(HY_SoftwareVersionQueryResponse)) #define HY_SoftwareVersionQueryResponse_PACK_SIZE (sizeof(HY_SoftwareVersionQueryResponse))
#define HY_SoftwareVersionQueryResponse_dataLen 17
/* 进入配置模式 */ /* 进入配置模式 */
typedef struct _HY_enterConfigMode{ typedef struct _HY_enterConfigMode{
@ -460,6 +473,7 @@ typedef struct _HY_enterConfigModeResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_enterConfigModeResponse; }HY_enterConfigModeResponse;
#define HY_enterConfigModeResponse_PACK_SIZE (sizeof(HY_enterConfigModeResponse)) #define HY_enterConfigModeResponse_PACK_SIZE (sizeof(HY_enterConfigModeResponse))
#define HY_enterConfigModeResponse_dataLen 5
/* 配置控制盒硬件ID号 */ /* 配置控制盒硬件ID号 */
typedef struct _HY_configHardwareID{ typedef struct _HY_configHardwareID{
@ -488,19 +502,36 @@ typedef struct _HY_configHardwareIDResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_configHardwareIDResponse; }HY_configHardwareIDResponse;
#define HY_configHardwareIDResponse_PACK_SIZE (sizeof(HY_configHardwareIDResponse)) #define HY_configHardwareIDResponse_PACK_SIZE (sizeof(HY_configHardwareIDResponse))
#define HY_configHardwareIDResponse_dataLen 5
///* 控制盒硬件ID号及通信ID号原传感器号查询 */ /* 控制盒硬件ID号及通信ID号原传感器号查询 */
//typedef struct _HY_QueryhardwareID_communicationID{ typedef struct _HY_QueryhardwareID_communicationID{
// uint8_t start_Flag; /* 起始标志 */ uint8_t start_Flag; /* 起始标志 */
// uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */ uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
// uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */ uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
// uint8_t controlWord; /* 控制字 */ uint8_t controlWord; /* 控制字 */
// uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */ uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
// uint32_t frameNumber; /* 帧序号 */ uint32_t frameNumber; /* 帧序号 */
// uint8_t check_Bit; /* 校验码 */ uint8_t check_Bit; /* 校验码 */
// uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
//}HY_QueryhardwareID_communicationID; }HY_QueryhardwareID_communicationID;
//#define HY_QueryhardwareID_communicationID_PACK_SIZE (sizeof(HY_QueryhardwareID_communicationID)) #define HY_QueryhardwareID_communicationID_PACK_SIZE (sizeof(HY_QueryhardwareID_communicationID))
/* 控制盒硬件ID号及通信ID号原传感器号查询响应 */
typedef struct _HY_QueryhardwareID_communicationIDResponse{
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t hardwareIDR[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationIDR[4]; /* 通信ID高字节在前低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_QueryhardwareID_communicationIDResponse;
#define HY_QueryhardwareID_communicationIDResponse_PACK_SIZE (sizeof(HY_QueryhardwareID_communicationIDResponse))
#define HY_QueryhardwareID_dataLen 14
/* 修改通信ID号原传感器号 */ /* 修改通信ID号原传感器号 */
typedef struct _HY_modifyCommunicationIDChange{ typedef struct _HY_modifyCommunicationIDChange{
@ -510,8 +541,8 @@ typedef struct _HY_modifyCommunicationIDChange{
uint8_t controlWord; /* 控制字 */ uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */ uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */ uint32_t frameNumber; /* 帧序号 */
uint8_t nowHardwareID[6]; /* 硬件ID高字节在前低字节在后 */ uint8_t newHardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t newcommunicationID[4]; /* 新通信ID高字节在前低字节在后 */ uint8_t newCommunicationID[4]; /* 新通信ID高字节在前低字节在后 */
uint8_t check_Bit; /* 校验码 */ uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_modifyCommunicationIDChange; }HY_modifyCommunicationIDChange;
@ -530,6 +561,7 @@ typedef struct _HY_modifyCommunicationIDChangeResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_modifyCommunicationIDChangeResponse; }HY_modifyCommunicationIDChangeResponse;
#define HY_modifyCommunicationIDChangeResponse_PACK_SIZE (sizeof(HY_modifyCommunicationIDChangeResponse)) #define HY_modifyCommunicationIDChangeResponse_PACK_SIZE (sizeof(HY_modifyCommunicationIDChangeResponse))
#define HY_modifyCommunicationIDChangeResponse_dataLen 5
/* 查询主板温度值 */ /* 查询主板温度值 */
typedef struct _HY_checkMotherboardTemperatureQuery{ typedef struct _HY_checkMotherboardTemperatureQuery{
@ -557,6 +589,7 @@ typedef struct _HY_checkMotherboardTemperatureResponse{
uint8_t end_Flag; /* 结束标志 */ uint8_t end_Flag; /* 结束标志 */
}HY_checkMotherboardTemperatureResponse; }HY_checkMotherboardTemperatureResponse;
#define HY_checkMotherboardTemperatureResponse_PACK_SIZE (sizeof(HY_checkMotherboardTemperatureResponse)) #define HY_checkMotherboardTemperatureResponse_PACK_SIZE (sizeof(HY_checkMotherboardTemperatureResponse))
#define HY_checkMotherboardTemperatureResponse_dataLen 8
/* 恢复默认的对齐设置 */ /* 恢复默认的对齐设置 */
#pragma pack(pop) #pragma pack(pop)

View File

@ -32,6 +32,7 @@ typedef struct _Mppt_controlparameter{
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */ uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
uint16_t excessiveLoadFlagTime; /* 出现过载后在该间隔时间中多次2次出现过载则关闭输出 (S) */ uint16_t excessiveLoadFlagTime; /* 出现过载后在该间隔时间中多次2次出现过载则关闭输出 (S) */
uint16_t eLAgainTime; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */ uint16_t eLAgainTime; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
uint32_t collectOpenCircuitVoltageTime; /* 开路电压采集时间间隔 */
} Mppt_controlparameter; } Mppt_controlparameter;
extern Mppt_controlparameter g_controlParameter; extern Mppt_controlparameter g_controlParameter;
@ -47,6 +48,7 @@ typedef struct _Mppt_otherParameter{
/* HY */ /* HY */
uint8_t hardwareID[6]; /* 硬件ID */ uint8_t hardwareID[6]; /* 硬件ID */
uint8_t communicationID[4]; /* 通信ID */ uint8_t communicationID[4]; /* 通信ID */
uint8_t protocolType; /* 协议类型; 0x01表示汇源协议(波特率9600) 0x02表示南瑞协议(波特率115200)*/
uint8_t startFlagHY; /* 起始码 */ uint8_t startFlagHY; /* 起始码 */
uint8_t endFlagHY; /* 结束码 */ uint8_t endFlagHY; /* 结束码 */
@ -86,6 +88,10 @@ typedef struct _Mppt_otherParameter{
uint8_t runBroadcast; /* 是否接收广播帧标志位 */ uint8_t runBroadcast; /* 是否接收广播帧标志位 */
uint16_t RegisterNumberMax; /* 寄存器个数 */ uint16_t RegisterNumberMax; /* 寄存器个数 */
uint16_t RegisterStartAddressMax; /* 读写的寄存器的最大起始位置,由设备决定 */ uint16_t RegisterStartAddressMax; /* 读写的寄存器的最大起始位置,由设备决定 */
uint32_t collectOpenCircuitVoltageNUM; /* 距离上次开路电压采集,运行次数 */
uint8_t HYconfigModeState; /* HY通信协议是否进入了配置模式0x00未进入0xFF进入 */
uint8_t HYconfigModeT; /* HY通信协议进入配置模式后的延时时间 */
}Mppt_otherParameter; }Mppt_otherParameter;
extern Mppt_otherParameter g_otherParameter; extern Mppt_otherParameter g_otherParameter;

View File

@ -16,7 +16,7 @@
/* Comment out this define to include debug messages */ /* Comment out this define to include debug messages */
//#define NDEBUG //#define NDEBUG
#define log_info_enable 0 #define log_info_enable 1
#define log_warn_enable 0 #define log_warn_enable 0
#define log_error_enable 0 #define log_error_enable 0

View File

@ -36,14 +36,18 @@ typedef enum
SL_Register_address = 0x0001, /* 地址 */ SL_Register_address = 0x0001, /* 地址 */
SL_Register_Access_Node_Type = 0x0002, /* 接入节点类型 */ SL_Register_Access_Node_Type = 0x0002, /* 接入节点类型 */
SL_Register_Communication_Methods = 0x0003, /* 通信方式 */ SL_Register_Communication_Methods = 0x0003, /* 通信方式 */
SL_Register_Output_Voltage = 0x0100, /* 输出电压 */
SL_Register_Solar_Open_Circuit_Voltage = 0x0100, /* 太阳能开路电压 */
SL_Register_Battery_Voltage = 0x0101, /* 电池电压 */ SL_Register_Battery_Voltage = 0x0101, /* 电池电压 */
SL_Register_Charg_Current = 0x0102, /* 充电电流(流向电池+负载) */ SL_Register_Charg_Current = 0x0102, /* 充电电流(流向电池+负载) */
SL_Register_Discharg_Current = 0x0103, /* 放电电流(流向负载) */ SL_Register_Discharg_Current = 0x0103, /* 放电电流(流向负载) */
SL_Register_Solar_Open_Circuit_Voltage = 0x0104, /* 太阳能开路电压 */ SL_Register_HighSideMos_Temperature = 0x0104, /* 高端mos的温度 */
SL_Register_HighSideMos_Temperature = 0x0105, /* 高端mos的温度 */ SL_Register_SOC = 0x0105, /* 剩余电量 */
SL_Register_DischargMos_State = 0x0106, /* 放电mos的状态 */ SL_Register_chargState = 0x0106, /* 充电状态 */
SL_Register_MPPT_Mode = 0x0107, /* 工作模式 */ SL_Register_totalChargCapacity = 0x0107, /* 总充电量 */
SL_Register_totalElectricityConsumption = 0x0108, /* 总放电量 */
SL_Register_MPPT_Mode = 0x0109, /* 工作模式 */
SL_Register_eliminateStatistical = 0x0110, /* 消除统计 */
}SL_Mppt_MsgRegister; }SL_Mppt_MsgRegister;
/* 注册状态 */ /* 注册状态 */

View File

@ -17,7 +17,7 @@ void Init();
/* 控制运行指示灯和喂狗 */ /* 控制运行指示灯和喂狗 */
#define WdiRunled_reloadVal 1000 /* 任务执行间隔 */ #define WdiRunled_reloadVal 1000 /* 任务执行间隔 */
#define WdiRunled_offset 700 /* 任务执行偏移量 */ #define WdiRunled_offset 100 /* 任务执行偏移量 */
#define wdi_RESET (60 * 60 * 24) /* 一天复位一次 */ #define wdi_RESET (60 * 60 * 24) /* 一天复位一次 */
extern STR_TimeSliceOffset m_WdiRunled; extern STR_TimeSliceOffset m_WdiRunled;
extern void Task_WdiRunled(void); extern void Task_WdiRunled(void);
@ -96,10 +96,24 @@ extern void Task_sensorEnableBroadcast(void);
extern STR_TimeSliceOffset m_uartConfigFile; extern STR_TimeSliceOffset m_uartConfigFile;
extern void Task_uartConfigFile(void); extern void Task_uartConfigFile(void);
/* 过载保护 */ ///* 过载延时 */
#define overloadDelay_reloadVal 10 /* 任务执行间隔 */ //#define overloadDelay_reloadVal 10 /* 任务执行间隔 */
#define overloadDelay_offset 0 /* 任务执行偏移量 */ //#define overloadDelay_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset g_overloadDelay; //extern STR_TimeSliceOffset g_overloadDelay;
extern void Task_overloadDelay(void); //extern void Task_overloadDelay(void);
/* 开路电压采集 */
#define collectOpenCircuitVoltage_reloadVal 1000 /* 任务执行间隔 */
#define collectOpenCircuitVoltage_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset g_collectOpenCircuitVoltage;
extern void Task_collectOpenCircuitVoltage(void);
/* HY进入配置模式延迟后退出 */
#define configurationModeDelayedExit_reloadVal 1000 /* 任务执行间隔 */
#define configurationModeDelayedExit_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset g_configurationModeDelayedExit;
extern void Task_configurationModeDelayedExit(void);
#endif /* APP_INC_TASK_H_ */ #endif /* APP_INC_TASK_H_ */

View File

@ -182,7 +182,7 @@ static int HY_matchCommunicationID(u_int8_t communicationID[4])
(communicationID[1] == g_otherParameter.communicationID[1]) && \ (communicationID[1] == g_otherParameter.communicationID[1]) && \
(communicationID[2] == g_otherParameter.communicationID[2]) && \ (communicationID[2] == g_otherParameter.communicationID[2]) && \
(communicationID[3] == g_otherParameter.communicationID[3])) { (communicationID[3] == g_otherParameter.communicationID[3])) {
log_info("Match_hardwareIDHY success \r\n"); log_info("Match_CommunicationIDHY success \r\n");
return 1; return 1;
} }
return 0; return 0;
@ -200,7 +200,7 @@ static int Match_BroadcastCommunicationID(u_int8_t communicationID[4])
communicationID[1] == 0xFF && \ communicationID[1] == 0xFF && \
communicationID[2] == 0xFF && \ communicationID[2] == 0xFF && \
communicationID[3] == 0xFF) { communicationID[3] == 0xFF) {
log_info("Match_BroadcastHardwareID success\r\n"); log_info("Match_BroadcastCommunicationID success\r\n");
return 1; return 1;
} }
return 0; return 0;
@ -242,11 +242,14 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
/* 匹配起始标志位 */ /* 匹配起始标志位 */
if (offset == HY_analyzeStartFlag || (flag_run > 0)) { if (offset == HY_analyzeStartFlag || (flag_run > 0)) {
if (pack->start_Flag != g_otherParameter.startFlagHY) { if (pack->start_Flag != g_otherParameter.startFlagHY) {
log_info("Match_start_Flag error"); log_info(" Match_start_Flag error %x ", pack->start_Flag);
// printf("1 : %x \n", pack->start_Flag);
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
} }
// log_info(" Match_start_Flag success ");
// printf("%x\n", pack->start_Flag);
} }
/* 匹配硬件ID */ /* 匹配硬件ID */
@ -273,7 +276,7 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
/* 匹配通信ID */ /* 匹配通信ID */
if (offset == HY_analyzeCommunicationID || (flag_run > 2)) { if (offset == HY_analyzeCommunicationID || (flag_run > 2)) {
if (HY_matchCommunicationID(pack->hardwareID) || Match_BroadcastCommunicationID(pack->hardwareID)) { if (!(HY_matchCommunicationID(pack->communicationID) || Match_BroadcastCommunicationID(pack->communicationID))) {
if (flag_run < 2) { if (flag_run < 2) {
flag_run = 2; flag_run = 2;
} }
@ -341,9 +344,9 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
else if (pack->controlWord == HY_configureHardwareID && hardwordIDType == 0x02) { else if (pack->controlWord == HY_configureHardwareID && hardwordIDType == 0x02) {
len = HY_configHardwareID_PACK_SIZE; len = HY_configHardwareID_PACK_SIZE;
} }
// else if (pack->controlWord == HY_hardwareID_communicationIDQuery) { else if (pack->controlWord == HY_hardwareID_communicationIDQuery && hardwordIDType == 0x01) {
// len = HY_modifyCommunicationIDChange_PACK_SIZE; len = HY_QueryhardwareID_communicationID_PACK_SIZE;
// } }
else if (pack->controlWord == HY_modifyCommunicationID && hardwordIDType == 0x02) { else if (pack->controlWord == HY_modifyCommunicationID && hardwordIDType == 0x02) {
len = HY_modifyCommunicationIDChange_PACK_SIZE; len = HY_modifyCommunicationIDChange_PACK_SIZE;
} }
@ -369,6 +372,7 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
if (flag_run < 4) { if (flag_run < 4) {
flag_run = 4; flag_run = 4;
} }
log_info("Match_dataLen error: %x", len);
log_info("Match_dataLen error: %x", (pack->dataLen[0] << 8 | pack->dataLen[1]) + 16); 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[0]);
log_info("Match_dataLen error: %x", pack->dataLen[1]); log_info("Match_dataLen error: %x", pack->dataLen[1]);
@ -457,26 +461,24 @@ void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t Msg
pack.dataLen[0] = HY_batteryStatusResponse_dataLen >> 8; pack.dataLen[0] = HY_batteryStatusResponse_dataLen >> 8;
pack.dataLen[1] = HY_batteryStatusResponse_dataLen; pack.dataLen[1] = HY_batteryStatusResponse_dataLen;
pack.batteryVoltage = g_otherParameter.Battery_Voltage; // pack.batteryVoltage = g_otherParameter.Battery_Voltage;
pack.batteryVoltage = 6.66;
pack.dischargCurrent = g_otherParameter.Discharg_Current; pack.dischargCurrent = g_otherParameter.Discharg_Current;
pack.chargCurrent1 = g_otherParameter.Charg_Current; pack.chargCurrent1 = g_otherParameter.Charg_Current;
pack.SOC = g_otherParameter.SOC; pack.SOC = g_otherParameter.SOC;
pack.openCircuitVoltage1 = g_otherParameter.Solar_In_Circuit_Voltage; pack.openCircuitVoltage1 = g_otherParameter.Solar_In_Circuit_Voltage;
if (g_controlParameter.dutyRatio) { if (g_controlParameter.dutyRatio && g_otherParameter.Charg_Current > 0.05) {
pack.chargSwitchStatus1 = 1; pack.chargSwitchStatus1 = HY_switchON;
} else { } else {
pack.chargSwitchStatus1 = 0; pack.chargSwitchStatus1 = HY_switchOFF;
} }
pack.chargCurrent2 = g_otherParameter.Charg_Current; pack.chargCurrent2 = pack.chargCurrent1;
pack.openCircuitVoltage1 = g_otherParameter.Solar_In_Circuit_Voltage; pack.openCircuitVoltage2 = pack.openCircuitVoltage1;
if (g_controlParameter.dutyRatio) { pack.chargSwitchStatus2 = pack.chargSwitchStatus1;
pack.chargSwitchStatus2 = 1;
} else {
pack.chargSwitchStatus2 = 0;
}
pack.Mos_Temperature = g_otherParameter.HighSideMos_Temperature; pack.Mos_Temperature = g_otherParameter.HighSideMos_Temperature;
@ -488,7 +490,6 @@ void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t Msg
pack.end_Flag = g_otherParameter.endFlagHY; pack.end_Flag = g_otherParameter.endFlagHY;
while (1) { while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) { if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE); uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE);
@ -500,8 +501,8 @@ void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t Msg
break; break;
} }
Delay_Ms(randomDelay());
} }
} }
/* 电量统计数据报 */ /* 电量统计数据报 */
@ -530,6 +531,12 @@ void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint
pack.statisticalDuration = 0; pack.statisticalDuration = 0;
pack.totalChargCapacity = g_otherParameter.totalChargCapacity; pack.totalChargCapacity = g_otherParameter.totalChargCapacity;
pack.totalElectricityConsumption = g_otherParameter.totalElectricityConsumption; pack.totalElectricityConsumption = g_otherParameter.totalElectricityConsumption;
/* ²éѯºóÇå¿Õ */
g_otherParameter.totalChargCapacity = 0;
g_otherParameter.totalElectricityConsumption = 0;
saveTotalPower(&g_otherParameter.totalElectricityConsumption, &g_otherParameter.totalChargCapacity);
HY_electricityStatisticsQuery *Tpack = (HY_electricityStatisticsQuery *)pMsg; HY_electricityStatisticsQuery *Tpack = (HY_electricityStatisticsQuery *)pMsg;
pack.frameNumber = Tpack->frameNumber; pack.frameNumber = Tpack->frameNumber;
@ -537,9 +544,8 @@ void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint
pack.end_Flag = g_otherParameter.endFlagHY; pack.end_Flag = g_otherParameter.endFlagHY;
while (1) { while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) { if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE); uart_dev_write(device, &pack, HY_electricityStatisticsResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) { if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
@ -549,6 +555,7 @@ void HY_MsgProcFunc_electricityStatistics(device_handle device, void *pMsg, uint
break; break;
} }
Delay_Ms(randomDelay());
} }
} }
@ -601,13 +608,12 @@ void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg,
pack.frameNumber = Tpack->frameNumber; pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_sensorNumberConfiguration_PACK_SIZE - 2); pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_sensorNumberConfigurationResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY; pack.end_Flag = g_otherParameter.endFlagHY;
while (1) { while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) { if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE); uart_dev_write(device, &pack, HY_sensorNumberConfigurationResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) { if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
@ -617,6 +623,7 @@ void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg,
break; break;
} }
Delay_Ms(randomDelay());
} }
} }
@ -660,13 +667,12 @@ void HY_MsgProcFunc_sensorNumberInquiry(device_handle device, void *pMsg, uint32
pack.frameNumber = Tpack->frameNumber; pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_sensorNumberConfiguration_PACK_SIZE - 2); pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_sensorNumberInquiryResponse_PACK_SIZE - 2);
pack.end_Flag = g_otherParameter.endFlagHY; pack.end_Flag = g_otherParameter.endFlagHY;
while (1) { while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) { if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE); uart_dev_write(device, &pack, HY_sensorNumberInquiryResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) { if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
@ -676,6 +682,7 @@ void HY_MsgProcFunc_sensorNumberInquiry(device_handle device, void *pMsg, uint32
break; break;
} }
Delay_Ms(randomDelay());
} }
} }
@ -725,9 +732,8 @@ void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t
pack.end_Flag = g_otherParameter.endFlagHY; pack.end_Flag = g_otherParameter.endFlagHY;
while (1) { while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(device)) { if (!Check_485_bus_busy(device)) {
uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE); uart_dev_write(device, &pack, HY_resetInstructionResponse_PACK_SIZE);
if (device == g_bat485_uart3_handle) { if (device == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
@ -736,6 +742,7 @@ void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t
} }
break; break;
} }
Delay_Ms(randomDelay());
} }
/* 复位 */ /* 复位 */
@ -746,107 +753,593 @@ void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t
/* 充电控制配置 */ /* 充电控制配置 */
void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen) void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen)
{ {
// HY_chargingControlConfig *Tpack = (HY_chargingControlConfig *)pMsg; HY_chargingControlConfig *Tpack = (HY_chargingControlConfig *)pMsg;
//
// HY_chargingControlConfigResponse pack; if (Tpack->chargInterfaceControl == HY_switchON) {
// if (g_controlParameter.dutyRatio == 0) {
// pack.start_Flag = g_otherParameter.startFlagHY; if (g_otherParameter.Output_Voltage > 11) {
// g_otherParameter.batteryState = 1;
// pack.hardwareID[0] = g_otherParameter.hardwareID[0]; } else {
// pack.hardwareID[1] = g_otherParameter.hardwareID[1]; g_otherParameter.batteryState = 0;
// pack.hardwareID[2] = g_otherParameter.hardwareID[2]; }
// pack.hardwareID[3] = g_otherParameter.hardwareID[3]; TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
// pack.hardwareID[4] = g_otherParameter.hardwareID[4]; }
// pack.hardwareID[5] = g_otherParameter.hardwareID[5]; }
//
// pack.communicationID[0] = g_otherParameter.communicationID[0]; if (Tpack->chargInterfaceControl == HY_switchOFF) {
// pack.communicationID[1] = g_otherParameter.communicationID[1]; if (g_controlParameter.dutyRatio != 0) {
// pack.communicationID[2] = g_otherParameter.communicationID[2]; TIM_Cmd(TIM3, DISABLE);
// pack.communicationID[3] = g_otherParameter.communicationID[3]; TIM_SetCompare4(TIM4, 0);
// g_controlParameter.dutyRatio = 0;
// pack.controlWord = Tpack->controlWord;
// TimeSliceOffset_Unregister(&g_collectOpenCircuitVoltage);
// pack.dataLen[0] = HY_chargingControlConfigResponse_dataLen >> 8; }
// pack.dataLen[1] = HY_chargingControlConfigResponse_dataLen; }
//
// pack.state = HY_success; HY_chargingControlConfigResponse pack;
//
// pack.frameNumber = Tpack->frameNumber; pack.start_Flag = g_otherParameter.startFlagHY;
//
// pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_chargingControlConfigResponse_PACK_SIZE - 2); pack.hardwareID[0] = g_otherParameter.hardwareID[0];
// pack.end_Flag = g_otherParameter.endFlagHY; pack.hardwareID[1] = g_otherParameter.hardwareID[1];
// pack.hardwareID[2] = g_otherParameter.hardwareID[2];
// while (1) { pack.hardwareID[3] = g_otherParameter.hardwareID[3];
// Delay_Ms(randomDelay()); pack.hardwareID[4] = g_otherParameter.hardwareID[4];
// if (!Check_485_bus_busy(device)) { pack.hardwareID[5] = g_otherParameter.hardwareID[5];
// uart_dev_write(device, &pack, HY_batteryStatusResponse_PACK_SIZE);
// pack.communicationID[0] = g_otherParameter.communicationID[0];
// if (device == g_bat485_uart3_handle) { pack.communicationID[1] = g_otherParameter.communicationID[1];
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); pack.communicationID[2] = g_otherParameter.communicationID[2];
// } else { pack.communicationID[3] = g_otherParameter.communicationID[3];
// USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
// } pack.controlWord = Tpack->controlWord;
// break;
// } 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());
}
} }
/* 充电控制查询 */ /* 充电控制查询 */
static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen) 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;
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());
}
} }
/* 配置协议类型 */ /* 配置协议类型 */
void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen) 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;
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();
} }
///* ÏìÓ¦ÅäÖÃЭÒéÀàÐÍ */
//static void HY_MsgProcFunc_batteryStatus(device_handle device, void *pMsg, uint32_t MsgLen);
/* 查询电池控制盒当前配置 */ /* 查询电池控制盒当前配置 */
void HY_MsgProcFunc_queryControlBoxConfiguration(device_handle device, void *pMsg, uint32_t MsgLen) 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];
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());
}
} }
/* 查询电池控制盒软件版本 */ /* 查询电池控制盒软件版本 */
void HY_MsgProcFunc_querySoftwareVersion(device_handle device, void *pMsg, uint32_t MsgLen) 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;
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());
}
} }
/* 进入配置模式 */ /* 进入配置模式 */
void HY_MsgProcFunc_enterConfigurationMode(device_handle device, void *pMsg, uint32_t MsgLen) 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;
} }
/* 配置控制盒硬件ID号 */ /* 配置控制盒硬件ID号 */
void HY_MsgProcFunc_configureHardwareID(device_handle device, void *pMsg, uint32_t MsgLen) 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;
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());
}
} }
/* 控制盒硬件ID号及通信ID号原传感器号查询 */ /* 控制盒硬件ID号及通信ID号原传感器号查询 */
void HY_MsgProcFunc_hardwareID_communicationIDQuery(device_handle device, void *pMsg, uint32_t MsgLen) 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);
}
break;
}
Delay_Ms(randomDelay());
}
} }
/* 修改通信ID号原传感器号 */ /* 修改通信ID号原传感器号 */
void HY_MsgProcFunc_modifyCommunicationID(device_handle device, void *pMsg, uint32_t MsgLen) 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];
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());
}
} }
/* 查询主板温度值 */ /* 查询主板温度值 */
void HY_MsgProcFunc_checkMotherboardTemperature(device_handle device, void *pMsg, uint32_t MsgLen) 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);
}
break;
}
Delay_Ms(randomDelay());
}
} }

View File

@ -202,6 +202,7 @@ void config_info_start(void)
g_controlParameter.outputAgainFlagTime = temp_configInfo.outputAgainFlagTime; g_controlParameter.outputAgainFlagTime = temp_configInfo.outputAgainFlagTime;
g_controlParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime; g_controlParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime;
g_controlParameter.eLAgainTime = temp_configInfo.eLAgainTime; g_controlParameter.eLAgainTime = temp_configInfo.eLAgainTime;
g_controlParameter.collectOpenCircuitVoltageTime= 3600;
// strlcpy(g_otherParameter.address, temp_configInfo.address, 7); // strlcpy(g_otherParameter.address, temp_configInfo.address, 7);
g_otherParameter.address[0] = temp_configInfo.address[0]; g_otherParameter.address[0] = temp_configInfo.address[0];
@ -228,6 +229,7 @@ void config_info_start(void)
g_otherParameter.communicationID[1] = temp_configInfo.communicationID[1]; g_otherParameter.communicationID[1] = temp_configInfo.communicationID[1];
g_otherParameter.communicationID[2] = temp_configInfo.communicationID[2]; g_otherParameter.communicationID[2] = temp_configInfo.communicationID[2];
g_otherParameter.communicationID[3] = temp_configInfo.communicationID[3]; g_otherParameter.communicationID[3] = temp_configInfo.communicationID[3];
g_otherParameter.protocolType = temp_configInfo.protocolType;
g_otherParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType; g_otherParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType;
// g_otherParameter.CommunicationProtocolType = 0x01; // g_otherParameter.CommunicationProtocolType = 0x01;
g_otherParameter.onlyPower = temp_configInfo.onlyPower; g_otherParameter.onlyPower = temp_configInfo.onlyPower;
@ -263,23 +265,27 @@ void config_info_start(void)
g_otherParameter.overTemperature = 0; g_otherParameter.overTemperature = 0;
g_otherParameter.RegistrationRequestFlag = 0; g_otherParameter.RegistrationRequestFlag = 0;
g_otherParameter.runBroadcast = 1; g_otherParameter.runBroadcast = 1;
g_otherParameter.RegisterNumberMax = 5; g_otherParameter.RegisterNumberMax = 10;
g_otherParameter.RegisterStartAddressMax = 0x150; g_otherParameter.RegisterStartAddressMax = 0x150;
g_otherParameter.HYconfigModeState = 0;
g_otherParameter.HYconfigModeT = 0;
if (g_otherParameter.CommunicationProtocolType == 0x00) { if (g_otherParameter.CommunicationProtocolType == 0x00) {
g_otherParameter.gw485_Baud = temp_configInfo.gw485_Baud; g_otherParameter.gw485_Baud = temp_configInfo.gw485_Baud;
g_otherParameter.bat485_Baud = temp_configInfo.bat485_Baud; g_otherParameter.bat485_Baud = temp_configInfo.bat485_Baud;
} else if (g_otherParameter.CommunicationProtocolType == 0x01) { } else if (g_otherParameter.CommunicationProtocolType == 0x01) {
g_otherParameter.bat485_Baud = temp_configInfo.bat485_Baud; g_otherParameter.bat485_Baud = temp_configInfo.bat485_Baud;
if (temp_configInfo.protocolType == 0x01) { if (g_otherParameter.protocolType == 0x01) {
g_otherParameter.gw485_Baud = 9600; g_otherParameter.gw485_Baud = 9600;
} else if (temp_configInfo.protocolType == 0x02) { } else if (g_otherParameter.protocolType == 0x02) {
g_otherParameter.gw485_Baud = 115200; g_otherParameter.gw485_Baud = 115200;
} }
} }
// printf(""); // printf("");
printf("%s\n", g_otherParameter.versionInformation);
printf("address : 0x %x %x %x %x %x %x %x\n", g_otherParameter.address[0] printf("address : 0x %x %x %x %x %x %x %x\n", g_otherParameter.address[0]
, g_otherParameter.address[1], g_otherParameter.address[2], g_otherParameter.address[3] , g_otherParameter.address[1], g_otherParameter.address[2], g_otherParameter.address[3]
, g_otherParameter.address[4], g_otherParameter.address[5], g_otherParameter.address[6]); , g_otherParameter.address[4], g_otherParameter.address[5], g_otherParameter.address[6]);

View File

@ -160,6 +160,7 @@ void MpptModeChoice(void)
TimeSliceOffset_Register(&g_startMpptControl, Task_startMpptControl TimeSliceOffset_Register(&g_startMpptControl, Task_startMpptControl
, startMpptControl_reloadVal, startMpptControl_offset); , startMpptControl_reloadVal, startMpptControl_offset);
TimeSliceOffset_Unregister(&g_collectOpenCircuitVoltage);
return; return;
} }
@ -179,7 +180,8 @@ void MpptModeChoice(void)
} }
if ((g_controlParameter.constantVoltageV < g_otherParameter.Battery_Voltage) if ((g_controlParameter.constantVoltageV < g_otherParameter.Battery_Voltage)
&& (g_controlParameter.floatI + 0.1 <= g_otherParameter.Charg_Current)) { // && (g_controlParameter.floatI + 0.1 <= g_otherParameter.Charg_Current)) {
&& ((g_controlParameter.floatI + 0.1 <= g_otherParameter.Charg_BatteryCurrent) || (g_controlParameter.floatI + 0.1 <= -g_otherParameter.Charg_Current))) {
g_otherParameter.MPPT_Mode = CONSTANTVOLTAGE; g_otherParameter.MPPT_Mode = CONSTANTVOLTAGE;
return; return;
} }
@ -211,11 +213,6 @@ void MpptContorl(void)
g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current; g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current;
/* 判断有无电池 */
if (g_otherParameter.batteryState == 0 && (g_otherParameter.Charg_BatteryCurrent > 0.1 || g_otherParameter.Charg_BatteryCurrent < -0.1)
&& g_otherParameter.Output_Voltage < 14.2) {
g_otherParameter.batteryState = 1;
}
if (!g_otherParameter.overTemperature) { if (!g_otherParameter.overTemperature) {
MpptModeChoice(); MpptModeChoice();

View File

@ -34,13 +34,18 @@ static void SL_MsgProcFunc_Registration_request(device_handle device, void *pMsg
static void SL_MsgProcFunc_Update_Profile(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 void SL_MsgProcFunc_Remote_Upgrade(device_handle device, void *pMsg, uint32_t MsgLen);
static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg);
static uint16_t SL_ReadRegisterBatteryVoltage(void *pMsg); static uint16_t SL_ReadRegisterBatteryVoltage(void *pMsg);
static uint16_t SL_ReadRegisterChargCurrent(void *pMsg); static uint16_t SL_ReadRegisterChargCurrent(void *pMsg);
static uint16_t SL_ReadRegisterDischargCurrent(void *pMsg); static uint16_t SL_ReadRegisterDischargCurrent(void *pMsg);
static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg);
static uint16_t SL_ReadRegisterHighSideMosTemperature(void *pMsg); static uint16_t SL_ReadRegisterHighSideMosTemperature(void *pMsg);
static uint16_t SL_ReadRegisterDischargMosState(void *pMsg); static uint16_t SL_ReadRegisterSOC(void *pMsg);
static uint16_t SL_ReadRegisterMPPTMode(void *pMsg); static uint16_t SL_ReadRegisterChargState(void *pMsg);
static uint16_t SL_ReadRegisterTotalChargCapacity(void *pMsg);
static uint16_t SL_ReadRegisterTotalElectricityConsumption(void *pMsg);
static uint16_t SL_ReadRegisterMPPT_Mode(void *pMsg);
static uint16_t SL_WriteRegisterEliminateStatistical(void *pMsg);
/* 功能码处理表 */ /* 功能码处理表 */
SL_FuncionMsgProcTable g_MsgTbl[] = SL_FuncionMsgProcTable g_MsgTbl[] =
@ -60,13 +65,16 @@ SL_RegProcTable g_RegTblR[] =
// {SL_Register_address, SL_ReadRegisteraddress}, // {SL_Register_address, SL_ReadRegisteraddress},
// {SL_Register_Access_Node_Type, SL_ReadRegisterAccessNodeType}, // {SL_Register_Access_Node_Type, SL_ReadRegisterAccessNodeType},
// {SL_Register_Communication_Methods, SL_ReadRegisterCommunicationMethods}, // {SL_Register_Communication_Methods, SL_ReadRegisterCommunicationMethods},
{SL_Register_Solar_Open_Circuit_Voltage, SL_ReadRegisterSolarOpenCircuitVoltage},
{SL_Register_Battery_Voltage, SL_ReadRegisterBatteryVoltage}, {SL_Register_Battery_Voltage, SL_ReadRegisterBatteryVoltage},
{SL_Register_Charg_Current, SL_ReadRegisterChargCurrent}, {SL_Register_Charg_Current, SL_ReadRegisterChargCurrent},
{SL_Register_Discharg_Current, SL_ReadRegisterDischargCurrent}, {SL_Register_Discharg_Current, SL_ReadRegisterDischargCurrent},
{SL_Register_Solar_Open_Circuit_Voltage, SL_ReadRegisterSolarOpenCircuitVoltage},
{SL_Register_HighSideMos_Temperature, SL_ReadRegisterHighSideMosTemperature}, {SL_Register_HighSideMos_Temperature, SL_ReadRegisterHighSideMosTemperature},
{SL_Register_DischargMos_State, SL_ReadRegisterDischargMosState}, {SL_Register_SOC, SL_ReadRegisterSOC},
{SL_Register_MPPT_Mode, SL_ReadRegisterMPPTMode}, {SL_Register_chargState, SL_ReadRegisterChargState},
{SL_Register_totalChargCapacity, SL_ReadRegisterTotalChargCapacity},
{SL_Register_totalElectricityConsumption, SL_ReadRegisterTotalElectricityConsumption},
{SL_Register_MPPT_Mode, SL_ReadRegisterMPPT_Mode},
}; };
/* 寄存器处理表 */ /* 寄存器处理表 */
@ -81,6 +89,7 @@ SL_RegProcTable g_RegTblW[] =
// {SL_Register_Remaining_Battery_Bower, SL_WriteRegisterRemainingBatteryBower}, // {SL_Register_Remaining_Battery_Bower, SL_WriteRegisterRemainingBatteryBower},
// {SL_Register_Solar_Open_Circuit_Voltage1, SL_WriteRegisterSolarOpenCircuitVoltage1}, // {SL_Register_Solar_Open_Circuit_Voltage1, SL_WriteRegisterSolarOpenCircuitVoltage1},
// {SL_Register_Solar_Open_Circuit_Voltage2, SL_WriteRegisterSolarOpenCircuitVoltage2}, // {SL_Register_Solar_Open_Circuit_Voltage2, SL_WriteRegisterSolarOpenCircuitVoltage2},
{SL_Register_eliminateStatistical, SL_WriteRegisterEliminateStatistical}
}; };
/** /**
@ -392,6 +401,19 @@ void SL_MsgProcFunc_Remote_Upgrade(device_handle device, void *pMsg, uint32_t Ms
} }
} }
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg)
{
log_info(" SL_ReadRegisterSolarOpenCircuitVoltage ");
uint16_t value = (uint16_t)(g_otherParameter.Solar_Open_Circuit_Voltage * 10);
return value;
}
/** /**
* @brief * @brief
* @param * @param
@ -429,19 +451,7 @@ uint16_t SL_ReadRegisterDischargCurrent(void *pMsg)
} }
/** /**
* @brief * @brief mos管的温度寄存器
* @param
* @retval
*/
uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg)
{
log_info(" SL_ReadRegisterSolarOpenCircuitVoltage ");
uint16_t value = (uint16_t)(g_otherParameter.Solar_Open_Circuit_Voltage * 10);
return value;
}
/**
* @brief mos管的温度寄存器
* @param * @param
* @retval * @retval
*/ */
@ -453,29 +463,93 @@ uint16_t SL_ReadRegisterHighSideMosTemperature(void *pMsg)
} }
/** /**
* @brief mos管状态寄存器 * @brief
* @param * @param
* @retval * @retval
*/ */
uint16_t SL_ReadRegisterDischargMosState(void *pMsg) uint16_t SL_ReadRegisterSOC(void *pMsg)
{ {
log_info(" SL_ReadRegisterDischargMosState "); log_info(" SL_ReadRegisterSOC ");
uint16_t value = (uint16_t)g_otherParameter.DischargMos_State; uint16_t value = (uint16_t)(1 * 10);
return value; return value;
} }
/** /**
* @brief mppt工作模式寄存器 * @brief
* @param * @param
* @retval * @retval
*/ */
uint16_t SL_ReadRegisterMPPTMode(void *pMsg) uint16_t SL_ReadRegisterChargState(void *pMsg)
{ {
log_info(" SL_ReadRegisterMPPTMode "); log_info(" SL_ReadRegisterChargState ");
uint16_t value = (uint16_t)g_otherParameter.MPPT_Mode; uint16_t value = 0;
if (g_controlParameter.dutyRatio > 0 && g_otherParameter.Charg_Current > 0.05) {
value |= 0xFF00;
} else {
value &= 0x00FF;
}
if (g_otherParameter.DischargMos_State == Bit_SET && g_otherParameter.Discharg_Current > 0.05) {
value |= 0x00FF;
} else {
value &= 0xFF00;
}
return value; return value;
} }
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterTotalChargCapacity(void *pMsg)
{
log_info(" SL_ReadRegisterTotalChargCapacity ");
uint16_t value = (uint16_t)(g_otherParameter.totalChargCapacity * 1000);
return value;
}
/**
* @brief
* @param
* @retval
*/
uint16_t SL_ReadRegisterTotalElectricityConsumption(void *pMsg)
{
log_info(" SL_ReadRegisterTotalElectricityConsumption ");
uint16_t value = (uint16_t)(g_otherParameter.totalElectricityConsumption * 1000);
return value;
}
/**
* @brief MPPT工作模式
* @param
* @retval
*/
uint16_t SL_ReadRegisterMPPT_Mode(void *pMsg)
{
log_info(" SL_ReadRegisterMPPT_Mode ");
uint16_t value = (uint16_t)(g_otherParameter.MPPT_Mode);
return value;
}
/**
* @brief
* @param
* @retval
*/
uint16_t SL_WriteRegisterEliminateStatistical(void *pMsg)
{
log_info(" SL_WriteRegisterEliminateStatistical ");
g_otherParameter.totalChargCapacity = 0;
g_otherParameter.totalElectricityConsumption = 0;
saveTotalPower(&g_otherParameter.totalElectricityConsumption, &g_otherParameter.totalChargCapacity);
return 1;
}
/** /**
* @brief "SL" * @brief "SL"
* @param start_buff * @param start_buff
@ -757,21 +831,3 @@ void read_and_process_uart_data(device_handle device)
} }
} }

View File

@ -34,7 +34,6 @@
void Init() void Init()
{ {
SPI_Flash_Init(); SPI_Flash_Init();
// SPI_Flash_Erase_Sector(0);
currBuffInit(); currBuffInit();
config_info_start(); config_info_start();
adcChangeProportionalInit(); adcChangeProportionalInit();
@ -48,6 +47,8 @@ void Init()
POW_FF_CON_Init(); POW_FF_CON_Init();
DSG_PROT_Init(); DSG_PROT_Init();
WORK_VOLT_INT_Init(); WORK_VOLT_INT_Init();
/* 1ms */
TIM3_Init(10); TIM3_Init(10);
TimeSliceOffset_Register(&m_WdiRunled, Task_WdiRunled, WdiRunled_reloadVal, WdiRunled_offset); TimeSliceOffset_Register(&m_WdiRunled, Task_WdiRunled, WdiRunled_reloadVal, WdiRunled_offset);
@ -102,6 +103,8 @@ void Task_WdiRunled(void)
GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, SET); GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, SET);
GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, RESET); GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, RESET);
// printf(" vBattery : %d/100 \n", (int)(g_otherParameter.Battery_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n")); uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
char buffer[80]; char buffer[80];
@ -187,11 +190,16 @@ void Task_refreshRegister(void)
g_otherParameter.Solar_In_Circuit_Voltage = get_PV1_VOLT_IN(); g_otherParameter.Solar_In_Circuit_Voltage = get_PV1_VOLT_IN();
g_otherParameter.HighSideMos_Temperature = get_MOSFET_Temper(); g_otherParameter.HighSideMos_Temperature = get_MOSFET_Temper();
if (g_controlParameter.dutyRatio == 0) {
g_otherParameter.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
}
g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current
- g_otherParameter.Discharg_Current; - g_otherParameter.Discharg_Current;
g_otherParameter.totalChargCapacity += totalChargCapacity / 3600000; g_otherParameter.totalChargCapacity += totalChargCapacity / 3600000;
g_otherParameter.totalElectricityConsumption += totalElectricityConsumption / 3600000; g_otherParameter.totalElectricityConsumption += totalElectricityConsumption / 3600000;
saveTotalPower(&g_otherParameter.totalElectricityConsumption, &g_otherParameter.totalChargCapacity); // saveTotalPower(&g_otherParameter.totalElectricityConsumption, &g_otherParameter.totalChargCapacity);
totalChargCapacity = 0; totalChargCapacity = 0;
totalElectricityConsumption = 0; totalElectricityConsumption = 0;
@ -238,12 +246,12 @@ void Task_impedanceCalculation(void)
return; return;
} }
if (num == 11) { // if (num == 11) {
currOne = get_CHG_CURR() - get_DSG_CURR(); // currOne = get_CHG_CURR() - get_DSG_CURR();
voltOne = get_PV_VOLT_OUT(); // voltOne = get_PV_VOLT_OUT();
TIM_SetCompare4(TIM4, 420); // TIM_SetCompare4(TIM4, 420);
return; // return;
} // }
if (num == 21) { if (num == 21) {
TimeSliceOffset_Unregister(&m_impedanceCalculation); TimeSliceOffset_Unregister(&m_impedanceCalculation);
@ -379,8 +387,7 @@ void Task_softStart(void)
if (g_otherParameter.batteryState == 1) { if (g_otherParameter.batteryState == 1) {
g_otherParameter.MPPT_Mode = CONSTANTCURRENT; g_otherParameter.MPPT_Mode = CONSTANTCURRENT;
TIM_Cmd(TIM3, ENABLE); goto start;
return;
} else { } else {
g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current
- g_otherParameter.Discharg_Current; - g_otherParameter.Discharg_Current;
@ -388,14 +395,14 @@ void Task_softStart(void)
if (g_otherParameter.Charg_BatteryCurrent > 0.1 if (g_otherParameter.Charg_BatteryCurrent > 0.1
|| g_otherParameter.Charg_BatteryCurrent < -0.1) { || g_otherParameter.Charg_BatteryCurrent < -0.1) {
g_otherParameter.MPPT_Mode = CONSTANTCURRENT; g_otherParameter.MPPT_Mode = CONSTANTCURRENT;
TIM_Cmd(TIM3, ENABLE);
return;
} }
g_otherParameter.MPPT_Mode = FLOAT; g_otherParameter.MPPT_Mode = FLOAT;
TIM_Cmd(TIM3, ENABLE);
return; start:
TIM_Cmd(TIM3, ENABLE);
TimeSliceOffset_Register(&g_collectOpenCircuitVoltage, Task_collectOpenCircuitVoltage
, collectOpenCircuitVoltage_reloadVal, collectOpenCircuitVoltage_offset);
} }
} }
} }
@ -439,6 +446,12 @@ void Task_startMpptControl(void)
STR_TimeSliceOffset g_dataJudgment; STR_TimeSliceOffset g_dataJudgment;
void Task_dataJudgment(void) void Task_dataJudgment(void)
{ {
/* 判断有无电池 */
if (g_otherParameter.batteryState == 0 && (g_otherParameter.Charg_BatteryCurrent > 0.1 || g_otherParameter.Charg_BatteryCurrent < -0.1)
&& g_otherParameter.Output_Voltage < 14.2) {
g_otherParameter.batteryState = 1;
}
/* 有电池,太阳能输出功率大,同时回路阻抗未测试或需要重新测试 */ /* 有电池,太阳能输出功率大,同时回路阻抗未测试或需要重新测试 */
if ((g_otherParameter.impedanceStart == 1 || g_controlParameter.loopImpedance == 0.0) if ((g_otherParameter.impedanceStart == 1 || g_controlParameter.loopImpedance == 0.0)
&& g_otherParameter.batteryState == 1 && (g_otherParameter.Charg_Current > 3.0)) { && g_otherParameter.batteryState == 1 && (g_otherParameter.Charg_Current > 3.0)) {
@ -623,18 +636,55 @@ void Task_uartConfigFile(void)
read_and_process_config_data(); read_and_process_config_data();
} }
///**
// * @brief 过载延时
// * @param
// * @retval
// *
// */
//STR_TimeSliceOffset g_overloadDelay;
//void Task_overloadDelay(void)
//{
// TimeSliceOffset_Unregister(&g_overloadDelay);
// g_overloadDelay.runFlag = 0;
// WORK_VOLT_INT_open();
//}
/** /**
* @brief ¹ýÔØÑÓʱ * @brief
* @param * @param
* @retval * @retval
* *
*/ */
STR_TimeSliceOffset g_overloadDelay; STR_TimeSliceOffset g_collectOpenCircuitVoltage;
void Task_overloadDelay(void) void Task_collectOpenCircuitVoltage(void)
{ {
TimeSliceOffset_Unregister(&g_overloadDelay); static uint8_t flag = 0;
g_overloadDelay.runFlag = 0; g_otherParameter.collectOpenCircuitVoltageNUM++;
WORK_VOLT_INT_open(); if (g_otherParameter.collectOpenCircuitVoltageNUM == g_controlParameter.collectOpenCircuitVoltageTime) {
if (g_otherParameter.batteryState) {
TIM_Cmd(TIM3, DISABLE);
TIM_SetCompare4(TIM4, 0);
g_controlParameter.dutyRatio = 0;
flag = 1;
g_collectOpenCircuitVoltage.count = 500;
}
}
if (flag) {
flag = 0;
g_otherParameter.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
} }
STR_TimeSliceOffset g_configurationModeDelayedExit;
void Task_configurationModeDelayedExit(void)
{
if (120 == ++g_otherParameter.HYconfigModeT) {
g_otherParameter.HYconfigModeState = 0;
g_otherParameter.HYconfigModeT = 0;
TimeSliceOffset_Unregister(&g_configurationModeDelayedExit);
g_configurationModeDelayedExit.runFlag = 0;
}
}

View File

@ -20,7 +20,7 @@ void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM1_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void TIM1_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/* delay_ms Ϊ0.1ms */
void TIM3_Init(uint16_t delay_ms) void TIM3_Init(uint16_t delay_ms)
{ {
/* 分频系数 */ /* 分频系数 */

View File

@ -39,5 +39,7 @@ int main(void)
printf("SystemClk:%d\r\n", SystemCoreClock); printf("SystemClk:%d\r\n", SystemCoreClock);
printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID()); printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID());
// Delay_Ms(10000);
Init(); Init();
} }

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.

Binary file not shown.

Binary file not shown.

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