use of com.github.paolodenti.jsapp.core.command.base.SappException in project openhab1-addons by openhab.
the class SappCentralExecuter method executeSapp75Command.
/**
* runs 75 command
*/
public int executeSapp75Command(String ip, int port, byte address) throws SappException {
synchronized (this) {
SappCommand sappCommand = new Sapp75Command(address);
sappCommand.run(ip, port);
if (!sappCommand.isResponseOk()) {
throw new SappException("command execution failed");
}
return sappCommand.getResponse().getDataAsWord();
}
}
use of com.github.paolodenti.jsapp.core.command.base.SappException in project openhab1-addons by openhab.
the class SappBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
if (isProperlyConfigured()) {
// wait until provider is properly configured and all items are loaded
SappBindingProvider provider = getFirstSappBindingProvider();
if (provider != null) {
if (provider.getSappUpdatePendingRequests().areUpdatePendingRequestsPresent()) {
// reinit
// items
Set<String> toBeProcessed = provider.getSappUpdatePendingRequests().getAndClearPendingUpdateRequests();
initializeAllItemsInProvider(provider, toBeProcessed);
} else {
if (!pollingEnabled) {
return;
}
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
for (String pnmasId : provider.getPnmasMap().keySet()) {
// each pnmas
SappPnmas pnmas = provider.getPnmasMap().get(pnmasId);
try {
PollingResult pollingResult = sappCentralExecuter.executePollingSappCommands(pnmas.getIp(), pnmas.getPort());
if (pollingResult.changedOutputs.size() != 0) {
for (Byte outputAddress : pollingResult.changedOutputs.keySet()) {
logger.debug("Output variation {} received, new value is {}", SappUtils.byteToUnsigned(outputAddress), pollingResult.changedOutputs.get(outputAddress));
provider.setOutputCachedValue(SappUtils.byteToUnsigned(outputAddress), pollingResult.changedOutputs.get(outputAddress).intValue());
updateState(pnmasId, SappAddressType.OUTPUT, SappUtils.byteToUnsigned(outputAddress), pollingResult.changedOutputs.get(outputAddress).intValue(), provider);
}
}
if (pollingResult.changedInputs.size() != 0) {
for (Byte inputAddress : pollingResult.changedInputs.keySet()) {
logger.debug("Input variation {} received, new value is {}", SappUtils.byteToUnsigned(inputAddress), pollingResult.changedInputs.get(inputAddress));
provider.setInputCachedValue(SappUtils.byteToUnsigned(inputAddress), pollingResult.changedInputs.get(inputAddress).intValue());
updateState(pnmasId, SappAddressType.INPUT, SappUtils.byteToUnsigned(inputAddress), pollingResult.changedInputs.get(inputAddress).intValue(), provider);
}
}
if (pollingResult.changedVirtuals.size() != 0) {
for (Integer virtualAddress : pollingResult.changedVirtuals.keySet()) {
logger.debug("Virtual variation {} received, new value is {}", virtualAddress, pollingResult.changedVirtuals.get(virtualAddress));
provider.setVirtualCachedValue(virtualAddress, pollingResult.changedVirtuals.get(virtualAddress).intValue());
updateState(pnmasId, SappAddressType.VIRTUAL, virtualAddress, pollingResult.changedVirtuals.get(virtualAddress).intValue(), provider);
}
}
} catch (SappException e) {
logger.error("polling failed on pnmas {}", pnmas);
}
}
}
}
}
}
use of com.github.paolodenti.jsapp.core.command.base.SappException in project openhab1-addons by openhab.
the class SappCentralExecuter method executePollingSappCommands.
/**
* runs polling on virtuals, inputs, outputs
*/
public PollingResult executePollingSappCommands(String ip, int port) throws SappException {
synchronized (this) {
PollingResult pollingResult = new PollingResult();
SappConnection sappConnection = null;
try {
sappConnection = new SappConnection(ip, port);
sappConnection.openConnection();
SappCommand sappCommand;
sappCommand = new Sapp80Command();
sappCommand.run(sappConnection);
if (!sappCommand.isResponseOk()) {
throw new SappException("Sapp80Command command execution failed");
}
pollingResult.changedOutputs = sappCommand.getResponse().getDataAsByteWordMap();
sappCommand = new Sapp81Command();
sappCommand.run(sappConnection);
if (!sappCommand.isResponseOk()) {
throw new SappException("Sapp81Command command execution failed");
}
pollingResult.changedInputs = sappCommand.getResponse().getDataAsByteWordMap();
sappCommand = new Sapp82Command();
sappCommand.run(sappConnection);
if (!sappCommand.isResponseOk()) {
throw new SappException("Sapp82Command command execution failed");
}
pollingResult.changedVirtuals = sappCommand.getResponse().getDataAsWordWordMap();
return pollingResult;
} catch (IOException e) {
throw new SappException(e.getMessage());
} finally {
if (sappConnection != null) {
sappConnection.closeConnection();
}
}
}
}
Aggregations