use of org.openmuc.framework.config.DeviceScanInfo in project OpenMUC by isc-konstanz.
the class SnmpScannerExample method main.
/**
* @param args
*/
public static void main(String[] args) {
SnmpDriver myDriver = new SnmpDriver();
String settings = SnmpDriverSettingVariableNames.AUTHENTICATIONPASSPHRASE + "=adminadmin:" + SnmpDriverScanSettingVariableNames.STARTIP + "=192.168.1.0:" + SnmpDriverScanSettingVariableNames.ENDIP + "=192.168.10.0";
class TestListener implements DriverDeviceScanListener {
@Override
public void scanProgressUpdate(int progress) {
}
@Override
public void deviceFound(DeviceScanInfo device) {
System.out.println("-----------------------------");
System.out.println("New device found: ");
System.out.println("Address: " + device.getAddress());
System.out.println("Description: " + device.getDescription());
System.out.println("-----------------------------");
}
}
;
TestListener listener = new TestListener();
try {
myDriver.scanForDevices(settings, listener);
Thread.sleep(100);
} catch (InterruptedException iex) {
System.out.println("Request cancelled: " + iex.getMessage());
} catch (ArgumentSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ScanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ScanInterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.openmuc.framework.config.DeviceScanInfo in project OpenMUC by isc-konstanz.
the class Iec62056Driver method scanForDevices.
@Override
public void scanForDevices(String settings, DriverDeviceScanListener listener) throws UnsupportedOperationException, ArgumentSyntaxException, ScanException, ScanInterruptedException {
handleScanParameter(settings);
Iec21Port iec21Port = null;
Builder iec21PortBuilder = getConfiguredBuilder();
try {
iec21Port = iec21PortBuilder.buildAndOpen();
} catch (IOException e) {
throw new ScanException("Failed to open serial port: " + e.getMessage());
}
try {
DataMessage dataMessage = iec21Port.read();
List<DataSet> dataSets = dataMessage.getDataSets();
StringBuilder deviceSettings = new StringBuilder();
if (baudRateChangeDelay > 0) {
deviceSettings.append(' ').append(BAUD_RATE_CHANGE_DELAY).append(' ').append(baudRateChangeDelay);
}
String deviceSettingsString = deviceSettings.toString().trim();
listener.deviceFound(new DeviceScanInfo(serialPortName, deviceSettingsString, dataSets.get(0).getAddress().replaceAll("\\p{Cntrl}", "")));
} catch (IOException e) {
throw new ScanException(e);
} finally {
iec21Port.close();
}
}
use of org.openmuc.framework.config.DeviceScanInfo in project OpenMUC by isc-konstanz.
the class KnxIpDiscover method notifyListener.
private void notifyListener(DriverDeviceScanListener listener) {
for (SearchResponse response : searchResponses) {
StringBuilder deviceAddress = new StringBuilder();
deviceAddress.append(KnxDriver.ADDRESS_SCHEME_KNXIP).append("://");
InetAddress address = response.getControlEndpoint().getAddress();
String ipAddress = address.getHostAddress();
if (address instanceof Inet6Address) {
deviceAddress.append("[").append(ipAddress).append("]");
} else {
deviceAddress.append(ipAddress);
}
deviceAddress.append(":").append(response.getControlEndpoint().getPort());
DeviceDIB deviceDIB = response.getDevice();
String name = deviceDIB.getSerialNumberString();
String description = deviceDIB.toString();
logger.debug("Found " + deviceAddress + " - " + name + " - " + description);
listener.deviceFound(new DeviceScanInfo(deviceAddress.toString(), "", description));
}
}
use of org.openmuc.framework.config.DeviceScanInfo in project OpenMUC by isc-konstanz.
the class Driver method scanPrimaryAddress.
private void scanPrimaryAddress(DriverDeviceScanListener listener, Settings settings, MBusConnection mBusConnection) throws ScanInterruptedException, ScanException {
VariableDataStructure dataStructure = null;
for (int i = 0; i <= 250; i++) {
if (interruptScan) {
throw new ScanInterruptedException();
}
if (i % 5 == 0) {
listener.scanProgressUpdate(i * 100 / 250);
}
logger.debug("scanning for meter with primary address {}", i);
try {
dataStructure = mBusConnection.read(i);
sleep(settings.delay);
} catch (InterruptedIOException e) {
logger.debug("No meter found on address {}", i);
continue;
} catch (IOException e) {
throw new ScanException(e);
} catch (ConnectionException e) {
throw new ScanException(e);
}
String description = "";
if (dataStructure != null) {
SecondaryAddress secondaryAddress = dataStructure.getSecondaryAddress();
description = getScanDescription(secondaryAddress);
}
listener.deviceFound(new DeviceScanInfo(settings.scanConnectionAddress + ':' + i, "", description));
logger.debug("Meter found on address {}", i);
}
}
use of org.openmuc.framework.config.DeviceScanInfo in project OpenMUC by isc-konstanz.
the class GpioScanner method scan.
@Override
public void scan(DriverDeviceScanListener listener) throws ArgumentSyntaxException, ScanException, ScanInterruptedException {
logger.info("Scan for {}s of the Raspberry Pi platform: {}", mode.name().toLowerCase().replace('_', ' '), board.name().replace('_', ' '));
interrupt = false;
int counter = 1;
Pin[] pins = RaspiPin.allPins(board);
for (Pin pin : pins) {
if (interrupt) {
break;
}
if (pin.getSupportedPinModes().contains(mode)) {
String scanAddress = GpioConfigs.PIN + ":" + pin.getAddress();
String scanSettings = GpioConfigs.MODE + ":" + mode.name();
listener.deviceFound(new DeviceScanInfo("Pin" + pin.getAddress(), scanAddress, scanSettings, pin.getName()));
listener.scanProgressUpdate((int) Math.round(counter / (double) pins.length * 100));
counter++;
}
}
}
Aggregations