Messages and blocks
A HSMS message secsgem.hsms.HsmsMessage consists of a header secsgem.hsms.HsmsHeader and a list of blocks secsgem.hsms.HsmsBlock.
It is initialized with a data field which is used to automatically generate the blocks. The blocks are parts of the data field, that are transmitted. For HSMS data only one block exists in a message, as the message doesn’t need to be split.
>>> secsgem.hsms.HsmsMessage(secsgem.hsms.HsmsLinktestReqHeader(2), b"")
HsmsMessage({'header': HsmsLinktestReqHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x05, system:0x00000002, require_response:False}), 'data': ''})
Every header has a system id to match the response to a certain request.
The system id is the first parameter to the headers constructor.
The connection keeps track of the system id, a new one can be requested with the secsgem.hsms.HsmsProtocol.get_next_system_counter() function.
HSMS block objects can encode themselves with the secsgem.hsms.HsmsBlock.encode() function to a byte array, which can be sent over the TCP connection.
>>> message = secsgem.hsms.HsmsMessage(secsgem.hsms.HsmsLinktestReqHeader(2), b"")
>>> secsgem.common.format_hex(message.blocks[0].encode())
'00:00:00:0a:ff:ff:00:00:00:05:00:00:00:02'
The other way around, a HSMS block object can be created from the byte array with the secsgem.hsms.HsmsBlock.decode() function.
>>> secsgem.hsms.HsmsBlock.decode(packetData)
<secsgem.hsms.message.HsmsBlock object at 0x1082c4f80>
There are classes inherited from secsgem.hsms.HsmsHeader for all HSMS packet types available:
Type |
Class |
SType |
|---|---|---|
1 |
||
2 |
||
3 |
||
4 |
||
5 |
||
6 |
||
7 |
||
9 |
||
0 |
Select Request
Establish HSMS communication
>>> secsgem.hsms.HsmsSelectReqHeader(14)
HsmsSelectReqHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x01, system:0x0000000e, require_response:False})
Select Response
Result of select request
>>> secsgem.hsms.HsmsSelectRspHeader(24)
HsmsSelectRspHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x02, system:0x00000018, require_response:False})
Deselect Request
Grateful close HSMS communication before disconnecting
>>> secsgem.hsms.HsmsDeselectReqHeader(1)
HsmsDeselectReqHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x03, system:0x00000001, require_response:False})
Deselect Response
Result of deselect request
>>> secsgem.hsms.HsmsDeselectRspHeader(1)
HsmsDeselectRspHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x04, system:0x00000001, require_response:False})
Linktest Request
Check the HSMS connection link is good
>>> secsgem.hsms.HsmsLinktestReqHeader(2)
HsmsLinktestReqHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x05, system:0x00000002, require_response:False})
Linktest Response
Result of linktest request
>>> secsgem.hsms.HsmsLinktestRspHeader(10)
HsmsLinktestRspHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x06, system:0x0000000a, require_response:False})
Reject Request
Response to unsupported HSMS message
>>> secsgem.hsms.HsmsRejectReqHeader(17, secsgem.hsms.HsmsSType.DESELECT_REQ, 4)
HsmsRejectReqHeader({device_id:0xffff, stream:03, function:04, p_type:0x00, s_type:0x07, system:0x00000011, require_response:False})
Separate Request
Immediate termination of the HSMS connection
>>> secsgem.hsms.HsmsSeparateReqHeader(17)
HsmsSeparateReqHeader({device_id:0xffff, stream:00, function:00, p_type:0x00, s_type:0x09, system:0x00000011, require_response:False})
Data Message
Secs stream and function message
>>> secsgem.hsms.HsmsStreamFunctionHeader(22, 1, 1, True, 100)
HsmsStreamFunctionHeader({device_id:0x0064, stream:01, function:01, p_type:0x00, s_type:0x00, system:0x00000016, require_response:True})