diff --git a/src/keyer.cpp b/src/keyer.cpp index e21abbc..5fd8f19 100644 --- a/src/keyer.cpp +++ b/src/keyer.cpp @@ -51,7 +51,7 @@ void Keyer::setSpeed(uint8_t wpm) void Keyer::sendMessage(std::string msg) { std::string morse = messageToMorse(msg); - printf("Morse (%i): %s\n", morse.length(), morse.c_str()); + for (unsigned char c : morse) { m_messageQueue.push(c); } diff --git a/src/morse.cpp b/src/morse.cpp index 3b9fa8b..8dac9f2 100644 --- a/src/morse.cpp +++ b/src/morse.cpp @@ -5,30 +5,30 @@ #include "morse.h" static std::map morseCode = { - {'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."}, {'F', "..-."}, - {'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"}, {'K', "-.-"}, {'L', ".-.."}, - {'M', "--"}, {'N', "-."}, {'O', "---"}, {'P', ".--."}, {'Q', "--.-"}, {'R', ".-."}, - {'S', "..."}, {'T', "-"}, {'U', "..-"}, {'V', "...-"}, {'W', ".--"}, {'X', "-..-"}, - {'Y', "-.--"}, {'Z', "--.."}, {'1', ".----"}, {'2', "..---"}, {'3', "...--"}, {'4', "....-"}, - {'5', "....."}, {'6', "-...."}, {'7', "--..."}, {'8', "---.."}, {'9', "----."}, {'0', "-----"}, - {',', "--..--"}, {'.', ".-.-.-"}, {'?', "..--.."}, {'/', "-..-."}, {'-', "-....-"}, {':', "---..."}, - {'&', ".-..."}, {'\'', ".----."}, {'@', ".--.-."}, {')', "-.--.-"}, {'(', "-.--."}, {'\"', ".-..-."}, - {'=', "-...-"}, // '=' == - {'k', "-.--."}, // k == - {'s', "...-.-"}, // s == - {'+', ".-.-."}, // + == - {'a', "-.-.-"}, // a == + {'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."}, {'F', "..-."}, + {'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"}, {'K', "-.-"}, {'L', ".-.."}, + {'M', "--"}, {'N', "-."}, {'O', "---"}, {'P', ".--."}, {'Q', "--.-"}, {'R', ".-."}, + {'S', "..."}, {'T', "-"}, {'U', "..-"}, {'V', "...-"}, {'W', ".--"}, {'X', "-..-"}, + {'Y', "-.--"}, {'Z', "--.."}, {'1', ".----"}, {'2', "..---"}, {'3', "...--"}, {'4', "....-"}, + {'5', "....."}, {'6', "-...."}, {'7', "--..."}, {'8', "---.."}, {'9', "----."}, {'0', "-----"}, + {',', "--..--"}, {'.', ".-.-.-"}, {'?', "..--.."}, {'/', "-..-."}, {'-', "-....-"}, {':', "---..."}, + {'&', ".-..."}, {'\'', ".----."}, {'@', ".--.-."}, {')', "-.--.-"}, {'(', "-.--."}, {'\"', ".-..-."}, + {'=', "-...-"}, // '=' == + {'b', "-...-.-"}, // '=' == + {'k', "-.--."}, // k == + {'s', "...-.-"}, // s == + {'+', ".-.-."}, // + == + {'a', "-.-.-"}, // a == }; void refurbishMessage(std::string &msg) { - printf("The message is: %s\n", msg.c_str()); - // Make the message all upper case std::transform(msg.begin(), msg.end(), msg.begin(), ::toupper); // Encode the special characters as we like it msg = std::regex_replace(msg, std::regex(""), "="); + msg = std::regex_replace(msg, std::regex(""), "b"); msg = std::regex_replace(msg, std::regex(""), "k"); msg = std::regex_replace(msg, std::regex(""), "s"); msg = std::regex_replace(msg, std::regex(""), "+"); @@ -36,22 +36,18 @@ void refurbishMessage(std::string &msg) // Remove all other unknown characters msg.erase(remove_if(msg.begin(), msg.end(), - [](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }), - msg.end()); + [](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }), + msg.end()); // Remove spaces, if there are too many of them msg = std::regex_replace(msg, std::regex("(\\s+)"), " "); - - printf("The message is now: %s\n", msg.c_str()); } std::string messageToMorse(std::string &msg) { refurbishMessage(msg); - - std::string morseString {}; - printf("Ref Mesg (%i): %s\n", msg.length(), msg.c_str()); + std::string morseString {}; for (unsigned int i = 0; i < msg.length(); i++) { char c = msg[i]; @@ -63,12 +59,11 @@ std::string messageToMorse(std::string &msg) // Ignore and continue with next char, if not found auto search = morseCode.find(c); if (search == morseCode.end()) { - printf("Nanu (i=%i)? %c\n", i, c); continue; } for (unsigned int j = 0; j < morseCode[c].length(); j++) { - char m = morseCode[c][j]; + char m = morseCode[c][j]; if (j == 0 && i > 0 && msg[i - 1] != ' ') { morseString.push_back('c'); } @@ -86,8 +81,5 @@ std::string messageToMorse(std::string &msg) morseString.push_back('w'); } - printf("Morse String: %s\n", morseString.c_str()); - printf("Ref Mesg 2 (%i): %s\n", msg.length(), msg.c_str()); - return morseString; } \ No newline at end of file diff --git a/src/raspi_keyer.cpp b/src/raspi_keyer.cpp index d9edd22..b6fab46 100644 --- a/src/raspi_keyer.cpp +++ b/src/raspi_keyer.cpp @@ -207,7 +207,7 @@ int main() busy_wait_ms(5000); if (!used) { //KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb pse k"}; - KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cqde dg2smbk"}; + KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb pse k"}; queue_add_blocking(&keyerQueue, &keyerQueueData); used = true; }