8 from rosserial_msgs.msg
import TopicInfo
9 from std_msgs.msg
import String, Int8
10 from marty_msgs.msg
import ServoMsg, ServoMsgArray
11 ROS_ACK =
"\xff\xfe\x00\x00\xff\x00\x00\xff" 16 MD5_String =
"992ce8a1687cec8c8bd883ec73ca41d1" 17 MD5_Int8 =
"27ffa0c9c4b8fb8492252bcad9e5c57b" 18 MD5_Int32 =
"da5909fbe378aeaf85e547e830cc1bb7" 19 MD5_ServoMsg =
"1bdf7d827c361b33ed3b4360c70ce4c0" 20 MD5_ServoMsgArray =
"320c8def1674d51423fb942c56a6619b" 28 signal.signal(signal.SIGINT, signal_handler)
34 return ''.join( [
"%02X " % ord( j )
for j
in byteStr ] ).strip()
39 test = (
''.join( [
"%02X " % ord( j )
for j
in byteStr ] ).strip()).split()
40 for i
in xrange(len(test)):
41 test[i] = int(test[i], 16)
48 hexStr =
''.join( hexStr.split(
" ") )
49 for i
in range(0, len(hexStr), 2):
50 byte_array.append( chr( int (hexStr[i:i+2], 16 ) ) )
51 return ''.join( byte_array )
58 return " {:02X}".format(255 - (checksum % 256))
63 return " {:02X}".format(255 - (checksum % 256))
67 LEN_HIGH =
" {:02X}".format(len(data) / 256)
68 LEN_LOW =
" {:02X}".format(len(data) % 256)
69 return LEN_LOW, LEN_HIGH
73 TID_HIGH =
" {:02X}".format(topic_num / 256)
74 TID_LOW =
" {:02X}".format(topic_num % 256)
75 print "LOW/HIGH: ", TID_LOW, TID_HIGH
76 return TID_LOW, TID_HIGH
87 parity=serial.PARITY_NONE,
88 stopbits=serial.STOPBITS_ONE,
89 bytesize=serial.EIGHTBITS,
94 pub_topic_info = TopicInfo()
95 pub_topic_info.topic_id = 101
96 pub_topic_info.topic_name =
"/marty/chatter" 97 pub_topic_info.message_type =
"std_msgs/String" 98 pub_topic_info.md5sum = MD5_String
99 pub_topic_info.buffer_size = 256
102 pub_msg.data =
"Testing!" 105 sub_topic_info = TopicInfo()
106 sub_topic_info.topic_id = 103
107 sub_topic_info.topic_name =
"/marty/servo_array" 110 sub_topic_info.message_type =
"marty_msgs/ServoMsgArray" 111 sub_topic_info.md5sum = MD5_ServoMsgArray
114 sub_topic_info.buffer_size = 32
117 pub_buffer = StringIO.StringIO()
118 pub_topic_info.serialize(pub_buffer)
119 pub_topic_data = pub_buffer.getvalue()
122 pub_msg_buffer = StringIO.StringIO()
123 pub_msg.serialize(pub_msg_buffer)
124 msg_data = pub_msg_buffer.getvalue()
127 sub_buffer = StringIO.StringIO()
128 sub_topic_info.serialize(sub_buffer)
129 sub_topic_data = sub_buffer.getvalue()
153 if (sub_init ==
False):
156 tid_low, tid_high =
HexTopID(TopicInfo.ID_SUBSCRIBER)
158 t_checksum =
TCheckSum(TopicInfo.ID_SUBSCRIBER, sub_topic_data)
159 s_header =
ByteToHex(ROS_RESP) + len_low + len_high + l_checksum + tid_low + tid_high
160 print "SerialHeader: ", s_header
161 print "TopicInfo: ", sub_buffer.getvalue()
167 print "Waiting for Sub Msg!"
def TCheckSum(topic_id, data)
def signal_handler(signal, frame)