1+ #include " AP_Periph.h"
2+ #include < AP_Filesystem/AP_Filesystem.h>
3+ #include < stdio.h>
4+
5+ #ifdef ENABLE_BASE_MODE
6+ // table of user settable parameters
7+ const AP_Param::GroupInfo GPS_Rover::var_info[] = {
8+ // @Param: ENABLE
9+ // @DisplayName: Enable GPS Rover Mode
10+ // @Description: Enable GPS Rover Mode
11+ // @User: Standard
12+ AP_GROUPINFO_FLAGS (" _ENABLE" , 1 , GPS_Rover, _enabled, 0 , AP_PARAM_FLAG_ENABLE),
13+
14+ AP_GROUPEND
15+ };
16+
17+ GPS_Rover::GPS_Rover () {
18+ // setup parameters
19+ AP_Param::setup_object_defaults (this , var_info);
20+ }
21+
22+ void GPS_Rover::init () {
23+ if (!_enabled) {
24+ return ;
25+ }
26+ // set gps raw data if not set
27+ float value;
28+ AP_Param::get (" GPS_RAW_DATA" , value);
29+ if (value < 1.0 ) {
30+ AP_Param::set_and_save_by_name (" GPS_RAW_DATA" , 1 );
31+ }
32+ // set callback for GPS RAW data
33+ AP::gps ().set_gps_raw_cb (FUNCTOR_BIND_MEMBER (&GPS_Rover::ubx_rawdata_cb, void , const uint8_t *, uint32_t ));
34+ }
35+
36+ void GPS_Rover::update () {
37+ // do nothing if not enabled
38+ if (!_initialized && _enabled && (AP::gps ().status () >= AP_GPS::GPS_OK_FIX_3D)) {
39+ init ();
40+ _initialized = true ;
41+ }
42+ }
43+
44+ void GPS_Rover::ubx_rawdata_cb (const uint8_t *data, uint32_t length) {
45+ if (ubx_log_fd == -1 ) {
46+ struct stat st;
47+ int ret = AP::FS ().stat (" rover" , &st);
48+ if (ret == -1 ) {
49+ ret = AP::FS ().mkdir (" rover" );
50+ }
51+ date_time dt;
52+ GPS_Base::gps_week_time (dt, AP::gps ().time_week (), AP::gps ().time_week_ms ());
53+ snprintf (_ubx_log_filename, sizeof (_ubx_log_filename), " /rover/UTC_%04d_%02d_%02d_%02d_%02d_%02d.ubx" , dt.year , dt.month , dt.day , dt.hour , dt.minute , dt.second );
54+ ubx_log_fd = AP::FS ().open (_ubx_log_filename, O_CREAT | O_WRONLY | O_TRUNC);
55+ if (ubx_log_fd < 0 ) {
56+ can_printf (" Failed to create rover log file %d\n " , errno);
57+ } else {
58+ can_printf (" Opened rover log file %s\n " , _ubx_log_filename);
59+ }
60+ if (!AP::FS ().set_mtime (_ubx_log_filename, dt.utc_sec )) {
61+ can_printf (" Failed to set file time %s\n " , strerror (errno));
62+ }
63+ }
64+
65+ if (ubx_log_fd != -1 ) {
66+ AP::FS ().write (ubx_log_fd, data, length);
67+ AP::FS ().fsync (ubx_log_fd);
68+ }
69+ }
70+
71+ #endif // ENABLE_BASE_MODE
0 commit comments