Skip to content

Commit 04a3a1a

Browse files
committed
[feat] use BytesData for data conversion
1 parent 0a167ad commit 04a3a1a

13 files changed

Lines changed: 680 additions & 352 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ example/wrapper/bak/
1010
example/wrapper/robot.conf
1111
bak-xarm/
1212
.vscode/
13-
.claude/
14-
xarm/core/utils/bytes_data.py
13+
.claude/

example/wrapper/common/3004-get_report_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../..'))
2020

2121
from xarm.core.comm import SocketPort
22-
from xarm.core.utils import convert
22+
from xarm.core.utils.bytes_data import BytesData
2323

2424

2525
#######################################################
@@ -49,9 +49,9 @@
4949
if data == -1:
5050
time.sleep(0.1)
5151
continue
52-
total = convert.bytes_to_u32(data[0:4])
53-
angles = convert.bytes_to_fp32s(data[7:35], 7)
54-
poses = convert.bytes_to_fp32s(data[35:59], 6)
52+
total = BytesData.to_u32(data[0:4])
53+
angles = BytesData.to_fp32_list(data[7:35], 7)
54+
poses = BytesData.to_fp32_list(data[35:59], 6)
5555
print('total={}, now={}'.format(total, datetime.datetime.now()))
5656
print('angles: {}'.format(angles))
5757
print('poses: {}'.format(poses))

example/wrapper/common/3005-task_feedback.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../../..'))
2020

2121
from xarm.wrapper import XArmAPI
22-
from xarm.core.utils import convert
22+
from xarm.core.utils.bytes_data import BytesData
2323

2424

2525
#######################################################
@@ -51,12 +51,12 @@
5151
# arm.set_cgpio_digital(0, 0)
5252

5353
def feedback_callback(data):
54-
cmd_id = convert.bytes_to_u16(data[0:2])
54+
cmd_id = BytesData.to_u16(data[0:2])
5555
feedback_type = data[8]
5656
feedback_funcode = data[9]
57-
feedback_taskid = convert.bytes_to_u16(data[10:12])
57+
feedback_taskid = BytesData.to_u16(data[10:12])
5858
feedback_code = data[12]
59-
feedback_us = convert.bytes_to_u64(data[13:21])
59+
feedback_us = BytesData.to_u64(data[13:21])
6060
if feedback_type == 1:
6161
# motion start
6262
print('[FB] motion task {} starts executing, funcode={}, cmd_id={}, us={}, {}'.format(feedback_taskid, feedback_funcode, cmd_id, feedback_us, datetime.datetime.now()))

xarm/core/comm/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import select
1313
import threading
1414
from ..utils.log import logger
15-
from ..utils import convert
15+
from ..utils.bytes_data import BytesData
1616

1717

1818
class RxParse(object):
@@ -182,7 +182,7 @@ def recv_report_proc(self):
182182
if size == 0:
183183
if data_num != 4:
184184
continue
185-
size = convert.bytes_to_u32(buffer[0:4])
185+
size = BytesData.to_u32(buffer[0:4])
186186
if size == 233:
187187
size_is_not_confirm = True
188188
size = 245
@@ -192,17 +192,17 @@ def recv_report_proc(self):
192192
continue
193193
if size_is_not_confirm:
194194
size_is_not_confirm = True
195-
if convert.bytes_to_u32(buffer[233:237]) == 233:
195+
if BytesData.to_u32(buffer[233:237]) == 233:
196196
size = 233
197197
buffer = buffer[233:]
198198
continue
199199

200-
if convert.bytes_to_u32(buffer[0:4]) != size and not (size_is_not_confirm and size == 245 and convert.bytes_to_u32(buffer[0:4]) == 233):
201-
logger.error('report data error, close, length={}, size={}'.format(convert.bytes_to_u32(buffer[0:4]), size))
200+
if BytesData.to_u32(buffer[0:4]) != size and not (size_is_not_confirm and size == 245 and BytesData.to_u32(buffer[0:4]) == 233):
201+
logger.error('report data error, close, length={}, size={}'.format(BytesData.to_u32(buffer[0:4]), size))
202202
break
203203

204204
# # buffer[494:502]
205-
# data_curr_us = convert.bytes_to_u64(buffer[-8:])
205+
# data_curr_us = BytesData.to_u64(buffer[-8:])
206206
# recv_curr_us = time.monotonic() * 1000000
207207
#
208208
# if data_prev_us != 0 and recv_prev_us != 0:
@@ -276,7 +276,7 @@ def recv_proc(self):
276276
while True:
277277
if len(buffer) < 6:
278278
break
279-
length = convert.bytes_to_u16(buffer[4:6]) + 6
279+
length = BytesData.to_u16(buffer[4:6]) + 6
280280
if len(buffer) < length:
281281
break
282282
rx_data = buffer[:length]

0 commit comments

Comments
 (0)