From edac1ef5a7a4fbac0165a3e99786fa5c48e3f542 Mon Sep 17 00:00:00 2001 From: Ryan Friedman Date: Fri, 3 Nov 2023 22:22:27 -0600 Subject: [PATCH] AP_GPS: Expose COM port and Output Rate in header * This removes magic numbers of hard coding the hardware port and output rate * This also fixes configuring the incorrect hardware port * Now, COM2 (TTL) is configured for GSOF output * The data rate remains the same as before Signed-off-by: Ryan Friedman --- libraries/AP_GPS/AP_GPS_GSOF.cpp | 13 ++++++++----- libraries/AP_GPS/AP_GPS_GSOF.h | 26 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS_GSOF.cpp b/libraries/AP_GPS/AP_GPS_GSOF.cpp index 248e38ef13920..af79dd2339bca 100644 --- a/libraries/AP_GPS/AP_GPS_GSOF.cpp +++ b/libraries/AP_GPS/AP_GPS_GSOF.cpp @@ -17,6 +17,11 @@ // Trimble GPS driver for ArduPilot. // Code by Michael Oborne // +// Usage in SITL with hardware for debugging: +// sim_vehicle.py -v Plane -A "--serial3=uart:/dev/ttyUSB0" --console --map -DG +// param set GPS_TYPE 11 // GSOF +// param set SERIAL3_PROTOCOL 5 // GPS +// #define ALLOW_DOUBLE_MATH_FUNCTIONS @@ -70,8 +75,7 @@ AP_GPS_GSOF::read(void) if (gsofmsgreq_index < (sizeof(gsofmsgreq))) { if (now > gsofmsg_time) { - requestGSOF(gsofmsgreq[gsofmsgreq_index], 0); - requestGSOF(gsofmsgreq[gsofmsgreq_index], 3); + requestGSOF(gsofmsgreq[gsofmsgreq_index], HW_Port::COM2, Output_Rate::FREQ_10_HZ); gsofmsg_time = now + 110; gsofmsgreq_index++; } @@ -167,16 +171,15 @@ AP_GPS_GSOF::requestBaud(const uint8_t portindex) } void -AP_GPS_GSOF::requestGSOF(const uint8_t messagetype, const uint8_t portindex) +AP_GPS_GSOF::requestGSOF(const uint8_t messageType, const HW_Port portIndex, const Output_Rate rateHz) { uint8_t buffer[21] = {0x02,0x00,0x64,0x0f,0x00,0x00,0x00, // application file record 0x03,0x00,0x01,0x00, // file control information block - 0x07,0x06,0x0a,portindex,0x01,0x00,0x01,0x00, // output message record + 0x07,0x06,0x0a,static_cast(portIndex),static_cast(rateHz),0x00,messageType,0x00, // output message record 0x00,0x03 }; // checksum buffer[4] = packetcount++; - buffer[17] = messagetype; uint8_t checksum = 0; for (uint8_t a = 1; a < (sizeof(buffer) - 1); a++) { diff --git a/libraries/AP_GPS/AP_GPS_GSOF.h b/libraries/AP_GPS/AP_GPS_GSOF.h index 8c8d56748a049..fe3b0cf8f6e64 100644 --- a/libraries/AP_GPS/AP_GPS_GSOF.h +++ b/libraries/AP_GPS/AP_GPS_GSOF.h @@ -40,15 +40,39 @@ class AP_GPS_GSOF : public AP_GPS_Backend private: + // A subset of the port identifiers in the GSOF protocol that are used for serial. + // Ethernet, USB, etc are not supported by the GPS driver at this time so they are omitted. + // These values are not documented in the API. + enum class HW_Port { + COM1 = 3, // RS232 serial + COM2 = 1, // TTL serial + }; + + // A subset of the data frequencies in the GSOF protocol that are used for serial. + // These values are not documented in the API. + enum class Output_Rate { + FREQ_10_HZ = 1, + FREQ_50_HZ = 15, + FREQ_100_HZ = 16, + }; + bool parse(const uint8_t temp) WARN_IF_UNUSED; bool process_message() WARN_IF_UNUSED; void requestBaud(const uint8_t portindex); - void requestGSOF(const uint8_t messagetype, const uint8_t portindex); + + // Send a request to the GPS to enable a message type on the port at the specified rate. + // Note - these request functions currently ignore the ACK from the device. + // If the device is already sending serial traffic, there is no mechanism to prevent conflict. + // According to the manufacturer, the best approach is to switch to ethernet. + void requestGSOF(const uint8_t messageType, const HW_Port portIndex, const Output_Rate rateHz); + double SwapDouble(const uint8_t* src, const uint32_t pos) const WARN_IF_UNUSED; float SwapFloat(const uint8_t* src, const uint32_t pos) const WARN_IF_UNUSED; uint32_t SwapUint32(const uint8_t* src, const uint32_t pos) const WARN_IF_UNUSED; uint16_t SwapUint16(const uint8_t* src, const uint32_t pos) const WARN_IF_UNUSED; + bool validate_baud(const uint8_t baud) const WARN_IF_UNUSED; + struct Msg_Parser {