11 #include "LibCyberRadio/Driver/RadioHandler.h" 12 #include "LibCyberRadio/Driver/NbddcGroupComponent.h" 13 #include "LibCyberRadio/Common/Pythonesque.h" 14 #include <boost/lexical_cast.hpp> 24 const std::string& name,
29 int groupMemberIndexBase) :
31 _numGroupMembers(numGroupMembers),
32 _groupMemberIndexBase(groupMemberIndexBase)
43 _numGroupMembers(other._numGroupMembers),
44 _groupMemberIndexBase(other._groupMemberIndexBase)
53 _numGroupMembers = other._numGroupMembers;
54 _groupMemberIndexBase = other._groupMemberIndexBase;
61 bool adjEnabled = enabled;
63 if ( _config.
hasKey(
"enable") )
68 _enabled = adjEnabled;
77 this->
debug(
"[NbddcGroupComponent::setConfiguration] Called\n");
82 bool adjEnabled = _enabled;
84 bool enableCmdNeedsExecuting =
false;
85 bool memberCmdNeedsExecuting =
false;
89 enableCmdNeedsExecuting =
true;
91 if ( cfg.
hasKey(
"members") && _config.
hasKey(
"members") )
95 for( BasicStringList::const_iterator it = vec.begin(); it != vec.end(); it++ )
99 memberCmdNeedsExecuting =
true;
101 if ( memberCmdNeedsExecuting )
105 if ( enableCmdNeedsExecuting )
111 _enabled = adjEnabled;
112 _groupMembers = adjMembers;
115 this->
debug(
"[NbddcGroupComponent::setConfiguration] Returning\n");
121 this->
debug(
"[NbddcGroupComponent::queryConfiguration] Called\n");
122 if ( _config.
hasKey(
"enable") )
126 if ( _config.
hasKey(
"members") )
131 this->
debug(
"[NbddcGroupComponent::queryConfiguration] Returning\n");
136 return _groupMembers;
141 this->
debug(
"[NbddcGroupComponent::setMembers] Called\n");
143 if ( _config.
hasKey(
"members") )
149 _groupMembers = groupMembers;
153 this->
debug(
"[NbddcGroupComponent::setMembers] Returning %s\n",
160 this->
debug(
"[NbddcGroupComponent::addMember] Called\n");
162 if ( _config.
hasKey(
"members") )
164 bool isMember =
true;
168 if ( std::count(_groupMembers.begin(), _groupMembers.end(), member) == 0 )
170 _groupMembers.push_back(member);
171 std::sort(_groupMembers.begin(), _groupMembers.end());
176 this->
debug(
"[NbddcGroupComponent::addMember] Returning %s\n",
183 this->
debug(
"[NbddcGroupComponent::removeMember] Called\n");
185 if ( _config.
hasKey(
"members") )
187 bool isMember =
false;
191 if ( std::count(_groupMembers.begin(), _groupMembers.end(), member) == 0 )
193 _groupMembers.push_back(member);
194 std::sort(_groupMembers.begin(), _groupMembers.end());
199 this->
debug(
"[NbddcGroupComponent::removeMember] Returning %s\n",
210 _config[
"members"] =
"";
215 this->
debug(
"[NbddcGroupComponent::updateConfigurationDict] Called\n");
217 if ( _config.
hasKey(
"members") )
219 this->
debug(
"[NbddcGroupComponent::updateConfigurationDict] Returning\n");
225 for (BasicIntList::const_iterator it = _groupMembers.begin();
226 it != _groupMembers.end(); it++)
228 vec.push_back( std::to_string(*it) );
238 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupEnableQuery] Called\n");
240 if ( (_parent != NULL) && (_parent->
isConnected()) )
242 std::ostringstream oss;
243 oss <<
"NBGE? " << index <<
"\n";
252 enabled = (boost::lexical_cast<
int>(vec[1]) == 1);
256 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupEnableQuery] Returning %s\n",
265 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupEnableCommand] Called\n");
267 if ( (_parent != NULL) && (_parent->
isConnected()) )
269 std::ostringstream oss;
270 oss <<
"NBGE " << index
271 <<
", " << (enabled ? 1 : 0)
279 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupEnableCommand] Returning %s\n",
288 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupQuery] Called\n");
291 groupMembers.clear();
292 for (
int member = _groupMemberIndexBase;
293 member < (_groupMemberIndexBase + _numGroupMembers); member++)
299 groupMembers.push_back(member);
304 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupQuery] Returning %s\n",
313 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupCommand] Called\n");
316 for (
int member = _groupMemberIndexBase;
317 member < (_groupMemberIndexBase + _numGroupMembers); member++)
319 isMember = ( std::count(groupMembers.begin(), groupMembers.end(), member) > 0 );
324 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupCommand] Returning %s\n",
332 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupMemberQuery] Called\n");
334 if ( (_parent != NULL) && (_parent->
isConnected()) )
336 std::ostringstream oss;
339 oss <<
"NBG? " << index
340 <<
", " << groupMember
351 isMember = ( boost::lexical_cast<
int>(vec[2]) == 1 );
355 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupMemberQuery] Returning %s\n",
364 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupMemberCommand] Called\n");
366 if ( (_parent != NULL) && (_parent->
isConnected()) )
368 std::ostringstream oss;
369 oss <<
"NBG " << index
370 <<
", " << groupMember
371 <<
", " << ( isMember ? 1 : 0 )
379 this->
debug(
"[NbddcGroupComponent::executeNbddcGroupMemberCommand] Returning %s\n",
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool getConfigurationValueAsBool(const std::string &key) const
Gets a named configuration value as a Boolean.
virtual bool executeNbddcGroupMemberQuery(int index, int groupMember, bool &isMember)
Executes the NBDDC group member query command.
virtual ConfigString getConfigurationValue(const std::string &key) const
Gets a named configuration value as a string.
virtual bool executeNbddcGroupEnableCommand(int index, bool &enabled)
Executes the NBDDC group enable command.
static std::string Strip(const std::string &str, const std::string &chars=" \\\)
Strips both leading and trailing whitespace from the given string.
Base hardware component class.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool executeNbddcGroupMemberCommand(int index, int groupMember, bool &isMember)
Executes the NBDDC group member set command.
Base NBDDC group component class.
virtual bool isConnected() const
Gets whether or not the handler is connected.
virtual RadioComponent & operator=(const RadioComponent &other)
Assignment operator for RadioComponent objects.
static std::string Replace(const std::string &str, const std::string &oldstr, const std::string &newstr, int count=INT_MAX)
Replaces occurrences of one substring with another within the given string.
NbddcGroupComponent(const std::string &name="NBG", int index=1, RadioHandler *parent=NULL, bool debug=false, int numGroupMembers=0, int groupMemberIndexBase=1)
Constructs a NbddcGroupComponent object.
virtual bool enable(bool enabled=true)
Enables this component.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool executeNbddcGroupCommand(int index, BasicIntList &groupMembers)
Executes the NBDDC group configuration set command.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual bool addMember(int member)
Adds a NBDDC to the list of group members.
static BasicStringList Split(const std::string &str, const std::string &sep, int maxsplit=INT_MAX)
Splits the given string into a list of string tokens.
virtual bool executeNbddcGroupQuery(int index, BasicIntList &groupMembers)
Executes the NBDDC group configuration query command.
virtual bool setMembers(const BasicIntList &groupMembers)
Sets the list of group members.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
Generic radio handler class.
virtual int debug(const char *format,...)
Outputs debug information.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
virtual std::string getMembersString()
Gets the string representation of the member list.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
Defines functionality for LibCyberRadio applications.
A configuration dictionary.
virtual std::string getLastCommandErrorInfo() const
Gets the error message from the last command attempted.
virtual BasicIntList getMembers() const
Gets the list of group members.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
virtual NbddcGroupComponent & operator=(const NbddcGroupComponent &other)
Assignment operator for NbddcGroupComponent objects.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.
BASIC_LIST_CONTAINER< int > BasicIntList
Type representing a list of integers.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
static std::string Join(const BasicStringList &vec, const std::string &sep)
Joins a list of string tokens, concatenating them into a single string.
virtual bool executeNbddcGroupEnableQuery(int index, bool &enabled)
Executes the NBDDC group enable query command.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
virtual ~NbddcGroupComponent()
Destroys a NbddcGroupComponent object.
virtual bool removeMember(int member)
Removes a NBDDC from the list of group members.