Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsw committed Oct 3, 2021
1 parent 338032a commit 6178ec7
Show file tree
Hide file tree
Showing 40 changed files with 4,185 additions and 1,120 deletions.
3 changes: 2 additions & 1 deletion .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"templates": {
"default": {
"useLongnameInNav": true
"useLongnameInNav": true,
"includeDate": false
}
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ CANopen see http://www.can-cia.org/

This library allows the manipulation of CANopen devices as defined in CiA 301.

## Documentation
Pre-built documentation is available here: https://daxbot.github.io/node-canopen/

## Protocols
### Emergency - EMCY
The CANopen emergency protocol is used to indicate internal errors with a
Expand Down
20 changes: 10 additions & 10 deletions docs/DataObject.html

Large diffs are not rendered by default.

51 changes: 33 additions & 18 deletions docs/Device.html

Large diffs are not rendered by default.

126 changes: 82 additions & 44 deletions docs/Eds.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/EdsError.html

Large diffs are not rendered by default.

157 changes: 119 additions & 38 deletions docs/Emcy.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/EmcyMessage.html

Large diffs are not rendered by default.

413 changes: 398 additions & 15 deletions docs/Lss.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/LssError.html

Large diffs are not rendered by default.

582 changes: 547 additions & 35 deletions docs/Nmt.html

Large diffs are not rendered by default.

1,101 changes: 1,089 additions & 12 deletions docs/Pdo.html

Large diffs are not rendered by default.

504 changes: 389 additions & 115 deletions docs/SdoClient.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/SdoError.html

Large diffs are not rendered by default.

393 changes: 370 additions & 23 deletions docs/SdoServer.html

Large diffs are not rendered by default.

45 changes: 33 additions & 12 deletions docs/Sync.html

Large diffs are not rendered by default.

37 changes: 28 additions & 9 deletions docs/Time.html

Large diffs are not rendered by default.

39 changes: 26 additions & 13 deletions docs/device.js.html

Large diffs are not rendered by default.

285 changes: 188 additions & 97 deletions docs/eds.js.html

Large diffs are not rendered by default.

228 changes: 2 additions & 226 deletions docs/global.html

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

119 changes: 57 additions & 62 deletions docs/protocol_emcy.js.html

Large diffs are not rendered by default.

46 changes: 33 additions & 13 deletions docs/protocol_lss.js.html

Large diffs are not rendered by default.

205 changes: 146 additions & 59 deletions docs/protocol_nmt.js.html

Large diffs are not rendered by default.

225 changes: 221 additions & 4 deletions docs/protocol_pdo.js.html

Large diffs are not rendered by default.

480 changes: 218 additions & 262 deletions docs/protocol_sdo.js.html

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions docs/protocol_sync.js.html

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions docs/protocol_time.js.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions examples/eds_creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
const { Eds, ObjectType, AccessType, DataType } = require('../index');
const os = require("os");

/** Step 1: Instantiate a new EDS object. */
// Step 1: Instantiate a new EDS object.
const eds = new Eds();

/** Step 2: Edit file info. */
// Step 2: Edit file info.
eds.fileName = 'example.eds';
eds.fileVersion = '1'
eds.fileRevision = '1'
eds.EDSVersion = '4.0'
eds.edsVersion = '4.0'
eds.description = 'An example EDS file';
eds.creationDate = new Date();
eds.createdBy = os.userInfo().username;

/** Step 3: Add entries. */
// Step 3: Add entries.
eds.addEntry(0x1016, {
parameterName: 'Consumer heartbeat time',
objectType: ObjectType.ARRAY,
Expand Down Expand Up @@ -53,5 +53,5 @@ eds.addEntry(0x2000, {
defaultValue: '00000000000000000000',
});

/** Step 4: Write to disk */
eds.save('example.eds');
// Step 4: Write to disk.
eds.save();
7 changes: 4 additions & 3 deletions examples/nmt_heartbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ channel.addListener('onMessage', (message) => device.receive(message));
device.setTransmitFunction((message) => channel.send(message));

device.init();
device.nmt.start();
channel.start();

// Step 5: Stop the node using NMT commands.
device.nmt.start();

setTimeout(() => {
device.nmt.stopNode(device.id);
// Step 5: Stop the node using NMT broadcast.
device.nmt.stopNode(0);
setTimeout(() => {
device.nmt.stop();
channel.stop();
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": "canopen",
"version": "3.0.1",
"version": "3.1.0",
"description": "CANopen implementation for Javascript",
"main": "index.js",
"scripts": {
Expand Down
33 changes: 23 additions & 10 deletions source/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { Pdo } = require('./protocol/pdo');
const { SdoClient, SdoServer } = require('./protocol/sdo');
const { Sync } = require('./protocol/sync');
const { Time } = require('./protocol/time');
const { Eds, DataObject } = require('./eds');
const { Eds, EdsError, DataObject } = require('./eds');

/**
* A CANopen device.
Expand All @@ -33,6 +33,17 @@ const { Eds, DataObject } = require('./eds');
* @fires 'sync' on consuming a synchronization object.
* @fires 'time' on consuming a time stamp object.
* @fires 'pdo' on updating a mapped pdo object.
* @example
* const can = require('socketcan');
*
* const channel = can.createRawChannel('can0');
* const device = new Device({ id: 0xa });
*
* channel.addListener('onMessage', (message) => device.receive(message));
* device.setTransmitFunction((message) => channel.send(message));
*
* device.init();
* channel.start();
*/
class Device extends EventEmitter {
constructor({ id, eds, loopback=false }) {
Expand Down Expand Up @@ -95,12 +106,14 @@ class Device extends EventEmitter {
}

/**
* Called with each outgoing CAN message.
* Called with each outgoing CAN message. This method should not be called
* directly - use the protocol objects instead.
*
* @param {object} message - CAN frame.
* @param {number} message.id - CAN message identifier.
* @param {Buffer} message.data - CAN message data;
* @param {number} message.len - CAN message length in bytes.
* @protected
*/
send(message) {
if(this._send === undefined)
Expand Down Expand Up @@ -131,7 +144,7 @@ class Device extends EventEmitter {
getValue(index) {
const entry = this.eds.getEntry(index);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

return entry.value;
}
Expand All @@ -146,7 +159,7 @@ class Device extends EventEmitter {
getValueArray(index, subIndex) {
const entry = this.eds.getSubEntry(index, subIndex);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

return entry.value;
}
Expand All @@ -160,7 +173,7 @@ class Device extends EventEmitter {
getRaw(index) {
const entry = this.eds.getEntry(index);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

return entry.raw;
}
Expand All @@ -175,7 +188,7 @@ class Device extends EventEmitter {
getRawArray(index, subIndex) {
const entry = this.eds.getSubEntry(index, subIndex);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

return entry.raw;
}
Expand All @@ -189,7 +202,7 @@ class Device extends EventEmitter {
setValue(index, value) {
const entry = this.eds.getEntry(index);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

entry.value = value;
}
Expand All @@ -204,7 +217,7 @@ class Device extends EventEmitter {
setValueArray(index, subIndex, value) {
const entry = this.eds.getSubEntry(index, subIndex);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

entry.value = value;
}
Expand All @@ -218,7 +231,7 @@ class Device extends EventEmitter {
setRaw(index, raw) {
const entry = this.eds.getEntry(index);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

entry.raw = raw;
}
Expand All @@ -233,7 +246,7 @@ class Device extends EventEmitter {
setRawArray(index, subIndex, raw) {
const entry = this.eds.getSubEntry(index, subIndex);
if(!entry)
throw ReferenceError("Entry does not exist");
throw new EdsError("Entry does not exist");

entry.raw = raw;
}
Expand Down
27 changes: 25 additions & 2 deletions source/eds.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ class DataObject extends EventEmitter {
}

/**
* Size of the raw data including sub-entries.
* Size of the raw data in bytes including sub-entries.
*
* @type {number}
*/
Expand Down Expand Up @@ -810,6 +810,26 @@ class DataObject extends EventEmitter {
* This class provides methods for loading and saving CANopen EDS v4.0 files.
*
* @see CiA306 "Electronic data sheet specification for CANopen"
* @example
* const eds = new Eds();
*
* eds.fileName = 'example.eds';
* eds.fileVersion = '1'
* eds.fileRevision = '1'
* eds.edsVersion = '4.0'
* eds.description = 'An example EDS file';
* eds.creationDate = new Date();
* eds.createdBy = 'node-canopen';
*
* eds.addEntry(0x1017, {
* parameterName: 'Producer heartbeat timer',
* objectType: ObjectType.VAR,
* dataType: DataType.UNSIGNED32,
* accessType: AccessType.READ_WRITE,
* defaultValue: 500,
* });
*
* eds.save();
*/
class Eds {
constructor() {
Expand Down Expand Up @@ -927,9 +947,12 @@ class Eds {
/**
* Write an EDS file.
*
* @param {string} path - path to file.
* @param {string} [path] - path to file, defaults to fileName.
*/
save(path) {
if(!path)
path = this.fileName;

const fd = fs.openSync(path, 'w');

// Write header fields
Expand Down
16 changes: 15 additions & 1 deletion source/protocol/emcy.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,21 @@ class EmcyMessage {
*
* @param {Device} device - parent device.
* @see CiA301 "Emergency object" (§7.2.7)
* @protected
* @example
* const can = require('socketcan');
*
* const channel = can.createRawChannel('can0');
* const device = new Device({ id: 0xa });
*
* channel.addListener('onMessage', (message) => device.receive(message));
* device.setTransmitFunction((message) => channel.send(message));
*
* device.emcy.cobId = 0x80;
*
* device.init();
* channel.start();
*
* device.emcy.write(0x1000);
*/
class Emcy {
constructor(device) {
Expand Down
1 change: 0 additions & 1 deletion source/protocol/lss.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class LssError extends Error {
*
* @param {Device} device - parent device.
* @see CiA305 "Layer Settings Services and Protocol (LSS)"
* @protected
*/
class Lss {
constructor(device) {
Expand Down
40 changes: 33 additions & 7 deletions source/protocol/nmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,21 @@ const NmtCommand = {
*
* @param {Device} device - parent device.
* @see CiA301 "Network management" (§7.2.8)
* @protected
* @example
* const can = require('socketcan');
*
* const channel = can.createRawChannel('can0');
* const device = new Device({ id: 0xa });
*
* channel.addListener('onMessage', (message) => device.receive(message));
* device.setTransmitFunction((message) => channel.send(message));
*
* device.nmt.producerTime = 500;
*
* device.init();
* channel.start();
*
* device.nmt.start();
*/
class Nmt {
constructor(device) {
Expand Down Expand Up @@ -234,6 +248,10 @@ class Nmt {
if(this.producerTime == 0)
throw TypeError('Producer heartbeat time can not be 0.')

// Switch to NmtState.OPERATIONAL
this.startNode();

// Start heartbeat timer
this.timers[this.device.id] = setInterval(() => {
this._sendHeartbeat();
}, this.producerTime);
Expand All @@ -249,7 +267,7 @@ class Nmt {
*
* Change the state of NMT slave(s) to NMT state operational.
*
* @param {number} nodeId - id of node or 0 for broadcast.
* @param {number} [nodeId] - id of node or 0 for broadcast.
* @see CiA301 "Service start remote node" (§7.2.8.2.1.2)
*/
startNode(nodeId) {
Expand All @@ -261,7 +279,7 @@ class Nmt {
*
* Change the state of NMT slave(s) to NMT state stopped.
*
* @param {number} nodeId - id of node or 0 for broadcast.
* @param {number} [nodeId] - id of node or 0 for broadcast.
* @see CiA301 "Service stop remote node" (§7.2.8.2.1.3)
*/
stopNode(nodeId) {
Expand All @@ -273,7 +291,7 @@ class Nmt {
*
* Change the state of NMT slave(s) to NMT state pre-operational.
*
* @param {number} nodeId - id of node or 0 for broadcast.
* @param {number} [nodeId] - id of node or 0 for broadcast.
* @see CiA301 "Service enter pre-operational" (§7.2.8.2.1.4)
*/
enterPreOperational(nodeId) {
Expand All @@ -285,7 +303,7 @@ class Nmt {
*
* Reset the application of NMT slave(s).
*
* @param {number} nodeId - id of node or 0 for broadcast.
* @param {number} [nodeId] - id of node or 0 for broadcast.
* @see CiA301 "Service reset node" (§7.2.8.2.1.5)
*/
resetNode(nodeId) {
Expand All @@ -297,7 +315,7 @@ class Nmt {
*
* Reset communication of NMT slave(s).
*
* @param {number} nodeId - id of node or 0 for broadcast.
* @param {number} [nodeId] - id of node or 0 for broadcast.
* @see CiA301 "Service reset communication" (§7.2.8.2.1.6)
*/
resetCommunication(nodeId) {
Expand All @@ -312,8 +330,16 @@ class Nmt {
* @private
*/
_sendNmt(nodeId, command) {
if(nodeId == 0 || nodeId == this.device.id)
if(nodeId === undefined || nodeId === this.device.id) {
// Handle internally and return
this._handleNmt(command);
return;
}

if(nodeId === 0) {
// Broadcast
this._handleNmt(command);
}

this.device.send({
id: 0x0,
Expand Down
1 change: 0 additions & 1 deletion source/protocol/pdo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const { ObjectType, AccessType, DataType, EdsError, DataObject } = require('../e
*
* @param {Device} device - parent device.
* @see CiA301 "Process data objects (PDO)" (§7.2.2)
* @protected
*/
class Pdo {
constructor(device) {
Expand Down
1 change: 0 additions & 1 deletion source/protocol/sdo.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ class Queue {
*
* @param {Device} device - parent device.
* @see CiA301 'Service data object (SDO)' (§7.2.4)
* @protected
*/
class SdoClient {
constructor(device) {
Expand Down
Loading

0 comments on commit 6178ec7

Please sign in to comment.