make style
This commit is contained in:
parent
1b11450312
commit
238be3f068
3 changed files with 31 additions and 31 deletions
|
@ -60,14 +60,13 @@
|
||||||
|
|
||||||
# if defined (__linux__)
|
# if defined (__linux__)
|
||||||
const char *i2c_ports_device_radix[] =
|
const char *i2c_ports_device_radix[] =
|
||||||
{ "i2c-", NULL };
|
{ "i2c-", NULL };
|
||||||
# else
|
# else
|
||||||
# error "Can't determine I2C devices standard names for your system"
|
# error "Can't determine I2C devices standard names for your system"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
|
||||||
struct i2c_device
|
struct i2c_device {
|
||||||
{
|
|
||||||
int fd; // I2C device file descriptor
|
int fd; // I2C device file descriptor
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,7 +113,7 @@ i2c_close(const i2c_device id)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
i2c_read(i2c_device id, uint8_t *pbtRx, const size_t szRx, void *abort_p,
|
i2c_read(i2c_device id, uint8_t *pbtRx, const size_t szRx, void *abort_p,
|
||||||
int timeout)
|
int timeout)
|
||||||
{
|
{
|
||||||
int iAbortFd = abort_p ? *((int *) abort_p) : 0;
|
int iAbortFd = abort_p ? *((int *) abort_p) : 0;
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ i2c_write(i2c_device id, const uint8_t *pbtTx, const size_t szTx, int timeout)
|
||||||
|
|
||||||
if ((const ssize_t) szTx == writeCount) {
|
if ((const ssize_t) szTx == writeCount) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
|
||||||
"wrote %d bytes successfully.", szTx);
|
"wrote %d bytes successfully.", szTx);
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
|
||||||
|
@ -175,14 +174,14 @@ i2c_list_ports(void)
|
||||||
|
|
||||||
res[0] = NULL;
|
res[0] = NULL;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
if ((dir = opendir("/dev")) == NULL ) {
|
if ((dir = opendir("/dev")) == NULL) {
|
||||||
perror("opendir error: /dev");
|
perror("opendir error: /dev");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
struct dirent entry;
|
struct dirent entry;
|
||||||
struct dirent *result;
|
struct dirent *result;
|
||||||
|
|
||||||
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL )) {
|
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
|
||||||
const char **p = i2c_ports_device_radix;
|
const char **p = i2c_ports_device_radix;
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (!strncmp(entry.d_name, *p, strlen(*p))) {
|
if (!strncmp(entry.d_name, *p, strlen(*p))) {
|
||||||
|
|
|
@ -55,6 +55,6 @@ int i2c_read(i2c_device id, uint8_t *pbtRx, const size_t szRx, void *abor
|
||||||
|
|
||||||
int i2c_write(i2c_device id, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
int i2c_write(i2c_device id, const uint8_t *pbtTx, const size_t szTx, int timeout);
|
||||||
|
|
||||||
char ** i2c_list_ports(void);
|
char **i2c_list_ports(void);
|
||||||
|
|
||||||
#endif // __NFC_BUS_I2C_H__
|
#endif // __NFC_BUS_I2C_H__
|
||||||
|
|
|
@ -188,13 +188,13 @@ pn532_i2c_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
// pn532_i2c:<i2c_device>
|
// pn532_i2c:<i2c_device>
|
||||||
int connstring_decode_level = connstring_decode(connstring, PN532_I2C_DRIVER_NAME, NULL, &i2c_devname, NULL);
|
int connstring_decode_level = connstring_decode(connstring, PN532_I2C_DRIVER_NAME, NULL, &i2c_devname, NULL);
|
||||||
|
|
||||||
switch(connstring_decode_level) {
|
switch (connstring_decode_level) {
|
||||||
case 2:
|
case 2:
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_dev = i2c_open(i2c_devname, PN532_I2C_ADDR);
|
i2c_dev = i2c_open(i2c_devname, PN532_I2C_ADDR);
|
||||||
|
@ -347,12 +347,12 @@ pn532_i2c_wait_rdyframe(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLe
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
gettimeofday(&start_tv, NULL );
|
gettimeofday(&start_tv, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Wait a little bit before reading */
|
/* Wait a little bit before reading */
|
||||||
nanosleep(&rdyDelay, (struct timespec *) NULL );
|
nanosleep(&rdyDelay, (struct timespec *) NULL);
|
||||||
|
|
||||||
int recCount = i2c_read(DRIVER_DATA(pnd)->dev, i2cRx, szDataLen + 1, abort_p, timeout);
|
int recCount = i2c_read(DRIVER_DATA(pnd)->dev, i2cRx, szDataLen + 1, abort_p, timeout);
|
||||||
|
|
||||||
|
@ -372,22 +372,22 @@ pn532_i2c_wait_rdyframe(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLe
|
||||||
|
|
||||||
done = true;
|
done = true;
|
||||||
res = recCount - 1;
|
res = recCount - 1;
|
||||||
copyLength = MIN (res, (int)szDataLen);
|
copyLength = MIN(res, (int)szDataLen);
|
||||||
memcpy(pbtData, &(i2cRx[1]), copyLength);
|
memcpy(pbtData, &(i2cRx[1]), copyLength);
|
||||||
} else {
|
} else {
|
||||||
/* Not ready yet. Check for elapsed timeout. */
|
/* Not ready yet. Check for elapsed timeout. */
|
||||||
|
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
gettimeofday(&cur_tv, NULL );
|
gettimeofday(&cur_tv, NULL);
|
||||||
duration = (cur_tv.tv_sec - start_tv.tv_sec) * 1000000L
|
duration = (cur_tv.tv_sec - start_tv.tv_sec) * 1000000L
|
||||||
+ (cur_tv.tv_usec - start_tv.tv_usec);
|
+ (cur_tv.tv_usec - start_tv.tv_usec);
|
||||||
|
|
||||||
if (duration / 1000 > timeout) {
|
if (duration / 1000 > timeout) {
|
||||||
res = NFC_ETIMEOUT;
|
res = NFC_ETIMEOUT;
|
||||||
done = 1;
|
done = 1;
|
||||||
|
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
|
||||||
"timeout reached with no RDY frame.");
|
"timeout reached with no RDY frame.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,9 +429,9 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
|
|
||||||
// Verify length checksum
|
// Verify length checksum
|
||||||
if (((frameBuf[5] + frameBuf[6] + frameBuf[7]) % 256) != 0) {
|
if (((frameBuf[5] + frameBuf[6] + frameBuf[7]) % 256) != 0) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch");
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
TFI_idx = 8;
|
TFI_idx = 8;
|
||||||
} else {
|
} else {
|
||||||
|
@ -440,7 +440,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
len = frameBuf[3];
|
len = frameBuf[3];
|
||||||
|
|
||||||
// Verify length checksum
|
// Verify length checksum
|
||||||
if ((uint8_t) (frameBuf[3] + frameBuf[4])) {
|
if ((uint8_t)(frameBuf[3] + frameBuf[4])) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch");
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -448,7 +448,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
TFI_idx = 5;
|
TFI_idx = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((len-2) > szDataLen) {
|
if ((len - 2) > szDataLen) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data: buffer too small. (szDataLen: %" PRIuPTR ", len: %" PRIuPTR ")", szDataLen, len);
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -461,9 +461,9 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameBuf[TFI_idx +1] != CHIP_DATA(pnd)->last_command + 1) {
|
if (frameBuf[TFI_idx + 1] != CHIP_DATA(pnd)->last_command + 1) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed. (got %d, expected %d)",
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed. (got %d, expected %d)",
|
||||||
frameBuf[TFI_idx +1], CHIP_DATA(pnd)->last_command + 1);
|
frameBuf[TFI_idx + 1], CHIP_DATA(pnd)->last_command + 1);
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
|
|
||||||
// Compute data checksum
|
// Compute data checksum
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
btDCS += frameBuf[TFI_idx +i];
|
btDCS += frameBuf[TFI_idx + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (btDCS != 0) {
|
if (btDCS != 0) {
|
||||||
|
@ -483,7 +483,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0x00 != frameBuf[TFI_idx + len + 1]) {
|
if (0x00 != frameBuf[TFI_idx + len + 1]) {
|
||||||
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame postamble mismatch (got %d)", frameBuf[frameLength -1]);
|
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame postamble mismatch (got %d)", frameBuf[frameLength - 1]);
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -512,7 +512,8 @@ static int
|
||||||
pn532_i2c_abort_command(nfc_device *pnd)
|
pn532_i2c_abort_command(nfc_device *pnd)
|
||||||
{
|
{
|
||||||
if (pnd) {
|
if (pnd) {
|
||||||
DRIVER_DATA(pnd)->abort_flag = true; }
|
DRIVER_DATA(pnd)->abort_flag = true;
|
||||||
|
}
|
||||||
return NFC_SUCCESS;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue