CosDpValueStruct value = new CosDpValueStruct();
value.timestamp = 0;
value.quality = CosDpQualityEnum.QualityGood;
// update the value
DataPoint dp = null;
// int dpWordAddress = 0;
boolean boolValue = false;
long intValue = 0;
String strValue = "";
double dblValue = 0;
for (int i = 0; i < datapoints.size(); i++)
{
dp = datapoints.get(i);
if (dp == null)
{
continue;
}
switch (dp.getSourceType())
{
case TYPE_DI:
boolValue = BufferParser.getBooleanValue(values, dp
.getAddress()
- offset, dp.getBitAddress());
value.value.boolValue(boolValue);
break;
case TYPE_INT16:
intValue = BufferParser.getLongValue(values, dp
.getAddress()
- offset, 2, false);
value.value.longValue((int) intValue);
break;
case TYPE_INT32:
intValue = BufferParser.getLongValue(values, dp
.getAddress()
- offset, 4, false);
value.value.longValue((int) intValue);
break;
case TYPE_UINT16:
intValue = BufferParser.getLongValue(values, dp
.getAddress()
- offset, 2, true);
value.value.unsignedValue((int) intValue);
break;
case TYPE_UINT32:
intValue = BufferParser.getLongValue(values, dp
.getAddress()
- offset, 4, true);
value.value.unsignedValue((int) intValue);
break;
case TYPE_BCD:
intValue = BufferParser.getBcdValue(values, dp.getAddress()
- offset, dp.getLength() / 2);
value.value.longValue((int) intValue);
break;
case TYPE_IEEE16:
dblValue = BufferParser.getDoubleValue(values, dp
.getAddress()
- offset, 2);
value.value.dblValue(dblValue);
break;
case TYPE_IEEE32:
dblValue = BufferParser.getDoubleValue(values, dp
.getAddress()
- offset, 4);
value.value.dblValue(dblValue);
break;
case TYPE_STRING:
strValue = BufferParser.getStringValue(values, dp
.getAddress()
- offset, dp.getLength() / 2);
value.value.charValue(strValue);
break;
}
// set the dp value
if (dp.setSourceValue(value) < 0)
{
logger.warn("Can not update source value of datapoint "
+ dp.name);
}
}