Search in sources :

Example 1 with DriverDeviceScanListener

use of org.openmuc.framework.driver.spi.DriverDeviceScanListener in project OpenMUC by isc-konstanz.

the class DriverTest method testInterrupedException.

@Test(expected = ScanInterruptedException.class)
public void testInterrupedException() throws Exception {
    final Driver mdriver = new Driver();
    DriverDeviceScanListener ddsl = mock(DriverDeviceScanListener.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            mdriver.interruptDeviceScan();
            return null;
        }
    }).when(ddsl).deviceFound(any(DeviceScanInfo.class));
    MBusConnection con = mock(MBusConnection.class);
    when(con.read(anyInt())).thenReturn(new VariableDataStructure(null, 0, 0, null, null));
    whenNew(MBusConnection.class).withAnyArguments().thenReturn(con);
    doNothing().when(con).linkReset(ArgumentMatchers.anyInt());
    PowerMockito.when(con.read(ArgumentMatchers.anyInt())).thenReturn(null);
    mdriver.scanForDevices("/dev/ttyS100:2400", ddsl);
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with DriverDeviceScanListener

use of org.openmuc.framework.driver.spi.DriverDeviceScanListener in project OpenMUC by isc-konstanz.

the class CsvScanDeviceTest method testDeviceScan.

@Test
public void testDeviceScan() throws ArgumentSyntaxException, UnsupportedOperationException, ScanException, ScanInterruptedException {
    CsvDriver csvDriver = new CsvDriver();
    String settings = "path=" + dir + "/src/test/resources";
    csvDriver.scanForDevices(settings, new DriverDeviceScanListener() {

        @Override
        public void scanProgressUpdate(int progress) {
            System.out.println("Scan progress: " + progress + " %");
        }

        @Override
        public void deviceFound(DeviceScanInfo scanInfo) {
            System.out.println(scanInfo.toString());
        }
    });
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) CsvDriver(org.openmuc.framework.driver.csv.CsvDriver) Test(org.junit.Test)

Example 3 with DriverDeviceScanListener

use of org.openmuc.framework.driver.spi.DriverDeviceScanListener 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)

Aggregations

DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)3 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)3 Test (org.junit.Test)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 ScanException (org.openmuc.framework.config.ScanException)1 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)1 CsvDriver (org.openmuc.framework.driver.csv.CsvDriver)1 SnmpDriver (org.openmuc.framework.driver.snmp.SnmpDriver)1 MBusConnection (org.openmuc.jmbus.MBusConnection)1 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1