muse-api 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Muse_Data.py ADDED
@@ -0,0 +1,225 @@
1
+ """ Muse_Data.py: Muse data objects definitions.
2
+
3
+ This program is free software: you can redistribute it and/or modify it under
4
+ the terms of the GNU General Public License as published by the Free Software
5
+ Foundation, either version 3 of the License, or (at your option) any later
6
+ version.
7
+
8
+ This program is distributed in the hope that it will be useful, but WITHOUT
9
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+
12
+ You should have received a copy of the GNU General Public License along with
13
+ this program. If not, see <http://www.gnu.org/licenses/>.
14
+ """
15
+
16
+ __authors__ = ["Luigi Mattiello", "Francesca Palazzo", "Roberto Bortoletto"]
17
+ __contact__ = "info@221e.com"
18
+ __copyright__ = "Copyright (c) 2020 by 221e srl."
19
+ __credits__ = ["Luigi Mattiello", "Francesca Palazzo", "Roberto Bortoletto"]
20
+ __deprecated__ = False
21
+ __email__ = "roberto.bortoletto@221e.com"
22
+ __license__ = "GNU General Public License"
23
+ __maintainer__ = "Roberto Bortoletto"
24
+ __status__ = "Production"
25
+ __version__ = "2.0.0"
26
+
27
+ class CommandResponse:
28
+ """Command response object"""
29
+ def __init__(self, buffer: bytearray):
30
+ """Command response object constructor
31
+
32
+ Args:
33
+ buffer (bytearray): response buffer
34
+ """
35
+ from Muse_HW import Muse_HW as MH
36
+ if buffer is not None:
37
+ self.rx = MH.Command(buffer[0])
38
+ if buffer[2] > 0x80:
39
+ self.tx = MH.Command(buffer[2] & 0x7F)
40
+ self.read = True
41
+ else:
42
+ self.tx = MH.Command(buffer[2])
43
+ self.read = False
44
+
45
+
46
+ self.len = buffer[1]
47
+ self.ack = MH.AcknowledgeType(buffer[3])
48
+
49
+ self.payload = buffer[4:4+self.len-2]
50
+ else:
51
+ self.rx = MH.Command.CMD_NONE
52
+ self.tx = MH.Command.CMD_NONE
53
+ self.len = -1
54
+ self.ack = MH.AcknowledgeType.ACK_NONE
55
+ self.payload = None
56
+
57
+ class SensorConfig:
58
+ """Sensors configuration structure
59
+ """
60
+ def __init__(self, fs: int, sens: float):
61
+ """MEMS configuration object constructor
62
+
63
+ Args:
64
+ fs (int): Full scale
65
+ sens (float): Sensitivity
66
+ """
67
+ self.FullScale = fs
68
+ self.Sensitivity = sens
69
+
70
+ def __str__(self):
71
+ """Override of ToString method
72
+
73
+ Returns:
74
+ string containing the full scale and sensitivity of the sensor
75
+ """
76
+ details = '{}, {}'.format(self.FullScale, self.Sensitivity)
77
+ return details
78
+
79
+ class FileInfo:
80
+ """File Information structure
81
+ """
82
+ def __init__(self, timestamp: int, gyrConfig: SensorConfig, axlConfig: SensorConfig, magConfig: SensorConfig, hdrConfig: SensorConfig, mode: int, frequency: int):
83
+ """FileInfo constructor
84
+
85
+ Args:
86
+ timestamp (int): Timestamp
87
+ gyrConfig (SensorConfig): Gyroscope configuration
88
+ axlConfig (SensorConfig): Accelerometer configuration
89
+ magConfig (SensorConfig): Magnetometer configuration
90
+ hdrConfig (SensorConfig): HDR Accelerometer configuration
91
+ mode (int): Acquisition mode
92
+ frequency (int): Acquisition frequency
93
+ """
94
+ from Muse_HW import Muse_HW as MH
95
+ from Muse_Utils import Muse_Utils as MU
96
+ self.timestamp = timestamp
97
+
98
+ self.GyrConfig = gyrConfig
99
+ self.AxlConfig = axlConfig
100
+ self.MagConfig = magConfig
101
+ self.HDRConfig = hdrConfig
102
+
103
+ self.ModeString = MU.DataModeToString(mode)
104
+ self.Mode = MH.DataMode(mode)
105
+
106
+
107
+ self.Frequency = MH.DataFrequency(frequency).value
108
+ self.FrequencyString = MU.DataFrequencyToString(MH.DataFrequency(frequency))
109
+
110
+ def __str__(self) -> str:
111
+ """Override of ToString method
112
+ """
113
+ return str(self.timestamp) + ", " + str(self.GyrConfig) + ", " + str(self.AxlConfig) + ", " + str(self.MagConfig) + ", " + str(self.HDRConfig) + ", " + str(self.ModeString) + ", " + str(self.FrequencyString)
114
+
115
+ class UserConfig:
116
+ """User Configuration object"""
117
+
118
+ def __init__(self, standby: bool, memory: bool, ble: bool, usb: bool, tcp: bool, mqtt: bool, mpe9dof: bool, slowfreq: bool, mqttcommands: bool):
119
+ """UserConfig object constructor
120
+
121
+ Args:
122
+ standby (bool): Boolean enabled/disabled standby status
123
+ memory (bool): Boolean enabled/disabled circular memory status
124
+ ble (bool): Boolean enabled/disabled BLE stream status
125
+ usb (bool): Boolean enabled/disabled USB stream status
126
+ tcp (bool): Boolean enabled/disabled TCP stream status
127
+ mqtt (bool): Boolean enabled/disabled MQTT stream status
128
+ mpe9dof (bool): Boolean enabled/disabled 9DOF MPE (only if MPE is present)
129
+ slowfreq (bool): Boolean enabled/disabled slow frequency streaming
130
+ mqttcommands (bool): Boolean enabled/disabled MQTT commands
131
+ """
132
+ self.AutoStandby = standby
133
+ self.CircularMemory = memory
134
+ self.StreamingSelectBLE = ble
135
+ self.StreamingSelectUSB = usb
136
+ self.StreamingSelectTCP = tcp
137
+ self.StreamingSelectMQTT = mqtt
138
+ self.MPE9DOF = mpe9dof
139
+ self.SlowFrequency = slowfreq
140
+ self.MQTTcommands = mqttcommands
141
+
142
+
143
+ def __str__(self) -> str:
144
+ """Override of ToString method
145
+ """
146
+ return ("USER CONFIGURATION\n"+"standby: "+str(self.AutoStandby) + "\ncircular memory: " + str(self.CircularMemory) + "\nchannel BLE streaming: " + str(self.StreamingSelectBLE) +
147
+ "\nchannel USB streaming: " + str(self.StreamingSelectUSB) + "\nchannel TCP streaming: " + str(self.StreamingSelectTCP) + "\nchannel MQTT streaming: " + str(self.StreamingSelectMQTT) +
148
+ "\nMPE 9DOF: " + str(self.MPE9DOF) + "\nslow frequency: " + str(self.SlowFrequency) + "\nMQTT commands: " + str(self.MQTTcommands))
149
+
150
+ class Light:
151
+ """Light object"""
152
+ def __init__(self, range: int , vis: int, ir: int, lux: int):
153
+ """Light object constructor
154
+
155
+ Args:
156
+ range (int): range value
157
+ vis (int): visible luminosity
158
+ ir (int): infrared luminosity
159
+ lux (int): LUX value computed from visible and infrared luminosity
160
+ """
161
+ self.range = range
162
+ self.lum_vis = vis
163
+ self.lum_ir = ir
164
+ self.lux = lux
165
+
166
+
167
+ def __str__(self) -> str:
168
+ """Override of ToString method
169
+ """
170
+ return str(self.range) + "\t" + str(self.lum_vis) + "\t" + str(self.lum_ir) + "\t" + str(self.lux)
171
+
172
+ class Muse_Data:
173
+ """Muse Data object"""
174
+ def __init__(self):
175
+ """Muse Data object constructor
176
+ """
177
+ self.gyr = [0.0] * 3
178
+ self.axl = [0.0] * 3
179
+ self.mag = [0.0] * 3
180
+ self.hdr = [0.0] * 3
181
+ self.th = [0.0] * 3
182
+ self.tp = [0.0] * 3
183
+
184
+ self.light = Light(0,0,0,0)
185
+
186
+ self.sound = 0
187
+
188
+ self.quat = [0.0] * 4
189
+ self.euler = [0.0] * 3
190
+
191
+ self.timestamp = 0
192
+ self.overall_timestamp = 0
193
+
194
+
195
+ def ChannelsToString(arg) -> str:
196
+
197
+ str_out = ""
198
+
199
+ for i in range(len(arg) -1):
200
+ str_out += str(arg[i]) + "\t"
201
+
202
+ str_out += str(arg[len(arg) - 1])
203
+
204
+ return str_out
205
+
206
+
207
+ def __str__(self):
208
+ """Override of ToString method
209
+ """
210
+ str = str(self.overall_timestamp) + "\t" + \
211
+ str(self.timestamp) + "\t" + \
212
+ self.ChannelsToString(self.gyr) + "\t" + \
213
+ self.ChannelsToString(self.axl) + "\t" + \
214
+ self.ChannelsToString(self.mag) + "\t" + \
215
+ self.ChannelsToString(self.hdr) + "\t" + \
216
+ self.ChannelsToString(self.th) + "\t" + \
217
+ self.ChannelsToString(self.tp) + "\t" + \
218
+ self.light + "\t" + \
219
+ self.ChannelsToString(self.quat)
220
+
221
+ return str
222
+
223
+
224
+
225
+