Instrument Neutral Distributed Interface INDI
2.2.5
drivers
ccd
simulator_clock.h
Go to the documentation of this file.
1
/*******************************************************************************
2
Copyright(c) 2026 Jasem Mutlaq. All rights reserved.
3
4
This program is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License
6
version 2 as published by the Free Software Foundation.
7
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
12
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
17
*******************************************************************************/
18
19
#pragma once
20
21
#include "
defaultdevice.h
"
22
#include "
indicom.h
"
23
#include "
indipropertytext.h
"
24
25
#include <libnova/julian_day.h>
26
#include <libnova/sidereal_time.h>
27
28
#include <cstring>
29
37
class
SimulatorClock
38
{
39
public
:
40
void
initProperties
(
const
char
*deviceName,
const
char
*group)
41
{
42
TimeTP[UTC].
fill
(
"UTC"
,
"UTC Time"
,
nullptr
);
43
TimeTP[OFFSET].
fill
(
"OFFSET"
,
"UTC Offset"
,
nullptr
);
44
TimeTP.
fill
(deviceName,
"TIME_UTC"
,
"UTC"
, group,
IP_RW
, 60,
IPS_IDLE
);
45
}
46
47
// Defines TIME_UTC while connected. A new connection starts from the system clock.
48
void
updateProperties
(
INDI::DefaultDevice
*
device
,
bool
connected)
49
{
50
if
(connected)
51
{
52
m_OffsetDays = 0;
53
device
->defineProperty(TimeTP);
54
}
55
else
56
device
->deleteProperty(TimeTP);
57
}
58
59
// Handles a new TIME_UTC. Returns false when the property is not TIME_UTC.
60
bool
processText
(
const
char
*name,
char
*texts[],
char
*names[],
int
n)
61
{
62
if
(!TimeTP.
isNameMatch
(name))
63
return
false
;
64
65
const
char
*utc =
nullptr
;
66
const
char
*offset =
nullptr
;
67
for
(
int
i = 0; i < n; i++)
68
{
69
if
(!strcmp(names[i],
"UTC"
))
70
utc = texts[i];
71
else
if
(!strcmp(names[i],
"OFFSET"
))
72
offset = texts[i];
73
}
74
75
ln_date utcDate;
76
if
(utc ==
nullptr
||
extractISOTime
(utc, &utcDate) == -1)
77
{
78
TimeTP.
setState
(
IPS_ALERT
);
79
TimeTP.
apply
(
"Date/Time is invalid: %s."
, utc ? utc :
""
);
80
return
true
;
81
}
82
83
m_OffsetDays = ln_get_julian_day(&utcDate) - ln_get_julian_from_sys();
84
TimeTP[UTC].setText(utc);
85
if
(offset)
86
TimeTP[OFFSET].setText(offset);
87
TimeTP.
setState
(
IPS_OK
);
88
TimeTP.
apply
();
89
return
true
;
90
}
91
92
// Julian date of the simulated clock
93
double
julianDate
()
const
94
{
95
return
ln_get_julian_from_sys() + m_OffsetDays;
96
}
97
98
// Local sidereal time in hours at this longitude (degrees, east positive)
99
double
localSiderealTime
(
double
longitude)
const
100
{
101
return
range24
(ln_get_apparent_sidereal_time(
julianDate
()) + longitude / 15.0);
102
}
103
104
private
:
105
enum
{ UTC, OFFSET };
106
INDI::PropertyText
TimeTP {2};
107
// Days to add to the system clock
108
double
m_OffsetDays {0};
109
};
device
hid_device * device
Definition
activefocuser_utils.cpp:102
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition
defaultdevice.h:123
INDI::PropertyBasic::setState
void setState(IPState state)
Definition
indipropertybasic.cpp:157
INDI::PropertyBasic::apply
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
Definition
indipropertybasic.cpp:318
INDI::PropertyBasic::isNameMatch
bool isNameMatch(const char *otherName) const
Definition
indipropertybasic.cpp:255
INDI::PropertyText
Definition
indipropertytext.h:28
INDI::PropertyText::fill
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
Definition
indipropertytext.cpp:49
SimulatorClock
The SimulatorClock class is the clock of a camera simulator: the system clock, shifted to the time th...
Definition
simulator_clock.h:38
SimulatorClock::processText
bool processText(const char *name, char *texts[], char *names[], int n)
Definition
simulator_clock.h:60
SimulatorClock::updateProperties
void updateProperties(INDI::DefaultDevice *device, bool connected)
Definition
simulator_clock.h:48
SimulatorClock::julianDate
double julianDate() const
Definition
simulator_clock.h:93
SimulatorClock::initProperties
void initProperties(const char *deviceName, const char *group)
Definition
simulator_clock.h:40
SimulatorClock::localSiderealTime
double localSiderealTime(double longitude) const
Definition
simulator_clock.h:99
defaultdevice.h
IP_RW
@ IP_RW
Definition
indiapi.h:184
IPS_ALERT
@ IPS_ALERT
Definition
indiapi.h:162
IPS_IDLE
@ IPS_IDLE
Definition
indiapi.h:159
IPS_OK
@ IPS_OK
Definition
indiapi.h:160
range24
double range24(double r)
range24 Limits a number to be between 0-24 range.
Definition
indicom.c:1311
indicom.h
Implementations for common driver routines.
extractISOTime
int extractISOTime(const char *timestr, struct ln_date *iso_date)
Extract ISO 8601 time and store it in a tm struct.
indipropertytext.h
Generated on Thu Oct 22 2026 14:46:47 for Instrument Neutral Distributed Interface INDI by
1.9.8