
// satnogs-proto: Protobuf schemas for SatNOGS
// Copyright (C) 2025, Libre Space Foundation <https://libre.space>
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it 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
// this program. If not, see <https://www.gnu.org/licenses/>.

edition = "2023";

package satnogsproto;

/* Coding messages */
message ReedSolomon {
  uint32 block_len = 1;
  uint32 message_len = 2;
}

message GolayCode {
  uint32 block_len = 1;
  uint32 message_len = 2;
  uint32 distance = 3;
}

message TurboCode { // Placeholder for turbo codes
}

message LDPCCode { // Placeholder for LDPC codes
}

message Coding {
  oneof coding {
    ReedSolomon rs = 1;
    GolayCode golay = 2;
    TurboCode turbo = 3;
    LDPCCode ldpc = 4;
  }
}

/* Scrambler message */
message Scrambler {
  uint64 mask = 1;
  uint64 seed = 2;
  uint32 order = 3;
  bool msb = 4 [default = true];
  bool self_synchronizing = 5;
}

/* CRC message */
message CRC {
  uint32 size_in_bits = 1;
  bytes polynomial = 2;
  bytes init_value = 3;
  bytes final_xor = 4;
  bool reflect_input = 5;
  bool reflect_output = 6;
}

/* Framing messages */
message GenericFraming {
  Coding coding = 1;
  Scrambler scrambler = 2;
  CRC crc = 3;
  bytes whitening_polynomial = 4;
}

message AX25 {
  bool diff_encoding = 1;
  bool invert = 2;
  GenericFraming generic_options = 3;
}

message AX100Mode5 {
  bytes preamble = 1;
  bytes sync_word = 2;
  GenericFraming generic_options = 3;
}

message AX100Mode6 {
  bool ax25_scrambling = 1;
  GenericFraming generic_options = 2;
}

message IEEE802_15_4 {
  bytes preamble = 1;
  uint32 preamble_length = 2;
  bytes sync_word = 3;
  uint32 max_frame_length = 4;
  GenericFraming generic_options = 5;
}

message Framing {
  oneof framing {
    AX25 ax25 = 1;
    AX100Mode5 ax100_mode5 = 2;
    AX100Mode6 ax100_mode6 = 3;
    IEEE802_15_4 ieee802_15_4 = 4;
  }
}

message Filter {
  // Filter type placeholder
}

/* Modulation messages */
message AFSK {
  double baudrate = 1;
  uint32 modulation_index = 2;
  double mark_tone = 3;
  double space_tone = 4;
}

message APT {
  double audio_low_cutoff_freq = 1;
  double audio_high_cutoff_freq = 2;
}

message FSK {
  double baudrate = 1;
  double modulation_index = 2;
  Filter filter = 3;
}

message CW {
  double wpm = 1;
  double wpm_deviation = 2;
  string header = 3;
  double tone_freq = 4;
}

message FM {
  double audio_bandwidth = 1;
  double deemphasis = 2;
}

message PSK {
  double baudrate = 1;
  uint32 modulation_index = 2;
}

message Modulation {
  oneof modulation {
    AFSK afsk = 1;
    APT apt = 2;
    FSK fsk = 3;
    CW cw = 4;
    FM fm = 5;
    PSK psk = 6;
  }
}

// Transmission mode holds information about the modulation, the framing and
// the transmission system
message TransmissionMode {
  enum TransmissionName {
    UNKNOWN = 0;
    AFSK = 1;
    AHRPT = 2;
    APT = 3;
    BPSK = 4;
    PMT_A3 = 5; // removed modulation part
    CERTO = 6; // check
    CW = 7;
    DATV = 8; // check
    DBPSK = 9;
    DOKA = 10; // check
    DPSK = 11;
    DSB = 12; // check
    DSTAR = 13; //check
    DUV = 14; // check
    DVB_S2 = 15;
    FM = 16;
    FM_N = 17; // No need to be different than FM i think
    FSK = 18;
    FSK_4 = 19;
    FT8 = 20;
    GFSK = 21;
    GMSK = 22;
    HRPT = 23;
    LORA = 24;
    LRPT = 25;
    LSB = 26;
    MSK = 27;
    OFDM = 28; // This is multiplexing i don't get why we have it like that. It comes from Es'hail2
    OQPSK = 29;
    PSK = 30;
    PSK_31 = 31;
    QPSK = 32;
    QPSK_31 = 33;
    SIDLOC = 34;
    SQPSK = 35;
    SSTV = 36;
    USB = 37;
    WSJT = 38;
  }
  TransmissionName name = 1;
  Modulation modulation = 2;
  Framing framing = 3;
}

// The transmitter message
message Transmitter {
  string name = 1;
  double center_freq = 2;
  double occupied_bandwidth = 3;
  double drift = 4;
  uint32 clock_drift = 5;
  repeated TransmissionMode transmission_mode = 6;
  bool audible = 7;
}
