add a node version as a quick prototype

main
inmysocks 2026-01-22 13:03:35 +01:00
parent 8cc1954bb1
commit 10dacbefb4
3 changed files with 18 additions and 17 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
roost roost
node/node_modules/ node/node_modules/
node/records/ node/records/
node/test_sender/alldata/

View File

@ -26,9 +26,9 @@
if(typeof message_handler !== 'function') { if(typeof message_handler !== 'function') {
message_handler = () => {} message_handler = () => {}
} }
console.log('received chunk: ', chunk) //console.log('received chunk: ', chunk)
const the_header = parse_chunk_header(chunk) const the_header = parse_chunk_header(chunk)
console.log('header: ', the_header) //console.log('header: ', the_header)
if(typeof the_header.message_id !== 'undefined') { if(typeof the_header.message_id !== 'undefined') {
// if this is a new message start a record for it // if this is a new message start a record for it
if(!chunk_record[the_header.message_id]) { if(!chunk_record[the_header.message_id]) {
@ -47,13 +47,13 @@
} }
// if this is a new chunk save it in chunk_records // if this is a new chunk save it in chunk_records
if(!chunk_record[the_header.message_id].chunks[the_header.chunk_index]) { if(!chunk_record[the_header.message_id].chunks[the_header.chunk_index]) {
console.log('new chunk for existing message') //console.log('new chunk for existing message')
chunk_record[the_header.message_id].chunks[the_header.chunk_index] = chunk.slice(the_header.header_length, the_header.chunk_length+the_header.header_length) chunk_record[the_header.message_id].chunks[the_header.chunk_index] = chunk.slice(the_header.header_length, the_header.chunk_length+the_header.header_length)
chunk_record[the_header.message_id].r_chunks = chunk_record[the_header.message_id].r_chunks + 1 chunk_record[the_header.message_id].r_chunks = chunk_record[the_header.message_id].r_chunks + 1
} }
// if we have all the chunks reconstruct the message and pass it on for processing // if we have all the chunks reconstruct the message and pass it on for processing
if(chunk_record[the_header.message_id].r_chunks === chunk_record[the_header.message_id].num_chunks) { if(chunk_record[the_header.message_id].r_chunks === chunk_record[the_header.message_id].num_chunks) {
console.log('have all chunks') //console.log('have all chunks')
let reconstructed_message = Buffer.from([]) let reconstructed_message = Buffer.from([])
Object.keys(chunk_record[the_header.message_id].chunks).sort((a,b)=>a-b).forEach(function(thisChunkIndex) { Object.keys(chunk_record[the_header.message_id].chunks).sort((a,b)=>a-b).forEach(function(thisChunkIndex) {
reconstructed_message = Buffer.concat([reconstructed_message, chunk_record[the_header.message_id].chunks[thisChunkIndex]]) reconstructed_message = Buffer.concat([reconstructed_message, chunk_record[the_header.message_id].chunks[thisChunkIndex]])
@ -155,4 +155,4 @@
receive_chunk, receive_chunk,
parse_chunk_header parse_chunk_header
} }
})() })()

View File

@ -93,7 +93,7 @@ function make_string_string_message(
target, target,
this_message_id, this_message_id,
); );
console.log("message header: ", theHeader); //console.log("message header: ", theHeader);
theData = Buffer.alloc(key.length + value.length + 3); theData = Buffer.alloc(key.length + value.length + 3);
theData.write(key, 0); theData.write(key, 0);
theData.writeUInt8(255, key.length); theData.writeUInt8(255, key.length);
@ -152,15 +152,15 @@ function sendFile(socket, rinfo, thisFilePath, fileList) {
} }
function handleMessage(message, rinfo) { function handleMessage(message, rinfo) {
console.log("store message: ", message); //console.log("store message: ", message);
// this is going to be for storing the new format for the data // this is going to be for storing the new format for the data
// this needs to be set up to handle different message types differently, or it could be done when the databuffer is storedu // this needs to be set up to handle different message types differently, or it could be done when the databuffer is storedu
console.log( //console.log(
new Date().toISOString(), // new Date().toISOString(),
" store data 2 route ", // " store data 2 route ",
Buffer.from(message, "hex").toString("hex"), // Buffer.from(message, "hex").toString("hex"),
); //);
const parsed_data = message_parser.parse_messages({ data: message }); const parsed_data = message_parser.parse_messages({ data: message });
let settingsString = Buffer.from([]); let settingsString = Buffer.from([]);
//const seenIDs = [] //const seenIDs = []
@ -172,7 +172,7 @@ function handleMessage(message, rinfo) {
) { ) {
return; return;
} else { } else {
console.log("parsed data: ", thisData); //console.log("parsed data: ", thisData);
} }
dataBuffer.push(thisData); dataBuffer.push(thisData);
if ( if (
@ -187,7 +187,7 @@ function handleMessage(message, rinfo) {
}); });
if (settingsString.length > 0) { if (settingsString.length > 0) {
console.log("settingsString: ", settingsString.toString("hex")); //console.log("settingsString: ", settingsString.toString("hex"));
message_id = message_id + 1; message_id = message_id + 1;
stream.write( stream.write(
"< " + "< " +
@ -201,9 +201,9 @@ function handleMessage(message, rinfo) {
settingsString, settingsString,
message_id, message_id,
); );
console.log("msg chunks: ", theRespChunks); //console.log("msg chunks: ", theRespChunks);
theRespChunks.forEach(function (thisChunk) { theRespChunks.forEach(function (thisChunk) {
console.log("thisChunk: ", thisChunk); //console.log("thisChunk: ", thisChunk);
socket.send(thisChunk, rinfo.port, rinfo.address, (err) => { socket.send(thisChunk, rinfo.port, rinfo.address, (err) => {
if (err) { if (err) {
console.log(err); console.log(err);
@ -351,7 +351,7 @@ function storeType1Messages(msgs) {
theseParams.push( theseParams.push(
msg.source.slice(4), msg.source.slice(4),
msg.reporting_node || "000000000000", msg.reporting_node || "000000000000",
settings[msg.source.slice(4)].temperature_site, settings[msg.source.slice(4)]?.temperature_site || "Unknowable 1",
msg.timestamp, msg.timestamp,
msg.data["18_inch_temperature"] || 500000, msg.data["18_inch_temperature"] || 500000,
msg.data["36_inch_temperature"] || 500000, msg.data["36_inch_temperature"] || 500000,