Code cleanup: remove many debug prints, enhance comments and documentation.
This commit is contained in:
parent
18e6e1bc7c
commit
5ac580a241
5 changed files with 25 additions and 33 deletions
|
@ -19,7 +19,7 @@
|
|||
|
||||
/**
|
||||
* @file acr122.c
|
||||
* @brief
|
||||
* @brief Driver for ACR122 devices (e.g. Tikitag, Touchatag, ACS ACR122)
|
||||
*/
|
||||
|
||||
#ifdef DRIVER_ACR122_ENABLED
|
||||
|
@ -160,12 +160,12 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
|
|||
// Retrieve the string array of all available pcsc readers
|
||||
if (SCardListReaders(*pscc,NULL,acDeviceNames,(void*)&szDeviceNamesLen) != SCARD_S_SUCCESS) return false;
|
||||
|
||||
DBG("%s", "PCSC reports following device(s):");
|
||||
// DBG("%s", "PCSC reports following device(s):");
|
||||
|
||||
while ((acDeviceNames[szPos] != '\0') && ((*pszDeviceFound) < szDevices)) {
|
||||
uiBusIndex++;
|
||||
|
||||
DBG("- %s (pos=%ld)", acDeviceNames + szPos, (unsigned long) szPos);
|
||||
// DBG("- %s (pos=%ld)", acDeviceNames + szPos, (unsigned long) szPos);
|
||||
|
||||
bSupported = false;
|
||||
for (i = 0; supported_devices[i] && !bSupported; i++) {
|
||||
|
@ -206,7 +206,7 @@ nfc_device_t* acr122_connect(const nfc_device_desc_t* pndd)
|
|||
|
||||
SCARDCONTEXT *pscc;
|
||||
|
||||
DBG("Connecting to %s",pndd->acDevice);
|
||||
DBG("Attempt to connect to %s",pndd->acDevice);
|
||||
// We no longer support connecting with a NULL
|
||||
if(pndd == NULL) return NULL;
|
||||
// Test if context succeeded
|
||||
|
|
|
@ -182,7 +182,7 @@ nfc_device_t* arygon_connect(const nfc_device_desc_t* pndd)
|
|||
DBG("%s", "arygon_connect() need an nfc_device_desc_t struct.");
|
||||
return NULL;
|
||||
} else {
|
||||
DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
|
||||
DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
|
||||
sp = uart_open(pndd->pcPort);
|
||||
|
||||
if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",pndd->pcPort);
|
||||
|
|
|
@ -161,7 +161,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
|
|||
DBG("%s", "pn532_uart_connect() need an nfc_device_desc_t struct.");
|
||||
return NULL;
|
||||
} else {
|
||||
DBG("Connecting to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
|
||||
DBG("Attempt to connect to: %s at %d bauds.",pndd->pcPort, pndd->uiSpeed);
|
||||
sp = uart_open(pndd->pcPort);
|
||||
|
||||
if (sp == INVALID_SERIAL_PORT) ERR("Invalid serial port: %s",pndd->pcPort);
|
||||
|
|
|
@ -63,14 +63,12 @@ void get_end_points(struct usb_device *dev, usb_spec_t* pus)
|
|||
// Test if we dealing with a bulk IN endpoint
|
||||
if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_IN)
|
||||
{
|
||||
DBG("Bulk endpoint in : 0x%02X", uiEndPoint);
|
||||
pus->uiEndPointIn = uiEndPoint;
|
||||
}
|
||||
|
||||
// Test if we dealing with a bulk OUT endpoint
|
||||
if((uiEndPoint & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_OUT)
|
||||
{
|
||||
DBG("Bulk endpoint in : 0x%02X", uiEndPoint);
|
||||
pus->uiEndPointOut = uiEndPoint;
|
||||
}
|
||||
}
|
||||
|
@ -89,10 +87,10 @@ bool pn53x_usb_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, s
|
|||
string[0]= '\0';
|
||||
usb_init();
|
||||
|
||||
// usb_find_busses will find all of the busses on the system. Returns the number of changes since previous call to this function (total of new busses and busses removed).
|
||||
if ((ret= usb_find_busses() < 0)) return false;
|
||||
DBG("%d busses",ret);
|
||||
// usb_find_devices will find all of the devices on each bus. This should be called after usb_find_busses. Returns the number of changes since the previous call to this function (total of new device and devices removed).
|
||||
if ((ret= usb_find_devices() < 0)) return false;
|
||||
DBG("%d devices",ret);
|
||||
|
||||
*pszDeviceFound = 0;
|
||||
|
||||
|
@ -102,7 +100,7 @@ bool pn53x_usb_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, s
|
|||
{
|
||||
for(i = 0; i < num_candidates; ++i)
|
||||
{
|
||||
DBG("Checking device %04x:%04x (%04x:%04x)",dev->descriptor.idVendor,dev->descriptor.idProduct,candidates[i].idVendor,candidates[i].idProduct);
|
||||
// DBG("Checking device %04x:%04x (%04x:%04x)",dev->descriptor.idVendor,dev->descriptor.idProduct,candidates[i].idVendor,candidates[i].idProduct);
|
||||
if (candidates[i].idVendor==dev->descriptor.idVendor && candidates[i].idProduct==dev->descriptor.idProduct)
|
||||
{
|
||||
// Make sure there are 2 endpoints available
|
||||
|
@ -136,18 +134,15 @@ bool pn53x_usb_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, s
|
|||
pnddDevices[*pszDeviceFound].pcDriver = target_name;
|
||||
pnddDevices[*pszDeviceFound].uiBusIndex = uiBusIndex;
|
||||
(*pszDeviceFound)++;
|
||||
DBG("%s","Match!");
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
if((*pszDeviceFound) == szDevices)
|
||||
{
|
||||
DBG("Found %ld devices", (unsigned long) *pszDeviceFound);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DBG("Found %ld devices", (unsigned long) *pszDeviceFound);
|
||||
if(*pszDeviceFound)
|
||||
return true;
|
||||
return false;
|
||||
|
@ -166,25 +161,21 @@ nfc_device_t* pn53x_usb_connect(const nfc_device_desc_t* pndd,const char * targe
|
|||
us.uiEndPointOut = 0;
|
||||
us.pudh = NULL;
|
||||
|
||||
|
||||
// must specify device to connect to
|
||||
if(pndd == NULL) return NULL;
|
||||
|
||||
DBG("Connecting %s device",target_name);
|
||||
DBG("Attempt to connect to %s device", target_name);
|
||||
usb_init();
|
||||
|
||||
uiBusIndex= pndd->uiBusIndex;
|
||||
|
||||
DBG("Skipping to device no. %d",uiBusIndex);
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next)
|
||||
{
|
||||
for (dev = bus->devices; dev; dev = dev->next, uiBusIndex--)
|
||||
{
|
||||
DBG("Checking device %04x:%04x",dev->descriptor.idVendor,dev->descriptor.idProduct);
|
||||
// DBG("Checking device %04x:%04x",dev->descriptor.idVendor,dev->descriptor.idProduct);
|
||||
if(uiBusIndex == 0)
|
||||
{
|
||||
DBG("Found device index %d", pndd->uiBusIndex);
|
||||
|
||||
// Open the USB device
|
||||
us.pudh = usb_open(dev);
|
||||
|
||||
|
@ -242,7 +233,6 @@ void pn53x_usb_disconnect(nfc_device_t* pnd)
|
|||
|
||||
free(pnd->nds);
|
||||
free(pnd);
|
||||
DBG("%s","done!");
|
||||
}
|
||||
|
||||
bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
|
@ -270,7 +260,6 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons
|
|||
// End of stream marker
|
||||
abtTx[szTxLen+6] = 0;
|
||||
|
||||
DBG("%s","pn53x_usb_transceive");
|
||||
#ifdef DEBUG
|
||||
PRINT_HEX("TX", abtTx,szTxLen+7);
|
||||
#endif
|
||||
|
|
11
libnfc/nfc.c
11
libnfc/nfc.c
|
@ -109,7 +109,6 @@ nfc_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *pszD
|
|||
{
|
||||
if (drivers_callbacks_list[uiDriver].list_devices != NULL)
|
||||
{
|
||||
DBG("List avaible device using %s driver",drivers_callbacks_list[uiDriver].acDriver);
|
||||
szN = 0;
|
||||
if (drivers_callbacks_list[uiDriver].list_devices (pnddDevices + (*pszDeviceFound), szDevices - (*pszDeviceFound), &szN))
|
||||
{
|
||||
|
@ -168,10 +167,8 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
|
|||
// Specific device is requested: using device description pndd
|
||||
if( 0 != strcmp(drivers_callbacks_list[uiDriver].acDriver, pndd->pcDriver ) )
|
||||
{
|
||||
DBG("Looking for %s, found %s... Skip it.", pndd->pcDriver, drivers_callbacks_list[uiDriver].acDriver);
|
||||
continue;
|
||||
} else {
|
||||
DBG("Looking for %s, found %s... Use it.", pndd->pcDriver, drivers_callbacks_list[uiDriver].acDriver);
|
||||
pnd = drivers_callbacks_list[uiDriver].connect(pndd);
|
||||
}
|
||||
}
|
||||
|
@ -733,7 +730,13 @@ bool nfc_initiator_transceive_dep_bytes(const nfc_device_t* pnd, const byte_t* p
|
|||
* @brief Transceive byte and APDU frames
|
||||
* @return Returns true if action was successfully performed; otherwise returns false.
|
||||
*
|
||||
* The reader will transmit the supplied bytes in pbtTx to the target (tag). It waits for the response and stores the received bytes in the pbtRx byte array. The parity bits are handled by the PN53X chip. The CRC can be generated automatically or handled manually. Using this function, frames can be communicated very fast via the NFC reader to the tag. Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
|
||||
* The reader will transmit the supplied bytes in pbtTx to the target (tag).
|
||||
* It waits for the response and stores the received bytes in the pbtRx byte array.
|
||||
* The parity bits are handled by the PN53X chip. The CRC can be generated automatically or handled manually.
|
||||
* Using this function, frames can be communicated very fast via the NFC reader to the tag.
|
||||
*
|
||||
* Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
|
||||
*
|
||||
* @warning The configuration option NDO_HANDLE_PARITY must be set to true (the default value).
|
||||
*/
|
||||
bool nfc_initiator_transceive_bytes(const nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
|
|
Loading…
Reference in a new issue