Skip to content
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
38 changes: 15 additions & 23 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "C++ Bazel Podman (Native)",
"image": "ghcr.io/simba-avionic/simba_avionics_dockers/devcontainer",
"customizations": {
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack",
Expand All @@ -15,7 +15,7 @@
"ms-python.vscode-pylance",
"ms-python.vscode-python-envs"
],
"settings": {
"settings": {
"cpplint.path": "/usr/local/bin/cpplint",
"C_Cpp.default.cppStandard": "c++23",
"C_Cpp.default.cStandard": "c23",
Expand All @@ -24,38 +24,30 @@
"bsv.buildozer.executable": "/usr/local/bin/buildozer",
"doxdocgen.generic.authorName": "${localEnv:DEV_AUTHOR_NAME}",
"doxdocgen.generic.authorEmail": "${localEnv:DEV_AUTHOR_EMAIL}",
"editor.formatOnSave": true,
"[bazel]": {
"editor.defaultFormatter": "bazelbuild.vscode-bazel"
}
}
}
},
"runArgs": [
"--userns=keep-id",
"--security-opt", "label=disable"
"--security-opt",
"label=disable"
],
"mounts": [
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached",
"source=bazel-cache-${localWorkspaceFolderBasename},target=/home/vscode/.cache,type=volume"
],

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode",
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "vscode",
"remoteEnv": {
"DEV_AUTHOR_NAME": "${localEnv:DEV_AUTHOR_NAME}",
"DEV_AUTHOR_EMAIL": "${localEnv:DEV_AUTHOR_EMAIL}"
}
}
}
39 changes: 21 additions & 18 deletions apps/ec/env_service/env_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,31 @@ int EnvService::Initialize(const std::map<ara::core::StringView, ara::core::Stri
ara::log::LogError() << "Failed to load temperature configuration";
return core::ErrorCode::kInitializeError;
}
// eeprom::EEPROM_config cfg{};
// cfg.pca9685_XO_corelation = 1.0429;
// strncpy(cfg.board_temp1_id, "000010787a1b", sizeof(cfg.board_temp1_id));
// strncpy(cfg.board_temp2_id, "00001078e1cf", sizeof(cfg.board_temp2_id));
// strncpy(cfg.board_temp3_id, "000010794c9a", sizeof(cfg.board_temp3_id));
// if (config.SetConfig(cfg) != core::ErrorCode::kOk) {
// ara::log::LogError() << "cant set eeprom";
// } else {
// auto read_back = config.GetConfig();
// if (!read_back.has_value()) {
// ara::log::LogError() << "EEPROM read-back failed after SetConfig";
// } else if (std::memcmp(&read_back.value(), &cfg, sizeof(cfg)) != 0) {
// ara::log::LogError() << "EEPROM read-back mismatch after SetConfig";
// } else {
// ara::log::LogInfo() << "EEPROM SetConfig + GetConfig roundtrip OK";
// }
// }

const std::optional<eeprom::EEPROM_config> eeprom_cfg = config.GetConfig();
if (!eeprom_cfg.has_value()) {
ara::log::LogError() << "Failed to load EEPROM temperature configuration";
return core::ErrorCode::kInitializeError;
}


