Search in sources :

Example 1 with MBusMessage

use of net.solarnetwork.node.io.mbus.MBusMessage 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 2 with MBusMessage

use of net.solarnetwork.node.io.mbus.MBusMessage in project solarnetwork-node by SolarNetwork.

the class WMBusDatumDataSourceTests method readDatumWithStatusInteger.

@Test
public void readDatumWithStatusInteger() throws IOException {
    // GIVEN
    MBusPropertyConfig[] propConfigs = new MBusPropertyConfig[] { new MBusPropertyConfig(TEST_STATUS_PROP_NAME, Status) };
    dataSource.setPropConfigs(propConfigs);
    final MBusMessage msg = new MBusMessage(Instant.now());
    final int expected = 7;
    msg.status = expected;
    // WHEN
    dataSource.handleMessage(msg);
    NodeDatum datum = dataSource.readCurrentDatum();
    // THEN
    assertThat("Datum returned", datum, notNullValue());
    assertThat("Created", datum.getTimestamp(), notNullValue());
    assertThat("Status", datum.asSampleOperations().getSampleInteger(Status, TEST_STATUS_PROP_NAME), equalTo(expected));
}
Also used : MBusPropertyConfig(net.solarnetwork.node.datum.mbus.MBusPropertyConfig) NodeDatum(net.solarnetwork.node.domain.datum.NodeDatum) MBusMessage(net.solarnetwork.node.io.mbus.MBusMessage) Test(org.junit.Test)

Example 3 with MBusMessage

use of net.solarnetwork.node.io.mbus.MBusMessage in project solarnetwork-node by SolarNetwork.

the class WMBusDatumDataSourceTests method readDatumWithInstantaneousValues.

@Test
public void readDatumWithInstantaneousValues() throws IOException {
    // GIVEN
    MBusPropertyConfig[] propConfigs = new MBusPropertyConfig[] { new MBusPropertyConfig(TEST_BCD_PROP_NAME, Instantaneous, MBusDataType.BCD, MBusDataDescription.Volume, BigDecimal.ONE, 3), new MBusPropertyConfig(TEST_DOUBLE_PROP_NAME, Instantaneous, MBusDataType.Double, MBusDataDescription.Energy, BigDecimal.ONE, 3), new MBusPropertyConfig(TEST_LONG_PROP_NAME, Instantaneous, MBusDataType.Long, MBusDataDescription.Current, BigDecimal.ONE, 0) };
    dataSource.setPropConfigs(propConfigs);
    final MBusMessage msg = new MBusMessage(Instant.now());
    msg.dataRecords.add(new MBusDataRecord(MBusDataDescription.Volume, MBusDataType.BCD, 27L, -3));
    msg.dataRecords.add(new MBusDataRecord(MBusDataDescription.Energy, 1.234, 0));
    msg.dataRecords.add(new MBusDataRecord(MBusDataDescription.Current, MBusDataType.Long, 874234L, 0));
    // WHEN
    dataSource.handleMessage(msg);
    NodeDatum datum = dataSource.readCurrentDatum();
    // THEN
    assertThat("Datum returned", datum, notNullValue());
    assertThat("Created", datum.getTimestamp(), notNullValue());
    assertThat("Source ID", datum.getSourceId(), equalTo(TEST_SOURCE_ID));
    assertThat("BCD value", datum.asSampleOperations().getSampleDouble(Instantaneous, TEST_BCD_PROP_NAME), equalTo(0.027));
    assertThat("Double value", datum.asSampleOperations().getSampleDouble(Instantaneous, TEST_DOUBLE_PROP_NAME), equalTo(1.234));
    assertThat("Long value", datum.asSampleOperations().getSampleDouble(Instantaneous, TEST_LONG_PROP_NAME), equalTo(874234.0));
}
Also used : MBusDataRecord(net.solarnetwork.node.io.mbus.MBusDataRecord) MBusPropertyConfig(net.solarnetwork.node.datum.mbus.MBusPropertyConfig) NodeDatum(net.solarnetwork.node.domain.datum.NodeDatum) MBusMessage(net.solarnetwork.node.io.mbus.MBusMessage) Test(org.junit.Test)

