Instrument Neutral Distributed Interface INDI  2.0.2
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.
31 std::unique_ptr<GPSSimulator> gpsSimulator(new GPSSimulator());
32 
34 {
35  setVersion(1, 0);
37 }
38 
40 {
41  return (const char *)"GPS Simulator";
42 }
43 
45 {
46  return true;
47 }
48 
50 {
51  return true;
52 }
53 
55 {
56  static char ts[32] = {0};
57  struct tm *utc, *local;
58 
59  time_t raw_time;
60  time(&raw_time);
61 
62  utc = gmtime(&raw_time);
63  strftime(ts, sizeof(ts), "%Y-%m-%dT%H:%M:%S", utc);
64  TimeTP[0].setText(ts);
65 
66  local = localtime(&raw_time);
67  snprintf(ts, sizeof(ts), "%4.2f", (local->tm_gmtoff / 3600.0));
68  TimeTP[1].setText(ts);
69 
71 
72  LocationNP[LOCATION_LATITUDE].value = 51.0;
73  LocationNP[LOCATION_LONGITUDE].value = 357.7;
74  LocationNP[LOCATION_ELEVATION].value = 72;
75 
77 
78  return IPS_OK;
79 }
The GPSSimulator class provides a simple simulator that provide GPS Time and Location services.
Definition: gps_simulator.h:35
IPState updateGPS()
updateGPS Retrieve Location & Time from GPS. Update LocationNP & TimeTP properties (value and state) ...
bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
const char * getDefaultName()
bool Disconnect()
Disconnect from device.
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
@ LOCATION_LONGITUDE
Definition: indigps.h:53
@ LOCATION_LATITUDE
Definition: indigps.h:52
@ LOCATION_ELEVATION
Definition: indigps.h:54
INDI::PropertyNumber LocationNP
Definition: indigps.h:93
INDI::PropertyText TimeTP
Definition: indigps.h:96
void setState(IPState state)
std::unique_ptr< GPSSimulator > gpsSimulator(new GPSSimulator())
IPState
Property state.
Definition: indiapi.h:160
@ IPS_OK
Definition: indiapi.h:162