plantstar-shared 2.0.3.0.2.9__tar.gz → 2.0.3.0.2.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/PKG-INFO +1 -1
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/api_types.py +0 -7
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/convert_bytes_to_object.py +1 -1
- plantstar-shared-2.0.3.0.2.10/plantstar_shared/tcp_socket_utils.py +112 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared.egg-info/PKG-INFO +1 -1
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared.egg-info/SOURCES.txt +0 -1
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/setup.py +1 -1
- plantstar-shared-2.0.3.0.2.9/plantstar_shared/HmiKeyConstants.py +0 -9
- plantstar-shared-2.0.3.0.2.9/plantstar_shared/tcp_socket_utils.py +0 -68
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/README.md +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/DataCollectionModuleProcessNames.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/HuskyInterfacePacketTypes.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/MockRawDataProcessor.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/RawDataProcessorInterfaceActions.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/SysconType.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/__init__.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/add_size_onto_string_and_return.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/convert_object_to_bytes.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/errors.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/global_definitions.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/is_valid_signed_string.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/obtain_raw_data_processor_function_for_action_name.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/syscon_image_field.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/syscon_json.py +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared.egg-info/dependency_links.txt +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared.egg-info/requires.txt +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared.egg-info/top_level.txt +0 -0
- {plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/setup.cfg +0 -0
{plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/api_types.py
RENAMED
@@ -101,10 +101,3 @@ class ApuApiTypes(SysconType):
|
|
101
101
|
|
102
102
|
class CosmosApiTypes(SysconType):
|
103
103
|
SEND_DATA_DICTIONARY = ("send_data_dictionary", "send_data_dictionary", True)
|
104
|
-
|
105
|
-
|
106
|
-
class HmiApiTypes(SysconType):
|
107
|
-
GET_HMI_SYSTEM_INFORMATION = ("get_hmi_system_information", "get_hmi_system_information", True)
|
108
|
-
SET_HMI_SYSTEM_INFORMATION = ("set_hmi_system_information", "set_hmi_system_information", True)
|
109
|
-
REBOOT_HMI = ("reboot_hmi", "reboot_hmi", True)
|
110
|
-
|
@@ -2,9 +2,9 @@ import msgpack
|
|
2
2
|
|
3
3
|
from plantstar_shared.errors import SocketConnectionError
|
4
4
|
|
5
|
+
|
5
6
|
# Converts bytes into an object using msgpack, with a parameter for strict_map_key
|
6
7
|
def convert_bytes_to_object(object_as_bytes, strict_map_key=False):
|
7
|
-
|
8
8
|
if not object_as_bytes:
|
9
9
|
raise SocketConnectionError
|
10
10
|
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import struct
|
2
|
+
|
3
|
+
from plantstar_shared.convert_bytes_to_object import convert_bytes_to_object
|
4
|
+
from plantstar_shared.convert_object_to_bytes import convert_object_to_bytes
|
5
|
+
from plantstar_shared.errors import SocketConnectionError, SysconProgrammingError
|
6
|
+
|
7
|
+
SIZE_OF_UNSIGNED_INT_STRUCT = 4 # size of integer value that precedes data coming from DCM
|
8
|
+
|
9
|
+
|
10
|
+
def read_size_value_from_socket(*, remote_socket, is_big_endian, number_of_bytes_for_size_prefix):
|
11
|
+
size_bytes = remote_socket.recv(number_of_bytes_for_size_prefix)
|
12
|
+
|
13
|
+
if not size_bytes:
|
14
|
+
return None
|
15
|
+
|
16
|
+
if number_of_bytes_for_size_prefix == 2:
|
17
|
+
message_length = int.from_bytes(size_bytes, 'big') if is_big_endian else int.from_bytes(size_bytes, 'little')
|
18
|
+
elif number_of_bytes_for_size_prefix == SIZE_OF_UNSIGNED_INT_STRUCT:
|
19
|
+
number_format = ">I" if is_big_endian else "<I"
|
20
|
+
|
21
|
+
try:
|
22
|
+
message_length = struct.unpack(number_format, size_bytes)[0]
|
23
|
+
except struct.error as error:
|
24
|
+
raise SocketConnectionError
|
25
|
+
else:
|
26
|
+
raise SysconProgrammingError("A size prefix was set to something other than 2 or 4")
|
27
|
+
|
28
|
+
return message_length
|
29
|
+
|
30
|
+
|
31
|
+
def get_bytes_from_socket(*, remote_socket, number_of_bytes_to_read=None, is_big_endian=True, number_of_bytes_for_size_prefix=0, should_remove_prefix_size_from_read=False):
|
32
|
+
"""Obtains a number of bytes from a provided socket, with options for different configurations and situations
|
33
|
+
|
34
|
+
Keywords / Example Configurations:
|
35
|
+
remote_socket -- the connection that bytes will be read from
|
36
|
+
|
37
|
+
number_of_bytes_to_read -- the number of bytes to read on the socket, if this is known, this is the only optional parameter needed (default: 0)
|
38
|
+
|
39
|
+
is_big_endian -- bool that determines what format string should be used for unpacking the size value (default: True)
|
40
|
+
|
41
|
+
number_of_bytes_for_size_prefix -- the number of bytes to read to determine the total size of the message to pass (default: 0)
|
42
|
+
|
43
|
+
should_remove_prefix_size_from_read -- bool that determines if the size should be removed from the calculated number of bytes to read (default: False)
|
44
|
+
|
45
|
+
-----
|
46
|
+
|
47
|
+
get_bytes_from_socket(remote_socket=conn, number_of_bytes_to_read=100) - likely would not be called directly, in most cases
|
48
|
+
|
49
|
+
get_bytes_from_socket(remote_socket=conn, is_big_endian=True, number_of_bytes_for_size_prefix=4) - reads 4 bytes to get the size, then reads that amount (DCM socket, etc)
|
50
|
+
|
51
|
+
get_bytes_from_socket(remote_socket=conn, is_big_endian=False, number_of_bytes_for_size_prefix=2, should_remove_prefix_size_from_read=True) - reads 2 bytes to get the size,
|
52
|
+
then reads that calculated amount minus 2 (Husky socket, etc)
|
53
|
+
|
54
|
+
"""
|
55
|
+
|
56
|
+
if not number_of_bytes_to_read:
|
57
|
+
if number_of_bytes_for_size_prefix:
|
58
|
+
number_of_bytes_to_read = read_size_value_from_socket(
|
59
|
+
remote_socket=remote_socket, is_big_endian=is_big_endian, number_of_bytes_for_size_prefix=number_of_bytes_for_size_prefix
|
60
|
+
)
|
61
|
+
|
62
|
+
if not number_of_bytes_to_read:
|
63
|
+
raise SysconProgrammingError("get_bytes_from_socket was called with no parameters for number_of_bytes_to_read or number_of_bytes_for_size_prefix")
|
64
|
+
|
65
|
+
if should_remove_prefix_size_from_read:
|
66
|
+
number_of_bytes_to_read = number_of_bytes_to_read - number_of_bytes_for_size_prefix
|
67
|
+
|
68
|
+
packets = []
|
69
|
+
bytes_received = 0
|
70
|
+
|
71
|
+
# While loop that will stream in data if the full request is not available yet
|
72
|
+
while bytes_received < number_of_bytes_to_read:
|
73
|
+
buffer_size = number_of_bytes_to_read - bytes_received
|
74
|
+
packet = remote_socket.recv(buffer_size)
|
75
|
+
|
76
|
+
if not packet:
|
77
|
+
return None
|
78
|
+
|
79
|
+
packets.append(packet)
|
80
|
+
bytes_received = bytes_received + len(packet)
|
81
|
+
|
82
|
+
data = b''.join(packets)
|
83
|
+
return data
|
84
|
+
|
85
|
+
|
86
|
+
def send_message_on_socket(*, remote_socket, dumpsable_object):
|
87
|
+
message_encoded_as_bytes = convert_object_to_bytes(dumpsable_object)
|
88
|
+
send_encoded_message_on_socket(remote_socket=remote_socket, encoded_message=message_encoded_as_bytes)
|
89
|
+
|
90
|
+
|
91
|
+
def send_encoded_message_on_socket(*, remote_socket, encoded_message):
|
92
|
+
size_of_string = len(encoded_message)
|
93
|
+
encoded_message_with_size = struct.pack('>I', size_of_string) + encoded_message
|
94
|
+
|
95
|
+
bytes_sent = remote_socket.send(encoded_message_with_size)
|
96
|
+
|
97
|
+
while bytes_sent < size_of_string + SIZE_OF_UNSIGNED_INT_STRUCT:
|
98
|
+
remaining_encoded_message_to_send = encoded_message_with_size[bytes_sent:]
|
99
|
+
new_bytes_sent = remote_socket.send(remaining_encoded_message_to_send)
|
100
|
+
bytes_sent += new_bytes_sent
|
101
|
+
|
102
|
+
|
103
|
+
def get_object_from_socket(
|
104
|
+
*, remote_socket, number_of_bytes_to_read=None, is_big_endian=True, number_of_bytes_for_size_prefix=SIZE_OF_UNSIGNED_INT_STRUCT, should_remove_prefix_size_from_read=False
|
105
|
+
):
|
106
|
+
"""Function that is used between the APU and DCM to send dictionaries """
|
107
|
+
object_from_interface_as_bytes = get_bytes_from_socket(
|
108
|
+
remote_socket=remote_socket, number_of_bytes_to_read=number_of_bytes_to_read, is_big_endian=is_big_endian, number_of_bytes_for_size_prefix=number_of_bytes_for_size_prefix,
|
109
|
+
should_remove_prefix_size_from_read=should_remove_prefix_size_from_read
|
110
|
+
)
|
111
|
+
object_from_interface = convert_bytes_to_object(object_from_interface_as_bytes)
|
112
|
+
return object_from_interface
|
@@ -7,7 +7,7 @@ setuptools.setup(
|
|
7
7
|
name="plantstar-shared",
|
8
8
|
# MAJOR_MILESTONE_VERSION.MINOR_MILESTONE_VERSION.MAJOR_VERSION.MINOR_VERSION.HOTFIX_VERSION.SUBVERSION
|
9
9
|
# The main version should stay as v2.0.3.0.x until we have passed that in the plantstar_apu/plantstar_dcm projects
|
10
|
-
version="2.0.3.0.2.
|
10
|
+
version="2.0.3.0.2.10",
|
11
11
|
author="SYSCON International",
|
12
12
|
author_email="dev@syscon-intl.com",
|
13
13
|
description="Shared code used in plantstar_apu and plantstar_dcm",
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class HmiKeyConstants:
|
2
|
-
APU_IP_ADDRESS = "apu_ip_address"
|
3
|
-
HMI_HOSTNAME = "hmi_hostname"
|
4
|
-
HMI_HOMEPAGE = "hmi_homepage"
|
5
|
-
HMI_IP_ADDRESS_TYPE = "hmi_ip_address_type"
|
6
|
-
HMI_IP_ADDRESS = "hmi_ip_address"
|
7
|
-
HMI_NETMASK = "hmi_netmask"
|
8
|
-
HMI_DEFAULT_GATEWAY = "hmi_default_gateway"
|
9
|
-
HMI_DNS = "hmi_dns"
|
@@ -1,68 +0,0 @@
|
|
1
|
-
import struct
|
2
|
-
|
3
|
-
from plantstar_shared.convert_bytes_to_object import convert_bytes_to_object
|
4
|
-
from plantstar_shared.convert_object_to_bytes import convert_object_to_bytes
|
5
|
-
from plantstar_shared.errors import SocketConnectionError
|
6
|
-
|
7
|
-
SIZE_OF_UNSIGNED_INT_STRUCT = 4
|
8
|
-
|
9
|
-
|
10
|
-
def read_size_value_from_socket(*, remote_socket):
|
11
|
-
size_struct = remote_socket.recv(SIZE_OF_UNSIGNED_INT_STRUCT)
|
12
|
-
|
13
|
-
if not size_struct:
|
14
|
-
return None
|
15
|
-
|
16
|
-
try:
|
17
|
-
message_length = struct.unpack('>I', size_struct)[0]
|
18
|
-
except struct.error as error:
|
19
|
-
raise SocketConnectionError
|
20
|
-
|
21
|
-
return message_length
|
22
|
-
|
23
|
-
|
24
|
-
def get_message_from_socket(*, remote_socket):
|
25
|
-
message_length = read_size_value_from_socket(remote_socket=remote_socket)
|
26
|
-
|
27
|
-
if not message_length:
|
28
|
-
return None
|
29
|
-
|
30
|
-
packets = []
|
31
|
-
bytes_received = 0
|
32
|
-
|
33
|
-
# While loop that will stream in data if the full request is not available yet
|
34
|
-
while bytes_received < message_length:
|
35
|
-
buffer_size = message_length - bytes_received
|
36
|
-
packet = remote_socket.recv(buffer_size)
|
37
|
-
|
38
|
-
if not packet:
|
39
|
-
return None
|
40
|
-
|
41
|
-
packets.append(packet)
|
42
|
-
bytes_received = bytes_received + len(packet)
|
43
|
-
|
44
|
-
data = b''.join(packets)
|
45
|
-
return data
|
46
|
-
|
47
|
-
|
48
|
-
def send_message_on_socket(*, remote_socket, dumpsable_object):
|
49
|
-
message_encoded_as_bytes = convert_object_to_bytes(dumpsable_object)
|
50
|
-
send_encoded_message_on_socket(remote_socket=remote_socket, encoded_message=message_encoded_as_bytes)
|
51
|
-
|
52
|
-
|
53
|
-
def send_encoded_message_on_socket(*, remote_socket, encoded_message):
|
54
|
-
size_of_string = len(encoded_message)
|
55
|
-
encoded_message_with_size = struct.pack('>I', size_of_string) + encoded_message
|
56
|
-
|
57
|
-
bytes_sent = remote_socket.send(encoded_message_with_size)
|
58
|
-
|
59
|
-
while bytes_sent < size_of_string + SIZE_OF_UNSIGNED_INT_STRUCT:
|
60
|
-
remaining_encoded_message_to_send = encoded_message_with_size[bytes_sent:]
|
61
|
-
new_bytes_sent = remote_socket.send(remaining_encoded_message_to_send)
|
62
|
-
bytes_sent += new_bytes_sent
|
63
|
-
|
64
|
-
|
65
|
-
def get_object_from_socket(*, remote_socket):
|
66
|
-
object_from_interface_as_bytes = get_message_from_socket(remote_socket=remote_socket)
|
67
|
-
object_from_interface = convert_bytes_to_object(object_from_interface_as_bytes)
|
68
|
-
return object_from_interface
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/SysconType.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{plantstar-shared-2.0.3.0.2.9 → plantstar-shared-2.0.3.0.2.10}/plantstar_shared/syscon_json.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|