Skip to content

Commit

Permalink
BAF-763 release fleet protocol as a package (#15)
Browse files Browse the repository at this point in the history
* remade cmake files to be able to create a header only package

* Fix protobuf

* Write TODOs

* Use CMDEF_ADD_LIBRARY, remove namespace aliases

* Fix protobuf parsing example

* Remove todo, commented code, origin_install_rpath

* Use NAMESPACE

* Namespace Tree structure

* Change version

* Fix Includes

* remove prefix from error_codes files. readme update

* Use cached variables

---------

Co-authored-by: mario <[email protected]>
  • Loading branch information
Melky-Phoe and MarioIvancik authored Mar 1, 2024
1 parent 68397c8 commit 309e180
Show file tree
Hide file tree
Showing 28 changed files with 267 additions and 108 deletions.
52 changes: 52 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR)
PROJECT(fleet-protocol C CXX)

SET(FLEET_PROTOCOL_VERSION 2.0.0)
SET(FLEET_PROTOCOL_NAMESPACE "fleet-protocol-interface::")

OPTION(BRINGAUTO_PACKAGE "Package creation" OFF)
OPTION(BRINGAUTO_INSTALL "Enable install" OFF)
OPTION(BRINGAUTO_SAMPLES "Enable build of sample app, not used in project" OFF)

IF(BRINGAUTO_PACKAGE)
IF(NOT BRINGAUTO_INSTALL)
SET(BRINGAUTO_INSTALL ON CACHE BOOL "Forced install due to BRINGAUTO_PACKAGE=ON" FORCE)
MESSAGE(WARNING "BRINGAUTO_INSTALL is switched to on because of BRINGAUTO_PACKAGE=ON")
ENDIF()
ENDIF()

FIND_PACKAGE(CMLIB
COMPONENTS CMDEF CMUTIL
REQUIRED
)

IF(BRINGAUTO_SAMPLES)
ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/examples")
ENDIF()
ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/lib")
ADD_SUBDIRECTORY("${CMAKE_CURRENT_SOURCE_DIR}/protobuf")

CMDEF_ADD_LIBRARY(
LIBRARY_GROUP fleet-protocol
TYPE INTERFACE
VERSION ${FLEET_PROTOCOL_VERSION}
)
TARGET_LINK_LIBRARIES(fleet-protocol-interface INTERFACE
common-headers-interface
internal-client-interface
module-gateway-interface
module-maintainer-external-server-interface
module-maintainer-module-gateway-interface
protobuf-cpp-interface
)


IF (BRINGAUTO_INSTALL)
CMDEF_INSTALL(
TARGET fleet-protocol-interface
NAMESPACE ${FLEET_PROTOCOL_NAMESPACE}
)

ENDIF ()

IF (BRINGAUTO_PACKAGE)
CMDEF_PACKAGE(
MAIN_TARGET fleet-protocol-interface
VERSION ${FLEET_PROTOCOL_VERSION}
)
SET(CPACK_GENERATOR ZIP)
SET(CPACK_PACKAGE_CONTACT "BringAuto s.r.o. <[email protected]>")
INCLUDE(CPack)
ENDIF()
98 changes: 83 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# Fleet protocol
# Fleet Protocol

Fleet protocol is a communication protocol developed by BringAuto to allow simple and reliable communication between multiple devices and cloud infrastructure.
Fleet Protocol is a communication protocol developed by BringAuto to allow simple and reliable communication between
multiple devices and cloud infrastructure.
**Complete protocol documentation will be released soon**. Protocol consists of three parts:

* internal client - specific part of device that communicates with module gateway
* module gateway:
- internal server - communicates with internal client
- aggregator - aggregates status messages
- external client - communicates with external server
- internal server - communicates with internal client
- aggregator - aggregates status messages
- external client - communicates with external server
* external server - communicates with server infrastructure that gives user the ability to control devices

## Communication protocol

# Communication protocol

We use [ProtoBuf] library for message format (version [Protobuf version]) and serialization/deserialization - protocol specification
We use [ProtoBuf] library for message format (version [Protobuf version]) and serialization/deserialization - protocol
specification
can be found in protobuff folder.

Each message must be prefixed with four bytes long (uint32_t data type) header which holds
information about size of the ProtoBuf message.
information about size of the ProtoBuf message.

To read more about the system architecture look at Fleet Protocol v2 documentation:

- [Summary]
- [Fleet Protocol Requirements]
- [Internal Client]
Expand All @@ -32,39 +35,104 @@ To read more about the system architecture look at Fleet Protocol v2 documentati
- [HTTP API]
- [HTTP API Wait Mechanism]

## Protocol messages
### Protocol messages

Messages are described by ProtoBuff v3.

If the message filed is not mandatory then it's marked as OPTIONAL by "OPTIONAL"
as the last comment in documentation for the given field.
Optional fields has defaults as described in [ProtoBuf] v3 doc.

# Repo structure
## Examples
## Repo structure

### Examples

Samples of fleet-protocol features usage.

