// @file sns_diag.proto
//
// Defines log messages used by the sensors diag service
//
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All rights reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.


syntax = "proto2";
import "nanopb.proto";
import "sns_std.proto";
import "sns_std_sensor.proto";
import "sns_client.proto";

// Batch Sample Type
enum sns_diag_batch_sample_type
{
  option (nanopb_enumopt).long_names = false;

  // This is the only sample in the batch
  SNS_DIAG_BATCH_SAMPLE_TYPE_ONLY = 0;

  // This is the first sample of the batch
  SNS_DIAG_BATCH_SAMPLE_TYPE_FIRST = 1;

  // This is an intermediate sample of the batch
  SNS_DIAG_BATCH_SAMPLE_TYPE_INTERMEDIATE = 2;

  // This is the last sample of the batch
  SNS_DIAG_BATCH_SAMPLE_TYPE_LAST = 3;
}

// Sensor Interrupts
enum sns_diag_interrupt
{
  option (nanopb_enumopt).long_names = false;

  // Interrupt caused by detection of a threshold being
  // exceeded
  SNS_DIAG_INTERRUPT_THRESHOLD = 0;

  // Interrupt caused by detection of movement of the device
  SNS_DIAG_INTERRUPT_MOTION    = 1;

  // Interrupt caused by detection of tilting of the device
  SNS_DIAG_INTERRUPT_TILT      = 2;

  // Interrupt caused by detection of free fall
  SNS_DIAG_INTERRUPT_FREE_FALL = 3;

  // Interrupt caused by detection of double-tap
  SNS_DIAG_INTERRUPT_DOUBLE_TAP= 4;

  // Interrupt caused by detection of acceleration shock
  SNS_DIAG_INTERRUPT_SHOCK     = 5;

  // Interrupt caused by CCD AMD
  SNS_DIAG_INTERRUPT_CCD_AMD   = 6;

  // Interrupt caused by CCD WALK
  SNS_DIAG_INTERRUPT_CCD_WALK  = 7;

  // Interrupt caused by CCD TILT
  SNS_DIAG_INTERRUPT_CCD_TILT  = 8;

  // Interrupt caused by CCD TE0
  SNS_DIAG_INTERRUPT_CCD_TE0   = 9;

  // Interrupt caused by CCD TE1
  SNS_DIAG_INTERRUPT_CCD_TE1   = 10;

  // Interrupt caused by CCD TE2
  SNS_DIAG_INTERRUPT_CCD_TE2   = 11;

  // Interrupt caused by CCD TE3
  SNS_DIAG_INTERRUPT_CCD_TE3   = 12;

  // Interrupt caused by CCD CD0
  SNS_DIAG_INTERRUPT_CCD_CD0   = 13;

  // Interrupt caused by CCD CD1
  SNS_DIAG_INTERRUPT_CCD_CD1   = 14;

  // Interrupt caused by CCD CD2
  SNS_DIAG_INTERRUPT_CCD_CD2   = 15;

  // Interrupt caused by CCD CD3
  SNS_DIAG_INTERRUPT_CCD_CD3   = 16;

  // Interrupt caused by CCD GBE
  SNS_DIAG_INTERRUPT_CCD_GBE1  = 17;

    // Interrupt caused by CCD GBE
  SNS_DIAG_INTERRUPT_CCD_GBE2  = 18;

  // Interrupt caused by CCD OGV0
  SNS_DIAG_INTERRUPT_CCD_OGV0  = 19;

  // Interrupt caused by CCD OGV1
  SNS_DIAG_INTERRUPT_CCD_OGV1  = 20;

  // Interrupt caused by CCD OGV2
  SNS_DIAG_INTERRUPT_CCD_OGV2  = 21;

  // Interrupt caused by CCD OGV3
  SNS_DIAG_INTERRUPT_CCD_OGV3  = 22;

  // Interrupt caused by CCD TE4
  SNS_DIAG_INTERRUPT_CCD_TE4   = 23;

  // Interrupt caused by CCD primary accel ppe
  SNS_DIAG_INTERRUPT_CCD_PPE   = 24;

