maix.protocol
maix.protocol module
You can use
maix.protocolto access this module with MaixPy
This module is generated from MaixCDK
Module
No module
Enum
CMD
| item | doc |
|---|---|
| brief | protocol cmd, more doc see MaixCDK document's convention doc |
| 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_UPLOAD: 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_UPLOAD = 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
| item | doc |
|---|---|
| brief | protocol flags, more doc see MaixCDK document's convention doc |
| 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
| item | doc |
|---|---|
| brief | protocol version |
| value | 1 |
| readonly | True |
C++ defination code:
const uint8_t VERSION = 1
HEADER
| item | doc |
|---|---|
| brief | protocol header |
| value | 0xBBACCAAA |
| readonly | True |
C++ defination code:
const uint32_t HEADER = 0xBBACCAAA
Function
crc16_IBM
| item | doc |
|---|---|
| brief | CRC16-IBM |
| param | data: data, bytes type. |
| return | CRC16-IBM value, uint16_t type. |
C++ defination code:
uint16_t crc16_IBM(const Bytes *data)
Class
MSG
| item | doc |
|---|---|
| brief | protocol msg |
C++ defination code:
class MSG
version
| item | doc |
|---|---|
| type | var |
| brief | protocol version |
| static | False |
| readonly | False |
C++ defination code:
uint8_t version
resp_ok
| item | doc |
|---|---|
| type | var |
| brief | Is success response or not, (only for response msg) |
| static | False |
| readonly | False |
C++ defination code:
uint8_t resp_ok
cmd
| item | doc |
|---|---|
| type | var |
| brief | CMD value |
| static | False |
| readonly | False |
C++ defination code:
uint8_t cmd
is_resp
| item | doc |
|---|---|
| type | var |
| brief | message is response or not, contrast with is_req |
| static | False |
| readonly | False |
C++ defination code:
bool is_resp
body_len
| item | doc |
|---|---|
| type | var |
| brief | Message body length, read only, use set_body() to update |
| 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)
| item | doc |
|---|---|
| type | func |
| brief | Encode response ok(success) message |
| 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)
| item | doc |
|---|---|
| type | func |
| brief | Encode proactively report message |
| 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)
| item | doc |
|---|---|
| type | func |
| brief | Encode response error message |
| 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
| item | doc |
|---|---|
| type | func |
| brief | Update message body |
| param | body_new: new body data |
| static | False |
C++ defination code:
void set_body(Bytes *body_new)
get_body
def get_body(*args, **kwargs)
| item | doc |
|---|---|
| type | func |
| brief | Get message body |
| return | message body, bytes type |
| static | False |
C++ defination code:
Bytes *get_body()
Protocol
| item | doc |
|---|---|
| brief | Communicate protocol |
C++ defination code:
class Protocol
__init__
| item | doc |
|---|---|
| type | func |
| brief | Construct a new Protocol object |
| param | buff_size: Data queue buffer size |
| static | False |
C++ defination code:
Protocol(int buff_size = 1024)
buff_size
| item | doc |
|---|---|
| type | func |
| brief | Data queue buffer size |
| static | False |
C++ defination code:
int buff_size()
push_data
| item | doc |
|---|---|
| type | func |
| brief | Add data to data queue |
| 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
| item | doc |
|---|---|
| type | func |
| brief | Decode data in data queue and return a message |
| 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
| item | doc |
|---|---|
| type | func |
| brief | Encode response ok(success) message to buffer |
| 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
| item | doc |
|---|---|
| type | func |
| brief | Encode proactively report message to buffer |
| 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
| item | doc |
|---|---|
| type | func |
| brief | Encode response error message to buffer |
| 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)