15int main(
int argc,
char** argv)
19 std::cout <<
"############ SOIL #############" << std::endl;
20 std::shared_ptr<SIGN::Signer> signer(
new SIGN::Signer(
"../../../../assets/private-device-key.pem"));
21 std::cout <<
"[INFO] " << signer->openssl_version() << std::endl;
22 std::shared_ptr<SOIL::Object> root_object =
SOIL::Object::create(NULL,
"OBJ-ROOT",
"Root Object",
"Root Object and entry point for the model.");
23 std::shared_ptr<SOIL::Object> lsm_object =
SOIL::Object::create(root_object,
"OBJ-LSM",
"LSM System",
"LSM system root object");
24 std::shared_ptr<SOIL::Object> entities_object =
SOIL::Object::create(lsm_object,
"OBJ-Entities",
"Mobile Entities",
"Mobile entities of the LSM system");
25 std::shared_ptr<SOIL::Object> target_A123 =
SOIL::Object::create(entities_object,
"OBJ-A123",
"Target A123",
"Target A123 of the LSM system");
26 std::shared_ptr<SOIL::Variable<double, 3> > variable =
SOIL::Variable<double, 3>::create(target_A123,
"VAR-Position",
"Position",
"A dummy position variable for testing",
"MTR",
"");
29 variable->update(std::vector<double>({ 1.0, 1.5, 2.0 }),
SOIL::TIME::utc_now(),
"LaVA Test");
30 variable->set_covariance(std::vector<std::vector<double> >({ { 0.01, 0, 0 },{0, 0.01, 0},{ 0, 0, 0.01 } }));
31 variable->sign(signer);
34 std::cout <<
"[INFO] " <<
"--- Exemplary JSON Serialization ---" << std::endl;
35 std::cout << variable->json() << std::endl << std::endl;
36 std::cout <<
"[INFO] " <<
"------------------------------------" << std::endl;
39 std::cout <<
"############ MQTT ############" << std::endl;
43 std::shared_ptr<MQTT::Publisher> mqtt_publisher = std::make_shared<MQTT::Publisher>(
"cpp-test");
44 mqtt_publisher->configure(mqtt_config);
45 std::cout <<
"[INFO] MQTT Connecting to " << mqtt_config.
uri() << std::endl;
46 mqtt_publisher->connect();
47 std::cout <<
"[OK] MQTT Connected" << std::endl;
49 std::cout <<
"[INFO] Running Loop Test" << std::endl;
51 auto begin = std::chrono::steady_clock::now();
52 for (
int i = 0; i < 1000; i++)
54 variable->update(std::vector<double>({ 1.0 * i, 2.0 * i, 3.0 * i }),
SOIL::TIME::utc_now(),
"Loop Test Update");
55 variable->set_covariance(std::vector<std::vector<double> >({ { 1.0 * i,0,0 },{ 0,1.0 * i,0 },{ 0,0,1.0 * i } }));
56 variable->sign(signer);
59 variable->mqtt(mqtt_publisher);
61 auto end = std::chrono::steady_clock::now();
62 std::cout <<
"[INFO] " <<
"Average update, serialization and publish cycle: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() / 1000.0 <<
" ms" << std::endl << std::endl;
64 std::this_thread::sleep_for(std::chrono::milliseconds(500));
65 mqtt_publisher->disconnect();
66 std::cout <<
"[OK] MQTT Disconnect" << std::endl << std::endl;
67 std::this_thread::sleep_for(std::chrono::milliseconds(500));
70 std::cout <<
"############ UDP #############" << std::endl;
74 udp_broadcast.
send(variable->json());
75 std::cout <<
"[OK] UDP Broadcast sent to localhost on port " << udp_config.
clients[
"127.0.0.1"] << std::endl << std::endl;
78 std::cout <<
"############ REST ############" << std::endl;
80 http_server.
add(
"/?(.*)", root_object);
82 std::cout <<
"[OK] HTTP Server listening on http://localhost:8000. Press Enter to quit..." << std::endl;
84 std::getline(std::cin, s);
86 std::cout <<
"[OK] Closing HTTP Server" << std::endl;
92 catch (std::exception& e)
94 std::cout <<
"[ERROR] " << e.what() << std::endl;
void close()
Stop listener.
void add(std::string path, std::shared_ptr< Resource > resource)
Register resource.
void open()
Start listener.
MQTT publishing configuration.
std::string certificate_authority
Path to CA PEM-file.
std::string uri()
URI Builder.
static std::shared_ptr< Object > create(std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string ontology="")
Create new Object.
static DLL boost::posix_time::ptime utc_now(void)
Current Time.
static std::shared_ptr< Variable > create(std::shared_ptr< Element > parent, std::string uuid, std::string name, std::string description, std::string unit, std::string ontology="", Range< T > range=Range< T >(), TIME time=TIME(), std::string nonce="")
Create new Variable.
void configure(UDP::Configuration config)
Configure Broadcast.
void send(std::string message)
Send Message.
UDP Broadcast Configuration.
std::map< std::string, int > clients
List of clients.
int main(int argc, char **argv)