android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / src / Blackboard / DeviceBlackboard.hpp
blobd79cc87f1bab0755c38883f18af881c5b3154400
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef DEVICE_BLACKBOARD_H
25 #define DEVICE_BLACKBOARD_H
27 #include "Blackboard/BaseBlackboard.hpp"
28 #include "Blackboard/ComputerSettingsBlackboard.hpp"
29 #include "Device/Simulator.hpp"
30 #include "Device/List.hpp"
31 #include "Thread/Mutex.hpp"
33 #include <cassert>
35 class AtmosphericPressure;
36 class OperationEnvironment;
38 /**
39 * Blackboard used by com devices: can write NMEA_INFO, reads DERIVED_INFO.
40 * Also provides methods to emulate device updates e.g. from logger replay
42 * The DeviceBlackboard is used as the global ground truth-state
43 * since it is accessed quickly with only one mutex
45 class DeviceBlackboard:
46 public BaseBlackboard,
47 public ComputerSettingsBlackboard
49 friend class MergeThread;
51 Simulator simulator;
53 /**
54 * Data from each physical device.
56 NMEAInfo per_device_data[NUMDEV];
58 /**
59 * Merged data from the physical devices.
61 NMEAInfo real_data;
63 /**
64 * Data from simulator.
66 NMEAInfo simulator_data;
68 /**
69 * Data from replay.
71 NMEAInfo replay_data;
73 public:
74 Mutex mutex;
76 public:
77 DeviceBlackboard();
78 void ReadBlackboard(const DerivedInfo &derived_info);
79 void ReadComputerSettings(const ComputerSettings &settings);
81 protected:
82 NMEAInfo &SetBasic() { return gps_info; }
83 MoreData &SetMoreData() { return gps_info; }
85 public:
86 const NMEAInfo &RealState(unsigned i) const {
87 assert(i < NUMDEV);
88 return per_device_data[i];
91 NMEAInfo &SetRealState(unsigned i) {
92 assert(i < NUMDEV);
93 return per_device_data[i];
96 NMEAInfo &SetSimulatorState() { return simulator_data; }
97 NMEAInfo &SetReplayState() { return replay_data; }
99 public:
100 const NMEAInfo &RealState() const { return real_data; }
103 * Is the specified device a FLARM?
105 * This method does not lock the blackboard, it is unprotected. It
106 * is assumed that this method is not important enough to implement
107 * proper locking.
109 gcc_pure
110 bool IsFLARM(unsigned i) const {
111 return RealState(i).flarm.IsDetected();
114 void SetStartupLocation(const GeoPoint &loc, const fixed alt);
115 void ProcessSimulation();
116 void StopReplay();
118 void SetSimulatorLocation(const GeoPoint &location);
119 void SetTrack(Angle val);
120 void SetSpeed(fixed val);
121 void SetAltitude(fixed alt);
123 void SetBallast(fixed fraction, fixed overload,
124 OperationEnvironment &env);
125 void SetBugs(fixed bugs, OperationEnvironment &env);
126 void SetQNH(AtmosphericPressure qnh, OperationEnvironment &env);
127 void SetMC(fixed mc, OperationEnvironment &env);
130 * Check the expiry time of the device connection with the wall
131 * clock time. This method locks the blackboard, i.e. it may be
132 * called from any thread.
134 * @return true if the connection has just expired, false if the
135 * connection status has not changed
137 void ExpireWallClock();
140 * Trigger the MergeThread, which will call Merge(). Call this
141 * after a modification. The caller doesn't need to hold the lock.
143 void ScheduleMerge();
146 * Copy real_data or simulator_data or replay_data to gps_info.
147 * Caller must lock the blackboard.
149 void Merge();
152 #endif