增加配置文件升级

This commit is contained in:
起床就犯困 2024-10-26 09:07:30 +08:00
parent 20d2cfe02f
commit a83d788afb
33 changed files with 15093 additions and 12483 deletions

View File

@ -11,6 +11,9 @@
#include "debug.h" #include "debug.h"
#include "math.h" #include "math.h"
#define softVer "SV01_24101501"
#pragma pack(push,1) #pragma pack(push,1)
/* 高字节在前,低字节在后 */ /* 高字节在前,低字节在后 */
@ -20,8 +23,8 @@ typedef struct _recv_config_info{
uint8_t address[7]; /* 地址 */ uint8_t address[7]; /* 地址 */
uint8_t Access_Node_Type[2]; /* 接入节点类型 */ uint8_t Access_Node_Type[2]; /* 接入节点类型 */
uint8_t Communication_Methods[2]; /* 通信方式 */ uint8_t Communication_Methods[2]; /* 通信方式 */
uint8_t gw485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */ uint8_t gw485_Baud[4]; /* 串口波特率 */
uint8_t bat485_Baud[4]; /* 串口波特率 */ uint8_t bat485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
/* HY */ /* HY */
uint8_t hardwareID[6]; /* 硬件ID */ uint8_t hardwareID[6]; /* 硬件ID */
@ -108,7 +111,6 @@ typedef struct _config_info{
#define CONFIG_SAVE_ADDR_END (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE) #define CONFIG_SAVE_ADDR_END (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE)
void save_config_info(config_info *save_config_info); void save_config_info(config_info *save_config_info);
void save_backups_config_info(config_info *save_config_info);
void read_config_info(config_info *output_config_info); void read_config_info(config_info *output_config_info);
void checkFlashContent(void); void checkFlashContent(void);
void saveLoopImpedance(float_t *loopImpedance); void saveLoopImpedance(float_t *loopImpedance);
@ -116,5 +118,6 @@ void saveTotalPower(float_t *totalElectricityConsumption, float_t *totalChargCap
void config_info_start(void); void config_info_start(void);
void read_and_process_config_data(void); void read_and_process_config_data(void);
extern uint16_t configCheckFunc(uint8_t *arr_buff, uint8_t len);
#endif /* APP_INC_INFLASH_H_ */ #endif /* APP_INC_INFLASH_H_ */

View File

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

View File

@ -13,10 +13,10 @@
#include "math.h" #include "math.h"
#define buffLen 100 #define buffLen 100
#define configBuffLen 100 #define configBuffLen 300
extern uint8_t rs485_buff[buffLen]; extern uint8_t rs485_buff[buffLen];
extern uint8_t config_buff[configBuffLen]; extern uint8_t config_buff[configBuffLen];
extern uint32_t cfig_len;
/* 功能码 */ /* 功能码 */
typedef enum typedef enum
@ -189,12 +189,10 @@ typedef struct _SL_Mppt_SOther_pack{
/* */ /* */
#define RECV_LENGTH 20
typedef struct _SL_Mppt_Recv_pack{ typedef struct _SL_Mppt_Recv_pack{
uint8_t start_Flag[2]; /* 起始标志 */ uint8_t start_Flag[2]; /* 起始标志 */
uint8_t address[7]; /* 地址 */ uint8_t address[7]; /* 地址 */
uint8_t function_Code; /* 功能码 */ uint8_t function_Code; /* 功能码 */
uint8_t recv_Data[RECV_LENGTH]; /* 其他部分 */
}SL_Mppt_Recv_pack; }SL_Mppt_Recv_pack;
/* 功能码处理函数 */ /* 功能码处理函数 */

View File

@ -17,7 +17,7 @@ void Init();
/* 控制运行指示灯和喂狗 */ /* 控制运行指示灯和喂狗 */
#define WdiRunled_reloadVal 1000 /* 任务执行间隔 */ #define WdiRunled_reloadVal 1000 /* 任务执行间隔 */
#define WdiRunled_offset 0 /* 任务执行偏移量 */ #define WdiRunled_offset 700 /* 任务执行偏移量 */
#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);
@ -54,22 +54,27 @@ extern void Task_softStart(void);
/* 启动任务 */ /* 启动任务 */
#define startMpptControl_reloadVal 1000 /* 任务执行间隔 */ #define startMpptControl_reloadVal 1000 /* 任务执行间隔 */
#define startMpptControl_offset 0 /* 任务执行偏移量 */ #define startMpptControl_offset 200 /* 任务执行偏移量 */
extern STR_TimeSliceOffset g_startMpptControl; extern STR_TimeSliceOffset g_startMpptControl;
extern void Task_startMpptControl(void); extern void Task_startMpptControl(void);
/* 根据寄存器数据完成一些判断 */ /* 根据寄存器数据完成一些判断 */
#define dataJudgment_reloadVal 1000 /* 任务执行间隔 */ #define dataJudgment_reloadVal 1000 /* 任务执行间隔 */
#define dataJudgment_offset 0 /* 任务执行偏移量 */ #define dataJudgment_offset 500 /* 任务执行偏移量 */
extern STR_TimeSliceOffset g_dataJudgment; extern STR_TimeSliceOffset g_dataJudgment;
extern void Task_dataJudgment(void); extern void Task_dataJudgment(void);
/* 串口数据解析和处理 */ /* 串口数据解析和处理 */
#define usartSL_reloadVal 100 /* 任务执行间隔 */ #define usartJudge_reloadVal 100 /* 任务执行间隔 */
#define usartSL_offset 0 /* 任务执行偏移量 */ #define usartJudge_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_usart; extern STR_TimeSliceOffset m_usartJudge;
extern void Task_usartSL(void); extern void Task_usartJudge(void);
extern void Task_usartHY(void); #define usartHandle_reloadVal 20 /* 任务执行间隔 */
#define usartHandle_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_usartHandle;
extern void Task_usartHandle(void);
typedef void (*uartJudgeHandle)(device_handle device);
extern uartJudgeHandle uart_judge_handle;
/* 广播回应 */ /* 广播回应 */
#define recvbroadcast_reloadVal 3000 /* 任务执行间隔 */ #define recvbroadcast_reloadVal 3000 /* 任务执行间隔 */
@ -85,5 +90,16 @@ extern void Task_recvbroadcast(void);
extern STR_TimeSliceOffset g_sensorEnableBroadcast; extern STR_TimeSliceOffset g_sensorEnableBroadcast;
extern void Task_sensorEnableBroadcast(void); extern void Task_sensorEnableBroadcast(void);
/* 配置文件读取 */
#define uartConfigFile_reloadVal 200 /* 任务执行间隔 */
#define uartConfigFile_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_uartConfigFile;
extern void Task_uartConfigFile(void);
/* 过载保护 */
#define overloadDelay_reloadVal 10 /* 任务执行间隔 */
#define overloadDelay_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset g_overloadDelay;
extern void Task_overloadDelay(void);
#endif /* APP_INC_TASK_H_ */ #endif /* APP_INC_TASK_H_ */

View File

@ -128,16 +128,17 @@ void adcChangeProportionalInit(void)
{ {
if (g_otherParameter.onlyPower) { if (g_otherParameter.onlyPower) {
/* 光伏充电输出电流比例,放大倍数*电阻 */ /* 光伏充电输出电流比例,放大倍数*电阻 */
P_CHG_CURR = (1.0 / (50 * 0.005 / 2)); // P_CHG_CURR = (1.0 / (50 * 0.005 / 2));
P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.005 * 3))));
/* 光伏充电输出电压比例,分压系数(放电时采集不准) */ /* 光伏充电输出电压比例,分压系数(放电时采集不准) */
//const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0; //const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0;
//const float P_PV_VOLT_OUT = (47.0 + 4.7) / 4.7; //const float P_PV_VOLT_OUT = (47.0 + 4.7) / 4.7;
P_PV_VOLT_OUT = (56.0 + 10.0) / 10.0; P_PV_VOLT_OUT = (56.0 + 10.0) / 10.0;
/* 放电电流采集电流倍数 */ /* 放电电流采集电流倍数 */
P_DSG_CURR = (1.0 / (50 * 0.005 / 2)); P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.005 * 5))));
///* 光伏1开路输出电压比例 */ ///* 光伏1开路输出电压比例 */
P_PV1_VOLT_IN = (100 + 4.7) / 4.7; // P_PV1_VOLT_IN = (100 + 4.7) / 4.7;
//const float P_PV1_VOLT_IN = (47.0 + 4.7) / 4.7; P_PV1_VOLT_IN = (47.0 + 4.7) / 4.7;
/* 光伏1开路输出电压比例 */ /* 光伏1开路输出电压比例 */
//const float P_PV1_VOLT_IN = (47 + 4.7) / 4.7; //const float P_PV1_VOLT_IN = (47 + 4.7) / 4.7;
/* 系统电源电压比例 */ /* 系统电源电压比例 */

