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;
}
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);
}
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());
}
});
}
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++;
}
}
}
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);
}
Aggregations