[PHY] Made virtual overloads non-pure

This commit is contained in:
jgromes 2023-01-08 15:10:48 +01:00
parent 27c1eb715a
commit 02de83f941
2 changed files with 152 additions and 66 deletions
src/protocols/PhysicalLayer

View file

@ -50,55 +50,11 @@ int16_t PhysicalLayer::transmit(const char* str, uint8_t addr) {
return(transmit((uint8_t*)str, strlen(str), addr));
}
int16_t PhysicalLayer::startTransmit(String& str, uint8_t addr) {
return(startTransmit(str.c_str(), addr));
}
int16_t PhysicalLayer::startTransmit(const char* str, uint8_t addr) {
return(startTransmit((uint8_t*)str, strlen(str), addr));
}
int16_t PhysicalLayer::readData(String& str, size_t len) {
int16_t state = RADIOLIB_ERR_NONE;
// read the number of actually received bytes
size_t length = getPacketLength();
if((len < length) && (len != 0)) {
// user requested less bytes than were received, this is allowed (but frowned upon)
// requests for more data than were received will only return the number of actually received bytes (unlike PhysicalLayer::receive())
length = len;
}
// build a temporary buffer
#if defined(RADIOLIB_STATIC_ONLY)
uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
#else
uint8_t* data = new uint8_t[length + 1];
if(!data) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
#endif
// read the received data
state = readData(data, length);
// any of the following leads to at least some data being available
// let's leave the decision of whether to keep it or not up to the user
if((state == RADIOLIB_ERR_NONE) || (state == RADIOLIB_ERR_CRC_MISMATCH) || (state == RADIOLIB_ERR_LORA_HEADER_DAMAGED)) {
// add null terminator
data[length] = 0;
// initialize Arduino String class
str = String((char*)data);
}
// deallocate temporary buffer
#if !defined(RADIOLIB_STATIC_ONLY)
delete[] data;
#endif
return(state);
int16_t PhysicalLayer::transmit(uint8_t* data, size_t len, uint8_t addr) {
(void)data;
(void)len;
(void)addr;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::receive(String& str, size_t len) {
@ -148,10 +104,127 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
return(state);
}
int16_t PhysicalLayer::receive(uint8_t* data, size_t len) {
(void)data;
(void)len;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::standby() {
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::startTransmit(String& str, uint8_t addr) {
return(startTransmit(str.c_str(), addr));
}
int16_t PhysicalLayer::startTransmit(const char* str, uint8_t addr) {
return(startTransmit((uint8_t*)str, strlen(str), addr));
}
int16_t PhysicalLayer::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
(void)data;
(void)len;
(void)addr;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::finishTransmit() {
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::readData(String& str, size_t len) {
int16_t state = RADIOLIB_ERR_NONE;
// read the number of actually received bytes
size_t length = getPacketLength();
if((len < length) && (len != 0)) {
// user requested less bytes than were received, this is allowed (but frowned upon)
// requests for more data than were received will only return the number of actually received bytes (unlike PhysicalLayer::receive())
length = len;
}
// build a temporary buffer
#if defined(RADIOLIB_STATIC_ONLY)
uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
#else
uint8_t* data = new uint8_t[length + 1];
if(!data) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
#endif
// read the received data
state = readData(data, length);
// any of the following leads to at least some data being available
// let's leave the decision of whether to keep it or not up to the user
if((state == RADIOLIB_ERR_NONE) || (state == RADIOLIB_ERR_CRC_MISMATCH) || (state == RADIOLIB_ERR_LORA_HEADER_DAMAGED)) {
// add null terminator
data[length] = 0;
// initialize Arduino String class
str = String((char*)data);
}
// deallocate temporary buffer
#if !defined(RADIOLIB_STATIC_ONLY)
delete[] data;
#endif
return(state);
}
int16_t PhysicalLayer::readData(uint8_t* data, size_t len) {
(void)data;
(void)len;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::transmitDirect(uint32_t frf) {
(void)frf;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::receiveDirect() {
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::setFrequency(float freq) {
(void)freq;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::setBitRate(float br) {
(void)br;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::setFrequencyDeviation(float freqDev) {
(void)freqDev;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::setDataShaping(uint8_t sh) {
(void)sh;
return(RADIOLIB_ERR_UNSUPPORTED);
}
int16_t PhysicalLayer::setEncoding(uint8_t encoding) {
(void)encoding;
return(RADIOLIB_ERR_UNSUPPORTED);
}
float PhysicalLayer::getFreqStep() const {
return(_freqStep);
}
size_t PhysicalLayer::getPacketLength(bool update) {
(void)update;
return(0);
}
int32_t PhysicalLayer::random(int32_t max) {
if(max == 0) {
return(0);
@ -180,6 +253,10 @@ int32_t PhysicalLayer::random(int32_t min, int32_t max) {
return(PhysicalLayer::random(max - min) + min);
}
uint8_t PhysicalLayer::randomByte() {
return(0);
}
int16_t PhysicalLayer::startDirect() {
// disable encodings
int16_t state = setEncoding(RADIOLIB_ENCODING_NRZ);
@ -266,6 +343,15 @@ void PhysicalLayer::updateDirectBuffer(uint8_t bit) {
}
}
}
void PhysicalLayer::setDirectAction(void (*func)(void)) {
(void)func;
}
void PhysicalLayer::readBit(RADIOLIB_PIN_TYPE pin) {
(void)pin;
}
#endif
int16_t PhysicalLayer::setDIOMapping(RADIOLIB_PIN_TYPE pin, uint8_t value) {

View file

@ -71,7 +71,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) = 0;
virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
/*!
\brief Arduino String receive method.
@ -89,7 +89,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t standby() = 0;
virtual int16_t standby();
/*!
\brief Binary receive method. Must be implemented in module class.
@ -100,7 +100,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t receive(uint8_t* data, size_t len) = 0;
virtual int16_t receive(uint8_t* data, size_t len);
/*!
\brief Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking.
@ -137,14 +137,14 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) = 0;
virtual int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0);
/*!
\brief Clean up after transmission is done.
\returns \ref status_codes
*/
virtual int16_t finishTransmit() = 0;
virtual int16_t finishTransmit();
/*!
\brief Reads data that was received after calling startReceive method.
@ -168,7 +168,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t readData(uint8_t* data, size_t len) = 0;
virtual int16_t readData(uint8_t* data, size_t len);
/*!
\brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class.
@ -178,7 +178,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t transmitDirect(uint32_t frf = 0) = 0;
virtual int16_t transmitDirect(uint32_t frf = 0);
/*!
\brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class.
@ -186,7 +186,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t receiveDirect() = 0;
virtual int16_t receiveDirect();
// configuration methods
@ -197,7 +197,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t setFrequency(float freq) = 0;
virtual int16_t setFrequency(float freq);
/*!
\brief Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class.
@ -206,7 +206,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t setBitRate(float br) = 0;
virtual int16_t setBitRate(float br);
/*!
\brief Sets FSK frequency deviation from carrier frequency. Only available in FSK mode. Must be implemented in module class.
@ -215,7 +215,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t setFrequencyDeviation(float freqDev) = 0;
virtual int16_t setFrequencyDeviation(float freqDev);
/*!
\brief Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class.
@ -224,7 +224,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t setDataShaping(uint8_t sh) = 0;
virtual int16_t setDataShaping(uint8_t sh);
/*!
\brief Sets FSK data encoding. Only available in FSK mode. Must be implemented in module class.
@ -233,7 +233,7 @@ class PhysicalLayer {
\returns \ref status_codes
*/
virtual int16_t setEncoding(uint8_t encoding) = 0;
virtual int16_t setEncoding(uint8_t encoding);
/*!
\brief Gets the module frequency step size that was set in constructor.
@ -249,7 +249,7 @@ class PhysicalLayer {
\returns Length of last received packet in bytes.
*/
virtual size_t getPacketLength(bool update = true) = 0;
virtual size_t getPacketLength(bool update = true);
/*!
\brief Get truly random number in range 0 - max.
@ -276,7 +276,7 @@ class PhysicalLayer {
\returns TRNG byte.
*/
virtual uint8_t randomByte() = 0;
virtual uint8_t randomByte();
/*!
\brief Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25. Only available in FSK mode.
@ -302,14 +302,14 @@ class PhysicalLayer {
\param func Pointer to interrupt service routine.
*/
virtual void setDirectAction(void (*func)(void)) = 0;
virtual void setDirectAction(void (*func)(void));
/*!
\brief Function to read and process data bit in direct reception mode. Must be implemented in module class.
\param pin Pin on which to read.
*/
virtual void readBit(RADIOLIB_PIN_TYPE pin) = 0;
virtual void readBit(RADIOLIB_PIN_TYPE pin);
/*!
\brief Get the number of direct mode bytes currently available in buffer.