syntax = "proto3";

package platform_iface;

// The doover device agent service definition.
service platformIface {

    rpc TestComms (TestCommsRequest) returns (TestCommsResponse) {}

    rpc getDI (getDIRequest) returns (getDIResponse) {}
    rpc getAI (getAIRequest) returns (getAIResponse) {}
    rpc startPulseCounter (pulseCounterRequest) returns (stream pulseCounterResponse) {}

    rpc getDO (getDORequest) returns (getDOResponse) {}
    rpc setDO (setDORequest) returns (setDOResponse) {}
    rpc scheduleDO (scheduleDORequest) returns (scheduleDOResponse) {}

    rpc getAO (getAORequest) returns (getAOResponse) {}
    rpc setAO (setAORequest) returns (setAOResponse) {}
    rpc scheduleAO (scheduleAORequest) returns (scheduleAOResponse) {}

    rpc getValue (getValueRequest) returns (getValueResponse) {}
    rpc setValue (setValueRequest) returns (setValueResponse) {}

    rpc getEvents (getEventsRequest) returns (getEventsResponse) {}
    rpc getDIEvents (getDIEventsRequest) returns (getDIEventsResponse) {}

    rpc getSystemStatus (getSystemStatusRequest) returns (getSystemStatusResponse) {}
    rpc getInputVoltage (getInputVoltageRequest) returns (getInputVoltageResponse) {}
    rpc getSystemPower (getSystemPowerRequest) returns (getSystemPowerResponse) {}
    rpc getTemperature (getTemperatureRequest) returns (getTemperatureResponse) {}
    rpc getIoTable (getIoTableRequest) returns (getIoTableResponse) {}
    // rpc getRtcTime (getRtcTimeRequest) returns (getRtcTimeResponse) {}
    rpc syncRtcTime (syncRtcTimeRequest) returns (syncRtcTimeResponse) {}
    // rpc getUptime (getUptimeRequest) returns (getUptimeResponse) {}
    // rpc getSystemInfo (getSystemInfoRequest) returns (getSystemInfoResponse) {}
    rpc getLocation (getLocationRequest) returns (getLocationResponse) {}
    
    rpc getShutdownImmunity (getShutdownImmunityRequest) returns (getShutdownImmunityResponse) {}
    rpc setShutdownImmunity (setShutdownImmunityRequest) returns (setShutdownImmunityResponse) {}

    rpc scheduleStartup (scheduleStartupRequest) returns (scheduleStartupResponse) {}
    rpc scheduleShutdown (scheduleShutdownRequest) returns (scheduleShutdownResponse) {}
    rpc reboot (rebootRequest) returns (rebootResponse) {}
    rpc shutdown (shutdownRequest) returns (shutdownResponse) {}

    rpc loadFirmware (loadFirmwareRequest) returns (loadFirmwareResponse) {}
    rpc loadBootloader (loadBootloaderRequest) returns (loadBootloaderResponse) {}
    rpc getFirmwareVersion (getFirmwareVersionRequest) returns (getFirmwareVersionResponse) {}

}

message ResponseHeader {
    bool success = 1;
    optional int32 response_code = 3;
    optional string message = 4;
}

message TestCommsRequest {
    string message = 1;
}

message TestCommsResponse {
    ResponseHeader response_header = 1;
    string response = 2;
}

message getDIRequest {
    repeated int32 di = 1;
}

message getDIResponse {
    ResponseHeader response_header = 1;
    repeated bool di = 2;
}

message getAIRequest {
    repeated int32 ai = 1;
}

message getAIResponse {
    ResponseHeader response_header = 1;
    repeated float ai = 2;
}

message pulseCounterRequest {
    int32 di = 1;
    string edge = 2;
}

message pulseCounterResponse {
    ResponseHeader response_header = 1;
    optional int32 di = 2;
    optional bool value = 3;
    optional float dt_secs = 4;
}

message getDORequest {
    repeated int32 do = 1;
}

message getDOResponse {
    ResponseHeader response_header = 1;
    repeated bool do = 2;
}

message setDORequest {
    repeated int32 do = 1;
    repeated bool value = 2;
}

message setDOResponse {
    ResponseHeader response_header = 1;
    repeated bool do = 2;
}

message scheduleDORequest {
    repeated int32 do = 1;
    repeated bool value = 2;
    optional float time_secs = 3;
}

message scheduleDOResponse {
    ResponseHeader response_header = 1;
    repeated bool do = 2;
    optional float time_secs = 3;
}

message getAORequest {
    repeated int32 ao = 1;
}

