Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
python_test_scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
python_test_scripts
Commits
525bccc6
Commit
525bccc6
authored
2 years ago
by
Gijs Schoonderbeek
Browse files
Options
Downloads
Patches
Plain Diff
Moved EEPROM to separate class
parent
6214a9dd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apspu_lib.py
+49
-40
49 additions, 40 deletions
apspu_lib.py
production_apspu.py
+2
-2
2 additions, 2 deletions
production_apspu.py
with
51 additions
and
42 deletions
apspu_lib.py
+
49
−
40
View file @
525bccc6
...
...
@@ -41,47 +41,8 @@ class ApspuClass:
self
.
pols
=
[]
for
pol
in
list
(
CTR_POLS
.
keys
()):
self
.
pols
.
append
(
PolClass
(
pol
))
self
.
dev_i2c_eeprom
=
I2C
(
EEPROM
)
self
.
dev_i2c_eeprom
.
bus_nr
=
I2CBUSNR
self
.
fans
=
FanmonitorClass
()
def
write_eeprom
(
self
,
data
=
"
APSPU
"
,
address
=
0
):
#
# Write the EEPROM with the serial number etc.
#
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_bytes
(
0
)
if
ret_ack
<
1
:
print
(
"
EEPROM not found during write
"
)
return
False
else
:
wr_data
=
bytearray
(
data
.
encode
(
"
utf-8
"
,
errors
=
"
ignore
"
))
for
loc
,
data_byte
in
enumerate
(
wr_data
):
self
.
dev_i2c_eeprom
.
write_bytes
(
address
+
loc
,
data_byte
)
sleep
(
0.1
)
return
True
def
read_eeprom
(
self
,
address
=
0
,
nof_bytes
=
5
):
#
# Read the EEPROM with the serial number etc.
#
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_last_reg
(
1
)
if
ret_ack
<
1
:
print
(
"
no EEPROM found during read
"
)
return
False
else
:
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_bytes
(
address
,
nof_bytes
)
str_return
=
bytes
.
fromhex
(
ret_value
[:
nof_bytes
*
2
]).
decode
(
'
UTF-8
'
)
return
str_return
def
wr_rd_eeprom
(
self
,
value
=
"
APSPU-1
"
,
address
=
0
):
#
# Write and Read the EEPROM to check functionality
#
if
self
.
write_eeprom
(
value
,
address
=
0
):
ret_value
=
self
.
read_eeprom
(
address
=
0
,
nof_bytes
=
len
(
value
))
stri
=
"
Wrote to EEPROM register 0x{2:x} : {0}, Read from EEPROM: {1}
"
.
format
(
value
,
ret_value
,
address
)
print
(
stri
)
return
True
self
.
eeprom
=
EepromClass
()
def
read_all
(
self
):
#
...
...
@@ -131,6 +92,54 @@ class ApspuClass:
pol
.
on_off
(
on
)
return
True
class
EepromClass
:
#
# Class to handle EEPROM communication
#
def
__init__
(
self
):
#
# All monitoring points Point of Load DC/DC converter
#
self
.
dev_i2c_eeprom
=
I2C
(
EEPROM
)
self
.
dev_i2c_eeprom
.
bus_nr
=
I2CBUSNR
def
write_eeprom
(
self
,
data
=
"
APSPU
"
,
address
=
0
):
#
# Write the EEPROM with the serial number etc.
#
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_bytes
(
0
)
if
ret_ack
<
1
:
print
(
"
EEPROM not found during write
"
)
return
False
else
:
wr_data
=
bytearray
(
data
.
encode
(
"
utf-8
"
,
errors
=
"
ignore
"
))
for
loc
,
data_byte
in
enumerate
(
wr_data
):
self
.
dev_i2c_eeprom
.
write_bytes
(
address
+
loc
,
data_byte
)
sleep
(
0.1
)
return
True
def
read_eeprom
(
self
,
address
=
0
,
nof_bytes
=
5
):
#
# Read the EEPROM with the serial number etc.
#
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_last_reg
(
1
)
if
ret_ack
<
1
:
print
(
"
no EEPROM found during read
"
)
return
False
else
:
ret_ack
,
ret_value
=
self
.
dev_i2c_eeprom
.
read_bytes
(
address
,
nof_bytes
)
str_return
=
bytes
.
fromhex
(
ret_value
[:
nof_bytes
*
2
]).
decode
(
'
UTF-8
'
)
return
str_return
def
wr_rd_eeprom
(
self
,
value
=
"
APSPU-1
"
,
address
=
0
):
#
# Write and Read the EEPROM to check functionality
#
if
self
.
write_eeprom
(
value
,
address
=
0
):
ret_value
=
self
.
read_eeprom
(
address
=
0
,
nof_bytes
=
len
(
value
))
stri
=
"
Wrote to EEPROM register 0x{2:x} : {0}, Read from EEPROM: {1}
"
.
format
(
value
,
ret_value
,
address
)
print
(
stri
)
return
True
class
PolClass
:
...
...
This diff is collapsed.
Click to expand it.
production_apspu.py
+
2
−
2
View file @
525bccc6
...
...
@@ -46,5 +46,5 @@ apspu.print_status()
#apspu.apspu_on_off(True)
id
=
"
APSPU-
"
+
sys
.
argv
[
1
]
serial
=
sys
.
argv
[
2
]
apspu
.
wr_rd_eeprom
(
id
,
address
=
0
)
apspu
.
wr_rd_eeprom
(
serial
,
address
=
0x20
)
apspu
.
eeprom
.
wr_rd_eeprom
(
id
,
address
=
0
)
apspu
.
eeprom
.
wr_rd_eeprom
(
serial
,
address
=
0x20
)
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