chargeController/APP/businessLogic/Src/parameter.c

475 lines
8.5 KiB
C
Raw Normal View History

2024-12-06 09:38:25 +00:00
#include "parameter.h"
#include "FM_TIM.h"
#include "FM_GPIO.h"
#include "capture.h"
2024-12-06 09:38:25 +00:00
config_parameter g_cfgParameter = {0};
static otherParameter g_otherParameter = {0};
static BOOL batteryState = FALSE; /* 有无电池(估计) */
static float dutyRatio; /* 占空比 */
2024-12-24 06:43:20 +00:00
static uint8_t mosTemperState = mosTemperStart; /* mos管温度状态 */
2024-12-11 09:51:48 +00:00
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
2024-12-24 06:43:20 +00:00
static timeInfo lastTime = {0}; /* 上次读取充放电量参数的时间 */
/**
* @brief
* @param
* @retval batteryState电池状态 FALSE
* TRUE
*/
BOOL getBatteryState(void)
{
return batteryState;
}
/**
* @brief
* @param state
* @retval
*
*/
void setBatteryState(BOOL state)
{
if (state != TRUE && state != FALSE) {
return;
}
batteryState = state;
}
/**
* @brief
* @param
* @retval dutyRatio
*/
float getDutyRatio(void)
{
return dutyRatio;
}
/**
* @brief ,01
* @param dutyRatio
* @retval
*/
void setDutyRatio(float DutyRatio)
{
2024-12-24 06:43:20 +00:00
if (DutyRatio > 0.95f) {
dutyRatio = 0.95f;
}
else if (DutyRatio < 0.05f) {
dutyRatio = 0.05f;
}
else {
dutyRatio = DutyRatio;
2024-12-24 06:43:20 +00:00
}
set_pwmDutyRatio(dutyRatio);
}
/**
* @brief 0pwm下桥的输出
* @param
* @retval
*/
void setDutyRatioToZero(void)
{
EN_PWMOUT_Diseable();
dutyRatio = 0;
set_pwmDutyRatio(dutyRatio);
}
2024-12-11 09:51:48 +00:00
/**
* @brief mos管温度状态
* @param
* @retval mosTemperState mos管温度状态
*/
uint8_t getMosTemperState(void)
{
return mosTemperState;
}
/**
* @brief mos管温度状态
* @param state mos管状态
* @retval
*/
void setMosTemperState(uint8_t state)
{
if (state == mosTemperStart || state == mosTemperEnd || state == mosTemperStop) {
mosTemperState = state;
}
}
/**
* @brief
* @param
* @retval checkImpedanceState FALSE
* TRUE
*/
BOOL getCheckImpedanceState(void)
{
return checkImpedanceState;
}
/**
* @brief
* @param
* @retval
*
*/
void setCheckImpedanceState(void)
{
checkImpedanceState = TRUE;
}
2024-12-24 06:43:20 +00:00
/**
* @brief
* @param
* @retval
*
*/
void setLastTime(timeInfo time)
{
lastTime = time;
}
/**
* @brief
* @param
* @retval
*
*/
timeInfo getLastTime(void)
{
return lastTime;
}
/**
* @brief
* @param
* @retval
*/
float getBatteryVoltage(void)
{
return g_otherParameter.Battery_Voltage;
}
/**
* @brief
* @param
* @retval
*/
void setBatteryVoltage(void)
{
g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
- getChargBatteryCurrent() * g_cfgParameter.loopImpedance;
}
/**
* @brief
* @param
* @retval
*/
float getOutputVoltage(void)
{
return g_otherParameter.Output_Voltage;
}
/**
* @brief
* @param
* @retval
*/
void setOutputVoltage(void)
{
g_otherParameter.Output_Voltage = get_PV_VOLT_OUT() ;
}
/**
* @brief
* @param
* @retval
*/
float getChargCurrent(void)
{
return g_otherParameter.Charg_Current;
}
/**
* @brief
* @param
* @retval
*/
void setChargCurrent(void)
{
g_otherParameter.Charg_Current = get_CHG_CURR();
}
/**
* @brief
* @param
* @retval
*/
float getDischargCurrent(void)
{
return g_otherParameter.Discharg_Current;
}
/**
* @brief
* @param
* @retval
*/
void setDischargCurrent(void)
{
g_otherParameter.Discharg_Current = get_DSG_CURR();
}
/**
* @brief
* @param
* @retval
*/
float getInputVoltage(void)
{
return g_otherParameter.Input_Voltage;
}
/**
* @brief
* @param
* @retval
*/
void setInputVoltage(void)
{
2024-12-11 09:51:48 +00:00
g_otherParameter.Input_Voltage = get_PV_VOLT_IN1();
}
/**
* @brief
* @param
* @retval
*/
float getSolarOpenCircuitVoltage(void)
{
return g_otherParameter.Solar_Open_Circuit_Voltage;
}
/**
* @brief
* @param
* @retval
*/
void setSolarOpenCircuitVoltage(void)
{
g_otherParameter.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
}
/**
* @brief mos管的温度
* @param
* @retval mos管的温度
*/
float getHighSideMosTemperature(void)
{
return g_otherParameter.HighSideMos_Temperature;
}
/**
* @brief mos管温度
* @param
* @retval
*/
void setHighSideMosTemperature(void)
{
g_otherParameter.HighSideMos_Temperature = get_MOSFET_Temper();
}
/**
* @brief
* @param
* @retval
*/
float getSolarInCircuitVoltage(void)
{
return g_otherParameter.Solar_In_Circuit_Voltage;
}
/**
* @brief
* @param
* @retval
*/
void setSolarInCircuitVoltage(void)
{
g_otherParameter.Solar_In_Circuit_Voltage = get_PV1_VOLT_IN();
}
/**
* @brief
* @param
* @retval
*/
float getTotalElectricityConsumption(void)
{
return g_otherParameter.totalElectricityConsumption;
}
/**
* @brief
* @param
* @retval
*/
void setTotalElectricityConsumption(void)
{
g_otherParameter.totalElectricityConsumption += g_otherParameter.Discharg_Current / 3600000.0f;
}
/**
* @brief
* @param totalPower
* @retval
*/
void totalElectricityConsumptionInt(float totalPower)
{
g_otherParameter.totalElectricityConsumption = totalPower;
}
/**
* @brief
* @param
* @retval
*/
float getTotalChargCapacity(void)
{
return g_otherParameter.totalChargCapacity;
}
/**
* @brief
* @param
* @retval
*/
void setTotalChargCapacity(void)
{
g_otherParameter.totalChargCapacity += g_otherParameter.Charg_Current / 3600000.0f;
}
/**
* @brief
* @param totalPower
* @retval
*/
void totalChargCapacityInt(float totalPower)
{
g_otherParameter.totalChargCapacity = totalPower;
}
/**
* @brief
* @param
* @retval
*/
float getSOC(void)
{
return g_otherParameter.SOC;
}
/**
* @brief
* @param
* @retval
*/
void setSOC(void)
{
}
/**
* @brief
* @param
* @retval
*/
int getMPPT_Mode(void)
{
return g_otherParameter.MPPT_Mode;
}
/**
* @brief
* @param
* @retval
*/
void setMPPT_Mode(int MPPT_Mode)
{
g_otherParameter.MPPT_Mode = MPPT_Mode;
}
/**
* @brief
* @param
* @retval
*/
float getChargBatteryCurrent(void)
{
return (g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current);
}
/**
* @brief
* @param
* @retval
*/
BOOL getChargMosState(void)
{
if (getDutyRatio() > 0 && getDutyRatio() < 1) {
return TRUE;
} else {
return FALSE;
}
}
/**
* @brief
* @param state FALSE
* @retval
*/
void setChargMosState(BOOL state)
{
if (state == FALSE) {
/* 关闭充电 */
2024-12-24 06:43:20 +00:00
stopChargWork();
} else if (state == TRUE) {
/* 打开充电 */
2024-12-24 06:43:20 +00:00
beginChargWork();
}
}
/**
* @brief
* @param
* @retval state FALSE
*/
BOOL getDischargMosState(void)
{
if (g_cfgParameter.onlyPower) {
return readOnlyPowerOutputState();
} else {
return readOutputState();
2024-12-11 09:51:48 +00:00
}
}
2024-12-06 09:38:25 +00:00
/**
* @brief
* @param
* @retval softVer
*/
uint8_t *getVersionInformation(void)
{
return softVer;
}
2024-12-06 09:38:25 +00:00