# Code architecture PCDU
- Everything in the main loop
## State machine
3 Main States
- MPPT allways on; Code already exists -> Translation to C++
### Powerup
- wait()
- powerPointTracking()
### IDLE
- checkAllAdc()
- evaluateBattery Voltage() -> State change possible!
- checkOvercurrents()
- powerPointTracking()
- checkHealthOfOBC()
- checkHighPriorityCommands()
### CRITICAL
- ensureEverything is off()
- checkAdcForBattery()
- evaluateBatteryVoltage() -> State change possible!
- powerPointTracking()
### State change PowerupLeave
- checkAdcForBattery()
- checkBatteryVoltage() -> State change to critical possible!
- startOBC()
- startTT&C S-Band()
- enableOBCInterrupt()
### State change IdleToCritical
- TurnEverythingOff()
- disableOBCInterrupt()
## OBC Interrupt
- storeTimeOfInterupt()
- sendFirstElementOfQueueIfAny()
## Data layout
### Send Queue
- 2 priority queues (Either ring buffer or list)
- high priority allways takes precedence over low
#### high
e.g Overcurrent or temperature events
#### low
e.g. Answering data requests, telemetry
### Sensor data
- One big Sensor data object (global variable)
- Wrapping the sensor objects and converts the values
### Use RAII!!!
- for critical regions