Skip to content

Commit 1c59784

Browse files
committed
Tested address claims with 2 competing devices on the bus
1 parent d1083c6 commit 1c59784

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ The code was incorrectly emitting address claims in response to all address clai
2727
For some devices on the bus this would cause a reset resulting in the first message on the new address having incomplete data. Eg Em-Track B921 devices report no GPS Fix for the first message on a new address. This caused MFDs to report lost fix and in some cases lost AIS data.
2828

2929
The fixes.
30+
3031
* Only emit claim responses when the addresses are claimed by 2 devices.
3132
* parse the address claim message completely. Its a 8 byte little endian uint_64 and can be set by pointing to the message buffer on a little endian CPU.
3233
* Where the names are identical, due to incorrect configuration if the device instance field, ramdomly select a new device instance field in the CAN device name to recolve the conflict. Since the Can Name device instance field is not generally used
3334
to indicate the physical measurement instance (eg Battery Instance), and cant be set (no support for setting it over Can Group Functions), this doesnt matter.
3435

36+
37+
# Testing
38+
39+
Using a CandelLite USB-CAN bus adapter with socket can on a linux box. see testscripts/
40+
3541
# references
3642

3743
Details of ISO Address Claim https://copperhilltech.com/blog/sae-j1939-address-management-messages-request-for-address-claimed-and-address-claimed/
@@ -44,6 +50,6 @@ Details of ISO Address Claim https://copperhilltech.com/blog/sae-j1939-address-m
4450
* [x] Fix address claim race conditions
4551
* [x] Fix incorrect name encoding and decoding
4652
* [x] Deal with name clashes on address claims
47-
* [ ] Test triggering address claim
53+
* [x] Test triggering address claim
4854

4955

SmallNMEA2000.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class SNMEA2000DeviceInfo {
119119
deviceInformation.industryGroupAndSystemInstance = 0x80 | ((industryGroup&0x07)<<4) | (systemInstance&0x0f);
120120
};
121121
void setSerialNumber(uint32_t uniqueNumber) {
122-
Serial.print("Serial Number set to ");
122+
Serial.print(F("Serial Number set to "));
123123
Serial.println(uniqueNumber);
124124
deviceInformation.unicNumberAndManCode=(deviceInformation.unicNumberAndManCode&0xffe00000) | (uniqueNumber&0x1fffff);
125125
};
@@ -333,6 +333,22 @@ class SNMEA2000 {
333333
bool setupRXFilter();
334334
int getPgmSize(const char *str, int maxLen);
335335

336+
void print(tUnionDeviceInformation * devInfo) {
337+
Serial.print(F(" UniqueNumber:"));
338+
Serial.println(devInfo->unicNumberAndManCode&0x1fffff);
339+
Serial.print(F(" ManufacturersCode:"));
340+
Serial.println((devInfo->unicNumberAndManCode>>21)&0x7ff);
341+
Serial.print(F(" deviceInstance:"));
342+
Serial.println(devInfo->deviceInstance, DEC);
343+
Serial.print(F(" deviceFunction:"));
344+
Serial.println(devInfo->deviceFunction, DEC);
345+
Serial.print(F(" deviceClass:"));
346+
Serial.println((devInfo->deviceClass>>1)&0x7f, DEC);
347+
Serial.print(F(" industryGroup:"));
348+
Serial.println((devInfo->industryGroupAndSystemInstance>>4)&0x07, DEC);
349+
Serial.print(F(" systemInstance:"));
350+
Serial.println((devInfo->industryGroupAndSystemInstance>>4)&0x0f, DEC);
351+
};
336352

337353

338354
unsigned char deviceAddress;

testscripts/testISOAddressClaim.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# This script requires a working socketcan + canboat installation
4+
# need php cli installed.
5+
# I am using candellight CAN-USB adapter on a linux box. Wont work on OSX as it has no support
6+
# for device.
7+
# $ sudo ip link set can0 type can bitrate 250000
8+
# $ sudo ip link set up can0
9+
10+
target="${1:-255}"
11+
12+
addressClaim=$(php util/format-message ${target} request_pgn 60928)
13+
14+
echo "Will send reqests to target address ${target}"
15+
16+
17+
18+
candump can0 | candump2analyzer | analyzer | grep "60928" &
19+
sleep 2
20+
echo ${addressClaim} | socketcan-writer can0
21+
sleep 10
22+
echo ${addressClaim} | socketcan-writer can0
23+
sleep 10
24+
kill %1

testscripts/testISORequests.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# This script requires a working socketcan + canboat installation
4+
# I am using candellight CAN-USB adapter on a linux box. Wont work on OSX as it has no support
5+
# for device.
6+
7+
target="${1:-255}"
8+
9+
productInformation=$(php util/format-message ${target} request_pgn 126996)
10+
pgnList=$(php util/format-message ${target} request_pgn 126464)
11+
configurationInformation=$(php util/format-message ${target} request_pgn 126998)
12+
batteryConfigurationInformation=$(php util/format-message ${target} request_pgn 127513)
13+
14+
echo "Will send reqests to target address ${target}"
15+
16+
17+
18+
candump can0 | candump2analyzer | analyzer &
19+
sleep 2
20+
echo "## Sending ISO Request for Product Information as ${productInformation}"
21+
echo ${productInformation} | socketcan-writer can0
22+
sleep 5
23+
echo "## Sending ISO Request for PGN List as ${pgnList}"
24+
echo ${pgnList} | socketcan-writer can0
25+
sleep 5
26+
echo "## Sending ISO Request for Configuration Information as ${configurationInformation}"
27+
echo ${configurationInformation} | socketcan-writer can0
28+
sleep 5
29+
echo "## Sending ISO Request for Battery Configuration Information as ${batteryConfigurationInformation}"
30+
echo ${batteryConfigurationInformation} | socketcan-writer can0
31+
32+
sleep 5
33+
kill %1

0 commit comments

Comments
 (0)