[Morse] Use compact Doxygen and stop using reserved format

This commit is contained in:
jgromes 2023-04-22 19:35:23 +02:00
parent 6bbd237fb3
commit bb4e6cf946
2 changed files with 43 additions and 57 deletions

View file

@ -5,35 +5,35 @@
#if !defined(RADIOLIB_EXCLUDE_MORSE) #if !defined(RADIOLIB_EXCLUDE_MORSE)
MorseClient::MorseClient(PhysicalLayer* phy) { MorseClient::MorseClient(PhysicalLayer* phy) {
_phy = phy; phyLayer = phy;
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
_audio = nullptr; audioClient = nullptr;
#endif #endif
} }
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
MorseClient::MorseClient(AFSKClient* audio) { MorseClient::MorseClient(AFSKClient* audio) {
_phy = audio->_phy; phyLayer = audio->phyLayer;
_audio = audio; audioClient = audio;
} }
#endif #endif
int16_t MorseClient::begin(float base, uint8_t speed) { int16_t MorseClient::begin(float base, uint8_t speed) {
// calculate 24-bit frequency // calculate 24-bit frequency
_baseHz = base; baseFreqHz = base;
_base = (base * 1000000.0) / _phy->getFreqStep(); baseFreq = (base * 1000000.0) / phyLayer->getFreqStep();
// calculate tone period for decoding // calculate tone period for decoding
_basePeriod = (1000000.0f/base)/2.0f; basePeriod = (1000000.0f/base)/2.0f;
// calculate symbol lengths (assumes PARIS as typical word) // calculate symbol lengths (assumes PARIS as typical word)
_dotLength = 1200 / speed; dotLength = 1200 / speed;
_dashLength = 3*_dotLength; dashLength = 3*dotLength;
_letterSpace = 3*_dotLength; letterSpace = 3*dotLength;
_wordSpace = 4*_dotLength; wordSpace = 4*dotLength;
// configure for direct mode // configure for direct mode
return(_phy->startDirect()); return(phyLayer->startDirect());
} }
size_t MorseClient::startSignal() { size_t MorseClient::startSignal() {
@ -59,13 +59,13 @@ char MorseClient::decode(uint8_t symbol, uint8_t len) {
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) { int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) {
Module* mod = _phy->getMod(); Module* mod = phyLayer->getMod();
// measure pulse duration in us // measure pulse duration in us
uint32_t duration = mod->hal->pulseIn(_audio->_pin, mod->hal->GpioLevelLow, 4*_basePeriod); uint32_t duration = mod->hal->pulseIn(audioClient->outPin, mod->hal->GpioLevelLow, 4*basePeriod);
// decide if this is a signal, or pause // decide if this is a signal, or pause
if((duration > low*_basePeriod) && (duration < high*_basePeriod)) { if((duration > low*basePeriod) && (duration < high*basePeriod)) {
// this is a signal // this is a signal
signalCounter++; signalCounter++;
} else if(duration == 0) { } else if(duration == 0) {
@ -80,9 +80,9 @@ int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) {
signalStart = mod->hal->millis(); signalStart = mod->hal->millis();
uint32_t pauseLen = mod->hal->millis() - pauseStart; uint32_t pauseLen = mod->hal->millis() - pauseStart;
if((pauseLen >= low*(float)_letterSpace) && (pauseLen <= high*(float)_letterSpace)) { if((pauseLen >= low*(float)letterSpace) && (pauseLen <= high*(float)letterSpace)) {
return(RADIOLIB_MORSE_CHAR_COMPLETE); return(RADIOLIB_MORSE_CHAR_COMPLETE);
} else if(pauseLen > _wordSpace) { } else if(pauseLen > wordSpace) {
RADIOLIB_DEBUG_PRINTLN("\n<space>"); RADIOLIB_DEBUG_PRINTLN("\n<space>");
return(RADIOLIB_MORSE_WORD_COMPLETE); return(RADIOLIB_MORSE_WORD_COMPLETE);
} }
@ -93,11 +93,11 @@ int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) {
pauseStart = mod->hal->millis(); pauseStart = mod->hal->millis();
uint32_t signalLen = mod->hal->millis() - signalStart; uint32_t signalLen = mod->hal->millis() - signalStart;
if((signalLen >= low*(float)_dotLength) && (signalLen <= high*(float)_dotLength)) { if((signalLen >= low*(float)dotLength) && (signalLen <= high*(float)dotLength)) {
RADIOLIB_DEBUG_PRINT("."); RADIOLIB_DEBUG_PRINT(".");
(*symbol) |= (RADIOLIB_MORSE_DOT << (*len)); (*symbol) |= (RADIOLIB_MORSE_DOT << (*len));
(*len)++; (*len)++;
} else if((signalLen >= low*(float)_dashLength) && (signalLen <= high*(float)_dashLength)) { } else if((signalLen >= low*(float)dashLength) && (signalLen <= high*(float)dashLength)) {
RADIOLIB_DEBUG_PRINT("-"); RADIOLIB_DEBUG_PRINT("-");
(*symbol) |= (RADIOLIB_MORSE_DASH << (*len)); (*symbol) |= (RADIOLIB_MORSE_DASH << (*len));
(*len)++; (*len)++;
@ -127,7 +127,7 @@ size_t MorseClient::write(uint8_t* buff, size_t len) {
} }
size_t MorseClient::write(uint8_t b) { size_t MorseClient::write(uint8_t b) {
Module* mod = _phy->getMod(); Module* mod = phyLayer->getMod();
// check unprintable ASCII characters and boundaries // check unprintable ASCII characters and boundaries
if((b < ' ') || (b == 0x60) || (b > 'z')) { if((b < ' ') || (b == 0x60) || (b > 'z')) {
@ -138,7 +138,7 @@ size_t MorseClient::write(uint8_t b) {
if(b == ' ') { if(b == ' ') {
RADIOLIB_DEBUG_PRINTLN("space"); RADIOLIB_DEBUG_PRINTLN("space");
standby(); standby();
mod->waitForMicroseconds(mod->hal->micros(), _wordSpace*1000); mod->waitForMicroseconds(mod->hal->micros(), wordSpace*1000);
return(1); return(1);
} }
@ -156,17 +156,17 @@ size_t MorseClient::write(uint8_t b) {
// send dot or dash // send dot or dash
if (code & RADIOLIB_MORSE_DASH) { if (code & RADIOLIB_MORSE_DASH) {
RADIOLIB_DEBUG_PRINT("-"); RADIOLIB_DEBUG_PRINT("-");
transmitDirect(_base, _baseHz); transmitDirect(baseFreq, baseFreqHz);
mod->waitForMicroseconds(mod->hal->micros(), _dashLength*1000); mod->waitForMicroseconds(mod->hal->micros(), dashLength*1000);
} else { } else {
RADIOLIB_DEBUG_PRINT("."); RADIOLIB_DEBUG_PRINT(".");
transmitDirect(_base, _baseHz); transmitDirect(baseFreq, baseFreqHz);
mod->waitForMicroseconds(mod->hal->micros(), _dotLength*1000); mod->waitForMicroseconds(mod->hal->micros(), dotLength*1000);
} }
// symbol space // symbol space
standby(); standby();
mod->waitForMicroseconds(mod->hal->micros(), _dotLength*1000); mod->waitForMicroseconds(mod->hal->micros(), dotLength*1000);
// move onto the next bit // move onto the next bit
code >>= 1; code >>= 1;
@ -174,7 +174,7 @@ size_t MorseClient::write(uint8_t b) {
// letter space // letter space
standby(); standby();
mod->waitForMicroseconds(mod->hal->micros(), _letterSpace*1000 - _dotLength*1000); mod->waitForMicroseconds(mod->hal->micros(), letterSpace*1000 - dotLength*1000);
RADIOLIB_DEBUG_PRINTLN(); RADIOLIB_DEBUG_PRINTLN();
return(1); return(1);
@ -381,20 +381,20 @@ size_t MorseClient::printFloat(double number, uint8_t digits) {
int16_t MorseClient::transmitDirect(uint32_t freq, uint32_t freqHz) { int16_t MorseClient::transmitDirect(uint32_t freq, uint32_t freqHz) {
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
if(_audio != nullptr) { if(audioClient != nullptr) {
return(_audio->tone(freqHz)); return(audioClient->tone(freqHz));
} }
#endif #endif
return(_phy->transmitDirect(freq)); return(phyLayer->transmitDirect(freq));
} }
int16_t MorseClient::standby() { int16_t MorseClient::standby() {
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
if(_audio != nullptr) { if(audioClient != nullptr) {
return(_audio->noTone(true)); return(audioClient->noTone(true));
} }
#endif #endif
return(_phy->standby()); return(phyLayer->standby());
} }
#endif #endif

View file

@ -87,14 +87,12 @@ static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
/*! /*!
\class MorseClient \class MorseClient
\brief Client for Morse Code communication. The public interface is the same as Arduino Serial. \brief Client for Morse Code communication. The public interface is the same as Arduino Serial.
*/ */
class MorseClient { class MorseClient {
public: public:
/*! /*!
\brief Constructor for 2-FSK mode. \brief Constructor for 2-FSK mode.
\param phy Pointer to the wireless module providing PhysicalLayer communication. \param phy Pointer to the wireless module providing PhysicalLayer communication.
*/ */
explicit MorseClient(PhysicalLayer* phy); explicit MorseClient(PhysicalLayer* phy);
@ -102,7 +100,6 @@ class MorseClient {
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(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.
*/ */
explicit MorseClient(AFSKClient* audio); explicit MorseClient(AFSKClient* audio);
@ -112,45 +109,34 @@ class MorseClient {
/*! /*!
\brief Initialization method. \brief Initialization method.
\param base Base RF frequency to be used in MHz (in 2-FSK mode), or the tone frequency in Hz (in AFSK mode) \param base Base RF frequency to be used in MHz (in 2-FSK mode), or the tone frequency in Hz (in AFSK mode)
\param speed Coding speed in words per minute. \param speed Coding speed in words per minute.
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t begin(float base, uint8_t speed = 20); int16_t begin(float base, uint8_t speed = 20);
/*! /*!
\brief Send start signal. \brief Send start signal.
\returns Number of bytes sent (always 0). \returns Number of bytes sent (always 0).
*/ */
size_t startSignal(); size_t startSignal();
/*! /*!
\brief Decode Morse symbol to ASCII. \brief Decode Morse symbol to ASCII.
\param symbol Morse code symbol, respresented as outlined in MorseTable. \param symbol Morse code symbol, respresented as outlined in MorseTable.
\param len Symbol length (number of dots and dashes). \param len Symbol length (number of dots and dashes).
\returns ASCII character matching the symbol, or 0xFF if no match is found. \returns ASCII character matching the symbol, or 0xFF if no match is found.
*/ */
static char decode(uint8_t symbol, uint8_t len); static char decode(uint8_t symbol, uint8_t len);
/*! /*!
\brief Read Morse tone on input pin. \brief Read Morse tone on input pin.
\param symbol Pointer to the symbol buffer. \param symbol Pointer to the symbol buffer.
\param len Pointer to the length counter. \param len Pointer to the length counter.
\param low Low threshold for decision limit (dot length, pause length etc.), defaults to 0.75. \param low Low threshold for decision limit (dot length, pause length etc.), defaults to 0.75.
\param high High threshold for decision limit (dot length, pause length etc.), defaults to 1.25. \param high High threshold for decision limit (dot length, pause length etc.), defaults to 1.25.
\returns 0 if not enough symbols were decoded, 1 if inter-character space was detected,
\returns 0 if not enough symbols were decoded, 1 if inter-character space was detected, 2 if inter-word space was detected. 2 if inter-word space was detected.
*/ */
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
int read(uint8_t* symbol, uint8_t* len, float low = 0.75f, float high = 1.25f); int read(uint8_t* symbol, uint8_t* len, float low = 0.75f, float high = 1.25f);
@ -190,17 +176,17 @@ class MorseClient {
#if !defined(RADIOLIB_GODMODE) #if !defined(RADIOLIB_GODMODE)
private: private:
#endif #endif
PhysicalLayer* _phy; PhysicalLayer* phyLayer;
#if !defined(RADIOLIB_EXCLUDE_AFSK) #if !defined(RADIOLIB_EXCLUDE_AFSK)
AFSKClient* _audio; AFSKClient* audioClient;
#endif #endif
uint32_t _base = 0, _baseHz = 0; uint32_t baseFreq = 0, baseFreqHz = 0;
float _basePeriod = 0.0f; float basePeriod = 0.0f;
uint32_t _dotLength = 0; uint32_t dotLength = 0;
uint32_t _dashLength = 0; uint32_t dashLength = 0;
uint32_t _letterSpace = 0; uint32_t letterSpace = 0;
uint16_t _wordSpace = 0; uint16_t wordSpace = 0;
// variables to keep decoding state // variables to keep decoding state
uint32_t signalCounter = 0; uint32_t signalCounter = 0;