From 02f42536f4c7a746320257b6ad9c94e2186bf565 Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Thu, 18 May 2023 06:10:46 -0700 Subject: [PATCH 01/11] added DC personalities for some meters to affected files --- compliance/check.py | 3 +++ ptd_client_server/lib/server.py | 10 ++++++++++ ptd_client_server/server.template.conf | 3 +++ 3 files changed, 16 insertions(+) diff --git a/compliance/check.py b/compliance/check.py index 379b98de..8e293e98 100755 --- a/compliance/check.py +++ b/compliance/check.py @@ -49,6 +49,9 @@ class CheckerWarning(Exception): "YokogawaWT330": 52, "YokogawaWT330E": 52, "YokogawaWT330_multichannel": 77, + "YokogawaWT210_DC": 508, + "YokogawaWT310_DC": 549, + "YokogawaWT330_DC": 586, } RANGING_MODE = "ranging" diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 529d2032..9a6ba21c 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -63,6 +63,8 @@ # https://github.com/mlcommons/power-dev/issues/220#issue-835336923 DEVICE_TYPE_WT500 = 48 +DC_DEVICES = [508, 549, 586] + MAX_RANGE_FOR_DEVICE = { 8: 20, # WT210 49: 20, # WT310 @@ -72,6 +74,10 @@ 48: 40, # WT500_multichannel 47: 50, # WT1800 66: 30, # WT5000 + 508: 20, # WT210 DC + 549: 20, # WT310 DC + 586: 20, # WT330 DC + } @@ -296,11 +302,13 @@ def get( "ptd", "channel", parse=parse_channel, fallback=None ) self.ptd_device_type: int = get("ptd", "deviceType", parse=int) + ptd_dc_flag: Optional[str] = get("ptd", "dcFlag", fallback=None) ptd_interface_flag: str = get("ptd", "interfaceFlag") ptd_device_port: str = get("ptd", "devicePort") ptd_board_num: Optional[int] = get("ptd", "gpibBoard", parse=int, fallback=None) # TODO: validate ptd_interface_flag? # TODO: validate ptd_device_type? + # we can have a list of supported/tested devices and throw a warning when new device is used? self.ptd_logfile: str = os.path.join(self.tmp_dir.name, "ptd_logfile.txt") self.ptd_port: int = get("ptd", "networkPort", parse=int, fallback="8888") self.ptd_command: List[str] = [ @@ -315,6 +323,7 @@ def get( if self.ptd_channel is None else ["-c", ",".join(str(x) for x in self.ptd_channel)] ), + *([] if ptd_dc_flag is None else [ptd_dc_flag]), *([] if ptd_interface_flag == "" else [ptd_interface_flag]), str(self.ptd_device_type), ptd_device_port, @@ -324,6 +333,7 @@ def get( "command": self.ptd_command, "device_type": self.ptd_device_type, "interface_flag": ptd_interface_flag, + "dc_flag": ptd_dc_flag, "device_port": ptd_device_port, "channel": self.ptd_channel, } diff --git a/ptd_client_server/server.template.conf b/ptd_client_server/server.template.conf index 6bb9007e..044a8788 100644 --- a/ptd_client_server/server.template.conf +++ b/ptd_client_server/server.template.conf @@ -57,3 +57,6 @@ devicePort: COM1 # Channel value should consist of two numbers separated by a comma for a multichannel analyzer. # Channel value should consist of one number or be disabled for a 1-channel analyzer. #channel: 1,2 + +# (Optional in case of DC meter) flag needed to specify to PTD that meter will be used as DC meter +# dcFlag: -D From f344279b3925d4244dba0ffba0b317af50ccc8ff Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Thu, 18 May 2023 06:16:24 -0700 Subject: [PATCH 02/11] removed one newline --- ptd_client_server/lib/server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 9a6ba21c..24f6e4cf 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -77,7 +77,6 @@ 508: 20, # WT210 DC 549: 20, # WT310 DC 586: 20, # WT330 DC - } From 0c198ae0792583eef9d7ebc553d96527d16ca408 Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Sun, 22 Oct 2023 13:55:41 -0700 Subject: [PATCH 03/11] added DC telnet command --- ptd_client_server/lib/server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 24f6e4cf..f42be0d0 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -39,6 +39,8 @@ from ptd_client_server.lib import summary as summarylib from ptd_client_server.lib import time_sync +PTD_READ_ALL_COMMAND_AC = "RL" +PTD_READ_ALL_COMMAND_DC = "DC-RL" RE_PTD_LOG = re.compile( r"""^ @@ -473,11 +475,13 @@ def _start(self) -> None: def grab_power_data(self) -> Tuple[int, str, Optional[str], Optional[str]]: # (DM) Created method that will utilize SPEC's (only) preferred way of PTD usage and data gathering - power_data_header = self.cmd("RL") # RL - command to show unread samples + power_data_header = self.cmd(PTD_READ_ALL_COMMAND_AC) # RL - command to show unread samples + if "Unknown command" in power_data_header: + power_data_header = self.cmd(PTD_READ_ALL_COMMAND_DC) # DC-RL - command to show unread samples in case of DC meter if power_data_header is not None: number_of_samples = int( power_data_header.split(" ")[1] - ) # first line of response will have message: "Last XYZ samples" + ) # first line of response will have message: "Last XYZ samples". in case of multich, it will hold inaccurate channel numbers, think how to get real stuff later else: number_of_samples = 0 grabbed_power_data = self.read(number_of_samples) From e9dd718d3b4b74f6a3a89d4e72769b30785cc00b Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Sun, 22 Oct 2023 14:36:14 -0700 Subject: [PATCH 04/11] black... --- ptd_client_server/lib/server.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index f42be0d0..a7037fbd 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -475,13 +475,17 @@ def _start(self) -> None: def grab_power_data(self) -> Tuple[int, str, Optional[str], Optional[str]]: # (DM) Created method that will utilize SPEC's (only) preferred way of PTD usage and data gathering - power_data_header = self.cmd(PTD_READ_ALL_COMMAND_AC) # RL - command to show unread samples + power_data_header = self.cmd( + PTD_READ_ALL_COMMAND_AC + ) # RL - command to show unread samples if "Unknown command" in power_data_header: - power_data_header = self.cmd(PTD_READ_ALL_COMMAND_DC) # DC-RL - command to show unread samples in case of DC meter + power_data_header = self.cmd( + PTD_READ_ALL_COMMAND_DC + ) # DC-RL - command to show unread samples in case of DC meter if power_data_header is not None: number_of_samples = int( power_data_header.split(" ")[1] - ) # first line of response will have message: "Last XYZ samples". in case of multich, it will hold inaccurate channel numbers, think how to get real stuff later + ) # first line of response will have message: "Last XYZ samples". else: number_of_samples = 0 grabbed_power_data = self.read(number_of_samples) From 258348faccaebe065e8f5cbb7c466618bbd677e8 Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Sun, 22 Oct 2023 14:51:09 -0700 Subject: [PATCH 05/11] mypy... --- ptd_client_server/lib/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index a7037fbd..79b18faf 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -478,7 +478,7 @@ def grab_power_data(self) -> Tuple[int, str, Optional[str], Optional[str]]: power_data_header = self.cmd( PTD_READ_ALL_COMMAND_AC ) # RL - command to show unread samples - if "Unknown command" in power_data_header: + if power_data_header.find("Unknown command") != -1: power_data_header = self.cmd( PTD_READ_ALL_COMMAND_DC ) # DC-RL - command to show unread samples in case of DC meter From 85aa67a0f6964efce731753d6c7415bf298a6e19 Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Sun, 22 Oct 2023 14:56:50 -0700 Subject: [PATCH 06/11] mypy is insane --- ptd_client_server/lib/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 79b18faf..ba5317f3 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -478,7 +478,7 @@ def grab_power_data(self) -> Tuple[int, str, Optional[str], Optional[str]]: power_data_header = self.cmd( PTD_READ_ALL_COMMAND_AC ) # RL - command to show unread samples - if power_data_header.find("Unknown command") != -1: + if re.search("Unknown command", power_data_header): power_data_header = self.cmd( PTD_READ_ALL_COMMAND_DC ) # DC-RL - command to show unread samples in case of DC meter From 30a06decec6357cf8faf7c1dab35ba8ae322b96a Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Sun, 22 Oct 2023 15:03:40 -0700 Subject: [PATCH 07/11] mypy again --- ptd_client_server/lib/server.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index ba5317f3..e9035d5e 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -478,14 +478,15 @@ def grab_power_data(self) -> Tuple[int, str, Optional[str], Optional[str]]: power_data_header = self.cmd( PTD_READ_ALL_COMMAND_AC ) # RL - command to show unread samples - if re.search("Unknown command", power_data_header): - power_data_header = self.cmd( - PTD_READ_ALL_COMMAND_DC - ) # DC-RL - command to show unread samples in case of DC meter if power_data_header is not None: - number_of_samples = int( - power_data_header.split(" ")[1] - ) # first line of response will have message: "Last XYZ samples". + if re.search("Unknown command", power_data_header): + power_data_header = self.cmd( + PTD_READ_ALL_COMMAND_DC + ) # DC-RL - command to show unread samples in case of DC meter + if power_data_header is not None: + number_of_samples = int( + power_data_header.split(" ")[1] + ) # first line of response will have message: "Last XYZ samples". else: number_of_samples = 0 grabbed_power_data = self.read(number_of_samples) From 3ed7df7ff0306d567b3de28fd5209d0b21b91c76 Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Wed, 15 Nov 2023 09:38:14 -0800 Subject: [PATCH 08/11] simplified cmd line to not need DC flag --- ptd_client_server/lib/server.py | 6 ++++-- ptd_client_server/server.template.conf | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index e9035d5e..62f485e0 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -303,7 +303,10 @@ def get( "ptd", "channel", parse=parse_channel, fallback=None ) self.ptd_device_type: int = get("ptd", "deviceType", parse=int) - ptd_dc_flag: Optional[str] = get("ptd", "dcFlag", fallback=None) + if self.ptd_device_type in DC_DEVICES: + ptd_dc_flag = str("-D") + else: + ptd_dc_flag = None ptd_interface_flag: str = get("ptd", "interfaceFlag") ptd_device_port: str = get("ptd", "devicePort") ptd_board_num: Optional[int] = get("ptd", "gpibBoard", parse=int, fallback=None) @@ -334,7 +337,6 @@ def get( "command": self.ptd_command, "device_type": self.ptd_device_type, "interface_flag": ptd_interface_flag, - "dc_flag": ptd_dc_flag, "device_port": ptd_device_port, "channel": self.ptd_channel, } diff --git a/ptd_client_server/server.template.conf b/ptd_client_server/server.template.conf index 044a8788..27ed0f1c 100644 --- a/ptd_client_server/server.template.conf +++ b/ptd_client_server/server.template.conf @@ -58,5 +58,3 @@ devicePort: COM1 # Channel value should consist of one number or be disabled for a 1-channel analyzer. #channel: 1,2 -# (Optional in case of DC meter) flag needed to specify to PTD that meter will be used as DC meter -# dcFlag: -D From 755f15581f43c52c521b46d8a78611d05f6f787e Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Tue, 21 Nov 2023 15:21:03 -0800 Subject: [PATCH 09/11] resolved main branch conlfict --- ptd_client_server/lib/server.py | 63 +++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 62f485e0..5aed671f 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -39,6 +39,7 @@ from ptd_client_server.lib import summary as summarylib from ptd_client_server.lib import time_sync +PTD_READ_ALL_COMMAND_AC_MULTICH = "RL,*,*" PTD_READ_ALL_COMMAND_AC = "RL" PTD_READ_ALL_COMMAND_DC = "DC-RL" @@ -478,10 +479,16 @@ def _start(self) -> None: def grab_power_data(self) -> Tuple[int, str, Optional[str], Optional[str]]: # (DM) Created method that will utilize SPEC's (only) preferred way of PTD usage and data gathering power_data_header = self.cmd( - PTD_READ_ALL_COMMAND_AC - ) # RL - command to show unread samples + PTD_READ_ALL_COMMAND_AC_MULTICH + ) # RL,*,* - command to show unread samples from sum channel and all channels individually if power_data_header is not None: - if re.search("Unknown command", power_data_header): + if re.search("Invalid number of parameters", power_data_header): + power_data_header = self.cmd( + PTD_READ_ALL_COMMAND_AC + ) # RL - command to show unread samples in case of singlechannel AC + elif power_data_header is not None and re.search( + "Unknown command", power_data_header + ): power_data_header = self.cmd( PTD_READ_ALL_COMMAND_DC ) # DC-RL - command to show unread samples in case of DC meter @@ -951,10 +958,28 @@ def stop(self, mode: Mode) -> bool: self._state = SessionState.RANGING_DONE self._ptd.stop() samples, log_data, uncertainty_data, sanity = self._ptd.grab_power_data() - # (DM) TODO: figure out how to flag/report number of unvertain samples and how to disqualify bad run(s) - formatted_log_data = log_data.replace( - "\n", str(",Mark," + self._id + "_ranging\n") - ) # honoring format of legacy spl.txt + # (DM) really ugly function that will parse telnet log and reformat it in log that is same as ptd.log + # If anyone knows how to do it better, please do + lines = log_data.split("\n") + formatted_log_data = "" + for ii in range(len(lines)): + temp = lines[ii].split("Watts") + line_fixed = "" + for jj in range(len(temp)): + line_fixed += temp[jj] + if jj > 0 and (jj < len(temp) - 1 or len(temp) == 2): + if jj == 1: + if len(temp) == 2: + line_fixed += "," + line_fixed += "Mark," + self._id + "_ranging" + if len(temp) > 2: + line_fixed += "," + if len(temp) > 2: + line_fixed += "Ch" + str(jj) + "," + if jj < len(temp) - 1: + line_fixed += "Watts" + formatted_log_data += line_fixed + "\n" + assert self._go_command_time is not None test_duration = time.monotonic() - self._go_command_time dirname = os.path.join(self.log_dir_path, "ranging") @@ -1016,10 +1041,26 @@ def stop(self, mode: Mode) -> bool: dirname = os.path.join(self.log_dir_path, "run_1") os.mkdir(dirname) samples, log_data, uncertainty_data, sanity = self._ptd.grab_power_data() - # (DM) TODO: figure out how to flag/report number of unvertain samples and how to disqualify bad run(s) - formatted_log_data = log_data.replace( - "\n", str(",Mark," + self._id + "_testing\n") - ) # honoring format of legacy spl.txt + # (DM) TODO: figure out how to flag/report number of unvertain samples and how to disqualify bad run(s)lines = log_data.split("\n") + lines = log_data.split("\n") + formatted_log_data = "" + for ii in range(len(lines)): + temp = lines[ii].split("Watts") + line_fixed = "" + for jj in range(len(temp)): + line_fixed += temp[jj] + if jj > 0 and (jj < len(temp) - 1 or len(temp) == 2): + if jj == 1: + if len(temp) == 2: + line_fixed += "," + line_fixed += "Mark," + self._id + "_testing" + if len(temp) > 2: + line_fixed += "," + if len(temp) > 2: + line_fixed += "Ch" + str(jj) + "," + if jj < len(temp) - 1: + line_fixed += "Watts" + formatted_log_data += line_fixed + "\n" with open(os.path.join(dirname, "spl.txt"), "w") as f: f.write(formatted_log_data) with open(os.path.join(dirname, "ptd_out.txt"), "w") as f: From 8dd39bec6150e0cfeefb1b51a84f76ec6cc8cb4f Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Tue, 21 Nov 2023 15:24:18 -0800 Subject: [PATCH 10/11] fixed formatting --- ptd_client_server/lib/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 5aed671f..2fba42b4 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -305,9 +305,9 @@ def get( ) self.ptd_device_type: int = get("ptd", "deviceType", parse=int) if self.ptd_device_type in DC_DEVICES: - ptd_dc_flag = str("-D") + ptd_dc_flag = str("-D") else: - ptd_dc_flag = None + ptd_dc_flag = None ptd_interface_flag: str = get("ptd", "interfaceFlag") ptd_device_port: str = get("ptd", "devicePort") ptd_board_num: Optional[int] = get("ptd", "gpibBoard", parse=int, fallback=None) From 52e1abc39a173223a2a673140a936049078f6e99 Mon Sep 17 00:00:00 2001 From: dmiskovic-NV Date: Tue, 21 Nov 2023 15:28:58 -0800 Subject: [PATCH 11/11] formatting mypy this time --- ptd_client_server/lib/server.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ptd_client_server/lib/server.py b/ptd_client_server/lib/server.py index 2fba42b4..f3a126da 100644 --- a/ptd_client_server/lib/server.py +++ b/ptd_client_server/lib/server.py @@ -304,10 +304,9 @@ def get( "ptd", "channel", parse=parse_channel, fallback=None ) self.ptd_device_type: int = get("ptd", "deviceType", parse=int) + ptd_dc_flag: Optional[str] = None if self.ptd_device_type in DC_DEVICES: ptd_dc_flag = str("-D") - else: - ptd_dc_flag = None ptd_interface_flag: str = get("ptd", "interfaceFlag") ptd_device_port: str = get("ptd", "devicePort") ptd_board_num: Optional[int] = get("ptd", "gpibBoard", parse=int, fallback=None)