kubtss / Mbed 2 deprecated BIRD2017

Dependencies:   mbed-rtos mbed

Revision:
5:9a1ec02229dd
Parent:
2:e0f1e8662b8c
Child:
6:0d9fa7152934
--- a/main.cpp	Tue Sep 29 18:23:29 2015 +0000
+++ b/main.cpp	Fri Oct 09 14:29:32 2015 +0000
@@ -9,6 +9,12 @@
 #include "Altitude.h"
 #include "Display.h"
 #include "XBee.h"
+#include <string>
+
+#define BUFMAX 20
+
+RawSerial pc(USBTX, USBRX);
+Queue<char, BUFMAX> queue;
 
 
 Display display(p9, p10);
@@ -20,12 +26,62 @@
 Cadence cadence(p29, p30, NC);
 
 
-void initializeTask(void const *pvParametersd){
-    while(1){
-        Thread::wait(50);
+void pc_rx(){
+    while(pc.readable()==1){
+        char buf = pc.getc();
+        queue.put((char*)buf);
     }
 }
 
+
+void initializeTask(void const *pvParametersd){
+    std::string strbuf;
+    while(1){
+        osEvent evt = queue.get();
+        if(evt.status == osEventMessage){
+            char temp = evt.value.v;
+            strbuf.push_back(temp);
+            if(temp == '\n'){
+                Global::led1 = 1;
+                
+                std::string::size_type spaceIndex = strbuf.find(" ");
+                if (spaceIndex != std::string::npos) {
+                    char *gomi;
+                    std::string command = strbuf.substr(0, spaceIndex);
+                    double num = strtod(strbuf.substr(spaceIndex+1, strbuf.size()-1).c_str(), &gomi);
+                    
+                    pc.printf("coms=%s, num=%f\n", command.c_str(), num);
+
+                    
+                    if(command == "eleneu"){
+                        Global::setneutralpitch(num);
+                    }else if(command == "elemax"){
+                        Global::setmaxpitch(num);
+                    }else if(command == "elemin"){
+                        Global::setminpitch(num);
+                    }else if(command == "rudneu"){
+                        Global::setneutralyaw(num);
+                    }else if(command == "rudmax"){
+                        Global::setmaxyaw(num);
+                    }else if(command == "rudmin"){
+                        Global::setminyaw(num);
+                    }
+                    
+                    strbuf.clear();
+                    //ここで,ニュートラル情報をLocalFileに保存                    
+                }
+            }
+            Thread::wait(10);
+            if(strbuf.size() >= BUFMAX){
+                pc.printf("\nInput Error ... ");
+                strbuf.clear();
+                pc.printf("Buffer clear\n");
+            }
+        }
+    }
+}
+
+
 void controlTask(void const *pvParameters){
     while(1){
         trim.update();
@@ -66,7 +122,11 @@
 
 int main(void){
     printf("start\n");
+    
+    pc.attach(pc_rx,Serial::RxIrq);
+
     Global::timer.start();
+    Thread InitializeTask(initializeTask);
     Thread ControlTask(controlTask);
     Thread AirspeedTask(airspeedTask);
     Thread CadenceTask(cadenceTask);