GIU\ZF

Dependencies:   MCP23017 WattBob_TextLCD mbed-rtos mbed

Fork of rtos_basic by mbed official

Revision:
12:90b5d8eae5ec
Child:
13:ab52f46c98ab
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tasks/sendMail.cpp	Tue Mar 27 14:35:09 2018 +0000
@@ -0,0 +1,74 @@
+#include "core.h"
+
+namespace mailData{
+    Mail<mail_t, 100> mailBox;
+}
+
+
+
+namespace loadMail{
+    
+    Thread thread;
+    static const float freq = 0.2; //hz
+    
+    //I/O
+    
+    void runTask(){
+        //Send speed, accelerometer and brake values to a 100 element
+        //MAIL queue
+        //• A MAIL queue is a structure available in the MBED RTOS
+        while(1){
+            using namespace mailData;
+            mail_t *mail = mailBox.alloc();
+            
+            runTimeParams::liveAccess.lock();
+            
+            mail->speed = runTimeParams::avgSpeed;
+            mail->accel = runTimeParams::accelForce;
+            mail->brake = runTimeParams::brakeForce;
+            
+            runTimeParams::liveAccess.unlock();
+            
+            mailBox.put(mail);
+            
+            wait(1.0f/freq);
+        }
+        
+    }
+}
+
+namespace sendMail{
+    
+    Thread thread;
+    const float freq = 0.05;
+    const float executionTime = 0;
+    Serial pc(USBTX, USBRX); // tx, rx
+    bool init = true;
+    
+    void runTask(){
+        //Dump contents of feature_7 MAIL queue to the serial
+        //connection to the PC. (Data will be passed through the MBED
+        //USB connection). See later technical note
+        
+        /* Mail */
+        if (init){
+             pc.printf("speed,acceleration,brake\n\r");
+             init = false;
+             } //?
+        using namespace mailData;
+        osEvent evt = mailBox.get();
+        if (evt.status == osEventMail){
+            mail_t * mail = (mail_t*)evt.value.p;
+            pc.printf("%.2f,%.2f,%.2f\n\r",mail->speed,mail->accel,mail->brake);
+            
+            mailBox.free(mail);
+            wait((1.0/freq)-executionTime);
+        }
+            
+    }
+}
+
+
+
+        
+    
\ No newline at end of file