23int main(
int argc,
char* argv[]) {
25 std::cerr <<
"Usage: " << argv[0] <<
" <db_port> [message_count]" << std::endl;
26 std::cerr <<
"Example: " << argv[0] <<
" 2240 10" << std::endl;
30 uint16_t
port = std::stoi(argv[1]);
31 int message_count = (argc > 2) ? std::stoi(argv[2]) : 10;
33 std::cout <<
"\n๐งช Sending fake RawPTMessage to Elodin" << std::endl;
34 std::cout <<
"===================================" << std::endl;
35 std::cout <<
"Database: 127.0.0.1:" <<
port << std::endl;
36 std::cout <<
"Messages: " << message_count << std::endl;
37 std::cout <<
"Packet ID: [0x20, 0x00]" << std::endl;
38 std::cout <<
"===================================\n" << std::endl;
42 daq_comms::elodin::ElodinClient client;
43 if (!client.connect(
"127.0.0.1",
port)) {
44 std::cerr <<
"โ Failed to connect to Elodin DB: " << client.last_error() << std::endl;
47 std::cout <<
"โ
Connected to Elodin DB" << std::endl;
53 if (!daq_comms::elodin::DatabaseConfig::register_tables(client)) {
54 std::cerr <<
"โ Failed to register tables" << std::endl;
57 std::cout <<
"โ
Registered VTables" << std::endl;
61 std::cout <<
"โณ Waiting 5 seconds for Elodin to fully process VTable registrations..."
63 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
66 std::cout <<
"๐ค Starting data transmission..." << std::endl;
67 std::cout <<
" Sending " << message_count <<
" RawPTMessage(s) to Elodin" << std::endl;
68 std::cout <<
" Rate: ~10 Hz (100ms between messages)" << std::endl;
69 std::cout << std::endl;
70 auto start_time = std::chrono::steady_clock::now();
72 std::array<uint8_t, 2> pt_packet_id{0x20, 0x00};
74 for (
int i = 0; i < message_count; ++i) {
78 auto now = std::chrono::steady_clock::now();
79 auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(now - start_time);
80 uint64_t timestamp_ns =
elapsed.count();
81 uint8_t channel_id = i % 3;
82 uint32_t raw_adc_counts = 1000 + i * 10;
83 uint32_t sample_timestamp_ms = i * 100;
84 uint8_t status_flags = 0;
88 pt_msg.
setField<2>(std::array<uint8_t, 3>{0, 0, 0});
90 pt_msg.
setField<4>(sample_timestamp_ms);
97 daq_comms::elodin::ElodinClient::serialize_msg(pt_packet_id, pt_msg);
99 std::cout <<
"\n[DEBUG] First message hex dump (" << debug_buf.size()
101 for (
size_t j = 0; j < debug_buf.size(); j++) {
102 std::cout << std::hex << std::setw(2) << std::setfill(
'0')
103 << (int)
static_cast<uint8_t
>(debug_buf[j]) <<
" ";
104 if ((j + 1) % 8 == 0)
107 std::cout << std::dec <<
"\n";
108 std::cout <<
"[DEBUG] Expected: len(4)=" << std::hex << (18 + 4) << std::dec
109 <<
", type=1, packet_id=[0x20,0x00], request_id=0\n";
113 if (!client.publish(pt_packet_id, pt_msg)) {
114 std::cerr <<
"โ Failed to publish message #" << (i + 1) << std::endl;
119 std::cout <<
"[send_fake_pt] โ
Sent #" << (i + 1)
120 <<
" (channel=" << (
int)channel_id <<
", adc=" << raw_adc_counts
121 <<
", timestamp=" << timestamp_ns <<
")" << std::endl;
122 }
else if (i % 50 == 0) {
123 std::cout <<
"[send_fake_pt] ๐ Progress: " << (i + 1) <<
"/" << message_count
124 <<
" messages sent" << std::endl;
128 client.flush_buffer();
129 std::this_thread::sleep_for(std::chrono::milliseconds(100));
133 client.flush_buffer();
135 auto end_time = std::chrono::steady_clock::now();
137 std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);
139 std::cout <<
"\n===================================" << std::endl;
140 std::cout <<
"โ
Transmission Complete!" << std::endl;
141 std::cout <<
" Messages sent: " << message_count << std::endl;
142 std::cout <<
" Duration: " << duration.count() <<
" ms" << std::endl;
143 std::cout <<
" Average rate: " << (message_count * 1000.0 / duration.count()) <<
" msg/s"
145 std::cout <<
"===================================" << std::endl;
146 std::cout <<
"\n๐ View data in Elodin editor:" << std::endl;
147 std::cout <<
" elodin editor ~/.local/share/elodin/test_pt_db" << std::endl;
148 std::cout << std::endl;
152 }
catch (
const std::exception& e) {
153 std::cerr <<
"โ Error: " << e.what() << std::endl;
CommsMessage< uint64_t, uint8_t, std::array< uint8_t, 3 >, uint32_t, uint32_t, uint8_t > RawPTMessage
Raw Pressure Transducer sample message for Elodin.