  // Interrupt caused by CCD gyro ppe
  SNS_DIAG_INTERRUPT_CCD_PPE1  = 25;

  // Interrupt caused by CCD secondary accel ppe
  SNS_DIAG_INTERRUPT_CCD_PPE2  = 26;
}

// Opaque Payload
// This message defines the fields used to log an undefined payload
message sns_diag_opaque_payload
{
  required bytes payload = 1;
}

// Batch Sample
// This message defines the fields used to log batched data.
message sns_diag_batch_sample
{
  // Indicates if the sample is the first, intermediate, last or only
  // sample of a batch
  required sns_diag_batch_sample_type sample_type = 1 [default = SNS_DIAG_BATCH_SAMPLE_TYPE_ONLY];

  // Timestamp of the sensor state data sample
  required fixed64 timestamp = 2;

  // Sensor state data sample
  repeated float sample = 3;

  // Data status.
  required sns_std_sensor_sample_status status = 4 [default = SNS_STD_SENSOR_SAMPLE_STATUS_UNRELIABLE];
}

// Sensor State Hardware Interrupt Log Packet
// This message defines the fields used to log sensor state information
// pertaining to hardware interrupts
// This message is used as the payload field of sns_diag_sensor_log
message sns_diag_sensor_state_interrupt
{
  // Type of sensor hardware interrupt
  required sns_diag_interrupt interrupt = 1;

  // Timestamp when the interrupt occurred
  required fixed64 timestamp = 2;
}

// Sensor State Raw
// This message defines the fields used to log sensor state information
// pertaining to raw uncalibrated physical sensor data.
// This message is used as the payload field of sns_diag_sensor_log
message sns_diag_sensor_state_raw
{
  repeated sns_diag_batch_sample sample = 1;
}

// Client API Response Message
message sns_diag_client_resp_msg
{
  // The error response sent to the client
  required sns_std_error error = 1;
}

// Client API log packet
// This message defines the fields to log all
// Request, Response and Event messages at the Client API
// This message is used as the payload field of sns_diag_sensor_log
message sns_diag_client_api_log
{
  // Client ID identifies the client connection
  required fixed64 client_id = 1;

  // Data type of the source sensor
  required string src_sensor_type = 2;

  // The Client API log packet payload
  oneof client_api_log_payload
  {
    // Client API Request message as defined in sns_client.proto
    sns_client_request_msg request_payload = 100;

    // Client API Event message as defined in sns_client.proto
    sns_client_event_msg event_payload = 101;

    // Client API Response message as defined in sns_diag.proto
    sns_diag_client_resp_msg resp_payload = 102;
  }
}

// Sensor API log packet
// This message defines the fields to log all Request and
// Event messages at the Sensor API
// This message is used as the payload field of sns_diag_sensor_log
message sns_diag_sensor_api_log
{
  // The message id of the message being logged
  required fixed32 message_id = 1;

  // Timestamp associated with this message
  required fixed64 timestamp = 2;

  // Data stream associated with this message
  optional fixed64 stream_id = 3;

  // The Sensor API log packet payload
  oneof sensor_api_log_payload
  {
    // Sensor API Event message containing sensor specific event message
    // as defined in the sensor's proto api file
    sns_diag_opaque_payload opaque_payload = 100;

    // Sensor API Request message as defined in sns_std.proto
    sns_std_request request_payload = 101;
  }
}

// Sensor log packet
// This message defines the fields to log all sensor specific
// messages. This includes Sensor API messages, Client API messages,
// HW Interrupt messages, Sensor State messages
message sns_diag_sensor_log
{
  // Log ID for the log packet
  required fixed32 log_id = 1;

  // Timestamp when log packet.was generated
  required fixed64 timestamp = 2;

  // Sensor UID for the log packet
  required sns_std_suid suid = 3;

  // Data type provided by the Sensor UID
  required string sensor_type = 4;

  // In case of client_api payload :
  // Instance ID of the Client Manager Sensor to which this
  // message was passed to or obtained from
  // In case of opaque, sensor_api and sensor_state payloads:
  // Instance ID of the Sensor to which this
  // message was passed to or obtained from
  required fixed64 instance_id = 5;

  // The log packet payload
  oneof sensor_log_payload
  {
    // Sensor specific Sensor State Algo message
    sns_diag_opaque_payload opaque_payload = 100;

    // Sensor API message
    sns_diag_sensor_api_log sensor_api_payload = 101;

    // Client API message
    sns_diag_client_api_log client_api_payload = 102;

    // Sensor State Raw message
    sns_diag_sensor_state_raw sensor_state_raw_payload = 103;

    // Sensor State Hardware Interrupt message
    sns_diag_sensor_state_interrupt sensor_state_interrupt_payload = 104;
  }
}

