Search in sources :

Example 1 with MBusMessageHandler

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

use of net.solarnetwork.node.io.mbus.MBusMessageHandler 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)2 MBusMessageHandler (net.solarnetwork.node.io.mbus.MBusMessageHandler)2 MBusData (net.solarnetwork.node.io.mbus.MBusData)1 MBusDataRecord (net.solarnetwork.node.io.mbus.MBusDataRecord)1 MBusSecondaryAddress (net.solarnetwork.node.io.mbus.MBusSecondaryAddress)1 Test (org.junit.Test)1 SecondaryAddress (org.openmuc.jmbus.SecondaryAddress)1 WMBusMessage (org.openmuc.jmbus.wireless.WMBusMessage)1