View File

@ -237,10 +237,12 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
c = uart_dev_in_char(uart_handle); c = uart_dev_in_char(uart_handle);
buff[offset++] = c; buff[offset++] = c;
config_buff[cfig_len++] = c;
/* 匹配起始标志位 */ /* 匹配起始标志位 */
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");
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
@ -258,6 +260,7 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
} }
else { else {
log_info("Match_hardwordID error");
hardwordIDType = 0x00; hardwordIDType = 0x00;
if (flag_run < 1) { if (flag_run < 1) {
flag_run = 1; flag_run = 1;
@ -274,6 +277,7 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
if (flag_run < 2) { if (flag_run < 2) {
flag_run = 2; flag_run = 2;
} }
log_info("Match_CommunicationID error");
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
@ -352,18 +356,22 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
if (flag_run < 3) { if (flag_run < 3) {
flag_run = 3; flag_run = 3;
} }
log_info("Match_controlWord error");
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
} }
} }
/* 匹配通信ID */ /* Æ¥ÅäÊý¾Ý³¤¶È */
if (offset == HY_analyzeDataLen || (flag_run > 4)) { if (offset == HY_analyzeDataLen || (flag_run > 4)) {
if (len != ((pack->dataLen[0] << 8 + pack->dataLen[1]) + 16)) { if (len != ((pack->dataLen[0] << 8 | pack->dataLen[1]) + 16)) {
if (flag_run < 4) { if (flag_run < 4) {
flag_run = 4; flag_run = 4;
} }
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); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
@ -376,10 +384,13 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
if (flag_run < 5) { if (flag_run < 5) {
flag_run = 5; flag_run = 5;
} }
log_info("check: %x, %x", (HY_CheckFunc(buff, len - 2) & 0xff), buff[len - 2]);
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
} }
memset(config_buff, 0, sizeof(config_buff));
cfig_len = 0;
return len; return len;
} }
} }
@ -410,15 +421,19 @@ static void HY_FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgL
*/ */
void HY_read_and_process_uart_data(device_handle device) void HY_read_and_process_uart_data(device_handle device)
{ {
// if (uart_dev_char_present(device)) {
if (uart_dev_char_present(device)) { // Delay_Ms(20);
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)); memset(rs485_buff, 0, sizeof(rs485_buff));
int ret = HY_uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff)); int ret = HY_uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
if(ret > 0){ if(ret > 0){
HY_FRT_MsgHandler(device, rs485_buff, ret); HY_FRT_MsgHandler(device, rs485_buff, ret);
} }
}
} }
/* 电池状态数据报 */ /* 电池状态数据报 */
@ -548,6 +563,17 @@ void HY_MsgProcFunc_sensorNumberConfiguration(device_handle device, void *pMsg,
g_otherParameter.communicationID[1] = Tpack->newCommunicationID[1]; g_otherParameter.communicationID[1] = Tpack->newCommunicationID[1];
g_otherParameter.communicationID[2] = Tpack->newCommunicationID[2]; g_otherParameter.communicationID[2] = Tpack->newCommunicationID[2];
g_otherParameter.communicationID[3] = Tpack->newCommunicationID[3]; 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_success; pack.state = HY_success;
} }
else { else {
@ -711,6 +737,9 @@ void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, uint32_t
break; break;
} }
} }
/* ¸´Î» */
NVIC_SystemReset();
} }

View File

