Alexandre Lemay / Mbed 2 deprecated APP4_FunTimes

Dependencies:   mbed mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
ThierryLeonard
Date:
Wed Oct 25 05:43:13 2017 +0000
Parent:
8:7c56fb1ed8c0
Commit message:
final???;

Changed in this revision

Receiver.cpp Show annotated file Show diff for this revision Revisions of this file
Receiver.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
sender.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7c56fb1ed8c0 -r 8f479f7c1b54 Receiver.cpp
--- a/Receiver.cpp	Wed Oct 25 04:17:42 2017 +0000
+++ b/Receiver.cpp	Wed Oct 25 05:43:13 2017 +0000
@@ -16,8 +16,10 @@
 {
     if(dataReady.wait(2)==0)
     {
+        timedOut = true;
         return BitData::timeout;
     }
+    
     char val = data[currentData];
     currentData++;
     if(currentData==size)
@@ -46,12 +48,12 @@
         if(mode == BitData::zero)
         {
             lastTime = curTime;
-            pushData(BitData::zero);
-            return;
+            pushData(BitData::zero);   
         }
+        return;
     }
     // data
-    if(dif > us_prepare)
+    else if(dif > us_prepare)
     {
         lastTime = curTime;
         pushData(mode);
@@ -96,10 +98,11 @@
             val = val|(1 << 7-i);
             break;
         case BitData::timeout:
+            val = 0;
             return false;       
         }
     }
-    pc.printf(" byte:%i\n",val);
+    //pc.printf(" byte:%i\n",val);
     return true;
 }
 
diff -r 7c56fb1ed8c0 -r 8f479f7c1b54 Receiver.h
--- a/Receiver.h	Wed Oct 25 04:17:42 2017 +0000
+++ b/Receiver.h	Wed Oct 25 05:43:13 2017 +0000
@@ -56,8 +56,6 @@
     
     bool getByte(unsigned char &val);
     
-private:    
-    
     bool getMessage( vector<unsigned char> &message, int &crc);
     
 private:  
diff -r 7c56fb1ed8c0 -r 8f479f7c1b54 main.cpp
--- a/main.cpp	Wed Oct 25 04:17:42 2017 +0000
+++ b/main.cpp	Wed Oct 25 05:43:13 2017 +0000
@@ -16,8 +16,8 @@
 
 #ifndef TESTPERIOD
 const int us_period = 20;
-const int us_timeout = us_period * 5/4
-const int us_prepare = us_period *3/4
+const int us_timeout = us_period * 5/4;
+const int us_prepare = us_period *3/4;
 #else
 int us_period = 100;
 #endif
@@ -30,7 +30,6 @@
 
 Sender manchesterSender;
 
-const int testByte = 106;
 void sendMessage()
 {
     unsigned char c = 0;
@@ -53,7 +52,7 @@
 
 
 #ifdef TESTPERIOD
-const int testCount = 500;
+const int testCount = 2000;
 void sendTestData()
 {
     vector<unsigned char> trame;
@@ -62,26 +61,35 @@
     {
         trame.push_back(106);   
     }
-
-    while(true)
-    {    
-        manchesterSender.sendMessage(trame);
-    }
-    
+    manchesterSender.sendMessage(trame);    
 }
 
+int sendMain()
+{
+    pc.printf("Start test");
+    int period;
+    while(true)
+    {
+        pc.scanf("%i",&period);
+        pc.printf("\n\nPeriod = %i\n",period);
+        us_period = period;
+        sendTestData();   
+    }
+}
 int testMain()
 {
     ManchesterReceiver r;
-    
-    for (int period = 100; period > 10; period -= 5)
+    pc.printf("Start test");
+    int period;
+    while(true)
     {
+        pc.scanf("%i",&period);
+        pc.printf("\n\nPeriod = %i\n",period);
         us_period = period;
-        sendTestData();
         unsigned char val;
         bool fail = false;
         while(!r.getByte(val))
-        {    }
+        {   }
         if(val!=106)
         {
             fail = true;
@@ -98,7 +106,7 @@
                 fail = true;
             }
         }
-        pc.printf("Period = %i\n",period);
+        pc.printf("\n\nEnd Period = %i\n",period);
     }
     
 }
@@ -120,10 +128,29 @@
         Thread::wait(1000);
     }
 }
+int sendMessageTest()
+{   
+    vector<unsigned char> trame;
+    
+    for(int i =0; i < 5;i++)
+    {
+        trame.push_back(106);   
+    }
+    
+    
+    trame = createFrame(trame);
+    while(true)
+        manchesterSender.sendMessage(trame);
+        
+    return 0;
+}
 
 
 int main()
 {
+#ifndef TESTPERIOD
     return consoleCommMain();
-    //return testMain();
+#else
+    return testMain();
+#endif
 }
diff -r 7c56fb1ed8c0 -r 8f479f7c1b54 sender.cpp
--- a/sender.cpp	Wed Oct 25 04:17:42 2017 +0000
+++ b/sender.cpp	Wed Oct 25 05:43:13 2017 +0000
@@ -58,7 +58,7 @@
 }
 void Sender::sendMessage(const vector<unsigned char> & data)
 {
-    while(_sending = false)
+    while(_sending == true)
     {
         Thread::yield();
     }