[AX25] Reworked macro configuration system

This commit is contained in:
jgromes 2023-11-27 21:16:34 +01:00
parent 98054055bd
commit 6c07552f84
2 changed files with 20 additions and 20 deletions

View file

@ -1,6 +1,6 @@
#include "AX25.h" #include "AX25.h"
#include <string.h> #include <string.h>
#if !defined(RADIOLIB_EXCLUDE_AX25) #if !RADIOLIB_EXCLUDE_AX25
AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control) AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control)
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, 0, NULL, 0) { : AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, 0, NULL, 0) {
@ -25,7 +25,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
// set repeaters // set repeaters
this->numRepeaters = 0; this->numRepeaters = 0;
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
this->repeaterCallsigns = NULL; this->repeaterCallsigns = NULL;
this->repeaterSSIDs = NULL; this->repeaterSSIDs = NULL;
#endif #endif
@ -43,7 +43,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
// info field // info field
this->infoLen = infoLen; this->infoLen = infoLen;
if(infoLen > 0) { if(infoLen > 0) {
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
this->info = new uint8_t[infoLen]; this->info = new uint8_t[infoLen];
#endif #endif
memcpy(this->info, info, infoLen); memcpy(this->info, info, infoLen);
@ -55,7 +55,7 @@ AX25Frame::AX25Frame(const AX25Frame& frame) {
} }
AX25Frame::~AX25Frame() { AX25Frame::~AX25Frame() {
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
// deallocate info field // deallocate info field
if(infoLen > 0) { if(infoLen > 0) {
delete[] this->info; delete[] this->info;
@ -124,7 +124,7 @@ int16_t AX25Frame::setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs
} }
// create buffers // create buffers
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
this->repeaterCallsigns = new char*[numRepeaters]; this->repeaterCallsigns = new char*[numRepeaters];
for(uint8_t i = 0; i < numRepeaters; i++) { for(uint8_t i = 0; i < numRepeaters; i++) {
this->repeaterCallsigns[i] = new char[strlen(repeaterCallsigns[i]) + 1]; this->repeaterCallsigns[i] = new char[strlen(repeaterCallsigns[i]) + 1];
@ -153,12 +153,12 @@ void AX25Frame::setSendSequence(uint8_t seqNumber) {
AX25Client::AX25Client(PhysicalLayer* phy) { AX25Client::AX25Client(PhysicalLayer* phy) {
phyLayer = phy; phyLayer = phy;
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
bellModem = nullptr; bellModem = nullptr;
#endif #endif
} }
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
AX25Client::AX25Client(AFSKClient* audio) { AX25Client::AX25Client(AFSKClient* audio) {
phyLayer = audio->phyLayer; phyLayer = audio->phyLayer;
bellModem = new BellClient(audio); bellModem = new BellClient(audio);
@ -194,7 +194,7 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preL
preambleLen = preLen; preambleLen = preLen;
// configure for direct mode // configure for direct mode
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
if(bellModem != nullptr) { if(bellModem != nullptr) {
return(phyLayer->startDirect()); return(phyLayer->startDirect());
} }
@ -226,7 +226,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
} }
// check repeater configuration // check repeater configuration
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
if(!(((frame->repeaterCallsigns == NULL) && (frame->repeaterSSIDs == NULL) && (frame->numRepeaters == 0)) || if(!(((frame->repeaterCallsigns == NULL) && (frame->repeaterSSIDs == NULL) && (frame->numRepeaters == 0)) ||
((frame->repeaterCallsigns != NULL) && (frame->repeaterSSIDs != NULL) && (frame->numRepeaters != 0)))) { ((frame->repeaterCallsigns != NULL) && (frame->repeaterSSIDs != NULL) && (frame->numRepeaters != 0)))) {
return(RADIOLIB_ERR_INVALID_NUM_REPEATERS); return(RADIOLIB_ERR_INVALID_NUM_REPEATERS);
@ -241,7 +241,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
// calculate frame length without FCS (destination address, source address, repeater addresses, control, PID, info) // calculate frame length without FCS (destination address, source address, repeater addresses, control, PID, info)
size_t frameBuffLen = ((2 + frame->numRepeaters)*(RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1)) + 1 + 1 + frame->infoLen; size_t frameBuffLen = ((2 + frame->numRepeaters)*(RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1)) + 1 + 1 + frame->infoLen;
// create frame buffer without preamble, start or stop flags // create frame buffer without preamble, start or stop flags
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
uint8_t* frameBuff = new uint8_t[frameBuffLen + 2]; uint8_t* frameBuff = new uint8_t[frameBuffLen + 2];
#else #else
uint8_t frameBuff[RADIOLIB_STATIC_ARRAY_SIZE]; uint8_t frameBuff[RADIOLIB_STATIC_ARRAY_SIZE];
@ -323,7 +323,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
*(frameBuffPtr++) = (uint8_t)(fcs & 0xFF); *(frameBuffPtr++) = (uint8_t)(fcs & 0xFF);
// prepare buffer for the final frame (stuffed, with added preamble + flags and NRZI-encoded) // prepare buffer for the final frame (stuffed, with added preamble + flags and NRZI-encoded)
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
// worst-case scenario: sequence of 1s, will have 120% of the original length, stuffed frame also includes both flags // worst-case scenario: sequence of 1s, will have 120% of the original length, stuffed frame also includes both flags
uint8_t* stuffedFrameBuff = new uint8_t[preambleLen + 1 + (6*frameBuffLen)/5 + 2]; uint8_t* stuffedFrameBuff = new uint8_t[preambleLen + 1 + (6*frameBuffLen)/5 + 2];
#else #else
@ -367,7 +367,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
} }
// deallocate memory // deallocate memory
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
delete[] frameBuff; delete[] frameBuff;
#endif #endif
@ -413,7 +413,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
// transmit // transmit
int16_t state = RADIOLIB_ERR_NONE; int16_t state = RADIOLIB_ERR_NONE;
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
if(bellModem != nullptr) { if(bellModem != nullptr) {
bellModem->idle(); bellModem->idle();
@ -427,12 +427,12 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
} else { } else {
#endif #endif
state = phyLayer->transmit(stuffedFrameBuff, stuffedFrameBuffLen); state = phyLayer->transmit(stuffedFrameBuff, stuffedFrameBuffLen);
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
} }
#endif #endif
// deallocate memory // deallocate memory
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
delete[] stuffedFrameBuff; delete[] stuffedFrameBuff;
#endif #endif

View file

@ -3,7 +3,7 @@
#include "../../TypeDef.h" #include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_AX25) #if !RADIOLIB_EXCLUDE_AX25
#include "../PhysicalLayer/PhysicalLayer.h" #include "../PhysicalLayer/PhysicalLayer.h"
#include "../AFSK/AFSK.h" #include "../AFSK/AFSK.h"
@ -125,7 +125,7 @@ class AX25Frame {
*/ */
uint16_t sendSeqNumber; uint16_t sendSeqNumber;
#if !defined(RADIOLIB_STATIC_ONLY) #if !RADIOLIB_STATIC_ONLY
/*! /*!
\brief The info field. \brief The info field.
*/ */
@ -243,7 +243,7 @@ class AX25Client {
*/ */
explicit AX25Client(PhysicalLayer* phy); explicit AX25Client(PhysicalLayer* phy);
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
/*! /*!
\brief Constructor for AFSK mode. \brief Constructor for AFSK mode.
\param audio Pointer to the AFSK instance providing audio. \param audio Pointer to the AFSK instance providing audio.
@ -303,13 +303,13 @@ class AX25Client {
*/ */
int16_t sendFrame(AX25Frame* frame); int16_t sendFrame(AX25Frame* frame);
#if !defined(RADIOLIB_GODMODE) #if !RADIOLIB_GODMODE
private: private:
#endif #endif
friend class APRSClient; friend class APRSClient;
PhysicalLayer* phyLayer; PhysicalLayer* phyLayer;
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !RADIOLIB_EXCLUDE_AFSK
BellClient* bellModem; BellClient* bellModem;
#endif #endif