Exemple #1
0
    private void comm(Pointer<hid_device> device) {
      log.debug("starting comm loop");
      Pointer<Byte> data = Pointer.allocateBytes(1024);
      HidapiLibrary.hid_set_nonblocking(device, 1);
      while (loop && connected) {
        int result = HidapiLibrary.hid_read(device, data, 1024);
        if (result > 0) {
          byte bytes[] = data.getBytes(result);
          messageQueue.addAll(parse(result, bytes));
        }

        BpmMessage msg = writeQueue.poll();
        if (msg != null) {
          encode(msg, writeBuffer);
          try {
            HidapiLibrary.hid_write(device, Pointer.pointerToBytes(writeBuffer), 9);
          } finally {
            writeBuffer.rewind();
          }
        }
      }
    }
Exemple #2
0
  /*
  	@Override
  	public Attribute setAttribute(Attribute attribute, Object value) {
  		byte[] b = (byte[])value;
  		attribute.value(Pointer.pointerToBytes(b));
  		attribute.size(b.length);
  		return attribute;
  	}

  	@Override
  	public Attribute createAttribute(AttributeType type) {
  		return createAttribute(type, getDefaultSize());
  	}

  	@Override
  	public Attribute createAttribute(AttributeType type, int size) {
  		return PKCS11.getInstance().createAttribute(type, new byte[size]);
  	}
  */
  @Override
  public Pair<Pointer<?>, Long> fromObject(Object value) {
    byte[] b = (byte[]) value;
    return new Pair<Pointer<?>, Long>(Pointer.pointerToBytes(b), (long) b.length);
  }