Hey there,
I've managed to get the BACnet4J library running on my Android Things device ( a master on an MS/TP network), communicating with another BACnet device (another master). See my previous question for more info.
However, when I try to send a WhoIsRequest to the other device, it reads in the response and then my whole application crashes. Here is a log:
2018-09-27 17:11:57.831 5290-5316/my.company.peripheraltest D/UartOutputStream: bytes written: [55,ff,6,ff,11,0,4,1a,1,0,10,8,bc,f9]
2018-09-27 17:11:57.832 5290-5316/my.company.peripheraltest W/System.err: [BACnet4J MS/TP node] DEBUG com.serotonin.bacnet4j.npdu.mstp.MasterNode - 17 doneWithToken:SendMaintenancePFM
2018-09-27 17:11:57.846 5290-5316/my.company.peripheraltest D/UartOutputStream: bytes written: [55,ff,1,13,11,0,0,6f]
2018-09-27 17:11:57.867 5290-5316/my.company.peripheraltest W/System.err: [BACnet4J MS/TP node] DEBUG com.serotonin.bacnet4j.npdu.mstp.MasterNode - 17 pollForMaster:DoneWithPFM
2018-09-27 17:11:57.881 5290-5316/my.company.peripheraltest D/UartOutputStream: bytes written: [55,ff,0,18,11,0,0,35]
2018-09-27 17:11:57.893 5290-5290/my.company.peripheraltest D/UartInputStream: bytes read: [55,ff,6,ff,18,0,15,41]
2018-09-27 17:11:57.894 5290-5316/my.company.peripheraltest W/System.err: [BACnet4J MS/TP node] DEBUG com.serotonin.bacnet4j.npdu.mstp.MasterNode - 17 passToken:SawTokenUser
2018-09-27 17:11:57.902 5290-5290/my.company.peripheraltest D/UartInputStream: bytes read: [1,20,ff,ff,0,ff,10,0]
2018-09-27 17:11:57.910 5290-5290/my.company.peripheraltest D/UartInputStream: bytes read: [c4,2,0,0,7c,22,1,e0]
2018-09-27 17:11:57.921 5290-5290/my.company.peripheraltest D/UartInputStream: bytes read: [91,3,22,1,4,83,b8]
2018-09-27 17:11:57.923 5290-5316/my.company.peripheraltest W/System.err: [BACnet4J MS/TP node] DEBUG com.serotonin.bacnet4j.npdu.mstp.MasterNode - 17 idle:ReceivedDataNoReply
2018-09-27 17:11:57.925 5290-5316/my.company.peripheraltest W/System.err: [BACnet4J MS/TP node] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from local network. From=Address [networkNumber=0, macAddress=[18]], local=0
2018-09-27 17:11:57.929 5290-5316/my.company.peripheraltest W/System.err: [BACnet4J MS/TP node] DEBUG com.serotonin.bacnet4j.npdu.Network - Received NPDU from [18]: NPDU [from=Address [networkNumber=0, macAddress=[18]], linkService=null, queue=[10,0,c4,2,0,0,7c,22,1,e0,91,3,22,1,4]]
2018-09-27 17:11:57.933 5290-5290/my.company.peripheraltest D/UartInputStream: bytes read: [55,ff,1,1b,18,0,0,7f]
--------- beginning of crash
2018-09-27 17:11:57.936 5290-5317/my.company.peripheraltest A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x68 in tid 5317 (BACnet4J transp), pid 5290 (.peripheraltest)
2018-09-27 17:11:57.985 5322-5322/? I/crash_dump32: type=1400 audit(0.0:643): avc: denied { write } for name="trace_marker" dev="tracefs" ino=47 scontext=u:r:crash_dump:s0:c512,c768 tcontext=u:object_r:debugfs_tracing:s0 tclass=file permissive=1
2018-09-27 17:11:58.048 5323-5323/? I/crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
2018-09-27 17:11:58.049 196-196/? I//system/bin/tombstoned: received crash request for pid 5290
2018-09-27 17:11:58.050 5323-5323/? I/crash_dump32: performing dump of process 5290 (target tid = 5317)
2018-09-27 17:11:58.050 5323-5323/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2018-09-27 17:11:58.051 5323-5323/? A/DEBUG: Build fingerprint: 'Things/iot_rpi3/rpi3:8.1.0/OIM1.180327.056/4925377:userdebug/dev-keys'
2018-09-27 17:11:58.051 5323-5323/? A/DEBUG: Revision: '0'
2018-09-27 17:11:58.051 5323-5323/? A/DEBUG: ABI: 'arm'
2018-09-27 17:11:58.051 5323-5323/? A/DEBUG: pid: 5290, tid: 5317, name: BACnet4J transp >>> my.company.peripheraltest <<<
2018-09-27 17:11:58.051 5323-5323/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x68
2018-09-27 17:11:58.051 5323-5323/? A/DEBUG: Cause: null pointer dereference
...
The crash and dump are not very useful, but it does say that the cause is a null pointer dereference.
Although I can't reproduce it right now, sometimes when I run in debug mode in Android Studio, I get a different crash error:
2018-09-27 17:43:56.784 5998-6025/my.company.peripheraltest E/AndroidRuntime: FATAL EXCEPTION: BACnet4J transport for device 123
Process: my.company.peripheraltest, PID: 5998
java.lang.BootstrapMethodError: Exception from call site #50 bootstrap method
at com.serotonin.bacnet4j.service.unconfirmed.IAmRequest.handle(IAmRequest.java:109)
at com.serotonin.bacnet4j.transport.DefaultTransport.receiveAPDU(DefaultTransport.java:645)
at com.serotonin.bacnet4j.transport.DefaultTransport.receiveImpl(DefaultTransport.java:573)
at com.serotonin.bacnet4j.transport.DefaultTransport.run(DefaultTransport.java:493)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.NoClassDefFoundError: Invalid descriptor: ([FLjava/util/Map;Lkotlin/jvm/functions/Function1;)Ljava/util/Map;.
at com.serotonin.bacnet4j.service.unconfirmed.IAmRequest.handle(IAmRequest.java:109)
at com.serotonin.bacnet4j.transport.DefaultTransport.receiveAPDU(DefaultTransport.java:645)
at com.serotonin.bacnet4j.transport.DefaultTransport.receiveImpl(DefaultTransport.java:573)
at com.serotonin.bacnet4j.transport.DefaultTransport.run(DefaultTransport.java:493)
at java.lang.Thread.run(Thread.java:764)
When I debug, I can get as far as line 109 of IAmRequest (in the handle
method). That line is:
localDevice.execute(() -> { ... });
So I think it's to do with the runnable or something that is happening within the runnable, but I'm not sure. It doesn't get to line 118, which fires the IAmReceived callback.
I've never seen this type of crash or error before, so any help would be appreciated. Maybe I'm just not setting everything up completely right.
Here is my code:
byte thermostatMACAddress = 17;
int networkNumber = 0;
int localDeviceId = 123;
UartInputStream ins = new UartInputStream(uartDevice);
UartOutputStream outs = new UartOutputStream(uartDevice, txControlPin);
MasterNode thermostatNode = new MasterNode("UART", ins, outs, thermostatMACAddress, 1);
MstpNetwork network = new MstpNetwork(thermostatNode, networkNumber);
DefaultTransport transport = new DefaultTransport(network);
localDevice = new LocalDevice(localDeviceId, transport);
try {
localDevice.initialize();
localDevice.getEventHandler().addListener(new Listener());
localDevice.sendLocalBroadcast(new WhoIsRequest());
} catch (Exception e) {
e.printStackTrace();
}