chargeController/APP/businessLogic/Src/parameter.c

409 lines
7.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "parameter.h"
#include "FM_TIM.h"
#include "FM_GPIO.h"
#include "capture.h"
config_parameter g_cfgParameter = {0};
static otherParameter g_otherParameter = {0};
static BOOL batteryState = FALSE; /* 有无电池(估计) */
static float dutyRatio; /* 占空比 */
/**
* @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)
{
if (DutyRatio > 0.9f) {
dutyRatio = 0.9f;
}
else if (DutyRatio < 0.05f) {
dutyRatio = 0.05f;
}
else {
dutyRatio = DutyRatio;
}
set_pwmDutyRatio(dutyRatio);
}
/**
* @brief 设置占空比大小为0同时关闭pwm下桥的输出
* @param
* @retval
*/
void setDutyRatioToZero(void)
{
EN_PWMOUT_Diseable();
dutyRatio = 0;
set_pwmDutyRatio(dutyRatio);
}
/**
* @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)
{
g_otherParameter.Discharg_Current = 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 * g_otherParameter.Output_Voltage;
}
/**
* @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 * g_otherParameter.Output_Voltage;
}
/**
* @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) {
/* 关闭充电 */
} else if (state == TRUE) {
/* 打开充电 */
}
}
/**
* @brief 得到放电状态
* @param
* @retval state 状态FALSE 关闭
*/
BOOL getDischargMosState(void)
{
if (g_cfgParameter.onlyPower) {
return readOnlyPowerOutputState();
} else {
return readOutputState();
}
}
/**
* @brief 得到软件版本号
* @param
* @retval softVer 软件版本号
*/
uint8_t *getVersionInformation(void)
{
return softVer;
}