mirror of
https://github.com/RfidResearchGroup/RFIDtools.git
synced 2026-05-12 11:19:59 -07:00
Merge pull request #41 from xianglin1998/master
PN53X communication bug fixed.
This commit is contained in:
@@ -58,7 +58,7 @@ dependencies {
|
||||
implementation 'com.github.xianglin1998:nfctag:1.0'
|
||||
implementation 'com.github.xianglin1998:nfc_console:1.0'
|
||||
|
||||
implementation 'com.github.xianglin1998:ComBridge:1.0.3'
|
||||
implementation 'com.github.xianglin1998:ComBridge:v1.0.4'
|
||||
|
||||
implementation project(':utils')
|
||||
implementation project(':libnfc_pn53x')
|
||||
|
||||
@@ -24,7 +24,7 @@ dependencies {
|
||||
implementation 'com.github.xianglin1998:mfkey:1.1'
|
||||
implementation 'com.github.xianglin1998:nfctag:1.0'
|
||||
|
||||
implementation 'com.github.xianglin1998:ComBridge:1.0.3'
|
||||
implementation 'com.github.xianglin1998:ComBridge:v1.0.4'
|
||||
|
||||
implementation project(path: ':utils')
|
||||
implementation project(path: ':communication')
|
||||
|
||||
@@ -24,5 +24,5 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.github.felHR85:UsbSerial:6.1.0'
|
||||
implementation 'androidx.annotation:annotation:1.1.0'
|
||||
implementation 'com.github.xianglin1998:ComBridge:1.0.3'
|
||||
implementation 'com.github.xianglin1998:ComBridge:v1.0.4'
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.github.xianglin1998:nfctag:1.0'
|
||||
implementation 'com.github.xianglin1998:nfc_console:1.0'
|
||||
implementation 'com.github.xianglin1998:ComBridge:1.0.3'
|
||||
implementation 'com.github.xianglin1998:ComBridge:v1.0.4'
|
||||
|
||||
implementation project(path: ':communication')
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ void c_close() {
|
||||
|
||||
int c_read(uint8_t *pbtRx, size_t szRx, int timeout) {
|
||||
if (sp != INVALID_SERIAL_PORT) {
|
||||
uart_reconfigure_timeouts(388);
|
||||
size_t recvLen = 0;
|
||||
size_t *pRecvLen = &recvLen;
|
||||
if (uart_receive(sp, pbtRx, szRx, pRecvLen) == NFC_SUCCESS) {
|
||||
@@ -34,7 +33,6 @@ int c_read(uint8_t *pbtRx, size_t szRx, int timeout) {
|
||||
|
||||
int c_write(const uint8_t *pbtTx, size_t szTx, int timeout) {
|
||||
if (sp != INVALID_SERIAL_PORT) {
|
||||
uart_reconfigure_timeouts((uint32_t) timeout);
|
||||
if (uart_send(sp, pbtTx, szTx) == NFC_SUCCESS) {
|
||||
return szTx;
|
||||
}
|
||||
|
||||
@@ -68,19 +68,12 @@ typedef struct {
|
||||
#define UART_FPC_CLIENT_RX_TIMEOUT_MS 200
|
||||
#define UART_TCP_CLIENT_RX_TIMEOUT_MS 500
|
||||
|
||||
// see pm3_cmd.h
|
||||
struct timeval timeout = {
|
||||
.tv_sec = 0, // 0 second
|
||||
.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000
|
||||
};
|
||||
|
||||
uint32_t newtimeout_value = 0;
|
||||
bool newtimeout_pending = false;
|
||||
|
||||
int uart_reconfigure_timeouts(uint32_t value) {
|
||||
|
||||
newtimeout_value = value;
|
||||
newtimeout_pending = true;
|
||||
newtimeout_value = value;
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -88,9 +81,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
serial_port_unix *sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t));
|
||||
if (sp == 0) return INVALID_SERIAL_PORT;
|
||||
|
||||
// init timeouts
|
||||
timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
if (memcmp(pcPortName, "tcp:", 4) == 0) {
|
||||
struct addrinfo *addr = NULL, *rp;
|
||||
char *addrstr = strdup(pcPortName + 4);
|
||||
@@ -101,8 +91,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
char *colon = strrchr(addrstr, ':');
|
||||
const char *portstr;
|
||||
if (colon) {
|
||||
@@ -172,9 +160,6 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
// we must use max timeout!
|
||||
timeout.tv_usec = UART_TCP_CLIENT_RX_TIMEOUT_MS * 1000;
|
||||
|
||||
size_t servernameLen = (strlen(pcPortName) - 7) + 1;
|
||||
char serverNameBuf[servernameLen];
|
||||
memset(serverNameBuf, '\0', servernameLen);
|
||||
@@ -295,20 +280,17 @@ void uart_close(const serial_port sp) {
|
||||
int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) {
|
||||
uint32_t byteCount; // FIONREAD returns size on 32b
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
if (newtimeout_pending) {
|
||||
timeout.tv_usec = newtimeout_value * 1000;
|
||||
newtimeout_pending = false;
|
||||
}
|
||||
// Reset the output count
|
||||
*pszRxLen = 0;
|
||||
do {
|
||||
// Reset file descriptor
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(((serial_port_unix *) sp)->fd, &rfds);
|
||||
tv = timeout;
|
||||
int res = select(((serial_port_unix *) sp)->fd + 1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
// int res = select(((serial_port_unix *) sp)->fd + 1, &rfds, NULL, NULL, NULL);
|
||||
struct timeval timeval = {.tv_sec = 2};
|
||||
int res = select(((serial_port_unix *) sp)->fd + 1, &rfds, NULL, NULL, &timeval);
|
||||
|
||||
// Read error
|
||||
if (res < 0) {
|
||||
@@ -346,7 +328,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||
// Stop if the OS has some troubles reading the data
|
||||
if (res <= 0) {
|
||||
return NFC_EIO;
|
||||
} else if (res > 0 && pszMaxRxLen > 255) { // 只有USB通信下才有大于255个字节的通信请求
|
||||
} else if (res > 0 && pszMaxRxLen >= 255) { // 只有USB通信下才有大于255个字节的通信请求
|
||||
*pszRxLen += res;
|
||||
/*
|
||||
* TODO Look me!
|
||||
@@ -355,7 +337,7 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||
* The communication process of PM3 is very different from the implementation of libnfc
|
||||
* (libnfc always requires about 265 bytes of data).
|
||||
* If we keep blocking and waiting, the program will be very slow,
|
||||
* so we need to return the data directly without waiting for enough 265 bytes.
|
||||
* so we need to return the data directly without waiting for enough 255 bytes.
|
||||
*
|
||||
* 这个UART实现是从PM3的开源库里拷贝过来的。
|
||||
* PM3的通信过程跟LIBNFC的实现有非常大的区别(LIBNFC某些驱动实现总是要求255个字节左右的数据),
|
||||
@@ -378,30 +360,9 @@ int uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uin
|
||||
|
||||
int uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
|
||||
uint32_t pos = 0;
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
while (pos < len) {
|
||||
// Reset file descriptor
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(((serial_port_unix *) sp)->fd, &rfds);
|
||||
tv = timeout;
|
||||
int res = select(((serial_port_unix *) sp)->fd + 1, NULL, &rfds, NULL, &tv);
|
||||
|
||||
// Write error
|
||||
if (res < 0) {
|
||||
printf("UART:: write error (%d)\n", res);
|
||||
return NFC_EIO;
|
||||
}
|
||||
|
||||
// Write time-out
|
||||
if (res == 0) {
|
||||
printf("UART:: write time-out\n");
|
||||
return NFC_ETIMEOUT;
|
||||
}
|
||||
|
||||
// Send away the bytes
|
||||
res = write(((serial_port_unix *) sp)->fd, pbtTx + pos, len - pos);
|
||||
int res = write(((serial_port_unix *) sp)->fd, pbtTx + pos, len - pos);
|
||||
|
||||
// Stop if the OS has some troubles sending the data
|
||||
if (res <= 0)
|
||||
|
||||
@@ -87,9 +87,5 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed);
|
||||
/* Gets the current speed of the serial port, in baud.
|
||||
*/
|
||||
uint32_t uart_get_speed(const serial_port sp);
|
||||
|
||||
/* Reconfigure timeouts
|
||||
*/
|
||||
int uart_reconfigure_timeouts(uint32_t value);
|
||||
#endif // _UART_H_
|
||||
|
||||
|
||||
@@ -41,6 +41,6 @@ android {
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation project(':communication')
|
||||
implementation 'com.github.xianglin1998:ComBridge:1.0.3'
|
||||
implementation 'com.github.xianglin1998:ComBridge:v1.0.4'
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ dependencies {
|
||||
implementation 'com.github.xianglin1998:nfctag:1.0'
|
||||
implementation 'com.github.xianglin1998:nfc_console:1.0'
|
||||
|
||||
implementation 'com.github.xianglin1998:ComBridge:1.0.3'
|
||||
implementation 'com.github.xianglin1998:ComBridge:v1.0.4'
|
||||
|
||||
implementation project(':communication')
|
||||
implementation project(path: ':utils')
|
||||
|
||||
Reference in New Issue
Block a user