|
| 1 | +#ifndef HIGH_LEVEL_SERVICE_HPP |
| 2 | +#define HIGH_LEVEL_SERVICE_HPP |
| 3 | + |
| 4 | +#include <etl/string.h> |
| 5 | + |
| 6 | +#include <HighLevelServiceBase.hpp> |
| 7 | +#include <xbot-service/Lock.hpp> |
| 8 | + |
| 9 | +using namespace xbot::service; |
| 10 | + |
| 11 | +class HighLevelService : public HighLevelServiceBase { |
| 12 | + private: |
| 13 | + THD_WORKING_AREA(wa, 1024){}; |
| 14 | + |
| 15 | + public: |
| 16 | + explicit HighLevelService(uint16_t service_id) : HighLevelServiceBase(service_id, wa, sizeof(wa)) { |
| 17 | + } |
| 18 | + |
| 19 | + HighLevelStatus GetStateId() { |
| 20 | + xbot::service::Lock lk{&mtx_}; |
| 21 | + return state_id_; |
| 22 | + } |
| 23 | + |
| 24 | + etl::string<100> GetStateName() { |
| 25 | + xbot::service::Lock lk{&mtx_}; |
| 26 | + return state_name_; |
| 27 | + } |
| 28 | + |
| 29 | + etl::string<100> GetSubStateName() { |
| 30 | + xbot::service::Lock lk{&mtx_}; |
| 31 | + return sub_state_name_; |
| 32 | + } |
| 33 | + |
| 34 | + float GetGpsQuality() { |
| 35 | + xbot::service::Lock lk{&mtx_}; |
| 36 | + return gps_quality_; |
| 37 | + } |
| 38 | + |
| 39 | + int16_t GetCurrentArea() { |
| 40 | + xbot::service::Lock lk{&mtx_}; |
| 41 | + return current_area_; |
| 42 | + } |
| 43 | + |
| 44 | + int16_t GetCurrentPath() { |
| 45 | + xbot::service::Lock lk{&mtx_}; |
| 46 | + return current_path_; |
| 47 | + } |
| 48 | + |
| 49 | + int16_t GetCurrentPathIndex() { |
| 50 | + xbot::service::Lock lk{&mtx_}; |
| 51 | + return current_path_index_; |
| 52 | + } |
| 53 | + |
| 54 | + void SetCallback(const etl::delegate<void()>& callback) { |
| 55 | + xbot::service::Lock lk{&mtx_}; |
| 56 | + state_changed_callback_ = callback; |
| 57 | + } |
| 58 | + |
| 59 | + private: |
| 60 | + MUTEX_DECL(mtx_); |
| 61 | + |
| 62 | + HighLevelStatus state_id_ = HighLevelStatus::UNKNOWN; |
| 63 | + etl::string<100> state_name_{}; |
| 64 | + etl::string<100> sub_state_name_{}; |
| 65 | + float gps_quality_ = 0; |
| 66 | + int16_t current_area_ = 0; |
| 67 | + int16_t current_path_ = 0; |
| 68 | + int16_t current_path_index_ = 0; |
| 69 | + |
| 70 | + etl::delegate<void()> state_changed_callback_{}; |
| 71 | + |
| 72 | + void OnStateIDChanged(const HighLevelStatus& new_value) override; |
| 73 | + void OnStateNameChanged(const char* new_value, uint32_t length) override; |
| 74 | + void OnSubStateNameChanged(const char* new_value, uint32_t length) override; |
| 75 | + void OnGpsQualityChanged(const float& new_value) override; |
| 76 | + void OnCurrentAreaChanged(const int16_t& new_value) override; |
| 77 | + void OnCurrentPathChanged(const int16_t& new_value) override; |
| 78 | + void OnCurrentPathIndexChanged(const int16_t& new_value) override; |
| 79 | + void OnTransactionEnd() override; |
| 80 | +}; |
| 81 | + |
| 82 | +#endif // HIGH_LEVEL_SERVICE_HPP |
0 commit comments