31 from struct
import pack,unpack
35 ON = TRUE = ENABLED = HIGH = 1
36 OFF = FALSE = DISABLED = LOW = 0
40 return self.TRUE
if b
else self.FALSE
43 START_TRAJECTORY_DOWNLOAD = -1
44 START_TRAJECTORY_STREAMING = -2
54 EXECUTE_PROGRAM = 9004
59 SET_TOOL_OFFSET = 9009
104 body = self.make_body()
105 prefix = pack(
"i", SimpleMessage.HEADER_SIZE + len(body))
106 header = pack(
"3i", self.msg_type, self.comm_type, self.reply_code)
107 return prefix + header + self.make_body()
121 print(
"recv: {}".format(remain))
122 buf = socket.recv(MAX_SIZE
if remain > MAX_SIZE
else remain)
139 print(
"send: {}".format(remain))
140 i = buf_size - remain
141 send_size = socket.send(buf[i:])
176 self.
sequence, = unpack(
'i', body[0:4])
177 self.
joint_data = list(unpack(
'10f', body[4:44]))
193 self.
sequence, = unpack(
'i', body[0:4])
194 self.
joint_data = list(unpack(
'10f', body[4:44]))
236 self.
data = list(unpack(
'32i', body[12:140]))
251 return pack(
'i', self.
result)
254 self.
result = unpack(
'i', body[0:4])
278 return pack(
"3f", *self.
force) + pack(
"3f", *self.
torque)
291 return self.
name + pack(
'i', len(self.
name))
294 param_size, = unpack(
'i', body[-4:])
295 self.
param = body[-(param_size + 4):-4]
296 name_size, = unpack(
'i', body[-(param_size + 4 * 2):-(param_size + 4)])
297 self.
name = body[0:name_size]
312 return pack(
'i', self.
result)
315 self.
result, = unpack(
'i', body[0:4])
329 self.
posture, = unpack(
'i', body[0:4])
343 self.
posture, = unpack(
'i', body[0:4])
357 self.
posture, = unpack(
'i', body[0:4])
371 self.
posture, = unpack(
'i', body[0:4])
439 return pack(
'6f', self.
x, self.
y, self.
z, self.
rz, self.
ry, self.
rx)
442 self.
x, self.
y, self.
z, self.
rz, self.
ry, self.
rx = unpack(
'6f', body)
457 return pack(
'i', self.
result)
460 self.
result = unpack(
'i', body[0:4])
464 MAX_BUFFER_SIZE = 4096
475 print(
":".join(
"{:02x}".format(ord(c))
for c
in data))
476 prefix, msg_type = unpack(
"2i", data[0:8])
479 SimpleMessageType.JOINT_TRAJ_PT: JointTrajPtMessage,
480 SimpleMessageType.STATUS: StatusMessage,
481 SimpleMessageType.SET_IO: SetIOMessage,
482 SimpleMessageType.EXECUTE_PROGRAM: ExecuteProgramMessage,
483 SimpleMessageType.SET_POSTURE: SetPostureMessage,
484 SimpleMessageType.GET_POSTURE: GetPostureMessage,
485 SimpleMessageType.SYS_STAT: SysStatMessage,
486 SimpleMessageType.SET_TOOL_OFFSET: SetToolOffsetMessage,
487 }.get(msg_type, SimpleMessage)
496 data_size, = unpack(
"I", prefix)
506 print(
"recv: {}".format(remain))
521 data_size = len(data)
525 print(
"send: {}".format(remain))
526 i = data_size - remain
527 send_size = self._sock.send(data[i:])
def load_body(self, body)
def _recv_bytes(self, num)
def _recv_message_bytes(self)
def _send_bytes(self, data)
def load_body(self, body)
def load_body(self, body)
def load_body(self, body)
def load_body(self, body)
def sendBytes(socket, buf)
def load_body(self, body)
def load_body(self, body)
def load_body(self, body)
def load_body(self, body)
def load_body(self, body)
def load_body(self, body)
def recvBytes(socket, num)
def load_body(self, body)
def load_body(self, body)