@@ -72,9 +72,9 @@ private static String arrayToHexString(byte[] value) {
7272 }
7373
7474 StringBuilder builder = new StringBuilder ();
75- builder .append (String .format ("[%02x" , value [0 ]));
75+ builder .append (String .format ("[0x %02x" , value [0 ]));
7676 for (int i = 1 ; i < value .length ; i ++) {
77- builder .append (String .format (", %02x" , value [i ]));
77+ builder .append (String .format (", 0x %02x" , value [i ]));
7878 }
7979 builder .append ("]" );
8080
@@ -968,7 +968,7 @@ protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
968968 byte second = (byte ) ((DataSignalImpl .this .outputSize - 1 ) & 0x3 | (isSigned () ? 0x4 : 0 ) |
969969 (params .mode .ordinal () << 3 ));
970970 ByteBuffer buffer = ByteBuffer .allocate (8 ).order (ByteOrder .LITTLE_ENDIAN );
971- Number firmwareValue = numberToFirmwareUnits (thsConfig .limit ), firmwareHysteresis = numberToFirmwareUnits (thsConfig .hysteresis );
971+ Number firmwareValue = parent . numberToFirmwareUnits (thsConfig .limit ), firmwareHysteresis = parent . numberToFirmwareUnits (thsConfig .hysteresis );
972972 buffer .put ((byte ) 0xd ).put (second ).putInt (firmwareValue .intValue ()).putShort (firmwareHysteresis .shortValue ());
973973
974974 return buffer .array ();
@@ -1054,7 +1054,7 @@ protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
10541054 ///< Do not allow the delta mode to be changed
10551055 byte second = (byte ) (((this .outputSize - 1 ) & 0x3 ) | (isSigned () ? 0x4 : 0 ) |
10561056 (params .mode .ordinal () << 3 ));
1057- Number firmware = numberToFirmwareUnits (deltaConfig .threshold );
1057+ Number firmware = parent . numberToFirmwareUnits (deltaConfig .threshold );
10581058 ByteBuffer config = ByteBuffer .allocate (6 ).order (ByteOrder .LITTLE_ENDIAN ).put ((byte ) 0xc ).put (second ).putInt (firmware .intValue ());
10591059 return config .array ();
10601060
@@ -1366,7 +1366,7 @@ public byte[] getFilterConfig() {
13661366 @ Override
13671367 protected byte [] processorConfigToBytes (ProcessorConfig newConfig ) {
13681368 Pulse pulseConfig = (Pulse ) newConfig ;
1369- Number firmwareThs = numberToFirmwareUnits (pulseConfig .threshold );
1369+ Number firmwareThs = parent . numberToFirmwareUnits (pulseConfig .threshold );
13701370
13711371 ///< Do not allow output type to switch
13721372 ByteBuffer buffer = ByteBuffer .allocate (10 ).put ((byte ) 0xb ).put (parent .outputSize ).put ((byte ) 0 ).put ((byte ) params .mode .ordinal ())
@@ -1557,7 +1557,7 @@ public void setState(State newState) {
15571557 } else if (newState instanceof Average .State ) {
15581558 stateBytes = new byte [0 ];
15591559 } else if (newState instanceof Delta .State ) {
1560- Number firmware = numberToFirmwareUnits (((Delta .State ) newState ).newPreviousValue );
1560+ Number firmware = parent . numberToFirmwareUnits (((Delta .State ) newState ).newPreviousValue );
15611561
15621562 stateBytes = ByteBuffer .allocate (4 ).order (ByteOrder .LITTLE_ENDIAN ).putInt (firmware .intValue ()).array ();
15631563 } else if (newState instanceof Passthrough .State ) {
@@ -1744,6 +1744,11 @@ protected byte[] processorConfigToBytes(ProcessorConfig newConfig) {
17441744 rmsMode };
17451745 }
17461746
1747+ @ Override
1748+ public Number numberToFirmwareUnits (Number input ) {
1749+ return parent .numberToFirmwareUnits (input );
1750+ }
1751+
17471752 @ Override
17481753 public boolean isSigned () {
17491754 return false ;
@@ -2279,7 +2284,9 @@ protected DefaultMetaWearBoard(final Connection conn) {
22792284 final ResponseProcessor idProcessor = new ResponseProcessor () {
22802285 @ Override
22812286 public Response process (byte [] response ) {
2282- pendingRoutes .peek ().receivedId (response [2 ]);
2287+ if (!pendingRoutes .isEmpty ()) {
2288+ pendingRoutes .peek ().receivedId (response [2 ]);
2289+ }
22832290 return null ;
22842291 }
22852292 };
@@ -2297,7 +2304,9 @@ public Response process(byte[] response) {
22972304 responses .put (new ResponseHeader (EventRegister .ENTRY ), new ResponseProcessor () {
22982305 @ Override
22992306 public Response process (byte [] response ) {
2300- currEventListener .receivedCommandId (response [2 ]);
2307+ if (currEventListener != null ) {
2308+ currEventListener .receivedCommandId (response [2 ]);
2309+ }
23012310 return null ;
23022311 }
23032312 });
@@ -2354,9 +2363,9 @@ public Response process(byte[] response) {
23542363 @ Override
23552364 public Response process (byte [] response ) {
23562365 try {
2357- byte [] respBody = new byte [response .length - 3 ];
2366+ byte [] respBody = new byte [response .length - 3 ];
23582367 System .arraycopy (response , 3 , respBody , 0 , respBody .length );
2359- ResponseHeader header = new ResponseHeader (response [0 ], response [1 ], response [2 ]);
2368+ ResponseHeader header = new ResponseHeader (response [0 ], response [1 ], response [2 ]);
23602369
23612370 if (bmi160AccMessageClasses .contains (dataProcMsgClasses .get (header ))) {
23622371 Constructor <?> cTor = dataProcMsgClasses .get (header ).getConstructor (byte [].class , float .class );
@@ -2370,6 +2379,8 @@ public Response process(byte[] response) {
23702379
23712380 Constructor <?> cTor = dataProcMsgClasses .get (header ).getConstructor (byte [].class );
23722381 return new Response ((Message ) cTor .newInstance (respBody ), header );
2382+ } catch (NullPointerException ex ) {
2383+ return null ;
23732384 } catch (Exception ex ) {
23742385 throw new RuntimeException ("Cannot create a message processor for filter output: " + Arrays .toString (response ), ex );
23752386 }
0 commit comments