@ -16,7 +16,7 @@
* @param * @param
* @retval * @retval
*/ */
static uint16_t configCheckFunc(uint8_t *arr_buff, uint8_t len) uint16_t configCheckFunc(uint8_t *arr_buff, uint8_t len)
{ {
uint16_t crc = 0xFFFF; uint16_t crc = 0xFFFF;
uint16_t i, j; uint16_t i, j;
@ -50,7 +50,7 @@ void save_config_info(config_info *save_config_info)
* @param save_config_info ÐèÒª±£´æµÄÅäÖÃÐÅÏ¢ * @param save_config_info ÐèÒª±£´æµÄÅäÖÃÐÅÏ¢
* @retval * @retval
*/ */
void save_backups_config_info(config_info *save_config_info) static void save_backups_config_info(config_info *save_config_info)
{ {
SPI_Flash_Write((uint8_t *)save_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE); SPI_Flash_Write((uint8_t *)save_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE);
} }
@ -61,7 +61,7 @@ void save_backups_config_info(config_info *save_config_info)
*/ */
void read_config_info(config_info *output_config_info) void read_config_info(config_info *output_config_info)
{ {
SPI_Flash_Read((uint8_t *)&output_config_info, CONFIG_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE); SPI_Flash_Read((uint8_t *)output_config_info, CONFIG_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
} }
/** /**
@ -70,7 +70,7 @@ void read_config_info(config_info *output_config_info)
*/ */
static void read_backups_config_info(config_info *output_config_info) static void read_backups_config_info(config_info *output_config_info)
{ {
SPI_Flash_Read((uint8_t *)&output_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE); SPI_Flash_Read((uint8_t *)output_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE);
} }
/** /**
@ -84,12 +84,16 @@ void checkFlashContent(void)
config_info temp_configInfo; config_info temp_configInfo;
read_config_info(&temp_configInfo); read_config_info(&temp_configInfo);
// printf("crc : %x %x\n", temp_configInfo.crc, configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2));
if (temp_configInfo.crc == configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2)) { if (temp_configInfo.crc == configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2)) {
// printf("config\n");
return; return;
} }
read_backups_config_info(&temp_configInfo); read_backups_config_info(&temp_configInfo);
if (temp_configInfo.crc == configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2)) { if (temp_configInfo.crc == configCheckFunc((uint8_t *)&temp_configInfo, CONFIG_INFO_SIZE - 2)) {
// printf("backups config\n");
save_config_info(&temp_configInfo); save_config_info(&temp_configInfo);
return; return;
} }
@ -98,7 +102,7 @@ void checkFlashContent(void)
.address = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, .address = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
.Access_Node_Type = 0x01, .Access_Node_Type = 0x01,
.Communication_Methods = 0x02, .Communication_Methods = 0x02,
.gw485_Baud = 115200, .gw485_Baud = 9600,
.bat485_Baud = 115200, .bat485_Baud = 115200,
.hardwareID = {0x48, 0x59, 0x30, 0x30, 0x30, 0x31}, .hardwareID = {0x48, 0x59, 0x30, 0x30, 0x30, 0x31},
@ -108,12 +112,12 @@ void checkFlashContent(void)
.CommunicationProtocolType = 0x00, .CommunicationProtocolType = 0x00,
.onlyPower = 0x01, .onlyPower = 0x01,
.constantVoltageV = 14.2, .constantVoltageV = 14,
.floatI = 0.02, .floatI = 0.02,
.startSolarOpenCircuitV = 17, .startSolarOpenCircuitV = 17,
.stopSolarOpenCircuitV = 15, .stopSolarOpenCircuitV = 15,
.constantVoltageChargeV = 14.4, .constantVoltageChargeV = 14.4,
.FloatChargeV = 14.2, .FloatChargeV = 14,
.HighSideMosTemperature_stop = 100, .HighSideMosTemperature_stop = 100,
.HighSideMosTemperature_end = 90, .HighSideMosTemperature_end = 90,
.HighSideMosTemperature_start = 50, .HighSideMosTemperature_start = 50,
@ -187,7 +191,7 @@ void config_info_start(void)
g_controlParameter.floatI = temp_configInfo.floatI; g_controlParameter.floatI = temp_configInfo.floatI;
g_controlParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV; g_controlParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV;
g_controlParameter.stopSolarOpenCircuitV = temp_configInfo.stopSolarOpenCircuitV; g_controlParameter.stopSolarOpenCircuitV = temp_configInfo.stopSolarOpenCircuitV;
g_controlParameter.stopSolarOpenCircuitV = temp_configInfo.constantVoltageChargeV; g_controlParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
g_controlParameter.FloatV = temp_configInfo.FloatChargeV; g_controlParameter.FloatV = temp_configInfo.FloatChargeV;
g_controlParameter.loopImpedance = temp_configInfo.loopImpedance; g_controlParameter.loopImpedance = temp_configInfo.loopImpedance;
g_controlParameter.HighSideMosTemperature_stop = temp_configInfo.HighSideMosTemperature_stop; g_controlParameter.HighSideMosTemperature_stop = temp_configInfo.HighSideMosTemperature_stop;
@ -199,12 +203,34 @@ void config_info_start(void)
g_controlParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime; g_controlParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime;
g_controlParameter.eLAgainTime = temp_configInfo.eLAgainTime; g_controlParameter.eLAgainTime = temp_configInfo.eLAgainTime;
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[1] = temp_configInfo.address[1];
g_otherParameter.address[2] = temp_configInfo.address[2];
g_otherParameter.address[3] = temp_configInfo.address[3];
g_otherParameter.address[4] = temp_configInfo.address[4];
g_otherParameter.address[5] = temp_configInfo.address[5];
g_otherParameter.address[6] = temp_configInfo.address[6];
// printf("address : 0x %x %x %x %x %x %x %x\n", temp_configInfo.address[0]
// , temp_configInfo.address[1], temp_configInfo.address[2], temp_configInfo.address[3]
// , temp_configInfo.address[4], temp_configInfo.address[5], temp_configInfo.address[6]);
g_otherParameter.Access_Node_Type = temp_configInfo.Access_Node_Type; g_otherParameter.Access_Node_Type = temp_configInfo.Access_Node_Type;
g_otherParameter.Communication_Methods = temp_configInfo.Communication_Methods; g_otherParameter.Communication_Methods = temp_configInfo.Communication_Methods;
strlcpy(g_otherParameter.hardwareID, temp_configInfo.hardwareID, 6); // strlcpy(g_otherParameter.hardwareID, temp_configInfo.hardwareID, 6);
strlcpy(g_otherParameter.communicationID, temp_configInfo.communicationID, 4); g_otherParameter.hardwareID[0] = temp_configInfo.hardwareID[0];
g_otherParameter.hardwareID[1] = temp_configInfo.hardwareID[1];
g_otherParameter.hardwareID[2] = temp_configInfo.hardwareID[2];
g_otherParameter.hardwareID[3] = temp_configInfo.hardwareID[3];
g_otherParameter.hardwareID[4] = temp_configInfo.hardwareID[4];
g_otherParameter.hardwareID[5] = temp_configInfo.hardwareID[5];
// strlcpy(g_otherParameter.communicationID, temp_configInfo.communicationID, 4);
g_otherParameter.communicationID[0] = temp_configInfo.communicationID[0];
g_otherParameter.communicationID[1] = temp_configInfo.communicationID[1];
g_otherParameter.communicationID[2] = temp_configInfo.communicationID[2];
g_otherParameter.communicationID[3] = temp_configInfo.communicationID[3];
g_otherParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType; g_otherParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType;
// g_otherParameter.CommunicationProtocolType = 0x01;
g_otherParameter.onlyPower = temp_configInfo.onlyPower;
g_otherParameter.Battery_Voltage = 0; g_otherParameter.Battery_Voltage = 0;
g_otherParameter.Output_Voltage = 0; g_otherParameter.Output_Voltage = 0;
g_otherParameter.Charg_Current = 0; g_otherParameter.Charg_Current = 0;
@ -220,9 +246,14 @@ void config_info_start(void)
g_otherParameter.chargMos_State = 0; g_otherParameter.chargMos_State = 0;
g_otherParameter.DischargMos_State = 0; g_otherParameter.DischargMos_State = 0;
g_otherParameter.MPPT_Mode = 0; g_otherParameter.MPPT_Mode = 0;
strlcpy(g_otherParameter.versionInformation, "SV01_24101501", 13); strlcpy(g_otherParameter.versionInformation, softVer, 13);
// strlcpy(g_otherParameter.startFlagSL, "SL", 2);
// printf("%s", g_otherParameter.startFlagSL);
g_otherParameter.startFlagSL[0] = 'S';
g_otherParameter.startFlagSL[1] = 'L';
strlcpy(g_otherParameter.startFlagSL, "SL", 2);
g_otherParameter.endFlagSL = 0x16; g_otherParameter.endFlagSL = 0x16;
g_otherParameter.startFlagHY = 0x68; g_otherParameter.startFlagHY = 0x68;
g_otherParameter.endFlagHY = 0x16; g_otherParameter.endFlagHY = 0x16;
@ -246,6 +277,42 @@ void config_info_start(void)
g_otherParameter.gw485_Baud = 115200; g_otherParameter.gw485_Baud = 115200;
} }
} }
// printf("");
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[4], g_otherParameter.address[5], g_otherParameter.address[6]);
printf("Access_Node_Type : 0x%x\n", g_otherParameter.Access_Node_Type);
printf("Communication_Methods : 0x%x\n", g_otherParameter.Communication_Methods);
printf("gw485_Baud : %d\n", g_otherParameter.gw485_Baud);
printf("bat485_Baud : %d\n", g_otherParameter.bat485_Baud);
printf("hardwareID : 0x %x %x %x %x %x %x\n", g_otherParameter.hardwareID[0]
, g_otherParameter.hardwareID[1], g_otherParameter.hardwareID[2], g_otherParameter.hardwareID[3]
, g_otherParameter.hardwareID[4], g_otherParameter.hardwareID[5]);
printf("communicationID : 0x %x %x %x %x\n", g_otherParameter.communicationID[0], g_otherParameter.communicationID[1]
, g_otherParameter.communicationID[2], g_otherParameter.communicationID[3]);
printf("Communication_Methods : 0x%x\n", g_otherParameter.CommunicationProtocolType);
printf("onlyPower : 0x%x\n", g_otherParameter.onlyPower);
printf("constantVoltageV : %d/100\n", (int)(g_controlParameter.constantVoltageV * 100));
printf("floatI : %d/100\n", (int)(g_controlParameter.floatI * 100));
printf("startSolarOpenCircuitV : %d/100\n", (int)(g_controlParameter.startSolarOpenCircuitV * 100));
printf("stopSolarOpenCircuitV : %d/100\n", (int)(g_controlParameter.stopSolarOpenCircuitV * 100));
printf("constantVoltageChargeV : %d/100\n", (int)(g_controlParameter.constantVoltageChargeV * 100));
printf("FloatV : %d/100\n", (int)(g_controlParameter.FloatV * 100));
printf("loopImpedance : %d/100\n", (int)(g_controlParameter.loopImpedance * 100));
printf("HighSideMosTemperature_stop : %d/100\n", (int)(g_controlParameter.HighSideMosTemperature_stop * 100));
printf("HighSideMosTemperature_end : %d/100\n", (int)(g_controlParameter.HighSideMosTemperature_end * 100));
printf("HighSideMosTemperature_start : %d/100\n", (int)(g_controlParameter.HighSideMosTemperature_start * 100));
printf("totalChargCapacity : %d/10000\n", (int)(g_otherParameter.totalChargCapacity * 10000));
printf("totalElectricityConsumption : %d/10000\n", (int)(g_otherParameter.totalElectricityConsumption * 10000));
printf("checkSolarOpenCircuitVTime : %d\n", g_controlParameter.checkSolarOpenCircuitVTime);
printf("sensorEnableBroadcastTime : %d\n", g_controlParameter.sensorEnableBroadcastTime);
printf("outputAgainFlagTime : %d\n", g_controlParameter.outputAgainFlagTime);
printf("excessiveLoadFlagTime : %d\n", g_controlParameter.excessiveLoadFlagTime);
printf("eLAgainTime : %d\n", g_controlParameter.eLAgainTime);
} }
/** /**
@ -254,16 +321,24 @@ void config_info_start(void)
* @retval * @retval
* *
*/ */
#define enlargeScale 100
void read_and_process_config_data(void) void read_and_process_config_data(void)
{ {
while (strlen(config_buff) > RECV_CONFIG_INFO) {
recv_config_info *pack = (recv_config_info *)config_buff; recv_config_info *pack = (recv_config_info *)config_buff;
config_info save_configInfo;
// uint32_t len = strlen(config_buff);
// char buffer[80];
// printf("%d %d\n", cfig_len, RECV_CONFIG_INFO);
while (cfig_len >= RECV_CONFIG_INFO) {
// printf("1\n");
/* 判断起始标志是否正确 */
if (pack->start_Flag[0] != g_otherParameter.startFlagSL[0] if (pack->start_Flag[0] != g_otherParameter.startFlagSL[0]
|| pack->start_Flag[1] != g_otherParameter.startFlagSL[1]) { || pack->start_Flag[1] != g_otherParameter.startFlagSL[1]) {
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); goto err;
continue;
} }
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
// if (pack->address[0] != g_otherParameter.address[0] // if (pack->address[0] != g_otherParameter.address[0]
// || pack->address[1] != g_otherParameter.address[1] // || pack->address[1] != g_otherParameter.address[1]
@ -275,66 +350,391 @@ void read_and_process_config_data(void)
// memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); // memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1);
// continue; // continue;
// } // }
uint16_t temp_u16;
temp_u16 = (uint16_t)pack->Access_Node_Type[0] << 8 /* 判断接入节点类型是否正确 */
save_configInfo.Access_Node_Type = (uint16_t)pack->Access_Node_Type[0] << 8
| (uint16_t)pack->Access_Node_Type[1]; | (uint16_t)pack->Access_Node_Type[1];
// if (temp_u16 != POWERBOX || temp_u16 != MICROMETEOROLOGY) { // memset(buffer, 0, sizeof(buffer));
if (temp_u16 != POWERBOX) { // sprintf(buffer, " Access_Node_Type : 0x%x \n", save_configInfo.Access_Node_Type);
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); // uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
continue; if (save_configInfo.Access_Node_Type != POWERBOX) {
goto err;
} }
temp_u16 = (uint16_t)pack->Communication_Methods[0] << 8 /* 判断通信方式是否正确 */
save_configInfo.Communication_Methods = (uint16_t)pack->Communication_Methods[0] << 8
| (uint16_t)pack->Communication_Methods[1]; | (uint16_t)pack->Communication_Methods[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " Communication_Methods : 0x%x \n", save_configInfo.Communication_Methods);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
// if (temp_u16 != RS485 || temp_u16 != RJ45) { // if (temp_u16 != RS485 || temp_u16 != RJ45) {
if (temp_u16 != RS485) { if (save_configInfo.Communication_Methods != RS485) {
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); goto err;
continue;
} }
uint32_t temp_u32; /* 判断波特率是否正确 */
temp_u32 = (uint32_t)pack->gw485_Baud[0] << 24 save_configInfo.gw485_Baud = (uint32_t)pack->gw485_Baud[0] << 24
| (uint32_t)pack->gw485_Baud[1] << 16 | (uint32_t)pack->gw485_Baud[1] << 16
| (uint32_t)pack->gw485_Baud[2] << 8 | (uint32_t)pack->gw485_Baud[2] << 8
| (uint32_t)pack->gw485_Baud[3]; | (uint32_t)pack->gw485_Baud[3];
if (temp_u32 != 9600 || temp_u32!= 115200) { // memset(buffer, 0, sizeof(buffer));
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); // sprintf(buffer, " gw485_Baud : 0x%x, %d \n", save_configInfo.gw485_Baud, save_configInfo.gw485_Baud);
continue; // uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.gw485_Baud != 9600 && save_configInfo.gw485_Baud != 115200) {
// if (save_configInfo.gw485_Baud != 0x2580 || save_configInfo.gw485_Baud != 115200) {
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " error : %d\n", save_configInfo.gw485_Baud);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
goto err;
} }
temp_u32 = (uint32_t)pack->bat485_Baud[0] << 24 save_configInfo.bat485_Baud = (uint32_t)pack->bat485_Baud[0] << 24
| (uint32_t)pack->bat485_Baud[1] << 16 | (uint32_t)pack->bat485_Baud[1] << 16
| (uint32_t)pack->bat485_Baud[2] << 8 | (uint32_t)pack->bat485_Baud[2] << 8
| (uint32_t)pack->bat485_Baud[3]; | (uint32_t)pack->bat485_Baud[3];
if (temp_u32 != 9600 || temp_u32!= 115200 || temp_u32!= 0) { // memset(buffer, 0, sizeof(buffer));
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); // sprintf(buffer, " bat485_Baud : 0x%x, %d \n", save_configInfo.bat485_Baud, save_configInfo.bat485_Baud);
continue; // uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.bat485_Baud != 9600 && save_configInfo.bat485_Baud!= 115200 && save_configInfo.bat485_Baud!= 0) {
goto err;
} }
if (pack->protocolType != 0x01 || pack->protocolType != 0x02) { /* 判断协议类型是否正确 */
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); if (pack->protocolType != 0x01 && pack->protocolType != 0x02) {
continue; goto err;
}
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " protocolType : 0x%x \n", pack->protocolType);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
/* 判断通信协议类型是否正确 */
if (pack->CommunicationProtocolType != 0x00 && pack->CommunicationProtocolType != 0x01) {
goto err;
}
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " CommunicationProtocolType : 0x%x \n", pack->CommunicationProtocolType);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
/* 判断电源盒类型是否正确 */
if (pack->onlyPower != 0x00 && pack->onlyPower != 0x01) {
goto err;
}
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " onlyPower : 0x%x \n", pack->onlyPower);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
/* 判断恒压充电阈值是否正确 */
save_configInfo.constantVoltageV =
(float_t)(pack->ConstantVoltageV[0] << 8 | pack->ConstantVoltageV[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " constantVoltageV : %d/100 \n", (int)(save_configInfo.constantVoltageV * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.constantVoltageV > 14.4 || save_configInfo.constantVoltageV < 13.5) {
goto err;
} }
if (pack->CommunicationProtocolType != 0x00 || pack->CommunicationProtocolType != 0x01) { /* 判断浮充充电阈值是否正确 */
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); save_configInfo.floatI = (float_t)(pack->FloatI[0] << 8 | pack->FloatI[1]) / enlargeScale;
continue; // memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " floatI : %d/100 \n", (int)(save_configInfo.floatI * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.floatI > 0.2 || save_configInfo.floatI < 0) {
goto err;
} }
if (pack->onlyPower != 0x00 || pack->onlyPower != 0x01) { /* 判断太阳能板开路启动电压是否正确 */
memcpy(config_buff, config_buff + 1, RECV_CONFIG_INFO - 1); save_configInfo.startSolarOpenCircuitV =
continue; (float_t)(pack->startSolarOpenCircuitV[0] << 8 | pack->startSolarOpenCircuitV[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " startSolarOpenCircuitV : %d/100 \n", (int)(save_configInfo.startSolarOpenCircuitV * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.startSolarOpenCircuitV > 24 || save_configInfo.startSolarOpenCircuitV < 14) {
goto err;
} }
float_t temp_float; /* 判断太阳能板关闭电压是否正确 */
save_configInfo.stopSolarOpenCircuitV =
(float_t)(pack->stopSolarOpenCircuitV[0] << 8 | pack->stopSolarOpenCircuitV[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " stopSolarOpenCircuitV : %d/100 \n", (int)(save_configInfo.stopSolarOpenCircuitV * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.stopSolarOpenCircuitV > 17 || save_configInfo.stopSolarOpenCircuitV < 13) {
goto err;
}
/* 判断恒压充电时的输出电压是否正确 */
save_configInfo.constantVoltageChargeV =
(float_t)(pack->constantVoltageChargeV[0] << 8 | pack->constantVoltageChargeV[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " constantVoltageChargeV : %d/100 \n", (int)(save_configInfo.constantVoltageChargeV * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.constantVoltageChargeV > 14.6 || save_configInfo.constantVoltageChargeV < 14) {
goto err;
}
/* 判断浮充充电时的输出电压是否正确 */
save_configInfo.FloatChargeV =
(float_t)(pack->FloatChargeV[0] << 8 | pack->FloatChargeV[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " FloatChargeV : %d/100 \n", (int)(save_configInfo.FloatChargeV * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.FloatChargeV > 14.4 || save_configInfo.FloatChargeV < 13.8) {
goto err;
}
/* 判断mos管停止工作温度是否正确 */
save_configInfo.HighSideMosTemperature_stop =
(float_t)(pack->HighSideMosTemperature_stop[0] << 8 | pack->HighSideMosTemperature_stop[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " HighSideMosTemperature_stop : %d/100 \n", (int)(save_configInfo.HighSideMosTemperature_stop * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.HighSideMosTemperature_stop < 60) {
goto err;
}
/* 判断mos管降低工作功率工作温度是否正确 */
save_configInfo.HighSideMosTemperature_end =
(float_t)(pack->HighSideMosTemperature_end[0] << 8 | pack->HighSideMosTemperature_end[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " HighSideMosTemperature_end : %d/100 \n", (int)(save_configInfo.HighSideMosTemperature_end * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.HighSideMosTemperature_end < 50) {
goto err;
}
/* 判断mos管完全恢复工作温度是否正确 */
save_configInfo.HighSideMosTemperature_start =
(float_t)(pack->HighSideMosTemperature_start[0] << 8 | pack->HighSideMosTemperature_start[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " HighSideMosTemperature_start : %d/100 \n", (int)(save_configInfo.HighSideMosTemperature_start * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.HighSideMosTemperature_start < 40) {
goto err;
}
/* 判断回路阻抗大小是否正确 */
save_configInfo.loopImpedance =
(float_t)(pack->loopImpedance[0] << 8 | pack->loopImpedance[1]) / enlargeScale / 10;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " loopImpedance : %d/100 \n", (int)(save_configInfo.loopImpedance * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.loopImpedance > 1 || save_configInfo.loopImpedance < 0) {
goto err;
}
/* 判断总电量消耗是否正确 */
save_configInfo.totalElectricityConsumption =
(float_t)(pack->totalElectricityConsumption[0] << 8 | pack->totalElectricityConsumption[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " totalElectricityConsumption : %d/100 \n", (int)(save_configInfo.totalElectricityConsumption * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.totalElectricityConsumption != 0) {
goto err;
}
/* 判断总充电电量是否正确 */
save_configInfo.totalChargCapacity =
(float_t)(pack->totalChargCapacity[0] << 8 | pack->totalChargCapacity[1]) / enlargeScale;
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " totalChargCapacity : %d/100 \n", (int)(save_configInfo.totalChargCapacity * 100));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.totalChargCapacity != 0) {
goto err;
}
/* 判断启动任务中太阳能板开路电压检测间隔时间是否正确 */
save_configInfo.checkSolarOpenCircuitVTime =
pack->checkSolarOpenCircuitVTime[0] << 8 | pack->checkSolarOpenCircuitVTime[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " checkSolarOpenCircuitVTime : %d \n", save_configInfo.checkSolarOpenCircuitVTime);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.checkSolarOpenCircuitVTime > 1800 || save_configInfo.checkSolarOpenCircuitVTime < 5) {
goto err;
}
/* 判断传感器运行再次注册的间隔是否正确 */
save_configInfo.sensorEnableBroadcastTime =
pack->sensorEnableBroadcastTime[0] << 8 | pack->sensorEnableBroadcastTime[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " sensorEnableBroadcastTime : %d \n", save_configInfo.sensorEnableBroadcastTime);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.sensorEnableBroadcastTime > 60 || save_configInfo.sensorEnableBroadcastTime < 10) {
goto err;
}
/* 判断出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出的间隔是否正确 */
save_configInfo.outputAgainFlagTime =
pack->outputAgainFlagTime[0] << 8 | pack->outputAgainFlagTime[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " outputAgainFlagTime : %d \n", save_configInfo.outputAgainFlagTime);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.sensorEnableBroadcastTime > 30 || save_configInfo.sensorEnableBroadcastTime < 5) {
goto err;
}
/* 判断出现过载后在该间隔时间中多次2次出现过载则关闭输出的间隔是否正确 */
save_configInfo.excessiveLoadFlagTime =
pack->excessiveLoadFlagTime[0] << 8 | pack->excessiveLoadFlagTime[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " excessiveLoadFlagTime : %d \n", save_configInfo.excessiveLoadFlagTime);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.excessiveLoadFlagTime > 90 || save_configInfo.excessiveLoadFlagTime < 30) {
goto err;
}
/* 判断出现过载过载保护后,在该间隔段时间后,再次尝试输出的间隔是否正确 */
save_configInfo.eLAgainTime = pack->eLAgainTime[0] << 8 | pack->eLAgainTime[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " eLAgainTime : %d \n", save_configInfo.eLAgainTime);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.eLAgainTime > 3000 || save_configInfo.eLAgainTime < 1000) {
goto err;
}
/* crc校验 */
save_configInfo.crc = pack->crc[0] << 8 | pack->crc[1];
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " crc : %x%x \n", pack->crc[0], pack->crc[1]);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (save_configInfo.crc != CheckFuncSL(config_buff, RECV_CONFIG_INFO - 3)) {
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " CheckFuncSL : %x \n", CheckFuncSL(config_buff, RECV_CONFIG_INFO));
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
goto err;
}
/* 结束标志 */
// memset(buffer, 0, sizeof(buffer));
// sprintf(buffer, " end_Flag : %x \n", pack->end_Flag);
// uart_dev_write(g_gw485_uart4_handle, buffer, sizeof(buffer));
if (pack->end_Flag != 0x16) {
goto err;
}
// printf("address : 0x %x %x %x %x %x %x %x\n", pack->address[0]
// , pack->address[1], pack->address[2], pack->address[3]
// , pack->address[4], pack->address[5], pack->address[6]);
config_info temp_configInfo;
read_config_info(&temp_configInfo);
if (pack->address[0] != 0xFF
|| pack->address[1] != 0xFF
|| pack->address[2] != 0xFF
|| pack->address[3] != 0xFF
|| pack->address[4] != 0xFF
|| pack->address[5] != 0xFF
|| pack->address[6] != 0xFF) {
save_configInfo.address[0] = pack->address[0];
save_configInfo.address[1] = pack->address[1];
save_configInfo.address[2] = pack->address[2];
save_configInfo.address[3] = pack->address[3];
save_configInfo.address[4] = pack->address[4];
save_configInfo.address[5] = pack->address[5];
save_configInfo.address[6] = pack->address[6];
// printf("address : 0x %x %x %x %x %x %x %x\n", save_configInfo.address[0]
// , save_configInfo.address[1], save_configInfo.address[2], save_configInfo.address[3]
// , save_configInfo.address[4], save_configInfo.address[5], save_configInfo.address[6]);
} else {
save_configInfo.address[0] = temp_configInfo.address[0];
save_configInfo.address[1] = temp_configInfo.address[1];
save_configInfo.address[2] = temp_configInfo.address[2];
save_configInfo.address[3] = temp_configInfo.address[3];
save_configInfo.address[4] = temp_configInfo.address[4];
save_configInfo.address[5] = temp_configInfo.address[5];
save_configInfo.address[6] = temp_configInfo.address[6];
}
if (pack->hardwareID[0] != 0xFF
|| pack->hardwareID[1] != 0xFF
|| pack->hardwareID[2] != 0xFF
|| pack->hardwareID[3] != 0xFF
|| pack->hardwareID[4] != 0xFF
|| pack->hardwareID[5] != 0xFF) {
save_configInfo.hardwareID[0] = pack->hardwareID[0];
save_configInfo.hardwareID[1] = pack->hardwareID[1];
save_configInfo.hardwareID[2] = pack->hardwareID[2];
save_configInfo.hardwareID[3] = pack->hardwareID[3];
save_configInfo.hardwareID[4] = pack->hardwareID[4];
save_configInfo.hardwareID[5] = pack->hardwareID[5];
} else {
save_configInfo.hardwareID[0] = temp_configInfo.hardwareID[0];
save_configInfo.hardwareID[1] = temp_configInfo.hardwareID[1];
save_configInfo.hardwareID[2] = temp_configInfo.hardwareID[2];
save_configInfo.hardwareID[3] = temp_configInfo.hardwareID[3];
save_configInfo.hardwareID[4] = temp_configInfo.hardwareID[4];
save_configInfo.hardwareID[5] = temp_configInfo.hardwareID[5];
}
if (pack->communicationID[0] != 0xFF
|| pack->communicationID[1] != 0xFF
|| pack->communicationID[2] != 0xFF
|| pack->communicationID[3] != 0xFF) {
save_configInfo.communicationID[0] = pack->communicationID[0];
save_configInfo.communicationID[1] = pack->communicationID[1];
save_configInfo.communicationID[2] = pack->communicationID[2];
save_configInfo.communicationID[3] = pack->communicationID[3];
} else {
save_configInfo.communicationID[0] = temp_configInfo.communicationID[0];
save_configInfo.communicationID[1] = temp_configInfo.communicationID[1];
save_configInfo.communicationID[2] = temp_configInfo.communicationID[2];
save_configInfo.communicationID[3] = temp_configInfo.communicationID[3];
}
save_configInfo.protocolType = pack->protocolType;
save_configInfo.CommunicationProtocolType = pack->CommunicationProtocolType;
save_configInfo.onlyPower = pack->onlyPower;
save_configInfo.crc = configCheckFunc((uint8_t *)&save_configInfo, CONFIG_INFO_SIZE - 2);
save_backups_config_info(&save_configInfo);
save_config_info(&save_configInfo);
memset(config_buff, 0, sizeof(config_buff));
/* 返回更改配置文件成功 */
SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
SUpdateProfile_pack.start_Flag[0] = g_otherParameter.startFlagSL[0];
SUpdateProfile_pack.start_Flag[1] = g_otherParameter.startFlagSL[1];
SUpdateProfile_pack.address[0] = save_configInfo.address[0];
SUpdateProfile_pack.address[1] = save_configInfo.address[1];
SUpdateProfile_pack.address[2] = save_configInfo.address[2];
SUpdateProfile_pack.address[3] = save_configInfo.address[3];
SUpdateProfile_pack.address[4] = save_configInfo.address[4];
SUpdateProfile_pack.address[5] = save_configInfo.address[5];
SUpdateProfile_pack.address[6] = save_configInfo.address[6];
SUpdateProfile_pack.function_Code = SL_Function_Code_Update_Profile;
SUpdateProfile_pack.state = 0x01;
uint16_t crc = CheckFuncSL((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
SUpdateProfile_pack.check_Bit_H = crc >> 8;
SUpdateProfile_pack.check_Bit_L = crc;
SUpdateProfile_pack.end_Flag = g_otherParameter.endFlagSL;
while (1) {
Delay_Ms(randomDelay());
if (!Check_485_bus_busy(g_gw485_uart4_handle)) {
uart_dev_write(g_gw485_uart4_handle, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
break;
}
}
/* 复位 */
NVIC_SystemReset();
return;
err:
cfig_len--;
memcpy(config_buff, config_buff + 1, sizeof(config_buff) - 1);
} }
} }

View File

@ -32,7 +32,7 @@ void mppt_constantVoltage(float InVoltage)
static float_t kp = 0.005; static float_t kp = 0.005;
static float_t ki = 0.00001; static float_t ki = 0.00001;
float_t pv1Volt = g_otherParameter.Input_Voltage; float_t pv1Volt = g_otherParameter.Solar_In_Circuit_Voltage;
float_t error = pv1Volt - InVoltage; float_t error = pv1Volt - InVoltage;
float_t stepPwm = kp * error + ki * pv1Volt; float_t stepPwm = kp * error + ki * pv1Volt;
g_controlParameter.dutyRatio += stepPwm; g_controlParameter.dutyRatio += stepPwm;
@ -167,22 +167,19 @@ void MpptModeChoice(void)
if ((g_otherParameter.Charg_BatteryCurrent < 0.05 && g_otherParameter.Charg_BatteryCurrent > -0.05) if ((g_otherParameter.Charg_BatteryCurrent < 0.05 && g_otherParameter.Charg_BatteryCurrent > -0.05)
|| g_otherParameter.Battery_Voltage > 16 || g_otherParameter.Battery_Voltage < 8) { || g_otherParameter.Battery_Voltage > 16 || g_otherParameter.Battery_Voltage < 8) {
g_otherParameter.MPPT_Mode = FLOAT; g_otherParameter.MPPT_Mode = FLOAT;
g_otherParameter.batteryState = 0; g_otherParameter.batteryState = 0;
return; return;
} }
/* */ /* */
if ((g_controlParameter.constantVoltageV - 0.2) >= g_otherParameter.Battery_Voltage if ((g_controlParameter.constantVoltageV - 0.2) >= g_otherParameter.Battery_Voltage
// && g_otherParameter.Charg_BatteryCurrent > 0.1) {
&& g_otherParameter.Charg_Current > 0.1) { && g_otherParameter.Charg_Current > 0.1) {
g_otherParameter.MPPT_Mode = CONSTANTCURRENT; g_otherParameter.MPPT_Mode = CONSTANTCURRENT;
return; return;
} }
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_otherParameter.MPPT_Mode = CONSTANTVOLTAGE; g_otherParameter.MPPT_Mode = CONSTANTVOLTAGE;
return; return;
} }
@ -190,7 +187,6 @@ void MpptModeChoice(void)
if ((((g_controlParameter.constantVoltageV < g_otherParameter.Battery_Voltage) if ((((g_controlParameter.constantVoltageV < g_otherParameter.Battery_Voltage)
&& (g_controlParameter.floatI > g_otherParameter.Charg_Current)) && (g_controlParameter.floatI > g_otherParameter.Charg_Current))
&& (g_controlParameter.floatI > g_otherParameter.Discharg_Current))) { && (g_controlParameter.floatI > g_otherParameter.Discharg_Current))) {
// || g_Mppt_Para.MPPT_Mode == FLOAT) {
g_otherParameter.MPPT_Mode = FLOAT; g_otherParameter.MPPT_Mode = FLOAT;
return; return;
} }
@ -206,12 +202,12 @@ void MpptModeChoice(void)
void MpptContorl(void) void MpptContorl(void)
{ {
g_otherParameter.Output_Voltage = get_PV_VOLT_OUT(); g_otherParameter.Output_Voltage = get_PV_VOLT_OUT();
g_otherParameter.Input_Voltage = get_PV1_VOLT_IN(); g_otherParameter.Solar_In_Circuit_Voltage = get_PV1_VOLT_IN();
/* 出现adc采集出错全为0,退出本次中断 */ // /* 出现adc采集出错全为0,退出本次中断 */
if (g_otherParameter.Discharg_Current == 0 && g_otherParameter.Charg_Current == 0) { // if (g_otherParameter.Discharg_Current == 0 && g_otherParameter.Charg_Current == 0) {
return; // return;
} // }
g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current; g_otherParameter.Charg_BatteryCurrent = g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current;

View File

@ -9,4 +9,3 @@
Mppt_controlparameter g_controlParameter = {0}; Mppt_controlparameter g_controlParameter = {0};
Mppt_otherParameter g_otherParameter = {0}; Mppt_otherParameter g_otherParameter = {0};

View File

@ -18,6 +18,7 @@
uint8_t rs485_buff[buffLen]={0x00}; uint8_t rs485_buff[buffLen]={0x00};
uint8_t config_buff[configBuffLen] = {0x00}; uint8_t config_buff[configBuffLen] = {0x00};
uint32_t cfig_len = 0;
/* 用于解析串口包时的长度 */ /* 用于解析串口包时的长度 */
#define analyzeStartFlag 2 //长度为2时解析起始标志 #define analyzeStartFlag 2 //长度为2时解析起始标志
@ -566,10 +567,12 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
c = uart_dev_in_char(uart_handle); c = uart_dev_in_char(uart_handle);
buff[offset++] = c; buff[offset++] = c;
config_buff[cfig_len++] = c;
/* 匹配起始标志位 */ /* 匹配起始标志位 */
if (offset == analyzeStartFlag || (flag_run > 0)) { if (offset == analyzeStartFlag || (flag_run > 0)) {
if (!Match_Startflag(pack->start_Flag)) { if (!Match_Startflag(pack->start_Flag)) {
log_info("Match_Startflag error \r\n");
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
@ -583,6 +586,11 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
if (flag_run < 1) { if (flag_run < 1) {
flag_run = 1; flag_run = 1;
} }
// log_info("Startflag 0x%x 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
// log_info("Match address error 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\r\n", pack->address[0], pack->address[1], pack->address[2]
// , pack->address[3], pack->address[4], pack->address[5], pack->address[6]);
// log_info("Match address error 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\r\n", g_otherParameter.address[0], g_otherParameter.address[1], g_otherParameter.address[2]
// , g_otherParameter.address[3], g_otherParameter.address[4], g_otherParameter.address[5], g_otherParameter.address[6]);
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
continue; continue;
@ -604,9 +612,15 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
log_info("Write_Register\r\n"); log_info("Write_Register\r\n");
} }
// /* 其他帧格式 */
// else if (pack->function_Code == SL_Function_Code_Update_Profile
// || pack->function_Code == SL_Function_Code_Remote_Upgrade) {
// len = SL_MPPT_ROTHER_PACK_SIZE;
// log_info("Other frames\r\n");
// }
/* 其他帧格式 */ /* 其他帧格式 */
else if (pack->function_Code == SL_Function_Code_Update_Profile else if (pack->function_Code == SL_Function_Code_Remote_Upgrade) {
|| pack->function_Code == SL_Function_Code_Remote_Upgrade) {
len = SL_MPPT_ROTHER_PACK_SIZE; len = SL_MPPT_ROTHER_PACK_SIZE;
log_info("Other frames\r\n"); log_info("Other frames\r\n");
} }
@ -684,10 +698,16 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
if (flag_run < 3) { if (flag_run < 3) {
flag_run = 3; flag_run = 3;
} }
// log_info(" crc : %x, %x", CheckFuncSL(buff, offset - 3), crc_16);
// log_info(" : %x, %x, %x", buff[offset - 3], buff[offset - 2], buff[offset - 1]);
memcpy(buff, buff+1, offset-1); memcpy(buff, buff+1, offset-1);
offset--; offset--;
} else { } else {
memset(config_buff, 0, sizeof(config_buff));
cfig_len = 0;
return offset; return offset;
} }
} }
@ -713,14 +733,28 @@ void FRT_MsgHandler(device_handle device, uint8_t *pMsg, uint32_t MsgLen)
void read_and_process_uart_data(device_handle device) void read_and_process_uart_data(device_handle device)
{ {
if (uart_dev_char_present(device)) { // if (uart_dev_char_present(device)) {
Delay_Ms(20); // Delay_Ms(20);
//// log_info("in read : %d", ring_queue_length(device));
//// char c;
//// while (uart_dev_char_present(device)) {
//// c = uart_dev_in_char(device);
//// log_info("%x ", (c & 0xff));
//// }
//// log_info("");
//
// memset(rs485_buff, 0, sizeof(rs485_buff));
// int ret = uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
// if(ret > 0){
// FRT_MsgHandler(device, rs485_buff, ret);
// }
// }
memset(rs485_buff, 0, sizeof(rs485_buff)); memset(rs485_buff, 0, sizeof(rs485_buff));
int ret = uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff)); int ret = uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
if(ret > 0){ if(ret > 0){
FRT_MsgHandler(device, rs485_buff, ret); FRT_MsgHandler(device, rs485_buff, ret);
} }
}
} }

View File

@ -34,6 +34,7 @@
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();
@ -44,9 +45,10 @@ void Init()
RUN_LED_Init(); RUN_LED_Init();
WDI_INPUT_Init(); WDI_INPUT_Init();
POW_OUT_CON_Init(); POW_OUT_CON_Init();
POW_FF_CON_Init();
DSG_PROT_Init(); DSG_PROT_Init();
WORK_VOLT_INT_Init(); WORK_VOLT_INT_Init();
TIM3_Init(1); TIM3_Init(10);
TimeSliceOffset_Register(&m_WdiRunled, Task_WdiRunled, WdiRunled_reloadVal, WdiRunled_offset); TimeSliceOffset_Register(&m_WdiRunled, Task_WdiRunled, WdiRunled_reloadVal, WdiRunled_offset);
TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister, TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister,
@ -57,10 +59,13 @@ void Init()
dataJudgment_reloadVal, dataJudgment_offset); dataJudgment_reloadVal, dataJudgment_offset);
if (g_otherParameter.CommunicationProtocolType == 0x00) { if (g_otherParameter.CommunicationProtocolType == 0x00) {
TimeSliceOffset_Register(&m_usart, Task_usartSL, usartSL_reloadVal, usartSL_offset); uart_judge_handle = read_and_process_uart_data;
} else if (g_otherParameter.CommunicationProtocolType == 0x01) { } else if (g_otherParameter.CommunicationProtocolType == 0x01) {
TimeSliceOffset_Register(&m_usart, Task_usartHY, usartSL_reloadVal, usartSL_offset); uart_judge_handle = HY_read_and_process_uart_data;
} }
TimeSliceOffset_Register(&m_usartJudge, Task_usartJudge, usartJudge_reloadVal, usartJudge_offset);
TimeSliceOffset_Register(&m_uartConfigFile, Task_uartConfigFile,
uartConfigFile_reloadVal, uartConfigFile_offset);
TIM2_Init(1); TIM2_Init(1);
TimeSliceOffset_Start(); /* 启动时间片轮询 */ TimeSliceOffset_Start(); /* 启动时间片轮询 */
@ -84,8 +89,88 @@ void Task_WdiRunled(void)
temp = 0; temp = 0;
NVIC_SystemReset(); NVIC_SystemReset();
} }
static uint8_t tempT = 10;
if (tempT != 0) {
tempT--;
if (tempT == 0) {
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
GPIO_WriteBit(POW_FF_CON_GPIO, POW_FF_CON_PIN, SET);
}
}
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);
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
char buffer[80];
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " duty_ratio : %d/1000 \n", (int)(g_controlParameter.dutyRatio * 1000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Solar_In_Circuit_Voltage : %d/100 \n", (int)(g_otherParameter.Solar_In_Circuit_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " vout : %d/100 \n", (int)(g_otherParameter.Output_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " vBattery : %d/100 \n", (int)(g_otherParameter.Battery_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Iout : %d/100 \n", (int)(g_otherParameter.Charg_Current * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Idisout : %d/100 \n", (int)(g_otherParameter.Discharg_Current * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " mosT : %d/10 \n", (int)(g_otherParameter.HighSideMos_Temperature * 10));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " impedance : %d/1000 \n", (int)(g_controlParameter.loopImpedance * 1000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " g_impedanceStart : %d \n", g_otherParameter.impedanceStart);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " mosState : %d \n", (int)(g_otherParameter.DischargMos_State));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " batteryState : %d \n", g_otherParameter.batteryState);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " outputAgainFlag : %d \n", g_otherParameter.outputAgainFlag);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " excessiveLoadFlag : %d \n", g_otherParameter.excessiveLoadFlag);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " inPower : %d/10000 \n", (int)(g_otherParameter.totalChargCapacity * 10000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " outPower : %d/10000 \n", (int)(g_otherParameter.totalElectricityConsumption * 10000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " 0.没有工作; 1.恒流模式; 2.恒压模式; 3.浮充模式 : %d \n", g_otherParameter.MPPT_Mode);
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
} }
/** /**
@ -361,7 +446,6 @@ void Task_dataJudgment(void)
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal); , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
} }
if (g_otherParameter.overTemperature != 0 if (g_otherParameter.overTemperature != 0
&& g_otherParameter.HighSideMos_Temperature < g_controlParameter.HighSideMosTemperature_start + 3) { && g_otherParameter.HighSideMos_Temperature < g_controlParameter.HighSideMosTemperature_start + 3) {
if (g_otherParameter.overTemperature == 2) { if (g_otherParameter.overTemperature == 2) {
@ -396,16 +480,24 @@ void Task_dataJudgment(void)
* @retval * @retval
* *
*/ */
STR_TimeSliceOffset m_usart; uartJudgeHandle uart_judge_handle;
void Task_usartSL(void) STR_TimeSliceOffset m_usartJudge;
void Task_usartJudge(void)
{ {
read_and_process_uart_data(g_gw485_uart4_handle); if (uart_dev_char_present(g_gw485_uart4_handle)) {
TimeSliceOffset_Register(&m_usartHandle, Task_usartHandle
, usartHandle_reloadVal, usartHandle_offset);
}
} }
void Task_usartHY(void) STR_TimeSliceOffset m_usartHandle;
void Task_usartHandle(void)
{ {
HY_read_and_process_uart_data(g_gw485_uart4_handle); TimeSliceOffset_Unregister(&m_usartHandle);
m_usartHandle.runFlag = 0;
uart_judge_handle(g_gw485_uart4_handle);
} }
/** /**
* @brief 广,3s * @brief 广,3s
* @param * @param
@ -484,7 +576,7 @@ void Task_recvbroadcast(void)
run_number = 0; run_number = 0;
return; return;
} }
uart_dev_write(g_recvBroadcastDevice, (uint8_t *)&recvpack, SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE + 1); uart_dev_write(g_recvBroadcastDevice, (uint8_t *)&recvpack, SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE);
if (g_recvBroadcastDevice == g_bat485_uart3_handle) { if (g_recvBroadcastDevice == g_bat485_uart3_handle) {
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
@ -519,3 +611,30 @@ void Task_sensorEnableBroadcast(void)
return; return;
} }
/**
* @brief
* @param
* @retval
*
*/
STR_TimeSliceOffset m_uartConfigFile;
void Task_uartConfigFile(void)
{
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();
}

