0

我正在使用 API 来控制连接到 android 设备的指纹扫描仪。我需要调用的本机方法需要将指针和双指针的混合传递给该方法,但我不确定如何执行此操作。

原始的 C 方法具有以下定义:

BioErrType BioGetTemplates(BioHandle handle, char **badgeNumberList,uint8_t *templateIndexList, BioTemplate **bioTemplateList)

提供的用于调用它的 Java 方法是:

public native int BioGetTemplates(int handle, int [] badgeNumberList, byte [] templateIndexList, byte [][]bioTemplateList);

原始 C 方法的文档指出:

***    Gets from the biometric device a template for each of the listed
***  badge numbers.
***  
***    The badgeNumberList pointer is a pointer to a null terminated array
***  of pointers to badge number strings.  The bioTemplateList should be an
***  array of pointers to memory where templates can be stored, one pointer
***  for each possible template returned.
***    The templateIndexList is a pointer to an array of template indices.
***  If templateIndexList is not null, than its size must be the same as the
***  number of badge number strings provided via badgeNumberList, which must
***  be the same size as the array of template pointers provided via
***  bioTemplateList. If templateIndexList is null, than the bioTemplateList
***  array size must be a device specific multiple of the number of badge
***  numbers.  For all current devices, this multiple is 2, corresponding to
***  a primary and secondary template for each badge number.
***    Each template is copied from the device to the memory at the
***  corresponding pointer in the bioTemplateList. If no template for a
***  given badge number and template index is stored in the device, the
***  corresponding pointer in the bioTemplateList is set to NULL.  If a
***  template pointer in bioTemplateList is NULL and yet a template exists
***  for the corresponding badge number and index, BIOAPI_INVALID is returned.
***    The applications program shall provide a separate buffer, of a size
***  specific to the device type, for every template it expects.
***
***  returns:
***    BIOAPI_OK if all templates found were copied to the provided template
***  buffers.
***    BIOAPI_INVALID if the handle is invalid or the badgeNumberList pointer
***  is null or if the bioTemplateList pointer is null, or if any badge
***  number in the list is invalid, or if any template index is out of range
***  for the device, or if a null template pointer is provided for a
***  template that is requested and is in the device, or if the device could
***  not successfully be talked to.  This error code can be returned even if
***  some of the templates were copied from the device, if the function was
***  not able to complete.
***    BIOAPI_BUSY if another thread is currently using the library.

我目前尝试调用代码:

            int[] badgeNumberList = { 100, 0 };
            byte[] templateIndexList = new byte[2 * (badgeNumberList.length - 1)];
            byte[][] bioTemplateList = new byte[1][2];

            try {
                mBio.bioGetTemplates(badgeNumberList, templateIndexList,
                        bioTemplateList);

                byte[] byteArr = bioTemplateList[0];
                BigInteger bigTemplate = new BigInteger(byteArr);

                Log.d(TAG, CLASS + "." + METHOD + " BigInt is: "
                        + bigTemplate.toString());

            } catch (BioError e) {
                Log.w(TAG, CLASS + "." + METHOD + ": " + e.getMessage());

            }

请注意,mBio 对象是提供的 Java API 的外观,它处理传入句柄并根据方法的整数返回引发错误。

我意识到我没有对输出做正确的事情,但到目前为止我只想看到一些输出,然后我可以稍后处理它。

当前运行此代码会引发 BIOAPI_INVALID 错误。

我目前无法在设备本身上调试,只能写入日志。

谢谢你提供的所有帮助。

4

2 回答 2

1

我与编写 API 的人交谈过,正确的调用是:

int[] badgeNumberList = new int[] { 100, 200 };
byte[] templateIndexList = new byte[] { 0, 0 };
byte[][] bioTemplateList = new byte[2][TEMPLATE_SIZE];

mBio.getTemplates(badgeNumberList, templateIndexList, bioTemplateList);
于 2013-06-11T13:52:14.370 回答
0

这只是一个猜测。

BIOAPI_INVALID: ...if any badge number in the list is invalid, ...

0可能无效吗?

如果我正在设计 Java API,我会省略诸如“空终止数组”之类的概念,这些概念仅服务于弱 C 数据结构。所以,int [] badgeNumberList只是一个徽章编号列表。

尝试:

int[] badgeNumberList = { 100 };

您确实需要 Java API 的文档。

于 2013-06-06T12:34:59.790 回答