MU2library

Files at this revision

API Documentation at this revision

Comitter:
Nerosho
Date:
Tue Jul 16 12:05:44 2019 +0000
Child:
1:dcb1eee964d5
Commit message:
ver1

Changed in this revision

MU2.cpp Show annotated file Show diff for this revision Revisions of this file
MU2.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MU2.cpp	Tue Jul 16 12:05:44 2019 +0000
@@ -0,0 +1,67 @@
+#include "MU2.h"
+#include "mbed.h"
+#include "stdint.h"
+#include <string>
+#include <sstream>
+
+MU2::MU2(PinName tx,PinName rx) //MU2クラスのMU2という関数(コンストラクタ)の定義
+{
+    _tx=tx;
+    _rx=rx;
+}
+
+/*MU2::MU2(PinName tx,PinName rx) : Serial(tx,rx){
+}*/
+
+
+void MU2::send(char Message[])
+{
+    Serial MuPort(_tx,_rx);
+    Serial pc(USBTX,USBRX);
+
+    MuPort.baud(19200);
+    pc.baud(9600);
+
+    int index=0;
+    std::string send_data;
+
+    uint8_t last_data[]= {0x0d,0x0a}; //復帰、改行のアスキーコードを16進数で表す
+
+
+    int j=0;
+    while(Message[j]!='\0')  {
+        j++;
+    }
+    index=j;//
+
+
+    send_data="@DT";
+
+    if(index<16) {
+        std::stringstream ss;  //stiringstreamクラスのstd::hexマニュピレータを用いて変換。<sstream>のincludeが必要。
+        ss << std::hex << index ; //indexを16進数に変換
+        std::string str_ss = ss.str();
+        send_data += '0'+str_ss;
+    } else {
+        std::stringstream ss;  //stiringstreamクラスのstd::hexマニュピレータを用いて変換。<sstream>のincludeが必要。
+        ss << std::hex << index ; //indexを16進数に変換
+        std::string str_ss = ss.str();
+        send_data += str_ss;
+    }
+
+
+    for(int n=0; n<index+1; n++) {
+        send_data += Message[n];
+    }
+
+
+    pc.printf("%s\n",send_data.c_str());
+
+
+    MuPort.printf("%s", send_data.c_str());//.c_str()でstring型のstrを変換
+
+
+    for(int i=0; i<2; i++) {
+        MuPort.putc(last_data[i]);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MU2.h	Tue Jul 16 12:05:44 2019 +0000
@@ -0,0 +1,21 @@
+#ifndef MU2_CLASS
+#define MU2_CLASS
+
+#include "mbed.h"
+
+class MU2
+{
+
+private:
+
+    PinName _tx; //tx pin name which connected to mbed
+    PinName _rx; //rx pin name which connected to mbed
+
+public:
+    MU2(PinName tx,PinName rx); //コンストラクタの宣言define pins for communication from CanSat
+    void send(char Message[]); //a method for sending data from CanSat to PC
+    //void send(int Send_Message[]); //overload the send(char)method
+
+};
+
+#endif
\ No newline at end of file