From ae65f2e6ab58c4f8189c02c27445ab69b1c0bc3f Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Thu, 30 Sep 2021 10:46:55 +0530 Subject: [PATCH] AP_GPS: fix build and working with single GPS Receiver config --- libraries/AP_GPS/AP_GPS.cpp | 9 ++++++--- libraries/AP_GPS/AP_GPS.h | 13 +++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS.cpp b/libraries/AP_GPS/AP_GPS.cpp index aa2f58ceaa..4d445fc59c 100644 --- a/libraries/AP_GPS/AP_GPS.cpp +++ b/libraries/AP_GPS/AP_GPS.cpp @@ -347,7 +347,7 @@ const AP_Param::GroupInfo AP_GPS::var_info[] = { AP_GROUPINFO("_PRIMARY", 27, AP_GPS, _primary, 0), #endif -#if GPS_MAX_RECEIVERS > 1 && HAL_ENABLE_LIBUAVCAN_DRIVERS +#if HAL_ENABLE_LIBUAVCAN_DRIVERS // @Param: _CAN_NODEID1 // @DisplayName: GPS Node ID 1 // @Description: GPS Node id for discovered first. @@ -355,25 +355,28 @@ const AP_Param::GroupInfo AP_GPS::var_info[] = { // @User: Advanced AP_GROUPINFO("_CAN_NODEID1", 28, AP_GPS, _node_id[0], 0), +#if GPS_MAX_RECEIVERS > 1 // @Param: _CAN_NODEID2 // @DisplayName: GPS Node ID 2 // @Description: GPS Node id for discovered second. // @ReadOnly: True // @User: Advanced AP_GROUPINFO("_CAN_NODEID2", 29, AP_GPS, _node_id[1], 0), - +#endif // GPS_MAX_RECEIVERS > 1 // @Param: 1_CAN_OVRIDE // @DisplayName: First UAVCAN GPS NODE ID // @Description: GPS Node id for first GPS. If 0 the gps will be automatically selected on first come basis. // @User: Advanced AP_GROUPINFO("1_CAN_OVRIDE", 30, AP_GPS, _override_node_id[0], 0), +#if GPS_MAX_RECEIVERS > 1 // @Param: 2_CAN_OVRIDE // @DisplayName: Second UAVCAN GPS NODE ID // @Description: GPS Node id for second GPS. If 0 the gps will be automatically selected on first come basis. // @User: Advanced AP_GROUPINFO("2_CAN_OVRIDE", 31, AP_GPS, _override_node_id[1], 0), -#endif +#endif // GPS_MAX_RECEIVERS > 1 +#endif // HAL_ENABLE_LIBUAVCAN_DRIVERS AP_GROUPEND }; diff --git a/libraries/AP_GPS/AP_GPS.h b/libraries/AP_GPS/AP_GPS.h index 294fa36e41..f1ce8a576d 100644 --- a/libraries/AP_GPS/AP_GPS.h +++ b/libraries/AP_GPS/AP_GPS.h @@ -31,9 +31,18 @@ #ifndef GPS_MAX_RECEIVERS #define GPS_MAX_RECEIVERS 2 // maximum number of physical GPS sensors allowed - does not include virtual GPS created by blending receiver data #endif -#ifndef GPS_MAX_INSTANCES +#if !defined(GPS_MAX_INSTANCES) +#if GPS_MAX_RECEIVERS > 1 #define GPS_MAX_INSTANCES (GPS_MAX_RECEIVERS + 1) // maximum number of GPS instances including the 'virtual' GPS created by blending receiver data +#else +#define GPS_MAX_INSTANCES 1 +#endif // GPS_MAX_RECEIVERS > 1 +#endif // GPS_MAX_INSTANCES + +#if GPS_MAX_RECEIVERS <= 1 && GPS_MAX_INSTANCES > 1 +#error "GPS_MAX_INSTANCES should be 1 for GPS_MAX_RECEIVERS <= 1" #endif + #if GPS_MAX_INSTANCES > GPS_MAX_RECEIVERS #define GPS_BLENDED_INSTANCE GPS_MAX_RECEIVERS // the virtual blended GPS is always the highest instance (2) #endif @@ -559,7 +568,7 @@ class AP_GPS AP_Float _blend_tc; AP_Int16 _driver_options; AP_Int8 _primary; -#if GPS_MAX_RECEIVERS > 1 && HAL_ENABLE_LIBUAVCAN_DRIVERS +#if HAL_ENABLE_LIBUAVCAN_DRIVERS AP_Int32 _node_id[GPS_MAX_RECEIVERS]; AP_Int32 _override_node_id[GPS_MAX_RECEIVERS]; #endif