qlsdk2 0.6.0a9__tar.gz → 0.6.0a11__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 (83) hide show
  1. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/PKG-INFO +1 -1
  2. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/setup.py +1 -1
  3. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/entity/__init__.py +2 -1
  4. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/persist/ars_edf.py +74 -74
  5. qlsdk2-0.6.0a11/src/qlsdk/rsc/device/arskindling.py +307 -0
  6. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/base.py +8 -4
  7. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/interface/device.py +7 -1
  8. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/paradigm.py +2 -1
  9. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/parser/base.py +2 -2
  10. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk2.egg-info/PKG-INFO +1 -1
  11. qlsdk2-0.6.0a9/src/qlsdk/rsc/device/arskindling.py +0 -80
  12. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/README.md +0 -0
  13. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/setup.cfg +0 -0
  14. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/__init__.py +0 -0
  15. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/ar4/__init__.py +0 -0
  16. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/ar4m/__init__.py +0 -0
  17. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/__init__.py +0 -0
  18. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/crc/__init__.py +0 -0
  19. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/crc/crctools.py +0 -0
  20. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/device.py +0 -0
  21. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/exception.py +0 -0
  22. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/filter/__init__.py +0 -0
  23. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/filter/norch.py +0 -0
  24. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/local.py +0 -0
  25. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/message/__init__.py +0 -0
  26. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/message/command.py +0 -0
  27. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/message/tcp.py +0 -0
  28. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/message/udp.py +0 -0
  29. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/network/__init__.py +0 -0
  30. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/network/monitor.py +0 -0
  31. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/core/utils.py +0 -0
  32. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/entity/__init__.py +0 -0
  33. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/entity/message.py +0 -0
  34. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/entity/signal.py +0 -0
  35. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/__init__.py +0 -0
  36. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/analyzer.py +0 -0
  37. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/collector.py +0 -0
  38. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/device.py +0 -0
  39. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/parser.py +0 -0
  40. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/stimulator.py +0 -0
  41. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/interface/store.py +0 -0
  42. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/persist/__init__.py +0 -0
  43. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/persist/edf.py +0 -0
  44. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/persist/rsc_edf.py +0 -0
  45. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/persist/stream.py +0 -0
  46. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/__init__.py +0 -0
  47. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/command/__init__.py +0 -0
  48. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/__init__.py +0 -0
  49. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/c16_rs.py +0 -0
  50. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/c256_rs.py +0 -0
  51. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/c64_rs.py +0 -0
  52. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/c64s1.py +0 -0
  53. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/device/device_factory.py +0 -0
  54. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/eegion.py +0 -0
  55. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/entity.py +0 -0
  56. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/interface/__init__.py +0 -0
  57. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/interface/command.py +0 -0
  58. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/interface/handler.py +0 -0
  59. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/interface/parser.py +0 -0
  60. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/manager/__init__.py +0 -0
  61. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/manager/container.py +0 -0
  62. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/manager/search.py +0 -0
  63. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/network/__init__.py +0 -0
  64. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/network/discover.py +0 -0
  65. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/parser/__init__.py +0 -0
  66. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/parser/base-new.py +0 -0
  67. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/parser/rsc.py +0 -0
  68. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/rsc/proxy.py +0 -0
  69. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/sdk/__init__.py +0 -0
  70. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/sdk/ar4sdk.py +0 -0
  71. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/sdk/hub.py +0 -0
  72. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/sdk/libs/libAr4SDK.dll +0 -0
  73. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/sdk/libs/libwinpthread-1.dll +0 -0
  74. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/x8/__init__.py +0 -0
  75. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk/x8m/__init__.py +0 -0
  76. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk2.egg-info/SOURCES.txt +0 -0
  77. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk2.egg-info/dependency_links.txt +0 -0
  78. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk2.egg-info/requires.txt +0 -0
  79. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/src/qlsdk2.egg-info/top_level.txt +0 -0
  80. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/test/test.222.py +0 -0
  81. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/test/test.py +0 -0
  82. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/test/test_ar4m.py +0 -0
  83. {qlsdk2-0.6.0a9 → qlsdk2-0.6.0a11}/test/test_bdf.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qlsdk2
