syntax = "proto3";

/*
 This container message is send from EVerest to MCU and may contain any allowed message in that direction.
*/
message EverestToMcu {
 oneof payload {
    // Needs to remain the same to allow firmware updates of older versions
    FirmwareUpdate firmware_update = 16;

    SetOutputVoltageCurrent set_output_voltage_current = 50;

    // Other IDs are 100+ to avoid compatibility issues with older firmware versions
    KeepAlive keep_alive = 100;
    uint32 pwm_duty_cycle = 103; // in 0.01 %, 0 = State F, 10000 = X1
    bool allow_power_on = 104;
    bool reset = 105;
    bool enable = 106;
    bool replug = 107;
  }
}

/*
 This container message is send from MCU to EVerest and may contain any allowed message in that direction.
*/
message McuToEverest {
 oneof payload {
  // Needs to remain the same to allow firmware updates of older versions
  KeepAliveLo keep_alive = 3;

  // Other IDs are 100+ to avoid compatibility issues with older firmware versions
  ResetReason reset = 101;
  CpState cp_state = 102;
  bool relais_state = 103; // false: relais are off, true: relais are on
  ErrorFlags error_flags = 104;
  Telemetry telemetry = 105;
 }
}

enum CpState {
  STATE_A = 0;
  STATE_B = 1;
  STATE_C = 2;
  STATE_D = 3;
  STATE_E = 4;
  STATE_F = 5;
}

message SetOutputVoltageCurrent {
  float voltage = 1;
  float current = 2;
}

message ErrorFlags {
  bool diode_fault = 1;
  bool cp_signal_fault = 6;
}

enum ResetReason {
  USER = 0;
  WATCHDOG = 1;
}

message KeepAliveLo {
  uint32 time_stamp = 1;
  uint32 hw_type = 2;
  uint32 hw_revision = 3;
  uint32 protocol_version_major = 4;
  uint32 protocol_version_minor = 5;
  string sw_version_string = 6;
  float hwcap_max_current = 7;
  float hwcap_min_current = 8;
  uint32 hwcap_max_phase_count = 9;
  uint32 hwcap_min_phase_count = 10;
  bool supports_changing_phases_during_charging = 11;
}

message KeepAlive {
  uint32 time_stamp = 1;
  uint32 hw_type = 2;
  uint32 hw_revision = 3;
  string sw_version_string = 6;
}

message Telemetry {
  float cp_hi = 1;
  float cp_lo = 2;
  float pwm_dc = 3;
  float relais_on = 4;
  float voltage = 5;
}

message FirmwareUpdate {
  bool invoke_rom_bootloader = 1;
}