Skip to content

Commit b003fa6

Browse files
committed
Fixing some bugs, cleaning up some formatting
1 parent da1c255 commit b003fa6

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

Modbus4J/src/com/serotonin/modbus4j/locator/NumericLocator.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,29 @@ public Number bytesToValueRealOffset(byte[] data, int offset) {
195195

196196
//MOD10K types
197197
if (dataType == DataType.FOUR_BYTE_MOD_10K)
198-
return BigInteger.valueOf((((data[offset+2] & 0xff) << 8) + (data[offset + 3]& 0xff)) )
199-
.multiply(BigInteger.valueOf(10000L)).add(BigInteger.valueOf((((data[offset]& 0xff) << 8) + (data[offset+1]& 0xff))));
198+
return BigInteger.valueOf((((data[offset + 2] & 0xff) << 8) + (data[offset + 3] & 0xff))).multiply(BigInteger.valueOf(10000L))
199+
.add(BigInteger.valueOf((((data[offset ] & 0xff) << 8) + (data[offset + 1] & 0xff))));
200200
if (dataType == DataType.FOUR_BYTE_MOD_10K_SWAPPED)
201-
return BigInteger.valueOf((((data[offset]& 0xff) << 8) + (data[offset+1]& 0xff)))
202-
.multiply(BigInteger.valueOf(10000L)).add(BigInteger.valueOf((((data[offset+2]& 0xff) << 8) + (data[offset+3]& 0xff))));
201+
return BigInteger.valueOf((((data[offset ] & 0xff) << 8) + (data[offset + 1] & 0xff))).multiply(BigInteger.valueOf(10000L))
202+
.add(BigInteger.valueOf((((data[offset + 2] & 0xff) << 8) + (data[offset + 3] & 0xff))));
203203
if (dataType == DataType.SIX_BYTE_MOD_10K)
204-
return BigInteger.valueOf((((data[offset+4] & 0xff) << 8) + (data[offset + 5]& 0xff))).multiply(BigInteger.valueOf(100000000L)).add(BigInteger.valueOf((((data[offset+2] & 0xff) << 8) + (data[offset + 3]& 0xff)))
205-
.multiply(BigInteger.valueOf(10000L))).add(BigInteger.valueOf((((data[offset] & 0xff) << 8) + (data[offset + 1]& 0xff))));
204+
return BigInteger.valueOf((((data[offset + 4] & 0xff) << 8) + (data[offset + 5] & 0xff))).multiply(BigInteger.valueOf(100000000L))
205+
.add(BigInteger.valueOf((((data[offset + 2] & 0xff) << 8) + (data[offset + 3] & 0xff))).multiply(BigInteger.valueOf(10000L)))
206+
.add(BigInteger.valueOf((((data[offset ] & 0xff) << 8) + (data[offset + 1] & 0xff))));
206207
if (dataType == DataType.SIX_BYTE_MOD_10K_SWAPPED)
207-
return BigInteger.valueOf((((data[offset] & 0xff) << 8) + (data[offset + 1]& 0xff))).multiply(BigInteger.valueOf(100000000L)).add(BigInteger.valueOf((((data[offset+2] & 0xff) << 8) + (data[offset + 3]& 0xff)))
208-
.multiply(BigInteger.valueOf(10000L))).add(BigInteger.valueOf((((data[offset] & 0xff) << 8) + (data[offset + 1]& 0xff))));
208+
return BigInteger.valueOf((((data[offset ] & 0xff) << 8) + (data[offset + 1] & 0xff))).multiply(BigInteger.valueOf(100000000L))
209+
.add(BigInteger.valueOf((((data[offset + 2] & 0xff) << 8) + (data[offset + 3] & 0xff))).multiply(BigInteger.valueOf(10000L)))
210+
.add(BigInteger.valueOf((((data[offset + 4] & 0xff) << 8) + (data[offset + 5] & 0xff))));
209211
if (dataType == DataType.EIGHT_BYTE_MOD_10K)
210-
return BigInteger.valueOf((((data[offset+6] & 0xff) << 8) + (data[offset + 7]& 0xff))).multiply(BigInteger.valueOf(1000000000000L)).add(BigInteger.valueOf((((data[offset+4] & 0xff) << 8) + (data[offset + 5]& 0xff)))
211-
.multiply(BigInteger.valueOf(100000000L))).add(BigInteger.valueOf((((data[offset+2] & 0xff) << 8) + (data[offset + 3]& 0xff))).multiply(BigInteger.valueOf(10000L)))
212-
.add(BigInteger.valueOf((((data[offset] & 0xff) << 8) + (data[offset + 1]& 0xff))));
212+
return BigInteger.valueOf((((data[offset + 6] & 0xff) << 8) + (data[offset + 7] & 0xff))).multiply(BigInteger.valueOf(1000000000000L))
213+
.add(BigInteger.valueOf((((data[offset + 4] & 0xff) << 8) + (data[offset + 5] & 0xff))).multiply(BigInteger.valueOf(100000000L)))
214+
.add(BigInteger.valueOf((((data[offset + 2] & 0xff) << 8) + (data[offset + 3] & 0xff))).multiply(BigInteger.valueOf(10000L)))
215+
.add(BigInteger.valueOf((((data[offset ] & 0xff) << 8) + (data[offset + 1] & 0xff))));
213216
if (dataType == DataType.EIGHT_BYTE_MOD_10K_SWAPPED)
214-
return BigInteger.valueOf((((data[offset] & 0xff) << 8) + (data[offset + 1]& 0xff))).multiply(BigInteger.valueOf(1000000000000L)).add(BigInteger.valueOf((((data[offset+2] & 0xff) << 8) + (data[offset + 3]& 0xff)))
215-
.multiply(BigInteger.valueOf(100000000L))).add(BigInteger.valueOf((((data[offset+4] & 0xff) << 8) + (data[offset + 5]& 0xff))).multiply(BigInteger.valueOf(10000L)))
216-
.add(BigInteger.valueOf((((data[offset+6] & 0xff) << 8) + (data[offset + 7]& 0xff))));
217+
return BigInteger.valueOf((((data[offset ] & 0xff) << 8) + (data[offset + 1] & 0xff))).multiply(BigInteger.valueOf(1000000000000L))
218+
.add(BigInteger.valueOf((((data[offset + 2] & 0xff) << 8) + (data[offset + 3] & 0xff))).multiply(BigInteger.valueOf(100000000L)))
219+
.add(BigInteger.valueOf((((data[offset + 4] & 0xff) << 8) + (data[offset + 5] & 0xff))).multiply(BigInteger.valueOf(10000L)))
220+
.add(BigInteger.valueOf((((data[offset + 6] & 0xff) << 8) + (data[offset + 7] & 0xff))));
217221

218222
// 8 bytes
219223
if (dataType == DataType.EIGHT_BYTE_INT_UNSIGNED) {
@@ -342,19 +346,19 @@ public short[] valueToShorts(Number value) {
342346
long l = value.longValue();
343347
return new short[] { (short) (l%10000), (short) ((l/10000)%10000)};
344348
}
345-
if (dataType == DataType.SIX_BYTE_MOD_10K) {
349+
if (dataType == DataType.SIX_BYTE_MOD_10K_SWAPPED) {
346350
long l = value.longValue();
347351
return new short[] { (short) ((l/100000000L)%10000), (short) ((l/10000)%10000), (short) (l%10000) };
348352
}
349-
if (dataType == DataType.SIX_BYTE_MOD_10K_SWAPPED) {
353+
if (dataType == DataType.SIX_BYTE_MOD_10K) {
350354
long l = value.longValue();
351355
return new short[] { (short) (l%10000), (short) ((l/10000)%10000), (short)((l/100000000L)%10000)};
352356
}
353-
if (dataType == DataType.EIGHT_BYTE_MOD_10K) {
357+
if (dataType == DataType.EIGHT_BYTE_MOD_10K_SWAPPED) {
354358
long l = value.longValue();
355359
return new short[] { (short)((l/1000000000000L)%10000), (short) ((l/100000000L)%10000), (short) ((l/10000)%10000), (short) (l%10000) };
356360
}
357-
if (dataType == DataType.EIGHT_BYTE_MOD_10K_SWAPPED) {
361+
if (dataType == DataType.EIGHT_BYTE_MOD_10K) {
358362
long l = value.longValue();
359363
return new short[] { (short) (l%10000), (short) ((l/10000)%10000), (short)((l/100000000L)%10000), (short)((l/1000000000000L)%10000)};
360364
}

0 commit comments

Comments
 (0)