Skip to content
19 changes: 18 additions & 1 deletion ptd_client_server/lib/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ def __init__(self, server: Server, label: str) -> None:
self._state = SessionState.INITIAL
self._maxAmps: Optional[str] = None
self._maxVolts: Optional[str] = None
self._desirableCurrentRange: Optional[str] = None

def start(self, mode: Mode) -> bool:
if mode == Mode.RANGING and self._state == SessionState.RANGING:
Expand Down Expand Up @@ -812,7 +813,7 @@ def start(self, mode: Mode) -> bool:
self._server._summary.phase("testing", 0)
self._ptd.start()
self._ptd.cmd(f"SR,V,{self._maxVolts}")
self._ptd.cmd(f"SR,A,{self._maxAmps}")
self._ptd.cmd(f"SR,A,{self._desirableCurrentRange}")
with common.sig:
time.sleep(ANALYZER_SLEEP_SECONDS)
logging.info("Starting testing mode")
Expand Down Expand Up @@ -875,6 +876,22 @@ def stop(self, mode: Mode) -> bool:
channels_amount,
)

# we will generate crude max power approximation and depending on that, we will add fix to crest factor
# default is crest factor 3 (pek current is 3x rms current)
# PSUs under 75W don't have mandatory Power Factor Correction, so they can be arbitrarily dirty
# meters use crest factor of 6 for such devices. so, most meaningful solution is to increase range x2
# that will increase detectable peak current to 6x original max noticed value
# in case such things are not done, peaks over 3x range will be cut off, so measured/reported power will be reported as lower than realistic

if self._maxAmps is not None and self._maxVolts is not None:
w = float(self._maxAmps) * float(self._maxVolts)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here power factor must also be multiplied right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly. and to get that, i need to modify max_volts_amps which will break all unit tests and when doing that, i'll just either base decision on power factor alone or rather on real power

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sure. I think using power factor alone should be reasonable here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'd need to make number up since power factor is not 100% reliable indicator of peak. THD is better, but PTD doesn't gather that. so instead i opted for modifying the function and also grabbing power

else:
w = -1
if w > 75:
self._desirableCurrentRange = self._maxAmps
else:
self._desirableCurrentRange = str(float(self._maxAmps) * 2)

except MaxVoltsAmpsNegativeValuesError as e:
if test_duration < 1:
raise MeasurementEndedTooFastError(
Expand Down