Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
ptblab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Daniele Nicolodi
ptblab
Commits
4d5894a9
Commit
4d5894a9
authored
1 year ago
by
Daniele Nicolodi
Browse files
Options
Downloads
Patches
Plain Diff
meerstetterTEC: Fix parsing of error replies
parent
15613e45
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
meerstetterTEC.py
+12
-3
12 additions, 3 deletions
meerstetterTEC.py
with
12 additions
and
3 deletions
meerstetterTEC.py
+
12
−
3
View file @
4d5894a9
...
@@ -14,6 +14,7 @@ from ptblab import datalogger, terminal, utils
...
@@ -14,6 +14,7 @@ from ptblab import datalogger, terminal, utils
EOF
=
b
'
\r
'
EOF
=
b
'
\r
'
DEVICE
=
b
'
!
'
DEVICE
=
b
'
!
'
HOST
=
b
'
#
'
HOST
=
b
'
#
'
ERROR
=
b
'
+
'
class
Errno
(
int
,
enum
.
Enum
):
class
Errno
(
int
,
enum
.
Enum
):
...
@@ -102,19 +103,27 @@ class MeCom:
...
@@ -102,19 +103,27 @@ class MeCom:
def
recv
(
self
,
crc
=
None
):
def
recv
(
self
,
crc
=
None
):
packet
=
self
.
conn
.
read_until
(
EOF
).
rstrip
()
packet
=
self
.
conn
.
read_until
(
EOF
).
rstrip
()
crc
=
crc
if
crc
is
not
None
else
self
.
crc
(
packet
[:
-
4
])
control
,
address
,
seqno
,
data
=
self
.
unpack
(
packet
[:
-
4
])
# When the received frame is an ACK to a VS instruction, the
# CRC matches the CRC of the packet containing the VS
# instruction. When the received frame is an error or a reply
# to other instructions, the CRC should match the CRC of the
# reply packet. When the reply is expected in response to a VS
# instruction, the expected CRC is provided as an argument.
crc
=
crc
if
crc
is
not
None
and
data
[
0
:
1
]
!=
ERROR
else
self
.
crc
(
packet
[:
-
4
])
if
not
packet
:
if
not
packet
:
raise
TimeoutError
raise
TimeoutError
if
crc
!=
packet
[
-
4
:]:
if
crc
!=
packet
[
-
4
:]:
raise
ValueError
(
f
'
CRC error:
{
packet
}
'
)
raise
ValueError
(
f
'
CRC error:
{
packet
}
'
)
control
,
address
,
seqno
,
data
=
self
.
unpack
(
packet
[:
-
4
])
if
control
!=
DEVICE
:
if
control
!=
DEVICE
:
raise
ValueError
(
f
'
unexpected control character:
{
packet
}
'
)
raise
ValueError
(
f
'
unexpected control character:
{
packet
}
'
)
if
address
!=
self
.
address
:
if
address
!=
self
.
address
:
raise
ValueError
(
f
'
unexpected return address:
{
packet
}
'
)
raise
ValueError
(
f
'
unexpected return address:
{
packet
}
'
)
if
seqno
!=
self
.
seqno
:
if
seqno
!=
self
.
seqno
:
raise
ValueError
(
f
'
unexpected return seqno:
{
packet
}
'
)
raise
ValueError
(
f
'
unexpected return seqno:
{
packet
}
'
)
if
data
[
0
:
1
]
==
b
'
+
'
:
if
data
[
0
:
1
]
==
ERROR
:
raise
MeComError
(
Errno
(
int
(
data
[
1
:])))
raise
MeComError
(
Errno
(
int
(
data
[
1
:])))
return
data
return
data
...
...
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