Reorganized morsecode symbols array and updated the MorseClient::write(uint8_t b) method
The whole idea was taken from the CubeSat way of doing morsecode,
This commit is contained in:
parent
444800ea08
commit
4272b0ff30
2 changed files with 107 additions and 104 deletions
|
@ -4,68 +4,79 @@
|
||||||
/*!
|
/*!
|
||||||
\cond RADIOLIB_DOXYGEN_HIDDEN
|
\cond RADIOLIB_DOXYGEN_HIDDEN
|
||||||
*/
|
*/
|
||||||
struct Morse_t {
|
|
||||||
char c; // ASCII character
|
|
||||||
char m[7]; // Morse code representation
|
|
||||||
};
|
|
||||||
/*!
|
|
||||||
\endcond
|
|
||||||
*/
|
|
||||||
|
|
||||||
// array of all Morse code characters
|
//----------------------------------------------------------------------------------------
|
||||||
const Morse_t MorseTable[MORSE_LENGTH] PROGMEM = {
|
// In the below array we represent dots as 0 and dashes as 1, using a further bit as
|
||||||
{'A', ".-"},
|
// 'guard' who tell us when we must stop in decoding our symbols.
|
||||||
{'B',"-..."},
|
// Some bytes are zeroed because there isn't a morse code representation of that char.
|
||||||
{'C', "-.-."},
|
// The ascii code of the letter is the search index into the array for the correspondent
|
||||||
{'D',"-.."},
|
// morse code representation.
|
||||||
{'E',"."},
|
//----------------------------------------------------------------------------------------
|
||||||
{'F',"..-."},
|
const uint8_t morse_lookuptable[64] PROGMEM = {
|
||||||
{'G',"--."},
|
0b00, // space 0x00
|
||||||
{'H',"...."},
|
0b1110101, // ! 117
|
||||||
{'I',".."},
|
0b1010010, // " 82
|
||||||
{'J',".---"},
|
0b00, // # (doesn't exists)<--
|
||||||
{'K',"-.-"},
|
0b11001000, // $ 200
|
||||||
{'L',".-.."},
|
0b00, // % (doesn't exists)<--
|
||||||
{'M',"--"},
|
0b100010, // & 34
|
||||||
{'N',"-."},
|
0b1011110, // ' 94
|
||||||
{'O',"---"},
|
0b101101, // ( 45
|
||||||
{'P',".--."},
|
0b1101101, // ) 109
|
||||||
{'Q',"--.-"},
|
0b00, // * (doesn't exists)<--
|
||||||
{'R',".-."},
|
0b101010, // + 42
|
||||||
{'S',"..."},
|
0b1110011, // , 115
|
||||||
{'T',"-"},
|
0b1100001, // - 97
|
||||||
{'U',"..-"},
|
0b1101010, // . 106
|
||||||
{'V',"...-"},
|
0b101001, // / 41
|
||||||
{'W',".--"},
|
0b111111, // 0 63
|
||||||
{'X',"-..-"},
|
0b111110, // 1 62
|
||||||
{'Y',"-.--"},
|
0b111100, // 2 60
|
||||||
{'Z',"--.."},
|
0b111000, // 3 56
|
||||||
{'1',".----"},
|
0b110000, // 4 48
|
||||||
{'2',"..---"},
|
0b100000, // 5 32
|
||||||
{'3',"...--"},
|
0b100001, // 6 33
|
||||||
{'4',"....-"},
|
0b100011, // 7 35
|
||||||
{'5',"....."},
|
0b100111, // 8 39
|
||||||
{'6',"-...."},
|
0b101111, // 9 47
|
||||||
{'7',"--..."},
|
0b1000111, // : 71
|
||||||
{'8',"---.."},
|
0b1101010, // ; 106
|
||||||
{'9',"----."},
|
0b00, // < (doesn't exists)<--
|
||||||
{'0',"-----"},
|
0b110001, // = 49
|
||||||
{'.',".-.-.-"},
|
0b00, // > (doesn't exists)<--
|
||||||
{',',"--..--"},
|
0b1001100, // ? 76
|
||||||
{':',"---..."},
|
0b1010110, // @ 86
|
||||||
{'?',"..--.."},
|
0b110, // A 6
|
||||||
{'\'',".----."},
|
0b10001, // B 17
|
||||||
{'-',"-....-"},
|
0b10101, // C 21
|
||||||
{'/',"-..-."},
|
0b1001, // D 9
|
||||||
{'(',"-.--."},
|
0b10, // E 2
|
||||||
{')',"-.--.-"},
|
0b10100, // F 20
|
||||||
{'\"',".-..-."},
|
0b1011, // G 11
|
||||||
{'=',"-...-"},
|
0b10000, // H 16
|
||||||
{'+',".-.-."},
|
0b100, // I 4
|
||||||
{'@',".--.-."},
|
0b11110, // J 30
|
||||||
{' ',"_"}, // space is used to separate words
|
0b1101, // K 13
|
||||||
{0x01,"-.-.-"}, // ASCII SOH (start of heading) is used as alias for start signal
|
0b10010, // L 18
|
||||||
{0x02,".-.-."} // ASCII EOT (end of transmission) is used as alias for stop signal
|
0b111, // M 7
|
||||||
|
0b101, // N 5
|
||||||
|
0b1111, // O 15
|
||||||
|
0b10110, // P 22
|
||||||
|
0b11011, // Q 27
|
||||||
|
0b1010, // R 10
|
||||||
|
0b1000, // S 8
|
||||||
|
0b11, // T 3
|
||||||
|
0b1100, // U 12
|
||||||
|
0b11000, // V 24
|
||||||
|
0b1110, // W 14
|
||||||
|
0b11001, // X 25
|
||||||
|
0b11101, // Y 29
|
||||||
|
0b10011, // Z 19
|
||||||
|
0b00, // [ (doesn't exists)<--
|
||||||
|
0b00, // \ (doesn't exists)<--
|
||||||
|
0b00, // ] (doesn't exists)<--
|
||||||
|
0b00, // ^ (doesn't exists)<--
|
||||||
|
0b1101100 // _ 108
|
||||||
};
|
};
|
||||||
|
|
||||||
MorseClient::MorseClient(PhysicalLayer* phy) {
|
MorseClient::MorseClient(PhysicalLayer* phy) {
|
||||||
|
@ -106,52 +117,40 @@ size_t MorseClient::write(uint8_t* buff, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MorseClient::write(uint8_t b) {
|
size_t MorseClient::write(uint8_t b) {
|
||||||
// find the correct Morse code in array
|
|
||||||
Morse_t mc;
|
//Note: using toupper() you always find a char, because all possible chars are included in this array!
|
||||||
bool found = false;
|
uint8_t ditdah_code = 0x00;
|
||||||
for(uint8_t pos = 0; pos < MORSE_LENGTH; pos++) {
|
|
||||||
memcpy_P(&mc, &MorseTable[pos], sizeof(Morse_t));
|
if (b == ' ') {
|
||||||
if(mc.c == toupper(b)) {
|
RADIOLIB_DEBUG_PRINTLN('space'); // inter-words pause (space)
|
||||||
found = true;
|
// symbol space
|
||||||
break;
|
_phy->standby();
|
||||||
}
|
delay(_dotLength * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the requested code was found in the array
|
ditdah_code = morse_lookuptable[(uint8_t)(toupper(b) - 32)]; // retrieve morse code from lookuptable
|
||||||
if(found) {
|
|
||||||
RADIOLIB_DEBUG_PRINT(mc.c);
|
|
||||||
RADIOLIB_DEBUG_PRINT('\t');
|
|
||||||
RADIOLIB_DEBUG_PRINTLN(mc.m);
|
|
||||||
|
|
||||||
// iterate over Morse code representation and output appropriate tones
|
//do it until 'guardbit' is reached
|
||||||
for(uint8_t i = 0; i < strlen(mc.m); i++) {
|
while (ditdah_code > GUARDBIT) {
|
||||||
switch(mc.m[i]) {
|
if (ditdah_code & DAH) {
|
||||||
case '.':
|
RADIOLIB_DEBUG_PRINT('-'); // tx a 'dah'
|
||||||
_phy->transmitDirect(_base);
|
_phy->transmitDirect(_base);
|
||||||
delay(_dotLength);
|
delay(_dotLength * 3);
|
||||||
break;
|
}
|
||||||
case '-':
|
else{
|
||||||
_phy->transmitDirect(_base);
|
RADIOLIB_DEBUG_PRINT('.'); // tx a 'dit'
|
||||||
delay(_dotLength * 3);
|
_phy->transmitDirect(_base);
|
||||||
break;
|
|
||||||
case '_':
|
|
||||||
// do nothing (word space)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// symbol space
|
|
||||||
_phy->standby();
|
|
||||||
delay(_dotLength);
|
delay(_dotLength);
|
||||||
}
|
}
|
||||||
|
ditdah_code >>= 1; // analyze next bit
|
||||||
// letter space
|
|
||||||
RADIOLIB_DEBUG_PRINTLN();
|
|
||||||
delay(_dotLength * 3);
|
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
// letter space
|
||||||
|
RADIOLIB_DEBUG_PRINTLN();
|
||||||
|
_phy->standby();
|
||||||
|
delay(_dotLength);
|
||||||
|
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MorseClient::print(__FlashStringHelper* fstr) {
|
size_t MorseClient::print(__FlashStringHelper* fstr) {
|
||||||
|
|
|
@ -4,7 +4,11 @@
|
||||||
#include "../../TypeDef.h"
|
#include "../../TypeDef.h"
|
||||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||||
|
|
||||||
#define MORSE_LENGTH 52
|
//#define MORSE_LENGTH 52
|
||||||
|
#define MORSE_LENGTH 64
|
||||||
|
#define DIT 0b0
|
||||||
|
#define DAH 0b1
|
||||||
|
#define GUARDBIT 0b1
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class MorseClient
|
\class MorseClient
|
||||||
|
|
Loading…
Add table
Reference in a new issue