Search in sources :

Example 6 with DeviceScanInfo

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();
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) SnmpDriver(org.openmuc.framework.driver.snmp.SnmpDriver) ScanException(org.openmuc.framework.config.ScanException) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException)

Example 7 with DeviceScanInfo

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();
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) ScanException(org.openmuc.framework.config.ScanException) DataSet(org.openmuc.j62056.DataSet) DataMessage(org.openmuc.j62056.DataMessage) Builder(org.openmuc.j62056.Iec21Port.Builder) Iec21Port(org.openmuc.j62056.Iec21Port) IOException(java.io.IOException)

Example 8 with DeviceScanInfo

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));
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) DeviceDIB(tuwien.auto.calimero.knxnetip.util.DeviceDIB) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) SearchResponse(tuwien.auto.calimero.knxnetip.servicetype.SearchResponse)

Example 9 with DeviceScanInfo

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);
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) ScanException(org.openmuc.framework.config.ScanException) SecondaryAddress(org.openmuc.jmbus.SecondaryAddress) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) ScanInterruptedException(org.openmuc.framework.config.ScanInterruptedException)

Example 10 with DeviceScanInfo

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++;
        }
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) Pin(com.pi4j.io.gpio.Pin) RaspiPin(com.pi4j.io.gpio.RaspiPin)

Aggregations

DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)11 ScanException (org.openmuc.framework.config.ScanException)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)2 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)2 JsonElement (com.google.gson.JsonElement)1 Pin (com.pi4j.io.gpio.Pin)1 RaspiPin (com.pi4j.io.gpio.RaspiPin)1 W1Device (com.pi4j.io.w1.W1Device)1 File (java.io.File)1 InterruptedIOException (java.io.InterruptedIOException)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 CsvDriver (org.openmuc.framework.driver.csv.CsvDriver)1 SnmpDriver (org.openmuc.framework.driver.snmp.SnmpDriver)1