// Sensor Instance Mapping Log Packet
// This message defines the fields used to log sensor instance mapping
// information.  This message is used as the payload field of sns_diag_fw_log
message sns_diag_instance_map_log
{
  // The instance id of the source sensor instance
  required fixed64 src_instance_id = 1;

  // Array of destination Sensor Instance IDs or Sensor IDs that the
  // source sensor instance is feeding to.
  // If no destination instance ids are specified it signifies
  // deletion of the source instance
  repeated fixed64 dest_instance_id = 2;

  // Array of data stream ids that the
  // source sensor instance is feeding to
  repeated fixed64 stream_id = 3;
}

// Island mode states
enum sns_diag_island_state
{
  option (nanopb_enumopt).long_names = false;

  // In Island mode
  SNS_DIAG_ISLAND_STATE_IN_ISLAND_MODE = 0;

  // Not in Island Mode
  SNS_DIAG_ISLAND_STATE_NOT_IN_ISLAND_MODE = 1;

  // Island mode disabled
  SNS_DIAG_ISLAND_STATE_ISLAND_DISABLED = 2;
}

// Island mode transition Log Packet
// This message defines the fields used to log
// transitions into and out of island mode
//
// This log packet is generated each time the system transitions into or out
// of island mode or when island mode is disabled or when triggered by
// a request to the diag sensor
//
// This message is used as the payload field of sns_diag_fw_log
// This message is legacy. It is replaced with 'message sns_diag_island_log'
message sns_diag_island_transition_log
{
  // Timestamp of the transition
  //
  // When logpacket is triggered, this timestamp will retain
  // the timestamp when the current state became effective.
  required fixed64 timestamp = 1;

  // Island state after transition is completed
  required sns_diag_island_state island_state = 2;

  // User defined cookie
  // Used by test scripts to identify logs triggered
  // by messages sent to the SSC
  optional fixed64 cookie = 3;

  // Total time system spent in island since device boot(micro seconds)
  optional fixed64 total_island_time = 4;
}
// This message is used to log system island states
message sns_diag_island_tx_log
{
  // Island state after transition is completed
  optional sns_diag_island_state island_state = 1;

  // User defined cookie
  // Used by test scripts to identify logs triggered
  // by messages sent to the SSC
  optional fixed64 cookie = 2;

  // Total time system spent in island since device boot(micro seconds)
  optional fixed64 total_island_time = 3;
}

// This message is used to log sensors' internal island states
message sns_diag_island_debug_log
{
  // previous state of island transition
  optional fixed32 previous_island_state = 1;

  // current state of island transition
  optional fixed32 current_island_state = 2;

  // caller symbols causing island transition
  repeated fixed32 callers = 3;
}

// This message is used to log the island transitions.
// The transitions includes both - system transitions into or out
// of island mode or when island mode is disabled or when triggered by
// a request to the diag sensor as well as debug transtions that capture
// the internal island states
//
// This message is used as the payload field of sns_diag_fw_log
message sns_diag_island_log
{
  // timestamp of island transition or debug transition
  optional fixed64 timestamp = 1;

  oneof sns_diag_island_log_payloads
  {
    sns_diag_island_tx_log log_payload = 2;

    sns_diag_island_debug_log dbg_log_payload = 3;
  }
}


