Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
update deps, use promises
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAwesomeP committed Feb 5, 2017
1 parent b154542 commit 01c0834
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
upb-cli
upb-cli [![Gitter chat](https://img.shields.io/gitter/room/DaAwesomeP/upb-cli.js.svg?maxAge=2592000&style=flat-square)](https://gitter.im/DaAwesomeP/upb-cli)
=======
[![npm](http://img.shields.io/npm/v/upb-cli.svg?style=flat-square)](https://www.npmjs.org/package/upb-cli) [![npm](http://img.shields.io/npm/dm/upb-cli.svg?style=flat-square)](https://www.npmjs.org/package/upb-cli) [![David](https://img.shields.io/david/DaAwesomeP/upb-cli.svg?style=flat-square)](https://david-dm.org/DaAwesomeP/upb-cli) [![npm](http://img.shields.io/npm/l/upb-cli.svg?style=flat-square)](https://github.com/DaAwesomeP/upb-cli/blob/master/LICENSE) [![Gitter chat](https://badges.gitter.im/DaAwesomeP/upb-cli.png?style=flat-square)](https://gitter.im/DaAwesomeP/upb-cli)
[![npm](http://img.shields.io/npm/v/upb-cli.svg?style=flat-square)](https://www.npmjs.org/package/upb-cli) [![npm](http://img.shields.io/npm/dm/upb-cli.svg?style=flat-square)](https://www.npmjs.org/package/upb-cli) [![David](https://img.shields.io/david/DaAwesomeP/upb-cli.svg?style=flat-square)](https://david-dm.org/DaAwesomeP/upb-cli) [![npm](http://img.shields.io/npm/l/upb-cli.svg?style=flat-square)](https://github.com/DaAwesomeP/upb-cli/blob/master/LICENSE)
---

A CLI interface to the UPB library that generates decodes UPB (Universal Powerline Bus) commands. **If you are looking for the NodeJS library version of this, then please see [node-upb](https://github.com/DaAwesomeP/node-upb/).**
Expand Down Expand Up @@ -173,8 +173,4 @@ I got most of the information the last three items listed on this Simply Automat
- **UPB System Description** - This PDF describes all parts of the UPB protocol.
- **UPB Command Wizard - Software** - This program lets you build commands with a wizard/GUI and see the result. It does not actually send the command, but it is very valuable for understanding the commands without reading too much of the above PDF.
- **UPB Powerline Interface Module (PIM) - Description** - This PDF contains information about the PIM. It shows serial specifications (4800 baud 8-n-1) and PIM responses. It look me a while to figure out that the PIM always responds with `PE` whenever a command is not prefixed by the #20 character.
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/DaAwesomeP/upb-cli/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
- **UPB Powerline Interface Module (PIM) - Description** - This PDF contains information about the PIM. It shows serial specifications (4800 baud 8-n-1) and PIM responses. It look me a while to figure out that the PIM always responds with `PE` whenever a command is not prefixed by the #20 character.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
}
],
"dependencies": {
"async": "0.9.*",
"commander": "2.8.*",
"serialport": "1.7.*",
"upb": "1.2.*"
"async": "2.1.*",
"commander": "2.9.*",
"serialport": "4.0.*",
"upb": "2.0.*"
}
}
34 changes: 20 additions & 14 deletions upb-cli
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ var command = upb.defaultCommand;
command.action = "generate";

program
//.version(require("./package.json").version)
.version("1.0.0")
.version(require("./package.json").version)
.option('-e, --generate', 'Generates a UPB command and outputs the command or JSON. Use with all other arguments but --decode and --listCommands. This is on by default (for backwards compatibility with versions 1.0.x) unless --decode or --listCommands are specified.')
.option('-d, --decode [command]', 'Decodes a UPB command and outputs JSON. Ignores all other commands but --jsonStringify. Use with all other arguments but generate and listCommands THIS WILL NOT ERVIFY THE CHECKSUM!')
.option('--send', 'Set whether to actually send the command or just to generate it. Defaults to false.')
Expand Down Expand Up @@ -117,22 +116,21 @@ function consoleDebug(msg) {
}

if (command.action == "generate") {
upb.generate(command, function(commandNew, err) {
if (err) throw err;
upb.generate(command).then(function(commandNew) {
if (defaults.response.fullJSON == false) { console.log(commandNew.generated); }
else if (defaults.response.fullJSON == true && defaults.response.fullJSONstring == true) { console.log(JSON.stringify(commandNew)); }
else if (defaults.response.fullJSON == true) { console.log(commandNew); }
if (defaults.response.send == true) {
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var pim = new SerialPort(defaults.serial.port, {
var pim = new serialport(defaults.serial.port, {
baudrate: defaults.serial.baudrate,
databits: defaults.serial.databits,
parity: defaults.serial.parity,
stopbits: defaults.serial.stopbits,
buffersize: defaults.serial.buffersize,
parser: serialport.parsers.readline(defaults.serial.parser)
}, false); // Do not automatically open port
parser: serialport.parsers.readline(defaults.serial.parser),
autoOpen: false
}); // Do not automatically open port

pim.open(function (err) {
if (err) throw err;
Expand Down Expand Up @@ -163,14 +161,22 @@ if (command.action == "generate") {
});
});
}
});
}).catch(function (err) {
console.error(err);
});
}
else if (command.action == "decode") {
upb.decode(command.generated, function(commandNew, err) {
if (err) throw err + "\n" + JSON.stringify(commandNew);
if (defaults.response.fullJSONstring == true) { console.log(JSON.stringify(commandNew)); }
else { console.log(commandNew); }
});
if (command.generated === null || command.generated === "" || command.generated === true) {
console.error('No command specified!');
}
else {
upb.decode(command.generated).then(function(commandNew) {
if (defaults.response.fullJSONstring == true) { console.log(JSON.stringify(commandNew)); }
else { console.log(commandNew); }
}).catch(function (err) {
console.error(err);
});
}
}
else if (command.action == "listCommands") {
console.log(upb.validCommands);
Expand Down

0 comments on commit 01c0834

Please sign in to comment.