3
- Version: 0.6.0a9
3
+ Version: 0.6.0a11
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.0a9",
9
+ version="0.6.0a11",
10
10
  author="hehuajun",
11
11
  author_email="hehuajun@eegion.com",
12
12
  description="SDK for quanlan device",
@@ -19,7 +19,8 @@ class RscPacket(Packet):
19
19
  self.filter = None
20
20
  self.data_len = None
21
21
  self.trigger = None
22
- self.eeg = None
22
+ self.eeg = None # 数字信号
23
+ self.eeg_p = None # 物理值
23
24
 
24
25
  @staticmethod
25
26
  def transfer(body: bytes) -> 'RscPacket':
@@ -85,67 +85,67 @@ class ARSKindlingEDFHandler(object):
85
85
  "D" : [7, 8, 5, 6, 3, 4, 1, 2, 9, 10, 11, 12, 13, 14],
86
86
  }
87
87
 
88
- self._channel_mapping = {
89
- 1: "D7",
90
- 2: "D8",
91
- 3: "D5",
92
- 4: "D6",
93
- 5: "D3",
94
- 6: "D4",
95
- 7: "D1",
96
- 8: "D2",
97
- 9: "D9",
98
- 10: "D10",
99
- 11: "D11",
100
- 12: "D12",
101
- 13: "D13",
102
- 14: "D14",
88
+ # self._channel_mapping = {
89
+ # 1: "D7",
90
+ # 2: "D8",
91
+ # 3: "D5",
92
+ # 4: "D6",
93
+ # 5: "D3",
94
+ # 6: "D4",
95
+ # 7: "D1",
96
+ # 8: "D2",
97
+ # 9: "D9",
98
+ # 10: "D10",
99
+ # 11: "D11",
100
+ # 12: "D12",
101
+ # 13: "D13",
102
+ # 14: "D14",
103
103
 
104
- 17: "C7",
105
- 18: "C8",
106
- 19: "C5",
107
- 20: "C6",
108
- 21: "C3",
109
- 22: "C4",
110
- 23: "C1",
111
- 24: "C2",
112
- 25: "C9",
113
- 26: "C10",
114
- 27: "C11",
115
- 28: "C12",
116
- 29: "C13",
117
- 30: "C14",
104
+ # 17: "C7",
105
+ # 18: "C8",
106
+ # 19: "C5",
107
+ # 20: "C6",
108
+ # 21: "C3",
109
+ # 22: "C4",
110
+ # 23: "C1",
111
+ # 24: "C2",
112
+ # 25: "C9",
113
+ # 26: "C10",
114
+ # 27: "C11",
115
+ # 28: "C12",
116
+ # 29: "C13",
117
+ # 30: "C14",
118
118
 
119
- 33: "B7",
120
- 34: "B8",
121
- 35: "B5",
122
- 36: "B6",
123
- 37: "B3",
124
- 38: "B4",
125
- 39: "B1",
126
- 40: "B2",
127
- 41: "B9",
128
- 42: "B10",
129
- 43: "B11",
130
- 44: "B12",
131
- 45: "B13",
132
- 46: "B14",
119
+ # 33: "B7",
120
+ # 34: "B8",
121
+ # 35: "B5",
122
+ # 36: "B6",
123
+ # 37: "B3",
124
+ # 38: "B4",
125
+ # 39: "B1",
126
+ # 40: "B2",
127
+ # 41: "B9",
128
+ # 42: "B10",
129
+ # 43: "B11",
130
+ # 44: "B12",
131
+ # 45: "B13",
132
+ # 46: "B14",
133
133
 
134
- 49: "A7",
135
- 50: "A8",
136
- 51: "A5",
137
- 52: "A6",
138
- 53: "A3",
139
- 54: "A4",
140
- 55: "A1",
141
- 56: "A2",
142
- 57: "A9",
143
- 58: "A10",
144
- 59: "A11",
145
- 60: "A12",
146
- 61: "A13",
147
- 62: "A14"
148
- }
134
+ # 49: "A7",
135
+ # 50: "A8",
136
+ # 51: "A5",
137
+ # 52: "A6",
138
+ # 53: "A3",
139
+ # 54: "A4",
140
+ # 55: "A1",
141
+ # 56: "A2",
142
+ # 57: "A9",
143
+ # 58: "A10",
144
+ # 59: "A11",
145
+ # 60: "A12",
146
+ # 61: "A13",
147
+ # 62: "A14"
148
+ # }
149
149
 
