// Copyright 2021:
//   JaiaRobotics LLC
// File authors:
//   Toby Schneider <toby@gobysoft.org>
//
//
// This file is part of the JaiaBot Project Binaries
// ("The Jaia Binaries").
//
// The Jaia Binaries are free software: you can redistribute them and/or modify
// them under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// The Jaia Binaries are distributed in the hope that they will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the Jaia Binaries.  If not, see <http://www.gnu.org/licenses/>.

syntax = "proto2";

import "goby/middleware/protobuf/app_config.proto";
import "goby/zeromq/protobuf/interprocess_config.proto";
import "goby/middleware/protobuf/udp_config.proto";
import "dccl/option_extensions.proto";
import "jaiabot/messages/motor.proto";

package jaiabot.config;

message LinuxHardwareConfig
{
    optional string data_disk_mountpoint = 10 [default = "/var/log"];

    optional float disk_low_available_percentage = 11 [default = 10];
    optional float disk_critical_available_percentage = 12 [default = 2];

    optional float ram_low_available_percentage = 20 [default = 10];
    optional float ram_critical_available_percentage = 21 [default = 1];

    // load per processor
    optional float high_load_factor = 30 [default = 0.9];
    optional float critical_load_factor = 31 [default = 5];

    optional string wireless_file = 40 [default = "/proc/net/wireless"];
    optional string wlan_interface = 41 [default = "wlan0"];
}

message NTPStatusConfig
{
    option (dccl.msg) = {
        unit_system: "si"
    };

    optional float high_offset_threshold = 10 [
        default = 10,
        (dccl.field).units = { prefix: "milli" base_dimensions: "T" }
    ];
    optional float high_jitter_threshold = 11 [
        default = 100,
        (dccl.field).units = { prefix: "milli" base_dimensions: "T" }
    ];
}

message HelmIVPStatusConfig
{
    option (dccl.msg) = {
        unit_system: "si"
    };
    optional int32 time_out_helm_status = 10 [default = 20];
}

message MotorStatusConfig
{
    option (dccl.msg) = {
        unit_system: "si"
    };

    optional int32 motor_rpm_report_timeout_seconds = 10 [default = 40];
    optional int32 motor_thermistor_report_timeout_seconds = 11 [default = 40];
    optional jaiabot.protobuf.MotorHarnessType motor_harness_type = 12 [default = NONE];

    optional string vehicle_db_path = 50 [default = "/var/log/jaiabot/db/vehicle.db"];
    optional string tail_serial_number = 51 [default = "unknown_serial_number"];
    optional string bot_vin = 52 [default = "unknown_vin"];
}

message ArduinoRecoveryConfig
{
    option (dccl.msg) = {
        unit_system: "si"
    };

    optional bool enable_auto_flash = 1 [default = true];
    optional int32 max_attempts = 3 [default = 3];
    optional string flash_script = 10 [default = "jaia_firm_arduino_flash.sh"];
}

message Health
{
    option (dccl.msg) = {
        unit_system: "si"
    };

    optional goby.middleware.protobuf.AppConfig app = 1;
    optional goby.zeromq.protobuf.InterProcessPortalConfig interprocess = 2;
    optional goby.middleware.protobuf.UDPPointToPointConfig udp_config = 3;

    optional bool auto_restart = 10 [default = true];
    optional int32 auto_restart_timeout = 11
        [default = 20, (dccl.field).units = { base_dimensions: "T" }];
    optional int32 auto_restart_init_grace_period = 12
        [default = 60, (dccl.field).units = { base_dimensions: "T" }];

    optional bool ignore_powerstate_changes = 20 [default = false];
    optional bool check_helm_ivp_status = 21 [default = true];
    optional bool is_in_sim = 23 [default = false];
    optional bool test_hardware_in_sim = 24 [default = false];

    optional LinuxHardwareConfig linux_hw = 30;
    optional NTPStatusConfig ntp = 40;
    optional HelmIVPStatusConfig helm = 41;
    optional MotorStatusConfig motor = 42;
    optional ArduinoRecoveryConfig arduino_recovery = 43;
}
