34 #include <sys/ioctl.h>
43 std::vector<std::string>
split(
const std::string &input,
const std::string ®ex)
47 std::sregex_token_iterator
48 first{input.begin(), input.end(), re, -1},
59 int nbytes_written = 0, nbytes_read = 0;
60 tcflush(m_PortFD, TCIOFLUSH);
62 std::string output =
command.dump();
64 if ( (tty_rc =
tty_write(m_PortFD, output.c_str(), output.length(), &nbytes_written)) !=
TTY_OK)
66 char errorMessage[
MAXRBUF] = {0};
68 LOGF_ERROR(
"Serial write error: %s", errorMessage);
73 if (response ==
nullptr)
76 char read_buf[DRIVER_LEN] = {0};
77 if ( (tty_rc =
tty_read_section(m_PortFD, read_buf, DRIVER_STOP_CHAR, DRIVER_TIMEOUT, &nbytes_read)) !=
TTY_OK)
79 char errorMessage[
MAXRBUF] = {0};
81 LOGF_ERROR(
"Serial write error: %s", errorMessage);
89 if (strstr(read_buf,
"Error:"))
94 *response = json::parse(read_buf)[
"res"];
108 std::string response;
109 if (
get(
type, parameter, response))
111 sscanf(response.c_str(),
"%lf", &value);
132 json jsonRequest = {{parameter,
""}};
153 return isDone ==
"done";
158 const json &command, T *response)
164 jsonRequest = {{
"req", {{
type, {{node,
command}}}}}};
165 if (response ==
nullptr)
174 std::string flat =
command.flatten().items().begin().key();
175 std::vector<std::string> keys =
split(flat,
"/");
183 if (jsonResponse[
type].contains(key))
185 else if (jsonResponse[
type].contains(
"ERROR"))
187 std::string error = jsonResponse[
type][
"ERROR"];
194 if (jsonResponse[
type][node].contains(key))
195 jsonResponse[
type][node][key].
get_to(*response);
196 else if (jsonResponse[
type][node].contains(
"ERROR"))
198 std::string error = jsonResponse[
type][node][
"ERROR"];
209 LOGF_ERROR(
"Failed Request: %s\nResponse: %s\nException: %s id: %d", jsonRequest.
dump().c_str(),
210 jsonResponse.
dump().c_str(),
235 std::string response;
237 return response ==
"done";
297 isDetected = detected == 1;
335 return status[
"BUSY"] == 1;
380 versions[
"SWAPP"].
get_to(response);
452 json preset = {{
"RP_NAME", user},
470 json jsonRequest = {{
"req", {{
"get", {{
"MOT1", { {
"FnRUN_ACC",
""},
471 {
"FnRUN_DEC",
""}, {
"FnRUN_SPD",
""}, {
"FnRUN_CURR_ACC",
""},
472 {
"FnRUN_CURR_DEC",
""}, {
"FnRUN_CURR_SPD",
""}, {
"FnRUN_CURR_HOLD",
""}, {
"HOLDCURR_STATUS",
""}
484 jsonResponse[
"get"][
"MOT1"][
"FnRUN_ACC"].
get_to(rates.
accRate);
485 jsonResponse[
"get"][
"MOT1"][
"FnRUN_DEC"].
get_to(rates.
decRate);
494 jsonResponse[
"get"][
"MOT1"][
"HOLDCURR_STATUS"].
get_to(status);
495 motorHoldActive = ( status == 1 );
578 return m_Communication->set(
GENERIC_NODE, {{
"ARCO", enabled ? 1 : 0}});
587 if (m_Communication->get(
GENERIC_NODE,
"ARCO", enabled))
601 command = {{
"POSITION_DEG",
""}};
604 command = {{
"POSITION_ARCSEC",
""}};
607 command = {{
"POSITION_STEP",
""}};
611 return m_Communication->genericRequest(
"MOT2",
"get", command, &value);
623 command = {{
"MOVE_ABS", {{
"DEG", value}}}};
626 command = {{
"MOVE_ABS", {{
"ARCSEC", value}}}};
629 command = {{
"MOVE_ABS", {{
"STEP",
static_cast<int>(value)}}}};
633 return m_Communication->command(
MOT_2, command);
645 command = {{
"SYNC_POS", {{
"DEG", value}}}};
648 command = {{
"SYNC_POS", {{
"ARCSEC", value}}}};
651 command = {{
"SYNC_POS", {{
"STEP",
static_cast<int>(value)}}}};
655 return m_Communication->command(
MOT_2, command);
664 if (m_Communication->get(
MOT_2,
"STATUS", status))
666 return status[
"BUSY"] == 1;
676 return m_Communication->get(
MOT_2,
"STATUS", status);
684 return m_Communication->command(
MOT_2, {{
"MOT_STOP",
""}});
692 return m_Communication->set(
MOT_2, {{
"CAL_STATUS",
"exec"}});
701 if (m_Communication->get(
MOT_2,
"CAL_STATUS", value))
703 return value ==
"exec";
713 return m_Communication->set(
MOT_2, {{
"REVERSE", enabled ? 1 : 0}});
722 if (m_Communication->get(
MOT_2,
"REVERSE", value))
734 return m_Communication->get(
GENERIC_NODE,
"ARCO_SN", response);
752 json jsonRequest = {{
"req", {{
"get", {{
"MOT2",
""}}}}}};
753 return m_Communication->sendRequest(jsonRequest, &info);
769 json jsonRequest = {{
"req", {{
"set", {{
"LIGHT", enabled ? 1 : 0}}}}}};
770 return m_Communication->sendRequest(jsonRequest);
791 return m_Communication->get(
GENERIC_NODE,
"MAX_BRIGHTNESS", value);
799 return m_Communication->set(
GENERIC_NODE, {{
"BRIGHTNESS", value}});
807 return m_Communication->get(
GENERIC_NODE,
"BRIGHTNESS", value);
824 return m_Communication->get(
GENERIC_NODE,
"MODNAME", model);
832 return m_Communication->get(
MOT_1,
"STATUS", status);
856 return m_Communication->set(
MOT_1, {{
"POSITION", value}});
864 return m_Communication->command(
MOT_1, {{
"MOT_STOP",
""}});
872 return m_Communication->command(
MOT_1, {{
"CAL_ALTO",
"Init"}});
880 return m_Communication->command(
MOT_1, {{
"CAL_ALTO", fast ?
"Open_Fast" :
"Open_Slow"}});
888 return m_Communication->command(
MOT_1, {{
"CAL_ALTO", fast ?
"Close_Fast" :
"Close_Slow"}});
896 return m_Communication->command(
MOT_1, {{
"CAL_ALTO",
"StoreAsClosedPos"}});
904 return m_Communication->command(
MOT_1, {{
"CAL_ALTO",
"StoreAsMaxOpenPos"}});
bool close(bool fast=false)
bool storeClosedPosition()
bool getModel(std::string &model)
ALTO(const std::string &name, int port)
bool setPosition(uint8_t value)
bool open(bool fast=false)
bool getStatus(json &status)
bool setEnabled(bool enabled)
bool getStatus(json &status)
bool getMotorInfo(json &info)
bool moveAbsolutePoition(Units unit, double value)
Arco(const std::string &name, int port)
bool sync(Units unit, double value)
bool getSerialNumber(std::string &response)
bool getAbsolutePosition(Units unit, double &value)
bool reverse(bool enabled)
bool getFirmwareVersion(std::string &response)
bool command(NodeType type, const json &jsonCommand)
bool genericRequest(const std::string &node, const std::string &type, const json &command, T *response=nullptr)
bool sendRequest(const json &command, json *response=nullptr)
bool getStringAsDouble(NodeType type, const std::string ¶meter, double &value)
getStringAsDouble Same as get, but it receives a string and scan it for double.
bool get(NodeType type, const std::string ¶meter, T &value)
bool set(NodeType type, const json &value)
bool setBacklash(uint32_t steps)
Esatto(const std::string &name, int port)
bool getBacklash(uint32_t &steps)
bool getVoltageUSB(double &value)
bool getVoltage12v(double &value)
std::unique_ptr< Communication > m_Communication
bool getAbsolutePosition(uint32_t &position)
bool getExternalTemp(double &value)
bool isHallSensorDetected(bool &isDetected)
bool getSerialNumber(std::string &response)
Focuser(const std::string &name, int port)
bool getFirmwareVersion(std::string &response)
bool setBacklash(uint32_t steps)
bool getCurrentSpeed(uint32_t &speed)
bool getMotorTemp(double &value)
bool getMaxPosition(uint32_t &position)
bool getStatus(json &status)
bool getBacklash(uint32_t &steps)
bool goAbsolutePosition(uint32_t position)
GIOTTO(const std::string &name, int port)
bool getMaxBrightness(uint16_t &value)
bool setLightEnabled(bool enabled)
bool getBrightness(uint16_t &value)
bool setBrightness(uint16_t value)
bool getMotorSettings(struct MotorRates &rates, struct MotorCurrents ¤ts, bool &motorHoldActive)
bool setMotorCurrents(const MotorCurrents ¤ts)
bool setMotorHold(bool hold)
bool applyMotorPreset(const std::string &name)
SestoSenso2(const std::string &name, int port)
bool setMotorUserPreset(uint32_t index, const MotorRates &rates, const MotorCurrents ¤ts)
bool storeAsMaxPosition()
bool storeAsMinPosition()
bool setMotorRates(const MotorRates &rates)
a class to store JSON values
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
general exception of the basic_json class
const char * what() const noexcept override
returns the explanatory string
const int id
the id of the exception
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Implementations for common driver routines.
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
std::vector< std::string > split(const std::string &input, const std::string ®ex)
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values