150
150
  self._lock = Lock()
151
151
 
@@ -172,6 +172,8 @@ class ARSKindlingEDFHandler(object):
172
172
  self._device_type = "C64RS"
173
173
  elif device_type == 0x40:
174
174
  self._device_type = "LJ64S1"
175
+ elif device_type == 0x60:
176
+ self._device_type = "ArsKindling"
175
177
  else:
176
178
  self._device_type = hex(device_type)
177
179
 
@@ -200,20 +202,22 @@ class ARSKindlingEDFHandler(object):
200
202
 
201
203
  #按分区写入数据
202
204
  for k in self._channel_spilt.keys():
203
- logger.trace(f'分区{k}, {self._channel_spilt[k]}')
204
- p = packet
205
- self.writeA(p, self._channel_spilt[k], k)
205
+ logger.trace(f'分区{k}写入数据到文件')
206
+ if k in packet.channels.keys():
207
+ p = packet
208
+ self.writeA(p, k)
206
209
 
207
- def writeA(self, packet: RscPacket, channel_filter, name='A'):
210
+ def writeA(self, packet: RscPacket, name='A'):
208
211
  # 参数检查
209
- if packet is None or channel_filter is None:
212
+ if packet is None:
210
213
  logger.warning("空数据,忽略")
211
214
  return
215
+
216
+ channels = packet.channels.get(name, None)
217
+ eeg = packet.eeg.get(name, None)
212
218
 
213
- channel_pos = intersection_positions(packet.channels, channel_filter)
214
-
215
- if channel_pos is None or len(channel_pos) == 0 :
216
- logger.trace(f"没有指定分区{name}的通道,跳过")
219
+ if eeg is None :
220
+ logger.trace(f"分区{name}没有可用的数据,跳过文件写入")
217
221
  return
218
222
 
219
223
  # 分区数据包写入
@@ -226,16 +230,12 @@ class ARSKindlingEDFHandler(object):
226
230
  logger.info(f"开始写入分区{name}的数据到文件")
227
231
  self._edf_handler[name] = edf_handler
228
232
 
229
- # 保留本分区的通道和数据
230
- channels = [packet.channels[p] for p in channel_pos]
231
- eeg = [packet.eeg[p] for p in channel_pos]
232
-
233
233
  # 新建数据包实例
234
234
  data = RscPacket()
235
235
  data.time_stamp = packet.time_stamp
236
236
  data.pkg_id = packet.pkg_id
237
237
  # data.channels = channels
238
- data.channels = self.channel_display(channels)
238
+ data.channels = self.channel_display(channels, name)
239
239
  data.origin_sample_rate = packet.origin_sample_rate
240
240
  data.sample_rate = packet.sample_rate
241
241
  data.sample_num = packet.sample_num
@@ -253,5 +253,5 @@ class ARSKindlingEDFHandler(object):
253
253
  for k in self._edf_handler.keys():
254
254
  self._edf_handler[k].trigger(desc, cur_time)
255
255
 
