19#include <mx/ioutils/stringUtils.hpp>
78 std::string clean = response;
80 size_t promptPos = clean.find(
"fli-cli>" );
81 if( promptPos != std::string::npos )
83 clean.erase( promptPos );
87 while( first < clean.size() && std::isspace(
static_cast<unsigned char>( clean[first] ) ) )
92 size_t last = clean.size();
93 while( last > first && std::isspace(
static_cast<unsigned char>( clean[last - 1] ) ) )
98 return clean.substr( first, last - first );
103 const std::string &response
113 value = std::strtof( clean.c_str(), &end );
115 if( end == clean.c_str() )
120 while( end !=
nullptr && *end !=
'\0' && std::isspace(
static_cast<unsigned char>( *end ) ) )
125 if( end !=
nullptr && *end !=
'\0' )
135 const std::string &response,
136 size_t expectedValues
140 std::vector<std::string> tokens;
142 mx::ioutils::parseStringVector( tokens, clean,
":, \t\r\n" );
149 if( expectedValues > 0 && tokens.size() != expectedValues )
155 values.reserve( tokens.size() );
157 for(
const auto &token : tokens )
167 values.push_back( value );
175 const std::string &response
179 std::transform( clean.begin(),
182 [](
unsigned char c ) { return static_cast<char>( std::tolower( c ) ); } );
184 if( clean ==
"on" || clean ==
"true" || clean ==
"1" )
190 if( clean ==
"off" || clean ==
"false" || clean ==
"0" )
202 const std::string &response
211 const std::string &response
215 std::vector<std::string> tokens;
217 mx::ioutils::parseStringVector( tokens, clean,
":" );
229 if( tokens.size() == 1 )
238 if( tokens.size() != 3 )
254 const std::string &response
258 std::vector<std::string> tokens;
259 mx::ioutils::parseStringVector( tokens, clean,
"-, \t\r\n" );
261 if( tokens.size() != 2 )
268 firstValue = mx::ioutils::stoT<int>( tokens[0] );
269 secondValue = mx::ioutils::stoT<int>( tokens[1] );
283 std::string lower = clean;
284 std::transform( lower.begin(),
287 [](
unsigned char c ) { return static_cast<char>( std::tolower( c ) ); } );
289 if( lower.find(
"error" ) != std::string::npos || lower.find(
"fail" ) != std::string::npos )
307 if( width < 1 || height < 1 || fullWidth < 1 || fullHeight < 1 )
312 roi.
startColumn =
static_cast<int>( std::lround( centerX - 0.5f * (
static_cast<float>( width ) - 1.0f ) ) );
314 roi.
startRow =
static_cast<int>( std::lround( centerY - 0.5f * (
static_cast<float>( height ) - 1.0f ) ) );
347 centerX = roi.
startColumn + 0.5f * (
static_cast<float>( width ) - 1.0f );
348 centerY = roi.
startRow + 0.5f * (
static_cast<float>( height ) - 1.0f );
362 return std::to_string( roi.
startRow ) +
"-" + std::to_string( roi.
endRow );
bool fullFrame
True when the ROI spans the full detector.
int endRow
Last included row.
int startRow
First included row.
int endColumn
Last included column.
int startColumn
First included column.
C-RED 2 ROI expressed as 0-based inclusive column and row limits.
std::string cred2ColumnsSpec(const cred2Roi &roi)
Format the column command payload for set cropping columns.
std::string cred2CleanResponse(const std::string &response)
Strip an optional prompt and surrounding whitespace from a C-RED 2 CLI response.
int cred2ParseRange(int &firstValue, int &secondValue, const std::string &response)
Parse a raw range response such as 0-639.
int cred2RoiToCenter(float ¢erX, float ¢erY, int &width, int &height, const cred2Roi &roi, int fullWidth, int fullHeight)
Convert C-RED 2 ROI corners into a MagAO-X ROI center/size description.
int cred2ParseCropState(bool &enabled, int &startColumn, int &endColumn, int &startRow, int &endRow, const std::string &response)
Parse a raw cropping status response such as on or on:192-447:128-383.
int cred2RoiFromCenter(cred2Roi &roi, float centerX, float centerY, int width, int height, int fullWidth, int fullHeight)
Convert a MagAO-X ROI center/size description into C-RED 2 corners.
int cred2ParseFloatVector(std::vector< float > &values, const std::string &response, size_t expectedValues)
Parse a delimited list of raw numeric responses into a float vector.
bool cred2ResponseOK(const std::string &response)
Check whether a command response looks successful.
std::string cred2RowsSpec(const cred2Roi &roi)
Format the row command payload for set cropping rows.
int cred2ParseFloat(float &value, const std::string &response)
Parse a raw numeric response into a float.
int cred2ParseBool(bool &value, const std::string &response)
Parse a raw on/off response into a boolean.
Structure holding the temperature values reported by the C-RED 2.
float powerboard
Power-board temperature [C].
float setpoint
Detector temperature setpoint [C].
float peltier
External TEC temperature [C].
float motherboard
Motherboard temperature [C].
bool operator==(const cred2Temps &t) const
Compare two cached temperature sets.
int setInvalid()
Mark all temperature values invalid.
float snake
Detector temperature [C].
float frontend
Front-end temperature [C].
float heatsink
Heatsink temperature [C].