Ref T730, namespace for BlackCore::Afv

* added namespace
* removed some *.pri files and added files to blackcore.pro
* added copyright etc.
This commit is contained in:
Klaus Basan
2019-09-19 00:56:54 +02:00
committed by Mat Sutcliffe
parent d064da13b5
commit 384aa3ce19
46 changed files with 2985 additions and 2916 deletions

View File

@@ -1,5 +1,15 @@
#ifndef DTO_H
#define DTO_H
/* Copyright (C) 2019
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
//! \file
#ifndef BLACKCORE_AFV_DTO_H
#define BLACKCORE_AFV_DTO_H
#include "msgpack.hpp"
@@ -7,186 +17,192 @@
#include <QJsonObject>
#include <QString>
struct IMsgPack
{ };
struct CryptoDtoChannelConfigDto
namespace BlackCore
{
QString channelTag;
QByteArray aeadReceiveKey;
QByteArray aeadTransmitKey;
QByteArray hmacKey;
QJsonObject toJson() const
namespace Afv
{
QJsonObject json;
json["channelTag"] = channelTag;
json["aeadReceiveKey"] = QString(aeadReceiveKey);
json["aeadTransmitKey"] = QString(aeadTransmitKey);
json["hmacKey"] = QString(hmacKey);
return json;
}
struct IMsgPack
{ };
static CryptoDtoChannelConfigDto fromJson(const QJsonObject &json)
{
CryptoDtoChannelConfigDto dto;
struct CryptoDtoChannelConfigDto
{
QString channelTag;
QByteArray aeadReceiveKey;
QByteArray aeadTransmitKey;
QByteArray hmacKey;
dto.channelTag = json.value("channelTag").toString();
dto.aeadReceiveKey = QByteArray::fromBase64(json.value("aeadReceiveKey").toString().toLocal8Bit());
dto.aeadTransmitKey = QByteArray::fromBase64(json.value("aeadTransmitKey").toString().toLocal8Bit());
dto.hmacKey = QByteArray::fromBase64(json.value("hmacKey").toString().toLocal8Bit());
return dto;
}
};
QJsonObject toJson() const
{
QJsonObject json;
json["channelTag"] = channelTag;
json["aeadReceiveKey"] = QString(aeadReceiveKey);
json["aeadTransmitKey"] = QString(aeadTransmitKey);
json["hmacKey"] = QString(hmacKey);
return json;
}
struct VoiceServerConnectionDataDto
{
QString addressIpV4; // Example: 123.123.123.123:50000
QString addressIpV6; // Example: 123.123.123.123:50000
CryptoDtoChannelConfigDto channelConfig;
static CryptoDtoChannelConfigDto fromJson(const QJsonObject &json)
{
CryptoDtoChannelConfigDto dto;
QJsonObject toJson() const
{
QJsonObject json;
json["addressIpV4"] = addressIpV4;
json["addressIpV6"] = addressIpV6;
json["channelConfig"] = channelConfig.toJson();
return json;
}
dto.channelTag = json.value("channelTag").toString();
dto.aeadReceiveKey = QByteArray::fromBase64(json.value("aeadReceiveKey").toString().toLocal8Bit());
dto.aeadTransmitKey = QByteArray::fromBase64(json.value("aeadTransmitKey").toString().toLocal8Bit());
dto.hmacKey = QByteArray::fromBase64(json.value("hmacKey").toString().toLocal8Bit());
return dto;
}
};
static VoiceServerConnectionDataDto fromJson(const QJsonObject &json)
{
VoiceServerConnectionDataDto dto;
dto.addressIpV4 = json.value("addressIpV4").toString();
dto.addressIpV6 = json.value("addressIpV6").toString();
dto.channelConfig = CryptoDtoChannelConfigDto::fromJson(json.value("channelConfig").toObject());
return dto;
}
};
struct VoiceServerConnectionDataDto
{
QString addressIpV4; // Example: 123.123.123.123:50000
QString addressIpV6; // Example: 123.123.123.123:50000
CryptoDtoChannelConfigDto channelConfig;
struct PostCallsignResponseDto
{
VoiceServerConnectionDataDto VoiceServer;
// DataServerConnectionDataDto DataServer;
bool isValid = false;
QJsonObject toJson() const
{
QJsonObject json;
json["addressIpV4"] = addressIpV4;
json["addressIpV6"] = addressIpV6;
json["channelConfig"] = channelConfig.toJson();
return json;
}
QJsonObject toJson() const
{
QJsonObject json;
json["voiceserverauthdatadto"] = VoiceServer.toJson();
// json["dataserverauthdatadto"] = DataServer.toJson();
return json;
}
static VoiceServerConnectionDataDto fromJson(const QJsonObject &json)
{
VoiceServerConnectionDataDto dto;
dto.addressIpV4 = json.value("addressIpV4").toString();
dto.addressIpV6 = json.value("addressIpV6").toString();
dto.channelConfig = CryptoDtoChannelConfigDto::fromJson(json.value("channelConfig").toObject());
return dto;
}
};
static PostCallsignResponseDto fromJson(const QJsonObject &json)
{
PostCallsignResponseDto dto;
dto.VoiceServer = VoiceServerConnectionDataDto::fromJson(json.value("voiceServer").toObject());
// dto.DataServer = DataServerConnectionDataDto::fromJson(json.value("dataServer").toObject());
dto.isValid = true;
return dto;
}
};
struct PostCallsignResponseDto
{
VoiceServerConnectionDataDto VoiceServer;
// DataServerConnectionDataDto DataServer;
bool isValid = false;
struct TransceiverDto
{
quint16 id;
quint32 frequency;
double LatDeg = 0.0;
double LonDeg = 0.0;
double HeightMslM = 0.0;
double HeightAglM = 0.0;
MSGPACK_DEFINE(id, frequency, LatDeg, LonDeg, HeightMslM, HeightAglM)
QJsonObject toJson() const
{
QJsonObject json;
json["voiceserverauthdatadto"] = VoiceServer.toJson();
// json["dataserverauthdatadto"] = DataServer.toJson();
return json;
}
QJsonObject toJson() const
{
QJsonObject json;
json["ID"] = id;
json["Frequency"] = static_cast<int>(frequency);
json["LatDeg"] = LatDeg;
json["LonDeg"] = LonDeg;
json["AltMslM"] = HeightMslM;
return json;
}
static PostCallsignResponseDto fromJson(const QJsonObject &json)
{
PostCallsignResponseDto dto;
dto.VoiceServer = VoiceServerConnectionDataDto::fromJson(json.value("voiceServer").toObject());
// dto.DataServer = DataServerConnectionDataDto::fromJson(json.value("dataServer").toObject());
dto.isValid = true;
return dto;
}
};
static TransceiverDto fromJson(const QJsonObject &json)
{
TransceiverDto dto;
dto.id = json.value("id").toInt();
dto.frequency = json.value("frequency").toInt();
dto.LatDeg = json.value("latDeg").toDouble();
dto.LonDeg = json.value("lonDeg").toDouble();
dto.HeightMslM = json.value("heightMslM").toDouble();
dto.HeightAglM = json.value("heightAglM").toDouble();
return dto;
}
};
struct TransceiverDto
{
quint16 id;
quint32 frequency;
double LatDeg = 0.0;
double LonDeg = 0.0;
double HeightMslM = 0.0;
double HeightAglM = 0.0;
MSGPACK_DEFINE(id, frequency, LatDeg, LonDeg, HeightMslM, HeightAglM)
struct HeartbeatDto
{
static QByteArray getDtoName() { return "HeartbeatDto"; }
static QByteArray getShortDtoName() { return "H"; }
QJsonObject toJson() const
{
QJsonObject json;
json["ID"] = id;
json["Frequency"] = static_cast<int>(frequency);
json["LatDeg"] = LatDeg;
json["LonDeg"] = LonDeg;
json["AltMslM"] = HeightMslM;
return json;
}
std::string callsign;
MSGPACK_DEFINE(callsign)
};
static TransceiverDto fromJson(const QJsonObject &json)
{
TransceiverDto dto;
dto.id = json.value("id").toInt();
dto.frequency = json.value("frequency").toInt();
dto.LatDeg = json.value("latDeg").toDouble();
dto.LonDeg = json.value("lonDeg").toDouble();
dto.HeightMslM = json.value("heightMslM").toDouble();
dto.HeightAglM = json.value("heightAglM").toDouble();
return dto;
}
};
struct HeartbeatAckDto
{
static QByteArray getDtoName() { return "HeartbeatAckDto"; }
static QByteArray getShortDtoName() { return "HA"; }
MSGPACK_DEFINE()
};
struct HeartbeatDto
{
static QByteArray getDtoName() { return "HeartbeatDto"; }
static QByteArray getShortDtoName() { return "H"; }
struct RxTransceiverDto
{
uint16_t id;
uint32_t frequency;
float distanceRatio;
// std::string RelayCallsign;
std::string callsign;
MSGPACK_DEFINE(callsign)
};
MSGPACK_DEFINE(id, frequency, distanceRatio/*, RelayCallsign*/)
};
struct HeartbeatAckDto
{
static QByteArray getDtoName() { return "HeartbeatAckDto"; }
static QByteArray getShortDtoName() { return "HA"; }
MSGPACK_DEFINE()
};
struct TxTransceiverDto
{
uint16_t id;
struct RxTransceiverDto
{
uint16_t id;
uint32_t frequency;
float distanceRatio;
// std::string RelayCallsign;
MSGPACK_DEFINE(id)
};
MSGPACK_DEFINE(id, frequency, distanceRatio/*, RelayCallsign*/)
};
struct AudioTxOnTransceiversDto
{
static QByteArray getDtoName() { return "AudioTxOnTransceiversDto"; }
static QByteArray getShortDtoName() { return "AT"; }
struct TxTransceiverDto
{
uint16_t id;
std::string callsign;
uint sequenceCounter;
std::vector<char> audio;
bool lastPacket;
std::vector<TxTransceiverDto> transceivers;
MSGPACK_DEFINE(callsign, sequenceCounter, audio, lastPacket, transceivers)
};
MSGPACK_DEFINE(id)
};
struct AudioRxOnTransceiversDto
{
static QByteArray getDtoName() { return "AudioRxOnTransceiversDto"; }
static QByteArray getShortDtoName() { return "AR"; }
struct AudioTxOnTransceiversDto
{
static QByteArray getDtoName() { return "AudioTxOnTransceiversDto"; }
static QByteArray getShortDtoName() { return "AT"; }
std::string callsign;
uint sequenceCounter;
std::vector<char> audio;
bool lastPacket;
std::vector<RxTransceiverDto> transceivers;
MSGPACK_DEFINE(callsign, sequenceCounter, audio, lastPacket, transceivers)
};
std::string callsign;
uint sequenceCounter;
std::vector<char> audio;
bool lastPacket;
std::vector<TxTransceiverDto> transceivers;
MSGPACK_DEFINE(callsign, sequenceCounter, audio, lastPacket, transceivers)
};
struct IAudioDto
{
QString callsign; // Callsign that audio originates from
uint sequenceCounter; // Receiver optionally uses this in reordering algorithm/gap detection
QByteArray audio; // Opus compressed audio
bool lastPacket; // Used to indicate to receiver that the sender has stopped sending
};
struct AudioRxOnTransceiversDto
{
static QByteArray getDtoName() { return "AudioRxOnTransceiversDto"; }
static QByteArray getShortDtoName() { return "AR"; }
#endif // DTO_H
std::string callsign;
uint sequenceCounter;
std::vector<char> audio;
bool lastPacket;
std::vector<RxTransceiverDto> transceivers;
MSGPACK_DEFINE(callsign, sequenceCounter, audio, lastPacket, transceivers)
};
struct IAudioDto
{
QString callsign; // Callsign that audio originates from
uint sequenceCounter; // Receiver optionally uses this in reordering algorithm/gap detection
QByteArray audio; // Opus compressed audio
bool lastPacket; // Used to indicate to receiver that the sender has stopped sending
};
} // ns
} // ns
#endif // guard