Instrument Neutral Distributed Interface INDI 2.2.5
gps_simulator.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2015 Jasem Mutlaq. All rights reserved.
3
4 Simple GPS Simulator
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#include "gps_simulator.h"
26
27#include <memory>
28#include <ctime>
29
30// We declare an auto pointer to GPSSimulator.
31std::unique_ptr<GPSSimulator> gpsSimulator(new GPSSimulator());
32
38
40{
41 return (const char *)"GPS Simulator";
42}
43
45{
46 return true;
47}
48
50{
51 return true;
52}
53
55{
57
58 // Location property must be RW.
59 LocationNP.fill(m_DefaultDevice->getDeviceName(), "GEOGRAPHIC_COORD", "Location",
61
62 // Original default values.
63 LocationNP[LOCATION_LATITUDE].setValue(51.0);
64 LocationNP[LOCATION_LONGITUDE].setValue(357.7);
65 LocationNP[LOCATION_ELEVATION].setValue(72);
66
67 return true;
68}
69
70bool GPSSimulator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
71{
72 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
73 {
74 if (LocationNP.isNameMatch(name))
75 {
76 LocationNP.update(values, names, n);
79 LOG_INFO("Values are updated and should be active on the next GPS update.");
80
81 return true;
82 }
83 }
84
85 return INDI::GPS::ISNewNumber(dev, name, values, names, n);
86}
87
88
90{
91 static char ts[32] = {0};
92 struct tm *utc, *local;
93
94 time_t raw_time;
95 time(&raw_time);
96
97 m_GPSTime = raw_time;
98
99 utc = gmtime(&raw_time);
100 strftime(ts, sizeof(ts), "%Y-%m-%dT%H:%M:%S", utc);
101 TimeTP[0].setText(ts);
102
103 local = localtime(&raw_time);
104 snprintf(ts, sizeof(ts), "%4.2f", (local->tm_gmtoff / 3600.0));
105 TimeTP[1].setText(ts);
106
108
110
111 return IPS_OK;
112}
113
115{
117 LocationNP.save(fp);
118
119 return true;
120}
The GPSSimulator class provides a simple simulator that provide GPS Time and Location services.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save refresh period
virtual IPState updateGPS() override
updateGPS Retrieve Location & Time from GPS. Update LocationNP & TimeTP properties (value and state) ...
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
const char * getDefaultName() override
bool Disconnect() override
Disconnect from device.
const char * getDeviceName() const
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.
INDI::PropertyNumber LocationNP
DefaultDevice * m_DefaultDevice
INDI::PropertyText TimeTP
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition indigps.cpp:88
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
Definition indigps.cpp:43
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save refresh period
Definition indigps.cpp:102
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
bool update(const double values[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
std::unique_ptr< GPSSimulator > gpsSimulator(new GPSSimulator())
@ IP_RW
Definition indiapi.h:184
IPState
Property state.
Definition indiapi.h:158
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
#define LOG_INFO(txt)
Definition indilogger.h:74
#define getDeviceName