Skip to content

Commit

Permalink
Merge pull request #14 from dspace-group/CodeCleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
ACanisLupus authored Sep 17, 2024
2 parents b350388 + d5ce91a commit d305d9e
Show file tree
Hide file tree
Showing 47 changed files with 527 additions and 639 deletions.
88 changes: 48 additions & 40 deletions include/DsVeosCoSim/DsVeosCoSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,55 @@
/**
* \brief Defines the maximum length of a CAN message payload.
*/
#define DSVEOSCOSIM_CAN_MESSAGE_MAX_LENGTH 64
enum {
DSVEOSCOSIM_CAN_MESSAGE_MAX_LENGTH = 64
};

/**
* \brief Defines the maximum length of an ethernet message payload.
*/
#define DSVEOSCOSIM_ETH_MESSAGE_MAX_LENGTH 9018
enum {
DSVEOSCOSIM_ETH_MESSAGE_MAX_LENGTH = 9018
};

/**
* \brief Defines the maximum length of a LIN message payload.
*/
#define DSVEOSCOSIM_LIN_MESSAGE_MAX_LENGTH 8
enum {
DSVEOSCOSIM_LIN_MESSAGE_MAX_LENGTH = 8
};

/**
* \brief Defines the maximum length of an ethernet address (MAC address).
*/
#define DSVEOSCOSIM_ETH_ADDRESS_LENGTH 6
enum {
DSVEOSCOSIM_ETH_ADDRESS_LENGTH = 6
};

/**
* \brief Represents a handle to be used for communicating with a dSPACE VEOS CoSim server.
*/
typedef void* DsVeosCoSim_Handle;
typedef void* DsVeosCoSim_Handle; // NOLINT

/**
* \brief Represents an IO signal id.
*/
typedef uint32_t DsVeosCoSim_IoSignalId;
typedef uint32_t DsVeosCoSim_IoSignalId; // NOLINT

/**
* \brief Represents a bus controller id.
*/
typedef uint32_t DsVeosCoSim_BusControllerId;
typedef uint32_t DsVeosCoSim_BusControllerId; // NOLINT

/**
* \brief Represents the simulation time in nanoseconds.
*/
typedef int64_t DsVeosCoSim_SimulationTime;
typedef int64_t DsVeosCoSim_SimulationTime; // NOLINT