auto register_sensor = [&](const std::string& raw_id, const std::string& label) -> core::ErrorCode {
std::string physical_id = "28-" + raw_id;
auto sensor_id = this->temp_->Register(physical_id);
Expand All @@ -121,23 +141,6 @@ int EnvService::Initialize(const std::map<ara::core::StringView, ara::core::Stri
if (register_sensor(eeprom_cfg.value().board_temp3_id, "board_3") !=
core::ErrorCode::kOk) return core::ErrorCode::kInitializeError;

// eeprom::EEPROM_config cfg{};
// cfg.pca9685_XO_corelation = 1.038;
// strncpy(cfg.board_temp1_id, "00001110ff83", sizeof(cfg.board_temp1_id));
// strncpy(cfg.board_temp2_id, "00001110e48e", sizeof(cfg.board_temp2_id));
// strncpy(cfg.board_temp3_id, "0000107b3c59", sizeof(cfg.board_temp3_id));
// if (config.SetConfig(cfg) != core::ErrorCode::kOk) {
// ara::log::LogError() << "cant set eeprom";
// } else {
// auto read_back = config.GetConfig();
// if (!read_back.has_value()) {
// ara::log::LogError() << "EEPROM read-back failed after SetConfig";
// } else if (std::memcmp(&read_back.value(), &cfg, sizeof(cfg)) != 0) {
// ara::log::LogError() << "EEPROM read-back mismatch after SetConfig";
// } else {
// ara::log::LogInfo() << "EEPROM SetConfig + GetConfig roundtrip OK";
// }
// }
return core::ErrorCode::kOk;
}

Expand Down Expand Up @@ -199,7 +202,7 @@ void EnvService::GenericPressureLoop(

std::ostringstream ss;
ss << std::fixed << std::setprecision(2) << val;
ara::log::LogDebug() << "Receive new " << label << ": " << ss.str() << " Bar";
ara::log::LogInfo() << "Receive new " << label << ": " << ss.str() << " Bar";

uint16_t encodedVal = static_cast<uint16_t>(val * kPressure_sensor_multiplicator);
eventIpc.Update(encodedVal);
Expand Down
2 changes: 1 addition & 1 deletion apps/ec/primer_service/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int PrimerService::Run(const std::stop_token& token) {
if (gpio_.SetPinValue(kHeartBeatPinID, 1, 500) != core::ErrorCode::kOk) {
ara::log::LogWarn() << "PrimerService::Run: failed to toggle heartbeat pin";
}
// controller->VerifyPrimerConection();
controller->VerifyPrimerConection();
const auto current_state = controller->GetPrimerState();
if (current_state != last_state) {
ara::log::LogInfo() << "PrimerService::Run: primer state changed from "
Expand Down
31 changes: 13 additions & 18 deletions apps/ec/primer_service/controller/primer_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <memory>

#include "mw/gpio_server/controller/gpio_controller.hpp"
#include "core/common/error_code.h"
#include "ara/log/log.h"
#include "core/common/condition.h"
#include "core/json/json_parser.h"
Expand All @@ -29,8 +30,8 @@ namespace {
static constexpr uint16_t kIgniter_active_time = 2500;
static constexpr uint8_t kPrimer_on = 1;
static constexpr uint8_t kPrimer_off = 0;
static constexpr bool kRequire_primer_veryfication = false;
static constexpr auto kIgniter_measureme_adc_channel = 4;
static constexpr bool kRequire_primer_veryfication = true;
static constexpr auto kIgniter_measureme_adc_channel = 3;
static constexpr auto kIgniter_measurement_adc_samples = 5;
static constexpr auto kIgniter_connected_treshold_mV = 1500;

Expand Down Expand Up @@ -60,6 +61,9 @@ PrimerController::PrimerController():
}

void PrimerController::VerifyPrimerConection() {
if (!kRequire_primer_veryfication) {
return;
}
auto verify_required = [this]() {
auto primer_state = primerState.load();
return (primer_state == PrimerState_t::kUNKNOWN || primer_state == PrimerState_t::kNOT_CONNECTED ||
Expand All @@ -68,24 +72,13 @@ void PrimerController::VerifyPrimerConection() {
if (!verify_required()) {
return;
}
float sum = 0;
auto sample_num = 0;
for (int i = 0; i < kIgniter_measurement_adc_samples; i++) {
auto voltage = adc_.GetAdcVoltage(kIgniter_measureme_adc_channel);
if (!voltage.has_value()) {
continue;
}
sum += voltage.value();
sample_num += 1;
}
if (sample_num == 0) {
prim_logger.LogWarn() << "Primer verification skipped: ADC returned no valid samples";
auto voltage = adc_.GetAdcVoltage(kIgniter_measureme_adc_channel);
if (!voltage.has_value()) {
return;
}
auto mean = sum / static_cast<float>(sample_num);
const auto previous_state = primerState.load();
auto next_state = previous_state;
if (mean >= kIgniter_connected_treshold_mV) {
if (voltage.value() >= kIgniter_connected_treshold_mV / 1000.0f) {
next_state = PrimerState_t::kCONNECTED;
} else {
next_state = PrimerState_t::kNOT_CONNECTED;
Expand All @@ -95,14 +88,16 @@ void PrimerController::VerifyPrimerConection() {
if (previous_state != next_state) {
prim_logger.LogInfo() << "Primer state changed from " << PrimerStateToString(previous_state)
<< " to " << PrimerStateToString(next_state)
<< " (ADC mean: " << mean << " mV)";
<< " (ADC voltage: " << voltage.value() << " mV)";
}
}

void PrimerController::Initialize() {
prim_logger.LogInfo() << "Initializing PrimerController";
this->primerState = PrimerState_t::kUNKNOWN;
this->adc_.Init();
auto i2c = std::make_unique<srp::i2c::I2CController>();
i2c->Init(std::make_unique<com::soc::StreamIpcSocket>());
this->adc_.Init(std::move(i2c));
prim_logger.LogInfo() << "PrimerController initialization complete";
}

Expand Down
1 change: 1 addition & 0 deletions apps/fc/env_service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ cc_binary(
"//deployment/apps/fc/env_service:someip_lib",
"//mw/i2c_service/controller/bme280:bme280_controller",
"//core/json:simba_json",
"//mw/i2c_service/controller/24lc32at/eeprom_config:eeprom_config",
],
)
56 changes: 51 additions & 5 deletions apps/fc/env_service/env_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int EnvServiceFc::Initialize(const std::map<ara::core::StringView, ara::core::St
ara::log::LogError() << "app_path parameter not found in parms";
return core::ErrorCode::kInitializeError;
}

config.Init();
// Initialize pressure sensor
bme = std::make_shared<i2c::BME280>();
auto i2c = std::make_unique<i2c::I2CController>();
Expand All @@ -80,7 +80,9 @@ int EnvServiceFc::Initialize(const std::map<ara::core::StringView, ara::core::St
std::this_thread::sleep_for(std::chrono::milliseconds(500));
res = this->temp_->Initialize(kSomeIPServiceID, std::bind(&EnvServiceFc::TempRxCallback,
this, std::placeholders::_1), std::make_unique<com::soc::StreamIpcSocket>());
ara::log::LogInfo() << "Cant connect to temp by id:" << kSomeIPServiceID << ", try num: " << i;
if (res != core::ErrorCode::kOk) {
ara::log::LogInfo() << "Cant connect to temp by id:" << kSomeIPServiceID << ", try num: " << i;
}
i++;
} while (res != core::ErrorCode::kOk && i < 6);
if (res != core::ErrorCode::kOk) {
Expand All @@ -91,6 +93,49 @@ int EnvServiceFc::Initialize(const std::map<ara::core::StringView, ara::core::St
ara::log::LogError() << "Failed to load temperature configuration";
return core::ErrorCode::kInitializeError;
}
// eeprom::EEPROM_config cfg{};
// cfg.pca9685_XO_corelation = 1.0;
// strncpy(cfg.board_temp1_id, "000011106551", sizeof(cfg.board_temp1_id));
// strncpy(cfg.board_temp2_id, "00001110e419", sizeof(cfg.board_temp2_id));
// strncpy(cfg.board_temp3_id, "0000111128f8", sizeof(cfg.board_temp3_id));
// if (config.SetConfig(cfg) != core::ErrorCode::kOk) {
// ara::log::LogError() << "cant set eeprom";
// } else {
// auto read_back = config.GetConfig();
// if (!read_back.has_value()) {
// ara::log::LogError() << "EEPROM read-back failed after SetConfig";
// } else if (std::memcmp(&read_back.value(), &cfg, sizeof(cfg)) != 0) {
// ara::log::LogError() << "EEPROM read-back mismatch after SetConfig";
// } else {
// ara::log::LogWarn() << "EEPROM SetConfig + GetConfig roundtrip OK";
// }
// }

const std::optional<eeprom::EEPROM_config> eeprom_cfg = config.GetConfig();
if (!eeprom_cfg.has_value()) {
ara::log::LogError() << "Failed to load EEPROM temperature configuration";
return core::ErrorCode::kInitializeError;
}

auto register_sensor = [&](const std::string& raw_id, const std::string& label) -> core::ErrorCode {
std::string physical_id = "28-" + raw_id;
auto sensor_id = this->temp_->Register(physical_id);

if (!sensor_id.has_value()) {
ara::log::LogError() << "Sensor_id is empty for " << label;
return core::ErrorCode::kInitializeError;
}

sensorIdsToPaths[sensor_id.value()] = std::make_pair(label, physical_id);
return core::ErrorCode::kOk;
};
if (register_sensor(eeprom_cfg.value().board_temp1_id, "board_1") !=
core::ErrorCode::kOk) return core::ErrorCode::kInitializeError;
if (register_sensor(eeprom_cfg.value().board_temp2_id, "board_2") !=
core::ErrorCode::kOk) return core::ErrorCode::kInitializeError;
if (register_sensor(eeprom_cfg.value().board_temp3_id, "board_3") !=
core::ErrorCode::kOk) return core::ErrorCode::kInitializeError;

service_ipc.StartOffer();
service_udp.StartOffer();
return core::ErrorCode::kOk;
Expand Down Expand Up @@ -139,6 +184,7 @@ int EnvServiceFc::LoadTempConfig(const std::map<ara::core::StringView, ara::core

int EnvServiceFc::Run(const std::stop_token& token) {
ara::log::LogDebug() << "Leci run";
temp_->StartRxThread();

while (!token.stop_requested()) {
const auto start = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -179,11 +225,11 @@ void EnvServiceFc::TempRxCallback(const std::vector<srp::mw::temp::TempReadHdr>&
<< ", name: " << sensorName
<< ", temp: " << (static_cast<float>(value) / 10.0f);

if (sensorName == "board_temp_1") {
if (sensorName == "board_1") {
updateEvents(this->service_ipc.newBoardTempEvent_1, this->service_udp.newBoardTempEvent_1, value);
} else if (sensorName == "board_temp_2") {
} else if (sensorName == "board_2") {
updateEvents(this->service_ipc.newBoardTempEvent_2, this->service_udp.newBoardTempEvent_2, value);
} else if (sensorName == "board_temp_3") {
} else if (sensorName == "board_3") {
updateEvents(this->service_ipc.newBoardTempEvent_3, this->service_udp.newBoardTempEvent_3, value);
} else {
ara::log::LogWarn() << "ID spoza zakresu: " << hdr.actuator_id;
Expand Down
3 changes: 2 additions & 1 deletion apps/fc/env_service/env_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "ara/exec/adaptive_application.h"
#include "mw/i2c_service/controller/bme280/controller.hpp"
#include "srp/env/EnvAppFcSkeleton.h"

#include "mw/i2c_service/controller/24lc32at/eeprom_config/cfg_manager.hpp"

namespace srp {
namespace envServiceFc {
Expand All @@ -32,6 +32,7 @@ class EnvServiceFc final : public ara::exec::AdaptiveApplication {
private:
std::unique_ptr<mw::temp::TempController> temp_{};
std::shared_ptr<i2c::BME280> bme{};
eeprom::ConfigManager config;

std::unordered_map<std::uint8_t, std::pair<std::string, std::string>> sensorIdsToPaths{};
// [sensor_id] = {name, physical_id}
Expand Down
2 changes: 1 addition & 1 deletion apps/fc/radio_service/radio_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void MavRadioController::TxThreadLoop(const std::stop_token& t) {
if (!package_opt.has_value()) {
continue;
}
ara::log::LogWarn() << "Send: " << package_opt.value();
ara::log::LogDebug() << "Send: " << package_opt.value();
uart_.Write(package_opt.value());
}
}
Expand Down
12 changes: 0 additions & 12 deletions deployment/apps/fc/env_service/config.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
{
"sensors-temp": [
{
"physical_id" : "28-00001111d147",
"name" : "board_temp_1"
},
{
"physical_id" : "28-00001110f487",
"name" : "board_temp_2"
},
{
"physical_id" : "28-00001110ce32",
"name" : "board_temp_3"
}
]
}
6 changes: 3 additions & 3 deletions deployment/apps/fc/radio_app/app_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"adaptive_application": {
"RadioApp": {
"app": {
"functional_groups":[
"functional_groups": [
"Running",
"SafetyMode"
],
"parms": "",
"logger": {
"app_id": "RAD-",
"app_des": "czytanie i wysyłanie po radiu",
"log_level": "kDebug",
"log_level": "kInfo",
"log_mode": "kRemote",
"ctx": [
{
Expand Down Expand Up @@ -132,4 +132,4 @@
]
}
}
}
}
2 changes: 1 addition & 1 deletion deployment/cpu/fc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cpu_def(
srp_components = SIMBA_COMPUTER_BASE_APPS + [

# "//deployment/example_adaptive/ExampleApp",
# "//deployment/apps/fc/env_service:EnvAppFc",
"//deployment/apps/fc/env_service:EnvAppFc",
"//deployment/apps/fc/gps_app:GPSApp",
"//deployment/apps/fc/recovery_service:RecoveryService",
"//deployment/apps/fc/radio_app:RadioApp",
Expand Down
Loading