21int main(
int argc,
char* argv[]) {
23 std::cerr <<
"Usage: " << argv[0] <<
" <db_port> [message_count]" << std::endl;
24 std::cerr <<
"Example: " << argv[0] <<
" 2240 100" << std::endl;
28 uint16_t
port = std::stoi(argv[1]);
29 int message_count = (argc >= 3) ? std::stoi(argv[2]) : 100;
31 std::cout <<
"๐งช Sending fake CalibratedPTMessage to Elodin" << std::endl;
32 std::cout <<
"=============================================" << std::endl;
33 std::cout <<
"DB: 127.0.0.1:" <<
port << std::endl;
34 std::cout <<
"Messages: " << message_count << std::endl;
37 daq_comms::elodin::ElodinClient client;
38 if (!client.connect(
"127.0.0.1",
port)) {
39 std::cerr <<
"โ Failed to connect to Elodin DB" << std::endl;
43 std::cout <<
"โ
Connected to Elodin DB" << std::endl;
47 std::cout <<
"โ ๏ธ Note: CalibratedPTMessage VTable registration not yet implemented"
49 std::cout <<
" This test will fail until VTable is registered" << std::endl;
50 std::cout << std::endl;
53 std::array<uint8_t, 2> calibrated_pt_packet_id = {0x30, 0x00};
55 std::cout <<
"๐ค Sending " << message_count <<
" CalibratedPTMessage(s)..." << std::endl;
57 auto start_time = std::chrono::steady_clock::now();
59 for (
int i = 0; i < message_count; ++i) {
63 auto now = std::chrono::steady_clock::now();
64 auto duration = now.time_since_epoch();
65 uint64_t timestamp_ns =
66 std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
68 uint8_t channel_id = i % 6;
72 double base_pressure = 100000.0;
73 double pressure_variation = 50000.0 * std::sin(t * 0.5);
74 double pressure = base_pressure + pressure_variation;
76 double temperature = 25.0 + 5.0 * std::sin(t * 0.3);
78 float quality = 0.95f + 0.05f * std::sin(t);
81 std::get<0>(msg.
fields) = timestamp_ns;
82 std::get<1>(msg.
fields) = channel_id;
83 std::get<2>(msg.
fields) = pressure;
84 std::get<3>(msg.
fields) = temperature;
85 std::get<4>(msg.
fields) = quality;
86 std::get<5>(msg.
fields) = valid;
88 client.publish(calibrated_pt_packet_id, msg);
90 if ((i + 1) % 10 == 0) {
91 std::cout <<
"Sent #" << (i + 1) <<
" (channel=" << (
int)channel_id
92 <<
", pressure=" << (int)pressure <<
" Pa)" << std::endl;
95 std::this_thread::sleep_for(std::chrono::milliseconds(100));
98 auto end_time = std::chrono::steady_clock::now();
100 std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
102 std::cout << std::endl;
103 std::cout <<
"โ
Done! Sent " << message_count <<
" messages in " <<
elapsed <<
" ms"
105 std::cout << std::endl;
106 std::cout <<
"Open Elodin editor: elodin editor <db_path>" << std::endl;
CommsMessage< uint64_t, uint8_t, double, double, float, uint8_t > CalibratedPTMessage
Calibrated pressure transducer message.