[PHY] Added support for Arduino flash strings
This commit is contained in:
parent
ad5c8ab72d
commit
ed3eeb0559
2 changed files with 40 additions and 2 deletions
|
@ -5,6 +5,33 @@ PhysicalLayer::PhysicalLayer(float crysFreq, uint8_t divExp) {
|
|||
_divExponent = divExp;
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) {
|
||||
// read flash string length
|
||||
size_t len = 0;
|
||||
PGM_P p = reinterpret_cast<PGM_P>(fstr);
|
||||
while(true) {
|
||||
char c = pgm_read_byte(p++);
|
||||
len++;
|
||||
if(c == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// dynamically allocate memory
|
||||
char* str = new char[len];
|
||||
|
||||
// copy string from flash
|
||||
p = reinterpret_cast<PGM_P>(fstr);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
str[i] = pgm_read_byte(p + i);
|
||||
}
|
||||
|
||||
// transmit string
|
||||
int16_t state = transmit(str, addr);
|
||||
delete[] str;
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::transmit(String& str, uint8_t addr) {
|
||||
return(transmit(str.c_str(), addr));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/*!
|
||||
\class PhysicalLayer
|
||||
|
||||
\brief Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN. Also extracts some common
|
||||
\brief Provides common interface for protocols that run on %LoRa/FSK modules, such as RTTY or LoRaWAN. Also extracts some common
|
||||
module-independent methods. Using this interface class allows to use the protocols on various modules without much code duplicity.
|
||||
Because this class is used mainly as interface, all of its virtual members must be implemented in the module class.
|
||||
*/
|
||||
|
@ -26,6 +26,17 @@ class PhysicalLayer {
|
|||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Arduino Flash String transmit method.
|
||||
|
||||
\param str Pointer to Arduino Flash String that will be transmitted.
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(__FlashStringHelper* fstr, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Arduino String transmit method.
|
||||
|
||||
|
@ -125,7 +136,7 @@ class PhysicalLayer {
|
|||
|
||||
\param str Address of Arduino String to save the received data.
|
||||
|
||||
\param len Expected number of characters in the message. Must be known in advance for %LoRa spreading factor 6.
|
||||
\param len Expected number of characters in the message.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue