Skip to content

Commit 25f3ced

Browse files
Juliana MashonJuliana Mashon
Juliana Mashon
authored and
Juliana Mashon
committed
Bookmark--updated formatting for some functions
1 parent 45c3d4c commit 25f3ced

File tree

1 file changed

+98
-60
lines changed

1 file changed

+98
-60
lines changed

broker_functions.py

+98-60
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@
1111
}
1212
}
1313

14+
"""MESSAGE TEMPLATE
15+
16+
message = {
17+
"kind": "rpc_request",
18+
"args": {
19+
"label": "",
20+
"priority": # Code here... (600)
21+
},
22+
"body": [
23+
{
24+
# Instructions here...
25+
}
26+
]
27+
}
28+
29+
"""
30+
1431
class BrokerFunctions():
1532
def __init__(self):
1633
self.broker_connect = BrokerConnect()
@@ -20,15 +37,21 @@ def __init__(self):
2037

2138
def read_status(self):
2239
# Get device status tree
23-
status_message = {
24-
**RPC_REQUEST,
25-
"body": {
26-
"kind": "read_status",
27-
"args": {}
28-
}
40+
message = {
41+
"kind": "rpc_request",
42+
"args": {
43+
"label": "",
44+
"priority": 600
45+
},
46+
"body": [
47+
{
48+
"kind": "read_status",
49+
"args": {}
50+
}
51+
]
2952
}
3053

31-
self.broker_connect.publish(status_message)
54+
self.broker_connect.publish(message)
3255
self.broker_connect.listen(5, 'status')
3356

3457
status_tree = self.broker_connect.last_message
@@ -38,7 +61,6 @@ def read_status(self):
3861

3962
def read_sensor(self, id):
4063
# Get sensor data
41-
# Return sensor as json object: sensor[""]
4264
peripheral_str = self.api.get_info('peripherals', id)
4365
mode = peripheral_str['mode']
4466

@@ -60,52 +82,63 @@ def read_sensor(self, id):
6082
}]
6183
}
6284

85+
# Return sensor as json object: sensor[""]
86+
6387
def message(self, message, type=None):
6488
# Send new log message via broker
65-
# No inherent return value
66-
message_message = {
67-
**RPC_REQUEST,
68-
"body": {
69-
"kind": "send_message",
70-
"args": {
71-
"message": message,
72-
"message_type": type
89+
message = {
90+
"kind": "rpc_request",
91+
"args": {
92+
"label": "",
93+
"priority": 600
94+
},
95+
"body": [
96+
{
97+
"kind": "send_message",
98+
"args": {
99+
"message": message,
100+
"message_type": type
101+
}
73102
}
74-
}
103+
]
75104
}
76-
77-
self.broker_connect.publish(message_message)
105+
self.broker_connect.publish(message)
106+
# No inherent return value
78107

79108
def debug(self, message):
80109
# Send 'debug' type message
81110
# No inherent return value
82-
self.message(message, 'debug')
111+
self.message(message, "debug")
83112

84113
def toast(self, message):
85114
# Send 'toast' type message
86115
# No inherent return value
87-
self.message(message, 'toast')
116+
self.message(message, "toast")
88117

89118
def wait(self, duration):
90119
# Tell bot to wait for some time
91-
# No inherent return value
92-
wait_message = {
93-
**RPC_REQUEST,
94-
"body": {
95-
"kind": "wait",
96-
"args": {
97-
"milliseconds": duration
120+
message = {
121+
"kind": "rpc_request",
122+
"args": {
123+
"label": "",
124+
"priority": 600
125+
},
126+
"body": [
127+
{
128+
"kind": "wait",
129+
"args": {
130+
"milliseconds": duration
131+
}
98132
}
99-
}
133+
]
100134
}
135+
self.broker_connect.publish(message)
101136

102-
self.broker_connect.publish(wait_message)
137+
# No inherent return value
103138
return print("Waiting for "+str(duration)+" milliseconds...")
104139

105140
def e_stop(self):
106141
# Tell bot to emergency stop
107-
# No inherent return value
108-
109142
new_message = {
110143
"kind": "rpc_request",
111144
"args": {
@@ -119,16 +152,9 @@ def e_stop(self):
119152
}
120153
]
121154
}
122-
# e_stop_message = {
123-
# **RPC_REQUEST,
124-
# "body": {
125-
# "kind": "emergency_lock",
126-
# "args": {}
127-
# }
128-
# }
129-
130-
# self.broker_connect.publish(e_stop_message)
131155
self.broker_connect.publish(new_message)
156+
157+
# No inherent return value
132158
return print("Triggered device emergency stop.")
133159

134160
def unlock(self):
@@ -192,8 +218,6 @@ def shutdown(self):
192218
return print("Triggered device shutdown.")
193219

194220
def move(self, x, y, z):
195-
# Tell bot to move to new xyz coord
196-
# Return new xyz position as values
197221
def axis_overwrite(axis, value):
198222
return {
199223
"kind": "axis_overwrite",
@@ -208,35 +232,49 @@ def axis_overwrite(axis, value):
208232
}
209233
}
210234

235+
# Tell bot to move to new xyz coord
211236
move_message = {
212-
**RPC_REQUEST,
213-
"body": {
214-
"kind": "move",
215-
"args": {},
216-
"body": [
217-
axis_overwrite("x", x),
218-
axis_overwrite("y", y),
219-
axis_overwrite("z", z)
220-
]
221-
}
237+
"kind": "rpc_request",
238+
"args": {
239+
"label": "",
240+
"priority": 600
241+
},
242+
"body": [
243+
{
244+
"kind": "move",
245+
"args": {},
246+
"body": [
247+
axis_overwrite("x", x),
248+
axis_overwrite("y", y),
249+
axis_overwrite("z", z)
250+
]
251+
}
252+
]
222253
}
223254

224255
self.broker_connect.publish(move_message)
256+
# Return new xyz position as values
225257

226258
def set_home(self, axis='all'):
227259
# Set current xyz coord as 0,0,0
228-
# No inherent return value
229260
set_home_message = {
230-
**RPC_REQUEST,
231-
"body": {
232-
"kind": "zero",
233-
"args": {
234-
"axis": axis
261+
"kind": "rpc_request",
262+
"args": {
263+
"label": "",
264+
"priority": 600
265+
},
266+
"body": [
267+
{
268+
"kind": "zero",
269+
"args": {
270+
"axis": axis
271+
}
235272
}
236-
}
273+
]
237274
}
238275

239276
self.broker_connect.publish(set_home_message)
277+
# No inherent return value
240278

241279
def find_home(self, axis='all', speed=100):
242280
# Move to 0,0,0

0 commit comments

Comments
 (0)