qlsdk2 0.6.0a6__tar.gz → 0.6.0a7__tar.gz

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.
Files changed (84) hide show
  1. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/PKG-INFO +1 -1
  2. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/setup.py +1 -1
  3. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/persist/ars_edf.py +3 -28
  4. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/persist/rsc_edf.py +1 -1
  5. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/command/__init__.py +6 -4
  6. qlsdk2-0.6.0a7/src/qlsdk/rsc/device/arskindling.py +95 -0
  7. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/device/base.py +56 -38
  8. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/device/c16_rs.py +1 -5
  9. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/device/c256_rs.py +13 -1
  10. qlsdk2-0.6.0a7/src/qlsdk/rsc/device/c64s1.py +29 -0
  11. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/interface/device.py +9 -1
  12. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/parser/base.py +1 -1
  13. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk2.egg-info/PKG-INFO +1 -1
  14. qlsdk2-0.6.0a6/src/qlsdk/rsc/device/arskindling.py +0 -386
  15. qlsdk2-0.6.0a6/src/qlsdk/rsc/device/c64s1.py +0 -365
  16. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/README.md +0 -0
  17. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/setup.cfg +0 -0
  18. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/__init__.py +0 -0
  19. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/ar4/__init__.py +0 -0
  20. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/ar4m/__init__.py +0 -0
  21. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/__init__.py +0 -0
  22. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/crc/__init__.py +0 -0
  23. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/crc/crctools.py +0 -0
  24. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/device.py +0 -0
  25. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/entity/__init__.py +0 -0
  26. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/exception.py +0 -0
  27. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/filter/__init__.py +0 -0
  28. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/filter/norch.py +0 -0
  29. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/local.py +0 -0
  30. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/message/__init__.py +0 -0
  31. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/message/command.py +0 -0
  32. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/message/tcp.py +0 -0
  33. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/message/udp.py +0 -0
  34. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/network/__init__.py +0 -0
  35. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/network/monitor.py +0 -0
  36. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/core/utils.py +0 -0
  37. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/entity/__init__.py +0 -0
  38. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/entity/message.py +0 -0
  39. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/entity/signal.py +0 -0
  40. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/__init__.py +0 -0
  41. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/analyzer.py +0 -0
  42. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/collector.py +0 -0
  43. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/device.py +0 -0
  44. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/parser.py +0 -0
  45. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/stimulator.py +0 -0
  46. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/interface/store.py +0 -0
  47. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/persist/__init__.py +0 -0
  48. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/persist/edf.py +0 -0
  49. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/persist/stream.py +0 -0
  50. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/__init__.py +0 -0
  51. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/device/__init__.py +0 -0
  52. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/device/c64_rs.py +0 -0
  53. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/device/device_factory.py +0 -0
  54. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/eegion.py +0 -0
  55. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/entity.py +0 -0
  56. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/interface/__init__.py +0 -0
  57. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/interface/command.py +0 -0
  58. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/interface/handler.py +0 -0
  59. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/interface/parser.py +0 -0
  60. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/manager/__init__.py +0 -0
  61. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/manager/container.py +0 -0
  62. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/manager/search.py +0 -0
  63. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/network/__init__.py +0 -0
  64. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/network/discover.py +0 -0
  65. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/paradigm.py +0 -0
  66. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/parser/__init__.py +0 -0
  67. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/parser/base-new.py +0 -0
  68. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/parser/rsc.py +0 -0
  69. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/rsc/proxy.py +0 -0
  70. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/sdk/__init__.py +0 -0
  71. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/sdk/ar4sdk.py +0 -0
  72. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/sdk/hub.py +0 -0
  73. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/sdk/libs/libAr4SDK.dll +0 -0
  74. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/sdk/libs/libwinpthread-1.dll +0 -0
  75. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/x8/__init__.py +0 -0
  76. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk/x8m/__init__.py +0 -0
  77. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk2.egg-info/SOURCES.txt +0 -0
  78. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk2.egg-info/dependency_links.txt +0 -0
  79. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk2.egg-info/requires.txt +0 -0
  80. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/src/qlsdk2.egg-info/top_level.txt +0 -0
  81. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/test/test.222.py +0 -0
  82. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/test/test.py +0 -0
  83. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/test/test_ar4m.py +0 -0
  84. {qlsdk2-0.6.0a6 → qlsdk2-0.6.0a7}/test/test_bdf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qlsdk2
