Fawkes API  Fawkes Development Version
SwitchInterface.h
1 
2 /***************************************************************************
3  * SwitchInterface.h - Fawkes BlackBoard Interface - SwitchInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2008 Tim Niemueller
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __INTERFACES_SWITCHINTERFACE_H_
25 #define __INTERFACES_SWITCHINTERFACE_H_
26 
27 #include <interface/interface.h>
28 #include <interface/message.h>
29 #include <interface/field_iterator.h>
30 
31 namespace fawkes {
32 
33 class SwitchInterface : public Interface
34 {
35  /// @cond INTERNALS
36  INTERFACE_MGMT_FRIENDS(SwitchInterface)
37  /// @endcond
38  public:
39  /* constants */
40 
41  private:
42  /** Internal data storage, do NOT modify! */
43  typedef struct __attribute__((packed)) {
44  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
45  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
46  bool enabled; /**<
47  True if the switch is currently enabled.
48  */
49  float value; /**<
50  If switches support multiple states these can be indicated with
51  this value. For example for a switch that notes the intensity it
52  could be a value in the valid range.
53  */
54  float history; /**<
55  This value records the number of seconds a switch has been
56  enabled continuously -- or not. The time is recorded in
57  seconds. A positive value indicates time the switch was turned
58  on, a negative value indicates the time (when converted to the
59  absolute value) the button has not been pressed. Zero means
60  "just initialized".
61  */
62  uint32_t short_activations; /**<
63  Number of consecutive short clicks (turned on). Can be used to recognize
64  patterns of clicks. This is an optional field.
65  */
66  uint32_t long_activations; /**<
67  Number of consecutive short clicks (turned on). Can be used to recognize
68  patterns of clicks. This is an optional field.
69  */
70  uint32_t activation_count; /**<
71  Number that is to be incremented whenever a short or long activation
72  happened. Can be used to decide if a change in status happened.
73  */
74  } SwitchInterface_data_t;
75 
76  SwitchInterface_data_t *data;
77 
78  public:
79  /* messages */
80  class SetMessage : public Message
81  {
82  private:
83  /** Internal data storage, do NOT modify! */
84  typedef struct __attribute__((packed)) {
85  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
86  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
87  bool enabled; /**<
88  True if the switch is currently enabled.
89  */
90  float value; /**<
91  If switches support multiple states these can be indicated with
92  this value. For example for a switch that notes the intensity it
93  could be a value in the valid range.
94  */
95  } SetMessage_data_t;
96 
97  SetMessage_data_t *data;
98 
99  public:
100  SetMessage(const bool ini_enabled, const float ini_value);
101  SetMessage();
102  ~SetMessage();
103 
104  SetMessage(const SetMessage *m);
105  /* Methods */
106  bool is_enabled() const;
107  void set_enabled(const bool new_enabled);
108  size_t maxlenof_enabled() const;
109  float value() const;
110  void set_value(const float new_value);
111  size_t maxlenof_value() const;
112  virtual Message * clone() const;
113  };
114 
116  {
117  private:
118  /** Internal data storage, do NOT modify! */
119  typedef struct __attribute__((packed)) {
120  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
121  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
122  } EnableSwitchMessage_data_t;
123 
124  EnableSwitchMessage_data_t *data;
125 
126  public:
129 
131  /* Methods */
132  virtual Message * clone() const;
133  };
134 
136  {
137  private:
138  /** Internal data storage, do NOT modify! */
139  typedef struct __attribute__((packed)) {
140  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
141  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
142  } DisableSwitchMessage_data_t;
143 
144  DisableSwitchMessage_data_t *data;
145 
146  public:
149 
151  /* Methods */
152  virtual Message * clone() const;
153  };
154 
156  {
157  private:
158  /** Internal data storage, do NOT modify! */
159  typedef struct __attribute__((packed)) {
160  int64_t timestamp_sec; /**< Interface Unix timestamp, seconds */
161  int64_t timestamp_usec; /**< Interface Unix timestamp, micro-seconds */
162  float duration; /**< Duration in seconds for which
163  the switch should be enabled. */
164  float value; /**<
165  If switches support multiple states these can be indicated with
166  this value. For example for a switch that notes the intensity it
167  could be a value in the valid range.
168  */
169  } EnableDurationMessage_data_t;
170 
171  EnableDurationMessage_data_t *data;
172 
173  public:
174  EnableDurationMessage(const float ini_duration, const float ini_value);
177 
179  /* Methods */
180  float duration() const;
181  void set_duration(const float new_duration);
182  size_t maxlenof_duration() const;
183  float value() const;
184  void set_value(const float new_value);
185  size_t maxlenof_value() const;
186  virtual Message * clone() const;
187  };
188 
189  virtual bool message_valid(const Message *message) const;
190  private:
191  SwitchInterface();
192  ~SwitchInterface();
193 
194  public:
195  /* Methods */
196  bool is_enabled() const;
197  void set_enabled(const bool new_enabled);
198  size_t maxlenof_enabled() const;
199  float value() const;
200  void set_value(const float new_value);
201  size_t maxlenof_value() const;
202  float history() const;
203  void set_history(const float new_history);
204  size_t maxlenof_history() const;
205  uint32_t short_activations() const;
206  void set_short_activations(const uint32_t new_short_activations);
207  size_t maxlenof_short_activations() const;
208  uint32_t long_activations() const;
209  void set_long_activations(const uint32_t new_long_activations);
210  size_t maxlenof_long_activations() const;
211  uint32_t activation_count() const;
212  void set_activation_count(const uint32_t new_activation_count);
213  size_t maxlenof_activation_count() const;
214  virtual Message * create_message(const char *type) const;
215 
216  virtual void copy_values(const Interface *other);
217  virtual const char * enum_tostring(const char *enumtype, int val) const;
218 
219 };
220 
221 } // end namespace fawkes
222 
223 #endif
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
SetMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_long_activations() const
Get maximum length of long_activations value.
Fawkes library namespace.
size_t maxlenof_history() const
Get maximum length of history value.
uint32_t short_activations() const
Get short_activations value.
uint32_t activation_count() const
Get activation_count value.
void set_history(const float new_history)
Set history value.
uint32_t long_activations() const
Get long_activations value.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
void set_short_activations(const uint32_t new_short_activations)
Set short_activations value.
float value() const
Get value value.
virtual Message * create_message(const char *type) const
Create message based on type name.
SwitchInterface Fawkes BlackBoard Interface.
const char * type() const
Get type of interface.
Definition: interface.cpp:651
void set_activation_count(const uint32_t new_activation_count)
Set activation_count value.
void set_enabled(const bool new_enabled)
Set enabled value.
DisableSwitchMessage Fawkes BlackBoard Interface Message.
float history() const
Get history value.
bool is_enabled() const
Get enabled value.
size_t maxlenof_value() const
Get maximum length of value value.
void set_long_activations(const uint32_t new_long_activations)
Set long_activations value.
size_t maxlenof_activation_count() const
Get maximum length of activation_count value.
virtual void copy_values(const Interface *other)
Copy values from other interface.
EnableSwitchMessage Fawkes BlackBoard Interface Message.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
void set_value(const float new_value)
Set value value.
EnableDurationMessage Fawkes BlackBoard Interface Message.
virtual const char * enum_tostring(const char *enumtype, int val) const
Convert arbitrary enum value to string.
size_t maxlenof_short_activations() const
Get maximum length of short_activations value.
size_t maxlenof_enabled() const
Get maximum length of enabled value.