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 ITA2_FIGS 0x1B
12 #define ITA2_LTRS 0x1F
13 #define 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[ITA2_LENGTH][2] RADIOLIB_PROGMEM = {{'\0', '\0'}, {'E', '3'}, {'\n', '\n'}, {'A', '-'}, {' ', ' '}, {'S', '\''}, {'I', '8'}, {'U', '7'},
19  {'\r', '\r'}, {'D', 0x05}, {'R', '4'}, {'J', '\a'}, {'N', ','}, {'F', '!'}, {'C', ':'}, {'K', '('},
20  {'T', '5'}, {'Z', '+'}, {'L', ')'}, {'W', '2'}, {'H', 0x7F}, {'Y', '6'}, {'P', '0'}, {'Q', '1'},
21  {'O', '9'}, {'B', '?'}, {'G', '&'}, {0x7F, 0x7F}, {'M', '.'}, {'X', '/'}, {'V', ';'}, {0x7F, 0x7F}};
22 
28 class ITA2String {
29  public:
35  explicit ITA2String(char c);
36 
42  explicit ITA2String(const char* str);
43 
47  ~ITA2String();
48 
54  size_t length();
55 
62  uint8_t* byteArr();
63 
64 #ifndef RADIOLIB_GODMODE
65  private:
66 #endif
67  #ifdef RADIOLIB_STATIC_ONLY
68  char _str[RADIOLIB_STATIC_ARRAY_SIZE];
69  #else
70  char* _str;
71  #endif
72  size_t _len;
73  size_t _ita2Len;
74 
75  static uint16_t getBits(char c);
76 };
77 
78 // supported encoding schemes
79 #define ASCII 0
80 #define ASCII_EXTENDED 1
81 #define ITA2 2
82 
88 class RTTYClient {
89  public:
95  explicit RTTYClient(PhysicalLayer* phy);
96 
97  #if !defined(RADIOLIB_EXCLUDE_AFSK)
98 
103  explicit RTTYClient(AFSKClient* audio);
104  #endif
105 
106  // basic methods
107 
123  int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding = ASCII, uint8_t stopBits = 1);
124 
128  void idle();
129 
130  size_t write(const char* str);
131  size_t write(uint8_t* buff, size_t len);
132  size_t write(uint8_t b);
133 
134  size_t print(__FlashStringHelper*);
135  size_t print(ITA2String &);
136  size_t print(const String &);
137  size_t print(const char[]);
138  size_t print(char);
139  size_t print(unsigned char, int = DEC);
140  size_t print(int, int = DEC);
141  size_t print(unsigned int, int = DEC);
142  size_t print(long, int = DEC);
143  size_t print(unsigned long, int = DEC);
144  size_t print(double, int = 2);
145 
146  size_t println(void);
147  size_t println(__FlashStringHelper*);
148  size_t println(ITA2String &);
149  size_t println(const String &);
150  size_t println(const char[]);
151  size_t println(char);
152  size_t println(unsigned char, int = DEC);
153  size_t println(int, int = DEC);
154  size_t println(unsigned int, int = DEC);
155  size_t println(long, int = DEC);
156  size_t println(unsigned long, int = DEC);
157  size_t println(double, int = 2);
158 
159 #ifndef RADIOLIB_GODMODE
160  private:
161 #endif
162  PhysicalLayer* _phy;
163  #if !defined(RADIOLIB_EXCLUDE_AFSK)
164  AFSKClient* _audio;
165  #endif
166 
167  uint8_t _encoding = ASCII;
168  uint32_t _base = 0, _baseHz = 0;
169  uint32_t _shift = 0, _shiftHz = 0;
170  uint32_t _bitDuration = 0;
171  uint8_t _dataBits = 0;
172  uint8_t _stopBits = 0;
173 
174  void mark();
175  void space();
176 
177  size_t printNumber(unsigned long, uint8_t);
178  size_t printFloat(double, uint8_t);
179 
180  int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
181  int16_t standby();
182 };
183 
184 #endif
185 
186 #endif
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:24
RTTYClient::idle
void idle()
Send out idle condition (RF tone at mark frequency).
Definition: RTTY.cpp:170
AFSKClient
Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direc...
Definition: AFSK.h:17
ITA2String::ITA2String
ITA2String(char c)
Default single-character constructor.
Definition: RTTY.cpp:4
ITA2String::~ITA2String
~ITA2String()
Default destructor.
Definition: RTTY.cpp:18
ITA2String
ITA2-encoded string.
Definition: RTTY.h:28
ITA2String::byteArr
uint8_t * byteArr()
Gets the ITA2 representation of the ASCII string set in constructor.
Definition: RTTY.cpp:36
RTTYClient::RTTYClient
RTTYClient(PhysicalLayer *phy)
Constructor for 2-FSK mode.
Definition: RTTY.cpp:110
RTTYClient::begin
int16_t begin(float base, uint32_t shift, uint16_t rate, uint8_t encoding=ASCII, uint8_t stopBits=1)
Initialization method.
Definition: RTTY.cpp:124
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:14
RTTYClient
Client for RTTY communication. The public interface is the same as Arduino Serial.
Definition: RTTY.h:88