Package org.nfctools.ndef.wkt.handover.records

Examples of org.nfctools.ndef.wkt.handover.records.HandoverSelectRecord


public class HandoverSelectRecordDecoder implements WellKnownRecordPayloadDecoder {

  @Override
  public WellKnownRecord decodePayload(byte[] payload, NdefMessageDecoder messageDecoder) {

    HandoverSelectRecord handoverSelectRecord = new HandoverSelectRecord();

    byte minorVersion = (byte)(payload[0] & 0x0F);
    byte majorVersion = (byte)((payload[0] >> 4) & 0x0F);

    handoverSelectRecord.setMinorVersion(minorVersion);
    handoverSelectRecord.setMajorVersion(majorVersion);

    // The Handover Selector MAY acknowledge zero, one, or more of the proposed alternative carriers at its own discretion.
    List<Record> records = messageDecoder.decodeToRecords(payload, 1, payload.length - 1);

    // Only Alternative Carrier Records and Error Records have a defined meaning in the payload of a Handover Select Record.
    // However, an implementation SHALL NOT raise an error if it encounters other record types, but SHOULD silently ignore them.
    for (int i = 0; i < records.size(); i++) {
      Record record = records.get(i);

      if (record instanceof AlternativeCarrierRecord) {
        handoverSelectRecord.add((AlternativeCarrierRecord)record);
      }
      else if (record instanceof ErrorRecord) {
        if (i == records.size() - 1) {
          handoverSelectRecord.setError((ErrorRecord)record);
        }
        else {
          // ignore
        }
      }
View Full Code Here


    byte[] message = getResource("/handover/1.2/BluetoothHandoverSelectMessage.bin");

    List<Record> records = decoder.decodeToRecords(message);
    assertEquals(2, records.size());

    HandoverSelectRecord handoverSelectRecord = (HandoverSelectRecord)records.get(0);

    assertEquals(1, handoverSelectRecord.getMajorVersion());
    assertEquals(2, handoverSelectRecord.getMinorVersion());

    List<AlternativeCarrierRecord> alternativeCarriers = handoverSelectRecord.getAlternativeCarriers();
    assertEquals(1, alternativeCarriers.size());

    AlternativeCarrierRecord alternativeCarrierRecord = alternativeCarriers.get(0);
    assertEquals(AlternativeCarrierRecord.CarrierPowerState.Active, alternativeCarrierRecord.getCarrierPowerState());
    assertEquals("0", alternativeCarrierRecord.getCarrierDataReference());
    assertFalse(alternativeCarrierRecord.hasAuxiliaryDataReferences());

    assertFalse(handoverSelectRecord.hasError());

    MimeRecord bluetooth = (MimeRecord)records.get(1);
    assertEquals("0", bluetooth.getKey());
  }
View Full Code Here

    byte[] message = getResource("/handover/1.2/BluetoothHandoverSelectMessageTag.bin");

    List<Record> records = decoder.decodeToRecords(message);
    assertEquals(2, records.size());

    HandoverSelectRecord handoverSelectRecord = (HandoverSelectRecord)records.get(0);

    assertEquals(1, handoverSelectRecord.getMajorVersion());
    assertEquals(2, handoverSelectRecord.getMinorVersion());

    List<AlternativeCarrierRecord> alternativeCarriers = handoverSelectRecord.getAlternativeCarriers();
    assertEquals(1, alternativeCarriers.size());

    AlternativeCarrierRecord alternativeCarrierRecord = alternativeCarriers.get(0);
    assertEquals(AlternativeCarrierRecord.CarrierPowerState.Unknown,
        alternativeCarrierRecord.getCarrierPowerState()); // note: active in figure, but unknown in table
    assertEquals("0", alternativeCarrierRecord.getCarrierDataReference());
    assertFalse(alternativeCarrierRecord.hasAuxiliaryDataReferences());

    assertFalse(handoverSelectRecord.hasError());

    MimeRecord bluetooth = (MimeRecord)records.get(1);
    assertEquals("0", bluetooth.getKey());
  }
View Full Code Here

public class HandoverSelectRecordEncoder implements WellKnownRecordPayloadEncoder {

  @Override
  public byte[] encodePayload(WellKnownRecord wellKnownRecord, NdefMessageEncoder messageEncoder) {

    HandoverSelectRecord handoverSelectRecord = (HandoverSelectRecord)wellKnownRecord;

    ByteArrayOutputStream payload = new ByteArrayOutputStream();

    // major version, minor version
    payload.write((handoverSelectRecord.getMajorVersion() << 4) | handoverSelectRecord.getMinorVersion());

    // implementation note: write alternative carriers and error record together
    if (handoverSelectRecord.hasError() && handoverSelectRecord.hasAlternativeCarriers()) {

      List<Record> records = new ArrayList<Record>();

      // n alternative carrier records
      records.addAll(handoverSelectRecord.getAlternativeCarriers());

      // an error message
      records.add(handoverSelectRecord.getError());

      messageEncoder.encode(records, payload);
    }
    else if (handoverSelectRecord.hasAlternativeCarriers()) {

      // n alternative carrier records
      messageEncoder.encode(handoverSelectRecord.getAlternativeCarriers(), payload);
    }
    else if (handoverSelectRecord.hasError()) {

      // an error message
      messageEncoder.encodeSingle(handoverSelectRecord.getError(), payload);
    }
    else {
      // do nothing
    }
View Full Code Here

TOP

Related Classes of org.nfctools.ndef.wkt.handover.records.HandoverSelectRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.