use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class WriteHandle method multiSet.
private void multiSet(List<ChannelValueContainer> writeList) throws ConnectionException {
List<AccessResultCode> resultCodes = callSet(writeList);
Iterator<AccessResultCode> iterResult = resultCodes.iterator();
Iterator<ChannelValueContainer> iterWriteList = writeList.iterator();
while (iterResult.hasNext() && iterWriteList.hasNext()) {
ChannelValueContainer valueContainer = iterWriteList.next();
AccessResultCode resCode = iterResult.next();
Flag flag = convertToFlag(resCode);
valueContainer.setFlag(flag);
}
}
use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class AmqpDriverConnection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException {
for (ChannelValueContainer container : containers) {
Record record = new Record(container.getValue(), System.currentTimeMillis());
if (parsers.containsKey(setting.parser)) {
byte[] message = new byte[0];
try {
message = parsers.get(setting.parser).serialize(record, container);
} catch (SerializationException e) {
logger.error(e.getMessage());
}
writer.write(container.getChannelAddress(), message);
container.setFlag(Flag.VALID);
} else {
throw new UnsupportedOperationException("A parser is needed to write messages");
}
}
return null;
}
use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class SnmpDevice method write.
/**
* At least device address and channel address must be specified in the container.<br>
* <br>
* containers.deviceAddress = device address (eg. 1.1.1.1/161) <br>
* containers.channelAddress = OID (eg. 1.3.6.1.2.1.1.0)
*/
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws ConnectionException {
try {
for (ChannelValueContainer container : containers) {
String oid = container.getChannelAddress();
Value value = container.getValue();
logger.debug("Write value for OID {}: {}", oid, value);
setRequest(oid, value);
container.setFlag(Flag.VALID);
}
} catch (SnmpTimeoutException e) {
logger.warn("Error while requesting SNMP SET: {}", e.getMessage());
}
return null;
}
use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class Iec61850ConnectionTest method testWrite.
@Test
public void testWrite() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
System.out.println("Attempting to connect to server " + host + " on port " + port);
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel, clientAssociation);
// ------------SCAN FOR CHANNELS-------------------
Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
// ----------WRITE-----------------
List<ChannelValueContainer> testChannelValueContainers = new ArrayList<>();
byte[] newValue = { 0x44 };
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(14).getChannelAddress(), new ByteArrayValue(newValue)));
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(25).getChannelAddress(), new FloatValue((float) 12.5)));
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(24).getChannelAddress(), new BooleanValue(true)));
testIec61850Connection.write(testChannelValueContainers, null);
// Create record container to read the changes made by "write"
List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
for (int i = 0; i < 34; i++) {
testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
}
testIec61850Connection.read(testRecordContainers, null, "");
Assert.assertEquals("[68]", testRecordContainers.get(14).getRecord().getValue().toString());
Assert.assertEquals("12.5", testRecordContainers.get(25).getRecord().getValue().toString());
Assert.assertEquals("true", testRecordContainers.get(24).getRecord().getValue().toString());
}
use of org.openmuc.framework.driver.spi.ChannelValueContainer in project OpenMUC by isc-konstanz.
the class Iec61850Connection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException, ConnectionException {
List<FcModelNode> modelNodesToBeWritten = new ArrayList<>(containers.size());
for (ChannelValueContainer container : containers) {
if (container.getChannelHandle() != null) {
modelNodesToBeWritten.add((FcModelNode) container.getChannelHandle());
setFcModelNode(container, (FcModelNode) container.getChannelHandle());
} else {
String[] args = container.getChannelAddress().split(":", 3);
if (args.length != 2) {
logger.debug("Wrong channel address syntax: {}", container.getChannelAddress());
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
continue;
}
ModelNode modelNode = serverModel.findModelNode(args[0], Fc.fromString(args[1]));
if (modelNode == null) {
logger.debug("No Basic Data Attribute for the channel address {} was found in the server model.", container.getChannelAddress());
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
continue;
}
FcModelNode fcModelNode;
try {
fcModelNode = (FcModelNode) modelNode;
} catch (ClassCastException e) {
logger.debug("ModelNode with object reference {} was found in the server model but is not a Basic Data Attribute.", container.getChannelAddress());
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
continue;
}
container.setChannelHandle(fcModelNode);
modelNodesToBeWritten.add(fcModelNode);
setFcModelNode(container, fcModelNode);
}
}
// TODO
// first check all datasets if the are some that contain only requested channels
// then check all remaining model nodes
List<FcModelNode> fcNodesToBeRequested = new ArrayList<>();
while (modelNodesToBeWritten.size() > 0) {
fillRequestedNodes(fcNodesToBeRequested, modelNodesToBeWritten, serverModel);
}
for (FcModelNode fcModelNode : fcNodesToBeRequested) {
try {
if (fcModelNode.getFc().toString().equals("CO")) {
logger.info("writing CO model node");
fcModelNode = (FcModelNode) fcModelNode.getParent().getParent();
clientAssociation.operate(fcModelNode);
} else {
clientAssociation.setDataValues(fcModelNode);
}
} catch (ServiceError e) {
logger.error("Error writing to channel: service error calling setDataValues on {}: {}", fcModelNode.getReference(), e);
for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
for (ChannelValueContainer valueContainer : containers) {
if (valueContainer.getChannelHandle() == bda) {
valueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE);
}
}
}
return null;
} catch (IOException e) {
throw new ConnectionException(e);
}
for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
for (ChannelValueContainer valueContainer : containers) {
if (valueContainer.getChannelHandle() == bda) {
valueContainer.setFlag(Flag.VALID);
}
}
}
}
return null;
}
Aggregations