/** * Create a TidData instance from the provided byte array. * * @param data * the byte array * @param offset * the offset to start * @return the TidData instance */ public static TidData fromByteArray(byte[] data, int offset) { if (data.length < (offset + 5)) { LOGGER.warn("The size of the provided data does not meet the expected length."); throw new IllegalArgumentException( "The size of the provided data does not meet the expected length (>=5). Provided length: " + data.length); } DecoderUniqueIdData uniqueIdData = DecoderUniqueIdData.fromByteArray(data, offset); int sid = ByteUtils.getInt(data[offset + 5]); TidData tidData = new TidData(uniqueIdData, sid); LOGGER.info("Return tidData: {}", tidData); return tidData; } }
/** * Create a RcPlusBindData instance from the provided byte array. * * @param data * the byte array * @param offset * the offset to start * @return the RcPlusBindData instance */ public static RcPlusBindData fromByteArray(byte[] data, int offset) { if (data.length < (offset + 7)) { LOGGER.warn("The size of the provided data does not meet the expected length."); throw new IllegalArgumentException( "The size of the provided data does not meet the expected length (=7). Provided length: " + data.length); } DecoderUniqueIdData uniqueIdData = DecoderUniqueIdData.fromByteArray(data, offset); AddressData address = AddressData.fromByteArray(data, offset + 5); RcPlusBindData answerData = new RcPlusBindData(uniqueIdData, address); LOGGER.trace("Return RcPlusBindData: {}", answerData); return answerData; }
/** * Create a RcPlusDecoderAnswerData instance from the provided byte array. * * @param data * the byte array * @param offset * the offset to start * @return the RcPlusDecoderAnswerData instance */ public static RcPlusDecoderAnswerData fromByteArray(byte[] data, int offset) { if (data.length < (offset + 5)) { LOGGER.warn("The size of the provided data does not meet the expected length."); throw new IllegalArgumentException( "The size of the provided data does not meet the expected length (>=5). Provided length: " + data.length); } RcPlusAcknowledge acknState = RcPlusAcknowledge.valueOf(data[offset]); DecoderUniqueIdData uniqueIdData = DecoderUniqueIdData.fromByteArray(data, offset + 1); RcPlusDecoderAnswerData answerData = new RcPlusDecoderAnswerData(acknState, uniqueIdData); LOGGER.trace("Return answerData: {}", answerData); return answerData; }
/** * Create a RcPlusDecoderAnswerData instance from the provided byte array. * * @param data * the byte array * @param offset * the offset to start * @return the RcPlusDecoderAnswerData instance */ public static RcPlusFeedbackBindData fromByteArray(byte[] data, int offset) { // TODO change this to be 7 after the GBM returns the address if (data.length < (offset + 5)) { LOGGER.warn("The size of the provided data does not meet the expected length."); throw new IllegalArgumentException( "The size of the provided data does not meet the expected length (=5). Provided length: " + data.length + ", offset: " + offset); } DecoderUniqueIdData uniqueIdData = DecoderUniqueIdData.fromByteArray(data, offset); AddressData address = null; if (data.length > (offset + 5)) { address = AddressData.fromByteArray(data, offset + 5); } RcPlusFeedbackBindData answerData = new RcPlusFeedbackBindData(uniqueIdData, address); LOGGER.info("Return RcPlusBindAcceptedData: {}", answerData); return answerData; }
public DecoderUniqueIdData getRcPlusUniqueId() { byte[] data = getData(); DecoderUniqueIdData uniqueIdData = null; switch (getOpCode()) { case RC_FIND_COLLISION_P0: case RC_FIND_COLLISION_P1: case RC_PONG_OKAY_LOCO_P0: case RC_PONG_OKAY_LOCO_P1: case RC_PONG_OKAY_ACCESSORY_P0: case RC_PONG_OKAY_ACCESSORY_P1: case RC_PONG_NEW_LOCO_P0: case RC_PONG_NEW_LOCO_P1: case RC_PONG_NEW_ACCESSORY_P0: case RC_PONG_NEW_ACCESSORY_P1: case RC_BIND_ACCEPTED_LOCO: case RC_BIND_ACCEPTED_ACCESSORY: uniqueIdData = DecoderUniqueIdData.fromByteArray(data, 2); break; default: LOGGER.warn("The current opCode is not RC_FIND_COLLISION or RC_PONG_OKAY/NEW or BIND_ACCEPTED!"); break; } return uniqueIdData; }
/** * Create a RcPlusBindAcceptedData instance from the provided byte array. * * @param data * the byte array * @param offset * the offset to start * @return the RcPlusBindAcceptedData instance */ public static RcPlusBindAcceptedData fromByteArray(byte[] data, int offset) { if (data.length < (offset + 7)) { LOGGER.warn("The size of the provided data does not meet the expected length."); throw new IllegalArgumentException( "The size of the provided data does not meet the expected length (=7). Provided length: " + data.length); } RcPlusAcknowledge acknState = RcPlusAcknowledge.valueOf(data[offset]); DecoderUniqueIdData uniqueIdData = DecoderUniqueIdData.fromByteArray(data, offset + 1); AddressData address = AddressData.fromByteArray(data, offset + 1 + 5); RcPlusBindAcceptedData answerData = new RcPlusBindAcceptedData(acknState, uniqueIdData, address); LOGGER.trace("Return RcPlusBindAcceptedData: {}", answerData); return answerData; }