Skip to content

Commit

Permalink
fix: disabe the transmit limit on the ikonvert (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored May 19, 2020
1 parent 7a03686 commit 268eca5
Showing 1 changed file with 44 additions and 75 deletions.
119 changes: 44 additions & 75 deletions lib/ikonvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,96 +156,65 @@ iKonvertStream.prototype.getSetupCommands = function () {
txPgns = txPgns + `,${pgn}`
})

const setupCommands = [
'$PDGY,N2NET_OFFLINE:$PDGY,TEXT,Digital_Yacht_Navlink2',
'$PDGY,N2NET_MODE,15:$PDGY,ACK,N2NET_MODE',
`${txPgns}:$PDGY,ACK,TX_LIST`,
'$PDGY,N2NET_INIT,ALL:$PDGY,ACK,N2NET_INIT,ALL'
]
const setupCommands = [];

setupCommands.push('$PDGY,N2NET_OFFLINE:$PDGY,TEXT,Digital_Yacht_')
if ( this.isTcp ) {
setupCommands.push('$PDGY,N2NET_MODE,15:$PDGY,ACK,N2NET_MODE')
}
setupCommands.push('$PDGY,TX_LIMIT,OFF:$PDGY,') // NACK is ok with old firmware
setupCommands.push(`${txPgns}:$PDGY,ACK,TX_LIST`)
setupCommands.push('$PDGY,N2NET_INIT,ALL:$PDGY,ACK,N2NET_INIT,ALL')

return setupCommands
}

iKonvertStream.prototype._transform = function (chunk, encoding, done) {
let line = chunk.toString().trim()
line = line.substring(0, line.length) // take off the \r

if ( this.isTcp ) {
if ( line.startsWith('$PDGY,TEXT') ) {
debug(line)
} else if ( line.startsWith('$PDGY,NAK') ) {
let parts = line.split(',')
let msg = `NavLink2 error ${parts[2]}: ${parts[3]}`
console.error(msg)
this.setProviderError(msg)
}
if ( line.startsWith('$PDGY,TEXT') ) {
debug(line)
} else if ( line.startsWith('$PDGY,NAK') ) {
let parts = line.split(',')
let msg = `NavLink2 error ${parts[2]}: ${parts[3]}`
console.error(msg)
this.setProviderError(msg)
}

if ( !this.isSetup ) {
debug(line)
let command = this.setupCommands[this.state].split(':')
if ( !this.expecting ) {
this.sendString(command[0])
this.expecting = true
this.sentTime = Date.now()
debug(`Waiting for ${command[1]}`)
} else {
if ( line.startsWith(command[1]) ) {
this.state = this.state + 1

if ( this.state == this.setupCommands.length ) {
this.isSetup = true
this.cansend = true
debug('Setup completed')
} else {
command = this.setupCommands[this.state].split(':')
this.sendString(command[0])
this.expecting = true
this.sentTime = Date.now()
debug(`Waiting for ${command[1]}`)
}
} else if ( Date.now() - this.sentTime > 5000 ) {
debug(`Did not receive expected: ${command[1]}, retrying...`)
if ( !this.isSetup ) {
debug(line)
let command = this.setupCommands[this.state].split(':')
if ( !this.expecting ) {
this.sendString(command[0])
this.expecting = true
this.sentTime = Date.now()
debug(`Waiting for ${command[1]}`)
} else {
if ( line.startsWith(command[1]) ) {
this.state = this.state + 1

if ( this.state == this.setupCommands.length ) {
this.isSetup = true
this.cansend = true
debug('Setup completed')
} else {
command = this.setupCommands[this.state].split(':')
this.sendString(command[0])
this.expecting = true
this.sentTime = Date.now()
debug(`Waiting for ${command[1]}`)
}
} else if ( Date.now() - this.sentTime > 5000 ) {
debug(`Did not receive expected: ${command[1]}, retrying...`)
this.sendString(command[0])
this.sentTime = Date.now()
}
} else {
this.push(line)
}

} else {
if ( line.startsWith('$PDGY') ) {
if ( line === '$PDGY,000000,,,,,,' ) {
//the iKonvert is not initialized
if ( !this.didSetup ) {
this.setup()
this.setProviderStatus('Initializing...')
this.didSetup = true
}
} else if ( line === '$PDGY,ACK,TX_LIST' ) {
debug('sending net init')
this.sendString('$PDGY,N2NET_INIT,ALL')
this.setProviderStatus('Initialized...')
} else if ( line === '$PDGY,ACK,N2NET_INIT,ALL' && !this.cansend ) {
this.cansend = true;
this.options.app.emit('nmea2000OutAvailable')
//this.sendString('$PDGY,SHOW_LISTS')
} else if ( line.startsWith('$PDGY,TEXT') ) {
debug(line)
} else if ( line.startsWith('$PDGY,000000') ) {
let parts = line.split(',')
debug('ikonvert can address: %s', parts[6])
debug(line)
} else if ( line.startsWith('$PDGY,NAK') ) {
let parts = line.split(',')
let msg = `iKonvert error ${parts[2]}: ${parts[3]}`
console.error(msg)
this.setProviderError(msg)
}
} else {
this.push(line)
}
this.push(line)
}

done()
}

Expand Down

0 comments on commit 268eca5

Please sign in to comment.