[AX25] Reworked macro configuration system
This commit is contained in:
parent
98054055bd
commit
6c07552f84
2 changed files with 20 additions and 20 deletions
|
@ -1,6 +1,6 @@
|
|||
#include "AX25.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(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
|
||||
this->numRepeaters = 0;
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = NULL;
|
||||
this->repeaterSSIDs = NULL;
|
||||
#endif
|
||||
|
@ -43,7 +43,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
|||
// info field
|
||||
this->infoLen = infoLen;
|
||||
if(infoLen > 0) {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->info = new uint8_t[infoLen];
|
||||
#endif
|
||||
memcpy(this->info, info, infoLen);
|
||||
|
@ -55,7 +55,7 @@ AX25Frame::AX25Frame(const AX25Frame& frame) {
|
|||
}
|
||||
|
||||
AX25Frame::~AX25Frame() {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
// deallocate info field
|
||||
if(infoLen > 0) {
|
||||
delete[] this->info;
|
||||
|
@ -124,7 +124,7 @@ int16_t AX25Frame::setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs
|
|||
}
|
||||
|
||||
// create buffers
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = new char*[numRepeaters];
|
||||
for(uint8_t i = 0; i < numRepeaters; i++) {
|
||||
this->repeaterCallsigns[i] = new char[strlen(repeaterCallsigns[i]) + 1];
|
||||
|
@ -153,12 +153,12 @@ void AX25Frame::setSendSequence(uint8_t seqNumber) {
|
|||
|
||||
AX25Client::AX25Client(PhysicalLayer* phy) {
|
||||
phyLayer = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
bellModem = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AX25Client::AX25Client(AFSKClient* audio) {
|
||||
phyLayer = audio->phyLayer;
|
||||
bellModem = new BellClient(audio);
|
||||
|
@ -194,7 +194,7 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preL
|
|||
preambleLen = preLen;
|
||||
|
||||
// configure for direct mode
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(bellModem != nullptr) {
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
|||
}
|
||||
|
||||
// check repeater configuration
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
if(!(((frame->repeaterCallsigns == NULL) && (frame->repeaterSSIDs == NULL) && (frame->numRepeaters == 0)) ||
|
||||
((frame->repeaterCallsigns != NULL) && (frame->repeaterSSIDs != NULL) && (frame->numRepeaters != 0)))) {
|
||||
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)
|
||||
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
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
uint8_t* frameBuff = new uint8_t[frameBuffLen + 2];
|
||||
#else
|
||||
uint8_t frameBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
|
@ -323,7 +323,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
|||
*(frameBuffPtr++) = (uint8_t)(fcs & 0xFF);
|
||||
|
||||
// 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
|
||||
uint8_t* stuffedFrameBuff = new uint8_t[preambleLen + 1 + (6*frameBuffLen)/5 + 2];
|
||||
#else
|
||||
|
@ -367,7 +367,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
|||
}
|
||||
|
||||
// deallocate memory
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] frameBuff;
|
||||
#endif
|
||||
|
||||
|
@ -413,7 +413,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
|||
|
||||
// transmit
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(bellModem != nullptr) {
|
||||
bellModem->idle();
|
||||
|
||||
|
@ -427,12 +427,12 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
|||
} else {
|
||||
#endif
|
||||
state = phyLayer->transmit(stuffedFrameBuff, stuffedFrameBuffLen);
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
}
|
||||
#endif
|
||||
|
||||
// deallocate memory
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] stuffedFrameBuff;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AX25)
|
||||
#if !RADIOLIB_EXCLUDE_AX25
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
|
@ -125,7 +125,7 @@ class AX25Frame {
|
|||
*/
|
||||
uint16_t sendSeqNumber;
|
||||
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
/*!
|
||||
\brief The info field.
|
||||
*/
|
||||
|
@ -243,7 +243,7 @@ class AX25Client {
|
|||
*/
|
||||
explicit AX25Client(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
|
@ -303,13 +303,13 @@ class AX25Client {
|
|||
*/
|
||||
int16_t sendFrame(AX25Frame* frame);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
friend class APRSClient;
|
||||
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
BellClient* bellModem;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue