示例#1
0
  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;
  }
  /**
   * An internal helper function which collects decoded bits and assembles messages
   *
   * @param b a decoded bit
   */
  private void addBit(final boolean b) {
    final int bit = b ? 1 : 0;

    decodedDataValue = decodedDataValue + bit;
    decodedMessageValue = decodedMessageValue + bit;

    data <<= 1;
    data |= bit;

    bitCounter++;

    // Check if a single data is receive
    if (bitCounter % (MCZDecoderV2.MESSAGE_LENGTH / MCZDecoderV2.NB_DATA_BY_MESSAGE) == 0) {
      // log(" DATA : " + Long.toBinaryString(data) + " 0x"
      // + Long.toHexString(data) + " " + data + " | ", false);
      //
      // log(decodedDataValue + " 0x"
      // + Long.toHexString(Long.parseLong(decodedDataValue, 2))
      // + " " + Long.parseLong(decodedDataValue, 2), true);

      datas.add(data);
      data = 0;
    }

    // Check if this is a complete message
    if (bitCounter == MCZDecoderV2.MESSAGE_LENGTH) {
      String hexMessage = "";

      for (final Long data : datas) {
        hexMessage += "0x" + Long.toHexString(data) + " ";
      }
      if (repeatCount == 0) {
        log("Message : " + hexMessage, true);
      }

      // Create the message
      final ProtocolMessage message = new ProtocolMessage("MCZ V2", 2, 6, 7);
      for (int i = 0; i < 7; i++) {
        message.setRawMessageByteAt(i, datas.get(i).intValue());
      }

      message.addField(new FieldValue("Message", hexMessage));

      // Check if this is a repeat
      if (decodedMessageValue.equals(lastDecodedMessageValue)) {
        repeatCount++;
        message.setRepeat(repeatCount);
      } else {
        repeatCount = 0;
      }

      // Report the parsed message
      sink.parsedMessage(message);
      lastDecodedMessageValue = decodedMessageValue;
      data = 0;
      bitCounter = 0;
      state = MCZDecoderV2.IDLE;
    }
  }