STAR
Cal STAR โ€” firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
fake_calibrated_pt.cpp
Go to the documentation of this file.
1/**
2 * Fake generator for CalibratedPTMessage
3 * Validates that calibrated PT data appears correctly in Elodin editor
4 */
5
6#include <array>
7#include <chrono>
8#include <cmath>
9#include <cstdint>
10#include <iostream>
11#include <thread>
12
13#include "../../utl/db.hpp"
15#include "../include/elodin/DatabaseConfig.hpp"
16#include "../include/elodin/ElodinClient.hpp"
17
18using namespace vtable;
19using namespace vtable::builder;
20
21int main(int argc, char* argv[]) {
22 if (argc < 2) {
23 std::cerr << "Usage: " << argv[0] << " <db_port> [message_count]" << std::endl;
24 std::cerr << "Example: " << argv[0] << " 2240 100" << std::endl;
25 return 1;
26 }
27
28 uint16_t port = std::stoi(argv[1]);
29 int message_count = (argc >= 3) ? std::stoi(argv[2]) : 100;
30
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;
35
36 // Connect to Elodin
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;
40 return 1;
41 }
42
43 std::cout << "โœ… Connected to Elodin DB" << std::endl;
44
45 // Register CalibratedPTMessage VTable
46 // TODO: Add registration in DatabaseConfig
47 std::cout << "โš ๏ธ Note: CalibratedPTMessage VTable registration not yet implemented"
48 << std::endl;
49 std::cout << " This test will fail until VTable is registered" << std::endl;
50 std::cout << std::endl;
51
52 // Packet ID for CalibratedPTMessage
53 std::array<uint8_t, 2> calibrated_pt_packet_id = {0x30, 0x00};
54
55 std::cout << "๐Ÿ“ค Sending " << message_count << " CalibratedPTMessage(s)..." << std::endl;
56
57 auto start_time = std::chrono::steady_clock::now();
58
59 for (int i = 0; i < message_count; ++i) {
60 // Create calibrated PT message with realistic pressure values
62
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();
67
68 uint8_t channel_id = i % 6; // Cycle through channels 0-5
69
70 // Generate realistic pressure: sine wave + noise
71 double t = i * 0.1; // Time in seconds
72 double base_pressure = 100000.0; // 100 kPa base pressure
73 double pressure_variation = 50000.0 * std::sin(t * 0.5); // ยฑ50 kPa variation
74 double pressure = base_pressure + pressure_variation;
75
76 double temperature = 25.0 + 5.0 * std::sin(t * 0.3); // Temperature variation
77
78 float quality = 0.95f + 0.05f * std::sin(t); // Quality between 0.95-1.0
79 uint8_t valid = 1;
80
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;
87
88 client.publish(calibrated_pt_packet_id, msg);
89
90 if ((i + 1) % 10 == 0) {
91 std::cout << "Sent #" << (i + 1) << " (channel=" << (int)channel_id
92 << ", pressure=" << (int)pressure << " Pa)" << std::endl;
93 }
94
95 std::this_thread::sleep_for(std::chrono::milliseconds(100));
96 }
97
98 auto end_time = std::chrono::steady_clock::now();
99 auto elapsed =
100 std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
101
102 std::cout << std::endl;
103 std::cout << "โœ… Done! Sent " << message_count << " messages in " << elapsed << " ms"
104 << std::endl;
105 std::cout << std::endl;
106 std::cout << "Open Elodin editor: elodin editor <db_path>" << std::endl;
107
108 return 0;
109}
static const emmc_port_t port
Definition emmc_stm32.c:210
CommsMessage< uint64_t, uint8_t, double, double, float, uint8_t > CalibratedPTMessage
Calibrated pressure transducer message.
static bool elapsed(uint32_t now, uint32_t then, uint32_t interval)
Definition self_test.c:10
std::tuple< Fields... > fields
int main()