API
stateCodes.cpp
Go to the documentation of this file.
1 /** \file stateCodes.cpp
2  * \brief MagAO-X Application States
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  *
6  * \ingroup app_files
7  */
8 
9 #include "stateCodes.hpp"
10 
11 namespace MagAOX
12 {
13 namespace app
14 {
15 
16 std::string stateCodes::codeText( const stateCodeT & stateCode )
17 {
18  switch(stateCode)
19  {
21  return "FAILURE";
22  case stateCodes::ERROR:
23  return "ERROR";
25  return "UNINITIALIZED";
27  return "INITIALIZED";
29  return "NODEVICE";
31  return "POWEROFF";
33  return "POWERON";
35  return "NOTCONNECTED";
37  return "CONNECTED";
39  return "LOGGEDIN";
41  return "CONFIGURING";
43  return "NOTHOMED";
44  case stateCodes::HOMING:
45  return "HOMING";
47  return "OPERATING";
48  case stateCodes::READY:
49  return "READY";
51  return "SHUTDOWN";
52  default:
53  return "UNKNOWN";
54  }
55 
56  return "UNKNOWN";
57 }
58 
59 stateCodes::stateCodeT stateCodes::str2Code( const std::string & stateStr )
60 {
61 
62  if(stateStr == "FAILURE")
63  {
64  return stateCodes::FAILURE;
65  }
66  else if(stateStr == "ERROR")
67  {
68  return stateCodes::ERROR;
69  }
70  else if(stateStr == "UNINITIALIZED")
71  {
73  }
74  else if(stateStr == "INITIALIZED" )
75  {
77  }
78  else if(stateStr == "NODEVICE" )
79  {
80  return stateCodes::NODEVICE;
81  }
82  else if(stateStr == "POWEROFF")
83  {
84  return stateCodes::POWEROFF;
85  }
86  else if(stateStr == "POWERON")
87  {
88  return stateCodes::POWERON;
89  }
90  else if(stateStr == "NOTCONNECTED")
91  {
93  }
94  else if(stateStr == "CONNECTED")
95  {
96  return stateCodes::CONNECTED;
97  }
98  else if(stateStr == "LOGGEDIN")
99  {
100  return stateCodes::LOGGEDIN;
101  }
102  else if(stateStr == "CONFIGURING")
103  {
105  }
106  else if(stateStr == "NOTHOMED")
107  {
108  return stateCodes::NOTHOMED;
109  }
110  else if(stateStr == "HOMING")
111  {
112  return stateCodes::HOMING;
113  }
114  else if(stateStr == "OPERATING")
115  {
116  return stateCodes::OPERATING;
117  }
118  else if(stateStr == "READY")
119  {
120  return stateCodes::READY;
121  }
122  else if(stateStr == "SHUTDOWN")
123  {
124  return stateCodes::SHUTDOWN;
125  }
126  else
127  {
128  return -999;
129  }
130 
131 }
132 
133 stateCodes::stateCodeT stateCodes::str2CodeFast( const std::string & stateStr )
134 {
135  switch(stateStr[0])
136  {
137  case 'C':
138  if(stateStr.size() < 4)
139  {
140  return -999;
141  }
142 
143  if( stateStr[3] == 'F')
144  {
146  }
147  else if( stateStr[3] == 'N')
148  {
149  return stateCodes::CONNECTED;
150  }
151  else
152  {
153  return -999;
154  }
155  case 'E':
156  return stateCodes::ERROR;
157  case 'F':
158  return stateCodes::FAILURE;
159  case 'H':
160  return stateCodes::HOMING;
161  case 'I':
162  return INITIALIZED;
163  case 'L':
164  return LOGGEDIN;
165  case 'N':
166  if(size(stateStr) < 4)
167  {
168  return -999;
169  }
170  if(stateStr[2] == 'D')
171  {
172  return stateCodes::NODEVICE;
173  }
174  else if(stateStr[3] == 'C')
175  {
177  }
178  else if(stateStr[3] == 'H')
179  {
180  return stateCodes::NOTHOMED;
181  }
182  else
183  {
184  return -999;
185  }
186  case 'O':
187  return stateCodes::OPERATING;
188  case 'P':
189  if(stateStr.size() < 7)
190  {
191  return -999;
192  }
193 
194  if(stateStr[6] == 'F')
195  {
196  return stateCodes::POWEROFF;
197  }
198  else if(stateStr[6] == 'N')
199  {
200  return stateCodes::POWERON;
201  }
202  else
203  {
204  return -999;
205  }
206  case 'R':
207  return stateCodes::READY;
208  case 'S':
209  return stateCodes::SHUTDOWN;
210  case 'U':
212  default:
213  return -999;
214  }
215 }
216 
217 } //namespace app
218 } //namespace MagAOX
219 
@ OPERATING
The device is operating, other than homing.
Definition: stateCodes.hpp:55
@ POWEROFF
The device power is off.
Definition: stateCodes.hpp:47
@ NODEVICE
No device exists for the application to control.
Definition: stateCodes.hpp:46
@ SHUTDOWN
The application has shutdown, set just after calling appShutdown().
Definition: stateCodes.hpp:57
@ NOTHOMED
The device has not been homed.
Definition: stateCodes.hpp:53
@ HOMING
The device is homing.
Definition: stateCodes.hpp:54
@ FAILURE
The application has failed, should be used when m_shutdown is set for an error.
Definition: stateCodes.hpp:42
@ CONFIGURING
The application is configuring the device.
Definition: stateCodes.hpp:52
@ ERROR
The application has encountered an error, from which it is recovering (with or without intervention)
Definition: stateCodes.hpp:43
@ READY
The device is ready for operation, but is not operating.
Definition: stateCodes.hpp:56
@ LOGGEDIN
The application has logged into the device or service.
Definition: stateCodes.hpp:51
@ CONNECTED
The application has connected to the device or service.
Definition: stateCodes.hpp:50
@ UNINITIALIZED
The application is unitialized, the default.
Definition: stateCodes.hpp:44
@ INITIALIZED
The application has been initialized, set just before calling appStartup().
Definition: stateCodes.hpp:45
@ NOTCONNECTED
The application is not connected to the device or service.
Definition: stateCodes.hpp:49
@ POWERON
The device power is on.
Definition: stateCodes.hpp:48
Definition: dm.hpp:24
MagAO-X Application States.
static stateCodeT str2CodeFast(const std::string &stateStr)
Get the stateCode corresponding to an ASCII string with minimal checks.
Definition: stateCodes.cpp:133
int16_t stateCodeT
The type of the state code.
Definition: stateCodes.hpp:35
static stateCodeT str2Code(const std::string &stateStr)
Get the stateCode corresponding to an ASCII string.
Definition: stateCodes.cpp:59
static std::string codeText(const stateCodeT &stateCode)
Get an ASCII string corresponding to an application stateCode.
Definition: stateCodes.cpp:16