UNPKG

@csllc/j1939

Version:

J1939 transport layer for CANBUS communication

100 lines (66 loc) 1.76 kB
/** * Test address claiming protocol * * this needs work */ /* // Test helpers const assert = require('chai').assert; const expect = require('chai').expect; var sinon = require('sinon'); // Create interface to the device const J1939 = require('..'); class CanStub extends EventEmitter { constructor() { } // register another CanStub that will receive what we send connect( device ){ this.remoteDevice = device; } // Send a CAN message tx( msg ) { this.remoteDevice.rx( msg ); } // receive a CAN message rx( msg ) { this.emit( 'rx', msg ); } } let device1 = new CanStub(); let device2 = new CanStub(); // imagine the devices talk to each other device1.connectStub( device2 ); device2.connectStub( device1 ); before(function( done ) { done(); }); after(function( done ) { // runs after all tests in this block done(); }); beforeEach(function( done ) { // runs before each test in this block addressSpy = sinon.spy(); j1939.on('address', addressSpy); done(); }); afterEach(function( done ) { // runs after each test in this block done(); }); describe('Claim address', function() { it('should claim an unused address', function(done) { let j1939 = new J1939( device1, { preferredAddress: 1, }); //make sure our spy was fired once and only once expect(addressSpy.callCount).to.equal(1); //get the data from our spy call var spyCall = addressSpy.getCall(0); // should be successful expect(spyCall.args[1]).to.equal( j1939.CLAIM_SUCCESSFUL ); // should get the address we requested expect(spyCall.args[2]).to.equal( 1 ); }); }); */