39static std::unique_ptr<SQM> sqm(
new SQM());
41#define UNIT_TAB "Unit"
53 IUFillNumber(&AverageReadingN[SKY_BRIGHTNESS],
"SKY_BRIGHTNESS",
"Quality (mag/arcsec^2)",
"%6.2f", -20, 30, 0, 0);
54 IUFillNumber(&AverageReadingN[SENSOR_FREQUENCY],
"SENSOR_FREQUENCY",
"Freq (Hz)",
"%6.2f", 0, 1000000, 0, 0);
55 IUFillNumber(&AverageReadingN[SENSOR_COUNTS],
"SENSOR_COUNTS",
"Period (counts)",
"%6.2f", 0, 1000000, 0, 0);
56 IUFillNumber(&AverageReadingN[SENSOR_PERIOD],
"SENSOR_PERIOD",
"Period (s)",
"%6.2f", 0, 1000000, 0, 0);
57 IUFillNumber(&AverageReadingN[SKY_TEMPERATURE],
"SKY_TEMPERATURE",
"Temperature (C)",
"%6.2f", -50, 80, 0, 0);
62 IUFillNumber(&UnitInfoN[UNIT_PROTOCOL],
"UNIT_PROTOCOL",
"Protocol",
"%.f", 0, 1000000, 0, 0);
63 IUFillNumber(&UnitInfoN[UNIT_MODEL],
"UNIT_MODEL",
"Model",
"%.f", 0, 1000000, 0, 0);
64 IUFillNumber(&UnitInfoN[UNIT_FEATURE],
"UNIT_FEATURE",
"Feature",
"%.f", 0, 1000000, 0, 0);
65 IUFillNumber(&UnitInfoN[UNIT_SERIAL],
"UNIT_SERIAL",
"Serial",
"%.f", 0, 1000000, 0, 0);
73 return getDeviceInfo();
86 return getDeviceInfo();
121bool SQM::ISNewNumber(
const char *dev,
const char *name,
double values[],
char *names[],
int n)
126 if (!strcmp(name,
"POLLING_PERIOD"))
128 uint32_t seconds = values[0] / 1000;
130 LOGF_WARN(
"Make sure SQM web timeout is configured for %ld seconds or more. Otherwise SQM will disconnect prematurely.",
138bool SQM::getReadings()
140 char res[DRIVER_LEN] = {0};
142 if (!sendCommand(
"rx", res))
146 int frequency, period_counts;
147 int rc = sscanf(res,
"r,%fm,%dHz,%dc,%fs,%fC", &mpsas, &frequency, &period_counts, &period_seconds, &
temperature);
151 rc = sscanf(res,
"r,%fm,%dHz,%dc,%fs,%fC,%*d", &mpsas, &frequency, &period_counts, &period_seconds, &
temperature);
159 AverageReadingN[0].value = mpsas;
160 AverageReadingN[1].value = frequency;
161 AverageReadingN[2].value = period_counts;
162 AverageReadingN[3].value = period_seconds;
173bool SQM::getDeviceInfo()
184 char res[DRIVER_LEN] = {0};
185 for (
int i = 0; i < 3; i++)
187 if (!sendCommand(
"ix", res))
197 LOGF_ERROR(
"Error getting device info while reading response: %s", strerror(
errno));
201 int protocol, model, feature, serial;
202 int rc = sscanf(res,
"i,%d,%d,%d,%d", &protocol, &model, &feature, &serial);
210 UnitInfoN[0].value = protocol;
211 UnitInfoN[1].value = model;
212 UnitInfoN[2].value = feature;
213 UnitInfoN[3].value = serial;
223 bool rc = getReadings();
234bool SQM::sendCommand(
const char *
cmd,
char * res,
int cmd_len,
int res_len)
236 int nbytes_written = 0, nbytes_read = 0, rc = -1;
238 tcflush(PortFD, TCIOFLUSH);
242 char hex_cmd[DRIVER_LEN * 3] = {0};
243 hexDump(hex_cmd,
cmd, cmd_len);
257 LOGF_ERROR(
"Serial write error: %s.", errstr);
265 rc =
tty_read(PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read);
267 rc =
tty_nread_section(PortFD, res, DRIVER_LEN, DRIVER_STOP_CHAR, DRIVER_TIMEOUT, &nbytes_read);
279 char hex_res[DRIVER_LEN * 3] = {0};
280 hexDump(hex_res, res, res_len);
286 res[nbytes_read - 2] = 0;
290 tcflush(PortFD, TCIOFLUSH);
298void SQM::hexDump(
char * buf,
const char * data,
int size)
300 for (
int i = 0; i < size; i++)
301 sprintf(buf + 3 * i,
"%02X ",
static_cast<uint8_t
>(data[i]));
304 buf[3 * size - 1] =
'\0';
310std::vector<std::string> SQM::split(
const std::string &input,
const std::string ®ex)
313 std::regex re(regex);
314 std::sregex_token_iterator
315 first{input.begin(), input.end(), re, -1},
317 return {first, last};
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
void setDefaultHost(const char *addressHost)
void setDefaultPort(uint32_t addressPort)
const char * getDeviceName() const
void addPollPeriodControl()
Add Polling period control to the driver.
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Connection::Interface * getActiveConnection()
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
const char * getDefaultName() override
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
int tty_write(int fd, const char *buf, int nbytes, int *nbytes_written)
Writes a buffer to fd.
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)