Search in sources :

Example 1 with MBusConnection

use of org.openmuc.jmbus.MBusConnection in project OpenMUC by isc-konstanz.

the class DriverConnectionTest method testReadThrowsIOException.

@Test
public void testReadThrowsIOException() 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 IOException());
    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);
    Flag actualFlag = records.get(0).getRecord().getFlag();
    assertEquals(Flag.DRIVER_ERROR_TIMEOUT, actualFlag);
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) IOException(java.io.IOException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) Flag(org.openmuc.framework.data.Flag) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with MBusConnection

use of org.openmuc.jmbus.MBusConnection in project OpenMUC by isc-konstanz.

the class DriverConnectionTest method testReadBcdDateLong.

@Test
public void testReadBcdDateLong() throws Exception {
    MBusConnection con = mock(MBusConnection.class);
    VariableDataStructure vds = new VariableDataStructure(SIEMENS_UH50_ANSWER, 6, SIEMENS_UH50_ANSWER.length - 6, null, null);
    vds.decode();
    when(con.read(anyInt())).thenReturn(vds);
    ConnectionInterface serialIntervace = new ConnectionInterface(con, "/dev/ttyS100:5", delay, interfaces);
    serialIntervace.increaseConnectionCounter();
    String[] deviceAddressTokens = { "/dev/ttyS100", "5" };
    DriverConnection mBusConnection = new DriverConnection(serialIntervace, Integer.parseInt(deviceAddressTokens[1]), null, delay);
    List<ChannelRecordContainer> records = new LinkedList<>();
    records.add(newChannelRecordContainer("09:74"));
    records.add(newChannelRecordContainer("42:6c"));
    records.add(newChannelRecordContainer("8c01:14"));
    mBusConnection.read(records, null, null);
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) ChannelRecordContainer(org.openmuc.framework.driver.spi.ChannelRecordContainer) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) LinkedList(java.util.LinkedList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with MBusConnection

use of org.openmuc.jmbus.MBusConnection 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 4 with MBusConnection

use of org.openmuc.jmbus.MBusConnection 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 5 with MBusConnection

use of org.openmuc.jmbus.MBusConnection in project OpenMUC by isc-konstanz.

the class DriverConnectionTest method newConnection.

private DriverConnection newConnection(String mBusAdresse) throws Exception {
    MBusConnection con = mock(MBusConnection.class);
    VariableDataStructure vds = new VariableDataStructure(NZR_ANSWER, 6, NZR_ANSWER.length - 6, null, null);
    vds.decode();
    PowerMockito.when(con.read(anyInt())).thenReturn(vds);
    ConnectionInterface serialIntervace = new ConnectionInterface(con, mBusAdresse, delay, interfaces);
    serialIntervace.increaseConnectionCounter();
    String[] deviceAddressTokens = mBusAdresse.trim().split(":");
    Integer mBusAddress;
    SecondaryAddress secondaryAddress = null;
    if (deviceAddressTokens[1].length() == 16) {
        mBusAddress = 0xfd;
        byte[] addressData = Helper.hexToBytes(deviceAddressTokens[1]);
        secondaryAddress = SecondaryAddress.newFromLongHeader(addressData, 0);
    } else {
        mBusAddress = Integer.decode(deviceAddressTokens[1]);
    }
    DriverConnection mBusConnection = new DriverConnection(serialIntervace, mBusAddress, secondaryAddress, delay);
    return mBusConnection;
}
Also used : MBusConnection(org.openmuc.jmbus.MBusConnection) SecondaryAddress(org.openmuc.jmbus.SecondaryAddress) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure)

Aggregations

MBusConnection (org.openmuc.jmbus.MBusConnection)20 Test (org.junit.Test)12 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 IOException (java.io.IOException)8 SerialPortTimeoutException (org.openmuc.jrxtx.SerialPortTimeoutException)5 InterruptedIOException (java.io.InterruptedIOException)4 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)4 DriverDeviceScanListener (org.openmuc.framework.driver.spi.DriverDeviceScanListener)3 ArrayList (java.util.ArrayList)2 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)2 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)2 DataRecord (org.openmuc.jmbus.DataRecord)2 MBusSerialBuilder (org.openmuc.jmbus.MBusConnection.MBusSerialBuilder)2 Parity (org.openmuc.jrxtx.Parity)2 LinkedList (java.util.LinkedList)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 DeviceScanInfo (org.openmuc.framework.config.DeviceScanInfo)1 ScanException (org.openmuc.framework.config.ScanException)1 ScanInterruptedException (org.openmuc.framework.config.ScanInterruptedException)1