Pi-XPlane-FMC-CDU
FMCManager.h
1 /*
2  This file is part of Pi-XPlane-FMC-CDU
3  A Raspberry Pi-based External FMC for XPlane
4 
5  Copyright (C) 2017-2018 shahada abubakar
6  <shahada@abubakar.net>
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
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.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <https://www.gnu.org/licenses/>.
20 
21  */
22 
23 #ifndef FMCMANAGER_H_
24 #define FMCMANAGER_H_
25 
26 #include <stdlib.h>
27 #include <time.h>
28 
29 
30 #include <XPlaneUDPClient.h>
31 #include <syslog.h>
32 
33 #include "AbstractFMC.h"
34 #include "SplashFMC.h"
35 #include "MainFMC.h"
36 
37 #include <XPlaneExtPlaneClient/ExtPlaneClient.h>
38 
43 class FMCManager {
44 private:
45  // private so it cannot be called publicly
46  FMCManager();
47 
48  // private so it cannot be called publicly
49  FMCManager(FMCManager const &) {};
50 
51 
52  // assignment operator is private too
53  FMCManager & operator =(FMCManager const &) {
54  abort();
55  }
56 
57  AbstractFMC * currentFMC;
58 
59  // here are our utility FMCs
60  SplashFMC * splashFMC;
61  MainFMC * mainFMC;
62 
63 
64  // actual FMCS go here
65  std::map<std::string, AbstractFMC *> actualFMCs;
66 
67 
68 protected:
69  static FMCManager * instance;
70 
72  time_t timeStarted;
73 
74  virtual ~FMCManager();
75 
76  void drawCenteredText(int line, std::string text);
77  void splash();
78  void setCurrentFMC(AbstractFMC * fmc);
79 
88  std::string currentConnection;
89 
93  XPlaneExtPlaneClient::ExtPlaneClient * xplaneConnection;
94 
99  time_t clearKeyPressTime = 0;
100 
101 public:
102  // @brief return pointer to the singleton instance
103  static FMCManager * getInstance() {
104  if (!instance) {
105  instance = new FMCManager();
106  };
107  return instance;
108  }
109 
110  void keyPressEvent(int row, int col);
111  void keyReleaseEvent(int row, int col);
112 
117  void tick();
118 
119  void gotoSplashFMC() {
120  setCurrentFMC(splashFMC);
121  }
122 
123  void gotoMainFMC() {
124  setCurrentFMC(mainFMC);
125  }
126 
127  void XPlaneBeaconListener(XPlaneBeaconListener::XPlaneServer server,
128  bool exists);
129 
130 
143  void connectToServer(std::string host, int port);
144 
145 
151  void receiveDataFromServer(std::string type, std::string dataref, std::string value);
152 
153 
154 
155 
161  void onExtPlaneConnect ();
162 
163 
168  void onExtPlaneDisconnect ();
169 
170 
176  void subscribeDataRef (std::string dataref, float accuracy = 0);
177 
178 
184  void unsubscribeDataRef (std::string dataref);
185 
190  void setDataRef (std::string dataref, std::string value);
191 
200  void setCurrentFMC(std::string fmc);
201 
202 
205  std::vector<std::string> getActualFMCList ();
206 
208  void sendCommand (std::string cmd);
209 
210 };
211 
212 #endif /* FMCMANAGER_H_ */
213 
Definition: AbstractFMC.h:28
void onExtPlaneConnect()
called when server connected.
Definition: FMCManager.cpp:271
void receiveDataFromServer(std::string type, std::string dataref, std::string value)
callback from network client
Definition: FMCManager.cpp:165
time_t clearKeyPressTime
track time when CLR was pressed.
Definition: FMCManager.h:99
void connectToServer(std::string host, int port)
connect to the server
Definition: FMCManager.cpp:138
std::string currentConnection
tracker for current server we&#39;re connected to.
Definition: FMCManager.h:88
void onExtPlaneDisconnect()
called when server disconnected.
Definition: FMCManager.cpp:282
time_t timeStarted
time when the FMCManager was created
Definition: FMCManager.h:72
Manages "current" screen by channelling data and keypresses to a FMC Handler.
Definition: FMCManager.h:43
void sendCommand(std::string cmd)
send CMD to current server
Definition: FMCManager.cpp:240
Definition: SplashFMC.h:29
std::vector< std::string > getActualFMCList()
gets names of actual FMCs
Definition: FMCManager.cpp:259
Definition: MainFMC.h:30
void setDataRef(std::string dataref, std::string value)
set dataref on the server
Definition: FMCManager.cpp:229
void tick()
called once every second by Screen&#39;s mainloop
Definition: FMCManager.cpp:101
XPlaneExtPlaneClient::ExtPlaneClient * xplaneConnection
our "connection" to the server
Definition: FMCManager.h:93
void unsubscribeDataRef(std::string dataref)
unsubscribe from a dataref from the current server
Definition: FMCManager.cpp:219
void subscribeDataRef(std::string dataref, float accuracy=0)
subscribe to a dataref from the current server
Definition: FMCManager.cpp:204