Skip to content
Open
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
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ FIND_PACKAGE(CMLIB
REQUIRED
)

SET(BRINGAUTO_MODULE_GATEWAY_VERSION 1.3.4)
SET(BRINGAUTO_MODULE_GATEWAY_VERSION 1.3.5)

SET(MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY "DEBUG" CACHE STRING "Minimum logger verbosity level for module-gateway")

CMDEF_COMPILE_DEFINITIONS(
ALL "MODULE_GATEWAY_VERSION=\"${BRINGAUTO_MODULE_GATEWAY_VERSION}\""
ALL
"MODULE_GATEWAY_VERSION=\"${BRINGAUTO_MODULE_GATEWAY_VERSION}\""
"MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY=\"${MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY}\""
)
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMDEF_LIBRARY_INSTALL_DIR}")
SET(CMAKE_CXX_STANDARD 20)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DBRINGAUTO_GET_PACKAGES_ONLY=ON

FROM bringauto/cpp-build-environment:latest AS mission_module_builder

ARG MISSION_MODULE_VERSION=v1.2.12
ARG MISSION_MODULE_VERSION=v1.2.13

# Install mission module dependencies
WORKDIR /home/bringauto/modules/
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ make
* BRINGAUTO_SYSTEM_DEP=ON/OFF
- DEFAULT: OFF

* MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY=DEBUG/INFO/WARNING/ERROR/CRITICAL
- DEFAULT: DEBUG
- sets the minimum logger verbosity on compile level to improve performance


* CURRENTLY UNUSED
* BRINGAUTO_SAMPLES=ON/OFF
Expand Down
36 changes: 31 additions & 5 deletions include/bringauto/common_utils/EnumUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <bringauto/structures/ExternalConnectionSettings.hpp>
#include <bringauto/logging/LoggerVerbosity.hpp>
#include <bringauto/settings/Constants.hpp>



Expand All @@ -24,10 +25,20 @@ class EnumUtils {
/**
* @brief Converts protocol type to string
*
* @param toEnum structures::ProtocolType
* @return std::string
* @param toString structures::ProtocolType
* @return std::string_view
*/
static std::string protocolTypeToString(structures::ProtocolType toString);
static constexpr std::string_view protocolTypeToString(structures::ProtocolType toString) {
switch(toString) {
case structures::ProtocolType::MQTT:
return settings::Constants::MQTT;
case structures::ProtocolType::DUMMY:
return settings::Constants::DUMMY;
case structures::ProtocolType::INVALID:
default:
return "";
}
};

/**
* @brief Converts string to logger verbosity
Expand All @@ -41,9 +52,24 @@ class EnumUtils {
* @brief Converts logger verbosity to string
*
* @param verbosity logging::LoggerVerbosity
* @return std::string
* @return std::string_view
*/
static std::string loggerVerbosityToString(logging::LoggerVerbosity verbosity);
static constexpr std::string_view loggerVerbosityToString(logging::LoggerVerbosity verbosity) {
switch(verbosity) {
case logging::LoggerVerbosity::Debug:
return settings::Constants::LOG_LEVEL_DEBUG;
case logging::LoggerVerbosity::Info:
return settings::Constants::LOG_LEVEL_INFO;
case logging::LoggerVerbosity::Warning:
return settings::Constants::LOG_LEVEL_WARNING;
case logging::LoggerVerbosity::Error:
return settings::Constants::LOG_LEVEL_ERROR;
case logging::LoggerVerbosity::Critical:
return settings::Constants::LOG_LEVEL_CRITICAL;
default:
return settings::Constants::LOG_LEVEL_INVALID;
}
};

};

Expand Down
16 changes: 7 additions & 9 deletions include/bringauto/common_utils/ProtobufUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <InternalProtocol.pb.h>
#include <ExternalProtocol.pb.h>
#include <fleet_protocol/common_headers/device_management.h>
#include <fleet_protocol/common_headers/memory_management.h>



Expand Down Expand Up @@ -37,7 +35,7 @@ class ProtobufUtils {
const InternalProtocol::DeviceConnectResponse_ResponseType &resType);

