sending messages is working now.
This commit is contained in:
parent
e21fda9917
commit
b1d3769522
3 changed files with 21 additions and 29 deletions
|
@ -51,7 +51,7 @@ void Keyer::setSpeed(uint8_t wpm)
|
||||||
void Keyer::sendMessage(std::string msg)
|
void Keyer::sendMessage(std::string msg)
|
||||||
{
|
{
|
||||||
std::string morse = messageToMorse(msg);
|
std::string morse = messageToMorse(msg);
|
||||||
printf("Morse (%i): %s\n", morse.length(), morse.c_str());
|
|
||||||
for (unsigned char c : morse) {
|
for (unsigned char c : morse) {
|
||||||
m_messageQueue.push(c);
|
m_messageQueue.push(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ static std::map<char, std::string> morseCode = {
|
||||||
{',', "--..--"}, {'.', ".-.-.-"}, {'?', "..--.."}, {'/', "-..-."}, {'-', "-....-"}, {':', "---..."},
|
{',', "--..--"}, {'.', ".-.-.-"}, {'?', "..--.."}, {'/', "-..-."}, {'-', "-....-"}, {':', "---..."},
|
||||||
{'&', ".-..."}, {'\'', ".----."}, {'@', ".--.-."}, {')', "-.--.-"}, {'(', "-.--."}, {'\"', ".-..-."},
|
{'&', ".-..."}, {'\'', ".----."}, {'@', ".--.-."}, {')', "-.--.-"}, {'(', "-.--."}, {'\"', ".-..-."},
|
||||||
{'=', "-...-"}, // '=' == <BT>
|
{'=', "-...-"}, // '=' == <BT>
|
||||||
|
{'b', "-...-.-"}, // '=' == <BK>
|
||||||
{'k', "-.--."}, // k == <KN>
|
{'k', "-.--."}, // k == <KN>
|
||||||
{'s', "...-.-"}, // s == <SK>
|
{'s', "...-.-"}, // s == <SK>
|
||||||
{'+', ".-.-."}, // + == <AR>
|
{'+', ".-.-."}, // + == <AR>
|
||||||
|
@ -22,13 +23,12 @@ static std::map<char, std::string> morseCode = {
|
||||||
|
|
||||||
void refurbishMessage(std::string &msg)
|
void refurbishMessage(std::string &msg)
|
||||||
{
|
{
|
||||||
printf("The message is: %s\n", msg.c_str());
|
|
||||||
|
|
||||||
// Make the message all upper case
|
// Make the message all upper case
|
||||||
std::transform(msg.begin(), msg.end(), msg.begin(), ::toupper);
|
std::transform(msg.begin(), msg.end(), msg.begin(), ::toupper);
|
||||||
|
|
||||||
// Encode the special characters as we like it
|
// Encode the special characters as we like it
|
||||||
msg = std::regex_replace(msg, std::regex("<BT>"), "=");
|
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("<KN>"), "k");
|
||||||
msg = std::regex_replace(msg, std::regex("<SK>"), "s");
|
msg = std::regex_replace(msg, std::regex("<SK>"), "s");
|
||||||
msg = std::regex_replace(msg, std::regex("<AR>"), "+");
|
msg = std::regex_replace(msg, std::regex("<AR>"), "+");
|
||||||
|
@ -41,8 +41,6 @@ void refurbishMessage(std::string &msg)
|
||||||
|
|
||||||
// Remove spaces, if there are too many of them
|
// 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("The message is now: %s\n", msg.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string messageToMorse(std::string &msg)
|
std::string messageToMorse(std::string &msg)
|
||||||
|
@ -51,8 +49,6 @@ std::string messageToMorse(std::string &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++) {
|
for (unsigned int i = 0; i < msg.length(); i++) {
|
||||||
char c = msg[i];
|
char c = msg[i];
|
||||||
if (c == ' ') {
|
if (c == ' ') {
|
||||||
|
@ -63,7 +59,6 @@ std::string messageToMorse(std::string &msg)
|
||||||
// Ignore and continue with next char, if not found
|
// Ignore and continue with next char, if not found
|
||||||
auto search = morseCode.find(c);
|
auto search = morseCode.find(c);
|
||||||
if (search == morseCode.end()) {
|
if (search == morseCode.end()) {
|
||||||
printf("Nanu (i=%i)? %c\n", i, c);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +81,5 @@ std::string messageToMorse(std::string &msg)
|
||||||
morseString.push_back('w');
|
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;
|
return morseString;
|
||||||
}
|
}
|
|
@ -207,7 +207,7 @@ int main()
|
||||||
busy_wait_ms(5000);
|
busy_wait_ms(5000);
|
||||||
if (!used) {
|
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"};
|
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb pse k"};
|
||||||
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
||||||
used = true;
|
used = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue