public void decodeMessage(long binaryMessage) { int command = (int) (binaryMessage >> 4) & 0x1; int address = (int) ((binaryMessage >> 6) & ((1 << 26) - 1)); int button = (int) ((binaryMessage & 0x0F) + ((binaryMessage & 0x20) >> 1) + 1); ProtocolMessage message = new ProtocolMessage("NexaL", command, address, 4); message.setRawMessageByteAt(3, (int) (binaryMessage & 0xFF)); message.setRawMessageByteAt(2, (int) ((binaryMessage >> 8) & 0xFF)); message.setRawMessageByteAt(1, (int) ((binaryMessage >> 16) & 0xFF)); message.setRawMessageByteAt(0, (int) ((binaryMessage >> 24) & 0xFF)); message.addField(new FieldValue("Command", command)); message.addField(new FieldValue("Address", address)); message.addField(new FieldValue("Button", button)); // It is, check if this really is a repeat if ((m_RepeatCount > 0) && (binaryMessage == m_LastData)) { message.setRepeat(m_RepeatCount); } else { // It is not a repeat, reset counter m_RepeatCount = 0; } // Report the parsed message m_Sink.parsedMessage(message); if (m_PrintAnalyze) { analyzer.printPulses(); } m_State = READING_LAST_BIT_MARK; }
/** {@inheritDoc} */ @Override public boolean sendMessageToSubscriber(ProtocolMessage protocolMessage, AndesContent content) throws AndesException { boolean sendSuccess; DeliverableAndesMetadata messageMetadata = protocolMessage.getMessage(); if (messageMetadata.isRetain()) { recordRetainedMessage(messageMetadata.getMessageID()); } // Should get the message from the list ByteBuffer message = MQTTUtils.getContentFromMetaInformation(content); // Will publish the message to the respective queue if (null != mqqtServerChannel) { try { // TODO:review - instead of getSubscribedDestination() used message destination mqqtServerChannel.distributeMessageToSubscriber( wildcardDestination, message, messageMetadata.getMessageID(), messageMetadata.getQosLevel(), messageMetadata.isPersistent(), getMqttSubscriptionID(), getSubscriberQOS(), messageMetadata); // We will indicate the ack to the kernel at this stage // For MQTT QOS 0 we do not get ack from subscriber, hence will be implicitly creating an // ack if (QOSLevel.AT_MOST_ONCE.getValue() == getSubscriberQOS() || QOSLevel.AT_MOST_ONCE.getValue() == messageMetadata.getQosLevel()) { mqqtServerChannel.implicitAck(messageMetadata.getMessageID(), getChannelID()); } sendSuccess = true; } catch (MQTTException e) { final String error = "Error occurred while delivering message to the subscriber for message :" + messageMetadata.getMessageID(); log.error(error, e); throw new AndesException(error, e); } } else { sendSuccess = false; } return sendSuccess; }
@Override public String serialize(ProtocolMessage message) { return message.toString(); }