windows平台修改libnfc 1.7.0使其支持pn532_uart模块
来源:互联网 发布:附加数据库错误602 编辑:程序博客网 时间:2024/06/07 12:51
前几天写了一篇文章,详述了libnfc 1.7.0在windows下的编译过程,打开了对acr122u模块、pn53x_usb模块、pn532_uart模块等的支持,今天试了一下,发现在win下libnfc默认好像只扫描使用acr122_pcsc driver和pn53x_usb driver的模块,而我连接了pn532_uart模块之后提示没有找到NFC设备。
Debug模式编译运行nfc-list.exe输出如下:
unknown libnfc.general log_level is set to 3
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 0 device(s) defined by user
nfc-list.exe uses libnfc 1.7.0
debug libnfc.general 0 device(s) found using acr122_pcsc driver
debug libnfc.general 0 device(s) found using pn53x_usb driver
No NFC device found.
于是,我开始查找支持pn532_uart的方法,通过查看源码发现libnfc使用两种方式获取nfc设备:
1.自动扫描 autoscan
2.用户自定义设备 user_defined_device
libnfc支持读取libnfc.conf配置文件的方式加载用户定义的设备。
最开始,我尝试了在cmake生成的config.h里增加#define CONFFILES,重新编译的时候报错:
undefined reference to '_imp__regcomp'
这是由于conf.c里面调用了regcomp等函数,这些函数属于regex正则解析库,但是我使用的MinGW64里面没有这个库。
于是我复制了早期的MinGW的libregex库以及头文件,编译能通过,但是运行nfc-list.exe运行到读取配置文件时就出错退出了,估计还是正则库有问题。
libregex使用不了也没关系,其实可以修改conf.c去掉正则解析的过程,直接将参数赋值给nfc_context。
主要需要修改config.h和conf.c两个文件。
在config.h里增加 #define CONFFILES
修改conf.c如下:
#include "conf.h"#ifdef HAVE_CONFIG_H# include "config.h"#endif // HAVE_CONFIG_H#ifdef CONFFILES#include <stdio.h>#include <stdlib.h>#include <dirent.h>#include <string.h>#include <regex.h>#include <sys/stat.h>#include <nfc/nfc.h>#include "nfc-internal.h"#include "log.h"#define LOG_CATEGORY "libnfc.config"#define LOG_GROUP NFC_LOG_GROUP_CONFIG#ifndef LIBNFC_SYSCONFDIR// If this define does not already exists, we build it using SYSCONFDIR#ifndef SYSCONFDIR#error "SYSCONFDIR is not defined but required."#endif // SYSCONFDIR#define LIBNFC_SYSCONFDIR SYSCONFDIR"/nfc"#endif // LIBNFC_SYSCONFDIR//#define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf"//#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d"#define LIBNFC_CONFFILE "libnfc.conf"#define LIBNFC_DEVICECONFDIR "devices.d"static boolconf_parse_file(const char *filename, void (*conf_keyvalue)(void *data), void *data){ printf("Try to Conf Key Value by chenxupro\n"); conf_keyvalue(data); return true;}static voidconf_keyvalue_context(void *data){ nfc_context *context = (nfc_context *)data; //if (strcmp(key, "allow_autoscan") == 0) { string_as_boolean("true", &(context->allow_autoscan)); //} else if (strcmp(key, "allow_intrusive_scan") == 0) { string_as_boolean("false", &(context->allow_intrusive_scan)); //} else if (strcmp(key, "log_level") == 0) { context->log_level = atoi("2"); //} else if (strcmp(key, "device.name") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].name, "") != 0) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; } strcpy(context->user_defined_devices[context->user_defined_device_count - 1].name, "chenxupro PN532"); //} else if (strcmp(key, "device.connstring") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "") != 0) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; } strcpy(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "pn532_uart:COM9:115200");}void conf_load(nfc_context *context){ conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context);}#endif // CONFFILES
重新编译,运行结果如下:
unknown libnfc.general log_level is set to 2
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 1 device(s) defined by user
debug libnfc.general #0 name: "chenxupro PN532", connstring: "pn532_uart:COM9:115200"
debug libnfc.general 0 device(s) found using acr122_pcsc driver
debug libnfc.general 0 device(s) found using pn53x_usb driver
debug libnfc.driver.pn532_uart Attempt to open: COM9 at 115200 bauds.
Try to Conf Key Value by chenxupro
nfc-list.exe uses libnfc 1.7.0
NFC device: pn532_uart:COM9 opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 04
UID (NFCID1): 7d 88 c9 1d
SAK (SEL_RES): 08
- windows平台修改libnfc 1.7.0使其支持pn532_uart模块
- windows平台使用cmake编译libnfc 1.7.0 rc6全过程
- windows平台使用cmake编译libnfc 1.7.0 rc6全过程
- 修改mini hook,使其支持vc6.0,x64系统
- windows + CentOS查看和修改MySQL字符集,使其支持中文
- JqueryEasyUI修改DataGrid使其支持多选框
- JqueryEasyUI修改DataGrid使其支持多选框
- 修改tomcat使其支持中文
- 修改KXMl使其符合平台要求
- 英飞凌可信平台模块解决方案全新支持Windows 8
- [NFC] Use Libnfc On Windows
- Libnfc
- 修改ReadMorePlugin.java,使其支持中文标题(roller webblog)
- DirectShow 修改CCaptureVideo类,使其支持多次打开
- 修改ThinkPHP使其支持多级域名部署
- 修改r8169驱动,使其仅支持百兆
- 修改Android的编译文件使其支持wml
- 修改android monkey源码使其支持UI自动化测试
- ORACLE错误一览表
- 抽象数据类型Triplet的表示和实现
- Android修改默认浏览器为其他浏览器(UC)
- AfxSocketInit()
- 在myeclipse中启动tomcat7.0.19时报的错误
- windows平台修改libnfc 1.7.0使其支持pn532_uart模块
- 如何从jar包中检索特定规则的代码
- android85--两个Activity之间怎么传递数据?
- 第六周项目2-2
- android86--Parcelable 和Serializable
- MC9S12 底层驱动
- 数据结构之二叉查找树
- 鸟哥的Linux私房菜基础学习篇(第三版)之第十一章:认识与学习BASH
- android87--