11 #include "LibCyberRadio/Driver/RadioHandler.h" 12 #include "LibCyberRadio/Driver/WbddcGroupComponent.h" 13 #include "LibCyberRadio/Common/Pythonesque.h" 14 #include <boost/lexical_cast.hpp> 25 const std::string& name,
30 int groupMemberIndexBase) :
32 _numGroupMembers(numGroupMembers),
33 _groupMemberIndexBase(groupMemberIndexBase)
44 _numGroupMembers(other._numGroupMembers),
45 _groupMemberIndexBase(other._groupMemberIndexBase)
54 _numGroupMembers = other._numGroupMembers;
55 _groupMemberIndexBase = other._groupMemberIndexBase;
62 bool adjEnabled = enabled;
64 if ( _config.
hasKey(
"enable") )
69 _enabled = adjEnabled;
78 this->
debug(
"[WbddcGroupComponent::setConfiguration] Called\n");
83 bool adjEnabled = _enabled;
85 bool enableCmdNeedsExecuting =
false;
86 bool memberCmdNeedsExecuting =
false;
90 enableCmdNeedsExecuting =
true;
92 if ( cfg.
hasKey(
"members") && _config.
hasKey(
"members") )
96 for( BasicStringList::const_iterator it = vec.begin(); it != vec.end(); it++ )
100 memberCmdNeedsExecuting =
true;
102 if ( memberCmdNeedsExecuting )
106 if ( enableCmdNeedsExecuting )
112 _enabled = adjEnabled;
113 _groupMembers = adjMembers;
116 this->
debug(
"[WbddcGroupComponent::setConfiguration] Returning\n");
122 this->
debug(
"[WbddcGroupComponent::queryConfiguration] Called\n");
123 if ( _config.
hasKey(
"enable") )
127 if ( _config.
hasKey(
"members") )
132 this->
debug(
"[WbddcGroupComponent::queryConfiguration] Returning\n");
137 return _groupMembers;
142 this->
debug(
"[WbddcGroupComponent::setMembers] Called\n");
144 if ( _config.
hasKey(
"members") )
150 _groupMembers = groupMembers;
154 this->
debug(
"[WbddcGroupComponent::setMembers] Returning %s\n",
161 this->
debug(
"[WbddcGroupComponent::addMember] Called\n");
163 if ( _config.
hasKey(
"members") )
165 bool isMember =
true;
169 if ( std::count(_groupMembers.begin(), _groupMembers.end(), member) == 0 )
171 _groupMembers.push_back(member);
172 std::sort(_groupMembers.begin(), _groupMembers.end());
177 this->
debug(
"[WbddcGroupComponent::addMember] Returning %s\n",
184 this->
debug(
"[WbddcGroupComponent::removeMember] Called\n");
186 if ( _config.
hasKey(
"members") )
188 bool isMember =
false;
192 BasicIntList::iterator it = std::find(_groupMembers.begin(), _groupMembers.end(),
194 if ( it != _groupMembers.end() )
196 _groupMembers.erase(it);
201 this->
debug(
"[WbddcGroupComponent::removeMember] Returning %s\n",
212 _config[
"members"] =
"";
217 this->
debug(
"[WbddcGroupComponent::updateConfigurationDict] Called\n");
219 if ( _config.
hasKey(
"members") )
221 this->
debug(
"[WbddcGroupComponent::updateConfigurationDict] Returning\n");
227 for (BasicIntList::const_iterator it = _groupMembers.begin();
228 it != _groupMembers.end(); it++)
230 vec.push_back( std::to_string(*it) );
240 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableQuery] Called\n");
242 if ( (_parent != NULL) && (_parent->
isConnected()) )
244 std::ostringstream oss;
245 oss <<
"WBGE? " << index <<
"\n";
254 enabled = (boost::lexical_cast<
int>(vec[1]) == 1);
258 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableQuery] Returning %s\n",
267 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableCommand] Called\n");
269 if ( (_parent != NULL) && (_parent->
isConnected()) )
271 std::ostringstream oss;
272 oss <<
"WBGE " << index
273 <<
", " << (enabled ? 1 : 0)
281 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableCommand] Returning %s\n",
290 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupQuery] Called\n");
293 groupMembers.clear();
294 for (
int member = _groupMemberIndexBase;
295 member < (_groupMemberIndexBase + _numGroupMembers); member++)
301 groupMembers.push_back(member);
306 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupQuery] Returning %s\n",
315 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupCommand] Called\n");
318 for (
int member = _groupMemberIndexBase;
319 member < (_groupMemberIndexBase + _numGroupMembers); member++)
321 isMember = ( std::count(groupMembers.begin(), groupMembers.end(), member) > 0 );
326 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupCommand] Returning %s\n",
334 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberQuery] Called\n");
336 if ( (_parent != NULL) && (_parent->
isConnected()) )
338 std::ostringstream oss;
341 oss <<
"WBG? " << index
342 <<
", " << groupMember
353 isMember = ( boost::lexical_cast<
int>(vec[2]) == 1 );
357 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberQuery] Returning %s\n",
366 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberCommand] Called\n");
368 if ( (_parent != NULL) && (_parent->
isConnected()) )
370 std::ostringstream oss;
371 oss <<
"WBG " << index
372 <<
", " << groupMember
373 <<
", " << ( isMember ? 1 : 0 )
381 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberCommand] 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 void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual bool removeMember(int member)
Removes a WBDDC from the list of group members.
virtual bool executeWbddcGroupEnableQuery(int index, bool &enabled)
Executes the WBDDC group enable query command.
virtual std::string getMembersString()
Gets the string representation of the member list.
virtual ConfigString getConfigurationValue(const std::string &key) const
Gets a named configuration value as a string.
virtual WbddcGroupComponent & operator=(const WbddcGroupComponent &other)
Assignment operator for WbddcGroupComponent objects.
static std::string Strip(const std::string &str, const std::string &chars=" \\\)
Strips both leading and trailing whitespace from the given string.
virtual BasicIntList getMembers() const
Gets the list of group members.
Base hardware component class.
virtual bool addMember(int member)
Adds a WBDDC to the list of group members.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
virtual bool executeWbddcGroupCommand(int index, BasicIntList &groupMembers)
Executes the WBDDC group configuration set command.
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.
virtual bool executeWbddcGroupEnableCommand(int index, bool &enabled)
Executes the WBDDC group enable command.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool executeWbddcGroupQuery(int index, BasicIntList &groupMembers)
Executes the WBDDC group configuration query command.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
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.
Base WBDDC group component class.
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 void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
Defines functionality for LibCyberRadio applications.
A configuration dictionary.
virtual ~WbddcGroupComponent()
Destroys a WbddcGroupComponent object.
virtual std::string getLastCommandErrorInfo() const
Gets the error message from the last command attempted.
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
WbddcGroupComponent(const std::string &name="WBG", int index=1, RadioHandler *parent=NULL, bool debug=false, int numGroupMembers=0, int groupMemberIndexBase=1)
Constructs a WbddcGroupComponent object.
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.
virtual bool executeWbddcGroupMemberCommand(int index, int groupMember, bool &isMember)
Executes the WBDDC group member set command.
BASIC_LIST_CONTAINER< int > BasicIntList
Type representing a list of integers.
virtual bool executeWbddcGroupMemberQuery(int index, int groupMember, bool &isMember)
Executes the WBDDC group member query command.
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 setMembers(const BasicIntList &groupMembers)
Sets the list of group members.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.