use of org.openhab.binding.russound.internal.net.WaitingSessionListener in project openhab-addons by openhab.
the class RioSystemDeviceDiscoveryService method scanDevice.
/**
* Starts a device scan. This will connect to the device and discover the controllers/sources/zones attached to the
* device and then disconnect via {@link #deactivate()}
*/
public void scanDevice() {
try {
final String ipAddress = sysHandler.getRioConfig().getIpAddress();
session = new SocketChannelSession(ipAddress, RioConstants.RIO_PORT);
listener = new WaitingSessionListener();
session.addListener(listener);
try {
logger.debug("Starting scan of RIO device at {}", ipAddress);
session.connect();
discoverControllers();
discoverSources();
} catch (IOException e) {
logger.debug("Trying to scan device but couldn't connect: {}", e.getMessage(), e);
}
} finally {
deactivate();
}
}
use of org.openhab.binding.russound.internal.net.WaitingSessionListener in project openhab-addons by openhab.
the class RioSystemDiscovery method scanAddress.
/**
* Helper method to scan a specific address. Will open up port 9621 on the address and if opened, query for any
* controller type (all 6 controllers are tested). If a valid type is found, a discovery result will be created.
*
* @param ipAddress a possibly null, possibly empty ip address (null/empty addresses will be ignored)
*/
private void scanAddress(String ipAddress) {
if (ipAddress == null || ipAddress.isEmpty()) {
return;
}
final SocketSession session = new SocketChannelSession(ipAddress, RioConstants.RIO_PORT);
try {
final WaitingSessionListener listener = new WaitingSessionListener();
session.addListener(listener);
session.connect(CONN_TIMEOUT_IN_MS);
logger.debug("Connected to port {}:{} - testing to see if RIO", ipAddress, RioConstants.RIO_PORT);
// need to check if any controllers are defined
for (int c = 1; c < 7; c++) {
session.sendCommand("GET C[" + c + "].type");
final String resp = listener.getResponse();
if (resp == null) {
continue;
}
if (!resp.startsWith("S C[" + c + "].type=\"")) {
continue;
}
final String type = resp.substring(13, resp.length() - 1);
if (!type.isBlank()) {
logger.debug("Found a RIO type #{}", type);
addResult(ipAddress, type);
break;
}
}
} catch (InterruptedException e) {
logger.debug("Connection was interrupted to port {}:{}", ipAddress, RioConstants.RIO_PORT);
} catch (IOException e) {
logger.trace("Connection couldn't be established to port {}:{}", ipAddress, RioConstants.RIO_PORT);
} finally {
try {
session.disconnect();
} catch (IOException e) {
// do nothing
}
}
}
Aggregations