Skip to content
Snippets Groups Projects
Commit 483e3f07 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add character set translation (CP437 <> UTF-8)

... for when your terminal and the node client terminal don't use the same
character set. Only CP437 and UTF-8 addressed in this commit, not PETSCII
or plain ASCII.

This was never possible before MQTT.
parent e99aa524
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
// Spy on a terminal server node using MQTT // Spy on a terminal server node using MQTT
// usage: mqtt_spy <node_num> [char_set]
require("key_defs.js", "CTRL_C"); require("key_defs.js", "CTRL_C");
require("nodedefs.js", "NodeStatus"); require("nodedefs.js", "NodeStatus");
...@@ -34,6 +36,19 @@ function get_ansi_seq() ...@@ -34,6 +36,19 @@ function get_ansi_seq()
return null; return null;
} }
var my_charset = js.global.console ? console.charset : argv[1] || 'CP437';
var node_charset;
function output(str)
{
if(my_charset != node_charset) {
if(node_charset == 'UTF-8')
str = utf8_decode(str);
else if(my_charset == 'UTF-8')
str = utf8_encode(str);
}
write(str);
}
if(argc < 1) { if(argc < 1) {
alert("Node number not specified"); alert("Node number not specified");
exit(0); exit(0);
...@@ -48,6 +63,7 @@ if(node_num < 1 || node_num > system.nodes || isNaN(node_num) ...@@ -48,6 +63,7 @@ if(node_num < 1 || node_num > system.nodes || isNaN(node_num)
var in_topic = format("sbbs/%s/node/%u/input", system.qwk_id, node_num); var in_topic = format("sbbs/%s/node/%u/input", system.qwk_id, node_num);
var out_topic = format("sbbs/%s/node/%u/output", system.qwk_id, node_num); var out_topic = format("sbbs/%s/node/%u/output", system.qwk_id, node_num);
var status_topic = format("sbbs/%s/node/%u/status", system.qwk_id, node_num); var status_topic = format("sbbs/%s/node/%u/status", system.qwk_id, node_num);
var terminal_topic = format("sbbs/%s/node/%u/terminal", system.qwk_id, node_num);
var mqtt = new MQTT(); var mqtt = new MQTT();
if(!mqtt.connect()) { if(!mqtt.connect()) {
alert("Connect error: " + mqtt.error_str); alert("Connect error: " + mqtt.error_str);
...@@ -62,13 +78,17 @@ if(!mqtt.subscribe(out_topic)) { ...@@ -62,13 +78,17 @@ if(!mqtt.subscribe(out_topic)) {
alert(format("Subscribe to '%s' error: %s", out_topic, mqtt.error_str)); alert(format("Subscribe to '%s' error: %s", out_topic, mqtt.error_str));
exit(1); exit(1);
} }
if(!mqtt.subscribe(terminal_topic)) {
alert(format("Subscribe to '%s' error: %s", terminal_topic, mqtt.error_str));
exit(1);
}
print("*** Synchronet MQTT Spy on Node " + node_num + ": Ctrl-C to Abort ***\r\n"); print("*** Synchronet MQTT Spy on Node " + node_num + ": Ctrl-C to Abort ***\r\n");
while(!js.terminated) { while(!js.terminated) {
var msg = mqtt.read(/* timeout: */10, /* verbose: */true); var msg = mqtt.read(/* timeout: */10, /* verbose: */true);
if(msg) { if(msg) {
if(msg.topic == out_topic) if(msg.topic == out_topic)
write(msg.data); output(msg.data);
else if(msg.topic == status_topic) { else if(msg.topic == status_topic) {
var new_status = parseInt(msg.data, 10); var new_status = parseInt(msg.data, 10);
if(new_status != node_status) { if(new_status != node_status) {
...@@ -76,6 +96,9 @@ while(!js.terminated) { ...@@ -76,6 +96,9 @@ while(!js.terminated) {
print("\r\nNew node status: " + NodeStatus[node_status]); print("\r\nNew node status: " + NodeStatus[node_status]);
} }
} }
else if(msg.topic == terminal_topic) {
node_charset = msg.data.split('\t')[4];
}
} }
if(js.global.console) { if(js.global.console) {
if(console.aborted || !bbs.online) if(console.aborted || !bbs.online)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment