2024-12-06 13:23:28 +00:00
|
|
|
|
|
|
|
|
|
#include "inFlash.h"
|
|
|
|
|
#include "parameter.h"
|
|
|
|
|
#include "pDebug.h"
|
|
|
|
|
|
|
|
|
|
// static uint8_t config_buff[200];
|
|
|
|
|
// static uint8_t config_buff_pos = 0;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 校验算法, modebus
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
static uint16_t configCheckFunc(uint8_t *arr_buff, uint8_t len)
|
|
|
|
|
{
|
|
|
|
|
uint16_t crc = 0xFFFF;
|
|
|
|
|
uint16_t i, j;
|
|
|
|
|
for (j = 0; j < len; ++j) {
|
|
|
|
|
crc = crc ^ (*arr_buff++);
|
|
|
|
|
for (i = 0; i < 8; ++i) {
|
|
|
|
|
if ((crc&0x0001) > 0) {
|
|
|
|
|
crc = crc >> 1;
|
|
|
|
|
crc = crc ^ 0xa001;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
crc = crc >> 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return crc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 保存配置信息
|
|
|
|
|
* @param save_config_info 需要保存的配置信息
|
|
|
|
|
* @retval None
|
|
|
|
|
*/
|
|
|
|
|
void save_config_info(config_info *save_config_info)
|
|
|
|
|
{
|
|
|
|
|
write_Flash((uint8_t *)save_config_info, CONFIG_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 保存配置信息到备份区
|
|
|
|
|
* @param save_config_info 需要保存的配置信息
|
|
|
|
|
* @retval None
|
|
|
|
|
*/
|
|
|
|
|
static void save_backups_config_info(config_info *save_config_info)
|
|
|
|
|
{
|
|
|
|
|
write_Flash((uint8_t *)save_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 读取配置信息
|
|
|
|
|
* @param read_config_info 读取配置信息并保存在output_config_info中
|
|
|
|
|
* @retval None
|
|
|
|
|
*/
|
|
|
|
|
void read_config_info(config_info *output_config_info)
|
|
|
|
|
{
|
|
|
|
|
read_Flash((uint8_t *)output_config_info, CONFIG_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 读取备份的配置信息
|
|
|
|
|
* @param read_config_info 读取配置信息并保存在output_config_info中
|
|
|
|
|
* @retval None
|
|
|
|
|
*/
|
|
|
|
|
static void read_backups_config_info(config_info *output_config_info)
|
|
|
|
|
{
|
|
|
|
|
read_Flash((uint8_t *)output_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 检测flash中是否有配置文件或者文件是否有损坏,若两处flash中都损坏则使用默认文件
|
|
|
|
|
* @param config_info 读取的配置信息
|
|
|
|
|
* @retval None
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void readFlashContent(config_info *config_info)
|
|
|
|
|
{
|
|
|
|
|
read_config_info(config_info);
|
|
|
|
|
|
|
|
|
|
/* 配置文件正确就返回 */
|
|
|
|
|
if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 更深处的配置文件正确就返回 */
|
|
|
|
|
read_backups_config_info(config_info);
|
|
|
|
|
if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) {
|
|
|
|
|
save_config_info(config_info);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 配置文件错误使用默认配置 */
|
|
|
|
|
config_info->address[0] = 0x11;
|
|
|
|
|
config_info->address[1] = 0x11;
|
|
|
|
|
config_info->address[2] = 0x11;
|
|
|
|
|
config_info->address[3] = 0x11;
|
|
|
|
|
config_info->address[4] = 0x11;
|
|
|
|
|
config_info->address[5] = 0x11;
|
|
|
|
|
config_info->address[6] = 0x11;
|
|
|
|
|
config_info->Access_Node_Type = 0x01;
|
|
|
|
|
config_info->Communication_Methods = 0x02;
|
|
|
|
|
config_info->gw485_Baud = 9600;
|
|
|
|
|
config_info->bat485_Baud = 115200;
|
|
|
|
|
|
|
|
|
|
config_info->hardwareID[0] = 0x48;
|
|
|
|
|
config_info->hardwareID[1] = 0x59;
|
|
|
|
|
config_info->hardwareID[2] = 0x30;
|
|
|
|
|
config_info->hardwareID[3] = 0x30;
|
|
|
|
|
config_info->hardwareID[4] = 0x30;
|
|
|
|
|
config_info->hardwareID[5] = 0x31;
|
|
|
|
|
config_info->communicationID[0] = 0x00;
|
|
|
|
|
config_info->communicationID[1] = 0x00;
|
|
|
|
|
config_info->communicationID[2] = 0x00;
|
|
|
|
|
config_info->communicationID[3] = 0x01;
|
|
|
|
|
config_info->protocolType = 0x01;
|
|
|
|
|
|
|
|
|
|
// config_info->CommunicationProtocolType = 0x00;
|
|
|
|
|
config_info->onlyPower = 0x01;
|
|
|
|
|
|
|
|
|
|
config_info->constantVoltageV = 14;
|
|
|
|
|
config_info->floatI = 0.02;
|
|
|
|
|
config_info->startSolarOpenCircuitV = 17;
|
|
|
|
|
config_info->stopSolarOpenCircuitV = 15;
|
|
|
|
|
config_info->constantVoltageChargeV = 14.4;
|
|
|
|
|
config_info->FloatChargeV = 14;
|
|
|
|
|
config_info->HighSideMosTemperature_stop = 100;
|
|
|
|
|
config_info->HighSideMosTemperature_end = 90;
|
|
|
|
|
config_info->HighSideMosTemperature_start = 50;
|
|
|
|
|
|
|
|
|
|
config_info->checkSolarOpenCircuitVTime = 10;
|
|
|
|
|
config_info->sensorEnableBroadcastTime = 20;
|
|
|
|
|
config_info->outputAgainFlagTime = 10;
|
|
|
|
|
config_info->excessiveLoadFlagTime = 60;
|
|
|
|
|
config_info->eLAgainTime = 1800;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 通过配置文件初始化系统参数
|
|
|
|
|
* @param None
|
|
|
|
|
* @retval None
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void config_info_start(void)
|
|
|
|
|
{
|
|
|
|
|
Flash_Init();
|
|
|
|
|
|
|
|
|
|
config_info temp_configInfo;
|
|
|
|
|
readFlashContent(&temp_configInfo);
|
|
|
|
|
|
|
|
|
|
g_cfgParameter.constantVoltageV = temp_configInfo.constantVoltageV;
|
|
|
|
|
g_cfgParameter.floatI = temp_configInfo.floatI;
|
|
|
|
|
g_cfgParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV;
|
|
|
|
|
g_cfgParameter.stopSolarOpenCircuitV = temp_configInfo.stopSolarOpenCircuitV;
|
|
|
|
|
g_cfgParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
|
|
|
|
|
g_cfgParameter.FloatV = temp_configInfo.FloatChargeV;
|
|
|
|
|
g_cfgParameter.HighSideMosTemperature_stop = temp_configInfo.HighSideMosTemperature_stop;
|
|
|
|
|
g_cfgParameter.HighSideMosTemperature_end = temp_configInfo.HighSideMosTemperature_end;
|
|
|
|
|
g_cfgParameter.HighSideMosTemperature_start = temp_configInfo.HighSideMosTemperature_start;
|
|
|
|
|
g_cfgParameter.sensorEnableBroadcastTime = temp_configInfo.sensorEnableBroadcastTime;
|
|
|
|
|
g_cfgParameter.checkSolarOpenCircuitVTime = temp_configInfo.checkSolarOpenCircuitVTime;
|
|
|
|
|
g_cfgParameter.outputAgainFlagTime = temp_configInfo.outputAgainFlagTime;
|
|
|
|
|
g_cfgParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime;
|
|
|
|
|
g_cfgParameter.eLAgainTime = temp_configInfo.eLAgainTime;
|
|
|
|
|
g_cfgParameter.collectOpenCircuitVoltageTime= 3600;
|
|
|
|
|
g_cfgParameter.address[0] = temp_configInfo.address[0];
|
|
|
|
|
g_cfgParameter.address[1] = temp_configInfo.address[1];
|
|
|
|
|
g_cfgParameter.address[2] = temp_configInfo.address[2];
|
|
|
|
|
g_cfgParameter.address[3] = temp_configInfo.address[3];
|
|
|
|
|
g_cfgParameter.address[4] = temp_configInfo.address[4];
|
|
|
|
|
g_cfgParameter.address[5] = temp_configInfo.address[5];
|
|
|
|
|
g_cfgParameter.address[6] = temp_configInfo.address[6];
|
|
|
|
|
g_cfgParameter.Access_Node_Type = temp_configInfo.Access_Node_Type;
|
|
|
|
|
g_cfgParameter.Communication_Methods = temp_configInfo.Communication_Methods;
|
|
|
|
|
g_cfgParameter.hardwareID[0] = temp_configInfo.hardwareID[0];
|
|
|
|
|
g_cfgParameter.hardwareID[1] = temp_configInfo.hardwareID[1];
|
|
|
|
|
g_cfgParameter.hardwareID[2] = temp_configInfo.hardwareID[2];
|
|
|
|
|
g_cfgParameter.hardwareID[3] = temp_configInfo.hardwareID[3];
|
|
|
|
|
g_cfgParameter.hardwareID[4] = temp_configInfo.hardwareID[4];
|
|
|
|
|
g_cfgParameter.hardwareID[5] = temp_configInfo.hardwareID[5];
|
|
|
|
|
g_cfgParameter.communicationID[0] = temp_configInfo.communicationID[0];
|
|
|
|
|
g_cfgParameter.communicationID[1] = temp_configInfo.communicationID[1];
|
|
|
|
|
g_cfgParameter.communicationID[2] = temp_configInfo.communicationID[2];
|
|
|
|
|
g_cfgParameter.communicationID[3] = temp_configInfo.communicationID[3];
|
|
|
|
|
g_cfgParameter.protocolType = temp_configInfo.protocolType;
|
|
|
|
|
// g_cfgParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType;
|
|
|
|
|
g_cfgParameter.onlyPower = temp_configInfo.onlyPower;
|
|
|
|
|
|
|
|
|
|
g_cfgParameter.startFlagSL[0] = 'S';
|
|
|
|
|
g_cfgParameter.startFlagSL[1] = 'L';
|
|
|
|
|
g_cfgParameter.endFlagSL = 0x16;
|
|
|
|
|
g_cfgParameter.startFlagHY = 0x68;
|
|
|
|
|
g_cfgParameter.endFlagHY = 0x16;
|
|
|
|
|
|
|
|
|
|
// if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
|
|
|
|
// g_cfgParameter.gw485_Baud = temp_configInfo.gw485_Baud;
|
|
|
|
|
// g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
|
|
|
|
// } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
|
|
|
|
// g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
|
|
|
|
// if (g_cfgParameter.protocolType == 0x01) {
|
|
|
|
|
// g_cfgParameter.gw485_Baud = 9600;
|
|
|
|
|
// } else if (g_cfgParameter.protocolType == 0x02) {
|
|
|
|
|
// g_cfgParameter.gw485_Baud = 115200;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
g_cfgParameter.gw485_Baud = 9600;
|
|
|
|
|
g_cfgParameter.gw485_Baud = 115200;
|
|
|
|
|
|
|
|
|
|
float fTemp;
|
|
|
|
|
readLoopImpedance(&fTemp);
|
|
|
|
|
/* 读取的回路阻抗偏差过大则不使用 */
|
|
|
|
|
if (fTemp > (float)0.005 && fTemp < (float)1) {
|
|
|
|
|
g_cfgParameter.loopImpedance = fTemp;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
g_cfgParameter.loopImpedance = 0;
|
|
|
|
|
saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
|
|
|
|
}
|
2024-12-07 09:52:46 +00:00
|
|
|
|
readtotalElectricityConsumption(&fTemp);
|
|
|
|
|
totalElectricityConsumptionInt(fTemp);
|
|
|
|
|
readtotalChargCapacity(&fTemp);
|
|
|
|
|
totalChargCapacityInt(fTemp);
|
2024-12-06 13:23:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 判断接收到的配置文件数据是否正确,正确的话存入flash中
|
|
|
|
|
* @param None
|
|
|
|
|
* @retval None
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
// #define enlargeScale 100
|
|
|
|
|
// BOOL read_and_process_config_data(uint8_t *config_buff[])
|
|
|
|
|
// {
|
|
|
|
|
// recv_config_info *pack = (recv_config_info *)*config_buff;
|
|
|
|
|
// config_info save_configInfo;
|
|
|
|
|
// while (config_buff_pos >= RECV_CONFIG_INFO) {
|
|
|
|
|
// /* 判断起始标志是否正确 */
|
|
|
|
|
// if (pack->start_Flag[0] != g_cfgParameter.startFlagSL[0]
|
|
|
|
|
// || pack->start_Flag[1] != g_cfgParameter.startFlagSL[1]) {
|
|
|
|
|
// // debug(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断接入节点类型是否正确 */
|
|
|
|
|
// save_configInfo.Access_Node_Type = (uint16_t)pack->Access_Node_Type[0] << 8
|
|
|
|
|
// | (uint16_t)pack->Access_Node_Type[1];
|
|
|
|
|
// // debug(" Access_Node_Type : 0x%x \n", save_configInfo.Access_Node_Type);
|
|
|
|
|
// if (save_configInfo.Access_Node_Type != POWERBOX) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断通信方式是否正确 */
|
|
|
|
|
// save_configInfo.Communication_Methods = (uint16_t)pack->Communication_Methods[0] << 8
|
|
|
|
|
// | (uint16_t)pack->Communication_Methods[1];
|
|
|
|
|
// // debug(" Communication_Methods : 0x%x \n", save_configInfo.Communication_Methods);
|
|
|
|
|
// // if (temp_u16 != RS485 || temp_u16 != RJ45) {
|
|
|
|
|
// if (save_configInfo.Communication_Methods != RS485) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断波特率是否正确 */
|
|
|
|
|
// save_configInfo.gw485_Baud = (uint32_t)pack->gw485_Baud[0] << 24
|
|
|
|
|
// | (uint32_t)pack->gw485_Baud[1] << 16
|
|
|
|
|
// | (uint32_t)pack->gw485_Baud[2] << 8
|
|
|
|
|
// | (uint32_t)pack->gw485_Baud[3];
|
|
|
|
|
// // debug(" gw485_Baud : 0x%x, %d \n", save_configInfo.gw485_Baud, save_configInfo.gw485_Baud);
|
|
|
|
|
// if (save_configInfo.gw485_Baud != 9600 && save_configInfo.gw485_Baud != 115200) {
|
|
|
|
|
// // if (save_configInfo.gw485_Baud != 0x2580 || save_configInfo.gw485_Baud != 115200) {
|
|
|
|
|
// // debug(" error : %d\n", save_configInfo.gw485_Baud);
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// save_configInfo.bat485_Baud = (uint32_t)pack->bat485_Baud[0] << 24
|
|
|
|
|
// | (uint32_t)pack->bat485_Baud[1] << 16
|
|
|
|
|
// | (uint32_t)pack->bat485_Baud[2] << 8
|
|
|
|
|
// | (uint32_t)pack->bat485_Baud[3];
|
|
|
|
|
// // debug(" bat485_Baud : 0x%x, %d \n", save_configInfo.bat485_Baud, save_configInfo.bat485_Baud);
|
|
|
|
|
// 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) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
// // debug(" protocolType : 0x%x \n", pack->protocolType);
|
|
|
|
|
|
|
|
|
|
/* 判断通信协议类型是否正确 */
|
|
|
|
|
/*
|
|
|
|
|
if (pack->CommunicationProtocolType != 0x00 && pack->CommunicationProtocolType != 0x01) {
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
// debug(" CommunicationProtocolType : 0x%x \n", pack->CommunicationProtocolType);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// /* 判断电源盒类型是否正确 */
|
|
|
|
|
// if (pack->onlyPower != 0x00 && pack->onlyPower != 0x01) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
// // debug(" onlyPower : 0x%x \n", pack->onlyPower);
|
|
|
|
|
|
|
|
|
|
// /* 判断恒压充电阈值是否正确 */
|
|
|
|
|
// save_configInfo.constantVoltageV =
|
|
|
|
|
// (float)(pack->ConstantVoltageV[0] << 8 | pack->ConstantVoltageV[1]) / enlargeScale;
|
|
|
|
|
// // debug(" constantVoltageV : %f \n", save_configInfo.constantVoltageV);
|
|
|
|
|
// if (save_configInfo.constantVoltageV > (float)14.4 || save_configInfo.constantVoltageV < (float)13.5) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断浮充充电阈值是否正确 */
|
|
|
|
|
// save_configInfo.floatI = (float)(pack->FloatI[0] << 8 | pack->FloatI[1]) / enlargeScale;
|
|
|
|
|
// // debug(" floatI : %f \n", save_configInfo.floatI);
|
|
|
|
|
// if (save_configInfo.floatI > (float)0.2 || save_configInfo.floatI < (float)0) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断太阳能板开路启动电压是否正确 */
|
|
|
|
|
// save_configInfo.startSolarOpenCircuitV =
|
|
|
|
|
// (float)(pack->startSolarOpenCircuitV[0] << 8 | pack->startSolarOpenCircuitV[1]) / enlargeScale;
|
|
|
|
|
// // debug(" startSolarOpenCircuitV : %f \n", save_configInfo.startSolarOpenCircuitV);
|
|
|
|
|
// if (save_configInfo.startSolarOpenCircuitV > 24 || save_configInfo.startSolarOpenCircuitV < 14) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断太阳能板关闭电压是否正确 */
|
|
|
|
|
// save_configInfo.stopSolarOpenCircuitV =
|
|
|
|
|
// (float)(pack->stopSolarOpenCircuitV[0] << 8 | pack->stopSolarOpenCircuitV[1]) / enlargeScale;
|
|
|
|
|
// // debug(" stopSolarOpenCircuitV : %f \n", save_configInfo.stopSolarOpenCircuitV);
|
|
|
|
|
// if (save_configInfo.stopSolarOpenCircuitV > 17 || save_configInfo.stopSolarOpenCircuitV < 13) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断恒压充电时的输出电压是否正确 */
|
|
|
|
|
// save_configInfo.constantVoltageChargeV =
|
|
|
|
|
// (float)(pack->constantVoltageChargeV[0] << 8 | pack->constantVoltageChargeV[1]) / enlargeScale;
|
|
|
|
|
// // debug(" constantVoltageChargeV : %f \n", save_configInfo.constantVoltageChargeV);
|
|
|
|
|
// if (save_configInfo.constantVoltageChargeV > (float)14.6 || save_configInfo.constantVoltageChargeV < (float)14) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断浮充充电时的输出电压是否正确 */
|
|
|
|
|
// save_configInfo.FloatChargeV =
|
|
|
|
|
// (float)(pack->FloatChargeV[0] << 8 | pack->FloatChargeV[1]) / enlargeScale;
|
|
|
|
|
// // debug(" FloatChargeV : %f \n", save_configInfo.FloatChargeV);
|
|
|
|
|
// if (save_configInfo.FloatChargeV > (float)14.4 || save_configInfo.FloatChargeV < (float)13.8) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断mos管停止工作温度是否正确 */
|
|
|
|
|
// save_configInfo.HighSideMosTemperature_stop =
|
|
|
|
|
// (float)(pack->HighSideMosTemperature_stop[0] << 8 | pack->HighSideMosTemperature_stop[1]) / enlargeScale;
|
|
|
|
|
// // debug(" HighSideMosTemperature_stop : %f \n", save_configInfo.HighSideMosTemperature_stop);
|
|
|
|
|
// if (save_configInfo.HighSideMosTemperature_stop < 60) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断mos管降低工作功率工作温度是否正确 */
|
|
|
|
|
// save_configInfo.HighSideMosTemperature_end =
|
|
|
|
|
// (float)(pack->HighSideMosTemperature_end[0] << 8 | pack->HighSideMosTemperature_end[1]) / enlargeScale;
|
|
|
|
|
// // debug(" HighSideMosTemperature_end : %f \n", save_configInfo.HighSideMosTemperature_end));
|
|
|
|
|
// if (save_configInfo.HighSideMosTemperature_end < 50) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断mos管完全恢复工作温度是否正确 */
|
|
|
|
|
// save_configInfo.HighSideMosTemperature_start =
|
|
|
|
|
// (float)(pack->HighSideMosTemperature_start[0] << 8 | pack->HighSideMosTemperature_start[1]) / enlargeScale;
|
|
|
|
|
// // debug(" HighSideMosTemperature_start : %d \n", save_configInfo.HighSideMosTemperature_start);
|
|
|
|
|
// if (save_configInfo.HighSideMosTemperature_start < 40) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断启动任务中太阳能板开路电压检测间隔时间是否正确 */
|
|
|
|
|
// save_configInfo.checkSolarOpenCircuitVTime =
|
|
|
|
|
// pack->checkSolarOpenCircuitVTime[0] << 8 | pack->checkSolarOpenCircuitVTime[1];
|
|
|
|
|
// // debug(" checkSolarOpenCircuitVTime : %d \n", save_configInfo.checkSolarOpenCircuitVTime);
|
|
|
|
|
// if (save_configInfo.checkSolarOpenCircuitVTime > 1800 || save_configInfo.checkSolarOpenCircuitVTime < 5) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断传感器运行再次注册的间隔是否正确 */
|
|
|
|
|
// save_configInfo.sensorEnableBroadcastTime =
|
|
|
|
|
// pack->sensorEnableBroadcastTime[0] << 8 | pack->sensorEnableBroadcastTime[1];
|
|
|
|
|
// // debug(" sensorEnableBroadcastTime : %d \n", save_configInfo.sensorEnableBroadcastTime);
|
|
|
|
|
// if (save_configInfo.sensorEnableBroadcastTime > 60 || save_configInfo.sensorEnableBroadcastTime < 10) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出的间隔是否正确 */
|
|
|
|
|
// save_configInfo.outputAgainFlagTime =
|
|
|
|
|
// pack->outputAgainFlagTime[0] << 8 | pack->outputAgainFlagTime[1];
|
|
|
|
|
// // debug(" outputAgainFlagTime : %d \n", save_configInfo.outputAgainFlagTime);
|
|
|
|
|
// if (save_configInfo.sensorEnableBroadcastTime > 30 || save_configInfo.sensorEnableBroadcastTime < 5) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出的间隔是否正确 */
|
|
|
|
|
// save_configInfo.excessiveLoadFlagTime =
|
|
|
|
|
// pack->excessiveLoadFlagTime[0] << 8 | pack->excessiveLoadFlagTime[1];
|
|
|
|
|
// // debug(" excessiveLoadFlagTime : %d \n", save_configInfo.excessiveLoadFlagTime);
|
|
|
|
|
// if (save_configInfo.excessiveLoadFlagTime > 90 || save_configInfo.excessiveLoadFlagTime < 30) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* 判断出现过载过载保护后,在该间隔段时间后,再次尝试输出的间隔是否正确 */
|
|
|
|
|
// save_configInfo.eLAgainTime = pack->eLAgainTime[0] << 8 | pack->eLAgainTime[1];
|
|
|
|
|
// // debug(" eLAgainTime : %d \n", save_configInfo.eLAgainTime);
|
|
|
|
|
// if (save_configInfo.eLAgainTime > 3000 || save_configInfo.eLAgainTime < 1000) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /* crc校验 */
|
|
|
|
|
// save_configInfo.crc = pack->crc[0] << 8 | pack->crc[1];
|
|
|
|
|
// // debug(" crc : %x%x \n", pack->crc[0], pack->crc[1]);
|
|
|
|
|
// if (save_configInfo.crc != configCheckFunc(config_buff, RECV_CONFIG_INFO - 3)) {
|
|
|
|
|
// // debug(" configCheckFunc : %x \n", configCheckFunc(config_buff, RECV_CONFIG_INFO));
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// /* 结束标志 */
|
|
|
|
|
// // debug(" end_Flag : %x \n", pack->end_Flag);
|
|
|
|
|
// if (pack->end_Flag != 0x16) {
|
|
|
|
|
// goto err;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // debug("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];
|
|
|
|
|
// // debug("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) {
|
|
|
|
|
// // 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;
|
|
|
|
|
// // }
|
|
|
|
|
// // Delay_Ms(randomDelay());
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
// /* 复位 */
|
|
|
|
|
// NVIC_SystemReset();
|
|
|
|
|
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// err:
|
|
|
|
|
// config_buff_pos--;
|
|
|
|
|
// memcpy(config_buff, config_buff + 1, sizeof(config_buff) - 1);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 保存回路阻抗在flash中
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
void saveLoopImpedance(float *loopImpedance)
|
|
|
|
|
{
|
|
|
|
|
write_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 读取flash中的回路阻抗
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
void readLoopImpedance(float *loopImpedance)
|
|
|
|
|
{
|
|
|
|
|
read_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 保存放电量在flash中
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
void savetotalElectricityConsumption(float *totalElectricityConsumption)
|
|
|
|
|
{
|
|
|
|
|
write_Flash((uint8_t *)totalElectricityConsumption, totalElectricityConsumption_SAVE_addr, sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 读取flash中的放电量
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
void readtotalElectricityConsumption(float *totalElectricityConsumption)
|
|
|
|
|
{
|
|
|
|
|
read_Flash((uint8_t *)totalElectricityConsumption, totalElectricityConsumption_SAVE_addr, sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 保存充电量在flash中
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
void savetotalChargCapacity(float *totalChargCapacity)
|
|
|
|
|
{
|
|
|
|
|
write_Flash((uint8_t *)totalChargCapacity, totalChargCapacity_SAVE_addr, sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 读取flash中的充电量
|
|
|
|
|
* @param
|
|
|
|
|
*/
|
|
|
|
|
void readtotalChargCapacity(float *totalChargCapacity)
|
|
|
|
|
{
|
|
|
|
|
read_Flash((uint8_t *)totalChargCapacity, totalChargCapacity_SAVE_addr, sizeof(float));
|
|
|
|
|
}
|
|
|
|
|
|