Use CMake option `BRINGAUTO_SAMPLES=ON` to configure them.

## Lib
### Lib

Header files of interfaces

## Protobuf
### Protobuf

Protobuf compiled and non-compiled files

## Usage

### Requirements

- [CMlib](https://github.com/cmakelib/cmakelib)

### Installation

To install the library, first configure the project with CMake option BRINGAUTO_INSTALL=ON and BRINGAUTO_PACKAGE=ON and then install it.

```bash
mkdir _build && cd _build
cmake -DBRINGAUTO_INSTALL=ON -DBRINGAUTO_PACKAGE=ON ..
make install
```

### Package

To create a package, configure the project with CMake option BRINGAUTO_PACKAGE=ON and then create it using `cpack`.

```bash
mkdir _build && cd _build
cmake -DBRINGAUTO_INSTALL=ON -DBRINGAUTO_PACKAGE=ON ..
cpack
```

### Using library in CMake projects

Once the library is installed, it can be used in other projects by adding the following lines to the `CMakeLists.txt`
file:

```cmake
FIND_PACKAGE(fleet-protocol-interface REQUIRED)
TARGET_LINK_LIBRARIES(<target> PUBLIC fleet-protocol-interface::fleet-protocol-interface)
```

This will link all interfaces. If you want to link only specific interface, use the interfaces from the list below:

* fleet-protocol-interface::common-headers-interface
* fleet-protocol-interface::internal-client-interface
* fleet-protocol-interface::module-gateway-interface
* fleet-protocol-interface::module-maintainer-external-server-interface
* fleet-protocol-interface::module-maintainer-module-gateway-interface
* fleet-protocol-interface::protobuf-cpp-interface

> Note that `protobuf-cpp-interface` also needs `protobuf::libprotobuf` to be linked to the target

[BringAutoDaemon.proto]: ./BringAutoDaemon.proto

[ProtoBuf]: https://developers.google.com/protocol-buffers

[Protobuf version]: https://github.com/protocolbuffers/protobuf/releases/tag/v3.21.12

[Summary]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/summary

[Fleet Protocol Requirements]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/protocol-requirements

[Internal Client]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client

[Module Gateway]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/module-gateway

[External Server]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/external-server

[Modules]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/modules

[Message Structure]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/message-structure
[Internal Client design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client-design

[Internal Client design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/internal-client-design

[Module Gateway design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/module-gateway-design

[External Server design]: https://ref.bringautofleet.com/r/protocol/v2/2.0.1/external-server-design

[HTTP API]: https://ref.bringautofleet.com/r/protocol/http-api/1.0.0/http-api

[HTTP API Wait Mechanism]: https://ref.bringautofleet.com/r/protocol/http-api/1.0.0/wait-mechanism
File renamed without changes.
20 changes: 13 additions & 7 deletions examples/protobuf_parsing_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ PROJECT(fleet-protocol CXX)

SET(CMAKE_CXX_STANDARD 20)

SET(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
FIND_PACKAGE(CMLIB REQUIRED COMPONENTS CMDEF STORAGE)
IF (NOT BRINGAUTO_SYSTEM_DEP)
INCLUDE(cmake/Dependencies.cmake)
ENDIF ()

FILE(GLOB_RECURSE source_files "source/*" "lib/protobuf/*")
ADD_LIBRARY(parsing_example_lib STATIC ${source_files})
TARGET_INCLUDE_DIRECTORIES(parsing_example_lib PUBLIC "include/" "lib/protobuf/")
TARGET_LINK_LIBRARIES(parsing_example_lib PUBLIC ${PROJECT_NAME}::protobuf_cpp)
SET(CMAKE_BUILD_RPATH_USE_ORIGIN ON)

FIND_PACKAGE(Protobuf 3.21.12 REQUIRED)

ADD_EXECUTABLE(protobuf_parser main.cpp)
TARGET_LINK_LIBRARIES(protobuf_parser parsing_example_lib)
FILE(GLOB_RECURSE source_files "source/*")
FILE(GLOB_RECURSE protobuf_files "lib/protobuf/*")
CMDEF_ADD_EXECUTABLE(TARGET protobuf-parser
SOURCES main.cpp ${source_files} ${protobuf_files}
INCLUDE_DIRECTORIES "include/" "lib/protobuf/"
VERSION 1.0.0)
TARGET_LINK_LIBRARIES(protobuf-parser PUBLIC protobuf::libprotobuf protobuf-cpp-interface)
File renamed without changes.
21 changes: 12 additions & 9 deletions lib/common_headers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR)
PROJECT(fleet-protocol-common-headers C CXX)
PROJECT(fleet-protocol C CXX)

ADD_LIBRARY(common_headers INTERFACE)
TARGET_INCLUDE_DIRECTORIES(common_headers INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/>"
"$<INSTALL_INTERFACE:include/>")
CMDEF_ADD_LIBRARY(
LIBRARY_GROUP common-headers
TYPE INTERFACE
VERSION ${FLEET_PROTOCOL_VERSION}
INCLUDE_DIRECTORIES include/
INSTALL_INCLUDE_DIRECTORIES include/
)

FILE(GLOB_RECURSE include_files include/*)
TARGET_SOURCES(common_headers INTERFACE
FILE_SET common_headers TYPE HEADERS FILES ${include_files} BASE_DIRS include)

ADD_LIBRARY(fleet-protocol::common_headers ALIAS common_headers)
CMDEF_INSTALL(
TARGET common-headers-interface
NAMESPACE ${FLEET_PROTOCOL_NAMESPACE}
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

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

#ifdef __cplusplus
extern "C" {
Expand Down
23 changes: 13 additions & 10 deletions lib/internal_client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR)
PROJECT(fleet-protocol-internal-client C CXX)
PROJECT(fleet-protocol C CXX)

ADD_LIBRARY(internal_client_interface INTERFACE)
TARGET_INCLUDE_DIRECTORIES(internal_client_interface INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/>"
"$<INSTALL_INTERFACE:include/>")
TARGET_LINK_LIBRARIES(internal_client_interface INTERFACE fleet-protocol::common_headers)
CMDEF_ADD_LIBRARY(
LIBRARY_GROUP internal-client
TYPE INTERFACE
VERSION ${FLEET_PROTOCOL_VERSION}
INCLUDE_DIRECTORIES include/
INSTALL_INCLUDE_DIRECTORIES include/
)
TARGET_LINK_LIBRARIES(internal-client-interface INTERFACE common-headers-interface)

FILE(GLOB_RECURSE include_files include/*)
TARGET_SOURCES(internal_client_interface INTERFACE
FILE_SET internal_client_interface TYPE HEADERS FILES ${include_files} BASE_DIRS include)

ADD_LIBRARY(fleet-protocol::internal_client_interface ALIAS internal_client_interface)
CMDEF_INSTALL(
TARGET internal-client-interface
NAMESPACE ${FLEET_PROTOCOL_NAMESPACE}
)

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

#include <general_error_codes.h>
#include <fleet_protocol/common_headers/general_error_codes.h>
/**
* @brief Specific error codes for internal_client
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
extern "C" {
#endif

#include <device_management.h>
#include <general_error_codes.h>
#include <memory_management.h>
#include <ic_error_codes.h>
#include <fleet_protocol/common_headers/device_management.h>
#include <fleet_protocol/common_headers/general_error_codes.h>
#include <fleet_protocol/common_headers/memory_management.h>
#include <fleet_protocol/internal_client/error_codes.h>

/**
* @section internal_client
Expand Down
21 changes: 12 additions & 9 deletions lib/module_gateway/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR)
PROJECT(fleet-protocol C CXX)

ADD_LIBRARY(module_gateway INTERFACE)
TARGET_INCLUDE_DIRECTORIES(module_gateway INTERFACE include/)
TARGET_LINK_LIBRARIES(module_gateway INTERFACE ${PROJECT_NAME}::common_headers)

FILE(GLOB_RECURSE include_files include/*)
TARGET_SOURCES(module_gateway INTERFACE
FILE_SET module_gateway TYPE HEADERS FILES ${include_files} BASE_DIRS include)

ADD_LIBRARY(${PROJECT_NAME}::module_gateway ALIAS module_gateway )
CMDEF_ADD_LIBRARY(
LIBRARY_GROUP module-gateway
TYPE INTERFACE
VERSION ${FLEET_PROTOCOL_VERSION}
INCLUDE_DIRECTORIES include/
INSTALL_INCLUDE_DIRECTORIES include/
)
TARGET_LINK_LIBRARIES(module-gateway-interface INTERFACE common-headers-interface)
CMDEF_INSTALL(
TARGET module-gateway-interface
NAMESPACE ${FLEET_PROTOCOL_NAMESPACE}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
extern "C" {
#endif

#include <device_management.h>
#include <mg_error_codes.h>
#include <memory_management.h>
#include <fleet_protocol/common_headers/device_management.h>
#include <fleet_protocol/common_headers/memory_management.h>
#include <fleet_protocol/module_gateway/error_codes.h>

/**
* @section module_gateway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
extern "C" {
#endif

#include <device_management.h>
#include <mg_error_codes.h>
#include <memory_management.h>
#include <fleet_protocol/common_headers/device_management.h>
#include <fleet_protocol/common_headers/memory_management.h>
#include <fleet_protocol/module_gateway/error_codes.h>

/**
* @section module_gateway
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <general_error_codes.h>
#include <fleet_protocol/common_headers/general_error_codes.h>

enum mg_error_codes {
DEVICE_NOT_SUPPORTED = RESERVED -1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
extern "C" {
#endif

#include <device_management.h>
#include <mg_error_codes.h>
#include <memory_management.h>
#include <fleet_protocol/common_headers/device_management.h>
#include <fleet_protocol/common_headers/memory_management.h>
#include <fleet_protocol/module_gateway/error_codes.h>

/**
* @section module_gateway
Expand Down
Loading

0 comments on commit 309e180

Please sign in to comment.