Commit f67822aa authored by Samuel Debionne's avatar Samuel Debionne
Browse files

Update to match controller v0.5 commands

parent 50e9ad2b
Pipeline #25262 failed with stages
in 39 minutes and 1 second
......@@ -45,7 +45,8 @@ class bad_lexical_cast : public std::bad_cast { using std::bad_cast::bad_cast; }
class regex_error : public std::runtime_error { using std::runtime_error::runtime_error; };
namespace details {
BETTER_ENUM(yes_no_t, uint8_t, yes, no);
BETTER_ENUM(on_off_t, uint8_t, on, off);
BETTER_ENUM(on_off_auto_t, uint8_t, on, off, automatic);
BETTER_ENUM(polarity_t, uint8_t, positive, negative);
......@@ -81,6 +82,7 @@ struct tester; // Forward declaration for befriending, used for private function
class smpx
{
public:
using yes_no_t = details::yes_no_t;
using on_off_t = details::on_off_t;
using on_off_auto_t = details::on_off_auto_t;
using polarity_t = details::polarity_t;
......@@ -147,6 +149,16 @@ public:
return parse_pxpitch(answer);
}
/// Set the pixel pitch [um]
/// \note Send the PXPITCH command
void pixel_pitch(int pitch) const
{
auto cmd = fmt::format("PXPITCH {}", pitch);
const char* answer = NULL;
command(SMPX_ALL, SMPX_NOFLG /*SMPX_MERGE*/, cmd.c_str());
}
/// Returns the sensor polarity
/// \note Send the ?SENSORPOL command
auto sensor_polarity() const
......@@ -427,10 +439,10 @@ public:
{
// TODO: Hana.Struct might not be necessary?
BOOST_HANA_DEFINE_STRUCT(acqpars_t,
(on_off_t, arb),
(on_off_t, chs),
(int, bits),
(int, nctrs),
(on_off_t, csm),
(yes_no_t, arb),
(int, bits),
(int, acfrms),
(on_off_auto_t, crm)
);
......@@ -438,7 +450,7 @@ public:
bool operator==(acqpars_t const& rhs) const /*= default in C++20*/
{
// TODO: Add comparison of crm
return (arb == rhs.arb) && (chs == rhs.chs) && (bits == rhs.bits) && (nctrs == rhs.nctrs) && (acfrms == rhs.acfrms) && (crm == rhs.crm);
return (nctrs == rhs.nctrs) && (csm == rhs.csm) && (arb == rhs.arb) && (bits == rhs.bits) && (acfrms == rhs.acfrms) && (crm == rhs.crm);
}
};
......@@ -575,7 +587,7 @@ private:
void command(int idx, unsigned int flags, const char* cmd, const char** answer = NULL, smpxdata_t* sendbdata = NULL, smpxdata_t* rcvbdata = NULL) const
{
std::cout << "CMD " << cmd << std::endl;
std::cout << "CMD: " << cmd << std::endl;
const char* buffer;
answer = answer ? answer : &buffer;
......@@ -633,7 +645,7 @@ private:
auto acfrms = (p.acfrms == 0) ? "NONE" : std::to_string(p.acfrms);
return fmt::format("ACQPARS ARB {} CHS {} BITS {} NCTRS {} ACFRMS {} CRM {}", to_string(p.arb), to_string(p.chs), p.bits, p.nctrs, acfrms, crm);
return fmt::format("ACQPARS NCTRS {} CSM {} ARB {} BITS {} ACFRMS {} CRM {}", p.nctrs, to_string(p.csm), to_string(p.arb), p.bits, acfrms, crm);
}
friend struct unit_test::tester;
......@@ -642,7 +654,7 @@ private:
inline std::ostream& operator<< (std::ostream& os, smpx::acqpars_t const& p)
{
os << "ARB " << p.arb << " CSM " << p.chs << " BITS " << p.bits << " NCTRS " << p.nctrs << " ACFRMS " << p.acfrms;
os << "NCTRS " << p.nctrs << " CSM " << p.csm << " ARB " << p.arb << " BITS " << p.bits << " ACFRMS " << p.acfrms << " CRM " << p.crm;
return os;
}
......
......@@ -83,10 +83,10 @@ void control::impl::prepare(const control::acq_params_t& acq_params)
// Set acquisition params
smpx::acqpars_t pars = {
smpx::on_off_t::off, //arb
smpx::on_off_t::off, //chs
settings::get(acq_params.cam.pixel_depth), //bits
1, //nctrs
smpx::on_off_t::off, //csm
smpx::yes_no_t::no, //arb
settings::get(acq_params.cam.pixel_depth), //bits
0, //acfrms
smpx::on_off_auto_t::off //crm
};
......
......@@ -27,6 +27,17 @@ namespace details {
// TODO: Use std::string_view once it is supported in better enum
// https://github.com/aantron/better-enums/issues/55
template <>
inline
yes_no_t lexical_cast_s<yes_no_t>(std::string s)
{
auto res = yes_no_t::_from_string_nocase_nothrow(s.c_str());
if (res)
return *res;
else
throw bad_lexical_cast{};
}
template <>
inline
on_off_t lexical_cast_s<on_off_t>(std::string s)
......@@ -286,19 +297,19 @@ int smpx::parse_frmmint(std::string_view sv)
}
static constexpr auto acqpars_pattern = ctll::fixed_string{
"ARB (ON|OFF) CHS (ON|OFF) BITS (\\d+) NCTRS (\\d+) ACFRMS (NONE|ALL|\\d+) CRM (ON|OFF|AUTO)"
"NCTRS (\\d+) CSM (ON|OFF) ARB (YES|NO) BITS (\\d+) ACFRMS (NONE|ALL|\\d+) CRM (ON|OFF|AUTO)"
};
smpx::acqpars_t smpx::parse_acqpars(std::string_view sv)
{
using namespace details;
if (auto [m, arb, chs, bits, nctrs, acfrms, crm] = ctre::match<acqpars_pattern>(sv); m) {
if (auto [m, nctrs, csm, arb, bits, acfrms, crm] = ctre::match<acqpars_pattern>(sv); m) {
return {
lexical_cast_s<on_off_t>(arb.to_string()),
lexical_cast_s<on_off_t>(chs.to_string()),
lexical_cast<int>(bits),
lexical_cast<int>(nctrs),
lexical_cast_s<on_off_t>(csm.to_string()),
lexical_cast_s<yes_no_t>(arb.to_string()),
lexical_cast<int>(bits),
// Let's keep things simple next time please
lexical_cast<int>((acfrms.to_view() == "NONE") ? "0" : ((acfrms.to_view() == "ALL") ? "-1" : acfrms.to_view())),
lexical_cast<on_off_auto_t>(crm)
......
......@@ -102,10 +102,10 @@ BOOST_AUTO_TEST_CASE(test_ctor)
// Set acquisition params
pars = {
smpx::on_off_t::off, //arb
smpx::on_off_t::off, //chs
12, //bits
1, //nctrs
smpx::on_off_t::off, //csm
smpx::yes_no_t::no, //arb
12, //bits
0, //acfrms
smpx::on_off_auto_t::off //crm
};
......
......@@ -35,10 +35,10 @@ namespace lima {
BOOST_AUTO_TEST_CASE(test_parse_acqpars)
{
auto res = unit_test::tester::parse_acqpars(
"ARB OFF CHS OFF BITS 12 NCTRS 1 ACFRMS 1 CRM AUTO"
"NCTRS 1 CSM OFF ARB NO BITS 12 ACFRMS NONE CRM AUTO"
);
smpx::acqpars_t expected{ smpx::on_off_t::off, smpx::on_off_t::off, 12, 1, 1, smpx::on_off_auto_t::automatic };
smpx::acqpars_t expected{ 1, smpx::on_off_t::off, smpx::yes_no_t::no, 12, 0, smpx::on_off_auto_t::automatic };
BOOST_CHECK_EQUAL(res, expected);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment