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.
Dependencies: MX12 ServoRingBuffer mbed-src
Fork of SpindleBot by
Serial_Receive.h
00001 #ifndef Serial_Receive_h 00002 #define Serial_Receive_h 00003 00004 #include "mbed.h" 00005 #include <string> 00006 00007 //vars for Serial packet recieve 00008 int receivePacket(); 00009 #define SOP '<' 00010 #define EOP '>' 00011 bool started = false; 00012 bool ended = false; 00013 char inData[80]; 00014 unsigned char index; 00015 00016 //Vars to process packet 00017 int newData[7] = {0}; 00018 char * val; 00019 char * tissue_type_name; 00020 int count = 0; 00021 std::string inString; 00022 00023 int receivePacket(Serial &serialObject){ 00024 //receive data packet 00025 while(serialObject.readable() > 0) 00026 { 00027 char inChar = serialObject.getc(); 00028 00029 if(inChar == SOP) 00030 { 00031 index = 0; 00032 inData[index] = '\0'; 00033 started = true; 00034 ended = false; 00035 } 00036 else if(inChar == EOP) 00037 { 00038 ended = true; 00039 break; 00040 } 00041 else 00042 { 00043 if(index < 79) 00044 { 00045 inData[index] = inChar; 00046 index++; 00047 inData[index] = '\0'; 00048 } 00049 } 00050 } 00051 // We are here either because all pending serial 00052 // data has been read OR because an end of 00053 // packet marker arrived. Which is it? 00054 if(started && ended) 00055 { 00056 inString=std::string(inData); 00057 tissue_type_name = strtok (inData,","); 00058 00059 //newData[count] = atoi(val); 00060 00061 while ((val = strtok (NULL, ",")) != NULL) 00062 { 00063 newData[++count] = atoi(val); 00064 } 00065 00066 // Reset for the next packet 00067 started = false; 00068 ended = false; 00069 index = 0; 00070 inData[index] = '\0'; 00071 count = 0; 00072 00073 // Flush any remaining characters from the buffer 00074 while(serialObject.readable() > 0) 00075 { 00076 serialObject.getc(); 00077 } 00078 00079 return 1; 00080 } 00081 return 0; 00082 } 00083 00084 00085 #endif
Generated on Thu Jul 14 2022 07:15:41 by
1.7.2
