refactor gps: use enum class for gps_driver_mode_t

This commit is contained in:
Beat Küng
2021-02-26 14:40:27 +01:00
committed by Daniel Agar
parent 09a42e7af2
commit 0f6bf6bc0e
+47 -47
View File
@@ -79,14 +79,14 @@
#define TIMEOUT_5HZ 500 //!< Timeout time in mS, 200 mS (5Hz) + 300 mS delta for error #define TIMEOUT_5HZ 500 //!< Timeout time in mS, 200 mS (5Hz) + 300 mS delta for error
#define RATE_MEASUREMENT_PERIOD 5000000 #define RATE_MEASUREMENT_PERIOD 5000000
typedef enum { enum class gps_driver_mode_t {
GPS_DRIVER_MODE_NONE = 0, None = 0,
GPS_DRIVER_MODE_UBX, UBX,
GPS_DRIVER_MODE_MTK, MTK,
GPS_DRIVER_MODE_ASHTECH, ASHTECH,
GPS_DRIVER_MODE_EMLIDREACH, EMLIDREACH,
GPS_DRIVER_MODE_FEMTOMES FEMTOMES
} gps_driver_mode_t; };
enum class gps_dump_comm_mode_t : int32_t { enum class gps_dump_comm_mode_t : int32_t {
Disabled = 0, Disabled = 0,
@@ -303,7 +303,7 @@ GPS::GPS(const char *path, gps_driver_mode_t mode, GPSHelper::Interface interfac
set_device_bus_type(device::Device::DeviceBusType::DeviceBusType_SPI); set_device_bus_type(device::Device::DeviceBusType::DeviceBusType_SPI);
} }
if (_mode == GPS_DRIVER_MODE_NONE) { if (_mode == gps_driver_mode_t::None) {
// use parameter to select mode if not provided via CLI // use parameter to select mode if not provided via CLI
char protocol_param_name[16]; char protocol_param_name[16];
snprintf(protocol_param_name, sizeof(protocol_param_name), "GPS_%i_PROTOCOL", (int)_instance + 1); snprintf(protocol_param_name, sizeof(protocol_param_name), "GPS_%i_PROTOCOL", (int)_instance + 1);
@@ -311,19 +311,19 @@ GPS::GPS(const char *path, gps_driver_mode_t mode, GPSHelper::Interface interfac
param_get(param_find(protocol_param_name), &protocol); param_get(param_find(protocol_param_name), &protocol);
switch (protocol) { switch (protocol) {
case 1: _mode = GPS_DRIVER_MODE_UBX; break; case 1: _mode = gps_driver_mode_t::UBX; break;
#ifndef CONSTRAINED_FLASH #ifndef CONSTRAINED_FLASH
case 2: _mode = GPS_DRIVER_MODE_MTK; break; case 2: _mode = gps_driver_mode_t::MTK; break;
case 3: _mode = GPS_DRIVER_MODE_ASHTECH; break; case 3: _mode = gps_driver_mode_t::ASHTECH; break;
case 4: _mode = GPS_DRIVER_MODE_EMLIDREACH; break; case 4: _mode = gps_driver_mode_t::EMLIDREACH; break;
#endif // CONSTRAINED_FLASH #endif // CONSTRAINED_FLASH
} }
} }
_mode_auto = _mode == GPS_DRIVER_MODE_NONE; _mode_auto = _mode == gps_driver_mode_t::None;
} }
GPS::~GPS() GPS::~GPS()
@@ -761,33 +761,33 @@ GPS::run()
} }
switch (_mode) { switch (_mode) {
case GPS_DRIVER_MODE_NONE: case gps_driver_mode_t::None:
_mode = GPS_DRIVER_MODE_UBX; _mode = gps_driver_mode_t::UBX;
/* FALLTHROUGH */ /* FALLTHROUGH */
case GPS_DRIVER_MODE_UBX: case gps_driver_mode_t::UBX:
_helper = new GPSDriverUBX(_interface, &GPS::callback, this, &_report_gps_pos, _p_report_sat_info, _helper = new GPSDriverUBX(_interface, &GPS::callback, this, &_report_gps_pos, _p_report_sat_info,
gps_ubx_dynmodel, heading_offset, ubx_mode); gps_ubx_dynmodel, heading_offset, ubx_mode);
set_device_type(DRV_GPS_DEVTYPE_UBX); set_device_type(DRV_GPS_DEVTYPE_UBX);
break; break;
#ifndef CONSTRAINED_FLASH #ifndef CONSTRAINED_FLASH
case GPS_DRIVER_MODE_MTK: case gps_driver_mode_t::MTK:
_helper = new GPSDriverMTK(&GPS::callback, this, &_report_gps_pos); _helper = new GPSDriverMTK(&GPS::callback, this, &_report_gps_pos);
set_device_type(DRV_GPS_DEVTYPE_MTK); set_device_type(DRV_GPS_DEVTYPE_MTK);
break; break;
case GPS_DRIVER_MODE_ASHTECH: case gps_driver_mode_t::ASHTECH:
_helper = new GPSDriverAshtech(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info, heading_offset); _helper = new GPSDriverAshtech(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info, heading_offset);
set_device_type(DRV_GPS_DEVTYPE_ASHTECH); set_device_type(DRV_GPS_DEVTYPE_ASHTECH);
break; break;
case GPS_DRIVER_MODE_EMLIDREACH: case gps_driver_mode_t::EMLIDREACH:
_helper = new GPSDriverEmlidReach(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info); _helper = new GPSDriverEmlidReach(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info);
set_device_type(DRV_GPS_DEVTYPE_EMLID_REACH); set_device_type(DRV_GPS_DEVTYPE_EMLID_REACH);
break; break;
case GPS_DRIVER_MODE_FEMTOMES: case gps_driver_mode_t::FEMTOMES:
_helper = new GPSDriverFemto(&GPS::callback, this, &_report_gps_pos/*, _p_report_sat_info*/); _helper = new GPSDriverFemto(&GPS::callback, this, &_report_gps_pos/*, _p_report_sat_info*/);
set_device_type(DRV_GPS_DEVTYPE_FEMTOMES); set_device_type(DRV_GPS_DEVTYPE_FEMTOMES);
break; break;
@@ -815,7 +815,7 @@ GPS::run()
_report_gps_pos.heading = NAN; _report_gps_pos.heading = NAN;
_report_gps_pos.heading_offset = heading_offset; _report_gps_pos.heading_offset = heading_offset;
if (_mode == GPS_DRIVER_MODE_UBX) { if (_mode == gps_driver_mode_t::UBX) {
/* GPS is obviously detected successfully, reset statistics */ /* GPS is obviously detected successfully, reset statistics */
_helper->resetUpdateRates(); _helper->resetUpdateRates();
@@ -894,19 +894,19 @@ GPS::run()
// const char *mode_str = "unknown"; // const char *mode_str = "unknown";
// //
// switch (_mode) { // switch (_mode) {
// case GPS_DRIVER_MODE_UBX: // case gps_driver_mode_t::UBX:
// mode_str = "UBX"; // mode_str = "UBX";
// break; // break;
// //
// case GPS_DRIVER_MODE_MTK: // case gps_driver_mode_t::MTK:
// mode_str = "MTK"; // mode_str = "MTK";
// break; // break;
// //
// case GPS_DRIVER_MODE_ASHTECH: // case gps_driver_mode_t::ASHTECH:
// mode_str = "ASHTECH"; // mode_str = "ASHTECH";
// break; // break;
// //
// case GPS_DRIVER_MODE_EMLIDREACH: // case gps_driver_mode_t::EMLIDREACH:
// mode_str = "EMLID REACH"; // mode_str = "EMLID REACH";
// break; // break;
// //
@@ -933,26 +933,26 @@ GPS::run()
if (_mode_auto) { if (_mode_auto) {
switch (_mode) { switch (_mode) {
case GPS_DRIVER_MODE_UBX: case gps_driver_mode_t::UBX:
#ifndef CONSTRAINED_FLASH #ifndef CONSTRAINED_FLASH
_mode = GPS_DRIVER_MODE_MTK; _mode = gps_driver_mode_t::MTK;
break; break;
case GPS_DRIVER_MODE_MTK: case gps_driver_mode_t::MTK:
_mode = GPS_DRIVER_MODE_ASHTECH; _mode = gps_driver_mode_t::ASHTECH;
break; break;
case GPS_DRIVER_MODE_ASHTECH: case gps_driver_mode_t::ASHTECH:
_mode = GPS_DRIVER_MODE_EMLIDREACH; _mode = gps_driver_mode_t::EMLIDREACH;
break; break;
case GPS_DRIVER_MODE_EMLIDREACH: case gps_driver_mode_t::EMLIDREACH:
_mode = GPS_DRIVER_MODE_FEMTOMES; _mode = gps_driver_mode_t::FEMTOMES;
break; break;
case GPS_DRIVER_MODE_FEMTOMES: case gps_driver_mode_t::FEMTOMES:
#endif // CONSTRAINED_FLASH #endif // CONSTRAINED_FLASH
_mode = GPS_DRIVER_MODE_UBX; _mode = gps_driver_mode_t::UBX;
px4_usleep(500000); // tried all possible drivers. Wait a bit before next round px4_usleep(500000); // tried all possible drivers. Wait a bit before next round
break; break;
@@ -987,24 +987,24 @@ GPS::print_status()
// GPS Mode // GPS Mode
switch (_mode) { switch (_mode) {
case GPS_DRIVER_MODE_UBX: case gps_driver_mode_t::UBX:
PX4_INFO("protocol: UBX"); PX4_INFO("protocol: UBX");
break; break;
#ifndef CONSTRAINED_FLASH #ifndef CONSTRAINED_FLASH
case GPS_DRIVER_MODE_MTK: case gps_driver_mode_t::MTK:
PX4_INFO("protocol: MTK"); PX4_INFO("protocol: MTK");
break; break;
case GPS_DRIVER_MODE_ASHTECH: case gps_driver_mode_t::ASHTECH:
PX4_INFO("protocol: ASHTECH"); PX4_INFO("protocol: ASHTECH");
break; break;
case GPS_DRIVER_MODE_EMLIDREACH: case gps_driver_mode_t::EMLIDREACH:
PX4_INFO("protocol: EMLIDREACH"); PX4_INFO("protocol: EMLIDREACH");
break; break;
case GPS_DRIVER_MODE_FEMTOMES: case gps_driver_mode_t::FEMTOMES:
PX4_INFO("protocol: FEMTOMES"); PX4_INFO("protocol: FEMTOMES");
break; break;
#endif // CONSTRAINED_FLASH #endif // CONSTRAINED_FLASH
@@ -1242,7 +1242,7 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)
bool enable_sat_info = false; bool enable_sat_info = false;
GPSHelper::Interface interface = GPSHelper::Interface::UART; GPSHelper::Interface interface = GPSHelper::Interface::UART;
GPSHelper::Interface interface_secondary = GPSHelper::Interface::UART; GPSHelper::Interface interface_secondary = GPSHelper::Interface::UART;
gps_driver_mode_t mode = GPS_DRIVER_MODE_NONE; gps_driver_mode_t mode = gps_driver_mode_t::None;
bool error_flag = false; bool error_flag = false;
int myoptind = 1; int myoptind = 1;
@@ -1304,19 +1304,19 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)
case 'p': case 'p':
if (!strcmp(myoptarg, "ubx")) { if (!strcmp(myoptarg, "ubx")) {
mode = GPS_DRIVER_MODE_UBX; mode = gps_driver_mode_t::UBX;
#ifndef CONSTRAINED_FLASH #ifndef CONSTRAINED_FLASH
} else if (!strcmp(myoptarg, "mtk")) { } else if (!strcmp(myoptarg, "mtk")) {
mode = GPS_DRIVER_MODE_MTK; mode = gps_driver_mode_t::MTK;
} else if (!strcmp(myoptarg, "ash")) { } else if (!strcmp(myoptarg, "ash")) {
mode = GPS_DRIVER_MODE_ASHTECH; mode = gps_driver_mode_t::ASHTECH;
} else if (!strcmp(myoptarg, "eml")) { } else if (!strcmp(myoptarg, "eml")) {
mode = GPS_DRIVER_MODE_EMLIDREACH; mode = gps_driver_mode_t::EMLIDREACH;
} else if (!strcmp(myoptarg, "fem")) { } else if (!strcmp(myoptarg, "fem")) {
mode = GPS_DRIVER_MODE_FEMTOMES; mode = gps_driver_mode_t::FEMTOMES;
#endif // CONSTRAINED_FLASH #endif // CONSTRAINED_FLASH
} else { } else {
PX4_ERR("unknown protocol: %s", myoptarg); PX4_ERR("unknown protocol: %s", myoptarg);