Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: uart.cpp
- Revision:
- 8:1ca49cb18290
- Parent:
- 7:bfbbf605be43
- Child:
- 14:76a56d517103
--- a/uart.cpp Sat Nov 24 11:49:51 2018 +0000
+++ b/uart.cpp Mon Nov 26 13:58:16 2018 +0000
@@ -2,25 +2,22 @@
#include "uart.h"
#include "command.h"
-#include <vector>
-#include <string>
-#include <sstream>
-using namespace std;
-
-//#define WIREED_SERIAL
-
-//シリアルポートインスタンス
+//ログ吐出し様シリアルポートインスタンス
+//----------------------------------
+#define WIREED_SERIAL
#ifdef WIREED_SERIAL
Serial sp(USBTX, USBRX); //有線のポート
- #define BAUD_RATE 9600
+ #define BAUD_RATE 115200
#else
Serial sp(p9, p10);//TWILITEをモジュールを接続したポート
#define BAUD_RATE 115200
#endif
Serial sp46Axis(p28,p27);
-#define BAUD_RATE4_6AXIS 115200
+//Asciiコード
+#define CR 0x0D
+#define LF 0x0A
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// UART 受信割り込みハンドラ
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -33,18 +30,6 @@
commandPush(buf);
}
-//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-// UART 受信割り込みハンドラ for Arduino UNO(Six Axis Sensor)
-//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-void uartRxIntHndler46Axis(){
- //1Byte抜き出す
- UCHAR buf = sp46Axis.getc();
- //エコーバック
- sp46Axis.putc(buf);
- //スルーするためのバッファに突っ込む
- PushBuf(buf);
-}
-
//=============================================================
//初期設定
//=============================================================
@@ -52,11 +37,8 @@
//ボーレート設定
sp.baud(BAUD_RATE);
- //受信割り込みハンドラ登録
- sp.attach
- (uartRxIntHndler //登録するハンドラ
- ,Serial::RxIrq //割り込み要因
- );
+ //受信割り込みハンドラ登録(登録するハンドラ,割り込み要因)
+ sp.attach(uartRxIntHndler,Serial::RxIrq);
sp.printf("***********\r\n");
sp.printf("UART open!!\r\n");
@@ -65,70 +47,4 @@
sp.printf("int = %d\r\n" ,sizeof(unsigned int) );
sp.printf("long = %d\r\n" ,sizeof(unsigned long) );
sp.printf("***********\r\n");
-
- ////////////////////////////
- // for 6Axis Sensor
- //ボーレート設定
- sp46Axis.baud(BAUD_RATE4_6AXIS);
-
- //受信割り込みハンドラ登録
- sp46Axis.attach
- (uartRxIntHndler46Axis //登録するハンドラ
- ,Serial::RxIrq //割り込み要因
- );
-
- sp46Axis.printf("***********\r\n");
- sp46Axis.printf("UART open!!\r\n");
- sp46Axis.printf("-----------\r\n");
- sp46Axis.printf("short = %d\r\n" ,sizeof(unsigned short) );
- sp46Axis.printf("int = %d\r\n" ,sizeof(unsigned int) );
- sp46Axis.printf("long = %d\r\n" ,sizeof(unsigned long) );
- sp46Axis.printf("***********\r\n");
-
- // bufferのクリア
- InitBuf();
- ////////////////////////////
}
-
-static std::vector<std::string> split(const std::string &str, char sep)
-{
- std::vector<std::string> v;
- std::stringstream ss(str);
- std::string buffer;
- while( std::getline(ss, buffer, sep) ) {
- v.push_back(buffer);
- }
- return v;
-}
-
-void InitBuf()
-{
- idxBufByG = 0;
- memset(bufDataByGyro, 0x00, sizeof(bufDataByGyro));
- accZ = gyroZ = yaw = 0.0f;
-}
-
-void PushBuf(UCHAR rxChar)
-{
- bufDataByGyro[idxBufByG] = rxChar;
- ++idxBufByG;
- if(0x0A != rxChar){
- return;
- }
- else
- {
- //std::size_t sz;
- std::string str((char*)bufDataByGyro);
- std::vector<std::string> list = split(str,0x09);
- if(list.size() > 0 && list.size() < 4){
- yaw = atof(list.at(0).c_str());
- accZ = atof(list.at(1).c_str());
- gyroZ = atof(list.at(2).c_str());
- sp.printf("yaw = %f " ,yaw );
- sp.printf("acc = %f" ,accZ );
- sp.printf("gyro = %f\r\n" ,gyroZ );
- }
- idxBufByG = 0;
- memset(bufDataByGyro, 0x00, sizeof(bufDataByGyro));
- }
-}