framing

Support for FreeWili serial framing.

class freewili.framing.ResponseFrame(rf_type: ResponseFrameType, rf_type_data: str, timestamp: int, seq_number: int, response: str, success: int, _raw: str)

Bases: object

Response Frame from a FreeWili serial.

static contains_end_of_frame(data: bytes | str) tuple[bool, int]

Identify if the data contains the end of a frame.

Parameters:

databytes:

data buffer to check.

Returns:

tuple[bool, int]:

True if contains end of frame, False otherwise. Also returns the index of the end of frame.

static contains_start_of_frame(data: bytes | str) tuple[bool, int]

Identify if the data contains the start of a frame.

Parameters:

databytes:

data buffer to check.

Returns:

tuple[bool, int]:

True if contains start of frame, False otherwise. Also returns the index of the start of frame.

classmethod from_raw(frame: str | bytes, strict: bool = True) Ok[Self] | Err[str]

Take a response frame string and create a ResponseFrame.

Parameters:

framestr

response frame string to decode.

strictbool

allows the timestamp to be invalid.

Returns:

Result[ResponseFrame, str]:

Ok(ResponseFrame) if decoded successfully, Err(str) if not.

static is_frame(frame: bytes | str) bool

Identify if the frame value is something we can parse.

Parameters:

framebytes | str:

response frame string to decode.

Returns:

bool:

True if is a frame, False otherwise.

is_ok() bool

Validates if the frame was successful.

Parameters:

None

Returns:

bool:

True if success == 1, False otherwise.

static is_start_of_frame(data: bytes | str) bool

Identify if the frame value is something we might be able to parse when complete.

Parameters:

framebytes | str:

response frame string to decode.

Returns:

bool:

True if is a frame, False otherwise.

response: str
response_as_bytes(check_ok: bool = True) Ok[bytes] | Err[str]

Convert the response into bytes.

Parameters:

check_ok: bool

Calls is_ok() to make sure the frame is valid.

Returns:

Result[bytes, str]:

Ok(bytes) if valid, False if data couldn’t be converted.

rf_type: ResponseFrameType
rf_type_data: str
seq_number: int
success: int
timestamp: int
timestamp_as_datetime(check_ok: bool = False) Ok[datetime64] | Err[str]

Convert the timestamp into a datetime.

Parameters:

check_ok: bool

Calls is_ok() to make sure the frame is valid.

Returns:

Result[np.datetime64, str]:

Ok(np.datetime64) if valid, Err(str) if timestamp couldn’t be converted.

static validate_start_of_frame(data: bytes | str) tuple[ResponseFrameType, int]

Validate that the data starts with a frame.

Parameters:

databytes | str:

data buffer to check.

Returns:

tuple[ResponseFrameType, int]:

Standard/Event if data has a start of frame, Invalid otherwise. Also returns the index of the start of frame. -1 if invalid.

class freewili.framing.ResponseFrameType(value)

Bases: Enum

FreeWili serial response frame types.

Event = 2
Invalid = 3
Standard = 1