-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4462bd6
commit 82c4269
Showing
6 changed files
with
229 additions
and
0 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
50 changes: 50 additions & 0 deletions
50
ecal/samples/cpp/pubsub/protobuf/person_snd_udp/CMakeLists.txt
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,50 @@ | ||
# ========================= eCAL LICENSE ================================= | ||
# | ||
# Copyright (C) 2016 - 2019 Continental Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# ========================= eCAL LICENSE ================================= | ||
|
||
cmake_minimum_required(VERSION 3.10) | ||
|
||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) | ||
|
||
project(person_snd_udp) | ||
|
||
find_package(eCAL REQUIRED) | ||
find_package(Protobuf REQUIRED) | ||
|
||
set(person_snd_udp_src | ||
src/person_snd_udp.cpp | ||
) | ||
|
||
set(person_snd_udp_proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/animal.proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/house.proto | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf/person.proto | ||
) | ||
|
||
ecal_add_sample(${PROJECT_NAME} ${person_snd_udp_src}) | ||
PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/protobuf ${person_snd_udp_proto}) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
PRIVATE | ||
eCAL::core_protobuf | ||
) | ||
|
||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) | ||
|
||
ecal_install_sample(${PROJECT_NAME}) | ||
|
||
set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER samples/cpp/pubsub/protobuf) |
79 changes: 79 additions & 0 deletions
79
ecal/samples/cpp/pubsub/protobuf/person_snd_udp/src/person_snd_udp.cpp
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,79 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
#include <ecal/ecal.h> | ||
#include <ecal/msg/protobuf/publisher.h> | ||
|
||
#include <iostream> | ||
|
||
#include "person.pb.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
// initialize eCAL API | ||
eCAL::Initialize(argc, argv, "person publisher multicast"); | ||
|
||
// set process state | ||
eCAL::Process::SetState(proc_sev_healthy, proc_sev_level1, "I feel good !"); | ||
|
||
// create a publisher (topic name "person") | ||
eCAL::protobuf::CPublisher<pb::People::Person> pub("person"); | ||
|
||
// switch all layer off | ||
pub.SetLayerMode(eCAL::TLayer::tlayer_all, eCAL::TLayer::smode_off); | ||
|
||
// switch unicast layer on | ||
pub.SetLayerMode(eCAL::TLayer::tlayer_udp_mc, eCAL::TLayer::smode_on); | ||
|
||
// generate a class instance of Person | ||
pb::People::Person person; | ||
|
||
// enter main loop | ||
auto cnt(0); | ||
while (eCAL::Ok()) | ||
{ | ||
// set person object content | ||
person.set_id(++cnt); | ||
person.set_name("Max"); | ||
person.set_stype(pb::People::Person_SType_MALE); | ||
person.set_email("[email protected]"); | ||
person.mutable_dog()->set_name("Brandy"); | ||
person.mutable_house()->set_rooms(4); | ||
|
||
// send the person object | ||
pub.Send(person); | ||
|
||
// print content | ||
std::cout << "person id : " << person.id() << std::endl; | ||
std::cout << "person name : " << person.name() << std::endl; | ||
std::cout << "person stype : " << person.stype() << std::endl; | ||
std::cout << "person email : " << person.email() << std::endl; | ||
std::cout << "dog.name : " << person.dog().name() << std::endl; | ||
std::cout << "house.rooms : " << person.house().rooms() << std::endl; | ||
std::cout << std::endl; | ||
|
||
// sleep 500 ms | ||
eCAL::Process::SleepMS(500); | ||
} | ||
|
||
// finalize eCAL API | ||
eCAL::Finalize(); | ||
|
||
return(0); | ||
} |
28 changes: 28 additions & 0 deletions
28
ecal/samples/cpp/pubsub/protobuf/person_snd_udp/src/protobuf/animal.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,28 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package pb.Animal; | ||
|
||
message Dog | ||
{ | ||
string name = 1; | ||
string colour = 2; | ||
} |
27 changes: 27 additions & 0 deletions
27
ecal/samples/cpp/pubsub/protobuf/person_snd_udp/src/protobuf/house.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,27 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
package pb.Environment; | ||
|
||
message House | ||
{ | ||
int32 rooms = 1; | ||
} |
42 changes: 42 additions & 0 deletions
42
ecal/samples/cpp/pubsub/protobuf/person_snd_udp/src/protobuf/person.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,42 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2019 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
syntax = "proto3"; | ||
|
||
import "animal.proto"; | ||
import "house.proto"; | ||
|
||
package pb.People; | ||
|
||
message Person | ||
{ | ||
enum SType | ||
{ | ||
MALE = 0; | ||
FEMALE = 1; | ||
} | ||
|
||
int32 id = 1; | ||
string name = 2; | ||
SType stype = 3; | ||
string email = 4; | ||
|
||
Animal.Dog dog = 5; | ||
Environment.House house = 6; | ||
} |