Skip to content

Commit

Permalink
feature: introduce optional canbus Mfg code, fixing canbus provider U…
Browse files Browse the repository at this point in the history
…niqueNumber logic (#1831)

Fixes #1831 .
  • Loading branch information
mrstas authored Jan 19, 2025
1 parent 70e5e71 commit f38b2e1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
30 changes: 23 additions & 7 deletions packages/server-admin-ui/src/views/ServerConfig/BasicProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,13 +794,29 @@ const NMEA2000 = (props) => {
)}
{(props.value.options.type === 'canbus' ||
props.value.options.type === 'canbus-canboatjs') && (
<TextInput
title="Interface"
name="options.interface"
helpText="Example: can0"
value={props.value.options.interface}
onChange={props.onChange}
/>
<div>
<TextInput
title="Interface"
name="options.interface"
helpText="Example: can0"
value={props.value.options.interface}
onChange={props.onChange}
/>
<TextInput
title="UniqueNumber"
name="options.uniqueNumber"
helpText="Example: any number from 1 to 2097151, will be equal to SerialNumber of a SignalK NMEA2000 device. Leave empty for random (default). Set a fixed value if you have problem with source identification on some B&G MFD's after SignalK restart."
value={props.value.options.uniqueNumber}
onChange={props.onChange}
/>
<TextInput
title="ManufacturerCode"
name="options.mfgCode"
helpText="Example: 999 - Unknown (default), 0 - Internal, or any other mabufacturer code to emulate. Leave empty for default 999. Set to 0 if you have problem with source identification on some B&G MFD's after SignalK restart."
value={props.value.options.mfgCode}
onChange={props.onChange}
/>
</div>
)}
{(props.value.options.type === 'ngt-1-canboatjs' ||
props.value.options.type === 'ikonvert-canboatjs' ||
Expand Down
19 changes: 14 additions & 5 deletions src/interfaces/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,20 @@ module.exports = function (app) {
]
}

if (
provider.options.type === 'canbus-canboatjs' &&
!provider.options.uniqueNumber
) {
provider.options.uniqueNumber = Math.floor(Math.random() * 2097151)
if (provider.options.type === 'canbus-canboatjs') {
const uniqueNumber = parseInt(provider.options.uniqueNumber, 10)
if (!isNaN(uniqueNumber)) {
provider.options.uniqueNumber = uniqueNumber
} else {
provider.options.uniqueNumber = Math.floor(Math.random() * 2097151)
}

const mfgCode = parseInt(provider.options.mfgCode, 10)
if (!isNaN(mfgCode)) {
provider.options.mfgCode = mfgCode
} else {
if (provider.options.mfgCode !== '') delete provider.options.mfgCode //if value is not empty or not a number then removing property
}
}

if (applyProviderSettings(updatedProvider, provider, res)) {
Expand Down

0 comments on commit f38b2e1

Please sign in to comment.