Instrument Neutral Distributed Interface INDI 2.2.5
sqm.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2016 Jasem Mutlaq. All rights reserved.
3
4 INDI Sky Quality Meter Driver
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 The full GNU General Public License is included in this distribution in the
22 file called LICENSE.
23*******************************************************************************/
24
25#pragma once
26
27#include "defaultdevice.h"
28
30{
31 public:
32 SQM();
33 virtual ~SQM() = default;
34
35 virtual bool initProperties() override;
36 virtual bool updateProperties() override;
37 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
38
43 typedef enum
44 {
49
50 protected:
51 const char *getDefaultName() override;
52 void TimerHit() override;
53
54 private:
55 bool getReadings();
56 bool getDeviceInfo();
57
58 // Readings
59 INumberVectorProperty AverageReadingNP;
60 INumber AverageReadingN[5];
61 enum
62 {
63 SKY_BRIGHTNESS,
64 SENSOR_FREQUENCY,
65 SENSOR_COUNTS,
66 SENSOR_PERIOD,
67 SKY_TEMPERATURE
68 };
69
70 // Device Information
71 INumberVectorProperty UnitInfoNP;
72 INumber UnitInfoN[4];
73 enum
74 {
75 UNIT_PROTOCOL,
76 UNIT_MODEL,
77 UNIT_FEATURE,
78 UNIT_SERIAL
79 };
80
81 Connection::Serial *serialConnection { nullptr };
82 Connection::TCP *tcpConnection { nullptr };
83
84 int PortFD { -1 };
85 uint8_t sqmConnection { CONNECTION_SERIAL | CONNECTION_TCP };
86
90 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
91 void hexDump(char * buf, const char * data, int size);
92 std::vector<std::string> split(const std::string &input, const std::string &regex);
93
97
101 static constexpr const char * INFO_TAB = "Info";
102 // 0xA is the stop char
103 static const char DRIVER_STOP_CHAR { 0x0A };
104 // Wait up to a maximum of 3 seconds for serial input
105 static constexpr const uint8_t DRIVER_TIMEOUT {3};
106 // Maximum buffer for sending/receiving.
107 static constexpr const uint8_t DRIVER_LEN {128};
108};
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition sqm.cpp:48
@ CONNECTION_NONE
Definition sqm.h:45
@ CONNECTION_SERIAL
Definition sqm.h:46
@ CONNECTION_TCP
Definition sqm.h:47
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition sqm.cpp:121
const char * getDefaultName() override
Definition sqm.cpp:168
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition sqm.cpp:218
virtual ~SQM()=default
SQM()
Definition sqm.cpp:43
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition sqm.cpp:100
struct _INumber INumber
struct _INumberVectorProperty INumberVectorProperty
*brief user defined string literal for JSON values *sa std::size_t n
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One number descriptor.
Holds the connection mode of the device.