Skip to content

Commit 5a7ae65

Browse files
committed
Include notifier
1 parent d8e0276 commit 5a7ae65

File tree

8 files changed

+33
-5
lines changed

8 files changed

+33
-5
lines changed

dist/binding.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export declare const readStreamSession: (descriptor: string, sessionHandle: numb
2525
export declare const closeStreamSession: (descriptor: string, sessionHandle: number) => number;
2626
export declare const getCANDetailStatus: (descriptor: string) => CanDeviceStatus;
2727
export declare const sendCANMessage: (descriptor: string, messageId: number, messageData: number[], repeatPeriod: number) => number;
28+
export declare const waitForNotifierAlarm: (time: number) => void;

dist/binding.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.sendCANMessage = exports.getCANDetailStatus = exports.closeStreamSession = exports.readStreamSession = exports.openStreamSession = exports.receiveMessage = exports.unregisterDeviceFromHAL = exports.registerDeviceToHAL = exports.getDevices = void 0;
3+
exports.waitForNotifierAlarm = exports.sendCANMessage = exports.getCANDetailStatus = exports.closeStreamSession = exports.readStreamSession = exports.openStreamSession = exports.receiveMessage = exports.unregisterDeviceFromHAL = exports.registerDeviceToHAL = exports.getDevices = void 0;
44
var util_1 = require("util");
55
var addon = require('bindings')('addon');
66
exports.getDevices = addon.getDevices;
@@ -12,3 +12,4 @@ exports.readStreamSession = addon.readStreamSession;
1212
exports.closeStreamSession = addon.closeStreamSession;
1313
exports.getCANDetailStatus = addon.getCANDetailStatus;
1414
exports.sendCANMessage = addon.sendCANMessage;
15+
exports.waitForNotifierAlarm = addon.waitForNotifierAlarm;

lib/binding.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ export const readStreamSession: (descriptor:string, sessionHandle:number, messag
3333
CanMessage[] = addon.readStreamSession;
3434
export const closeStreamSession: (descriptor:string, sessionHandle:number) => number = addon.closeStreamSession;
3535
export const getCANDetailStatus: (descriptor:string) => CanDeviceStatus = addon.getCANDetailStatus;
36-
export const sendCANMessage: (descriptor:string, messageId: number, messageData: number[], repeatPeriod: number) => number = addon.sendCANMessage;
36+
export const sendCANMessage: (descriptor:string, messageId: number, messageData: number[], repeatPeriod: number) => number = addon.sendCANMessage;
37+
export const waitForNotifierAlarm: (time:number) => void = addon.waitForNotifierAlarm;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-can-bridge",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"author": "REV Robotics",
55
"description": "Get CAN Data",
66
"license": "MIT",

src/addon.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
2020
Napi::Function::New(env, getCANDetailStatus));
2121
exports.Set(Napi::String::New(env, "sendCANMessage"),
2222
Napi::Function::New(env, sendCANMessage));
23+
exports.Set(Napi::String::New(env, "waitForNotifierAlarm"),
24+
Napi::Function::New(env, waitForNotifierAlarm));
2325
return exports;
2426
}
2527

src/canWrapper.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,15 @@ Napi::Number sendCANMessage(const Napi::CallbackInfo& info) {
359359
rev::usb::CANMessage* message = new rev::usb::CANMessage(messageId, messageData, dataParam.Length());
360360
rev::usb::CANStatus status = deviceIterator->second->SendCANMessage(*message, repeatPeriodMs);
361361
return Napi::Number::New(env, (int)status);
362-
}
362+
}
363+
364+
void waitForNotifierAlarm(const Napi::CallbackInfo& info) {
365+
uint32_t time = info[0].As<Napi::Number>().Uint32Value();
366+
int32_t status;
367+
368+
uint32_t m_notifier = HAL_InitializeNotifier(&status);
369+
HAL_UpdateNotifierAlarm(m_notifier, HAL_GetFPGATime(&status) + time, &status);
370+
HAL_WaitForNotifierAlarm(m_notifier, &status);
371+
HAL_StopNotifier(m_notifier, &status);
372+
HAL_CleanNotifier(m_notifier, &status);
373+
}

src/canWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ Napi::Array readStreamSession(const Napi::CallbackInfo& info);
1111
Napi::Number closeStreamSession(const Napi::CallbackInfo& info);
1212
Napi::Object getCANDetailStatus(const Napi::CallbackInfo& info);
1313
Napi::Number sendCANMessage(const Napi::CallbackInfo& info);
14-
14+
void waitForNotifierAlarm(const Napi::CallbackInfo& info);
1515
#endif

test/test_binding.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,29 @@ async function testSendCANMessage() {
121121
}
122122
}
123123

124+
async function testWaitForNotifierAlarm() {
125+
try {
126+
const start = Date.now();
127+
addon.waitForNotifierAlarm(10000);
128+
console.log("Time passed:", Date.now() - start);
129+
} catch(error) {
130+
assert.fail(error);
131+
}
132+
}
133+
124134
process.on('uncaughtException', function (exception) {
125135
console.log(exception);
126136
});
127137

138+
128139
testGetDevices()
129140
.then(testReceiveMessage)
130141
.then(testOpenStreamSession)
131142
.then(testReadStreamSession)
132143
.then(testCloseStreamSession)
133144
.then(testGetCANDetailStatus)
134145
.then(testSendCANMessage)
146+
.then(testWaitForNotifierAlarm)
135147
.catch((error) => {
136148
console.log(error);
137149
});

0 commit comments

Comments
 (0)