Kallisto Linux API
Library for interacting with Kallisto devices
sensor_impl.hpp
Go to the documentation of this file.
1 
42 #ifndef SENSOR_IMPL_HPP
43 #define SENSOR_IMPL_HPP
44 
45 #include <string>
46 #include <list>
47 #include <map>
48 #include <memory>
49 #include <chrono>
50 #include <mutex>
51 
52 #include "../../../util/error/kallisto_error.hpp"
53 #include "sensor.hpp"
55 #include "../../../util/executor/executor.hpp"
56 #include "../../../bluetooth/device/bluetooth_dispatcher.hpp"
57 #include "../synchronization/time_synchronizer.hpp"
58 
59 namespace kallisto {
60 namespace hardware {
61 
66 typedef std::function<void(SensorEvent& event)> InternalSensorEventListener;
67 
71 class SensorImpl : public Sensor {
72 private:
74  util::Executor& m_event_dispatcher; //Executor used to dispatch sensor events to clients
76  std::list<SensorEventListener*> m_listeners; //Holds the sensor listeners.
78  std::mutex m_listener_list_mutex; //Used for concurrent access to the listener list.
80  std::map<std::string, const void*> m_parameters;
84  void handleSensorEvent(SensorEvent& event);
85 
86 protected:
88  bool m_link_loss = false; //Signals if this sensor is in link loss.
90  bluetooth::BluetoothDispatcher& m_bluetooth_dispatcher; //Interface to dispatch BLE operations
92  TimeSynchronizer* m_sensor_synchronizer; //Used to sync sensor timestamps
93 
103  virtual error::KallistoDetailedResult start(std::map<std::string, const void*> parameters, InternalSensorEventListener internal_listener) = 0;
104 
113  virtual error::KallistoDetailedResult update(std::map<std::string, const void*> parameters) = 0;
114 
119  virtual std::map<std::string, const void*> getParameters() = 0;
120 
127  virtual error::KallistoDetailedResult stop(bool link_loss) = 0;
128 
129 
133  SensorImpl(std::string name, std::string address, std::string vendor, unsigned int version, SensorType type, std::string string_type,
134  ReportingMode reporting_mode, unsigned int identifier, float max_range, float resolution, float power, std::chrono::microseconds min_delay,
135  std::chrono::microseconds max_delay, util::Executor& event_dispatcher, bluetooth::BluetoothDispatcher& bluetooth_dispatcher, TimeSynchronizer* sensor_synchronizer);
136 
137 public:
141  virtual ~SensorImpl();
142 
146  SensorImpl(SensorImpl const&) = delete;
147  SensorImpl(SensorImpl&&) = delete;
148  void operator=(SensorImpl const&) = delete;
149  void operator=(SensorImpl &&) = delete;
150 
166  error::KallistoDetailedResult registerListener(std::map<std::string, const void*> parameters, SensorEventListener& listener);
167 
173  error::KallistoDetailedResult unregisterListener(SensorEventListener& listener);
174 
180  bool getEnabled();
181 
187  void onLinkLoss();
188 
197  error::KallistoDetailedResult onLinkRecovered();
198 
202  static unsigned int generateHandle();
203 
204  /***************************************************************************************
205  * Parameter keys
206  ***************************************************************************************/
210  static const std::string& KEY_DELAY();
211 
212  /***************************************************************************************
213  * Helper functions
214  ***************************************************************************************/
221  static unsigned char getTypeFromManufacturerData(unsigned char byte);
222 
229  static unsigned char getIdFromManufacturerData(unsigned char byte);
230 
231 };
232 
233 } /* namespace hardware */
234 } /* namespace kallisto */
235 
236 #endif // SENSOR_IMPL_HPP
error::KallistoDetailedResult registerListener(std::map< std::string, const void *> parameters, SensorEventListener &listener)
Definition: bluetooth_adapter.hpp:52
bool m_link_loss
Definition: sensor_impl.hpp:87
static unsigned char getTypeFromManufacturerData(unsigned char byte)
TimeSynchronizer * m_sensor_synchronizer
Definition: sensor_impl.hpp:91
SensorType
Definition: sensor.hpp:60
virtual error::KallistoDetailedResult start(std::map< std::string, const void *> parameters, InternalSensorEventListener internal_listener)=0
virtual error::KallistoDetailedResult update(std::map< std::string, const void *> parameters)=0
error::KallistoDetailedResult unregisterListener(SensorEventListener &listener)
static unsigned char getIdFromManufacturerData(unsigned char byte)
virtual std::map< std::string, const void * > getParameters()=0
static unsigned int generateHandle()
static const std::string & KEY_DELAY()
virtual error::KallistoDetailedResult stop(bool link_loss)=0
bluetooth::BluetoothDispatcher & m_bluetooth_dispatcher
Definition: sensor_impl.hpp:89
error::KallistoDetailedResult onLinkRecovered()
SensorImpl(std::string name, std::string address, std::string vendor, unsigned int version, SensorType type, std::string string_type, ReportingMode reporting_mode, unsigned int identifier, float max_range, float resolution, float power, std::chrono::microseconds min_delay, std::chrono::microseconds max_delay, util::Executor &event_dispatcher, bluetooth::BluetoothDispatcher &bluetooth_dispatcher, TimeSynchronizer *sensor_synchronizer)
std::function< void(SensorEvent &event)> InternalSensorEventListener
Definition: sensor_impl.hpp:65
ReportingMode
Definition: sensor.hpp:126