Skip to content

Added Event sending through mavlink #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ load("@srp_platform//:pip_install.bzl", "pip_install")
pip_install()


include_srp_mavlink("0.2")

include_srp_mavlink("0.3")
include_gtest_mock()
include_json("3.11.3")

Expand Down
34 changes: 34 additions & 0 deletions apps/fc/radio_service/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cc_library(
name = "radio_app_lib",
deps = [
"@srp_platform//ara/exec:adaptive_application_lib",
"@srp_mavlink//lib:mavlink_lib",
"//deployment/apps/fc/radio_app:someip_lib",
"//deployment/apps/fc/radio_app:ara",
"//core/timestamp:timestamp_controller",
"//core/uart:uart_driver",
"@srp_platform//ara/log",
],
srcs = [
"radio_app.cc",
"event_data.cc",
],
hdrs = [
"radio_app.h",
"event_data.h",
],
visibility = ["//apps/fc/radio_service:__subpackages__",],
)

cc_binary(
name = "radio_service",
srcs = [
"main.cc",
],
visibility = [
"//deployment:__subpackages__",
],
deps = [
"//apps/fc/radio_service:radio_app_lib",
],
)
111 changes: 111 additions & 0 deletions apps/fc/radio_service/event_data.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @file event_data.cc
* @author Mateusz Krajewski (matikrajek42@gmail.com)
* @brief
* @version 0.1
* @date 2025-04-26
*
* @copyright Copyright (c) 2025
*
*/
#include "apps/fc/radio_service/event_data.h"

namespace srp {
namespace apps {
namespace {
static std::shared_ptr<EventData> event_data = nullptr;
}
std::shared_ptr<EventData> EventData::GetInstance() {
if (event_data == nullptr) {
event_data = std::make_shared<EventData>();
}
return event_data;
}

template <typename T>
void EventData::SetValue(T res, T* field) {
std::unique_lock<std::shared_mutex> lock(this->mtx_);
*field = res;
}

void EventData::SetTemp1(uint16_t res) {
SetValue(res, &this->temp.temp1);
}

void EventData::SetTemp2(uint16_t res) {
SetValue(res, &this->temp.temp2);
}

void EventData::SetTemp3(uint16_t res) {
SetValue(res, &this->temp.temp3);
}

void EventData::SetDPress(float res) {
SetValue(res, &this->press.Dpressure);
}

void EventData::SetPress(float res) {
SetValue(res, &this->press.pressure);
}

void EventData::SetGPS(int32_t lon, int32_t lat) {
std::unique_lock<std::shared_mutex> lock(this->mtx_);
this->gps.lat = lat;
this->gps.lon = lon;
}

void EventData::SetActuatorBit(uint8_t res, uint8_t bit_position) {
if (bit_position > 7 || res > 1) {
return;
}
std::unique_lock<std::shared_mutex> lock(this->mtx_);
this->actuator.values =
(this->actuator.values & ~(1 << bit_position)) | (res << bit_position);
}

uint16_t EventData::GetTemp1() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->temp.temp1;
}

uint16_t EventData::GetTemp2() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->temp.temp2;
}

uint16_t EventData::GetTemp3() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->temp.temp3;
}

float EventData::GetDPress() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->press.Dpressure;
}

float EventData::GetPress() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->press.pressure;
}

int32_t EventData::GetGPSLat() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->gps.lat;
}

int32_t EventData::GetGPSLon() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->gps.lon;
}

uint8_t EventData::GetActuator() {
std::shared_lock<std::shared_mutex> lock(mtx_);
return this->actuator.values;
}

// Instancja szablonu musi być jawnie zdefiniowana w pliku .cpp
template void EventData::SetValue<uint16_t>(uint16_t, uint16_t*);
template void EventData::SetValue<float>(float, float*);

} // namespace apps
} // namespace srp
64 changes: 64 additions & 0 deletions apps/fc/radio_service/event_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file event_data.h
* @author Michał Mańkowski (m.mankowski2004@gmail.com)
* @brief
* @version 0.1
* @date 2025-05-07
*
* @copyright Copyright (c) 2025
*
*/
#ifndef APPS_FC_RADIO_SERVICE_EVENT_DATA_H_
#define APPS_FC_RADIO_SERVICE_EVENT_DATA_H_

#include <shared_mutex>
#include <mutex> // NOLINT
#include <memory>
#include <cstdint>

#include "lib/simba/mavlink.h"

namespace srp {
namespace apps {

class EventData {
private:
__mavlink_simba_tank_temperature_t temp;
__mavlink_simba_tank_pressure_t press;
__mavlink_simba_gps_t gps;
__mavlink_simba_actuator_t actuator;
std::shared_mutex mtx_;

template <typename T>
void SetValue(T res, T* field);

public:
static std::shared_ptr<EventData> GetInstance();

void SetTemp1(uint16_t res);
void SetTemp2(uint16_t res);
void SetTemp3(uint16_t res);

void SetDPress(float res);
void SetPress(float res);

void SetGPS(int32_t lon, int32_t lat);
void SetActuatorBit(uint8_t res, uint8_t bit_position);

uint16_t GetTemp1();
uint16_t GetTemp2();
uint16_t GetTemp3();

float GetDPress();
float GetPress();

int32_t GetGPSLat();
int32_t GetGPSLon();

uint8_t GetActuator();
};

} // namespace apps
} // namespace srp

#endif // APPS_FC_RADIO_SERVICE_EVENT_DATA_H_
17 changes: 17 additions & 0 deletions apps/fc/radio_service/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file main.cc
* @author Michał Mańkowski (m.mankowski2004@gmail.com)
* @brief
* @version 0.1
* @date 2025-04-07
*
* @copyright Copyright (c) 2025
*
*/
#include "apps/fc/radio_service/radio_app.h"
#include "ara/exec/adaptive_lifecycle.h"
int main(int argc, char const *argv[]) {
// setsid();
return ara::exec::RunAdaptiveLifecycle<srp::apps::RadioApp>(argc,
argv);
}
Loading