From ddcc8c9348a4bcbef43b46c0cee86cb971132b20 Mon Sep 17 00:00:00 2001 From: samson0v Date: Tue, 16 Jan 2024 12:54:04 +0200 Subject: [PATCH 1/4] Added blackbox tests for modbus --- tests/blackbox/__init__.py | 0 tests/blackbox/connectors/__init__.py | 0 tests/blackbox/connectors/modbus/__init__.py | 0 .../modbus/test_modbus_uplink_messages.py | 229 ++++++++++++++++++ ...plink_converter_only_on_change_config.json | 127 ++++++++++ ...uplink_converter_coils_reading_little.json | 0 ...rter_holding_registers_reading_little.json | 0 ...verter_input_registers_reading_little.json | 124 ++++++++++ .../discrete_and_coils_registers_values.json | 3 + .../test_values/holding_registers_values.json | 13 + .../test_values/input_registers_values.json | 14 ++ 11 files changed, 510 insertions(+) create mode 100644 tests/blackbox/__init__.py create mode 100644 tests/blackbox/connectors/__init__.py create mode 100644 tests/blackbox/connectors/modbus/__init__.py create mode 100644 tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py create mode 100644 tests/blackbox/data/configs/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/input_registers_values.json diff --git a/tests/blackbox/__init__.py b/tests/blackbox/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/blackbox/connectors/__init__.py b/tests/blackbox/connectors/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/blackbox/connectors/modbus/__init__.py b/tests/blackbox/connectors/modbus/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py b/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py new file mode 100644 index 000000000..5f9210f11 --- /dev/null +++ b/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py @@ -0,0 +1,229 @@ +import unittest +from os import path + +from simplejson import load + +from tb_rest_client.rest_client_ce import * + +TB_URL_CE = 'http://0.0.0.0:8080' + +TB_TENANT_USERNAME_CE = 'tenant@thingsboard.org' +TB_TENANT_PASSWORD_CE = 'tenant' + + +class ModbusUplinkMessagesTest(unittest.TestCase): + CONFIG_PATH = path.join(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))), + "data" + path.sep + "configs" + path.sep + "modbus" + path.sep) + + client = None + gateway = None + device = None + + @classmethod + def setUpClass(cls) -> None: + # ThingsBoard REST API URL + url = TB_URL_CE + + # Default Tenant Administrator credentials + username = TB_TENANT_USERNAME_CE + password = TB_TENANT_PASSWORD_CE + + with RestClientCE(url) as cls.client: + cls.client.login(username, password) + # assert cls.client.token is not None + + cls.gateway = cls.client.get_tenant_devices(10, 0, text_search='Gateway').data[0] + assert cls.gateway is not None + + cls.device = cls.client.get_tenant_devices(10, 0, text_search='Temp Sensor').data[0] + assert cls.device is not None + + @classmethod + def load_configuration(cls, config_file_path): + with open(config_file_path, 'r', encoding="UTF-8") as config: + config = load(config) + return config + + @classmethod + def change_connector_configuration(cls, config_file_path): + """ + Change the configuration of the connector. + + Args: + config_file_path (str): The path to the configuration file. + + Returns: + tuple: A tuple containing the modified configuration and the response of the save_device_attributes method. + """ + + config = cls.load_configuration(config_file_path) + config['Modbus']['ts'] = int(time() * 1000) + response = cls.client.save_device_attributes(cls.gateway.id, 'SHARED_SCOPE', config) + sleep(2) + return config, response + + def test_gateway_connection(self): + """ + Test the gateway connection by asserting that the value returned by + `get_attributes_by_scope` is `True`. + + Returns: + None + """ + + self.assertEqual(self.client.get_attributes_by_scope(self.gateway.id, 'SERVER_SCOPE', 'active')[0]['value'], + True) + + def test_send_only_on_data_changed(self): + """ + Test the send_only_on_data_changed method. + + This method tests the behavior of the send_only_on_data_changed method in the MyClass class. + The method performs the following steps: + 1. Changes the connector configuration using the change_connector_configuration method with + the specified configuration file. + 2. Retrieves the telemetry keys from the modified configuration. + 3. Retrieves the latest timeseries data for the device. + 4. Pauses the execution for 5 seconds. + 5. Retrieves the latest timeseries data for the device again. + 6. Compares the timestamps of the two sets of timeseries data for each telemetry key. + + Parameters: + - self: The instance of the ModbusUplinkMessagesTest class. + + Returns: + None. + """ + + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/initial_modbus_uplink_converter_only_on_change_config.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + sleep(5) + latest_ts_1 = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + + # check that timestamps are equal + for ts_key in telemetry_keys: + self.assertEqual(latest_ts[ts_key][0]['ts'], latest_ts_1[ts_key][0]['ts'], + f'Timestamps are not equal for the next telemetry key: {ts_key}') + + def test_input_register_reading_little_endian(self): + """ + Test the input register reading in little endian format. + + This function tests the reading of input registers in little endian format. It performs the following steps: + + 1. Changes the connector configuration by loading the JSON file located at + 'data/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json'. + 2. Retrieves the telemetry keys from the configuration. + 3. Waits for 2 seconds. + 4. Retrieves the latest timeseries data for the specified telemetry keys. + 5. Loads the expected values for the input registers from the JSON file located at + 'data/modbus/test_values/input_registers_values.json'. + 6. Compares the expected values with the actual values obtained from the timeseries data. + + Parameters: + self (ModbusUplinkMessagesTest): The object instance. + + Returns: + None + """ + + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/modbus_uplink_converter_input_registers_reading_little.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration(self.CONFIG_PATH + 'test_values/input_registers_values.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') + + def test_holding_register_reading_little_endian(self): + """ + Test the reading of holding registers in little-endian format. + + This function is responsible for testing the reading of holding registers in + little-endian format. It performs the following steps: + + 1. Changes the connector configuration using the specified JSON file. + 2. Retrieves the telemetry keys from the configuration. + 3. Waits for 2 seconds. + 4. Retrieves the latest timeseries data for the device using the retrieved telemetry keys. + 5. Loads the expected values from the specified JSON file. + 6. Compares the expected values with the retrieved timeseries data. + + Parameters: + self (ModbusUplinkMessagesTest): The object instance. + + Returns: + None + """ + + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'modbus_uplink_converter_holding_registers_reading_little.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration(self.CONFIG_PATH + 'test_values/holding_registers_values.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') + + def test_coils_reading_little_endian(self): + """ + Test the function test_coils_reading_little_endian. + + This function is responsible for testing the functionality of the + test_coils_reading_little_endian method. It performs the following steps: + + 1. Changes the connector configuration. + 2. Retrieves telemetry keys. + 3. Waits for 2 seconds. + 4. Gets the latest timeseries. + 5. Loads the test values. + 6. Compares the values with the latest timeseries. + + Parameters: + - self: The object instance. + + Returns: + - None + """ + + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'modbus_uplink_converter_coils_reading_little.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration( + self.CONFIG_PATH + 'test_values/discrete_and_coils_registers_values.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') + + def test_discrete_input_reading_little_endian(self): + pass + + def test_coils_reading_big_endian(self): + pass + + def test_discrete_input_reading_big_endian(self): + pass + + def test_input_register_reading_big_endian(self): + pass + + def test_holding_register_reading_big_endian(self): + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/blackbox/data/configs/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json b/tests/blackbox/data/configs/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json new file mode 100644 index 000000000..cc5ebd7fd --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json @@ -0,0 +1,127 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "host.docker.internal", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "LITTLE", + "wordOrder": "LITTLE", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 1000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": true, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [ + { + "tag": "string_read", + "type": "string", + "functionCode": 4, + "objectsCount": 4, + "address": 1 + }, + { + "tag": "bits_read", + "type": "bits", + "functionCode": 4, + "objectsCount": 1, + "address": 5 + }, + { + "tag": "8int_read", + "type": "8int", + "functionCode": 4, + "objectsCount": 1, + "address": 6 + }, + { + "tag": "16int_read", + "type": "16int", + "functionCode": 4, + "objectsCount": 1, + "address": 7 + }, + { + "tag": "32int_read_divider", + "type": "32int", + "functionCode": 4, + "objectsCount": 2, + "address": 8, + "divider": 10 + }, + { + "tag": "8int_read_multiplier", + "type": "8int", + "functionCode": 4, + "objectsCount": 1, + "address": 10, + "multiplier": 10 + }, + { + "tag": "32int_read", + "type": "32int", + "functionCode": 4, + "objectsCount": 2, + "address": 11 + }, + { + "tag": "64int_read", + "type": "64int", + "functionCode": 4, + "objectsCount": 4, + "address": 13 + } + ], + "timeseries": [ + { + "tag": "8uint_read", + "type": "8uint", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "16uint_read", + "type": "16uint", + "functionCode": 4, + "objectsCount": 2, + "address": 18 + }, + { + "tag": "32uint_read", + "type": "32uint", + "functionCode": 4, + "objectsCount": 4, + "address": 20 + }, + { + "tag": "16float_read", + "type": "16float", + "functionCode": 4, + "objectsCount": 1, + "address": 25 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json new file mode 100644 index 000000000..e69de29bb diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json new file mode 100644 index 000000000..e69de29bb diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json new file mode 100644 index 000000000..8410e5ecd --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json @@ -0,0 +1,124 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "host.docker.internal", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "LITTLE", + "wordOrder": "LITTLE", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 1000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": true, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "string", + "type": "string", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "bytes", + "type": "bytes", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "bits", + "type": "bits", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "16uint", + "type": "16uint", + "functionCode": 4, + "objectsCount": 2, + "address": 18 + }, + { + "tag": "16int", + "type": "16int", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "16float", + "type": "16float", + "functionCode": 4, + "objectsCount": 1, + "address": 25 + }, + { + "tag": "32uint", + "type": "32uint", + "functionCode": 4, + "objectsCount": 4, + "address": 20 + }, + { + "tag": "32int", + "type": "32int", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "32float", + "type": "32float", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "64int", + "type": "64int", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "64uint", + "type": "64uint", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + }, + { + "tag": "64float", + "type": "64float", + "functionCode": 4, + "objectsCount": 1, + "address": 17 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json new file mode 100644 index 000000000..d311fba95 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json @@ -0,0 +1,3 @@ +{ + "bits": "" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json new file mode 100644 index 000000000..d7e671b79 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json @@ -0,0 +1,13 @@ +{ + "string": "", + "bytes": "", + "16int": "", + "16uint": "", + "16float": "", + "32int": "", + "32uint": "", + "32float": "", + "64int": "", + "64uint": "", + "64float": "" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/input_registers_values.json b/tests/blackbox/data/configs/modbus/test_values/input_registers_values.json new file mode 100644 index 000000000..9a2431cb8 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/input_registers_values.json @@ -0,0 +1,14 @@ +{ + "string": "", + "bytes": "", + "bits": "", + "16int": "", + "16uint": "", + "16float": "", + "32int": "", + "32uint": "", + "32float": "", + "64int": "", + "64uint": "", + "64float": "" +} \ No newline at end of file From ca35e8b2046c4f1995f298f115104661650f8d9e Mon Sep 17 00:00:00 2001 From: samson0v Date: Wed, 17 Jan 2024 14:03:25 +0200 Subject: [PATCH 2/4] Added blackbox tests for modbus connector uplink messaging --- .../modbus/test_modbus_uplink_messages.py | 81 ++++++++++-- ...us_uplink_converter_coils_reading_big.json | 54 ++++++++ ...uplink_converter_coils_reading_little.json | 54 ++++++++ ..._converter_discrete_input_reading_big.json | 54 ++++++++ ...nverter_discrete_input_reading_little.json | 54 ++++++++ ...nverter_holding_registers_reading_big.json | 124 ++++++++++++++++++ ...rter_holding_registers_reading_little.json | 124 ++++++++++++++++++ ...converter_input_registers_reading_big.json | 124 ++++++++++++++++++ ...verter_input_registers_reading_little.json | 74 +++++------ .../discrete_and_coils_registers_values.json | 3 - ...screte_and_coils_registers_values_big.json | 4 + ...ete_and_coils_registers_values_little.json | 4 + .../test_values/holding_registers_values.json | 13 -- .../holding_registers_values_big.json | 13 ++ .../holding_registers_values_little.json | 13 ++ .../test_values/input_registers_values.json | 14 -- .../input_registers_values_big.json | 13 ++ .../input_registers_values_little.json | 13 ++ 18 files changed, 753 insertions(+), 80 deletions(-) create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_big.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json create mode 100644 tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json delete mode 100644 tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_big.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_little.json delete mode 100644 tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/holding_registers_values_big.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/holding_registers_values_little.json delete mode 100644 tests/blackbox/data/configs/modbus/test_values/input_registers_values.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/input_registers_values_big.json create mode 100644 tests/blackbox/data/configs/modbus/test_values/input_registers_values_little.json diff --git a/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py b/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py index 5f9210f11..0e6b00adf 100644 --- a/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py +++ b/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py @@ -136,7 +136,7 @@ def test_input_register_reading_little_endian(self): slave['timeseries']] sleep(2) latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) - must_be_values = self.load_configuration(self.CONFIG_PATH + 'test_values/input_registers_values.json') + must_be_values = self.load_configuration(self.CONFIG_PATH + 'test_values/input_registers_values_little.json') for (_type, value) in must_be_values.items(): self.assertEqual(value, latest_ts[_type][0]['value'], @@ -164,12 +164,12 @@ def test_holding_register_reading_little_endian(self): """ (config, _) = self.change_connector_configuration( - self.CONFIG_PATH + 'modbus_uplink_converter_holding_registers_reading_little.json') + self.CONFIG_PATH + 'configs/modbus_uplink_converter_holding_registers_reading_little.json') telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in slave['timeseries']] sleep(2) latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) - must_be_values = self.load_configuration(self.CONFIG_PATH + 'test_values/holding_registers_values.json') + must_be_values = self.load_configuration(self.CONFIG_PATH + 'test_values/holding_registers_values_little.json') for (_type, value) in must_be_values.items(): self.assertEqual(value, latest_ts[_type][0]['value'], @@ -197,32 +197,87 @@ def test_coils_reading_little_endian(self): """ (config, _) = self.change_connector_configuration( - self.CONFIG_PATH + 'modbus_uplink_converter_coils_reading_little.json') + self.CONFIG_PATH + 'configs/modbus_uplink_converter_coils_reading_little.json') telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in slave['timeseries']] sleep(2) latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) must_be_values = self.load_configuration( - self.CONFIG_PATH + 'test_values/discrete_and_coils_registers_values.json') + self.CONFIG_PATH + 'test_values/discrete_and_coils_registers_values_little.json') for (_type, value) in must_be_values.items(): self.assertEqual(value, latest_ts[_type][0]['value'], f'Value is not equal for the next telemetry key: {_type}') def test_discrete_input_reading_little_endian(self): - pass - - def test_coils_reading_big_endian(self): - pass + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/modbus_uplink_converter_discrete_input_reading_little.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration( + self.CONFIG_PATH + 'test_values/discrete_and_coils_registers_values_little.json') - def test_discrete_input_reading_big_endian(self): - pass + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') def test_input_register_reading_big_endian(self): - pass + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/modbus_uplink_converter_input_registers_reading_big.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration( + self.CONFIG_PATH + 'test_values/input_registers_values_big.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') def test_holding_register_reading_big_endian(self): - pass + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/modbus_uplink_converter_holding_registers_reading_big.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration( + self.CONFIG_PATH + 'test_values/holding_registers_values_big.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') + + def test_coils_reading_big_endian(self): + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/modbus_uplink_converter_coils_reading_big.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration( + self.CONFIG_PATH + 'test_values/discrete_and_coils_registers_values_big.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') + + def test_discrete_input_reading_big_endian(self): + (config, _) = self.change_connector_configuration( + self.CONFIG_PATH + 'configs/modbus_uplink_converter_discrete_input_reading_big.json') + telemetry_keys = [key['tag'] for slave in config['Modbus']['configurationJson']['master']['slaves'] for key in + slave['timeseries']] + sleep(2) + latest_ts = self.client.get_latest_timeseries(self.device.id, ','.join(telemetry_keys)) + must_be_values = self.load_configuration( + self.CONFIG_PATH + 'test_values/discrete_and_coils_registers_values_big.json') + + for (_type, value) in must_be_values.items(): + self.assertEqual(value, latest_ts[_type][0]['value'], + f'Value is not equal for the next telemetry key: {_type}') if __name__ == '__main__': diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_big.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_big.json new file mode 100644 index 000000000..c27730673 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_big.json @@ -0,0 +1,54 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "BIG", + "wordOrder": "BIG", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "bits", + "type": "bits", + "functionCode": 1, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "bit", + "type": "bit", + "functionCode": 1, + "objectsCount": 1, + "address": 2 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json index e69de29bb..7888d9c43 100644 --- a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json @@ -0,0 +1,54 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "LITTLE", + "wordOrder": "LITTLE", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "bits", + "type": "bits", + "functionCode": 1, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "bit", + "type": "bit", + "functionCode": 1, + "objectsCount": 1, + "address": 2 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json new file mode 100644 index 000000000..3efcf6b04 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json @@ -0,0 +1,54 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "BIG", + "wordOrder": "BIG", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "bits", + "type": "bits", + "functionCode": 2, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "bit", + "type": "bit", + "functionCode": 2, + "objectsCount": 1, + "address": 2 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json new file mode 100644 index 000000000..4c95cf0b7 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json @@ -0,0 +1,54 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "LITTLE", + "wordOrder": "LITTLE", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "bits", + "type": "bits", + "functionCode": 2, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "bit", + "type": "bit", + "functionCode": 2, + "objectsCount": 1, + "address": 2 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json new file mode 100644 index 000000000..12a713952 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json @@ -0,0 +1,124 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "BIG", + "wordOrder": "BIG", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "string", + "type": "string", + "functionCode": 3, + "objectsCount": 2, + "address": 0 + }, + { + "tag": "bits", + "type": "bits", + "functionCode": 3, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "16int", + "type": "16int", + "functionCode": 3, + "objectsCount": 1, + "address": 4 + }, + { + "tag": "16uint", + "type": "16uint", + "functionCode": 3, + "objectsCount": 1, + "address": 5 + }, + { + "tag": "32int", + "type": "32int", + "functionCode": 3, + "objectsCount": 2, + "address": 6 + }, + { + "tag": "32uint", + "type": "32uint", + "functionCode": 3, + "objectsCount": 2, + "address": 8 + }, + { + "tag": "16float", + "type": "16float", + "functionCode": 3, + "objectsCount": 1, + "address": 10 + }, + { + "tag": "32float", + "type": "32float", + "functionCode": 3, + "objectsCount": 2, + "address": 11 + }, + { + "tag": "-32float", + "type": "32float", + "functionCode": 3, + "objectsCount": 2, + "address": 13 + }, + { + "tag": "64int", + "type": "64int", + "functionCode": 3, + "objectsCount": 4, + "address": 15 + }, + { + "tag": "64uint", + "type": "64uint", + "functionCode": 3, + "objectsCount": 4, + "address": 19 + }, + { + "tag": "64float", + "type": "64float", + "functionCode": 3, + "objectsCount": 4, + "address": 27 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json index e69de29bb..a5257ca76 100644 --- a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json @@ -0,0 +1,124 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "LITTLE", + "wordOrder": "LITTLE", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "string", + "type": "string", + "functionCode": 3, + "objectsCount": 2, + "address": 0 + }, + { + "tag": "bits", + "type": "bits", + "functionCode": 3, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "16int", + "type": "16int", + "functionCode": 3, + "objectsCount": 1, + "address": 4 + }, + { + "tag": "16uint", + "type": "16uint", + "functionCode": 3, + "objectsCount": 1, + "address": 5 + }, + { + "tag": "32int", + "type": "32int", + "functionCode": 3, + "objectsCount": 2, + "address": 6 + }, + { + "tag": "32uint", + "type": "32uint", + "functionCode": 3, + "objectsCount": 2, + "address": 8 + }, + { + "tag": "16float", + "type": "16float", + "functionCode": 3, + "objectsCount": 1, + "address": 10 + }, + { + "tag": "32float", + "type": "32float", + "functionCode": 3, + "objectsCount": 2, + "address": 11 + }, + { + "tag": "-32float", + "type": "32float", + "functionCode": 3, + "objectsCount": 2, + "address": 13 + }, + { + "tag": "64int", + "type": "64int", + "functionCode": 3, + "objectsCount": 4, + "address": 15 + }, + { + "tag": "64uint", + "type": "64uint", + "functionCode": 3, + "objectsCount": 4, + "address": 19 + }, + { + "tag": "64float", + "type": "64float", + "functionCode": 3, + "objectsCount": 4, + "address": 27 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json new file mode 100644 index 000000000..f2337b7ff --- /dev/null +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json @@ -0,0 +1,124 @@ +{ + "Modbus": { + "name": "Modbus", + "type": "modbus", + "logLevel": "DEBUG", + "configuration": "modbus.json", + "configurationJson": { + "name": "Modbus", + "logLevel": "DEBUG", + "master": { + "slaves": [ + { + "host": "0.0.0.0", + "port": 5021, + "type": "tcp", + "method": "socket", + "timeout": 35, + "byteOrder": "BIG", + "wordOrder": "BIG", + "retries": true, + "retryOnEmpty": true, + "retryOnInvalid": true, + "pollPeriod": 2000, + "unitId": 1, + "deviceName": "Temp Sensor", + "sendDataOnlyOnChange": false, + "connectAttemptTimeMs": 5000, + "connectAttemptCount": 5, + "waitAfterFailedAttemptsMs": 300000, + "attributes": [], + "timeseries": [ + { + "tag": "string", + "type": "string", + "functionCode": 4, + "objectsCount": 2, + "address": 0 + }, + { + "tag": "bits", + "type": "bits", + "functionCode": 4, + "objectsCount": 16, + "address": 2 + }, + { + "tag": "16int", + "type": "16int", + "functionCode": 4, + "objectsCount": 1, + "address": 4 + }, + { + "tag": "16uint", + "type": "16uint", + "functionCode": 4, + "objectsCount": 1, + "address": 5 + }, + { + "tag": "32int", + "type": "32int", + "functionCode": 4, + "objectsCount": 2, + "address": 6 + }, + { + "tag": "32uint", + "type": "32uint", + "functionCode": 4, + "objectsCount": 2, + "address": 8 + }, + { + "tag": "16float", + "type": "16float", + "functionCode": 4, + "objectsCount": 1, + "address": 10 + }, + { + "tag": "32float", + "type": "32float", + "functionCode": 4, + "objectsCount": 2, + "address": 11 + }, + { + "tag": "-32float", + "type": "32float", + "functionCode": 4, + "objectsCount": 2, + "address": 13 + }, + { + "tag": "64int", + "type": "64int", + "functionCode": 4, + "objectsCount": 4, + "address": 15 + }, + { + "tag": "64uint", + "type": "64uint", + "functionCode": 4, + "objectsCount": 4, + "address": 19 + }, + { + "tag": "64float", + "type": "64float", + "functionCode": 4, + "objectsCount": 4, + "address": 27 + } + ], + "attributeUpdates": [], + "rpc": [] + } + ] + } + } + } +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json index 8410e5ecd..013aa532e 100644 --- a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json +++ b/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json @@ -10,7 +10,7 @@ "master": { "slaves": [ { - "host": "host.docker.internal", + "host": "0.0.0.0", "port": 5021, "type": "tcp", "method": "socket", @@ -20,10 +20,10 @@ "retries": true, "retryOnEmpty": true, "retryOnInvalid": true, - "pollPeriod": 1000, + "pollPeriod": 2000, "unitId": 1, "deviceName": "Temp Sensor", - "sendDataOnlyOnChange": true, + "sendDataOnlyOnChange": false, "connectAttemptTimeMs": 5000, "connectAttemptCount": 5, "waitAfterFailedAttemptsMs": 300000, @@ -33,85 +33,85 @@ "tag": "string", "type": "string", "functionCode": 4, - "objectsCount": 1, - "address": 17 + "objectsCount": 2, + "address": 0 }, { - "tag": "bytes", - "type": "bytes", + "tag": "bits", + "type": "bits", "functionCode": 4, - "objectsCount": 1, - "address": 17 + "objectsCount": 16, + "address": 2 }, { - "tag": "bits", - "type": "bits", + "tag": "16int", + "type": "16int", "functionCode": 4, "objectsCount": 1, - "address": 17 + "address": 4 }, { "tag": "16uint", "type": "16uint", "functionCode": 4, - "objectsCount": 2, - "address": 18 - }, - { - "tag": "16int", - "type": "16int", - "functionCode": 4, "objectsCount": 1, - "address": 17 + "address": 5 }, { - "tag": "16float", - "type": "16float", + "tag": "32int", + "type": "32int", "functionCode": 4, - "objectsCount": 1, - "address": 25 + "objectsCount": 2, + "address": 6 }, { "tag": "32uint", "type": "32uint", "functionCode": 4, - "objectsCount": 4, - "address": 20 + "objectsCount": 2, + "address": 8 }, { - "tag": "32int", - "type": "32int", + "tag": "16float", + "type": "16float", "functionCode": 4, "objectsCount": 1, - "address": 17 + "address": 10 }, { "tag": "32float", "type": "32float", "functionCode": 4, - "objectsCount": 1, - "address": 17 + "objectsCount": 2, + "address": 11 + }, + { + "tag": "-32float", + "type": "32float", + "functionCode": 4, + "objectsCount": 2, + "address": 13 }, { "tag": "64int", "type": "64int", "functionCode": 4, - "objectsCount": 1, - "address": 17 + "objectsCount": 4, + "address": 15 }, { "tag": "64uint", "type": "64uint", "functionCode": 4, - "objectsCount": 1, - "address": 17 + "objectsCount": 4, + "address": 19 }, { "tag": "64float", "type": "64float", "functionCode": 4, - "objectsCount": 1, - "address": 17 + "objectsCount": 4, + "address": 27 } ], "attributeUpdates": [], diff --git a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json deleted file mode 100644 index d311fba95..000000000 --- a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "bits": "" -} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_big.json b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_big.json new file mode 100644 index 000000000..cebb77a6c --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_big.json @@ -0,0 +1,4 @@ +{ + "bits": "[true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]", + "bit": "true" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_little.json b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_little.json new file mode 100644 index 000000000..cebb77a6c --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_little.json @@ -0,0 +1,4 @@ +{ + "bits": "[true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]", + "bit": "true" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json deleted file mode 100644 index d7e671b79..000000000 --- a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "string": "", - "bytes": "", - "16int": "", - "16uint": "", - "16float": "", - "32int": "", - "32uint": "", - "32float": "", - "64int": "", - "64uint": "", - "64float": "" -} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_big.json b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_big.json new file mode 100644 index 000000000..b15148bda --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_big.json @@ -0,0 +1,13 @@ +{ + "string": "abcd", + "bits": "[false,true,false,true,true,false,true,true,true,true,false,true,false,false,true,false]", + "16int": "-30551", + "16uint": "13330", + "16float": "0.0670166015625", + "32int": "-856817665", + "32uint": "2018915346", + "32float": "-0.00000000000000000000000016669035218533905", + "64int": "1243365278113333247", + "64uint": "17275436391653061650", + "64float": "-6065988000872354500000000000000000000000000000000000000000000000000" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_little.json b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_little.json new file mode 100644 index 000000000..637633ac9 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_little.json @@ -0,0 +1,13 @@ +{ + "string": "abcd", + "bits": "[false,true,false,true,true,false,true,true,true,true,false,true,false,false,true,false]", + "16int": "-22136", + "16uint": "4660", + "16float": "12.34375", + "32int": "-4660", + "32uint": "305419896", + "32float": "223546.34375", + "64int": "-3735928559", + "64uint": "1311768468603649775", + "64float": "123.45" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/input_registers_values.json b/tests/blackbox/data/configs/modbus/test_values/input_registers_values.json deleted file mode 100644 index 9a2431cb8..000000000 --- a/tests/blackbox/data/configs/modbus/test_values/input_registers_values.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "string": "", - "bytes": "", - "bits": "", - "16int": "", - "16uint": "", - "16float": "", - "32int": "", - "32uint": "", - "32float": "", - "64int": "", - "64uint": "", - "64float": "" -} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/input_registers_values_big.json b/tests/blackbox/data/configs/modbus/test_values/input_registers_values_big.json new file mode 100644 index 000000000..b15148bda --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/input_registers_values_big.json @@ -0,0 +1,13 @@ +{ + "string": "abcd", + "bits": "[false,true,false,true,true,false,true,true,true,true,false,true,false,false,true,false]", + "16int": "-30551", + "16uint": "13330", + "16float": "0.0670166015625", + "32int": "-856817665", + "32uint": "2018915346", + "32float": "-0.00000000000000000000000016669035218533905", + "64int": "1243365278113333247", + "64uint": "17275436391653061650", + "64float": "-6065988000872354500000000000000000000000000000000000000000000000000" +} \ No newline at end of file diff --git a/tests/blackbox/data/configs/modbus/test_values/input_registers_values_little.json b/tests/blackbox/data/configs/modbus/test_values/input_registers_values_little.json new file mode 100644 index 000000000..637633ac9 --- /dev/null +++ b/tests/blackbox/data/configs/modbus/test_values/input_registers_values_little.json @@ -0,0 +1,13 @@ +{ + "string": "abcd", + "bits": "[false,true,false,true,true,false,true,true,true,true,false,true,false,false,true,false]", + "16int": "-22136", + "16uint": "4660", + "16float": "12.34375", + "32int": "-4660", + "32uint": "305419896", + "32float": "223546.34375", + "64int": "-3735928559", + "64uint": "1311768468603649775", + "64float": "123.45" +} \ No newline at end of file From c10ecedf5bd09223e355632fe7cf73d7d933db0f Mon Sep 17 00:00:00 2001 From: samson0v Date: Wed, 17 Jan 2024 14:03:59 +0200 Subject: [PATCH 3/4] Fixed modbus uplink converter --- .../connectors/modbus/bytes_modbus_uplink_converter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/thingsboard_gateway/connectors/modbus/bytes_modbus_uplink_converter.py b/thingsboard_gateway/connectors/modbus/bytes_modbus_uplink_converter.py index 3f6b931d2..4b500b108 100644 --- a/thingsboard_gateway/connectors/modbus/bytes_modbus_uplink_converter.py +++ b/thingsboard_gateway/connectors/modbus/bytes_modbus_uplink_converter.py @@ -37,9 +37,9 @@ def from_coils(coils, endian_order=Endian.Little, word_endian_order=Endian.Big): if _is_wordorder: try: decoder = BinaryPayloadDecoder.fromCoils(coils, byteorder=endian_order, - _wordorder=word_endian_order) + wordorder=word_endian_order) except TypeError: - decoder = BinaryPayloadDecoder.fromCoils(coils, _wordorder=word_endian_order) + decoder = BinaryPayloadDecoder.fromCoils(coils, wordorder=word_endian_order) else: try: decoder = BinaryPayloadDecoder.fromCoils(coils, byteorder=endian_order, @@ -144,8 +144,8 @@ def decode_from_registers(self, decoder, configuration): decoded = None if lower_type in ['bit', 'bits']: - decoded_lastbyte = decoder_functions[type_]() decoded = decoder_functions[type_]() + decoded_lastbyte = decoder_functions[type_]() decoded += decoded_lastbyte decoded = decoded[len(decoded)-objects_count:] From e30f2518f2ad840cf68b2956e9efbf5ea16e9c3a Mon Sep 17 00:00:00 2001 From: samson0v Date: Wed, 17 Jan 2024 14:36:23 +0200 Subject: [PATCH 4/4] Updated data files structure for blackbox tests --- tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py | 2 +- .../initial_modbus_uplink_converter_only_on_change_config.json | 0 .../configs/modbus_uplink_converter_coils_reading_big.json | 0 .../configs/modbus_uplink_converter_coils_reading_little.json | 0 .../modbus_uplink_converter_discrete_input_reading_big.json | 0 .../modbus_uplink_converter_discrete_input_reading_little.json | 0 .../modbus_uplink_converter_holding_registers_reading_big.json | 0 ...odbus_uplink_converter_holding_registers_reading_little.json | 0 .../modbus_uplink_converter_input_registers_reading_big.json | 0 .../modbus_uplink_converter_input_registers_reading_little.json | 0 .../test_values/discrete_and_coils_registers_values_big.json | 0 .../test_values/discrete_and_coils_registers_values_little.json | 0 .../modbus/test_values/holding_registers_values_big.json | 0 .../modbus/test_values/holding_registers_values_little.json | 0 .../modbus/test_values/input_registers_values_big.json | 0 .../modbus/test_values/input_registers_values_little.json | 0 16 files changed, 1 insertion(+), 1 deletion(-) rename tests/blackbox/data/{configs => }/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_coils_reading_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_coils_reading_little.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json (100%) rename tests/blackbox/data/{configs => }/modbus/test_values/discrete_and_coils_registers_values_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/test_values/discrete_and_coils_registers_values_little.json (100%) rename tests/blackbox/data/{configs => }/modbus/test_values/holding_registers_values_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/test_values/holding_registers_values_little.json (100%) rename tests/blackbox/data/{configs => }/modbus/test_values/input_registers_values_big.json (100%) rename tests/blackbox/data/{configs => }/modbus/test_values/input_registers_values_little.json (100%) diff --git a/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py b/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py index 0e6b00adf..e364e034c 100644 --- a/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py +++ b/tests/blackbox/connectors/modbus/test_modbus_uplink_messages.py @@ -13,7 +13,7 @@ class ModbusUplinkMessagesTest(unittest.TestCase): CONFIG_PATH = path.join(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))), - "data" + path.sep + "configs" + path.sep + "modbus" + path.sep) + "data" + path.sep + "modbus" + path.sep) client = None gateway = None diff --git a/tests/blackbox/data/configs/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json b/tests/blackbox/data/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json rename to tests/blackbox/data/modbus/configs/initial_modbus_uplink_converter_only_on_change_config.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_big.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_coils_reading_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_big.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_coils_reading_big.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_coils_reading_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_coils_reading_little.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_coils_reading_little.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_discrete_input_reading_big.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_discrete_input_reading_little.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_holding_registers_reading_big.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_holding_registers_reading_little.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_input_registers_reading_big.json diff --git a/tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json b/tests/blackbox/data/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json rename to tests/blackbox/data/modbus/configs/modbus_uplink_converter_input_registers_reading_little.json diff --git a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_big.json b/tests/blackbox/data/modbus/test_values/discrete_and_coils_registers_values_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_big.json rename to tests/blackbox/data/modbus/test_values/discrete_and_coils_registers_values_big.json diff --git a/tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_little.json b/tests/blackbox/data/modbus/test_values/discrete_and_coils_registers_values_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/test_values/discrete_and_coils_registers_values_little.json rename to tests/blackbox/data/modbus/test_values/discrete_and_coils_registers_values_little.json diff --git a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_big.json b/tests/blackbox/data/modbus/test_values/holding_registers_values_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/test_values/holding_registers_values_big.json rename to tests/blackbox/data/modbus/test_values/holding_registers_values_big.json diff --git a/tests/blackbox/data/configs/modbus/test_values/holding_registers_values_little.json b/tests/blackbox/data/modbus/test_values/holding_registers_values_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/test_values/holding_registers_values_little.json rename to tests/blackbox/data/modbus/test_values/holding_registers_values_little.json diff --git a/tests/blackbox/data/configs/modbus/test_values/input_registers_values_big.json b/tests/blackbox/data/modbus/test_values/input_registers_values_big.json similarity index 100% rename from tests/blackbox/data/configs/modbus/test_values/input_registers_values_big.json rename to tests/blackbox/data/modbus/test_values/input_registers_values_big.json diff --git a/tests/blackbox/data/configs/modbus/test_values/input_registers_values_little.json b/tests/blackbox/data/modbus/test_values/input_registers_values_little.json similarity index 100% rename from tests/blackbox/data/configs/modbus/test_values/input_registers_values_little.json rename to tests/blackbox/data/modbus/test_values/input_registers_values_little.json