@@ -64,6 +64,16 @@ public void scanInit() {
64
64
resultAddrNext = 0 ;
65
65
}
66
66
67
+ public static byte digittohex ( int d ) {
68
+ if ( d >= 0 && d <= 9 ) {
69
+ return (byte ) ( '0' + d );
70
+ }
71
+ if ( d >= 10 && d <= 16 ) {
72
+ return (byte ) ( 'A' + ( d - 10 ));
73
+ }
74
+ return -1 ;
75
+ }
76
+
67
77
public static int hextodigit ( final byte c ) {
68
78
if ( c >= '0' && c <= '9' ) {
69
79
return c - '0' ;
@@ -199,6 +209,29 @@ public static int lineCheck( final byte [] hex, final int hexIdx) {
199
209
return hextobyte ( hex , hexIdx + 9 + count * 2 );
200
210
}
201
211
212
+ public static boolean setCheck ( byte [] hex , final int hexIdx ) {
213
+ int sum = calcSum (hex , hexIdx );
214
+ if (sum < 0 ) {
215
+ return false ;
216
+ }
217
+ int check = (sum == 0 ? 0 : (256 - sum ));
218
+ int count = hextobyte ( hex , hexIdx + 1 );
219
+ int checkIdx = hexIdx + 9 + count * 2 ;
220
+ hex [ checkIdx ] = digittohex (check / 16 );
221
+ hex [ checkIdx + 1 ] = digittohex (check % 16 );
222
+
223
+ int chk = irmHexUtils .lineCheck ( hex , hexIdx );
224
+ if ( chk < 0 ) {
225
+ return false ;
226
+ }
227
+ sum = irmHexUtils .calcSum ( hex , hexIdx );
228
+ sum = ( chk + sum ) % 256 ;
229
+ if ( sum != 0 ) {
230
+ return false ;
231
+ }
232
+ return true ;
233
+ }
234
+
202
235
public static boolean lineData ( final byte [] hex , final int hexIdx , byte [] data , final int idx ) {
203
236
int count = hextobyte ( hex , hexIdx + 1 );
204
237
if ( count < 0 )
@@ -339,7 +372,6 @@ public int scanForDataHex( byte [] datahex, final int hexBlock, final byte [] un
339
372
if ( !isUniversal || dataWanted ) {
340
373
long fullAddr = lastBaseAddr + lineAddr ;
341
374
if ( fullAddr + lineCount > scanAddrMin && fullAddr < scanAddrNext ) {
342
- // TODO support part lines?
343
375
if ( resultAddrMin > fullAddr ) {
344
376
resultAddrMin = fullAddr ;
345
377
}
@@ -350,6 +382,9 @@ public int scanForDataHex( byte [] datahex, final int hexBlock, final byte [] un
350
382
System .arraycopy (universalhex , lineHidx , datahex , hexSize , rlen );
351
383
datahex [hexSize + 7 ] = '0' ;
352
384
datahex [hexSize + 8 ] = '0' ;
385
+ if ( !setCheck ( datahex , hexSize )) {
386
+ return 0 ;
387
+ }
353
388
}
354
389
lastSize = hexSize ;
355
390
lastType = lineType ;
@@ -459,4 +494,4 @@ public boolean universalHexToApplicationHex( final byte [] universalHex, final i
459
494
scanAddrNext = mnp [1 ];
460
495
return scanForDataHex ( universalHex , hexBlock );
461
496
}
462
- };
497
+ };
0 commit comments