1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 'Use for direct communication with the NXT ***EXTREMELY ADVANCED USERS ONLY***'
16 import time
17
22
24 tgram = _create(opcode)
25 tgram.add_filename(fname)
26 return tgram
27
30
32 return _create(opcode)
33
35 tgram = _create(opcode)
36 tgram.add_u8(loop)
37 tgram.add_filename(fname)
38 return tgram
39
41 'Play a tone at frequency (Hz) for duration (ms)'
42 tgram = _create(opcode)
43 tgram.add_u16(frequency)
44 tgram.add_u16(duration)
45 return tgram
46
47 -def set_output_state(opcode, port, power, mode, regulation, turn_ratio,
48 run_state, tacho_limit):
58
65
67 tgram = _create(opcode)
68 tgram.add_u8(port)
69 return tgram
70
85
90
104
109
111 tgram = _create(opcode)
112 tgram.add_u8(inbox)
113 tgram.add_u8(len(message) + 1)
114 tgram.add_string(len(message), message)
115 tgram.add_u8(0)
116 return tgram
117
119 tgram = _create(opcode)
120 tgram.add_u8(port)
121 tgram.add_u8(relative)
122 return tgram
123
125 return _create(opcode)
126
131
133 return _create(opcode)
134
136 return _create(opcode)
137
142
144 'Get status of low-speed sensor (ultrasonic)'
145 tgram = _create(opcode)
146 tgram.add_u8(port)
147 return tgram
148
153
154 -def ls_write(opcode, port, tx_data, rx_bytes):
155 'Write a low-speed command to a sensor (ultrasonic)'
156 time.sleep(0.005)
157 tgram = _create(opcode)
158 tgram.add_u8(port)
159 tgram.add_u8(len(tx_data))
160 tgram.add_u8(rx_bytes)
161 tgram.add_string(len(tx_data), tx_data)
162 return tgram
163
165 'Read a low-speed sensor value (ultrasonic)'
166 tgram = _create(opcode)
167 tgram.add_u8(port)
168 return tgram
169
175
177 return _create(opcode)
178
183
184 -def message_read(opcode, remote_inbox, local_inbox, remove):
185 tgram = _create(opcode)
186 tgram.add_u8(remote_inbox)
187 tgram.add_u8(local_inbox)
188 tgram.add_u8(remove)
189 return tgram
190
197
198 OPCODES = {
199 0x00: (start_program, _parse_simple),
200 0x01: (stop_program, _parse_simple),
201 0x02: (play_sound_file, _parse_simple),
202 0x03: (play_tone, _parse_simple),
203 0x04: (set_output_state, _parse_simple),
204 0x05: (set_input_mode, _parse_simple),
205 0x06: (get_output_state, _parse_get_output_state),
206 0x07: (get_input_values, _parse_get_input_values),
207 0x08: (reset_input_scaled_value, _parse_simple),
208 0x09: (message_write, _parse_simple),
209 0x0A: (reset_motor_position, _parse_simple),
210 0x0B: (get_battery_level, _parse_get_battery_level),
211 0x0C: (stop_sound_playback, _parse_simple),
212 0x0D: (keep_alive, _parse_keep_alive),
213 0x0E: (ls_get_status, _parse_ls_get_status),
214 0x0F: (ls_write, _parse_simple),
215 0x10: (ls_read, _parse_ls_read),
216 0x11: (get_current_program_name, _parse_get_current_program_name),
217 0x13: (message_read, _parse_message_read),
218 }
219