Skip to content

Commit ab4c09c

Browse files
committed
gnss: Add timestamp
1 parent 3509dad commit ab4c09c

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

ports/cxd56/common-hal/gnss/GNSS.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
#include <unistd.h>
2828
#include <fcntl.h>
29+
#include <string.h>
2930
#include <sys/ioctl.h>
30-
#include <arch/chip/gnss.h>
3131

3232
#include "py/runtime.h"
3333

@@ -104,6 +104,8 @@ void common_hal_gnss_update(gnss_obj_t *self) {
104104
self->latitude = positiondata.receiver.latitude;
105105
self->longitude = positiondata.receiver.longitude;
106106
self->altitude = positiondata.receiver.altitude;
107+
memcpy(&self->date, &positiondata.receiver.date, sizeof(struct cxd56_gnss_date_s));
108+
memcpy(&self->time, &positiondata.receiver.time, sizeof(struct cxd56_gnss_time_s));
107109
}
108110
}
109111

@@ -119,6 +121,15 @@ mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self) {
119121
return (mp_float_t) self->altitude;
120122
}
121123

124+
void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm) {
125+
tm->tm_year = self->date.year;
126+
tm->tm_mon = self->date.month;
127+
tm->tm_mday = self->date.day;
128+
tm->tm_hour = self->time.hour;
129+
tm->tm_min = self->time.minute;
130+
tm->tm_sec = self->time.sec;
131+
}
132+
122133
gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self) {
123134
return fix_to_positionfix_type(self->fix);
124135
}

ports/cxd56/common-hal/gnss/GNSS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H
2828
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H
2929

30+
#include <arch/chip/gnss.h>
31+
3032
#include "py/obj.h"
3133

3234
typedef struct {
@@ -36,6 +38,8 @@ typedef struct {
3638
double latitude;
3739
double longitude;
3840
double altitude;
41+
struct cxd56_gnss_date_s date;
42+
struct cxd56_gnss_time_s time;
3943
} gnss_obj_t;
4044

4145
#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H

shared-bindings/gnss/GNSS.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include "shared-bindings/gnss/GNSS.h"
28+
#include "shared-bindings/time/__init__.h"
2829
#include "shared-bindings/util.h"
2930

3031
#include "py/objproperty.h"
@@ -170,6 +171,25 @@ const mp_obj_property_t gnss_altitude_obj = {
170171
(mp_obj_t)&mp_const_none_obj},
171172
};
172173

174+
//| timestamp: Any = ...
175+
//| """Time when the position data was updated."""
176+
//|
177+
STATIC mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) {
178+
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
179+
check_for_deinit(self);
180+
timeutils_struct_time_t tm;
181+
common_hal_gnss_get_timestamp(self, &tm);
182+
return struct_time_from_tm(&tm);
183+
}
184+
MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_timestamp_obj, gnss_obj_get_timestamp);
185+
186+
const mp_obj_property_t gnss_timestamp_obj = {
187+
.base.type = &mp_type_property,
188+
.proxy = {(mp_obj_t)&gnss_get_timestamp_obj,
189+
(mp_obj_t)&mp_const_none_obj,
190+
(mp_obj_t)&mp_const_none_obj},
191+
};
192+
173193
//| fix: Any = ...
174194
//| """Fix mode."""
175195
//|
@@ -194,6 +214,7 @@ STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = {
194214
{ MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) },
195215
{ MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) },
196216
{ MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) },
217+
{ MP_ROM_QSTR(MP_QSTR_timestamp), MP_ROM_PTR(&gnss_timestamp_obj) },
197218
{ MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) }
198219
};
199220
STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table);

shared-bindings/gnss/GNSS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "shared-bindings/gnss/SatelliteSystem.h"
3232
#include "shared-bindings/gnss/PositionFix.h"
3333

34+
#include "lib/timeutils/timeutils.h"
35+
3436
extern const mp_obj_type_t gnss_type;
3537

3638
void common_hal_gnss_construct(gnss_obj_t *self, unsigned long selection);
@@ -41,6 +43,7 @@ void common_hal_gnss_update(gnss_obj_t *self);
4143
mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self);
4244
mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self);
4345
mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self);
46+
void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm);
4447
gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self);
4548

4649
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H

0 commit comments

Comments
 (0)