Search in sources :

Example 1 with DeviceScanInfo

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

the class FromJson method getDeviceScanInfoList.

public List<DeviceScanInfo> getDeviceScanInfoList() {
    List<DeviceScanInfo> returnValue = new ArrayList<>();
    // TODO: another name?
    JsonElement jse = jsonObject.get(Const.CHANNELS);
    JsonArray jsa;
    if (jse.isJsonArray()) {
        jsa = jse.getAsJsonArray();
        Iterator<JsonElement> jseIterator = jsa.iterator();
        while (jseIterator.hasNext()) {
            JsonObject jso = jseIterator.next().getAsJsonObject();
            String id = getString(jso.get(Const.ID));
            String deviceAddress = getString(jso.get(Const.ADDRESS));
            String settings = getString(jso.get(Const.SETTINGS));
            String description = getString(jso.get(Const.DESCRIPTION));
            returnValue.add(new DeviceScanInfo(id, deviceAddress, settings, description));
        }
    } else {
        returnValue = null;
    }
    return returnValue;
}
Also used : JsonArray(com.google.gson.JsonArray) DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 2 with DeviceScanInfo

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

the class ToJson method addDeviceScanInfoList.

public void addDeviceScanInfoList(List<DeviceScanInfo> deviceScanInfoList) {
    JsonArray jsa = new JsonArray();
    for (DeviceScanInfo deviceScanInfo : deviceScanInfoList) {
        JsonObject jso = new JsonObject();
        jso.addProperty(Const.ID, deviceScanInfo.getId());
        jso.addProperty(Const.ADDRESS, deviceScanInfo.getAddress());
        jso.addProperty(Const.SETTINGS, deviceScanInfo.getSettings());
        jso.addProperty(Const.DESCRIPTION, deviceScanInfo.getDescription());
        jsa.add(jso);
    }
    jsonObject.add(Const.DEVICES, jsa);
}
Also used : JsonArray(com.google.gson.JsonArray) DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) JsonObject(com.google.gson.JsonObject)

Example 3 with DeviceScanInfo

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

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

the class CsvScanner method scan.

@Override
public void scan(DriverDeviceScanListener listener) throws ArgumentSyntaxException, ScanException, ScanInterruptedException {
    logger.info("Scan for CSV files in directory: {}", path);
    interrupt = false;
    if (files != null) {
        final double numberOfFiles = files.length;
        double fileCounter = 0;
        int idCounter = 0;
        for (File file : files) {
            // check if device scan was interrupted
            if (interrupt) {
                break;
            }
            if (file.isFile()) {
                if (file.getName().endsWith("csv")) {
                    String deviceId = "csv_device_" + idCounter;
                    listener.deviceFound(new DeviceScanInfo(deviceId, file.getAbsolutePath(), DEFAULT_DEVICE_SETTINGS.toLowerCase(), file.getName()));
                }
            // else: do nothing, non csv files are ignored
            }
            // else: do nothing, folders are ignored
            fileCounter++;
            listener.scanProgressUpdate((int) (fileCounter / numberOfFiles * 100.0));
            idCounter++;
        }
    }
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo) File(java.io.File)

Example 5 with DeviceScanInfo

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

the class SnmpDriverDiscoveryListener method onNewDeviceFound.

@Override
public void onNewDeviceFound(SnmpDiscoveryEvent e) {
    DeviceScanInfo newDevice = new DeviceScanInfo(e.getDeviceAddress().toString(), null, e.getDescription());
    scannerListener.deviceFound(newDevice);
}
Also used : DeviceScanInfo(org.openmuc.framework.config.DeviceScanInfo)

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