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
3 changes: 2 additions & 1 deletion CMLibStorage.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SET(STORAGE_LIST DEP)

SET(STORAGE_LIST_DEP "https://github.com/bacpack-system/package-tracker.git")
SET(STORAGE_LIST_DEP "https://github.com/bacpack-system/package-tracker.git")
SET(STORAGE_LIST_DEP_REVISION "v0.0.0" CACHE STRING "" FORCE)
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ FIND_PACKAGE(CMLIB
REQUIRED
)

SET(BRINGAUTO_MODULE_GATEWAY_VERSION 1.3.4)
SET(BRINGAUTO_MODULE_GATEWAY_VERSION 1.3.5)

SET(BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY "DEBUG" CACHE STRING "Minimum logger verbosity level for module-gateway")
SET_PROPERTY(CACHE BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY PROPERTY STRINGS "DEBUG" "INFO" "WARNING" "ERROR" "CRITICAL")

CMDEF_COMPILE_DEFINITIONS(
ALL "MODULE_GATEWAY_VERSION=\"${BRINGAUTO_MODULE_GATEWAY_VERSION}\""
ALL
"MODULE_GATEWAY_VERSION=\"${BRINGAUTO_MODULE_GATEWAY_VERSION}\""
"BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY=\"${BRINGAUTO_MODULE_GATEWAY_MINIMUM_LOGGER_VERBOSITY}\""
)
SET(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMDEF_LIBRARY_INSTALL_DIR}")
SET(CMAKE_CXX_STANDARD 20)
Expand Down Expand Up @@ -43,8 +48,8 @@ SET(Protobuf_USE_STATIC_LIBS ON)

FIND_PACKAGE(Boost 1.74 REQUIRED CONFIG)
FIND_PACKAGE(Protobuf 3.21.12 REQUIRED)
FIND_PACKAGE(cxxopts 3.0.0 REQUIRED)
FIND_PACKAGE(nlohmann_json 3.2.0 REQUIRED)
FIND_PACKAGE(cxxopts 3.1.1 REQUIRED)
FIND_PACKAGE(nlohmann_json 3.10.5 REQUIRED)
FIND_PACKAGE(PahoMqttCpp REQUIRED)
FIND_PACKAGE(eclipse-paho-mqtt-c REQUIRED)
FIND_PACKAGE(libbringauto_logger 2.0.0 REQUIRED)
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

* BRINGAUTO_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
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SET(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
BA_PACKAGE_LIBRARY(protobuf v4.21.12)
BA_PACKAGE_LIBRARY(fleet-protocol-interface v2.0.0 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(nlohmann-json v3.10.5 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(cxxopts v3.0.5 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(cxxopts v3.1.1 NO_DEBUG ON)
BA_PACKAGE_LIBRARY(boost v1.86.0)
BA_PACKAGE_LIBRARY(ba-logger v2.0.0
)
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
15 changes: 8 additions & 7 deletions include/bringauto/external_client/ExternalClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

#include <InternalProtocol.pb.h>

#include <list>
#include <memory>
#include <unordered_map>
#include <vector>
#include <list>



Expand All @@ -20,9 +21,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 +55,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 +69,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,42 @@
#pragma once

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



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

/**
* @brief Dummy communication channel for unit-test and send-only scenarios.
* Does not establish any real connection, just simulates it.
*
* Constraints:
* - receiveMessage() always returns nullptr.
* - Because ExternalConnection's connect sequence relies on receiving a valid
* server response, DUMMY can never complete a connect sequence. Any gateway
* instance configured with protocol-type "DUMMY" will loop reconnecting
* indefinitely. Use only in unit tests or when the connect sequence is
* bypassed by the test harness.
* - initializeConnection() and closeConnection() only toggle an internal flag
* used to gate sendMessage() log output.
*/
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
Loading