Search in sources :

Example 1 with ScanException

use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.

the class DataManager method scanForChannels.

@Override
public List<ChannelScanInfo> scanForChannels(String deviceId, String settings) throws DriverNotAvailableException, UnsupportedOperationException, ArgumentSyntaxException, ScanException {
    // TODO this function is probably not thread safe
    DeviceConfigImpl config = (DeviceConfigImpl) this.rootConfig.getDevice(deviceId);
    if (config == null) {
        throw new ScanException("No device with ID \"" + deviceId + "\" found.");
    }
    DriverService activeDriver = activeDrivers.get(config.driverParent.id);
    if (activeDriver == null) {
        throw new DriverNotAvailableException();
    }
    waitTilDeviceIsConnected(config.device);
    try {
        return config.device.connection.scanForChannels(settings);
    } catch (ConnectionException e) {
        config.device.disconnectedSignal();
        throw new ScanException(e.getMessage(), e);
    }
}
Also used : ScanException(org.openmuc.framework.config.ScanException) DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) DriverService(org.openmuc.framework.driver.spi.DriverService)

Example 2 with ScanException

use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.

the class Driver method scanForDevices.

@Override
public void scanForDevices(String settingsString, DriverDeviceScanListener listener) throws ArgumentSyntaxException, ScanException, ScanInterruptedException {
    interruptScan = false;
    Settings settings = new Settings(settingsString, true);
    MBusConnection mBusConnection;
    if (!interfaces.containsKey(settings.scanConnectionAddress)) {
        try {
            if (settings.host.isEmpty()) {
                mBusConnection = MBusConnection.newSerialBuilder(settings.scanConnectionAddress).setBaudrate(settings.baudRate).setTimeout(settings.timeout).build();
            } else {
                mBusConnection = MBusConnection.newTcpBuilder(settings.host, settings.port).setTimeout(settings.timeout).setConnectionTimeout(settings.connectionTimeout).build();
            }
        } catch (IOException e) {
            throw new ScanException(e);
        }
        if (logger.isTraceEnabled()) {
            mBusConnection.setVerboseMessageListener(new VerboseMessageListenerImpl());
        }
    } else {
        mBusConnection = interfaces.get(settings.scanConnectionAddress).getMBusConnection();
    }
    ConnectionInterface connectionInterface = interfaces.get(settings.scanConnectionAddress);
    if (connectionInterface != null && connectionInterface.isOpen()) {
        throw new ScanException("Device is already connected. Disable device which uses port " + settings.scanConnectionAddress + ", before scan.");
    }
    try {
        if (settings.scanSecondary) {
            SecondaryAddressListenerImplementation secondaryAddressListenerImplementation = new SecondaryAddressListenerImplementation(listener, settings.scanConnectionAddress);
            mBusConnection.scan("ffffffff", secondaryAddressListenerImplementation, settings.delay);
        } else {
            scanPrimaryAddress(listener, settings, mBusConnection);
        }
    } catch (IOException e) {
        logger.error("Failed to scan for devices.", e);
    } finally {
        mBusConnection.close();
    }
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) ScanException(org.openmuc.framework.config.ScanException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 3 with ScanException

use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.

the class ColumnScanner method scan.

@Override
public void scan(List<ChannelScanInfo> channels) throws ArgumentSyntaxException, ScanException, ConnectionException {
    logger.info("Scan for columns in {}.{}", database, table);
    try (Connection connection = source.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            try (ResultSet result = statement.executeQuery(String.format("SELECT * FROM %s LIMIT 1", table))) {
                if (result.first()) {
                    ResultSetMetaData metaData = result.getMetaData();
                    for (int i = 1; i <= metaData.getColumnCount(); i++) {
                        String column = metaData.getColumnName(i);
                        Integer typeLength = null;
                        ValueType type;
                        switch(metaData.getColumnTypeName(i)) {
                            case "BIT":
                                type = ValueType.BOOLEAN;
                                break;
                            case "TINYINT":
                                type = ValueType.BYTE;
                                break;
                            case "SMALLINT":
                                type = ValueType.SHORT;
                                break;
                            case "INTEGER":
                                type = ValueType.INTEGER;
                                break;
                            case "BIGINT":
                                type = ValueType.LONG;
                                break;
                            case "REAL":
                                type = ValueType.FLOAT;
                                break;
                            case "DOUBLE":
                            case "NUMERIC":
                                type = ValueType.DOUBLE;
                                break;
                            case "VARBINARY":
                            case "LONGVARBINARY":
                                typeLength = metaData.getColumnDisplaySize(i);
                                type = ValueType.BYTE_ARRAY;
                                break;
                            case "VARCHAR":
                            case "LONGVARCHAR":
                            default:
                                typeLength = metaData.getColumnDisplaySize(i);
                                type = ValueType.STRING;
                        }
                        channels.add(new ChannelScanInfo(column, column, type, typeLength));
                    }
                }
            } catch (SQLException e) {
                throw new ScanException(e);
            }
        }
    } catch (SQLException e) {
        throw new ConnectionException(e);
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ScanException(org.openmuc.framework.config.ScanException) ValueType(org.openmuc.framework.data.ValueType) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 4 with ScanException

use of org.openmuc.framework.config.ScanException 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 5 with ScanException

use of org.openmuc.framework.config.ScanException in project OpenMUC by isc-konstanz.

the class CsvScanDeviceTest method testChannelScan.

@Test
public void testChannelScan() {
    CsvDriver csvDriver = new CsvDriver();
    String deviceAddress = dir + "/src/test/resources/test_data.csv";
    try {
        String settings = "SAMPLINGMODE=hhmmss";
        CsvFile csvConnection = (CsvFile) csvDriver.connect(deviceAddress, settings);
        List<ChannelScanInfo> channelsScanInfos = csvConnection.scanForChannels("");
        for (ChannelScanInfo info : channelsScanInfos) {
            System.out.println("Channel: " + info.getChannelAddress());
        }
    } catch (ArgumentSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedOperationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ScanException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ScanException(org.openmuc.framework.config.ScanException) CsvFile(org.openmuc.framework.driver.csv.CsvFile) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException) CsvDriver(org.openmuc.framework.driver.csv.CsvDriver) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException) Test(org.junit.Test)

Aggregations

ScanException (org.openmuc.framework.config.ScanException)12 IOException (java.io.IOException)5 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)5 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)4 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)3 DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)3 DriverNotAvailableException (org.openmuc.framework.config.DriverNotAvailableException)3 InterruptedIOException (java.io.InterruptedIOException)2 ArrayList (java.util.ArrayList)2 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)2 DriverService (org.openmuc.framework.driver.spi.DriverService)2 DataMessage (org.openmuc.j62056.DataMessage)2 DataSet (org.openmuc.j62056.DataSet)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Test (org.junit.Test)1 ValueType (org.openmuc.framework.data.ValueType)1