3
- Version: 0.6.0a6
3
+ Version: 0.6.0a7
4
4
  Summary: SDK for quanlan device
5
5
  Home-page: https://github.com/hehuajun/qlsdk
6
6
  Author: hehuajun
@@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8' ) as fh:
6
6
 
7
7
  setuptools.setup(
8
8
  name="qlsdk2",
9
- version="0.6.0a6",
9
+ version="0.6.0a7",
10
10
  author="hehuajun",
11
11
  author_email="hehuajun@eegion.com",
12
12
  description="SDK for quanlan device",
@@ -195,39 +195,14 @@ class ARSKindlingEDFHandler(object):
195
195
  if packet is None:
196
196
  # self._edf_writer_thread.stop_recording()
197
197
  for k in self._edf_handler.keys():
198
- self._edf_handler[k].append(None)
198
+ self._edf_handler[k].write(None)
199
199
  return
200
200
 
201
- #按分区写入数据
202
-
201
+ #按分区写入数据
203
202
  for k in self._channel_spilt.keys():
204
- logger.info(f'分区{k}, {self._channel_spilt[k]}')
203
+ logger.trace(f'分区{k}, {self._channel_spilt[k]}')
205
204
  p = packet
206
205
  self.writeA(p, self._channel_spilt[k], k)
207
-
208
- # with self._lock:
209
- # if self.channels is None:
210
- # logger.info(f"开始记录数据到文件...")
211
- # self.channels = packet.channels
212
- # self._first_pkg_id = packet.pkg_id if self._first_pkg_id is None else self._first_pkg_id
213
- # self._first_timestamp = packet.time_stamp if self._first_timestamp is None else self._first_timestamp
214
- # self._start_time = datetime.now()
215
- # logger.info(f"第一个包id: {self._first_pkg_id }, 时间戳:{self._first_timestamp}, 当前时间:{datetime.now().timestamp()} offset: {datetime.now().timestamp() - self._first_timestamp}")
216
-
217
- # if self._last_pkg_id and self._last_pkg_id != packet.pkg_id - 1:
218
- # self._lost_packets += packet.pkg_id - self._last_pkg_id - 1
219
- # logger.warning(f"数据包丢失: {self._last_pkg_id} -> {packet.pkg_id}, 丢包数: {packet.pkg_id - self._last_pkg_id - 1}")
220
-
221
- # self._last_pkg_id = packet.pkg_id
222
- # self._total_packets += 1
223
-
224
- # if self._edf_writer_thread is None:
225
- # self._edf_writer_thread = EDFStreamWriter(self.channels, self.sample_rate, self.physical_max, self.physical_min, self.file_type, self.file_name)
226
- # self._edf_writer_thread.set_start_time(self._start_time)
227
- # self._edf_writer_thread.start()
228
- # logger.info(f"开始写入数据: {self.file_name}")
229
-
230
- # self._edf_writer_thread.append(packet.eeg)
231
206
 
232
207
  def writeA(self, packet: RscPacket, channel_filter, name='A'):
233
208
  # 参数检查
@@ -62,7 +62,7 @@ class EDFStreamWriter(Thread):
62
62
  self._recording = False
63
63
 
64
64
  def append(self, data):
65
- if data:
65
+ if data is not None:
66
66
  # 数据
67
67
  self.data_queue.put(data)
68
68
 
@@ -243,8 +243,9 @@ class StartStimulationCommand(DeviceCommand):
243
243
  # error_channel - 8B
244
244
  # error_channel= int.from_bytes(body[9:17], 'big')
245
245
  channels = to_channels(body[9:17])
246
- logger.success(f"通道 {channels} 刺激开始")
247
- self.device.trigger(f"通道 {channels} 刺激开始")
246
+ logger.info(f"通道 {channels} 刺激开始")
247
+ if self.device:
248
+ self.device.trigger(f"通道 {channels} 刺激开始")
248
249
  # error_type - 1B
249
250
  error_type = body[17]
250
251
 
@@ -268,8 +269,9 @@ class StopStimulationNotifyCommand(DeviceCommand):
268
269
  # error_channel - 8B
269
270
  # error_channel= int.from_bytes(body[9:17], 'big')
270
271
  channels = to_channels(body[9:17])
271
- logger.success(f"通道 {channels} 刺激结束")
272
- self.device.trigger(f"通道 {channels} 刺激结束", time)
272
+ logger.info(f"通道 {channels} 刺激结束")
273
+ if self.device:
274
+ self.device.trigger(f"通道 {channels} 刺激结束", time)
273
275
  # error_type - 1B
274
276
  error_type = body[17]
275
277
  # 刺激信息
@@ -0,0 +1,95 @@
1
+ from loguru import logger
2
+ from qlsdk.persist import ARSKindlingEDFHandler
3
+ from qlsdk.rsc.interface import IDevice
4
+ from qlsdk.rsc.command import *
5
+ from qlsdk.rsc.device.base import QLBaseDevice
6
+
7
+ class ARSKindling(QLBaseDevice):
8
+
9
+ device_type = 0x60 # C64RS设备类型标识符
10
+
11
+ def __init__(self, socket):
12
+ super().__init__(socket)
13
+
14
+ self.channel_mapping = {
15
+ "A1": 55, "A2": 56, "A3": 53, "A4": 54, "A5": 51, "A6": 52, "A7": 49, "A8": 50,
16
+ "A9": 57, "A10": 58, "A11": 59, "A12": 60, "A13": 61, "A14": 62,
17
+
18
+ "B1": 39, "B2": 40, "B3": 37, "B4": 38, "B5": 35, "B6": 36, "B7": 33, "B8": 34,
19
+ "B9": 41, "B10": 42, "B11": 43, "B12": 44, "B13": 45, "B14": 46,
20
+
21
+ "C1": 23, "C2": 24, "C3": 21, "C4": 22, "C5": 19, "C6": 20, "C7": 17, "C8": 18,
22
+ "C9": 25, "C10": 26, "C11": 27, "C12": 28, "C13": 29, "C14": 30,
23
+
24
+ "D1": 7, "D2": 8, "D3": 5, "D4": 6, "D5": 3, "D6": 4, "D7": 1, "D8": 2,
25
+ "D9": 9, "D10": 10, "D11": 11, "D12": 12, "D13": 13, "D14": 14,
26
+ }
27
+
28
+ @classmethod
29
+ def from_parent(cls, parent:IDevice) -> IDevice:
30
+ rlt = cls(parent.socket)
31
+ rlt.device_id = parent.device_id
32
+ rlt._device_no = parent.device_no
33
+ return rlt
34
+
35
+ def init_edf_handler(self):
36
+ self._edf_handler = ARSKindlingEDFHandler(self.sample_rate, self.sample_range * 1000 , - self.sample_range * 1000, self.resolution)
37
+ self._edf_handler.set_device_type(self.device_type)
38
+ self._edf_handler.set_device_no(self.device_no)
39
+ self._edf_handler.set_storage_path(self._storage_path)
40
+ self._edf_handler.set_file_prefix(self._file_prefix if self._file_prefix else 'ARS')
41
+ logger.debug(f"EDF Handler initialized")
42
+
43
+ # 设置采集参数
44
+ def set_acq_param(self, channels, sample_rate = 500, sample_range = 188):
45
+ self._acq_param["original_channels"] = channels
46
+
47
+ # 根据映射关系做通道转换
48
+ for k in channels.keys():
49
+ if isinstance(channels[k], list):
50
+ temp = [k + str(i) for i in channels[k]]
51
+ channels[k] = [self.channel_mapping.get(c, 1) for c in temp]
52
+ else:
53
+ channels[k] = [k + str(channels[k])]
54
+
55
+
56
+ # 更新采集参数
57
+ self._acq_param["channels"] = channels
58
+ self._acq_param["sample_rate"] = sample_rate
59
+ self._acq_param["sample_range"] = sample_range
60
+ self._acq_channels = channels
61
+ self._sample_rate = sample_rate
62
+ self._sample_range = sample_range
63
+
64
+ def gen_set_acquirement_param(self) -> bytes:
65
+
66
+ arr = []
67
+ for k in self.acq_channels.keys():
68
+ arr = list(arr + self.acq_channels[k])
69
+
70
+ arr = list(set(arr))
71
+ body = to_bytes(arr)
72
+ body += self.sample_range.to_bytes(4, byteorder='little')
73
+ body += self.sample_rate.to_bytes(4, byteorder='little')
74
+ body += self.sample_num.to_bytes(4, byteorder='little')
75
+ body += self.resolution.to_bytes(1, byteorder='little')
76
+ body += bytes.fromhex('00')
77
+
78
+ return body
79
+
80
+ def __str__(self):
81
+ return f'''
82
+ Device:
83
+ Name: {self.device_no},
84
+ Type: {hex(self.device_type) if self.device_type else None},
85
+ ID: {self.device_id if self.device_id else None},
86
+ Software: {self.software_version},
87
+ Hardware: {self.hardware_version},
88
+ Connect Time: {self.connect_time},
89
+ Current Time: {self.current_time},
90
+ Voltage: {str(self.voltage) + "mV" if self.voltage else None},
91
+ Battery Remain: {str(self.battery_remain)+ "%" if self.battery_remain else None},
92
+ Battery Total: {str(self.battery_total) + "%" if self.battery_total else None}
93
+ '''
94
+
95
+
@@ -93,21 +93,6 @@ class QLBaseDevice(IDevice):
93
93
  }