Example 4 with MBusMessage

use of net.solarnetwork.node.io.mbus.MBusMessage in project solarnetwork-node by SolarNetwork.

the class WMBusNetworkTests method receiveMessage.

@Test
public void receiveMessage() throws IOException, DecodingException {
    final byte[] bytes = copyToByteArray(WMBusNetworkTests.class.getResourceAsStream("wmbus-message.bin"));
    final WMBusMessage msg = WMBusMessageDecoder.decode(bytes, 0, keyMap);
    final MBusData expected = new MBusData(Instant.now());
    expected.dataRecords.add(new MBusDataRecord(MBusDataDescription.Volume, MBusDataType.BCD, 27L, -3));
    expected.dataRecords.add(new MBusDataRecord(MBusDataDescription.DateTime, Instant.ofEpochMilli(1593064440000L)));
    MBusMessageHandler messageHandler = EasyMock.createMock(MBusMessageHandler.class);
    messageHandler.handleMessage(new MBusMessage(expected));
    expectLastCall();
    replay(messageHandler);
    conn.open(messageHandler);
    network.newMessage(msg);
    verify(messageHandler);
}
Also used : WMBusMessage(org.openmuc.jmbus.wireless.WMBusMessage) MBusDataRecord(net.solarnetwork.node.io.mbus.MBusDataRecord) MBusMessageHandler(net.solarnetwork.node.io.mbus.MBusMessageHandler) MBusData(net.solarnetwork.node.io.mbus.MBusData) MBusMessage(net.solarnetwork.node.io.mbus.MBusMessage) WMBusMessage(org.openmuc.jmbus.wireless.WMBusMessage) Test(org.junit.Test)

Example 5 with MBusMessage

use of net.solarnetwork.node.io.mbus.MBusMessage in project solarnetwork-node by SolarNetwork.

the class JMBusWMBusNetwork method newMessage.

@Override
public void newMessage(org.openmuc.jmbus.wireless.WMBusMessage message) {
    SecondaryAddress addr = message.getSecondaryAddress();
    log.debug("JMBus data received from secondary address {}: {}", addr, message);
    // route message to all registered listeners
    if (addr != null) {
        Set<MBusMessageHandler> handlers = listeners.get(addr);
        if (handlers != null) {
            MBusMessage msg = JMBusConversion.from(message);
            for (MBusMessageHandler handler : handlers) {
                handler.handleMessage(msg);
            }
        }
    }
}
Also used : SecondaryAddress(org.openmuc.jmbus.SecondaryAddress) MBusSecondaryAddress(net.solarnetwork.node.io.mbus.MBusSecondaryAddress) MBusMessageHandler(net.solarnetwork.node.io.mbus.MBusMessageHandler) MBusMessage(net.solarnetwork.node.io.mbus.MBusMessage)

Aggregations

MBusMessage (net.solarnetwork.node.io.mbus.MBusMessage)6 MBusDataRecord (net.solarnetwork.node.io.mbus.MBusDataRecord)4 Test (org.junit.Test)4 MBusPropertyConfig (net.solarnetwork.node.datum.mbus.MBusPropertyConfig)3 NodeDatum (net.solarnetwork.node.domain.datum.NodeDatum)3 MBusData (net.solarnetwork.node.io.mbus.MBusData)2 MBusMessageHandler (net.solarnetwork.node.io.mbus.MBusMessageHandler)2 WMBusMessage (org.openmuc.jmbus.wireless.WMBusMessage)2 MBusSecondaryAddress (net.solarnetwork.node.io.mbus.MBusSecondaryAddress)1 DataRecord (org.openmuc.jmbus.DataRecord)1 DecodingException (org.openmuc.jmbus.DecodingException)1 SecondaryAddress (org.openmuc.jmbus.SecondaryAddress)1 VariableDataStructure (org.openmuc.jmbus.VariableDataStructure)1