RadioLib Universal wireless communication library for Arduino

RTTY.h
1 #if !defined(_RADIOLIB_RTTY_H)
2 #define _RADIOLIB_RTTY_H
3
4 #include "../../TypeDef.h"
5
6 #if !defined(RADIOLIB_EXCLUDE_RTTY)
7
8 #include "../PhysicalLayer/PhysicalLayer.h"
9 #include "../AFSK/AFSK.h"
10
11 #define RADIOLIB_ITA2_FIGS 0x1B
12 #define RADIOLIB_ITA2_LTRS 0x1F
13 #define RADIOLIB_ITA2_LENGTH 32
14
15 // ITA2 character table: - position in array corresponds to 5-bit ITA2 code
16 // - characters to the left are in letters shift, characters to the right in figures shift
17 // - characters marked 0x7F do not have ASCII equivalent
18 static const char ITA2Table[RADIOLIB_ITA2_LENGTH][2] RADIOLIB_NONVOLATILE = {
19 {'\0', '\0'}, {'E', '3'}, {'\n', '\n'}, {'A', '-'}, {' ', ' '}, {'S', '\''}, {'I', '8'}, {'U', '7'},
20 {'\r', '\r'}, {'D', 0x05}, {'R', '4'}, {'J', '\a'}, {'N', ','}, {'F', '!'}, {'C', ':'}, {'K', '('},
21 {'T', '5'}, {'Z', '+'}, {'L', ')'}, {'W', '2'}, {'H', 0x7F}, {'Y', '6'}, {'P', '0'}, {'Q', '1'},
22 {'O', '9'}, {'B', '?'}, {'G', '&'}, {0x7F, 0x7F}, {'M', '.'}, {'X', '/'}, {'V', ';'}, {0x7F, 0x7F}
23 };
24
29 class ITA2String {
30 public:
35 explicit ITA2String(char c);
36
41 explicit ITA2String(const char* str);
42
46 ~ITA2String();
47
52 size_t length();
53
59 uint8_t* byteArr();
60
61 #if !defined(RADIOLIB_GODMODE)
62 private:
63 #endif
64 #if defined(RADIOLIB_STATIC_ONLY)
65 char strAscii[RADIOLIB_STATIC_ARRAY_SIZE];
66 #else
67 char* strAscii;
68 #endif
69 size_t asciiLen;
70 size_t ita2Len;
71
72 static uint16_t getBits(char c);
73 };
74
75 // supported encoding schemes
76 #define RADIOLIB_ASCII 0
77 #define RADIOLIB_ASCII_EXTENDED 1
78 #define RADIOLIB_ITA2 2
79
84 class RTTYClient {
85 public:
90 explicit RTTYClient(PhysicalLayer* phy);
91
92 #if !defined(RADIOLIB_EXCLUDE_AFSK)
97 explicit RTTYClient(AFSKClient* audio);
98 #endif
99
100 // basic methods
101
111 int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t enc = RADIOLIB_ASCII, uint8_t stopBits = 1);
112
116 void idle();
117
122 int16_t standby();
123
124 size_t write(const char* str);
125 size_t write(uint8_t* buff, size_t len);
126 size_t write(uint8_t b);
127
128 #if defined(RADIOLIB_BUILD_ARDUINO)
129 size_t print(__FlashStringHelper*);
130 size_t print(const String &);
131 #endif
132 size_t print(ITA2String &);
133 size_t print(const char[]);
134 size_t print(char);
135 size_t print(unsigned char, int = DEC);
136 size_t print(int, int = DEC);
137 size_t print(unsigned int, int = DEC);
138 size_t print(long, int = DEC);
139 size_t print(unsigned long, int = DEC);
140 size_t print(double, int = 2);
141
142 size_t println(void);
143 #if defined(RADIOLIB_BUILD_ARDUINO)
144 size_t println(__FlashStringHelper*);
145 size_t println(const String &);
146 #endif
147 size_t println(ITA2String &);
148 size_t println(const char[]);
149 size_t println(char);
150 size_t println(unsigned char, int = DEC);
151 size_t println(int, int = DEC);
152 size_t println(unsigned int, int = DEC);
153 size_t println(long, int = DEC);
154 size_t println(unsigned long, int = DEC);
155 size_t println(double, int = 2);
156
157 #if !defined(RADIOLIB_GODMODE)
158 private:
159 #endif
160 PhysicalLayer* phyLayer;
161 #if !defined(RADIOLIB_EXCLUDE_AFSK)
162 AFSKClient* audioClient;
163 #endif
164
165 uint8_t encoding = RADIOLIB_ASCII;
166 uint32_t baseFreq = 0, baseFreqHz = 0;
167 uint32_t shiftFreq = 0, shiftFreqHz = 0;
168 uint32_t bitDuration = 0;
169 uint8_t dataBitsNum = 0;
170 uint8_t stopBitsNum = 0;
171
172 void mark();
173 void space();
174
175 size_t printNumber(unsigned long, uint8_t);
176 size_t printFloat(double, uint8_t);
177
178 int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
179 };
180
181 #endif
182
183 #endif
AFSKClient
Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direc...
Definition: AFSK.h:16
ITA2String
ITA2-encoded string.
Definition: RTTY.h:29
ITA2String::byteArr
uint8_t * byteArr()
Gets the ITA2 representation of the ASCII string set in constructor.
Definition: RTTY.cpp:42
ITA2String::length
size_t length()
Gets the length of the ITA2 string. This number is not the same as the length of ASCII-encoded string...
Definition: RTTY.cpp:30
ITA2String::ITA2String
ITA2String(char c)
Default single-character constructor.
Definition: RTTY.cpp:6
ITA2String::~ITA2String
~ITA2String()
Default destructor.
Definition: RTTY.cpp:24
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:15
RTTYClient
Client for RTTY communication. The public interface is the same as Arduino Serial.
Definition: RTTY.h:84
RTTYClient::standby
int16_t standby()
Stops transmitting.
Definition: RTTY.cpp:535
RTTYClient::idle
void idle()
Send out idle condition (RF tone at mark frequency).
Definition: RTTY.cpp:176
RTTYClient::begin
int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t enc=RADIOLIB_ASCII, uint8_t stopBits=1)
Initialization method.
Definition: RTTY.cpp:130
RTTYClient::RTTYClient
RTTYClient(PhysicalLayer *phy)
Constructor for 2-FSK mode.
Definition: RTTY.cpp:116