RadioLib Universal wireless communication library for Arduino

Morse.h
1 #if !defined(_RADIOLIB_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE)
2 #define _RADIOLIB_RADIOLIB_MORSE_H
3
4 #include "../../TypeDef.h"
5 #include "../PhysicalLayer/PhysicalLayer.h"
6 #include "../AFSK/AFSK.h"
7
8 #define RADIOLIB_MORSE_DOT 0b0
9 #define RADIOLIB_MORSE_DASH 0b1
10 #define RADIOLIB_MORSE_GUARDBIT 0b1
11 #define RADIOLIB_MORSE_UNSUPORTED 0xFF
12 #define RADIOLIB_MORSE_ASCII_OFFSET 32
13 #define RADIOLIB_MORSE_INTER_SYMBOL 0x00
14 #define RADIOLIB_MORSE_CHAR_COMPLETE 0x01
15 #define RADIOLIB_MORSE_WORD_COMPLETE 0x02
16
17 // Morse character table: - using codes defined in ITU-R M.1677-1
18 // - Morse code representation is saved LSb first, using additional bit as guard
19 // - position in array corresponds ASCII code minus RADIOLIB_MORSE_ASCII_OFFSET
20 // - ASCII characters marked RADIOLIB_MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent
21 static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
22 0b00, // space
23 0b110101, // ! (unsupported)
24 0b1010010, // "
25 RADIOLIB_MORSE_UNSUPORTED, // # (unsupported)
26 RADIOLIB_MORSE_UNSUPORTED, // $ (unsupported)
27 RADIOLIB_MORSE_UNSUPORTED, // % (unsupported)
28 RADIOLIB_MORSE_UNSUPORTED, // & (unsupported)
29 0b1011110, // '
30 0b101101, // (
31 0b1101101, // )
32 RADIOLIB_MORSE_UNSUPORTED, // * (unsupported)
33 0b101010, // +
34 0b1110011, // ,
35 0b1100001, // -
36 0b1101010, // .
37 0b101001, // /
38 0b111111, // 0
39 0b111110, // 1
40 0b111100, // 2
41 0b111000, // 3
42 0b110000, // 4
43 0b100000, // 5
44 0b100001, // 6
45 0b100011, // 7
46 0b100111, // 8
47 0b101111, // 9
48 0b1000111, // :
49 RADIOLIB_MORSE_UNSUPORTED, // ; (unsupported)
50 RADIOLIB_MORSE_UNSUPORTED, // < (unsupported)
51 0b110001, // =
52 RADIOLIB_MORSE_UNSUPORTED, // > (unsupported)
53 0b1001100, // ?
54 0b1010110, // @
55 0b110, // A
56 0b10001, // B
57 0b10101, // C
58 0b1001, // D
59 0b10, // E
60 0b10100, // F
61 0b1011, // G
62 0b10000, // H
63 0b100, // I
64 0b11110, // J
65 0b1101, // K
66 0b10010, // L
67 0b111, // M
68 0b101, // N
69 0b1111, // O
70 0b10110, // P
71 0b11011, // Q
72 0b1010, // R
73 0b1000, // S
74 0b11, // T
75 0b1100, // U
76 0b11000, // V
77 0b1110, // W
78 0b11001, // X
79 0b11101, // Y
80 0b10011, // Z
81 RADIOLIB_MORSE_UNSUPORTED, // [ (unsupported)
82 RADIOLIB_MORSE_UNSUPORTED, // \ (unsupported)
83 RADIOLIB_MORSE_UNSUPORTED, // ] (unsupported)
84 0b1101000, // ^ (unsupported, used as alias for end of work)
85 0b110101 // _ (unsupported, used as alias for starting signal)
86 };
87
92 class MorseClient {
93 public:
98 explicit MorseClient(PhysicalLayer* phy);
99
100 #if !defined(RADIOLIB_EXCLUDE_AFSK)
105 explicit MorseClient(AFSKClient* audio);
106 #endif
107
108 // basic methods
109
116 int16_t begin(float base, uint8_t speed = 20);
117
122 size_t startSignal();
123
130 static char decode(uint8_t symbol, uint8_t len);
131
141 #if !defined(RADIOLIB_EXCLUDE_AFSK)
142 int read(uint8_t* symbol, uint8_t* len, float low = 0.75f, float high = 1.25f);
143 #endif
144
145 size_t write(const char* str);
146 size_t write(uint8_t* buff, size_t len);
147 size_t write(uint8_t b);
148
149 #if defined(RADIOLIB_BUILD_ARDUINO)
150 size_t print(__FlashStringHelper*);
151 size_t print(const String &);
152 #endif
153 size_t print(const char[]);
154 size_t print(char);
155 size_t print(unsigned char, int = DEC);
156 size_t print(int, int = DEC);
157 size_t print(unsigned int, int = DEC);
158 size_t print(long, int = DEC);
159 size_t print(unsigned long, int = DEC);
160 size_t print(double, int = 2);
161
162 size_t println(void);
163 #if defined(RADIOLIB_BUILD_ARDUINO)
164 size_t println(__FlashStringHelper*);
165 size_t println(const String &);
166 #endif
167 size_t println(const char[]);
168 size_t println(char);
169 size_t println(unsigned char, int = DEC);
170 size_t println(int, int = DEC);
171 size_t println(unsigned int, int = DEC);
172 size_t println(long, int = DEC);
173 size_t println(unsigned long, int = DEC);
174 size_t println(double, int = 2);
175
176 #if !defined(RADIOLIB_GODMODE)
177 private:
178 #endif
179 PhysicalLayer* phyLayer;
180 #if !defined(RADIOLIB_EXCLUDE_AFSK)
181 AFSKClient* audioClient;
182 #endif
183
184 uint32_t baseFreq = 0, baseFreqHz = 0;
185 float basePeriod = 0.0f;
186 uint32_t dotLength = 0;
187 uint32_t dashLength = 0;
188 uint32_t letterSpace = 0;
189 uint16_t wordSpace = 0;
190
191 // variables to keep decoding state
192 uint32_t signalCounter = 0;
193 uint32_t signalStart = 0;
194 uint32_t pauseCounter = 0;
195 uint32_t pauseStart = 0;
196
197 size_t printNumber(unsigned long, uint8_t);
198 size_t printFloat(double, uint8_t);
199
200 int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
201 int16_t standby();
202 };
203
204 #endif
AFSKClient
Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direc...
Definition: AFSK.h:16
MorseClient
Client for Morse Code communication. The public interface is the same as Arduino Serial.
Definition: Morse.h:92
MorseClient::startSignal
size_t startSignal()
Send start signal.
Definition: Morse.cpp:39
MorseClient::begin
int16_t begin(float base, uint8_t speed=20)
Initialization method.
Definition: Morse.cpp:21
MorseClient::read
int read(uint8_t *symbol, uint8_t *len, float low=0.75f, float high=1.25f)
Read Morse tone on input pin.
Definition: Morse.cpp:61
MorseClient::decode
static char decode(uint8_t symbol, uint8_t len)
Decode Morse symbol to ASCII.
Definition: Morse.cpp:43
MorseClient::MorseClient
MorseClient(PhysicalLayer *phy)
Constructor for 2-FSK mode.
Definition: Morse.cpp:7
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:15