use of org.openmuc.jmbus.VariableDataStructure 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);
}
use of org.openmuc.jmbus.VariableDataStructure 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;
}
use of org.openmuc.jmbus.VariableDataStructure in project OpenMUC by isc-konstanz.
the class DriverTest method testInterrupedException.
@Test(expected = ScanInterruptedException.class)
public void testInterrupedException() throws Exception {
final Driver mdriver = new Driver();
DriverDeviceScanListener ddsl = mock(DriverDeviceScanListener.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
mdriver.interruptDeviceScan();
return null;
}
}).when(ddsl).deviceFound(any(DeviceScanInfo.class));
MBusConnection con = mock(MBusConnection.class);
when(con.read(anyInt())).thenReturn(new VariableDataStructure(null, 0, 0, null, null));
whenNew(MBusConnection.class).withAnyArguments().thenReturn(con);
doNothing().when(con).linkReset(ArgumentMatchers.anyInt());
PowerMockito.when(con.read(ArgumentMatchers.anyInt())).thenReturn(null);
mdriver.scanForDevices("/dev/ttyS100:2400", ddsl);
}
use of org.openmuc.jmbus.VariableDataStructure in project OpenMUC by isc-konstanz.
the class Driver method scanPrimaryAddress.
private void scanPrimaryAddress(DriverDeviceScanListener listener, Settings settings, MBusConnection mBusConnection) throws ScanInterruptedException, ScanException {
VariableDataStructure dataStructure = null;
for (int i = 0; i <= 250; i++) {
if (interruptScan) {
throw new ScanInterruptedException();
}
if (i % 5 == 0) {
listener.scanProgressUpdate(i * 100 / 250);
}
logger.debug("scanning for meter with primary address {}", i);
try {
dataStructure = mBusConnection.read(i);
sleep(settings.delay);
} catch (InterruptedIOException e) {
logger.debug("No meter found on address {}", i);
continue;
} catch (IOException e) {
throw new ScanException(e);
} catch (ConnectionException e) {
throw new ScanException(e);
}
String description = "";
if (dataStructure != null) {
SecondaryAddress secondaryAddress = dataStructure.getSecondaryAddress();
description = getScanDescription(secondaryAddress);
}
listener.deviceFound(new DeviceScanInfo(settings.scanConnectionAddress + ':' + i, "", description));
logger.debug("Meter found on address {}", i);
}
}
use of org.openmuc.jmbus.VariableDataStructure in project OpenMUC by isc-konstanz.
the class DriverConnection method scanForChannels.
@Override
public List<ChannelScanInfo> scanForChannels(String settings) throws UnsupportedOperationException, ConnectionException {
int scanDelay = 50 + this.delay;
synchronized (connectionInterface) {
List<ChannelScanInfo> channelScanInfo = new ArrayList<>();
try {
MBusConnection mBusConnection = connectionInterface.getMBusConnection();
if (secondaryAddress != null) {
mBusConnection.selectComponent(secondaryAddress);
} else {
mBusConnection.linkReset(mBusAddress);
sleep(delay);
mBusConnection.resetReadout(mBusAddress);
}
VariableDataStructure variableDataStructure;
do {
sleep(scanDelay);
variableDataStructure = mBusConnection.read(mBusAddress);
List<DataRecord> dataRecords = variableDataStructure.getDataRecords();
for (DataRecord dataRecord : dataRecords) {
fillDataRecordInChannelScanInfo(channelScanInfo, dataRecord);
}
} while (variableDataStructure.moreRecordsFollow());
} catch (IOException e) {
throw new ConnectionException(e);
}
return channelScanInfo;
}
}
Aggregations