libcyberradio  22.01.24
WbddcGroupComponent.cpp
1 /***************************************************************************
2  * \file WbddcGroupComponent.cpp
3  * \brief Defines the WBDDC group interface for the NDR472.
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/NDR472/WbddcGroupComponent.h"
12 #include "LibCyberRadio/Driver/RadioHandler.h"
13 #include "LibCyberRadio/Common/Pythonesque.h"
14 #include <boost/lexical_cast.hpp>
15 #include <boost/format.hpp>
16 
17 
18 namespace LibCyberRadio
19 {
20  namespace Driver
21  {
22 
23  namespace NDR472
24  {
25 
28  bool debug) :
30  /* const std::string& name */ (boost::format("NDR472-WBG%02d") % \
31  index).str(),
32  /* int index */ index,
33  /* ::LibCyberRadio::Driver::RadioHandler* parent */ parent,
34  /* bool debug */ debug,
35  /* int numGroupMembers */ 2,
36  /* int groupMemberIndexBase */ 1)
37  {
39  }
40 
42  {
43  }
44 
46  ::LibCyberRadio::Driver::WbddcGroupComponent(other)
47  {
48  }
49 
51  {
52  ::LibCyberRadio::Driver::WbddcGroupComponent::operator=(other);
53  if ( this != &other )
54  {
55  }
56  return *this;
57  }
58 
59  // OVERRIDE
60  // This radio uses commas to delimit query parameters rather than commas
62  bool& enabled)
63  {
64  this->debug("[NDR472::WbddcGroupComponent::executeWbddcGroupEnableQuery] Called\n");
65  bool ret = false;
66  if ( (_parent != NULL) && (_parent->isConnected()) )
67  {
68  std::ostringstream oss;
69  oss << "WBGE? " << index << "\n";
70  BasicStringList rsp = _parent->sendCommand(oss.str(), 2.0);
71  if ( _parent->getLastCommandErrorInfo() == "" )
72  {
74  Pythonesque::Replace(rsp.front(), "WBGE ", ""),
75  " ");
76  // vec[0] = Index
77  // vec[1] = Enabled indicator
78  enabled = (boost::lexical_cast<int>(vec[1]) == 1);
79  ret = true;
80  }
81  }
82  this->debug("[NDR472::WbddcGroupComponent::executeWbddcGroupEnableQuery] Returning %s\n",
83  this->debugBool(ret));
84  return ret;
85  }
86 
87  bool WbddcGroupComponent::executeWbddcGroupMemberQuery(int index, int groupMember,
88  bool& isMember)
89  {
90  this->debug("[NDR472::WbddcGroupComponent::executeWbddcGroupMemberQuery] Called\n");
91  bool ret = false;
92  if ( (_parent != NULL) && (_parent->isConnected()) )
93  {
94  std::ostringstream oss;
95  BasicStringList rsp, vec;
96  int inGroup;
97  oss << "WBG? " << index
98  << ", " << groupMember
99  << "\n";
100  rsp = _parent->sendCommand(oss.str(), 2.0);
101  if ( _parent->getLastCommandErrorInfo() == "" )
102  {
103  vec = Pythonesque::Split(
104  Pythonesque::Replace(rsp.front(), "WBG ", ""),
105  " ");
106  // vec[0] = Group index
107  // vec[1] = Member index
108  // vec[2] = 0 if member is not in group, 1 if it is
109  isMember = ( boost::lexical_cast<int>(vec[2]) == 1 );
110  ret = true;
111  }
112  }
113  this->debug("[NDR472::WbddcGroupComponent::executeWbddcGroupMemberQuery] Returning %s\n",
114  this->debugBool(ret));
115  return ret;
116  }
117 
118  } /* namespace NDR472 */
119 
120  } // namespace Driver
121 
122 } // namespace LibCyberRadio
123 
virtual ~WbddcGroupComponent()
Destroys a WbddcGroupComponent object.
virtual WbddcGroupComponent & operator=(const WbddcGroupComponent &other)
Assignment operator for WbddcGroupComponent objects.
virtual bool executeWbddcGroupMemberQuery(int index, int groupMember, bool &isMember)
Executes the WBDDC group member query command.
WbddcGroupComponent(int index=1, ::LibCyberRadio::Driver::RadioHandler *parent=NULL, bool debug=false)
Constructs a WbddcGroupComponent object.
virtual bool isConnected() const
Gets whether or not the handler is connected.
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.
Definition: Pythonesque.cpp:62
virtual bool executeWbddcGroupEnableQuery(int index, bool &enabled)
Executes the WBDDC group enable 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.
Definition: Pythonesque.cpp:77
Generic radio handler class.
Definition: RadioHandler.h:54
virtual int debug(const char *format,...)
Outputs debug information.
Definition: Debuggable.cpp:95
BASIC_LIST_CONTAINER< std::string > BasicStringList
Type representing a list of strings.
Definition: BasicList.h:25
Defines functionality for LibCyberRadio applications.
Definition: App.h:23
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.
Definition: Debuggable.cpp:126
WBDDC group component class for the NDR472.
virtual BasicStringList sendCommand(const std::string &cmdString, double timeout=-1)
Sends a command to the radio.