Falcon
Loading...
Searching...
No Matches
eventdelayed.hpp
1// ---------------------------------------------------------------------
2// This file is part of falcon-core.
3//
4// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5//
6// Falcon-server is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Falcon-server is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------
19
20#pragma once
21
22#include <queue>
23#include <string>
24
25#include "eventconverter/eventconverter.hpp"
26#include "eventdata/eventdata.hpp"
27#include "iprocessor.hpp"
28#include "utilities/general.hpp"
29#include "utilities/math_numeric.hpp"
30#include "utilities/time.hpp"
31
32struct Delayed {
33 TimePoint ts;
34 EventType::Data* data_in;
35
36 Delayed(TimePoint ts, EventType::Data* data_in) : ts(ts), data_in(data_in) {}
37 bool operator>(const Delayed& test) const { return (ts > test.ts); }
38};
39
40class EventDelayed : public IProcessor {
41 // CONSTRUCTOR and OVERLOADED METHODS
42 public:
43 EventDelayed();
44 void CreatePorts() override;
45 void Configure(const GlobalContext& context) override;
46 void CompleteStreamInfo() override;
47 void Preprocess(ProcessingContext& context) override;
48 void Process(ProcessingContext& context) override;
49 void Postprocess(ProcessingContext& context) override;
50
51 /* Use with delayed event check if enough time will have passed between this
52 * stimulation and the last occuring stimulation. if still in the look out
53 * period, the event is ignored.
54 * @input TimePoint when the new stimulation should occur in the future.
55 * @return true if still in the look out period
56 */
57 bool to_lock_out_in_future(TimePoint start_event);
58 /* check if enough time has passed since the last triggered event. if still
59 * in the look out period, the event is ignored.
60 *
61 * @return true if still in the look out period
62 */
63 bool to_lock_out();
64
65 // DATA PORTS
66 protected:
67 PortIn<EventType>* data_in_port_;
68 PortOut<EventType>* output_port_;
69
70 // STATES
71 protected:
72 FollowerState<bool>* disabled_;
73 FollowerState<bool>* delayed_event_;
74 StaticState<double>* stop_detection_period_;
75 StaticState<double>* stop_analysis_period_;
76 BroadcasterState<bool>* analysis_unlocked_;
77
78 // OPTIONS
79 protected:
80 options::Bool default_disabled_{false};
81 options::Measurement<double, false> initial_stop_detection_period_{
82 50, "ms", options::positive<double>(false)};
83 options::Value<std::vector<int>, true> when_stop_analysis_period_{{0, 0}};
84 options::Measurement<double, false> initial_stop_analysis_period_{
85 50., "ms", options::positive<double>(false)};
86 options::Bool start_after_detection_{false};
87 options::Bool start_after_stimulation_{true};
88 options::Bool initial_delayed_event_{false};
89 options::Bool save_events_{true};
90 options::String prefix_{"stim_"};
91 options::String msg_delayed_{"d"};
92 options::String msg_detection_{"r"};
93 options::String msg_ontime_{"o"};
94 options::Value<std::vector<long int>, true> initial_delayed_range_{{150, 200}};
95
96 private:
97 void send_event(EventType::Data* data_in, std::string type);
98 // variables
99 protected:
100 uint64_t ontime_received_event_;
101 uint64_t delayed_received_event_;
102 uint64_t event_lockout_;
103
104 Range<long int> delayed_range_;
105 TimePoint previous_TS_nostim_;
106
107 std::priority_queue<Delayed, std::vector<Delayed>, std::greater<Delayed>> delayed_event_queue_;
108
109 std::priority_queue<Delayed, std::vector<Delayed>, std::greater<Delayed>> lockout_queue_;
110
111 // CONSTANT
112 protected:
113 const std::string DISABLED_S = "detection_only_mode";
114 const std::string DELAYED_S = "delayed_mode";
115 const std::string STOP_DETECTION_TIME_S = "event_trigger_lockout_time";
116 const std::string STOP_ANALYSIS_TIME_S = "analysis_lockout_time";
117};
Definition context.hpp:54
const std::string type() const
Definition iprocessor.hpp:131
Definition streamports.hpp:256
Definition streamports.hpp:98
Definition runinfo.hpp:248