M17: LinkSetupFrame: use new Callsign class
Replaced the old callsign handling based on std::strings with the new Callsign class. This change freed 1808 byte of flash. Signed-off-by: Silvano Seva <silseva@fastwebnet.it>
This commit is contained in:
parent
edbe038329
commit
1f9a95e60d
|
|
@ -28,6 +28,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include "M17Datatypes.hpp"
|
#include "M17Datatypes.hpp"
|
||||||
|
#include "Callsign.hpp"
|
||||||
|
|
||||||
namespace M17
|
namespace M17
|
||||||
{
|
{
|
||||||
|
|
@ -64,28 +65,28 @@ public:
|
||||||
*
|
*
|
||||||
* @param callsign: string containing the source callsign.
|
* @param callsign: string containing the source callsign.
|
||||||
*/
|
*/
|
||||||
void setSource(const std::string& callsign);
|
void setSource(const Callsign& callsign);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get source callsign.
|
* Get source callsign.
|
||||||
*
|
*
|
||||||
* @return: string containing the source callsign.
|
* @return: string containing the source callsign.
|
||||||
*/
|
*/
|
||||||
std::string getSource();
|
Callsign getSource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set destination callsign.
|
* Set destination callsign.
|
||||||
*
|
*
|
||||||
* @param callsign: string containing the destination callsign.
|
* @param callsign: string containing the destination callsign.
|
||||||
*/
|
*/
|
||||||
void setDestination(const std::string& callsign);
|
void setDestination(const Callsign& callsign);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get destination callsign.
|
* Get destination callsign.
|
||||||
*
|
*
|
||||||
* @return: string containing the destination callsign.
|
* @return: string containing the destination callsign.
|
||||||
*/
|
*/
|
||||||
std::string getDestination();
|
Callsign getDestination();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get stream type field.
|
* Get stream type field.
|
||||||
|
|
|
||||||
|
|
@ -41,24 +41,24 @@ void M17LinkSetupFrame::clear()
|
||||||
data.dst.fill(0xFF);
|
data.dst.fill(0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17LinkSetupFrame::setSource(const std::string& callsign)
|
void M17LinkSetupFrame::setSource(const Callsign& callsign)
|
||||||
{
|
{
|
||||||
encode_callsign(callsign, data.src);
|
data.src = callsign;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string M17LinkSetupFrame::getSource()
|
Callsign M17LinkSetupFrame::getSource()
|
||||||
{
|
{
|
||||||
return decode_callsign(data.src);
|
return Callsign(data.src);
|
||||||
}
|
}
|
||||||
|
|
||||||
void M17LinkSetupFrame::setDestination(const std::string& callsign)
|
void M17LinkSetupFrame::setDestination(const Callsign& callsign)
|
||||||
{
|
{
|
||||||
encode_callsign(callsign, data.dst);
|
data.dst = callsign;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string M17LinkSetupFrame::getDestination()
|
Callsign M17LinkSetupFrame::getDestination()
|
||||||
{
|
{
|
||||||
return decode_callsign(data.dst);
|
return Callsign(data.dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
streamType_t M17LinkSetupFrame::getType()
|
streamType_t M17LinkSetupFrame::getType()
|
||||||
|
|
|
||||||
|
|
@ -206,8 +206,9 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
|
||||||
dataValid = true;
|
dataValid = true;
|
||||||
|
|
||||||
// Retrieve stream source and destination data
|
// Retrieve stream source and destination data
|
||||||
std::string dst = lsf.getDestination();
|
Callsign dst = lsf.getDestination();
|
||||||
std::string src = lsf.getSource();
|
Callsign src = lsf.getSource();
|
||||||
|
strncpy(status->M17_dst, dst, 10);
|
||||||
|
|
||||||
// Retrieve extended callsign data
|
// Retrieve extended callsign data
|
||||||
streamType_t streamType = lsf.getType();
|
streamType_t streamType = lsf.getType();
|
||||||
|
|
@ -218,8 +219,8 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
|
||||||
extendedCall = true;
|
extendedCall = true;
|
||||||
|
|
||||||
meta_t& meta = lsf.metadata();
|
meta_t& meta = lsf.metadata();
|
||||||
std::string exCall1 = decode_callsign(meta.extended_call_sign.call1);
|
Callsign exCall1(meta.extended_call_sign.call1);
|
||||||
std::string exCall2 = decode_callsign(meta.extended_call_sign.call2);
|
Callsign exCall2(meta.extended_call_sign.call2);
|
||||||
|
|
||||||
//
|
//
|
||||||
// The source callsign only contains the last link when
|
// The source callsign only contains the last link when
|
||||||
|
|
@ -227,21 +228,16 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
|
||||||
// the true source of a transmission, we need to store the first
|
// the true source of a transmission, we need to store the first
|
||||||
// extended callsign in M17_src.
|
// extended callsign in M17_src.
|
||||||
//
|
//
|
||||||
strncpy(status->M17_src, exCall1.c_str(), 10);
|
strncpy(status->M17_src, exCall1, 10);
|
||||||
strncpy(status->M17_refl, exCall2.c_str(), 10);
|
strncpy(status->M17_refl, exCall2, 10);
|
||||||
|
strncpy(status->M17_link, src, 10);
|
||||||
extendedCall = true;
|
} else {
|
||||||
|
strncpy(status->M17_src, src, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set source and destination fields.
|
// Set source and destination fields.
|
||||||
// If we have received an extended callsign the src will be the RF link address
|
// If we have received an extended callsign the src will be the RF link address
|
||||||
// The M17_src will already be stored from the extended callsign
|
// The M17_src will already be stored from the extended callsign
|
||||||
strncpy(status->M17_dst, dst.c_str(), 10);
|
|
||||||
|
|
||||||
if(extendedCall)
|
|
||||||
strncpy(status->M17_link, src.c_str(), 10);
|
|
||||||
else
|
|
||||||
strncpy(status->M17_src, src.c_str(), 10);
|
|
||||||
|
|
||||||
// Check CAN on RX, if enabled.
|
// Check CAN on RX, if enabled.
|
||||||
// If check is disabled, force match to true.
|
// If check is disabled, force match to true.
|
||||||
|
|
@ -250,7 +246,8 @@ void OpMode_M17::rxState(rtxStatus_t *const status)
|
||||||
|
|
||||||
// Check if the destination callsign of the incoming transmission
|
// Check if the destination callsign of the incoming transmission
|
||||||
// matches with ours
|
// matches with ours
|
||||||
bool callMatch = compareCallsigns(std::string(status->source_address), dst);
|
bool callMatch = (Callsign(status->source_address) == dst)
|
||||||
|
|| dst.isSpecial();
|
||||||
|
|
||||||
// Open audio path only if CAN and callsign match
|
// Open audio path only if CAN and callsign match
|
||||||
uint8_t pthSts = audioPath_getStatus(rxAudioPath);
|
uint8_t pthSts = audioPath_getStatus(rxAudioPath);
|
||||||
|
|
@ -306,13 +303,14 @@ void OpMode_M17::txState(rtxStatus_t *const status)
|
||||||
{
|
{
|
||||||
startTx = false;
|
startTx = false;
|
||||||
|
|
||||||
std::string src(status->source_address);
|
|
||||||
std::string dst(status->destination_address);
|
|
||||||
M17LinkSetupFrame lsf;
|
M17LinkSetupFrame lsf;
|
||||||
|
|
||||||
lsf.clear();
|
lsf.clear();
|
||||||
lsf.setSource(src);
|
lsf.setSource(status->source_address);
|
||||||
if(!dst.empty()) lsf.setDestination(dst);
|
|
||||||
|
Callsign dst(status->destination_address);
|
||||||
|
if(!dst.isEmpty())
|
||||||
|
lsf.setDestination(dst);
|
||||||
|
|
||||||
streamType_t type;
|
streamType_t type;
|
||||||
type.fields.dataMode = M17_DATAMODE_STREAM; // Stream
|
type.fields.dataMode = M17_DATAMODE_STREAM; // Stream
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue