beware of memory constraints!?
This commit is contained in:
parent
b6ca08f32f
commit
4b0b6bbcea
7 changed files with 130 additions and 36 deletions
2
.vscode/c_cpp_properties.json
vendored
2
.vscode/c_cpp_properties.json
vendored
|
@ -9,7 +9,7 @@
|
|||
"defines": [],
|
||||
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++20",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "linux-gcc-arm",
|
||||
"configurationProvider" : "ms-vscode.cmake-tools"
|
||||
}
|
||||
|
|
79
.vscode/settings.json
vendored
79
.vscode/settings.json
vendored
|
@ -15,6 +15,83 @@
|
|||
},
|
||||
},
|
||||
"files.associations": {
|
||||
"board.h": "c"
|
||||
"board.h": "c",
|
||||
"any": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bit": "cpp",
|
||||
"*.tcc": "cpp",
|
||||
"bitset": "cpp",
|
||||
"cctype": "cpp",
|
||||
"charconv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"compare": "cpp",
|
||||
"complex": "cpp",
|
||||
"concepts": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"csignal": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"deque": "cpp",
|
||||
"forward_list": "cpp",
|
||||
"list": "cpp",
|
||||
"map": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"unordered_set": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"regex": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"format": "cpp",
|
||||
"fstream": "cpp",
|
||||
"future": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"numbers": "cpp",
|
||||
"ostream": "cpp",
|
||||
"ranges": "cpp",
|
||||
"semaphore": "cpp",
|
||||
"span": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"stop_token": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"valarray": "cpp",
|
||||
"variant": "cpp"
|
||||
},
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "keyer.h"
|
||||
#include "sidetone.h"
|
||||
#include "morse.h"
|
||||
|
||||
extern const uint LED_PIN;
|
||||
extern const uint LEFT_PADDLE_PIN;
|
||||
|
@ -47,9 +48,11 @@ void Keyer::setSpeed(uint8_t wpm)
|
|||
m_elementDuration = calcElementDurationUs(wpm);
|
||||
}
|
||||
|
||||
void Keyer::sendMessage(const std::string &msg)
|
||||
void Keyer::sendMessage(std::string &msg)
|
||||
{
|
||||
for (auto c : 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);
|
||||
}
|
||||
}
|
||||
|
@ -77,12 +80,14 @@ 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;
|
||||
break;
|
||||
case '-':
|
||||
m_messageKeyingState = MessageState::Dit;
|
||||
m_messageKeyingState = MessageState::Dah;
|
||||
break;
|
||||
case 'i':
|
||||
m_messageKeyingState = MessageState::IntraCharSpace;
|
||||
|
|
|
@ -14,7 +14,7 @@ class Keyer final
|
|||
|
||||
void setMode(Mode mode) { m_mode = mode; }
|
||||
void setSpeed(uint8_t wpm);
|
||||
void sendMessage(const std::string &msg);
|
||||
void sendMessage(std::string &msg);
|
||||
|
||||
void run();
|
||||
void stop();
|
||||
|
@ -53,7 +53,7 @@ class Keyer final
|
|||
|
||||
std::queue<char> m_messageQueue;
|
||||
MessageState m_messageKeyingState {MessageState::Wait};
|
||||
char m_messageChar;
|
||||
char m_messageChar{};
|
||||
|
||||
uint64_t m_elementDuration {0};
|
||||
bool m_currentlyKeying {false};
|
||||
|
|
|
@ -20,41 +20,49 @@ std::map<char, std::string> morseCode = {
|
|||
{'a', "-.-.-"}, // a == <KA>
|
||||
};
|
||||
|
||||
std::string refurbishMessage(const std::string &msg)
|
||||
void refurbishMessage(std::string &msg)
|
||||
{
|
||||
std::string msgRefurb;
|
||||
msgRefurb.resize(msg.length());
|
||||
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.cbegin(), msg.cend(), msgRefurb.begin(), [](unsigned char c) { return std::toupper(c); });
|
||||
//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
|
||||
msgRefurb = std::regex_replace(msgRefurb, std::regex("<BT>"), "=");
|
||||
msgRefurb = std::regex_replace(msgRefurb, std::regex("<KN>"), "k");
|
||||
msgRefurb = std::regex_replace(msgRefurb, std::regex("<SK>"), "s");
|
||||
msgRefurb = std::regex_replace(msgRefurb, std::regex("<AR>"), "+");
|
||||
msgRefurb = std::regex_replace(msgRefurb, 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
|
||||
msgRefurb.erase(remove_if(msgRefurb.begin(), msgRefurb.end(),
|
||||
[](const char &c) { return c != ' ' && morseCode.find(c) == morseCode.end(); }),
|
||||
msgRefurb.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
|
||||
msgRefurb = std::regex_replace(msgRefurb, std::regex("(\\s+)"), " ");
|
||||
//msg = std::regex_replace(msg, std::regex("(\\s+)"), " ");
|
||||
|
||||
return msgRefurb;
|
||||
//printf("Msg Origgg2: %s\n", msg.c_str());
|
||||
//return msgRefurb;
|
||||
}
|
||||
|
||||
std::string messageToMorse(const std::string &msg)
|
||||
std::string messageToMorse(std::string &msg)
|
||||
{
|
||||
std::string refMsg = refurbishMessage(msg);
|
||||
std::string morseString;
|
||||
refurbishMessage(msg);
|
||||
|
||||
for (unsigned int i = 0; i < refMsg.length(); i++) {
|
||||
auto c = refMsg[i];
|
||||
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.append(" ");
|
||||
morseString += 'w';
|
||||
continue;
|
||||
}
|
||||
|
@ -62,30 +70,31 @@ std::string messageToMorse(const 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++) {
|
||||
auto m = morseCode[c][j];
|
||||
if (j == 0 && i > 0 && refMsg[i - 1] != ' ') {
|
||||
// morseString.append(" ");
|
||||
char m = morseCode[c][j]; printf("M = %c\n", m);
|
||||
if (j == 0 && i > 0 && msg[i - 1] != ' ') {
|
||||
morseString += 'c';
|
||||
}
|
||||
|
||||
morseString += m;
|
||||
|
||||
if (j < morseCode[c].length() - 1) {
|
||||
// morseString.append(" ");
|
||||
morseString += 'i';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Append word space if last char was not a blank
|
||||
if (refMsg.back() != ' ') {
|
||||
// morseString.append(" ");
|
||||
if (msg.back() != ' ') {
|
||||
morseString += 'w';
|
||||
}
|
||||
|
||||
printf("Sodele: %s\n", morseString.c_str());
|
||||
printf("Ref Mesg 2 (%i): %s\n", msg.length(), msg.c_str());
|
||||
|
||||
return morseString;
|
||||
}
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
std::string messageToMorse(const std::string &msg);
|
||||
std::string messageToMorse(std::string &msg);
|
|
@ -94,6 +94,7 @@ void core1_main()
|
|||
break;
|
||||
case KeyerQueueCommand::SendMessage:
|
||||
keyer.sendMessage(data.message);
|
||||
data.cmd = KeyerQueueCommand::Run;
|
||||
break;
|
||||
case KeyerQueueCommand::Wait:
|
||||
break;
|
||||
|
@ -203,10 +204,12 @@ int main()
|
|||
lastWpm = currentWpm;
|
||||
}
|
||||
|
||||
busy_wait_ms(10000);
|
||||
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