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);
}
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);
}
}
}
}
Aggregations