38 static std::unique_ptr<LPM> lpm(
new LPM());
40 #define UNIT_TAB "Unit"
60 IUFillNumber(&AverageReadingN[0],
"SKY_BRIGHTNESS",
"Quality (mag/arcsec^2)",
"%6.2f", -20, 30, 0, 0);
61 IUFillNumber(&AverageReadingN[1],
"AVG_SKY_BRIGHTNESS",
"Avg. Quality (mag/argsec^2)",
"%6.2f", -20, 30, 0, 0);
62 IUFillNumber(&AverageReadingN[2],
"MIN_SKY_BRIGHTNESS",
"Min. Quality (mag/argsec^2)",
"%6.2f", -20, 30, 0, 0);
63 IUFillNumber(&AverageReadingN[3],
"MAX_SKY_BRIGHTNESS",
"Max. Quality (mag/argsec^2)",
"%6.2f", -20, 30, 0, 0);
64 IUFillNumber(&AverageReadingN[4],
"NAKED_EYES_LIMIT",
"NELM (V mags)",
"%6.2f", -20, 30, 0, 0);
80 std::string defaultDirectory = std::string(getenv(
"HOME")) + std::string(
"/lpm");
81 IUFillText(&RecordFileT[0],
"RECORD_FILE_DIR",
"Dir.", defaultDirectory.data());
82 IUFillText(&RecordFileT[1],
"RECORD_FILE_NAME",
"Name",
"lpmlog.txt");
85 snprintf(filename, 2048,
"%s/%s", RecordFileT[0].text, RecordFileT[1].text);
88 IUFillNumber(&UnitInfoN[0],
"Calibdata",
"",
"%6.2f", -20, 30, 0, 0);
97 return getDeviceInfo();
133 bool LPM::ISNewText(
const char *dev,
const char *name,
char *texts[],
char *names[],
int n)
137 if (strcmp(name, RecordFileTP.
name) == 0)
142 snprintf(filename, 2048,
"%s/%s", RecordFileT[0].text, RecordFileT[1].text);
143 LOGF_INFO(
"filename changed to %s", filename);
161 if (!strcmp(name, ResetBP.
name))
168 AverageReadingN[0].value = 0;
169 AverageReadingN[1].value = 0;
170 AverageReadingN[2].value = 0;
171 AverageReadingN[3].value = 0;
177 else if (!strcmp(name, SaveBP.
name))
183 LOGF_INFO(
"Save readings to %s", filename);
215 void LPM::openFilePtr()
218 mkdir(RecordFileT[0].text, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
219 fp = fopen(filename,
"a");
222 bool LPM::getReadings()
224 const char *
cmd =
"V#";
226 int nbytes_written = 0;
235 sscanf(res,
"%f#", &mpsas);
252 AverageReadingN[0].value = mpsas;
257 AverageReadingN[1].value = sumSQ / count;
258 if (mpsas < AverageReadingN[2].value)
260 AverageReadingN[2].value = mpsas;
262 if (mpsas > AverageReadingN[3].value)
264 AverageReadingN[3].value = mpsas;
269 AverageReadingN[2].value = mpsas;
270 AverageReadingN[3].value = mpsas;
273 AverageReadingN[4].value = 7.93 - 5 * log(pow(10, (4.316 - (mpsas / 5))) + 1) / log(10);
280 return "Astromechanics LPM";
283 bool LPM::getDeviceInfo()
285 const char *
cmd =
"C#";
295 ssize_t written = write(PortFD,
cmd, 2);
299 LOGF_ERROR(
"Error getting device info while writing to device: %s", strerror(
errno));
303 ssize_t received = 0;
307 ssize_t response = read(PortFD,
buffer + received, 5 - received);
310 LOGF_ERROR(
"Error getting device info while reading response: %s", strerror(
errno));
314 received += response;
326 int rc = sscanf(
buffer,
"%f#", &calib);
334 UnitInfoN[0].value = calib;
344 bool rc = getReadings();
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
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...
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 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()
Initilize properties initial state and value. The child class must implement this function.
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 ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
const char * getDefaultName() override
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
#define NARRAY(a)
Handy macro to find the number of elements in array a[]. Must be used with actual array,...
int tty_read_section(int fd, char *buf, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
const char * indi_timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
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 IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text'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 IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
std::vector< uint8_t > buffer
int mkdir(const char *path, mode_t mode)