use of com.rapplogic.xbee.api.XBeeAddress64 in project openhab1-addons by openhab.
the class DiyOnXBeeBinding method internalReceiveCommand.
/**
*
* @return if the command was sent successfully
*/
private boolean internalReceiveCommand(DiyOnXBeeBindingProvider provider, String itemName, Command command) {
final String remote = provider.getRemote(itemName);
final int[] remoteAddress = FormatUtil.fromReadableAddress(remote);
Item item;
try {
item = itemRegistry.getItem(itemName);
} catch (ItemNotFoundException e1) {
logger.error("unable to get item {}", itemName, e1);
return false;
}
final String commandValue = createCommand(item, command);
if (commandValue == null) {
logger.warn("unable to create command {} for item {}", commandValue, itemName);
return false;
} else {
logger.debug("created command {} for item {}", commandValue, itemName);
}
final String commandString = new StringBuilder().append(provider.getId(itemName)).append('=').append(commandValue).append('\n').toString();
final ZNetTxRequest request = new ZNetTxRequest(new XBeeAddress64(remoteAddress), createPayload(commandString));
xbeeUsageLock.lock();
try {
if (xbee == null) {
logger.error("cannot send command to {} as the XBee module isn't initialized", itemName);
return false;
} else {
// TODO:
final XBeeResponse response = xbee.sendSynchronous(request);
// response?
return true;
}
} catch (XBeeTimeoutException e) {
logger.error("failed sending {} to {}", command, itemName, e);
} catch (XBeeException e) {
logger.error("failed sending {} to {}", command, itemName, e);
} finally {
xbeeUsageLock.unlock();
}
return false;
}
Aggregations