-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cleanup vcpkg.json * add protobuf for sparkplug_b * Committing clang-format changes * Added some data to existing example * Committing clang-format changes --------- Co-authored-by: Ómar Högni Guðmarsson <[email protected]> Co-authored-by: omarhogni <[email protected]>
- Loading branch information
1 parent
726f7b0
commit 14581d5
Showing
6 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sparkplug_b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.24) | ||
project(mqtt-sparkplug) | ||
|
||
find_package(protobuf CONFIG REQUIRED) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
sparkplug_proto | ||
GIT_REPOSITORY https://github.com/eclipse/tahu.git | ||
GIT_TAG v1.0.4 | ||
) | ||
FetchContent_Populate(sparkplug_proto) | ||
|
||
file( | ||
COPY | ||
${sparkplug_proto_SOURCE_DIR}/sparkplug_b/sparkplug_b.proto | ||
DESTINATION | ||
${CMAKE_CURRENT_SOURCE_DIR}/sparkplug_b/ | ||
) | ||
|
||
add_library(sparkplug_proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/sparkplug_b/sparkplug_b.proto | ||
) | ||
add_library(tfc::sparkplug::proto ALIAS sparkplug_proto) | ||
target_link_libraries(sparkplug_proto | ||
PUBLIC | ||
protobuf::libprotobuf | ||
) | ||
target_include_directories(sparkplug_proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) | ||
protobuf_generate(TARGET sparkplug_proto LANGUAGE cpp) | ||
|
||
add_subdirectory(example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
add_executable(mqtt-sparkplug-example mqtt-sparkplug-example.cpp) | ||
|
||
target_link_libraries(mqtt-sparkplug-example PUBLIC tfc::sparkplug::proto) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
// specification https://sparkplug.eclipse.org/specification/version/3.0/documents/sparkplug-specification-3.0.0.pdf | ||
|
||
#include <sparkplug_b/sparkplug_b.pb.h> | ||
#include <filesystem> | ||
|
||
using org::eclipse::tahu::protobuf::Payload; | ||
using org::eclipse::tahu::protobuf::Payload_Metric; | ||
|
||
using std::chrono::duration_cast; | ||
using std::chrono::milliseconds; | ||
using std::chrono::system_clock; | ||
|
||
int main() { | ||
[[maybe_unused]] Payload_Metric metric{}; | ||
[[maybe_unused]] Payload p{}; | ||
metric.set_name("test"); | ||
metric.set_timestamp(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count()); | ||
|
||
std::cout << metric.name() << std::endl; | ||
|
||
std::cout << "--------Sparkplug b DATA-----------" << std::endl; | ||
|
||
std::vector<uint8_t> data = { 8, 240, 163, 235, 168, 148, 49, 18, 46, 10, 20, 78, 111, 100, 101, 95, 82, 101, 100, | ||
47, 115, 111, 109, 101, 95, 115, 116, 114, 105, 110, 103, 24, 240, 163, 235, 168, 148, 49, | ||
32, 12, 122, 13, 73, 115, 32, 116, 104, 105, 115, 32, 108, 105, 102, 101, 63, 24, 6 }; | ||
p.ParseFromArray(data.data(), data.size()); | ||
p.PrintDebugString(); | ||
|
||
std::cout << "--------Sparkplug b Nbirth-----------" << std::endl; | ||
|
||
data = { 8, 134, 165, 128, 171, 148, 49, 18, 26, 10, 20, 78, 111, 100, 101, 32, 67, | ||
111, 110, 116, 114, 111, 108, 47, 82, 101, 98, 105, 114, 116, 104, 32, 11, 112, | ||
0, 18, 11, 10, 5, 98, 100, 83, 101, 113, 32, 8, 88, 0, 24, 0 }; | ||
p.ParseFromArray(data.data(), data.size()); | ||
p.PrintDebugString(); | ||
|
||
std::cout << "--------Sparkplug b Nbirth #2-----------" << std::endl; | ||
data = { 8, 177, 192, 243, 202, 148, 49, 18, 26, 10, 20, 78, 111, 100, 101, 95, 82, 101, 100, 47, 115, 111, | ||
109, 101, 95, 110, 117, 109, 98, 101, 114, 32, 3, 56, 1, 18, 26, 10, 20, 78, 111, 100, 101, 95, | ||
82, 101, 100, 47, 115, 111, 109, 101, 95, 115, 116, 114, 105, 110, 103, 32, 12, 56, 1, 24, 1 }; | ||
p.ParseFromArray(data.data(), data.size()); | ||
p.PrintDebugString(); | ||
|
||
std::cout << "-------------------" << std::endl; | ||
for (auto& k : p.metrics()) { | ||
std::cout << k.name() << std::endl; | ||
} | ||
std::cout << "-------------------" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters