Repository navigation
Expand file tree
/
Copy pathdevBrammi.hpp
More file actions
205 lines (185 loc) · 6.6 KB
/
Copy pathdevBrammi.hpp
File metadata and controls
205 lines (185 loc) · 6.6 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef __DEVBRAMMI_HPP
#define __DEVBRAMMI_HPP
#include "commBase.hpp"
#include <thread>
#include <array>
#include <atomic>
#include <mutex>
/**
* \brief Contains all types for communications with Phoenix Brammi device.
*/
namespace Brammi {
/// \enum Brammi::enModes_t
/// \brief Brammi device operating modes.
enum class enModes_t : char {
Idle = 'I', ///< Idle mode.
Mattress = 'M', ///< Mattress mode.
Servo = 'S', ///< Servo mode.
Warming = 'W' ///< Warming mode.
};
/// \enum Brammi::enConnectionType_t
/// \brief Brammi device connectiob type.
enum class enConnectionType_t {
UART, ///< Virtual COMx port.
USB ///< FTDI with Brammi description.
};
/// \enum Brammi::enStatus_t
/// \brief Brammi driver status.
enum class enStatus_t : int {
INVALID_PARAMETER = -4, ///< Passed parameter out of range.
NOT_CONECTED = -3, ///< Connection not established.
CONNECTION_LOST = -2, ///< Connection lost crtitical error.
TIMEOUT = -1, ///< Brammi data timeout.
SUCCESS = 0, ///< Brammi data success.
CONECTING = 1, ///< Establishing connection.
};
/// \struct Brammi::stData_t
/// \brief Brammi data set.
struct stData_t {
uint32_t patientID;
enModes_t mode;
uint16_t therapySetTime;
uint16_t therapyRuntime;
float setTemp;
float rectalTemp;
float skinTemp;
float mattressTemp;
uint16_t waterFlow;
uint16_t waterLevel;
uint16_t pletierPowerLevel;
uint32_t serialNumber;
union {
struct {
uint8_t systemErrorM : 1;
uint8_t systemErrorF : 1;
uint8_t systemErrorP : 1;
uint8_t waterFlowFail : 1;
uint8_t babySkinOverTemp : 1;
uint8_t matterssProbeFail : 1;
uint8_t mattressTooCold : 1;
uint8_t rectalProbeFail : 1;
} field;
uint8_t value;
} alarm1;
union {
struct {
uint8_t rectalProbeDislocated : 1;
uint8_t babyCoreTempTooLow : 1;
uint8_t babyCoreOverTemp : 1;
uint8_t matterssOverTemp : 1;
uint8_t skinProbeFail : 1;
uint8_t babyCoreTempHigh : 1;
uint8_t babyCoreTempLow : 1;
uint8_t powerFail : 1;
} field;
uint8_t value;
} alarm2;
union {
struct {
uint8_t connetToMains : 1;
uint8_t mattressTempLow : 1;
uint8_t mattressTempHigh : 1;
uint8_t skinProbeDislocated : 1;
uint8_t therapyCompleted : 1;
uint8_t controlCardError : 1;
uint8_t unexpectedSystemError : 1;
uint8_t batteryLow : 1;
} field;
uint8_t value;
} alarm3;
union {
struct {
uint8_t waterLevelLow : 1;
uint8_t waterLevelSensorFail : 1;
uint8_t reserve1 : 1;
uint8_t reserve2 : 1;
uint8_t reserve3 : 1;
uint8_t reserve4 : 1;
uint8_t reserve5 : 1;
} field;
uint8_t value;
} alarm4;
};
/**
* \class Driver
* \brief Comunication and data extractig of Phoenix Brammi device.
*/
class Driver {
public:
/// \brief Constructs a new Driver object.
Driver()
: thd_dataParsing_terminate(false), status(enStatus_t::NOT_CONECTED),
deviceName("unknown"), motherName("unknown"), commDrv(nullptr)
{
brammiData.patientID = (-1); //set unknown patientID
}
/// \brief Closing connection and destructs Driver object.
~Driver() { stop(); }
/**
* \brief Start communication with Brammi device.
*
* \param type Connection type.
* \param comPort Virtual COMx port number for UART typ only.
* \return True if communication started, false otherwise.
*/
bool start(enConnectionType_t type, int comPort = -1);
/**
* \brief Stop Brammi device communication.
*
* \return always True.
*/
bool stop();
/**
* @brief Gets Brammi device name.
*
* \param deviceNameBuff Pointer to buffer for a device name.
* \param buffSize Size of passed buffer.
* \return Driver status as integer of enStatus_t type.
*
* \details
* Returns INVALID_PARAMETER if buffor to short or not exist.
*
* \see enStatus_t
*/
int getDeviceName(char *deviceNameBuff, size_t buffSize);
/**
* @brief Gets patient mothers name.
*
* \param motherNameBuff Pointer to buffer for a mothers name.
* \param buffSize Size of passed buffer.
* \return Driver status as integer of enStatus_t type.
*
* \details
* Returns INVALID_PARAMETER if buffor to short or not exist.
*
* \see enStatus_t
*/
int getMotherName(char *motherNameBuff, size_t buffSize);
/**
* \brief Gets Brammi data structure.
*
* \param brammiDataSet Reference to brammi data structure.
* \return Driver status as integer of enStatus_t type.
*
* \see enStatus_t
* \see stData_t
*/
int getBrammiData(stData_t& brammiDataSet);
private:
//connection establishing packet
const uint8_t OEM_PACKET[7] = { 0x02, 0x03, 0x50, 0x4D, 0x53, 0xF0, 0x03 };
bool thd_dataParsing_terminate;
std::thread thd_dataParsing;
std::mutex mtx_rw;
enStatus_t status;
std::string deviceName;
std::string motherName;
stData_t brammiData;
std::atomic<stData_t> brammiData2;
std::unique_ptr<commBase> commDrv;
void dataParsing_task() noexcept;
bool get_line(std::string& ln);
std::string get_token(std::string& line, char delimiter);
};
}
#endif // !__DEVBRAMMI_HPP