Skip to content
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
3 changes: 2 additions & 1 deletion source/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ class Device extends EventEmitter {
* @param {number} message.id - CAN message identifier.
* @param {Buffer} message.data - CAN message data;
* @param {number} message.len - CAN message length in bytes.
* @returns {number} number of bytes sent or -1 for error
* @protected
*/
send(message) {
if(this._send === null)
throw ReferenceError("please call setTransmitFunction() first");

this._send(message);
return this._send(message);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion source/protocol/sdo.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ class SdoTransfer {
* Send a data buffer.
*
* @param {Buffer} data - data to send.
* @returns {number} Number of bits sent or -1 for error
*/
send(data) {
this.device.send({
return this.device.send({
id: this.cobId,
data: data,
});
Expand Down
14 changes: 12 additions & 2 deletions source/protocol/sdo_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class SdoClient {
this.servers = {};
this.transfers = {};
this._blockSize = 127;
// Minimum timeout for the sdo block download.
this._blockDownloadTimeout = 1;
}

/**
Expand Down Expand Up @@ -641,6 +643,10 @@ class SdoClient {
return;
}

if(this._blockDownloadTimeout > 1){
this._blockDownloadTimeout = this._blockDownloadTimeout >> 1;
}

const sendBuffer = Buffer.alloc(8);
const offset = 7 * (transfer.blockSequence
+ (transfer.blockCount * transfer.blockSize));
Expand All @@ -652,15 +658,19 @@ class SdoClient {
}

transfer.data.copy(sendBuffer, 1, offset, offset + 7);
transfer.send(sendBuffer);
const ret = transfer.send(sendBuffer);
if(ret < 0 ){
this._blockDownloadTimeout = this._blockDownloadTimeout << 8;
transfer.blockSequence -= 1
}
transfer.refresh();

if(transfer.blockFinished
|| transfer.blockSequence >= transfer.blockSize) {
clearInterval(transfer.blockInterval);
transfer.blockInterval = null;
}
});
}, this._blockDownloadTimeout);
}

/**
Expand Down