From 9437ee2c755e34286bf9e892e083c4288199540e Mon Sep 17 00:00:00 2001 From: chentao9 Date: Fri, 13 Aug 2021 22:25:17 +0800 Subject: [PATCH 1/2] feature:cAT: add usrdata for cAT ack N/A add usrdata for cAT ack Signed-off-by: chentao9 --- src/cat.h | 3 ++ src/cat_usrdata.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ src/cat_usrdata.h | 67 +++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 src/cat_usrdata.c create mode 100644 src/cat_usrdata.h diff --git a/src/cat.h b/src/cat.h index c0d008f..f261baf 100644 --- a/src/cat.h +++ b/src/cat.h @@ -32,6 +32,9 @@ extern "C" { #include #include #include +#if CONFIG_LIB_CAT_USRDATA +#include "cat_usrdata.h" +#endif /* only forward declarations (looks for definition below) */ struct cat_command; diff --git a/src/cat_usrdata.c b/src/cat_usrdata.c new file mode 100644 index 0000000..ec08ea8 --- /dev/null +++ b/src/cat_usrdata.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * src/cat_usrdata.c + * + * Copyright (C) 2021 Xiaomi Corperation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include "cat.h" +#include "cat_usrdata.h" + +static cat_user_data_t cat_user_data; +/** + * @description:clear databuf + * @param {cat_user_data_ops_e} ops:read/write + * @param {cat_user_data_ack_e} ack:ok/error + * @return:success/fail + */ +bool cat_user_databuf_clear(cat_user_data_ops_e ops,cat_user_data_ack_e ack) +{ + assert(IS_DATA_OPS(ops)); + assert(IS_DATA_ACK(ack)); + memset((cat_user_data.data_buf[ops][ack].buf),0,WRITEBUF_LEN); + return true; +} + +/** + * @description:get databuf + * @param {cat_user_data_ops_e} ops:read/write + * @param {cat_user_data_ack_e} ack:ok/error + * @return:databuf pointer + */ +uint8_t *get_cat_user_databuf(cat_user_data_ops_e ops,cat_user_data_ack_e ack) +{ + assert(IS_DATA_OPS(ops)); + assert(IS_DATA_ACK(ack)); + return (uint8_t *)(cat_user_data.data_buf[ops][ack].buf); +} + +/** + * @description:get databuf size + * @param {cat_user_data_ops_e} ops:read/write + * @param {cat_user_data_ack_e} ack:ok/error + * @return:databuf size + */ +uint16_t get_cat_user_databuf_size(cat_user_data_ops_e ops,cat_user_data_ack_e ack) +{ + assert(IS_DATA_OPS(ops)); + assert(IS_DATA_ACK(ack)); + return sizeof(cat_user_data.data_buf[ops][ack].buf); +} + +/** + * @description:get errorcode + * @param {*} + * @return:errorcode + */ +uint16_t get_cat_user_databuf_errorcode(void) +{ + return cat_user_data.error_code; +} + +/** + * @description:set errorcode + * @param {uint16_t} val + * @return {*} + */ +void set_cat_user_databuf_errorcode(uint16_t val) +{ + cat_user_data.error_code = val; +} + +/** + * @description:userdata initialization + * @param {*} + * @return {*} + */ +void cat_user_data_init(void) +{ + memset(&cat_user_data,0,sizeof(cat_user_data)); +} diff --git a/src/cat_usrdata.h b/src/cat_usrdata.h new file mode 100644 index 0000000..9248e4b --- /dev/null +++ b/src/cat_usrdata.h @@ -0,0 +1,67 @@ +/**************************************************************************** + * src/cat_usrdata.h + * + * Copyright (C) 2021 Xiaomi Corperation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ****************************************************************************/ +#ifndef __CAT_USRDATA_H +#define __CAT_USRDATA_H + +/*user define*/ +#define WRITEBUF_LEN 256 +#define READBUF_LEN WRITEBUF_LEN +#define ACKBUF_LEN 512 + +/*cat user date buffer for write/read*/ +typedef enum { + CAT_USER_DATABUF_OPS_WRITE = 0, + CAT_USER_DATABUF_OPS_READ, + CAT_USER_DATABUF_OPS_MAX +} cat_user_data_ops_e; + +/*cat user date buffer for ack_ok/ack_error */ +typedef enum { + CAT_USER_DATABUF_ACK_OK = 0, + CAT_USER_DATABUF_ACK_ERR, + CAT_USER_DATABUF_ACK_MAX +} cat_user_data_ack_e; + +/*usr data buf*/ +typedef struct cat_user_databuf_s +{ + uint8_t buf[WRITEBUF_LEN]; +}cat_user_databuf_t; + +/*usr data struct*/ +typedef struct cat_user_data_s +{ + cat_user_databuf_t data_buf[CAT_USER_DATABUF_OPS_MAX][CAT_USER_DATABUF_ACK_MAX]; + uint16_t error_code; +}cat_user_data_t; + + +#define IS_DATA_OPS(n) ((CAT_USER_DATABUF_OPS_WRITE == n) || \ + (CAT_USER_DATABUF_OPS_READ == n)) + +#define IS_DATA_ACK(n) ((CAT_USER_DATABUF_ACK_OK == n) || \ + (CAT_USER_DATABUF_ACK_ERR == n)) + +bool cat_user_databuf_clear(cat_user_data_ops_e ops,cat_user_data_ack_e ack); +uint8_t *get_cat_user_databuf(cat_user_data_ops_e ops,cat_user_data_ack_e ack); +uint16_t get_cat_user_databuf_size(cat_user_data_ops_e ops,cat_user_data_ack_e ack); +uint16_t get_cat_user_databuf_errorcode(void); +void set_cat_user_databuf_errorcode(uint16_t val); +void cat_user_data_init(void); + +#endif /*__CAT_USRDATA_H*/ From 82daa32617aab5cbe4c0ab9fbf93bcb96d44c8fe Mon Sep 17 00:00:00 2001 From: chentao9 Date: Fri, 13 Aug 2021 22:25:59 +0800 Subject: [PATCH 2/2] feature:cAT: add usrdata to cAT process N/A add usrdata buf to cAT's ack and initialization Signed-off-by: chentao9 --- src/cat.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/cat.c b/src/cat.c index 22b6c87..b80e6d9 100644 --- a/src/cat.c +++ b/src/cat.c @@ -72,6 +72,9 @@ static void reset_state(struct cat_object *self) } self->cmd = NULL; self->cmd_type = CAT_CMD_TYPE_NONE; + #if CONFIG_LIB_CAT_USRDATA + cat_user_data_init(); + #endif } static void unsolicited_reset_state(struct cat_object *self) @@ -323,7 +326,23 @@ static void ack_error(struct cat_object *self) { assert(self != NULL); + #if CONFIG_LIB_CAT_USRDATA + char *strbuf = (char *)malloc(512); + assert(NULL == strbuf); + memset(strbuf,0,ACKBUF_LEN); + if(get_cat_user_databuf_errorcode()) + { + sprintf(strbuf,"ERROR%s",get_cat_user_databuf(CAT_USER_DATABUF_OPS_WRITE, CAT_USER_DATABUF_ACK_ERR)); + } + else + { + sprintf(strbuf,"ERROR"); + } + strncpy(get_atcmd_buf(self), strbuf, get_atcmd_buf_size(self)); + free(strbuf); + #else strncpy(get_atcmd_buf(self), "ERROR", get_atcmd_buf_size(self)); + #endif start_flush_io_buffer(self, CAT_STATE_AFTER_FLUSH_RESET); return; } @@ -332,7 +351,16 @@ static void ack_ok(struct cat_object *self) { assert(self != NULL); + #if CONFIG_LIB_CAT_USRDATA + char *strbuf = (char *)malloc(ACKBUF_LEN); + assert(NULL == strbuf); + memset(strbuf,0,ACKBUF_LEN); + sprintf(strbuf,"OK%s",get_cat_user_databuf(CAT_USER_DATABUF_OPS_WRITE, CAT_USER_DATABUF_ACK_OK)); + strncpy(get_atcmd_buf(self), strbuf, get_atcmd_buf_size(self)); + free(strbuf); + #else strncpy(get_atcmd_buf(self), "OK", get_atcmd_buf_size(self)); + #endif start_flush_io_buffer(self, CAT_STATE_AFTER_FLUSH_RESET); return; }