Search in sources :

Example 1 with DataRecord

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;
}
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 DataRecord

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;
}
Also used : MBusDataRecord(net.solarnetwork.node.io.mbus.MBusDataRecord) DecodingException(org.openmuc.jmbus.DecodingException) MBusDataRecord(net.solarnetwork.node.io.mbus.MBusDataRecord) DataRecord(org.openmuc.jmbus.DataRecord) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) MBusMessage(net.solarnetwork.node.io.mbus.MBusMessage) WMBusMessage(org.openmuc.jmbus.wireless.WMBusMessage)

Example 3 with DataRecord

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;
}
Also used : MBusDataRecord(net.solarnetwork.node.io.mbus.MBusDataRecord) DecodingException(org.openmuc.jmbus.DecodingException) MBusDataRecord(net.solarnetwork.node.io.mbus.MBusDataRecord) DataRecord(org.openmuc.jmbus.DataRecord) MBusData(net.solarnetwork.node.io.mbus.MBusData)

Example 4 with DataRecord

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;
    }
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) MBusConnection(org.openmuc.jmbus.MBusConnection) ArrayList(java.util.ArrayList) DataRecord(org.openmuc.jmbus.DataRecord) IOException(java.io.IOException) VariableDataStructure(org.openmuc.jmbus.VariableDataStructure) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 5 with DataRecord

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);
    }
}
Also used : DataRecord(org.openmuc.jmbus.DataRecord)

Aggregations

DataRecord (org.openmuc.jmbus.DataRecord)6 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)3 MBusDataRecord (net.solarnetwork.node.io.mbus.MBusDataRecord)2 Record (org.openmuc.framework.data.Record)2 ChannelRecordContainer (org.openmuc.framework.driver.spi.ChannelRecordContainer)2 DecodingException (org.openmuc.jmbus.DecodingException)2 MBusConnection (org.openmuc.jmbus.MBusConnection)2 MBusData (net.solarnetwork.node.io.mbus.MBusData)1 MBusMessage (net.solarnetwork.node.io.mbus.MBusMessage)1 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)1 WMBusMessage (org.openmuc.jmbus.wireless.WMBusMessage)1 SerialPortTimeoutException (org.openmuc.jrxtx.SerialPortTimeoutException)1