Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
ur_simple_control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Guberina
ur_simple_control
Commits
5e8584b0
Commit
5e8584b0
authored
4 months ago
by
m-guberina
Browse files
Options
Downloads
Patches
Plain Diff
added buffer to parse chopped off messages
parent
c89223f3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/ur_simple_control/networking/client.py
+16
-12
16 additions, 12 deletions
python/ur_simple_control/networking/client.py
with
16 additions
and
12 deletions
python/ur_simple_control/networking/client.py
+
16
−
12
View file @
5e8584b0
...
@@ -4,6 +4,7 @@ from google.protobuf.internal.encoder import _VarintBytes
...
@@ -4,6 +4,7 @@ from google.protobuf.internal.encoder import _VarintBytes
from
google.protobuf.internal.decoder
import
_DecodeVarint32
from
google.protobuf.internal.decoder
import
_DecodeVarint32
from
ur_simple_control.networking.util
import
DictPb2EncoderDecoder
from
ur_simple_control.networking.util
import
DictPb2EncoderDecoder
import
pickle
import
pickle
import
time
def
client
(
args
,
init_command
,
shm_name
,
lock
):
def
client
(
args
,
init_command
,
shm_name
,
lock
):
...
@@ -24,7 +25,7 @@ def client(args, init_command, shm_name, lock):
...
@@ -24,7 +25,7 @@ def client(args, init_command, shm_name, lock):
ex. host_port = 7777
ex. host_port = 7777
"""
"""
def
parse_message
(
msg_raw
):
def
parse_message
(
buffer
):
"""
"""
parse_message
parse_message
-------------
-------------
...
@@ -36,21 +37,22 @@ def client(args, init_command, shm_name, lock):
...
@@ -36,21 +37,22 @@ def client(args, init_command, shm_name, lock):
a sensor or something similar, not files or whatever else needs to be whole
a sensor or something similar, not files or whatever else needs to be whole
"""
"""
pos
,
next_pos
=
0
,
0
pos
,
next_pos
=
0
,
0
msg
_len
=
len
(
msg_raw
)
buffer
_len
=
len
(
buffer
)
msg_in_bytes
=
b
""
msg_in_bytes
=
b
""
len_size_offset
=
0
while
True
:
while
True
:
next_pos
,
pos
=
_DecodeVarint32
(
msg_raw
,
pos
)
next_pos
,
pos
=
_DecodeVarint32
(
buffer
,
pos
)
# TODO: either save the message chunk, or save how many initial bytes to ignore in the next message
# TODO: either save the message chunk, or save how many initial bytes to ignore in the next message
if
pos
+
next_pos
>
msg_len
:
if
pos
+
next_pos
>
buffer_len
:
print
(
"
NETWORKING CLIENT: BUFFER OVERFLOW, DROPPING MSG!
"
)
# print("NETWORKING CLIENT: BUFFER OVERFLOW, DROPPING MSG!")
break
return
msg_in_bytes
,
pos
-
len_size_offset
msg_in_bytes
=
_VarintBytes
(
pos
+
next_pos
)
+
msg_raw
[
pos
:
pos
+
next_pos
]
msg_in_bytes
=
_VarintBytes
(
pos
+
next_pos
)
+
buffer
[
pos
:
pos
+
next_pos
]
len_size_offset
=
len
(
_VarintBytes
(
pos
+
next_pos
))
pos
+=
next_pos
pos
+=
next_pos
if
pos
>=
msg_len
:
if
pos
>=
buffer_len
:
break
return
msg_in_bytes
,
pos
return
msg_in_bytes
# TODO: deltte
buffer
=
b
""
encoder_decoder
=
DictPb2EncoderDecoder
()
encoder_decoder
=
DictPb2EncoderDecoder
()
msg_code
=
encoder_decoder
.
dictToMsgCode
(
init_command
)
msg_code
=
encoder_decoder
.
dictToMsgCode
(
init_command
)
...
@@ -64,7 +66,9 @@ def client(args, init_command, shm_name, lock):
...
@@ -64,7 +66,9 @@ def client(args, init_command, shm_name, lock):
try
:
try
:
while
True
:
while
True
:
msg_raw
=
s
.
recv
(
1024
)
msg_raw
=
s
.
recv
(
1024
)
msg_in_bytes
=
parse_message
(
msg_raw
)
buffer
+=
msg_raw
msg_in_bytes
,
pos
=
parse_message
(
buffer
)
buffer
=
buffer
[
pos
:]
dict_msg
=
encoder_decoder
.
serializedPb2MsgToDict
(
msg_in_bytes
,
msg_code
)
dict_msg
=
encoder_decoder
.
serializedPb2MsgToDict
(
msg_in_bytes
,
msg_code
)
# print(
# print(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment