Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HEV - High Energy Ventilator
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Operate
Environments
Monitor
Incidents
Service Desk
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
Projects
HEV - High Energy Ventilator
Commits
dd67226b
Commit
dd67226b
authored
4 years ago
by
Chris Burr
Browse files
Options
Downloads
Patches
Plain Diff
Remove BaseFormat.toByteArray
parent
70e01ce5
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
raspberry-dataserver/CommsCommon.py
+4
-35
4 additions, 35 deletions
raspberry-dataserver/CommsCommon.py
with
4 additions
and
35 deletions
raspberry-dataserver/CommsCommon.py
+
4
−
35
View file @
dd67226b
...
...
@@ -126,55 +126,28 @@ class BaseFormat():
_RPI_VERSION
:
ClassVar
[
int
]
=
field
(
default
=
0xA2
,
init
=
False
,
repr
=
False
)
_type
:
ClassVar
[
Any
]
=
field
(
default
=
PAYLOAD_TYPE
.
UNSET
,
init
=
False
,
repr
=
False
)
_dataStruct
:
ClassVar
[
Any
]
=
field
(
default
=
Struct
(
"
<BI
"
),
init
=
False
,
repr
=
False
)
_byteArray
:
ClassVar
[
bytearray
]
=
field
(
default
=
None
,
init
=
False
,
repr
=
False
)
_autogen
:
ClassVar
[
bool
]
=
field
(
default
=
False
,
init
=
False
,
repr
=
False
)
# class variables
version
:
int
=
0
timestamp
:
int
=
0
def
__post_init__
(
self
):
self
.
toByteArray
()
self
.
_autogen
=
True
def
__setattr__
(
self
,
key
,
value
):
self
.
__dict__
[
key
]
=
value
# if any other variable is modified outside init, regenerate the bytearray
if
self
.
_autogen
and
key
[
0
]
!=
"
_
"
and
key
!=
"
version
"
:
self
.
toByteArray
()
@property
def
byteArray
(
self
)
->
bytearray
:
self
.
toByteArray
()
return
self
.
_byteArray
@byteArray.setter
def
byteArray
(
self
,
byte_array
)
->
None
:
try
:
self
.
fromByteArray
(
byte_array
)
self
.
_byteArray
=
byte_array
except
Exception
:
raise
def
toByteArray
(
self
)
->
None
:
self
.
version
=
self
.
_RPI_VERSION
self
.
_byteArray
=
self
.
_dataStruct
.
pack
(
*
[
return
self
.
_dataStruct
.
pack
(
*
[
v
.
value
if
isinstance
(
v
,
IntEnum
)
or
isinstance
(
v
,
Enum
)
else
v
for
v
in
asdict
(
self
).
values
()
])
# at the minute not generalised. needs to be overridden
def
fromByteArray
(
self
,
byteArray
:
bytearray
)
->
None
:
(
self
.
version
,
self
.
timestamp
)
=
self
.
_dataStruct
.
unpack
(
byteArray
)
self
.
_byteArray
=
byteArray
(
self
.
version
,
self
.
timestamp
)
=
self
.
_dataStruct
.
unpack
(
byteArray
)
# check for mismatch between pi and microcontroller version
def
checkVersion
(
self
)
->
bool
:
return
self
.
_RPI_VERSION
==
self
.
version
def
getSize
(
self
)
->
int
:
return
len
(
self
.
_byteArray
)
#
def getSize(self) -> int:
#
return len(self._byteArray)
def
getType
(
self
)
->
Any
:
return
self
.
_type
...
...
@@ -315,7 +288,6 @@ class ReadbackFormat(BaseFormat):
self
.
exhale_trigger_enable
,
self
.
peep
,
self
.
inhale_exhate_ratio
)
=
self
.
_dataStruct
.
unpack
(
byteArray
)
self
.
_byteArray
=
byteArray
# =======================================
...
...
@@ -371,7 +343,6 @@ class CycleFormat(BaseFormat):
self
.
apnea_index
,
self
.
apnea_time
,
self
.
mandatory_breath
)
=
self
.
_dataStruct
.
unpack
(
byteArray
)
self
.
_byteArray
=
byteArray
# =======================================
...
...
@@ -397,7 +368,6 @@ class CommandFormat(BaseFormat):
self
.
cmd_type
,
self
.
cmd_code
,
self
.
param
)
=
self
.
_dataStruct
.
unpack
(
byteArray
)
self
.
_byteArray
=
byteArray
# =======================================
...
...
@@ -420,4 +390,3 @@ class AlarmFormat(BaseFormat):
alarm
,
self
.
param
)
=
self
.
_dataStruct
.
unpack
(
byteArray
)
self
.
alarm_code
=
ALARM_CODES
(
alarm
)
self
.
_byteArray
=
byteArray
This diff is collapsed.
Click to expand it.
Preview
0%
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