Skip to content

Commit

Permalink
Updated power test to include new PG signals
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohrer committed Jun 14, 2024
1 parent 33ee574 commit 7d1ffc6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
30 changes: 19 additions & 11 deletions amplipi/rt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import time
import logging
import sys
from dataclasses import dataclass
from enum import Enum
from typing import Dict, List, Tuple, Union, Optional

Expand Down Expand Up @@ -89,6 +90,18 @@ class FanCtrl(Enum):
FORCED = 3


@dataclass
class PowerStatus:
"""Contains the status of the AmpliPi's various power supplies as measured by the firmware."""
pg_5vd: bool # True if the 5VD rail is good
pg_5va: bool # True if the 5VA rail is good
pg_9v: bool # True if the 9V rail is good
en_9v: bool # True if the 9V rail is enabled
pg_12v: bool # True if the 12V rail is good
en_12v: bool # True if the 12V rail is enabled
v12: float # Fan power supply voltage, nominally 12V


def is_amplipi():
""" Check if the current hardware is an AmpliPi
Expand Down Expand Up @@ -297,29 +310,24 @@ def read_version(self, preamp: int = 1):
return major, minor, git_hash, dirty
return None, None, None, None

def read_power_status(self, preamp: int = 1) -> Tuple[
Optional[bool], Optional[bool], Optional[bool], Optional[bool], Optional[float]
]:
def read_power_status(self, preamp: int = 1) -> Optional[PowerStatus]:
""" Read the status of the power supplies
Returns:
pg_9v: True if the 9V rail is good
en_9v: True if the 9V rail is enabled
pg_12v: True if the 12V rail is good
en_12v: True if the 12V rail is enabled
v12: Fan power supply voltage, nominally 12V
Returns the state of the power supplies as a PowerStatus.
"""
assert 1 <= preamp <= 6
if self.bus is not None:
pstat = self.bus.read_byte_data(preamp * 8, _REG_ADDRS['POWER'])
pg_5va = (pstat & 0x20) != 0
pg_5vd = (pstat & 0x10) != 0
en_12v = (pstat & 0x08) != 0
pg_12v = (pstat & 0x04) != 0
en_9v = (pstat & 0x02) != 0
pg_9v = (pstat & 0x01) != 0
fvstat = self.bus.read_byte_data(preamp * 8, _REG_ADDRS['FAN_VOLTS'])
v12 = fvstat / 2**4
return pg_9v, en_9v, pg_12v, en_12v, v12
return None, None, None, None, None
return PowerStatus(pg_5vd, pg_5va, pg_9v, en_9v, pg_12v, en_12v, v12)
return None

def read_fan_status(self, preamp: int = 1) -> Union[
Tuple[FanCtrl, bool, bool, bool, bool], Tuple[None, None, None, None, None]
Expand Down
11 changes: 6 additions & 5 deletions hw/test_ap1_s4z6.tex
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@
\end{checklist}
{\renewcommand{\arraystretch}{1.5} % Make the rows double-height
\hspace{2em}\begin{tabularx}{\dimexpr\linewidth-2em}{X@{\hskip 3em}X}
Fans Off \hfill\rule{3em}{0.4pt} & Fans On \hfill\rule{3em}{0.4pt} \\
PG\_12V \hfill\rule{3em}{0.4pt} & 12V Supply \hfill\rule{3em}{0.4pt} \\
HV1 Temp \hfill\rule{3em}{0.4pt} & \\
AMP1 Temp \hfill\rule{3em}{0.4pt} & AMP2 Temp \hfill\rule{3em}{0.4pt} \\
Temp Rise \hfill\rule{3em}{0.4pt} & \\
Fans Off \hfill\rule{3em}{0.4pt} & PG\_12V \hfill\rule{3em}{0.4pt} \\
Fans On \hfill\rule{3em}{0.4pt} & 12V Supply \hfill\rule{3em}{0.4pt} \\
PG\_5VD \hfill\rule{3em}{0.4pt} & AMP1 Temp \hfill\rule{3em}{0.4pt} \\
PG\_5VA \hfill\rule{3em}{0.4pt} & AMP2 Temp \hfill\rule{3em}{0.4pt} \\
PG\_9V \hfill\rule{3em}{0.4pt} & HV1 Temp \hfill\rule{3em}{0.4pt} \\
& Temp Rise \hfill\rule{3em}{0.4pt} \\
\end{tabularx}}

\begin{checklist}
Expand Down
5 changes: 3 additions & 2 deletions hw/test_ap1_z6.tex
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@
\end{checklist}
{\renewcommand{\arraystretch}{1.5} % Make the rows 1.5x-height
\hspace{2em}\begin{tabularx}{40em}{XXXX}
Fans Off \hfill\rule{3em}{0.4pt} & Fans On \hfill\rule{3em}{0.4pt} & PG\_12V \hfill\rule{3em}{0.4pt} & 12V Supply \hfill\rule{3em}{0.4pt} \\
HV1 Temp \hfill\rule{3em}{0.4pt} & AMP1 Temp \hfill\rule{3em}{0.4pt} & AMP2 Temp \hfill\rule{3em}{0.4pt} & Temp Rise \hfill\rule{3em}{0.4pt} \\
Fans Off \hfill\rule{3em}{0.4pt} & PG\_5VD \hfill\rule{3em}{0.4pt} & PG\_9V \hfill\rule{3em}{0.4pt} & AMP1 Temp \hfill\rule{3em}{0.4pt} \\
Fans On \hfill\rule{3em}{0.4pt} & PG\_5VA \hfill\rule{3em}{0.4pt} & PG\_12V \hfill\rule{3em}{0.4pt} & AMP2 Temp \hfill\rule{3em}{0.4pt} \\
Temp Rise \hfill\rule{3em}{0.4pt} & & 12V Supply \hfill\rule{3em}{0.4pt} & HV1 Temp \hfill\rule{3em}{0.4pt} \\
\end{tabularx}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
22 changes: 13 additions & 9 deletions hw/tests/preamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def print_status(p: rt._Preamps, u: int):
sys.exit(ExitCode.BAD_VERSION)
print(f' Version {major}.{minor}-{git_hash:07X}, {"dirty" if dirty else "clean"}')

# Power - note: failed only exists on Rev2 Power Board
pg_9v, en_9v, pg_12v, en_12v, v12 = p.read_power_status(u)
print(f' 9V: EN={en_9v}, PG={pg_9v}')
print(f' 12V: EN={en_12v}, PG={pg_12v}, {v12} V')
# Power
pstat = p.read_power_status(u)
print(f' Power: PG_5VD={pstat.pg_5vd}, PG_5VA={pstat.pg_5va}, PG_9V={pstat.pg_9v}, PG_12V={pstat.pg_12v}')
print(f' 9V_EN={pstat.en_9v}, 12V_EN={pstat.en_12v}, {pstat.v12} V')

# 24V and temp
hv1, hv2 = p.read_hv(u)
Expand Down Expand Up @@ -103,11 +103,15 @@ def print_cond(u: int, ok: bool, s: str):
success = True
for u in range(len(p.preamps)):
if not unit or u + 1 == unit: # u is 0-based, unit is 1-based
_, _, pg_12v, _, v12 = p.read_power_status(u + 1)
v12_ok = 6 < v12 < 12.5
success &= pg_12v and v12_ok
print_cond(u, pg_12v, f'PG_12V {"ok" if pg_12v else "bad"}')
print_cond(u, v12_ok, f'12V supply {"ok" if v12_ok else "bad"} - {v12:.2f}V')
pstat = p.read_power_status(u + 1)
v12_ok = 6 < pstat.v12 < 12.5
success &= pstat.pg_5vd and pstat.pg_5va and pstat.pg_9v and pstat.pg_12v and v12_ok
print_cond(u, pstat.pg_5vd, f'PG_5VD {"ok" if pstat.pg_5vd else "bad"}')
print_cond(u, pstat.pg_5va, f'PG_5VA {"ok" if pstat.pg_5va else "bad"}')
print_cond(u, pstat.pg_9v, f'PG_9V {"ok" if pstat.pg_9v else "bad"}')
print_cond(u, pstat.pg_12v, f'PG_12V {"ok" if pstat.pg_12v else "bad"}')
print_cond(u, v12_ok, f'12V supply {"ok" if v12_ok else "bad"} - {pstat.v12:.2f}V')

hv1_tmp, hv2_tmp, amp1_tmp, amp2_tmp = p.read_temps(u + 1)
hv2_present = hv2_tmp is not None
hv1_ok = -19 <= hv1_tmp <= 106
Expand Down

0 comments on commit 7d1ffc6

Please sign in to comment.