draw aircraft

This commit is contained in:
2026-08-05 13:05:30 +02:00
parent 25824ac2f9
commit 704126fd3f
10 changed files with 66 additions and 7 deletions
+1 -1
View File
@@ -2,5 +2,5 @@ build*
.cache .cache
.vscode .vscode
src/core/config.hpp src/core/config.hpp
readsb readsb*
compile_commands.json compile_commands.json
+9 -4
View File
@@ -10,6 +10,11 @@ set(BUILD_DOCUMENTATION OFF CACHE BOOL "" FORCE)
set(BUILD_BOTH_LIBRARIES OFF CACHE BOOL "" FORCE) set(BUILD_BOTH_LIBRARIES OFF CACHE BOOL "" FORCE)
set(PACKAGE_DEBIAN OFF CACHE BOOL "" FORCE) set(PACKAGE_DEBIAN OFF CACHE BOOL "" FORCE)
# Automatically collect core sources and platform-specific HAL files
file(GLOB CORE_SOURCES CONFIGURE_DEPENDS "src/core/*.cpp" "src/core/*.c")
file(GLOB HAL_PICO_SOURCES CONFIGURE_DEPENDS "src/hal/*_pico.cpp")
file(GLOB HAL_LINUX_SOURCES CONFIGURE_DEPENDS "src/hal/*_linux.cpp")
if(BUILD_FOR_PICO) if(BUILD_FOR_PICO)
set(PICO_BOARD pico_w CACHE STRING "Board type") set(PICO_BOARD pico_w CACHE STRING "Board type")
include(pico_sdk_import.cmake) include(pico_sdk_import.cmake)
@@ -25,8 +30,8 @@ if(BUILD_FOR_PICO)
add_executable(p-rad add_executable(p-rad
src/main.cpp src/main.cpp
src/core/logic.cpp ${CORE_SOURCES}
src/hal/hal_pico.cpp ${HAL_PICO_SOURCES}
) )
target_compile_definitions(p-rad PRIVATE PICO_BUILD) target_compile_definitions(p-rad PRIVATE PICO_BUILD)
@@ -47,8 +52,8 @@ else()
add_executable(p-rad add_executable(p-rad
src/main.cpp src/main.cpp
src/core/logic.cpp ${CORE_SOURCES}
src/hal/hal_linux.cpp ${HAL_LINUX_SOURCES}
) )
target_include_directories(p-rad PRIVATE src) target_include_directories(p-rad PRIVATE src)
+1
View File
@@ -4,3 +4,4 @@ constexpr char* user_agent = "p-rad/0.1";
#define ARRAY_LENGHT(arr) sizeof(arr) / sizeof(arr[0])
+16
View File
@@ -0,0 +1,16 @@
#include <GeographicLib/Geodesic.hpp>
#include <cmath>
#include <tuple>
#include "global.hpp"
std::tuple<float, float> get_offset_from_station(double lat, double lon) {
const GeographicLib::Geodesic &geod = GeographicLib::Geodesic::WGS84();
double distance, azi1, azi2;
geod.Inverse(receiver_lat, receiver_lon, lat, lon, distance, azi1,
azi2);
double azi_rad = azi1 * M_PI / 180.0;
return {static_cast<float>(distance * std::sin(azi_rad)),static_cast<float>(-distance * std::cos(azi_rad))};
}
+3
View File
@@ -0,0 +1,3 @@
#pragma once
#include <tuple>
std::tuple<float, float> get_offset_from_station(double lat, double lon);
+2
View File
@@ -0,0 +1,2 @@
float receiver_lat;
float receiver_lon;
+3
View File
@@ -0,0 +1,3 @@
#pragma once
extern float receiver_lat;
extern float receiver_lon;
+1
View File
@@ -18,4 +18,5 @@ struct rect_t {
void pixel(const uint16_t x, const uint16_t y, const color_t color); void pixel(const uint16_t x, const uint16_t y, const color_t color);
void filled_rect(const rect_t* rect, const color_t color); void filled_rect(const rect_t* rect, const color_t color);
void circle(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color); void circle(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color);
void rhombus(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color);
} }
+7
View File
@@ -142,6 +142,13 @@ void circle(const uint16_t x_center, const uint16_t y_center,const uint16_t radi
} }
} }
} }
void rhombus(const uint16_t x_center, const uint16_t y_center,const uint16_t radius, const color_t color) {
SDL_SetRenderDrawColor(main_sdl_session.renderer, color.r, color.g, color.b,
0xff);
const SDL_FPoint points[] = {{static_cast<float>(x_center+radius),static_cast<float>(y_center)},{static_cast<float>(x_center),static_cast<float>(y_center+radius)},{static_cast<float>(x_center-radius),static_cast<float>(y_center)},{static_cast<float>(x_center),static_cast<float>(y_center-radius)},{static_cast<float>(x_center+radius),static_cast<float>(y_center)}};
SDL_RenderLines(main_sdl_session.renderer, points, ARRAY_LENGHT(points));
}
} // namespace draw } // namespace draw
namespace net { namespace net {
+23 -2
View File
@@ -10,6 +10,8 @@
#include <cstdio> #include <cstdio>
#include <format> #include <format>
#include <iostream> #include <iostream>
#include "core/global.hpp"
#include "core/geo.hpp"
int main() { int main() {
if (hal::init() != 0) { if (hal::init() != 0) {
@@ -24,8 +26,6 @@ int main() {
const uint16_t middle_x = (screen_w / 2); const uint16_t middle_x = (screen_w / 2);
const uint16_t middle_y = (screen_h / 2); const uint16_t middle_y = (screen_h / 2);
float receiver_lat;
float receiver_lon;
{ {
nlohmann::json receiver = nlohmann::json receiver =
net::http_get_json(std::format("{}/receiver.json", base_url)); net::http_get_json(std::format("{}/receiver.json", base_url));
@@ -72,6 +72,27 @@ int main() {
} }
} }
{ // draw planes
nlohmann::json aircraft = net::http_get_json(std::format("{}/aircraft.json", base_url));
if (aircraft!= nullptr) {
for(nlohmann::json &craft : aircraft["aircraft"]) {
try {
const auto [x_offset,y_offset] = get_offset_from_station(craft["lat"].get<double>(), craft["lon"].get<double>());
const uint16_t x_center = middle_x+((x_offset/1000)*pixels_per_km);
const uint16_t y_center = middle_y+((y_offset/1000)*pixels_per_km);
draw::pixel(x_center, y_center, {0xff,0x68,0x00});
draw::rhombus(x_center, y_center, 8/*TODO: remove magic*/,{0xff,0x68,0x00});
} catch(...) {
std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n";
}
}
} else {
// TODO draw vizual error
std::cerr << RED"[ERROR]" RESET " failed to get aircraft\n";
}
}
hal::end_frame(); hal::end_frame();
} }
} }