-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnalysis_Test_Sender.cpp
More file actions
122 lines (109 loc) · 4.3 KB
/
Copy pathAnalysis_Test_Sender.cpp
File metadata and controls
122 lines (109 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (C) 2025: Arizona Board of Regents on Behalf of the University of Arizona
*/
// This is a client that sends reports as it from a cmaera but just generates moving outputs so
// that we can verify that a Render Module is displaying them correctly.
/**
* @file Analysis_Test_Sender.cpp
* @brief Apache Strap-Down Pilotage example analysis module using C++.
*
* @author ReliaSolve.
* @date December 4, 2025.
*/
#include <iostream>
#include <chrono>
#include <cmath>
#include <ASDP_Core_API.h>
using namespace asdp;
void usage(std::string programName)
{
std::cerr << "Usage: " << programName << " [--analysisServer URL] [--camID ID]" << std::endl;
std::cerr << " --analysisServer URL URL of the analysis module server. Default is tcp://localhost." << std::endl;
std::cerr << " --camID ID Camera ID to use. Default is 1." << std::endl;
}
int main(int argc, char** argv)
{
std::string analysisURL = "tcp://localhost"; ///< URL of the analysis module server.
uint32_t camID = 1; ///< Camera ID to use.
size_t realParams = 0;
// Parse the command line arguments.
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--analysisServer") {
if ((i + 1) >= argc) {
usage(argv[0]);
return 1;
}
analysisURL = argv[++i];
}
else if (std::string(argv[i]) == "--camID") {
if ((i + 1) >= argc) {
usage(argv[0]);
return 1;
}
camID = static_cast<uint32_t>(std::stoul(argv[++i]));
}
else if (argv[i][0] == '-' ) {
std::cerr << "Unknown flag: " << argv[i] << std::endl;
usage(argv[0]);
return 1;
} else switch (realParams++) {
case 0:
default:
usage(argv[0]);
return 2;
}
}
if (realParams != 0) {
usage(argv[0]);
return 2;
}
// Open a JSON string server to report analysis results to.
std::shared_ptr<JSONStringSender> jsonSender;
Status s = JSONStringSender::Create(analysisURL, jsonSender);
if (s != OKAY) {
std::cerr << "Failed to create JSONStringSender: " << ErrorMessage(s) << std::endl;
return 100;
}
// Construct and send moving analysis results, sending 60 reports per second.
auto lastSendTime = std::chrono::steady_clock::now();
while (true) {
// Check if it's time to send the next report.
auto now = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed = now - lastSendTime;
if (elapsed.count() >= (1.0 / 60.0)) {
// The time is based on the current now time, stored as second and microseconds.
uint32_t seconds = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() / 1000000);
uint32_t microseconds = static_cast<uint32_t>(std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count() % 1000000);
// Send analysis reports of each type, moving over time.
{
double y = 0.25;
double x = 0.5 + 0.4 * std::sin(now.time_since_epoch().count() / 1e9);
std::string jsonReport = R"({"CamID":)" + std::to_string(camID)
+ R"(,"Time":[)" + std::to_string(seconds) + R"(,)" + std::to_string(microseconds) + R"(])"
+ R"(,"Name":"Object1")"
+ R"(,"Loc":[)" + std::to_string(x) + R"(,)" + std::to_string(y) + R"(])"
+ R"(,"Class":[{"Type":"Dot","IFF":"friend"}])"
+ R"(})";
jsonSender->Send(jsonReport);
}
{
double y = 0.75;
double x = 0.5 + 0.4 * std::sin(now.time_since_epoch().count() / 2e9);
std::string jsonReport = R"({"CamID":)" + std::to_string(camID)
+ R"(,"Time":[)" + std::to_string(seconds) + R"(,)" + std::to_string(microseconds) + R"(])"
+ R"(,"Name":"Object2")"
+ R"(,"Loc":[)" + std::to_string(x) + R"(,)" + std::to_string(y) + R"(])"
+ R"(,"Rect":[0.1,0.15])"
+ R"(,"Class":[{"Type":"Box","IFF":"foe"}])"
+ R"(})";
jsonSender->Send(jsonReport);
}
lastSendTime = now;
} else {
// Sleep for a short time to avoid busy-waiting.
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
std::cout << std::endl << "Success!" << std::endl;
return 0;
}