use of org.openmuc.framework.data.StringValue in project OpenMUC by isc-konstanz.
the class SnmpDevice method readChannelGroup.
/**
* Read all the channels of the device at once.
*
* @param device
* @param containers
* @param timeout
* @return Object
* @throws ConnectionException
*/
private Object readChannelGroup(List<ChannelRecordContainer> containers, int timeout) throws ConnectionException {
new Date().getTime();
List<String> oids = new ArrayList<>();
for (ChannelRecordContainer container : containers) {
if (getDeviceAddress().equalsIgnoreCase(container.getChannel().getDeviceAddress())) {
oids.add(container.getChannelAddress());
}
}
Map<String, String> values;
try {
values = getRequestsList(oids);
long receiveTime = System.currentTimeMillis();
for (ChannelRecordContainer container : containers) {
// make sure the value exists for corresponding channel
if (values.get(container.getChannelAddress()) != null) {
logger.debug("{}: value = '{}'", container.getChannelAddress(), values.get(container.getChannelAddress()));
container.setRecord(new Record(new StringValue(values.get(container.getChannelAddress())), receiveTime));
}
}
} catch (SnmpTimeoutException e) {
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.TIMEOUT));
}
}
return null;
}
use of org.openmuc.framework.data.StringValue in project OpenMUC by isc-konstanz.
the class OpcChannel method setValue.
@Override
public void setValue(AttributeContext context, VariableNode node, DataValue value) throws UaException {
Variant variant = value.getValue();
Record record = null;
switch(getValueType()) {
case BOOLEAN:
record = new Record(new BooleanValue((Boolean) variant.getValue()), value.getServerTime().getUtcTime());
break;
case BYTE:
record = new Record(new ByteValue((Byte) variant.getValue()), value.getServerTime().getUtcTime());
break;
case SHORT:
record = new Record(new ShortValue((Short) variant.getValue()), value.getServerTime().getUtcTime());
break;
case INTEGER:
record = new Record(new IntValue((Integer) variant.getValue()), value.getServerTime().getUtcTime());
break;
case LONG:
record = new Record(new LongValue((Long) variant.getValue()), value.getServerTime().getUtcTime());
break;
case FLOAT:
record = new Record(new FloatValue((Float) variant.getValue()), value.getServerTime().getUtcTime());
break;
case DOUBLE:
record = new Record(new DoubleValue((Double) variant.getValue()), value.getServerTime().getUtcTime());
break;
default:
record = new Record(new StringValue((String) variant.getValue()), value.getServerTime().getUtcTime());
break;
}
setRecord(record);
}
use of org.openmuc.framework.data.StringValue in project OpenMUC by isc-konstanz.
the class SmlConnection method convertEntryToScanInfo.
private static ChannelScanInfo convertEntryToScanInfo(SmlListEntry entry) {
String channelAddress = convertBytesToHexString(entry.getObjName().getValue());
ValueContainer valueContainer = extractValueOf(entry);
Value value = valueContainer.value;
String description = MessageFormat.format("Current value: {0} {1}", value, entry.getUnit());
ValueType valueType = valueContainer.valueType;
Integer valueTypeLength = null;
if (value != null) {
if (valueType == ValueType.STRING) {
String stringValue = value.asString();
valueTypeLength = stringValue.length();
} else if (valueType == ValueType.BYTE_ARRAY) {
byte[] byteValue = value.asByteArray();
valueTypeLength = byteValue.length;
}
}
boolean readable = true;
boolean writable = false;
return new ChannelScanInfo(channelAddress, description, valueType, valueTypeLength, readable, writable);
}
use of org.openmuc.framework.data.StringValue in project OpenMUC by isc-konstanz.
the class Options method parseValue.
public static Value parseValue(ValueType type, String valueStr) throws ArgumentSyntaxException {
Value value;
switch(type) {
case DOUBLE:
value = new DoubleValue(Double.valueOf(valueStr));
break;
case FLOAT:
value = new FloatValue(Float.valueOf(valueStr));
break;
case INTEGER:
value = new IntValue(Integer.valueOf(valueStr));
break;
case LONG:
value = new LongValue(Long.valueOf(valueStr));
break;
case SHORT:
value = new ShortValue(Short.valueOf(valueStr));
break;
case BYTE:
value = new ByteValue(Byte.valueOf(valueStr));
break;
case BOOLEAN:
value = new BooleanValue(Boolean.valueOf(valueStr));
break;
case BYTE_ARRAY:
byte[] arr;
if (!valueStr.startsWith("0x")) {
arr = valueStr.getBytes(StandardCharsets.US_ASCII);
} else {
try {
arr = OptionValue.hexToBytes(valueStr.substring(2).trim());
} catch (IllegalArgumentException e) {
throw new ArgumentSyntaxException("Unable to parse value as byte array: " + valueStr);
}
}
value = new ByteArrayValue(arr);
break;
case STRING:
value = new StringValue(valueStr);
break;
default:
throw new ArgumentSyntaxException("Parameter value type not configured: " + type.name().toLowerCase());
}
return value;
}
use of org.openmuc.framework.data.StringValue in project OpenMUC by isc-konstanz.
the class SimpleDemoApp method updateEvStatusChannel.
/**
* Checks if the electric vehicle is charging (Demonstrates how to access a value from a channel and how to set a
* value/record)
*/
private void updateEvStatusChannel() {
double evPower;
String status = "idle";
// get current value of the electric vehicle power channel
Record lastRecord = chPowerElecticVehicle.getLatestRecord();
if (lastRecord != null) {
Value value = lastRecord.getValue();
if (value != null) {
evPower = chPowerElecticVehicle.getLatestRecord().getValue().asDouble();
if (evPower > STANDBY_POWER_CHARGING_STATION) {
status = "charging";
}
// set value for virtual channel
Record newRecord = new Record(new StringValue(status), System.currentTimeMillis(), Flag.VALID);
chEvStatus.setLatestRecord(newRecord);
}
}
}
Aggregations