message getAOResponse {
    ResponseHeader response_header = 1;
    repeated float ao = 2;
}

message getIoTableRequest {}

message getIoTableResponse {
    ResponseHeader response_header = 1;
    optional string io_table = 2;
}

message setAORequest {
    repeated int32 ao = 1;
    repeated float value = 3;
}

message setAOResponse {
    ResponseHeader response_header = 1;
    repeated float ao = 2;
}

message scheduleAORequest {
    repeated int32 ao = 1;
    repeated float value = 2;
    optional float time_secs = 3;
}

message scheduleAOResponse {
    ResponseHeader response_header = 1;
    repeated float ao = 2;
    optional float time_secs = 3;
}

message getValueRequest {
    repeated string name = 1;
}

message getValueResponse {
    ResponseHeader response_header = 1;
    repeated string value = 2;
}

message setValueRequest {
    repeated string name = 1;
    repeated string value = 2;
}

message setValueResponse {
    ResponseHeader response_header = 1;
    repeated string value = 2;
}

message getSystemStatusRequest {}

message getSystemStatusResponse {
    ResponseHeader response_header = 1;
    optional float input_voltage = 2;
    optional float temperature = 3;
    optional string rtc_time = 4;
    optional float uptime = 5;
    optional string system_info = 6;
    optional int32 scheduled_startup_secs = 7;
    optional int32 scheduled_shutdown_secs = 8;
    optional float system_current = 9;
    optional float system_power = 10;
}

message getShutdownImmunityRequest {}

message getShutdownImmunityResponse {
    ResponseHeader response_header = 1;
    optional int32 immunity_secs = 2;
}

message setShutdownImmunityRequest {
    int32 immunity_secs = 1;
}

message setShutdownImmunityResponse {
    ResponseHeader response_header = 1;
    optional int32 immunity_secs = 2;
}

message scheduleStartupRequest {
    optional float time_secs = 1;
}

message scheduleStartupResponse {
    ResponseHeader response_header = 1;
    optional float time_secs = 2;
}

message scheduleShutdownRequest {
    optional float time_secs = 1;
}

message scheduleShutdownResponse {
    ResponseHeader response_header = 1;
    optional float time_secs = 2;
}

message rebootRequest {}

message rebootResponse {
    ResponseHeader response_header = 1;
}

message shutdownRequest {}

message shutdownResponse {
    ResponseHeader response_header = 1;
}


message getTemperatureRequest {}

message getTemperatureResponse {
    ResponseHeader response_header = 1;
    optional float temperature = 2;
}

message getInputVoltageRequest {}

message getInputVoltageResponse {
    ResponseHeader response_header = 1;
    optional float voltage = 2;
}

message getSystemPowerRequest {}

message getSystemPowerResponse {
    ResponseHeader response_header = 1;
    optional float power_watts = 2;
}

message loadFirmwareRequest {
    string url = 1;
    string target = 2;
}

message loadFirmwareResponse {
    ResponseHeader response_header = 1;
}

message loadBootloaderRequest {
    string url = 1;
}

message loadBootloaderResponse {
    ResponseHeader response_header = 1;
}

message getFirmwareVersionRequest {}

message getFirmwareVersionResponse {
    ResponseHeader response_header = 1;
    string version = 2;
}

message getLocationRequest {}

message getLocationResponse {
    ResponseHeader response_header = 1;
    optional float latitude = 2;
    optional float longitude = 3;
    optional float altitude_m = 4;
    optional float accuracy_m = 5;
    optional float speed_mps = 6;
    optional float heading_deg = 7;
    optional int32 sat_count = 8;
    optional string timestamp = 9;
}

message syncRtcTimeRequest {}
message syncRtcTimeResponse {
    ResponseHeader response_header = 1;
}

message EventDetail {
    int32 event_id = 1;                // Event ID
    string event = 2;                   // Event type
    int32 pin = 3;                     // Pin
    string value = 4;                   // Value
    int64 time = 5;                     // Timestamp
    optional bool cm4_online = 6;
}

message getEventsRequest {
    optional int64 events_from = 1;
}

message getEventsResponse {
    ResponseHeader response_header = 1;
    repeated EventDetail events = 2;
    optional bool events_synced = 3;
}

message getDIEventsRequest {
    int32 pin = 1;
    bool rising = 2;
    bool falling = 3;
    bool include_system_events = 4;
    optional int64 events_from = 5;
}

message getDIEventsResponse {
    ResponseHeader response_header = 1;
    repeated EventDetail events = 2;
    optional bool events_synced = 3;
}
