WappAutomation 2 : - WITH RESET - WITHOUT Switch Cable Tested on TEL50

Dependencies:   MFRC522

Revision:
9:cfa9a379dbd3
Parent:
7:64d536d218c3
Child:
10:4eebb90e8e06
--- a/main.cpp	Fri Feb 02 09:22:47 2018 +0000
+++ b/main.cpp	Mon Apr 16 15:07:19 2018 +0000
@@ -4,8 +4,8 @@
 
 
 //***************************** Change this for each new prober installation ********************************
-#define PROBER_NAME "tl26"
-#define IP          "10.129.97.118"
+#define PROBER_NAME "tl37"
+#define IP          "10.129.97.108"
 /*Please update the list below:
     TEL12 : 10.129.97.100
     TEL20 : 10.129.97.101
@@ -108,6 +108,7 @@
 //  Return false if no Tag present
 //  Return true if a Tag ID was read (Tag ID is saved int the bufTagID buffer)
 bool IsTagPresent(){
+    /*
     if (Antenna.PICC_IsNewCardPresent() && WappExchangeSwitch == 1){
         PC.printf("TAG detected ... ");
         
@@ -146,6 +147,57 @@
         return true;
     }
     else return false;
+    */
+    
+    //Look for new cards during 5s
+    int timeout = 0;
+    while ( ! Antenna.PICC_IsNewCardPresent() && WappExchangeSwitch == 1 && timeout < TIMEOUT_WAITTAG) {
+        wait_ms(100);
+        timeout++;
+    }
+    if (timeout >= TIMEOUT_WAITTAG) {
+        PC.printf("Timeout occured -> no Tag present\r\n");
+        return false;
+    }
+    if (WappExchangeSwitch == 0) return false; 
+    PC.printf("TAG detected ... ");   
+
+    //pc.printf("Yes, tag is present... Try to read Tag ID\r\n");
+    
+    //Select one of the cards
+    timeout = 0;
+    while ( ! Antenna.PICC_ReadCardSerial() && WappExchangeSwitch == 1 && timeout < TIMEOUT_WAITTAG) {
+        wait_ms(100);
+        timeout++;
+    }
+    if (timeout >= TIMEOUT_WAITTAG) {
+        PC.printf("Timeout occured during ReadCardSerial\r\n");
+        return false;
+    }
+    if (WappExchangeSwitch == 0) return false;    
+    
+    //Light during 1s Tag LED to indicate that a tag was read
+    TagReadLED = LED_ON;
+    wait_ms(500);
+    TagReadLED = LED_OFF;   
+    
+    //Save Tag ID into buffer
+    PC.printf("ID = ");
+    int pos = 0;
+    char hexbuf[2];
+    for (int i = 0; i < 256; i++) bufTagID[i] = '\0';
+    for (uint8_t i = 0; i < Antenna.uid.size; i++) {
+        sprintf(hexbuf, "%02x", Antenna.uid.uidByte[i]);
+        PC.putc(hexbuf[0]);
+        PC.putc(hexbuf[1]);
+        bufTagID[pos] = hexbuf[0];
+        pos++;
+        bufTagID[pos] = hexbuf[1];
+        pos++;
+    }
+    PC.printf("\r\n");
+        
+    return true;
 }
 
 //APCDGetWappAlarm: function to check from APCD mailbox if a wapp alarm was sent by automation