-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathReceiveData.py
111 lines (96 loc) · 2.92 KB
/
ReceiveData.py
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
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 29 09:36:14 2019
@author: ALU
"""
import json
import websocket
import asyncio
URL = "ws://localhost:31278/ws"
FIND_DONGLE = json.dumps({
"type":{
"type": "request",
"target_type": "device",
"target_name": "dongle"
},
"name": None,
"contents": "find_dongle"
})
CONNECT_DEVICE = json.dumps({
"type":{
"type": "setting",
"target_type": "device",
"target_name": "dongle"
},
"name": None,
"contents": {
"on_off": True,
"target_id": "STEEG_DG329018",
"ch_config": 0
}
})
DEVICE_INFO = json.dumps({
"type":{
"type": "request",
"target_type": "device",
"target_name": "device"
},
"name": None,
"contents": "device_info"
})
RAWDATA_SETTING = json.dumps({
"type":{
"type": "request",
"target_type": "raw",
"target_name": "raw"
},
"name": None,
"contents":{
"enable" : True,
"chunk_size": 4
}
})
RAWDATA_REQUEST = json.dumps({
"type":{
"type": "request",
"target_type": "raw",
"target_name": "raw"
},
"name": None,
"contents":{
"requirement" : [
"enable", "sps_origin",
"ch_num", "chunk_size",
"ch_label"]
}
})
RAWDATA = json.dumps({
"type":{
"type": "data",
"target_type": "raw",
"target_name": "raw"
},
"name": None,
"contents":{
"requirement" : [
"eeg", "sync_tick"
]
}
})
ws = websocket.create_connection(URL) # construct the connection
ws.send(FIND_DONGLE)
result = ws.recv()
print (result)
ws.send(CONNECT_DEVICE)
result = ws.recv()
print (result)
ws.send(RAWDATA_SETTING)
result = ws.recv()
print (result)
ws.send(RAWDATA_REQUEST)
result = ws.recv()
print (result)
ws.send(RAWDATA)
result = ws.recv()
print (result)
ws.close()