Compare commits
No commits in common. "b1d376952214b3015cd9ec9054cfc826055d076e" and "491d5e34f1d69c1d96e9f9c6f8b1b5978ccbeedb" have entirely different histories.
b1d3769522
...
491d5e34f1
3 changed files with 50 additions and 33 deletions
|
@ -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);
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ void Keyer::run()
|
|||
m_messageChar = m_messageQueue.front();
|
||||
m_messageQueue.pop();
|
||||
|
||||
printf("Char is: %c\n", m_messageChar);
|
||||
|
||||
switch (m_messageChar) {
|
||||
case '.':
|
||||
m_messageKeyingState = MessageState::Dit;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "morse.h"
|
||||
|
||||
static std::map<char, std::string> morseCode = {
|
||||
std::map<char, std::string> morseCode = {
|
||||
{'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."}, {'F', "..-."},
|
||||
{'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"}, {'K', "-.-"}, {'L', ".-.."},
|
||||
{'M', "--"}, {'N', "-."}, {'O', "---"}, {'P', ".--."}, {'Q', "--.-"}, {'R', ".-."},
|
||||
|
@ -14,7 +14,6 @@ static std::map<char, std::string> morseCode = {
|
|||
{',', "--..--"}, {'.', ".-.-.-"}, {'?', "..--.."}, {'/', "-..-."}, {'-', "-....-"}, {':', "---..."},
|
||||
{'&', ".-..."}, {'\'', ".----."}, {'@', ".--.-."}, {')', "-.--.-"}, {'(', "-.--."}, {'\"', ".-..-."},
|
||||
{'=', "-...-"}, // '=' == <BT>
|
||||
{'b', "-...-.-"}, // '=' == <BK>
|
||||
{'k', "-.--."}, // k == <KN>
|
||||
{'s', "...-.-"}, // s == <SK>
|
||||
{'+', ".-.-."}, // + == <AR>
|
||||
|
@ -23,63 +22,79 @@ static std::map<char, std::string> morseCode = {
|
|||
|
||||
void refurbishMessage(std::string &msg)
|
||||
{
|
||||
printf("The message is: %s\n", msg.c_str());
|
||||
//std::string msgRefurb;
|
||||
//msgRefurb.resize(msg.size());
|
||||
|
||||
// Make the message all upper case
|
||||
//std::transform(msg.begin(), msg.end(), msgRefurb.begin(), [](unsigned char c) { return std::toupper(c); });
|
||||
std::transform(msg.begin(), msg.end(), msg.begin(), ::toupper);
|
||||
|
||||
|
||||
// Encode the special characters as we like it
|
||||
msg = std::regex_replace(msg, std::regex("<BT>"), "=");
|
||||
msg = std::regex_replace(msg, std::regex("<BK>"), "b");
|
||||
msg = std::regex_replace(msg, std::regex("<KN>"), "k");
|
||||
msg = std::regex_replace(msg, std::regex("<SK>"), "s");
|
||||
msg = std::regex_replace(msg, std::regex("<AR>"), "+");
|
||||
msg = std::regex_replace(msg, std::regex("<KA>"), "a");
|
||||
//msg = std::regex_replace(msg, std::regex("<BT>"), "=");
|
||||
//msg = std::regex_replace(msg, std::regex("<KN>"), "k");
|
||||
//msg = std::regex_replace(msg, std::regex("<SK>"), "s");
|
||||
//msg = std::regex_replace(msg, std::regex("<AR>"), "+");
|
||||
//msg = std::regex_replace(msg, std::regex("<KA>"), "a");
|
||||
|
||||
//printf("Msg Origgg: %s\n", msg.c_str());
|
||||
|
||||
// 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());
|
||||
//msg.erase(remove_if(msg.begin(), 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+)"), " ");
|
||||
//msg = std::regex_replace(msg, std::regex("(\\s+)"), " ");
|
||||
|
||||
//printf("Msg Origgg2: %s\n", msg.c_str());
|
||||
//return msgRefurb;
|
||||
}
|
||||
|
||||
std::string messageToMorse(std::string &msg)
|
||||
{
|
||||
refurbishMessage(msg);
|
||||
|
||||
std::string morseString {};
|
||||
std::string morseString = "";
|
||||
|
||||
printf("Ref Mesg (%i): %s\n", msg.length(), msg.c_str());
|
||||
|
||||
for (unsigned int i = 0; i < msg.length(); i++) {
|
||||
char c = msg[i];
|
||||
if (c == ' ') {
|
||||
morseString.push_back('w');
|
||||
morseString += 'w';
|
||||
continue;
|
||||
}
|
||||
|
||||
// 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]; printf("M = %c\n", m);
|
||||
if (j == 0 && i > 0 && msg[i - 1] != ' ') {
|
||||
morseString.push_back('c');
|
||||
morseString += 'c';
|
||||
}
|
||||
|
||||
morseString += m;
|
||||
|
||||
if (j < morseCode[c].length() - 1) {
|
||||
morseString.push_back('i');
|
||||
morseString += 'i';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append word space if last char was not a blank
|
||||
if (msg.back() != ' ') {
|
||||
morseString.push_back('w');
|
||||
morseString += 'w';
|
||||
}
|
||||
|
||||
printf("Sodele: %s\n", morseString.c_str());
|
||||
printf("Ref Mesg 2 (%i): %s\n", msg.length(), msg.c_str());
|
||||
|
||||
return morseString;
|
||||
}
|
|
@ -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 cq de dg2smb dg2smb pse k"};
|
||||
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cqde dg2smbk"};
|
||||
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
||||
used = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue