plantstar-shared 2.0.3.0.2.15__tar.gz → 2.0.3.0.2.17__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.15 → plantstar_shared-2.0.3.0.2.17}/PKG-INFO +1 -1
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/convert_bytes_to_object.py +1 -1
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/syscon_json.py +5 -2
- plantstar_shared-2.0.3.0.2.17/plantstar_shared/tcp_socket_utils.py +68 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared.egg-info/PKG-INFO +1 -1
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/setup.py +1 -1
- plantstar-shared-2.0.3.0.2.15/plantstar_shared/tcp_socket_utils.py +0 -132
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/README.md +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/DataCollectionModuleProcessNames.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/HuskyInterfacePacketTypes.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/MockRawDataProcessor.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/RawDataProcessorInterfaceActions.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/SysconType.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/__init__.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/add_size_onto_string_and_return.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/api_types.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/convert_object_to_bytes.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/errors.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/global_definitions.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/is_valid_signed_string.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/obtain_raw_data_processor_function_for_action_name.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/syscon_image_field.py +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared.egg-info/SOURCES.txt +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared.egg-info/dependency_links.txt +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared.egg-info/requires.txt +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared.egg-info/top_level.txt +0 -0
- {plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/setup.cfg +0 -0
@@ -2,9 +2,9 @@ import msgpack
|
|
2
2
|
|
3
3
|
from plantstar_shared.errors import SocketConnectionError
|
4
4
|
|
5
|
-
|
6
5
|
# Converts bytes into an object using msgpack, with a parameter for strict_map_key
|
7
6
|
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
|
|
{plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/syscon_json.py
RENAMED
@@ -90,8 +90,11 @@ class SysconDecoder(json.JSONDecoder):
|
|
90
90
|
# This is here for a weird bug that was happening
|
91
91
|
if dictionary["tzinfo"] is None or dictionary["tzinfo"] in ["None", "tzlocal()", "tzutc()"]:
|
92
92
|
dictionary["tzinfo"] = "UTC"
|
93
|
-
|
94
|
-
|
93
|
+
else:
|
94
|
+
tzinfo_to_localize = pytz.timezone(dictionary["tzinfo"])
|
95
|
+
dictionary.pop('tzinfo')
|
96
|
+
localized_datetime = tzinfo_to_localize.localize(datetime.datetime(**dictionary))
|
97
|
+
return localized_datetime
|
95
98
|
|
96
99
|
if type_name == "datetime":
|
97
100
|
return datetime.datetime(**dictionary)
|
@@ -0,0 +1,68 @@
|
|
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
|
@@ -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.17",
|
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,132 +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, SysconProgrammingError
|
6
|
-
|
7
|
-
SIZE_OF_UNSIGNED_INT_FOR_HUSKY = 2 # size of the integer value that precedes data coming from Husky OIs
|
8
|
-
SIZE_OF_UNSIGNED_INT_STRUCT = 4 # size of the integer value that precedes data coming from most sockets (DeviceController, DCM, etc)
|
9
|
-
|
10
|
-
|
11
|
-
def read_size_value_from_socket(*, remote_socket, is_big_endian, number_of_bytes_for_size_prefix, size_value_includes_size_prefix_bytes=False):
|
12
|
-
size_bytes = remote_socket.recv(number_of_bytes_for_size_prefix)
|
13
|
-
|
14
|
-
if not size_bytes:
|
15
|
-
raise SocketConnectionError
|
16
|
-
|
17
|
-
if number_of_bytes_for_size_prefix == SIZE_OF_UNSIGNED_INT_FOR_HUSKY:
|
18
|
-
size_for_message = int.from_bytes(size_bytes, 'big') if is_big_endian else int.from_bytes(size_bytes, 'little')
|
19
|
-
elif number_of_bytes_for_size_prefix == SIZE_OF_UNSIGNED_INT_STRUCT:
|
20
|
-
number_format = ">I" if is_big_endian else "<I"
|
21
|
-
|
22
|
-
try:
|
23
|
-
size_for_message = struct.unpack(number_format, size_bytes)[0]
|
24
|
-
except struct.error as error:
|
25
|
-
raise SocketConnectionError
|
26
|
-
else:
|
27
|
-
raise SysconProgrammingError("A size prefix was set to something other than 2 or 4")
|
28
|
-
|
29
|
-
if size_value_includes_size_prefix_bytes:
|
30
|
-
size_for_message = size_for_message - number_of_bytes_for_size_prefix
|
31
|
-
|
32
|
-
return size_for_message, size_bytes
|
33
|
-
|
34
|
-
|
35
|
-
def get_bytes_from_socket(
|
36
|
-
*, remote_socket, number_of_bytes_to_read=None, is_big_endian=True, number_of_bytes_for_size_prefix=0, size_value_includes_size_prefix_bytes=False,
|
37
|
-
size_value_should_be_included_in_final_message=False
|
38
|
-
):
|
39
|
-
"""Obtains a number of bytes from a provided socket, with options for different configurations and situations.
|
40
|
-
Returns byte sequence, and the size value that was obtained from the prefix bytes.
|
41
|
-
|
42
|
-
Keywords / Example Configurations:
|
43
|
-
remote_socket -- the connection that bytes will be read from
|
44
|
-
|
45
|
-
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)
|
46
|
-
|
47
|
-
is_big_endian -- bool: what format string should be used for unpacking the size value (default: True)
|
48
|
-
|
49
|
-
number_of_bytes_for_size_prefix -- the number of bytes to read to determine the total size of the message to pass (default: 0)
|
50
|
-
|
51
|
-
size_value_includes_size_prefix_bytes -- bool: if size value includes the size_prefix_bytes based on the systems implementation
|
52
|
-
|
53
|
-
size_value_should_be_included_in_final_message -- bool: if size value should be prepended to the byte sequence, likely only Husky logic wants this (default: False)
|
54
|
-
|
55
|
-
-----
|
56
|
-
|
57
|
-
get_bytes_from_socket(remote_socket=conn, number_of_bytes_to_read=100) - likely would not be called directly, in most cases
|
58
|
-
|
59
|
-
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)
|
60
|
-
|
61
|
-
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,
|
62
|
-
then reads that calculated amount minus 2 (Husky socket, etc)
|
63
|
-
|
64
|
-
"""
|
65
|
-
|
66
|
-
packets = []
|
67
|
-
|
68
|
-
if not number_of_bytes_to_read:
|
69
|
-
if number_of_bytes_for_size_prefix:
|
70
|
-
number_of_bytes_to_read, size_bytes = read_size_value_from_socket(
|
71
|
-
remote_socket=remote_socket, is_big_endian=is_big_endian, number_of_bytes_for_size_prefix=number_of_bytes_for_size_prefix,
|
72
|
-
size_value_includes_size_prefix_bytes=size_value_includes_size_prefix_bytes
|
73
|
-
)
|
74
|
-
|
75
|
-
if not number_of_bytes_to_read:
|
76
|
-
raise SocketConnectionError
|
77
|
-
|
78
|
-
if size_value_should_be_included_in_final_message:
|
79
|
-
packets.append(size_bytes)
|
80
|
-
|
81
|
-
else:
|
82
|
-
raise SysconProgrammingError("get_bytes_from_socket was called with no parameters for number_of_bytes_to_read or number_of_bytes_for_size_prefix")
|
83
|
-
|
84
|
-
bytes_received = 0
|
85
|
-
|
86
|
-
# While loop that will stream in data if the full request is not available yet
|
87
|
-
while bytes_received < number_of_bytes_to_read:
|
88
|
-
buffer_size = number_of_bytes_to_read - bytes_received
|
89
|
-
packet = remote_socket.recv(buffer_size)
|
90
|
-
|
91
|
-
if not packet:
|
92
|
-
raise SocketConnectionError
|
93
|
-
|
94
|
-
packets.append(packet)
|
95
|
-
bytes_received = bytes_received + len(packet)
|
96
|
-
|
97
|
-
data = b''.join(packets)
|
98
|
-
return data, number_of_bytes_to_read
|
99
|
-
|
100
|
-
|
101
|
-
def send_message_on_socket(*, remote_socket, dumpsable_object):
|
102
|
-
message_encoded_as_bytes = convert_object_to_bytes(dumpsable_object)
|
103
|
-
send_encoded_message_on_socket(remote_socket=remote_socket, encoded_message=message_encoded_as_bytes)
|
104
|
-
|
105
|
-
|
106
|
-
def send_encoded_message_on_socket(*, remote_socket, encoded_message):
|
107
|
-
size_of_string = len(encoded_message)
|
108
|
-
encoded_message_with_size = struct.pack('>I', size_of_string) + encoded_message
|
109
|
-
|
110
|
-
bytes_sent = remote_socket.send(encoded_message_with_size)
|
111
|
-
|
112
|
-
while bytes_sent < size_of_string + SIZE_OF_UNSIGNED_INT_STRUCT:
|
113
|
-
remaining_encoded_message_to_send = encoded_message_with_size[bytes_sent:]
|
114
|
-
new_bytes_sent = remote_socket.send(remaining_encoded_message_to_send)
|
115
|
-
bytes_sent += new_bytes_sent
|
116
|
-
|
117
|
-
|
118
|
-
def get_object_from_socket(
|
119
|
-
*, remote_socket, number_of_bytes_to_read=None, is_big_endian=True, number_of_bytes_for_size_prefix=SIZE_OF_UNSIGNED_INT_STRUCT,
|
120
|
-
size_value_includes_size_prefix_bytes=False
|
121
|
-
):
|
122
|
-
"""Function that is used between the APU and DCM to send dictionaries. Returns a tuple of the object and its size in bytes."""
|
123
|
-
object_from_interface_as_bytes, size_of_object_in_bytes = get_bytes_from_socket(
|
124
|
-
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,
|
125
|
-
size_value_includes_size_prefix_bytes=size_value_includes_size_prefix_bytes
|
126
|
-
)
|
127
|
-
|
128
|
-
if not object_from_interface_as_bytes:
|
129
|
-
raise SocketConnectionError
|
130
|
-
|
131
|
-
object_from_interface = convert_bytes_to_object(object_from_interface_as_bytes)
|
132
|
-
return object_from_interface, size_of_object_in_bytes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/SysconType.py
RENAMED
File without changes
|
{plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/__init__.py
RENAMED
File without changes
|
File without changes
|
{plantstar-shared-2.0.3.0.2.15 → plantstar_shared-2.0.3.0.2.17}/plantstar_shared/api_types.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
|
File without changes
|
File without changes
|
File without changes
|