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

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


    assertEquals(0, handoverRequestRecord.getMinorVersion());
    assertNull(handoverRequestRecord.getCollisionResolution());

    assertEquals(1, handoverRequestRecord.getAlternativeCarriers().size());

    AlternativeCarrierRecord alternativeCarrierRecord = handoverRequestRecord.getAlternativeCarriers().get(0);
    assertEquals(CarrierPowerState.Active, alternativeCarrierRecord.getCarrierPowerState());
    assertEquals("0", alternativeCarrierRecord.getCarrierDataReference());
    assertEquals(0, alternativeCarrierRecord.getAuxiliaryDataReferences().size());

    BinaryMimeRecord binaryMimeRecord = (BinaryMimeRecord)records.get(1);
    assertArrayEquals(new byte[] { 0x30 }, binaryMimeRecord.getId());

  }
View Full Code Here


    assertEquals((0x01 << 8) | 0x02, collisionResolution.getRandomNumber());

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

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

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

    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

    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 AlternativeCarrierRecordEncoder implements WellKnownRecordPayloadEncoder {

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

    AlternativeCarrierRecord alternativeCarrierRecord = (AlternativeCarrierRecord)wellKnownRecord;

    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    // cps
    CarrierPowerState carrierPowerState = alternativeCarrierRecord.getCarrierPowerState();
    if (carrierPowerState == null) {
      throw new NdefEncoderException("Expected carrier power state", alternativeCarrierRecord);
    }
    bout.write(carrierPowerState.getValue() & 0x7); // 3 lsb

    // carrier data reference: 1
    String carrierDataReference = alternativeCarrierRecord.getCarrierDataReference();
    if (carrierDataReference == null) {
      throw new NdefEncoderException("Expected carrier data reference", alternativeCarrierRecord);
    }
    byte[] carrierDataReferenceChar = carrierDataReference.getBytes(NdefConstants.DEFAULT_CHARSET);
    if (carrierDataReferenceChar.length > 255) {
      throw new NdefEncoderException("Expected carrier data reference '" + carrierDataReference
          + "' <= 255 bytes", alternativeCarrierRecord);
    }
    // carrier data reference length (1)
    bout.write(carrierDataReferenceChar.length);
    // carrier data reference char
    bout.write(carrierDataReferenceChar, 0, carrierDataReferenceChar.length);

    // auxiliary data
    List<String> auxiliaryDataReferences = alternativeCarrierRecord.getAuxiliaryDataReferences();
    // auxiliary data reference count
    bout.write(auxiliaryDataReferences.size());

    for (String auxiliaryDataReference : auxiliaryDataReferences) {
View Full Code Here

public class AlternativeCarrierRecordDecoder implements WellKnownRecordPayloadDecoder {

  @Override
  public WellKnownRecord decodePayload(byte[] payload, NdefMessageDecoder messageDecoder) {
    AlternativeCarrierRecord alternativeCarrierRecord = new AlternativeCarrierRecord();

    // cps
    alternativeCarrierRecord.setCarrierPowerState(CarrierPowerState.toCarrierPowerState(payload[0]));

    // carrier data reference
    short carrierDataReferenceLength = (short)payload[1];
    alternativeCarrierRecord.setCarrierDataReference(new String(payload, 2, carrierDataReferenceLength,
        NdefConstants.DEFAULT_CHARSET));

    // auxiliary data reference
    short auxiliaryDataReferenceCount = (short)payload[2 + carrierDataReferenceLength];

    int index = 2 + carrierDataReferenceLength + 1;
    for (int i = 0; i < auxiliaryDataReferenceCount; i++) {
      short auxiliaryDataReferenceLength = (short)payload[index];

      alternativeCarrierRecord.addAuxiliaryDataReference(new String(payload, index + 1,
          auxiliaryDataReferenceLength, NdefConstants.DEFAULT_CHARSET));

      index += 1 + auxiliaryDataReferenceLength;
    }
View Full Code Here

TOP

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

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.