From 7c1131317483091d2b55efc578fd7ffac3d0a9c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nils=20Forss=C3=A9n?= Date: Fri, 14 Jun 2024 23:44:49 +0200 Subject: [PATCH] added logging library --- CMakeLists.txt | 8 +++++--- README.md | 4 ++-- lib/spdlog | 1 + processes/CMakeLists.txt | 2 ++ processes/click_reader/CMakeLists.txt | 7 +++++++ processes/click_reader/main.cpp | 7 +++++++ processes/udp_server/CMakeLists.txt | 8 ++++++++ {src => processes/udp_server}/main.cpp | 10 ++++++++-- py/cam_stream_web.py | 6 +++--- run.sh | 2 +- src/CMakeLists.txt | 7 ------- src/include/test.h | 1 - 12 files changed, 44 insertions(+), 19 deletions(-) create mode 160000 lib/spdlog create mode 100644 processes/CMakeLists.txt create mode 100644 processes/click_reader/CMakeLists.txt create mode 100644 processes/click_reader/main.cpp create mode 100755 processes/udp_server/CMakeLists.txt rename {src => processes/udp_server}/main.cpp (93%) delete mode 100755 src/CMakeLists.txt delete mode 100755 src/include/test.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 74538e1..45e3975 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,9 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.11) project(client VERSION 0.1.0 LANGUAGES CXX) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) -add_subdirectory(src) -add_subdirectory(lib/mavlink) \ No newline at end of file +add_subdirectory(lib/mavlink) +add_subdirectory(lib/spdlog) + +add_subdirectory(processes) \ No newline at end of file diff --git a/README.md b/README.md index aece5e7..db237f6 100755 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ Enable fan pin 20 through raspi-config ``` -sudo apt install -y cmake build-essential checkinstall zlib1g-dev libssl-dev python3 python3-pip ninja-build git ufw python3-picamera2 --no-install-recommends +sudo apt install -y cmake build-essential checkinstall zlib1g-dev libssl-dev python3 python3-pip ninja-build git ufw python3-picamera2 --no-install-recommends libspdlog-dev ``` based a bit on example [this is my link](https://github.com/mavlink/mavlink/blob/master/examples/c/udp_example.c) +also want to create mavlink base server using mavproxy ufw for firewall -sudo ufw allow 1234, 14550, 14551 \ No newline at end of file diff --git a/lib/spdlog b/lib/spdlog new file mode 160000 index 0000000..c3aed4b --- /dev/null +++ b/lib/spdlog @@ -0,0 +1 @@ +Subproject commit c3aed4b68373955e1cc94307683d44dca1515d2b diff --git a/processes/CMakeLists.txt b/processes/CMakeLists.txt new file mode 100644 index 0000000..3e7fc10 --- /dev/null +++ b/processes/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(udp_server) +add_subdirectory(click_reader) \ No newline at end of file diff --git a/processes/click_reader/CMakeLists.txt b/processes/click_reader/CMakeLists.txt new file mode 100644 index 0000000..7ba0848 --- /dev/null +++ b/processes/click_reader/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(click_reader + main.cpp +) + +target_include_directories(click_reader PRIVATE include) + +target_link_libraries(click_reader PRIVATE MAVLink) \ No newline at end of file diff --git a/processes/click_reader/main.cpp b/processes/click_reader/main.cpp new file mode 100644 index 0000000..17edc53 --- /dev/null +++ b/processes/click_reader/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char* argv[]) +{ + printf("Hello, World!\n"); + return 0; +} \ No newline at end of file diff --git a/processes/udp_server/CMakeLists.txt b/processes/udp_server/CMakeLists.txt new file mode 100755 index 0000000..070e2cb --- /dev/null +++ b/processes/udp_server/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(upd_server + main.cpp +) + +target_include_directories(upd_server PRIVATE include) + +target_link_libraries(upd_server PRIVATE MAVLink) +target_link_libraries(upd_server PRIVATE spdlog::spdlog) diff --git a/src/main.cpp b/processes/udp_server/main.cpp similarity index 93% rename from src/main.cpp rename to processes/udp_server/main.cpp index 391aa97..032e04c 100755 --- a/src/main.cpp +++ b/processes/udp_server/main.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include @@ -25,7 +27,7 @@ void send_heartbeat(int socket_fd, const struct sockaddr_in* src_addr, socklen_t int main(int argc, char* argv[]) { // Open UDP socket - const int socket_fd = socket(PF_INET, SOCK_DGRAM, 0); + const int socket_fd = socket(AF_INET, SOCK_DGRAM, 0); if (socket_fd < 0) { printf("socket error: %s\n", strerror(errno)); @@ -37,7 +39,7 @@ int main(int argc, char* argv[]) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; inet_pton(AF_INET, "0.0.0.0", &(addr.sin_addr)); // listen on all network interfaces - addr.sin_port = htons(14550); // default port on the ground + addr.sin_port = htons(14552); // default port on the ground if (bind(socket_fd, (struct sockaddr*)(&addr), sizeof(addr)) != 0) { printf("bind error: %s\n", strerror(errno)); @@ -66,6 +68,7 @@ int main(int argc, char* argv[]) if (src_addr_set) { send_some(socket_fd, &src_addr, src_addr_len); + printf("sent some\n"); } } @@ -102,6 +105,9 @@ void receive_some(int socket_fd, struct sockaddr_in* src_addr, socklen_t* src_ad case MAVLINK_MSG_ID_HEARTBEAT: handle_heartbeat(&message); break; + default: + printf("Received message %d from %d/%d\n", message.msgid, message.sysid, message.compid); + break; } } } diff --git a/py/cam_stream_web.py b/py/cam_stream_web.py index 1b427d0..9e63d51 100755 --- a/py/cam_stream_web.py +++ b/py/cam_stream_web.py @@ -15,15 +15,15 @@ from picamera2.outputs import FileOutput PAGE = """\ -picamera2 MJPEG streaming demo -

Picamera2 MJPEG Streaming Demo

""" +# viewable with http://192.168.0.197:8000/stream.mjpg + class StreamingOutput(io.BufferedIOBase): def __init__(self): self.frame = None @@ -81,7 +81,7 @@ class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer): picam2 = Picamera2() -picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)})) +picam2.configure(picam2.create_video_configuration(main={"size": (1920, 1080)}, controls={"FrameDurationLimits": (33333, 33333)})) output = StreamingOutput() picam2.start_recording(MJPEGEncoder(), FileOutput(output)) diff --git a/run.sh b/run.sh index 72c9097..fee9765 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ #!/usr/bin/bash cd $(dirname "$0")/bin -./client \ No newline at end of file +./udp_server \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100755 index 37c58d9..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_executable(client - main.cpp -) - -target_include_directories(client PRIVATE include) - -target_link_libraries(client PUBLIC MAVLink) diff --git a/src/include/test.h b/src/include/test.h deleted file mode 100755 index 34889fd..0000000 --- a/src/include/test.h +++ /dev/null @@ -1 +0,0 @@ -#include \ No newline at end of file -- 2.30.2