Attempt to support ARYGON APDB (APDB1UA33N and APDB2UA33).
Code clean up.
This commit is contained in:
parent
710745262d
commit
b16bc53025
4 changed files with 99 additions and 62 deletions
|
@ -34,7 +34,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||
|
||||
#define BUFFER_LENGTH 256
|
||||
#define USB_TIMEOUT 30000
|
||||
static byte_t abtTxBuf[BUFFER_LENGTH] = { 0x32, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
||||
|
||||
/** @def DEV_ARYGON_PROTOCOL_ARYGON_ASCII
|
||||
* @brief High level language in ASCII format. (Common µC commands and Mifare® commands)
|
||||
*/
|
||||
#define DEV_ARYGON_PROTOCOL_ARYGON_ASCII '0'
|
||||
/** @def DEV_ARYGON_MODE_HL_ASCII
|
||||
* @brief High level language in Binary format With AddressingByte for party line. (Common µC commands and Mifare® commands)
|
||||
*/
|
||||
#define DEV_ARYGON_PROTOCOL_ARYGON_BINARY_WAB '1'
|
||||
/** @def DEV_ARYGON_PROTOCOL_TAMA
|
||||
* @brief Philips protocol (TAMA language) in binary format.
|
||||
*/
|
||||
#define DEV_ARYGON_PROTOCOL_TAMA '2'
|
||||
/** @def DEV_ARYGON_PROTOCOL_TAMA_WAB
|
||||
* @brief Philips protocol (TAMA language) in binary With AddressingByte for party line.
|
||||
*/
|
||||
#define DEV_ARYGON_PROTOCOL_TAMA_WAB '3'
|
||||
|
||||
static byte_t abtTxBuf[BUFFER_LENGTH] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
||||
|
||||
dev_info* dev_arygon_connect(const uint32_t uiIndex)
|
||||
{
|
||||
|
@ -43,9 +61,7 @@ dev_info* dev_arygon_connect(const uint32_t uiIndex)
|
|||
char acConnect[BUFFER_LENGTH];
|
||||
dev_info* pdi = INVALID_DEVICE_INFO;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Trying to find ARYGON device on serial port: %s#\n",SERIAL_STRING);
|
||||
#endif
|
||||
DBG("Trying to find ARYGON device on serial port: %s#",SERIAL_STRING);
|
||||
|
||||
// I have no idea how MAC OS X deals with multiple devices, so a quick workaround
|
||||
for (uiDevNr=0; uiDevNr<MAX_DEVICES; uiDevNr++)
|
||||
|
@ -59,16 +75,14 @@ dev_info* dev_arygon_connect(const uint32_t uiIndex)
|
|||
#endif
|
||||
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) break;
|
||||
#ifdef DEBUG
|
||||
if (sp == INVALID_SERIAL_PORT) printf("invalid serial port: %s\n",acConnect);
|
||||
if (sp == CLAIMED_SERIAL_PORT) printf("serial port already claimed: %s\n",acConnect);
|
||||
if (sp == INVALID_SERIAL_PORT) DBG("Invalid serial port: %s",acConnect);
|
||||
if (sp == CLAIMED_SERIAL_PORT) DBG("Serial port already claimed: %s",acConnect);
|
||||
#endif
|
||||
}
|
||||
// Test if we have found a device
|
||||
if (uiDevNr == MAX_DEVICES) return INVALID_DEVICE_INFO;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Succesfully connected to: %s\n",acConnect);
|
||||
#endif
|
||||
DBG("Successfully connected to: %s",acConnect);
|
||||
|
||||
// We have a connection
|
||||
pdi = malloc(sizeof(dev_info));
|
||||
|
@ -112,20 +126,25 @@ bool dev_arygon_transceive(const dev_spec ds, const byte_t* pbtTx, const uint32_
|
|||
abtTxBuf[uiTxLen+7] = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Tx: ");
|
||||
printf(" TX: ");
|
||||
print_hex(abtTxBuf,uiTxLen+8);
|
||||
#endif
|
||||
if (!rs232_send((serial_port)ds,abtTxBuf,uiTxLen+8)) return false;
|
||||
|
||||
if (!rs232_receive((serial_port)ds,abtRxBuf,&uiRxBufLen)) return false;
|
||||
if (!rs232_send((serial_port)ds,abtTxBuf,uiTxLen+8)) {
|
||||
ERR("Unable to transmit data. (TX)");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!rs232_receive((serial_port)ds,abtRxBuf,&uiRxBufLen)) {
|
||||
ERR("Unable to receive data. (RX)");
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Rx: ");
|
||||
printf(" RX: ");
|
||||
print_hex(abtRxBuf,uiRxBufLen);
|
||||
#endif
|
||||
|
||||
// When the answer should be ignored, just return a succesful result
|
||||
// When the answer should be ignored, just return a successful result
|
||||
if(pbtRx == NULL || puiRxLen == NULL) return true;
|
||||
|
||||
// Only succeed when the result is at least 00 00 ff 00 ff 00 00 00 FF xx Fx Dx xx .. .. .. xx 00 (x = variable)
|
||||
|
|
|
@ -260,14 +260,14 @@ dev_info* nfc_connect()
|
|||
// Search through the device list for an available device
|
||||
for (uiDev=0; uiDev<sizeof(dev_callbacks_list)/sizeof(dev_callbacks_list[0]); uiDev++)
|
||||
{
|
||||
// Try to claim the device
|
||||
// Try to claim the device
|
||||
pdi = dev_callbacks_list[uiDev].connect(0);
|
||||
|
||||
// Test if the connection was successful
|
||||
if (pdi != INVALID_DEVICE_INFO)
|
||||
{
|
||||
// Great we have claimed a device
|
||||
pdi->pdc = &(dev_callbacks_list[uiDev]);
|
||||
pdi->pdc = &(dev_callbacks_list[uiDev]);
|
||||
pdi->pdc->transceive(pdi->ds,pncmd_get_register,4,NULL,NULL);
|
||||
|
||||
// Try to retrieve PN53x chip revision
|
||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, const char* argv[])
|
|||
|
||||
if (pdi == INVALID_DEVICE_INFO)
|
||||
{
|
||||
printf("Error connecting NFC reader\n");
|
||||
ERR("Unable to connect to NFC device.");
|
||||
return 1;
|
||||
}
|
||||
nfc_initiator_init(pdi);
|
||||
|
|
24
src/rs232.c
24
src/rs232.c
|
@ -73,12 +73,24 @@ serial_port rs232_open(const char* pcPortName)
|
|||
|
||||
// Copy the old terminal info struct
|
||||
sp->tiNew = sp->tiOld;
|
||||
|
||||
/** @todo provide this settings dynamically using model provide in configuration file */
|
||||
sp->tiNew.c_cflag = CS8 | CLOCAL | CREAD;
|
||||
sp->tiNew.c_iflag = CCLAIMED | IGNPAR;
|
||||
sp->tiNew.c_oflag = 0;
|
||||
sp->tiNew.c_lflag = 0;
|
||||
sp->tiNew.c_cc[VMIN] = 0; // block untill n bytes are received
|
||||
sp->tiNew.c_cc[VTIME] = 0; // block untill a timer expires (n * 100 mSec.)
|
||||
|
||||
/**
|
||||
* @note ARYGON-ADRA (PN531): ???,n,8,1
|
||||
* @note ARYGON-ADRB (PN532): ???,n,8,1
|
||||
* @note ARYGON-APDA (PN531): 9600,n,8,1
|
||||
* @note ARYGON-APDB (PN532): 115200,n,8,1
|
||||
*/
|
||||
cfsetispeed(&(sp->tiNew), B115200);
|
||||
cfsetospeed(&(sp->tiNew), B115200);
|
||||
|
||||
sp->tiNew.c_cc[VMIN] = 0; // block until n bytes are received
|
||||
sp->tiNew.c_cc[VTIME] = 0; // block until a timer expires (n * 100 mSec.)
|
||||
if(tcsetattr(sp->fd,TCSANOW,&sp->tiNew) == -1)
|
||||
{
|
||||
rs232_close(sp);
|
||||
|
@ -115,13 +127,19 @@ bool rs232_receive(const serial_port sp, byte_t* pbtRx, uint32_t* puiRxLen)
|
|||
iResult = select(((serial_port_unix*)sp)->fd+1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
// Read error
|
||||
if (iResult < 0) return false;
|
||||
if (iResult < 0) {
|
||||
DBG("RX error.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read time-out
|
||||
if (iResult == 0)
|
||||
{
|
||||
// Test if we at least have received something
|
||||
if (uiCount == 0) return false;
|
||||
|
||||
DBG("RX time-out.");
|
||||
|
||||
// Store the received byte count and return succesful
|
||||
*puiRxLen = uiCount;
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue