mirror of
https://github.com/jwetzell/aas-js.git
synced 2026-08-24 14:29:12 +00:00
initial commit
This commit is contained in:
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { SerialPort } = require('serialport');
|
||||
const { Console, Packets } = require('aas-lib');
|
||||
const { writeFileSync } = require('fs');
|
||||
const { program } = require('commander');
|
||||
const packageInfo = require('./package.json');
|
||||
|
||||
program.name(packageInfo.name);
|
||||
program.version(packageInfo.version);
|
||||
program.description('Simple protocol router /s');
|
||||
program.option('-d, --device <serial port path>', 'serialport path');
|
||||
program.parse(process.argv);
|
||||
|
||||
const options = program.opts();
|
||||
if (!options.device) {
|
||||
console.error('app: no device specified');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const aasConsole = new Console();
|
||||
const port = new SerialPort({
|
||||
path: options.device,
|
||||
baudRate: 76800,
|
||||
});
|
||||
|
||||
port.on('error', (error) => {
|
||||
console.error('app: problem with serial port');
|
||||
console.error(error.message);
|
||||
});
|
||||
|
||||
// Switches the port into "flowing mode"
|
||||
port.on('data', (data) => {
|
||||
if (aasConsole) {
|
||||
aasConsole.update(data);
|
||||
writeFileSync('aa.json', JSON.stringify(aasConsole, null, 2));
|
||||
}
|
||||
});
|
||||
|
||||
port.write(Packets.START_LIVE);
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('app: shutting down');
|
||||
port.write(Packets.STOP_LIVE);
|
||||
port.close();
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "aas-cli",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"bin": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"aas-lib": "^0.1.0",
|
||||
"commander": "^11.1.0",
|
||||
"serialport": "^12.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user