94
94
 
95
95
  self.stim_paradigm: StimulationParadigm = None
96
-
97
- signal_info = {
98
- "param" : None,
99
- "start_time" : None,
100
- "finished_time" : None,
101
- "packet_total" : None,
102
- "last_packet_time" : None,
103
- "state" : 0
104
- }
105
- stim_info = {
106
-
107
- }
108
- Impedance_info = {
109
-
110
- }
111
96
  # 信号采集状态
112
97
  # 信号数据包总数(一个信号采集周期内)
113
98
  # 信号采集参数
@@ -128,6 +113,8 @@ class QLBaseDevice(IDevice):
128
113
  self.storage_enable = True
129
114
  self._listening = False
130
115
  # self.ready()
116
+ self._signal_cache: Queue = None
117
+ self._recording = False
131
118
 
132
119
  def parser(self) -> IParser:
133
120
  return self._parser
@@ -166,9 +153,16 @@ class QLBaseDevice(IDevice):
166
153
  for pos in trigger_positions:
167
154
  self.trigger(data.trigger[pos])
168
155
  # 存储
169
- if self.storage_enable:
170
- self._write_signal(data)
171
-
156
+ if self.storage_enable:
157
+ # 确保记录线程启动
158
+ if self._recording is False:
159
+ self._start_recording()
160
+
161
+ # 写入文件的缓存队列
162
+ if self._signal_cache is None:
163
+ self._signal_cache = Queue(256 * 1024 * 1024) # 256MB缓存
164
+ self._signal_cache.put(data)
165
+
172
166
  if len(self.signal_consumers) > 0 :
