Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw telegram event #48

Merged
merged 7 commits into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ exports.Connection = Connection;
exports.Parser = Parser;
exports.createMessage = createMessage;
exports.str2addr = tools.str2addr;
exports.addr2str = tools.adr2str;
exports.addr2str = tools.addr2str;
21 changes: 17 additions & 4 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
var Readable = require('stream').Readable,
Decoder = require('./decoder'),
tools = require('./tools');

var isModernBuffer = (
typeof Buffer.alloc === 'function' &&
typeof Buffer.allocUnsafe === 'function' &&
typeof Buffer.from === 'function'
);

/**
* Parser
*/
Expand Down Expand Up @@ -71,12 +78,18 @@ Parser.prototype.parseTelegram = function(telegram) {

// value
var val = null;

val = telegram[telegram.length-1];
if(len > 8) {
var valbuffer;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing node api detection in one place

var isModernBuffer = (
  typeof Buffer.alloc === 'function' &&
  typeof Buffer.allocUnsafe === 'function' &&
  typeof Buffer.from === 'function'
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now in the head of the module.

if (len<=8) {
val = telegram[telegram.length-1];
valbuffer = isModernBuffer ? Buffer.from(val) : new Buffer([val]);
} else { //if(len > 8)
val = telegram.slice(10, telegram.length);
valbuffer = isModernBuffer ? Buffer.from(val) : new Buffer(val);
}


// emit raw telegram event, pass the addresses and the buffer, no DPT guessing, copy of data buffer
self.emit('telegram', event, tools.addr2str(src, false), tools.addr2str(dest, true), valbuffer);

self.decoder.decode(len, val, function(err, type, value) {

// emit action event
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eibd",
"version": "0.3.7",
"version": "0.3.8",
"description": "node eibd client",
"main": "./index",
"repository": {
Expand Down