Second part of error handling.

- Define two sets of DE<FOOBAR> macros: the first one for 'generic' errors
  which could be encountered regardless of the NFC device the library is acting
  with (0xX000), and ont set for device-dependant errors (0x0X00).
- Make some more functions accept a nfc_device_t* as first argument to have
  access to the iLastError;
- Reset errors when entering public API functions;
- Save errors when applicable;
- Distinguish system-level errors (e.g. I/O error) and operational errors (the
  PCD returns an unexpected value);
- Minor tweaks.

Update issue 65
Status: Feedback

New review:
Owner: rconty@il4p.fr
Cc: rtartiere@il4p.fr
Summary: Review the error-handling code.
Branch: /branches/libnfc-error-handling

For this development, a strong emphasis has been set on making changes that
will not go through our way on the way to libnfc-1.6+.  For this reason, some
constructs are not natural (e.g. error codes defined in two different places),
please keep this in mind when reviewing.
This commit is contained in:
Romain Tartiere
2010-08-15 14:08:29 +00:00
parent d7e0b926ac
commit 08eb21aa9d
9 changed files with 166 additions and 31 deletions

View File

@@ -39,6 +39,7 @@ Thanks to d18c7db and Okko for example code
#include "../drivers.h"
#include "../chips/pn53x.h"
#include <nfc/nfc.h>
#include <nfc/nfc-messages.h>
#define BUFFER_LENGTH 256
@@ -271,6 +272,7 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
if( ret < 0 )
{
DBG("usb_bulk_write failed with error %d", ret);
pnd->iLastError = DEIO;
return false;
}
@@ -278,6 +280,7 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
if( ret < 0 )
{
DBG( "usb_bulk_read failed with error %d", ret);
pnd->iLastError = DEIO;
return false;
}
@@ -292,6 +295,7 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
if( ret < 0 )
{
DBG("usb_bulk_read failed with error %d", ret);
pnd->iLastError = DEIO;
return false;
}
@@ -311,6 +315,7 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
if(ret < 9)
{
DBG("%s","No data");
pnd->iLastError = DEINVAL;
return false;
}
@@ -327,5 +332,8 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
memcpy( pbtRx, abtRx + 7, *pszRxLen);
if (abtRx[5] != pbtTx[0] + 1) {
pnd->iLastError = DEISERRFRAME;
}
return true;
}