use of org.openmuc.framework.data.ValueType in project OpenMUC by isc-konstanz.
the class LogFileHeader method appendChannelSpecificComment.
/**
* Appends channel specific comments to a StringBuilder
*
* @param sb
* @param logChannel
* @param colNumber
*/
private static void appendChannelSpecificComment(StringBuilder sb, LogChannel logChannel, int colNumber) {
String unit = logChannel.getUnit();
if (unit.equals("")) {
unit = "0";
}
ValueType vType = logChannel.getValueType();
String valueType = vType.toString();
int valueTypeLength = 0;
if (vType.equals(ValueType.BYTE_ARRAY) || vType.equals(ValueType.STRING)) {
valueTypeLength = logChannel.getValueTypeLength();
} else {
valueTypeLength = LoggerUtils.getLengthOfValueType(vType);
}
String description = logChannel.getDescription();
if (description.equals("")) {
description = "-";
}
createRow(sb, String.format("%03d", colNumber), logChannel.getId(), FALSE_STRING, TRUE_STRING, unit, OTHER_STRING, valueType, valueTypeLength, description);
}
use of org.openmuc.framework.data.ValueType in project OpenMUC by isc-konstanz.
the class LogFileWriter method getDataTypeSize.
/**
* Returns the size of a DataType / ValueType.
*
* @param logChannel
* @param iterator
* @return size of DataType / ValueType.
*/
private int getDataTypeSize(LogChannel logChannel, int iterator) {
int size;
if (logChannel != null) {
boolean isByteArray = logChannel.getValueType().equals(ValueType.BYTE_ARRAY);
boolean isString = logChannel.getValueType().equals(ValueType.STRING);
if (isString) {
// get length from channel for String / ByteArray
size = logChannel.getValueTypeLength();
} else if (isByteArray) {
size = Const.HEXADECIMAL.length() + logChannel.getValueTypeLength() * 2;
} else {
// get length from channel for simple value types
size = LoggerUtils.getLengthOfValueType(logChannel.getValueType());
}
} else {
// get length from file
ValueType vt = LoggerUtils.identifyValueType(iterator + Const.NUM_OF_TIME_TYPES_IN_HEADER + 1, actualFile);
size = LoggerUtils.getLengthOfValueType(vt);
if ((vt.equals(ValueType.BYTE_ARRAY) || (vt.equals(ValueType.STRING))) && size <= Const.VALUE_SIZE_MINIMAL) {
size = LoggerUtils.getValueTypeLengthFromFile(iterator + Const.NUM_OF_TIME_TYPES_IN_HEADER + 1, actualFile);
}
}
return size;
}
use of org.openmuc.framework.data.ValueType in project OpenMUC by isc-konstanz.
the class DriverConnection method fillDataRecordInChannelScanInfo.
private void fillDataRecordInChannelScanInfo(List<ChannelScanInfo> channelScanInfo, DataRecord dataRecord) {
String vib = Helper.bytesToHex(dataRecord.getVib());
String dib = Helper.bytesToHex(dataRecord.getDib());
ValueType valueType;
Integer valueLength;
switch(dataRecord.getDataValueType()) {
case STRING:
valueType = ValueType.STRING;
valueLength = 25;
break;
case LONG:
if (dataRecord.getMultiplierExponent() == 0) {
valueType = ValueType.LONG;
} else {
valueType = ValueType.DOUBLE;
}
valueLength = null;
break;
case DOUBLE:
case DATE:
valueType = ValueType.DOUBLE;
valueLength = null;
break;
case BCD:
if (dataRecord.getMultiplierExponent() == 0) {
valueType = ValueType.DOUBLE;
} else {
valueType = ValueType.LONG;
}
valueLength = null;
break;
case NONE:
default:
valueType = ValueType.BYTE_ARRAY;
valueLength = 100;
break;
}
String unit = "";
if (dataRecord.getUnit() != null) {
unit = dataRecord.getUnit().getUnit();
}
channelScanInfo.add(new ChannelScanInfo(dib + ':' + vib, getDescription(dataRecord), valueType, valueLength, true, true, "", unit));
}
use of org.openmuc.framework.data.ValueType in project OpenMUC by isc-konstanz.
the class IecConnection method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(int timeout) {
List<ChannelScanInfo> channelInfos = new LinkedList<>();
logger.debug("scanning channels");
try {
byte[] frame = receiver.receiveMessage(timeout);
ModeDMessage message = ModeDMessage.parse(frame);
List<String> dataSets = message.getDataSets();
for (String data : dataSets) {
DataSet dataSet = new DataSet(data);
String channelAddress = dataSet.getAddress();
String description = "Current value: " + dataSet.parseValueAsDouble() + dataSet.getUnit();
ValueType valueType = ValueType.DOUBLE;
Integer valueTypeLength = null;
Boolean readable = true;
Boolean writable = false;
ChannelScanInfo channelInfo = new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
channelInfos.add(channelInfo);
}
} catch (ParseException | IOException e) {
logger.warn("read failed", e);
}
return channelInfos;
}
use of org.openmuc.framework.data.ValueType in project OpenMUC by isc-konstanz.
the class SmlConnection method extractValueOf.
private static ValueContainer extractValueOf(SmlListEntry entry) {
double value = 0;
ValueType valueType = ValueType.DOUBLE;
ASNObject obj = entry.getValue().getChoice();
if (obj.getClass().equals(Integer64.class)) {
Integer64 val = (Integer64) obj;
value = val.getVal();
} else if (obj.getClass().equals(Integer32.class)) {
Integer32 val = (Integer32) obj;
value = val.getVal();
} else if (obj.getClass().equals(Integer16.class)) {
Integer16 val = (Integer16) obj;
value = val.getVal();
} else if (obj.getClass().equals(Integer8.class)) {
Integer8 val = (Integer8) obj;
value = val.getVal();
} else if (obj.getClass().equals(Unsigned64.class)) {
Unsigned64 val = (Unsigned64) obj;
value = val.getVal();
} else if (obj.getClass().equals(Unsigned32.class)) {
Unsigned32 val = (Unsigned32) obj;
value = val.getVal();
} else if (obj.getClass().equals(Unsigned16.class)) {
Unsigned16 val = (Unsigned16) obj;
value = val.getVal();
} else if (obj.getClass().equals(Unsigned8.class)) {
Unsigned8 val = (Unsigned8) obj;
value = val.getVal();
} else if (obj.getClass().equals(OctetString.class)) {
OctetString val = (OctetString) obj;
return new ValueContainer(new StringValue(new String(val.getValue())), ValueType.STRING);
} else {
return new ValueContainer(new DoubleValue(Double.NaN), valueType);
}
byte scaler = entry.getScaler().getVal();
double scaledValue = value * Math.pow(10, scaler);
return new ValueContainer(new DoubleValue(scaledValue), valueType);
}
Aggregations