Skip to content

Commit 51dea24

Browse files
committed
GPS -detecting mtk
1 parent b43a8ba commit 51dea24

File tree

8 files changed

+39
-21
lines changed

8 files changed

+39
-21
lines changed

src/components/gps/controller.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,17 @@ bool GPSController::DetectMediatek() {
158158
char buffer[buf_len];
159159
size_t available = _uart_hardware->GetHardwareSerial()->available();
160160
size_t bytes_to_read = min(available, buf_len - 1);
161+
// Print the two out
162+
WS_DEBUG_PRINT("[gps] Reading MediaTek GPS response: ");
163+
WS_DEBUG_PRINT(available);
164+
WS_DEBUG_PRINT(" bytes, reading ");
165+
WS_DEBUG_PRINTLN(bytes_to_read);
161166
for (size_t i = 0; i < bytes_to_read; i++) {
162167
buffer[i] = _uart_hardware->GetHardwareSerial()->read();
163168
}
164169
buffer[bytes_to_read] = '\0';
170+
WS_DEBUG_PRINT("[gps] MediaTek GPS response: ");
171+
WS_DEBUG_PRINTLN(buffer);
165172
// Compare the first 7 characters to the expected PMTK705 string
166173
if (strncmp(buffer, CMD_MTK_QUERY_FW_RESP, 7) != 0) {
167174
return false;

src/components/gps/controller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#define CMD_MTK_QUERY_FW \
2323
"$PMTK605*31" ///< Request to query MediaTek firmware version
2424
#define CMD_MTK_QUERY_FW_RESP \
25-
"PMTK705" ///< Response from querying MediaTek firmware version without the
26-
///< ReleaseStr
25+
"$PMTK705" ///< Response from querying MediaTek firmware version without the
26+
///< ReleaseStr
2727
#define MAX_NEMA_SENTENCE_LEN 82 ///< Maximum length of a NMEA sentence
2828

2929
class Wippersnapper_V2; ///< Forward declaration

src/components/uart/controller.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,9 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
6868
WS_DEBUG_PRINTLN("[uart] UART hardware instance configured successfully!");
6969

7070
// Create a new UartDevice "driver" on the hardware layer (UARTHardware)
71-
wippersnapper_uart_UartDeviceConfig cfg_device = add_msg->cfg_device;
72-
WS_DEBUG_PRINT("cfg_device.device_type: ");
73-
WS_DEBUG_PRINTLN(cfg_device.device_type);
7471
drvUartBase *uart_driver = nullptr;
75-
76-
// tODO: Am seeing an issue where device_id causes a crash
77-
// uncomment below:
78-
// WS_DEBUG_PRINT("cfg_device.device_id: ");
79-
// WS_DEBUG_PRINTLN(cfg_device.device_id);
80-
81-
/*
82-
// TODO: Monday, Crash occurs here, no idea why yet
72+
wippersnapper_uart_UartDeviceConfig cfg_device = add_msg->cfg_device;
73+
GPSController gps; // TODO: This should be a member variable, not a local one
8374
switch (cfg_device.device_type) {
8475
case wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_UNSPECIFIED:
8576
WS_DEBUG_PRINTLN("[uart] ERROR: Unspecified device type!");
@@ -111,8 +102,26 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
111102
return false;
112103
case wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_GPS:
113104
WS_DEBUG_PRINTLN("[uart] GPS device type not implemented!");
114-
delete uart_hardware; // cleanup
115-
return false;
105+
// delete uart_hardware; // cleanup
106+
// return false;
107+
108+
WS_DEBUG_PRINTLN("[uart] Adding GPS device..");
109+
if (!gps.SetInterface(uart_hardware)) {
110+
WS_DEBUG_PRINTLN("[uart] ERROR: Failed to set GPS interface!");
111+
delete uart_hardware; // cleanup
112+
return false;
113+
}
114+
WS_DEBUG_PRINTLN("[uart] Initializing GPS device...");
115+
if (!gps.begin()) {
116+
WS_DEBUG_PRINTLN("[uart] ERROR: Failed to initialize GPS device!");
117+
delete uart_hardware; // cleanup
118+
return false;
119+
}
120+
WS_DEBUG_PRINTLN("[uart] GPS device initialized successfully!");
121+
// TODO: Figure out how to add this to the drivers list so it can be
122+
// queried, also this is sitting on the stack instead of the heap, so it
123+
// will be destroyed when this function returns!!!
124+
break;
116125
case wippersnapper_uart_UartDeviceType_UART_DEVICE_TYPE_PM25AQI:
117126
WS_DEBUG_PRINTLN("[uart] Adding PM2.5 AQI device..");
118127
// Create a new PM2.5 AQI driver instance
@@ -136,6 +145,7 @@ bool UARTController::Handle_UartAdd(pb_istream_t *stream) {
136145
return false;
137146
}
138147

148+
/*
139149
// Attempt to initialize the UART driver
140150
if (uart_driver == nullptr) {
141151
WS_DEBUG_PRINTLN("[uart] ERROR: Failed to create UART driver!");

src/components/uart/controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "drivers/drvUartUs100.h"
2525

2626
class Wippersnapper_V2; ///< Forward declaration
27+
class GPSController;
2728
class UARTModel; ///< Forward declaration
2829
class UARTHardware; ///< Forward declaration
2930

src/protos/gps.pb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#error Regenerate this file with the current version of nanopb generator.
77
#endif
88

9-
PB_BIND(wippersnapper_gps_GPSConfig, wippersnapper_gps_GPSConfig, 4)
9+
PB_BIND(wippersnapper_gps_GPSConfig, wippersnapper_gps_GPSConfig, 2)
1010

1111

1212
PB_BIND(wippersnapper_gps_GPSDateTime, wippersnapper_gps_GPSDateTime, AUTO)

src/protos/gps.pb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
typedef struct _wippersnapper_gps_GPSConfig {
1818
/* Baud rate is not included here as it is included in the UartAdd->UartSerialConfig message. */
1919
pb_size_t commands_count;
20-
char commands[16][256]; /* * List of commands to configure the GPS * */
20+
char commands[16][90]; /* * List of commands to configure the GPS * */
2121
} wippersnapper_gps_GPSConfig;
2222

2323
/* * GPSDateTime represents the date and time information from a GPRMC/GPGGA string * */
@@ -161,7 +161,7 @@ extern const pb_msgdesc_t wippersnapper_gps_GPGGAResponse_msg;
161161
/* Maximum encoded size of messages (where known) */
162162
#define WIPPERSNAPPER_GPS_GPS_PB_H_MAX_SIZE wippersnapper_gps_GPSConfig_size
163163
#define wippersnapper_gps_GPGGAResponse_size 168
164-
#define wippersnapper_gps_GPSConfig_size 4128
164+
#define wippersnapper_gps_GPSConfig_size 1456
165165
#define wippersnapper_gps_GPSDateTime_size 77
166166
#define wippersnapper_gps_GPSRMCResponse_size 139
167167

src/protos/signal.pb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#error Regenerate this file with the current version of nanopb generator.
77
#endif
88

9-
PB_BIND(wippersnapper_signal_BrokerToDevice, wippersnapper_signal_BrokerToDevice, 4)
9+
PB_BIND(wippersnapper_signal_BrokerToDevice, wippersnapper_signal_BrokerToDevice, 2)
1010

1111

1212
PB_BIND(wippersnapper_signal_DeviceToBroker, wippersnapper_signal_DeviceToBroker, 4)

src/protos/uart.pb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ PB_BIND(wippersnapper_uart_TrinamicDynamixelConfig, wippersnapper_uart_TrinamicD
1818
PB_BIND(wippersnapper_uart_PM25AQIConfig, wippersnapper_uart_PM25AQIConfig, AUTO)
1919

2020

21-
PB_BIND(wippersnapper_uart_UartDeviceConfig, wippersnapper_uart_UartDeviceConfig, 4)
21+
PB_BIND(wippersnapper_uart_UartDeviceConfig, wippersnapper_uart_UartDeviceConfig, 2)
2222

2323

24-
PB_BIND(wippersnapper_uart_UartAdd, wippersnapper_uart_UartAdd, 4)
24+
PB_BIND(wippersnapper_uart_UartAdd, wippersnapper_uart_UartAdd, 2)
2525

2626

2727
PB_BIND(wippersnapper_uart_UartAdded, wippersnapper_uart_UartAdded, AUTO)

0 commit comments

Comments
 (0)