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: SerialCtrl.cpp
- Revision:
- 4:32f7deade942
- Parent:
- 1:0184f38e2e83
- Child:
- 5:731e4a7f5947
--- a/SerialCtrl.cpp Mon Sep 02 02:29:22 2019 +0000
+++ b/SerialCtrl.cpp Tue Feb 18 08:47:32 2020 +0000
@@ -5,6 +5,7 @@
_Serial = pts;
_Timer = ptt;
TIMEOUT_MS = 8;
+ RETRY_MAX = RETRY_DEF;
}
void SerialCtrl::param(unsigned char header, unsigned char footer) {
@@ -13,26 +14,39 @@
}
bool SerialCtrl::get() {
- int fail = 0;
- unsigned char sum = 0;
+ int retry = 0;
- while(1) {
- if(input() == STX) {
- break;
+ do {
+ //judge start of text
+ if( !(input() == STX) ) {
+ ++retry;
} else {
- ++fail;
- if(fail > FAIL_MAX) return false;
+ unsigned char sum = 0;
+
+ //get data
+ for(int i=0; i<DATA_N; ++i) data[i] = input();
+ for(int i=0; i<DATA_N-1; ++i) sum += data[i];
+
+ //judge checksum and end of text
+ if( (sum == data[SUM]) && (input() == ETX) ) {
+ return true;
+ } else {
+ ++retry;
+ }
}
+ } while(retry < RETRY_MAX);
+ return false;
+}
+
+void SerialCtrl::setFailMax(int n) {
+ if(n >= 0) {
+ RETRY_MAX = n;
+ } else {
+ return;
}
-
- for(int i=0; i<DATA_N; ++i) data[i] = input();
- for(int i=0; i<DATA_N-1; ++i) sum += data[i];
-
- if( (sum == data[SUM]) && (input() == ETX) ) {
- return true;
- } else {
- return false;
- }
+}
+void SerialCtrl::setFailMax() {
+ RETRY_MAX = RETRY_DEF;
}
unsigned char SerialCtrl::input() {