11#include "LibCyberRadio/Driver/RadioHandler.h"
12#include "LibCyberRadio/Driver/WbddcGroupComponent.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(
"[WbddcGroupComponent::setConfiguration] Called\n");
82 bool adjEnabled = _enabled;
84 bool enableCmdNeedsExecuting =
false;
85 bool memberCmdNeedsExecuting =
false;
86 if ( cfg.
hasKey(
"enable") && _config.hasKey(
"enable") )
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(
"[WbddcGroupComponent::setConfiguration] Returning\n");
121 this->
debug(
"[WbddcGroupComponent::queryConfiguration] Called\n");
122 if ( _config.hasKey(
"enable") )
126 if ( _config.hasKey(
"members") )
131 this->
debug(
"[WbddcGroupComponent::queryConfiguration] Returning\n");
136 return _groupMembers;
141 this->
debug(
"[WbddcGroupComponent::setMembers] Called\n");
143 if ( _config.hasKey(
"members") )
149 _groupMembers = groupMembers;
153 this->
debug(
"[WbddcGroupComponent::setMembers] Returning %s\n",
160 this->
debug(
"[WbddcGroupComponent::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(
"[WbddcGroupComponent::addMember] Returning %s\n",
183 this->
debug(
"[WbddcGroupComponent::removeMember] Called\n");
185 if ( _config.hasKey(
"members") )
187 bool isMember =
false;
191 BasicIntList::iterator it = std::find(_groupMembers.begin(), _groupMembers.end(),
193 if ( it != _groupMembers.end() )
195 _groupMembers.erase(it);
200 this->
debug(
"[WbddcGroupComponent::removeMember] Returning %s\n",
211 _config[
"members"] =
"";
216 this->
debug(
"[WbddcGroupComponent::updateConfigurationDict] Called\n");
218 if ( _config.hasKey(
"members") )
220 this->
debug(
"[WbddcGroupComponent::updateConfigurationDict] Returning\n");
226 for (BasicIntList::const_iterator it = _groupMembers.begin();
227 it != _groupMembers.end(); it++)
229 vec.push_back( std::to_string(*it) );
239 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableQuery] Called\n");
241 if ( (_parent != NULL) && (_parent->isConnected()) )
243 std::ostringstream oss;
244 oss <<
"WBGE? " << index <<
"\n";
246 if ( _parent->getLastCommandErrorInfo() ==
"" )
253 enabled = (boost::lexical_cast<int>(vec[1]) == 1);
257 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableQuery] Returning %s\n",
266 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableCommand] Called\n");
268 if ( (_parent != NULL) && (_parent->isConnected()) )
270 std::ostringstream oss;
271 oss <<
"WBGE " << index
272 <<
", " << (enabled ? 1 : 0)
275 if ( _parent->getLastCommandErrorInfo() ==
"" )
280 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupEnableCommand] Returning %s\n",
289 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupQuery] Called\n");
292 groupMembers.clear();
293 for (
int member = _groupMemberIndexBase;
294 member < (_groupMemberIndexBase + _numGroupMembers); member++)
300 groupMembers.push_back(member);
305 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupQuery] Returning %s\n",
314 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupCommand] Called\n");
317 for (
int member = _groupMemberIndexBase;
318 member < (_groupMemberIndexBase + _numGroupMembers); member++)
320 isMember = ( std::count(groupMembers.begin(), groupMembers.end(), member) > 0 );
325 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupCommand] Returning %s\n",
333 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberQuery] Called\n");
335 if ( (_parent != NULL) && (_parent->isConnected()) )
337 std::ostringstream oss;
340 oss <<
"WBG? " << index
341 <<
", " << groupMember
343 rsp = _parent->sendCommand(oss.str(), 2.0);
344 if ( _parent->getLastCommandErrorInfo() ==
"" )
352 isMember = ( boost::lexical_cast<int>(vec[2]) == 1 );
356 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberQuery] Returning %s\n",
365 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberCommand] Called\n");
367 if ( (_parent != NULL) && (_parent->isConnected()) )
369 std::ostringstream oss;
370 oss <<
"WBG " << index
371 <<
", " << groupMember
372 <<
", " << ( isMember ? 1 : 0 )
375 if ( _parent->getLastCommandErrorInfo() ==
"" )
380 this->
debug(
"[WbddcGroupComponent::executeWbddcGroupMemberCommand] Returning %s\n",
virtual const char * debugBool(bool x)
Gets a debug output string for a Boolean value.
virtual int debug(const char *format,...)
Outputs debug information.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this object.
virtual bool getConfigurationValueAsBool(const std::string &key) const
Gets a named configuration value as a Boolean.
virtual bool setConfigurationValue(const std::string &key, const std::string &value)
Sets a named configuration value to a string.
virtual ConfigString getConfigurationValue(const std::string &key) const
Gets a named configuration value as a string.
A configuration dictionary.
virtual bool hasKey(const std::string &key) const
Determines if the dictionary has the given key.
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.
Generic radio handler class.
virtual BasicIntList getMembers() const
Gets the list of group members.
virtual bool enable(bool enabled=true)
Enables this component.
virtual bool setConfiguration(ConfigurationDict &cfg)
Sets the configuration dictionary for this component.
virtual std::string getMembersString()
Gets the string representation of the member list.
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 ~WbddcGroupComponent()
Destroys a WbddcGroupComponent object.
virtual bool executeWbddcGroupCommand(int index, BasicIntList &groupMembers)
Executes the WBDDC group configuration set command.
virtual bool removeMember(int member)
Removes a WBDDC from the list of group members.
virtual bool addMember(int member)
Adds a WBDDC to the list of group members.
virtual bool setMembers(const BasicIntList &groupMembers)
Sets the list of group members.
virtual bool executeWbddcGroupQuery(int index, BasicIntList &groupMembers)
Executes the WBDDC group configuration query command.
virtual bool executeWbddcGroupMemberQuery(int index, int groupMember, bool &isMember)
Executes the WBDDC group member query command.
virtual void queryConfiguration()
Tells the component to query its hardware configuration in order to create its configuration dictiona...
virtual WbddcGroupComponent & operator=(const WbddcGroupComponent &other)
Assignment operator for WbddcGroupComponent objects.
virtual bool executeWbddcGroupEnableCommand(int index, bool &enabled)
Executes the WBDDC group enable command.
virtual void updateConfigurationDict()
Updates the configuration dictionary from component settings.
virtual bool executeWbddcGroupEnableQuery(int index, bool &enabled)
Executes the WBDDC group enable query command.
virtual bool executeWbddcGroupMemberCommand(int index, int groupMember, bool &isMember)
Executes the WBDDC group member set command.
virtual void initConfigurationDict()
Initializes the configuration dictionary, defining the allowed keys.
static std::string Strip(const std::string &str, const std::string &chars=" \r\n\t\v\f")
Strips both leading and trailing whitespace from the given string.
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.
static std::string Join(const BasicStringList &vec, const std::string &sep)
Joins a list of string tokens, concatenating them into a single string.
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.
Provides programming elements for driving CRS NDR-class radios.
Defines functionality for LibCyberRadio applications.
BASIC_LIST_CONTAINER< int > BasicIntList
Type representing a list of integers.
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.