/**
* @brief Create a Internal Server Command message
* @brief Create an Internal Server Command message
*
* @param device Protobuf message Device
* @param command command data
Expand All @@ -47,7 +45,7 @@ class ProtobufUtils {
const modules::Buffer &command);

/**
* @brief Create a Internal Client Status message
* @brief Create an Internal Client Status message
*
* @param device Protobuf message Device
* @param status status data
Expand All @@ -67,7 +65,7 @@ class ProtobufUtils {
const modules::Buffer &status);

/**
* @brief Create a External Client Connect message
* @brief Create an External Client Connect message
*
* @param sessionId session identification
* @param company name of the company
Expand All @@ -81,7 +79,7 @@ class ProtobufUtils {
const std::vector<structures::DeviceIdentification> &devices);

/**
* @brief Create a External Client Status message
* @brief Create an External Client Status message
*
* @param sessionId session identification
* @param deviceState state of the device
Expand All @@ -97,7 +95,7 @@ class ProtobufUtils {
const modules::Buffer &errorMessage = modules::Buffer {});

/**
* @brief Create a External Client Command Response object
* @brief Create an External Client Command Response object
*
* @param sessionId session identification
* @param type command response message type
Expand All @@ -114,15 +112,15 @@ class ProtobufUtils {
* @param status status to be copied
* @param buffer buffer to copy to
*/
static void copyStatusToBuffer(const InternalProtocol::DeviceStatus &status, modules::Buffer &buffer);
static void copyStatusToBuffer(const InternalProtocol::DeviceStatus &status, const modules::Buffer &buffer);

/**
* @brief Copy command data from DeviceCommand to a Buffer
*
* @param command command to be copied
* @param buffer buffer to copy to
*/
static void copyCommandToBuffer(const InternalProtocol::DeviceCommand &command, modules::Buffer &buffer);
static void copyCommandToBuffer(const InternalProtocol::DeviceCommand &command, const modules::Buffer &buffer);

};
}
7 changes: 1 addition & 6 deletions include/bringauto/external_client/ErrorAggregator.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#pragma once

#include <bringauto/modules/ModuleManagerLibraryHandler.hpp>

#include <fleet_protocol/common_headers/memory_management.h>
#include <fleet_protocol/common_headers/device_management.h>

#include <bringauto/structures/DeviceIdentification.hpp>

#include <functional>
#include <filesystem>
#include <unordered_map>