173
167
  logger.trace(f"dg eeg: {data.eeg}")
174
168
  # 信号数字值转物理值
@@ -187,14 +181,35 @@ class QLBaseDevice(IDevice):
187
181
  def _signal_wrapper(self, body: bytes):
188
182
  return RscPacket().transfer(body)
189
183
 
190
- def _write_signal(self, data: RscPacket):
184
+ def _write_signal(self):
191
185
  # 文件写入到edf
192
186
  if self._edf_handler is None:
193
187
  logger.debug("Initializing EDF handler for data storage")
194
188
  self.init_edf_handler()
195
189
 
196
- if self._edf_handler:
190
+ while self._recording:
191
+ data = self._signal_cache.get()
197
192
  self._edf_handler.write(data)
193
+ if data is None:
194
+ break
195
+
196
+ self._recording = False
197
+ def _start_recording(self):
198
+ if self.storage_enable is False:
199
+ logger.trace("Storage is disabled, will not start recording")
200
+ return
201
+
202
+ if self._signal_cache is None:
203
+ self._signal_cache = Queue(256 * 1024 * 1024) # 256MB缓存
204
+
205
+ try:
206
+ self._recording = True
207
+ t = Thread(target=self._write_signal, daemon=True)
208
+ t.start()
209
+ logger.info(f"开启记录")
210
+ except Exception as e:
211
+ logger.error(f"开启记录失败: {str(e)}")
212
+ return
198
213
 
199
214
  def start_listening(self):
200
215
 
@@ -305,7 +320,7 @@ class QLBaseDevice(IDevice):
305
320
  @property
306
321
  def edf_handler(self):
307
322
  if not self.storage_enable:
308
- logger.warning("EDF storage is disabled, no edf handler available")
323
+ logger.info("已关闭文件记录,不会生成edf/bdf文件")
309
324
  return None
310
325
 
311
326
  if self._edf_handler is None:
