From 6460d566cde27119a7dfe35e30ca9cdf63739ec9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 5 Sep 2021 16:04:14 +0200 Subject: [PATCH] [AX.25] Added option to adjust audio frequencies (#346) --- .../AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino | 16 ++++++++++++++++ keywords.txt | 1 + src/protocols/AX25/AX25.cpp | 12 ++++++++++-- src/protocols/AX25/AX25.h | 13 +++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino index 703847af..a44d1ed9 100644 --- a/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino +++ b/examples/AX25/AX25_Transmit_AFSK/AX25_Transmit_AFSK.ino @@ -74,6 +74,22 @@ void setup() { Serial.println(state); while(true); } + + // Sometimes, it may be required to adjust audio + // frequencies to match the expected 1200/2200 Hz tones. + // The following method will offset mark frequency by + // 100 Hz up and space frequency by 100 Hz down + /* + Serial.print(F("[AX.25] Setting correction ... ")); + state = ax25.setCorrection(100, -100); + if(state == ERR_NONE) { + Serial.println(F("success!")); + } else { + Serial.print(F("failed, code ")); + Serial.println(state); + while(true); + } + */ } void loop() { diff --git a/keywords.txt b/keywords.txt index 0950331b..1448a752 100644 --- a/keywords.txt +++ b/keywords.txt @@ -230,6 +230,7 @@ setRepeaters KEYWORD2 setRecvSequence KEYWORD2 setSendSequence KEYWORD2 sendFrame KEYWORD2 +setCorrection KEYWORD2 # SSTV sendHeader KEYWORD2 diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index 1c3334cc..d5b5520c 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -160,6 +160,14 @@ AX25Client::AX25Client(PhysicalLayer* phy) { AX25Client::AX25Client(AFSKClient* audio) { _phy = audio->_phy; _audio = audio; + _afskMark = AX25_AFSK_MARK; + _afskSpace = AX25_AFSK_SPACE; +} + +int16_t AX25Client::setCorrection(int16_t mark, int16_t space) { + _afskMark = AX25_AFSK_MARK + mark; + _afskSpace = AX25_AFSK_SPACE + space; + return(ERR_NONE); } #endif @@ -393,9 +401,9 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) { for(uint16_t mask = 0x80; mask >= 0x01; mask >>= 1) { uint32_t start = Module::micros(); if(stuffedFrameBuff[i] & mask) { - _audio->tone(AX25_AFSK_MARK, false); + _audio->tone(_afskMark, false); } else { - _audio->tone(AX25_AFSK_SPACE, false); + _audio->tone(_afskSpace, false); } while(Module::micros() - start < AX25_AFSK_TONE_DURATION) { Module::yield(); diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index 7848850b..6b9dbbf9 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -292,6 +292,17 @@ class AX25Client { \param audio Pointer to the AFSK instance providing audio. */ explicit AX25Client(AFSKClient* audio); + + /*! + \brief Set AFSK tone correction offset. On some platforms, this is required to get the audio produced by the setup to match the expected 1200/2200 Hz tones. + + \param mark Positive or negative correction offset for mark audio frequency in Hz. + + \param space Positive or negative correction offset for space audio frequency in Hz. + + \returns \ref status_codes + */ + int16_t setCorrection(int16_t mark, int16_t space); #endif // basic methods @@ -337,6 +348,8 @@ class AX25Client { PhysicalLayer* _phy; #if !defined(RADIOLIB_EXCLUDE_AFSK) AFSKClient* _audio; + uint32_t _afskMark; + uint32_t _afskSpace; #endif char _srcCallsign[AX25_MAX_CALLSIGN_LEN + 1] = {0, 0, 0, 0, 0, 0, 0};