Skip to content

Commit

Permalink
Merge pull request #701 from ut-issl/feature/add-namespace
Browse files Browse the repository at this point in the history
namespaceの追加
  • Loading branch information
200km authored Oct 2, 2024
2 parents 1cab569 + a4b50bc commit a74da28
Show file tree
Hide file tree
Showing 343 changed files with 2,835 additions and 1,756 deletions.
9 changes: 7 additions & 2 deletions src/components/base/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

#include "component.hpp"

Component::Component(const unsigned int prescaler, ClockGenerator* clock_generator, const unsigned int fast_prescaler)
namespace s2e::components {

Component::Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, const unsigned int fast_prescaler)
: clock_generator_(clock_generator) {
power_port_ = new PowerPort();
clock_generator_->RegisterComponent(this);
prescaler_ = (prescaler > 0) ? prescaler : 1;
fast_prescaler_ = (fast_prescaler > 0) ? fast_prescaler : 1;
}

Component::Component(const unsigned int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const unsigned int fast_prescaler)
Component::Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port,
const unsigned int fast_prescaler)
: clock_generator_(clock_generator), power_port_(power_port) {
clock_generator_->RegisterComponent(this);
prescaler_ = (prescaler > 0) ? prescaler : 1;
Expand Down Expand Up @@ -48,3 +51,5 @@ void Component::FastTick(const unsigned int fast_count) {
PowerOffRoutine();
}
}

} // namespace s2e::components
16 changes: 10 additions & 6 deletions src/components/base/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "interface_tickable.hpp"

namespace s2e::components {

/**
* @class Component
* @brief Base class for component emulation. All components have to inherit this.
Expand All @@ -27,7 +29,7 @@ class Component : public ITickable {
* @param [in] clock_generator: Clock generator
* @param [in] fast_prescaler: Frequency scale factor for fast update (used only for component faster than component update period)
*/
Component(const unsigned int prescaler, ClockGenerator* clock_generator, const unsigned int fast_prescaler = 1);
Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, const unsigned int fast_prescaler = 1);
/**
* @fn Component
* @brief Constructor with power port
Expand All @@ -36,7 +38,7 @@ class Component : public ITickable {
* @param [in] power_port: Power port
* @param [in] fast_prescaler: Frequency scale factor for fast update (used only for component faster than component update period)
*/
Component(const unsigned int prescaler, ClockGenerator* clock_generator, PowerPort* power_port, const unsigned int fast_prescaler = 1);
Component(const unsigned int prescaler, environment::ClockGenerator* clock_generator, PowerPort* power_port, const unsigned int fast_prescaler = 1);
/**
* @fn Component
* @brief Copy constructor
Expand Down Expand Up @@ -76,16 +78,18 @@ class Component : public ITickable {
* @brief Pure virtual function used to calculate high-frequency disturbances(e.g. RW jitter)
* @note Override only when high-frequency disturbances need to be calculated.
*/
virtual void FastUpdate(){};
virtual void FastUpdate() {};

/**
* @fn PowerOffRoutine
* @brief Pure virtual function executed when the power switch is off.
*/
virtual void PowerOffRoutine(){};
virtual void PowerOffRoutine() {};

ClockGenerator* clock_generator_; //!< Clock generator
PowerPort* power_port_; //!< Power port
environment::ClockGenerator* clock_generator_; //!< Clock generator
PowerPort* power_port_; //!< Power port
};

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_COMPONENT_HPP_
4 changes: 4 additions & 0 deletions src/components/base/gpio_connection_with_obc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "gpio_connection_with_obc.hpp"

