From 48446c7959e30cd34561008e70a214f067c751fc Mon Sep 17 00:00:00 2001 From: Riccardo Musso <riccardo.musso@skywarder.eu> Date: Sun, 2 Apr 2023 18:34:10 +0200 Subject: [PATCH] Implemented trivial entrypoint that transmits and receives mavlink nas_tm packets --- CMakeLists.txt | 3 + .../groundstation-nas-extractor.cpp | 76 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/entrypoints/groundstation-nas-extractor.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 07850a8b5..58c4bfdb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ sbs_target(bmx160-calibration-v3 stm32f429zi_skyward_death_stack_v3) add_executable(config-dsgamma src/entrypoints/config-dsgamma.cpp) sbs_target(config-dsgamma stm32f429zi_stm32f4discovery) +add_executable(groundstation-nas-extractor src/entrypoints/groundstation-nas-extractor.cpp) +sbs_target(groundstation-nas-extractor stm32f407vg_stm32f4discovery) + add_executable(imu-calibration src/entrypoints/imu-calibration.cpp) sbs_target(imu-calibration stm32f429zi_skyward_parafoil) diff --git a/src/entrypoints/groundstation-nas-extractor.cpp b/src/entrypoints/groundstation-nas-extractor.cpp new file mode 100644 index 000000000..4c8b5ef5a --- /dev/null +++ b/src/entrypoints/groundstation-nas-extractor.cpp @@ -0,0 +1,76 @@ +/* Copyright (c) 2023 Skyward Experimental Rocketry + * Author: Riccardo Musso + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include <drivers/usart/USART.h> +#include <mavlink_lib/pyxis/mavlink.h> +#include <radio/MavlinkDriver/MavlinkDriver.h> +#include <radio/SerialTransceiver/SerialTransceiver.h> +#include <scheduler/TaskScheduler.h> + +using namespace miosix; +using namespace Boardcore; + +using MavDriver = MavlinkDriver<20, 10>; + +void sendMessage(); +void receiveHandler(MavDriver*, const mavlink_message_t&); + +USART usart(USART1, USARTInterface::Baudrate::B115200); +SerialTransceiver transceiver(usart); +MavDriver mavlink(&transceiver, receiveHandler); +TaskScheduler scheduler; + +int main() +{ + u1rx1::mode(Mode::ALTERNATE); + u1rx1::alternateFunction(7); + u1tx1::mode(Mode::ALTERNATE); + u1tx1::alternateFunction(7); + + usart.init(); + mavlink.start(); + scheduler.start(); + + scheduler.addTask(sendMessage, 2000); + + while (true) + Thread::sleep(1000); +} + +void sendMessage() +{ + mavlink_message_t message; + mavlink_msg_nas_tm_pack(1, 1, &message, TimestampTimer::getTimestamp(), 0, + 0.75, 2.54, 120.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0); + mavlink.enqueueMsg(message); + printf("Sent message\n"); +} + +void receiveHandler(MavDriver* channel, const mavlink_message_t& msg) +{ + printf("Received message (%llu) %f %f %f\n", + mavlink_msg_nas_tm_get_timestamp(&msg), + mavlink_msg_nas_tm_get_nas_n(&msg), + mavlink_msg_nas_tm_get_nas_e(&msg), + mavlink_msg_nas_tm_get_nas_d(&msg)); +} -- GitLab