Add the digital interface, running MMTTY under Wine
MMTTY and 2Tone have no socket or pipe interface: N1MM hosts XMMT.ocx and exchanges window messages with the engine. A Linux process cannot load that control, so bridge/nonemm-mmtty-bridge.exe hosts it under Wine and passes lines over its standard input and output. docs/digital-bridge.md states the protocol and what the control needs. The window is N1MM's: receive pane with coloured callsigns, grab list, call stacking, twenty-four macro buttons and the engine controls. One left click copies what is under it — a callsign to the callsign box, anything else to the exchange box the contest keeps for that kind of value. Config > Digital registers XMMT.ocx in the Wine prefix on its own, making the prefix first if it is not there. The engine, the bridge and the control start at the copies shipped beside the program. The bridge reads the control's own events. OnTranslateMessage carries only the messages the control has no event for, so nothing was ever decoded through it. hamlib's data mode names read as digital modes now, and a mode typed into the callsign box changes mode the way a frequency changes band, so a station with no radio can reach RTTY at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
86
bridge/Protocol.cpp
Normal file
86
bridge/Protocol.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "Protocol.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
|
||||
namespace protocol {
|
||||
namespace {
|
||||
|
||||
std::mutex writing;
|
||||
|
||||
std::string escape(const std::string& field) {
|
||||
std::string escaped;
|
||||
for (char c : field) {
|
||||
switch (c) {
|
||||
case '\\': escaped += "\\\\"; break;
|
||||
case '\t': escaped += "\\t"; break;
|
||||
case '\r': escaped += "\\r"; break;
|
||||
case '\n': escaped += "\\n"; break;
|
||||
default: escaped += c;
|
||||
}
|
||||
}
|
||||
return escaped;
|
||||
}
|
||||
|
||||
std::string unescape(const std::string& field) {
|
||||
std::string plain;
|
||||
for (size_t i = 0; i < field.size(); i++) {
|
||||
if (field[i] != '\\' || i + 1 == field.size()) {
|
||||
plain += field[i];
|
||||
continue;
|
||||
}
|
||||
switch (field[++i]) {
|
||||
case 't': plain += '\t'; break;
|
||||
case 'r': plain += '\r'; break;
|
||||
case 'n': plain += '\n'; break;
|
||||
default: plain += field[i];
|
||||
}
|
||||
}
|
||||
return plain;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string Line::field(size_t index) const {
|
||||
return index < fields.size() ? fields[index] : std::string();
|
||||
}
|
||||
|
||||
long Line::number(size_t index) const {
|
||||
return std::strtol(field(index).c_str(), nullptr, 10);
|
||||
}
|
||||
|
||||
Line read(const std::string& text) {
|
||||
Line line;
|
||||
size_t start = 0;
|
||||
while (true) {
|
||||
size_t tab = text.find('\t', start);
|
||||
std::string part = text.substr(start, tab == std::string::npos ? tab : tab - start);
|
||||
if (start == 0) {
|
||||
line.verb = part;
|
||||
} else {
|
||||
line.fields.push_back(unescape(part));
|
||||
}
|
||||
if (tab == std::string::npos) {
|
||||
return line;
|
||||
}
|
||||
start = tab + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void write(const std::string& verb, const std::vector<std::string>& fields) {
|
||||
std::string line = verb;
|
||||
for (const std::string& field : fields) {
|
||||
line += '\t' + escape(field);
|
||||
}
|
||||
line += '\n';
|
||||
std::lock_guard<std::mutex> held(writing);
|
||||
std::fwrite(line.data(), 1, line.size(), stdout);
|
||||
std::fflush(stdout);
|
||||
}
|
||||
|
||||
void write(const std::string& verb, long value) {
|
||||
write(verb, {std::to_string(value)});
|
||||
}
|
||||
|
||||
} // namespace protocol
|
||||
Reference in New Issue
Block a user