namespace s2e::components {

GpioConnectionWithObc::GpioConnectionWithObc(const std::vector<int> port_id, OnBoardComputer* obc) : port_id_(port_id), obc_(obc) {
for (size_t i = 0; i < port_id_.size(); i++) {
obc_->GpioConnectPort(port_id_[i]);
Expand All @@ -17,3 +19,5 @@ GpioConnectionWithObc::~GpioConnectionWithObc() {}
bool GpioConnectionWithObc::Read(const int index) { return obc_->GpioComponentRead(port_id_[index]); }

void GpioConnectionWithObc::Write(const int index, const bool is_high) { obc_->GpioComponentWrite(port_id_[index], is_high); }

} // namespace s2e::components
4 changes: 4 additions & 0 deletions src/components/base/gpio_connection_with_obc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "../real/cdh/on_board_computer.hpp"

namespace s2e::components {

/**
* @class GpioConnectionWithObc
* @brief Base class for GPIO communication with OBC flight software
Expand Down Expand Up @@ -50,4 +52,6 @@ class GpioConnectionWithObc {
OnBoardComputer* obc_; //!< The communication target OBC
};

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_GPIO_CONNECTION_WITH_OBC_HPP_
6 changes: 5 additions & 1 deletion src/components/base/i2c_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include <iostream>
#include <utilities/macros.hpp>

namespace s2e::components {

I2cController::I2cController(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size,
const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager)
const unsigned int rx_buffer_size, simulation::HilsPortManager* hils_port_manager)
: hils_port_id_(hils_port_id),
baud_rate_(baud_rate),
tx_buffer_size_(tx_buffer_size),
Expand Down Expand Up @@ -48,3 +50,5 @@ int I2cController::SendCommand(const unsigned char length) {
if (simulation_mode_ != SimulationMode::kHils) return -1;
return hils_port_manager_->I2cControllerSend(hils_port_id_, &tx_buffer_.front(), 0, length);
}

} // namespace s2e::components
8 changes: 6 additions & 2 deletions src/components/base/i2c_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "../../simulation/hils/hils_port_manager.hpp"
#include "uart_communication_with_obc.hpp"

namespace s2e::components {

/**
* @class I2cController
* @brief This class simulates the I2C Controller communication with the I2C Target.
Expand All @@ -28,7 +30,7 @@ class I2cController {
* @param [in] hils_port_manager: HILS port manager
*/
I2cController(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size, const unsigned int rx_buffer_size,
HilsPortManager* hils_port_manager);
simulation::HilsPortManager* hils_port_manager);
/**
* @fn ~I2cController
* @brief Destructor
Expand Down Expand Up @@ -61,7 +63,9 @@ class I2cController {
unsigned int rx_buffer_size_; //!< RX (Target to Controller) buffer size
SimulationMode simulation_mode_ = SimulationMode::kError; //!< Simulation mode (SILS or HILS)

HilsPortManager* hils_port_manager_; //!< HILS port manager
simulation::HilsPortManager* hils_port_manager_; //!< HILS port manager
};

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_I2C_CONTROLLER_HPP_
8 changes: 6 additions & 2 deletions src/components/base/i2c_target_communication_with_obc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <iostream>

namespace s2e::components {

I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int sils_port_id, const unsigned char i2c_address, OnBoardComputer* obc)
: sils_port_id_(sils_port_id), i2c_address_(i2c_address), obc_(obc) {
#ifdef USE_HILS
Expand All @@ -18,7 +20,7 @@ I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int
}

I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int hils_port_id, const unsigned char i2c_address,
HilsPortManager* hils_port_manager)
simulation::HilsPortManager* hils_port_manager)
: hils_port_id_(hils_port_id), i2c_address_(i2c_address), hils_port_manager_(hils_port_manager) {
#ifdef USE_HILS
simulation_mode_ = SimulationMode::kHils;
Expand All @@ -34,7 +36,7 @@ I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int

I2cTargetCommunicationWithObc::I2cTargetCommunicationWithObc(const unsigned int sils_port_id, const unsigned int hils_port_id,
const unsigned char i2c_address, OnBoardComputer* obc,
HilsPortManager* hils_port_manager)
simulation::HilsPortManager* hils_port_manager)
: sils_port_id_(sils_port_id), hils_port_id_(hils_port_id), i2c_address_(i2c_address), obc_(obc), hils_port_manager_(hils_port_manager) {
#ifdef USE_HILS
simulation_mode_ = SimulationMode::kHils;
Expand Down Expand Up @@ -163,3 +165,5 @@ int I2cTargetCommunicationWithObc::StoreTelemetry(const unsigned int stored_fram
}
return 0;
}

} // namespace s2e::components
12 changes: 8 additions & 4 deletions src/components/base/i2c_target_communication_with_obc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "../real/cdh/on_board_computer.hpp"
#include "uart_communication_with_obc.hpp"

namespace s2e::components {

/**
* @class I2cTargetCommunicationWithObc
* @brief Base class for I2C communication as target side with OBC flight software
Expand All @@ -32,7 +34,7 @@ class I2cTargetCommunicationWithObc {
* @param [in] i2c_address: I2C address for the target
* @param [in] hils_port_manager: HILS port manager
*/
I2cTargetCommunicationWithObc(const unsigned int hils_port_id, const unsigned char i2c_address, HilsPortManager* hils_port_manager);
I2cTargetCommunicationWithObc(const unsigned int hils_port_id, const unsigned char i2c_address, simulation::HilsPortManager* hils_port_manager);
/**
* @fn I2cTargetCommunicationWithObc
* @brief Constructor for both SILS and HILS mode
Expand All @@ -43,7 +45,7 @@ class I2cTargetCommunicationWithObc {
* @param [in] hils_port_manager: HILS port manager
*/
I2cTargetCommunicationWithObc(const unsigned int sils_port_id, const unsigned int hils_port_id, const unsigned char i2c_address,
OnBoardComputer* obc, HilsPortManager* hils_port_manager);
OnBoardComputer* obc, simulation::HilsPortManager* hils_port_manager);
/**
* @fn I2cTargetCommunicationWithObc
* @brief Prevent double freeing of memory when this class is copied
Expand Down Expand Up @@ -117,8 +119,10 @@ class I2cTargetCommunicationWithObc {

SimulationMode simulation_mode_ = SimulationMode::kError; //!< Simulation mode

OnBoardComputer* obc_; //!< Communication target OBC
HilsPortManager* hils_port_manager_; //!< HILS port manager
OnBoardComputer* obc_; //!< Communication target OBC
simulation::HilsPortManager* hils_port_manager_; //!< HILS port manager
};

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_I2C_TARGET_COMMUNICATION_WITH_OBC_HPP_
6 changes: 5 additions & 1 deletion src/components/base/interface_gpio_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_
#define S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_

namespace s2e::components {

/**
* @class IGPIOCompo
* @brief Interface class for components which have GPIO port
Expand All @@ -16,7 +18,7 @@ class IGPIOCompo {
* @fn ~IGPIOCompo
* @brief Destructor
*/
virtual ~IGPIOCompo(){};
virtual ~IGPIOCompo() {};

/**
* @fn GpioStateChanged
Expand All @@ -27,4 +29,6 @@ class IGPIOCompo {
virtual void GpioStateChanged(const int port_id, const bool is_positive_edge) = 0;
};

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_CLASSES_INTERFACE_GPIO_COMPONENT_HPP_
4 changes: 4 additions & 0 deletions src/components/base/interface_tickable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_
#define S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_

namespace s2e::components {

/**
* @class ITickable
* @brief Interface class for time update of components
Expand Down Expand Up @@ -40,4 +42,6 @@ class ITickable {
bool needs_fast_update_ = false; //!< Whether or not high-frequency disturbances need to be calculated
};

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_CLASSES_INTERFACE_TICKABLE_HPP_
6 changes: 5 additions & 1 deletion src/components/base/sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <math_physics/randomization/normal_randomization.hpp>
#include <math_physics/randomization/random_walk.hpp>

namespace s2e::components {

/**
* @class Sensor
* @brief Base class for sensor emulation to add noises
Expand Down Expand Up @@ -56,7 +58,7 @@ class Sensor {
math::Vector<N> range_to_const_c_; //!< Output range limit to be constant output value at the component frame
math::Vector<N> range_to_zero_c_; //!< Output range limit to be zero output value at the component frame
randomization::NormalRand normal_random_noise_c_[N]; //!< Normal random
RandomWalk<N> random_walk_noise_c_; //!< Random Walk
randomization::RandomWalk<N> random_walk_noise_c_; //!< Random Walk

/**
* @fn Clip
Expand Down Expand Up @@ -85,6 +87,8 @@ template <size_t N>
Sensor<N> ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name,
const std::string unit = "");

} // namespace s2e::components

#include "./sensor_template_functions.hpp"

#endif // S2E_COMPONENTS_BASE_SENSOR_HPP_
8 changes: 6 additions & 2 deletions src/components/base/sensor_template_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <math_physics/randomization/global_randomization.hpp>
#include <setting_file_reader/initialize_file_access.hpp>

namespace s2e::components {

template <size_t N>
Sensor<N>::Sensor(const math::Matrix<N, N>& scale_factor, const math::Vector<N>& range_to_const_c, const math::Vector<N>& range_to_zero_c,
const math::Vector<N>& bias_noise_c, const math::Vector<N>& normal_random_standard_deviation_c,
Expand All @@ -20,7 +22,7 @@ Sensor<N>::Sensor(const math::Matrix<N, N>& scale_factor, const math::Vector<N>&
range_to_zero_c_(range_to_zero_c),
random_walk_noise_c_(random_walk_step_width_s, random_walk_standard_deviation_c, random_walk_limit_c) {
for (size_t i = 0; i < N; i++) {
normal_random_noise_c_[i].SetParameters(0.0, normal_random_standard_deviation_c[i], global_randomization.MakeSeed());
normal_random_noise_c_[i].SetParameters(0.0, normal_random_standard_deviation_c[i], randomization::global_randomization.MakeSeed());
}
RangeCheck();
}
Expand Down Expand Up @@ -77,7 +79,7 @@ void Sensor<N>::RangeCheck(void) {

template <size_t N>
Sensor<N> ReadSensorInformation(const std::string file_name, const double step_width_s, const std::string component_name, const std::string unit) {
IniAccess ini_file(file_name);
setting_file_reader::IniAccess ini_file(file_name);
std::string section = "SENSOR_BASE_" + component_name;

math::Vector<N * N> scale_factor_vector;
Expand Down Expand Up @@ -121,4 +123,6 @@ Sensor<N> ReadSensorInformation(const std::string file_name, const double step_w
return sensor_base;
}

} // namespace s2e::components

#endif // S2E_COMPONENTS_BASE_SENSOR_TEMPLATE_FUNCTIONS_HPP_
11 changes: 8 additions & 3 deletions src/components/base/uart_communication_with_obc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <iostream>

namespace s2e::components {

UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int sils_port_id, OnBoardComputer* obc) : sils_port_id_(sils_port_id), obc_(obc) {
#ifdef USE_HILS
simulation_mode_ = SimulationMode::kError;
Expand All @@ -33,7 +35,8 @@ UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int sils_port_
InitializeObcComBase();
}

UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, HilsPortManager* hils_port_manager)
UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate,
simulation::HilsPortManager* hils_port_manager)
: hils_port_id_(hils_port_id), baud_rate_(baud_rate), hils_port_manager_(hils_port_manager) {
#ifdef USE_HILS
simulation_mode_ = SimulationMode::kHils;
Expand All @@ -47,7 +50,7 @@ UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_
}

UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_id, const unsigned int baud_rate, const unsigned int tx_buffer_size,
const unsigned int rx_buffer_size, HilsPortManager* hils_port_manager)
const unsigned int rx_buffer_size, simulation::HilsPortManager* hils_port_manager)
: hils_port_id_(hils_port_id),
baud_rate_(baud_rate),
tx_buffer_size_(tx_buffer_size),
Expand All @@ -65,7 +68,7 @@ UartCommunicationWithObc::UartCommunicationWithObc(const unsigned int hils_port_
}

UartCommunicationWithObc::UartCommunicationWithObc(const int sils_port_id, OnBoardComputer* obc, const unsigned int hils_port_id,
const unsigned int baud_rate, HilsPortManager* hils_port_manager)
const unsigned int baud_rate, simulation::HilsPortManager* hils_port_manager)
: sils_port_id_(sils_port_id), hils_port_id_(hils_port_id), baud_rate_(baud_rate), obc_(obc), hils_port_manager_(hils_port_manager) {
#ifdef USE_HILS
simulation_mode_ = SimulationMode::kHils;
Expand Down Expand Up @@ -173,3 +176,5 @@ int UartCommunicationWithObc::SendTelemetry(const unsigned int offset) {
return -1;
}
}

} // namespace s2e::components
Loading

0 comments on commit a74da28

Please sign in to comment.