@@ -339,8 +354,12 @@ class QLBaseDevice(IDevice):
339
354
  return self._impedance_consumer
340
355
 
341
356
  # 设置记录文件路径
342
- def set_storage_path(self, path):
343
- self._storage_path = path
357
+ def set_storage_path(self, dir: str):
358
+ import os
359
+
360
+ abs_path = os.path.abspath(dir)
361
+ os.makedirs(abs_path, exist_ok=True)
362
+ self._storage_path = abs_path
344
363
 
345
364
  # 设置记录文件名称前缀
346
365
  def set_file_prefix(self, prefix):
@@ -362,10 +381,6 @@ class QLBaseDevice(IDevice):
362
381
  self._acq_channels = channels
363
382
  self._sample_rate = sample_rate
364
383
  self._sample_range = sample_range
365
-
366
- # 通用配置-TODO
367
- def set_config(self, key:str, val: str):
368
- pass
369
384
 
370
385
  def start_impedance(self):
371
386
  logger.info(f"[设备-{self.device_no}]启动阻抗测量")
@@ -399,8 +414,8 @@ class QLBaseDevice(IDevice):
399
414
  sleep(1)
400
415
  delay -= 1
401
416
  logger.debug(f"_stop_stimulation_trigger duration: {duration}")
402
- if self._edf_handler:
403
- self._edf_handler.trigger("stimulation should be stopped")
417
+ if self.edf_handler:
418
+ self.edf_handler.trigger("stimulation should be stopped")
404
419
  else:
405
420
  logger.warning("stop stim trigger fail. no edf writer alive")
406
421
 
@@ -411,11 +426,10 @@ class QLBaseDevice(IDevice):
411
426
  self.socket.sendall(msg)
412
427
 
413
428
  # 启动采集
414
- def start_acquisition(self, recording = True):
429
+ def start_acquisition(self):
415
430
  logger.info(f"[设备-{self.device_no}]启动信号采集")
416
- self._recording = recording
417
- # 初始化EDF处理器
418
- self.init_edf_handler()
431
+ # 记录准备
432
+ self._start_recording()
419
433
  # 设置数据采集参数
420
434
  param_bytes = SetAcquisitionParamCommand.build(self).pack()
421
435
  # 启动数据采集
@@ -430,9 +444,10 @@ class QLBaseDevice(IDevice):
430
444
  msg = StopAcquisitionCommand.build(self).pack()
431
445
  logger.trace(f"stop_acquisition message is {msg.hex()}")
432
446
  self.socket.sendall(msg)
433
- if self._edf_handler:
447
+ # 结束标识
448
+ if self._signal_cache:
434
449
  # 发送结束标识
435
- self.edf_handler.write(None)
450
+ self._signal_cache.put(None)
436
451
 
437
452
  '''
438
453
  订阅数据
@@ -450,7 +465,7 @@ class QLBaseDevice(IDevice):
450
465
 
451
466
  # 数据队列
452
467
  if q is None:
453
- q = Queue(maxsize=1024 * 1024)
468
+ q = Queue(maxsize=100 * 1024 * 1024)
454
469
 
455
470
  # 订阅生理电信号数据
456
471
  if type == "signal":
@@ -470,10 +485,10 @@ class QLBaseDevice(IDevice):
470
485
  return topic, q
471
486
 
472
487
  def trigger(self, desc):
473
- if self._edf_handler:
488
+ if self.edf_handler:
474
489
  self.edf_handler.trigger(desc)
475
490
  else:
476
- logger.warning("没有开启文件记录时,无法记录trigger信息")
491
+ logger.info("已关闭文件记录,不会记录trigger信息")
477
492
 
478
493
  def gen_set_acquirement_param(self) -> bytes:
479
494
 
@@ -499,6 +514,9 @@ class QLBaseDevice(IDevice):
499
514
 
500
515
  # 关闭解析器
501
516
  self._parser.stop()
517
+
518
+ def enable_storage(self, enable: bool = True):
519
+ self.storage_enable = enable
502
520
 
503
521
  def __str__(self):
504
522
  return f'''
@@ -115,11 +115,7 @@ class C16RS(QLBaseDevice):
115
115
  self._edf_handler.set_device_no(self.device_no)
116
116
  self._edf_handler.set_storage_path(self._storage_path)
117
117
  self._edf_handler.set_file_prefix(self._file_prefix if self._file_prefix else 'C16R')
