stringtools.csp (Carriage-Return seperation protocol)¶
Author:
Dirk Alders <sudo-dirk@mount-mockery.de>
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:
[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