Search in sources :

Example 1 with SerialPortTimeoutException

use of org.openmuc.jrxtx.SerialPortTimeoutException in project OpenMUC by isc-konstanz.

the class DriverConnection method setRecords.

private boolean setRecords(List<ChannelRecordContainer> containers, MBusConnection mBusConnection, long timestamp, List<DataRecord> dataRecords, String[] dibvibs) throws ConnectionException {
    boolean selectForReadoutSet = false;
    for (ChannelRecordContainer container : containers) {
        String channelAddress = container.getChannelAddress();
        if (channelAddress.startsWith("X")) {
            String[] dibAndVib = channelAddress.split(":");
            if (dibAndVib.length != 2) {
                container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_ADDRESS_SYNTAX_INVALID));
            }
            List<DataRecord> dataRecordsToSelectForReadout = new ArrayList<>(1);
            selectForReadoutSet = true;
            try {
                mBusConnection.selectForReadout(mBusAddress, dataRecordsToSelectForReadout);
                sleep(delay);
            } catch (SerialPortTimeoutException e) {
                container.setRecord(new Record(Flag.DRIVER_ERROR_TIMEOUT));
                continue;
            } catch (IOException e) {
                connectionInterface.close();
                throw new ConnectionException(e);
            }
            VariableDataStructure variableDataStructure2 = null;
            try {
                variableDataStructure2 = mBusConnection.read(mBusAddress);
            } catch (SerialPortTimeoutException e1) {
                container.setRecord(new Record(Flag.DRIVER_ERROR_TIMEOUT));
                continue;
            } catch (IOException e1) {
                connectionInterface.close();
                throw new ConnectionException(e1);
            }
            DataRecord dataRecord = variableDataStructure2.getDataRecords().get(0);
            setContainersRecord(timestamp, container, dataRecord);
            continue;
        }
        int j = 0;
        for (DataRecord dataRecord : dataRecords) {
            if (dibvibs[j++].equalsIgnoreCase(channelAddress)) {
                setContainersRecord(timestamp, container, dataRecord);
                break;
            }
        }
        if (container.getRecord() == null) {
            container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND));
        }
    }
    return selectForReadoutSet;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) DataRecord(org.openmuc.jmbus.DataRecord) Record(org.openmuc.framework.data.Record) DataRecord(org.openmuc.jmbus.DataRecord) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 2 with SerialPortTimeoutException

use of org.openmuc.jrxtx.SerialPortTimeoutException in project OpenMUC by isc-konstanz.

the class DriverConnectionTest method testReadThrowsTimeoutException.

@Test
public void testReadThrowsTimeoutException() throws Exception {
    MBusConnection con = mock(MBusConnection.class);
    VariableDataStructure vds = new VariableDataStructure(NZR_ANSWER, 6, NZR_ANSWER.length - 6, null, null);
    vds.decode();
    when(con.read(anyInt())).thenThrow(new SerialPortTimeoutException());
    ConnectionInterface serialIntervace = new ConnectionInterface(con, "/dev/ttyS100:5", delay, interfaces);
    serialIntervace.increaseConnectionCounter();
    String[] deviceAddressTokens = { "/dev/ttyS100", "5" };
    int address = Integer.parseInt(deviceAddressTokens[1]);
    DriverConnection driverCon = new DriverConnection(serialIntervace, address, null, delay);
    List<ChannelRecordContainer> records = Arrays.asList(newChannelRecordContainer("04:03"));
    driverCon.read(records, null, null);
    assertEquals(Flag.DRIVER_ERROR_TIMEOUT, records.get(0).getRecord().getFlag());
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with SerialPortTimeoutException

use of org.openmuc.jrxtx.SerialPortTimeoutException in project OpenMUC by isc-konstanz.

the class DriverConnectionTest method testScanThrowsTimeoutException.

@Test(expected = ConnectionException.class)
public void testScanThrowsTimeoutException() throws Exception {
    MBusConnection con = mock(MBusConnection.class);
    VariableDataStructure vds = new VariableDataStructure(NZR_ANSWER, 6, NZR_ANSWER.length - 6, null, null);
    vds.decode();
    when(con.read(anyInt())).thenThrow(new SerialPortTimeoutException());
    ConnectionInterface serialIntervace = new ConnectionInterface(con, "/dev/ttyS100:5", delay, interfaces);
    serialIntervace.increaseConnectionCounter();
    String[] deviceAddressTokens = { "/dev/ttyS100", "5" };
    DriverConnection driverCon = new DriverConnection(serialIntervace, Integer.parseInt(deviceAddressTokens[1]), null, delay);
    driverCon.scanForChannels(null);
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with SerialPortTimeoutException

use of org.openmuc.jrxtx.SerialPortTimeoutException in project OpenMUC by isc-konstanz.

the class DriverTest method testMBusSapReadThrowsTimeoutException.

@Test(expected = ConnectionException.class)
public void testMBusSapReadThrowsTimeoutException() throws Exception {
    Driver mdriver = new Driver();
    MBusConnection mockedMBusSap = PowerMockito.mock(MBusConnection.class);
    PowerMockito.whenNew(MBusConnection.class).withAnyArguments().thenReturn(mockedMBusSap);
    PowerMockito.doThrow(new SerialPortTimeoutException()).when(mockedMBusSap).linkReset(ArgumentMatchers.anyInt());
    mdriver.connect("/dev/ttyS100:5", "2400:sc");
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with SerialPortTimeoutException

use of org.openmuc.jrxtx.SerialPortTimeoutException in project OpenMUC by isc-konstanz.

the class DriverTest method scan.

// ******************* SCAN TESTS ********************//
private static void scan(String settings) throws Exception {
    MBusConnection con = mock(MBusConnection.class);
    PowerMockito.whenNew(MBusConnection.class).withAnyArguments().thenReturn(con);
    PowerMockito.when(con.read(1)).thenReturn(new VariableDataStructure(null, 0, 0, null, null));
    PowerMockito.when(con.read(250)).thenThrow(new SerialPortTimeoutException());
    PowerMockito.when(con.read(anyInt())).thenThrow(new SerialPortTimeoutException());
    Driver mdriver = new Driver();
    mdriver.interruptDeviceScan();
    mdriver.scanForDevices(settings, mock(DriverDeviceScanListener.class));
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) SerialPortTimeoutException(org.openmuc.jrxtx.SerialPortTimeoutException) DriverDeviceScanListener(org.openmuc.framework.driver.spi.DriverDeviceScanListener) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure)

Aggregations

SerialPortTimeoutException (org.openmuc.jrxtx.SerialPortTimeoutException)6 MBusConnection (org.openmuc.jmbus.MBusConnection)5 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)5 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 IOException (java.io.IOException)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)2 InterruptedIOException (java.io.InterruptedIOException)1 ArrayList (java.util.ArrayList)1 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)1 Record (org.openmuc.framework.data.Record)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1 DataRecord (org.openmuc.jmbus.DataRecord)1