node-red-contrib-time-converter
Version:
A Node-RED node that converts seconds to mm:ss format and outputs it.
31 lines (26 loc) • 1.06 kB
JavaScript
module.exports = function(RED) {
function DecToAsciiNode(config) {
RED.nodes.createNode(this, config);
const node = this;
node.on("input", function(msg, send, done) {
try {
if (Array.isArray(msg.payload)) {
msg.payload = msg.payload
.slice(0, 32)
.map(num => String.fromCharCode(num & 0xff))
.join("");
msg.topic = `msg.payload=msg.payload.slice(0,32).map(num => String.fromCharCode(num & 0xff)).join("")`;
} else {
msg.payload = "錯誤:msg.payload 不是陣列";
node.warn("msg.payload 必須為十進位數字陣列");
}
send(msg);
if (done) done();
} catch (err) {
if (done) done(err);
else node.error(err, msg);
}
});
}
RED.nodes.registerType("dec-to-ascii", DecToAsciiNode);
};