Skip to content

Commit ba4bcb6

Browse files
authored
Merge pull request #4 from cchamchi/0.1.11
Add files via upload
2 parents 4ee7601 + a0de0dc commit ba4bcb6

2 files changed

Lines changed: 48 additions & 24 deletions

File tree

libraries/cansat/CansatGPS.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ class CansatGPS
5353
char c;
5454
this->stream.RxModePortSet(RxMode_GPS_PORT);
5555
numc = this->stream.available();
56-
while (numc--) {
57-
this->stream.read(&c,1); //read 1 Byte
58-
if (decode(c)) {
59-
parsed = true;
60-
}
61-
}
56+
while (numc--) {
57+
this->stream.read(&c,1); //read 1 Byte
58+
if (decode(c)) {
59+
parsed = true;
60+
}
61+
}
6262
return parsed;
6363

6464
}
65-
65+
void rx_empty(void)
66+
{
67+
char a;
68+
while(this->stream.available() > 0) {
69+
this->stream.read(&a,1);
70+
}
71+
}
6672
int connected() { return this->conn && this->stream; }
6773
int available() { return this->stream.available(); }
6874
// ground speed in m/s

libraries/cansat/CansatIMU.h

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,57 @@
4141

4242
void begin(uint32_t baud) {
4343
this->stream.begin(baud);
44+
buf_offset=0;
45+
_data_start=false;
4446
}
4547
void begin() {
4648
this->stream.begin(115200);
49+
buf_offset=0;
50+
_data_start=false;
4751
}
4852
bool read(float *buf,int num_items){
49-
uint8_t buf_cnt=0;
53+
54+
5055
char *addr;
51-
bool result=false;
56+
char c;
57+
bool valid_data=false;
5258
this->stream.RxModePortSet(RxMode_IMU_PORT);
53-
delay(3);
54-
int rbytes=this->stream.available();
55-
memset(_imu_data, NULL, sizeof(_imu_data));
56-
if(rbytes>62){ // Some serial datas conficted, select only IMU data with size
57-
for(int n=0;n<rbytes;n++){
58-
this->stream.read((_imu_data+buf_cnt),1);
59-
if(_imu_data[buf_cnt]==0x0a){ //end of string
59+
60+
int16_t rbytes=this->stream.available();
61+
while(rbytes--){
62+
this->stream.read((_imu_data+buf_offset),1);
63+
if(_imu_data[buf_offset]=='\n'){ //LF end of string
64+
if (_data_start){
6065
addr=strtok(_imu_data,",");
6166
for(int i=0;i<num_items;i++){
6267
buf[i]=atof(addr);
6368
addr=strtok(NULL,",");
6469
}
65-
result= true;
66-
}else if(_imu_data[buf_cnt]=='*'){
67-
buf_cnt=-1;
70+
_data_start=false;
71+
valid_data=true;
6872
}
69-
buf_cnt++;
70-
if(buf_cnt>=IMU_DATA_SIZE)buf_cnt=0;
73+
}else if(_imu_data[buf_offset]=='*'){ //start of string
74+
buf_offset=-1;
75+
_data_start=true;
7176
}
72-
//Serial.print("IMU_buff ");
73-
//Serial.println(_imu_data);
77+
// ordinary characters
78+
buf_offset++;
79+
if(buf_offset>=IMU_DATA_SIZE)buf_offset=0;
7480
}
7581

76-
return result;
82+
83+
return valid_data;
84+
7785
}
7886

87+
88+
void rx_empty(void)
89+
{
90+
char a;
91+
while(this->stream.available() > 0) {
92+
this->stream.read(&a,1);
93+
}
94+
}
7995
int connected() { return this->conn && this->stream; }
8096
int available() { return this->stream.available(); }
8197
private:
@@ -98,6 +114,8 @@
98114

99115
char _imu_data[IMU_DATA_SIZE];
100116
size_t _buff_size=IMU_DATA_SIZE;
117+
uint8_t buf_offset;
118+
bool _data_start;
101119
};
102120

103121

0 commit comments

Comments
 (0)