View File

@ -19,7 +19,7 @@ device_handle g_bat485_uart3_handle;
device_handle g_gw485_uart4_handle; device_handle g_gw485_uart4_handle;
static uint8_t bat485_in_buff[200]; static uint8_t bat485_in_buff[200];
static uint8_t gw485_in_buff[300]; static uint8_t gw485_in_buff[200];
uint8_t rs485_out_buff[100]; uint8_t rs485_out_buff[100];
@ -106,9 +106,9 @@ void uart_init(uartIndex_e uart_index, int baud)
{ {
if (uart_index == BAT485_UART_INDEX) { if (uart_index == BAT485_UART_INDEX) {
// BAT_485_Init(uart_devices[0].uart_baudrate); // BAT_485_Init(uart_devices[0].uart_baudrate);
BAT_485_Init(115200); BAT_485_Init(baud);
} else if (uart_index == GW485_UART_INDEX) { } else if (uart_index == GW485_UART_INDEX) {
GW_485_Init(uart_devices[1].uart_baudrate); GW_485_Init(baud);
} }
} }

View File

@ -70,6 +70,14 @@ void EnPowerSupply_Init(void);
/* WORK_VOLT_INT --> PA12 */ /* WORK_VOLT_INT --> PA12 */
#define WORK_VOLT_INT_GPIO GPIOA #define WORK_VOLT_INT_GPIO GPIOA
#define WORK_VOLT_INT_PIN GPIO_Pin_12 #define WORK_VOLT_INT_PIN GPIO_Pin_12
void WORK_VOLT_INT_open(void);
void WORK_VOLT_INT_close(void);
void WORK_VOLT_INT_Init(void); void WORK_VOLT_INT_Init(void);
/* 防反mos的控制 */
/* POW_FF_CON --> PA15 */
#define POW_FF_CON_GPIO GPIOA
#define POW_FF_CON_PIN GPIO_Pin_15
void POW_FF_CON_Init(void);
#endif /* HARDWARE_INC_GPIO_H_ */ #endif /* HARDWARE_INC_GPIO_H_ */