118
-
119
- # 设置刺激参数
120
- def set_stim_param(self, param):
121
- self.stim_paradigm = param
122
-
118
+
123
119
  # 设置采集参数
124
120
  def set_acq_param(self, channels, sample_rate = 500, sample_range = 188):
125
121
  # 保存原始通道参数
@@ -13,6 +13,13 @@ class C256RS(QLBaseDevice):
13
13
  def __init__(self, socket):
14
14
  super().__init__(socket)
15
15
 
16
+ @classmethod
17
+ def from_parent(cls, parent:IDevice) -> IDevice:
18
+ rlt = cls(parent.socket)
19
+ rlt.device_id = parent.device_id
20
+ rlt._device_no = parent.device_no
21
+ return rlt
22
+
16
23
  def init_edf_handler(self):
17
24
  self._edf_handler = RscEDFHandler(self.sample_rate, self.sample_range * 1000 , - self.sample_range * 1000, self.resolution)
18
25
  self._edf_handler.set_device_type(self.device_type)
@@ -20,7 +27,12 @@ class C256RS(QLBaseDevice):
20
27
  self._edf_handler.set_storage_path(self._storage_path)
21
28
  self._edf_handler.set_file_prefix(self._file_prefix if self._file_prefix else 'C256RS')
22
29
  logger.debug(f"EDF Handler initialized")
23
-
30
+
31
+ @property
32
+ def acq_channels(self):
33
+ if self._acq_channels is None:
34
+ self._acq_channels = [i for i in range(1, 256)]
35
+ return self._acq_channels
24
36
 
25
37
  def _signal_wrapper(self, body: bytes):
26
38
  return C256RSPacket().transfer(body)
@@ -0,0 +1,29 @@
1
+ from loguru import logger
2
+ from qlsdk.persist import RscEDFHandler
3
+ from qlsdk.rsc.interface import IDevice
4
+ from qlsdk.rsc.command import *
5
+ from qlsdk.rsc.device.base import QLBaseDevice
6
+
7
+ class C64S1(QLBaseDevice):
8
+
9
+ device_type = 0x40 # C64RS-S1设备类型标识符
10
+
11
+ def __init__(self, socket):
12
+ super().__init__(socket)
13
+
14
+ @classmethod
15
+ def from_parent(cls, parent:IDevice) -> IDevice:
16
+ rlt = cls(parent.socket)
17
+ rlt.device_id = parent.device_id
18
+ rlt._device_no = parent.device_no
19
+ return rlt
20
+
21
+
22
+ def init_edf_handler(self):
23
+ self._edf_handler = RscEDFHandler(self.sample_rate, self.sample_range * 1000 , - self.sample_range * 1000, self.resolution)
24
+ self._edf_handler.set_device_type(self.device_type)
25
+ self._edf_handler.set_device_no(self.device_no)
26
+ self._edf_handler.set_storage_path(self._storage_path)
27
+ self._edf_handler.set_file_prefix(self._file_prefix if self._file_prefix else 'C64S1')
28
+ logger.debug(f"EDF Handler initialized")
29
+
@@ -61,4 +61,12 @@ class IDevice(ABC):
61
61
  raise NotImplementedError("Not Supported")
62
62
  def disconnect(self) -> None:
63
63
  raise NotImplementedError("Not Supported")
64
-
64
+
65
+ def set_stim_param(self, param):
66
+ pass
67
+
68
+ def trigger(self, desc):
69
+ pass
70
+
71
+ def enable_storage(self, enable: bool = True):
72
+ pass
@@ -64,7 +64,7 @@ class TcpMessageParser(IParser):
64
64
  start_pos = self.buffer.tell()
65
65
  head = self.buffer.read(2)
66
66
  if head != self.header:
67
- logger.debug(f"数据包头部不匹配: {head.hex()}, 期望: {self.header.hex()},继续查找...")
67
+ logger.trace(f"数据包头部不匹配: {head.hex()}, 期望: {self.header.hex()},继续查找...")
68
68
  self.buffer.seek(start_pos + 1) # 移动到下一个字节
69
69
  continue
70
70
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qlsdk2
3
- Version: 0.6.0a6
3
+ Version: 0.6.0a7
4
4
  Summary: SDK for quanlan device
5
5
  Home-page: https://github.com/hehuajun/qlsdk
6
6
  Author: hehuajun