/**
* \brief Represents a result of a function.
*/
typedef enum DsVeosCoSim_Result {
typedef enum DsVeosCoSim_Result { // NOLINT
/**
* \brief Will be returned if the API function was successful.
*/
Expand All @@ -101,7 +109,7 @@ typedef enum DsVeosCoSim_Result {
DsVeosCoSim_Result_Error,

/**
* \brief Will be returned if the receive API function found an empty buffer.
* \brief Will be returned if the reception API function found an empty buffer.
*/
DsVeosCoSim_Result_Empty,

Expand All @@ -126,7 +134,7 @@ typedef enum DsVeosCoSim_Result {
/**
* \brief Represents a command for the non-blocking API.
*/
typedef enum DsVeosCoSim_Command {
typedef enum DsVeosCoSim_Command { // NOLINT
/**
* \brief No command.
*/
Expand Down Expand Up @@ -168,7 +176,7 @@ typedef enum DsVeosCoSim_Command {
/**
* \brief Represents the severity of a log message.
*/
typedef enum DsVeosCoSim_Severity {
typedef enum DsVeosCoSim_Severity { // NOLINT
/**
* \brief Error message.
*/
Expand All @@ -195,7 +203,7 @@ typedef enum DsVeosCoSim_Severity {
/**
* \brief Represents the reason of a simulation termination.
*/
typedef enum DsVeosCoSim_TerminateReason {
typedef enum DsVeosCoSim_TerminateReason { // NOLINT
/**
* \brief Simulation finished successfully.
*/
Expand All @@ -212,7 +220,7 @@ typedef enum DsVeosCoSim_TerminateReason {
/**
* \brief Represents the connection state.
*/
typedef enum DsVeosCoSim_ConnectionState {
typedef enum DsVeosCoSim_ConnectionState { // NOLINT
/**
* \brief Disconnected.
*/
Expand All @@ -229,7 +237,7 @@ typedef enum DsVeosCoSim_ConnectionState {
/**
* \brief Represents the data type of IO signal.
*/
typedef enum DsVeosCoSim_DataType {
typedef enum DsVeosCoSim_DataType { // NOLINT
/**
* \brief Boolean. Underlying data type is uint8. 0 is equal to false, != 0 is equal to true.
*/
Expand Down Expand Up @@ -291,7 +299,7 @@ typedef enum DsVeosCoSim_DataType {
/**
* \brief Represents the size kind of IO signal.
*/
typedef enum DsVeosCoSim_SizeKind {
typedef enum DsVeosCoSim_SizeKind { // NOLINT
/**
* \brief The IO signal size is fixed.
*/
Expand All @@ -308,7 +316,7 @@ typedef enum DsVeosCoSim_SizeKind {
/**
* \brief Represents an IO signal.
*/
typedef struct DsVeosCoSim_IoSignal { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_IoSignal { // NOLINT
/**
* \brief Unique id of the IO signal.
*/
Expand Down Expand Up @@ -339,7 +347,7 @@ typedef struct DsVeosCoSim_IoSignal { // NOLINT(readability-identifier-naming)
/**
* \brief Represents a CAN controller.
*/
typedef struct DsVeosCoSim_CanController { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_CanController { // NOLINT
/**
* \brief Unique id of the CAN controller.
*/
Expand Down Expand Up @@ -379,7 +387,7 @@ typedef struct DsVeosCoSim_CanController { // NOLINT(readability-identifier-nam
/**
* \brief Underlying data type of the flags of a CAN message.
*/
typedef uint32_t DsVeosCoSim_CanMessageFlags;
typedef uint32_t DsVeosCoSim_CanMessageFlags; // NOLINT

/**
* \brief Represents the flags of a CAN message.
Expand Down Expand Up @@ -425,7 +433,7 @@ enum {
/**
* \brief Represents a CAN message.
*/
typedef struct DsVeosCoSim_CanMessage { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_CanMessage { // NOLINT
/**
* \brief The simulation time when the CAN message was received.
* For received messages only.
Expand Down Expand Up @@ -461,7 +469,7 @@ typedef struct DsVeosCoSim_CanMessage { // NOLINT(readability-identifier-naming
/**
* \brief Represents an ethernet controller.
*/
typedef struct DsVeosCoSim_EthController { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_EthController { // NOLINT
/**
* \brief Unique id of the ethernet controller.
*/
Expand Down Expand Up @@ -501,7 +509,7 @@ typedef struct DsVeosCoSim_EthController { // NOLINT(readability-identifier-nam
/**
* \brief Underlying data type of the flags of an ethernet message.
*/
typedef uint32_t DsVeosCoSim_EthMessageFlags;
typedef uint32_t DsVeosCoSim_EthMessageFlags; // NOLINT

/**
* \brief Represents the flags of an ethernet message.
Expand Down Expand Up @@ -529,7 +537,7 @@ enum {
/**
* \brief Represents an ethernet message.
*/
typedef struct DsVeosCoSim_EthMessage { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_EthMessage { // NOLINT
/**
* \brief The simulation time when the ethernet message was received.
* For received messages only.
Expand Down Expand Up @@ -565,7 +573,7 @@ typedef struct DsVeosCoSim_EthMessage { // NOLINT(readability-identifier-naming
/**
* \brief Represents the type of the LIN controller.
*/
typedef enum DsVeosCoSim_LinControllerType {
typedef enum DsVeosCoSim_LinControllerType { // NOLINT
/**
* \brief LIN controller is a responder.
*/
Expand All @@ -582,7 +590,7 @@ typedef enum DsVeosCoSim_LinControllerType {
/**
* \brief Represents an LIN controller.
*/
typedef struct DsVeosCoSim_LinController { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_LinController { // NOLINT
/**
* \brief Unique id of the LIN controller.
*/
Expand Down Expand Up @@ -622,7 +630,7 @@ typedef struct DsVeosCoSim_LinController { // NOLINT(readability-identifier-nam
/**
* \brief Underlying data type of the flags of a LIN message.
*/
typedef uint32_t DsVeosCoSim_LinMessageFlags;
typedef uint32_t DsVeosCoSim_LinMessageFlags; // NOLINT

/**
* \brief Represents the flags of a LIN message.
Expand Down Expand Up @@ -704,7 +712,7 @@ enum {
/**
* \brief Represents a LIN message.
*/
typedef struct DsVeosCoSim_LinMessage { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_LinMessage { // NOLINT
/**
* \brief The simulation time when the LIN message was received.
* For received messages only.
Expand Down Expand Up @@ -742,22 +750,22 @@ typedef struct DsVeosCoSim_LinMessage { // NOLINT(readability-identifier-naming
* \param severity The severity of the message.
* \param logMessage The log message.
*/
typedef void (*DsVeosCoSim_LogCallback)(DsVeosCoSim_Severity severity, const char* logMessage);
typedef void (*DsVeosCoSim_LogCallback)(DsVeosCoSim_Severity severity, const char* logMessage); // NOLINT

/**
* \brief Represents a simulation state changed or step callback function pointer.
* \param simulationTime The current simulation time.
* \param userData The user data passed via DsVeosCoSim_SetCallbacks.
*/
typedef void (*DsVeosCoSim_SimulationCallback)(DsVeosCoSim_SimulationTime simulationTime, void* userData);
typedef void (*DsVeosCoSim_SimulationCallback)(DsVeosCoSim_SimulationTime simulationTime, void* userData); // NOLINT

/**
* \brief Represents a simulation terminated callback function pointer.
* \param simulationTime The current simulation time.
* \param reason The termination reason.
* \param userData The user data passed via DsVeosCoSim_SetCallbacks.
*/
typedef void (*DsVeosCoSim_SimulationTerminatedCallback)(DsVeosCoSim_SimulationTime simulationTime,
typedef void (*DsVeosCoSim_SimulationTerminatedCallback)(DsVeosCoSim_SimulationTime simulationTime, // NOLINT
DsVeosCoSim_TerminateReason reason,
void* userData);

Expand All @@ -769,7 +777,7 @@ typedef void (*DsVeosCoSim_SimulationTerminatedCallback)(DsVeosCoSim_SimulationT
* \param value The changed data.
* \param userData The user data passed via DsVeosCoSim_SetCallbacks.
*/
typedef void (*DsVeosCoSim_IncomingSignalChangedCallback)(DsVeosCoSim_SimulationTime simulationTime,
typedef void (*DsVeosCoSim_IncomingSignalChangedCallback)(DsVeosCoSim_SimulationTime simulationTime, // NOLINT
const DsVeosCoSim_IoSignal* incomingSignal,
uint32_t length,
const void* value,
Expand All @@ -782,7 +790,7 @@ typedef void (*DsVeosCoSim_IncomingSignalChangedCallback)(DsVeosCoSim_Simulation
* \param message The received message.
* \param userData The user data passed via DsVeosCoSim_SetCallbacks.
*/
typedef void (*DsVeosCoSim_CanMessageReceivedCallback)(DsVeosCoSim_SimulationTime simulationTime,
typedef void (*DsVeosCoSim_CanMessageReceivedCallback)(DsVeosCoSim_SimulationTime simulationTime, // NOLINT
const DsVeosCoSim_CanController* canController,
const DsVeosCoSim_CanMessage* message,
void* userData);
Expand All @@ -794,7 +802,7 @@ typedef void (*DsVeosCoSim_CanMessageReceivedCallback)(DsVeosCoSim_SimulationTim
* \param message The received message.
* \param userData The user data passed via DsVeosCoSim_SetCallbacks.
*/
typedef void (*DsVeosCoSim_EthMessageReceivedCallback)(DsVeosCoSim_SimulationTime simulationTime,
typedef void (*DsVeosCoSim_EthMessageReceivedCallback)(DsVeosCoSim_SimulationTime simulationTime, // NOLINT
const DsVeosCoSim_EthController* ethController,
const DsVeosCoSim_EthMessage* message,
void* userData);
Expand All @@ -806,15 +814,15 @@ typedef void (*DsVeosCoSim_EthMessageReceivedCallback)(DsVeosCoSim_SimulationTim
* \param message The received message.
* \param userData The user data passed via DsVeosCoSim_SetCallbacks.
*/
typedef void (*DsVeosCoSim_LinMessageReceivedCallback)(DsVeosCoSim_SimulationTime simulationTime,
typedef void (*DsVeosCoSim_LinMessageReceivedCallback)(DsVeosCoSim_SimulationTime simulationTime, // NOLINT
const DsVeosCoSim_LinController* linController,
const DsVeosCoSim_LinMessage* message,
void* userData);

/**
* \brief Represents the callbacks that will be fired during the co-simulation.
*/
typedef struct DsVeosCoSim_Callbacks { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_Callbacks { // NOLINT
/**
* \brief Will be called when the simulation started in dSPACE VEOS.
*/
Expand Down Expand Up @@ -858,34 +866,34 @@ typedef struct DsVeosCoSim_Callbacks { // NOLINT(readability-identifier-naming)
/**
* \brief Will be called when a CAN message was received from dSPACE VEOS.
* If this callback is registered, then DsVeosCoSim_ReceiveCanMessage will always return
* DsVeosCoSim_Result_Empty.
* DsVeosCoSim_Result_Empty.
*/
DsVeosCoSim_CanMessageReceivedCallback canMessageReceivedCallback;

/**
* \brief Will be called when an ethernet message was received from dSPACE VEOS.
* If this callback is registered, then DsVeosCoSim_ReceiveEthMessage will always return
* DsVeosCoSim_Result_Empty.
* DsVeosCoSim_Result_Empty.
*/
DsVeosCoSim_EthMessageReceivedCallback ethMessageReceivedCallback;

/**
* \brief Will be called when a LIN message was received from dSPACE VEOS.
* If this callback is registered, then DsVeosCoSim_ReceiveLinMessage will always return
* DsVeosCoSim_Result_Empty.
* DsVeosCoSim_Result_Empty.
*/
DsVeosCoSim_LinMessageReceivedCallback linMessageReceivedCallback;

/**
* \brief An arbitrary object the will be passed to every callback.
* \brief An arbitrary object that will be passed to every callback.
*/
void* userData;
} DsVeosCoSim_Callbacks;

/**
* \brief Represents the data that will be used for establishing the connection.
*/
typedef struct DsVeosCoSim_ConnectConfig { // NOLINT(readability-identifier-naming)
typedef struct DsVeosCoSim_ConnectConfig { // NOLINT
/**
* \brief The IP address of the dSPACE VEOS CoSim server. "127.0.0.1" if not specified.
*/
Expand Down
2 changes: 1 addition & 1 deletion shared/BackgroundService.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BackgroundService final {
~BackgroundService() noexcept;

BackgroundService(const BackgroundService&) = delete;
BackgroundService& operator=(BackgroundService const&) = delete;
BackgroundService& operator=(const BackgroundService&) = delete;

BackgroundService(BackgroundService&&) = delete;
BackgroundService& operator=(BackgroundService&&) = delete;
Expand Down
1 change: 0 additions & 1 deletion shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_library(
STATIC
BackgroundService.cpp
ClientServerTestHelper.cpp
CoSimServerWrapper.cpp
Generator.cpp
Helper.cpp
LogHelper.cpp
Expand Down
2 changes: 1 addition & 1 deletion shared/ClientServerTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool IsSendingLinMessagesEnabled() {
return g_sendLinMessages;
}

bool SendSomeData(DsVeosCoSim::SimulationTime simulationTime, const RunTimeInfo& runTimeInfo) {
bool SendSomeData(DsVeosCoSim_SimulationTime simulationTime, const RunTimeInfo& runTimeInfo) {
static int64_t lastHalfSecond = -1;
static int64_t counter = 0;
const int64_t currentHalfSecond = simulationTime / 500000000;
Expand Down
4 changes: 2 additions & 2 deletions shared/ClientServerTestHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct RunTimeInfo {
std::vector<DsVeosCoSim::LinController> linControllers;
std::vector<DsVeosCoSim::IoSignal> incomingSignals;
std::vector<DsVeosCoSim::IoSignal> outgoingSignals;
std::function<void(DsVeosCoSim::IoSignalId signalId, uint32_t length, const void* value)> write;
std::function<void(DsVeosCoSim_IoSignalId signalId, uint32_t length, const void* value)> write;
std::function<bool(const DsVeosCoSim_CanMessage& message)> transmitCan;
std::function<bool(const DsVeosCoSim_EthMessage& message)> transmitEth;
std::function<bool(const DsVeosCoSim_LinMessage& message)> transmitLin;
Expand All @@ -29,4 +29,4 @@ bool IsSendingCanMessagesEnabled();
bool IsSendingEthMessagesEnabled();
bool IsSendingLinMessagesEnabled();

[[nodiscard]] bool SendSomeData(DsVeosCoSim::SimulationTime simulationTime, const RunTimeInfo& runTimeInfo);
[[nodiscard]] bool SendSomeData(DsVeosCoSim_SimulationTime simulationTime, const RunTimeInfo& runTimeInfo);
Loading

0 comments on commit d305d9e

Please sign in to comment.