Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CCS
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marko Mecina
CCS
Commits
22c23ff8
Commit
22c23ff8
authored
1 year ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
improve communication output formatting
parent
f5f6fb8b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ccs/communication.py
+21
-5
21 additions, 5 deletions
Ccs/communication.py
with
21 additions
and
5 deletions
Ccs/communication.py
+
21
−
5
View file @
22c23ff8
...
@@ -32,6 +32,7 @@ class Connector:
...
@@ -32,6 +32,7 @@ class Connector:
self
.
conn
=
None
self
.
conn
=
None
self
.
log
=
[]
self
.
log
=
[]
self
.
_storagefd
=
None
self
.
_storagefd
=
None
self
.
_storage_hexsep
=
''
self
.
receiver
=
None
self
.
receiver
=
None
...
@@ -43,8 +44,9 @@ class Connector:
...
@@ -43,8 +44,9 @@ class Connector:
if
save_to
is
not
None
:
if
save_to
is
not
None
:
self
.
setup_storage
(
save_to
)
self
.
setup_storage
(
save_to
)
def
setup_storage
(
self
,
fname
):
def
setup_storage
(
self
,
fname
,
hexsep
=
''
):
self
.
_storagefd
=
open
(
fname
,
'
w
'
)
self
.
_storagefd
=
open
(
fname
,
'
w
'
)
self
.
_storage_hexsep
=
hexsep
def
setup_port
(
self
):
def
setup_port
(
self
):
...
@@ -121,12 +123,15 @@ class Connector:
...
@@ -121,12 +123,15 @@ class Connector:
self
.
log
.
append
((
t
,
msg
,
resp
))
self
.
log
.
append
((
t
,
msg
,
resp
))
if
self
.
_storagefd
is
not
None
:
if
self
.
_storagefd
is
not
None
:
self
.
_storagefd
.
write
(
'
{:.3f}
\t
{}
\t
{}
\n
'
.
format
(
t
,
_msgdecoder
(
msg
,
self
.
msgdecoding
),
_msgdecoder
(
resp
,
self
.
msgdecoding
)))
self
.
_storagefd
.
write
(
'
{:.3f}
\t
{}
\t
{}
\n
'
.
format
(
t
,
_msgdecoder
(
msg
,
self
.
msgdecoding
,
sep
=
self
.
_storage_hexsep
),
_msgdecoder
(
resp
,
self
.
msgdecoding
,
sep
=
self
.
_storage_hexsep
)))
self
.
_storagefd
.
flush
()
self
.
_storagefd
.
flush
()
if
output
:
if
output
:
print
(
'
{:.3f}: SENT {} | RECV: {}
'
.
format
(
t
,
_msgdecoder
(
msg
,
self
.
msgdecoding
),
_msgdecoder
(
resp
,
self
.
msgdecoding
)))
print
(
'
{:.3f}: SENT {} | RECV: {}
'
.
format
(
t
,
_msgdecoder
(
msg
,
self
.
msgdecoding
),
_msgdecoder
(
resp
,
self
.
msgdecoding
)))
if
not
rx
:
return
None
return
resp
if
self
.
resp_decoder
is
None
else
self
.
resp_decoder
(
resp
)
return
resp
if
self
.
resp_decoder
is
None
else
self
.
resp_decoder
(
resp
)
else
:
else
:
...
@@ -255,7 +260,8 @@ class Receiver:
...
@@ -255,7 +260,8 @@ class Receiver:
except
socket
.
timeout
:
except
socket
.
timeout
:
continue
continue
except
(
ValueError
,
OSError
):
except
(
ValueError
,
OSError
)
as
err
:
print
(
err
)
self
.
stop
()
self
.
stop
()
break
break
...
@@ -277,7 +283,10 @@ class Receiver:
...
@@ -277,7 +283,10 @@ class Receiver:
if
self
.
proc_data_fd
is
not
None
:
if
self
.
proc_data_fd
is
not
None
:
try
:
try
:
self
.
proc_data_fd
.
write
(
str
(
procdata
))
if
self
.
proc_data_fd
.
mode
.
count
(
'
b
'
):
self
.
proc_data_fd
.
write
(
procdata
)
else
:
self
.
proc_data_fd
.
write
(
str
(
procdata
))
except
Exception
as
err
:
except
Exception
as
err
:
self
.
proc_data_fd
.
write
(
'
# {} #
\n
'
.
format
(
err
))
self
.
proc_data_fd
.
write
(
'
# {} #
\n
'
.
format
(
err
))
continue
continue
...
@@ -304,9 +313,16 @@ def _msgdecoder(msg, fmt, sep=''):
...
@@ -304,9 +313,16 @@ def _msgdecoder(msg, fmt, sep=''):
def
hexify
(
bs
,
sep
=
''
):
def
hexify
(
bs
,
sep
=
''
):
if
bs
is
None
:
if
bs
is
None
:
bs
=
b
''
bs
=
b
''
return
bs
.
hex
().
upper
()
if
sep
==
''
else
bs
.
hex
(
sep
).
upper
()
if
isinstance
(
sep
,
tuple
):
sep
,
grp
=
sep
else
:
grp
=
0
return
bs
.
hex
().
upper
()
if
sep
==
''
else
bs
.
hex
(
sep
,
grp
).
upper
()
def
toascii
(
bs
,
errors
=
'
replace
'
):
def
toascii
(
bs
,
errors
=
'
replace
'
):
...
...
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