use of org.openmuc.jmbus.DataRecord 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;
}
use of org.openmuc.jmbus.DataRecord in project solarnetwork-node by SolarNetwork.
the class JMBusConversion method from.
/**
* Convert a JMBus WMBus message
*
* @param message
* The JMBus WMBus message to convert
* @return A message
*/
public static MBusMessage from(WMBusMessage message) {
final MBusMessage msg = new MBusMessage(Instant.now());
msg.status = message.getVariableDataResponse().getStatus();
final VariableDataStructure vds = message.getVariableDataResponse();
try {
vds.decode();
} catch (DecodingException e) {
log.error("Failed to decode JMBus variable data structure: {}", e.getMessage());
}
for (DataRecord record : vds.getDataRecords()) {
final MBusDataRecord rec = from(record);
if (rec != null) {
msg.dataRecords.add(rec);
}
}
msg.moreRecordsFollow = message.getVariableDataResponse().moreRecordsFollow();
return msg;
}
use of org.openmuc.jmbus.DataRecord in project solarnetwork-node by SolarNetwork.
the class JMBusConversion method from.
public static MBusData from(VariableDataStructure vds) {
try {
final MBusData data = new MBusData(Instant.now());
data.status = vds.getStatus();
vds.decode();
for (DataRecord record : vds.getDataRecords()) {
final MBusDataRecord rec = from(record);
if (rec != null) {
data.dataRecords.add(rec);
}
}
return data;
} catch (DecodingException e) {
log.error("Failed to decode JMBus variable data structure: {}", e.getMessage());
}
return null;
}
use of org.openmuc.jmbus.DataRecord 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;
}
}
use of org.openmuc.jmbus.DataRecord in project OpenMUC by isc-konstanz.
the class DriverConnection method setDibVibs.
private void setDibVibs(List<DataRecord> dataRecords, String[] dibvibs) {
int i = 0;
for (DataRecord dataRecord : dataRecords) {
String dibHex = Helper.bytesToHex(dataRecord.getDib());
String vibHex = Helper.bytesToHex(dataRecord.getVib());
dibvibs[i++] = MessageFormat.format("{0}:{1}", dibHex, vibHex);
}
}
Aggregations