maix::protocol
maix.protocol module
This is
maix::protocol
module of MaixCDK.
All of these elements are in namespacemaix::protocol
.For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!
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
HEADER
protocol header
item | description |
---|---|
readonly | False |
C++ defination code:
extern uint32_t HEADER
Function
crc16_IBM
CRC16-IBM
item | description |
---|---|
param | data: data len: data length |
return | CRC16-IBM value, uint16_t type. |
C++ defination code:
uint16_t crc16_IBM(unsigned char *data, size_t len)
crc16_IBM (overload 1)
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)
encode
Encode message to buffer
item | description |
---|---|
param | out_buff: output buffer out_buff_len: output buffer length cmd: CMD value flags: FLAGS value, @see maix.protocol.FLAGS body: message body, can be null body_len: message body length, can be 0 code: error code, only for error message, that is FLAGS.FLAG_ERR in flags version: protocol version |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
C++ defination code:
int encode(uint8_t *out_buff, int out_buff_len, uint8_t cmd, uint8_t flags, uint8_t *body, int body_len, uint8_t code = 0xFF, const uint8_t version = VERSION)
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
Indicate response message type, true means CMD valid and the CMD processed correctly, (only for response msg)
item | description |
---|---|
type | var |
static | False |
readonly | False |
C++ defination code:
uint8_t resp_ok
has_been_replied
Flag whether CMD has been processed and responded to CMD sender.\nE.g. CMD CMD_START_APP will be automatically processed in CommProtocol.get_msg function,\nso the return msg will set this flag to true.
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
Message body, 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:
uint8_t *body
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
Encode response ok(success) message
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length body: response body, can be null body_len: response body length, can be 0 |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
static | False |
C++ defination code:
int encode_resp_ok(uint8_t *buff, int buff_len, uint8_t *body = nullptr, int body_len = 0)
encode_resp_ok (overload 1)
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(uint8_t *body = nullptr, int body_len = 0)
encode_resp_ok (overload 2)
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
Encode proactively report message
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length body: report body, can be null body_len: report body length, can be 0 |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
static | False |
C++ defination code:
int encode_report(uint8_t *buff, int buff_len, uint8_t *body = nullptr, int body_len = 0)
encode_report (overload 1)
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(uint8_t *body = nullptr, int body_len = 0)
encode_report (overload 2)
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
Encode response error message
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length code: error code msg: error message |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
static | False |
C++ defination code:
int encode_resp_err(uint8_t *buff, int buff_len, err::Err code, const std::string &msg)
encode_resp_err (overload 1)
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
Update message body
item | description |
---|---|
type | func |
param | body_new: new body data body_len: new body data length |
static | False |
C++ defination code:
void set_body(uint8_t *body_new, int body_len)
set_body (overload 1)
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
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
Protocol
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
Data queue buffer size
item | description |
---|---|
type | func |
static | False |
C++ defination code:
int buff_size()
push_data
Add data to data queue
item | description |
---|---|
type | func |
param | new_data: new data len: new data length |
return | error code, maybe err.Err.ERR_BUFF_FULL |
static | False |
C++ defination code:
err::Err push_data(uint8_t *new_data, int len)
push_data (overload 1)
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
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. len: new data length, can be 0. |
return | decoded message, if nullptr, means no message decoded. |
static | False |
C++ defination code:
protocol::MSG *decode(uint8_t *new_data = nullptr, size_t len = 0)
decode (overload 1)
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
Encode response ok(success) message to buffer
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length cmd: CMD value body: response body, can be null body_len: response body length, can be 0 |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
static | False |
C++ defination code:
int encode_resp_ok(uint8_t *buff, int buff_len, uint8_t cmd, uint8_t *body = nullptr, int body_len = 0)
encode_resp_ok (overload 1)
Encode response ok(success) message to buffer
item | description |
---|---|
type | func |
param | cmd: CMD value body: response body, can be null body_len: response body length, can be 0 |
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, uint8_t *body = nullptr, int body_len = 0)
encode_resp_ok (overload 2)
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
Encode proactively report message to buffer
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length cmd: CMD value body: report body, can be null body_len: report body length, can be 0 |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
static | False |
C++ defination code:
int encode_report(uint8_t *buff, int buff_len, uint8_t cmd, uint8_t *body = nullptr, int body_len = 0)
encode_report (overload 1)
Encode proactively report message to buffer
item | description |
---|---|
type | func |
param | cmd: CMD value body: report body, can be null body_len: report body length, can be 0 |
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, uint8_t *body = nullptr, int body_len = 0)
encode_report (overload 2)
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
Encode response error message to buffer
item | description |
---|---|
type | func |
param | buff: output buffer buff_len: output buffer length cmd: CMD value code: error code msg: error message |
return | encoded data length, if < 0, means error, and the error code is -err.Err |
static | False |
C++ defination code:
int encode_resp_err(uint8_t *buff, int buff_len, uint8_t cmd, err::Err code, const std::string &msg)
encode_resp_err (overload 1)
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)