22 #include "webview-ptzcam-thread.h" 23 #include "webview-ptzcam-processor.h" 25 #include <webview/url_manager.h> 26 #include <webview/nav_manager.h> 27 #include <webview/request_manager.h> 28 #include <utils/time/time.h> 29 #include <utils/time/wait.h> 31 #include <interfaces/PanTiltInterface.h> 32 #include <interfaces/SwitchInterface.h> 33 #include <interfaces/CameraControlInterface.h> 37 #define PTZCAM_URL_PREFIX "/ptzcam" 46 :
Thread(
"WebviewPtzCamThread",
Thread::OPMODE_CONTINUOUS)
69 float pan_increment =
config->
get_float(
"/webview/ptzcam/pan-increment");
70 float tilt_increment =
config->
get_float(
"/webview/ptzcam/tilt-increment");
71 unsigned int zoom_increment =
config->
get_uint(
"/webview/ptzcam/zoom-increment");
72 float post_powerup_time =
config->
get_float(
"/webview/ptzcam/post-power-up-time");
74 std::string nav_entry =
"PTZ Cam";
79 float loop_interval =
config->
get_float(
"/webview/ptzcam/loop-interval");
80 long int loop_time = (
long int)roundf(fabs(loop_interval) * 1000000.);
82 cfg_inactivity_timeout_ = fabs(
config->
get_float(
"/webview/ptzcam/inactivity-timeout"));
83 cfg_park_pan_tolerance_ = fabs(
config->
get_float(
"/webview/ptzcam/park/pan-tolerance"));
84 cfg_park_pan_pos_ = fabs(
config->
get_float(
"/webview/ptzcam/park/pan"));
85 cfg_park_tilt_tolerance_ = fabs(
config->
get_float(
"/webview/ptzcam/park/tilt-tolerance"));
86 cfg_park_tilt_pos_ = fabs(
config->
get_float(
"/webview/ptzcam/park/tilt"));
88 std::map<std::string, std::tuple<std::string, float, float, unsigned int>> presets;
89 std::string prefix =
"/webview/ptzcam/presets/";
90 #if __cplusplus >= 201103L 91 std::unique_ptr<Configuration::ValueIterator> i(
config->
search(prefix.c_str()));
93 std::auto_ptr<Configuration::ValueIterator> i(
config->
search(prefix.c_str()));
96 std::string cfg_name = std::string(i->
path()).substr(prefix.length());
97 cfg_name = cfg_name.substr(0, cfg_name.find(
"/"));
99 if (presets.find(cfg_name) == presets.end()) {
100 std::string cfg_prefix = prefix + cfg_name +
"/";
105 unsigned int zoom =
config->
get_uint((cfg_prefix +
"zoom").c_str());
106 presets[cfg_name] = std::make_tuple(name, pan, tilt, zoom);
114 pantilt_id, camctrl_id, power_id, camera_id,
115 pan_increment, tilt_increment,
116 zoom_increment, post_powerup_time,
126 bool ceiling_mount =
false;
128 ceiling_mount =
config->
get_bool(
"/webview/ptzcam/ceiling-mount");
169 Time last_completion =
172 if (now - &last_completion >= cfg_inactivity_timeout_) {
180 if (fabs(cfg_park_pan_pos_ - ptu_if_->
pan()) >= cfg_park_pan_tolerance_ ||
181 fabs(cfg_park_tilt_pos_ - ptu_if_->
tilt()) >= cfg_park_tilt_tolerance_)
WebNavManager * webview_nav_manager
Webview navigation manager.
void wait()
Wait until minimum loop time has been reached.
unsigned int num_active_requests() const
Get number of currently active requests.
virtual void log_info(const char *component, const char *format,...)=0
Log informational message.
Pan/tilt/zoom camera request processor.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
A class for handling time.
virtual bool next()=0
Check if there is another element and advance to this if possible.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
CameraControlInterface Fawkes BlackBoard Interface.
float tilt() const
Get tilt value.
Logger * logger
This is the Logger member used to access the logger.
virtual ~WebviewPtzCamThread()
Destructor.
Clock * clock
By means of this member access to the clock is given.
WebRequestManager * webview_request_manager
Webview request manager.
SwitchInterface Fawkes BlackBoard Interface.
virtual void finalize()
Finalize the thread.
Base class for exceptions in Fawkes.
void read()
Read from BlackBoard into local copy.
WebUrlManager * webview_url_manager
Webview request processor manager.
void unregister_baseurl(const char *url_prefix)
Remove a request processor.
WebviewPtzCamThread()
Constructor.
bool has_writer() const
Check if there is a writer for the interface.
DisableSwitchMessage Fawkes BlackBoard Interface Message.
const char * name() const
Get name of thread.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual void init()
Initialize the thread.
virtual const char * path() const =0
Path of value.
bool is_enabled() const
Get enabled value.
GotoMessage Fawkes BlackBoard Interface Message.
float pan() const
Get pan value.
void add_nav_entry(std::string baseurl, std::string name)
Add a navigation entry.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
void mark_start()
Mark start of loop.
Time last_request_completion_time() const
Get time when last request was completed.
SetMirrorMessage Fawkes BlackBoard Interface Message.
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
PanTiltInterface Fawkes BlackBoard Interface.
void remove_nav_entry(std::string baseurl)
Remove a navigation entry.
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
Configuration * config
This is the Configuration member used to access the configuration.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
virtual void loop()
Code to execute in the thread.
void register_baseurl(const char *url_prefix, WebRequestProcessor *processor)
Add a request processor.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual void close(Interface *interface)=0
Close interface.