// Island exit vote Log Packet
// This message defines the fields used to log vote for island mode exits.
//
// This log packet is generated at each call to island_exit()
message sns_diag_island_exit_vote_log
{
  // Timestamp
  required fixed64 timestamp = 1;

  // SUID of the Sensor responsible for the vote
  optional sns_std_suid sensor = 2;
}

// Heap IDs
enum sns_diag_heap_id
{
  option (nanopb_enumopt).long_names = false;

  // Primary Heap
  SNS_DIAG_HEAP_ID_HEAP_MAIN = 0;

  // Island Heap
  SNS_DIAG_HEAP_ID_HEAP_ISLAND = 1;

  // PRAM Heap
  SNS_DIAG_HEAP_ID_HEAP_PRAM = 2;

  // EVENT Heap
  SNS_DIAG_HEAP_ID_HEAP_EVENT = 3;

  // BATCH Heap
  SNS_DIAG_HEAP_ID_HEAP_BATCH = 4;

  // Event buffer
  SNS_DIAG_HEAP_ID_EVENT_BUFFER = 100;
}

// Memory status Log Packet
// This message defines the fields used to log the memory utilization
// This log packet is generated when a request is sent to the diag sensor
message sns_diag_mem_utilization_log
{
  // Timestamp
  required fixed64 timestamp = 1;

  // Heap ID
  required sns_diag_heap_id heap_id = 2;

  // Total Memory
  required fixed32 total_memory = 3;

  // Used Memory
  required fixed32 used_memory = 4;

  // User defined cookie
  // Used by test scripts to identify logs triggered
  // by messages sent to the SSC
  optional fixed64 cookie = 5;
}

// Event Service status Log Packet
// This message defines the fields used to log the memory utilization and
// other statistics from the Event Service.
// Used only for SW debug; *not guaranteed to be backward compatible*
// This log packet is generated when a request is sent to the diag sensor
message sns_diag_event_service_log
{
  // Timestamp
  required fixed64 timestamp = 1;

  // User defined cookie
  // Used by test scripts to identify logs triggered
  // by messages sent to the SSC
  optional fixed64 cookie = 2;

  message heap_stats
  {
    enum sns_event_service_heap_id
    {
      SNS_EVENT_SERVICE_HEAP_ID_ISLAND = 0;
      SNS_EVENT_SERVICE_HEAP_ID_MAIN = 1;
    }
    // Heap ID
    required sns_event_service_heap_id heap_id = 1;

    // Total memory available in heap (in blocks)
    required fixed32 total_memory = 2;

    // Current memory consumption (in blocks)
    required fixed32 used_memory = 3;

    // Maximum memory consumption since last log packet (in blocks)
    required fixed32 max_memory = 4;

    // Total clusters available
    required fixed32 total_clusters = 5;

    // Current number of clusters in use
    required fixed32 used_clusters = 6;

    // Maximum in-use clusters since last log packet
    required fixed32 max_clusters = 7;

    // Number of allocation failues since the last DIAG log packet
    // If Island will result in island exit; else causes dropped samples
    required fixed32 alloc_failures = 8;

    // Largest event allocation since the last DIAG log packet (in bytes)
    required fixed32 max_size = 9;
  }
  repeated heap_stats stats = 3;
}

// Framework log packet
// This message defines the fields to log all framework messages. This
// includes memory, island, instance mapping messages.
message sns_diag_fw_log
{
  // Log ID for the log packet
  required fixed32 log_id = 1;

  // Timestamp when log packet.was generated
  required fixed64 timestamp = 2;

  // The log packet payload
  oneof fw_log_payload
  {
    // Sensor Instance Map message
    sns_diag_instance_map_log instance_map_payload = 100;

    // Sensor Island Mode (Legacy)
    sns_diag_island_transition_log island_mode_payload = 101;

    // Sensors Island Exit vote
    // NOT SUPPORTED YET.
    sns_diag_island_exit_vote_log island_exit_vote_payload = 102;

    // Sensors Memory Utilization
    sns_diag_mem_utilization_log memory_utilization_payload = 103;

    // Event Service status log
    sns_diag_event_service_log event_service_payload = 104;

    // Island related logs
    sns_diag_island_log island_payload = 105;
  }
}

