SecsGemPro 1.0.0__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.
- secsgem/__init__.py +1 -0
- secsgem/common/__init__.py +35 -0
- secsgem/common/block_send_info.py +50 -0
- secsgem/common/byte_queue.py +124 -0
- secsgem/common/callbacks.py +117 -0
- secsgem/common/codec_jis_x_0201.py +32 -0
- secsgem/common/connection.py +106 -0
- secsgem/common/events.py +196 -0
- secsgem/common/header.py +114 -0
- secsgem/common/helpers.py +97 -0
- secsgem/common/message.py +188 -0
- secsgem/common/protocol.py +318 -0
- secsgem/common/protocol_dispatcher.py +124 -0
- secsgem/common/settings.py +121 -0
- secsgem/common/state_machine.py +228 -0
- secsgem/common/tcp_client_connection.py +164 -0
- secsgem/common/tcp_connection.py +196 -0
- secsgem/common/tcp_server_connection.py +146 -0
- secsgem/common/timeouts.py +101 -0
- secsgem/example.py +31 -0
- secsgem/gem/__init__.py +20 -0
- secsgem/gem/alarm.py +51 -0
- secsgem/gem/alarm_capability.py +185 -0
- secsgem/gem/capability.py +90 -0
- secsgem/gem/clock_capability.py +43 -0
- secsgem/gem/collection_event.py +55 -0
- secsgem/gem/collection_event_capability.py +327 -0
- secsgem/gem/collection_event_link.py +46 -0
- secsgem/gem/collection_event_report.py +35 -0
- secsgem/gem/communication_state_machine.py +194 -0
- secsgem/gem/control_state_machine.py +208 -0
- secsgem/gem/data_value.py +73 -0
- secsgem/gem/data_value_capability.py +77 -0
- secsgem/gem/equipment_constant.py +71 -0
- secsgem/gem/equipment_constants_capability.py +220 -0
- secsgem/gem/equipmenthandler.py +75 -0
- secsgem/gem/handler.py +275 -0
- secsgem/gem/hosthandler.py +249 -0
- secsgem/gem/remote_command.py +57 -0
- secsgem/gem/remote_control_capability.py +112 -0
- secsgem/gem/state_models_capability.py +158 -0
- secsgem/gem/status_data_collection_capability.py +168 -0
- secsgem/gem/status_variable.py +64 -0
- secsgem/hsms/__init__.py +26 -0
- secsgem/hsms/connection_state_machine.py +81 -0
- secsgem/hsms/deselect_req_header.py +26 -0
- secsgem/hsms/deselect_rsp_header.py +26 -0
- secsgem/hsms/header.py +184 -0
- secsgem/hsms/linktest_req_header.py +26 -0
- secsgem/hsms/linktest_rsp_header.py +26 -0
- secsgem/hsms/message.py +39 -0
- secsgem/hsms/protocol.py +494 -0
- secsgem/hsms/reject_req_header.py +29 -0
- secsgem/hsms/select_req_header.py +25 -0
- secsgem/hsms/select_rsp_header.py +25 -0
- secsgem/hsms/separate_req_header.py +25 -0
- secsgem/hsms/settings.py +138 -0
- secsgem/hsms/stream_function_header.py +35 -0
- secsgem/secs/__init__.py +7 -0
- secsgem/secs/data_items/__init__.py +273 -0
- secsgem/secs/data_items/abs.py +17 -0
- secsgem/secs/data_items/acka.py +29 -0
- secsgem/secs/data_items/ackc10.py +36 -0
- secsgem/secs/data_items/ackc5.py +31 -0
- secsgem/secs/data_items/ackc6.py +31 -0
- secsgem/secs/data_items/ackc7.py +48 -0
- secsgem/secs/data_items/alcd.py +57 -0
- secsgem/secs/data_items/aled.py +34 -0
- secsgem/secs/data_items/alid.py +39 -0
- secsgem/secs/data_items/altx.py +20 -0
- secsgem/secs/data_items/attrdata.py +49 -0
- secsgem/secs/data_items/attrid.py +31 -0
- secsgem/secs/data_items/attrreln.py +48 -0
- secsgem/secs/data_items/base.py +67 -0
- secsgem/secs/data_items/bcequ.py +23 -0
- secsgem/secs/data_items/binlt.py +27 -0
- secsgem/secs/data_items/caack.py +23 -0
- secsgem/secs/data_items/carrieraction.py +27 -0
- secsgem/secs/data_items/carrierid.py +27 -0
- secsgem/secs/data_items/cattrdata.py +36 -0
- secsgem/secs/data_items/cattrid.py +36 -0
- secsgem/secs/data_items/ccode.py +35 -0
- secsgem/secs/data_items/ceed.py +27 -0
- secsgem/secs/data_items/ceid.py +43 -0
- secsgem/secs/data_items/cename.py +16 -0
- secsgem/secs/data_items/cepack.py +36 -0
- secsgem/secs/data_items/cepval.py +46 -0
- secsgem/secs/data_items/cmda.py +39 -0
- secsgem/secs/data_items/colct.py +27 -0
- secsgem/secs/data_items/commack.py +32 -0
- secsgem/secs/data_items/cpack.py +36 -0
- secsgem/secs/data_items/cpname.py +39 -0
- secsgem/secs/data_items/cpval.py +41 -0
- secsgem/secs/data_items/dataid.py +44 -0
- secsgem/secs/data_items/datalength.py +34 -0
- secsgem/secs/data_items/datlc.py +16 -0
- secsgem/secs/data_items/drack.py +41 -0
- secsgem/secs/data_items/dsid.py +36 -0
- secsgem/secs/data_items/dsper.py +16 -0
- secsgem/secs/data_items/dutms.py +17 -0
- secsgem/secs/data_items/dvname.py +36 -0
- secsgem/secs/data_items/dvval.py +46 -0
- secsgem/secs/data_items/dvvalname.py +16 -0
- secsgem/secs/data_items/eac.py +38 -0
- secsgem/secs/data_items/ecdef.py +44 -0
- secsgem/secs/data_items/ecid.py +39 -0
- secsgem/secs/data_items/ecmax.py +44 -0
- secsgem/secs/data_items/ecmin.py +44 -0
- secsgem/secs/data_items/ecname.py +16 -0
- secsgem/secs/data_items/ecv.py +47 -0
- secsgem/secs/data_items/edid.py +38 -0
- secsgem/secs/data_items/erack.py +32 -0
- secsgem/secs/data_items/errcode.py +180 -0
- secsgem/secs/data_items/errtext.py +23 -0
- secsgem/secs/data_items/exid.py +24 -0
- secsgem/secs/data_items/exmessage.py +17 -0
- secsgem/secs/data_items/exrecvra.py +19 -0
- secsgem/secs/data_items/extype.py +17 -0
- secsgem/secs/data_items/fcnid.py +19 -0
- secsgem/secs/data_items/ffrot.py +19 -0
- secsgem/secs/data_items/fnloc.py +20 -0
- secsgem/secs/data_items/grant6.py +35 -0
- secsgem/secs/data_items/grnt1.py +47 -0
- secsgem/secs/data_items/hcack.py +48 -0
- secsgem/secs/data_items/idtyp.py +47 -0
- secsgem/secs/data_items/length.py +34 -0
- secsgem/secs/data_items/limitack.py +50 -0
- secsgem/secs/data_items/limitid.py +20 -0
- secsgem/secs/data_items/limitmax.py +44 -0
- secsgem/secs/data_items/limitmin.py +44 -0
- secsgem/secs/data_items/lowerdb.py +45 -0
- secsgem/secs/data_items/lrack.py +44 -0
- secsgem/secs/data_items/lvack.py +41 -0
- secsgem/secs/data_items/maper.py +35 -0
- secsgem/secs/data_items/mapft.py +36 -0
- secsgem/secs/data_items/mdack.py +40 -0
- secsgem/secs/data_items/mdln.py +20 -0
- secsgem/secs/data_items/mexp.py +18 -0
- secsgem/secs/data_items/mhead.py +22 -0
- secsgem/secs/data_items/mid.py +36 -0
- secsgem/secs/data_items/mlcl.py +27 -0
- secsgem/secs/data_items/nulbc.py +24 -0
- secsgem/secs/data_items/objack.py +33 -0
- secsgem/secs/data_items/objid.py +31 -0
- secsgem/secs/data_items/objspec.py +18 -0
- secsgem/secs/data_items/objtype.py +29 -0
- secsgem/secs/data_items/oflack.py +29 -0
- secsgem/secs/data_items/onlack.py +35 -0
- secsgem/secs/data_items/orloc.py +43 -0
- secsgem/secs/data_items/pparm.py +45 -0
- secsgem/secs/data_items/ppbody.py +39 -0
- secsgem/secs/data_items/ppgnt.py +44 -0
- secsgem/secs/data_items/ppid.py +30 -0
- secsgem/secs/data_items/praxi.py +51 -0
- secsgem/secs/data_items/prdct.py +27 -0
- secsgem/secs/data_items/ptn.py +27 -0
- secsgem/secs/data_items/rcmd.py +26 -0
- secsgem/secs/data_items/refp.py +27 -0
- secsgem/secs/data_items/repgsz.py +36 -0
- secsgem/secs/data_items/rowct.py +27 -0
- secsgem/secs/data_items/rpsel.py +17 -0
- secsgem/secs/data_items/rptid.py +41 -0
- secsgem/secs/data_items/rsda.py +35 -0
- secsgem/secs/data_items/rsdc.py +32 -0
- secsgem/secs/data_items/rsinf.py +29 -0
- secsgem/secs/data_items/rspack.py +32 -0
- secsgem/secs/data_items/sdack.py +29 -0
- secsgem/secs/data_items/sdbin.py +32 -0
- secsgem/secs/data_items/shead.py +18 -0
- secsgem/secs/data_items/smpln.py +34 -0
- secsgem/secs/data_items/softrev.py +15 -0
- secsgem/secs/data_items/stime.py +16 -0
- secsgem/secs/data_items/strack.py +36 -0
- secsgem/secs/data_items/strid.py +19 -0
- secsgem/secs/data_items/strp.py +29 -0
- secsgem/secs/data_items/sv.py +47 -0
- secsgem/secs/data_items/svid.py +39 -0
- secsgem/secs/data_items/svname.py +16 -0
- secsgem/secs/data_items/text.py +39 -0
- secsgem/secs/data_items/tiaack.py +44 -0
- secsgem/secs/data_items/tiack.py +30 -0
- secsgem/secs/data_items/tid.py +19 -0
- secsgem/secs/data_items/time.py +18 -0
- secsgem/secs/data_items/timestamp.py +20 -0
- secsgem/secs/data_items/totsmp.py +36 -0
- secsgem/secs/data_items/trid.py +37 -0
- secsgem/secs/data_items/units.py +19 -0
- secsgem/secs/data_items/upperdb.py +45 -0
- secsgem/secs/data_items/v.py +49 -0
- secsgem/secs/data_items/vid.py +44 -0
- secsgem/secs/data_items/vlaack.py +35 -0
- secsgem/secs/data_items/xdies.py +31 -0
- secsgem/secs/data_items/xypos.py +29 -0
- secsgem/secs/data_items/ydies.py +31 -0
- secsgem/secs/functions/__init__.py +293 -0
- secsgem/secs/functions/_all.py +288 -0
- secsgem/secs/functions/base.py +200 -0
- secsgem/secs/functions/s00f00.py +31 -0
- secsgem/secs/functions/s01f00.py +31 -0
- secsgem/secs/functions/s01f01.py +31 -0
- secsgem/secs/functions/s01f02.py +62 -0
- secsgem/secs/functions/s01f03.py +46 -0
- secsgem/secs/functions/s01f04.py +46 -0
- secsgem/secs/functions/s01f11.py +47 -0
- secsgem/secs/functions/s01f12.py +66 -0
- secsgem/secs/functions/s01f13.py +62 -0
- secsgem/secs/functions/s01f14.py +79 -0
- secsgem/secs/functions/s01f15.py +31 -0
- secsgem/secs/functions/s01f16.py +39 -0
- secsgem/secs/functions/s01f17.py +31 -0
- secsgem/secs/functions/s01f18.py +39 -0
- secsgem/secs/functions/s01f21.py +45 -0
- secsgem/secs/functions/s01f22.py +60 -0
- secsgem/secs/functions/s01f23.py +45 -0
- secsgem/secs/functions/s01f24.py +66 -0
- secsgem/secs/functions/s02f00.py +31 -0
- secsgem/secs/functions/s02f13.py +47 -0
- secsgem/secs/functions/s02f14.py +45 -0
- secsgem/secs/functions/s02f15.py +62 -0
- secsgem/secs/functions/s02f16.py +39 -0
- secsgem/secs/functions/s02f17.py +31 -0
- secsgem/secs/functions/s02f18.py +39 -0
- secsgem/secs/functions/s02f21.py +39 -0
- secsgem/secs/functions/s02f22.py +39 -0
- secsgem/secs/functions/s02f23.py +72 -0
- secsgem/secs/functions/s02f24.py +39 -0
- secsgem/secs/functions/s02f25.py +39 -0
- secsgem/secs/functions/s02f26.py +39 -0
- secsgem/secs/functions/s02f29.py +47 -0
- secsgem/secs/functions/s02f30.py +92 -0
- secsgem/secs/functions/s02f31.py +17 -0
- secsgem/secs/functions/s02f32.py +17 -0
- secsgem/secs/functions/s02f33.py +80 -0
- secsgem/secs/functions/s02f34.py +39 -0
- secsgem/secs/functions/s02f35.py +72 -0
- secsgem/secs/functions/s02f36.py +39 -0
- secsgem/secs/functions/s02f37.py +54 -0
- secsgem/secs/functions/s02f38.py +39 -0
- secsgem/secs/functions/s02f41.py +72 -0
- secsgem/secs/functions/s02f42.py +75 -0
- secsgem/secs/functions/s02f43.py +69 -0
- secsgem/secs/functions/s02f44.py +86 -0
- secsgem/secs/functions/s02f45.py +101 -0
- secsgem/secs/functions/s02f46.py +89 -0
- secsgem/secs/functions/s02f47.py +45 -0
- secsgem/secs/functions/s02f48.py +106 -0
- secsgem/secs/functions/s02f49.py +82 -0
- secsgem/secs/functions/s02f50.py +75 -0
- secsgem/secs/functions/s03f17.py +34 -0
- secsgem/secs/functions/s03f18.py +30 -0
- secsgem/secs/functions/s05f00.py +31 -0
- secsgem/secs/functions/s05f01.py +57 -0
- secsgem/secs/functions/s05f02.py +39 -0
- secsgem/secs/functions/s05f03.py +49 -0
- secsgem/secs/functions/s05f04.py +39 -0
- secsgem/secs/functions/s05f05.py +45 -0
- secsgem/secs/functions/s05f06.py +64 -0
- secsgem/secs/functions/s05f07.py +31 -0
- secsgem/secs/functions/s05f08.py +64 -0
- secsgem/secs/functions/s05f09.py +72 -0
- secsgem/secs/functions/s05f10.py +31 -0
- secsgem/secs/functions/s05f11.py +61 -0
- secsgem/secs/functions/s05f12.py +31 -0
- secsgem/secs/functions/s05f13.py +49 -0
- secsgem/secs/functions/s05f14.py +73 -0
- secsgem/secs/functions/s05f15.py +81 -0
- secsgem/secs/functions/s05f16.py +31 -0
- secsgem/secs/functions/s05f17.py +39 -0
- secsgem/secs/functions/s05f18.py +75 -0
- secsgem/secs/functions/s06f00.py +31 -0
- secsgem/secs/functions/s06f01.py +67 -0
- secsgem/secs/functions/s06f02.py +39 -0
- secsgem/secs/functions/s06f05.py +49 -0
- secsgem/secs/functions/s06f06.py +39 -0
- secsgem/secs/functions/s06f07.py +39 -0
- secsgem/secs/functions/s06f08.py +100 -0
- secsgem/secs/functions/s06f11.py +82 -0
- secsgem/secs/functions/s06f12.py +39 -0
- secsgem/secs/functions/s06f15.py +39 -0
- secsgem/secs/functions/s06f16.py +82 -0
- secsgem/secs/functions/s06f19.py +39 -0
- secsgem/secs/functions/s06f20.py +45 -0
- secsgem/secs/functions/s06f21.py +39 -0
- secsgem/secs/functions/s06f22.py +60 -0
- secsgem/secs/functions/s06f23.py +39 -0
- secsgem/secs/functions/s06f24.py +39 -0
- secsgem/secs/functions/s07f00.py +31 -0
- secsgem/secs/functions/s07f01.py +49 -0
- secsgem/secs/functions/s07f02.py +39 -0
- secsgem/secs/functions/s07f03.py +49 -0
- secsgem/secs/functions/s07f04.py +39 -0
- secsgem/secs/functions/s07f05.py +39 -0
- secsgem/secs/functions/s07f06.py +49 -0
- secsgem/secs/functions/s07f17.py +45 -0
- secsgem/secs/functions/s07f18.py +39 -0
- secsgem/secs/functions/s07f19.py +31 -0
- secsgem/secs/functions/s07f20.py +45 -0
- secsgem/secs/functions/s07f23.py +32 -0
- secsgem/secs/functions/s07f24.py +21 -0
- secsgem/secs/functions/s07f25.py +39 -0
- secsgem/secs/functions/s07f26.py +36 -0
- secsgem/secs/functions/s09f00.py +31 -0
- secsgem/secs/functions/s09f01.py +39 -0
- secsgem/secs/functions/s09f03.py +39 -0
- secsgem/secs/functions/s09f05.py +39 -0
- secsgem/secs/functions/s09f07.py +39 -0
- secsgem/secs/functions/s09f09.py +39 -0
- secsgem/secs/functions/s09f11.py +39 -0
- secsgem/secs/functions/s09f13.py +49 -0
- secsgem/secs/functions/s10f00.py +31 -0
- secsgem/secs/functions/s10f01.py +49 -0
- secsgem/secs/functions/s10f02.py +39 -0
- secsgem/secs/functions/s10f03.py +49 -0
- secsgem/secs/functions/s10f04.py +39 -0
- secsgem/secs/functions/s12f00.py +31 -0
- secsgem/secs/functions/s12f01.py +138 -0
- secsgem/secs/functions/s12f02.py +39 -0
- secsgem/secs/functions/s12f03.py +86 -0
- secsgem/secs/functions/s12f04.py +138 -0
- secsgem/secs/functions/s12f05.py +61 -0
- secsgem/secs/functions/s12f06.py +39 -0
- secsgem/secs/functions/s12f07.py +79 -0
- secsgem/secs/functions/s12f08.py +39 -0
- secsgem/secs/functions/s12f09.py +61 -0
- secsgem/secs/functions/s12f10.py +39 -0
- secsgem/secs/functions/s12f11.py +79 -0
- secsgem/secs/functions/s12f12.py +39 -0
- secsgem/secs/functions/s12f13.py +49 -0
- secsgem/secs/functions/s12f14.py +79 -0
- secsgem/secs/functions/s12f15.py +49 -0
- secsgem/secs/functions/s12f16.py +61 -0
- secsgem/secs/functions/s12f17.py +56 -0
- secsgem/secs/functions/s12f18.py +79 -0
- secsgem/secs/functions/s12f19.py +49 -0
- secsgem/secs/functions/s14f00.py +31 -0
- secsgem/secs/functions/s14f01.py +95 -0
- secsgem/secs/functions/s14f02.py +133 -0
- secsgem/secs/functions/s14f03.py +86 -0
- secsgem/secs/functions/s14f04.py +133 -0
- secsgem/secs/functions/streams_functions.py +81 -0
- secsgem/secs/handler.py +302 -0
- secsgem/secs/variables/__init__.py +41 -0
- secsgem/secs/variables/array.py +196 -0
- secsgem/secs/variables/base.py +100 -0
- secsgem/secs/variables/base_number.py +214 -0
- secsgem/secs/variables/base_text.py +204 -0
- secsgem/secs/variables/binary.py +207 -0
- secsgem/secs/variables/boolean.py +209 -0
- secsgem/secs/variables/dynamic.py +253 -0
- secsgem/secs/variables/f4.py +22 -0
- secsgem/secs/variables/f8.py +22 -0
- secsgem/secs/variables/functions.py +57 -0
- secsgem/secs/variables/i1.py +22 -0
- secsgem/secs/variables/i2.py +22 -0
- secsgem/secs/variables/i4.py +22 -0
- secsgem/secs/variables/i8.py +22 -0
- secsgem/secs/variables/jis8.py +23 -0
- secsgem/secs/variables/list_type.py +249 -0
- secsgem/secs/variables/string.py +21 -0
- secsgem/secs/variables/u1.py +22 -0
- secsgem/secs/variables/u2.py +22 -0
- secsgem/secs/variables/u4.py +22 -0
- secsgem/secs/variables/u8.py +22 -0
- secsgempro-1.0.0.dist-info/METADATA +14 -0
- secsgempro-1.0.0.dist-info/RECORD +366 -0
- secsgempro-1.0.0.dist-info/WHEEL +4 -0
secsgem/common/header.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""header base class."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import abc
|
|
5
|
+
import typing
|
|
6
|
+
|
|
7
|
+
HeaderT = typing.TypeVar("HeaderT", bound="Header")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Header(abc.ABC):
|
|
11
|
+
"""Abstract base class for a message header."""
|
|
12
|
+
|
|
13
|
+
length = -1
|
|
14
|
+
|
|
15
|
+
def __init__( # pylint: disable=too-many-arguments
|
|
16
|
+
self,
|
|
17
|
+
system: int,
|
|
18
|
+
session_id: int,
|
|
19
|
+
stream: int,
|
|
20
|
+
function: int,
|
|
21
|
+
require_response: bool
|
|
22
|
+
):
|
|
23
|
+
"""Initialize a hsms header.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
system: message ID
|
|
27
|
+
session_id: device / session ID
|
|
28
|
+
stream: stream
|
|
29
|
+
function: function
|
|
30
|
+
require_response: True when a response is required
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
self._session_id = session_id
|
|
34
|
+
self._stream = stream
|
|
35
|
+
self._function = function
|
|
36
|
+
self._system = system
|
|
37
|
+
self._require_response = require_response
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def session_id(self) -> int:
|
|
42
|
+
"""Get session id."""
|
|
43
|
+
return self._session_id
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def stream(self) -> int:
|
|
47
|
+
"""Get stream."""
|
|
48
|
+
return self._stream
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def function(self) -> int:
|
|
52
|
+
"""Get function."""
|
|
53
|
+
return self._function
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def system(self) -> int:
|
|
57
|
+
"""Get system."""
|
|
58
|
+
return self._system
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def require_response(self) -> bool:
|
|
62
|
+
"""Get require response flag."""
|
|
63
|
+
return self._require_response
|
|
64
|
+
|
|
65
|
+
@abc.abstractmethod
|
|
66
|
+
def encode(self) -> bytes:
|
|
67
|
+
"""Encode header to message.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
encoded header
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
raise NotImplementedError("Header.encode missing implementation")
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
@abc.abstractmethod
|
|
77
|
+
def decode(cls, data: bytes) -> Header:
|
|
78
|
+
"""Decode byte array header to Header object.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
data: byte-encode header data
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
Header object
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
raise NotImplementedError("Header.decode missing implementation")
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
@abc.abstractmethod
|
|
91
|
+
def _as_dictionary(self) -> dict[str, typing.Any]:
|
|
92
|
+
"""Get the data as dictionary.
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
Header data as dictionary.
|
|
96
|
+
|
|
97
|
+
"""
|
|
98
|
+
raise NotImplementedError("Header._as_dictionary missing implementation")
|
|
99
|
+
|
|
100
|
+
def updated_with(self: HeaderT, **kwargs) -> HeaderT:
|
|
101
|
+
"""Get a new header with updated fields.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
kwargs: parameter name will update constructor field
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
new header with modified data
|
|
108
|
+
|
|
109
|
+
"""
|
|
110
|
+
data = self._as_dictionary
|
|
111
|
+
|
|
112
|
+
data.update(kwargs)
|
|
113
|
+
|
|
114
|
+
return self.__class__(**data)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Contains helper functions."""
|
|
2
|
+
import errno
|
|
3
|
+
import sys
|
|
4
|
+
import types
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def format_hex(text: bytes) -> str:
|
|
8
|
+
"""Return byte arrays (string) formated as hex numbers.
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
text: byte array
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
formated sring
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
>>> import secsgem.common
|
|
18
|
+
>>>
|
|
19
|
+
>>> data = b"asdfg"
|
|
20
|
+
>>> secsgem.common.format_hex(data)
|
|
21
|
+
'61:73:64:66:67'
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
return ":".join(f"{c:02x}" for c in bytearray(text))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def is_windows() -> bool:
|
|
28
|
+
"""Return True if running on windows.
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
True when running on a windows system
|
|
32
|
+
|
|
33
|
+
"""
|
|
34
|
+
if sys.platform == "win32":
|
|
35
|
+
return True
|
|
36
|
+
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def function_name(function) -> str:
|
|
41
|
+
"""Get name of function or method.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
function/method name
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
if isinstance(function, types.FunctionType):
|
|
48
|
+
return function.__name__
|
|
49
|
+
|
|
50
|
+
return function.__self__.__class__.__name__ + "." + function.__name__
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def indent_line(line: str, spaces: int = 2) -> str:
|
|
54
|
+
"""Indent line by a number of spaces.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
line: input text
|
|
58
|
+
spaces: number of spaces to prepend
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
indented text
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
return f"{' ' * spaces}{line}"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def indent_block(block: str, spaces: int = 2) -> str:
|
|
68
|
+
"""Indent a multiline string by a number of spaces.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
block: input text
|
|
72
|
+
spaces: number of spaces to prepend to each line
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
indented text
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
lines = block.split("\n")
|
|
79
|
+
lines_filter = filter(None, lines)
|
|
80
|
+
indented_lines = [indent_line(line, spaces) for line in lines_filter]
|
|
81
|
+
return "\n".join(indented_lines)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def is_errorcode_ewouldblock(errorcode: int) -> bool:
|
|
85
|
+
"""Check if the errorcode is a would-block error.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
errorcode: Code of the error
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
True if blocking error code
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
if errorcode in (errno.EAGAIN, errno.EWOULDBLOCK):
|
|
95
|
+
return True
|
|
96
|
+
|
|
97
|
+
return False
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Message base class."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import abc
|
|
5
|
+
import struct
|
|
6
|
+
import typing
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from .header import Header
|
|
10
|
+
|
|
11
|
+
BlockHeaderT = typing.TypeVar("BlockHeaderT", bound="Header")
|
|
12
|
+
BlockT = typing.TypeVar("BlockT", bound="Block")
|
|
13
|
+
|
|
14
|
+
MessageT = typing.TypeVar("MessageT", bound="Message")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Block(abc.ABC, typing.Generic[BlockHeaderT]):
|
|
18
|
+
"""Base class for data block."""
|
|
19
|
+
|
|
20
|
+
header_type: type[BlockHeaderT]
|
|
21
|
+
length_format: str
|
|
22
|
+
checksum_format: str
|
|
23
|
+
|
|
24
|
+
def __init__(self, header: BlockHeaderT, data: bytes):
|
|
25
|
+
"""Initialize a block header.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
header: block header
|
|
29
|
+
data: block data
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
self._header = header
|
|
33
|
+
self._data = data
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def header(self) -> BlockHeaderT:
|
|
37
|
+
"""Get the header."""
|
|
38
|
+
return self._header
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def data(self) -> bytes:
|
|
42
|
+
"""Get the data."""
|
|
43
|
+
return self._data
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def checksum(self) -> int:
|
|
47
|
+
"""Get the checksum."""
|
|
48
|
+
if self.checksum_format == "":
|
|
49
|
+
return 0
|
|
50
|
+
|
|
51
|
+
calculated_checksum = 0
|
|
52
|
+
|
|
53
|
+
for data_byte in self.header.encode() + self.data:
|
|
54
|
+
calculated_checksum += data_byte
|
|
55
|
+
|
|
56
|
+
return calculated_checksum
|
|
57
|
+
|
|
58
|
+
def encode(self) -> bytes:
|
|
59
|
+
"""Encode block data.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
byte-encoded block
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
data_length = len(self.data)
|
|
66
|
+
|
|
67
|
+
struct_args: tuple = (
|
|
68
|
+
self.header.length + data_length,
|
|
69
|
+
self.header.encode(),
|
|
70
|
+
self.data,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
if self.checksum_format != "":
|
|
74
|
+
struct_args += (self.checksum, )
|
|
75
|
+
|
|
76
|
+
return struct.pack(
|
|
77
|
+
f">{self.length_format}{self.header.length}s{data_length}s{self.checksum_format}",
|
|
78
|
+
*struct_args,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def decode(cls: type[BlockT], data: bytes) -> BlockT | None:
|
|
83
|
+
"""Decode byte array hsms packet to HsmsPacket object.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
data: byte-encode packet data
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
received packet object
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
data_length = struct.unpack_from(f">{cls.length_format}", data)[0] - cls.header_type.length
|
|
93
|
+
|
|
94
|
+
data_fields = struct.unpack(
|
|
95
|
+
f">{cls.length_format}{cls.header_type.length}s{data_length}s{cls.checksum_format}",
|
|
96
|
+
data,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
header = cls.header_type.decode(data_fields[1])
|
|
100
|
+
|
|
101
|
+
obj = cls(header, data_fields[2])
|
|
102
|
+
|
|
103
|
+
if cls.checksum_format != "" and obj.checksum != data_fields[3]:
|
|
104
|
+
return None
|
|
105
|
+
|
|
106
|
+
return obj
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class Message(abc.ABC, typing.Generic[BlockT]):
|
|
110
|
+
"""Abstract base class for a message."""
|
|
111
|
+
|
|
112
|
+
block_size = -1
|
|
113
|
+
block_type: type[BlockT]
|
|
114
|
+
|
|
115
|
+
def __init__(self, header: BlockHeaderT, data: bytes):
|
|
116
|
+
"""Initialize a Message object.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
header: header used for this message
|
|
120
|
+
data: data part used for streams and functions (SType 0)
|
|
121
|
+
|
|
122
|
+
"""
|
|
123
|
+
self._blocks: list[BlockT] = self._split_blocks(data, header)
|
|
124
|
+
|
|
125
|
+
@classmethod
|
|
126
|
+
def _split_blocks(cls, data: bytes, header: BlockHeaderT) -> list[BlockT]:
|
|
127
|
+
if cls.block_size == -1:
|
|
128
|
+
return [cls.block_type(header, data)]
|
|
129
|
+
|
|
130
|
+
data_blocks = [data[i: i + cls.block_size] for i in range(0, len(data), cls.block_size)]
|
|
131
|
+
|
|
132
|
+
blocks = []
|
|
133
|
+
for index, block_data in enumerate(data_blocks):
|
|
134
|
+
header_data = {
|
|
135
|
+
"block": index + 1,
|
|
136
|
+
"last_block": (index + 1) == len(data_blocks),
|
|
137
|
+
}
|
|
138
|
+
block_header = header.updated_with(**header_data)
|
|
139
|
+
blocks.append(cls.block_type(block_header, block_data))
|
|
140
|
+
|
|
141
|
+
return blocks
|
|
142
|
+
|
|
143
|
+
@classmethod
|
|
144
|
+
def from_block(cls: type[MessageT], block: Block) -> MessageT:
|
|
145
|
+
"""Initialize Message object from Block object.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
block: block to initialize from
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
Message object
|
|
152
|
+
|
|
153
|
+
"""
|
|
154
|
+
return cls(block.header, block.data)
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
@abc.abstractmethod
|
|
158
|
+
def header(self) -> Header:
|
|
159
|
+
"""Get the header."""
|
|
160
|
+
raise NotImplementedError("Message.header missing implementation")
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
@abc.abstractmethod
|
|
164
|
+
def data(self) -> bytes:
|
|
165
|
+
"""Get the header."""
|
|
166
|
+
raise NotImplementedError("Message.data missing implementation")
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
@abc.abstractmethod
|
|
170
|
+
def complete(self) -> bool:
|
|
171
|
+
"""Check if the message is complete."""
|
|
172
|
+
raise NotImplementedError("Message.complete missing implementation")
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def blocks(self) -> list[BlockT]:
|
|
176
|
+
"""Get the blocks."""
|
|
177
|
+
return self._blocks
|
|
178
|
+
|
|
179
|
+
def __str__(self) -> str:
|
|
180
|
+
"""Generate string representation for an object of this class."""
|
|
181
|
+
return f"'header': {self.header} "
|
|
182
|
+
|
|
183
|
+
def __repr__(self) -> str:
|
|
184
|
+
"""Generate textual representation for an object of this class."""
|
|
185
|
+
return (
|
|
186
|
+
f"{self.__class__.__name__}"
|
|
187
|
+
f"({{'header': {self.header.__repr__()}, 'data': '{self.data.decode('utf-8')}'}})"
|
|
188
|
+
)
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"""protocol base class."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import abc
|
|
5
|
+
import logging
|
|
6
|
+
import queue
|
|
7
|
+
import random
|
|
8
|
+
import typing
|
|
9
|
+
|
|
10
|
+
from .block_send_info import BlockSendInfo
|
|
11
|
+
from .byte_queue import ByteQueue
|
|
12
|
+
from .events import EventProducer
|
|
13
|
+
from .protocol_dispatcher import ProtocolDispatcher
|
|
14
|
+
|
|
15
|
+
if typing.TYPE_CHECKING:
|
|
16
|
+
from ..secs.functions.base import SecsStreamFunction
|
|
17
|
+
from .connection import Connection
|
|
18
|
+
from .message import Message
|
|
19
|
+
from .settings import Settings
|
|
20
|
+
|
|
21
|
+
MessageT = typing.TypeVar("MessageT", bound="Message")
|
|
22
|
+
BlockT = typing.TypeVar("BlockT", bound="Block")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Protocol(abc.ABC, typing.Generic[MessageT, BlockT]): # pylint: disable=too-many-instance-attributes
|
|
26
|
+
"""Abstract base class for a protocol."""
|
|
27
|
+
|
|
28
|
+
message_type: type[MessageT]
|
|
29
|
+
|
|
30
|
+
def __init__(self, settings: Settings) -> None:
|
|
31
|
+
"""Initialize protocol base object."""
|
|
32
|
+
super().__init__()
|
|
33
|
+
|
|
34
|
+
self._settings = settings
|
|
35
|
+
|
|
36
|
+
self._event_producer = EventProducer()
|
|
37
|
+
self._event_producer.targets += self
|
|
38
|
+
|
|
39
|
+
self._system_counter = random.randint(0, (2 ** 32) - 1) # noqa: S311
|
|
40
|
+
|
|
41
|
+
self._logger = logging.getLogger(self.__module__ + "." + self.__class__.__name__)
|
|
42
|
+
self._communication_logger = logging.getLogger("communication")
|
|
43
|
+
|
|
44
|
+
self.__connection: Connection | None = None
|
|
45
|
+
|
|
46
|
+
self._response_queues: dict[int, queue.Queue[MessageT]] = {}
|
|
47
|
+
|
|
48
|
+
self._receive_buffer = ByteQueue()
|
|
49
|
+
self._send_queue: queue.Queue[BlockSendInfo] = queue.Queue()
|
|
50
|
+
self._incomplete_messages: dict[int, MessageT] = {}
|
|
51
|
+
|
|
52
|
+
self._thread = ProtocolDispatcher(
|
|
53
|
+
self._process_data,
|
|
54
|
+
self._dispatch_block,
|
|
55
|
+
self._settings,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def communication_logger(self):
|
|
60
|
+
return self._communication_logger
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def _connection(self) -> Connection:
|
|
64
|
+
if self.__connection is None:
|
|
65
|
+
self.__connection = self._settings.create_connection()
|
|
66
|
+
self.__connection.on_connected.register(self._on_connected)
|
|
67
|
+
self.__connection.on_data.register(self._on_connection_data_received)
|
|
68
|
+
self.__connection.on_disconnecting.register(self._on_disconnecting)
|
|
69
|
+
self.__connection.on_disconnected.register(self._on_disconnected)
|
|
70
|
+
|
|
71
|
+
return self.__connection
|
|
72
|
+
|
|
73
|
+
@abc.abstractmethod
|
|
74
|
+
def _on_connected(self, _: dict[str, typing.Any]):
|
|
75
|
+
raise NotImplementedError("Protocol._on_connected missing implementation")
|
|
76
|
+
|
|
77
|
+
@abc.abstractmethod
|
|
78
|
+
def _on_disconnecting(self, _: dict[str, typing.Any]):
|
|
79
|
+
raise NotImplementedError("Protocol._on_disconnecting missing implementation")
|
|
80
|
+
|
|
81
|
+
@abc.abstractmethod
|
|
82
|
+
def _on_disconnected(self, _: dict[str, typing.Any]):
|
|
83
|
+
raise NotImplementedError("Protocol._on_disconnected missing implementation")
|
|
84
|
+
|
|
85
|
+
def _on_connection_data_received(self, data: dict[str, typing.Any]):
|
|
86
|
+
"""Data received by connection.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
data: received data
|
|
90
|
+
|
|
91
|
+
"""
|
|
92
|
+
self._receive_buffer.append(data["data"])
|
|
93
|
+
self._thread.trigger_receiver()
|
|
94
|
+
|
|
95
|
+
def _process_data(self):
|
|
96
|
+
"""Parse the receiving buffer and dispatch callbacks."""
|
|
97
|
+
self._process_send_queue()
|
|
98
|
+
self._process_received_data()
|
|
99
|
+
|
|
100
|
+
@abc.abstractmethod
|
|
101
|
+
def _process_send_queue(self):
|
|
102
|
+
"""Process the send to communication queue."""
|
|
103
|
+
raise NotImplementedError("Protocol._process_send_queue missing implementation")
|
|
104
|
+
|
|
105
|
+
@abc.abstractmethod
|
|
106
|
+
def _process_received_data(self):
|
|
107
|
+
"""Process the receiving from communication queue."""
|
|
108
|
+
raise NotImplementedError("Protocol._process_received_data missing implementation")
|
|
109
|
+
|
|
110
|
+
def _dispatch_block(self, source: object, block: BlockT):
|
|
111
|
+
result = self._add_message_block(block)
|
|
112
|
+
if result is None:
|
|
113
|
+
return
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
self._on_connection_message_received(source, result)
|
|
117
|
+
except Exception: # pylint: disable=broad-except
|
|
118
|
+
self._logger.exception("ignoring exception for on_connection_message_received handler")
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def events(self):
|
|
122
|
+
"""Property for event handling."""
|
|
123
|
+
return self._event_producer
|
|
124
|
+
|
|
125
|
+
def get_next_system_counter(self):
|
|
126
|
+
"""Return the next System.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
System for the next command
|
|
130
|
+
|
|
131
|
+
"""
|
|
132
|
+
self._system_counter += 1
|
|
133
|
+
|
|
134
|
+
if self._system_counter > ((2 ** 32) - 1):
|
|
135
|
+
self._system_counter = 0
|
|
136
|
+
|
|
137
|
+
return self._system_counter
|
|
138
|
+
|
|
139
|
+
def enable(self):
|
|
140
|
+
"""Enable the connection."""
|
|
141
|
+
self._connection.enable()
|
|
142
|
+
|
|
143
|
+
def disable(self):
|
|
144
|
+
"""Disable the connection."""
|
|
145
|
+
self._connection.disable()
|
|
146
|
+
|
|
147
|
+
@abc.abstractmethod
|
|
148
|
+
def serialize_data(self) -> dict[str, typing.Any]:
|
|
149
|
+
"""Get protocol serialized data for debugging."""
|
|
150
|
+
raise NotImplementedError("Protocol.serialize_data missing implementation")
|
|
151
|
+
|
|
152
|
+
@abc.abstractmethod
|
|
153
|
+
def _on_connection_message_received(self, source: object, message: MessageT):
|
|
154
|
+
"""Message received by connection.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
source: source of event
|
|
158
|
+
message: received data message
|
|
159
|
+
|
|
160
|
+
"""
|
|
161
|
+
raise NotImplementedError("Protocol._on_connection_message_received missing implementation")
|
|
162
|
+
|
|
163
|
+
def _get_queue_for_system(self, system_id: int) -> queue.Queue:
|
|
164
|
+
"""Create a new queue to receive responses for a certain system.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
system_id: system id to watch
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
queue to receive responses with
|
|
171
|
+
|
|
172
|
+
"""
|
|
173
|
+
self._response_queues[system_id] = queue.Queue()
|
|
174
|
+
return self._response_queues[system_id]
|
|
175
|
+
|
|
176
|
+
def _remove_queue(self, system_id: int):
|
|
177
|
+
"""Remove queue for system id from list.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
system_id: system id to remove
|
|
181
|
+
|
|
182
|
+
"""
|
|
183
|
+
del self._response_queues[system_id]
|
|
184
|
+
|
|
185
|
+
def _add_message_block(self, block: BlockT) -> MessageT | None:
|
|
186
|
+
"""Add a block, and get completed message if available.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
block: block to add
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
completed message or None if paket not complete
|
|
193
|
+
|
|
194
|
+
"""
|
|
195
|
+
if block.header.system not in self._incomplete_messages:
|
|
196
|
+
self._incomplete_messages[block.header.system] = self.message_type.from_block(block)
|
|
197
|
+
else:
|
|
198
|
+
self._incomplete_messages[block.header.system].blocks.append(block)
|
|
199
|
+
|
|
200
|
+
message = self._incomplete_messages[block.header.system]
|
|
201
|
+
|
|
202
|
+
if not message.complete:
|
|
203
|
+
return None
|
|
204
|
+
|
|
205
|
+
del self._incomplete_messages[block.header.system]
|
|
206
|
+
return message
|
|
207
|
+
|
|
208
|
+
@abc.abstractmethod
|
|
209
|
+
def _create_message_for_function(
|
|
210
|
+
self,
|
|
211
|
+
function: SecsStreamFunction,
|
|
212
|
+
system_id: int,
|
|
213
|
+
) -> Message:
|
|
214
|
+
"""Create a protocol specific message for a function.
|
|
215
|
+
|
|
216
|
+
Args:
|
|
217
|
+
function: function to create message for
|
|
218
|
+
system_id: system
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
created message
|
|
222
|
+
|
|
223
|
+
"""
|
|
224
|
+
raise NotImplementedError("Protocol._create_message_for_function missing implementation")
|
|
225
|
+
|
|
226
|
+
def send_message(self, message: Message) -> bool:
|
|
227
|
+
"""Send a message to the remote host.
|
|
228
|
+
|
|
229
|
+
Args:
|
|
230
|
+
message: message to be transmitted
|
|
231
|
+
|
|
232
|
+
Returns:
|
|
233
|
+
True if sending was successful
|
|
234
|
+
|
|
235
|
+
"""
|
|
236
|
+
for block in message.blocks:
|
|
237
|
+
block_send_info = BlockSendInfo(block.encode())
|
|
238
|
+
self._send_queue.put(block_send_info)
|
|
239
|
+
self._thread.trigger_receiver()
|
|
240
|
+
|
|
241
|
+
if not block_send_info.wait():
|
|
242
|
+
return False
|
|
243
|
+
|
|
244
|
+
return True
|
|
245
|
+
|
|
246
|
+
def send_and_waitfor_response(self, function: SecsStreamFunction) -> Message | None:
|
|
247
|
+
"""Send the message and wait for the response.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
function: message to be sent
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
Message that was received
|
|
254
|
+
|
|
255
|
+
"""
|
|
256
|
+
system_id = self.get_next_system_counter()
|
|
257
|
+
|
|
258
|
+
response_queue = self._get_queue_for_system(system_id)
|
|
259
|
+
|
|
260
|
+
out_message = self._create_message_for_function(function, system_id)
|
|
261
|
+
|
|
262
|
+
self._communication_logger.info("> %s\n%s", out_message, function, extra=self._get_log_extra())
|
|
263
|
+
|
|
264
|
+
if not self.send_message(out_message):
|
|
265
|
+
self._logger.error("Sending message failed")
|
|
266
|
+
self._remove_queue(system_id)
|
|
267
|
+
return None
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
response = response_queue.get(True, self._settings.timeouts.t3)
|
|
271
|
+
except queue.Empty:
|
|
272
|
+
response = None
|
|
273
|
+
|
|
274
|
+
self._remove_queue(system_id)
|
|
275
|
+
|
|
276
|
+
return response
|
|
277
|
+
|
|
278
|
+
def send_response(self, function: SecsStreamFunction, system: int) -> bool:
|
|
279
|
+
"""Send response function for system.
|
|
280
|
+
|
|
281
|
+
Args:
|
|
282
|
+
function: function to be sent
|
|
283
|
+
system: system to reply to
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
True if sending was successful
|
|
287
|
+
|
|
288
|
+
"""
|
|
289
|
+
out_message = self._create_message_for_function(function, system)
|
|
290
|
+
|
|
291
|
+
self._communication_logger.info("> %s\n%s", out_message, function, extra=self._get_log_extra())
|
|
292
|
+
|
|
293
|
+
return self.send_message(out_message)
|
|
294
|
+
|
|
295
|
+
def send_stream_function(self, function: SecsStreamFunction) -> bool:
|
|
296
|
+
"""Send the message and wait for the response.
|
|
297
|
+
|
|
298
|
+
Args:
|
|
299
|
+
function: message to be sent
|
|
300
|
+
|
|
301
|
+
Returns:
|
|
302
|
+
True if successful
|
|
303
|
+
|
|
304
|
+
"""
|
|
305
|
+
out_message = self._create_message_for_function(function, self.get_next_system_counter())
|
|
306
|
+
|
|
307
|
+
self._communication_logger.info("> %s\n%s", out_message, function, extra=self._get_log_extra())
|
|
308
|
+
|
|
309
|
+
return self.send_message(out_message)
|
|
310
|
+
|
|
311
|
+
def __repr__(self):
|
|
312
|
+
"""Generate textual representation for an object of this class."""
|
|
313
|
+
return f"{self.__class__.__name__} {self.serialize_data()}"
|
|
314
|
+
|
|
315
|
+
@abc.abstractmethod
|
|
316
|
+
def _get_log_extra(self) -> dict[str, typing.Any]:
|
|
317
|
+
"""Get extra fields for logging."""
|
|
318
|
+
raise NotImplementedError("Protocol._get_log_extra missing implementation")
|