use of org.openmuc.framework.config.ChannelScanInfo 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);
}
}
use of org.openmuc.framework.config.ChannelScanInfo 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();
}
}
use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.
the class DeviceResourceServlet method scanForAllChannels.
private List<ChannelScanInfo> scanForAllChannels(String deviceId, String settings, HttpServletResponse response) {
List<ChannelScanInfo> channelList = new ArrayList<>();
List<ChannelScanInfo> scannedDevicesList;
try {
scannedDevicesList = configService.scanForChannels(deviceId, settings);
for (ChannelScanInfo scannedDevice : scannedDevicesList) {
channelList.add(scannedDevice);
}
} catch (UnsupportedOperationException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Device does not support scanning.", REST_ID, deviceId);
} catch (DriverNotAvailableException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_FOUND, logger, REQUESTED_ID_IS_NOT_AVAILABLE, REST_ID, deviceId);
} catch (ArgumentSyntaxException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_NOT_ACCEPTABLE, logger, "Argument syntax was wrong.", REST_ID, deviceId, " Settings = ", settings);
} catch (ScanException e) {
ServletLib.sendHTTPErrorAndLogDebug(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, logger, "Error while scan device channels", REST_ID, deviceId, " Settings = ", settings);
}
return channelList;
}
use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.
the class Iec61850ConnectionTest method testWrite.
@Test
public void testWrite() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
System.out.println("Attempting to connect to server " + host + " on port " + port);
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel, clientAssociation);
// ------------SCAN FOR CHANNELS-------------------
Iec61850Connection testIec61850Connection = new Iec61850Connection(clientAssociation, serverModel);
List<ChannelScanInfo> testChannelScanList = testIec61850Connection.scanForChannels("");
// ----------WRITE-----------------
List<ChannelValueContainer> testChannelValueContainers = new ArrayList<>();
byte[] newValue = { 0x44 };
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(14).getChannelAddress(), new ByteArrayValue(newValue)));
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(25).getChannelAddress(), new FloatValue((float) 12.5)));
testChannelValueContainers.add(new ChannelValueContainerImpl(testChannelScanList.get(24).getChannelAddress(), new BooleanValue(true)));
testIec61850Connection.write(testChannelValueContainers, null);
// Create record container to read the changes made by "write"
List<ChannelRecordContainer> testRecordContainers = new ArrayList<>();
for (int i = 0; i < 34; i++) {
testRecordContainers.add(new ChannelRecordContainerImpl(testChannelScanList.get(i).getChannelAddress()));
}
testIec61850Connection.read(testRecordContainers, null, "");
Assert.assertEquals("[68]", testRecordContainers.get(14).getRecord().getValue().toString());
Assert.assertEquals("12.5", testRecordContainers.get(25).getRecord().getValue().toString());
Assert.assertEquals("true", testRecordContainers.get(24).getRecord().getValue().toString());
}
use of org.openmuc.framework.config.ChannelScanInfo in project OpenMUC by isc-konstanz.
the class Iec61850ConnectionTest method testScanForChannels.
@Test
public void testScanForChannels() throws IOException, ServiceError, ConfigurationException, javax.naming.ConfigurationException, SclParseException, InterruptedException, UnsupportedOperationException, ConnectionException {
System.out.println("Attempting to connect to server " + host + " on port " + port);
clientAssociation = clientSap.associate(InetAddress.getByName(host), port, null, this);
ServerModel serverModel = SclParser.parse("src/test/resources/testOpenmuc.icd").get(0);
clientAssociation.setServerModel(serverModel);
getAllBdas(serverModel, clientAssociation);
Iec61850Connection testConnection = new Iec61850Connection(clientAssociation, serverModel);
List<ChannelScanInfo> testChannelScanList = testConnection.scanForChannels("");
for (int i = 14; i < 23; i++) {
System.out.print(testChannelScanList.get(i).getChannelAddress() + "\n");
Assert.assertEquals("BYTE_ARRAY", testChannelScanList.get(i).getValueType().toString());
}
Assert.assertEquals("LONG", testChannelScanList.get(23).getValueType().toString());
Assert.assertEquals("BOOLEAN", testChannelScanList.get(24).getValueType().toString());
Assert.assertEquals("FLOAT", testChannelScanList.get(25).getValueType().toString());
Assert.assertEquals("DOUBLE", testChannelScanList.get(26).getValueType().toString());
Assert.assertEquals("BYTE", testChannelScanList.get(27).getValueType().toString());
Assert.assertEquals("SHORT", testChannelScanList.get(28).getValueType().toString());
Assert.assertEquals("SHORT", testChannelScanList.get(29).getValueType().toString());
Assert.assertEquals("INTEGER", testChannelScanList.get(30).getValueType().toString());
Assert.assertEquals("INTEGER", testChannelScanList.get(31).getValueType().toString());
Assert.assertEquals("LONG", testChannelScanList.get(32).getValueType().toString());
Assert.assertEquals("LONG", testChannelScanList.get(33).getValueType().toString());
Assert.assertEquals("BYTE_ARRAY", testChannelScanList.get(34).getValueType().toString());
}
Aggregations