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 
93 class MorseClient {
94  public:
100  explicit MorseClient(PhysicalLayer* phy);
101 
102  #if !defined(RADIOLIB_EXCLUDE_AFSK)
103 
108  explicit MorseClient(AFSKClient* audio);
109  #endif
110 
111  // basic methods
112 
122  int16_t begin(float base, uint8_t speed = 20);
123 
129  size_t startSignal();
130 
140  static char decode(uint8_t symbol, uint8_t len);
141 
155  #if !defined(RADIOLIB_EXCLUDE_AFSK)
156  int read(byte* symbol, byte* len, float low = 0.75f, float high = 1.25f);
157  #endif
158 
159  size_t write(const char* str);
160  size_t write(uint8_t* buff, size_t len);
161  size_t write(uint8_t b);
162 
163  size_t print(__FlashStringHelper*);
164  size_t print(const String &);
165  size_t print(const char[]);
166  size_t print(char);
167  size_t print(unsigned char, int = DEC);
168  size_t print(int, int = DEC);
169  size_t print(unsigned int, int = DEC);
170  size_t print(long, int = DEC);
171  size_t print(unsigned long, int = DEC);
172  size_t print(double, int = 2);
173 
174  size_t println(void);
175  size_t println(__FlashStringHelper*);
176  size_t println(const String &);
177  size_t println(const char[]);
178  size_t println(char);
179  size_t println(unsigned char, int = DEC);
180  size_t println(int, int = DEC);
181  size_t println(unsigned int, int = DEC);
182  size_t println(long, int = DEC);
183  size_t println(unsigned long, int = DEC);
184  size_t println(double, int = 2);
185 
186 #if !defined(RADIOLIB_GODMODE)
187  private:
188 #endif
189  PhysicalLayer* _phy;
190  #if !defined(RADIOLIB_EXCLUDE_AFSK)
191  AFSKClient* _audio;
192  #endif
193 
194  uint32_t _base = 0, _baseHz = 0;
195  float _basePeriod = 0.0f;
196  uint16_t _dotLength = 0;
197  uint16_t _dashLength = 0;
198  uint16_t _letterSpace = 0;
199  uint16_t _wordSpace = 0;
200 
201  // variables to keep decoding state
202  uint32_t signalCounter = 0;
203  uint32_t signalStart = 0;
204  uint32_t pauseCounter = 0;
205  uint32_t pauseStart = 0;
206 
207  size_t printNumber(unsigned long, uint8_t);
208  size_t printFloat(double, uint8_t);
209 
210  int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0);
211  int16_t standby();
212 };
213 
214 #endif
AFSKClient
Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direc...
Definition: AFSK.h:17
MorseClient::read
int read(byte *symbol, byte *len, float low=0.75f, float high=1.25f)
Read Morse tone on input pin.
Definition: Morse.cpp:58
MorseClient
Client for Morse Code communication. The public interface is the same as Arduino Serial.
Definition: Morse.h:93
MorseClient::MorseClient
MorseClient(PhysicalLayer *phy)
Constructor for 2-FSK mode.
Definition: Morse.cpp:4
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:14
MorseClient::decode
static char decode(uint8_t symbol, uint8_t len)
Decode Morse symbol to ASCII.
Definition: Morse.cpp:40
MorseClient::begin
int16_t begin(float base, uint8_t speed=20)
Initialization method.
Definition: Morse.cpp:18
MorseClient::startSignal
size_t startSignal()
Send start signal.
Definition: Morse.cpp:36