|
| 1 | +/* |
| 2 | + * Copyright(c) 2006 to 2020 ZettaScale Technology and others |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0 which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License |
| 7 | + * v. 1.0 which is available at |
| 8 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 | + * |
| 10 | + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| 11 | + */ |
| 12 | +#include <iostream> |
| 13 | +#include "dds/dds.hpp" |
| 14 | +#include "ATCDataModel.hpp" |
| 15 | + |
| 16 | + |
| 17 | +int main() { |
| 18 | + std::cout << "Cyclone- ATC Pub" << std::endl; |
| 19 | + |
| 20 | + /** A dds::domain::DomainParticipant is created for the default domain. */ |
| 21 | + dds::domain::DomainParticipant dp(0); |
| 22 | + dds::topic::qos::TopicQos topicQos = dp.default_topic_qos(); |
| 23 | + |
| 24 | + /** A dds::topic::Topic is created for our sample type on the domain participant. */ |
| 25 | + dds::topic::Topic<ATCDataModule::Flight> topic(dp, "FlightData", topicQos); |
| 26 | + |
| 27 | + /** 5 dds Publishers are associated to 5 different partitions. */ |
| 28 | + dds::pub::qos::PublisherQos PubGotalandQoS = dp.default_publisher_qos(); |
| 29 | + dds::pub::qos::PublisherQos PubSardegnaQoS = dp.default_publisher_qos(); |
| 30 | + dds::pub::qos::PublisherQos PubNorrlandQoS = dp.default_publisher_qos(); |
| 31 | + dds::pub::qos::PublisherQos PubLombardiaQoS = dp.default_publisher_qos(); |
| 32 | + dds::pub::qos::PublisherQos pubSiciliaQoS = dp.default_publisher_qos(); |
| 33 | + dds::pub::qos::PublisherQos pubZeelandQoS = dp.default_publisher_qos(); |
| 34 | + dds::pub::qos::PublisherQos pubDrentheQoS = dp.default_publisher_qos(); |
| 35 | + |
| 36 | + PubGotalandQoS << dds::core::policy::Partition("/Europe/Sweden/Gotaland"); |
| 37 | + PubNorrlandQoS << dds::core::policy::Partition("/Europe/Sweden/Norrland"); |
| 38 | + PubSardegnaQoS << dds::core::policy::Partition("/Europe/Italy/Sardegna"); |
| 39 | + PubLombardiaQoS << dds::core::policy::Partition("/Europe/Italy/Lombardia"); |
| 40 | + pubSiciliaQoS << dds::core::policy::Partition("/Europe/Italy/Sicilia"); |
| 41 | + pubZeelandQoS << dds::core::policy::Partition("/Europe/Netherlands/Zeeland"); |
| 42 | + pubDrentheQoS << dds::core::policy::Partition("/Europe/Netherlands/Drenthe"); |
| 43 | + |
| 44 | + dds::pub::Publisher pubGotaland(dp, PubGotalandQoS); |
| 45 | + dds::pub::Publisher pubNorrland(dp, PubNorrlandQoS); |
| 46 | + dds::pub::Publisher pubSardegna(dp, PubSardegnaQoS); |
| 47 | + dds::pub::Publisher pubLombardia(dp, PubLombardiaQoS); |
| 48 | + dds::pub::Publisher pubSicilia(dp, pubSiciliaQoS); |
| 49 | + dds::pub::Publisher pubZeeland(dp, pubZeelandQoS); |
| 50 | + dds::pub::Publisher pubDrenthe(dp, pubDrentheQoS); |
| 51 | + |
| 52 | + /** A dds::pub::DataWriter is created on the Publisher & Topic with the associated Partition Qos. */ |
| 53 | + dds::pub::qos::DataWriterQos dwqos = topic.qos(); |
| 54 | + |
| 55 | + dds::pub::DataWriter<ATCDataModule::Flight> dwGotaland(pubGotaland, topic, dwqos); |
| 56 | + dds::pub::DataWriter<ATCDataModule::Flight> dwNorrland(pubNorrland, topic, dwqos); |
| 57 | + dds::pub::DataWriter<ATCDataModule::Flight> dwSardegna(pubSardegna, topic, dwqos); |
| 58 | + dds::pub::DataWriter<ATCDataModule::Flight> dwLombardia(pubLombardia, topic, dwqos); |
| 59 | + dds::pub::DataWriter<ATCDataModule::Flight> dwsicilia(pubSicilia, topic, dwqos); |
| 60 | + dds::pub::DataWriter<ATCDataModule::Flight> dwzeeland(pubZeeland, topic, dwqos); |
| 61 | + dds::pub::DataWriter<ATCDataModule::Flight> dwdrenthe(pubDrenthe, topic, dwqos); |
| 62 | + |
| 63 | + // std::cout << "@ With ddsi, Let the Apps discover each other a bit ZZZzzz:" << std::endl; |
| 64 | + //dds_sleepfor (DDS_MSECS (5000)); |
| 65 | + |
| 66 | + std::cout << "===> Waiting for a subscriber. " << std::endl; |
| 67 | + while (dwdrenthe.publication_matched_status().current_count() == 0 && |
| 68 | + dwzeeland.publication_matched_status().current_count() == 0 && |
| 69 | + dwsicilia.publication_matched_status().current_count() == 0 && |
| 70 | + dwLombardia.publication_matched_status().current_count() == 0 && |
| 71 | + dwSardegna.publication_matched_status().current_count() == 0 && |
| 72 | + dwNorrland.publication_matched_status().current_count() == 0 && |
| 73 | + dwGotaland.publication_matched_status().current_count() == 0) |
| 74 | + { |
| 75 | + dds_sleepfor (DDS_MSECS (20)); |
| 76 | + } |
| 77 | + std::cout << "===> Found a matching one ... " << std::endl; |
| 78 | + |
| 79 | + for (int16_t i = 0; i < 5; i++) { |
| 80 | + ATCDataModule::Position p1(i+800, i+20, i+93 ); |
| 81 | + ATCDataModule::Flight FlightInstance(i, p1,"** /Europe/Sweden/Gotaland partition ** "); |
| 82 | + dwGotaland << FlightInstance; |
| 83 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Sweden/Gotaland Region " << std::endl; |
| 84 | + |
| 85 | + dds_sleepfor (DDS_MSECS (500)); |
| 86 | + } |
| 87 | + |
| 88 | + for (int16_t i = 5; i < 10; i++) { |
| 89 | + ATCDataModule::Position p2(i+7900, i+20, i+93 ); |
| 90 | + ATCDataModule::Flight FlightInstance(i, p2, "** /Europe/Sweden/Norrland partition ++"); |
| 91 | + dwNorrland << FlightInstance; |
| 92 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Sweden/Norrland Region " << std::endl; |
| 93 | + |
| 94 | + dds_sleepfor (DDS_MSECS (500)); |
| 95 | + } |
| 96 | + |
| 97 | + for (int16_t i = 10; i < 15; i++) { |
| 98 | + ATCDataModule::Position p3(i+800, i+20, i+93 ); |
| 99 | + ATCDataModule::Flight FlightInstance(i, p3, "** /Europe/Italy/Sardegna partition &&"); |
| 100 | + dwSardegna << FlightInstance; |
| 101 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Italy/Sardegna Region " << std::endl; |
| 102 | + |
| 103 | + dds_sleepfor (DDS_MSECS (500)); |
| 104 | + } |
| 105 | + |
| 106 | + for (int16_t i = 15; i < 20; i++) { |
| 107 | + ATCDataModule::Position p4(i+99, i+97, i+93 ); |
| 108 | + ATCDataModule::Flight FlightInstance(i, p4, "** /Europe/Italy/Lombardia partition %%"); |
| 109 | + dwLombardia << FlightInstance; |
| 110 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Italy/Lombardia Region " << std::endl; |
| 111 | + |
| 112 | + dds_sleepfor (DDS_MSECS (500)); |
| 113 | + } |
| 114 | + |
| 115 | + for (int16_t i = 20; i < 25; i++) { |
| 116 | + ATCDataModule::Position p5(i+242, i+240, i+930 ); |
| 117 | + ATCDataModule::Flight FlightInstance(i,p5, "** /Europe/Italy/Sicilia partition $$"); |
| 118 | + dwsicilia << FlightInstance; |
| 119 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Italy/Sicilia Region " << std::endl; |
| 120 | + |
| 121 | + dds_sleepfor (DDS_MSECS (500)); |
| 122 | + } |
| 123 | + |
| 124 | + for (int16_t i = 25; i < 30; i++) { |
| 125 | + ATCDataModule::Position p6(i+22, i+20, i+930 ); |
| 126 | + ATCDataModule::Flight FlightInstance(i,p6, "** /Europe/Netherlands/Zeeland partition &&"); |
| 127 | + dwzeeland << FlightInstance; |
| 128 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Netherlands/Zeeland Region " << std::endl; |
| 129 | + |
| 130 | + dds_sleepfor (DDS_MSECS (500)); |
| 131 | + } |
| 132 | + |
| 133 | + for (int16_t i = 30; i < 35; i++) { |
| 134 | + ATCDataModule::Position p7(i+22, i+20, i+930 ); |
| 135 | + ATCDataModule::Flight FlightInstance(i,p7, "** /Europe/Netherlands/Drenthe partition &&"); |
| 136 | + dwdrenthe << FlightInstance; |
| 137 | + std::cout << "=> [Radar Simulator] detecting FlightID: "<< FlightInstance.ID() << " in the /Europe/Netherlands/Drenthe Region " << std::endl; |
| 138 | + |
| 139 | + dds_sleepfor (DDS_MSECS (500)); |
| 140 | + } |
| 141 | + |
| 142 | + dds_sleepfor (DDS_MSECS (5000)); |
| 143 | + return 0; |
| 144 | +} |
0 commit comments