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