Package org.nfctools.ndef.wkt.records

Examples of org.nfctools.ndef.wkt.records.GenericControlRecord


*
*/
public class NdefExampleRecords {

  public static GenericControlRecord createVibrateModeGc() {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new TextRecord("PropertyManager")));
    gcr.setAction(new GcActionRecord(new TextRecord("SilentMode")));
    gcr.setData(new GcDataRecord(new TextRecord("VIBRATE")));
    return gcr;
  }
View Full Code Here


    gcr.setData(new GcDataRecord(new TextRecord("VIBRATE")));
    return gcr;
  }

  public static GenericControlRecord createNavigationGc() {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new TextRecord("Navigation")));
    gcr.setAction(new GcActionRecord(Action.DEFAULT_ACTION));
    gcr.setData(new GcDataRecord(new TextRecord("D", "Street 3, 12345 City")));
    return gcr;
  }
View Full Code Here

    gcr.setData(new GcDataRecord(new TextRecord("D", "Street 3, 12345 City")));
    return gcr;
  }

  public static GenericControlRecord createSilentModeGc() {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new TextRecord("PropertyManager")));
    gcr.setAction(new GcActionRecord(new TextRecord("SilentMode")));
    gcr.setData(new GcDataRecord(new TextRecord("ON")));
    return gcr;
  }
View Full Code Here

    gcr.setData(new GcDataRecord(new TextRecord("ON")));
    return gcr;
  }

  public static GenericControlRecord createSilentModeOffGc() {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new TextRecord("PropertyManager")));
    gcr.setAction(new GcActionRecord(new TextRecord("SilentMode")));
    gcr.setData(new GcDataRecord(new TextRecord("OFF")));
    return gcr;
  }
View Full Code Here

    gcr.setData(new GcDataRecord(new TextRecord("OFF")));
    return gcr;
  }

  public static GenericControlRecord createWifiSetting() {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new TextRecord("WifiManager")));
    gcr.setAction(new GcActionRecord(Action.DEFAULT_ACTION));
    gcr.setData(new GcDataRecord(new TextRecord("T", "WPA"), new TextRecord("S", "somelan"), new TextRecord("P",
        "26888282a6eff09dbc7e91e61dccf99bd660881ea69a6fad5941288f6cbc0f35")));
    return gcr;
  }
View Full Code Here

  public static final byte[] dataBytes = { (byte)0xd1, 0x01, 0x09, 0x54, 0x05, 0x65, 0x6e, 0x2d, 0x55, 0x53, 0x35,
      0x30, 0x30 };

  @Test
  public void testEncode() throws Exception {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new UriRecord(
        "file://localhost/Appli/CustomerBonus")));

    gcr.setAction(new GcActionRecord(new TextRecord("add", Charset.forName("utf8"), Locale.US)));
    gcr.setData(new GcDataRecord(new TextRecord("500", Locale.US)));

    byte[] encodedGcr = messageEncoder.encodeSingle(gcr);

    assertArrayEquals(GenericControlRecordDecoderTest.payload, encodedGcr);
  }
View Full Code Here

    assertArrayEquals(GenericControlRecordDecoderTest.payload, encodedGcr);
  }

  @Test
  public void testEncodeSimple() throws Exception {
    GenericControlRecord gcr = new GenericControlRecord(new GcTargetRecord(new UriRecord("http://localhost/test")));
    byte[] encodedGcr = messageEncoder.encodeSingle(gcr);

    assertEquals(encodedNdefSimple, NfcUtils.convertBinToASCII(encodedGcr));
  }
View Full Code Here

      0x64, 0x64, (byte)0xd1, 0x01, 0x0d, 0x64, (byte)0xd1, 0x01, 0x09, 0x54, 0x05, 0x65, 0x6e, 0x2d, 0x55, 0x53,
      0x35, 0x30, 0x30 };

  @Test
  public void testDecodeGenericControlRecordFromSpec() throws Exception {
    GenericControlRecord gcr = messageDecoder.decodeToRecord(payload);

    assertTrue(gcr.getTarget().getTargetIdentifier() instanceof UriRecord);

    UriRecord uriRecord = (UriRecord)gcr.getTarget().getTargetIdentifier();
    assertEquals("file://localhost/Appli/CustomerBonus", uriRecord.getUri());

    assertTrue(gcr.getAction().hasActionRecord());
    assertTrue(gcr.getAction().getActionRecord() instanceof TextRecord);

    TextRecord actionTextRecord = (TextRecord)gcr.getAction().getActionRecord();

    assertEquals("add", actionTextRecord.getText());

    assertEquals(1, gcr.getData().getRecords().size());
  }
View Full Code Here

    assertEquals(1, gcr.getData().getRecords().size());
  }

  @Test
  public void testDecode() throws Exception {
    GenericControlRecord gcr = messageDecoder.decodeToRecord(NfcUtils
        .convertASCIIToBin(GenericControlRecordEncoderTest.encodedNdefSimple));
    assertNotNull(gcr);
  }
View Full Code Here

public class GenericControlRecordEncoder implements WellKnownRecordPayloadEncoder {

  @Override
  public byte[] encodePayload(WellKnownRecord wellKnownRecord, NdefMessageEncoder messageEncoder) {
    GenericControlRecord myRecord = (GenericControlRecord)wellKnownRecord;

    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
     
      baos.write(myRecord.getConfigurationByte());

      if(!myRecord.hasTarget()) {
        throw new NdefEncoderException("Expected target", myRecord);
      }
      baos.write(messageEncoder.encodeSingle(myRecord.getTarget()));

      if (myRecord.getAction() != null)
        baos.write(messageEncoder.encodeSingle(myRecord.getAction()));
      if (myRecord.getData() != null)
        baos.write(messageEncoder.encodeSingle(myRecord.getData()));

      return baos.toByteArray();
    }
    catch (IOException e) {
      throw new RuntimeException(e);
View Full Code Here

TOP

Related Classes of org.nfctools.ndef.wkt.records.GenericControlRecord

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.