Line data Source code
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 10 : int parseC( float & temp, ///< [out] the reported temperature
27 : const std::string & str ///< [in] the string returned by the device
28 : )
29 : {
30 10 : size_t st = str.find(" C\r\n>");
31 10 : if(st == std::string::npos)
32 : {
33 4 : temp = -999;
34 4 : return -1;
35 : }
36 :
37 6 : if(st == 0)
38 : {
39 1 : temp = -999;
40 1 : return -2;
41 : }
42 :
43 5 : if(!isdigit(str[0]) && str[0] != '-')
44 : {
45 1 : temp = -999;
46 1 : return -3;
47 : }
48 :
49 4 : temp = std::stof( str.substr(0, st) );
50 :
51 4 : 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 11 : int parseH( float & humid, ///< [out] the reported temperature
62 : const std::string & str ///< [in] the string returned by the device
63 : )
64 : {
65 11 : size_t st = str.find(" %RH\r\n>");
66 11 : if(st == std::string::npos)
67 : {
68 4 : humid = -999;
69 4 : return -1;
70 : }
71 :
72 7 : if(st == 0)
73 : {
74 1 : humid = -999;
75 1 : return -2;
76 : }
77 :
78 6 : if(!isdigit(str[0]))
79 : {
80 2 : humid = -999;
81 2 : return -3;
82 : }
83 :
84 4 : humid = std::stof( str.substr(0, st) );
85 :
86 4 : return 0;
87 : }
88 :
89 : } //namespace RH
90 : } //namespace app
91 : } //namespace MagAOX
92 :
93 : #endif //rhusbMonParsers_hpp
|