99
1010#include < cmath>
1111
12- namespace xbot {
13- namespace driver {
14- namespace gps {
1512
16- GpsInterface::GpsInterface () {
13+
14+ namespace xbot ::driver::gps {
15+
16+ GpsDriver::GpsDriver () {
1717 datum_lat_ = datum_long_ = NAN;
1818}
19- bool GpsInterface::start_driver (UARTDriver *uart, uint32_t baudrate) {
19+ bool GpsDriver::StartDriver (UARTDriver *uart, uint32_t baudrate) {
2020 chDbgAssert (stopped_, " don't start the driver twice" );
2121 chDbgAssert (uart != nullptr , " need to provide a driver" );
2222 if (!stopped_) {
2323 return false ;
2424 }
25- this ->uart = uart;
26- uart_config .speed = baudrate;
27- uart_config .context = this ;
28- bool uartStarted = uartStart (uart, &uart_config ) == MSG_OK;
25+ this ->uart_ = uart;
26+ uart_config_ .speed = baudrate;
27+ uart_config_ .context = this ;
28+ bool uartStarted = uartStart (uart, &uart_config_ ) == MSG_OK;
2929 if (!uartStarted) {
3030 return false ;
3131 }
3232
3333
34- uart_config .rxchar_cb = [](UARTDriver* uartp, uint16_t c) {
34+ uart_config_ .rxchar_cb = [](UARTDriver* uartp, uint16_t c) {
3535 (void )uartp;
3636 (void )c;
3737 static int missing_bytes=0 ;
3838 missing_bytes++;
3939 };
4040
41- uart_config .rxend_cb = [](UARTDriver* uartp) {
41+ uart_config_ .rxend_cb = [](UARTDriver* uartp) {
4242 (void )uartp;
4343 static int i = 0 ;
4444 i++;
45- GpsInterface * instance = reinterpret_cast <const UARTConfigEx*>(uartp->config )->context ;
46- if (!instance->processing_done ) {
45+ GpsDriver * instance = reinterpret_cast <const UARTConfigEx*>(uartp->config )->context ;
46+ if (!instance->processing_done_ ) {
4747 // This is bad, processing is too slow to keep up with updates!
4848 // We just read into the same buffer again
49- uint8_t * next_recv_buffer = (instance->processing_buffer == instance->recv_buffer1 ) ? instance->recv_buffer2 : instance->recv_buffer1 ;
49+ uint8_t * next_recv_buffer = (instance->processing_buffer_ == instance->recv_buffer1_ ) ? instance->recv_buffer2_ : instance->recv_buffer1_ ;
5050 uartStartReceiveI (uartp, RECV_BUFFER_SIZE, next_recv_buffer);
5151 } else {
5252 // Swap buffers and read into the next one
5353 // Get the pointer to the receiving buffer (it's not the processing buffer)
54- uint8_t * next_recv_buffer = instance->processing_buffer ;
54+ uint8_t * next_recv_buffer = instance->processing_buffer_ ;
5555 uartStartReceiveI (uartp, RECV_BUFFER_SIZE, next_recv_buffer);
56- instance->processing_buffer = (instance->processing_buffer == instance->recv_buffer1 ) ? instance->recv_buffer2 : instance->recv_buffer1 ;
57- instance->processing_buffer_len = RECV_BUFFER_SIZE;
58- instance->processing_done = false ;
56+ instance->processing_buffer_ = (instance->processing_buffer_ == instance->recv_buffer1_ ) ? instance->recv_buffer2_ : instance->recv_buffer1_ ;
57+ instance->processing_buffer_len_ = RECV_BUFFER_SIZE;
58+ instance->processing_done_ = false ;
5959 // Signal the processing thread
6060 if (instance->processing_thread_ ) {
6161 chEvtSignalI (instance->processing_thread_ , 1 );
@@ -66,45 +66,43 @@ bool GpsInterface::start_driver(UARTDriver *uart, uint32_t baudrate) {
6666
6767
6868 stopped_ = false ;
69- processing_thread_ = chThdCreateStatic (&wa , sizeof (wa ), NORMALPRIO, threadHelper, this );
69+ processing_thread_ = chThdCreateStatic (&thd_wa_ , sizeof (thd_wa_ ), NORMALPRIO, threadHelper, this );
7070
71- uartStartReceive (uart, RECV_BUFFER_SIZE, recv_buffer1 );
71+ uartStartReceive (uart, RECV_BUFFER_SIZE, recv_buffer1_ );
7272 return true ;
7373}
7474
75- void GpsInterface::set_state_callback (const GpsInterface ::StateCallback &function) {
76- state_callback = function;
75+ void GpsDriver::SetStateCallback (const GpsDriver ::StateCallback &function) {
76+ state_callback_ = function;
7777}
78- void GpsInterface::set_datum (double datum_lat, double datum_long,
78+ void GpsDriver::SetDatum (double datum_lat, double datum_long,
7979 double datum_height) {
8080 datum_lat_ = datum_lat;
8181 datum_long_ = datum_long;
8282 datum_u_ = datum_height;
8383}
8484
85- bool GpsInterface ::send_raw (const void *data, size_t size) {
85+ bool GpsDriver ::send_raw (const void *data, size_t size) {
8686 // sdWrite(uart, static_cast<const uint8_t*>(data), size);
87- uartSendFullTimeout (uart , &size, data, TIME_INFINITE);
87+ uartSendFullTimeout (uart_ , &size, data, TIME_INFINITE);
8888 return true ;
8989}
9090
91- void GpsInterface ::threadFunc () {
91+ void GpsDriver ::threadFunc () {
9292 while (!stopped_) {
9393 // Wait for data to arrive, process and mark as done
9494 chEvtWaitAny (ALL_EVENTS);
95- process_bytes (processing_buffer, processing_buffer_len );
96- processing_done = true ;
95+ ProcessBytes (processing_buffer_, processing_buffer_len_ );
96+ processing_done_ = true ;
9797 }
9898}
9999
100- void GpsInterface ::threadHelper (void *instance) {
101- auto *gps_interface = static_cast <GpsInterface *>(instance);
100+ void GpsDriver ::threadHelper (void *instance) {
101+ auto *gps_interface = static_cast <GpsDriver *>(instance);
102102 gps_interface->threadFunc ();
103103}
104104
105- void GpsInterface::send_rtcm (const uint8_t *data, size_t size) {
105+ void GpsDriver::SendRTCM (const uint8_t *data, size_t size) {
106106 send_raw (data, size);
107107}
108- } // namespace gps
109- } // namespace driver
110- } // namespace xbot
108+ } // namespace xbot::driver::gps
0 commit comments