Commit 3baf2819 authored by Vincent van Beveren's avatar Vincent van Beveren

fixed readInt in DDMI value

parent de10b3e3
......@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import nl.nikhef.sfp.ddmi.DDMIMeta.BitFieldValue;
import nl.nikhef.tools.Utils;
public class DDMIValue extends DDMIElement {
......@@ -160,14 +161,15 @@ public class DDMIValue extends DDMIElement {
if (_length > 4) throw new AccessException("Can't interpret as integer");
byte[] d = readRaw(ctx);
if (d == null) return 0;
int l = d.length - 1;
int i = d[l];
l--;
while (l >= 0 ) {
i = (i << 8) | (0xFF & d[l]);
l--;
int v = d[0];
for (int i = 1; i < d.length; i++) {
v <<= 8;
v |= 0xFF & d[i];
}
return i;
return v;
}
public void writeInt(DDMIContext ctx, int v)
......@@ -242,7 +244,7 @@ public class DDMIValue extends DDMIElement {
break;
case DECIMAL_TYPE_UNSIGNED:
baseValue = readInt(ctx);
baseValue = 0xFFFFFFFFL & readInt(ctx);
break;
case DECIMAL_TYPE_SIGNED:
baseValue = readInt(ctx);
......@@ -251,6 +253,10 @@ public class DDMIValue extends DDMIElement {
break;
}
if (DDMIMeta.CONV.partOf(this)) {
baseValue = DDMIMeta.CONV.of(this).apply(baseValue);
}
return baseValue;
}
......@@ -270,7 +276,7 @@ public class DDMIValue extends DDMIElement {
case DECIMAL_TYPE_FLOAT:
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
return String.format("%f", readDecimal(ctx));
return String.format("%.3f", readDecimal(ctx));
default:
StringBuilder sb = new StringBuilder();
for (byte b : readRaw(ctx))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment