Skip to content

Commit

Permalink
This commit is a pre-check before updating the master_JRE branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbblue0922 committed Oct 10, 2023
1 parent 2b4cfce commit 7356b7c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
20 changes: 6 additions & 14 deletions libraries/AP_RangeFinder/AP_RangeFinder_JRE_Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "AP_RangeFinder_JRE_Serial.h"
#include <AP_Math/AP_Math.h>
#include "AP_RangeFinder_config.h"

#if AP_RANGEFINDER_JRE_SERIAL_ENABLED

#include "AP_RangeFinder_JRE_Serial.h"
#include <AP_Math/AP_Math.h>

#define FRAME_HEADER_1 'R' // 0x52
#define FRAME_HEADER_2 'A' // 0x41

Expand All @@ -30,15 +32,10 @@ bool AP_RangeFinder_JRE_Serial::get_reading(float &reading_m)
if (uart == nullptr) {
return false; // not update
}
uint32_t n = uart->available();
if (n == 0) {
return false;
}

uint16_t valid_count = 0; // number of valid readings
uint16_t invalid_count = 0; // number of invalid readings
float sum = 0;
float reading_cm;
// max distance the sensor can reliably measure - read from parameters
const int16_t distance_cm_max = max_distance_cm();

Expand Down Expand Up @@ -71,17 +68,12 @@ bool AP_RangeFinder_JRE_Serial::get_reading(float &reading_m)
if (data_buff_idx >= ARRAY_SIZE(data_buff)) { // 1 data set complete
// crc check
uint16_t crc = crc16_ccitt_r(data_buff, ARRAY_SIZE(data_buff) - 2, 0xffff, 0xffff);
if ((((crc>>8) & 0xff) == data_buff[15]) && ((crc & 0xff) == data_buff[14])) {
if ((HIGHBYTE(crc) == data_buff[15]) && (LOWBYTE(crc) == data_buff[14])) {
// status check
if (data_buff[13] & 0x02) { // NTRK
invalid_count++;
} else { // TRK
reading_cm = data_buff[4] * 256 + data_buff[5];
if (reading_cm < distance_cm_max) {
reading_m = reading_cm * 0.01f;
} else {
reading_m = distance_cm_max * 0.01f;
}
reading_m = (data_buff[4] * 256 + data_buff[5]) * 0.01f;
sum += reading_m;
valid_count++;
}
Expand Down
6 changes: 4 additions & 2 deletions libraries/AP_RangeFinder/AP_RangeFinder_JRE_Serial.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#include "AP_RangeFinder.h"
#include "AP_RangeFinder_Backend_Serial.h"
#include "AP_RangeFinder_config.h"

#if AP_RANGEFINDER_JRE_SERIAL_ENABLED

#include "AP_RangeFinder.h"
#include "AP_RangeFinder_Backend_Serial.h"

#define DATA_LENGTH 16

class AP_RangeFinder_JRE_Serial : public AP_RangeFinder_Backend_Serial
Expand Down

0 comments on commit 7356b7c

Please sign in to comment.