View File

@ -135,14 +135,8 @@ void EnPowerSupply_Init(void)
void EXTI15_10_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void EXTI15_10_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void WORK_VOLT_INT_Init(void) void WORK_VOLT_INT_open(void)
{ {
RCC_PB2PeriphClockCmd(RCC_PB2Periph_AFIO | RCC_PB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = WORK_VOLT_INT_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
GPIO_Init(WORK_VOLT_INT_GPIO, &GPIO_InitStructure);
/* GPIOA ----> EXTI_Line12 */ /* GPIOA ----> EXTI_Line12 */
EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);//指定中断/事件线的输入源实际上是设定外部中断配置寄存器AFIO_EXTICRx的值此处为PA12 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);//指定中断/事件线的输入源实际上是设定外部中断配置寄存器AFIO_EXTICRx的值此处为PA12
@ -151,6 +145,29 @@ void WORK_VOLT_INT_Init(void)
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //EXTI边沿触发事件此处选择为上升沿触发 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //EXTI边沿触发事件此处选择为上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能EXTI线 EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能EXTI线
EXTI_Init(&EXTI_InitStructure); EXTI_Init(&EXTI_InitStructure);
}
void WORK_VOLT_INT_close(void)
{
/* GPIOA ----> EXTI_Line12 */
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);//指定中断/事件线的输入源实际上是设定外部中断配置寄存器AFIO_EXTICRx的值此处为PA12
EXTI_InitStructure.EXTI_Line = EXTI_Line12; //EXTI中断/事件线选择此处选择EXTI_Line12
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //EXTI模式选择此处选择为产生中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //EXTI边沿触发事件此处选择为上升沿触发
EXTI_InitStructure.EXTI_LineCmd = DISABLE; //使能EXTI线
EXTI_Init(&EXTI_InitStructure);
}
void WORK_VOLT_INT_Init(void)
{
RCC_PB2PeriphClockCmd(RCC_PB2Periph_AFIO | RCC_PB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = WORK_VOLT_INT_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
GPIO_Init(WORK_VOLT_INT_GPIO, &GPIO_InitStructure);
WORK_VOLT_INT_open();
NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能EXTI12中断通道 NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能EXTI12中断通道
@ -163,6 +180,11 @@ void WORK_VOLT_INT_Init(void)
void EXTI15_10_IRQHandler(void) void EXTI15_10_IRQHandler(void)
{ {
if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态如果EXTI线产生中断则返回SET否则返回RESET if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态如果EXTI线产生中断则返回SET否则返回RESET
// WORK_VOLT_INT_close();
// TimeSliceOffset_Register(&g_overloadDelay, Task_overloadDelay
// , overloadDelay_reloadVal, overloadDelay_offset);
Delay_Us(10);
// WORK_VOLT_INT_open();
EXTI_ClearITPendingBit(EXTI_Line12); //清除中断标志位 EXTI_ClearITPendingBit(EXTI_Line12); //清除中断标志位
if (0 == g_otherParameter.excessiveLoadFlag) { if (0 == g_otherParameter.excessiveLoadFlag) {
TimeSliceOffset_Register(&g_excessiveLoad, Task_excessiveLoad TimeSliceOffset_Register(&g_excessiveLoad, Task_excessiveLoad
@ -172,3 +194,15 @@ void EXTI15_10_IRQHandler(void)
} }
} }
void POW_FF_CON_Init(void)
{
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = POW_FF_CON_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(POW_FF_CON_GPIO, &GPIO_InitStructure);
// GPIO_WriteBit(POW_FF_CON_GPIO, POW_FF_CON_PIN, SET);
GPIO_WriteBit(POW_FF_CON_GPIO, POW_FF_CON_PIN, RESET);
}

View File

@ -8,7 +8,7 @@
#include "rs485.h" #include "rs485.h"
#include "uart_dev.h" #include "uart_dev.h"
#include "ring_queue.h" #include "ring_queue.h"
#include "pdebug.h"
void USART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void USART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void USART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void USART4_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
@ -59,7 +59,8 @@ void GW_485_Init(int baud)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PB1为浮空输入 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置PB1为浮空输入
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = baud; // USART_InitStructure.USART_BaudRate = baud;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_Parity = USART_Parity_No;
@ -68,7 +69,7 @@ void GW_485_Init(int baud)
USART_Init(USART4, &USART_InitStructure); USART_Init(USART4, &USART_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART4_IRQn; NVIC_InitStructure.NVIC_IRQChannel = USART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //抢占优先级为1 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级为2 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级为2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化 NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
@ -119,7 +120,7 @@ void BAT_485_Init(int baud)
USART_Init(USART3, &USART_InitStructure); USART_Init(USART3, &USART_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //抢占优先级为1 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级为1 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级为1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //中断优先级初始化 NVIC_Init(&NVIC_InitStructure); //中断优先级初始化
@ -295,12 +296,15 @@ void USART4_IRQHandler(void)
{ {
// printf(" in usart4 \n"); // printf(" in usart4 \n");
// USART_ClearITPendingBit(USART4, USART_IT_RXNE); //清除中断标志 // USART_ClearITPendingBit(USART4, USART_IT_RXNE); //清除中断标志
// uint8_t c = 0;
// c = USART4_Rbuffer[0];
// log_info("%x ", (USART4_Rbuffer[0] & 0xff));
USART4_Rbuffer[0] = USART_ReceiveData(USART4); //接收数据 USART4_Rbuffer[0] = USART_ReceiveData(USART4); //接收数据
uint8_t c = 0;
uart_device_info *dev = (uart_device_info *)g_gw485_uart4_handle; uart_device_info *dev = (uart_device_info *)g_gw485_uart4_handle;
c = USART4_Rbuffer[0]; // log_info("%x ", (USART4_Rbuffer[0] & 0xff));
if(!RingQueueFull(&dev->uart_ring_queue)) if(!RingQueueFull(&dev->uart_ring_queue))
InRingQueue(&dev->uart_ring_queue, c); InRingQueue(&dev->uart_ring_queue, USART4_Rbuffer[0]);
} }
// if(USART_GetFlagStatus(USART4,USART_FLAG_TC) == SET) //中断发送 // if(USART_GetFlagStatus(USART4,USART_FLAG_TC) == SET) //中断发送

View File

@ -112,8 +112,8 @@ void TIM2_IRQHandler(void)
g_otherParameter.Charg_Current = get_CHG_CURR(); g_otherParameter.Charg_Current = get_CHG_CURR();
g_otherParameter.Discharg_Current = get_DSG_CURR(); g_otherParameter.Discharg_Current = get_DSG_CURR();
totalElectricityConsumption += g_otherParameter.Charg_Current * g_otherParameter.Output_Voltage; totalChargCapacity += g_otherParameter.Charg_Current * g_otherParameter.Output_Voltage;
totalChargCapacity += g_otherParameter.Discharg_Current * g_otherParameter.Output_Voltage; totalElectricityConsumption += g_otherParameter.Discharg_Current * g_otherParameter.Output_Voltage;
} }
} }

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.

View File

@ -27,7 +27,8 @@ Hardware/src/rs485.o: ../Hardware/src/rs485.c \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h \ D:\psx\MPPT\git\Peripheral\inc/ch32l103_lptim.h \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \ D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \
D:\psx\MPPT\git\App\inc/uart_dev.h \ D:\psx\MPPT\git\App\inc/uart_dev.h \
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \
D:\psx\MPPT\git\App\inc/pdebug.h D:\psx\MPPT\git\App\inc/uart_dev.h
D:\psx\MPPT\git\Hardware\inc/rs485.h: D:\psx\MPPT\git\Hardware\inc/rs485.h:
@ -90,3 +91,7 @@ D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h:
D:\psx\MPPT\git\App\inc/uart_dev.h: D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h: D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h:
D:\psx\MPPT\git\App\inc/pdebug.h:
D:\psx\MPPT\git\App\inc/uart_dev.h:

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