Skip to content

Conversation

@LeonCT
Copy link

@LeonCT LeonCT commented Aug 13, 2021

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!

chentao9 added 2 commits August 13, 2021 22:25
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]>
@marcinbor85 marcinbor85 self-requested a review August 15, 2021 07:45
}
self->cmd = NULL;
self->cmd_type = CAT_CMD_TYPE_NONE;
#if CONFIG_LIB_CAT_USRDATA
Copy link
Owner

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.

self->cmd = NULL;
self->cmd_type = CAT_CMD_TYPE_NONE;
#if CONFIG_LIB_CAT_USRDATA
cat_user_data_init();
Copy link
Owner

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.

{
assert(self != NULL);

#if CONFIG_LIB_CAT_USRDATA
Copy link
Owner

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);
Copy link
Owner

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)
Copy link
Owner

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));
Copy link
Owner

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));
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

#include <stdio.h>
#include <stdbool.h>
#if CONFIG_LIB_CAT_USRDATA
#include "cat_usrdata.h"
Copy link
Owner

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);
Copy link
Owner

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;
Copy link
Owner

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
Copy link
Owner

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);
Copy link
Owner

@marcinbor85 marcinbor85 Aug 15, 2021

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)

@marcinbor85
Copy link
Owner

marcinbor85 commented Aug 15, 2021

besides of all above, all new features require add some basic unit tests or at least examples to show how to use it.

@LeonCT
Copy link
Author

LeonCT commented Aug 15, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants