ROBOSTEP_5期 / Mbed 2 deprecated serial_to_python

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
yuto17320508
Date:
Sun Sep 01 09:46:15 2019 +0000
Commit message:
first commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Sep 01 09:46:15 2019 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+#include "string"
+#include "vector"
+
+DigitalOut led(LED1);
+
+Serial pc(USBTX, USBRX); //rtosの機能を使うときはSerialではなくRawSerialを使えとの情報をみてこうしています。
+
+char data[100];
+int data_index = 0;
+
+std::vector<std::string> separate_string(std::string input) 
+{
+    std::vector<std::string> return_data; 
+    std::string separator = std::string(",");
+    int separator_length = separator.length();
+    std::string::size_type offset = std::string::size_type(0);
+    while(1)
+    {
+        int pos = input.find(separator, offset);             
+        if (pos == std::string::npos) 
+        {
+            return_data.push_back(input.substr(offset));
+            break;
+        }
+        return_data.push_back(input.substr(offset,pos-offset));
+        offset = pos + separator_length;
+    }
+    return return_data;
+}
+
+
+ 
+int main(void){
+    while(1){
+      if (!pc.readable()) continue;
+
+        char c = pc.getc();
+        data[data_index++] = c;
+        if (c == '\n')
+        {
+            data[data_index] = '\0';
+            std::string str;
+            str = data;
+            std::vector<std::string> data_list = separate_string(str);
+            for(int i=0;data_list.size();++i)
+            {
+                pc.puts(data_list[i].c_str());
+                pc.puts("+");
+            }
+            data_index = 0;
+        }
+        
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Sep 01 09:46:15 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file