diff --git a/src/dev_arygon.c b/src/dev_arygon.c index e8c8846..5810eae 100644 --- a/src/dev_arygon.c +++ b/src/dev_arygon.c @@ -68,14 +68,14 @@ static byte_t abtTxBuf[BUFFER_LENGTH] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, * @note ARYGON-APDB2UA33 (PN532 + ARYGON µC): 9600,n,8,1 */ -dev_info* dev_arygon_connect(const nfc_device_desc_t* device_desc) +dev_info* dev_arygon_connect(const nfc_device_desc_t* pndd) { uint32_t uiDevNr; serial_port sp; char acConnect[BUFFER_LENGTH]; dev_info* pdi = INVALID_DEVICE_INFO; - if( device_desc == NULL ) { + if( pndd == NULL ) { #ifdef DISABLE_SERIAL_AUTOPROBE INFO("Sorry, serial auto-probing have been disabled at compile time."); return INVALID_DEVICE_INFO; @@ -105,14 +105,14 @@ dev_info* dev_arygon_connect(const nfc_device_desc_t* device_desc) // Test if we have found a device if (uiDevNr == MAX_DEVICES) return INVALID_DEVICE_INFO; } else { - DBG("Connecting to: %s at %d bauds.",device_desc->port, device_desc->speed); - strcpy(acConnect,device_desc->port); + DBG("Connecting to: %s at %d bauds.",pndd->port, pndd->speed); + strcpy(acConnect,pndd->port); sp = rs232_open(acConnect); if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",acConnect); if (sp == CLAIMED_SERIAL_PORT) ERR("Serial port already claimed: %s",acConnect); if ((sp == CLAIMED_SERIAL_PORT) || (sp == INVALID_SERIAL_PORT)) return INVALID_DEVICE_INFO; - rs232_set_speed(sp, device_desc->speed); + rs232_set_speed(sp, pndd->speed); } DBG("Successfully connected to: %s",acConnect); diff --git a/src/rs232.c b/src/rs232.c index 20bab51..afaec69 100644 --- a/src/rs232.c +++ b/src/rs232.c @@ -32,7 +32,7 @@ available: http://www.teuniz.net/RS-232/index.html #ifndef _WIN32 typedef struct termios term_info; -typedef struct { +typedef struct { int fd; // Serial port file descriptor term_info tiOld; // Terminal info before using the port term_info tiNew; // Terminal info during the transaction @@ -40,7 +40,7 @@ typedef struct { // Set time-out on 30 miliseconds struct timeval tv = { - .tv_sec = 0, // No seconds + .tv_sec = 0, // 0 second .tv_usec = 30000 // 30,000 micro seconds }; @@ -88,6 +88,8 @@ serial_port rs232_open(const char* pcPortName) rs232_close(sp); return INVALID_SERIAL_PORT; } + + tcflush(sp, TCIFLUSH); return sp; } @@ -151,22 +153,25 @@ bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen) // Read error if (iResult < 0) { DBG("RX error."); + *puiRxLen = 0; + return false; + } + // Read time-out + if (iResult == 0) { + DBG("RX time-out."); + *puiRxLen = 0; return false; } // Number of bytes in the input buffer ioctl(((serial_port_unix*)sp)->fd, FIONREAD, &byteCount); - // Read time-out or empty buffer -#ifdef DEBUG - if (iResult == 0) { - DBG("RX time-out"); - } + // Empty buffer if (byteCount == 0) { - DBG("RX empty buffer"); + DBG("RX empty buffer."); + *puiRxLen = 0; + return false; } -#endif - if (iResult == 0 || byteCount == 0) return false; // There is something available, read the data *puiRxLen = read(((serial_port_unix*)sp)->fd,pbtRx,byteCount);