-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortController.h
137 lines (96 loc) · 3.47 KB
/
PortController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2023 Allen Institute for Brain Science and Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PORTCONTROLLER_H__
#define __PORTCONTROLLER_H__
#include <thread>
#include <chrono>
#include "oni.h"
#include "../OnixDevice.h"
using namespace std::this_thread;
enum class PortControllerRegister : uint32_t
{
ENABLE = 0,
GPOSTATE = 1,
DESPWR = 2,
PORTVOLTAGE = 3,
SAVEVOLTAGE = 4,
LINKSTATE = 5
};
enum class PortStatusCode : uint32_t
{
SerdesLock = 0x0001,
SerdesParityPass = 0x0002,
CrcError = 0x0100,
TooManyDevices = 0x0200,
InitializationError = 0x0400,
BadPacketFormat = 0x0800,
InitializationCrcError = 0x1000,
};
class DiscoveryParameters
{
public:
float minVoltage = 0.0f;
float maxVoltage = 0.0f;
float voltageOffset = 0.0f;
float voltageIncrement = 0.0f;
DiscoveryParameters() {};
DiscoveryParameters(float minVoltage_, float maxVoltage_, float voltageOffset_, float voltageIncrement_)
{
minVoltage = minVoltage_;
maxVoltage = maxVoltage_;
voltageOffset = voltageOffset_;
voltageIncrement = voltageIncrement_;
}
~DiscoveryParameters() {};
bool operator==(const DiscoveryParameters& rhs) const
{
return rhs.minVoltage == minVoltage && rhs.maxVoltage == maxVoltage && rhs.voltageOffset == voltageOffset && rhs.voltageIncrement == voltageIncrement;
}
};
class PortController : public OnixDevice
{
public:
PortController(PortName port_, const oni_ctx ctx_);
~PortController();
int configureDevice() override;
int updateSettings() override { return 0; }
void startAcquisition() override;
void stopAcquisition() override;
void addFrame(oni_frame_t*) override;
void processFrames() override;
void addSourceBuffers(OwnedArray<DataBuffer>& sourceBuffers) override {};
void updateDiscoveryParameters(DiscoveryParameters parameters);
bool configureVoltage(float voltage = defaultVoltage);
/** Sets the voltage to the given value, after setting the voltage to zero */
void setVoltage(float voltage);
/** Overrides the voltage setting and directly sets it to the given voltage */
void setVoltageOverride(float voltage, bool waitToSettle = true);
bool checkLinkState() const;
String getPortNameString(PortName portName);
static DiscoveryParameters getHeadstageDiscoveryParameters(String headstage);
/** Check if the port status changed and there is an error reported */
bool getErrorFlag() { return errorFlag; }
private:
Array<oni_frame_t*, CriticalSection, 10> frameArray;
const PortName port;
static constexpr float defaultVoltage = -1.0f;
const uint32_t LINKSTATE_PP = 0x2; // parity check pass bit
const uint32_t LINKSTATE_SL = 0x1; // SERDES lock bit
DiscoveryParameters discoveryParameters;
std::atomic<bool> errorFlag = false;
};
#endif // !__PORTCONTROLLER_H__