add a test script to send data to the database
parent
926a68d6b6
commit
8cc1954bb1
|
|
@ -0,0 +1,48 @@
|
||||||
|
const dgram = require("dgram");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const cellularChunking = require("./../cellularChunking");
|
||||||
|
const messageParser = require("./../messages");
|
||||||
|
|
||||||
|
const socket = dgram.createSocket("udp4");
|
||||||
|
|
||||||
|
const theFiles = fs.readdirSync("./alldata")
|
||||||
|
theFiles.sort()
|
||||||
|
console.log(theFiles)
|
||||||
|
let thisFileInd = theFiles.length - 3
|
||||||
|
|
||||||
|
function send_next_line(i, theLines) {
|
||||||
|
console.log(`sending line ${i} of ${theLines.length}`);
|
||||||
|
if (theLines.length > i) {
|
||||||
|
const theBits = theLines[i].split(" ")
|
||||||
|
if(theBits.length < 3 || theBits[2].length < 10) {
|
||||||
|
send_next_line(i+1, theLines)
|
||||||
|
} else {
|
||||||
|
socket.send(
|
||||||
|
Buffer.from(theBits[2], "hex"),
|
||||||
|
57321,
|
||||||
|
"127.0.0.1",
|
||||||
|
function (err) {
|
||||||
|
setTimeout(send_next_line, 250, i + 1, theLines);
|
||||||
|
//send_next_line(i + 1, theLines)
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
thisFileInd += 1
|
||||||
|
do_next_file()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function do_next_file() {
|
||||||
|
if (thisFileInd > theFiles.length - 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const fileData = fs.readFileSync(`./alldata/${theFiles[thisFileInd]}`, "utf8");
|
||||||
|
const theLines = fileData.split("\n");
|
||||||
|
let i = 0;
|
||||||
|
send_next_line(i, theLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
// open the file with the messages and then send them
|
||||||
|
do_next_file()
|
||||||
Loading…
Reference in New Issue