diff --git a/CMakeLists.txt b/CMakeLists.txt index 07850a8b5ec88a9efc3c68736ecacaa79bee2b2e..58c4bfdb4ab5cda9616abb1f9f89f73ff485a2c0 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 0000000000000000000000000000000000000000..4c8b5ef5aaac0530aa918a5f477fdb31690655ef --- /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)); +}