Skip to content

Commit

Permalink
Merge pull request #1 from jpilet/jp-src-addr
Browse files Browse the repository at this point in the history
Pass source address to the packet reception callback
jonasseglare committed Mar 3, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 534bace + 6aaec3f commit aba7798
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ coverage

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
build/Debug

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
@@ -35,3 +36,5 @@ node_modules

# vim
.*sw[po]

tags
4 changes: 3 additions & 1 deletion src/j1939socket.cc
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ class Packet {
snprintf(str, sizeof(str), "%0llx", (unsigned long long) src_.can_addr.j1939.name);
Local<String> srcName = Nan::New<String>(str).ToLocalChecked();
Local<Number> pgn = Nan::New<Number>(src_.can_addr.j1939.pgn);
Local<Number> addr = Nan::New<Number>(src_.can_addr.j1939.addr);
Local<Date> timestamp =
Nan::New<Date>(time_.tv_sec * 1000.0
+ time_.tv_usec / 1000.0).ToLocalChecked();
@@ -71,7 +72,8 @@ class Packet {
srcName,
pgn,
priority,
dstAddr
dstAddr,
addr
};
// buffer will be garbage collected by v8
data_ = 0;
6 changes: 4 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var socket = require('./main');

socket.open( function (data, timestamp, srcName, pgn, priority, dstAddr) {
console.log("t:" + timestamp + " s:" + srcName + " pgn:" + pgn + " d:" + dstAddr);
socket.open(function (data, timestamp, srcName,
pgn, priority, dstAddr, srcAddr) {
console.log("t:" + timestamp + " s:" + srcName + " pgn:" + pgn
+ "src: " + srcAddr + " d:" + dstAddr);
console.warn(data);
}
);

0 comments on commit aba7798

Please sign in to comment.