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
25ef40f0
Commit
25ef40f0
authored
1 year ago
by
Marko Mecina
Browse files
Options
Downloads
Patches
Plain Diff
communication module: minor changes in output formatting
parent
3e1c6338
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
+13
-10
13 additions, 10 deletions
Ccs/communication.py
with
13 additions
and
10 deletions
Ccs/communication.py
+
13
−
10
View file @
25ef40f0
...
@@ -22,7 +22,7 @@ class Connector:
...
@@ -22,7 +22,7 @@ class Connector:
def
__init__
(
self
,
host
,
port
,
is_server
=
False
,
response_to
=
2
,
recv_nbytes_min
=
0
,
save_to_file
=
None
,
msgdecoding
=
'
hex
'
,
resp_decoder
=
None
):
def
__init__
(
self
,
host
,
port
,
is_server
=
False
,
response_to
=
2
,
recv_nbytes_min
=
0
,
save_to_file
=
None
,
msgdecoding
=
'
hex
'
,
resp_decoder
=
None
):
self
.
sock_timeout
=
10
self
.
sock_timeout
=
10
self
.
response_to
=
response_to
self
.
_
response_to
=
response_to
self
.
host
=
host
self
.
host
=
host
self
.
port
=
port
self
.
port
=
port
self
.
isserver
=
is_server
self
.
isserver
=
is_server
...
@@ -34,6 +34,7 @@ class Connector:
...
@@ -34,6 +34,7 @@ class Connector:
self
.
log
=
[]
self
.
log
=
[]
self
.
_storagefd
=
None
self
.
_storagefd
=
None
self
.
_storage_hexsep
=
''
self
.
_storage_hexsep
=
''
self
.
_storage_fmt
=
'
{:.3f}
\t
{}
\t
{}
\n
'
self
.
receiver
=
None
self
.
receiver
=
None
...
@@ -45,9 +46,12 @@ class Connector:
...
@@ -45,9 +46,12 @@ 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
,
hexsep
=
''
):
def
setup_storage
(
self
,
fname
,
hexsep
=
None
,
fmt
=
None
):
self
.
_storagefd
=
open
(
fname
,
'
w
'
)
self
.
_storagefd
=
open
(
fname
,
'
w
'
)
self
.
_storage_hexsep
=
hexsep
if
hexsep
is
not
None
:
self
.
_storage_hexsep
=
hexsep
if
fmt
is
not
None
:
self
.
_storage_fmt
=
fmt
def
setup_port
(
self
):
def
setup_port
(
self
):
...
@@ -70,7 +74,7 @@ class Connector:
...
@@ -70,7 +74,7 @@ class Connector:
self
.
conn
=
self
.
sockfd
self
.
conn
=
self
.
sockfd
print
(
'
Connected to {}:{}
'
.
format
(
self
.
host
,
self
.
port
))
print
(
'
Connected to {}:{}
'
.
format
(
self
.
host
,
self
.
port
))
self
.
conn
.
settimeout
(
self
.
response_to
)
self
.
conn
.
settimeout
(
self
.
_
response_to
)
def
_close
(
self
,
servershtdwn
):
def
_close
(
self
,
servershtdwn
):
if
self
.
conn
.
fileno
()
!=
-
1
:
if
self
.
conn
.
fileno
()
!=
-
1
:
...
@@ -103,10 +107,9 @@ class Connector:
...
@@ -103,10 +107,9 @@ class Connector:
self
.
_storagefd
.
close
()
self
.
_storagefd
.
close
()
self
.
_storagefd
=
None
self
.
_storagefd
=
None
def
dump_log
(
self
,
fname
,
hexsep
=
''
):
def
dump_log
(
self
,
fname
,
hexsep
=
''
,
fmt
=
'
{:.3f}
\t
{}
\t
{}
'
):
log
=
'
\n
'
.
join
([
'
{:.3f}
\t
{}
\t
{}
'
.
format
(
t
,
_msgdecoder
(
msg
,
self
.
msgdecoding
,
sep
=
hexsep
),
_msgdecoder
(
resp
,
self
.
msgdecoding
,
sep
=
hexsep
))
for
(
t
,
msg
,
resp
)
in
self
.
log
])
with
open
(
fname
,
'
w
'
)
as
fd
:
with
open
(
fname
,
'
w
'
)
as
fd
:
fd
.
write
(
log
)
fd
.
write
(
'
\n
'
.
join
([
fmt
.
format
(
t
,
_msgdecoder
(
msg
,
self
.
msgdecoding
,
sep
=
hexsep
),
_msgdecoder
(
resp
,
self
.
msgdecoding
,
sep
=
hexsep
))
for
(
t
,
msg
,
resp
)
in
self
.
log
])
)
def
send
(
self
,
msg
,
rx
=
True
,
output
=
False
):
def
send
(
self
,
msg
,
rx
=
True
,
output
=
False
):
...
@@ -124,11 +127,11 @@ class Connector:
...
@@ -124,11 +127,11 @@ 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
,
sep
=
self
.
_storage_hexsep
),
_msgdecoder
(
resp
,
self
.
msgdecoding
,
sep
=
self
.
_storage_hexsep
)))
self
.
_storagefd
.
write
(
self
.
_storage_fmt
.
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
:
if
not
rx
:
return
None
return
None
...
@@ -164,7 +167,7 @@ class Connector:
...
@@ -164,7 +167,7 @@ class Connector:
def
set_response_to
(
self
,
seconds
):
def
set_response_to
(
self
,
seconds
):
self
.
conn
.
settimeout
(
seconds
)
self
.
conn
.
settimeout
(
seconds
)
self
.
response_to
=
seconds
self
.
_
response_to
=
seconds
def
start_receiver
(
self
,
procfunc
=
None
,
outfile
=
None
,
ofmode
=
'
w
'
):
def
start_receiver
(
self
,
procfunc
=
None
,
outfile
=
None
,
ofmode
=
'
w
'
):
"""
"""
...
...
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