Expand Down Expand Up @@ -108,7 +103,7 @@ class ErrorAggregator {
*
* @see fleet-protocol/lib/common_headers/include/device_management.h
*/
int is_device_type_supported(unsigned int device_type);
int is_device_type_supported(unsigned int device_type) const;

private:
struct DeviceState {
Expand Down
12 changes: 6 additions & 6 deletions include/bringauto/external_client/ExternalClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace bringauto::external_client {
class ExternalClient {
public:

ExternalClient(std::shared_ptr<structures::GlobalContext> &context,
ExternalClient(const std::shared_ptr<structures::GlobalContext> &context,
structures::ModuleLibrary &moduleLibrary,
std::shared_ptr<structures::AtomicQueue<structures::InternalClientMessage>> &toExternalQueue);
const std::shared_ptr<structures::AtomicQueue<structures::InternalClientMessage>> &toExternalQueue);

/**
* @brief Initialize connections, error aggregators
Expand Down Expand Up @@ -54,7 +54,7 @@ class ExternalClient {
void handleAggregatedMessages();

/**
* @brief Handle commands messages from from an external server
* @brief Handle commands messages from an external server
*/
void handleCommands();

Expand All @@ -68,18 +68,18 @@ class ExternalClient {
/**
* @brief Send aggregated status message to the external server
*
* @param deviceStatus aggregated status message ready to send
* @param internalMessage aggregated status message ready to send
* @return reconnect expected if true, reconnect not expected if false
*/
bool sendStatus(const structures::InternalClientMessage &deviceStatus);
bool sendStatus(const structures::InternalClientMessage &internalMessage);

bool insideConnectSequence_ { false };

/**
* @brief Map of external connections, key is number from settings
* - map is needed because of the possibility of multiple modules connected to one external server
*/
std::map<unsigned int, std::reference_wrapper<connection::ExternalConnection>> externalConnectionMap_ {};
std::unordered_map<unsigned int, std::reference_wrapper<connection::ExternalConnection>> externalConnectionMap_ {};
/// List of external connections, each device can have its own connection or multiple devices can share one connection
std::list<connection::ExternalConnection> externalConnectionsList_ {};
/// Queue for messages from module handler to external client to be sent to external server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <bringauto/structures/DeviceIdentification.hpp>
#include <bringauto/structures/ReconnectQueueItem.hpp>

#include <fleet_protocol/common_headers/general_error_codes.h>

#include <string>
#include <vector>
#include <thread>
Expand Down Expand Up @@ -72,9 +70,10 @@ class ExternalConnection {
* @brief Force aggregation on all devices in all modules that the connection services.
* Is used before the connect sequence to assure that every device has an available status to be sent
*
* @param connectedDevices
* @return number of devices
*/
std::vector<structures::DeviceIdentification> forceAggregationOnAllDevices(std::vector<structures::DeviceIdentification> connectedDevices);
std::vector<structures::DeviceIdentification> forceAggregationOnAllDevices(const std::vector<structures::DeviceIdentification> &connectedDevices);

/**
* @brief Fill error aggregator with not acknowledged status messages
Expand Down Expand Up @@ -104,11 +103,11 @@ class ExternalConnection {
* @brief Check if module type is supported
*
* @param moduleNum module type number
* @return true if moudle type is supported otherwise false
* @return true if module type is supported otherwise false
*/
bool isModuleSupported(int moduleNum);
bool isModuleSupported(int moduleNum) const;

std::vector <structures::DeviceIdentification> getAllConnectedDevices();
std::vector <structures::DeviceIdentification> getAllConnectedDevices() const;

private:

Expand Down Expand Up @@ -172,7 +171,7 @@ class ExternalConnection {
/// Class handling sent messages - timers, not acknowledged statuses etc.
std::unique_ptr <messages::SentMessagesHandler> sentMessagesHandler_ {};
/// @brief Map of error aggregators, key is module number
std::map<unsigned int, ErrorAggregator> errorAggregators_ {};
std::unordered_map<unsigned int, ErrorAggregator> errorAggregators_ {};
/// Queue of commands received from external server, commands are processed by aggregator
std::shared_ptr <structures::AtomicQueue<InternalProtocol::DeviceCommand>> commandQueue_ {};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <bringauto/external_client/connection/communication/ICommunicationChannel.hpp>



namespace bringauto::external_client::connection::communication {

/**
* @brief Dummy communication channel for testing purposes.
* Does not establish any real connection, just simulates it.
* receiveMessage always returns nullptr.
* Initialization and closing connection only changes the debug logs of sendMessage.
*/
class DummyCommunication: public ICommunicationChannel {
public:
explicit DummyCommunication(const structures::ExternalConnectionSettings &settings);

~DummyCommunication() override;

void initializeConnection() override;

bool sendMessage(ExternalProtocol::ExternalClient *message) override;

std::shared_ptr<ExternalProtocol::ExternalServer> receiveMessage() override;

void closeConnection() override;

private:
/// Flag to indicate if the fake connection is established
bool isConnected_ { false };
};

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <bringauto/structures/ExternalConnectionSettings.hpp>
#include <utility>

#include <ExternalProtocol.pb.h>

#include <utility>



namespace bringauto::external_client::connection::communication {
Expand All @@ -16,7 +15,7 @@ namespace bringauto::external_client::connection::communication {
*/
class ICommunicationChannel {
public:
explicit ICommunicationChannel(const structures::ExternalConnectionSettings &settings): settings_ { settings } {};
explicit ICommunicationChannel(structures::ExternalConnectionSettings settings): settings_ {std::move( settings )} {};

virtual ~ICommunicationChannel() = default;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <bringauto/external_client/connection/communication/ICommunicationChannel.hpp>
#include <bringauto/structures/ExternalConnectionSettings.hpp>

#include <mqtt/async_client.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <ExternalProtocol.pb.h>
#include <boost/asio.hpp>

#include <utility>


Expand All @@ -14,8 +13,8 @@ namespace bringauto::external_client::connection::messages {
*/
class NotAckedStatus {
public:
NotAckedStatus(const ExternalProtocol::Status &status, boost::asio::io_context &timerContext,
std::atomic<bool> &responseHandled, std::mutex &responseHandledMutex): status_ { status },
NotAckedStatus(ExternalProtocol::Status status, boost::asio::io_context &timerContext,
std::atomic<bool> &responseHandled, std::mutex &responseHandledMutex): status_ {std::move( status )},
timer_ { timerContext },
responseHandled_ {
responseHandled },
Expand Down Expand Up @@ -54,7 +53,7 @@ class NotAckedStatus {
*
* @param endConnectionFunc function which is called when status does not get response
*/
void timeoutHandler(const std::function<void()> &endConnectionFunc);
void timeoutHandler(const std::function<void()> &endConnectionFunc) const;
/// Status message that was not acknowledged yet
ExternalProtocol::Status status_ {};
/// Timer for checking if status got response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <bringauto/external_client/connection/messages/NotAckedStatus.hpp>
#include <bringauto/structures/GlobalContext.hpp>
#include <bringauto/structures/DeviceIdentification.hpp>
#include <utility>

#include <ExternalProtocol.pb.h>

Expand Down Expand Up @@ -91,7 +90,7 @@ class SentMessagesHandler {

/**
* @brief returns message counter of status_response
* @param status
* @param statusResponse
* @return counter
*/
[[nodiscard]] static u_int32_t getStatusResponseCounter(const ExternalProtocol::StatusResponse &statusResponse);
Expand Down
Loading