/**
 * Copyright © 2016-2026 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
syntax = "proto3";

option java_package = "org.thingsboard.server.gen.transport.coap";
option java_outer_classname = "DeviceInfoProtos";

message ProtoRuntime
{

  /* Up-time in seconds (since reset).                                                                                          *
   * Status: In use [06.00 - LATEST]                                                                                            */
  uint32 up_time = 1;

  /* Message counters (since reset).                                                                                            *
   * 1st item - Confirmable message attempts counter.                                                                           *
   * 2nd item - Non-confirmable message attempts counter.                                                                       *
   * 3rd item - Successful message counter.                                                                                     *
   * Status: In use [06.00 - LATEST]                                                                                            */
  repeated uint32 message_counters = 2;

  /* MCU temperature in Celsius.                                                                                                *
   * Status: In use [06.00 - LATEST]                                                                                            */
  sint32 mcu_temperature = 3;

  /* Battery voltage in mV.                                                                                                     *
   *   - [0:65534] - Battery voltage in millivolts                                                                              *
   *   - 65535 - No measurement                                                                                                 *
   * Status: In use [07.00.00 - LATEST] / Previously as min_battery_voltage [06.00 - 06.xx.xx]                                  */
  uint32 battery_voltage = 4;

  /* MCU temperature in Celsius when minimum battery voltage was reached.                                                       *
   * Status: Deprecated [06.00 - 06.xx.xx]                                                                                      */
  sint32 min_battery_mcu_temperature = 5;

  /* Battery reset timestamp in seconds since 1st of January 1970 (epoch time).                                                 *
   * Status: Deprecated [06.00 - 06.xx.xx]                                                                                      */
  uint32 battery_reset_timestamp = 6;

  /* Maximum MCU temperature in Celsius.                                                                                        *
   * Status: In use [06.00 - LATEST]                                                                                            */
  sint32 max_mcu_temperature = 7;

  /* Minimum MCU temperature in Celsius                                                                                         *
   * Status: In use [06.00 - LATEST]                                                                                            */
  sint32 min_mcu_temperature = 8;

  /* Device's runtime errors.                                                                                                   *
   * Up to 20 error items supported.                                                                                            *
   * Status: In use [06.02 - LATEST]                                                                                            */
  repeated uint32 runtime_errors = 9;

  /* Number of sensor resets (since power-up).                                                                                  *
   * Status: In use [06.21.00 - LATEST]                                                                                         */
  uint32 reset_counter = 10;
}

message ProtoUpdateInfo
{

  /* Timestamp of the last update check in seconds since 1st of January 1970 (epoch time).                                      *
   * Status: In use [06.00 - LATEST]                                                                                            */
  uint32 timestamp = 1;

  /* Status of the last update check:                                                                                           *
   *   - 1 - No update check                                                                                                    *
   *   - 2 - No error                                                                                                           *
   *   - 3 - UDP socekt error                                                                                                   *
   *   - 4 - Invalid hash                                                                                                       *
   *   - 5 - Missing packet                                                                                                     *
   *   - 6 - Invalid data                                                                                                       *
   *   - 7 - Sending timeout                                                                                                    *
   *   - 8 - No software to update                                                                                              *
   *   - 9 - Sending unexpected error                                                                                           *
   *   - 10 - Unexpected error                                                                                                  *
   * Status: In use [06.00 - LATEST]                                                                                            */
  uint32 status = 2;
}

enum ModemType
{

  /* Invalid value.                                                                                                             */
  MODEM_TYPE_UNSPECIFIED = 0;

  /* Quectel BC66 modem.                                                                                                        */
  MODEM_TYPE_BC66 = 1;

  /* Quectel BC66-NA modem.                                                                                                     */
  MODEM_TYPE_BC66NA = 2;

  /* Uses a shared modem from another sensor.                                                                                   */
  MODEM_TYPE_SHARED_MODEM = 3;

  /* Quectel BC660 modem.                                                                                                       */
  MODEM_TYPE_BC660 = 4;
}