256
- def channel_display(self, channel):
257
- return [self._channel_mapping.get(channel_id, []) for channel_id in channel]
256
+ def channel_display(self, channel, name: str):
257
+ return [f'{name}-{channel_id}' for channel_id in channel]
@@ -0,0 +1,307 @@
1
+ from multiprocessing import Queue
2
+ from typing import Literal
3
+ from loguru import logger
4
+ from qlsdk.persist import ARSKindlingEDFHandler
5
+ from qlsdk.rsc.interface import IDevice
6
+ from qlsdk.rsc.command import *
7
+ from qlsdk.rsc.device.base import QLBaseDevice
8
+
9
+
10
+ def intersection_positions(A, B):
11
+ setB = set(B)
12
+ seen = set()
13
+ return [idx for idx, elem in enumerate(A)
14
+ if elem in setB and elem not in seen and not seen.add(elem)]
15
+
16
+ def get_sorted_indices_basic(A, B):
17
+ """
18
+ 找出数组A中存在于数组B的元素,并返回这些元素在A中的位置,且顺序与它们在B中的顺序一致。
19
+
20
+ 参数:
21
+ A (list): 待查找的数组。
22
+ B (list): 作为参考的数组。
23
+
24
+ 返回:
25
+ list: 一个列表,包含符合条件的元素在A中的索引,顺序与这些元素在B中的出现顺序一致。
26
+ """
27
+ # 1. 创建B中元素到其索引的映射
28
+ b_index_map = {value: idx for idx, value in enumerate(B)}
29
+
30
+ # 2. 筛选A中存在于B的元素,并记录其在A中的索引及在B中的位置
31
+ # 使用列表推导式,同时避免重复元素干扰(如果B有重复,以第一次出现为准)
32
+ found_elements = []
33
+ for idx_a, value in enumerate(A):
34
+ if value in b_index_map:
35
+ # 记录: (该元素在A中的索引, 该元素在B中的索引)
36
+ found_elements.append((idx_a, b_index_map[value]))
37
+
38
+ # 3. 根据元素在B中的位置进行排序
39
+ # 排序的依据是元组的第二个元素,即 b_index_map[value]
40
+ found_elements_sorted = sorted(found_elements, key=lambda x: x[1])
41
+
42
+ # 4. 提取排序后在A中的索引,形成结果数组C
43
+ array_C = [item[0] for item in found_elements_sorted]
44
+
45
+ return array_C
46
+
47
+ class ARSKindling(QLBaseDevice):
48
+
49
+ device_type = 0x60 # C64RS设备类型标识符
50
+
51
+ def __init__(self, socket):
52
+ super().__init__(socket)
53
+
54
+ self.channel_mapping = {
55
+ "A1": 55, "A2": 56, "A3": 53, "A4": 54, "A5": 51, "A6": 52, "A7": 49, "A8": 50,
56
+ "A9": 57, "A10": 58, "A11": 59, "A12": 60, "A13": 61, "A14": 62,
57
+
58
+ "B1": 39, "B2": 40, "B3": 37, "B4": 38, "B5": 35, "B6": 36, "B7": 33, "B8": 34,
59
+ "B9": 41, "B10": 42, "B11": 43, "B12": 44, "B13": 45, "B14": 46,
60
+
61
+ "C1": 23, "C2": 24, "C3": 21, "C4": 22, "C5": 19, "C6": 20, "C7": 17, "C8": 18,
62
+ "C9": 25, "C10": 26, "C11": 27, "C12": 28, "C13": 29, "C14": 30,
63
+
64
+ "D1": 7, "D2": 8, "D3": 5, "D4": 6, "D5": 3, "D6": 4, "D7": 1, "D8": 2,
65
+ "D9": 9, "D10": 10, "D11": 11, "D12": 12, "D13": 13, "D14": 14,
66
+ }
67
+
68
+ self._channel_spilt = {
69
+ "A" : [55, 56, 53, 54, 51, 52, 49, 50, 57, 58, 59, 60, 61, 62],
70
+ "B" : [39, 40, 37, 38, 35, 36, 33, 34, 41, 42, 43, 44, 45, 46],
71
+ "C" : [23, 24, 21, 22, 19, 20, 17, 18, 25, 26, 27, 28, 29, 30],
72
+ "D" : [7, 8, 5, 6, 3, 4, 1, 2, 9, 10, 11, 12, 13, 14],
73
+ }
74
+
75
+ self._channel_mapping = {
76
+ 1: "7",
77
+ 2: "8",
78
+ 3: "5",
79
+ 4: "6",
80
+ 5: "3",
81
+ 6: "4",
82
+ 7: "1",
83
+ 8: "2",
84
+ 9: "9",
85
+ 10: "10",
86
+ 11: "11",
87
+ 12: "12",
88
+ 13: "13",
89
+ 14: "14",
90
+
91
+ 17: "7",
92
+ 18: "8",
93
+ 19: "5",
94
+ 20: "6",
95
+ 21: "3",
96
+ 22: "4",
97
+ 23: "1",
98
+ 24: "2",
99
+ 25: "9",
100
+ 26: "10",
101
+ 27: "11",
102
+ 28: "12",
103
+ 29: "13",
104
+ 30: "14",
105
+
106
+ 33: "7",
107
+ 34: "8",
108
+ 35: "5",
109
+ 36: "6",
110
+ 37: "3",
111
+ 38: "4",
112
+ 39: "1",
113
+ 40: "2",
114
+ 41: "9",
115
+ 42: "10",
116
+ 43: "11",
117
+ 44: "12",
118
+ 45: "13",
119
+ 46: "14",
120
+
121
+ 49: "7",
122
+ 50: "8",
123
+ 51: "5",
124
+ 52: "6",
125
+ 53: "3",
126
+ 54: "4",
127
+ 55: "1",
128
+ 56: "2",
129
+ 57: "9",
130
+ 58: "10",
131
+ 59: "11",
132
+ 60: "12",
133
+ 61: "13",
134
+ 62: "14"
135
+ }
136
+
137
+ @classmethod
138
+ def from_parent(cls, parent:IDevice) -> IDevice:
139
+ rlt = cls(parent.socket)
140
+ rlt.device_id = parent.device_id
141
+ rlt._device_no = parent.device_no
142
+ return rlt
143
+
144
+ def init_edf_handler(self):
145
+ self._edf_handler = ARSKindlingEDFHandler(self.sample_rate, self.sample_range * 1000 , - self.sample_range * 1000, self.resolution)
146
+ self._edf_handler.set_device_type(self.device_type)
147
+ self._edf_handler.set_device_no(self.device_no)
148
+ self._edf_handler.set_storage_path(self._storage_path)
149
+ self._edf_handler.set_file_prefix(self._file_prefix if self._file_prefix else 'ARS')
150
+ logger.debug(f"EDF Handler initialized")
151
+
152
+ # 设置采集参数
153
+ def set_acq_param(self, channels, sample_rate = 500, sample_range = 188):
154
+ self._acq_param["original_channels"] = channels
155
+
156
+ # 根据映射关系做通道转换
157
+ for k in channels.keys():
158
+ if isinstance(channels[k], list):
159
+ temp = [k + str(i) for i in channels[k]]
160
+ channels[k] = [self.channel_mapping.get(c, 1) for c in temp]
161
+ else:
162
+ channels[k] = [k + str(channels[k])]
163
+
164
+
165
+ # 更新采集参数
166
+ self._acq_param["channels"] = channels
167
+ self._acq_param["sample_rate"] = sample_rate
168
+ self._acq_param["sample_range"] = sample_range
169
+ self._acq_channels = channels
170
+ self._sample_rate = sample_rate
171
+ self._sample_range = sample_range
172
+
173
+ @property
174
+ def acq_channels(self):
175
+ if self._acq_channels is None:
176
+ self._acq_channels = [i for i in range(1, 63)]
177
+
178
+ arr = []
179
+ for k in self._acq_channels.keys():
180
+ arr = list(arr + self._acq_channels[k])
181
+
182
+ return list(set(arr))
183
+
184
+ def _produce_impedance(self, body: bytes):
185
+ # 分发阻抗数据包给订阅者
186
+ if len(self._impedance_consumer) > 0:
187
+ packet = ImpedancePacket.transfer(body)
188
+ real_data = self.__impedance_transfer(packet)
189
+ for topic, q in self._impedance_consumer.items():
190
+ try:
191
+ # 队列满了就丢弃最早的数据
192
+ if q.full():
193
+ q.get()
194
+ q.put(real_data, timeout=1)
195
+ except Exception as e:
196
+ logger.error(f"impedance data put to queue exception: {str(e)}")
197
+
198
+ def _produce_signal(self, body: bytes):
199
+
200
+ # 处理信号数据
201
+ data = self._signal_wrapper(body)
202
+ # logger.debug("pkg_id: {}, eeg len: {}".format(data.pkg_id, len(data.eeg)))
203
+
204
+ trigger_positions = [index for index, value in enumerate(data.trigger) if value != 0]
205
+ if len(trigger_positions) > 0:
206
+ # logger.debug(f"Trigger触发点位置: {trigger_positions}, 触发点时间戳: {[data.time_stamp + int(pos * 1000 / data.sample_rate) for pos in trigger_positions]}")
207
+ for pos in trigger_positions:
208
+ self.trigger(self.trigger_info(data.trigger[pos]))
209
+
210
+ if len(self.signal_consumers) > 0 :
211
+ # 信号数字值转物理值
212
+ data.eeg_p = self.eeg2phy(np.array(data.eeg))
213
+
214
+ real_data = self.__signal_transfer(data)
215
+
216
+ # 存储
217
+ if self.storage_enable:
218
+ # 确保记录线程启动
219
+ if self._recording is False:
220
+ self._start_recording()
221
+
222
+ # 写入文件的缓存队列
223
+ if self._signal_cache is None:
224
+ self._signal_cache = Queue(1000000) # 缓冲队列
225
+ self._signal_cache.put(real_data)
226
+
227
+ if len(self.signal_consumers) > 0 :
228
+ # 订阅只返回物理值
229
+ real_data.eeg = real_data.eeg_p
230
+ # 发送数据包到订阅者
231
+ for q in list(self.signal_consumers.values()):
232
+ # 队列满了就丢弃最早的数据
233
+ if q.full():
234
+ q.get()
235
+
236
+ q.put(real_data)
237
+
238
+ # 信号数据转换
239
+ def __impedance_transfer(self, packet: ImpedancePacket):
240
+ channels = {}
241
+ impedance = {}
242
+ #按分区拆分数据格式
243
+ for k in self._channel_spilt.keys():
244
+ logger.trace(f'分区{k}的阻抗数据')
245
+ c, d, p = self.__packet_filter(packet, self._channel_spilt[k], type='impedance')
246
+ if c is not None:
247
+ channels[k] = c
248
+ impedance[k] = d
249
+ packet.channels = channels
250
+ packet.impedance = impedance
251
+
252
+ return packet
253
+
254
+ # 信号数据转换
255
+ def __signal_transfer(self, packet: RscPacket):
256
+ channels = {}
257
+ eeg = {}
258
+ eeg_p = {}
259
+ #按分区拆分数据格式
260
+ for k in self._channel_spilt.keys():
261
+ logger.trace(f'分区{k}, {self._channel_spilt[k]}')
262
+ c, d, p = self.__packet_filter(packet, self._channel_spilt[k])
263
+ if c is not None:
264
+ channels[k] = c
265
+ eeg[k] = d
266
+ if p is not None:
267
+ eeg_p[k] = p
268
+ packet.channels = channels
269
+ packet.eeg = eeg
270
+ #物理值
271
+ if packet.eeg_p is not None:
272
+ packet.eeg_p = eeg_p
273
+
274
+ return packet
275
+
276
+ def __packet_filter(self, packet, channel_filter=None, type:Literal['signal','impedance']='signal'):
277
+ # 参数检查
278
+ if packet is None or channel_filter is None:
279
+ logger.warning("空数据,忽略")
280
+ return None, None, None
281
+
282
+ channel_pos = get_sorted_indices_basic(packet.channels, channel_filter)
283
+
284
+ if channel_pos is None or len(channel_pos) == 0 :
285
+ logger.trace(f"没有指定分区的通道,跳过")
286
+ return None, None, None
287
+
288
+ # 分区数据包写入
289
+
290
+ # 保留本分区的通道和数据
291
+ channels = [packet.channels[p] for p in channel_pos]
292
+
293
+ #阻抗数据
294
+ if type == 'impedance':
295
+ impedance = [packet.impedance[p] for p in channel_pos]
296
+ return [self._channel_mapping.get(channel_id, []) for channel_id in channels], impedance, None
297
+
298
+ # 信号数据
299
+ eeg = [packet.eeg[p] for p in channel_pos]
300
+ eeg_p = None
301
+ if packet.eeg_p is not None:
302
+ eeg_p = [packet.eeg_p[p] for p in channel_pos]
303
+
304
+ return [self._channel_mapping.get(channel_id, []) for channel_id in channels], eeg, eeg_p
305
+
306
+
307
+
@@ -137,6 +137,9 @@ class QLBaseDevice(IDevice):
137
137
  if len(self._impedance_consumer) > 0:
138
138
  for topic, q in self._impedance_consumer.items():
139
139
  try:
140
+ # 队列满了就丢弃最早的数据
141
+ if q.full():
142
+ q.get()
140
143
  q.put(packet, timeout=1)
141
144
  except Exception as e:
142
145
  logger.error(f"impedance data put to queue exception: {str(e)}")
@@ -151,7 +154,7 @@ class QLBaseDevice(IDevice):
151
154
  if len(trigger_positions) > 0:
152
155
  # logger.debug(f"Trigger触发点位置: {trigger_positions}, 触发点时间戳: {[data.time_stamp + int(pos * 1000 / data.sample_rate) for pos in trigger_positions]}")
153
156
  for pos in trigger_positions:
154
- self.trigger(trigger_info(data.trigger[pos]))
157
+ self.trigger(self.trigger_info(data.trigger[pos]))
155
158
  # 存储
156
159
  if self.storage_enable:
157
160
  # 确保记录线程启动
@@ -517,6 +520,9 @@ class QLBaseDevice(IDevice):
517
520
 
518
521
  def enable_storage(self, enable: bool = True):
519
522
  self.storage_enable = enable
523
+
524
+ def trigger_info(self, code: int) -> str:
525
+ return __TRIGGER_MAPPING.get(code, hex(code))
520
526
 
