swift
dto.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_CORE_AFV_DTO_H
7 #define SWIFT_CORE_AFV_DTO_H
8 
9 #include <QByteArray>
10 #include <QJsonObject>
11 #include <QString>
12 #include <QUuid>
13 
14 #include "msgpack.hpp"
15 
16 namespace swift::core::afv
17 {
21  {
29 
32  {
33  QJsonObject json;
34  json["channelTag"] = channelTag;
35  json["aeadReceiveKey"] = QString(aeadReceiveKey);
36  json["aeadTransmitKey"] = QString(aeadTransmitKey);
37  json["hmacKey"] = QString(hmacKey);
38  return json;
39  }
40 
43  {
45 
46  dto.channelTag = json.value("channelTag").toString();
47  dto.aeadReceiveKey = QByteArray::fromBase64(json.value("aeadReceiveKey").toString().toLocal8Bit());
48  dto.aeadTransmitKey = QByteArray::fromBase64(json.value("aeadTransmitKey").toString().toLocal8Bit());
49  dto.hmacKey = QByteArray::fromBase64(json.value("hmacKey").toString().toLocal8Bit());
50  return dto;
51  }
52  };
53 
56  {
59  QString addressIpV4; // Example: 123.123.123.123:50000
60  QString addressIpV6; // Example: 123.123.123.123:50000
63 
66  {
67  QJsonObject json;
68  json["addressIpV4"] = addressIpV4;
69  json["addressIpV6"] = addressIpV6;
70  json["channelConfig"] = channelConfig.toJson();
71  return json;
72  }
73 
76  {
78  dto.addressIpV4 = json.value("addressIpV4").toString();
79  dto.addressIpV6 = json.value("addressIpV6").toString();
80  dto.channelConfig = CryptoDtoChannelConfigDto::fromJson(json.value("channelConfig").toObject());
81  return dto;
82  }
83  };
84 
87  {
90  // DataServerConnectionDataDto DataServer;
92  bool isValid = false;
94 
97  {
98  QJsonObject json;
99  json["voiceserverauthdatadto"] = VoiceServer.toJson();
100  // json["dataserverauthdatadto"] = DataServer.toJson();
101  return json;
102  }
103 
106  {
109  // dto.DataServer = DataServerConnectionDataDto::fromJson(json.value("dataServer").toObject());
110  dto.isValid = true;
111  return dto;
112  }
113  };
114 
117  {
120  quint16 id {};
121  quint32 frequencyHz {};
122  double LatDeg = 0.0;
123  double LonDeg = 0.0;
124  double HeightMslM = 0.0;
125  double HeightAglM = 0.0;
127  MSGPACK_DEFINE(id, frequencyHz, LatDeg, LonDeg, HeightMslM, HeightAglM)
128 
129 
131  {
132  QJsonObject json;
133  json["ID"] = id;
134  json["Frequency"] = static_cast<int>(frequencyHz);
135  json["LatDeg"] = LatDeg;
136  json["LonDeg"] = LonDeg;
137  json["HeightMslM"] = HeightMslM;
138  json["HeightAglM"] = HeightAglM;
139  return json;
140  }
141 
143  static TransceiverDto fromJson(const QJsonObject &json)
144  {
145  TransceiverDto dto;
146  dto.id = static_cast<quint16>(json.value("id").toInt());
147  dto.frequencyHz = static_cast<quint32>(json.value("frequency").toInt());
148  dto.LatDeg = json.value("latDeg").toDouble();
149  dto.LonDeg = json.value("lonDeg").toDouble();
150  dto.HeightMslM = json.value("heightMslM").toDouble();
151  dto.HeightAglM = json.value("heightAglM").toDouble();
152  return dto;
153  }
154  };
155 
157  struct StationDto
158  {
163  quint32 frequencyHz {};
164  quint32 frequencyAliasHz {};
166 
168  static StationDto fromJson(const QJsonObject &json)
169  {
170  StationDto dto;
171  dto.id = QUuid(json.value("id").toString());
172  dto.name = json.value("name").toString();
173  dto.frequencyHz = static_cast<quint32>(json.value("frequency").toInt());
174  dto.frequencyAliasHz = static_cast<quint32>(json.value("frequencyAlias").toInt());
175  return dto;
176  }
177  };
178 
181  {
184  static QByteArray getDtoName() { return "HeartbeatDto"; }
185  static QByteArray getShortDtoName() { return "H"; }
187 
188  std::string callsign;
189  MSGPACK_DEFINE(callsign)
190  };
191 
194  {
197  static QByteArray getDtoName() { return "HeartbeatAckDto"; }
198  static QByteArray getShortDtoName() { return "HA"; }
200 
201  MSGPACK_DEFINE()
202  };
203 
206  {
209  uint16_t id;
210  uint32_t frequency;
212  // std::string RelayCallsign;
214 
215  MSGPACK_DEFINE(id, frequency, distanceRatio /*, RelayCallsign*/)
216  };
217 
220  {
222  TxTransceiverDto() = default;
223 
225  TxTransceiverDto(const TransceiverDto &dto) : id(dto.id) {}
226 
228  TxTransceiverDto(uint16_t value) : id(value) {}
229 
230  uint16_t id {};
231  MSGPACK_DEFINE(id)
232  };
233 
236  {
239  static QByteArray getDtoName() { return "AudioTxOnTransceiversDto"; }
240  static QByteArray getShortDtoName() { return "AT"; }
242 
245  std::string callsign;
247  std::vector<char> audio;
249  std::vector<TxTransceiverDto> transceivers;
252  };
253 
256  {
259  static QByteArray getDtoName() { return "AudioRxOnTransceiversDto"; }
260  static QByteArray getShortDtoName() { return "AR"; }
262 
265  std::string callsign;
267  std::vector<char> audio;
269  std::vector<RxTransceiverDto> transceivers;
272  };
273 
275  struct IAudioDto
276  {
280  bool lastPacket;
281  };
282 } // namespace swift::core::afv
283 
284 #endif // SWIFT_CORE_AFV_DTO_H
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
QJsonValue value(QLatin1StringView key) const const
double toDouble(double defaultValue) const const
int toInt(int defaultValue) const const
QJsonObject toObject() const const
QString toString() const const
QByteArray toLocal8Bit() const const
AudioRxOnTransceiversDto.
Definition: dto.h:256
std::vector< RxTransceiverDto > transceivers
Properties.
Definition: dto.h:269
static QByteArray getDtoName()
Names.
Definition: dto.h:259
static QByteArray getShortDtoName()
Names.
Definition: dto.h:260
std::string callsign
Properties.
Definition: dto.h:265
std::vector< char > audio
Properties.
Definition: dto.h:267
AudioTxOnTransceiversDto.
Definition: dto.h:236
std::vector< char > audio
Properties.
Definition: dto.h:247
std::vector< TxTransceiverDto > transceivers
Properties.
Definition: dto.h:249
static QByteArray getShortDtoName()
Names.
Definition: dto.h:240
static QByteArray getDtoName()
Names.
Definition: dto.h:239
std::string callsign
Properties.
Definition: dto.h:245
QByteArray aeadReceiveKey
Properties.
Definition: dto.h:25
QByteArray aeadTransmitKey
Properties.
Definition: dto.h:26
QJsonObject toJson() const
To JSON.
Definition: dto.h:31
QByteArray hmacKey
Properties.
Definition: dto.h:27
static CryptoDtoChannelConfigDto fromJson(const QJsonObject &json)
From JSON.
Definition: dto.h:42
static QByteArray getDtoName()
Name.
Definition: dto.h:197
static QByteArray getShortDtoName()
Name.
Definition: dto.h:198
Heartbeat DTO.
Definition: dto.h:181
static QByteArray getShortDtoName()
Name.
Definition: dto.h:185
std::string callsign
callsign
Definition: dto.h:188
static QByteArray getDtoName()
Name.
Definition: dto.h:184
bool lastPacket
Used to indicate to receiver that the sender has stopped sending.
Definition: dto.h:280
QByteArray audio
Opus compressed audio.
Definition: dto.h:279
QString callsign
Callsign that audio originates from.
Definition: dto.h:277
uint sequenceCounter
Receiver optionally uses this in reordering algorithm/gap detection.
Definition: dto.h:278
Callsign DTO.
Definition: dto.h:87
bool isValid
Properties.
Definition: dto.h:92
QJsonObject toJson() const
To JSON.
Definition: dto.h:96
VoiceServerConnectionDataDto VoiceServer
Properties.
Definition: dto.h:91
static PostCallsignResponseDto fromJson(const QJsonObject &json)
From JSON.
Definition: dto.h:105
Receive transceiver DTO.
Definition: dto.h:206
uint16_t id
Properties.
Definition: dto.h:209
float distanceRatio
Properties.
Definition: dto.h:211
uint32_t frequency
Properties.
Definition: dto.h:210
QUuid id
Properties.
Definition: dto.h:161
quint32 frequencyAliasHz
Properties.
Definition: dto.h:164
static StationDto fromJson(const QJsonObject &json)
From JSON.
Definition: dto.h:168
quint32 frequencyHz
Properties.
Definition: dto.h:163
QString name
Properties.
Definition: dto.h:162
Transceiver DTO.
Definition: dto.h:117
QJsonObject toJson() const
To JSON.
Definition: dto.h:130
double LonDeg
Properties.
Definition: dto.h:123
double LatDeg
Properties.
Definition: dto.h:122
double HeightMslM
Properties.
Definition: dto.h:124
double HeightAglM
Properties.
Definition: dto.h:125
static TransceiverDto fromJson(const QJsonObject &json)
From JSON.
Definition: dto.h:143
quint32 frequencyHz
Properties.
Definition: dto.h:121
quint16 id
Properties.
Definition: dto.h:120
Transmit transceiver DTO.
Definition: dto.h:220
TxTransceiverDto(const TransceiverDto &dto)
Ctor.
Definition: dto.h:225
TxTransceiverDto(uint16_t value)
Ctor.
Definition: dto.h:228
QJsonObject toJson() const
To JSON.
Definition: dto.h:65
static VoiceServerConnectionDataDto fromJson(const QJsonObject &json)
From JSON.
Definition: dto.h:75
CryptoDtoChannelConfigDto channelConfig
Properties.
Definition: dto.h:61