Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retry setting the tx pgn list on ngt-1 #134

Merged
merged 1 commit into from
Oct 9, 2020
Merged
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
15 changes: 14 additions & 1 deletion lib/serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function SerialStream (options) {
this.reconnect = options.reconnect || true
this.serial = null
this.options = options
this.transmitPGNRetries = 2

this.transmitPGNs = defaultTransmitPGNs
if ( this.options.transmitPGNs ) {
Expand Down Expand Up @@ -351,12 +352,24 @@ function processNTGMessage(that, buffer, len)
})
debug('needed pgns: %j', that.neededTransmitPGNs)
} else if ( command === 0x49 && buffer[3] === 4 ) {
if ( that.neededTransmitPGNs.length ) {
//I think this means done receiving the pgns list
if ( !that.neededTransmitPGNs ) {
if ( that.transmitPGNRetries-- > 0 ) {
debug('did not get tx pgn list, retrying...')
that.serial.write(composeRequestTXPGNList())
} else {
const msg = 'could not set transmit pgn list'
that.options.app.setProviderStatus(msg)
console.warn(msg)
enableOutput(that)
}
} else if ( that.neededTransmitPGNs.length ) {
enableTXPGN(that.serial, that.neededTransmitPGNs[0])
} else {
enableOutput(that)
}
} else if ( command === 0x47 ) {
//response from enable a pgn
if ( buffer[3] === 1 ) {
debug('enabled %d', that.neededTransmitPGNs[0])
that.neededTransmitPGNs = that.neededTransmitPGNs.slice(1)
Expand Down