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: BusSerial.cpp
- Revision:
- 0:418bb20836bd
- Child:
- 1:62db8d68f92e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/BusSerial.cpp Fri Mar 06 04:39:27 2020 +0000
@@ -0,0 +1,40 @@
+#include "BusSerial.h"
+
+BusSerial::BusSerial(PinName tx, PinName rx,Timer *timer):BufferedSerial(tx,rx)
+{
+ _timer = timer;
+ _timer -> start();
+}
+
+void BusSerial::GetBusSerial(uint8_t *Argument_Array, int myHead_ID, int RecieveData_sizeof, int BusSerialTimeout)
+{
+ long BusSerialTimeout_start_t = _timer->read_ms(); //タイマーセット
+ for (int i = 0; i < RecieveData_sizeof; i++) *(Argument_Array + i) = 0; //データ初期化
+
+ //*** データ受信 ちゃんとなるまでループ(timeoutあり)***
+ while (*Argument_Array != myHead_ID) {
+ //*** 1byte読み込み ***
+ if (readable() > 0) *Argument_Array = getc();
+
+ if (*Argument_Array == myHead_ID ) {
+ int old_i = 0;
+ //*** データ格納エリア ***
+ for (int i = 1; i < RecieveData_sizeof; i++) {
+ //格納中のtimeout処理用時間設定
+ if (old_i != i) {
+ old_i = i;
+ BusSerialTimeout_start_t = _timer->read_ms(); //データ格納timeout用
+ }
+
+ //***データ格納部***
+ if (readable() > 0) {
+ *(Argument_Array + i) = getc();
+ } else {
+ if (_timer->read_ms() - BusSerialTimeout_start_t > BusSerialTimeout) break;
+ i--;
+ }
+ }
+ }
+ if (_timer->read_ms() - BusSerialTimeout_start_t > BusSerialTimeout) break;//timeout
+ }
+}
\ No newline at end of file