From f29e4072ff28b227fc6deeb38ded1757928fae75 Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Mon, 9 Oct 2023 18:44:18 +0300 Subject: [PATCH] add diff pressure --- Udral/airspeed.cpp | 20 ++++++++++++++++++++ Udral/airspeed.hpp | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Udral/airspeed.cpp create mode 100644 Udral/airspeed.hpp diff --git a/Udral/airspeed.cpp b/Udral/airspeed.cpp new file mode 100644 index 0000000..f52d227 --- /dev/null +++ b/Udral/airspeed.cpp @@ -0,0 +1,20 @@ +/// This software is distributed under the terms of the MIT License. +/// Copyright (c) 2023 Dmitry Ponomarev. +/// Author: Dmitry Ponomarev + +#include "airspeed.hpp" +#include "main.h" +#include "params.hpp" + +void DiffPressurePublisher::publish(float pressure) { + uavcan_si_sample_pressure_Scalar_1_0 msg; + msg.pascal = pressure; + msg.timestamp.microsecond = 0; + + static uint8_t buffer[uavcan_si_sample_pressure_Scalar_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_]; + size_t buffer_size = uavcan_si_sample_pressure_Scalar_1_0_SERIALIZATION_BUFFER_SIZE_BYTES_; + int32_t result = uavcan_si_sample_pressure_Scalar_1_0_serialize_(&msg, buffer, &buffer_size); + if (NUNAVUT_SUCCESS == result) { + push(buffer_size, buffer); + } +} diff --git a/Udral/airspeed.hpp b/Udral/airspeed.hpp new file mode 100644 index 0000000..4eb8696 --- /dev/null +++ b/Udral/airspeed.hpp @@ -0,0 +1,17 @@ +/// This software is distributed under the terms of the MIT License. +/// Copyright (c) 2023 Dmitry Ponomarev. +/// Author: Dmitry Ponomarev + +#ifndef UDRAL_AIRSPEED_HPP_ +#define UDRAL_AIRSPEED_HPP_ + +#include "cyphal.hpp" +#include "uavcan/si/sample/pressure/Scalar_1_0.h" + +struct DiffPressurePublisher: public CyphalPublisher { + DiffPressurePublisher(Cyphal* driver_, CanardPortID port_id) : CyphalPublisher(driver_, port_id) {}; + void publish(float pressure); +}; + + +#endif // UDRAL_AIRSPEED_HPP_