-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.py
161 lines (155 loc) · 4.81 KB
/
utils.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
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
from whad.ble.profile.attribute import UUID
from whad.ble.profile import PrimaryService, Characteristic, GenericProfile
from scenario import Scenario
from scenario.scenario0 import Scenario0
from scenario.scenario1 import Scenario1Client, Scenario1Server
from scenario.scenario2 import Scenario2Client, Scenario2Server
from scenario.scenario3 import Scenario3Client, Scenario3Server
from scenario.scenario4 import Scenario4Server
from scenario.scenario5 import Scenario5Server
from scenario.scenario6 import Scenario6Client, Scenario6Server
from scenario.scenario7 import Scenario7Client, Scenario7Server
from scenario.scenario9 import Scenario9Server
def scenario_choice(scenario_number: int, client: bool) -> Scenario:
"""Select the corresponding scenario.
"""
match scenario_number:
case 0:
return Scenario0()
case 1:
if client:
return Scenario1Client()
else:
return Scenario1Server()
case 2:
if client:
return Scenario2Client()
else:
return Scenario2Server()
case 3:
if client:
return Scenario3Client()
else:
return Scenario3Server()
case 4:
return Scenario4Server()
case 5:
return Scenario5Server()
case 6:
if client:
return Scenario6Client()
else:
return Scenario6Server()
case 7:
if client:
return Scenario7Client()
else:
return Scenario7Server()
case 9:
return Scenario9Server()
NAME = "BLE_TEST"
class MyPeripheral(GenericProfile):
"""Create a PrimaryService."""
device = PrimaryService(
uuid=UUID(0x1800),
device_name=Characteristic(
uuid=UUID(0x2A00),
permissions=['read', 'write'],
notify=True,
value=bytes(NAME, 'utf-8'),
),
msg1=Characteristic(
uuid=UUID(0x2A01),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld',
description = "This is a test"
),
msg2=Characteristic(
uuid=UUID(0x2A01),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld'
),
msg3=Characteristic(
uuid=UUID(0x2A03),
permissions=['read'],
notify=True,
value=b'HelloWorld'
),
msg4=Characteristic(
uuid=UUID(0x2A04),
permissions=['read'],
notify=True,
value=b'HelloWorld'
),
msg5=Characteristic(
uuid=UUID(0x2A05),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld'
),
msg6=Characteristic(
uuid=UUID(0x2A06),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld',
description = "This is a test"
),
msg7=Characteristic(
uuid=UUID(0x2A07),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld',
description = "This is a test"
),
msg8=Characteristic(
uuid=UUID(0x2A08),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld',
description = "This is a test"
),
msg9=Characteristic(
uuid=UUID(0x2A09),
permissions=['read',"write"],
notify=True,
value=b'HelloWorld',
description = "This is a test"
),
)
# create a custom service
custom = PrimaryService(
uuid=UUID('abcdabcd-0001-0001-0001-000100020000'),
guess=Characteristic(
uuid=UUID('abcdabcd-0001-0001-0001-00010002000A'),
permissions=['read', 'write'],
notify=False,
value=b'Guess the number!',
description="Hello TEST"
),
number=Characteristic(
uuid=UUID('abcdabcd-0001-0001-0001-00010002000B'),
permissions=['read'],
notify=True,
value=b'Default'
),
number1=Characteristic(
uuid=UUID('abcdabcd-0001-0001-0001-00010002000C'),
permissions=['read'],
notify=True,
value=b'Default'
),
number2=Characteristic(
uuid=UUID('abcdabcd-0001-0001-0001-00010002000D'),
permissions=['read'],
notify=True,
value=b'Default'
),
number3=Characteristic(
uuid=UUID('abcdabcd-0001-0001-0001-00010002000E'),
permissions=['read'],
notify=True,
value=b'Default'
),
)