Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
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
Anders Blomdell
LabComm
Commits
8a0eeb9d
Commit
8a0eeb9d
authored
11 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Allow tuples and other iterables for arrays in python.
Fixed python encode_byte to be unsigned.
parent
2d0cba67
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/python/labcomm/LabComm.py
+15
-5
15 additions, 5 deletions
lib/python/labcomm/LabComm.py
test/test_encoder_decoder.py
+1
-1
1 addition, 1 deletion
test/test_encoder_decoder.py
with
16 additions
and
6 deletions
lib/python/labcomm/LabComm.py
+
15
−
5
View file @
8a0eeb9d
...
@@ -93,6 +93,7 @@
...
@@ -93,6 +93,7 @@
# sequences of 7 bit chunks, represented in bytes with the high bit meaning
# sequences of 7 bit chunks, represented in bytes with the high bit meaning
# that more data is to come.
# that more data is to come.
import
types
import
struct
as
packer
import
struct
as
packer
VERSION
=
"
LabComm2013
"
VERSION
=
"
LabComm2013
"
...
@@ -316,18 +317,26 @@ class array(object):
...
@@ -316,18 +317,26 @@ class array(object):
encoder
.
encode_packed32
(
i
)
encoder
.
encode_packed32
(
i
)
encoder
.
encode_type_number
(
self
.
decl
)
encoder
.
encode_type_number
(
self
.
decl
)
def
min_max_shape
(
self
,
l
,
depth
=
0
,
shape
=
[]):
def
min_max_shape
(
self
,
l
,
depth
,
shape
):
if
isinstance
(
l
,
list
):
if
isinstance
(
l
,
types
.
StringTypes
):
return
shape
try
:
length
=
len
(
l
)
length
=
len
(
l
)
if
len
(
shape
)
<=
depth
:
if
len
(
shape
)
<=
depth
:
shape
.
append
((
length
,
length
))
shape
.
append
((
length
,
length
))
pass
else
:
else
:
(
low
,
high
)
=
shape
[
depth
]
(
low
,
high
)
=
shape
[
depth
]
low
=
min
(
low
,
length
)
low
=
min
(
low
,
length
)
high
=
max
(
high
,
length
)
high
=
max
(
high
,
length
)
shape
[
depth
]
=
(
low
,
high
)
shape
[
depth
]
=
(
low
,
high
)
pass
for
e
in
l
:
for
e
in
l
:
shape
=
self
.
min_max_shape
(
e
,
depth
+
1
,
shape
)
shape
=
self
.
min_max_shape
(
e
,
depth
+
1
,
shape
)
pass
pass
except
TypeError
:
pass
return
shape
return
shape
def
shape
(
self
,
l
):
def
shape
(
self
,
l
):
...
@@ -356,7 +365,8 @@ class array(object):
...
@@ -356,7 +365,8 @@ class array(object):
return
depth
return
depth
def
encode_value
(
self
,
encoder
,
value
,
depth
):
def
encode_value
(
self
,
encoder
,
value
,
depth
):
if
depth
and
isinstance
(
value
,
list
):
# if depth and isinstance(value, list):
if
depth
:
for
e
in
value
:
for
e
in
value
:
self
.
encode_value
(
encoder
,
e
,
depth
-
1
)
self
.
encode_value
(
encoder
,
e
,
depth
-
1
)
else
:
else
:
...
@@ -585,7 +595,7 @@ class Encoder(Codec):
...
@@ -585,7 +595,7 @@ class Encoder(Codec):
self
.
pack
(
"
!b
"
,
0
)
self
.
pack
(
"
!b
"
,
0
)
def
encode_byte
(
self
,
v
):
def
encode_byte
(
self
,
v
):
self
.
pack
(
"
!
b
"
,
v
)
self
.
pack
(
"
!
B
"
,
v
)
def
encode_short
(
self
,
v
):
def
encode_short
(
self
,
v
):
self
.
pack
(
"
!h
"
,
v
)
self
.
pack
(
"
!h
"
,
v
)
...
@@ -669,7 +679,7 @@ class Decoder(Codec):
...
@@ -669,7 +679,7 @@ class Decoder(Codec):
return
self
.
unpack
(
"
!b
"
)
!=
0
return
self
.
unpack
(
"
!b
"
)
!=
0
def
decode_byte
(
self
):
def
decode_byte
(
self
):
return
self
.
unpack
(
"
!
b
"
)
return
self
.
unpack
(
"
!
B
"
)
def
decode_short
(
self
):
def
decode_short
(
self
):
return
self
.
unpack
(
"
!h
"
)
return
self
.
unpack
(
"
!h
"
)
...
...
This diff is collapsed.
Click to expand it.
test/test_encoder_decoder.py
+
1
−
1
View file @
8a0eeb9d
...
@@ -59,7 +59,7 @@ def generate(decl):
...
@@ -59,7 +59,7 @@ def generate(decl):
return
[
False
,
True
]
return
[
False
,
True
]
elif
decl
.
__class__
==
labcomm
.
BYTE
:
elif
decl
.
__class__
==
labcomm
.
BYTE
:
return
[
-
12
8
,
0
,
127
]
return
[
0
,
12
7
,
128
,
255
]
elif
decl
.
__class__
==
labcomm
.
SHORT
:
elif
decl
.
__class__
==
labcomm
.
SHORT
:
return
[
-
32768
,
0
,
32767
]
return
[
-
32768
,
0
,
32767
]
...
...
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