From f537c98ca26005e23f685af270b306684fd75d26 Mon Sep 17 00:00:00 2001
From: Dave Royer <dave@ainstein.ai>
Date: Fri, 18 Jan 2019 11:06:34 -0600
Subject: [PATCH] ulanding radar: update driver for new 2nd gen hardware
 (#11035)

---
 src/drivers/distance_sensor/ulanding/ulanding.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/drivers/distance_sensor/ulanding/ulanding.cpp b/src/drivers/distance_sensor/ulanding/ulanding.cpp
index 5f58560bcd..7e88c4b6f3 100644
--- a/src/drivers/distance_sensor/ulanding/ulanding.cpp
+++ b/src/drivers/distance_sensor/ulanding/ulanding.cpp
@@ -360,8 +360,11 @@ bool Radar::read_and_parse(uint8_t *buf, int len, float *range)
 		if (is_header_byte(_buf[index])) {
 			if (no_header_counter >= BUF_LEN / 3 - 1) {
 				if (ULANDING_VERSION == 1) {
-					if (((_buf[index + 1] + _buf[index + 2] + _buf[index + 3] + _buf[index + 4])) != (_buf[index + 5])
-					    || (_buf[index + 1] <= 0)) {
+					bool checksum_passed = (((_buf[index + 1] + _buf[index + 2] + _buf[index + 3] + _buf[index + 4]) & 0xFF) == _buf[index +
+								5]);
+
+					if (!checksum_passed) {
+						// checksum failed
 						ret = false;
 						break;
 					}
-- 
GitLab