/*
 * AMS_HighLevel.h
 *
 *  Created on: 20.07.2022
 *      Author: max
 */

#ifndef INC_AMS_HIGHLEVEL_H_
#define INC_AMS_HIGHLEVEL_H_

#include "ADBMS_Abstraction.h"
#include "ADBMS_CMD_MAKROS.h"
#include "ADBMS_LL_Driver.h"
#include "can.h"
#include "TMP1075.h"
#include "can-halal.h"
#include "errors.h"
#include "stm32f3xx_hal.h"
#include <stdint.h>

typedef enum {
  AMSDEACTIVE,
  AMSIDLE,
  AMSCHARGING,
  AMSIDLEBALANCING,
  AMSDISCHARGING,
  AMSWARNING,
  AMSERROR
} amsState;

extern amsState currentAMSState;
extern Cell_Module module;
extern uint32_t balancedCells;
extern uint8_t BalancingActive;
extern uint8_t stateofcharge;

extern uint8_t amserrorcode;
extern uint8_t amswarningcode;

extern uint8_t numberofCells;
extern uint8_t numberofAux;

void AMS_Init(SPI_HandleTypeDef* hspi);
void AMS_Loop();

uint8_t AMS_Balancing_Loop();
uint8_t AMS_Idle_Loop();
uint8_t AMS_Warning_Loop();
uint8_t AMS_Error_Loop();
uint8_t AMS_Charging_Loop();
uint8_t AMS_Discharging_Loop();

uint8_t writeWarningLog(uint8_t warningCode);
uint8_t writeErrorLog(uint8_t errorCode);
uint8_t integrateCurrent();

#endif /* INC_AMS_HIGHLEVEL_H_ */
