libcyberradio 22.01.24
RadioComponent.cpp
1/***************************************************************************
2 * \file RadioComponent.cpp
3 * \brief Defines the basic component interface for an NDR-class radio.
4 * \author DA
5 * \author NH
6 * \author MN
7 * \copyright (c) 2017 CyberRadio Solutions, Inc. All rights reserved.
8 *
9 ***************************************************************************/
10
11#include "LibCyberRadio/Driver/RadioHandler.h"
12#include "LibCyberRadio/Driver/RadioComponent.h"
13
14
15namespace LibCyberRadio
16{
17 namespace Driver
18 {
19
20 RadioComponent::RadioComponent(const std::string& name,
21 int index,
22 RadioHandler* parent,
23 bool debug) :
24 Configurable(name, debug),
25 _index(index),
26 _parent(parent),
27 _enabled(false)
28 {
30 }
31
35
37 Configurable(other),
38 _index(other._index),
39 _parent(other._parent),
40 _enabled(other._enabled)
41 {
42 }
43
45 {
47 if ( this != &other )
48 {
49 _index = other._index;
50 _parent = other._parent;
51 _enabled = other._enabled;
52 }
53 return *this;
54 }
55
57 {
58 return _index;
59 }
60
62 {
63 _index = index;
64 }
65
67 {
68 return _parent;
69 }
70
72 {
73 _parent = parent;
74 }
75
77 {
78 return enable(false);
79 }
80
81 bool RadioComponent::enable(bool enabled)
82 {
83 _enabled = enabled;
85 return true;
86 }
87
89 {
90 return _enabled;
91 }
92
94 {
95 //this->debug("[RadioComponent::setConfiguration] Called\n");
96 // Call the base-class version to modify the configuration dictionary
97 bool ret = Configurable::setConfiguration(cfg);
98 // Use the keys provided in the *incoming* dictionary to determine
99 // what needs to be changed.
100 if ( cfg.hasKey("enable") && _config.hasKey("enable") )
101 {
102 ret = enable( _config["enable"].asBool() );
103 }
104 //this->debug("[RadioComponent::setConfiguration] Returning\n");
105 return ret;
106 }
107
109 {
110 //this->debug("[RadioComponent::queryConfiguration] Called\n");
111 // Replace this with hardware queries to determine values
112 //this->debug("[RadioComponent::queryConfiguration] Returning\n");
113 }
114
116 {
117 //this->debug("[RadioComponent::initConfigurationDict] Called\n");
118 _config["enable"] = _enabled;
119 //this->debug("[RadioComponent::initConfigurationDict] Returning\n");
120 }
121
123 {
124 //this->debug("[RadioComponent::updateConfigurationDict] Called\n");
125 if ( _config.hasKey("enable") )
126 this->setConfigurationValueToBool("enable", _enabled);
127 //this->debug("[RadioComponent::updateConfigurationDict] Returning\n");
128 }
129
130 } // namespace Driver
131
132} // namespace LibCyberRadio
133
virtual int debug(const char *format,...)
Outputs debug information.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual Configurable & operator=(const Configurable &other)
Assignment operator for Configurable objects.
Configurable(const std::string &name="<unknown>", bool debug=false)
Constructs a Configurable object.
virtual bool setConfigurationValueToBool(const std::string &key, const bool value)
Sets a named configuration value to a Boolean.
A configuration dictionary.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual int getIndex() const
Gets the index number of the component.
virtual void setIndex(int index)
Sets the index number of the component.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool isEnabled() const
Gets whether or not the component is enabled.
virtual ~RadioComponent()
Destroys a RadioComponent object.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual RadioComponent & operator=(const RadioComponent &other)
Assignment operator for RadioComponent objects.
RadioComponent(const std::string &name="<unknown>", int index=0, RadioHandler *parent=NULL, bool debug=false)
Constructs a RadioComponent object.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual RadioHandler * getParent() const
Gets the "parent" radio handler for this component.
virtual bool disable()
Disables this component.
virtual void setParent(RadioHandler *parent)
Sets the "parent" radio handler for this component.
Generic radio handler class.
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
Definition App.h:24