/*
 * BatteryManagement.h
 *
 *  Created on: 29.01.2022
 *      Author: max
 */

#ifndef INC_BATTERYMANAGEMENT_H_
#define INC_BATTERYMANAGEMENT_H_

#include "stm32f4xx_hal.h"

#define OVERVOLTAGE_LIMIT 55100 // 4.2V
#define UNDERVOLTAGE_LIMIT 34100 // 2.6V

#define OVERTEMPERATURE_LIMIT
#define UNDERTEMPERATURE_LIMIT

#define AMS_MONITORING 1
#define AMS_OV_ERROR 2
#define AMS_UV_ERROR 3
#define AMS_OT_ERROR 4
#define AMS_UT_ERROR 5
#define AMS_TIMEOUT_ERROR 6

uint8_t highestcell;
uint8_t lowestcell;

uint8_t highesttempsensor;
uint8_t lowesttempsensor;

uint32_t modulesumvoltage;

uint8_t ams_status;


void ams_init(UART_HandleTypeDef* uarthandle, DMA_HandleTypeDef* uartdma);

void ams_loop_discharging();
void ams_loop_charging();

void ams_check_cell_voltages();
void ams_check_cell_temperaures();

void ams_step_soc_model();
void ams_step_balancing_model();

void ams_fan_control();


#endif /* INC_BATTERYMANAGEMENT_H_ */
