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.
Dependents: Nucleo_NHK_2018_syudo_wheel a_team_R1370 Nucleo_NHK_2018_syudo_wheel 2018NHK_gaku_ver2 ... more
Revision 4:31dbd7ea393b, committed 2018-09-13
- Comitter:
- tanabe2000
- Date:
- Thu Sep 13 06:17:23 2018 +0000
- Parent:
- 2:a14ba6b3f198
- Child:
- 5:4109001829fe
- Child:
- 6:7f87c3ff29ef
- Commit message:
- checksum?????
Changed in this revision
| SerialMultiByte.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SerialMultiByte.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SerialMultiByte.cpp Wed Sep 12 15:20:52 2018 +0000
+++ b/SerialMultiByte.cpp Thu Sep 13 06:17:23 2018 +0000
@@ -2,6 +2,7 @@
SerialMultiByte::SerialMultiByte(PinName tx, PinName rx) :
RawSerial(tx, rx),
+ debug(USBTX,USBRX, 115200),
myled(LED1)
{
header[0] = DEFAULT_FIRST_HEADER;
@@ -33,6 +34,7 @@
void SerialMultiByte::receiveByte()
{
buffer[bufferPoint % bufferSize] = getc();
+
if(bufferPoint != 0xff) {
++bufferPoint;
@@ -42,21 +44,31 @@
++receivedBytes;
- if(receivedBytes == bufferSize) checkData();
+ if(receivedBytes >= bufferSize) checkData();
}
void SerialMultiByte::checkData()
{
- for(int i = 0; i < bufferSize; i++) {
- if(buffer[i % bufferSize] == header[0] && buffer[(i + 1) % bufferSize] == header[1]) {
+
+ for(int i = 0; i < bufferSize; i++) {
+ if(buffer[i % bufferSize] == header[0] && buffer[(i + 1) % bufferSize] == header[1]) {
+
+ uint8_t checksum = 0x00;
+ for(int j = 0; j < bufferSize - 3; j++) {
+ checksum += buffer[(i + 2 + j)% bufferSize];
+
+ }
+ if(checksum == buffer[(i + bufferSize - 1)% bufferSize]) {
+ myled = !myled;
for(int j = 0; j < bufferSize - 3; j++) {
data[j] = buffer[(i + 2 + j) % bufferSize];
}
receivedBytes = 0;
- myled = !myled;
+
return;
}
}
+ }
}
void SerialMultiByte::getData(uint8_t data_[])
--- a/SerialMultiByte.h Wed Sep 12 15:20:52 2018 +0000
+++ b/SerialMultiByte.h Thu Sep 13 06:17:23 2018 +0000
@@ -30,6 +30,7 @@
uint8_t header[2];
uint16_t bufferSize;
uint8_t* data;
+ Serial debug;
};
#endif
\ No newline at end of file