stringtools.csp (Carriage-Return seperation protocol)

Author:

Description:

This module is a submodule of stringtools and creates an frame to transmit and receive messages via an serial interface.

Submodules:

stringtools.csp.build_frame(msg, seperator=b'\n')

This Method builds an “csp-frame” to be transfered via a stream.

Parameters:data (str) – A String (Bytes) to be framed
Returns:The “csp-framed” message to be sent
Return type:str

Example:

import sys
sys.path.append('../..')

import stringtools

data = b'message'
print(stringtools.hexlify(data))
print(stringtools.hexlify(stringtools.csp.build_frame(data)))

Will result to the following output:

(7): 6d 65 73 73 61 67 65
(8): 6d 65 73 73 61 67 65 0a
class stringtools.csp.csp(seperator=b'n')

This class extracts messages from an “csp-stream”.

Example:

import sys
sys.path.append('../..')

import report
import stringtools

report.stdoutLoggingConfigure(log_name_lvl=[('root', 'DEBUG'), ])
s = stringtools.csp.csp()
for byte in b'message\n':
    data = s.process(bytes([byte]))
    if len(data) > 0:
        print(data)

Will result to the following output:

2023-10-26 00:01:04,786: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (1): 6d
2023-10-26 00:01:04,787: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (2): 6d 65
2023-10-26 00:01:04,787: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (3): 6d 65 73
2023-10-26 00:01:04,787: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (4): 6d 65 73 73
2023-10-26 00:01:04,787: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (5): 6d 65 73 73 61
2023-10-26 00:01:04,787: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (6): 6d 65 73 73 61 67
2023-10-26 00:01:04,787: root.stringtools.csp - DEBUG - CSP: Leaving data in buffer (to be processed next time): (7): 6d 65 73 73 61 67 65
2023-10-26 00:01:04,787: root.stringtools.csp - INFO - CSP: message identified - (7): 6d 65 73 73 61 67 65
[b'message']
process(data)

This processes a byte out of a “stp-stream”.

Parameters:data (bytes) – A byte stream
Returns:A list of the extracted message(s)
Return type:list