@@ -216,6 +216,29 @@ class ProtocolCode(object):
216216 MERCURY_DRAG_TECH_PAUSE = 0x72
217217 MERCURY_DRAG_TEACH_CLEAN = 0x73
218218
219+ GET_ROBOT_MODIFIED_VERSION = 1
220+ GET_ROBOT_FIRMWARE_VERSION = 2
221+ GET_ROBOT_AUXILIARY_FIRMWARE_VERSION = 3
222+ GET_ROBOT_ATOM_MODIFIED_VERSION = 4
223+ GET_ROBOT_TOOL_FIRMWARE_VERSION = 9
224+ GET_ROBOT_SERIAL_NUMBER = 5
225+ SET_ROBOT_ERROR_CHECK_STATE = 6
226+ GET_ROBOT_ERROR_CHECK_STATE = 7
227+ GET_ROBOT_ERROR_STATUS = 0x15
228+ GET_ATOM_PRESS_STATUS = 0x6b
229+ GET_ATOM_LED_COLOR = 0x6a
230+ SET_ATOM_PIN_STATUS = 0x61
231+ GET_ATOM_PIN_STATUS = 0x62
232+ SET_MASTER_PIN_STATUS = 0x61
233+ GET_MASTER_PIN_STATUS = 0x62
234+ SET_AUXILIARY_PIN_STATUS = 0x63
235+ GET_AUXILIARY_PIN_STATUS = 0x64
236+ SET_SERVO_MOTOR_CLOCKWISE = 0x73
237+ GET_SERVO_MOTOR_CLOCKWISE = 0Xea
238+ SET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0x74
239+ GET_SERVO_MOTOR_COUNTER_CLOCKWISE = 0xeb
240+ SET_SERVO_MOTOR_CONFIG = 0x52
241+ GET_SERVO_MOTOR_CONFIG = 0x53
219242 GET_BASE_COORDS = 0xF0
220243 BASE_TO_SINGLE_COORDS = 0xF1
221244 COLLISION = 0xF2
@@ -265,6 +288,47 @@ class ProtocolCode(object):
265288
266289
267290class DataProcessor (object ):
291+ def _mesg (self , genre , * args , ** kwargs ):
292+ """
293+ Args:
294+ genre: command type (Command)
295+ *args: other data.
296+ It is converted to octal by default.
297+ If the data needs to be encapsulated into hexadecimal,
298+ the array is used to include them. (Data cannot be nested)
299+ **kwargs: support `has_reply`
300+ has_reply: Whether there is a return value to accept.
301+ """
302+ command_data = self ._process_data_command (genre , self .__class__ .__name__ , args )
303+
304+ if genre == 178 :
305+ # 修改wifi端口
306+ command_data = self ._encode_int16 (command_data )
307+
308+ elif genre in [76 , 77 ]:
309+ command_data = [command_data [0 ]] + self ._encode_int16 (command_data [1 ]* 10 )
310+ elif genre == 115 and self .__class__ .__name__ not in ["MyArmC" , "MyArmM" ]:
311+ command_data = [command_data [1 ],command_data [3 ]]
312+ LEN = len (command_data ) + 2
313+
314+ command = [
315+ ProtocolCode .HEADER ,
316+ ProtocolCode .HEADER ,
317+ LEN ,
318+ genre ,
319+ ]
320+ if command_data :
321+ command .extend (command_data )
322+ if self .__class__ .__name__ in ["Mercury" , "MercurySocket" ]:
323+ command [2 ] += 1
324+ command .extend (self .crc_check (command ))
325+ else :
326+ command .append (ProtocolCode .FOOTER )
327+
328+ real_command = self ._flatten (command )
329+ has_reply = kwargs .get ("has_reply" , False )
330+ return real_command , has_reply
331+
268332 # Functional approach
269333 def _encode_int8 (self , data ):
270334 return struct .pack ("b" , data )
@@ -572,7 +636,7 @@ def write(self, command, method=None):
572636 self ._serial_port .flush ()
573637
574638
575- def read (self , genre , method = None , command = None , _class = None ):
639+ def read (self , genre , method = None , command = None , _class = None , timeout = None ):
576640 datas = b""
577641 data_len = - 1
578642 k = 0
@@ -581,8 +645,8 @@ def read(self, genre, method=None, command=None, _class=None):
581645 wait_time = 0.1
582646 if method is not None :
583647 wait_time = 0.3
584- if genre == ProtocolCode . GO_ZERO :
585- wait_time = 120
648+ if timeout is not None :
649+ wait_time = timeout
586650 if _class in ["Mercury" , "MercurySocket" ]:
587651 if genre == ProtocolCode .POWER_ON :
588652 wait_time = 8
@@ -677,4 +741,4 @@ def read(self, genre, method=None, command=None, _class=None):
677741 command_log += hex (d )[2 :] + " "
678742 self .log .debug ("_read : {}" .format (command_log ))
679743
680- return datas
744+ return datas
0 commit comments