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.
BusSerial.cpp
- Committer:
- ttrist
- Date:
- 2020-03-17
- Revision:
- 2:6895c7ec9db1
- Parent:
- 1:62db8d68f92e
- Child:
- 4:3b347fa779b7
File content as of revision 2:6895c7ec9db1:
#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
}
}