First Version

Dependencies:   EthernetInterface mbed-rtos mbed

Revision:
1:ce016c668e34
Parent:
0:9df41090ba33
Child:
2:bf4bbf7d6793
--- a/main.cpp	Tue Jul 21 21:29:49 2015 +0000
+++ b/main.cpp	Fri Jul 24 16:39:11 2015 +0000
@@ -24,6 +24,7 @@
 
 void InitializeEthernetLink();
 int SelectOption();
+int SelectOutlet();
 void ShowRMSValues();
 void ShowMeanValues();
 void ShowSamplesFromChannel();
@@ -31,6 +32,7 @@
 void SetOffset();
 void SetGain();
 void TestRFID();
+void TestManyTimesRFID();
 
 void thread1(void const *args)
 {
@@ -50,6 +52,7 @@
             case (4): SetOffset();              break;
             case (5): SetGain();                break;
             case (6): TestRFID();               break;
+            case (7): TestManyTimesRFID();      break;
             case (8): mbed_reset();             break;            
         }
     }
@@ -103,22 +106,78 @@
         Thread::yield();
     }
 }
+void TestManyTimesRFID(){
+    char rfid_number[9], reads[100][9];
+    int vezes[100];    
+    bool achou;    
+    int num_tom = 0, difs, i, j;
+    
+    num_tom = SelectOutlet();
+    difs = 0;
+    for(i=0; i < 10; i++){
+        vezes[i] = 0;
+        strcpy(reads[i], "VVVVVVVV"); // 'V' isn't valid digit (Hex)
+    }
+    for(i =0; i < 100; i++){
+        Capture::ReadRFID(num_tom,rfid_number);
+        //printf("\n{%s} - difs %d", rfid_number, difs);
+        achou = false;
+        for(j=0; j < difs; j++){
+            if (strcmp(rfid_number, reads[j]) == 0){
+                vezes[j] = vezes[j] + 1;
+                achou = true;
+            }
+        }
+        if (! achou){
+            strcpy(reads[j], rfid_number);
+            vezes[j] = 1;
+            difs++;
+        }
+    }    
+    
+    for(i=0; i < difs; i++)
+        printf("\nRFID {%s} read %d times.", reads[i], vezes[i]);    
+}
+
 
 void TestRFID(){
-    char rfid_number[9];
-    int num_tom = 0;
-    while (1){
-        printf("\nType the outlet number (1 to 3): ");
-        scanf("%d", &num_tom);
-        if ((num_tom > 3) || (num_tom < 1) )
-            printf("Invalid Outlet - Retype (1 to 3) !!! ");
-        else
+    char rfid_number[9], read[9];
+    bool first = true;
+    char c='%';
+    float perc;
+    int num_tom = 0, zero, ok, i;
+    
+    num_tom = SelectOutlet();
+    
+    zero = ok = 0;
+    for(i =0; i < 5; i++){
+        Capture::ReadRFID(num_tom,rfid_number);
+        if (strcmp(rfid_number, "00000000") == 0)
+            zero++;
+        else{
+            if (first){
+                ok++;
+                strcpy(read, rfid_number);
+                first = false;
+            }
+            else
+                if (strcmp(rfid_number, read) == 0)
+                    ok++;            
+        }
+        if (ok == 3)
             break;
     }
+    i = i == 5 ? 5 : i+1;
     
-    Capture::ReadRFID((int)(num_tom - '0'),rfid_number);
-    printf("\n\nRFID SERIAL NUMBER: ");
-    printf("{%8s}\n\n", rfid_number);
+    if(ok == 3)
+        perc = (float) ok/i;        
+    else{
+        perc = (float) zero/i ;        
+        
+        strcpy(read, "00000000");
+    }
+    perc = perc * 100 ;
+    printf("\n\RFID SERIAL NUMBER: {%8s} with %.2f%c of hit.\n", read, perc, c);
 }
 
 void SetGain(){
@@ -198,6 +257,19 @@
     printf("\n\nYou MUST in the sequence adjust the gain!!!\n\n");
 }
 
+int SelectOutlet(){
+    int num = 0;
+    while(1){    
+        printf("\nSelect an outlet to test (1 to 3): ");
+        scanf("%d", &num);
+        if ( (num > 3) || (num < 1) )
+            printf("\n\n\nInvalid Outlet! - Retype a valid outlet\n\n\n ");        
+        else
+            break;
+    }
+    return num;
+}
+
 int SelectChannel(){
     int num_channel = 0;
     while(1){