// Water Linked Sonar 3D-15 protocol
syntax = "proto3";

package waterlinked.sonar.protocol;
import "google/protobuf/timestamp.proto";
import "google/protobuf/any.proto";

// Packet is the top-level message that is sent over the wire.
message Packet {
  google.protobuf.Any msg = 1; // Use .type_url to deserialize .value into one of the messages defined in this proto file
}

message Header {
  google.protobuf.Timestamp timestamp = 1;
  // Sequence id is a monotonically increasing number that identifies
  // each shot of the sonar. It can be used to detect missing shots or
  // to relate messages of different types to each other. The value
  // wraps around to 0 after reaching the maximum value.
  uint32 sequence_id = 2;
}

enum BitmapImageType {
  // Bitmap image showing for each x,y pixel the strength of the
  // strongest reflection
  SIGNAL_STRENGTH_IMAGE = 0;
  // Bitmap image showing a shaded representation of the depth in the
  // range image. The light source is behind and above the observer.
  // (This is experimental and may be removed in the future)
  SHADED_IMAGE = 1;
}

// BitmapImageGreyscale8 can be shown to user without further processing.
// Uncompressed, 8-bit color depth, greyscale.
message BitmapImageGreyscale8 {
  Header header = 1;
  float speed_of_sound = 2; // Configured speed of sound in water in m/s
  float range = 3; // Configured range in meters
  uint32 frequency = 4; // Configured imaging frequency in Hz
  BitmapImageType type = 5; // identifier for what is shown in the image
  uint32 width = 6;
  uint32 height = 7;
  float fov_horizontal = 8;
  float fov_vertical = 9;
  // image pixel data is organized in rows of pixels. Each row is
  // 'width' wide, and there are 'height' rows. Each pixel is an 8-bit
  // value that represents the intensity of the pixel, from 0 to 255
  bytes image_pixel_data = 10;
}

// RangeImage measures the distance to the strongest reflection
// for each pixel.
message RangeImage {
  Header header = 1;
  float speed_of_sound = 2; // Configured speed of sound in water in m/s
  float range = 3; // Configured range in meters
  uint32 frequency = 4; // Configured imaging frequency in Hz
  uint32 width = 5;
  uint32 height = 6;
  float fov_horizontal = 7; // in degrees
  float fov_vertical = 8; // in degrees
  float image_pixel_scale = 9;

  // image_pixel_data is organized in rows of pixels. Each row is
  // 'width' wide, and there are 'height' rows.
  // Each pixel is a 16-bit value that must be multiplied by
  // image_pixel_scale to obtain the distance in meters from the sonar
  // to the strongest reflection in that direction.
  repeated uint32 image_pixel_data = 10;
}