diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml index ece9c16..2b0d179 100644 --- a/.github/workflows/sphinx.yml +++ b/.github/workflows/sphinx.yml @@ -3,8 +3,7 @@ name: Sphinx docs on: push: branches: - - master - - dict-update + - v2 jobs: deploy: diff --git a/bench.py b/bench.py new file mode 100644 index 0000000..7fda3e6 --- /dev/null +++ b/bench.py @@ -0,0 +1,11 @@ +from timeit import timeit + +setup = """ +import pydrs +drs = pydrs.EthDRS('10.0.6.56', 5000) +drs.slave_addr = 5""" + +for i in range(0, 10): + print( + timeit("drs.read_vars_fbp(); drs.read_vars_common();", setup=setup, number=100) + ) diff --git a/pyproject.toml b/pyproject.toml index c0adb39..1a3c3d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,4 +47,4 @@ dev = [ "pyflakes==2.5.0", "types-setuptools", "pytest==7.1.2" -] \ No newline at end of file +] diff --git a/scripts-dev/input.xlsx b/scripts-dev/input.xlsx new file mode 100644 index 0000000..833a3c2 Binary files /dev/null and b/scripts-dev/input.xlsx differ diff --git a/src/pydrs/base.py b/src/pydrs/base.py index fc5372d..7cf9fe6 100644 --- a/src/pydrs/base.py +++ b/src/pydrs/base.py @@ -1765,6 +1765,7 @@ def _read_vars_generic( if length is None: length = 255 + sum([data["size"] for data in template.values()]) + # Dynamically obtaining transfer sizes incurs a 70 uS penalty per execution vals = self._transfer( @@ -1835,6 +1836,7 @@ def read_vars_fac_acdc(self, iib: bool = True) -> dict: vars_dict["iib_is_alarms_raw"] = vars_dict.pop("iib_alarms_is") vars_dict["iib_is_interlocks_raw"] = vars_dict.pop("iib_interlocks_is") + vars_dict["iib_is_interlocks"] = self.decode_interlocks( vars_dict["iib_is_interlocks_raw"], fac.list_acdc_iib_is_interlocks, @@ -1854,9 +1856,9 @@ def read_vars_fac_acdc(self, iib: bool = True) -> dict: vars_dict["iib_cmd_alarms_raw"], fac.list_acdc_iib_cmd_alarms, ) - return vars_dict + def read_vars_fac_dcdc(self, iib: bool = True) -> dict: """Reads FAC DCDC power supply variables @@ -2179,6 +2181,7 @@ def read_vars_fac_2p_dcdc_imas(self, com_add=1) -> dict: """ Read FAC 2P DCDC IMAS specific power supply variables + Returns ------- dict @@ -2191,6 +2194,7 @@ def read_vars_fac_2p_dcdc_imas(self, com_add=1) -> dict: ) def check_param_bank(self, param_file: str): + ps_param_list = [] # max_sampling_freq = 600000 @@ -2253,6 +2257,14 @@ def calc_pi(self, r_load, l_load, f_bw, v_dclink, send_drs=0, dsp_id=0): self.set_dsp_coeffs(3, dsp_id, [kp, ki, 0.95, -0.95]) return {"kp": kp, "ki": ki} + def store_dsp_modules_bank_csv(self, bank): + filename = input("Digite o nome do arquivo: ") + with open(filename + ".csv", "w", newline="") as f: + writer = csv.writer(f, delimiter=",") + for dsp_module, values in bank.items(): + for i, coef in enumerate(values["coeffs"]): + writer.writerow([dsp_module, values["class"], i] + coef) + def config_dsp_modules_drs_fap_tests(self): kp_load = 0 ki_load = 20.95 @@ -2330,6 +2342,7 @@ def get_dsp_modules_bank( dsp_coeffs ) + return dsp_modules_bank def set_dsp_modules_bank( @@ -2386,6 +2399,7 @@ def read_csv_dsp_modules_bank(dsp_modules_file_csv: str): Returns ------- + dict[dsp_class_name] = {"class":int, "coeffs":[float]} """ dsp_coeffs_from_csv = {} diff --git a/tests/bsmp/__init__.py b/tests/bsmp/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/bsmp/test_commands.py b/tests/bsmp/test_commands.py deleted file mode 100644 index c3a2516..0000000 --- a/tests/bsmp/test_commands.py +++ /dev/null @@ -1,36 +0,0 @@ -from unittest import TestCase - -from siriuspy.pwrsupply.bsmp.constants import ConstPSBSMP - -from pydrs.bsmp import CommonPSBSMP, EntitiesPS, SerialInterface - - -class TestSerialCommandsx0(TestCase): - """Test BSMP consulting methods.""" - - def setUp(self): - """Common setup for all tests.""" - - self._serial = SerialInterface(path="/serial", baudrate=9600) - self._entities = EntitiesPS() - - self._pwrsupply = CommonPSBSMP( - iointerface=self._serial, entities=self._entities, slave_address=1 - ) - - def test_query_protocol_version(self): - """Test""" - - def test_query_variable(self): - """Test""" - self._pwrsupply.pread_variable(var_id=ConstPSBSMP.V_PS_STATUS, timeout=500) - - def test_query_parameter(self): - """Test""" - self._pwrsupply.parameter_read(var_id=ConstPSBSMP.P_PS_NAME, timeout=500) - - def test_write_parameter(self): - """Test""" - self._pwrsupply.parameter_write( - var_id=ConstPSBSMP.P_PS_NAME, value="pv_test_name", timeout=500 - ) diff --git a/tests/bsmp/test_interface.py b/tests/bsmp/test_interface.py deleted file mode 100644 index 9d5f047..0000000 --- a/tests/bsmp/test_interface.py +++ /dev/null @@ -1,26 +0,0 @@ -from unittest import TestCase - -from serial.serialutil import SerialException - -from pydrs.bsmp import SerialInterface - - -class TestSerialInterface(TestCase): - def test_serial_creation(self): - with self.assertRaises(SerialException): - SerialInterface(path="/serial", baudrate=9600, auto_connect=True) - - with self.assertRaises(TypeError): - SerialInterface() - - with self.assertRaises(ValueError): - SerialInterface(path=None, baudrate=None) - - def test_serial_write(self): - raise NotImplementedError() - - def test_serial_read(self): - raise NotImplementedError() - - def test_serial_request(self): - raise NotImplementedError() diff --git a/tests/integration/test_act.py b/tests/integration/test_act.py deleted file mode 100644 index f0118a4..0000000 --- a/tests/integration/test_act.py +++ /dev/null @@ -1,26 +0,0 @@ -import json -from unittest import TestCase - -from pydrs import pydrs -from pydrs.validation import SerialInvalidCmd - - -class TestAct(TestCase): - def setUp(self): - with open("secrets.json") as f: - self.secret = json.loads(f.read()) - - self.drs = pydrs.EthDRS(self.secret["ip"], self.secret["port"]) - - def test_turn_on(self): - self.drs.turn_on() - - def test_turn_off(self): - self.drs.turn_off() - - def test_invalid_password(self): - with self.assertRaises(SerialInvalidCmd): - self.drs.unlock_udc(0xDEAD) - - def test_valid_password(self): - self.drs.unlock_udc(self.secret["password"]) diff --git a/tests/integration/test_perm.py b/tests/integration/test_perm.py deleted file mode 100644 index 151e94e..0000000 --- a/tests/integration/test_perm.py +++ /dev/null @@ -1,25 +0,0 @@ -import json -from unittest import TestCase - -from pydrs import pydrs -from pydrs.validation import SerialForbidden, SerialInvalidCmd - - -class TestPerm(TestCase): - def setUp(self): - with open("secrets.json") as f: - self.secret = json.loads(f.read()) - - self.drs = pydrs.EthDRS(self.secret["ip"], self.secret["port"]) - self.drs.lock_udc(self.secret["password"]) - - def test_forbidden_set_param(self): - with self.assertRaises(SerialForbidden): - self.drs.set_ps_name("A Name") - - def test_invalid_password(self): - with self.assertRaises(SerialInvalidCmd): - self.drs.unlock_udc(0xDEAD) - - def test_valid_password(self): - self.drs.unlock_udc(self.secret["password"]) diff --git a/tests/integration/test_read.py b/tests/integration/test_read.py deleted file mode 100644 index dc024ff..0000000 --- a/tests/integration/test_read.py +++ /dev/null @@ -1,48 +0,0 @@ -import json -from unittest import TestCase - -from pydrs import pydrs - - -class TestRead(TestCase): - def setUp(self): - with open("secrets.json") as f: - self.secret = json.loads(f.read()) - - self.drs = pydrs.EthDRS(self.secret["ip"], self.secret["port"]) - - def test_read_udc_arm_version(self): - self.assertEqual(self.drs.read_udc_arm_version(), "V0.43 2021-12-02") - - def test_get_scope_vars(self): - self.drs.get_scope_vars() - - def test_get_default_ramp_waveform(self): - self.assertEqual(len(self.drs.get_default_ramp_waveform()), 4000) - - def test_get_wfmref_vars(self): - self.drs.get_wfmref_vars(1) - - def test_read_curve_block(self): - self.assertEqual(len(self.drs.read_curve_block(0, 0)), 256) - - def test_get_ps_name(self): - self.drs.unlock_udc(self.secret["password"]) - self.drs.set_ps_name( - "Jiga FBP para teste de resposta a setpoints do grupo CONS" - ) - self.assertEqual( - self.drs.get_ps_name(), - "Jiga FBP para teste de resposta a setpoints do grupo CONS", - ) - self.drs.lock_udc(self.secret["password"]) - - def test_get_param_bank(self): - self.drs.get_param_bank() - - def test_get_param_valid(self): - self.assertIsInstance(self.drs.get_param(26), float) - - def test_get_param_invalid(self): - val = self.drs.get_param(2999) - self.assertNotEqual(val, val) diff --git a/tests/integration/test_set.py b/tests/integration/test_set.py deleted file mode 100644 index 4d17213..0000000 --- a/tests/integration/test_set.py +++ /dev/null @@ -1,32 +0,0 @@ -import json -from unittest import TestCase - -from pydrs import pydrs -from pydrs.validation import SerialInvalidCmd - - -class TestSet(TestCase): - def setUp(self): - with open("secrets.json") as f: - self.secret = json.loads(f.read()) - - self.drs = pydrs.EthDRS(self.secret["ip"], self.secret["port"]) - - def test_set_slowref(self): - self.drs.set_slowref(100) - - def test_set_slowref_fbp(self): - self.drs.set_slowref_fbp(100) - - def test_set_slowref_readback_mon(self): - self.assertAlmostEqual(0, self.drs.set_slowref_readback_mon(100), 3) - - def test_set_slowref_readback_ref(self): - self.assertAlmostEqual(0, self.drs.set_slowref_readback_ref(100), 3) - - def test_invalid_password(self): - with self.assertRaises(SerialInvalidCmd): - self.drs.unlock_udc(0xDEAD) - - def test_valid_password(self): - self.drs.unlock_udc(self.secret["password"])