gnss: Add timestamp

This commit is contained in:
Kamil Tomaszewski 2020-06-24 11:06:25 +02:00
parent 3509dad5b3
commit ab4c09cea7
4 changed files with 40 additions and 1 deletions

View File

@ -26,8 +26,8 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <arch/chip/gnss.h>
#include "py/runtime.h" #include "py/runtime.h"
@ -104,6 +104,8 @@ void common_hal_gnss_update(gnss_obj_t *self) {
self->latitude = positiondata.receiver.latitude; self->latitude = positiondata.receiver.latitude;
self->longitude = positiondata.receiver.longitude; self->longitude = positiondata.receiver.longitude;
self->altitude = positiondata.receiver.altitude; self->altitude = positiondata.receiver.altitude;
memcpy(&self->date, &positiondata.receiver.date, sizeof(struct cxd56_gnss_date_s));
memcpy(&self->time, &positiondata.receiver.time, sizeof(struct cxd56_gnss_time_s));
} }
} }
@ -119,6 +121,15 @@ mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self) {
return (mp_float_t) self->altitude; return (mp_float_t) self->altitude;
} }
void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm) {
tm->tm_year = self->date.year;
tm->tm_mon = self->date.month;
tm->tm_mday = self->date.day;
tm->tm_hour = self->time.hour;
tm->tm_min = self->time.minute;
tm->tm_sec = self->time.sec;
}
gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self) { gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self) {
return fix_to_positionfix_type(self->fix); return fix_to_positionfix_type(self->fix);
} }

View File

@ -27,6 +27,8 @@
#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H #ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H
#define MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H #define MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H
#include <arch/chip/gnss.h>
#include "py/obj.h" #include "py/obj.h"
typedef struct { typedef struct {
@ -36,6 +38,8 @@ typedef struct {
double latitude; double latitude;
double longitude; double longitude;
double altitude; double altitude;
struct cxd56_gnss_date_s date;
struct cxd56_gnss_time_s time;
} gnss_obj_t; } gnss_obj_t;
#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H #endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_GNSS_GNSS_H

View File

@ -25,6 +25,7 @@
*/ */
#include "shared-bindings/gnss/GNSS.h" #include "shared-bindings/gnss/GNSS.h"
#include "shared-bindings/time/__init__.h"
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
#include "py/objproperty.h" #include "py/objproperty.h"
@ -170,6 +171,25 @@ const mp_obj_property_t gnss_altitude_obj = {
(mp_obj_t)&mp_const_none_obj}, (mp_obj_t)&mp_const_none_obj},
}; };
//| timestamp: Any = ...
//| """Time when the position data was updated."""
//|
STATIC mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) {
gnss_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
timeutils_struct_time_t tm;
common_hal_gnss_get_timestamp(self, &tm);
return struct_time_from_tm(&tm);
}
MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_timestamp_obj, gnss_obj_get_timestamp);
const mp_obj_property_t gnss_timestamp_obj = {
.base.type = &mp_type_property,
.proxy = {(mp_obj_t)&gnss_get_timestamp_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
//| fix: Any = ... //| fix: Any = ...
//| """Fix mode.""" //| """Fix mode."""
//| //|
@ -194,6 +214,7 @@ STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) }, { MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) },
{ MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) }, { MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) },
{ MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) }, { MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) },
{ MP_ROM_QSTR(MP_QSTR_timestamp), MP_ROM_PTR(&gnss_timestamp_obj) },
{ MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) } { MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) }
}; };
STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table); STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table);

View File

@ -31,6 +31,8 @@
#include "shared-bindings/gnss/SatelliteSystem.h" #include "shared-bindings/gnss/SatelliteSystem.h"
#include "shared-bindings/gnss/PositionFix.h" #include "shared-bindings/gnss/PositionFix.h"
#include "lib/timeutils/timeutils.h"
extern const mp_obj_type_t gnss_type; extern const mp_obj_type_t gnss_type;
void common_hal_gnss_construct(gnss_obj_t *self, unsigned long selection); 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);
mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self); mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self);
mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self); mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self);
mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self); mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self);
void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm);
gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self); gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H