521
527
  def __str__(self):
522
528
  return f'''
@@ -546,6 +552,4 @@ __TRIGGER_MAPPING = {
546
552
  0x3EB: "Descending start of stimulation ",
547
553
  0x3EC: "刺激参数有误",
548
554
  0x3ED: "End of stimulation (by force)",
549
- }
550
- def trigger_info(code: int) -> str:
551
- return __TRIGGER_MAPPING.get(code, "未知触发事件")
555
+ }
@@ -69,4 +69,10 @@ class IDevice(ABC):
69
69
  pass
70
70
 
71
71
  def enable_storage(self, enable: bool = True):
72
- pass
72
+ pass
73
+
74
+ def start_impedance(self):
75
+ raise NotImplementedError("Not Supported")
76
+
77
+ def stop_impedance(self):
78
+ raise NotImplementedError("Not Supported")
@@ -191,7 +191,8 @@ class ACStimulation(StimulationChannel):
191
191
  self.frequency = frequency
192
192
  # self.frequency = frequency
193
193
  self.phase_position = phase_position
194
-
194
+ if current < 0:
195
+ self.phase_position = (phase_position + 180) % 360
195
196
  def to_json(self):
196
197
  return {
197
198
  "channel_id": self.channel_id,
@@ -53,7 +53,7 @@ class TcpMessageParser(IParser):
53
53
  buf_len = get_len(self.buffer)
54
54
 
55
55
  if buf_len < self.header_len:
56
- logger.trace(f"等待数据中...: expect: {self.header_len}, actual: {buf_len}")
56
+ # logger.trace(f"等待数据中...: expect: {self.header_len}, actual: {buf_len}")
57
57
  if not self.__fill_from_cache():
58
58
  time.sleep(0.1)
59
59
  continue
@@ -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.trace(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.0a9
3
+ Version: 0.6.0a11
4
4
  Summary: SDK for quanlan device
5
5
  Home-page: https://github.com/hehuajun/qlsdk
6
6
  Author: hehuajun
@@ -1,80 +0,0 @@
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
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes