MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
ISSTracker.h
Go to the documentation of this file.
1/*
2 MetaImGUI
3 Copyright (C) 2026 A P Nicholson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <atomic>
22#include <deque>
23#include <functional>
24#include <memory>
25#include <mutex>
26#include <stop_token>
27#include <string>
28#include <thread>
29
30namespace MetaImGUI {
31
32// ISS position data structure
34 double latitude = 0.0;
35 double longitude = 0.0;
36 double altitude = 0.0; // km
37 double velocity = 0.0; // km/h
38 long timestamp = 0; // Unix timestamp
39 bool valid = false;
40};
41
52public:
53 ISSTracker();
55
56 // Disable copy and move
57 ISSTracker(const ISSTracker&) = delete;
58 ISSTracker& operator=(const ISSTracker&) = delete;
61
66 void StartTracking(std::function<void(const ISSPosition&)> callback = nullptr);
67
71 void StopTracking();
72
76 bool IsTracking() const;
77
82
88 void GetPositionHistory(std::vector<double>& latitudes, std::vector<double>& longitudes) const;
89
93 size_t GetMaxHistorySize() const {
94 return m_maxHistorySize;
95 }
96
101
102private:
103 // API endpoint
104 static constexpr const char* ISS_API_URL = "https://api.wheretheiss.at/v1/satellites/25544";
105
106 // Maximum number of historical positions to store
107 static constexpr size_t m_maxHistorySize = 100;
108
109 // Current position and history
110 ISSPosition m_currentPosition;
111 std::deque<ISSPosition> m_positionHistory;
112 mutable std::mutex m_dataMutex;
113
114 // Threading
115 std::atomic<bool> m_tracking;
116 std::jthread m_trackingThread;
117 mutable std::mutex m_threadMutex;
118
119 // Callback (protected by m_callbackMutex)
120 std::function<void(const ISSPosition&)> m_callback;
121 mutable std::mutex m_callbackMutex;
122
123 // Internal methods
124 void TrackingLoop(const std::stop_token& stopToken);
125 ISSPosition FetchPositionImpl();
126 std::string FetchJSON(const std::string& url);
127 ISSPosition ParseJSON(const std::string& jsonResponse);
128 void AddToHistory(const ISSPosition& position);
129};
130
131} // namespace MetaImGUI
ISS Tracker that fetches ISS position data asynchronously.
Definition ISSTracker.h:51
ISSTracker & operator=(ISSTracker &&)=delete
void GetPositionHistory(std::vector< double > &latitudes, std::vector< double > &longitudes) const
Get position history for orbit trail (thread-safe)
ISSTracker(ISSTracker &&)=delete
size_t GetMaxHistorySize() const
Get the maximum number of positions stored in history.
Definition ISSTracker.h:93
ISSPosition GetCurrentPosition() const
Get the current ISS position (thread-safe)
void StopTracking()
Stop tracking.
ISSTracker & operator=(const ISSTracker &)=delete
void StartTracking(std::function< void(const ISSPosition &)> callback=nullptr)
Start tracking ISS position asynchronously.
bool IsTracking() const
Check if tracking is active.
ISSPosition FetchPositionSync()
Manually fetch ISS position once (synchronous)
ISSTracker(const ISSTracker &)=delete