#pragma once #include "Tactility/Mutex.h" #include "Tactility/PubSub.h" #include "Tactility/hal/gps/GpsDevice.h" #include "Tactility/service/Service.h" #include "Tactility/service/gps/GpsState.h" namespace tt::service::gps { class GpsService final : public Service { private: struct GpsDeviceRecord { std::shared_ptr device = nullptr; hal::gps::GpsDevice::GgaSubscriptionId satelliteSubscriptionId = -1; hal::gps::GpsDevice::RmcSubscriptionId rmcSubscriptionId = -1; }; minmea_sentence_rmc rmcRecord; TickType_t rmcTime = 0; Mutex mutex = Mutex(Mutex::Type::Recursive); Mutex stateMutex; std::vector deviceRecords; std::shared_ptr statePubSub = std::make_shared(); State state = State::Off; bool startGpsDevice(GpsDeviceRecord& deviceRecord); static bool stopGpsDevice(GpsDeviceRecord& deviceRecord); GpsDeviceRecord* _Nullable findGpsRecord(const std::shared_ptr& record); void onGgaSentence(hal::Device::Id deviceId, const minmea_sentence_gga& gga); void onRmcSentence(hal::Device::Id deviceId, const minmea_sentence_rmc& rmc); void setState(State newState); public: void onStart(tt::service::ServiceContext &serviceContext) final; void onStop(tt::service::ServiceContext &serviceContext) final; void addGpsDevice(const std::shared_ptr& device); void removeGpsDevice(const std::shared_ptr& device); bool startReceiving(); void stopReceiving(); State getState() const; bool hasCoordinates() const; bool getCoordinates(minmea_sentence_rmc& rmc) const; /** @return GPS service pubsub that broadcasts State* objects */ std::shared_ptr getStatePubsub() const { return statePubSub; } }; } // tt::hal::gps