maix.protocol

maix.protocol module

You can use maix.protocol to access this module with MaixPy
This module is generated from MaixPy and MaixCDK

Module

No module

Enum

CMD

protocol cmd, more doc see MaixCDK document's convention doc

item describe
note max app custom CMD value should < CMD_APP_MAX
values CMD_APP_MAX: 200, max app custom CMD value should < CMD_APP_MAX
CMD_SET_REPORT: set auto upload data mode
CMD_APP_LIST:
CMD_START_APP:
CMD_EXIT_APP:
CMD_CUR_APP_INFO:
CMD_APP_INFO:
CMD_KEY:
CMD_TOUCH:

C++ defination code:

enum CMD
        {
            CMD_APP_MAX = 0xC8,     //  200, max app custom CMD value should < CMD_APP_MAX

            CMD_SET_REPORT   = 0xF8, // set auto upload data mode
            CMD_APP_LIST     = 0xF9,
            CMD_START_APP    = 0xFA,
            CMD_EXIT_APP     = 0xFB,
            CMD_CUR_APP_INFO = 0xFC,
            CMD_APP_INFO     = 0xFD,
            CMD_KEY          = 0xFE,
            CMD_TOUCH        = 0xFF,
        }

FLAGS

protocol flags, more doc see MaixCDK document's convention doc

item describe
values FLAG_REQ:
FLAG_RESP:
FLAG_IS_RESP_MASK:
FLAG_RESP_OK:
FLAG_RESP_ERR:
FLAG_RESP_OK_MASK:
FLAG_REPORT:
FLAG_REPORT_MASK:
FLAG_VERSION_MASK:

C++ defination code:

enum FLAGS
        {
            FLAG_REQ = 0x00,
            FLAG_RESP = 0x80,
            FLAG_IS_RESP_MASK = 0x80,

            FLAG_RESP_OK = 0x40,
            FLAG_RESP_ERR = 0x00,
            FLAG_RESP_OK_MASK = 0x40,

            FLAG_REPORT = 0x20,
            FLAG_REPORT_MASK = 0x20,

            FLAG_VERSION_MASK = 0x03
        }

Variable

VERSION

protocol version

item description
value 1
readonly True

C++ defination code:

const uint8_t VERSION = 1

protocol header

item description
readonly False

C++ defination code:

extern uint32_t HEADER

Function

crc16_IBM

def crc16_IBM(data: maix.Bytes(bytes)) -> int

CRC16-IBM

item description
param data: data, bytes type.
return CRC16-IBM value, uint16_t type.

C++ defination code:

uint16_t crc16_IBM(const Bytes *data)

Class

MSG

protocol msg

C++ defination code:

class MSG

version

protocol version

item description
type var
static False
readonly False

C++ defination code:

uint8_t version

resp_ok

Is success response or not, (only for response msg)

item description
type var
static False
readonly False

C++ defination code:

uint8_t resp_ok

has_been_replied

Whether or not it has been replied to.

item description
type var
static False
readonly False

C++ defination code:

bool has_been_replied{false}

cmd

CMD value

item description
type var
static False
readonly False

C++ defination code:

uint8_t cmd

is_resp

message is response or not, contrast with is_req

item description
type var
static False
readonly False

C++ defination code:

bool is_resp

body_len

Message body length, read only, use set_body() to update

item description
type var
attention DO NOT manually change this value
static False
readonly False

C++ defination code:

int body_len

encode_resp_ok

def encode_resp_ok(*args, **kwargs)

Encode response ok(success) message

item description
type func
param body: response body, can be null
return encoded data, if nullptr, means error, and the error code is -err.Err
static False

C++ defination code:

Bytes *encode_resp_ok(Bytes *body = nullptr)

encode_report

def encode_report(*args, **kwargs)

Encode proactively report message

item description
type func
param body: report body, can be null
return encoded data, if nullptr, means error, and the error code is -err.Err
static False

C++ defination code:

Bytes *encode_report(Bytes *body = nullptr)

encode_resp_err

def encode_resp_err(*args, **kwargs)

Encode response error message

item description
type func
param code: error code
msg: error message
return encoded data, if nullptr, means error, and the error code is -err.Err
static False

C++ defination code:

Bytes *encode_resp_err(err::Err code, const std::string &msg)

set_body

def set_body(self, body_new: maix.Bytes(bytes)) -> None

Update message body

item description
type func
param body_new: new body data
static False

C++ defination code:

void set_body(Bytes *body_new)

get_body

def get_body(*args, **kwargs)

Get message body

item description
type func
return message body, bytes type
static False

C++ defination code:

Bytes *get_body()

Protocol

Communicate protocol

C++ defination code:

class Protocol

__init__

def __init__(self, buff_size: int = 1024, header: int = 3148663466) -> None

Construct a new Protocol object

item description
type func
param buff_size: Data queue buffer size
static False

C++ defination code:

Protocol(int buff_size = 1024, uint32_t header=maix::protocol::HEADER)

buff_size

def buff_size(self) -> int

Data queue buffer size

item description
type func
static False

C++ defination code:

int buff_size()

push_data

def push_data(self, new_data: maix.Bytes(bytes)) -> maix.err.Err

Add data to data queue

item description
type func
param new_data: new data
return error code, maybe err.Err.ERR_BUFF_FULL
static False

C++ defination code:

err::Err push_data(const Bytes *new_data)

decode

def decode(self, new_data: maix.Bytes(bytes) = None) -> MSG

Decode data in data queue and return a message

item description
type func
param new_data: new data add to data queue, if null, only decode.
return decoded message, if nullptr, means no message decoded.
static False

C++ defination code:

protocol::MSG *decode(const Bytes *new_data = nullptr)

encode_resp_ok

def encode_resp_ok(*args, **kwargs)

Encode response ok(success) message to buffer

item description
type func
param cmd: CMD value
body: response body, can be null
return encoded data, if nullptr, means error, and the error code is -err.Err
static False

C++ defination code:

Bytes *encode_resp_ok(uint8_t cmd, Bytes *body = nullptr)

encode_report

def encode_report(*args, **kwargs)

Encode proactively report message to buffer

item description
type func
param cmd: CMD value
body: report body, can be null
return encoded data, if nullptr, means error, and the error code is -err.Err
static False

C++ defination code:

Bytes *encode_report(uint8_t cmd, Bytes *body = nullptr)

encode_resp_err

def encode_resp_err(*args, **kwargs)

Encode response error message to buffer

item description
type func
param cmd: CMD value
code: error code
msg: error message
return encoded data, if nullptr, means error, and the error code is -err.Err
static False

C++ defination code:

Bytes *encode_resp_err(uint8_t cmd, err::Err code, const std::string &msg)