enum ModemFirmwareVersion
{
  /* Invalid value.                                                                                                             */
  MODEM_FIRMWARE_VERSION_UNSPECIFIED = 0;

  /* Unable to read firmware version from device.                                                                               */
  MODEM_FIRMWARE_VERSION_READING_ERROR = 1;

  /* Unknown firmware version.                                                                                                  */
  MODEM_FIRMWARE_VERSION_UNKNOWN = 2;

  /* BC660KGLAAR01A05_01.002.01.002.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V1 = 3;

  /* BC660KGLAAR01A05_01.200.01.200.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V2 = 4;

  /* BC660KGLAAR01A05_01.202.01.202.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V3 = 5;

  /* BC660KGLAAR01A05_01.203.01.203.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V4 = 6;

  /* BC660KGLAAR01A05_01.204.01.204.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V5 = 7;

  /* BC660KGLAAR01A05_01.205.01.205.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V6 = 8;

  /* BC660KGLAAR01A05_01.301.01.301.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V7 = 9;

  /* BC660KGLAAR01A05_01.303.01.303.                                                                                            */
  MODEM_FIRMWARE_VERSION_BC660_V8 = 10;
}

message ProtoModem
{

  /* Modem type.                                                                                                                *
   * Status: In use [06.00 - LATEST]                                                                                            */
  ModemType type = 1;

  /* Modem runtime parameters.                                                                                                  *
   * For BC66 modem (34 parameters):                                                                                            *
   *   - 1st item - sc_EARFCN. Range: [0:262143]. Unknown value: -1                                                             *
   *   - 2nd item - sc_EARNFCN_offset. Range: [0:4] mapped to [-2, -1, -0.5, 0, 1]. Unknown value: -1                           *
   *   - 3rd item - sc_PCI. Range: [0:502]. Unknown value: -1                                                                   *
   *   - 4th item - sc_Cell_Id. Range: [1:268435456]. Unknown value: 0                                                          *
   *   - 5th item - sc_RSRP [dBm]. Range: [-140:-44]. Unknown value: 0                                                          *
   *   - 6th item - sc_RSRQ [dB]. Range: [-20:-3]. Unknown value: 0                                                             *
   *   - 7th item - sc_RSSI [dBm]. Range: [-110:-3] Unknown value: 0                                                            *
   *   - 8th item - sc_SINR [dB]. Range: [-10:30]. Unknown value: 31                                                            *
   *   - 9th item - sc_Band. Range: [see module supported bands]. The current serving cell band. Unknown value: -1              *
   *   - 10th item - sc_TAC. Range: [0:65536]. Unknown value: -1                                                                *
   *   - 11th item - sc_ECL. Range: [0:2]. Unknown value: -1                                                                    *
   *   - 12th item - sc_TX_PWR [0.1dBm]. Range [-440:230]. Unknown value: -1000                                                 *
   *   - 13th item - OP_MODE. Range: [0:3]. Unknown value: -1                                                                   *
   *   - 14th item - nc_EARFCN. Range: [0:262143]. Unknown value: -1                                                            *
   *   - 15th item - nc_EARNFCN_offset. Range: [0:4] mapped to [-2, -1, -0.5, 0, 1]. Unknown value: -1                          *
   *   - 16th item - nc_PCI. Range: [0:502]. Unknown value: -1                                                                  *
   *   - 17th item - nc_RSRP [dBm]. Range: [-140:-44]. Unknown value: 0                                                         *
   *   - 18th item - RLC_UL_BLER. Range: [0:100]. Unknown value: -1                                                             *
   *   - 19th item - RLC_DL_BLER. Range: [0:100]. Unknown value: -1                                                             *
   *   - 20th item - MAC_UL_BLER. Range: [0:100]. Unknown value: -1                                                             *
   *   - 21th item - MAC_DL_BLER. Range: [0:100]. Unknown value: -1                                                             *
   *   - 22th item - MAC_UL_TOTAL_BYTES. Range: [0:2147483647]. Unknown value: -1                                               *
   *   - 23th item - MAC_DL_TOTAL_BYTES. Range: [0:2147483647]. Unknown value: -1                                               *
   *   - 24th item - MAC_UL_total_HARQ_Tx. Range: [0:2147483647]. Unknown value: -1                                             *
   *   - 25th item - MAC_DL_total_HARQ_Tx. Range: [0:2147483647]. Unknown value: -1                                             *
   *   - 26th item - MAC_UL_HARQ_re_Tx. Range: [0:2147483647]. Unknown value: -1                                                *
   *   - 27th item - MAC_DL_HARQ_re_Tx. Range: [0:2147483647]. Unknown value: -1                                                *
   *   - 28th item - RLC_UL_tput. Range: [0:2147483647]. Unknown value: -1                                                      *
   *   - 29th item - RLC_DL_tput. Range: [0:2147483647]. Unknown value: -1                                                      *
   *   - 30th item - MAC_UL_tput. Range: [0:2147483647]. Unknown value: -1                                                      *
   *   - 31th item - MAC_DL_tput. Range: [0:2147483647]. Unknown value: -1                                                      *
   *   - 32th item - sleep_duration [0.1s]. Range: [0:2147483647]. Unknown value: -1                                            *
   *   - 33th item - Rx_time [0.1s]. Range: [0:2147483647]. Unknown value: -1                                                   *
   *   - 34th item - Tx_time [0.1s]. Range: [0:2147483647]. Unknown value: -1                                                   *
   * For BC660 modem (22 parameters):                                                                                           *
   *   - 1st item - sc_EARFCN. Range: [0:262143]. Unknown value: -1                                                             *
   *   - 2nd item - sc_EARNFCN_offset. Range: [0:21] mapped to                                                                  *
   *                   [Invalid, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, -0.5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9].                  *
   *                   Unknown value: -1                                                                                        *
   *   - 3rd item - sc_PCI. Range: [0:503]. Unknown value: -1                                                                   *
   *   - 4th item - sc_Cell_Id. Range: [1:268435456]. Unknown value: 0                                                          *
   *   - 5th item - sc_RSRP [dBm]. Range: [-140:-44]. Unknown value: 0                                                          *
   *   - 6th item - sc_RSRQ [dB]. Range: [-20:-3]. Unknown value: 0                                                             *
   *   - 7th item - sc_RSSI [dBm]. Range: [-110:-3] Unknown value: 0                                                            *
   *   - 8th item - sc_SINR [dB]. Range: [-10:30]. Unknown value: 31                                                            *
   *   - 9th item - sc_Band. Range: [see module supported bands]. The current serving cell band. Unknown value: -1              *
   *   - 10th item - sc_TAC. Range: [0:65536]. Unknown value: -1                                                                *
   *   - 11th item - sc_ECL. Range: [0:2]. Unknown value: -1                                                                    *
   *   - 12th item - sc_TX_PWR [dBm]. Range [-45:23]. Unknown value: 128                                                        *
   *   - 13th item - OP_MODE. Range: [0:3] mapped to [In-band same PCI, In-band different PCI, Guard band, Stand alone].        *
   *                 Unknown value: -1                                                                                          *
   *   - 14th item - nc_EARFCN. Range: [0:262143]. Unknown value: -1                                                            *
   *   - 15th item - nc_PCI. Range: [0:503]. Unknown value: -1                                                                  *
   *   - 16th item - nc_RSRP [dBm]. Range: [-140:-44]. Unknown value: 0                                                         *
   *   - 17th item - nc_RSRQ [dBm]. Range: [-140:-44]. Unknown value: 0                                                         *
   *   - 18th item - sleep_duration [0.1s]. Range: [0:2147483647]. Unknown value: -1                                            *
   *   - 19th item - Rx_time [0.1s]. Range: [0:2147483647]. Unknown value: -1                                                   *
   *   - 20th item - Tx_time [0.1s]. Range: [0:2147483647]. Unknown value: -1                                                   *
   *   - 21st item - PLMN_state. Range: [0:3] mapped to [No PLMN, Searching, Selected, Unknown]. Unknown value: 3               *
   *   - 22nd item - select_PLMN. Range: [100:999999]. Unknown value: -1                                                        *
   * For shared modem client (4 parameters):                                                                                    *
   *   - 1st item - RSRP [dBm]. Range: [-140:-44]. Unknown value: 0                                                             *
   *   - 2nd item - RSRQ [dB]. Range: [-20:-3]. Unknown value: 0                                                                *
   *   - 3rd item - RSSI [dBm]. Range: [-110:-3] Unknown value: 0                                                               *
   *   - 4th item - SINR [dB]. Range: [-10:30]. Unknown value: 31                                                               *
   * Status: In use [06.00 - LATEST]                                                                                            */
  repeated sint32 parameters = 2;

  /* Integrated Circuit Card Identifier (ICCID) of the inserted/soldered SIM card.                                              *
   * String up to 22 characters:                                                                                                *
   * A string containing only the special character 0x7F (DEL) indicates that the SIM card is not detected.                     *
   * Status: In use [06.07.04/06.09.09/06.10.10/06.11.09/06.12.06/06.13.00/06.21.00 - LATEST]                                   */
  string sim_card_identification = 3;

  /* Modem firmware version.                                                                                                    *
   * Status: In use [06.20.05/06.21.00 - LATEST]                                                                                */
  ModemFirmwareVersion firmware_version = 4;

  /* Modem identification:                                                                                                      *
   *   - IMEI (International Mobile Equipment Identity) of the modem                                                            *
   *   - Serial number of the most recently used modem-sharing sensor                                                           *
   * String up to 15 characters.                                                                                                *
   * Status: In use [07.00.00 - LATEST]                                                                                         */
  string modem_identification = 5;

  /* Modem statistics.                                                                                                          *
   * 1st item - Number of transmissions since the last device information message. Undefined value: 0.                          *
   * 2nd item - Time in seconds since the last device information message. Undefined value: 0.                                  *
   * 3rd item - Total time in the power saving mode, in seconds. Undefined value: 0.                                            *
   * 4th item - Total time in the active state in seconds. Undefined value: 0.                                                  *
   * Status: In use [07.00.00 - LATEST]                                                                                         */
  repeated uint32 modem_statistics = 6;
}

