Skip to content

Commit

Permalink
adding BlinkTest
Browse files Browse the repository at this point in the history
  • Loading branch information
acien101 committed Jul 3, 2018
1 parent ffd1ea7 commit 1f6590d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/granasat/GranaSatDashboard#readme",
"dependencies": {
"c-struct": "0.0.5",
"colors": "^1.1.2",
"dateformat": "^1.0.12",
"mysql": "^2.11.1"
Expand Down
65 changes: 65 additions & 0 deletions tcpServerBlinkTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
SOURCE: https://gist.github.com/tedmiston/5935757
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it.
And connect with a tcp client from the command line using netcat, the *nix
utility for reading and writing across tcp/udp network connections. I've only
used it for debugging myself.
$ netcat 127.0.0.1 1337
MODIFIED FOR SAVING INPUT DATA TO A FILE
*/

var _ = require('c-struct');

var soh_t = {
length : 0,
id : 1,
delay: 1000
};

var _soh_t = new _.Schema({
length : _.type.uint8,
id : _.type.uint8,
delay : _.type.uint8
});

_.register('soh_t', _soh_t);

//Log
var log = require('./utils/logger.js').Logger;

//Config
var config = require('./config.json');

var net = require('net');

var server = net.createServer(function(socket) {
socket.on('data', function (input) {
log("Received data: " + input.toString('utf8'), "info");

soh_t.delay = input;
});

setInterval(function () {
soh_t.length = Object.keys(soh_t).length;

var buff = _.packSync('soh_t', {
length : soh_t.length,
id : soh_t.id,
delay : soh_t.delay
});

console.log(buff);

socket.write(buff);
}, 1000);
});

server.listen(config.web_port, config.web_host);
console.log("Listening on port " + config.web_port + " on " + config.web_host);


0 comments on commit 1f6590d

Please sign in to comment.