Search in sources :

Example 1 with XBeeResponse

use of com.rapplogic.xbee.api.XBeeResponse 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;
}
Also used : Item(org.openhab.core.items.Item) ZNetTxRequest(com.rapplogic.xbee.api.zigbee.ZNetTxRequest) XBeeAddress64(com.rapplogic.xbee.api.XBeeAddress64) XBeeException(com.rapplogic.xbee.api.XBeeException) XBeeResponse(com.rapplogic.xbee.api.XBeeResponse) XBeeTimeoutException(com.rapplogic.xbee.api.XBeeTimeoutException) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Aggregations

XBeeAddress64 (com.rapplogic.xbee.api.XBeeAddress64)1 XBeeException (com.rapplogic.xbee.api.XBeeException)1 XBeeResponse (com.rapplogic.xbee.api.XBeeResponse)1 XBeeTimeoutException (com.rapplogic.xbee.api.XBeeTimeoutException)1 ZNetTxRequest (com.rapplogic.xbee.api.zigbee.ZNetTxRequest)1 Item (org.openhab.core.items.Item)1 ItemNotFoundException (org.openhab.core.items.ItemNotFoundException)1