1
#include "com/ubuntu/location/providers/gps/provider.h"
3
#include "com/ubuntu/location/logging.h"
5
#include <ubuntu/application/ubuntu_application_gps.h>
7
namespace cul = com::ubuntu::location;
8
namespace culg = com::ubuntu::location::providers::gps;
12
static const std::map<uint16_t, std::string> status_lut =
14
{UBUNTU_GPS_STATUS_NONE, "UBUNTU_GPS_STATUS_NONE"},
15
{UBUNTU_GPS_STATUS_SESSION_BEGIN, "UBUNTU_GPS_STATUS_SESSION_BEGIN"},
16
{UBUNTU_GPS_STATUS_SESSION_END, "UBUNTU_GPS_STATUS_SESSION_END"},
17
{UBUNTU_GPS_STATUS_ENGINE_ON, "UBUNTU_GPS_STATUS_ENGINE_ON"},
18
{UBUNTU_GPS_STATUS_ENGINE_OFF, "UBUNTU_GPS_STATUS_ENGINE_OFF"}
22
struct culg::Provider::Private
25
static void on_location_update(UbuntuGpsLocation* location, void* context)
27
auto thiz = static_cast<culg::Provider*>(context);
29
if (location->flags & UBUNTU_GPS_LOCATION_HAS_LAT_LONG)
31
VLOG(1) << "location->flags & UBUNTU_GPS_LOCATION_HAS_LAT_LONG";
34
pos.latitude(cul::wgs84::Latitude{location->latitude * cul::units::Degrees});
35
pos.longitude(cul::wgs84::Longitude{location->longitude * cul::units::Degrees});
36
if(location->flags & UBUNTU_GPS_LOCATION_HAS_ALTITUDE)
37
pos.altitude(cul::wgs84::Altitude{location->altitude * cul::units::Meters});
39
thiz->deliver_position_updates(cul::Update<cul::Position>{pos, cul::Clock::now()});
42
if (location->flags & UBUNTU_GPS_LOCATION_HAS_SPEED)
44
VLOG(1) << "location->flags & UBUNTU_GPS_LOCATION_HAS_SPEED";
46
cul::Velocity v{location->speed * cul::units::MetersPerSecond};
47
thiz->deliver_velocity_updates(cul::Update<cul::Velocity>{v, cul::Clock::now()});
50
if (location->flags & UBUNTU_GPS_LOCATION_HAS_BEARING)
52
VLOG(1) << "location->flags & UBUNTU_GPS_LOCATION_HAS_BEARING";
54
cul::Heading h{location->bearing * cul::units::Degrees};
55
thiz->deliver_heading_updates(cul::Update<cul::Heading>{h, cul::Clock::now()});
59
static void on_status_update(uint16_t status, void* /*context*/)
61
VLOG(1) << "Status = " << status_lut.at(status);
64
static void on_sv_status_update(UbuntuGpsSvStatus* sv_info, void* /*context*/)
66
VLOG(1) << "SV status update: [#svs: " << sv_info->num_svs << "]";
69
static void on_nmea_update(int64_t /*timestamp*/, const char* /*nmea*/, int /*length*/, void* /*context*/)
73
static void on_set_capabilities(uint32_t capabilities, void* /*context*/)
75
VLOG(1) << __PRETTY_FUNCTION__ << ": " << capabilities;
78
static void on_request_utc_time(void* /*context*/)
80
VLOG(1) << __PRETTY_FUNCTION__;
83
static void on_agps_status_update(UbuntuAgpsStatus* /*status*/, void* /*context*/)
85
VLOG(1) << __PRETTY_FUNCTION__;
88
static void on_gps_ni_notification(UbuntuGpsNiNotification* /*notification*/, void* /*context*/)
90
VLOG(1) << __PRETTY_FUNCTION__;
93
static void on_agps_ril_request_set_id(uint32_t /*flags*/, void* /*context*/)
95
VLOG(1) << __PRETTY_FUNCTION__;
98
static void on_agps_ril_request_ref_lock(uint32_t /*flags*/, void* /*context*/)
100
VLOG(1) << __PRETTY_FUNCTION__;
105
ubuntu_gps_start(gps_handle);
110
ubuntu_gps_stop(gps_handle);
113
UbuntuGpsParams gps_params;
114
UbuntuGps gps_handle;
117
std::string culg::Provider::class_name()
119
return "gps::Provider";
122
cul::Provider::Ptr culg::Provider::create_instance(const cul::ProviderFactory::Configuration&)
124
return cul::Provider::Ptr{new culg::Provider{}};
127
const cul::Provider::FeatureFlags& culg::Provider::default_feature_flags()
129
static const cul::Provider::FeatureFlags flags{"001"};
133
const cul::Provider::RequirementFlags& culg::Provider::default_requirement_flags()
135
static const cul::Provider::RequirementFlags flags{"1010"};
139
culg::Provider::Provider()
141
culg::Provider::default_feature_flags(),
142
culg::Provider::default_requirement_flags()),
145
d->gps_params.location_cb = culg::Provider::Private::on_location_update;
146
d->gps_params.status_cb = culg::Provider::Private::on_status_update;
147
d->gps_params.sv_status_cb = culg::Provider::Private::on_sv_status_update;
148
d->gps_params.nmea_cb = culg::Provider::Private::on_nmea_update;
149
d->gps_params.set_capabilities_cb = culg::Provider::Private::on_set_capabilities;
150
d->gps_params.request_utc_time_cb = culg::Provider::Private::on_request_utc_time;
151
d->gps_params.xtra_download_request_cb = nullptr;
153
d->gps_params.agps_status_cb = culg::Provider::Private::on_agps_status_update;
155
d->gps_params.gps_ni_notify_cb = culg::Provider::Private::on_gps_ni_notification;
157
d->gps_params.request_setid_cb = culg::Provider::Private::on_agps_ril_request_set_id;
158
d->gps_params.request_refloc_cb = culg::Provider::Private::on_agps_ril_request_ref_lock;
159
d->gps_params.context = this;
161
d->gps_handle = ubuntu_gps_new(std::addressof(d->gps_params));
164
culg::Provider::~Provider() noexcept
167
ubuntu_gps_delete(d->gps_handle);
170
bool culg::Provider::matches_criteria(const cul::Criteria&)
175
void culg::Provider::start_position_updates()
180
void culg::Provider::stop_position_updates()
185
void culg::Provider::start_velocity_updates()
190
void culg::Provider::stop_velocity_updates()
195
void culg::Provider::start_heading_updates()
200
void culg::Provider::stop_heading_updates()