-
Notifications
You must be signed in to change notification settings - Fork 82
share 2 patch for ack extension #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
N/A add usrdata for cAT ack Signed-off-by: chentao9 <[email protected]>
N/A add usrdata buf to cAT's ack and initialization Signed-off-by: chentao9 <[email protected]>
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at this moment in cAT library there is no macro-based configuration feature. adding this kind of feature should be separated task.
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling functions from external cAT-related modules needs to pass current context (self pointer). it allows to continue object-oriented architecture.
@@ -323,7 +326,23 @@ static void ack_error(struct cat_object *self) | |||
{ | |||
assert(self != NULL); | |||
|
|||
#if CONFIG_LIB_CAT_USRDATA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
#if CONFIG_LIB_CAT_USRDATA | ||
char *strbuf = (char *)malloc(512); | ||
assert(NULL == strbuf); | ||
memset(strbuf,0,ACKBUF_LEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using dynamic allocation for this purpose is completely unnecessary. first of all, one of the major requirements is to completely avoid dynamic allocations in this library. at second, You could use variable array length, for this purpose.
* @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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all cat-related functions should be prefixed with cat_ prefix
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
differentation (and customization) of the automatic ack/error response could be implemented more generic way, for e.g. with optional callbacks with return codes.
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
/**************************************************************************** | ||
* src/cat_usrdata.c | ||
* | ||
* Copyright (C) 2021 Xiaomi Corperation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
@@ -32,6 +32,9 @@ extern "C" { | |||
#include <stdint.h> | |||
#include <stdio.h> | |||
#include <stdbool.h> | |||
#if CONFIG_LIB_CAT_USRDATA | |||
#include "cat_usrdata.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
{ | ||
assert(IS_DATA_OPS(ops)); | ||
assert(IS_DATA_ACK(ack)); | ||
memset((cat_user_data.data_buf[ops][ack].buf),0,WRITEBUF_LEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces between comas and args...
#include "cat.h" | ||
#include "cat_usrdata.h" | ||
|
||
static cat_user_data_t cat_user_data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this static allocation makes it impossible to use more than one cAT instance in single system. pointer to this data should be passed in function args to continue object-oriented approach
/*user define*/ | ||
#define WRITEBUF_LEN 256 | ||
#define READBUF_LEN WRITEBUF_LEN | ||
#define ACKBUF_LEN 512 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcoded buffers sizes should be strongly avoded (please use static descriptors instead)
#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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comments (source code functions documentation)
besides of all above, all new features require add some basic unit tests or at least examples to show how to use it. |
Thank you for your improvement suggestions after the code review. I will revise it according to the suggestions and resubmit it. Please review it later.I really appreciate it! |
hi:
Thank you very much for the convenience of your excellent code framework.and I want to share 2 patch for ack extension.
please review If code requirements are met.Thank you very much!