Search in sources :

Example 1 with DriverNotAvailableException

use of org.openmuc.framework.config.DriverNotAvailableException 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 DriverNotAvailableException

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

the class DataManager method interruptDeviceScan.

@Override
public void interruptDeviceScan(String driverId) throws DriverNotAvailableException, UnsupportedOperationException {
    DriverService driver = activeDrivers.get(driverId);
    if (driver == null) {
        throw new DriverNotAvailableException();
    }
    driver.interruptDeviceScan();
}
Also used : DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) DriverService(org.openmuc.framework.driver.spi.DriverService)

Example 3 with DriverNotAvailableException

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

the class RestDriverWrapper method getDriver.

public static RestDriverWrapper getDriver(DriverConfig config, ConfigService configService, DataAccessService data) {
    boolean running;
    DriverInfo driver;
    try {
        driver = configService.getDriverInfo(config.getId());
        running = true;
    } catch (DriverNotAvailableException e) {
        driver = new DriverInfo(config.getId(), null, null, null, null, null);
        running = false;
    }
    List<RestDevice> devices = new LinkedList<RestDevice>();
    for (DeviceConfig device : config.getDevices()) {
        List<RestChannel> channels = new LinkedList<RestChannel>();
        for (ChannelConfig channel : device.getChannels()) {
            channels.add(RestChannelMapper.getRestChannel(data.getChannel(channel.getId())));
        }
        devices.add(RestDeviceMapper.getRestDevice(device, configService.getDeviceState(device.getId()), channels));
    }
    return new RestDriverWrapper(config, driver, devices, running);
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) DeviceConfig(org.openmuc.framework.config.DeviceConfig) DriverInfo(org.openmuc.framework.config.DriverInfo) LinkedList(java.util.LinkedList)

Example 4 with DriverNotAvailableException

use of org.openmuc.framework.config.DriverNotAvailableException 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;
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) ScanException(org.openmuc.framework.config.ScanException) ArrayList(java.util.ArrayList) DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) ArgumentSyntaxException(org.openmuc.framework.config.ArgumentSyntaxException)

Example 5 with DriverNotAvailableException

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

the class RestDeviceWrapper method getDevice.

public static RestDeviceWrapper getDevice(DeviceConfig config, ConfigService configService, DataAccessService data) {
    String driverId = config.getDriver().getId();
    DriverInfo driver;
    try {
        driver = configService.getDriverInfo(driverId);
    } catch (DriverNotAvailableException e) {
        driver = new DriverInfo(driverId, null, null, null, null, null);
    }
    List<RestChannel> channels = new LinkedList<RestChannel>();
    for (ChannelConfig channelConfig : config.getChannels()) {
        channels.add(RestChannelMapper.getRestChannel(data.getChannel(channelConfig.getId())));
    }
    return new RestDeviceWrapper(config, configService.getDeviceState(config.getId()), driver, channels);
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) DriverNotAvailableException(org.openmuc.framework.config.DriverNotAvailableException) DriverInfo(org.openmuc.framework.config.DriverInfo) LinkedList(java.util.LinkedList)

Aggregations

DriverNotAvailableException (org.openmuc.framework.config.DriverNotAvailableException)7 DriverService (org.openmuc.framework.driver.spi.DriverService)4 ScanException (org.openmuc.framework.config.ScanException)3 LinkedList (java.util.LinkedList)2 ChannelConfig (org.openmuc.framework.config.ChannelConfig)2 DriverInfo (org.openmuc.framework.config.DriverInfo)2 ArrayList (java.util.ArrayList)1 ArgumentSyntaxException (org.openmuc.framework.config.ArgumentSyntaxException)1 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 DeviceConfig (org.openmuc.framework.config.DeviceConfig)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1