final int timeout) {
if (!isConnected()) {
return false;
}
try {
AtCommandResponse response;
int[] responseValue;
final XBeeAddress16 remoteAddress = getXbeeAddress(remoteNode
.getAddress());
if (remoteAddress != null) {
final RemoteAtRequest request = new RemoteAtRequest(
remoteAddress, "MY");
final RemoteAtResponse remoteResponse = (RemoteAtResponse) xbee
.sendSynchronous(request,
timeout <= 0 ? DEFAULT_WAIT_MILISECONDS
: timeout);
response = remoteResponse;
} else {
response = (AtCommandResponse) xbee
.sendSynchronous(new AtCommand("MY"));
}
if (response.isOk()) {
responseValue = response.getValue();
final String address = ByteUtils.toBase16(responseValue);
log.info(String.format("Successfully got %1$s address %2$s",
(remoteAddress != null ? "remote" : "local"), address));
if (address != null && !address.isEmpty()) {
return true;
}
} else {
throw new XBeeException(
"Failed to get remote address response. Status is "
+ response.getStatus());
}
} catch (final XBeeTimeoutException e) {
log.warn("Timed out getting remote XBee address", e);
} catch (final XBeeException e) {
log.warn("Error getting remote XBee address", e);