Falcon
Loading...
Searching...
No Matches
nlxparser.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 <arpa/inet.h>
23#include <netinet/in.h>
24#include <sys/select.h>
25#include <sys/time.h>
26
27#include <limits>
28#include <string>
29#include <vector>
30
31#include "iprocessor.hpp"
32#include "neuralynx/nlx.hpp"
33#include "options/options.hpp"
34#include "timeseriesdata/timeseriesdata.hpp"
35#include "utilities/time.hpp"
36#include "vectordata/vectordata.hpp"
37
38enum class GapFill { NONE = 0, ASAP, DISTRIBUTED };
39
40std::string gapfill_to_string(GapFill x);
41GapFill string_to_gapfill(std::string s);
42
43namespace YAML {
44template <>
45struct convert<GapFill> {
46 static Node encode(const GapFill& rhs) {
47 Node node;
48 node = gapfill_to_string(rhs);
49 return node;
50 }
51
52 static bool decode(const Node& node, GapFill& rhs) {
53 rhs = string_to_gapfill(node.as<std::string>());
54 return true;
55 }
56};
57} // namespace YAML
58
59class NlxParser : public IProcessor {
60 public:
61 NlxParser();
62 void CreatePorts() override;
63 void CompleteStreamInfo() override;
64 void Prepare(GlobalContext& context) override;
65 void Preprocess(ProcessingContext& context) override;
66 void Process(ProcessingContext& context) override;
67 void Postprocess(ProcessingContext& context) override;
68
69 // METHODS
70 protected:
71 /* log statistics (packet invalid, duplicated, out of order,
72 * missed, gaps, filled + synchronous lag in ms) if update
73 * @input condition log only when true
74 */
75 void print_stats(bool condition = true);
76
77 // VARIABLES
78 protected:
79 unsigned int nchannels_;
80 unsigned int sample_counter_;
81 uint64_t valid_packet_counter_;
82 TimePoint first_valid_packet_arrival_time_;
83 uint64_t timestamp_;
84 uint64_t last_timestamp_;
85 nlx::NlxSignalRecord nlxrecord_;
86 nlx::NlxStatistics stats_;
87 std::vector<unsigned int> channel_list_;
88 int64_t n_filling_packets_;
89
90 // PORTS
91 protected:
92 PortOut<TimeSeriesType<double>>* output_port_signal_;
93 PortOut<TimeSeriesType<uint32_t>>* output_port_ttl_;
94 PortIn<VectorType<uint32_t>>* data_in_port_;
95
96 // STATES
97 protected:
98 BroadcasterState<uint64_t>* n_invalid_;
99
100 // OPTIONS
101 protected:
102 options::Value<unsigned int, false> batch_size_{2};
103 options::Measurement<std::uint64_t, false> update_interval_{
104 20, "second",
105 options::multiplied<std::uint64_t>(nlx::NLX_SIGNAL_SAMPLING_FREQUENCY) +
106 options::zeroismax<std::uint64_t>()};
107 options::Bool triggered_{false};
108 options::Value<uint32_t, false> hardware_trigger_channel_{0};
109 options::Value<GapFill, false> gap_fill_{GapFill::ASAP};
110};
Definition context.hpp:54
Definition streamports.hpp:256
Definition streamports.hpp:98
Definition runinfo.hpp:248
Definition nlx.hpp:144
Definition nlx.hpp:244