REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
user_plugin_static.cpp
Go to the documentation of this file.
1#include <proto/main.pb.h>
2
3#include <plugin/static.h>
4#include <run/run.h>
5#include <protocol/protocol.h>
6#include <protocol/protocol_oob.h>
7
8constexpr uint16_t bufsize = 300;
9uint16_t *results = nullptr;
10size_t cur_run = 0;
11run::Run *reprun = nullptr;
12
13void tear_down() {
14 delete reprun;
15 delete results;
16 cur_run = 0;
17}
18
19/*
20class MonteCarloHandler : public msg::handlers::MessageHandler {
21public:
22 int handle(JsonObjectConst msg_in, utils::StreamingJson &msg_out) override {
23 if(msg_in.containsKey("run_delete"))
24 tear_down();
25
26 if(msg_in.containsKey("run_config")) {
27 auto run_config_json = msg_in["run_config"].as<JsonObjectConst>();
28 auto run_config = run::RunConfig::from_pb(run_config_json);
29 if(reprun)
30 tear_down();
31
32
33 reprun = new run::Run(
34 "monte_carlo",
35 run_config,
36 std::make_unique<client::RunStateChangeNotificationHandler>(msg_out.output),
37 std::make_unique<client::RunDataNotificationHandler>(msg_out.output),
38 daq::DAQConfig::silence()
39 );
40 }
41
42 return success;
43 }
44};*/
45
46void static_plugin::setup() {
47 //msg::handlers::Registry::get().set("monte_carlo", new MonteCarloHandler(), net::auth::SecurityLevel::RequiresLogin);
48}
49
50void static_plugin::loop() {
51 if(!reprun) return;
52
53 if(!results) {
54 results = new uint16_t[bufsize]; // because RAM2 has more of leftover
55 }
56
57 // carry out the next run, not streaming any data during run.
58 // TODO: Add carrier reference to plugins and fix this call
59 auto carrier = static_cast<carrier::Carrier*>(nullptr);
60 reprun->run(*carrier);
61 // sample exactly one channel at end of run.
62 results[cur_run++] = daq::sample_raw()[0];
63
64 if(cur_run < bufsize) return;
65
66 // stream out the results, reusing existing infrastructure.
67 //reprun->streaming_run_data_notification_handler->handle(results, bufsize, 1, *reprun);
68 cur_run = 0;
69}
Definition daq.h:14
void tear_down()
uint16_t * results
constexpr uint16_t bufsize
run::Run * reprun
size_t cur_run