24 #include <interfaces/SwitchInterface.h>
26 #include <core/exceptions/software.h>
49 SwitchInterface::SwitchInterface() : Interface()
51 data_size =
sizeof(SwitchInterface_data_t);
52 data_ptr = malloc(data_size);
53 data = (SwitchInterface_data_t *)data_ptr;
54 data_ts = (interface_data_ts_t *)data_ptr;
55 memset(data_ptr, 0, data_size);
56 add_fieldinfo(IFT_BOOL,
"enabled", 1, &data->enabled);
57 add_fieldinfo(IFT_FLOAT,
"value", 1, &data->value);
58 add_fieldinfo(IFT_FLOAT,
"history", 1, &data->history);
59 add_fieldinfo(IFT_UINT32,
"short_activations", 1, &data->short_activations);
60 add_fieldinfo(IFT_UINT32,
"long_activations", 1, &data->long_activations);
61 add_fieldinfo(IFT_UINT32,
"activation_count", 1, &data->activation_count);
62 add_messageinfo(
"SetMessage");
63 add_messageinfo(
"EnableSwitchMessage");
64 add_messageinfo(
"DisableSwitchMessage");
65 add_messageinfo(
"EnableDurationMessage");
66 unsigned char tmp_hash[] = {0xa7, 0xa4, 0xc, 0x19, 0x66, 0xa4, 0x87, 0x6b, 0xa9, 0x32, 0x95, 0x40, 0xc7, 0x82, 0x75, 0x6d};
71 SwitchInterface::~SwitchInterface()
83 SwitchInterface::is_enabled()
const
93 SwitchInterface::maxlenof_enabled()
const
105 SwitchInterface::set_enabled(
const bool new_enabled)
107 data_changed |=
change_field(data->enabled, new_enabled);
119 SwitchInterface::value()
const
129 SwitchInterface::maxlenof_value()
const
143 SwitchInterface::set_value(
const float new_value)
160 SwitchInterface::history()
const
162 return data->history;
170 SwitchInterface::maxlenof_history()
const
187 SwitchInterface::set_history(
const float new_history)
189 data_changed |=
change_field(data->history, new_history);
200 SwitchInterface::short_activations()
const
202 return data->short_activations;
210 SwitchInterface::maxlenof_short_activations()
const
223 SwitchInterface::set_short_activations(
const uint32_t new_short_activations)
225 data_changed |=
change_field(data->short_activations, new_short_activations);
236 SwitchInterface::long_activations()
const
238 return data->long_activations;
246 SwitchInterface::maxlenof_long_activations()
const
259 SwitchInterface::set_long_activations(
const uint32_t new_long_activations)
261 data_changed |=
change_field(data->long_activations, new_long_activations);
272 SwitchInterface::activation_count()
const
274 return data->activation_count;
282 SwitchInterface::maxlenof_activation_count()
const
295 SwitchInterface::set_activation_count(
const uint32_t new_activation_count)
297 data_changed |=
change_field(data->activation_count, new_activation_count);
302 SwitchInterface::create_message(
const char *type)
const
304 if ( strncmp(
"SetMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
306 }
else if ( strncmp(
"EnableSwitchMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
308 }
else if ( strncmp(
"DisableSwitchMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
310 }
else if ( strncmp(
"EnableDurationMessage", type, INTERFACE_MESSAGE_TYPE_SIZE_ - 1) == 0 ) {
314 "message type for this interface type.", type);
328 type(), other->
type());
330 memcpy(data, oi->data,
sizeof(SwitchInterface_data_t));
334 SwitchInterface::enum_tostring(
const char *enumtype,
int val)
const
351 SwitchInterface::SetMessage::SetMessage(
const bool ini_enabled,
const float ini_value) :
Message(
"SetMessage")
356 data = (SetMessage_data_t *)
data_ptr;
358 data->enabled = ini_enabled;
359 data->value = ini_value;
369 data = (SetMessage_data_t *)
data_ptr;
389 data = (SetMessage_data_t *)
data_ptr;
403 return data->enabled;
486 data_size =
sizeof(EnableSwitchMessage_data_t);
489 data = (EnableSwitchMessage_data_t *)
data_ptr;
507 data = (EnableSwitchMessage_data_t *)
data_ptr;
532 data_size =
sizeof(DisableSwitchMessage_data_t);
535 data = (DisableSwitchMessage_data_t *)
data_ptr;
553 data = (DisableSwitchMessage_data_t *)
data_ptr;
581 data_size =
sizeof(EnableDurationMessage_data_t);
584 data = (EnableDurationMessage_data_t *)
data_ptr;
586 data->duration = ini_duration;
587 data->value = ini_value;
594 data_size =
sizeof(EnableDurationMessage_data_t);
597 data = (EnableDurationMessage_data_t *)
data_ptr;
617 data = (EnableDurationMessage_data_t *)
data_ptr;
630 return data->duration;
Base class for all Fawkes BlackBoard interfaces.
const char * type() const
Get type of interface.
void * data_ptr
Pointer to local memory storage.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
void * data_ptr
Pointer to memory that contains local data.
message_data_ts_t * data_ts
data timestamp aliasing pointer
unsigned int data_size
Size of memory needed to hold all data.
DisableSwitchMessage Fawkes BlackBoard Interface Message.
DisableSwitchMessage()
Constructor.
~DisableSwitchMessage()
Destructor.
virtual Message * clone() const
Clone this message.
EnableDurationMessage Fawkes BlackBoard Interface Message.
void set_duration(const float new_duration)
Set duration value.
void set_value(const float new_value)
Set value value.
size_t maxlenof_duration() const
Get maximum length of duration value.
float value() const
Get value value.
virtual Message * clone() const
Clone this message.
float duration() const
Get duration value.
EnableDurationMessage()
Constructor.
size_t maxlenof_value() const
Get maximum length of value value.
~EnableDurationMessage()
Destructor.
EnableSwitchMessage Fawkes BlackBoard Interface Message.
virtual Message * clone() const
Clone this message.
EnableSwitchMessage()
Constructor.
~EnableSwitchMessage()
Destructor.
SetMessage Fawkes BlackBoard Interface Message.
void set_enabled(const bool new_enabled)
Set enabled value.
float value() const
Get value value.
virtual Message * clone() const
Clone this message.
bool is_enabled() const
Get enabled value.
void set_value(const float new_value)
Set value value.
size_t maxlenof_enabled() const
Get maximum length of enabled value.
size_t maxlenof_value() const
Get maximum length of value value.
SwitchInterface Fawkes BlackBoard Interface.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Fawkes library namespace.
bool change_field(FieldT &field, const DataT &value)
Set a field and return whether it changed.
Timestamp data, must be present and first entries for each interface data structs!...