message ProtoDeviceInfo
{

  /* RESERVED FIELDS ---------------------------------------------------------------------------------------------------------- */

  reserved 2,4,5,6,7,8,9,10,11,12;

  /* DEVICE STATUS FIELDS ----------------------------------------------------------------------------------------------------- */

  /* Serial number of the device.                                                                                               *
   * Length: 6 bytes.                                                                                                           *
   * Status: In use [07.00.00 - LATEST] / Previously as serial_num [06.00 - 06.xx.xx]                                           */
  bytes serial_number = 1;

  /* DEVICE INFORMATION FIELDS ------------------------------------------------------------------------------------------------ */

  /* Software version (excluding LTS).                                                                                          *
   * Example: 1546 -> 0x060A -> SW version 06.10                                                                                *
   * Status: In use [06.00 - LATEST]                                                                                            */
  uint32 sw_version = 3;

  /* Software commit ID and LTS version.                                                                                        *
   * String of 7 characters:                                                                                                    *
   *   - Commit ID (examples: "fa02cd0" means the beginning of the commit ID "fa02cd0") [06.00 - 06.06.xx]                      *
   *   - LTS version and commit ID (examples: "0bdd23f" means LTS version 11 and the beginning of the commit ID "dd23f")        *
         [06.07.00 - LATEST]                                                                                                    *
   * Status: In use [06.00 - LATEST]                                                                                            */
  string commit_id = 15;

  /* Device runtime information.                                                                                                *
   * Status: In use [06.00 - LATEST]                                                                                            */
  ProtoRuntime runtime_info = 13;

  /* Memory statistics:                                                                                                         *
   * 1st item - Status of the non-volatile storage:                                                                             *
   *   - 0 - Non-volatile storage works properly                                                                                *
   *   - 1 - Non-volatile storage has some corrupt packets. Memory is read-only                                                 *
   *   - 2 - Non-volatile storage is corrupted. Memory is unavailable                                                           *
   * 2nd item - Timestamp of the end of collecting statistics in seconds since 1st of January 1970 (epoch time).                *
                Undefined value: 4294967295.                                                                                    *
   * 3rd item - Capacity of the memory in bytes.                                                                                *
   * 4th item - Used space in bytes.                                                                                            *
   * 5th item - Size of invalid (outdated) packets in bytes.                                                                    *
   * 6th item - Size of corrupt packets in bytes.                                                                               *
   * 7th item - Number of valid packets.                                                                                        *
   * 8th item - Number of invalid (outdated) packets.                                                                           *
   * 9th item - Number of corrupt packets.                                                                                      *
   * 10th item - Number of all samples for channel 1 (valid packets).                                                           *
   * 11th item - Number of all samples for channel 2 (valid packets).                                                           *
   * 12th item - Number of all samples for channel 3 (valid packets).                                                           *
   * 13th item - Number of all samples for channel 4 (valid packets).                                                           *
   * 14th item - Number of all samples for channel 5 (valid packets).                                                           *
   * 15th item - Number of all samples for channel 6 (valid packets).                                                           *
   * 16th item - Timestamp of the first binary measurement in seconds since 1st of January 1970 (epoch time).                   *
   *             Undefined value: 4294967295.                                                                                   *
   * 17th item - Timestamp of the last binary measurement in seconds since 1st of January 1970 (epoch time).                    *
   *             Undefined value: 4294967295.                                                                                   *
   * 18th item - Timestamp of the last binary measurement marked as sent, in seconds since 1st of January 1970 (epoch time).    *
   *             Undefined value: 4294967295.                                                                                   *
   * 19th item - Timestamp of the first continuous measurement in seconds since 1st of January 1970 (epoch time).               *
   *             Undefined value: 4294967295.                                                                                   *
   * 20th item - Timestamp of the last continuous measurement in seconds since 1st of January 1970 (epoch time).                *
   *             Undefined value: 4294967295.                                                                                   *
   * 21th item - Timestamp of the last continuous measurement marked as sent, in seconds since 1st of January 1970 (epoch time).*
   *             Undefined value: 4294967295.                                                                                   *
   * 22th item - NvM write counter.                                                                                             *
   * Status: In use [06.02 - LATEST]                                                                                            */
  repeated uint32 memory_statistics = 17;

  /* Last update check information.                                                                                             *
   * Status: In use [06.08.00 - LATEST]                                                                                         */
  ProtoUpdateInfo last_update_info = 18;

  /* Modem information.                                                                                                         *
   * Only used if the sensor has a modem.                                                                                       *
   * Status: In use [06.00 - LATEST]                                                                                            */
  ProtoModem modem = 14;

  /* SERVER COMMUNICATION FIELDS ---------------------------------------------------------------------------------------------- */

  /* Cloud token.                                                                                                               *
   * Can be empty, set to any user-defined value, or hold device IMEI.                                                          *
   * String up to 36 characters.                                                                                                *
   * This field is only sent during server communication.                                                                       *
   * Status: In use [06.00 - LATEST]                                                                                            */
  string cloud_token = 16;

  /* Enclosure tamper alert:                                                                                                    *
   *   - 0 - Inactive                                                                                                           *
   *   - 1 - Active (enclosure opened)                                                                                          *
   *   - 2 - Inactive, was active (enclosure closed)                                                                            *
   * The transition from 'Inactive, was active' to 'Inactive' occurs after the alert has been successfully sent to the server   *
   * or the user has reset the alert via Bluetooth.                                                                             *
   * This field is only sent during server communication.                                                                       *
   * Status: In use [07.00.01 - LATEST]                                                                                         */
  uint32 enclosure_tamper_alert = 19;
}