Update RadioLib
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
#include "AFSK.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
|
||||
AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin): _pin(pin) {
|
||||
_phy = phy;
|
||||
AFSKClient::AFSKClient(PhysicalLayer* phy, uint32_t pin): outPin(pin) {
|
||||
phyLayer = phy;
|
||||
}
|
||||
|
||||
AFSKClient::AFSKClient(AFSKClient* aud) {
|
||||
phyLayer = aud->phyLayer;
|
||||
outPin = aud->outPin;
|
||||
}
|
||||
|
||||
int16_t AFSKClient::begin() {
|
||||
return(_phy->startDirect());
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
int16_t AFSKClient::tone(uint16_t freq, bool autoStart) {
|
||||
@@ -15,23 +20,23 @@ int16_t AFSKClient::tone(uint16_t freq, bool autoStart) {
|
||||
}
|
||||
|
||||
if(autoStart) {
|
||||
int16_t state = _phy->transmitDirect();
|
||||
int16_t state = phyLayer->transmitDirect();
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
Module* mod = _phy->getMod();
|
||||
mod->tone(_pin, freq);
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->hal->tone(outPin, freq);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t AFSKClient::noTone(bool keepOn) {
|
||||
Module* mod = _phy->getMod();
|
||||
mod->noTone(_pin);
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->hal->noTone(outPin);
|
||||
if(keepOn) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(_phy->standby());
|
||||
return(phyLayer->standby());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
|
||||
#include "../../Module.h"
|
||||
|
||||
@@ -11,52 +11,49 @@
|
||||
|
||||
/*!
|
||||
\class AFSKClient
|
||||
|
||||
\brief Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direct mode transmission using DIO pins.
|
||||
*/
|
||||
class AFSKClient {
|
||||
public:
|
||||
/*!
|
||||
\brief Default contructor.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
|
||||
\param pin The pin that will be used for audio output.
|
||||
*/
|
||||
AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin);
|
||||
AFSKClient(PhysicalLayer* phy, uint32_t pin);
|
||||
|
||||
/*!
|
||||
\brief Copy contructor.
|
||||
\param aud Pointer to the AFSKClient instance to copy.
|
||||
*/
|
||||
explicit AFSKClient(AFSKClient* aud);
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin();
|
||||
|
||||
/*!
|
||||
\brief Start transmitting audio tone.
|
||||
|
||||
\param freq Frequency of the tone in Hz.
|
||||
|
||||
\param autoStart Whether to automatically enter transmission mode. Defaults to true.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t tone(uint16_t freq, bool autoStart = true);
|
||||
|
||||
/*!
|
||||
\brief Stops transmitting audio tone.
|
||||
|
||||
\param freq Keep transmitter on - this may limit noise when switching transmitter on or off.
|
||||
|
||||
\param keepOn Keep transmitter on - this may limit noise when switching transmitter on or off.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t noTone(bool keepOn = false);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
RADIOLIB_PIN_TYPE _pin;
|
||||
PhysicalLayer* phyLayer;
|
||||
uint32_t outPin;
|
||||
|
||||
// allow specific classes access the private PhysicalLayer pointer
|
||||
friend class RTTYClient;
|
||||
@@ -65,6 +62,7 @@ class AFSKClient {
|
||||
friend class SSTVClient;
|
||||
friend class AX25Client;
|
||||
friend class FSK4Client;
|
||||
friend class BellClient;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,54 +1,84 @@
|
||||
#include "APRS.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#if !RADIOLIB_EXCLUDE_APRS
|
||||
|
||||
APRSClient::APRSClient(AX25Client* ax) {
|
||||
_ax = ax;
|
||||
axClient = ax;
|
||||
phyLayer = nullptr;
|
||||
}
|
||||
|
||||
int16_t APRSClient::begin(char symbol, bool alt) {
|
||||
RADIOLIB_CHECK_RANGE(symbol, ' ', '}', RADIOLIB_ERR_INVALID_SYMBOL);
|
||||
_symbol = symbol;
|
||||
APRSClient::APRSClient(PhysicalLayer* phy) {
|
||||
axClient = nullptr;
|
||||
phyLayer = phy;
|
||||
}
|
||||
|
||||
int16_t APRSClient::begin(char sym, char* callsign, uint8_t ssid, bool alt) {
|
||||
RADIOLIB_CHECK_RANGE(sym, ' ', '}', RADIOLIB_ERR_INVALID_SYMBOL);
|
||||
symbol = sym;
|
||||
|
||||
if(alt) {
|
||||
_table = '\\';
|
||||
table = '\\';
|
||||
} else {
|
||||
_table = '/';
|
||||
table = '/';
|
||||
}
|
||||
|
||||
// callsign is only processed for LoRa APRS
|
||||
if(!callsign) {
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
if(strlen(callsign) > RADIOLIB_AX25_MAX_CALLSIGN_LEN) {
|
||||
return(RADIOLIB_ERR_INVALID_CALLSIGN);
|
||||
}
|
||||
|
||||
memcpy(this->src, callsign, strlen(callsign));
|
||||
this->id = ssid;
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t APRSClient::sendPosition(char* destCallsign, uint8_t destSSID, char* lat, char* lon, char* msg, char* time) {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
size_t len = 1 + strlen(lat) + 1 + strlen(lon);
|
||||
if(msg != NULL) {
|
||||
len += 1 + strlen(msg);
|
||||
}
|
||||
if(time != NULL) {
|
||||
len += strlen(time);
|
||||
}
|
||||
char* info = new char[len];
|
||||
size_t len = 1 + strlen(lat) + 1 + strlen(lon);
|
||||
if(msg != NULL) {
|
||||
len += 1 + strlen(msg);
|
||||
}
|
||||
if(time != NULL) {
|
||||
len += strlen(time);
|
||||
}
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
char* info = new char[len + 2];
|
||||
#else
|
||||
char info[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#endif
|
||||
|
||||
// build the info field
|
||||
if((msg == NULL) && (time == NULL)) {
|
||||
// no message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_NO_MSG "%s%c%s%c", lat, _table, lon, _symbol);
|
||||
} else if((msg != NULL) && (time == NULL)) {
|
||||
// message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_MSG "%s%c%s%c%s", lat, _table, lon, _symbol, msg);
|
||||
} else if((msg == NULL) && (time != NULL)) {
|
||||
// timestamp, no message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_NO_MSG "%s%s%c%s%c", time, lat, _table, lon, _symbol);
|
||||
if(msg != NULL) {
|
||||
if(time != NULL) {
|
||||
// timestamp and message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_MSG "%s%s%c%s%c%s", time, lat, table, lon, symbol, msg);
|
||||
} else {
|
||||
// message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_MSG "%s%c%s%c%s", lat, table, lon, symbol, msg);
|
||||
}
|
||||
|
||||
} else {
|
||||
// timestamp and message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_MSG "%s%s%c%s%c%s", time, lat, _table, lon, _symbol, msg);
|
||||
if(time != NULL) {
|
||||
// timestamp, no message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_NO_MSG "%s%s%c%s%c", time, lat, table, lon, symbol);
|
||||
} else {
|
||||
// no message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_NO_MSG "%s%c%s%c", lat, table, lon, symbol);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// send the frame
|
||||
info[len] = '\0';
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("APRS Info: %s, length = %d", info, (int)len);
|
||||
int16_t state = sendFrame(destCallsign, destSSID, info);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] info;
|
||||
#endif
|
||||
return(state);
|
||||
@@ -71,7 +101,7 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
|
||||
// prepare buffers
|
||||
char destCallsign[7];
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
size_t infoLen = 10;
|
||||
if(telemLen > 0) {
|
||||
infoLen += 1 + telemLen;
|
||||
@@ -96,7 +126,7 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
// as discussed in https://github.com/jgromes/RadioLib/issues/430
|
||||
|
||||
// latitude first, because that is in the destination field
|
||||
float lat_abs = abs(lat);
|
||||
float lat_abs = RADIOLIB_ABS(lat);
|
||||
int lat_deg = (int)lat_abs;
|
||||
int lat_min = (lat_abs - (float)lat_deg) * 60.0f;
|
||||
int lat_hun = (((lat_abs - (float)lat_deg) * 60.0f) - lat_min) * 100.0f;
|
||||
@@ -129,7 +159,7 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
info[infoPos++] = RADIOLIB_APRS_MIC_E_GPS_DATA_CURRENT;
|
||||
|
||||
// encode the longtitude
|
||||
float lon_abs = abs(lon);
|
||||
float lon_abs = RADIOLIB_ABS(lon);
|
||||
int32_t lon_deg = (int32_t)lon_abs;
|
||||
int32_t lon_min = (lon_abs - (float)lon_deg) * 60.0f;
|
||||
int32_t lon_hun = (((lon_abs - (float)lon_deg) * 60.0f) - lon_min) * 100.0f;
|
||||
@@ -166,8 +196,8 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
|
||||
info[infoPos++] = speed_uni*10 + head_hun + 32;
|
||||
info[infoPos++] = head_ten_uni + 28;
|
||||
info[infoPos++] = _symbol;
|
||||
info[infoPos++] = _table;
|
||||
info[infoPos++] = symbol;
|
||||
info[infoPos++] = table;
|
||||
|
||||
// onto the optional stuff - check telemetry first
|
||||
if(telemLen > 0) {
|
||||
@@ -207,21 +237,43 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
info[infoPos++] = '\0';
|
||||
|
||||
// send the frame
|
||||
int16_t state = sendFrame(destCallsign, 0, info);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
uint8_t destSSID = 0;
|
||||
if(this->phyLayer != nullptr) {
|
||||
// TODO make SSID configurable?
|
||||
destSSID = 1;
|
||||
}
|
||||
int16_t state = sendFrame(destCallsign, destSSID, info);
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] info;
|
||||
#endif
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t APRSClient::sendFrame(char* destCallsign, uint8_t destSSID, char* info) {
|
||||
// get AX.25 callsign
|
||||
char srcCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1];
|
||||
_ax->getCallsign(srcCallsign);
|
||||
// encoding depends on whether AX.25 should be used or not
|
||||
if(this->axClient != nullptr) {
|
||||
// AX.25/classical mode, get AX.25 callsign
|
||||
char srcCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1];
|
||||
axClient->getCallsign(srcCallsign);
|
||||
|
||||
AX25Frame frameUI(destCallsign, destSSID, srcCallsign, _ax->getSSID(), RADIOLIB_AX25_CONTROL_U_UNNUMBERED_INFORMATION |
|
||||
RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME,
|
||||
RADIOLIB_AX25_PID_NO_LAYER_3, (const char*)info);
|
||||
AX25Frame frameUI(destCallsign, destSSID, srcCallsign, axClient->getSSID(),
|
||||
RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME,
|
||||
RADIOLIB_AX25_PID_NO_LAYER_3, const_cast<char*>(info));
|
||||
|
||||
return(_ax->sendFrame(&frameUI));
|
||||
return(axClient->sendFrame(&frameUI));
|
||||
|
||||
} else if(this->phyLayer != nullptr) {
|
||||
// non-AX.25/LoRa mode
|
||||
size_t len = RADIOLIB_APRS_LORA_HEADER_LEN + strlen(this->src) + 4 + strlen(destCallsign) + 11 + strlen(info);
|
||||
char* buff = new char[len];
|
||||
snprintf(buff, len, RADIOLIB_APRS_LORA_HEADER "%s-%d>%s,WIDE%d-%d:%s", this->src, this->id, destCallsign, destSSID, destSSID, info);
|
||||
|
||||
int16_t res = this->phyLayer->transmit(reinterpret_cast<uint8_t*>(buff), strlen(buff));
|
||||
delete[] buff;
|
||||
return(res);
|
||||
}
|
||||
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#if !defined(_RADIOLIB_RADIOLIB_APRS_H)
|
||||
#define _RADIOLIB_RADIOLIB_APRS_H
|
||||
#if !defined(_RADIOLIB_APRS_H)
|
||||
#define _RADIOLIB_APRS_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_APRS)
|
||||
#if !RADIOLIB_EXCLUDE_APRS
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AX25/AX25.h"
|
||||
@@ -29,17 +29,33 @@
|
||||
|
||||
/*!
|
||||
\defgroup mic_e_message_types Mic-E message types.
|
||||
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \brief Mic-E "Off duty" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_OFF_DUTY 0b00000111
|
||||
|
||||
/*! \brief Mic-E "En route" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_EN_ROUTE 0b00000110
|
||||
|
||||
/*! \brief Mic-E "In service" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_IN_SERVICE 0b00000101
|
||||
|
||||
/*! \brief Mic-E "Returning" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_RETURNING 0b00000100
|
||||
|
||||
/*! \brief Mic-E "Commited" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_COMMITTED 0b00000011
|
||||
|
||||
/*! \brief Mic-E special message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_SPECIAL 0b00000010
|
||||
|
||||
/*! \brief Mic-E priority message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_PRIORITY 0b00000001
|
||||
|
||||
/*! \brief Mic-E emergency message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_EMERGENCY 0b00000000
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
@@ -58,98 +74,89 @@
|
||||
// alias for unused altitude in Mic-E
|
||||
#define RADIOLIB_APRS_MIC_E_ALTITUDE_UNUSED -1000000
|
||||
|
||||
// special header applied for APRS over LoRa
|
||||
#define RADIOLIB_APRS_LORA_HEADER "<\xff\x01"
|
||||
#define RADIOLIB_APRS_LORA_HEADER_LEN (3)
|
||||
|
||||
/*!
|
||||
\class APRSClient
|
||||
|
||||
\brief Client for APRS communication.
|
||||
*/
|
||||
class APRSClient {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\brief Constructor for "classic" mode using AX.25/AFSK.
|
||||
\param ax Pointer to the instance of AX25Client to be used for APRS.
|
||||
*/
|
||||
explicit APRSClient(AX25Client* ax);
|
||||
|
||||
/*!
|
||||
\brief Constructor for LoRa mode.
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit APRSClient(PhysicalLayer* phy);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param symbol APRS symbol to be displayed.
|
||||
|
||||
\param sym APRS symbol to be displayed.
|
||||
\param callsign Source callsign. Required and only used for APRS over LoRa, ignored in classic mode.
|
||||
\param ssid Source SSID. Only used for APRS over LoRa, ignored in classic mode, defaults to 0.
|
||||
\param alt Whether to use the primary (false) or alternate (true) symbol table. Defaults to primary table.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(char symbol, bool alt = false);
|
||||
int16_t begin(char sym, char* callsign = NULL, uint8_t ssid = 0, bool alt = false);
|
||||
|
||||
/*!
|
||||
\brief Transmit position.
|
||||
|
||||
\param destCallsign Destination station callsign.
|
||||
|
||||
\param destSSID Destination station SSID.
|
||||
|
||||
\param lat Latitude as a null-terminated string.
|
||||
|
||||
\param long Longitude as a null-terminated string.
|
||||
|
||||
\param lon Longitude as a null-terminated string.
|
||||
\param msg Message to be transmitted. Defaults to NULL (no message).
|
||||
|
||||
\param msg Position timestamp. Defaults to NULL (no timestamp).
|
||||
|
||||
\param time Position timestamp. Defaults to NULL (no timestamp).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendPosition(char* destCallsign, uint8_t destSSID, char* lat, char* lon, char* msg = NULL, char* time = NULL);
|
||||
|
||||
/*
|
||||
/*!
|
||||
\brief Transmit position using Mic-E encoding.
|
||||
|
||||
\param lat Geographical latitude, positive for north, negative for south.
|
||||
|
||||
\param lon Geographical longitude, positive for east, negative for west.
|
||||
|
||||
\param heading Heading in degrees.
|
||||
|
||||
\param speed Speed in knots.
|
||||
|
||||
\param type Mic-E message type - see \ref mic_e_message_types.
|
||||
|
||||
\param telem Pointer to telemetry array (either 2 or 5 bytes long). NULL when telemetry is not used.
|
||||
|
||||
\param telemLen Telemetry length, 2 or 5. 0 when telemetry is not used.
|
||||
|
||||
\param grid Maidenhead grid locator. NULL when not used.
|
||||
|
||||
\param status Status message to send. NULL when not used.
|
||||
|
||||
\param alt Altitude to send. RADIOLIB_APRS_MIC_E_ALTITUDE_UNUSED when not used.
|
||||
*/
|
||||
int16_t sendMicE(float lat, float lon, uint16_t heading, uint16_t speed, uint8_t type, uint8_t* telem = NULL, size_t telemLen = 0, char* grid = NULL, char* status = NULL, int32_t alt = RADIOLIB_APRS_MIC_E_ALTITUDE_UNUSED);
|
||||
|
||||
/*!
|
||||
\brief Transmit generic APRS frame.
|
||||
|
||||
\param destCallsign Destination station callsign.
|
||||
|
||||
\param destSSID Destination station SSID.
|
||||
|
||||
\param info AX.25 info field contents.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendFrame(char* destCallsign, uint8_t destSSID, char* info);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
AX25Client* _ax;
|
||||
AX25Client* axClient;
|
||||
PhysicalLayer* phyLayer;
|
||||
|
||||
// default APRS symbol (car)
|
||||
char _symbol = '>';
|
||||
char _table = '/';
|
||||
char symbol = '>';
|
||||
char table = '/';
|
||||
|
||||
// source callsign when using APRS over LoRa
|
||||
char src[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = { 0 };
|
||||
uint8_t id = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "AX25.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_AX25)
|
||||
#include <string.h>
|
||||
#if !RADIOLIB_EXCLUDE_AX25
|
||||
|
||||
AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control)
|
||||
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, 0, NULL, 0) {
|
||||
@@ -7,7 +8,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
||||
}
|
||||
|
||||
AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, const char* info)
|
||||
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, protocolID, (uint8_t*)info, strlen(info)) {
|
||||
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, protocolID, reinterpret_cast<uint8_t*>(const_cast<char*>(info)), strlen(info)) {
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
||||
|
||||
// set repeaters
|
||||
this->numRepeaters = 0;
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = NULL;
|
||||
this->repeaterSSIDs = NULL;
|
||||
#endif
|
||||
@@ -42,19 +43,52 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
||||
// info field
|
||||
this->infoLen = infoLen;
|
||||
if(infoLen > 0) {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->info = new uint8_t[infoLen];
|
||||
#endif
|
||||
memcpy(this->info, info, infoLen);
|
||||
}
|
||||
}
|
||||
|
||||
AX25Frame::AX25Frame(const AX25Frame& frame) {
|
||||
*this = frame;
|
||||
AX25Frame::AX25Frame(const AX25Frame& frame)
|
||||
: destSSID(frame.destSSID),
|
||||
srcSSID(frame.srcSSID),
|
||||
numRepeaters(frame.numRepeaters),
|
||||
control(frame.control),
|
||||
protocolID(frame.protocolID),
|
||||
infoLen(frame.infoLen),
|
||||
rcvSeqNumber(frame.rcvSeqNumber),
|
||||
sendSeqNumber(frame.sendSeqNumber) {
|
||||
strncpy(this->destCallsign, frame.destCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
strncpy(this->srcCallsign, frame.srcCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
|
||||
if(frame.infoLen) {
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->info = new uint8_t[frame.infoLen];
|
||||
#endif
|
||||
memcpy(this->info, frame.info, frame.infoLen);
|
||||
}
|
||||
|
||||
if(frame.numRepeaters) {
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = new char*[frame.numRepeaters];
|
||||
for(uint8_t i = 0; i < frame.numRepeaters; i++) {
|
||||
this->repeaterCallsigns[i] = new char[strlen(frame.repeaterCallsigns[i]) + 1];
|
||||
}
|
||||
this->repeaterSSIDs = new uint8_t[frame.numRepeaters];
|
||||
#endif
|
||||
|
||||
this->numRepeaters = frame.numRepeaters;
|
||||
for(uint8_t i = 0; i < frame.numRepeaters; i++) {
|
||||
memcpy(this->repeaterCallsigns[i], frame.repeaterCallsigns[i], strlen(frame.repeaterCallsigns[i]));
|
||||
this->repeaterCallsigns[i][strlen(frame.repeaterCallsigns[i])] = '\0';
|
||||
}
|
||||
memcpy(this->repeaterSSIDs, frame.repeaterSSIDs, frame.numRepeaters);
|
||||
}
|
||||
}
|
||||
|
||||
AX25Frame::~AX25Frame() {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
// deallocate info field
|
||||
if(infoLen > 0) {
|
||||
delete[] this->info;
|
||||
@@ -123,7 +157,7 @@ int16_t AX25Frame::setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs
|
||||
}
|
||||
|
||||
// create buffers
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = new char*[numRepeaters];
|
||||
for(uint8_t i = 0; i < numRepeaters; i++) {
|
||||
this->repeaterCallsigns[i] = new char[strlen(repeaterCallsigns[i]) + 1];
|
||||
@@ -151,30 +185,65 @@ void AX25Frame::setSendSequence(uint8_t seqNumber) {
|
||||
}
|
||||
|
||||
AX25Client::AX25Client(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audio = nullptr;
|
||||
bellModem = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AX25Client::AX25Client(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
_afskMark = RADIOLIB_AX25_AFSK_MARK;
|
||||
_afskSpace = RADIOLIB_AX25_AFSK_SPACE;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AX25Client::AX25Client(AFSKClient* aud)
|
||||
: audio(aud) {
|
||||
phyLayer = this->audio->phyLayer;
|
||||
bellModem = new BellClient(this->audio);
|
||||
bellModem->setModem(Bell202);
|
||||
}
|
||||
|
||||
int16_t AX25Client::setCorrection(int16_t mark, int16_t space) {
|
||||
_afskMark = RADIOLIB_AX25_AFSK_MARK + mark;
|
||||
_afskSpace = RADIOLIB_AX25_AFSK_SPACE + space;
|
||||
AX25Client::AX25Client(const AX25Client& ax25)
|
||||
: phyLayer(ax25.phyLayer),
|
||||
sourceSSID(ax25.sourceSSID),
|
||||
preambleLen(ax25.preambleLen) {
|
||||
strncpy(sourceCallsign, ax25.sourceCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(ax25.bellModem) {
|
||||
this->audio = ax25.audio;
|
||||
this->bellModem = new BellClient(ax25.audio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
AX25Client& AX25Client::operator=(const AX25Client& ax25) {
|
||||
if(&ax25 != this) {
|
||||
this->phyLayer = ax25.phyLayer;
|
||||
this->sourceSSID = ax25.sourceSSID;
|
||||
this->preambleLen = ax25.preambleLen;
|
||||
strncpy(sourceCallsign, ax25.sourceCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(ax25.bellModem) {
|
||||
this->audio = ax25.audio;
|
||||
this->bellModem = new BellClient(ax25.audio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return(*this);
|
||||
}
|
||||
|
||||
int16_t AX25Client::setCorrection(int16_t mark, int16_t space, float length) {
|
||||
BellModem_t modem;
|
||||
modem.freqMark = Bell202.freqMark + mark;
|
||||
modem.freqSpace = Bell202.freqSpace + space;
|
||||
modem.freqMarkReply = modem.freqMark;
|
||||
modem.freqSpaceReply = modem.freqSpace;
|
||||
modem.baudRate = length*(float)Bell202.baudRate;
|
||||
bellModem->setModem(modem);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preambleLen) {
|
||||
int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preLen) {
|
||||
// set source SSID
|
||||
_srcSSID = srcSSID;
|
||||
sourceSSID = srcSSID;
|
||||
|
||||
// check source callsign length (6 characters max)
|
||||
if(strlen(srcCallsign) > RADIOLIB_AX25_MAX_CALLSIGN_LEN) {
|
||||
@@ -182,22 +251,30 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t prea
|
||||
}
|
||||
|
||||
// copy callsign
|
||||
memcpy(_srcCallsign, srcCallsign, strlen(srcCallsign));
|
||||
_srcCallsign[strlen(srcCallsign)] = '\0';
|
||||
memcpy(sourceCallsign, srcCallsign, strlen(srcCallsign));
|
||||
sourceCallsign[strlen(srcCallsign)] = '\0';
|
||||
|
||||
// save preamble length
|
||||
_preambleLen = preambleLen;
|
||||
preambleLen = preLen;
|
||||
|
||||
// configure for direct mode
|
||||
return(_phy->startDirect());
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t AX25Client::transmit(String& str, const char* destCallsign, uint8_t destSSID) {
|
||||
return(transmit(str.c_str(), destCallsign, destSSID));
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t AX25Client::transmit(const char* str, const char* destCallsign, uint8_t destSSID) {
|
||||
// create control field
|
||||
uint8_t controlField = RADIOLIB_AX25_CONTROL_U_UNNUMBERED_INFORMATION | RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME;
|
||||
uint8_t controlField = RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME;
|
||||
|
||||
// build the frame
|
||||
AX25Frame frame(destCallsign, destSSID, _srcCallsign, _srcSSID, controlField, RADIOLIB_AX25_PID_NO_LAYER_3, (uint8_t*)str, strlen(str));
|
||||
AX25Frame frame(destCallsign, destSSID, sourceCallsign, sourceSSID, controlField,
|
||||
RADIOLIB_AX25_PID_NO_LAYER_3,
|
||||
reinterpret_cast<uint8_t*>(const_cast<char*>(str)), strlen(str));
|
||||
|
||||
// send Unnumbered Information frame
|
||||
return(sendFrame(&frame));
|
||||
@@ -210,7 +287,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
// check repeater configuration
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
if(!(((frame->repeaterCallsigns == NULL) && (frame->repeaterSSIDs == NULL) && (frame->numRepeaters == 0)) ||
|
||||
((frame->repeaterCallsigns != NULL) && (frame->repeaterSSIDs != NULL) && (frame->numRepeaters != 0)))) {
|
||||
return(RADIOLIB_ERR_INVALID_NUM_REPEATERS);
|
||||
@@ -225,7 +302,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
// calculate frame length without FCS (destination address, source address, repeater addresses, control, PID, info)
|
||||
size_t frameBuffLen = ((2 + frame->numRepeaters)*(RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1)) + 1 + 1 + frame->infoLen;
|
||||
// create frame buffer without preamble, start or stop flags
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
uint8_t* frameBuff = new uint8_t[frameBuffLen + 2];
|
||||
#else
|
||||
uint8_t frameBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
@@ -292,27 +369,33 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
|
||||
// flip bit order
|
||||
for(size_t i = 0; i < frameBuffLen; i++) {
|
||||
frameBuff[i] = Module::flipBits(frameBuff[i]);
|
||||
frameBuff[i] = Module::reflect(frameBuff[i], 8);
|
||||
}
|
||||
|
||||
// calculate FCS
|
||||
uint16_t fcs = getFrameCheckSequence(frameBuff, frameBuffLen);
|
||||
// calculate
|
||||
RadioLibCRCInstance.size = 16;
|
||||
RadioLibCRCInstance.poly = RADIOLIB_CRC_CCITT_POLY;
|
||||
RadioLibCRCInstance.init = RADIOLIB_CRC_CCITT_INIT;
|
||||
RadioLibCRCInstance.out = RADIOLIB_CRC_CCITT_OUT;
|
||||
RadioLibCRCInstance.refIn = false;
|
||||
RadioLibCRCInstance.refOut = false;
|
||||
uint16_t fcs = RadioLibCRCInstance.checksum(frameBuff, frameBuffLen);
|
||||
*(frameBuffPtr++) = (uint8_t)((fcs >> 8) & 0xFF);
|
||||
*(frameBuffPtr++) = (uint8_t)(fcs & 0xFF);
|
||||
|
||||
// prepare buffer for the final frame (stuffed, with added preamble + flags and NRZI-encoded)
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
// worst-case scenario: sequence of 1s, will have 120% of the original length, stuffed frame also includes both flags
|
||||
uint8_t* stuffedFrameBuff = new uint8_t[_preambleLen + 1 + (6*frameBuffLen)/5 + 2];
|
||||
uint8_t* stuffedFrameBuff = new uint8_t[preambleLen + 1 + (6*frameBuffLen)/5 + 2];
|
||||
#else
|
||||
uint8_t stuffedFrameBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#endif
|
||||
|
||||
// initialize buffer to all zeros
|
||||
memset(stuffedFrameBuff, 0x00, _preambleLen + 1 + (6*frameBuffLen)/5 + 2);
|
||||
memset(stuffedFrameBuff, 0x00, preambleLen + 1 + (6*frameBuffLen)/5 + 2);
|
||||
|
||||
// stuff bits (skip preamble and both flags)
|
||||
uint16_t stuffedFrameBuffLenBits = 8*(_preambleLen + 1);
|
||||
uint16_t stuffedFrameBuffLenBits = 8*(preambleLen + 1);
|
||||
uint8_t count = 0;
|
||||
for(size_t i = 0; i < frameBuffLen + 2; i++) {
|
||||
for(int8_t shift = 7; shift >= 0; shift--) {
|
||||
@@ -345,12 +428,12 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
// deallocate memory
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] frameBuff;
|
||||
#endif
|
||||
|
||||
// set preamble bytes and start flag field
|
||||
for(uint16_t i = 0; i < _preambleLen + 1; i++) {
|
||||
for(uint16_t i = 0; i < preambleLen + 1; i++) {
|
||||
stuffedFrameBuff[i] = RADIOLIB_AX25_FLAG;
|
||||
}
|
||||
|
||||
@@ -368,7 +451,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
// convert to NRZI
|
||||
for(size_t i = _preambleLen + 1; i < stuffedFrameBuffLen*8; i++) {
|
||||
for(size_t i = preambleLen + 1; i < stuffedFrameBuffLen*8; i++) {
|
||||
size_t currBitPos = i + 7 - 2*(i%8);
|
||||
size_t prevBitPos = (i - 1) + 7 - 2*((i - 1)%8);
|
||||
if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos)) {
|
||||
@@ -391,40 +474,26 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
|
||||
// transmit
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
Module* mod = _phy->getMod();
|
||||
_phy->transmitDirect();
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(bellModem != nullptr) {
|
||||
bellModem->idle();
|
||||
|
||||
// iterate over all bytes in the buffer
|
||||
for(uint32_t i = 0; i < stuffedFrameBuffLen; i++) {
|
||||
|
||||
// check each bit
|
||||
for(uint16_t mask = 0x80; mask >= 0x01; mask >>= 1) {
|
||||
uint32_t start = mod->micros();
|
||||
if(stuffedFrameBuff[i] & mask) {
|
||||
_audio->tone(_afskMark, false);
|
||||
} else {
|
||||
_audio->tone(_afskSpace, false);
|
||||
}
|
||||
while(mod->micros() - start < RADIOLIB_AX25_AFSK_TONE_DURATION) {
|
||||
mod->yield();
|
||||
}
|
||||
}
|
||||
|
||||
bellModem->write(stuffedFrameBuff[i]);
|
||||
}
|
||||
|
||||
_audio->noTone();
|
||||
bellModem->standby();
|
||||
|
||||
} else {
|
||||
#endif
|
||||
state = _phy->transmit(stuffedFrameBuff, stuffedFrameBuffLen);
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
state = phyLayer->transmit(stuffedFrameBuff, stuffedFrameBuffLen);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
}
|
||||
#endif
|
||||
|
||||
// deallocate memory
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] stuffedFrameBuff;
|
||||
#endif
|
||||
|
||||
@@ -432,34 +501,11 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
void AX25Client::getCallsign(char* buff) {
|
||||
strncpy(buff, _srcCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN);
|
||||
strncpy(buff, sourceCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
}
|
||||
|
||||
uint8_t AX25Client::getSSID() {
|
||||
return(_srcSSID);
|
||||
}
|
||||
|
||||
/*
|
||||
CCITT CRC implementation based on https://github.com/kicksat/ax25
|
||||
|
||||
Licensed under Creative Commons Attribution-ShareAlike 4.0 International
|
||||
https://creativecommons.org/licenses/by-sa/4.0/
|
||||
*/
|
||||
uint16_t AX25Client::getFrameCheckSequence(uint8_t* buff, size_t len) {
|
||||
uint8_t outBit;
|
||||
uint16_t mask;
|
||||
uint16_t shiftReg = CRC_CCITT_INIT;
|
||||
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
for(uint8_t b = 0x80; b > 0x00; b /= 2) {
|
||||
outBit = (shiftReg & 0x01) ? 0x01 : 0x00;
|
||||
shiftReg >>= 1;
|
||||
mask = XOR((buff[i] & b), outBit) ? CRC_CCITT_POLY_REVERSED : 0x0000;
|
||||
shiftReg ^= mask;
|
||||
}
|
||||
}
|
||||
|
||||
return(Module::flipBits16(~shiftReg));
|
||||
return(sourceSSID);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,29 +1,20 @@
|
||||
#if !defined(_RADIOLIB_RADIOLIB_AX25_H)
|
||||
#define _RADIOLIB_RADIOLIB_AX25_H
|
||||
#if !defined(_RADIOLIB_AX25_H)
|
||||
#define _RADIOLIB_AX25_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AX25)
|
||||
#if !RADIOLIB_EXCLUDE_AX25
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
|
||||
// macros to access bits in byte array, from http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html
|
||||
#define SET_BIT_IN_ARRAY(A, k) ( A[(k/8)] |= (1 << (k%8)) )
|
||||
#define CLEAR_BIT_IN_ARRAY(A, k) ( A[(k/8)] &= ~(1 << (k%8)) )
|
||||
#define TEST_BIT_IN_ARRAY(A, k) ( A[(k/8)] & (1 << (k%8)) )
|
||||
#define GET_BIT_IN_ARRAY(A, k) ( (A[(k/8)] & (1 << (k%8))) ? 1 : 0 )
|
||||
|
||||
// CRC-CCITT calculation macros
|
||||
#define XOR(A, B) ( ((A) || (B)) && !((A) && (B)) )
|
||||
#define CRC_CCITT_POLY 0x1021 // generator polynomial
|
||||
#define CRC_CCITT_POLY_REVERSED 0x8408 // CRC_CCITT_POLY in reversed bit order
|
||||
#define CRC_CCITT_INIT 0xFFFF // initial value
|
||||
#include "../BellModem/BellModem.h"
|
||||
#include "../../utils/CRC.h"
|
||||
#include "../../utils/FEC.h"
|
||||
|
||||
// maximum callsign length in bytes
|
||||
#define RADIOLIB_AX25_MAX_CALLSIGN_LEN 6
|
||||
|
||||
// flag field MSB LSB DESCRIPTION
|
||||
// flag field MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_AX25_FLAG 0b01111110 // 7 0 AX.25 frame start/end flag
|
||||
|
||||
// address field
|
||||
@@ -73,16 +64,8 @@
|
||||
#define RADIOLIB_AX25_PID_NO_LAYER_3 0xF0
|
||||
#define RADIOLIB_AX25_PID_ESCAPE_CHARACTER 0xFF
|
||||
|
||||
// AFSK tones in Hz
|
||||
#define RADIOLIB_AX25_AFSK_MARK 1200
|
||||
#define RADIOLIB_AX25_AFSK_SPACE 2200
|
||||
|
||||
// tone duration in us (for 1200 baud AFSK)
|
||||
#define RADIOLIB_AX25_AFSK_TONE_DURATION 833
|
||||
|
||||
/*!
|
||||
\class AX25Frame
|
||||
|
||||
\brief Abstraction of AX.25 frame format.
|
||||
*/
|
||||
class AX25Frame {
|
||||
@@ -137,7 +120,7 @@ class AX25Frame {
|
||||
*/
|
||||
uint16_t sendSeqNumber;
|
||||
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
/*!
|
||||
\brief The info field.
|
||||
*/
|
||||
@@ -171,62 +154,41 @@ class AX25Frame {
|
||||
|
||||
/*!
|
||||
\brief Overloaded constructor, for frames without info field.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID SSID of the destination station.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID SSID of the source station.
|
||||
|
||||
\param control The control field.
|
||||
*/
|
||||
AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control);
|
||||
|
||||
/*!
|
||||
\brief Overloaded constructor, for frames with C-string info field.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID SSID of the destination station.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID SSID of the source station.
|
||||
|
||||
\param control The control field.
|
||||
|
||||
\param protocolID The protocol identifier (PID) field. Set to zero if the frame doesn't have this field.
|
||||
|
||||
\param info Information field, in the form of null-terminated C-string.
|
||||
*/
|
||||
AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, const char* info);
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID SSID of the destination station.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID SSID of the source station.
|
||||
|
||||
\param control The control field.
|
||||
|
||||
\param protocolID The protocol identifier (PID) field. Set to zero if the frame doesn't have this field.
|
||||
|
||||
\param info Information field, in the form of arbitrary binary buffer.
|
||||
|
||||
\param infoLen Number of bytes in the information field.
|
||||
*/
|
||||
AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, uint8_t* info, uint16_t infoLen);
|
||||
|
||||
/*!
|
||||
\brief Copy constructor.
|
||||
|
||||
\param frame AX25Frame instance to copy.
|
||||
*/
|
||||
AX25Frame(const AX25Frame& frame);
|
||||
@@ -238,34 +200,27 @@ class AX25Frame {
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
|
||||
\param frame rvalue AX25Frame.
|
||||
*/
|
||||
AX25Frame& operator=(const AX25Frame& frame);
|
||||
|
||||
/*!
|
||||
\brief Method to set the repeater callsigns and SSIDs.
|
||||
|
||||
\param repeaterCallsigns Array of repeater callsigns in the form of null-terminated C-strings.
|
||||
|
||||
\param repeaterSSIDs Array of repeater SSIDs.
|
||||
|
||||
\param numRepeaters Number of repeaters, maximum is 8.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs, uint8_t numRepeaters);
|
||||
|
||||
/*!
|
||||
\brief Method to set receive sequence number.
|
||||
|
||||
\param seqNumber Sequence number to set, 0 to 7.
|
||||
*/
|
||||
void setRecvSequence(uint8_t seqNumber);
|
||||
|
||||
/*!
|
||||
\brief Method to set send sequence number.
|
||||
|
||||
\param seqNumber Sequence number to set, 0 to 7.
|
||||
*/
|
||||
void setSendSequence(uint8_t seqNumber);
|
||||
@@ -273,92 +228,102 @@ class AX25Frame {
|
||||
|
||||
/*!
|
||||
\class AX25Client
|
||||
|
||||
\brief Client for AX25 communication.
|
||||
*/
|
||||
class AX25Client {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for 2-FSK mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit AX25Client(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
\param aud Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit AX25Client(AFSKClient* audio);
|
||||
explicit AX25Client(AFSKClient* aud);
|
||||
|
||||
/*!
|
||||
\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.
|
||||
\brief Copy constructor.
|
||||
\param ax25 AX25Client instance to copy.
|
||||
*/
|
||||
AX25Client(const AX25Client& ax25);
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
\param ax25 rvalue AX25Client.
|
||||
*/
|
||||
AX25Client& operator=(const AX25Client& ax25);
|
||||
|
||||
/*!
|
||||
\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.
|
||||
|
||||
\param length Audio tone length modifier, defaults to 1.0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCorrection(int16_t mark, int16_t space);
|
||||
int16_t setCorrection(int16_t mark, int16_t space, float length = 1.0f);
|
||||
#endif
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID 4-bit SSID of the source station (in case there are more stations with the same callsign). Defaults to 0.
|
||||
|
||||
\param preambleLen Number of "preamble" bytes (RADIOLIB_AX25_FLAG) sent ahead of the actual AX.25 frame. Does not include the first RADIOLIB_AX25_FLAG byte, which is considered part of the frame. Defaults to 8.
|
||||
|
||||
\param srcSSID 4-bit SSID of the source station (in case there are more stations with the same callsign).
|
||||
Defaults to 0.
|
||||
\param preLen Number of "preamble" bytes (RADIOLIB_AX25_FLAG) sent ahead of the actual AX.25 frame.
|
||||
Does not include the first RADIOLIB_AX25_FLAG byte, which is considered part of the frame. Defaults to 8.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(const char* srcCallsign, uint8_t srcSSID = 0x00, uint8_t preambleLen = 8);
|
||||
int16_t begin(const char* srcCallsign, uint8_t srcSSID = 0x00, uint8_t preLen = 8);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Transmit unnumbered information (UI) frame.
|
||||
\param str Data to be sent as Arduino String.
|
||||
\param destCallsign Callsign of the destination station.
|
||||
\param destSSID 4-bit SSID of the destination station (in case there are more stations with the same callsign).
|
||||
Defaults to 0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(String& str, const char* destCallsign, uint8_t destSSID = 0x00);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Transmit unnumbered information (UI) frame.
|
||||
|
||||
\param str Data to be sent.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID 4-bit SSID of the destination station (in case there are more stations with the same callsign). Defaults to 0.
|
||||
|
||||
\param destSSID 4-bit SSID of the destination station (in case there are more stations with the same callsign).
|
||||
Defaults to 0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(const char* str, const char* destCallsign, uint8_t destSSID = 0x00);
|
||||
|
||||
/*!
|
||||
\brief Transmit arbitrary AX.25 frame.
|
||||
|
||||
\param frame Frame to be sent.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendFrame(AX25Frame* frame);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
friend class APRSClient;
|
||||
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
uint32_t _afskMark;
|
||||
uint32_t _afskSpace;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AFSKClient* audio;
|
||||
BellClient* bellModem;
|
||||
#endif
|
||||
|
||||
char _srcCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = {0, 0, 0, 0, 0, 0, 0};
|
||||
uint8_t _srcSSID = 0;
|
||||
uint16_t _preambleLen = 0;
|
||||
|
||||
static uint16_t getFrameCheckSequence(uint8_t* buff, size_t len);
|
||||
char sourceCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = { 0 };
|
||||
uint8_t sourceSSID = 0;
|
||||
uint16_t preambleLen = 0;
|
||||
|
||||
void getCallsign(char* buff);
|
||||
uint8_t getSSID();
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#include "BellModem.h"
|
||||
#if !RADIOLIB_EXCLUDE_BELL
|
||||
|
||||
const BellModem_t Bell101 = {
|
||||
.freqMark = 1270,
|
||||
.freqSpace = 1070,
|
||||
.baudRate = 110,
|
||||
.freqMarkReply = 2225,
|
||||
.freqSpaceReply = 2025,
|
||||
};
|
||||
|
||||
const BellModem_t Bell103 = {
|
||||
.freqMark = 1270,
|
||||
.freqSpace = 1070,
|
||||
.baudRate = 300,
|
||||
.freqMarkReply = 2225,
|
||||
.freqSpaceReply = 2025,
|
||||
};
|
||||
|
||||
const BellModem_t Bell202 = {
|
||||
.freqMark = 1200,
|
||||
.freqSpace = 2200,
|
||||
.baudRate = 1200,
|
||||
.freqMarkReply = 1200,
|
||||
.freqSpaceReply = 2200,
|
||||
};
|
||||
|
||||
BellClient::BellClient(PhysicalLayer* phy, uint32_t pin) : AFSKClient(phy, pin) {
|
||||
this->reply = false;
|
||||
}
|
||||
|
||||
BellClient::BellClient(AFSKClient* aud) : AFSKClient(aud) {
|
||||
this->reply = false;
|
||||
}
|
||||
|
||||
int16_t BellClient::begin(const BellModem_t& modem) {
|
||||
int16_t state = setModem(modem);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = phyLayer->startDirect();
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t BellClient::setModem(const BellModem_t& modem) {
|
||||
this->modemType = modem;
|
||||
this->toneLen = (1000000.0/(float)this->modemType.baudRate)*this->correction;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t BellClient::setCorrection(float corr) {
|
||||
this->correction = corr;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
size_t BellClient::write(uint8_t b) {
|
||||
// first get the frequencies
|
||||
uint16_t toneMark = this->modemType.freqMark;
|
||||
uint16_t toneSpace = this->modemType.freqSpace;
|
||||
if(this->reply) {
|
||||
toneMark = this->modemType.freqMarkReply;
|
||||
toneSpace = this->modemType.freqSpaceReply;
|
||||
}
|
||||
|
||||
// get the Module pointer to access HAL
|
||||
Module* mod = this->phyLayer->getMod();
|
||||
|
||||
if(this->autoStart) {
|
||||
phyLayer->transmitDirect();
|
||||
}
|
||||
|
||||
// iterate over the bits and set correct frequencies
|
||||
for(uint16_t mask = 0x80; mask >= 0x01; mask >>= 1) {
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
if(b & mask) {
|
||||
this->tone(toneMark, false);
|
||||
} else {
|
||||
this->tone(toneSpace, false);
|
||||
}
|
||||
mod->waitForMicroseconds(start, this->toneLen);
|
||||
}
|
||||
|
||||
if(this->autoStart) {
|
||||
phyLayer->standby();
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
int16_t BellClient::idle() {
|
||||
this->autoStart = false;
|
||||
return(phyLayer->transmitDirect());
|
||||
}
|
||||
|
||||
int16_t BellClient::standby() {
|
||||
this->autoStart = true;
|
||||
return(phyLayer->standby());
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,131 @@
|
||||
#if !defined(_RADIOLIB_BELL_MODEM_H)
|
||||
#define _RADIOLIB_BELL_MODEM_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
#include "../../Module.h"
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
#include "../../ArduinoHal.h"
|
||||
#endif
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_BELL
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
#include "../Print/Print.h"
|
||||
#include "../Print/ITA2String.h"
|
||||
|
||||
/*!
|
||||
\struct BellModem_t
|
||||
\brief Definition of the Bell-compatible modem.
|
||||
*/
|
||||
struct BellModem_t {
|
||||
/*!
|
||||
\brief Frequency of the mark tone.
|
||||
*/
|
||||
int16_t freqMark;
|
||||
|
||||
/*!
|
||||
\brief Frequency of the space tone.
|
||||
*/
|
||||
int16_t freqSpace;
|
||||
|
||||
/*!
|
||||
\brief Baud rate.
|
||||
*/
|
||||
int16_t baudRate;
|
||||
|
||||
/*!
|
||||
\brief Frequency of the mark tone when replying.
|
||||
*/
|
||||
int16_t freqMarkReply;
|
||||
|
||||
/*!
|
||||
\brief Frequency of the space tone when replying.
|
||||
*/
|
||||
int16_t freqSpaceReply;
|
||||
};
|
||||
|
||||
// currently implemented Bell modems
|
||||
extern const struct BellModem_t Bell101;
|
||||
extern const struct BellModem_t Bell103;
|
||||
extern const struct BellModem_t Bell202;
|
||||
|
||||
/*!
|
||||
\class BellClient
|
||||
\brief Client for Bell modem communication. The public interface is the same as Arduino Serial.
|
||||
*/
|
||||
class BellClient: public AFSKClient, public RadioLibPrint {
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
\brief Whether the modem is replying.
|
||||
On some modems, the replying station has different tone frequencies.
|
||||
*/
|
||||
bool reply;
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
\param pin The GPIO pin at which the tones will be generated.
|
||||
*/
|
||||
explicit BellClient(PhysicalLayer* phy, uint32_t pin);
|
||||
|
||||
/*!
|
||||
\brief Audio-client constructor. Can be used when AFSKClient instance already exists.
|
||||
\param aud Audio client to use.
|
||||
*/
|
||||
explicit BellClient(AFSKClient* aud);
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
\param modem Definition of the Bell modem to use for communication.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(const BellModem_t& modem);
|
||||
|
||||
/*!
|
||||
\brief Set Bell modem.
|
||||
\param modem Definition of the Bell modem to use for communication.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setModem(const BellModem_t& modem);
|
||||
|
||||
/*!
|
||||
\brief Set correction coefficient for tone length.
|
||||
\param corr Timing correction factor, used to adjust the length of tones.
|
||||
Less than 1.0 leads to shorter tones, defaults to 1.0 (no correction).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCorrection(float corr);
|
||||
|
||||
/*!
|
||||
\brief Write one byte. Implementation of interface of the RadioLibPrint/Print class.
|
||||
\param b Byte to write.
|
||||
\returns 1 if the byte was written, 0 otherwise.
|
||||
*/
|
||||
size_t write(uint8_t b) override;
|
||||
|
||||
/*!
|
||||
\brief Set the modem to idle (ready to transmit).
|
||||
*/
|
||||
int16_t idle();
|
||||
|
||||
/*!
|
||||
\brief Set the modem to standby (transmitter off).
|
||||
*/
|
||||
int16_t standby();
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
BellModem_t modemType = Bell101;
|
||||
float correction = 1.0;
|
||||
uint16_t toneLen = 0;
|
||||
bool autoStart = true;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "ExternalRadio.h"
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
ExternalRadio::ExternalRadio(uint32_t pin) : PhysicalLayer(1, 0) {
|
||||
mod = new Module(RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, pin);
|
||||
mod->hal->pinMode(pin, mod->hal->GpioModeOutput);
|
||||
this->prevFrf = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
ExternalRadio::ExternalRadio(RadioLibHal *hal, uint32_t pin) : PhysicalLayer(1, 0) {
|
||||
mod = new Module(hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, pin);
|
||||
mod->hal->pinMode(pin, mod->hal->GpioModeOutput);
|
||||
this->prevFrf = 0;
|
||||
}
|
||||
|
||||
ExternalRadio::ExternalRadio(const ExternalRadio& ext) : PhysicalLayer(1, 0) {
|
||||
this->prevFrf = ext.prevFrf;
|
||||
if(ext.mod) {
|
||||
this->mod = new Module(ext.mod->hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, ext.mod->getGpio());
|
||||
}
|
||||
}
|
||||
|
||||
ExternalRadio& ExternalRadio::operator=(const ExternalRadio& ext) {
|
||||
if(&ext != this) {
|
||||
this->prevFrf = ext.prevFrf;
|
||||
if(ext.mod) {
|
||||
this->mod = new Module(ext.mod->hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, ext.mod->getGpio());
|
||||
}
|
||||
}
|
||||
return(*this);
|
||||
}
|
||||
|
||||
ExternalRadio::~ExternalRadio() {
|
||||
if(this->mod) {
|
||||
delete this->mod;
|
||||
}
|
||||
}
|
||||
|
||||
Module* ExternalRadio::getMod() {
|
||||
return(mod);
|
||||
}
|
||||
|
||||
int16_t ExternalRadio::setFrequencyDeviation(float freqDev) {
|
||||
(void)freqDev;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t ExternalRadio::setDataShaping(uint8_t sh) {
|
||||
(void)sh;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t ExternalRadio::setEncoding(uint8_t encoding) {
|
||||
(void)encoding;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t ExternalRadio::transmitDirect(uint32_t frf) {
|
||||
if(frf != this->prevFrf) {
|
||||
uint32_t val = this->mod->hal->GpioLevelLow;
|
||||
if(frf > this->prevFrf) {
|
||||
val = this->mod->hal->GpioLevelHigh;
|
||||
}
|
||||
this->prevFrf = frf;
|
||||
this->mod->hal->digitalWrite(this->mod->getGpio(), val);
|
||||
}
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
#if !defined(_RADIOLIB_EXTERNAL_RADIO_H)
|
||||
#define _RADIOLIB_EXTERNAL_RADIO_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
#include "../../Module.h"
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
#include "../../ArduinoHal.h"
|
||||
#endif
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
|
||||
/*!
|
||||
\class ExternalRadio
|
||||
\brief Class to interface with external radio hardware.
|
||||
*/
|
||||
class ExternalRadio: public PhysicalLayer {
|
||||
public:
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param pin Output pin when using direct transmission, defaults to unused pin.
|
||||
*/
|
||||
ExternalRadio(uint32_t pin = RADIOLIB_NC); // cppcheck-suppress noExplicitConstructor
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param hal Pointer to the hardware abstraction layer to use.
|
||||
\param pin Output pin when using direct transmission, defaults to unused pin.
|
||||
*/
|
||||
ExternalRadio(RadioLibHal *hal, uint32_t pin = RADIOLIB_NC); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Copy constructor.
|
||||
\param ext ExternalRadio instance to copy.
|
||||
*/
|
||||
ExternalRadio(const ExternalRadio& ext);
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
\param ext rvalue ExternalRadio.
|
||||
*/
|
||||
ExternalRadio& operator=(const ExternalRadio& ext);
|
||||
|
||||
/*!
|
||||
\brief Default destructor.
|
||||
*/
|
||||
~ExternalRadio();
|
||||
|
||||
/*!
|
||||
\brief Method to retrieve pointer to the underlying Module instance.
|
||||
\returns Pointer to the Module instance.
|
||||
*/
|
||||
Module* getMod() override;
|
||||
|
||||
/*!
|
||||
\brief Dummy implementation overriding PhysicalLayer.
|
||||
\param freqDev Ignored.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequencyDeviation(float freqDev) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy implementation overriding PhysicalLayer.
|
||||
\param sh Ignored.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(uint8_t sh) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy implementation overriding PhysicalLayer.
|
||||
\param encoding Ignored.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setEncoding(uint8_t encoding) override;
|
||||
|
||||
/*!
|
||||
\brief Direct transmission to drive external radio.
|
||||
\param frf "Frequency" to control the output pin. If the frequency is higher than the one sent previously,
|
||||
the output pin will be set to logic high. Otherwise it will be set to logic low.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmitDirect(uint32_t frf = 0) override;
|
||||
|
||||
private:
|
||||
Module* mod;
|
||||
uint32_t prevFrf;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,59 +1,43 @@
|
||||
#include "FSK4.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_FSK4)
|
||||
#include <math.h>
|
||||
#if !RADIOLIB_EXCLUDE_FSK4
|
||||
|
||||
FSK4Client::FSK4Client(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audioClient = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
FSK4Client::FSK4Client(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
phyLayer = audio->phyLayer;
|
||||
audioClient = audio;
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t FSK4Client::begin(float base, uint32_t shift, uint16_t rate) {
|
||||
// save configuration
|
||||
_baseHz = base;
|
||||
_shiftHz = shift;
|
||||
baseFreqHz = base;
|
||||
shiftFreqHz = shift;
|
||||
|
||||
// calculate duration of 1 bit
|
||||
_bitDuration = (uint32_t)1000000/rate;
|
||||
bitDuration = (RadioLibTime_t)1000000/rate;
|
||||
|
||||
// calculate module carrier frequency resolution
|
||||
uint32_t step = round(_phy->getFreqStep());
|
||||
|
||||
// check minimum shift value
|
||||
if(shift < step / 2) {
|
||||
return(RADIOLIB_ERR_INVALID_RTTY_SHIFT);
|
||||
}
|
||||
|
||||
// round shift to multiples of frequency step size
|
||||
if(shift % step < (step / 2)) {
|
||||
_shift = shift / step;
|
||||
} else {
|
||||
_shift = (shift / step) + 1;
|
||||
}
|
||||
// calculate carrier shift
|
||||
shiftFreq = getRawShift(shift);
|
||||
|
||||
// Write resultant tones into arrays for quick lookup when modulating.
|
||||
_tones[0] = 0;
|
||||
_tones[1] = _shift;
|
||||
_tones[2] = _shift*2;
|
||||
_tones[3] = _shift*3;
|
||||
|
||||
_tonesHz[0] = 0;
|
||||
_tonesHz[1] = _shiftHz;
|
||||
_tonesHz[2] = _shiftHz*2;
|
||||
_tonesHz[3] = _shiftHz*3;
|
||||
for(uint8_t i = 0; i < 4; i++) {
|
||||
tones[i] = shiftFreq*i;
|
||||
tonesHz[i] = shiftFreqHz*i;
|
||||
}
|
||||
|
||||
// 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 FSK4Client::idle() {
|
||||
@@ -61,6 +45,15 @@ void FSK4Client::idle() {
|
||||
tone(0);
|
||||
}
|
||||
|
||||
int16_t FSK4Client::setCorrection(int16_t offsets[], float length) {
|
||||
for(uint8_t i = 0; i < 4; i++) {
|
||||
tones[i] += getRawShift(offsets[i]);
|
||||
tonesHz[i] += offsets[i];
|
||||
}
|
||||
bitDuration *= length;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
size_t FSK4Client::write(uint8_t* buff, size_t len) {
|
||||
size_t n = 0;
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
@@ -87,30 +80,50 @@ size_t FSK4Client::write(uint8_t b) {
|
||||
}
|
||||
|
||||
void FSK4Client::tone(uint8_t i) {
|
||||
Module* mod = _phy->getMod();
|
||||
uint32_t start = mod->micros();
|
||||
transmitDirect(_base + _tones[i], _baseHz + _tonesHz[i]);
|
||||
while(mod->micros() - start < _bitDuration) {
|
||||
mod->yield();
|
||||
}
|
||||
Module* mod = phyLayer->getMod();
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
transmitDirect(baseFreq + tones[i], baseFreqHz + tonesHz[i]);
|
||||
mod->waitForMicroseconds(start, bitDuration);
|
||||
}
|
||||
|
||||
int16_t FSK4Client::transmitDirect(uint32_t freq, uint32_t freqHz) {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->tone(freqHz));
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->tone(freqHz));
|
||||
}
|
||||
#endif
|
||||
return(_phy->transmitDirect(freq));
|
||||
return(phyLayer->transmitDirect(freq));
|
||||
}
|
||||
|
||||
int16_t FSK4Client::standby() {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->noTone());
|
||||
// ensure everything is stopped in interrupt timing mode
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->waitForMicroseconds(0, 0);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->noTone());
|
||||
}
|
||||
#endif
|
||||
return(_phy->standby());
|
||||
return(phyLayer->standby());
|
||||
}
|
||||
|
||||
int32_t FSK4Client::getRawShift(int32_t shift) {
|
||||
// calculate module carrier frequency resolution
|
||||
int32_t step = round(phyLayer->getFreqStep());
|
||||
|
||||
// check minimum shift value
|
||||
if(RADIOLIB_ABS(shift) < step / 2) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
// round shift to multiples of frequency step size
|
||||
if(RADIOLIB_ABS(shift) % step < (step / 2)) {
|
||||
return(shift / step);
|
||||
}
|
||||
if(shift < 0) {
|
||||
return((shift / step) - 1);
|
||||
}
|
||||
return((shift / step) + 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,29 +3,26 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_FSK4)
|
||||
#if !RADIOLIB_EXCLUDE_FSK4
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
|
||||
/*!
|
||||
\class FSK4Client
|
||||
|
||||
\brief Client for FSK-4 communication. The public interface is the same as Arduino Serial.
|
||||
*/
|
||||
class FSK4Client {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for FSK-4 mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit FSK4Client(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit FSK4Client(AFSKClient* audio);
|
||||
@@ -35,14 +32,10 @@ class FSK4Client {
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param base Base (space) frequency to be used in MHz (in FSK-4 mode), or the space tone frequency in Hz (in AFSK mode)
|
||||
|
||||
\param base Base (space) frequency to be used in MHz (in FSK-4 mode),
|
||||
or the space tone frequency in Hz (in AFSK mode)
|
||||
\param shift Frequency shift between each tone in Hz.
|
||||
|
||||
\param rate Baud rate to be used during transmission.
|
||||
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float base, uint32_t shift, uint16_t rate);
|
||||
@@ -52,28 +45,53 @@ class FSK4Client {
|
||||
*/
|
||||
void idle();
|
||||
|
||||
/*!
|
||||
\brief Set correction coefficients for frequencies and tone length.
|
||||
\param offsets Four positive or negative correction offsets for audio frequencies in Hz.
|
||||
\param length Tone length modifier, defaults to 1.0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCorrection(int16_t offsets[4], float length = 1.0f);
|
||||
|
||||
/*!
|
||||
\brief Transmit binary data.
|
||||
\param buff Buffer to transmit.
|
||||
\param len Number of bytes to transmit.
|
||||
\returns Number of transmitted bytes.
|
||||
*/
|
||||
size_t write(uint8_t* buff, size_t len);
|
||||
|
||||
/*!
|
||||
\brief Transmit a single byte.
|
||||
\param b Byte to transmit.
|
||||
\returns Number of transmitted bytes.
|
||||
*/
|
||||
size_t write(uint8_t b);
|
||||
|
||||
/*!
|
||||
\brief Stop transmitting.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t standby();
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AFSKClient* audioClient;
|
||||
#endif
|
||||
|
||||
uint32_t _base = 0, _baseHz = 0;
|
||||
uint32_t _shift = 0, _shiftHz = 0;
|
||||
uint32_t _bitDuration = 0;
|
||||
uint32_t _tones[4];
|
||||
uint32_t _tonesHz[4];
|
||||
uint32_t baseFreq = 0, baseFreqHz = 0;
|
||||
uint32_t shiftFreq = 0, shiftFreqHz = 0;
|
||||
RadioLibTime_t bitDuration = 0;
|
||||
uint32_t tones[4] = { 0 };
|
||||
uint32_t tonesHz[4] = { 0 };
|
||||
|
||||
void tone(uint8_t i);
|
||||
|
||||
int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
|
||||
int16_t standby();
|
||||
int32_t getRawShift(int32_t shift);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,45 +1,50 @@
|
||||
#include "Hellschreiber.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_HELLSCHREIBER)
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_HELLSCHREIBER
|
||||
|
||||
HellClient::HellClient(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
lineFeed = " ";
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audioClient = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
HellClient::HellClient(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
phyLayer = audio->phyLayer;
|
||||
lineFeed = " ";
|
||||
audioClient = audio;
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t HellClient::begin(float base, float rate) {
|
||||
// calculate 24-bit frequency
|
||||
_baseHz = base;
|
||||
_base = (base * 1000000.0) / _phy->getFreqStep();
|
||||
baseFreqHz = base;
|
||||
baseFreq = (base * 1000000.0) / phyLayer->getFreqStep();
|
||||
|
||||
// calculate "pixel" duration
|
||||
_pixelDuration = 1000000.0/rate;
|
||||
pixelDuration = 1000000.0/rate;
|
||||
|
||||
// configure for direct mode
|
||||
return(_phy->startDirect());
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
size_t HellClient::printGlyph(uint8_t* buff) {
|
||||
size_t HellClient::printGlyph(const uint8_t* buff) {
|
||||
// print the character
|
||||
Module* mod = _phy->getMod();
|
||||
Module* mod = phyLayer->getMod();
|
||||
bool transmitting = false;
|
||||
for(uint8_t mask = 0x40; mask >= 0x01; mask >>= 1) {
|
||||
for(int8_t i = RADIOLIB_HELL_FONT_HEIGHT - 1; i >= 0; i--) {
|
||||
uint32_t start = mod->micros();
|
||||
if(buff[i] & mask) {
|
||||
transmitDirect(_base, _baseHz);
|
||||
} else {
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
if((buff[i] & mask) && (!transmitting)) {
|
||||
transmitting = true;
|
||||
transmitDirect(baseFreq, baseFreqHz);
|
||||
} else if((!(buff[i] & mask)) && (transmitting)) {
|
||||
transmitting = false;
|
||||
standby();
|
||||
}
|
||||
while(mod->micros() - start < _pixelDuration);
|
||||
mod->waitForMicroseconds(start, pixelDuration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,23 +54,8 @@ size_t HellClient::printGlyph(uint8_t* buff) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
void HellClient::setInversion(bool invert) {
|
||||
_inv = invert;
|
||||
}
|
||||
|
||||
size_t HellClient::write(const char* str) {
|
||||
if(str == NULL) {
|
||||
return(0);
|
||||
}
|
||||
return(HellClient::write((uint8_t *)str, strlen(str)));
|
||||
}
|
||||
|
||||
size_t HellClient::write(uint8_t* buff, size_t len) {
|
||||
size_t n = 0;
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
n += HellClient::write(buff[i]);
|
||||
}
|
||||
return(n);
|
||||
void HellClient::setInversion(bool inv) {
|
||||
invert = inv;
|
||||
}
|
||||
|
||||
size_t HellClient::write(uint8_t b) {
|
||||
@@ -91,218 +81,22 @@ size_t HellClient::write(uint8_t b) {
|
||||
return(printGlyph(buff));
|
||||
}
|
||||
|
||||
size_t HellClient::print(__FlashStringHelper* fstr) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(fstr);
|
||||
size_t n = 0;
|
||||
while(true) {
|
||||
char c = RADIOLIB_NONVOLATILE_READ_BYTE(p++);
|
||||
if(c == '\0') {
|
||||
break;
|
||||
}
|
||||
n += HellClient::write(c);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t HellClient::print(const String& str) {
|
||||
return(HellClient::write((uint8_t*)str.c_str(), str.length()));
|
||||
}
|
||||
|
||||
size_t HellClient::print(const char* str) {
|
||||
return(HellClient::write((uint8_t*)str, strlen(str)));
|
||||
}
|
||||
|
||||
size_t HellClient::print(char c) {
|
||||
return(HellClient::write(c));
|
||||
}
|
||||
|
||||
size_t HellClient::print(unsigned char b, int base) {
|
||||
return(HellClient::print((unsigned long)b, base));
|
||||
}
|
||||
|
||||
size_t HellClient::print(int n, int base) {
|
||||
return(HellClient::print((long)n, base));
|
||||
}
|
||||
|
||||
size_t HellClient::print(unsigned int n, int base) {
|
||||
return(HellClient::print((unsigned long)n, base));
|
||||
}
|
||||
|
||||
size_t HellClient::print(long n, int base) {
|
||||
if(base == 0) {
|
||||
return(HellClient::write(n));
|
||||
} else if(base == DEC) {
|
||||
if (n < 0) {
|
||||
int t = HellClient::print('-');
|
||||
n = -n;
|
||||
return(HellClient::printNumber(n, DEC) + t);
|
||||
}
|
||||
return(HellClient::printNumber(n, DEC));
|
||||
} else {
|
||||
return(HellClient::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t HellClient::print(unsigned long n, int base) {
|
||||
if(base == 0) {
|
||||
return(HellClient::write(n));
|
||||
} else {
|
||||
return(HellClient::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t HellClient::print(double n, int digits) {
|
||||
return(HellClient::printFloat(n, digits));
|
||||
}
|
||||
|
||||
size_t HellClient::println(void) {
|
||||
// Hellschreiber has no concept of "line ending", print one space instead
|
||||
return(HellClient::print(' '));
|
||||
}
|
||||
|
||||
size_t HellClient::println(__FlashStringHelper* fstr) {
|
||||
size_t n = HellClient::print(fstr);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(const String& str) {
|
||||
size_t n = HellClient::print(str);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(const char* str) {
|
||||
size_t n = HellClient::print(str);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(char c) {
|
||||
size_t n = HellClient::print(c);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(unsigned char b, int base) {
|
||||
size_t n = HellClient::print(b, base);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(int num, int base) {
|
||||
size_t n = HellClient::print(num, base);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(unsigned int num, int base) {
|
||||
size_t n = HellClient::print(num, base);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(long num, int base) {
|
||||
size_t n = HellClient::print(num, base);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(unsigned long num, int base) {
|
||||
size_t n = HellClient::print(num, base);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::println(double d, int digits) {
|
||||
size_t n = HellClient::print(d, digits);
|
||||
n += HellClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t HellClient::printNumber(unsigned long n, uint8_t base) {
|
||||
char buf[8 * sizeof(long) + 1];
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
|
||||
if(base < 2) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
do {
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
|
||||
return(HellClient::write(str));
|
||||
}
|
||||
|
||||
size_t HellClient::printFloat(double number, uint8_t digits) {
|
||||
size_t n = 0;
|
||||
|
||||
char code[] = {0x00, 0x00, 0x00, 0x00};
|
||||
if (isnan(number)) strcpy(code, "nan");
|
||||
if (isinf(number)) strcpy(code, "inf");
|
||||
if (number > 4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
|
||||
if(code[0] != 0x00) {
|
||||
return(HellClient::write(code));
|
||||
}
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
n += HellClient::print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for(uint8_t i = 0; i < digits; ++i) {
|
||||
rounding /= 10.0;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += HellClient::print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if(digits > 0) {
|
||||
n += HellClient::print('.');
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while(digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)(remainder);
|
||||
n += HellClient::print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int16_t HellClient::transmitDirect(uint32_t freq, uint32_t freqHz) {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->tone(freqHz));
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->tone(freqHz));
|
||||
}
|
||||
#endif
|
||||
return(_phy->transmitDirect(freq));
|
||||
return(phyLayer->transmitDirect(freq));
|
||||
}
|
||||
|
||||
int16_t HellClient::standby() {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->noTone(_inv));
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->noTone(invert));
|
||||
}
|
||||
#endif
|
||||
return(_phy->standby());
|
||||
return(phyLayer->standby(RADIOLIB_STANDBY_WARM));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_HELLSCHREIBER)
|
||||
#if !RADIOLIB_EXCLUDE_HELLSCHREIBER
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
#include "../Print/Print.h"
|
||||
|
||||
#define RADIOLIB_HELL_FONT_WIDTH 7
|
||||
#define RADIOLIB_HELL_FONT_HEIGHT 7
|
||||
|
||||
// font definition: characters are stored in rows,
|
||||
// least significant byte of each character is the first row
|
||||
// Hellschreiber use 7x7 characters, but this simplified font uses only 5x5 - the extra bytes aren't stored
|
||||
// Hellschreiber use 7x7 characters, but this simplified font uses only 5x5
|
||||
// the extra bytes aren't stored
|
||||
static const uint8_t HellFont[64][RADIOLIB_HELL_FONT_WIDTH - 2] RADIOLIB_NONVOLATILE = {
|
||||
{ 0b0000000, 0b0000000, 0b0000000, 0b0000000, 0b0000000 }, // space
|
||||
{ 0b0001000, 0b0001000, 0b0001000, 0b0000000, 0b0001000 }, // !
|
||||
@@ -83,22 +85,19 @@ static const uint8_t HellFont[64][RADIOLIB_HELL_FONT_WIDTH - 2] RADIOLIB_NONVOLA
|
||||
|
||||
/*!
|
||||
\class HellClient
|
||||
|
||||
\brief Client for Hellschreiber transmissions.
|
||||
*/
|
||||
class HellClient {
|
||||
class HellClient: public RadioLibPrint {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for 2-FSK mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit HellClient(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit HellClient(AFSKClient* audio);
|
||||
@@ -108,67 +107,42 @@ class HellClient {
|
||||
|
||||
/*!
|
||||
\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 rate Baud rate to be used during transmission. Defaults to 122.5 ("Feld Hell")
|
||||
*/
|
||||
int16_t begin(float base, float rate = 122.5);
|
||||
|
||||
/*!
|
||||
\brief Method to "print" a buffer of pixels, this is exposed to allow users to send custom characters.
|
||||
|
||||
\param buff Buffer of pixels to send, in a 7x7 pixel array.
|
||||
|
||||
\returns Always returns the number of printed glyphs (1).
|
||||
*/
|
||||
size_t printGlyph(uint8_t* buff);
|
||||
size_t printGlyph(const uint8_t* buff);
|
||||
|
||||
/*!
|
||||
\brief Invert text color.
|
||||
|
||||
\param invert Whether to enable color inversion (white text on black background), or not (black text on white background)
|
||||
\param inv Whether to enable color inversion (white text on black background), or not (black text on white background)
|
||||
*/
|
||||
void setInversion(bool invert);
|
||||
void setInversion(bool inv);
|
||||
|
||||
size_t write(const char* str);
|
||||
size_t write(uint8_t* buff, size_t len);
|
||||
size_t write(uint8_t b);
|
||||
/*!
|
||||
\brief Write one byte. Implementation of interface of the RadioLibPrint/Print class.
|
||||
\param b Byte to write.
|
||||
\returns 1 if the byte was written, 0 otherwise.
|
||||
*/
|
||||
size_t write(uint8_t b) override;
|
||||
|
||||
size_t print(__FlashStringHelper*);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
|
||||
size_t println(void);
|
||||
size_t println(__FlashStringHelper*);
|
||||
size_t println(const String &);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AFSKClient* audioClient;
|
||||
#endif
|
||||
|
||||
uint32_t _base = 0, _baseHz = 0;
|
||||
uint32_t _pixelDuration = 0;
|
||||
bool _inv = false;
|
||||
uint32_t baseFreq = 0, baseFreqHz = 0;
|
||||
uint32_t pixelDuration = 0;
|
||||
bool invert = false;
|
||||
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,879 @@
|
||||
#include "LoRaWAN.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LORAWAN
|
||||
|
||||
// array of pointers to currently supported LoRaWAN bands
|
||||
const LoRaWANBand_t* LoRaWANBands[RADIOLIB_LORAWAN_NUM_SUPPORTED_BANDS] = {
|
||||
&EU868,
|
||||
&US915,
|
||||
&EU433,
|
||||
&AU915,
|
||||
&CN500,
|
||||
&AS923,
|
||||
&AS923_2,
|
||||
&AS923_3,
|
||||
&AS923_4,
|
||||
&KR920,
|
||||
&IN865,
|
||||
};
|
||||
|
||||
const LoRaWANBand_t EU868 = {
|
||||
.bandNum = BandEU868,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 8630000,
|
||||
.freqMax = 8700000,
|
||||
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 250, 250, 58, 123, 58, 123, 0, 0, 0 },
|
||||
.powerMax = 16,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 36000,
|
||||
.dwellTimeUp = 0,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = false,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 8681000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 8683000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 2, .freq = 8685000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 1, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 2, 1, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 3, 2, 1, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 4, 3, 2, 1, 0, 0, 0xFF, 0xFF },
|
||||
{ 5, 4, 3, 2, 1, 0, 0xFF, 0xFF },
|
||||
{ 6, 5, 4, 3, 2, 1, 0xFF, 0xFF },
|
||||
{ 7, 6, 5, 4, 3, 2, 0xFF, 0xFF },
|
||||
{ 1, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 2, 1, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 1, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 2, 1, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 8695250, .drMin = 0, .drMax = 7, .dr = 0, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 8651000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 8655000, .drMin = 3, .drMax = 3, .dr = 3, .available = true }
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 8653000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 8659000, .drMin = 3, .drMax = 3, .dr = 3, .available = true }
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_1_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_137_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_2_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_137_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_1_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_336_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_2_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_336_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t US915 = {
|
||||
.bandNum = BandUS915,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_FIXED,
|
||||
.freqMin = 9020000,
|
||||
.freqMax = 9280000,
|
||||
.payloadLenMax = { 19, 61, 133, 250, 250, 58, 133, 0, 61, 137, 250, 250, 250, 250, 0 },
|
||||
.powerMax = 30,
|
||||
.powerNumSteps = 10,
|
||||
.dutyCycle = 0,
|
||||
.dwellTimeUp = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = false,
|
||||
.txFreqs = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 2,
|
||||
.txSpans = {
|
||||
{
|
||||
.numChannels = 64,
|
||||
.freqStart = 9023000,
|
||||
.freqStep = 2000,
|
||||
.drMin = 0,
|
||||
.drMax = 3,
|
||||
.drJoinRequest = 0
|
||||
},
|
||||
{
|
||||
.numChannels = 8,
|
||||
.freqStart = 9030000,
|
||||
.freqStep = 16000,
|
||||
.drMin = 4,
|
||||
.drMax = 4,
|
||||
.drJoinRequest = 4
|
||||
}
|
||||
},
|
||||
.rx1Span = {
|
||||
.numChannels = 8,
|
||||
.freqStart = 9233000,
|
||||
.freqStep = 6000,
|
||||
.drMin = 8,
|
||||
.drMax = 13,
|
||||
.drJoinRequest = RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
},
|
||||
.rx1DrTable = {
|
||||
{ 10, 9, 8, 8, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 11, 10, 9, 8, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 12, 11, 10, 9, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 13, 12, 11, 10, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 13, 13, 12, 11, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 10, 9, 8, 8, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 11, 10, 9, 8, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9233000, .drMin = 8, .drMax = 13, .dr = 8, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9167000, .drMin = 10, .drMax = 10, .dr = 10, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9199000, .drMin = 10, .drMax = 10, .dr = 10, .available = true }
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9183000, .drMin = 10, .drMax = 10, .dr = 10, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9215000, .drMin = 10, .drMax = 10, .dr = 10, .available = true }
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_1_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_2_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t EU433 = {
|
||||
.bandNum = BandEU433,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 4330000,
|
||||
.freqMax = 4340000,
|
||||
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 12,
|
||||
.powerNumSteps = 5,
|
||||
.dutyCycle = 36000,
|
||||
.dwellTimeUp = 0,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = false,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 4331750, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 4333750, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 2, .freq = 4335750, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 1, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 2, 1, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 3, 2, 1, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 4, 3, 2, 1, 0, 0, 0xFF, 0xFF },
|
||||
{ 5, 4, 3, 2, 1, 0, 0xFF, 0xFF },
|
||||
{ 6, 5, 4, 3, 2, 1, 0xFF, 0xFF },
|
||||
{ 7, 6, 5, 4, 3, 2, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 4346650, .drMin = 0, .drMax = 7, .dr = 0, .available = true },
|
||||
.txWoR = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txAck = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t AU915 = {
|
||||
.bandNum = BandAU915,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_FIXED,
|
||||
.freqMin = 9150000,
|
||||
.freqMax = 9280000,
|
||||
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 250, 58, 61, 137, 250, 250, 250, 250, 0 },
|
||||
.powerMax = 30,
|
||||
.powerNumSteps = 10,
|
||||
.dutyCycle = 0,
|
||||
.dwellTimeUp = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = true, // conflict: not implemented according to RP v1.1
|
||||
.txFreqs = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 2,
|
||||
.txSpans = {
|
||||
{
|
||||
.numChannels = 64,
|
||||
.freqStart = 9152000,
|
||||
.freqStep = 2000,
|
||||
.drMin = 0,
|
||||
.drMax = 5,
|
||||
.drJoinRequest = 2
|
||||
},
|
||||
{
|
||||
.numChannels = 8,
|
||||
.freqStart = 9159000,
|
||||
.freqStep = 16000,
|
||||
.drMin = 6,
|
||||
.drMax = 6,
|
||||
.drJoinRequest = 6
|
||||
}
|
||||
},
|
||||
.rx1Span = {
|
||||
.numChannels = 8,
|
||||
.freqStart = 9233000,
|
||||
.freqStep = 6000,
|
||||
.drMin = 8,
|
||||
.drMax = 13,
|
||||
.drJoinRequest = RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
},
|
||||
.rx1DrTable = {
|
||||
{ 8, 8, 8, 8, 8, 8, 0xFF, 0xFF },
|
||||
{ 9, 8, 8, 8, 8, 8, 0xFF, 0xFF },
|
||||
{ 10, 9, 8, 8, 8, 8, 0xFF, 0xFF },
|
||||
{ 11, 10, 9, 8, 8, 8, 0xFF, 0xFF },
|
||||
{ 12, 11, 10, 9, 8, 8, 0xFF, 0xFF },
|
||||
{ 13, 12, 11, 10, 9, 8, 0xFF, 0xFF },
|
||||
{ 13, 13, 12, 11, 10, 9, 0xFF, 0xFF },
|
||||
{ 9, 8, 8, 8, 8, 8, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9233000, .drMin = 8, .drMax = 13, .dr = 8, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9167000, .drMin = 10, .drMax = 10, .dr = 10, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9199000, .drMin = 10, .drMax = 10, .dr = 10, .available = true }
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9183000, .drMin = 10, .drMax = 10, .dr = 10, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9215000, .drMin = 10, .drMax = 10, .dr = 10, .available = true }
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS | RADIOLIB_LORAWAN_DATA_RATE_CR_1_3 | RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t CN500 = {
|
||||
.bandNum = BandCN500,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_FIXED,
|
||||
.freqMin = 4700000,
|
||||
.freqMax = 5100000,
|
||||
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 19,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 0,
|
||||
.dwellTimeUp = 0,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = false,
|
||||
.txFreqs = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 1,
|
||||
.txSpans = {
|
||||
{
|
||||
.numChannels = 96,
|
||||
.freqStart = 4703000,
|
||||
.freqStep = 2000,
|
||||
.drMin = 0,
|
||||
.drMax = 5,
|
||||
.drJoinRequest = 0
|
||||
},
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = {
|
||||
.numChannels = 48,
|
||||
.freqStart = 5003000,
|
||||
.freqStep = 2000,
|
||||
.drMin = 0,
|
||||
.drMax = 5,
|
||||
.drJoinRequest = RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
},
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 1, 1, 1, 1, 1, 1, 0xFF, 0xFF },
|
||||
{ 2, 1, 1, 1, 1, 1, 0xFF, 0xFF },
|
||||
{ 3, 2, 1, 1, 1, 1, 0xFF, 0xFF },
|
||||
{ 4, 3, 2, 1, 1, 1, 0xFF, 0xFF },
|
||||
{ 5, 4, 3, 2, 1, 1, 0xFF, 0xFF },
|
||||
{ 6, 5, 4, 3, 2, 1, 0xFF, 0xFF },
|
||||
{ 7, 6, 5, 4, 3, 2, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 5053000, .drMin = 0, .drMax = 5, .dr = 0, .available = true },
|
||||
.txWoR = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txAck = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t AS923 = {
|
||||
.bandNum = BandAS923,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 9150000,
|
||||
.freqMax = 9280000,
|
||||
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 16,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 36000,
|
||||
.dwellTimeUp = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.dwellTimeDn = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.txParamSupported = true,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9232000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9234000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 1, 2 }, // note:
|
||||
{ 1, 0, 0, 0, 0, 0, 2, 3 }, // when downlinkDwellTime is one
|
||||
{ 2, 1, 0, 0, 0, 0, 3, 4 }, // we should clip any value <2 to 2
|
||||
{ 3, 2, 1, 0, 0, 0, 4, 5 },
|
||||
{ 4, 3, 2, 1, 0, 0, 5, 6 },
|
||||
{ 5, 4, 3, 2, 1, 0, 6, 7 },
|
||||
{ 6, 5, 4, 3, 2, 1, 7, 7 },
|
||||
{ 7, 6, 5, 4, 3, 2, 7, 7 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9232000, .drMin = 0, .drMax = 7, .dr = 2, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9236000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9238000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t AS923_2 = {
|
||||
.bandNum = BandAS923_2,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 9150000,
|
||||
.freqMax = 9280000,
|
||||
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 16,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 36000,
|
||||
.dwellTimeUp = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.dwellTimeDn = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.txParamSupported = true,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9214000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9216000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 1, 2 }, // note:
|
||||
{ 1, 0, 0, 0, 0, 0, 2, 3 }, // when downlinkDwellTime is one
|
||||
{ 2, 1, 0, 0, 0, 0, 3, 4 }, // we should clip any value <2 to 2
|
||||
{ 3, 2, 1, 0, 0, 0, 4, 5 },
|
||||
{ 4, 3, 2, 1, 0, 0, 5, 6 },
|
||||
{ 5, 4, 3, 2, 1, 0, 6, 7 },
|
||||
{ 6, 5, 4, 3, 2, 1, 7, 7 },
|
||||
{ 7, 6, 5, 4, 3, 2, 7, 7 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9214000, .drMin = 0, .drMax = 7, .dr = 2, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9218000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9220000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t AS923_3 = {
|
||||
.bandNum = BandAS923_3,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 9150000,
|
||||
.freqMax = 9280000,
|
||||
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 16,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 36000,
|
||||
.dwellTimeUp = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.dwellTimeDn = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.txParamSupported = true,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9166000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9168000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 1, 2 }, // note:
|
||||
{ 1, 0, 0, 0, 0, 0, 2, 3 }, // when downlinkDwellTime is one
|
||||
{ 2, 1, 0, 0, 0, 0, 3, 4 }, // we should clip any value <2 to 2
|
||||
{ 3, 2, 1, 0, 0, 0, 4, 5 },
|
||||
{ 4, 3, 2, 1, 0, 0, 5, 6 },
|
||||
{ 5, 4, 3, 2, 1, 0, 6, 7 },
|
||||
{ 6, 5, 4, 3, 2, 1, 7, 7 },
|
||||
{ 7, 6, 5, 4, 3, 2, 7, 7 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9166000, .drMin = 0, .drMax = 7, .dr = 2, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9170000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9172000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t AS923_4 = {
|
||||
.bandNum = BandAS923_4,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 9170000,
|
||||
.freqMax = 9200000,
|
||||
.payloadLenMax = { 59, 59, 123, 123, 250, 250, 250, 250, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 16,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 36000,
|
||||
.dwellTimeUp = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.dwellTimeDn = RADIOLIB_LORAWAN_DWELL_TIME,
|
||||
.txParamSupported = true,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9173000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9175000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 1, 2 }, // note:
|
||||
{ 1, 0, 0, 0, 0, 0, 2, 3 }, // when downlinkDwellTime is one
|
||||
{ 2, 1, 0, 0, 0, 0, 3, 4 }, // we should clip any value <2 to 2
|
||||
{ 3, 2, 1, 0, 0, 0, 4, 5 },
|
||||
{ 4, 3, 2, 1, 0, 0, 5, 6 },
|
||||
{ 5, 4, 3, 2, 1, 0, 6, 7 },
|
||||
{ 6, 5, 4, 3, 2, 1, 7, 7 },
|
||||
{ 7, 6, 5, 4, 3, 2, 7, 7 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9173000, .drMin = 0, .drMax = 7, .dr = 2, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9177000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9179000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t KR920 = {
|
||||
.bandNum = BandKR920,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 9209000,
|
||||
.freqMax = 9233000,
|
||||
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 14,
|
||||
.powerNumSteps = 7,
|
||||
.dutyCycle = 0,
|
||||
.dwellTimeUp = 0,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = false,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9221000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9223000, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 2, .freq = 9225000, .drMin = 0, .drMax = 5, .dr = 5, .available = true }
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 1, 0, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 2, 1, 0, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 3, 2, 1, 0, 0, 0, 0xFF, 0xFF },
|
||||
{ 4, 3, 2, 1, 0, 0, 0xFF, 0xFF },
|
||||
{ 5, 4, 3, 2, 1, 0, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 9219000, .drMin = 0, .drMax = 5, .dr = 0, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9227000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9231000, .drMin = 3, .drMax = 3, .dr = 3, .available = true }
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 9229000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 9231000, .drMin = 3, .drMax = 3, .dr = 3, .available = true }
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
const LoRaWANBand_t IN865 = {
|
||||
.bandNum = BandIN865,
|
||||
.bandType = RADIOLIB_LORAWAN_BAND_DYNAMIC,
|
||||
.freqMin = 8650000,
|
||||
.freqMax = 8670000,
|
||||
.payloadLenMax = { 59, 59, 59, 123, 250, 250, 0, 250, 0, 0, 0, 0, 0, 0, 0 },
|
||||
.powerMax = 30,
|
||||
.powerNumSteps = 10,
|
||||
.dutyCycle = 0,
|
||||
.dwellTimeUp = 0,
|
||||
.dwellTimeDn = 0,
|
||||
.txParamSupported = false,
|
||||
.txFreqs = {
|
||||
{ .enabled = true, .idx = 0, .freq = 8650625, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 8654025, .drMin = 0, .drMax = 5, .dr = 5, .available = true },
|
||||
{ .enabled = true, .idx = 2, .freq = 8659850, .drMin = 0, .drMax = 5, .dr = 5, .available = true }
|
||||
},
|
||||
.txJoinReq = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_NONE
|
||||
},
|
||||
.numTxSpans = 0,
|
||||
.txSpans = {
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE
|
||||
},
|
||||
.rx1Span = RADIOLIB_LORAWAN_CHANNEL_SPAN_NONE,
|
||||
.rx1DrTable = {
|
||||
{ 0, 0, 0, 0, 0, 0, 1, 2 },
|
||||
{ 1, 0, 0, 0, 0, 0, 2, 3 },
|
||||
{ 2, 1, 0, 0, 0, 0, 3, 4 },
|
||||
{ 3, 2, 1, 0, 0, 0, 4, 5 },
|
||||
{ 4, 3, 2, 1, 0, 0, 5, 5 },
|
||||
{ 5, 4, 3, 2, 1, 0, 5, 7 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 7, 6, 5, 4, 3, 2, 7, 7 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
},
|
||||
.rx2 = { .enabled = true, .idx = 0, .freq = 8665500, .drMin = 0, .drMax = 7, .dr = 2, .available = true },
|
||||
.txWoR = {
|
||||
{ .enabled = true, .idx = 0, .freq = 8660000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 8667000, .drMin = 3, .drMax = 3, .dr = 3, .available = true }
|
||||
},
|
||||
.txAck = {
|
||||
{ .enabled = true, .idx = 0, .freq = 8662000, .drMin = 3, .drMax = 3, .dr = 3, .available = true },
|
||||
{ .enabled = true, .idx = 1, .freq = 8669000, .drMin = 3, .drMax = 3, .dr = 3, .available = true }
|
||||
},
|
||||
.dataRates = {
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_12 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_11 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_10 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_9 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_8 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_LORA | RADIOLIB_LORAWAN_DATA_RATE_SF_7 | RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_FSK,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
|
||||
RADIOLIB_LORAWAN_DATA_RATE_UNUSED
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,36 +1,41 @@
|
||||
#include "Morse.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_MORSE)
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_MORSE
|
||||
|
||||
MorseClient::MorseClient(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
lineFeed = "^";
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audioClient = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
MorseClient::MorseClient(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
phyLayer = audio->phyLayer;
|
||||
lineFeed = "^";
|
||||
audioClient = audio;
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t MorseClient::begin(float base, uint8_t speed) {
|
||||
// calculate 24-bit frequency
|
||||
_baseHz = base;
|
||||
_base = (base * 1000000.0) / _phy->getFreqStep();
|
||||
baseFreqHz = base;
|
||||
baseFreq = (base * 1000000.0) / phyLayer->getFreqStep();
|
||||
|
||||
// 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)
|
||||
_dotLength = 1200 / speed;
|
||||
_dashLength = 3*_dotLength;
|
||||
_letterSpace = 3*_dotLength;
|
||||
_wordSpace = 4*_dotLength;
|
||||
dotLength = 1200 / speed;
|
||||
dashLength = 3*dotLength;
|
||||
letterSpace = 3*dotLength;
|
||||
wordSpace = 4*dotLength;
|
||||
|
||||
// configure for direct mode
|
||||
return(_phy->startDirect());
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
size_t MorseClient::startSignal() {
|
||||
@@ -51,18 +56,18 @@ char MorseClient::decode(uint8_t symbol, uint8_t len) {
|
||||
}
|
||||
|
||||
// nothing found
|
||||
return(RADIOLIB_MORSE_UNSUPORTED);
|
||||
return(RADIOLIB_MORSE_UNSUPPORTED);
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
int MorseClient::read(byte* symbol, byte* len, float low, float high) {
|
||||
Module* mod = _phy->getMod();
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
int MorseClient::read(uint8_t* symbol, uint8_t* len, float low, float high) {
|
||||
Module* mod = phyLayer->getMod();
|
||||
|
||||
// measure pulse duration in us
|
||||
uint32_t duration = mod->pulseIn(_audio->_pin, LOW, 4*_basePeriod);
|
||||
uint32_t duration = mod->hal->pulseIn(audioClient->outPin, mod->hal->GpioLevelLow, 4*basePeriod);
|
||||
|
||||
// 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
|
||||
signalCounter++;
|
||||
} else if(duration == 0) {
|
||||
@@ -74,34 +79,32 @@ int MorseClient::read(byte* symbol, byte* len, float low, float high) {
|
||||
if((pauseCounter > 0) && (signalCounter == 1)) {
|
||||
// start of dot or dash
|
||||
pauseCounter = 0;
|
||||
signalStart = mod->millis();
|
||||
uint32_t pauseLen = mod->millis() - pauseStart;
|
||||
signalStart = mod->hal->millis();
|
||||
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);
|
||||
} else if(pauseLen > _wordSpace) {
|
||||
RADIOLIB_DEBUG_PRINTLN("\n<space>");
|
||||
} else if(pauseLen > wordSpace) {
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("\n<space>");
|
||||
return(RADIOLIB_MORSE_WORD_COMPLETE);
|
||||
}
|
||||
|
||||
} else if((signalCounter > 0) && (pauseCounter == 1)) {
|
||||
// end of dot or dash
|
||||
signalCounter = 0;
|
||||
pauseStart = mod->millis();
|
||||
uint32_t signalLen = mod->millis() - signalStart;
|
||||
pauseStart = mod->hal->millis();
|
||||
uint32_t signalLen = mod->hal->millis() - signalStart;
|
||||
|
||||
if((signalLen >= low*(float)_dotLength) && (signalLen <= high*(float)_dotLength)) {
|
||||
RADIOLIB_DEBUG_PRINT('.');
|
||||
if((signalLen >= low*(float)dotLength) && (signalLen <= high*(float)dotLength)) {
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINT(".");
|
||||
(*symbol) |= (RADIOLIB_MORSE_DOT << (*len));
|
||||
(*len)++;
|
||||
} else if((signalLen >= low*(float)_dashLength) && (signalLen <= high*(float)_dashLength)) {
|
||||
RADIOLIB_DEBUG_PRINT('-');
|
||||
} else if((signalLen >= low*(float)dashLength) && (signalLen <= high*(float)dashLength)) {
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINT("-");
|
||||
(*symbol) |= (RADIOLIB_MORSE_DASH << (*len));
|
||||
(*len)++;
|
||||
} else {
|
||||
RADIOLIB_DEBUG_PRINT("<len=");
|
||||
RADIOLIB_DEBUG_PRINT(signalLen);
|
||||
RADIOLIB_DEBUG_PRINTLN("ms>");
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("<len=%lums>", (long unsigned int)signalLen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,24 +112,8 @@ int MorseClient::read(byte* symbol, byte* len, float low, float high) {
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t MorseClient::write(const char* str) {
|
||||
if(str == NULL) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(MorseClient::write((uint8_t*)str, strlen(str)));
|
||||
}
|
||||
|
||||
size_t MorseClient::write(uint8_t* buff, size_t len) {
|
||||
size_t n = 0;
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
n += MorseClient::write(buff[i]);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::write(uint8_t b) {
|
||||
Module* mod = _phy->getMod();
|
||||
Module* mod = phyLayer->getMod();
|
||||
|
||||
// check unprintable ASCII characters and boundaries
|
||||
if((b < ' ') || (b == 0x60) || (b > 'z')) {
|
||||
@@ -135,9 +122,9 @@ size_t MorseClient::write(uint8_t b) {
|
||||
|
||||
// inter-word pause (space)
|
||||
if(b == ' ') {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("space"));
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("space");
|
||||
standby();
|
||||
mod->delay(_wordSpace);
|
||||
mod->waitForMicroseconds(mod->hal->micros(), wordSpace*1000);
|
||||
return(1);
|
||||
}
|
||||
|
||||
@@ -145,7 +132,7 @@ size_t MorseClient::write(uint8_t b) {
|
||||
uint8_t code = RADIOLIB_NONVOLATILE_READ_BYTE(&MorseTable[(uint8_t)(toupper(b) - RADIOLIB_MORSE_ASCII_OFFSET)]);
|
||||
|
||||
// check unsupported characters
|
||||
if(code == RADIOLIB_MORSE_UNSUPORTED) {
|
||||
if(code == RADIOLIB_MORSE_UNSUPPORTED) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -154,18 +141,18 @@ size_t MorseClient::write(uint8_t b) {
|
||||
|
||||
// send dot or dash
|
||||
if (code & RADIOLIB_MORSE_DASH) {
|
||||
RADIOLIB_DEBUG_PRINT('-');
|
||||
transmitDirect(_base, _baseHz);
|
||||
mod->delay(_dashLength);
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINT("-");
|
||||
transmitDirect(baseFreq, baseFreqHz);
|
||||
mod->waitForMicroseconds(mod->hal->micros(), dashLength*1000);
|
||||
} else {
|
||||
RADIOLIB_DEBUG_PRINT('.');
|
||||
transmitDirect(_base, _baseHz);
|
||||
mod->delay(_dotLength);
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINT(".");
|
||||
transmitDirect(baseFreq, baseFreqHz);
|
||||
mod->waitForMicroseconds(mod->hal->micros(), dotLength*1000);
|
||||
}
|
||||
|
||||
// symbol space
|
||||
standby();
|
||||
mod->delay(_dotLength);
|
||||
mod->waitForMicroseconds(mod->hal->micros(), dotLength*1000);
|
||||
|
||||
// move onto the next bit
|
||||
code >>= 1;
|
||||
@@ -173,223 +160,28 @@ size_t MorseClient::write(uint8_t b) {
|
||||
|
||||
// letter space
|
||||
standby();
|
||||
mod->delay(_letterSpace - _dotLength);
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
mod->waitForMicroseconds(mod->hal->micros(), letterSpace*1000 - dotLength*1000);
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN();
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
size_t MorseClient::print(__FlashStringHelper* fstr) {
|
||||
PGM_P p = reinterpret_cast<PGM_P>(fstr);
|
||||
size_t n = 0;
|
||||
while(true) {
|
||||
char c = RADIOLIB_NONVOLATILE_READ_BYTE(p++);
|
||||
if(c == '\0') {
|
||||
break;
|
||||
}
|
||||
n += MorseClient::write(c);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t MorseClient::print(const String& str) {
|
||||
return(MorseClient::write((uint8_t*)str.c_str(), str.length()));
|
||||
}
|
||||
|
||||
size_t MorseClient::print(const char* str) {
|
||||
return(MorseClient::write((uint8_t*)str, strlen(str)));
|
||||
}
|
||||
|
||||
size_t MorseClient::print(char c) {
|
||||
return(MorseClient::write(c));
|
||||
}
|
||||
|
||||
size_t MorseClient::print(unsigned char b, int base) {
|
||||
return(MorseClient::print((unsigned long)b, base));
|
||||
}
|
||||
|
||||
size_t MorseClient::print(int n, int base) {
|
||||
return(MorseClient::print((long)n, base));
|
||||
}
|
||||
|
||||
size_t MorseClient::print(unsigned int n, int base) {
|
||||
return(MorseClient::print((unsigned long)n, base));
|
||||
}
|
||||
|
||||
size_t MorseClient::print(long n, int base) {
|
||||
if(base == 0) {
|
||||
return(MorseClient::write(n));
|
||||
} else if(base == DEC) {
|
||||
if (n < 0) {
|
||||
int t = MorseClient::print('-');
|
||||
n = -n;
|
||||
return(MorseClient::printNumber(n, DEC) + t);
|
||||
}
|
||||
return(MorseClient::printNumber(n, DEC));
|
||||
} else {
|
||||
return(MorseClient::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t MorseClient::print(unsigned long n, int base) {
|
||||
if(base == 0) {
|
||||
return(MorseClient::write(n));
|
||||
} else {
|
||||
return(MorseClient::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t MorseClient::print(double n, int digits) {
|
||||
return(MorseClient::printFloat(n, digits));
|
||||
}
|
||||
|
||||
size_t MorseClient::println(void) {
|
||||
return(MorseClient::write('^'));
|
||||
}
|
||||
|
||||
size_t MorseClient::println(__FlashStringHelper* fstr) {
|
||||
size_t n = MorseClient::print(fstr);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(const String& str) {
|
||||
size_t n = MorseClient::print(str);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(const char* str) {
|
||||
size_t n = MorseClient::print(str);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(char c) {
|
||||
size_t n = MorseClient::print(c);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(unsigned char b, int base) {
|
||||
size_t n = MorseClient::print(b, base);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(int num, int base) {
|
||||
size_t n = MorseClient::print(num, base);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(unsigned int num, int base) {
|
||||
size_t n = MorseClient::print(num, base);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(long num, int base) {
|
||||
size_t n = MorseClient::print(num, base);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(unsigned long num, int base) {
|
||||
size_t n = MorseClient::print(num, base);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::println(double d, int digits) {
|
||||
size_t n = MorseClient::print(d, digits);
|
||||
n += MorseClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t MorseClient::printNumber(unsigned long n, uint8_t base) {
|
||||
char buf[8 * sizeof(long) + 1];
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
|
||||
if(base < 2) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
do {
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
|
||||
return(MorseClient::write(str));
|
||||
}
|
||||
|
||||
size_t MorseClient::printFloat(double number, uint8_t digits) {
|
||||
size_t n = 0;
|
||||
|
||||
char code[] = {0x00, 0x00, 0x00, 0x00};
|
||||
if (isnan(number)) strcpy(code, "nan");
|
||||
if (isinf(number)) strcpy(code, "inf");
|
||||
if (number > 4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
|
||||
if(code[0] != 0x00) {
|
||||
return(MorseClient::write(code));
|
||||
}
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
n += MorseClient::print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for(uint8_t i = 0; i < digits; ++i) {
|
||||
rounding /= 10.0;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += MorseClient::print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if(digits > 0) {
|
||||
n += MorseClient::print('.');
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while(digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)(remainder);
|
||||
n += MorseClient::print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int16_t MorseClient::transmitDirect(uint32_t freq, uint32_t freqHz) {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->tone(freqHz));
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->tone(freqHz));
|
||||
}
|
||||
#endif
|
||||
return(_phy->transmitDirect(freq));
|
||||
return(phyLayer->transmitDirect(freq));
|
||||
}
|
||||
|
||||
int16_t MorseClient::standby() {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->noTone(true));
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->noTone(true));
|
||||
}
|
||||
#endif
|
||||
return(_phy->standby());
|
||||
return(phyLayer->standby());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#if !defined(_RADIOLIB_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE)
|
||||
#define _RADIOLIB_RADIOLIB_MORSE_H
|
||||
#if !defined(_RADIOLIB_MORSE_H) && !RADIOLIB_EXCLUDE_MORSE
|
||||
#define _RADIOLIB_MORSE_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
#include "../Print/Print.h"
|
||||
|
||||
#define RADIOLIB_MORSE_DOT 0b0
|
||||
#define RADIOLIB_MORSE_DASH 0b1
|
||||
#define RADIOLIB_MORSE_GUARDBIT 0b1
|
||||
#define RADIOLIB_MORSE_UNSUPORTED 0xFF
|
||||
#define RADIOLIB_MORSE_UNSUPPORTED 0xFF
|
||||
#define RADIOLIB_MORSE_ASCII_OFFSET 32
|
||||
#define RADIOLIB_MORSE_INTER_SYMBOL 0x00
|
||||
#define RADIOLIB_MORSE_CHAR_COMPLETE 0x01
|
||||
@@ -17,19 +18,19 @@
|
||||
// Morse character table: - using codes defined in ITU-R M.1677-1
|
||||
// - Morse code representation is saved LSb first, using additional bit as guard
|
||||
// - position in array corresponds ASCII code minus RADIOLIB_MORSE_ASCII_OFFSET
|
||||
// - ASCII characters marked RADIOLIB_MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent
|
||||
// - ASCII characters marked RADIOLIB_MORSE_UNSUPPORTED do not have ITU-R M.1677-1 equivalent
|
||||
static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
|
||||
0b00, // space
|
||||
0b110101, // ! (unsupported)
|
||||
0b1010010, // "
|
||||
RADIOLIB_MORSE_UNSUPORTED, // # (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPORTED, // $ (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPORTED, // % (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPORTED, // & (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // # (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // $ (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // % (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // & (unsupported)
|
||||
0b1011110, // '
|
||||
0b101101, // (
|
||||
0b1101101, // )
|
||||
RADIOLIB_MORSE_UNSUPORTED, // * (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // * (unsupported)
|
||||
0b101010, // +
|
||||
0b1110011, // ,
|
||||
0b1100001, // -
|
||||
@@ -46,10 +47,10 @@ static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
|
||||
0b100111, // 8
|
||||
0b101111, // 9
|
||||
0b1000111, // :
|
||||
RADIOLIB_MORSE_UNSUPORTED, // ; (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPORTED, // < (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // ; (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // < (unsupported)
|
||||
0b110001, // =
|
||||
RADIOLIB_MORSE_UNSUPORTED, // > (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // > (unsupported)
|
||||
0b1001100, // ?
|
||||
0b1010110, // @
|
||||
0b110, // A
|
||||
@@ -78,31 +79,28 @@ static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
|
||||
0b11001, // X
|
||||
0b11101, // Y
|
||||
0b10011, // Z
|
||||
RADIOLIB_MORSE_UNSUPORTED, // [ (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPORTED, // \ (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPORTED, // ] (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // [ (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // \ (unsupported)
|
||||
RADIOLIB_MORSE_UNSUPPORTED, // ] (unsupported)
|
||||
0b1101000, // ^ (unsupported, used as alias for end of work)
|
||||
0b110101 // _ (unsupported, used as alias for starting signal)
|
||||
};
|
||||
|
||||
/*!
|
||||
\class MorseClient
|
||||
|
||||
\brief Client for Morse Code communication. The public interface is the same as Arduino Serial.
|
||||
*/
|
||||
class MorseClient {
|
||||
class MorseClient: public RadioLibPrint {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for 2-FSK mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit MorseClient(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit MorseClient(AFSKClient* audio);
|
||||
@@ -112,97 +110,66 @@ class MorseClient {
|
||||
|
||||
/*!
|
||||
\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 speed Coding speed in words per minute.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float base, uint8_t speed = 20);
|
||||
|
||||
/*!
|
||||
\brief Send start signal.
|
||||
|
||||
\returns Number of bytes sent (always 0).
|
||||
*/
|
||||
size_t startSignal();
|
||||
|
||||
/*!
|
||||
\brief Decode Morse symbol to ASCII.
|
||||
|
||||
\param symbol Morse code symbol, respresented as outlined in MorseTable.
|
||||
|
||||
\param symbol Morse code symbol, represented as outlined in MorseTable.
|
||||
\param len Symbol length (number of dots and dashes).
|
||||
|
||||
\returns ASCII character matching the symbol, or 0xFF if no match is found.
|
||||
*/
|
||||
static char decode(uint8_t symbol, uint8_t len);
|
||||
|
||||
/*!
|
||||
\brief Read Morse tone on input pin.
|
||||
|
||||
\param symbol Pointer to the symbol buffer.
|
||||
|
||||
\param len Pointer to the length counter.
|
||||
|
||||
\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.
|
||||
|
||||
\returns 0 if not enough symbols were decoded, 1 if inter-character space was detected, 2 if inter-word 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.
|
||||
*/
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
int read(byte* symbol, byte* len, float low = 0.75f, float high = 1.25f);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
int read(uint8_t* symbol, uint8_t* len, float low = 0.75f, float high = 1.25f);
|
||||
#endif
|
||||
|
||||
size_t write(const char* str);
|
||||
size_t write(uint8_t* buff, size_t len);
|
||||
size_t write(uint8_t b);
|
||||
/*!
|
||||
\brief Write one byte. Implementation of interface of the RadioLibPrint/Print class.
|
||||
\param b Byte to write.
|
||||
\returns 1 if the byte was written, 0 otherwise.
|
||||
*/
|
||||
size_t write(uint8_t b) override;
|
||||
|
||||
size_t print(__FlashStringHelper*);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
|
||||
size_t println(void);
|
||||
size_t println(__FlashStringHelper*);
|
||||
size_t println(const String &);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AFSKClient* audioClient;
|
||||
#endif
|
||||
|
||||
uint32_t _base = 0, _baseHz = 0;
|
||||
float _basePeriod = 0.0f;
|
||||
uint16_t _dotLength = 0;
|
||||
uint16_t _dashLength = 0;
|
||||
uint16_t _letterSpace = 0;
|
||||
uint16_t _wordSpace = 0;
|
||||
uint32_t baseFreq = 0, baseFreqHz = 0;
|
||||
float basePeriod = 0.0f;
|
||||
uint32_t dotLength = 0;
|
||||
uint32_t dashLength = 0;
|
||||
uint32_t letterSpace = 0;
|
||||
uint16_t wordSpace = 0;
|
||||
|
||||
// variables to keep decoding state
|
||||
uint32_t signalCounter = 0;
|
||||
uint32_t signalStart = 0;
|
||||
RadioLibTime_t signalStart = 0;
|
||||
uint32_t pauseCounter = 0;
|
||||
uint32_t pauseStart = 0;
|
||||
RadioLibTime_t pauseStart = 0;
|
||||
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
|
||||
@@ -0,0 +1,594 @@
|
||||
#include "Pager.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#if defined(ESP_PLATFORM)
|
||||
#include "esp_attr.h"
|
||||
#endif
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_PAGER
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
// this is a massive hack, but we need a global-scope ISR to manage the bit reading
|
||||
// let's hope nobody ever tries running two POCSAG receivers at the same time
|
||||
static PhysicalLayer* readBitInstance = NULL;
|
||||
static uint32_t readBitPin = RADIOLIB_NC;
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
IRAM_ATTR
|
||||
#endif
|
||||
static void PagerClientReadBit(void) {
|
||||
if(readBitInstance) {
|
||||
readBitInstance->readBit(readBitPin);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
PagerClient::PagerClient(PhysicalLayer* phy) {
|
||||
phyLayer = phy;
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
readBitInstance = phyLayer;
|
||||
#endif
|
||||
}
|
||||
|
||||
int16_t PagerClient::begin(float base, uint16_t speed, bool invert, uint16_t shift) {
|
||||
// calculate duration of 1 bit in us
|
||||
dataRate = (float)speed/1000.0f;
|
||||
bitDuration = (RadioLibTime_t)1000000/speed;
|
||||
|
||||
// calculate 24-bit frequency
|
||||
baseFreq = base;
|
||||
baseFreqRaw = (baseFreq * 1000000.0) / phyLayer->getFreqStep();
|
||||
|
||||
// calculate module carrier frequency resolution
|
||||
uint16_t step = round(phyLayer->getFreqStep());
|
||||
|
||||
// calculate raw frequency shift
|
||||
shiftFreqHz = shift;
|
||||
shiftFreq = shiftFreqHz/step;
|
||||
inv = invert;
|
||||
|
||||
// initialize BCH encoder
|
||||
RadioLibBCHInstance.begin(RADIOLIB_PAGER_BCH_N, RADIOLIB_PAGER_BCH_K, RADIOLIB_PAGER_BCH_PRIMITIVE_POLY);
|
||||
|
||||
// configure for direct mode
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
int16_t PagerClient::sendTone(uint32_t addr) {
|
||||
return(PagerClient::transmit(NULL, 0, addr));
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t PagerClient::transmit(String& str, uint32_t addr, uint8_t encoding, uint8_t function) {
|
||||
return(PagerClient::transmit(str.c_str(), addr, encoding, function));
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t PagerClient::transmit(const char* str, uint32_t addr, uint8_t encoding, uint8_t function) {
|
||||
return(PagerClient::transmit((uint8_t*)str, strlen(str), addr, encoding, function));
|
||||
}
|
||||
|
||||
int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding, uint8_t function) {
|
||||
if(addr > RADIOLIB_PAGER_ADDRESS_MAX) {
|
||||
return(RADIOLIB_ERR_INVALID_ADDRESS_WIDTH);
|
||||
}
|
||||
|
||||
if(((data == NULL) && (len > 0)) || ((data != NULL) && (len == 0))) {
|
||||
return(RADIOLIB_ERR_INVALID_PAYLOAD);
|
||||
}
|
||||
|
||||
// get symbol bit length based on encoding
|
||||
uint8_t symbolLength = 0;
|
||||
if(encoding == RADIOLIB_PAGER_BCD) {
|
||||
symbolLength = 4;
|
||||
|
||||
} else if(encoding == RADIOLIB_PAGER_ASCII) {
|
||||
symbolLength = 7;
|
||||
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_ENCODING);
|
||||
|
||||
}
|
||||
|
||||
// Automatically set function bits based on given encoding
|
||||
if (function == RADIOLIB_PAGER_FUNC_AUTO) {
|
||||
if(encoding == RADIOLIB_PAGER_BCD) {
|
||||
function = RADIOLIB_PAGER_FUNC_BITS_NUMERIC;
|
||||
|
||||
} else if(encoding == RADIOLIB_PAGER_ASCII) {
|
||||
function = RADIOLIB_PAGER_FUNC_BITS_ALPHA;
|
||||
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_ENCODING);
|
||||
|
||||
}
|
||||
if(len == 0) {
|
||||
function = RADIOLIB_PAGER_FUNC_BITS_TONE;
|
||||
}
|
||||
}
|
||||
if (function > RADIOLIB_PAGER_FUNC_BITS_ALPHA) {
|
||||
return(RADIOLIB_ERR_INVALID_FUNCTION);
|
||||
}
|
||||
|
||||
// get target position in batch (3 LSB from address determine frame position in batch)
|
||||
uint8_t framePos = 2*(addr & 0x07);
|
||||
|
||||
// get address that will be written into address frame
|
||||
uint32_t frameAddr = ((addr >> 3) << RADIOLIB_PAGER_ADDRESS_POS) | (function << RADIOLIB_PAGER_FUNC_BITS_POS);
|
||||
|
||||
// calculate the number of 20-bit data blocks
|
||||
size_t numDataBlocks = (len * symbolLength) / RADIOLIB_PAGER_MESSAGE_BITS_LENGTH;
|
||||
if((len * symbolLength) % RADIOLIB_PAGER_MESSAGE_BITS_LENGTH > 0) {
|
||||
numDataBlocks += 1;
|
||||
}
|
||||
|
||||
// calculate number of batches
|
||||
size_t numBatches = (1 + framePos + numDataBlocks) / RADIOLIB_PAGER_BATCH_LEN + 1;
|
||||
if((1 + numDataBlocks) % RADIOLIB_PAGER_BATCH_LEN == 0) {
|
||||
numBatches -= 1;
|
||||
}
|
||||
|
||||
// calculate message length in 32-bit code words
|
||||
size_t msgLen = RADIOLIB_PAGER_PREAMBLE_LENGTH + (1 + RADIOLIB_PAGER_BATCH_LEN) * numBatches;
|
||||
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
uint32_t msg[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
uint32_t* msg = new uint32_t[msgLen];
|
||||
#endif
|
||||
|
||||
// build the message
|
||||
memset(msg, 0x00, msgLen*sizeof(uint32_t));
|
||||
|
||||
// set preamble
|
||||
for(size_t i = 0; i < RADIOLIB_PAGER_PREAMBLE_LENGTH; i++) {
|
||||
msg[i] = RADIOLIB_PAGER_PREAMBLE_CODE_WORD;
|
||||
}
|
||||
|
||||
// start by setting everything after preamble to idle
|
||||
for(size_t i = RADIOLIB_PAGER_PREAMBLE_LENGTH; i < msgLen; i++) {
|
||||
msg[i] = RADIOLIB_PAGER_IDLE_CODE_WORD;
|
||||
}
|
||||
|
||||
// set frame synchronization code words
|
||||
for(size_t i = 0; i < numBatches; i++) {
|
||||
msg[RADIOLIB_PAGER_PREAMBLE_LENGTH + i*(1 + RADIOLIB_PAGER_BATCH_LEN)] = RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD;
|
||||
}
|
||||
|
||||
// write address code word
|
||||
msg[RADIOLIB_PAGER_PREAMBLE_LENGTH + 1 + framePos] = RadioLibBCHInstance.encode(frameAddr);
|
||||
|
||||
// write the data as 20-bit code blocks
|
||||
if(len > 0) {
|
||||
int8_t remBits = 0;
|
||||
uint8_t dataPos = 0;
|
||||
for(size_t i = 0; i < numDataBlocks + numBatches - 1; i++) {
|
||||
uint8_t blockPos = RADIOLIB_PAGER_PREAMBLE_LENGTH + 1 + framePos + 1 + i;
|
||||
|
||||
// check if we need to skip a frame sync marker
|
||||
if(((blockPos - (RADIOLIB_PAGER_PREAMBLE_LENGTH + 1)) % RADIOLIB_PAGER_BATCH_LEN) == 0) {
|
||||
blockPos++;
|
||||
i++;
|
||||
}
|
||||
|
||||
// mark this as a message code word
|
||||
msg[blockPos] = RADIOLIB_PAGER_MESSAGE_CODE_WORD << (RADIOLIB_PAGER_CODE_WORD_LEN - 1);
|
||||
|
||||
// first insert the remainder from previous code word (if any)
|
||||
if(remBits > 0) {
|
||||
// this doesn't apply to BCD messages, so no need to check that here
|
||||
uint8_t prev = Module::reflect(data[dataPos - 1], 8);
|
||||
prev >>= 1;
|
||||
msg[blockPos] |= (uint32_t)prev << (RADIOLIB_PAGER_CODE_WORD_LEN - 1 - remBits);
|
||||
}
|
||||
|
||||
// set all message symbols until we overflow to the next code word or run out of message symbols
|
||||
int8_t symbolPos = RADIOLIB_PAGER_CODE_WORD_LEN - 1 - symbolLength - remBits;
|
||||
while(symbolPos > (RADIOLIB_PAGER_FUNC_BITS_POS - symbolLength)) {
|
||||
|
||||
// for BCD, encode the symbol
|
||||
uint8_t symbol = data[dataPos++];
|
||||
if(encoding == RADIOLIB_PAGER_BCD) {
|
||||
symbol = encodeBCD(symbol);
|
||||
}
|
||||
symbol = Module::reflect(symbol, 8);
|
||||
symbol >>= (8 - symbolLength);
|
||||
|
||||
// insert the next message symbol
|
||||
msg[blockPos] |= (uint32_t)symbol << symbolPos;
|
||||
symbolPos -= symbolLength;
|
||||
|
||||
// check if we ran out of message symbols
|
||||
if(dataPos >= len) {
|
||||
// in BCD mode, pad the rest of the code word with spaces (0xC)
|
||||
if(encoding == RADIOLIB_PAGER_BCD) {
|
||||
uint8_t numSteps = (symbolPos - RADIOLIB_PAGER_FUNC_BITS_POS + symbolLength)/symbolLength;
|
||||
for(uint8_t j = 0; j < numSteps; j++) {
|
||||
symbol = encodeBCD(' ');
|
||||
symbol = Module::reflect(symbol, 8);
|
||||
symbol >>= (8 - symbolLength);
|
||||
msg[blockPos] |= (uint32_t)symbol << symbolPos;
|
||||
symbolPos -= symbolLength;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure the parity bits are not set due to overflow
|
||||
msg[blockPos] &= ~(RADIOLIB_PAGER_BCH_BITS_MASK);
|
||||
|
||||
// save the number of overflown bits
|
||||
remBits = RADIOLIB_PAGER_FUNC_BITS_POS - symbolPos - symbolLength;
|
||||
|
||||
// do the FEC
|
||||
msg[blockPos] = RadioLibBCHInstance.encode(msg[blockPos]);
|
||||
}
|
||||
}
|
||||
|
||||
// transmit the message
|
||||
PagerClient::write(msg, msgLen);
|
||||
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] msg;
|
||||
#endif
|
||||
|
||||
// turn transmitter off
|
||||
phyLayer->standby();
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
int16_t PagerClient::startReceive(uint32_t pin, uint32_t addr, uint32_t mask) {
|
||||
// save the variables
|
||||
readBitPin = pin;
|
||||
filterAddr = addr;
|
||||
filterMask = mask;
|
||||
filterAddresses = NULL;
|
||||
filterMasks = NULL;
|
||||
filterNumAddresses = 0;
|
||||
return(startReceiveCommon());
|
||||
}
|
||||
|
||||
int16_t PagerClient::startReceive(uint32_t pin, uint32_t *addrs, uint32_t *masks, size_t numAddresses) {
|
||||
// save the variables
|
||||
readBitPin = pin;
|
||||
filterAddr = 0;
|
||||
filterMask = 0;
|
||||
filterAddresses = addrs;
|
||||
filterMasks = masks;
|
||||
filterNumAddresses = numAddresses;
|
||||
return(startReceiveCommon());
|
||||
}
|
||||
|
||||
int16_t PagerClient::startReceiveCommon() {
|
||||
// set the carrier frequency
|
||||
int16_t state = phyLayer->setFrequency(baseFreq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set bitrate
|
||||
state = phyLayer->setBitRate(dataRate);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set frequency deviation to 4.5 khz
|
||||
state = phyLayer->setFrequencyDeviation((float)shiftFreqHz / 1000.0f);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// now set up the direct mode reception
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->hal->pinMode(readBitPin, mod->hal->GpioModeInput);
|
||||
|
||||
// set direct sync word to the frame sync word
|
||||
// the logic here is inverted, because modules like SX1278
|
||||
// assume high frequency to be logic 1, which is opposite to POCSAG
|
||||
if(!inv) {
|
||||
phyLayer->setDirectSyncWord(~RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD, 32);
|
||||
} else {
|
||||
phyLayer->setDirectSyncWord(RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD, 32);
|
||||
}
|
||||
|
||||
phyLayer->setDirectAction(PagerClientReadBit);
|
||||
phyLayer->receiveDirect();
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
size_t PagerClient::available() {
|
||||
return(phyLayer->available() + sizeof(uint32_t))/(sizeof(uint32_t) * (RADIOLIB_PAGER_BATCH_LEN + 1));
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t PagerClient::readData(String& str, size_t len, uint32_t* addr) {
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
|
||||
// determine the message length, based on user input or the amount of received data
|
||||
size_t length = len;
|
||||
if(length == 0) {
|
||||
// one batch can contain at most 80 message symbols
|
||||
length = available()*80;
|
||||
}
|
||||
|
||||
// build a temporary buffer
|
||||
#if 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, addr);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
// check tone-only tramsissions
|
||||
if(length == 0) {
|
||||
length = 6;
|
||||
strncpy((char*)data, "<tone>", length + 1);
|
||||
}
|
||||
|
||||
// add null terminator
|
||||
data[length] = 0;
|
||||
|
||||
// initialize Arduino String class
|
||||
str = String((char*)data);
|
||||
}
|
||||
|
||||
// deallocate temporary buffer
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] data;
|
||||
#endif
|
||||
|
||||
return(state);
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t PagerClient::readData(uint8_t* data, size_t* len, uint32_t* addr) {
|
||||
// find the correct address
|
||||
bool match = false;
|
||||
uint8_t framePos = 0;
|
||||
uint8_t symbolLength = 0;
|
||||
while(!match && phyLayer->available()) {
|
||||
uint32_t cw = read();
|
||||
framePos++;
|
||||
|
||||
// check if it's the idle code word
|
||||
if(cw == RADIOLIB_PAGER_IDLE_CODE_WORD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if it's the sync word
|
||||
if(cw == RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD) {
|
||||
framePos = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
// not an idle code word, check if it's an address word
|
||||
if(cw & (RADIOLIB_PAGER_MESSAGE_CODE_WORD << (RADIOLIB_PAGER_CODE_WORD_LEN - 1))) {
|
||||
// this is pretty weird, it seems to be a message code word without address
|
||||
continue;
|
||||
}
|
||||
|
||||
// should be an address code word, extract the address
|
||||
uint32_t addr_found = ((cw & RADIOLIB_PAGER_ADDRESS_BITS_MASK) >> (RADIOLIB_PAGER_ADDRESS_POS - 3)) | (framePos/2);
|
||||
if (addressMatched(addr_found)) {
|
||||
match = true;
|
||||
if(addr) {
|
||||
*addr = addr_found;
|
||||
}
|
||||
|
||||
// determine the encoding from the function bits
|
||||
if((cw & RADIOLIB_PAGER_FUNCTION_BITS_MASK) >> RADIOLIB_PAGER_FUNC_BITS_POS == RADIOLIB_PAGER_FUNC_BITS_NUMERIC) {
|
||||
symbolLength = 4;
|
||||
} else {
|
||||
symbolLength = 7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!match) {
|
||||
// address not found
|
||||
return(RADIOLIB_ERR_ADDRESS_NOT_FOUND);
|
||||
}
|
||||
|
||||
// we have the address, start pulling out the message
|
||||
size_t decodedBytes = 0;
|
||||
uint32_t prevCw = 0;
|
||||
bool overflow = false;
|
||||
int8_t ovfBits = 0;
|
||||
while(phyLayer->available()) {
|
||||
uint32_t cw = read();
|
||||
|
||||
// check if it's the idle code word
|
||||
if(cw == RADIOLIB_PAGER_IDLE_CODE_WORD) {
|
||||
break;
|
||||
}
|
||||
|
||||
// skip the sync words
|
||||
if(cw == RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check overflow from previous code word
|
||||
uint8_t bitPos = RADIOLIB_PAGER_CODE_WORD_LEN - 1 - symbolLength;
|
||||
if(overflow) {
|
||||
overflow = false;
|
||||
|
||||
// this is a bit convoluted - first, build masks for both previous and current code word
|
||||
uint8_t currPos = RADIOLIB_PAGER_CODE_WORD_LEN - 1 - symbolLength + ovfBits;
|
||||
uint8_t prevPos = RADIOLIB_PAGER_MESSAGE_END_POS;
|
||||
uint32_t prevMask = (0x7FUL << prevPos) & ~((uint32_t)0x7FUL << (RADIOLIB_PAGER_MESSAGE_END_POS + ovfBits));
|
||||
uint32_t currMask = (0x7FUL << currPos) & ~((uint32_t)1 << (RADIOLIB_PAGER_CODE_WORD_LEN - 1));
|
||||
|
||||
// next, get the two parts of the message symbol and stick them together
|
||||
uint8_t prevSymbol = (prevCw & prevMask) >> prevPos;
|
||||
uint8_t currSymbol = (cw & currMask) >> currPos;
|
||||
uint32_t symbol = prevSymbol << (symbolLength - ovfBits) | currSymbol;
|
||||
|
||||
// finally, we can flip the bits
|
||||
symbol = Module::reflect((uint8_t)symbol, 8);
|
||||
symbol >>= (8 - symbolLength);
|
||||
|
||||
// decode BCD and we're done
|
||||
if(symbolLength == 4) {
|
||||
symbol = decodeBCD(symbol);
|
||||
}
|
||||
data[decodedBytes++] = symbol;
|
||||
|
||||
// adjust the bit position of the next message symbol
|
||||
bitPos += ovfBits;
|
||||
bitPos -= symbolLength;
|
||||
}
|
||||
|
||||
// get the message symbols based on the encoding type
|
||||
while(bitPos >= RADIOLIB_PAGER_MESSAGE_END_POS) {
|
||||
// get the message symbol from the code word and reverse bits
|
||||
uint32_t symbol = (cw & (0x7FUL << bitPos)) >> bitPos;
|
||||
symbol = Module::reflect((uint8_t)symbol, 8);
|
||||
symbol >>= (8 - symbolLength);
|
||||
|
||||
// decode BCD if needed
|
||||
if(symbolLength == 4) {
|
||||
symbol = decodeBCD(symbol);
|
||||
}
|
||||
data[decodedBytes++] = symbol;
|
||||
|
||||
// now calculate if the next symbol is overflowing to the following code word
|
||||
int8_t remBits = bitPos - RADIOLIB_PAGER_MESSAGE_END_POS;
|
||||
if(remBits < symbolLength) {
|
||||
// overflow!
|
||||
prevCw = cw;
|
||||
overflow = true;
|
||||
ovfBits = remBits;
|
||||
}
|
||||
bitPos -= symbolLength;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// save the number of decoded bytes
|
||||
*len = decodedBytes;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool PagerClient::addressMatched(uint32_t addr) {
|
||||
// check whether to match single or multiple addresses/masks
|
||||
if(filterNumAddresses == 0) {
|
||||
return((addr & filterMask) == (filterAddr & filterMask));
|
||||
}
|
||||
|
||||
// multiple addresses, check there are some to match
|
||||
if((filterAddresses == NULL) || (filterMasks == NULL)) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < filterNumAddresses; i++) {
|
||||
if((filterAddresses[i] & filterMasks[i]) == (addr & filterMasks[i])) {
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
void PagerClient::write(uint32_t* data, size_t len) {
|
||||
// write code words from buffer
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
PagerClient::write(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void PagerClient::write(uint32_t codeWord) {
|
||||
// write single code word
|
||||
Module* mod = phyLayer->getMod();
|
||||
for(int8_t i = 31; i >= 0; i--) {
|
||||
uint32_t mask = (uint32_t)0x01 << i;
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
|
||||
// figure out the shift direction - start by assuming the bit is 0
|
||||
int16_t change = shiftFreq;
|
||||
|
||||
// now check if it's actually 1
|
||||
if(codeWord & mask) {
|
||||
change = -shiftFreq;
|
||||
}
|
||||
|
||||
// finally, check if inversion is enabled
|
||||
if(inv) {
|
||||
change = -change;
|
||||
}
|
||||
|
||||
// now transmit the shifted frequency
|
||||
phyLayer->transmitDirect(baseFreqRaw + change);
|
||||
|
||||
// this is pretty silly, while(mod->hal->micros() ... ) would be enough
|
||||
// but for some reason, MegaCore throws a linker error on it
|
||||
// "relocation truncated to fit: R_AVR_7_PCREL against `no symbol'"
|
||||
RadioLibTime_t now = mod->hal->micros();
|
||||
while(now - start < bitDuration) {
|
||||
now = mod->hal->micros();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
uint32_t PagerClient::read() {
|
||||
uint32_t codeWord = 0;
|
||||
codeWord |= (uint32_t)phyLayer->read() << 24;
|
||||
codeWord |= (uint32_t)phyLayer->read() << 16;
|
||||
codeWord |= (uint32_t)phyLayer->read() << 8;
|
||||
codeWord |= (uint32_t)phyLayer->read();
|
||||
|
||||
// check if we need to invert bits
|
||||
// the logic here is inverted, because modules like SX1278
|
||||
// assume high frequency to be logic 1, which is opposite to POCSAG
|
||||
if(!inv) {
|
||||
codeWord = ~codeWord;
|
||||
}
|
||||
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("R\t%lX", (long unsigned int)codeWord);
|
||||
// TODO BCH error correction here
|
||||
return(codeWord);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t PagerClient::encodeBCD(char c) {
|
||||
switch(c) {
|
||||
case '*':
|
||||
return(0x0A);
|
||||
case 'U':
|
||||
return(0x0B);
|
||||
case ' ':
|
||||
return(0x0C);
|
||||
case '-':
|
||||
return(0x0D);
|
||||
case ')':
|
||||
return(0x0E);
|
||||
case '(':
|
||||
return(0x0F);
|
||||
}
|
||||
return(c - '0');
|
||||
}
|
||||
|
||||
char PagerClient::decodeBCD(uint8_t b) {
|
||||
switch(b) {
|
||||
case 0x0A:
|
||||
return('*');
|
||||
case 0x0B:
|
||||
return('U');
|
||||
case 0x0C:
|
||||
return(' ');
|
||||
case 0x0D:
|
||||
return('-');
|
||||
case 0x0E:
|
||||
return(')');
|
||||
case 0x0F:
|
||||
return('(');
|
||||
}
|
||||
return(b + '0');
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,206 @@
|
||||
#if !defined(_RADIOLIB_PAGER_H) && !RADIOLIB_EXCLUDE_PAGER
|
||||
#define _RADIOLIB_PAGER_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../../utils/FEC.h"
|
||||
|
||||
// frequency shift in Hz
|
||||
#define RADIOLIB_PAGER_FREQ_SHIFT_HZ (4500)
|
||||
|
||||
// supported encoding schemes
|
||||
#define RADIOLIB_PAGER_ASCII (0)
|
||||
#define RADIOLIB_PAGER_BCD (1)
|
||||
|
||||
// preamble length in 32-bit code words
|
||||
#define RADIOLIB_PAGER_PREAMBLE_LENGTH (18)
|
||||
|
||||
// protocol-specified code words
|
||||
#define RADIOLIB_PAGER_PREAMBLE_CODE_WORD (0xAAAAAAAA)
|
||||
#define RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD (0x7CD215D8)
|
||||
#define RADIOLIB_PAGER_IDLE_CODE_WORD (0x7A89C197)
|
||||
|
||||
// code word type identification flags
|
||||
#define RADIOLIB_PAGER_ADDRESS_CODE_WORD (0UL)
|
||||
#define RADIOLIB_PAGER_MESSAGE_CODE_WORD (1UL)
|
||||
|
||||
// length of code word in bits
|
||||
#define RADIOLIB_PAGER_CODE_WORD_LEN (32)
|
||||
|
||||
// number of message bits in a single code block
|
||||
#define RADIOLIB_PAGER_ADDRESS_POS (13)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_POS (11)
|
||||
#define RADIOLIB_PAGER_MESSAGE_BITS_LENGTH (20)
|
||||
#define RADIOLIB_PAGER_MESSAGE_END_POS (11)
|
||||
|
||||
// number of code words in a batch
|
||||
#define RADIOLIB_PAGER_BATCH_LEN (16)
|
||||
|
||||
// mask for address bits in a single code word
|
||||
#define RADIOLIB_PAGER_ADDRESS_BITS_MASK (0x7FFFE000UL)
|
||||
|
||||
// mask for function bits in a single code word
|
||||
#define RADIOLIB_PAGER_FUNCTION_BITS_MASK (0x00001800UL)
|
||||
|
||||
// mask for BCH bits in a single code word
|
||||
#define RADIOLIB_PAGER_BCH_BITS_MASK (0x000007FFUL)
|
||||
|
||||
// message type functional bits
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_ACTIVATION (0b10)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11)
|
||||
#define RADIOLIB_PAGER_FUNC_AUTO 0xFF
|
||||
|
||||
// the maximum allowed address (2^22 - 1)
|
||||
#define RADIOLIB_PAGER_ADDRESS_MAX (2097151)
|
||||
|
||||
/*!
|
||||
\class PagerClient
|
||||
\brief Client for Pager communication.
|
||||
*/
|
||||
class PagerClient {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit PagerClient(PhysicalLayer* phy);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
\param base Base (center) frequency to be used in MHz.
|
||||
\param speed Bit rate to use in bps. Common POCSAG decoders can receive 512, 1200 and 2400 bps.
|
||||
\param invert Enable frequency inversion. Disabled by default (high frequency is digital 0).
|
||||
\param shift Set custom frequency shift, defaults to 4500 Hz.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float base, uint16_t speed, bool invert = false, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
|
||||
|
||||
/*!
|
||||
\brief Method to send a tone-only alert to a destination pager.
|
||||
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendTone(uint32_t addr);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Arduino String transmit method.
|
||||
\param str Address of Arduino string that will be transmitted.
|
||||
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
|
||||
\param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD.
|
||||
\param function bits (NUMERIC, TONE, ACTIVATION, ALPHANUMERIC). Allowed values 0 to 3. Defaults to auto select by specified encoding
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief C-string transmit method.
|
||||
\param str C-string that will be transmitted.
|
||||
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
|
||||
\param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD.
|
||||
\param function bits (NUMERIC, TONE, ACTIVATION, ALPHANUMERIC). Allowed values 0 to 3. Defaults to auto select by specified encoding
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
|
||||
|
||||
/*!
|
||||
\brief Binary transmit method. Will transmit arbitrary binary data.
|
||||
\param data Binary data that will be transmitted.
|
||||
\param len Length of binary data to transmit (in bytes).
|
||||
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
|
||||
\param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD.
|
||||
\param function bits (NUMERIC, TONE, ACTIVATION, ALPHANUMERIC). Allowed values 0 to 3. Defaults to auto select by specified encoding
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
/*!
|
||||
\brief Start reception of POCSAG packets.
|
||||
\param pin Pin to receive digital data on (e.g., DIO2 for SX127x).
|
||||
\param addr Address of this "pager". Allowed values are 0 to 2097151 - values above 2000000 are reserved.
|
||||
\param mask Address filter mask - set individual bits to enable or disable match on that bit of the address.
|
||||
Set to 0xFFFFF (all bits checked) by default.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive(uint32_t pin, uint32_t addr, uint32_t mask = 0xFFFFF);
|
||||
|
||||
/*!
|
||||
\brief Start reception of POCSAG packets for multiple addresses and masks.
|
||||
\param pin Pin to receive digital data on (e.g., DIO2 for SX127x).
|
||||
\param addrs Array of addresses to receive.
|
||||
\param masks Array of address masks to use for filtering. Masks will be applied to corresponding addresses in addr array.
|
||||
\param numAddress Number of addresses/masks to match.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive(uint32_t pin, uint32_t *addrs, uint32_t *masks, size_t numAddress);
|
||||
|
||||
/*!
|
||||
\brief Get the number of POCSAG batches available in buffer. Limited by the size of direct mode buffer!
|
||||
\returns Number of available batches.
|
||||
*/
|
||||
size_t available();
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method.
|
||||
\param str Address of Arduino String to save the received data.
|
||||
\param len Expected number of characters in the message. When set to 0, the message length will be retrieved
|
||||
automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
|
||||
\param addr Pointer to variable holding the address of the received pager message.
|
||||
Set to NULL to not retrieve address.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method.
|
||||
\param data Pointer to array to save the received message.
|
||||
\param len Pointer to variable holding the number of bytes that will be read. When set to 0, the packet length
|
||||
will be retrieved automatically. When more bytes than received are requested, only the number of bytes
|
||||
requested will be returned. Upon completion, the number of bytes received will be written to this variable.
|
||||
\param addr Pointer to variable holding the address of the received pager message.
|
||||
Set to NULL to not retrieve address.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL);
|
||||
#endif
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* phyLayer;
|
||||
|
||||
float baseFreq = 0;
|
||||
float dataRate = 0;
|
||||
uint32_t baseFreqRaw = 0;
|
||||
uint16_t shiftFreq = 0;
|
||||
uint16_t shiftFreqHz = 0;
|
||||
RadioLibTime_t bitDuration = 0;
|
||||
uint32_t filterAddr = 0;
|
||||
uint32_t filterMask = 0;
|
||||
uint32_t *filterAddresses = nullptr;
|
||||
uint32_t *filterMasks = nullptr;
|
||||
size_t filterNumAddresses = 0;
|
||||
bool inv = false;
|
||||
|
||||
void write(uint32_t* data, size_t len);
|
||||
void write(uint32_t codeWord);
|
||||
int16_t startReceiveCommon();
|
||||
bool addressMatched(uint32_t addr);
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
uint32_t read();
|
||||
#endif
|
||||
|
||||
uint8_t encodeBCD(char c);
|
||||
char decodeBCD(uint8_t b);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,14 +1,16 @@
|
||||
#include "PhysicalLayer.h"
|
||||
#include <string.h>
|
||||
|
||||
PhysicalLayer::PhysicalLayer(float freqStep, size_t maxPacketLength) {
|
||||
_freqStep = freqStep;
|
||||
_maxPacketLength = maxPacketLength;
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
_bufferBitPos = 0;
|
||||
_bufferWritePos = 0;
|
||||
PhysicalLayer::PhysicalLayer(float step, size_t maxLen) {
|
||||
this->freqStep = step;
|
||||
this->maxPacketLength = maxLen;
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
this->bufferBitPos = 0;
|
||||
this->bufferWritePos = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) {
|
||||
// read flash string length
|
||||
size_t len = 0;
|
||||
@@ -22,7 +24,7 @@ int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) {
|
||||
}
|
||||
|
||||
// dynamically allocate memory
|
||||
#if defined(RADIOLIB_STATIC_ONLY)
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
char str[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
char* str = new char[len];
|
||||
@@ -36,7 +38,7 @@ int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) {
|
||||
|
||||
// transmit string
|
||||
int16_t state = transmit(str, addr);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] str;
|
||||
#endif
|
||||
return(state);
|
||||
@@ -45,60 +47,20 @@ int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) {
|
||||
int16_t PhysicalLayer::transmit(String& str, uint8_t addr) {
|
||||
return(transmit(str.c_str(), addr));
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
// 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(const uint8_t* data, size_t len, uint8_t addr) {
|
||||
(void)data;
|
||||
(void)len;
|
||||
(void)addr;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t PhysicalLayer::receive(String& str, size_t len) {
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
|
||||
@@ -106,12 +68,12 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
|
||||
size_t length = len;
|
||||
|
||||
// build a temporary buffer
|
||||
#if defined(RADIOLIB_STATIC_ONLY)
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
|
||||
#else
|
||||
uint8_t* data = NULL;
|
||||
if(length == 0) {
|
||||
data = new uint8_t[_maxPacketLength + 1];
|
||||
data = new uint8_t[this->maxPacketLength + 1];
|
||||
} else {
|
||||
data = new uint8_t[length + 1];
|
||||
}
|
||||
@@ -123,7 +85,9 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
|
||||
// attempt packet reception
|
||||
state = receive(data, length);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
// 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)) {
|
||||
// read the number of actually received bytes (for unknown packets)
|
||||
if(len == 0) {
|
||||
length = getPacketLength(false);
|
||||
@@ -137,15 +101,277 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
|
||||
}
|
||||
|
||||
// deallocate temporary buffer
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] data;
|
||||
#endif
|
||||
|
||||
return(state);
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t PhysicalLayer::receive(uint8_t* data, size_t len) {
|
||||
(void)data;
|
||||
(void)len;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::sleep() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::standby() {
|
||||
return(standby(RADIOLIB_STANDBY_DEFAULT));
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::standby(uint8_t mode) {
|
||||
(void)mode;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::startReceive() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len) {
|
||||
(void)timeout;
|
||||
(void)irqFlags;
|
||||
(void)irqMask;
|
||||
(void)len;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t PhysicalLayer::startTransmit(String& str, uint8_t addr) {
|
||||
return(startTransmit(str.c_str(), addr));
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t PhysicalLayer::startTransmit(const char* str, uint8_t addr) {
|
||||
return(startTransmit((uint8_t*)str, strlen(str), addr));
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::startTransmit(const 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);
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
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 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 !RADIOLIB_STATIC_ONLY
|
||||
delete[] data;
|
||||
#endif
|
||||
|
||||
return(state);
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::invertIQ(bool enable) {
|
||||
(void)enable;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setOutputPower(int8_t power) {
|
||||
(void)power;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
(void)power;
|
||||
(void)clipped;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setSyncWord(uint8_t* sync, size_t len) {
|
||||
(void)sync;
|
||||
(void)len;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setPreambleLength(size_t len) {
|
||||
(void)len;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setDataRate(DataRate_t dr) {
|
||||
(void)dr;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::checkDataRate(DataRate_t dr) {
|
||||
(void)dr;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
float PhysicalLayer::getFreqStep() const {
|
||||
return(_freqStep);
|
||||
return(this->freqStep);
|
||||
}
|
||||
|
||||
size_t PhysicalLayer::getPacketLength(bool update) {
|
||||
(void)update;
|
||||
return(0);
|
||||
}
|
||||
|
||||
float PhysicalLayer::getRSSI() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
float PhysicalLayer::getSNR() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
RadioLibTime_t PhysicalLayer::getTimeOnAir(size_t len) {
|
||||
(void)len;
|
||||
return(0);
|
||||
}
|
||||
|
||||
RadioLibTime_t PhysicalLayer::calculateRxTimeout(RadioLibTime_t timeoutUs) {
|
||||
(void)timeoutUs;
|
||||
return(0);
|
||||
}
|
||||
|
||||
uint32_t PhysicalLayer::getIrqMapped(RadioLibIrqFlags_t irq) {
|
||||
// iterate over all set bits and build the module-specific flags
|
||||
uint32_t irqRaw = 0;
|
||||
for(uint8_t i = 0; i < 8*(sizeof(RadioLibIrqFlags_t)); i++) {
|
||||
if((irq & (uint32_t)(1UL << i)) && (this->irqMap[i] != RADIOLIB_IRQ_NOT_SUPPORTED)) {
|
||||
irqRaw |= this->irqMap[i];
|
||||
}
|
||||
}
|
||||
|
||||
return(irqRaw);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::checkIrq(RadioLibIrqType_t irq) {
|
||||
if((irq > RADIOLIB_IRQ_TIMEOUT) || (this->irqMap[irq] == RADIOLIB_IRQ_NOT_SUPPORTED)) {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
return(getIrqFlags() & this->irqMap[irq]);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setIrq(RadioLibIrqFlags_t irq) {
|
||||
return(setIrqFlags(getIrqMapped(irq)));
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::clearIrq(RadioLibIrqFlags_t irq) {
|
||||
return(clearIrqFlags(getIrqMapped(irq)));
|
||||
}
|
||||
|
||||
uint32_t PhysicalLayer::getIrqFlags() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setIrqFlags(uint32_t irq) {
|
||||
(void)irq;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::clearIrqFlags(uint32_t irq) {
|
||||
(void)irq;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::startChannelScan() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::startChannelScan(const ChannelScanConfig_t &config) {
|
||||
(void)config;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::getChannelScanResult() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::scanChannel() {
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::scanChannel(const ChannelScanConfig_t &config) {
|
||||
(void)config;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
int32_t PhysicalLayer::random(int32_t max) {
|
||||
@@ -164,7 +390,6 @@ int32_t PhysicalLayer::random(int32_t max) {
|
||||
if(randNum < 0) {
|
||||
randNum *= -1;
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(randNum);
|
||||
return(randNum % max);
|
||||
}
|
||||
|
||||
@@ -176,6 +401,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);
|
||||
@@ -190,31 +419,37 @@ int16_t PhysicalLayer::startDirect() {
|
||||
return(state);
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
int16_t PhysicalLayer::available() {
|
||||
return(_bufferWritePos);
|
||||
return(this->bufferWritePos);
|
||||
}
|
||||
|
||||
uint8_t PhysicalLayer::read() {
|
||||
if(_directSyncWordLen > 0) {
|
||||
_gotSync = false;
|
||||
_syncBuffer = 0;
|
||||
void PhysicalLayer::dropSync() {
|
||||
if(this->directSyncWordLen > 0) {
|
||||
this->gotSync = false;
|
||||
this->syncBuffer = 0;
|
||||
}
|
||||
_bufferWritePos--;
|
||||
return(_buffer[_bufferReadPos++]);
|
||||
}
|
||||
|
||||
uint8_t PhysicalLayer::read(bool drop) {
|
||||
if(drop) {
|
||||
dropSync();
|
||||
}
|
||||
this->bufferWritePos--;
|
||||
return(this->buffer[this->bufferReadPos++]);
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::setDirectSyncWord(uint32_t syncWord, uint8_t len) {
|
||||
if(len > 32) {
|
||||
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
|
||||
}
|
||||
_directSyncWordMask = 0xFFFFFFFF >> (32 - len);
|
||||
_directSyncWordLen = len;
|
||||
_directSyncWord = syncWord;
|
||||
this->directSyncWordMask = 0xFFFFFFFF >> (32 - len);
|
||||
this->directSyncWordLen = len;
|
||||
this->directSyncWord = syncWord;
|
||||
|
||||
// override sync word matching when length is set to 0
|
||||
if(_directSyncWordLen == 0) {
|
||||
_gotSync = true;
|
||||
if(this->directSyncWordLen == 0) {
|
||||
this->gotSync = true;
|
||||
}
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
@@ -222,35 +457,87 @@ int16_t PhysicalLayer::setDirectSyncWord(uint32_t syncWord, uint8_t len) {
|
||||
|
||||
void PhysicalLayer::updateDirectBuffer(uint8_t bit) {
|
||||
// check sync word
|
||||
if(!_gotSync) {
|
||||
_syncBuffer <<= 1;
|
||||
_syncBuffer |= bit;
|
||||
if((_syncBuffer & _directSyncWordMask) == _directSyncWord) {
|
||||
_gotSync = true;
|
||||
_bufferWritePos = 0;
|
||||
_bufferReadPos = 0;
|
||||
_bufferBitPos = 0;
|
||||
if(!this->gotSync) {
|
||||
this->syncBuffer <<= 1;
|
||||
this->syncBuffer |= bit;
|
||||
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("S\t%lu", (long unsigned int)this->syncBuffer);
|
||||
|
||||
if((this->syncBuffer & this->directSyncWordMask) == this->directSyncWord) {
|
||||
this->gotSync = true;
|
||||
this->bufferWritePos = 0;
|
||||
this->bufferReadPos = 0;
|
||||
this->bufferBitPos = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
// save the bit
|
||||
if(bit) {
|
||||
_buffer[_bufferWritePos] |= 0x01 << _bufferBitPos;
|
||||
this->buffer[this->bufferWritePos] |= 0x01 << this->bufferBitPos;
|
||||
} else {
|
||||
_buffer[_bufferWritePos] &= ~(0x01 << _bufferBitPos);
|
||||
this->buffer[this->bufferWritePos] &= ~(0x01 << this->bufferBitPos);
|
||||
}
|
||||
_bufferBitPos++;
|
||||
this->bufferBitPos++;
|
||||
|
||||
// check complete byte
|
||||
if(_bufferBitPos == 8) {
|
||||
_buffer[_bufferWritePos] = Module::flipBits(_buffer[_bufferWritePos]);
|
||||
_bufferWritePos++;
|
||||
_bufferBitPos = 0;
|
||||
if(this->bufferBitPos == 8) {
|
||||
this->buffer[this->bufferWritePos] = Module::reflect(this->buffer[this->bufferWritePos], 8);
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("R\t%X", this->buffer[this->bufferWritePos]);
|
||||
|
||||
this->bufferWritePos++;
|
||||
this->bufferBitPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicalLayer::setDirectAction(void (*func)(void)) {
|
||||
(void)func;
|
||||
}
|
||||
|
||||
void PhysicalLayer::readBit(uint32_t pin) {
|
||||
(void)pin;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int16_t PhysicalLayer::setDIOMapping(RADIOLIB_PIN_TYPE pin, uint8_t value) {
|
||||
int16_t PhysicalLayer::setDIOMapping(uint32_t pin, uint32_t value) {
|
||||
(void)pin;
|
||||
(void)value;
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
void PhysicalLayer::setPacketReceivedAction(void (*func)(void)) {
|
||||
(void)func;
|
||||
}
|
||||
|
||||
void PhysicalLayer::clearPacketReceivedAction() {
|
||||
|
||||
}
|
||||
|
||||
void PhysicalLayer::setPacketSentAction(void (*func)(void)) {
|
||||
(void)func;
|
||||
}
|
||||
|
||||
void PhysicalLayer::clearPacketSentAction() {
|
||||
|
||||
}
|
||||
|
||||
void PhysicalLayer::setChannelScanAction(void (*func)(void)) {
|
||||
(void)func;
|
||||
}
|
||||
|
||||
void PhysicalLayer::clearChannelScanAction() {
|
||||
|
||||
}
|
||||
|
||||
#if RADIOLIB_INTERRUPT_TIMING
|
||||
void PhysicalLayer::setInterruptSetup(void (*func)(uint32_t)) {
|
||||
Module* mod = getMod();
|
||||
mod->TimerSetupCb = func;
|
||||
}
|
||||
|
||||
void PhysicalLayer::setTimerFlag() {
|
||||
Module* mod = getMod();
|
||||
mod->TimerFlag = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,12 +4,133 @@
|
||||
#include "../../TypeDef.h"
|
||||
#include "../../Module.h"
|
||||
|
||||
// common IRQ values - the IRQ flags in RadioLibIrqFlags_t arguments are offset by this value
|
||||
enum RadioLibIrqType_t {
|
||||
RADIOLIB_IRQ_TX_DONE = 0x00,
|
||||
RADIOLIB_IRQ_RX_DONE = 0x01,
|
||||
RADIOLIB_IRQ_PREAMBLE_DETECTED = 0x02,
|
||||
RADIOLIB_IRQ_SYNC_WORD_VALID = 0x03,
|
||||
RADIOLIB_IRQ_HEADER_VALID = 0x04,
|
||||
RADIOLIB_IRQ_HEADER_ERR = 0x05,
|
||||
RADIOLIB_IRQ_CRC_ERR = 0x06,
|
||||
RADIOLIB_IRQ_CAD_DONE = 0x07,
|
||||
RADIOLIB_IRQ_CAD_DETECTED = 0x08,
|
||||
RADIOLIB_IRQ_TIMEOUT = 0x09,
|
||||
RADIOLIB_IRQ_NOT_SUPPORTED = 0x1F, // this must be the last value, intentionally set to 31
|
||||
};
|
||||
|
||||
// some commonly used default values - defined here to ensure all modules have the same default behavior
|
||||
#define RADIOLIB_IRQ_RX_DEFAULT_FLAGS ((1UL << RADIOLIB_IRQ_RX_DONE) | (1UL << RADIOLIB_IRQ_TIMEOUT) | (1UL << RADIOLIB_IRQ_CRC_ERR) | (1UL << RADIOLIB_IRQ_HEADER_VALID) | (1UL << RADIOLIB_IRQ_HEADER_ERR))
|
||||
#define RADIOLIB_IRQ_RX_DEFAULT_MASK ((1UL << RADIOLIB_IRQ_RX_DONE))
|
||||
#define RADIOLIB_IRQ_CAD_DEFAULT_FLAGS ((1UL << RADIOLIB_IRQ_CAD_DETECTED) | (1UL << RADIOLIB_IRQ_CAD_DONE))
|
||||
#define RADIOLIB_IRQ_CAD_DEFAULT_MASK ((1UL << RADIOLIB_IRQ_CAD_DETECTED) | (1UL << RADIOLIB_IRQ_CAD_DONE))
|
||||
|
||||
/*!
|
||||
\struct LoRaRate_t
|
||||
\brief Data rate structure interpretation in case LoRa is used
|
||||
*/
|
||||
struct LoRaRate_t {
|
||||
/*! \brief LoRa spreading factor */
|
||||
uint8_t spreadingFactor;
|
||||
|
||||
/*! \brief LoRa bandwidth in kHz */
|
||||
float bandwidth;
|
||||
|
||||
/*! \brief LoRa coding rate */
|
||||
uint8_t codingRate;
|
||||
};
|
||||
|
||||
/*!
|
||||
\struct FSKRate_t
|
||||
\brief Data rate structure interpretation in case FSK is used
|
||||
*/
|
||||
struct FSKRate_t {
|
||||
/*! \brief FSK bit rate in kbps */
|
||||
float bitRate;
|
||||
|
||||
/*! \brief FSK frequency deviation in kHz */
|
||||
float freqDev;
|
||||
};
|
||||
|
||||
/*!
|
||||
\struct LrFhssRate_t
|
||||
\brief Data rate structure interpretation in case LR-FHSS is used
|
||||
*/
|
||||
struct LrFhssRate_t {
|
||||
/*! \brief Bandwidth */
|
||||
uint8_t bw;
|
||||
|
||||
/*! \brief Coding rate */
|
||||
uint8_t cr;
|
||||
};
|
||||
|
||||
/*!
|
||||
\union DataRate_t
|
||||
\brief Common data rate structure
|
||||
*/
|
||||
union DataRate_t {
|
||||
/*! \brief Interpretation for LoRa modems */
|
||||
LoRaRate_t lora;
|
||||
|
||||
/*! \brief Interpretation for FSK modems */
|
||||
FSKRate_t fsk;
|
||||
};
|
||||
|
||||
/*!
|
||||
\struct CADScanConfig_t
|
||||
\brief Channel scan configuration interpretation in case LoRa CAD is used
|
||||
*/
|
||||
struct CADScanConfig_t {
|
||||
/*! \brief Number of symbols to consider signal present */
|
||||
uint8_t symNum;
|
||||
|
||||
/*! \brief Number of peak detection symbols */
|
||||
uint8_t detPeak;
|
||||
|
||||
/*! \brief Number of minimum detection symbols */
|
||||
uint8_t detMin;
|
||||
|
||||
/*! \brief Exit mode after signal detection is complete - module-specific value */
|
||||
uint8_t exitMode;
|
||||
|
||||
/*! \brief Timeout in microseconds */
|
||||
RadioLibTime_t timeout;
|
||||
|
||||
/*! \brief Optional IRQ flags to set, bits offset by the value of RADIOLIB_IRQ_ */
|
||||
RadioLibIrqFlags_t irqFlags;
|
||||
|
||||
/*! \brief Optional IRQ mask to set, bits offset by the value of RADIOLIB_IRQ_ */
|
||||
RadioLibIrqFlags_t irqMask;
|
||||
};
|
||||
|
||||
/*!
|
||||
\struct RSSIScanConfig_t
|
||||
\brief Channel scan configuration interpretation in case RSSI threshold is used
|
||||
*/
|
||||
struct RSSIScanConfig_t {
|
||||
/*! \brief RSSI limit in dBm */
|
||||
float limit;
|
||||
};
|
||||
|
||||
/*!
|
||||
\union ChannelScanConfig_t
|
||||
\brief Common channel scan configuration structure
|
||||
*/
|
||||
union ChannelScanConfig_t {
|
||||
/*! \brief Interpretation for modems that use CAD (usually LoRa modems)*/
|
||||
CADScanConfig_t cad;
|
||||
|
||||
/*! \brief Interpretation for modems that use RSSI threshold*/
|
||||
RSSIScanConfig_t rssi;
|
||||
};
|
||||
|
||||
/*!
|
||||
\class PhysicalLayer
|
||||
|
||||
\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.
|
||||
\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.
|
||||
*/
|
||||
class PhysicalLayer {
|
||||
public:
|
||||
@@ -18,322 +139,547 @@ class PhysicalLayer {
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param freqStep Frequency step of the synthesizer in Hz.
|
||||
|
||||
\param maxPacketLength Maximum length of packet that can be received by the module.
|
||||
\param step Frequency step of the synthesizer in Hz.
|
||||
\param maxLen Maximum length of packet that can be received by the module.
|
||||
*/
|
||||
PhysicalLayer(float freqStep, size_t maxPacketLength);
|
||||
PhysicalLayer(float step, size_t maxLen);
|
||||
|
||||
// basic methods
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\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.
|
||||
|
||||
\param str Address of Arduino 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(String& str, uint8_t addr = 0);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief C-string transmit method.
|
||||
|
||||
\param str C-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(const char* str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Binary transmit method. Must be implemented in module class.
|
||||
|
||||
\param data Binary data that will be transmitted.
|
||||
|
||||
\param len Length of binary data to transmit (in bytes).
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) = 0;
|
||||
virtual int16_t transmit(const uint8_t* data, size_t len, uint8_t addr = 0);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Arduino String receive method.
|
||||
|
||||
\param str Address of Arduino String to save the received data.
|
||||
|
||||
\param len Expected number of characters in the message. Leave as 0 if expecting a unknown size packet
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receive(String& str, size_t len = 0);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Sets module to sleep.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t sleep();
|
||||
|
||||
/*!
|
||||
\brief Sets module to standby.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t standby() = 0;
|
||||
virtual int16_t standby();
|
||||
|
||||
/*!
|
||||
\brief Sets module to a specific standby mode.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t standby(uint8_t mode);
|
||||
|
||||
/*!
|
||||
\brief Sets module to received mode using its default configuration.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t startReceive();
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven receive method. A DIO pin will be activated when full packet is received.
|
||||
Must be implemented in module class.
|
||||
\param timeout Raw timeout value. Some modules use this argument to specify operation mode
|
||||
(single vs. continuous receive).
|
||||
\param irqFlags Sets the IRQ flags.
|
||||
\param irqMask Sets the mask of IRQ flags that will trigger the radio interrupt pin.
|
||||
\param len Packet length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len);
|
||||
|
||||
/*!
|
||||
\brief Binary receive method. Must be implemented in module class.
|
||||
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
||||
|
||||
\param len Packet length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
|
||||
\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);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking.
|
||||
Interrupt pin will be activated when transmission finishes.
|
||||
|
||||
\param str Address of Arduino 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 startTransmit(String& str, uint8_t addr = 0);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking.
|
||||
Interrupt pin will be activated when transmission finishes.
|
||||
|
||||
\param str C-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 startTransmit(const char* str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven binary transmit method.
|
||||
|
||||
\param data Binary data that will be transmitted.
|
||||
|
||||
\param len Length of binary data to transmit (in bytes).
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) = 0;
|
||||
virtual int16_t startTransmit(const 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();
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method.
|
||||
|
||||
\param str Address of Arduino String to save the received data.
|
||||
|
||||
\param len Expected number of characters in the message. When set to 0, the packet length will be retreived automatically.
|
||||
When more bytes than received are requested, only the number of bytes requested will be returned.
|
||||
|
||||
\param len Expected number of characters in the message. When set to 0, the packet length will be retrieved
|
||||
automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(String& str, size_t len = 0);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method.
|
||||
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
|
||||
\param len Number of bytes that will be read. When set to 0, the packet length will be retrieved automatically.
|
||||
When more bytes than received are requested, only the number of bytes requested will be returned.
|
||||
|
||||
\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.
|
||||
While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\param frf 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.
|
||||
|
||||
\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.
|
||||
While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t receiveDirect() = 0;
|
||||
virtual int16_t receiveDirect();
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz.
|
||||
Only available in FSK mode. Must be implemented in module class.
|
||||
|
||||
\param freqDev Frequency deviation to be set (in kHz).
|
||||
|
||||
\brief Sets carrier frequency. Must be implemented in module class.
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setFrequencyDeviation(float freqDev) = 0;
|
||||
virtual int16_t setFrequency(float freq);
|
||||
|
||||
/*!
|
||||
\brief Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class.
|
||||
\param br Bit rate to be set (in kbps).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
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.
|
||||
\param freqDev Frequency deviation to be set (in kHz).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setFrequencyDeviation(float freqDev);
|
||||
|
||||
/*!
|
||||
\brief Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class.
|
||||
|
||||
\param sh Shaping to be set. See \ref config_shaping for possible values.
|
||||
|
||||
\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.
|
||||
|
||||
\param enc Encoding to be used. See \ref config_encoding for possible values.
|
||||
|
||||
\param encoding Encoding to be used. See \ref config_encoding for possible values.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setEncoding(uint8_t encoding) = 0;
|
||||
virtual int16_t setEncoding(uint8_t encoding);
|
||||
|
||||
/*!
|
||||
\brief Set IQ inversion. Must be implemented in module class if the module supports it.
|
||||
\param enable True to use inverted IQ, false for non-inverted.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t invertIQ(bool enable);
|
||||
|
||||
/*!
|
||||
\brief Set output power. Must be implemented in module class if the module supports it.
|
||||
\param power Output power in dBm. The allowed range depends on the module used.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setOutputPower(int8_t power);
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable. Must be implemented in module class if the module supports it.
|
||||
\param power Output power in dBm. The allowed range depends on the module used.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t checkOutputPower(int8_t power, int8_t* clipped);
|
||||
|
||||
/*!
|
||||
\brief Set sync word. Must be implemented in module class if the module supports it.
|
||||
\param sync Pointer to the sync word.
|
||||
\param len Sync word length in bytes. Maximum length depends on the module used.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setSyncWord(uint8_t* sync, size_t len);
|
||||
|
||||
/*!
|
||||
\brief Set preamble length. Must be implemented in module class if the module supports it.
|
||||
\param len Preamble length in bytes. Maximum length depends on the module used.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setPreambleLength(size_t len);
|
||||
|
||||
/*!
|
||||
\brief Set data. Must be implemented in module class if the module supports it.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setDataRate(DataRate_t dr);
|
||||
|
||||
/*!
|
||||
\brief Check the data rate can be configured by this module. Must be implemented in module class if the module supports it.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t checkDataRate(DataRate_t dr);
|
||||
|
||||
/*!
|
||||
\brief Gets the module frequency step size that was set in constructor.
|
||||
|
||||
\returns Synthesizer frequency step size in Hz.
|
||||
*/
|
||||
float getFreqStep() const;
|
||||
|
||||
/*!
|
||||
\brief Query modem for the packet length of received payload. Must be implemented in module class.
|
||||
|
||||
\param update Update received packet length. Will return cached value when set to false.
|
||||
|
||||
\returns Length of last received packet in bytes.
|
||||
*/
|
||||
virtual size_t getPacketLength(bool update = true) = 0;
|
||||
virtual size_t getPacketLength(bool update = true);
|
||||
|
||||
/*!
|
||||
\brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
|
||||
\returns RSSI of the last received packet in dBm.
|
||||
*/
|
||||
virtual float getRSSI();
|
||||
|
||||
/*!
|
||||
\brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
|
||||
\returns SNR of the last received packet in dB.
|
||||
*/
|
||||
virtual float getSNR();
|
||||
|
||||
/*!
|
||||
\brief Get expected time-on-air for a given size of payload
|
||||
\param len Payload length in bytes.
|
||||
\returns Expected time-on-air in microseconds.
|
||||
*/
|
||||
virtual RadioLibTime_t getTimeOnAir(size_t len);
|
||||
|
||||
/*!
|
||||
\brief Calculate the timeout value for this specific module / series
|
||||
(in number of symbols or units of time).
|
||||
\param timeoutUs Timeout in microseconds to listen for.
|
||||
\returns Timeout value in a unit that is specific for the used module.
|
||||
*/
|
||||
virtual RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs);
|
||||
|
||||
/*!
|
||||
\brief Convert from radio-agnostic IRQ flags to radio-specific flags.
|
||||
\param irq Radio-agnostic IRQ flags.
|
||||
\returns Flags for a specific radio module.
|
||||
*/
|
||||
uint32_t getIrqMapped(RadioLibIrqFlags_t irq);
|
||||
|
||||
/*!
|
||||
\brief Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone).
|
||||
\param irq IRQ type to check, one of RADIOLIB_IRQ_*.
|
||||
\returns 1 when requested IRQ is set, 0 when it is not or RADIOLIB_ERR_UNSUPPORTED if the IRQ is not supported.
|
||||
*/
|
||||
int16_t checkIrq(RadioLibIrqType_t irq);
|
||||
|
||||
/*!
|
||||
\brief Set interrupt on specific IRQ bit(s) (e.g. RxTimeout, CadDone).
|
||||
Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!
|
||||
\param irq Flags to set, multiple bits may be enabled. IRQ to enable corresponds to the bit index (RadioLibIrq_t).
|
||||
For example, if bit 0 is enabled, the module will enable its RADIOLIB_IRQ_TX_DONE (if it is supported).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setIrq(RadioLibIrqFlags_t irq);
|
||||
|
||||
/*!
|
||||
\brief Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).
|
||||
Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!
|
||||
\param irq Flags to set, multiple bits may be enabled. IRQ to enable corresponds to the bit index (RadioLibIrq_t).
|
||||
For example, if bit 0 is enabled, the module will enable its RADIOLIB_IRQ_TX_DONE (if it is supported).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t clearIrq(RadioLibIrqFlags_t irq);
|
||||
|
||||
/*!
|
||||
\brief Read currently active IRQ flags.
|
||||
Must be implemented in module class.
|
||||
\returns IRQ flags.
|
||||
*/
|
||||
virtual uint32_t getIrqFlags();
|
||||
|
||||
/*!
|
||||
\brief Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone).
|
||||
Must be implemented in module class.
|
||||
\param irq Module-specific IRQ flags.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setIrqFlags(uint32_t irq);
|
||||
|
||||
/*!
|
||||
\brief Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).
|
||||
Must be implemented in module class.
|
||||
\param irq Module-specific IRQ flags.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t clearIrqFlags(uint32_t irq);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven channel activity detection method. Interrupt will be activated
|
||||
when packet is detected. Must be implemented in module class.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t startChannelScan();
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven channel activity detection method. interrupt will be activated
|
||||
when packet is detected. Must be implemented in module class.
|
||||
\param config Scan configuration structure. Interpretation depends on currently active modem.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t startChannelScan(const ChannelScanConfig_t &config);
|
||||
|
||||
/*!
|
||||
\brief Read the channel scan result
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t getChannelScanResult();
|
||||
|
||||
/*!
|
||||
\brief Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules,
|
||||
or RSSI measurement for FSK modules.
|
||||
\returns RADIOLIB_CHANNEL_FREE when channel is free,
|
||||
RADIOLIB_PREAMBLE_DETECTEDwhen occupied or other \ref status_codes.
|
||||
*/
|
||||
virtual int16_t scanChannel();
|
||||
|
||||
/*!
|
||||
\brief Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules,
|
||||
or RSSI measurement for FSK modules.
|
||||
\param config Scan configuration structure. Interpretation depends on currently active modem.
|
||||
\returns RADIOLIB_CHANNEL_FREE when channel is free,
|
||||
RADIOLIB_PREAMBLE_DETECTEDwhen occupied or other \ref status_codes.
|
||||
*/
|
||||
virtual int16_t scanChannel(const ChannelScanConfig_t &config);
|
||||
|
||||
/*!
|
||||
\brief Get truly random number in range 0 - max.
|
||||
|
||||
\param max The maximum value of the random number (non-inclusive).
|
||||
|
||||
\returns Random number.
|
||||
*/
|
||||
int32_t random(int32_t max);
|
||||
|
||||
/*!
|
||||
\brief Get truly random number in range min - max.
|
||||
|
||||
\param min The minimum value of the random number (inclusive).
|
||||
|
||||
\param max The maximum value of the random number (non-inclusive).
|
||||
|
||||
\returns Random number.
|
||||
*/
|
||||
int32_t random(int32_t min, int32_t max);
|
||||
|
||||
/*!
|
||||
\brief Get one truly random byte from RSSI noise. Must be implemented in module class.
|
||||
|
||||
\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.
|
||||
|
||||
\brief Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25.
|
||||
Only available in FSK mode.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startDirect();
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
/*!
|
||||
\brief Set sync word to be used to determine start of packet in direct reception mode.
|
||||
|
||||
\param syncWord Sync word bits.
|
||||
|
||||
\param len Sync word length in bits. Set to zero to disable sync word matching.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
|
||||
|
||||
/*!
|
||||
\brief Set interrupt service routine function to call when data bit is receveid in direct mode. Must be implemented in module class.
|
||||
|
||||
\brief Set interrupt service routine function to call when data bit is received in direct mode.
|
||||
Must be implemented in module class.
|
||||
\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(uint32_t pin);
|
||||
|
||||
/*!
|
||||
\brief Get the number of direct mode bytes currently available in buffer.
|
||||
|
||||
\returns Number of available bytes.
|
||||
*/
|
||||
int16_t available();
|
||||
|
||||
/*!
|
||||
\brief Get data from direct mode buffer.
|
||||
\brief Forcefully drop synchronization.
|
||||
*/
|
||||
void dropSync();
|
||||
|
||||
/*!
|
||||
\brief Get data from direct mode buffer.
|
||||
\param drop Drop synchronization on read - next reading will require waiting for the sync word again.
|
||||
Defaults to true.
|
||||
\returns Byte from direct mode buffer.
|
||||
*/
|
||||
uint8_t read();
|
||||
uint8_t read(bool drop = true);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Configure DIO pin mapping to get a given signal on a DIO pin (if available).
|
||||
|
||||
\param pin Pin number onto which a signal is to be placed.
|
||||
|
||||
\param value The value that indicates which function to place on that pin. See chip datasheet for details.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setDIOMapping(RADIOLIB_PIN_TYPE pin, uint8_t value);
|
||||
virtual int16_t setDIOMapping(uint32_t pin, uint32_t value);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a packet is received.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
virtual void setPacketReceivedAction(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a packet is received.
|
||||
*/
|
||||
virtual void clearPacketReceivedAction();
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a packet is sent.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
virtual void setPacketSentAction(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a packet is sent.
|
||||
*/
|
||||
virtual void clearPacketSentAction();
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a channel scan is finished.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
virtual void setChannelScanAction(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a channel scan is finished.
|
||||
*/
|
||||
virtual void clearChannelScanAction();
|
||||
|
||||
#if RADIOLIB_INTERRUPT_TIMING
|
||||
|
||||
/*!
|
||||
\brief Set function to be called to set up the timing interrupt.
|
||||
For details, see https://github.com/jgromes/RadioLib/wiki/Interrupt-Based-Timing
|
||||
\param func Setup function to be called, with one argument (pulse length in microseconds).
|
||||
*/
|
||||
void setInterruptSetup(void (*func)(uint32_t));
|
||||
|
||||
/*!
|
||||
\brief Set timing interrupt flag.
|
||||
For details, see https://github.com/jgromes/RadioLib/wiki/Interrupt-Based-Timing
|
||||
*/
|
||||
void setTimerFlag();
|
||||
|
||||
#endif
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
uint32_t irqMap[10] = { 0 };
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
void updateDirectBuffer(uint8_t bit);
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
float _freqStep;
|
||||
size_t _maxPacketLength;
|
||||
float freqStep;
|
||||
size_t maxPacketLength;
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
uint8_t _bufferBitPos;
|
||||
uint8_t _bufferWritePos;
|
||||
uint8_t _bufferReadPos;
|
||||
uint8_t _buffer[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
uint32_t _syncBuffer;
|
||||
uint32_t _directSyncWord;
|
||||
uint8_t _directSyncWordLen;
|
||||
uint32_t _directSyncWordMask;
|
||||
bool _gotSync;
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
uint8_t bufferBitPos = 0;
|
||||
uint8_t bufferWritePos = 0;
|
||||
uint8_t bufferReadPos = 0;
|
||||
uint8_t buffer[RADIOLIB_STATIC_ARRAY_SIZE] = { 0 };
|
||||
uint32_t syncBuffer = 0;
|
||||
uint32_t directSyncWord = 0;
|
||||
uint8_t directSyncWordLen = 0;
|
||||
uint32_t directSyncWordMask = 0;
|
||||
bool gotSync = false;
|
||||
#endif
|
||||
|
||||
virtual Module* getMod() = 0;
|
||||
@@ -346,6 +692,10 @@ class PhysicalLayer {
|
||||
friend class SSTVClient;
|
||||
friend class AX25Client;
|
||||
friend class FSK4Client;
|
||||
friend class PagerClient;
|
||||
friend class BellClient;
|
||||
friend class FT8Client;
|
||||
friend class LoRaWANNode;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
#include "ITA2String.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
ITA2String::ITA2String(char c) {
|
||||
asciiLen = 1;
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
strAscii = new char[1];
|
||||
#endif
|
||||
strAscii[0] = c;
|
||||
ita2Len = 0;
|
||||
}
|
||||
|
||||
ITA2String::ITA2String(const char* str) {
|
||||
asciiLen = strlen(str);
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
strAscii = new char[asciiLen + 1];
|
||||
#endif
|
||||
strcpy(strAscii, str);
|
||||
ita2Len = 0;
|
||||
}
|
||||
|
||||
ITA2String::ITA2String(const ITA2String& ita2) {
|
||||
this->asciiLen = ita2.asciiLen;
|
||||
this->ita2Len = ita2.ita2Len;
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->strAscii = new char[asciiLen + 1];
|
||||
#endif
|
||||
strcpy(this->strAscii, ita2.strAscii);
|
||||
}
|
||||
|
||||
ITA2String& ITA2String::operator=(const ITA2String& ita2) {
|
||||
if(&ita2 != this) {
|
||||
this->asciiLen = ita2.asciiLen;
|
||||
this->ita2Len = ita2.ita2Len;
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->strAscii = new char[asciiLen + 1];
|
||||
#endif
|
||||
strcpy(this->strAscii, ita2.strAscii);
|
||||
}
|
||||
return(*this);
|
||||
}
|
||||
|
||||
ITA2String::~ITA2String() {
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] strAscii;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t ITA2String::length() {
|
||||
// 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) {
|
||||
// ITA2 length wasn't calculated yet, call byteArr() to calculate it
|
||||
byteArr();
|
||||
}
|
||||
|
||||
return(ita2Len);
|
||||
}
|
||||
|
||||
uint8_t* ITA2String::byteArr() {
|
||||
// create temporary array 2x the string length (figures may be 3 bytes)
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
uint8_t temp[RADIOLIB_STATIC_ARRAY_SIZE*2 + 1];
|
||||
#else
|
||||
uint8_t* temp = new uint8_t[asciiLen*2 + 1];
|
||||
#endif
|
||||
|
||||
// ensure the minimum possible array size is always initialized
|
||||
temp[0] = 0;
|
||||
|
||||
size_t arrayLen = 0;
|
||||
bool flagFigure = false;
|
||||
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
|
||||
if(shift == RADIOLIB_ITA2_FIGS) {
|
||||
// check if this is the first figure in sequence
|
||||
if(!flagFigure) {
|
||||
flagFigure = true;
|
||||
temp[arrayLen++] = RADIOLIB_ITA2_FIGS;
|
||||
}
|
||||
|
||||
// add the character code
|
||||
temp[arrayLen++] = character & 0b11111;
|
||||
|
||||
// check the following character (skip for message end)
|
||||
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
|
||||
temp[arrayLen++] = RADIOLIB_ITA2_LTRS;
|
||||
flagFigure = false;
|
||||
}
|
||||
} else {
|
||||
// reached the end of the message, terminate figure shift
|
||||
temp[arrayLen++] = RADIOLIB_ITA2_LTRS;
|
||||
flagFigure = false;
|
||||
}
|
||||
} else {
|
||||
temp[arrayLen++] = character & 0b11111;
|
||||
}
|
||||
}
|
||||
|
||||
// save ITA2 string length
|
||||
ita2Len = arrayLen;
|
||||
|
||||
uint8_t* arr = new uint8_t[arrayLen];
|
||||
memcpy(arr, temp, arrayLen);
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] temp;
|
||||
#endif
|
||||
|
||||
return(arr);
|
||||
}
|
||||
|
||||
uint16_t ITA2String::getBits(char c) {
|
||||
// search ITA2 table
|
||||
uint16_t code = 0x0000;
|
||||
for(uint8_t i = 0; i < RADIOLIB_ITA2_LENGTH; i++) {
|
||||
if(RADIOLIB_NONVOLATILE_READ_BYTE(&ITA2Table[i][0]) == c) {
|
||||
// character is in letter shift
|
||||
code = (RADIOLIB_ITA2_LTRS << 5) | i;
|
||||
break;
|
||||
} else if(RADIOLIB_NONVOLATILE_READ_BYTE(&ITA2Table[i][1]) == c) {
|
||||
// character is in figures shift
|
||||
code = (RADIOLIB_ITA2_FIGS << 5) | i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(code);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#if !defined(_RADIOLIB_ITA2_STRING_H)
|
||||
#define _RADIOLIB_ITA2_STRING_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#define RADIOLIB_ITA2_FIGS 0x1B
|
||||
#define RADIOLIB_ITA2_LTRS 0x1F
|
||||
#define RADIOLIB_ITA2_LENGTH 32
|
||||
|
||||
// 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'},
|
||||
{'\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}
|
||||
};
|
||||
|
||||
/*!
|
||||
\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);
|
||||
|
||||
/*!
|
||||
\brief Copy constructor.
|
||||
\param ita2 ITA2String instance to copy.
|
||||
*/
|
||||
ITA2String(const ITA2String& ita2);
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
\param ita2 rvalue ITA2String.
|
||||
*/
|
||||
ITA2String& operator=(const ITA2String& ita2);
|
||||
|
||||
/*!
|
||||
\brief Default destructor.
|
||||
*/
|
||||
~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!
|
||||
*/
|
||||
uint8_t* byteArr();
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
char strAscii[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
char* strAscii;
|
||||
#endif
|
||||
size_t asciiLen;
|
||||
size_t ita2Len;
|
||||
|
||||
static uint16_t getBits(char c);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,312 @@
|
||||
#include "Print.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
size_t RadioLibPrint::print(ITA2String& ita2) {
|
||||
uint8_t enc = this->encoding;
|
||||
this->encoding = RADIOLIB_ITA2;
|
||||
uint8_t* arr = ita2.byteArr();
|
||||
size_t n = write(arr, ita2.length());
|
||||
delete[] arr;
|
||||
this->encoding = enc;
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(ITA2String& ita2) {
|
||||
size_t n = RadioLibPrint::print(ita2);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::write(const uint8_t *buffer, size_t size) {
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
size_t RadioLibPrint::print(const __FlashStringHelper* fstr) {
|
||||
// read flash string length
|
||||
size_t len = 0;
|
||||
RADIOLIB_NONVOLATILE_PTR p = reinterpret_cast<RADIOLIB_NONVOLATILE_PTR>(fstr);
|
||||
while(true) {
|
||||
char c = RADIOLIB_NONVOLATILE_READ_BYTE(p++);
|
||||
len++;
|
||||
if(c == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// dynamically allocate memory
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
char str[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
char* str = new char[len];
|
||||
#endif
|
||||
|
||||
// copy string from flash
|
||||
p = reinterpret_cast<RADIOLIB_NONVOLATILE_PTR>(fstr);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
str[i] = RADIOLIB_NONVOLATILE_READ_BYTE(p + i);
|
||||
}
|
||||
|
||||
size_t n = 0;
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str);
|
||||
n = RadioLibPrint::print(ita2);
|
||||
} else {
|
||||
n = write((uint8_t*)str, len);
|
||||
}
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] str;
|
||||
#endif
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(const String& str) {
|
||||
size_t n = 0;
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str.c_str());
|
||||
n = RadioLibPrint::print(ita2);
|
||||
} else {
|
||||
n = write((uint8_t*)str.c_str(), str.length());
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(const __FlashStringHelper* fstr) {
|
||||
size_t n = RadioLibPrint::print(fstr);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(const String& str) {
|
||||
size_t n = RadioLibPrint::print(str);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t RadioLibPrint::print(const char str[]) {
|
||||
size_t n = 0;
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str);
|
||||
n = RadioLibPrint::print(ita2);
|
||||
} else {
|
||||
n = write((uint8_t*)str, strlen(str));
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(char c) {
|
||||
size_t n = 0;
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(c);
|
||||
n = RadioLibPrint::print(ita2);
|
||||
} else {
|
||||
n = write(c);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(unsigned char b, int base) {
|
||||
return(RadioLibPrint::print((unsigned long)b, base));
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(int n, int base) {
|
||||
return(RadioLibPrint::print((long)n, base));
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(unsigned int n, int base) {
|
||||
return(RadioLibPrint::print((unsigned long)n, base));
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(long n, int base) {
|
||||
if(base == 0) {
|
||||
return(write(n));
|
||||
} else if(base == DEC) {
|
||||
if (n < 0) {
|
||||
int t = RadioLibPrint::print('-');
|
||||
n = -n;
|
||||
return(RadioLibPrint::printNumber(n, DEC) + t);
|
||||
}
|
||||
return(RadioLibPrint::printNumber(n, DEC));
|
||||
} else {
|
||||
return(RadioLibPrint::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(unsigned long n, int base) {
|
||||
if(base == 0) {
|
||||
return(write(n));
|
||||
} else {
|
||||
return(RadioLibPrint::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::print(double n, int digits) {
|
||||
return(RadioLibPrint::printFloat(n, digits));
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(const char str[]) {
|
||||
size_t n = RadioLibPrint::print(str);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(char c) {
|
||||
size_t n = RadioLibPrint::print(c);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(unsigned char b, int base) {
|
||||
size_t n = RadioLibPrint::print(b, base);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(int num, int base) {
|
||||
size_t n = RadioLibPrint::print(num, base);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(unsigned int num, int base) {
|
||||
size_t n = RadioLibPrint::print(num, base);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(long num, int base) {
|
||||
size_t n = RadioLibPrint::print(num, base);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(unsigned long num, int base) {
|
||||
size_t n = RadioLibPrint::print(num, base);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(double d, int digits) {
|
||||
size_t n = RadioLibPrint::print(d, digits);
|
||||
n += RadioLibPrint::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::println(void) {
|
||||
size_t n = 0;
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String lf = ITA2String("\r\n");
|
||||
n = RadioLibPrint::print(lf);
|
||||
} else {
|
||||
n = write("\r\n");
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RadioLibPrint::printNumber(unsigned long n, uint8_t base) {
|
||||
char buf[8 * sizeof(long) + 1];
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
|
||||
if(base < 2) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
do {
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
|
||||
size_t l = 0;
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str);
|
||||
uint8_t* arr = ita2.byteArr();
|
||||
l = write(arr, ita2.length());
|
||||
delete[] arr;
|
||||
} else {
|
||||
l = write(str);
|
||||
}
|
||||
|
||||
return(l);
|
||||
}
|
||||
|
||||
/// \todo improve ITA2 float print speed (characters are sent one at a time)
|
||||
size_t RadioLibPrint::printFloat(double number, uint8_t digits) {
|
||||
size_t n = 0;
|
||||
|
||||
char code[] = {0x00, 0x00, 0x00, 0x00};
|
||||
if (isnan(number)) strcpy(code, "nan");
|
||||
if (isinf(number)) strcpy(code, "inf");
|
||||
if (number > (double)4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
if (number < (double)-4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
|
||||
if(code[0] != 0x00) {
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(code);
|
||||
uint8_t* arr = ita2.byteArr();
|
||||
n = write(arr, ita2.length());
|
||||
delete[] arr;
|
||||
return(n);
|
||||
} else {
|
||||
return(write(code));
|
||||
}
|
||||
}
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < (double)0.0) {
|
||||
if(this->encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String("-");
|
||||
uint8_t* arr = ita2.byteArr();
|
||||
n += write(arr, ita2.length());
|
||||
delete[] arr;
|
||||
} else {
|
||||
n += RadioLibPrint::print('-');
|
||||
}
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for(uint8_t i = 0; i < digits; ++i) {
|
||||
rounding /= (double)10.0;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += RadioLibPrint::print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if(digits > 0) {
|
||||
if(encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(".");
|
||||
uint8_t* arr = ita2.byteArr();
|
||||
n += write(arr, ita2.length());
|
||||
delete[] arr;
|
||||
} else {
|
||||
n += RadioLibPrint::print('.');
|
||||
}
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while(digits-- > 0) {
|
||||
remainder *= (double) 10.0;
|
||||
unsigned int toPrint = (unsigned int)(remainder);
|
||||
n += RadioLibPrint::print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#if !defined(_RADIOLIB_PRINT_H)
|
||||
#define _RADIOLIB_PRINT_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ITA2String.h"
|
||||
|
||||
// supported encoding schemes
|
||||
#define RADIOLIB_ASCII 0
|
||||
#define RADIOLIB_ASCII_EXTENDED 1
|
||||
#define RADIOLIB_ITA2 2
|
||||
|
||||
/*!
|
||||
\class RadioLibPrint
|
||||
\brief Printing class, based on Arduino Print class with additional encodings.
|
||||
*/
|
||||
class RadioLibPrint {
|
||||
public:
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write(reinterpret_cast<const uint8_t *>(str), strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write(reinterpret_cast<const uint8_t *>(buffer), size);
|
||||
}
|
||||
|
||||
size_t print(ITA2String& ita2);
|
||||
size_t println(ITA2String& ita2);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &);
|
||||
#endif
|
||||
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(void);
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
uint8_t encoding = RADIOLIB_ASCII_EXTENDED;
|
||||
const char* lineFeed = "\r\n";
|
||||
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,156 +1,37 @@
|
||||
#include "RTTY.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_RTTY)
|
||||
|
||||
ITA2String::ITA2String(char c) {
|
||||
_len = 1;
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
_str = new char[1];
|
||||
#endif
|
||||
_str[0] = c;
|
||||
_ita2Len = 0;
|
||||
}
|
||||
#include <math.h>
|
||||
|
||||
ITA2String::ITA2String(const char* str) {
|
||||
_len = strlen(str);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
_str = new char[_len + 1];
|
||||
#endif
|
||||
strcpy(_str, str);
|
||||
_ita2Len = 0;
|
||||
}
|
||||
|
||||
ITA2String::~ITA2String() {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
delete[] _str;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t ITA2String::length() {
|
||||
// length returned by this method is different than the length of ASCII-encoded _str
|
||||
// ITA2-encoded string length varies based on how many number and characters the string contains
|
||||
|
||||
if(_ita2Len == 0) {
|
||||
// ITA2 length wasn't calculated yet, call byteArr() to calculate it
|
||||
byteArr();
|
||||
}
|
||||
|
||||
return(_ita2Len);
|
||||
}
|
||||
|
||||
uint8_t* ITA2String::byteArr() {
|
||||
// create temporary array 2x the string length (figures may be 3 bytes)
|
||||
#if defined(RADIOLIB_STATIC_ONLY)
|
||||
uint8_t temp[RADIOLIB_STATIC_ARRAY_SIZE*2 + 1];
|
||||
#else
|
||||
uint8_t* temp = new uint8_t[_len*2 + 1];
|
||||
#endif
|
||||
|
||||
size_t arrayLen = 0;
|
||||
bool flagFigure = false;
|
||||
for(size_t i = 0; i < _len; i++) {
|
||||
uint16_t code = getBits(_str[i]);
|
||||
uint8_t shift = (code >> 5) & 0b11111;
|
||||
uint8_t character = code & 0b11111;
|
||||
// check if the code is letter or figure
|
||||
if(shift == RADIOLIB_ITA2_FIGS) {
|
||||
// check if this is the first figure in sequence
|
||||
if(!flagFigure) {
|
||||
flagFigure = true;
|
||||
temp[arrayLen++] = RADIOLIB_ITA2_FIGS;
|
||||
}
|
||||
|
||||
// add the character code
|
||||
temp[arrayLen++] = character & 0b11111;
|
||||
|
||||
// check the following character (skip for message end)
|
||||
if(i < (_len - 1)) {
|
||||
uint16_t nextCode = getBits(_str[i+1]);
|
||||
uint8_t nextShift = (nextCode >> 5) & 0b11111;
|
||||
if(nextShift == RADIOLIB_ITA2_LTRS) {
|
||||
// next character is a letter, terminate figure shift
|
||||
temp[arrayLen++] = RADIOLIB_ITA2_LTRS;
|
||||
flagFigure = false;
|
||||
}
|
||||
} else {
|
||||
// reached the end of the message, terminate figure shift
|
||||
temp[arrayLen++] = RADIOLIB_ITA2_LTRS;
|
||||
flagFigure = false;
|
||||
}
|
||||
} else {
|
||||
temp[arrayLen++] = character & 0b11111;
|
||||
}
|
||||
}
|
||||
|
||||
// save ITA2 string length
|
||||
_ita2Len = arrayLen;
|
||||
|
||||
uint8_t* arr = new uint8_t[arrayLen];
|
||||
memcpy(arr, temp, arrayLen);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
delete[] temp;
|
||||
#endif
|
||||
|
||||
return(arr);
|
||||
}
|
||||
|
||||
uint16_t ITA2String::getBits(char c) {
|
||||
// search ITA2 table
|
||||
uint16_t code = 0x0000;
|
||||
for(uint8_t i = 0; i < RADIOLIB_ITA2_LENGTH; i++) {
|
||||
if(RADIOLIB_NONVOLATILE_READ_BYTE(&ITA2Table[i][0]) == c) {
|
||||
// character is in letter shift
|
||||
code = (RADIOLIB_ITA2_LTRS << 5) | i;
|
||||
break;
|
||||
} else if(RADIOLIB_NONVOLATILE_READ_BYTE(&ITA2Table[i][1]) == c) {
|
||||
// character is in figures shift
|
||||
code = (RADIOLIB_ITA2_FIGS << 5) | i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(code);
|
||||
}
|
||||
#if !RADIOLIB_EXCLUDE_RTTY
|
||||
|
||||
RTTYClient::RTTYClient(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
lineFeed = "\r\n";
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audioClient = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
RTTYClient::RTTYClient(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
phyLayer = audio->phyLayer;
|
||||
lineFeed = "\r\n";
|
||||
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;
|
||||
|
||||
switch(encoding) {
|
||||
case RADIOLIB_ASCII:
|
||||
_dataBits = 7;
|
||||
break;
|
||||
case RADIOLIB_ASCII_EXTENDED:
|
||||
_dataBits = 8;
|
||||
break;
|
||||
case RADIOLIB_ITA2:
|
||||
_dataBits = 5;
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_UNSUPPORTED_ENCODING);
|
||||
}
|
||||
RadioLibPrint::encoding = enc;
|
||||
stopBitsNum = stopBits;
|
||||
baseFreqHz = base;
|
||||
shiftFreqHz = shift;
|
||||
|
||||
// calculate duration of 1 bit
|
||||
_bitDuration = (uint32_t)1000000/rate;
|
||||
bitDuration = (RadioLibTime_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) {
|
||||
@@ -159,41 +40,40 @@ 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() {
|
||||
mark();
|
||||
}
|
||||
|
||||
size_t RTTYClient::write(const char* str) {
|
||||
if(str == NULL) {
|
||||
return(0);
|
||||
}
|
||||
return(RTTYClient::write((uint8_t *)str, strlen(str)));
|
||||
}
|
||||
|
||||
size_t RTTYClient::write(uint8_t* buff, size_t len) {
|
||||
size_t n = 0;
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
n += RTTYClient::write(buff[i]);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::write(uint8_t b) {
|
||||
uint8_t dataBitsNum = 0;
|
||||
switch(RadioLibPrint::encoding) {
|
||||
case RADIOLIB_ASCII:
|
||||
dataBitsNum = 7;
|
||||
break;
|
||||
case RADIOLIB_ASCII_EXTENDED:
|
||||
dataBitsNum = 8;
|
||||
break;
|
||||
case RADIOLIB_ITA2:
|
||||
dataBitsNum = 5;
|
||||
break;
|
||||
default:
|
||||
return(0);
|
||||
}
|
||||
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();
|
||||
@@ -202,341 +82,46 @@ size_t RTTYClient::write(uint8_t b) {
|
||||
}
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < _stopBits; i++) {
|
||||
for(uint8_t i = 0; i < stopBitsNum; i++) {
|
||||
mark();
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(__FlashStringHelper* fstr) {
|
||||
// read flash string length
|
||||
size_t len = 0;
|
||||
PGM_P p = reinterpret_cast<PGM_P>(fstr);
|
||||
while(true) {
|
||||
char c = RADIOLIB_NONVOLATILE_READ_BYTE(p++);
|
||||
len++;
|
||||
if(c == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// dynamically allocate memory
|
||||
#if defined(RADIOLIB_STATIC_ONLY)
|
||||
char str[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
char* str = new char[len];
|
||||
#endif
|
||||
|
||||
// copy string from flash
|
||||
p = reinterpret_cast<PGM_P>(fstr);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
str[i] = RADIOLIB_NONVOLATILE_READ_BYTE(p + i);
|
||||
}
|
||||
|
||||
size_t n = 0;
|
||||
if(_encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str);
|
||||
n = RTTYClient::print(ita2);
|
||||
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
|
||||
n = RTTYClient::write((uint8_t*)str, len);
|
||||
}
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
delete[] str;
|
||||
#endif
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(ITA2String& ita2) {
|
||||
uint8_t* arr = ita2.byteArr();
|
||||
size_t n = RTTYClient::write(arr, ita2.length());
|
||||
delete[] arr;
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(const String& str) {
|
||||
size_t n = 0;
|
||||
if(_encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str.c_str());
|
||||
n = RTTYClient::print(ita2);
|
||||
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
|
||||
n = RTTYClient::write((uint8_t*)str.c_str(), str.length());
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(const char str[]) {
|
||||
size_t n = 0;
|
||||
if(_encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(str);
|
||||
n = RTTYClient::print(ita2);
|
||||
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
|
||||
n = RTTYClient::write((uint8_t*)str, strlen(str));
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(char c) {
|
||||
size_t n = 0;
|
||||
if(_encoding == RADIOLIB_ITA2) {
|
||||
ITA2String ita2 = ITA2String(c);
|
||||
n = RTTYClient::print(ita2);
|
||||
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
|
||||
n = RTTYClient::write(c);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(unsigned char b, int base) {
|
||||
return(RTTYClient::print((unsigned long)b, base));
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(int n, int base) {
|
||||
return(RTTYClient::print((long)n, base));
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(unsigned int n, int base) {
|
||||
return(RTTYClient::print((unsigned long)n, base));
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(long n, int base) {
|
||||
if(base == 0) {
|
||||
return(RTTYClient::write(n));
|
||||
} else if(base == DEC) {
|
||||
if (n < 0) {
|
||||
int t = RTTYClient::print('-');
|
||||
n = -n;
|
||||
return(RTTYClient::printNumber(n, DEC) + t);
|
||||
}
|
||||
return(RTTYClient::printNumber(n, DEC));
|
||||
} else {
|
||||
return(RTTYClient::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(unsigned long n, int base) {
|
||||
if(base == 0) {
|
||||
return(RTTYClient::write(n));
|
||||
} else {
|
||||
return(RTTYClient::printNumber(n, base));
|
||||
}
|
||||
}
|
||||
|
||||
size_t RTTYClient::print(double n, int digits) {
|
||||
return(RTTYClient::printFloat(n, digits));
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(void) {
|
||||
size_t n = 0;
|
||||
if(_encoding == RADIOLIB_ITA2) {
|
||||
ITA2String lf = ITA2String("\r\n");
|
||||
n = RTTYClient::print(lf);
|
||||
} else if((_encoding == RADIOLIB_ASCII) || (_encoding == RADIOLIB_ASCII_EXTENDED)) {
|
||||
n = RTTYClient::write("\r\n");
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(__FlashStringHelper* fstr) {
|
||||
size_t n = RTTYClient::print(fstr);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(ITA2String& ita2) {
|
||||
size_t n = RTTYClient::print(ita2);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(const String& str) {
|
||||
size_t n = RTTYClient::print(str);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(const char* str) {
|
||||
size_t n = RTTYClient::print(str);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(char c) {
|
||||
size_t n = RTTYClient::print(c);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(unsigned char b, int base) {
|
||||
size_t n = RTTYClient::print(b, base);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(int num, int base) {
|
||||
size_t n = RTTYClient::print(num, base);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(unsigned int num, int base) {
|
||||
size_t n = RTTYClient::print(num, base);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(long num, int base) {
|
||||
size_t n = RTTYClient::print(num, base);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(unsigned long num, int base) {
|
||||
size_t n = RTTYClient::print(num, base);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
size_t RTTYClient::println(double d, int digits) {
|
||||
size_t n = RTTYClient::print(d, digits);
|
||||
n += RTTYClient::println();
|
||||
return(n);
|
||||
}
|
||||
|
||||
void RTTYClient::mark() {
|
||||
Module* mod = _phy->getMod();
|
||||
uint32_t start = mod->micros();
|
||||
transmitDirect(_base + _shift, _baseHz + _shiftHz);
|
||||
while(mod->micros() - start < _bitDuration) {
|
||||
mod->yield();
|
||||
}
|
||||
Module* mod = phyLayer->getMod();
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
transmitDirect(baseFreq + shiftFreq, baseFreqHz + shiftFreqHz);
|
||||
mod->waitForMicroseconds(start, bitDuration);
|
||||
}
|
||||
|
||||
void RTTYClient::space() {
|
||||
Module* mod = _phy->getMod();
|
||||
uint32_t start = mod->micros();
|
||||
transmitDirect(_base, _baseHz);
|
||||
while(mod->micros() - start < _bitDuration) {
|
||||
mod->yield();
|
||||
}
|
||||
}
|
||||
|
||||
size_t RTTYClient::printNumber(unsigned long n, uint8_t base) {
|
||||
char buf[8 * sizeof(long) + 1];
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
|
||||
if(base < 2) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
do {
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
|
||||
size_t l = 0;
|
||||
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)) {
|
||||
l = RTTYClient::write(str);
|
||||
}
|
||||
|
||||
return(l);
|
||||
}
|
||||
|
||||
/// \todo improve ITA2 float print speed (characters are sent one at a time)
|
||||
size_t RTTYClient::printFloat(double number, uint8_t digits) {
|
||||
size_t n = 0;
|
||||
|
||||
char code[] = {0x00, 0x00, 0x00, 0x00};
|
||||
if (isnan(number)) strcpy(code, "nan");
|
||||
if (isinf(number)) strcpy(code, "inf");
|
||||
if (number > 4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) strcpy(code, "ovf"); // constant determined empirically
|
||||
|
||||
if(code[0] != 0x00) {
|
||||
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)) {
|
||||
return(RTTYClient::write(code));
|
||||
}
|
||||
}
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
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)) {
|
||||
n += RTTYClient::print('-');
|
||||
}
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for(uint8_t i = 0; i < digits; ++i) {
|
||||
rounding /= 10.0;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += RTTYClient::print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if(digits > 0) {
|
||||
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)) {
|
||||
n += RTTYClient::print('.');
|
||||
}
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while(digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)(remainder);
|
||||
n += RTTYClient::print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
Module* mod = phyLayer->getMod();
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
transmitDirect(baseFreq, baseFreqHz);
|
||||
mod->waitForMicroseconds(start, bitDuration);
|
||||
}
|
||||
|
||||
int16_t RTTYClient::transmitDirect(uint32_t freq, uint32_t freqHz) {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->tone(freqHz));
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->tone(freqHz));
|
||||
}
|
||||
#endif
|
||||
return(_phy->transmitDirect(freq));
|
||||
return(phyLayer->transmitDirect(freq));
|
||||
}
|
||||
|
||||
int16_t RTTYClient::standby() {
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
return(_audio->noTone());
|
||||
// ensure everything is stopped in interrupt timing mode
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->waitForMicroseconds(0, 0);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
return(audioClient->noTone());
|
||||
}
|
||||
#endif
|
||||
return(_phy->standby());
|
||||
return(phyLayer->standby());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,101 +3,28 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_RTTY)
|
||||
#if !RADIOLIB_EXCLUDE_RTTY
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
|
||||
#define RADIOLIB_ITA2_FIGS 0x1B
|
||||
#define RADIOLIB_ITA2_LTRS 0x1F
|
||||
#define RADIOLIB_ITA2_LENGTH 32
|
||||
|
||||
// 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'},
|
||||
{'\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}};
|
||||
|
||||
/*!
|
||||
\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);
|
||||
|
||||
/*!
|
||||
\brief Default destructor.
|
||||
*/
|
||||
~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!
|
||||
*/
|
||||
uint8_t* byteArr();
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
private:
|
||||
#endif
|
||||
#if defined(RADIOLIB_STATIC_ONLY)
|
||||
char _str[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
char* _str;
|
||||
#endif
|
||||
size_t _len;
|
||||
size_t _ita2Len;
|
||||
|
||||
static uint16_t getBits(char c);
|
||||
};
|
||||
|
||||
// supported encoding schemes
|
||||
#define RADIOLIB_ASCII 0
|
||||
#define RADIOLIB_ASCII_EXTENDED 1
|
||||
#define RADIOLIB_ITA2 2
|
||||
#include "../Print/Print.h"
|
||||
#include "../Print/ITA2String.h"
|
||||
|
||||
/*!
|
||||
\class RTTYClient
|
||||
|
||||
\brief Client for RTTY communication. The public interface is the same as Arduino Serial.
|
||||
*/
|
||||
class RTTYClient {
|
||||
class RTTYClient: public RadioLibPrint {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for 2-FSK mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit RTTYClient(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit RTTYClient(AFSKClient* audio);
|
||||
@@ -107,20 +34,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,61 +50,33 @@ class RTTYClient {
|
||||
|
||||
/*!
|
||||
\brief Stops transmitting.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t standby();
|
||||
|
||||
size_t write(const char* str);
|
||||
size_t write(uint8_t* buff, size_t len);
|
||||
size_t write(uint8_t b);
|
||||
/*!
|
||||
\brief Write one byte. Implementation of interface of the RadioLibPrint/Print class.
|
||||
\param b Byte to write.
|
||||
\returns 1 if the byte was written, 0 otherwise.
|
||||
*/
|
||||
size_t write(uint8_t b) override;
|
||||
|
||||
size_t print(__FlashStringHelper*);
|
||||
size_t print(ITA2String &);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
|
||||
size_t println(void);
|
||||
size_t println(__FlashStringHelper*);
|
||||
size_t println(ITA2String &);
|
||||
size_t println(const String &);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
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;
|
||||
uint32_t baseFreq = 0, baseFreqHz = 0;
|
||||
uint32_t shiftFreq = 0, shiftFreqHz = 0;
|
||||
RadioLibTime_t bitDuration = 0;
|
||||
uint8_t stopBitsNum = 0;
|
||||
|
||||
void mark();
|
||||
void space();
|
||||
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
|
||||
int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SSTV.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SSTV)
|
||||
#if !RADIOLIB_EXCLUDE_SSTV
|
||||
|
||||
const SSTVMode_t Scottie1 {
|
||||
.visCode = RADIOLIB_SSTV_SCOTTIE_1,
|
||||
@@ -8,13 +8,13 @@ const SSTVMode_t Scottie1 {
|
||||
.scanPixelLen = 432,
|
||||
.numTones = 7,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,13 +25,13 @@ const SSTVMode_t Scottie2 {
|
||||
.scanPixelLen = 275,
|
||||
.numTones = 7,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,13 +42,13 @@ const SSTVMode_t ScottieDX {
|
||||
.scanPixelLen = 1080,
|
||||
.numTones = 7,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,14 +59,14 @@ const SSTVMode_t Martin1 {
|
||||
.scanPixelLen = 458,
|
||||
.numTones = 8,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 4862, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 }
|
||||
{ .type = tone_t::GENERIC, .len = 4862, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -77,14 +77,14 @@ const SSTVMode_t Martin2 {
|
||||
.scanPixelLen = 229,
|
||||
.numTones = 8,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 4862, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 }
|
||||
{ .type = tone_t::GENERIC, .len = 4862, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 572, .freq = 1500 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -95,11 +95,11 @@ const SSTVMode_t Wrasse {
|
||||
.scanPixelLen = 734,
|
||||
.numTones = 5,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 5523, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 5523, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -110,13 +110,13 @@ const SSTVMode_t PasokonP3 {
|
||||
.scanPixelLen = 208,
|
||||
.numTones = 7,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 5208, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1042, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1042, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1042, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 5208, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1042, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1042, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1042, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -127,13 +127,13 @@ const SSTVMode_t PasokonP5 {
|
||||
.scanPixelLen = 312,
|
||||
.numTones = 7,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 7813, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1563, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1563, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1563, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 7813, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 1563, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1563, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 1563, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -144,67 +144,110 @@ const SSTVMode_t PasokonP7 {
|
||||
.scanPixelLen = 417,
|
||||
.numTones = 7,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 10417, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 2083, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 2083, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 2083, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE, .len = 0, .freq = 0 }
|
||||
{ .type = tone_t::GENERIC, .len = 10417, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 2083, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 2083, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 2083, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 }
|
||||
}
|
||||
};
|
||||
|
||||
const SSTVMode_t Robot36 {
|
||||
.visCode = RADIOLIB_SSTV_ROBOT_36,
|
||||
.width = 320,
|
||||
.height = 240,
|
||||
.scanPixelLen = 275, // this is the Y-scan length, Cb/Cr are one half
|
||||
.numTones = 6,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 3000, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 4500, .freq = 1500 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1900 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 }, // on even lines, this is the Cr component
|
||||
}
|
||||
};
|
||||
|
||||
const SSTVMode_t Robot72 {
|
||||
.visCode = RADIOLIB_SSTV_ROBOT_72,
|
||||
.width = 320,
|
||||
.height = 240,
|
||||
.scanPixelLen = 431, // this is the Y-scan length, Cb/Cr are one half
|
||||
.numTones = 9,
|
||||
.tones = {
|
||||
{ .type = tone_t::GENERIC, .len = 9000, .freq = 1200 },
|
||||
{ .type = tone_t::GENERIC, .len = 3000, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_GREEN_Y, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 4500, .freq = 1500 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1900 },
|
||||
{ .type = tone_t::SCAN_RED_CR, .len = 0, .freq = 0 },
|
||||
{ .type = tone_t::GENERIC, .len = 4500, .freq = 2300 },
|
||||
{ .type = tone_t::GENERIC, .len = 1500, .freq = 1500 },
|
||||
{ .type = tone_t::SCAN_BLUE_CB, .len = 0, .freq = 0 },
|
||||
}
|
||||
};
|
||||
|
||||
SSTVClient::SSTVClient(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audioClient = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
SSTVClient::SSTVClient(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
phyLayer = audio->phyLayer;
|
||||
audioClient = audio;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
int16_t SSTVClient::begin(const SSTVMode_t& mode, float correction) {
|
||||
if(_audio == nullptr) {
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
int16_t SSTVClient::begin(const SSTVMode_t& mode) {
|
||||
if(audioClient == nullptr) {
|
||||
// this initialization method can only be used in AFSK mode
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
return(begin(0, mode, correction));
|
||||
return(begin(0, mode));
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t SSTVClient::begin(float base, const SSTVMode_t& mode, float correction) {
|
||||
int16_t SSTVClient::begin(float base, const SSTVMode_t& mode) {
|
||||
// save mode
|
||||
_mode = mode;
|
||||
|
||||
// apply correction factor to all timings
|
||||
_mode.scanPixelLen *= correction;
|
||||
for(uint8_t i = 0; i < _mode.numTones; i++) {
|
||||
_mode.tones[i].len *= correction;
|
||||
}
|
||||
txMode = mode;
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
int16_t SSTVClient::setCorrection(float correction) {
|
||||
// check if mode is initialized
|
||||
if(txMode.visCode == 0) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// apply correction factor to all timings
|
||||
txMode.scanPixelLen *= correction;
|
||||
for(uint8_t i = 0; i < txMode.numTones; i++) {
|
||||
txMode.tones[i].len *= correction;
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
void SSTVClient::idle() {
|
||||
_phy->transmitDirect();
|
||||
phyLayer->transmitDirect();
|
||||
this->tone(RADIOLIB_SSTV_TONE_LEADER);
|
||||
}
|
||||
|
||||
void SSTVClient::sendHeader() {
|
||||
// save first header flag for Scottie modes
|
||||
_firstLine = true;
|
||||
_phy->transmitDirect();
|
||||
// reset line counter
|
||||
lineCount = 0;
|
||||
phyLayer->transmitDirect();
|
||||
|
||||
// send the first part of header (leader-break-leader)
|
||||
this->tone(RADIOLIB_SSTV_TONE_LEADER, RADIOLIB_SSTV_HEADER_LEADER_LENGTH);
|
||||
@@ -217,7 +260,7 @@ void SSTVClient::sendHeader() {
|
||||
// VIS code
|
||||
uint8_t parityCount = 0;
|
||||
for(uint8_t mask = 0x01; mask < 0x80; mask <<= 1) {
|
||||
if(_mode.visCode & mask) {
|
||||
if(txMode.visCode & mask) {
|
||||
this->tone(RADIOLIB_SSTV_TONE_VIS_1, RADIOLIB_SSTV_HEADER_BIT_LENGTH);
|
||||
parityCount++;
|
||||
} else {
|
||||
@@ -238,64 +281,96 @@ void SSTVClient::sendHeader() {
|
||||
this->tone(RADIOLIB_SSTV_TONE_BREAK, RADIOLIB_SSTV_HEADER_BIT_LENGTH);
|
||||
}
|
||||
|
||||
void SSTVClient::sendLine(uint32_t* imgLine) {
|
||||
// check first line flag in Scottie modes
|
||||
if(_firstLine && ((_mode.visCode == RADIOLIB_SSTV_SCOTTIE_1) || (_mode.visCode == RADIOLIB_SSTV_SCOTTIE_2) || (_mode.visCode == RADIOLIB_SSTV_SCOTTIE_DX))) {
|
||||
_firstLine = false;
|
||||
|
||||
void SSTVClient::sendLine(const uint32_t* imgLine) {
|
||||
// check first line in Scottie modes
|
||||
if((lineCount == 0) && ((txMode.visCode == RADIOLIB_SSTV_SCOTTIE_1) || (txMode.visCode == RADIOLIB_SSTV_SCOTTIE_2) || (txMode.visCode == RADIOLIB_SSTV_SCOTTIE_DX))) {
|
||||
// send start sync tone
|
||||
this->tone(RADIOLIB_SSTV_TONE_BREAK, 9000);
|
||||
}
|
||||
|
||||
// send all tones in sequence
|
||||
for(uint8_t i = 0; i < _mode.numTones; i++) {
|
||||
if((_mode.tones[i].type == tone_t::GENERIC) && (_mode.tones[i].len > 0)) {
|
||||
for(uint8_t i = 0; i < txMode.numTones; i++) {
|
||||
if((txMode.tones[i].type == tone_t::GENERIC) && (txMode.tones[i].len > 0)) {
|
||||
// Robot36 has different separator tones for even and odd lines
|
||||
uint32_t freq = txMode.tones[i].freq;
|
||||
if((txMode.visCode == RADIOLIB_SSTV_ROBOT_36) && (i == 3)) {
|
||||
freq = (lineCount % 2) ? 2300 : txMode.tones[3].freq;
|
||||
}
|
||||
|
||||
// sync/porch tones
|
||||
this->tone(_mode.tones[i].freq, _mode.tones[i].len);
|
||||
this->tone(freq, txMode.tones[i].len);
|
||||
|
||||
} else {
|
||||
// scan lines
|
||||
for(uint16_t j = 0; j < _mode.width; j++) {
|
||||
for(uint16_t j = 0; j < txMode.width; j++) {
|
||||
uint32_t color = imgLine[j];
|
||||
switch(_mode.tones[i].type) {
|
||||
case(tone_t::SCAN_RED):
|
||||
uint32_t len = txMode.scanPixelLen;
|
||||
|
||||
// Robot modes work in YCbCr
|
||||
if((txMode.visCode == RADIOLIB_SSTV_ROBOT_36) || (txMode.visCode == RADIOLIB_SSTV_ROBOT_72)) {
|
||||
uint8_t r = (color & 0x00FF0000) >> 16;
|
||||
uint8_t g = (color & 0x0000FF00) >> 8;
|
||||
uint8_t b = (color & 0x000000FF);
|
||||
uint8_t y = 16.0 + (0.003906 * ((65.738 * r) + (129.057 * g) + (25.064 * b)));
|
||||
uint8_t cb = 128.0 + (0.003906 * ((-37.945 * r) + (-74.494 * g) + (112.439 * b)));
|
||||
uint8_t cr = 128.0 + (0.003906 * ((112.439 * r) + (-94.154 * g) + (-18.285 * b)));
|
||||
color = ((uint32_t)y << 8);
|
||||
if(txMode.visCode == RADIOLIB_SSTV_ROBOT_36) {
|
||||
// odd lines carry Cb, even lines carry Cr
|
||||
color |= (lineCount % 2) ? cb : cr;
|
||||
} else {
|
||||
color |= ((uint32_t)cr << 16) | cb;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch(txMode.tones[i].type) {
|
||||
case(tone_t::SCAN_RED_CR):
|
||||
color &= 0x00FF0000;
|
||||
color >>= 16;
|
||||
if((txMode.visCode == RADIOLIB_SSTV_ROBOT_36) || (txMode.visCode == RADIOLIB_SSTV_ROBOT_72)) {
|
||||
len /= 2;
|
||||
}
|
||||
break;
|
||||
case(tone_t::SCAN_GREEN):
|
||||
case(tone_t::SCAN_GREEN_Y):
|
||||
color &= 0x0000FF00;
|
||||
color >>= 8;
|
||||
break;
|
||||
case(tone_t::SCAN_BLUE):
|
||||
case(tone_t::SCAN_BLUE_CB):
|
||||
color &= 0x000000FF;
|
||||
if((txMode.visCode == RADIOLIB_SSTV_ROBOT_36) || (txMode.visCode == RADIOLIB_SSTV_ROBOT_72)) {
|
||||
len /= 2;
|
||||
}
|
||||
break;
|
||||
case(tone_t::GENERIC):
|
||||
break;
|
||||
}
|
||||
this->tone(RADIOLIB_SSTV_TONE_BRIGHTNESS_MIN + ((float)color * 3.1372549), _mode.scanPixelLen);
|
||||
this->tone(RADIOLIB_SSTV_TONE_BRIGHTNESS_MIN + ((float)color * 3.1372549), len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// increment line counter (needed for Robot36 mode)
|
||||
lineCount++;
|
||||
}
|
||||
|
||||
uint16_t SSTVClient::getPictureHeight() const {
|
||||
return(_mode.height);
|
||||
return(txMode.height);
|
||||
}
|
||||
|
||||
void SSTVClient::tone(float freq, uint32_t len) {
|
||||
Module* mod = _phy->getMod();
|
||||
uint32_t start = mod->micros();
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
_audio->tone(freq, false);
|
||||
void SSTVClient::tone(float freq, RadioLibTime_t len) {
|
||||
Module* mod = phyLayer->getMod();
|
||||
RadioLibTime_t start = mod->hal->micros();
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(audioClient != nullptr) {
|
||||
audioClient->tone(freq, false);
|
||||
} else {
|
||||
_phy->transmitDirect(_base + (freq / _phy->getFreqStep()));
|
||||
phyLayer->transmitDirect(baseFreq + (freq / phyLayer->getFreqStep()));
|
||||
}
|
||||
#else
|
||||
_phy->transmitDirect(_base + (freq / _phy->getFreqStep()));
|
||||
phyLayer->transmitDirect(baseFreq + (freq / phyLayer->getFreqStep()));
|
||||
#endif
|
||||
while(mod->micros() - start < len) {
|
||||
mod->yield();
|
||||
}
|
||||
mod->waitForMicroseconds(start, len);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#if !defined(_RADIOLIB_RADIOLIB_SSTV_H)
|
||||
#define _RADIOLIB_RADIOLIB_SSTV_H
|
||||
#if !defined(_RADIOLIB_SSTV_H)
|
||||
#define _RADIOLIB_SSTV_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SSTV)
|
||||
#if !RADIOLIB_EXCLUDE_SSTV
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
@@ -21,6 +21,8 @@
|
||||
#define RADIOLIB_SSTV_PASOKON_P3 113
|
||||
#define RADIOLIB_SSTV_PASOKON_P5 114
|
||||
#define RADIOLIB_SSTV_PASOKON_P7 115
|
||||
#define RADIOLIB_SSTV_ROBOT_36 8
|
||||
#define RADIOLIB_SSTV_ROBOT_72 12
|
||||
|
||||
// SSTV tones in Hz
|
||||
#define RADIOLIB_SSTV_TONE_LEADER 1900
|
||||
@@ -37,7 +39,6 @@
|
||||
|
||||
/*!
|
||||
\struct tone_t
|
||||
|
||||
\brief Structure to save data about tone.
|
||||
*/
|
||||
struct tone_t {
|
||||
@@ -47,15 +48,15 @@ struct tone_t {
|
||||
*/
|
||||
enum {
|
||||
GENERIC = 0,
|
||||
SCAN_GREEN,
|
||||
SCAN_BLUE,
|
||||
SCAN_RED
|
||||
SCAN_GREEN_Y,
|
||||
SCAN_BLUE_CB,
|
||||
SCAN_RED_CR
|
||||
} type;
|
||||
|
||||
/*!
|
||||
\brief Length of tone in us, set to 0 for picture scan tones.
|
||||
*/
|
||||
uint32_t len;
|
||||
RadioLibTime_t len;
|
||||
|
||||
/*!
|
||||
\brief Frequency of tone in Hz, set to 0 for picture scan tones.
|
||||
@@ -65,7 +66,6 @@ struct tone_t {
|
||||
|
||||
/*!
|
||||
\struct SSTVMode_t
|
||||
|
||||
\brief Structure to save data about supported SSTV modes.
|
||||
*/
|
||||
struct SSTVMode_t {
|
||||
@@ -98,7 +98,7 @@ struct SSTVMode_t {
|
||||
/*!
|
||||
\brief Sequence of tones in each transmission line. This is used to create the correct encoding sequence.
|
||||
*/
|
||||
tone_t tones[8];
|
||||
tone_t tones[9];
|
||||
};
|
||||
|
||||
// all currently supported SSTV modes
|
||||
@@ -111,25 +111,24 @@ extern const SSTVMode_t Wrasse;
|
||||
extern const SSTVMode_t PasokonP3;
|
||||
extern const SSTVMode_t PasokonP5;
|
||||
extern const SSTVMode_t PasokonP7;
|
||||
extern const SSTVMode_t Robot36;
|
||||
extern const SSTVMode_t Robot72;
|
||||
|
||||
/*!
|
||||
\class SSTVClient
|
||||
|
||||
\brief Client for SSTV transmissions.
|
||||
*/
|
||||
class SSTVClient {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for 2-FSK mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit SSTVClient(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit SSTVClient(AFSKClient* audio);
|
||||
@@ -139,30 +138,33 @@ class SSTVClient {
|
||||
|
||||
/*!
|
||||
\brief Initialization method for 2-FSK.
|
||||
|
||||
\param base Base "0 Hz tone" RF frequency to be used in MHz.
|
||||
|
||||
\param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7.
|
||||
|
||||
\param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction).
|
||||
|
||||
\param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2,
|
||||
ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7,
|
||||
Robot36 and Robot37.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float base, const SSTVMode_t& mode, float correction = 1.0);
|
||||
int16_t begin(float base, const SSTVMode_t& mode);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Initialization method for AFSK.
|
||||
|
||||
\param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2, ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7.
|
||||
|
||||
\param correction Timing correction factor, used to adjust the length of timing pulses. Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction).
|
||||
|
||||
\param mode SSTV mode to be used. Currently supported modes are Scottie1, Scottie2,
|
||||
ScottieDX, Martin1, Martin2, Wrasse, PasokonP3, PasokonP5 and PasokonP7,
|
||||
Robot36 and Robot37.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(const SSTVMode_t& mode, float correction = 1.0);
|
||||
int16_t begin(const SSTVMode_t& mode);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Set correction coefficient for tone length.
|
||||
\param correction Timing correction factor, used to adjust the length of timing pulses.
|
||||
Less than 1.0 leads to shorter timing pulses, defaults to 1.0 (no correction).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCorrection(float correction);
|
||||
|
||||
/*!
|
||||
\brief Sends out tone at 1900 Hz.
|
||||
*/
|
||||
@@ -175,31 +177,30 @@ class SSTVClient {
|
||||
|
||||
/*!
|
||||
\brief Sends single picture line in the currently configured SSTV mode.
|
||||
|
||||
\param imgLine Image line to send, in 24-bit RGB. It is up to the user to ensure that imgLine has enough pixels to send it in the current SSTV mode.
|
||||
\param imgLine Image line to send, in 24-bit RGB. It is up to the user to ensure that
|
||||
imgLine has enough pixels to send it in the current SSTV mode.
|
||||
*/
|
||||
void sendLine(uint32_t* imgLine);
|
||||
void sendLine(const uint32_t* imgLine);
|
||||
|
||||
/*!
|
||||
\brief Get picture height of the currently configured SSTV mode.
|
||||
|
||||
\returns Picture height of the currently configured SSTV mode in pixels.
|
||||
*/
|
||||
uint16_t getPictureHeight() const;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AFSKClient* audioClient;
|
||||
#endif
|
||||
|
||||
uint32_t _base = 0;
|
||||
SSTVMode_t _mode = Scottie1;
|
||||
bool _firstLine = true;
|
||||
uint32_t baseFreq = 0;
|
||||
SSTVMode_t txMode = Scottie1;
|
||||
uint32_t lineCount = 0;
|
||||
|
||||
void tone(float freq, uint32_t len = 0);
|
||||
void tone(float freq, RadioLibTime_t len = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user