Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_GPS: replace utility functions with compiler builtins #24936

Merged
merged 1 commit into from Sep 11, 2023

Conversation

peterbarker
Copy link
Contributor

Tested with this patch:

--- a/libraries/AP_GPS/GPS_Backend.cpp
+++ b/libraries/AP_GPS/GPS_Backend.cpp
@@ -157,6 +157,21 @@ AP_GPS_Backend::inject_data(const uint8_t *data, uint16_t len)
 
 void AP_GPS_Backend::_detection_message(char *buffer, const uint8_t buflen) const
 {
+    const int32_t values[] { 0, 1, INT32_MAX, INT32_MIN, 17, 123456789};
+    for (auto value : values) {
+        if (swap_int32(value) != (int32_t)htobe32(value)) {
+            abort();
+        }
+    }
+    gcs().send_text(MAV_SEVERITY_INFO, "swap32 OK");
+    const int16_t values16[] { 0, 1, INT16_MAX, INT16_MIN, 17, -17};
+    for (auto value : values16) {
+        if (swap_int16(value) != (int16_t) htobe16(value)) {
+            abort();
+        }
+    }
+    gcs().send_text(MAV_SEVERITY_INFO, "swap16 OK");
+
     const uint8_t instance = state.instance;
     const struct AP_GPS::detect_state dstate = gps.detect_state[instance];
 

@peterbarker
Copy link
Contributor Author

Board               AP_Periph  blimp  bootloader  copter  heli  iofirmware  plane  rover  sub
Durandal                       8      *           8       8                 8      8      8
HerePro             *                                                                     
Hitec-Airspeed      *                                                                     
KakuteH7-bdshot                0      *           -16     -24               0      -24    0
MatekF405                      *      *           *       *                 *      *      *
Pixhawk1-1M-bdshot             *                  *       *                 *      *      *
f103-QiotekPeriph   *                                                                     
f303-Universal      *                                                                     
iomcu                                                           *                         
revo-mini                      0      *           -16     -24               0      -24    0
skyviper-v2450                                    *                                       

@amilcarlucas
Copy link
Contributor

Good catch

@tridge tridge merged commit a391b14 into ArduPilot:master Sep 11, 2023
84 checks passed
@peterbarker peterbarker deleted the pr/remove-int16-int32-swap branch September 12, 2023 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants