syntax = "proto3";

option csharp_namespace = "Leica.Spider.SpiderBasics";

package spider.spiderbasics;

import "SpiderRealTimeProduct.proto";
import "SpiderUniqueId.proto";
import "JobId.proto";
import "GpsTime.proto";
import "SatCount.proto";

message MacConfiguration {
    spider.basics.SpiderUniqueId master_station_id = 1;
    int32 cluster_id = 2;
    repeated spider.basics.SpiderUniqueId auxiliary_station_ids = 3;
}

message SpiderRtkRoverStatus {
    /**
     * position quality of GPS measurements
     */
    enum PositionQuality {
        /**
         * fix not available or invalid
         */
        INVALID = 0;
        /**
         * navigated position (GPS SPS mode; fix valid)
         */
        N = 1;
        /**
         * precise navigated position (differential Code)
         */
        PN = 2;
        /**
         * GPS PPS mode; fix valid
         */
        PN2 = 3;
        /**
         * Realtime kinematic; system used in RTK mode with fixed integers
         */
        HPN = 4;
        /**
         * float RTK. Satellite system used in RTK mode; floating integers
         */
        PN_F = 5;
    }

    enum StatusCode {
        //
        // Classical Status Updates from within Spider

        /**
         * Connection is started (channel is instantiated)
         */
        CONNECTION_STARTED = 0;
        /**
         * Send correction is started
         */
        SEND_CORRECTION_STARTED = 1;
        /**
         * User authenticated -> only used in CConnectionLogXMLFiles (backwards compatibility)
         */
        USER_AUTHENTICATED = 2;
        /**
         * Connection ended by user
         */
        CONNECTION_ENDED_BY_USER = 3;
        /**
         * Connection ended by operator
         */
        CONNECTION_ENDED_BY_OPERATOR = 4;
        /**
         * Connection ended by accident
         */
        CONNECTION_ENDED_BY_ACCIDENT = 5;
        /**
         * Wrong or invalid NMEA position received from rover
         */
        WRONG_NMEA_POSITION = 6;
        /**
         * Valid NMEA position received from rover.
         */
        VALID_NMEA_POSITION = 7;
        /**
         * status of reference station changed.
         */
        REF_STATUS_CHANGED = 8;
        /**
         * Rover moved to another station/cell.
         */
        STATION_SWITCHED = 9;
        /**
         * Switched to backup product (unused; only for backwards compatibility)
         */
        SWITCHED_TO_BACKUP_PRODUCT = 10;
        /**
         * Switched to default product  (unused; only for backwards compatibility)
         */
        SWITCHED_TO_DEFAULT_PRODUCT = 11;
        /**
         * Receiving NMEA messages is started
         */
        SEND_NMEA_MESSAGES_STARTED = 12;
        /**
         * status of Rover changed
         */
        ROVER_STATUS_CHANGED = 13;
        /**
         * Reject Rover due to out of range distance to site(s)
         */
        ROVER_REJECTED_DUE_TO_DISTANCE = 14;
        /**
         * Fallback to single site due to short baseline length to master site.
         */
        SWITCHED_TO_SINGLE_SITE_PRODUCT_DUE_TO_DIST = 15;
        /**
         * Fallback to single site due to network not available
         */
        SWITCHED_TO_SINGLE_SITE_PRODUCT_DUE_TO_NW_STATE = 16;
        /**
         * a new Auto cell was found
         */
        TRIGGERED_AUTO_CELL_CHANGE = 17;
        /**
         * A new Reference Site was found (Nearest Site Product)
         */
        TRIGGERED_REF_SITE_CHANGE = 18;
        /**
         * Connection closed by spider because no heartbeat was received
         */
        CONNECTION_ENDED_BY_HEARTBEAT_CHECK = 19;
        /**
         * Fall forward to network solution
         */
        FALL_FORWARD_TO_NETWORK = 20;
        /**
         * Fallback to single site due to Rover outside network
         */
        SWITCHED_TO_SINGLE_SITE_PRODUCT_DUE_TO_OUTSIDE_NW = 21;

        //
        // Rover Error Logs (Numeric codes aligned with old style logging server)

        // Special Disconnect Reasons
        REJECTED_NOT_AUTHORIZED = 1000;
        REJECTED_AUTH_MODE_NOT_SUPPORTED = 1001;
        REJECTED_GPUID = 1002;
        REJECTED_INCORRECT_PASSWORD = 1003;
        REJECTED_INVALID_COORDINATE = 1004;
        REJECTED_NO_COORDINATE = 1005;
        REJECTED_NO_HOST_AND_USER_INFO_RECEIVED = 1006;
        REJECTED_NO_HOST_INFO_RECEIVED = 1007;
        REJECTED_NO_AUTHENTICATION_OR_MOUNTPOINT_RECEIVED = 1008;
        REJECTED_NO_MOUNTPOINT_RECEIVED = 1009;
        REJECTED_NO_PHONE_NUMBER_RECEIVED = 1010;
        REJECTED_OUTSIDE_REGION = 1011;
        REJECTED_SBC_FALLBACK = 1012;
        REJECTED_TOO_MANY_AUTHORIZATION_REQUESTS = 1013;
        REJECTED_TOO_MANY_CONCURRENT_CONNECTION_REQUESTS = 1014;
        REJECTED_TOO_MANY_CONCURRENT_CONNECTIONS = 1015;
        REJECTED_UNKNOWN_USER = 1016;
        REJECTED_USER_EXPIRED = 1017;
        REJECTED_USER_NAME_NOT_RECEIVED = 1018;
        REJECTED_SMART_ROVER_INVALID_HANDSHAKE_DATA = 1019;
        REJECTED_SMART_ROVER_NO_SMART_NET = 1020;
        REJECTED_SMART_ROVER_NOT_AUTHORIZED = 1021;
        REJECTED_TOO_MANY_CONCURRENT_SUBSCRIPTION_CONNECTIONS = 1022;
        REJECTED_GPUID_OR_GPGGA = 1023;
        REJECTED_INVALID_OR_OUT_OF_RANGE_COORDINATE = 1024;
        REJECTED_CONNECTION_OVERLOAD = 1025;
        REJECTED_DENIAL_OF_SERVICE = 1026;
        REJECTED_TCP_ACCEPT_FAILED = 1027;
        REJECTED_DEVICE_AUTH_CODE_NO_DEVICE_CODE_RECEIVED = 1028;
        REJECTED_DEVICE_AUTH_CODE_UNKNOWN_SENSOR_ID = 1029;
        REJECTED_INVALID_SENSOR_CODE = 1030;
        REJECTED_INVALID_SENSOR_FORMAT = 1031;
        REJECTED_INVALID_SENSOR_HANDSHAKE_DATA = 1032;

        // Special events happening during a connection.
        SPECIAL_FALLBACK_TO_SS_BELOW_MINIMUM_DISTANCE = 1100;
        SPECIAL_FALLBACK_TO_SS_NETWORK_FIXING = 1101;
        SPECIAL_FALLBACK_TO_SS_ROVER_OUTSIDE_NETWORK = 1102;
        SPECIAL_FALL_FORWARD_TO_NETWORK_SOLUTION = 1103;
        SPECIAL_NO_DATA_AVAILABLE = 1104;
        SPECIAL_NO_HEARTBEAT = 1105;
        SPECIAL_NO_DATA_YOU_ARE_OUTSIDE = 1106;
        SPECIAL_NO_DATA_LEFT_NETWORK_BOUNDARIES = 1107;
        // Already part of classical spider events, kept to indicate old status.
        // SEND_CORRECTION_STARTED = 1108;
        SPECIAL_TOO_MANY_CONCURRENT_CONNECTIONS = 1109;
        SPECIAL_TOO_MANY_CONCURRENT_SUBSCRIPTION_CONNECTIONS = 1110;
        SPECIAL_TOO_MANY_CONCURRENT_CONNECTION_REQUESTS = 1111;
        SPECIAL_INVALID_OR_OUT_OF_RANGE_COORDINATE_ROVER_POSITION_CHANGED = 1112;
        SPECIAL_INVALID_OR_OUT_OF_RANGE_COORDINATE_FIND_NEAREST_SITE = 1113;
        SPECIAL_INVALID_OR_OUT_OF_RANGE_COORDINATE_FIND_NEAREST_CELL = 1114;
        SPECIAL_NO_DATA_AVAILABLE_MAX_DISTANCE_CHECK = 1115;
        SPECIAL_TERMINATED_UNEXPECTEDLY = 1116;
        SPECIAL_NO_DATA_AVAILABLE_NO_MASTER_SITE_DATA = 1117;
        SPECIAL_NO_DATA_AVAILABLE_NOT_ENOUGH_AUX_SITES = 1118;
        SPECIAL_NO_DATA_AVAILABLE_CELL_CREATION_FAILED = 1119;
        SPECIAL_NO_DATA_AVAILABLE_SINGLE_SITE_NOT_STREAMING = 1120;
        SPECIAL_NO_DATA_AVAILABLE_NEAREST_ACTIVE_SITE_NOT_FOUND = 1121;
        SPECIAL_NO_DATA_AVAILABLE_NEAREST_INACTIVE_SITE_NOT_FOUND = 1122;
        SPECIAL_NO_DATA_AVAILABLE_MAX_DISTANCE_CHECK_TO_MASTER = 1123;
        SPECIAL_NO_DATA_AVAILABLE_NO_CELL_FOUND = 1124;
        SPECIAL_NO_DATA_AVAILABLE_NO_SITES_OR_CLUSTERS_DEFINED = 1125;
        SPECIAL_REMOVED_BY_OPERATOR = 1126;
        SPECIAL_NO_RESIDUAL_VALUES_FOUND_ROVER_OUTSIDE_GRID = 1127;
        SPECIAL_ROVER_OUTSIDE_AREA_OF_VALIDITY = 1128;
        SPECIAL_NO_DATA_AVAILABLE_PREVENT_SEARCH = 1129;

        // General Error Events from within Spider are negative (those should normally not happen and rather indicate
        // a bug in Spider where timestamps are not filled as per expectation)

        /**
         * Only used to indicate that the status code was not initialized.
         */
        ERROR_NO_STATUS = -5;
        /**
         * only used if ConnLog receives wrong start time
         */
        ERROR_IN_START_TIME = -4;
        /**
         * only used if ConnLog receives wrong time of first correction
         */
        ERROR_IN_SEND_FIRST_CORRECTION_TIME = -3;
        /**
         * only used if ConnLog receives wrong end time
         */
        ERROR_IN_END_TIME = -2;
        /*+
         * only used if ConnLog receives wrong epoch time
         */
        ERROR_IN_EPOCH_TIME = -1;
    }

    spider.rtkbasics.JobId job_id = 1;
    uint32 product_id = 2;
    uint32 rover_user_id = 3;
    uint32 rover_sbc_user_id = 4;
    string rover_user_name = 5;
    /**
     * NMEA $GPUID GUID1: Rover identifier; written in SAPOS General Log File for NTRIP connections
     */
    string rover_guid1 = 6;
    /**
     * NMEA $GPUID GUID2: Rover identifier; written in SAPOS General Log File for NTRIP connections
     */
    string rover_guid2 = 7;

    uint32 rover_credential_id = 8;
    string rover_credential_name = 9;

    string rover_user_company_name = 10;
    string rover_user_detail = 11;
    string rover_client_host_info = 12;
    string subscription_id = 13;

    bool ftp_push_detailed_connection_log = 14;

    bool rover_user_general_log = 15;
    bool rover_user_detailed_log = 16;
    bool rover_user_nmea_log = 17;
    bool rover_user_connection_log_disabled = 18;

    uint32 heartbeat_disconnect_time = 19;
    spider.rtkbasics.MjdTime epoch_time = 20;
    bool single_site_fallback_active = 21;

    PositionQuality position_quality = 22;
    spider.rtkbasics.MjdTimeAndTickCount start_of_connection = 23;
    spider.rtkbasics.MjdTimeRelative first_correction_time = 24;
    spider.rtkbasics.MjdTimeRelative end_of_connection = 25;
    spider.rtkbasics.MjdTimeRelative last_received_data_time = 26;

    spider.rawconverter.SatCount sat_count_rover = 27;
    float hdop = 28;

    double rover_latitude = 29;
    double rover_longitude = 30;
    double rover_height = 31;

    double vrs_latitude = 32;
    double vrs_longitude = 33;
    double vrs_height = 34;

    string user_agent = 35;

    spider.rawconverter.SatCount sat_count_used_ref = 36;
    spider.rawconverter.SatCount sat_count_used_fkp = 37;

    float latency_msecs = 38;

    spider.rawconverter.SatCount sat_count_fixed_ref = 39;

    spider.spiderbasics.SpiderRealTimeProduct.MessageType message_type = 40;

    StatusCode status_code = 41;
    string verbose_status_change_information = 42;

    int32 ref_station_id = 43;
    int32 vrs_id = 44;
    int32 nmea_ref_station_id = 45;

    spider.basics.SpiderUniqueId unique_station_id = 46;

    MacConfiguration mac_configuration = 47;

    // IMPORTANT: When the RTK Rover Status is extended with information it must be ensured that the
    // data forwarding to the Logging Server is as complete as possible. Missing data can lead to inconsistencies
    // and incorrect Detailed Logs being produced for customers.
    //
    // For most events only a RtkJob is available (+ some data being currently produced). If the status is extended
    // potentially also the RtkJob needs to be extended to ensure data is forwarded.
    // CRtkJob::FillToErrorLog should then be adjusted accordingly.
}
