holado 0.2.3__py3-none-any.whl → 0.2.4__py3-none-any.whl
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.
Potentially problematic release.
This version of holado might be problematic. Click here for more details.
- holado/__init__.py +11 -1
- {holado-0.2.3.dist-info → holado-0.2.4.dist-info}/METADATA +1 -1
- {holado-0.2.3.dist-info → holado-0.2.4.dist-info}/RECORD +11 -11
- holado_ais/ais/ais_messages.py +140 -139
- holado_logging/__init__.py +2 -1
- holado_logging/common/logging/log_config.py +127 -127
- holado_protobuf/__init__.py +1 -1
- holado_protobuf/ipc/protobuf/protobuf_messages.py +821 -818
- holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py +1 -2
- {holado-0.2.3.dist-info → holado-0.2.4.dist-info}/WHEEL +0 -0
- {holado-0.2.3.dist-info → holado-0.2.4.dist-info}/licenses/LICENSE +0 -0
holado/__init__.py
CHANGED
|
@@ -67,7 +67,12 @@ def change_logging_config(log_level=None, log_on_console=False, log_in_file=True
|
|
|
67
67
|
SessionContext.instance().log_manager.on_console = log_on_console
|
|
68
68
|
SessionContext.instance().log_manager.in_file = log_in_file
|
|
69
69
|
SessionContext.instance().log_manager.set_config()
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def initialize_minimal():
|
|
73
|
+
_initialize_logging(initialize_logging=False, logging_config_file=None,
|
|
74
|
+
log_level=None, log_on_console=True, log_in_file=False)
|
|
75
|
+
|
|
71
76
|
def initialize(TSessionContext=None, initialize_logging=True, logging_config_file=None,
|
|
72
77
|
log_level=None, log_on_console=False, log_in_file=True, session_kwargs=None,
|
|
73
78
|
garbage_collector_periodicity=default_value):
|
|
@@ -265,3 +270,8 @@ def print_imported_modules(prefix):
|
|
|
265
270
|
# print(f"{prefix} globals modules: {globals_modules}")
|
|
266
271
|
|
|
267
272
|
|
|
273
|
+
|
|
274
|
+
# Process minimal initialization of HolAdo
|
|
275
|
+
initialize_minimal()
|
|
276
|
+
|
|
277
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
holado/__init__.py,sha256=
|
|
1
|
+
holado/__init__.py,sha256=tVzIpBBIgMekJxxcfFQY2NXdj5OkwkmGdZfVBes1YA8,12902
|
|
2
2
|
holado/holado_config.py,sha256=v6qmTYcO50Gjtq7jwpcVp79HMeWuf2wZCGLlKDaDFc8,2369
|
|
3
3
|
holado/common/__init__.py,sha256=ZjXM-FRQgnfzRNXqcvJOGewDHVRR-U5-ugStSs8U2Xs,1525
|
|
4
4
|
holado/common/context/__init__.py,sha256=3jJBLm8myrYF9jbdV1EhIA6BtnlmjX33eeoDpTzwmLA,1604
|
|
@@ -14,7 +14,7 @@ holado/common/tools/gc_manager.py,sha256=TjQg7MisGRhxuiQ22hB3IuqNhnWCVEWpU253-rO
|
|
|
14
14
|
holado_ais/__init__.py,sha256=Mudcgu_7p1hBDBs6LpSz757H4haB0yLHgT70sznG82c,1807
|
|
15
15
|
holado_ais/ais/MaritimeIdentificationDigits.csv,sha256=r-uHt4wOvxlbA26af9e-N3BKbuiMf6ia3PN0ZGfYk2A,8547
|
|
16
16
|
holado_ais/ais/ais_manager.py,sha256=QvN94JoUBbSXT08HABl2FNsAVOM-YCmQO5tN9COg6Rc,6496
|
|
17
|
-
holado_ais/ais/ais_messages.py,sha256=
|
|
17
|
+
holado_ais/ais/ais_messages.py,sha256=Fh35mDS1mcZcH1XKmrAxxgfnGq-xp6Vgapc_C0dK_xU,10899
|
|
18
18
|
holado_ais/ais/ais_payload.py,sha256=mdOa_4JIbkFLK4_KUmQF5jUt1nLxvZhmIcqK8i-YY6w,1791
|
|
19
19
|
holado_ais/ais/enums.py,sha256=bsqfJVg65fWiJwL_VlSKwKgTY0pLoDcI4T06aEOcQnw,1108
|
|
20
20
|
holado_ais/ais/patch_pyais.py,sha256=ViRXz3__FXm-VBwD5C4bQ_gGvujCJuJSOoqewkFM6GI,54835
|
|
@@ -217,9 +217,9 @@ holado_keycloak/tests/behave/steps/__init__.py,sha256=NBE4L-am7jgPiJxcHRlZ4PQRjJ
|
|
|
217
217
|
holado_keycloak/tests/behave/steps/tools/keycloak_client_steps.py,sha256=Ku3G7GAmmX9Wzsv5ihj1tiPWae8gQDjpxYieMim6CrQ,3005
|
|
218
218
|
holado_keycloak/tools/keycloak/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
219
219
|
holado_keycloak/tools/keycloak/keycloak_client.py,sha256=QXAsf9rF0pKq1dHhXeZFZOxuEg_1uzp6vqXnwWDnegg,4019
|
|
220
|
-
holado_logging/__init__.py,sha256=
|
|
220
|
+
holado_logging/__init__.py,sha256=nQwlWD2UCPGea_0wC4CKxhkk8SVkOgM12N2CLcNOxec,2076
|
|
221
221
|
holado_logging/common/logging/holado_logger.py,sha256=msHjaL1At-ijKk0yYVn8z-3KEZulaT1Dt4B-ZC1Rm3k,3352
|
|
222
|
-
holado_logging/common/logging/log_config.py,sha256=
|
|
222
|
+
holado_logging/common/logging/log_config.py,sha256=q6jn-eZbrSRqj6OWh77e6mnrzy7LT36eyhiTxMo-Z14,5465
|
|
223
223
|
holado_logging/common/logging/log_manager.py,sha256=U3KMa689V7tc9LlRFRcwTJIbZCnH3S7qdvcUT-fKhCI,13683
|
|
224
224
|
holado_multitask/__init__.py,sha256=EwuwiBmp8ICbPZ8CKPju8tHRTh2rG68PB_wGXczY9rw,2143
|
|
225
225
|
holado_multitask/multiprocessing/function_process.py,sha256=HFXjpnzWed5J1tjmWMQyRx8AGcY6D1laegHqZ5j1dco,4550
|
|
@@ -243,11 +243,11 @@ holado_multitask/multithreading/reflection/traceback.py,sha256=Bnq-Xp0aA3D4kYtb7
|
|
|
243
243
|
holado_multitask/tests/behave/steps/__init__.py,sha256=H3pe2qGVRV8gj5hLg9xvQM_S0u3UZH_3X3mSwvkAgH8,1319
|
|
244
244
|
holado_multitask/tests/behave/steps/multiprocessing_steps.py,sha256=SgDBUpU_j7NjPS-HRZUo7fhE4ukMYa8MuQhjNhvX7fM,7441
|
|
245
245
|
holado_multitask/tests/behave/steps/multithreading_steps.py,sha256=ZiPifzvN_L9vfY5xu2yqX8T-XLurX4TWT4-uXD9P0wI,6827
|
|
246
|
-
holado_protobuf/__init__.py,sha256=
|
|
246
|
+
holado_protobuf/__init__.py,sha256=PsfsVCEC663IoDbDGyAjRUnOzXXSammPd9MH4nkOp28,3491
|
|
247
247
|
holado_protobuf/ipc/protobuf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
248
248
|
holado_protobuf/ipc/protobuf/protobuf_compiler.py,sha256=RIHyjsLpgv6jwsIz4hXUStTnn_TGwFL3LOgrzxKhEOw,6349
|
|
249
249
|
holado_protobuf/ipc/protobuf/protobuf_converter.py,sha256=L3SAhBC3L5ghcXFD9Q9nHodPb3aP4bBd6nB7k9soHJ4,8995
|
|
250
|
-
holado_protobuf/ipc/protobuf/protobuf_messages.py,sha256=
|
|
250
|
+
holado_protobuf/ipc/protobuf/protobuf_messages.py,sha256=ENWbNLg-JicsMLeV1mz3jrfGU3u3z_KTG4EHh9p-WYI,61684
|
|
251
251
|
holado_protobuf/ipc/protobuf/protobuf_modifier.py,sha256=TZUfUYJd2nPoDYw3GXaGy5GLp7YwG-bqJFZ6Ep1mNLQ,3271
|
|
252
252
|
holado_protobuf/ipc/protobuf/abstracts/type.py,sha256=xr6CvHTJJQBDKtpPdOlUJyWjdjbHsm5uPHa3eOZlvLQ,2234
|
|
253
253
|
holado_protobuf/ipc/protobuf/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -296,7 +296,7 @@ holado_rabbitmq/tests/behave/steps/__init__.py,sha256=l-VWY2Qv9f-9ZoPmWjUmeurF8k
|
|
|
296
296
|
holado_rabbitmq/tests/behave/steps/tools/rabbitmq_client_steps.py,sha256=H5_r6LKaw_ElmmjcghZMT5KQInoJrdYNOtATh8GG3MQ,28833
|
|
297
297
|
holado_rabbitmq/tests/behave/steps/tools/rabbitmq_server_steps.py,sha256=35cXpKCuqg827dpf22rjmD4dJeXUnfOEN1cFkUr9P7Q,3060
|
|
298
298
|
holado_rabbitmq/tools/rabbitmq/rabbitmq_blocking_client.py,sha256=ABv8GlwdZ_lvJQswL1Yz9kO6C7nXIKv4BSNb0JiByFo,15116
|
|
299
|
-
holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py,sha256=
|
|
299
|
+
holado_rabbitmq/tools/rabbitmq/rabbitmq_client.py,sha256=ChKiC5C4i00tW6tn2Pw70g6P4mXG-xHtB5UlmULQMro,29723
|
|
300
300
|
holado_rabbitmq/tools/rabbitmq/rabbitmq_manager.py,sha256=lCbbow3qFNhLNMzFHKEKhsaO4GmAH5DPYXwcjIittkA,9021
|
|
301
301
|
holado_rabbitmq/tools/rabbitmq/rabbitmq_select_client.py,sha256=urWn9A8XZqpAAtbvRZ-YUGVbOX_1Y0uSBA2lHGqJxLA,21039
|
|
302
302
|
holado_rabbitmq/tools/rabbitmq/rabbitmq_server.py,sha256=FW8iKAHm0I78bHQEbRk4rl0dtCmv4dvAe5BY_HfOQVM,1613
|
|
@@ -529,7 +529,7 @@ test_holado/tools/django/api_rest/api_rest/api1/serializers.py,sha256=o_YxFr-tgC
|
|
|
529
529
|
test_holado/tools/django/api_rest/api_rest/api1/tests.py,sha256=mrbGGRNg5jwbTJtWWa7zSKdDyeB4vmgZCRc2nk6VY-g,60
|
|
530
530
|
test_holado/tools/django/api_rest/api_rest/api1/views.py,sha256=kOt2xT6bxO47_z__5yYR9kcYIWWv4qYzpX0K8Tqonik,758
|
|
531
531
|
test_holado/tools/django/api_rest/api_rest/api1/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
532
|
-
holado-0.2.
|
|
533
|
-
holado-0.2.
|
|
534
|
-
holado-0.2.
|
|
535
|
-
holado-0.2.
|
|
532
|
+
holado-0.2.4.dist-info/METADATA,sha256=Jjt1xRdJDYLb177alFU2WvyfX3YfIGo05BMirzUDLyw,5796
|
|
533
|
+
holado-0.2.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
534
|
+
holado-0.2.4.dist-info/licenses/LICENSE,sha256=IgGmNlcFHnbp7UWrLJqAFvs_HIgjJDTmjCNRircJLsk,1070
|
|
535
|
+
holado-0.2.4.dist-info/RECORD,,
|
holado_ais/ais/ais_messages.py
CHANGED
|
@@ -21,7 +21,6 @@ from holado_core.common.tools.string_tools import StrTools
|
|
|
21
21
|
from holado_binary.ipc.binary import Binary
|
|
22
22
|
from holado_core.common.tools.tools import Tools
|
|
23
23
|
from holado_python.standard_library.typing import Typing
|
|
24
|
-
from holado_ais.ais.patch_pyais import HATagBlock, HA_ais_to_nmea_0183
|
|
25
24
|
import copy
|
|
26
25
|
|
|
27
26
|
logger = logging.getLogger(__name__)
|
|
@@ -29,6 +28,7 @@ logger = logging.getLogger(__name__)
|
|
|
29
28
|
try:
|
|
30
29
|
import pyais
|
|
31
30
|
from bitarray import bitarray
|
|
31
|
+
from holado_ais.ais.patch_pyais import HATagBlock, HA_ais_to_nmea_0183
|
|
32
32
|
with_pyais = True
|
|
33
33
|
|
|
34
34
|
# Patch pyais with some fixes
|
|
@@ -36,7 +36,6 @@ try:
|
|
|
36
36
|
except Exception as exc:
|
|
37
37
|
if Tools.do_log(logger, logging.DEBUG):
|
|
38
38
|
logger.debug(f"AIS is not available. Initialization failed on error: {exc}")
|
|
39
|
-
logger.warning(f"AIS is not available. Initialization failed on error: {exc}")
|
|
40
39
|
with_pyais = False
|
|
41
40
|
|
|
42
41
|
|
|
@@ -47,157 +46,159 @@ class AISMessages(object):
|
|
|
47
46
|
def is_available(cls):
|
|
48
47
|
return with_pyais
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
self.__tag_block_group_id = 0
|
|
52
|
-
|
|
53
|
-
def default_message_data(self, msg_type:int):
|
|
54
|
-
"""Return default data values for required data by pyais but not functionnaly required.
|
|
55
|
-
It is useful when generating custom messages, for example for tests.
|
|
56
|
-
"""
|
|
57
|
-
return {}
|
|
58
|
-
|
|
59
|
-
def new_message_as_bitarray_bytes(self, msg_type:int, data:Union[dict,TableWithHeader]):
|
|
60
|
-
msg = self.new_message(msg_type, data)
|
|
61
|
-
res = self.convert_message_to_bytes(msg)
|
|
62
|
-
return res
|
|
63
|
-
|
|
64
|
-
def new_message(self, msg_type:int, data:Union[dict,TableWithHeader]):
|
|
65
|
-
if isinstance(data, TableWithHeader):
|
|
66
|
-
data = self.__convert_table_to_dict(data)
|
|
67
|
-
if not isinstance(data, dict):
|
|
68
|
-
raise TechnicalException(f"Unexpected data type '{Typing.get_object_class_fullname(data)}'")
|
|
49
|
+
if with_pyais:
|
|
69
50
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return res
|
|
73
|
-
|
|
74
|
-
def decode(self, *args, encoded_msg=None, parts_separator=b'\n'):
|
|
75
|
-
if encoded_msg is not None:
|
|
76
|
-
if isinstance(encoded_msg, str):
|
|
77
|
-
encoded_bytes = encoded_msg.encode("utf-8")
|
|
78
|
-
elif isinstance(encoded_msg, bytes):
|
|
79
|
-
encoded_bytes = encoded_msg
|
|
80
|
-
else:
|
|
81
|
-
raise TechnicalException(f"Parameter 'encoded_msg' must be of type str or bytes")
|
|
82
|
-
args = encoded_bytes.split(parts_separator)
|
|
83
|
-
return pyais.decode(*args, error_if_checksum_invalid=True)
|
|
84
|
-
|
|
85
|
-
def decode_message(self, msg_type:int, bit_array:Union[str,bitarray]):
|
|
86
|
-
if isinstance(bit_array, str):
|
|
87
|
-
if StrTools.is_hex(bit_array) and not StrTools.is_bitarray(bit_array):
|
|
88
|
-
bit_array = Binary.convert_hex_str_to_bin_str(bit_array)
|
|
89
|
-
bit_array = bitarray(bit_array)
|
|
90
|
-
if not isinstance(bit_array, bitarray):
|
|
91
|
-
raise TechnicalException(f"Bad parameter 'bit_array' (accepted types: bitarray, str)")
|
|
92
|
-
|
|
93
|
-
message_type = self.__get_message_type(msg_type)
|
|
94
|
-
return message_type.from_bitarray(bit_array)
|
|
95
|
-
|
|
96
|
-
def encode_raw_payload(self, payload_hex: str, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
97
|
-
from pyais.util import encode_ascii_6
|
|
51
|
+
def __init__(self):
|
|
52
|
+
self.__tag_block_group_id = 0
|
|
98
53
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
54
|
+
def default_message_data(self, msg_type:int):
|
|
55
|
+
"""Return default data values for required data by pyais but not functionnaly required.
|
|
56
|
+
It is useful when generating custom messages, for example for tests.
|
|
57
|
+
"""
|
|
58
|
+
return {}
|
|
102
59
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
60
|
+
def new_message_as_bitarray_bytes(self, msg_type:int, data:Union[dict,TableWithHeader]):
|
|
61
|
+
msg = self.new_message(msg_type, data)
|
|
62
|
+
res = self.convert_message_to_bytes(msg)
|
|
63
|
+
return res
|
|
106
64
|
|
|
107
|
-
|
|
108
|
-
|
|
65
|
+
def new_message(self, msg_type:int, data:Union[dict,TableWithHeader]):
|
|
66
|
+
if isinstance(data, TableWithHeader):
|
|
67
|
+
data = self.__convert_table_to_dict(data)
|
|
68
|
+
if not isinstance(data, dict):
|
|
69
|
+
raise TechnicalException(f"Unexpected data type '{Typing.get_object_class_fullname(data)}'")
|
|
70
|
+
|
|
71
|
+
message_type = self.__get_message_type(msg_type)
|
|
72
|
+
res = message_type.create(**data)
|
|
73
|
+
return res
|
|
74
|
+
|
|
75
|
+
def decode(self, *args, encoded_msg=None, parts_separator=b'\n'):
|
|
76
|
+
if encoded_msg is not None:
|
|
77
|
+
if isinstance(encoded_msg, str):
|
|
78
|
+
encoded_bytes = encoded_msg.encode("utf-8")
|
|
79
|
+
elif isinstance(encoded_msg, bytes):
|
|
80
|
+
encoded_bytes = encoded_msg
|
|
81
|
+
else:
|
|
82
|
+
raise TechnicalException(f"Parameter 'encoded_msg' must be of type str or bytes")
|
|
83
|
+
args = encoded_bytes.split(parts_separator)
|
|
84
|
+
return pyais.decode(*args, error_if_checksum_invalid=True)
|
|
109
85
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
def encode_msg(self, msg, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
121
|
-
if not isinstance(msg, pyais.messages.Payload):
|
|
122
|
-
raise TechnicalException(f"Parameter 'msg' is not an AIS message (obtained type: {Typing.get_object_class_fullname(msg)})")
|
|
86
|
+
def decode_message(self, msg_type:int, bit_array:Union[str,bitarray]):
|
|
87
|
+
if isinstance(bit_array, str):
|
|
88
|
+
if StrTools.is_hex(bit_array) and not StrTools.is_bitarray(bit_array):
|
|
89
|
+
bit_array = Binary.convert_hex_str_to_bin_str(bit_array)
|
|
90
|
+
bit_array = bitarray(bit_array)
|
|
91
|
+
if not isinstance(bit_array, bitarray):
|
|
92
|
+
raise TechnicalException(f"Bad parameter 'bit_array' (accepted types: bitarray, str)")
|
|
93
|
+
|
|
94
|
+
message_type = self.__get_message_type(msg_type)
|
|
95
|
+
return message_type.from_bitarray(bit_array)
|
|
123
96
|
|
|
124
|
-
|
|
125
|
-
|
|
97
|
+
def encode_raw_payload(self, payload_hex: str, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
98
|
+
from pyais.util import encode_ascii_6
|
|
99
|
+
|
|
100
|
+
payload_bitarray = bitarray()
|
|
101
|
+
payload_bitarray.frombytes(bytes.fromhex(payload_hex))
|
|
102
|
+
payload_ascii6, fill_bits = encode_ascii_6(payload_bitarray)
|
|
103
|
+
|
|
104
|
+
seq_id = kwargs.pop('seq_id') if 'seq_id' in kwargs else self.__tag_block_group_id % 10
|
|
105
|
+
radio_channel = kwargs['radio_channel'] if 'radio_channel' in kwargs else 'A'
|
|
106
|
+
group_id = kwargs.pop('group_id') if 'group_id' in kwargs else None
|
|
107
|
+
|
|
108
|
+
sentences = HA_ais_to_nmea_0183(payload_ascii6, talker_id, radio_channel, fill_bits, seq_id)
|
|
109
|
+
return self.__encode_add_tag_block(sentences, tag_block, with_tag_block=with_tag_block, group_id=group_id)
|
|
110
|
+
|
|
111
|
+
def encode(self, data, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
112
|
+
if isinstance(data, pyais.messages.Payload):
|
|
113
|
+
return self.encode_msg(data, tag_block=tag_block, with_tag_block=with_tag_block, talker_id=talker_id, **kwargs)
|
|
114
|
+
elif isinstance(data, dict):
|
|
115
|
+
return self.encode_data(data, tag_block=tag_block, with_tag_block=with_tag_block, talker_id=talker_id, **kwargs)
|
|
116
|
+
elif isinstance(data, TableWithHeader):
|
|
117
|
+
return self.encode_table(data, tag_block=tag_block, with_tag_block=with_tag_block, talker_id=talker_id, **kwargs)
|
|
118
|
+
else:
|
|
119
|
+
raise TechnicalException(f"Unexpected data type '{Typing.get_object_class_fullname(data)}'")
|
|
126
120
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
def encode_msg(self, msg, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
122
|
+
if not isinstance(msg, pyais.messages.Payload):
|
|
123
|
+
raise TechnicalException(f"Parameter 'msg' is not an AIS message (obtained type: {Typing.get_object_class_fullname(msg)})")
|
|
124
|
+
|
|
125
|
+
seq_id = kwargs.pop('seq_id') if 'seq_id' in kwargs else self.__tag_block_group_id % 10
|
|
126
|
+
group_id = kwargs.pop('group_id') if 'group_id' in kwargs else None
|
|
127
|
+
|
|
128
|
+
sentences = pyais.encode_msg(msg, seq_id=seq_id, talker_id=talker_id, **kwargs)
|
|
129
|
+
return self.__encode_add_tag_block(sentences, tag_block, with_tag_block=with_tag_block, group_id=group_id)
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
def encode_data(self, data, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
132
|
+
if not isinstance(data, dict):
|
|
133
|
+
raise TechnicalException(f"Parameter 'data' is not a dict (obtained type: {Typing.get_object_class_fullname(data)})")
|
|
134
|
+
|
|
135
|
+
seq_id = kwargs.pop('seq_id') if 'seq_id' in kwargs else self.__tag_block_group_id % 10
|
|
136
|
+
group_id = kwargs.pop('group_id') if 'group_id' in kwargs else None
|
|
137
|
+
|
|
138
|
+
sentences = pyais.encode_dict(data, seq_id=seq_id, talker_id=talker_id, **kwargs)
|
|
139
|
+
return self.__encode_add_tag_block(sentences, tag_block, with_tag_block=with_tag_block, group_id=group_id)
|
|
136
140
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def encode_table(self, table, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
141
|
-
data = self.__convert_table_to_dict(table)
|
|
142
|
-
return self.encode_data(data, tag_block=tag_block, with_tag_block=with_tag_block, talker_id=talker_id, **kwargs)
|
|
143
|
-
|
|
144
|
-
def __encode_add_tag_block(self, encoded_sentences, tag_block: HATagBlock = None, with_tag_block=True, group_id=None):
|
|
145
|
-
from pyais.messages import TagBlockGroup
|
|
141
|
+
def encode_table(self, table, tag_block: HATagBlock = None, with_tag_block=True, talker_id: str = "AIVDM", **kwargs):
|
|
142
|
+
data = self.__convert_table_to_dict(table)
|
|
143
|
+
return self.encode_data(data, tag_block=tag_block, with_tag_block=with_tag_block, talker_id=talker_id, **kwargs)
|
|
146
144
|
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
def __encode_add_tag_block(self, encoded_sentences, tag_block: HATagBlock = None, with_tag_block=True, group_id=None):
|
|
146
|
+
from pyais.messages import TagBlockGroup
|
|
147
|
+
|
|
148
|
+
if not with_tag_block:
|
|
149
|
+
return encoded_sentences
|
|
150
|
+
|
|
151
|
+
res = []
|
|
152
|
+
nb_sentences = len(encoded_sentences)
|
|
153
|
+
if nb_sentences > 1 and group_id is None:
|
|
154
|
+
group_id = self.__tag_block_group_id
|
|
155
|
+
# Increment group_id for next message needing a group_id
|
|
156
|
+
self.__new_tag_block_group_id()
|
|
157
|
+
elif nb_sentences == 1:
|
|
158
|
+
# No group tag block is needed
|
|
159
|
+
group_id = None
|
|
160
|
+
|
|
161
|
+
for index, sentence in enumerate(encoded_sentences):
|
|
162
|
+
sentence_tag_block = copy.deepcopy(tag_block) if index == 0 else None
|
|
163
|
+
if group_id is not None:
|
|
164
|
+
if sentence_tag_block is None:
|
|
165
|
+
sentence_tag_block = HATagBlock()
|
|
166
|
+
sentence_tag_block._group = TagBlockGroup(msg_id=index+1, total=nb_sentences, group_id=group_id)
|
|
167
|
+
|
|
168
|
+
if sentence_tag_block is not None:
|
|
169
|
+
res.append('\\' + sentence_tag_block.to_raw().decode() + '\\' + sentence)
|
|
170
|
+
else:
|
|
171
|
+
res.append(sentence)
|
|
172
|
+
|
|
173
|
+
return res
|
|
149
174
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
self.__new_tag_block_group_id()
|
|
156
|
-
elif nb_sentences == 1:
|
|
157
|
-
# No group tag block is needed
|
|
158
|
-
group_id = None
|
|
175
|
+
def __new_tag_block_group_id(self):
|
|
176
|
+
self.__tag_block_group_id += 1
|
|
177
|
+
if self.__tag_block_group_id > 9999:
|
|
178
|
+
self.__tag_block_group_id = 0
|
|
179
|
+
return self.__tag_block_group_id
|
|
159
180
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if group_id is not None:
|
|
163
|
-
if sentence_tag_block is None:
|
|
164
|
-
sentence_tag_block = HATagBlock()
|
|
165
|
-
sentence_tag_block._group = TagBlockGroup(msg_id=index+1, total=nb_sentences, group_id=group_id)
|
|
166
|
-
|
|
167
|
-
if sentence_tag_block is not None:
|
|
168
|
-
res.append('\\' + sentence_tag_block.to_raw().decode() + '\\' + sentence)
|
|
169
|
-
else:
|
|
170
|
-
res.append(sentence)
|
|
181
|
+
def convert_message_to_binary_str(self, msg):
|
|
182
|
+
return msg.to_bitarray().to01()
|
|
171
183
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
def __new_tag_block_group_id(self):
|
|
175
|
-
self.__tag_block_group_id += 1
|
|
176
|
-
if self.__tag_block_group_id > 9999:
|
|
177
|
-
self.__tag_block_group_id = 0
|
|
178
|
-
return self.__tag_block_group_id
|
|
179
|
-
|
|
180
|
-
def convert_message_to_binary_str(self, msg):
|
|
181
|
-
return msg.to_bitarray().to01()
|
|
182
|
-
|
|
183
|
-
def convert_message_to_bytes(self, msg):
|
|
184
|
-
return msg.to_bitarray().tobytes()
|
|
185
|
-
|
|
186
|
-
def __get_message_type(self, msg_type:int):
|
|
187
|
-
import importlib
|
|
188
|
-
module = importlib.import_module('pyais.messages')
|
|
189
|
-
res = getattr(module, f"MessageType{msg_type}")
|
|
190
|
-
return res
|
|
184
|
+
def convert_message_to_bytes(self, msg):
|
|
185
|
+
return msg.to_bitarray().tobytes()
|
|
191
186
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
def __get_message_type(self, msg_type:int):
|
|
188
|
+
import importlib
|
|
189
|
+
module = importlib.import_module('pyais.messages')
|
|
190
|
+
res = getattr(module, f"MessageType{msg_type}")
|
|
191
|
+
return res
|
|
192
|
+
|
|
193
|
+
def __convert_table_to_dict(self, table):
|
|
194
|
+
if not ValueTableManager.is_table_with_header(table):
|
|
195
|
+
raise TechnicalException(f"Parameter 'table' is not a table with header (obtained type: {Typing.get_object_class_fullname(table)})")
|
|
196
|
+
|
|
197
|
+
if ValueTableManager.verify_table_is_name_value_table(table, raise_exception=False):
|
|
198
|
+
res = ValueTableConverter.convert_name_value_table_2_dict(table)
|
|
199
|
+
else:
|
|
200
|
+
res = ValueTableConverter.convert_table_with_header_to_dict(table)
|
|
201
|
+
return res
|
|
195
202
|
|
|
196
|
-
if ValueTableManager.verify_table_is_name_value_table(table, raise_exception=False):
|
|
197
|
-
res = ValueTableConverter.convert_name_value_table_2_dict(table)
|
|
198
|
-
else:
|
|
199
|
-
res = ValueTableConverter.convert_table_with_header_to_dict(table)
|
|
200
|
-
return res
|
|
201
|
-
|
|
202
203
|
|
|
203
204
|
|
holado_logging/__init__.py
CHANGED
|
@@ -32,5 +32,6 @@ def register():
|
|
|
32
32
|
log_manager = LogManager()
|
|
33
33
|
log_manager.initialize(log_on_console=True)
|
|
34
34
|
|
|
35
|
-
SessionContext.instance().services.register_service_instance("log_manager", log_manager, SessionContext.instance()
|
|
35
|
+
SessionContext.instance().services.register_service_instance("log_manager", log_manager, SessionContext.instance(),
|
|
36
|
+
raise_if_service_exist=False, raise_if_object_exist=False)
|
|
36
37
|
|