Exemplo n.º 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;
    }
  }
Exemplo n.º 3
0
 /* (non-Javadoc)
  * @see ssg.ir.IRDecoder#parse(java.lang.Double)
  */
 public int parse(double pulse, boolean state) {
   switch (m_State) {
     case IDLE:
       {
         if (NEXA_HEADER_MARK.matches(pulse) && (m_LastPulse > (NEXA_REPEAT.length() / 2))) {
           m_State = READING_HEADER_SPACE;
         }
         break;
       }
     case READING_HEADER_SPACE:
       {
         if (NEXA_HEADER_SPACE.matches(pulse)) {
           m_State = READING_BIT_MARK_BEFORE;
           m_Data = 0;
           m_BitCounter = 0;
         } else {
           m_State = IDLE;
         }
         break;
       }
     case READING_BIT_MARK_BEFORE:
       {
         if (NEXA_MARK.matches(pulse)) {
           m_State = READING_BIT_SPACE;
         } else {
           m_Sink.partiallyParsedMessage("NexaL BMB " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
         }
         break;
       }
     case READING_BIT_SPACE:
       {
         if (NEXA_SHORT_SPACE.matches(pulse)) {
           m_State = READING_BIT_MARK_AFTER_SHORT;
           addBit(0);
         } else if (NEXA_LONG_SPACE.matches(pulse)) {
           m_State = READING_BIT_MARK_AFTER_LONG;
           addBit(1);
         } else {
           m_Sink.partiallyParsedMessage("NexaL BS " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
         }
         break;
       }
     case READING_BIT_MARK_AFTER_SHORT:
       {
         if (NEXA_MARK.matches(pulse)) {
           m_State = READING_INTER_SPACE_LONG;
         } else {
           m_Sink.partiallyParsedMessage("NexaL BMAS " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
         }
         break;
       }
     case READING_BIT_MARK_AFTER_LONG:
       {
         if (NEXA_MARK.matches(pulse)) {
           m_State = READING_INTER_SPACE_SHORT;
         } else {
           m_Sink.partiallyParsedMessage("NexaL BMAL " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
         }
         break;
       }
     case READING_INTER_SPACE_SHORT:
       {
         if (NEXA_SHORT_INTER_SPACE.matches(pulse)) {
           m_State = READING_BIT_MARK_BEFORE;
         } else {
           m_Sink.partiallyParsedMessage("NexaL ISS " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
         }
         break;
       }
     case READING_INTER_SPACE_LONG:
       {
         if (NEXA_LONG_INTER_SPACE.matches(pulse)) {
           m_State = READING_BIT_MARK_BEFORE;
         } else {
           m_Sink.partiallyParsedMessage("NexaL ISL " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
         }
         break;
       }
     case READING_LAST_BIT_MARK:
       {
         if (NEXA_MARK.matches(pulse)) {
           m_State = READING_TRAILING_SPACE;
         } else {
           m_Sink.partiallyParsedMessage("NexaL LBM " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
           m_RepeatCount = 0;
         }
         break;
       }
     case READING_TRAILING_SPACE:
       {
         if (NEXA_LONG_INTER_SPACE.matches(pulse) || NEXA_SHORT_INTER_SPACE.matches(pulse)) {
           m_State = READING_TRAILING_MARK;
         } else {
           m_Sink.partiallyParsedMessage("NexaL TS " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
           m_RepeatCount = 0;
         }
         break;
       }
     case READING_TRAILING_MARK:
       {
         if (NEXA_MARK.matches(pulse)) {
           m_State = REPEAT_SCAN;
         } else {
           m_Sink.partiallyParsedMessage("NexaL TM " + Double.toString(pulse), m_BitCounter);
           m_State = IDLE;
           m_RepeatCount = 0;
         }
         break;
       }
     case REPEAT_SCAN:
       {
         if (NEXA_REPEAT.matches(pulse)) {
           m_RepeatCount += 1; // Start repeat sequence
           // Save this sequence
           m_LastData = m_Data;
         } else {
           m_RepeatCount = 0;
         }
         m_State = IDLE;
         break;
       }
   }
   m_LastPulse = pulse;
   return m_State;
 }