RadioLib Universal wireless communication library for Arduino

Morse.h
1 #if !defined(_RADIOLIB_MORSE_H) && !RADIOLIB_EXCLUDE_MORSE
2 #define _RADIOLIB_MORSE_H
3
4 #include "../../TypeDef.h"
5 #include "../PhysicalLayer/PhysicalLayer.h"
6 #include "../AFSK/AFSK.h"
7 #include "../Print/Print.h"
8
9 #define RADIOLIB_MORSE_DOT 0b0
10 #define RADIOLIB_MORSE_DASH 0b1
11 #define RADIOLIB_MORSE_GUARDBIT 0b1
12 #define RADIOLIB_MORSE_UNSUPPORTED 0xFF
13 #define RADIOLIB_MORSE_ASCII_OFFSET 32
14 #define RADIOLIB_MORSE_INTER_SYMBOL 0x00
15 #define RADIOLIB_MORSE_CHAR_COMPLETE 0x01
16 #define RADIOLIB_MORSE_WORD_COMPLETE 0x02
17
18 // Morse character table: - using codes defined in ITU-R M.1677-1
19 // - Morse code representation is saved LSb first, using additional bit as guard
20 // - position in array corresponds ASCII code minus RADIOLIB_MORSE_ASCII_OFFSET
21 // - ASCII characters marked RADIOLIB_MORSE_UNSUPPORTED do not have ITU-R M.1677-1 equivalent
22 static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
23 0b00, // space
24 0b110101, // ! (unsupported)
25 0b1010010, // "
26 RADIOLIB_MORSE_UNSUPPORTED, // # (unsupported)
27 RADIOLIB_MORSE_UNSUPPORTED, // $ (unsupported)
28 RADIOLIB_MORSE_UNSUPPORTED, // % (unsupported)
29 RADIOLIB_MORSE_UNSUPPORTED, // & (unsupported)
30 0b1011110, // '
31 0b101101, // (
32 0b1101101, // )
33 RADIOLIB_MORSE_UNSUPPORTED, // * (unsupported)
34 0b101010, // +
35 0b1110011, // ,
36 0b1100001, // -
37 0b1101010, // .
38 0b101001, // /
39 0b111111, // 0
40 0b111110, // 1
41 0b111100, // 2
42 0b111000, // 3
43 0b110000, // 4
44 0b100000, // 5
45 0b100001, // 6
46 0b100011, // 7
47 0b100111, // 8
48 0b101111, // 9
49 0b1000111, // :
50 RADIOLIB_MORSE_UNSUPPORTED, // ; (unsupported)
51 RADIOLIB_MORSE_UNSUPPORTED, // < (unsupported)
52 0b110001, // =
53 RADIOLIB_MORSE_UNSUPPORTED, // > (unsupported)
54 0b1001100, // ?
55 0b1010110, // @
56 0b110, // A
57 0b10001, // B
58 0b10101, // C
59 0b1001, // D
60 0b10, // E
61 0b10100, // F
62 0b1011, // G
63 0b10000, // H
64 0b100, // I
65 0b11110, // J
66 0b1101, // K
67 0b10010, // L
68 0b111, // M
69 0b101, // N
70 0b1111, // O
71 0b10110, // P
72 0b11011, // Q
73 0b1010, // R
74 0b1000, // S
75 0b11, // T
76 0b1100, // U
77 0b11000, // V
78 0b1110, // W
79 0b11001, // X
80 0b11101, // Y
81 0b10011, // Z
82 RADIOLIB_MORSE_UNSUPPORTED, // [ (unsupported)
83 RADIOLIB_MORSE_UNSUPPORTED, // \ (unsupported)
84 RADIOLIB_MORSE_UNSUPPORTED, // ] (unsupported)
85 0b1101000, // ^ (unsupported, used as alias for end of work)
86 0b110101 // _ (unsupported, used as alias for starting signal)
87 };
88
93 class MorseClient: public RadioLibPrint {
94 public:
99 explicit MorseClient(PhysicalLayer* phy);
100
101 #if !RADIOLIB_EXCLUDE_AFSK
106 explicit MorseClient(AFSKClient* audio);
107 #endif
108
109 // basic methods
110
117 int16_t begin(float base, uint8_t speed = 20);
118
123 size_t startSignal();
124
131 static char decode(uint8_t symbol, uint8_t len);
132
142 #if !RADIOLIB_EXCLUDE_AFSK
143 int read(uint8_t* symbol, uint8_t* len, float low = 0.75f, float high = 1.25f);
144 #endif
145
151 size_t write(uint8_t b);
152
153 #if !RADIOLIB_GODMODE
154 private:
155 #endif
156 PhysicalLayer* phyLayer;
157 #if !RADIOLIB_EXCLUDE_AFSK
158 AFSKClient* audioClient;
159 #endif
160
161 uint32_t baseFreq = 0, baseFreqHz = 0;
162 float basePeriod = 0.0f;
163 uint32_t dotLength = 0;
164 uint32_t dashLength = 0;
165 uint32_t letterSpace = 0;
166 uint16_t wordSpace = 0;
167
168 // variables to keep decoding state
169 uint32_t signalCounter = 0;
170 uint32_t signalStart = 0;
171 uint32_t pauseCounter = 0;
172 uint32_t pauseStart = 0;
173
174 size_t printNumber(unsigned long, uint8_t);
175 size_t printFloat(double, uint8_t);
176
177 int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
178 int16_t standby();
179 };
180
181 #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:93
MorseClient::startSignal
size_t startSignal()
Send start signal.
Definition: Morse.cpp:41
MorseClient::begin
int16_t begin(float base, uint8_t speed=20)
Initialization method.
Definition: Morse.cpp:23
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:63
MorseClient::decode
static char decode(uint8_t symbol, uint8_t len)
Decode Morse symbol to ASCII.
Definition: Morse.cpp:45
MorseClient::write
size_t write(uint8_t b)
Write one byte. Implementation of interface of the RadioLibPrint/Print class.
Definition: Morse.cpp:115
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:54
RadioLibPrint
Printing class, based on Arduino Print class with additional encodings.
Definition: Print.h:17