[RTTY] Use compact Doxygen and stop using reserved format

This commit is contained in:
jgromes 2023-04-22 19:34:38 +02:00
parent 47e759f322
commit 5ab24e05dd
2 changed files with 89 additions and 102 deletions

View file

@ -4,39 +4,39 @@
#if !defined(RADIOLIB_EXCLUDE_RTTY)
ITA2String::ITA2String(char c) {
_len = 1;
asciiLen = 1;
#if !defined(RADIOLIB_STATIC_ONLY)
_str = new char[1];
strAscii = new char[1];
#endif
_str[0] = c;
_ita2Len = 0;
strAscii[0] = c;
ita2Len = 0;
}
ITA2String::ITA2String(const char* str) {
_len = strlen(str);
asciiLen = strlen(str);
#if !defined(RADIOLIB_STATIC_ONLY)
_str = new char[_len + 1];
strAscii = new char[asciiLen + 1];
#endif
strcpy(_str, str);
_ita2Len = 0;
strcpy(strAscii, str);
ita2Len = 0;
}
ITA2String::~ITA2String() {
#if !defined(RADIOLIB_STATIC_ONLY)
delete[] _str;
delete[] strAscii;
#endif
}
size_t ITA2String::length() {
// length returned by this method is different than the length of ASCII-encoded _str
// length returned by this method is different than the length of ASCII-encoded strAscii
// ITA2-encoded string length varies based on how many number and characters the string contains
if(_ita2Len == 0) {
if(ita2Len == 0) {
// ITA2 length wasn't calculated yet, call byteArr() to calculate it
byteArr();
}
return(_ita2Len);
return(ita2Len);
}
uint8_t* ITA2String::byteArr() {
@ -44,13 +44,13 @@ uint8_t* ITA2String::byteArr() {
#if defined(RADIOLIB_STATIC_ONLY)
uint8_t temp[RADIOLIB_STATIC_ARRAY_SIZE*2 + 1];
#else
uint8_t* temp = new uint8_t[_len*2 + 1];
uint8_t* temp = new uint8_t[asciiLen*2 + 1];
#endif
size_t arrayLen = 0;
bool flagFigure = false;
for(size_t i = 0; i < _len; i++) {
uint16_t code = getBits(_str[i]);
for(size_t i = 0; i < asciiLen; i++) {
uint16_t code = getBits(strAscii[i]);
uint8_t shift = (code >> 5) & 0b11111;
uint8_t character = code & 0b11111;
// check if the code is letter or figure
@ -65,8 +65,8 @@ uint8_t* ITA2String::byteArr() {
temp[arrayLen++] = character & 0b11111;
// check the following character (skip for message end)
if(i < (_len - 1)) {
uint16_t nextCode = getBits(_str[i+1]);
if(i < (asciiLen - 1)) {
uint16_t nextCode = getBits(strAscii[i+1]);
uint8_t nextShift = (nextCode >> 5) & 0b11111;
if(nextShift == RADIOLIB_ITA2_LTRS) {
// next character is a letter, terminate figure shift
@ -84,7 +84,7 @@ uint8_t* ITA2String::byteArr() {
}
// save ITA2 string length
_ita2Len = arrayLen;
ita2Len = arrayLen;
uint8_t* arr = new uint8_t[arrayLen];
memcpy(arr, temp, arrayLen);
@ -114,45 +114,45 @@ uint16_t ITA2String::getBits(char c) {
}
RTTYClient::RTTYClient(PhysicalLayer* phy) {
_phy = phy;
phyLayer = phy;
#if !defined(RADIOLIB_EXCLUDE_AFSK)
_audio = nullptr;
audioClient = nullptr;
#endif
}
#if !defined(RADIOLIB_EXCLUDE_AFSK)
RTTYClient::RTTYClient(AFSKClient* audio) {
_phy = audio->_phy;
_audio = audio;
phyLayer = audio->phyLayer;
audioClient = audio;
}
#endif
int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding, uint8_t stopBits) {
int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc, uint8_t stopBits) {
// save configuration
_encoding = encoding;
_stopBits = stopBits;
_baseHz = base;
_shiftHz = shift;
encoding = enc;
stopBitsNum = stopBits;
baseFreqHz = base;
shiftFreqHz = shift;
switch(encoding) {
case RADIOLIB_ASCII:
_dataBits = 7;
dataBitsNum = 7;
break;
case RADIOLIB_ASCII_EXTENDED:
_dataBits = 8;
dataBitsNum = 8;
break;
case RADIOLIB_ITA2:
_dataBits = 5;
dataBitsNum = 5;
break;
default:
return(RADIOLIB_ERR_UNSUPPORTED_ENCODING);
}
// calculate duration of 1 bit
_bitDuration = (uint32_t)1000000/rate;
bitDuration = (uint32_t)1000000/rate;
// calculate module carrier frequency resolution
uint32_t step = round(_phy->getFreqStep());
uint32_t step = round(phyLayer->getFreqStep());
// check minimum shift value
if(shift < step / 2) {
@ -161,16 +161,16 @@ int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc
// round shift to multiples of frequency step size
if(shift % step < (step / 2)) {
_shift = shift / step;
shiftFreq = shift / step;
} else {
_shift = (shift / step) + 1;
shiftFreq = (shift / step) + 1;
}
// calculate 24-bit frequency
_base = (base * 1000000.0) / _phy->getFreqStep();
baseFreq = (base * 1000000.0) / phyLayer->getFreqStep();
// configure for direct mode
return(_phy->startDirect());
return(phyLayer->startDirect());
}
void RTTYClient::idle() {
@ -195,7 +195,7 @@ size_t RTTYClient::write(uint8_t* buff, size_t len) {
size_t RTTYClient::write(uint8_t b) {
space();
uint16_t maxDataMask = 0x01 << (_dataBits - 1);
uint16_t maxDataMask = 0x01 << (dataBitsNum - 1);
for(uint16_t mask = 0x01; mask <= maxDataMask; mask <<= 1) {
if(b & mask) {
mark();
@ -204,7 +204,7 @@ size_t RTTYClient::write(uint8_t b) {
}
}
for(uint8_t i = 0; i < _stopBits; i++) {
for(uint8_t i = 0; i < stopBitsNum; i++) {
mark();
}
@ -238,10 +238,10 @@ size_t RTTYClient::print(__FlashStringHelper* fstr) {
}
size_t n = 0;
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(str);
n = RTTYClient::print(ita2);
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n = RTTYClient::write((uint8_t*)str, len);
}
#if !defined(RADIOLIB_STATIC_ONLY)
@ -252,10 +252,10 @@ size_t RTTYClient::print(__FlashStringHelper* fstr) {
size_t RTTYClient::print(const String& str) {
size_t n = 0;
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(str.c_str());
n = RTTYClient::print(ita2);
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n = RTTYClient::write((uint8_t*)str.c_str(), str.length());
}
return(n);
@ -271,10 +271,10 @@ size_t RTTYClient::print(ITA2String& ita2) {
size_t RTTYClient::print(const char str[]) {
size_t n = 0;
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(str);
n = RTTYClient::print(ita2);
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n = RTTYClient::write((uint8_t*)str, strlen(str));
}
return(n);
@ -282,10 +282,10 @@ size_t RTTYClient::print(const char str[]) {
size_t RTTYClient::print(char c) {
size_t n = 0;
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(c);
n = RTTYClient::print(ita2);
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n = RTTYClient::write(c);
}
return(n);
@ -332,10 +332,10 @@ size_t RTTYClient::print(double n, int digits) {
size_t RTTYClient::println(void) {
size_t n = 0;
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String lf = ITA2String("\r\n");
n = RTTYClient::print(lf);
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n = RTTYClient::write("\r\n");
}
return(n);
@ -410,17 +410,17 @@ size_t RTTYClient::println(double d, int digits) {
}
void RTTYClient::mark() {
Module* mod = _phy->getMod();
Module* mod = phyLayer->getMod();
uint32_t start = mod->hal->micros();
transmitDirect(_base + _shift, _baseHz + _shiftHz);
mod->waitForMicroseconds(start, _bitDuration);
transmitDirect(baseFreq + shiftFreq, baseFreqHz + shiftFreqHz);
mod->waitForMicroseconds(start, bitDuration);
}
void RTTYClient::space() {
Module* mod = _phy->getMod();
Module* mod = phyLayer->getMod();
uint32_t start = mod->hal->micros();
transmitDirect(_base, _baseHz);
mod->waitForMicroseconds(start, _bitDuration);
transmitDirect(baseFreq, baseFreqHz);
mod->waitForMicroseconds(start, bitDuration);
}
size_t RTTYClient::printNumber(unsigned long n, uint8_t base) {
@ -441,12 +441,12 @@ size_t RTTYClient::printNumber(unsigned long n, uint8_t base) {
} while(n);
size_t l = 0;
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(str);
uint8_t* arr = ita2.byteArr();
l = RTTYClient::write(arr, ita2.length());
delete[] arr;
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
l = RTTYClient::write(str);
}
@ -464,25 +464,25 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) {
if (number <-4294967040.0) strcpy(code, "ovf"); // constant determined empirically
if(code[0] != 0x00) {
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(code);
uint8_t* arr = ita2.byteArr();
n = RTTYClient::write(arr, ita2.length());
delete[] arr;
return(n);
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
return(RTTYClient::write(code));
}
}
// Handle negative numbers
if (number < 0.0) {
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String("-");
uint8_t* arr = ita2.byteArr();
n += RTTYClient::write(arr, ita2.length());
delete[] arr;
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n += RTTYClient::print('-');
}
number = -number;
@ -502,12 +502,12 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) {
// Print the decimal point, but only if there are digits beyond
if(digits > 0) {
if(_encoding == RADIOLIB_ITA2) {
if(encoding == RADIOLIB_ITA2) {
ITA2String ita2 = ITA2String(".");
uint8_t* arr = ita2.byteArr();
n += RTTYClient::write(arr, ita2.length());
delete[] arr;
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
} else if((encoding == RADIOLIB_ASCII) || (encoding == RADIOLIB_ASCII_EXTENDED)) {
n += RTTYClient::print('.');
}
}
@ -525,23 +525,23 @@ size_t RTTYClient::printFloat(double number, uint8_t digits) {
int16_t RTTYClient::transmitDirect(uint32_t freq, uint32_t freqHz) {
#if !defined(RADIOLIB_EXCLUDE_AFSK)
if(_audio != nullptr) {
return(_audio->tone(freqHz));
if(audioClient != nullptr) {
return(audioClient->tone(freqHz));
}
#endif
return(_phy->transmitDirect(freq));
return(phyLayer->transmitDirect(freq));
}
int16_t RTTYClient::standby() {
// ensure everything is stopped in interrupt timing mode
Module* mod = _phy->getMod();
Module* mod = phyLayer->getMod();
mod->waitForMicroseconds(0, 0);
#if !defined(RADIOLIB_EXCLUDE_AFSK)
if(_audio != nullptr) {
return(_audio->noTone());
if(audioClient != nullptr) {
return(audioClient->noTone());
}
#endif
return(_phy->standby());
return(phyLayer->standby());
}
#endif

View file

@ -15,28 +15,27 @@
// ITA2 character table: - position in array corresponds to 5-bit ITA2 code
// - characters to the left are in letters shift, characters to the right in figures shift
// - characters marked 0x7F do not have ASCII equivalent
static const char ITA2Table[RADIOLIB_ITA2_LENGTH][2] RADIOLIB_NONVOLATILE = {{'\0', '\0'}, {'E', '3'}, {'\n', '\n'}, {'A', '-'}, {' ', ' '}, {'S', '\''}, {'I', '8'}, {'U', '7'},
static const char ITA2Table[RADIOLIB_ITA2_LENGTH][2] RADIOLIB_NONVOLATILE = {
{'\0', '\0'}, {'E', '3'}, {'\n', '\n'}, {'A', '-'}, {' ', ' '}, {'S', '\''}, {'I', '8'}, {'U', '7'},
{'\r', '\r'}, {'D', 0x05}, {'R', '4'}, {'J', '\a'}, {'N', ','}, {'F', '!'}, {'C', ':'}, {'K', '('},
{'T', '5'}, {'Z', '+'}, {'L', ')'}, {'W', '2'}, {'H', 0x7F}, {'Y', '6'}, {'P', '0'}, {'Q', '1'},
{'O', '9'}, {'B', '?'}, {'G', '&'}, {0x7F, 0x7F}, {'M', '.'}, {'X', '/'}, {'V', ';'}, {0x7F, 0x7F}};
{'O', '9'}, {'B', '?'}, {'G', '&'}, {0x7F, 0x7F}, {'M', '.'}, {'X', '/'}, {'V', ';'}, {0x7F, 0x7F}
};
/*!
\class ITA2String
\brief ITA2-encoded string.
*/
class ITA2String {
public:
/*!
\brief Default single-character constructor.
\param c ASCII-encoded character to encode as ITA2.
*/
explicit ITA2String(char c);
/*!
\brief Default string constructor.
\param str ASCII-encoded string to encode as ITA2.
*/
explicit ITA2String(const char* str);
@ -48,14 +47,12 @@ class ITA2String {
/*!
\brief Gets the length of the ITA2 string. This number is not the same as the length of ASCII-encoded string!
\returns Length of ITA2-encoded string.
*/
size_t length();
/*!
\brief Gets the ITA2 representation of the ASCII string set in constructor.
\returns Pointer to dynamically allocated array, which contains ITA2-encoded bytes.
It is the caller's responsibility to deallocate this memory!
*/
@ -65,12 +62,12 @@ class ITA2String {
private:
#endif
#if defined(RADIOLIB_STATIC_ONLY)
char _str[RADIOLIB_STATIC_ARRAY_SIZE];
char strAscii[RADIOLIB_STATIC_ARRAY_SIZE];
#else
char* _str;
char* strAscii;
#endif
size_t _len;
size_t _ita2Len;
size_t asciiLen;
size_t ita2Len;
static uint16_t getBits(char c);
};
@ -82,14 +79,12 @@ class ITA2String {
/*!
\class RTTYClient
\brief Client for RTTY communication. The public interface is the same as Arduino Serial.
*/
class RTTYClient {
public:
/*!
\brief Constructor for 2-FSK mode.
\param phy Pointer to the wireless module providing PhysicalLayer communication.
*/
explicit RTTYClient(PhysicalLayer* phy);
@ -97,7 +92,6 @@ class RTTYClient {
#if !defined(RADIOLIB_EXCLUDE_AFSK)
/*!
\brief Constructor for AFSK mode.
\param audio Pointer to the AFSK instance providing audio.
*/
explicit RTTYClient(AFSKClient* audio);
@ -107,20 +101,14 @@ class RTTYClient {
/*!
\brief Initialization method.
\param base Base (space) frequency to be used in MHz (in 2-FSK mode), or the space tone frequency in Hz (in AFSK mode)
\param shift Frequency shift between mark and space in Hz.
\param rate Baud rate to be used during transmission.
\param encoding Encoding to be used. Defaults to ASCII.
\param enc Encoding to be used. Defaults to ASCII.
\param stopBits Number of stop bits to be used.
\returns \ref status_codes
*/
int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding = RADIOLIB_ASCII, uint8_t stopBits = 1);
int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t enc = RADIOLIB_ASCII, uint8_t stopBits = 1);
/*!
\brief Send out idle condition (RF tone at mark frequency).
@ -129,7 +117,6 @@ class RTTYClient {
/*!
\brief Stops transmitting.
\returns \ref status_codes
*/
int16_t standby();
@ -170,17 +157,17 @@ class RTTYClient {
#if !defined(RADIOLIB_GODMODE)
private:
#endif
PhysicalLayer* _phy;
PhysicalLayer* phyLayer;
#if !defined(RADIOLIB_EXCLUDE_AFSK)
AFSKClient* _audio;
AFSKClient* audioClient;
#endif
uint8_t _encoding = RADIOLIB_ASCII;
uint32_t _base = 0, _baseHz = 0;
uint32_t _shift = 0, _shiftHz = 0;
uint32_t _bitDuration = 0;
uint8_t _dataBits = 0;
uint8_t _stopBits = 0;
uint8_t encoding = RADIOLIB_ASCII;
uint32_t baseFreq = 0, baseFreqHz = 0;
uint32_t shiftFreq = 0, shiftFreqHz = 0;
uint32_t bitDuration = 0;
uint8_t dataBitsNum = 0;
uint8_t stopBitsNum = 0;
void mark();
void space();