PN532 NFC library for Seeed Studio's NFC Shield

Fork of PN532 by Yihui Xiong

Revision:
3:4189a10038e6
Parent:
1:b8cab5222fd0
diff -r f618fb2169c4 -r 4189a10038e6 PN532_SPI.cpp
--- a/PN532_SPI.cpp	Thu Oct 17 06:51:32 2013 +0000
+++ b/PN532_SPI.cpp	Thu Nov 21 04:30:49 2013 +0000
@@ -1,6 +1,6 @@
 
 #include "PN532_SPI.h"
-#include "debug.h"
+#include "PN532_debug.h"
 
 #define STATUS_READ     2
 #define DATA_WRITE      1
@@ -38,10 +38,10 @@
     _ss = 1;
 }
 
-int8_t PN532_SPI::writeCommand(const uint8_t buf[], uint8_t len)
+int8_t PN532_SPI::writeCommand(const uint8_t *header, uint8_t hlen, const uint8_t *body, uint8_t blen)
 {
-    command = buf[0];
-    writeFrame(buf, len);
+    command = header[0];
+    writeFrame(header, hlen, body, blen);
 
     uint8_t timeout = PN532_ACK_WAIT_TIME;
     while (!isReady()) {
@@ -148,7 +148,7 @@
     return status;
 }
 
-void PN532_SPI::writeFrame(const uint8_t buf[], uint8_t len)
+void PN532_SPI::writeFrame(const uint8_t *header, uint8_t hlen, const uint8_t *body, uint8_t blen)
 {
     _ss = 0;
     wait_ms(2);               // wake up PN532
@@ -158,7 +158,7 @@
     write(PN532_STARTCODE1);
     write(PN532_STARTCODE2);
 
-    uint8_t length = len + 1;   // length of data field: TFI + DATA
+    uint8_t length = hlen + blen + 1;   // length of data field: TFI + DATA
     write(length);
     write(~length + 1);         // checksum of length
 
@@ -167,11 +167,17 @@
 
     DMSG("write: ");
 
-    for (uint8_t i = 0; i < len; i++) {
-        write(buf[i]);
-        sum += buf[i];
+    for (uint8_t i = 0; i < hlen; i++) {
+        write(header[i]);
+        sum += header[i];
 
-        DMSG_HEX(buf[i]);
+        DMSG_HEX(header[i]);
+    }
+    for (uint8_t i = 0; i < blen; i++) {
+        write(body[i]);
+        sum += body[i];
+        
+        DMSG_HEX(header[i]);
     }
 
     uint8_t checksum = ~sum + 1;        // checksum of TFI + DATA