public AddressData getAddress() { byte[] data = getData(); AddressData addressData = null; switch (getOpCode()) { case RC_BIND_ACCEPTED_LOCO: case RC_BIND_ACCEPTED_ACCESSORY: addressData = AddressData.fromByteArray(data, 2 + 5); break; default: LOGGER.warn("The current opCode is not RC_BIND_ACCEPTED!"); break; } return addressData; }
/** * 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 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; }
/** * 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; }