5 XCSoar Glide Computer - http://www.xcsoar.org/
6 Copyright (C) 2000-2013 The XCSoar Project
7 A detailed list of copyright holders can be found in the file "AUTHORS".
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "Device/Simulator.hpp"
27 #include "Device/Parser.hpp"
28 #include "NMEA/Info.hpp"
29 #include "NMEA/InputLine.hpp"
30 #include "NMEA/Checksum.hpp"
31 #include "../Simulator.hpp"
32 #include "OS/Clock.hpp"
34 #include "Geo/Math.hpp"
39 Simulator::Init(NMEAInfo
&basic
)
41 /* just in case DeviceBlackboard::SetStartupLocation never gets
42 called, set some dummy values that are better than uninitialised
45 basic
.location
= GeoPoint::Zero();
46 basic
.track
= Angle::Zero();
47 basic
.ground_speed
= fixed(0);
48 basic
.gps_altitude
= fixed(0);
49 basic
.date_available
= true;
53 * This function creates some simulated traffic for FLARM debugging
54 * @param GPS_INFO Pointer to the NMEA_INFO struct
57 Simulator::GenerateFLARMTraffic(NMEAInfo
&basic
)
68 const Angle angle
= Angle::FullCircle() * i
/ 255;
69 Angle dangle
= (angle
+ Angle::Degrees(120)).AsBearing();
70 Angle hangle
= dangle
.Flipped().AsBearing();
72 int alt
= (angle
.ifastsine()) / 7;
73 int north
= (angle
.ifastsine()) / 2 - 200;
74 int east
= (angle
.ifastcosine()) / 1.5;
75 int track
= -(int)angle
.AsBearing().Degrees();
76 unsigned alarm_level
= (i
% 30 > 13 ? 0 : (i
% 30 > 5 ? 2 : 1));
78 NMEAParser
parser(true);
81 // PFLAA,<AlarmLevel>,<RelativeNorth>,<RelativeEast>,<RelativeVertical>,
82 // <IDType>,<ID>,<Track>,<TurnRate>,<GroundSpeed>,<ClimbRate>,<AcftType>
83 sprintf(buffer
, "$PFLAA,%d,%d,%d,%d,2,DDA85C,%d,0,35,0,1",
84 alarm_level
, north
, east
, alt
, track
);
85 parser
.ParseLine(buffer
, basic
);
87 alt
= (angle
.ifastcosine()) / 10;
88 north
= (dangle
.ifastsine()) / 1.20 + 300;
89 east
= (dangle
.ifastcosine()) + 500;
90 track
= (int)hangle
.Degrees();
92 // PFLAA,<AlarmLevel>,<RelativeNorth>,<RelativeEast>,<RelativeVertical>,
93 // <IDType>,<ID>,<Track>,<TurnRate>,<GroundSpeed>,<ClimbRate>,<AcftType>
94 sprintf(buffer
, "$PFLAA,0,%d,%d,%d,2,AA9146,,,,,1",
96 parser
.ParseLine(buffer
, basic
);
98 // PFLAU,<RX>,<TX>,<GPS>,<Power>,<AlarmLevel>,<RelativeBearing>,<AlarmType>,
99 // <RelativeVertical>,<RelativeDistance>(,<ID>)
100 sprintf(buffer
, "$PFLAU,2,1,2,1,%d", alarm_level
);
101 parser
.ParseLine(buffer
, basic
);
105 Simulator::Touch(NMEAInfo
&basic
)
107 assert(is_simulator());
110 basic
.alive
.Update(basic
.clock
);
111 basic
.gps
.simulator
= true;
112 basic
.gps
.real
= false;
114 basic
.location_available
.Update(basic
.clock
);
115 basic
.track_available
.Update(basic
.clock
);
116 basic
.ground_speed_available
.Update(basic
.clock
);
117 basic
.gps_altitude_available
.Update(basic
.clock
);
119 basic
.time_available
.Update(basic
.clock
);
120 basic
.time
+= fixed(1);
121 basic
.date_time_utc
= basic
.date_time_utc
+ 1;
125 Simulator::Process(NMEAInfo
&basic
)
127 assert(is_simulator());
131 basic
.location
= FindLatitudeLongitude(basic
.location
, basic
.track
,
134 // use this to test FLARM parsing/display
135 if (IsDebug() && !IsAltair())
136 GenerateFLARMTraffic(basic
);