...
This commit is contained in:
parent
491d5e34f1
commit
e21fda9917
2 changed files with 18 additions and 27 deletions
|
@ -80,8 +80,6 @@ void Keyer::run()
|
||||||
m_messageChar = m_messageQueue.front();
|
m_messageChar = m_messageQueue.front();
|
||||||
m_messageQueue.pop();
|
m_messageQueue.pop();
|
||||||
|
|
||||||
printf("Char is: %c\n", m_messageChar);
|
|
||||||
|
|
||||||
switch (m_messageChar) {
|
switch (m_messageChar) {
|
||||||
case '.':
|
case '.':
|
||||||
m_messageKeyingState = MessageState::Dit;
|
m_messageKeyingState = MessageState::Dit;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "morse.h"
|
#include "morse.h"
|
||||||
|
|
||||||
std::map<char, std::string> morseCode = {
|
static std::map<char, std::string> morseCode = {
|
||||||
{'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."}, {'F', "..-."},
|
{'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."}, {'F', "..-."},
|
||||||
{'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"}, {'K', "-.-"}, {'L', ".-.."},
|
{'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"}, {'K', "-.-"}, {'L', ".-.."},
|
||||||
{'M', "--"}, {'N', "-."}, {'O', "---"}, {'P', ".--."}, {'Q', "--.-"}, {'R', ".-."},
|
{'M', "--"}, {'N', "-."}, {'O', "---"}, {'P', ".--."}, {'Q', "--.-"}, {'R', ".-."},
|
||||||
|
@ -23,47 +23,40 @@ 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());
|
printf("The message is: %s\n", msg.c_str());
|
||||||
//std::string msgRefurb;
|
|
||||||
//msgRefurb.resize(msg.size());
|
|
||||||
|
|
||||||
// Make the message all upper case
|
// 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);
|
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("<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>"), "+");
|
||||||
//msg = std::regex_replace(msg, std::regex("<KA>"), "a");
|
msg = std::regex_replace(msg, std::regex("<KA>"), "a");
|
||||||
|
|
||||||
//printf("Msg Origgg: %s\n", msg.c_str());
|
|
||||||
|
|
||||||
// Remove all other unknown characters
|
// Remove all other unknown characters
|
||||||
//msg.erase(remove_if(msg.begin(), msg.end(),
|
msg.erase(remove_if(msg.begin(), msg.end(),
|
||||||
// [](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }),
|
[](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }),
|
||||||
// msg.end());
|
msg.end());
|
||||||
|
|
||||||
// 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("Msg Origgg2: %s\n", msg.c_str());
|
printf("The message is now: %s\n", msg.c_str());
|
||||||
//return msgRefurb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string messageToMorse(std::string &msg)
|
std::string messageToMorse(std::string &msg)
|
||||||
{
|
{
|
||||||
refurbishMessage(msg);
|
refurbishMessage(msg);
|
||||||
|
|
||||||
std::string morseString = "";
|
std::string morseString {};
|
||||||
|
|
||||||
printf("Ref Mesg (%i): %s\n", msg.length(), msg.c_str());
|
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 == ' ') {
|
||||||
morseString += 'w';
|
morseString.push_back('w');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,25 +68,25 @@ std::string messageToMorse(std::string &msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int j = 0; j < morseCode[c].length(); j++) {
|
for (unsigned int j = 0; j < morseCode[c].length(); j++) {
|
||||||
char m = morseCode[c][j]; printf("M = %c\n", m);
|
char m = morseCode[c][j];
|
||||||
if (j == 0 && i > 0 && msg[i - 1] != ' ') {
|
if (j == 0 && i > 0 && msg[i - 1] != ' ') {
|
||||||
morseString += 'c';
|
morseString.push_back('c');
|
||||||
}
|
}
|
||||||
|
|
||||||
morseString += m;
|
morseString += m;
|
||||||
|
|
||||||
if (j < morseCode[c].length() - 1) {
|
if (j < morseCode[c].length() - 1) {
|
||||||
morseString += 'i';
|
morseString.push_back('i');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append word space if last char was not a blank
|
// Append word space if last char was not a blank
|
||||||
if (msg.back() != ' ') {
|
if (msg.back() != ' ') {
|
||||||
morseString += 'w';
|
morseString.push_back('w');
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Sodele: %s\n", morseString.c_str());
|
printf("Morse String: %s\n", morseString.c_str());
|
||||||
printf("Ref Mesg 2 (%i): %s\n", msg.length(), msg.c_str());
|
printf("Ref Mesg 2 (%i): %s\n", msg.length(), msg.c_str());
|
||||||
|
|
||||||
return morseString;
|
return morseString;
|
||||||
|
|
Loading…
Reference in a new issue