Falcon
Toggle main menu visibility
Loading...
Searching...
No Matches
nlxreader.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 <cstdint>
28
#include <limits>
29
#include <map>
30
#include <string>
31
#include <vector>
32
33
#include "iprocessor.hpp"
34
#include "neuralynx/nlx.hpp"
35
#include "options/options.hpp"
36
#include "recording_utilities/channellist.hpp"
37
#include "timeseriesdata/timeseriesdata.hpp"
38
#include "utilities/time.hpp"
39
40
typedef
std::map<std::string, ChannelList<unsigned int>> ChannelMap;
41
42
class
NlxReader :
public
IProcessor {
43
// CONSTRUCTOR and OVERLOADED METHODS
44
public
:
45
NlxReader();
46
void
Configure(
const
GlobalContext
& context)
override
;
47
void
CreatePorts()
override
;
48
void
CompleteStreamInfo()
override
;
49
void
Prepare(
GlobalContext
& context)
override
;
50
void
Preprocess(
ProcessingContext
& context)
override
;
51
void
Process(
ProcessingContext
& context)
override
;
52
void
Postprocess(
ProcessingContext
& context)
override
;
53
54
// METHODS
55
protected
:
56
/* log statistics (packet invalid, duplicated, out of order,
57
* missed, gaps, filled + synchronous lag in ms) if update
58
* @input condition log only when true
59
*/
60
void
print_stats(
bool
condition =
true
);
61
62
// PORT
63
protected
:
64
std::map<std::string, PortOut<TimeSeriesType<double>>*> data_ports_;
65
66
// CONSTANTS
67
public
:
68
struct
timeval timeout_;
69
const
decltype
(timeout_.tv_sec) TIMEOUT_SEC = 3;
70
static
constexpr
uint16_t MAX_NCHANNELS = 128;
71
static
constexpr
decltype
(MAX_NCHANNELS) UDP_BUFFER_SIZE =
72
nlx::NLX_PACKETBYTESIZE(MAX_NCHANNELS);
73
74
// VARIABLES
75
protected
:
76
fd_set file_descriptor_set_;
77
int
udp_socket_;
78
struct
sockaddr_in server_addr_;
79
80
unsigned
int
sample_counter_;
81
uint64_t valid_packet_counter_;
82
83
TimePoint first_valid_packet_arrival_time_;
84
uint64_t timestamp_;
85
uint64_t last_timestamp_;
86
87
// UDP_BUFFER_SIZE is in bytes, so divide by size of int32_t
88
char
buffer_[UDP_BUFFER_SIZE];
89
90
nlx::NlxSignalRecord
nlxrecord_;
91
nlx::NlxStatistics
stats_;
92
93
// OPTIONS
94
protected
:
95
options::Value<ChannelMap, false> channelmap_;
96
options::String address_{
"127.0.0.1"
};
97
options::Value<unsigned int, false> port_{5000};
98
options::Value<std::uint64_t, false> npackets_{0, options::zeroismax<std::uint64_t>()};
99
options::Value<unsigned int, false> batch_size_{1};
100
options::Value<unsigned int, false> nchannels_{nlx::NLX_DEFAULT_NCHANNELS};
101
options::Measurement<std::uint64_t, false> update_interval_{5,
"second"
};
102
options::Bool triggered_{
false
};
103
options::Value<uint32_t, false> hardware_trigger_channel_{0};
104
};
GlobalContext
Definition
context.hpp:54
ProcessingContext
Definition
runinfo.hpp:248
nlx::NlxSignalRecord
Definition
nlx.hpp:144
nlx::NlxStatistics
Definition
nlx.hpp:244
extensions
falcon-fklab-extensions
processors
nlxreader
nlxreader.hpp
Generated by
1.18.0