API
rhusbMonParsers.hpp
Go to the documentation of this file.
1 /** \file rhusbMonParsers.hpp
2  * \brief Parsers for the MagAO-X RH USB monitor
3  *
4  * \ingroup rhusbMon_files
5  */
6 
7 #ifndef rhusbMonParsers_hpp
8 #define rhusbMonParsers_hpp
9 
10 #include <string>
11 
12 namespace MagAOX
13 {
14 namespace app
15 {
16 namespace RH
17 {
18 
19 /// Parse the RH probe C temp command
20 /**
21  * \returns -1 if the end of transmission string is not found
22  * \returns -2 if there is no value in the string
23  * \returns -3 if the parsed string does not begin with a digit
24  * \returns 0 on success
25  */
26 int parseC( float & temp, ///< [out] the reported temperature
27  const std::string & str ///< [in] the string returned by the device
28  )
29 {
30  size_t st = str.find(" C\r\n>");
31  if(st == std::string::npos)
32  {
33  temp = -999;
34  return -1;
35  }
36 
37  if(st == 0)
38  {
39  temp = -999;
40  return -2;
41  }
42 
43  if(!isdigit(str[0]) && str[0] != '-')
44  {
45  temp = -999;
46  return -3;
47  }
48 
49  temp = std::stof( str.substr(0, st) );
50 
51  return 0;
52 }
53 
54 /// Parse the RH probe H humidity command
55 /**
56  * \returns -1 if the end of transmission string is not found
57  * \returns -2 if there is not value in the string
58  * \returns -3 if the parsed string does not begin with a digit
59  * \returns 0 on success
60  */
61 int parseH( float & humid, ///< [out] the reported temperature
62  const std::string & str ///< [in] the string returned by the device
63  )
64 {
65  size_t st = str.find(" %RH\r\n>");
66  if(st == std::string::npos)
67  {
68  humid = -999;
69  return -1;
70  }
71 
72  if(st == 0)
73  {
74  humid = -999;
75  return -2;
76  }
77 
78  if(!isdigit(str[0]))
79  {
80  humid = -999;
81  return -3;
82  }
83 
84  humid = std::stof( str.substr(0, st) );
85 
86  return 0;
87 }
88 
89 } //namespace RH
90 } //namespace app
91 } //namespace MagAOX
92 
93 #endif //rhusbMonParsers_hpp
int parseH(float &humid, const std::string &str)
Parse the RH probe H humidity command.
int parseC(float &temp, const std::string &str)
Parse the RH probe C temp command.
Definition: dm.hpp:24