-
Notifications
You must be signed in to change notification settings - Fork 3k
ATCmdParser: merge scanf and recv functions #11720
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
Conversation
611b6be
to
3d884a4
Compare
@mtomczykmobica, thank you for your changes. |
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.
Functionally this makes perfect sense to me and reduces code duplication. I only left some minor remarks.
@VeijoPesonen , if you, as the author of this idea, had a few minutes to take a look and let us know if you see anything alarming, that would be great.
platform/source/ATCmdParser.cpp
Outdated
} | ||
|
||
bool ATCmdParser::vrecv(const char *response, std::va_list args) | ||
int ATCmdParser::vrecvscanf(const char *response, std::va_list args, bool issacnf) |
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.
typo? Should be isscanf
but now it is issacnf
?
But why don't we use something that would describe the purpose of this flag, such as multiline
or multiple_lines
or something equally descriptive?
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.
Done
platform/source/ATCmdParser.cpp
Outdated
// If just peeking for OOBs, and at start of line, check | ||
// readability | ||
if (!response && j == 0 && !_fh->readable()) { | ||
return false; | ||
if (!issacnf && !response && j == 0 && !_fh->readable()) { |
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.
I see that old vrecv
didn't have this check, but actually I don't see why we would not return an error if the file handle (that is - serial port) is not readable, no matter if we're reading single or multiple lines?
Unless there is a good reason, I suggest to return error regardless of the flag.
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.
Done
platform/source/ATCmdParser.cpp
Outdated
} | ||
|
||
// Command parsing with line handling | ||
bool ATCmdParser::vsend(const char *command, std::va_list args) |
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.
Why was this moved? The header file has this one declared before vrecvscanf. Perhaps we could keep the header's order?
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.
Done
platform/ATCmdParser.h
Outdated
@@ -222,7 +222,7 @@ class ATCmdParser : private NonCopyable<ATCmdParser> { | |||
*/ | |||
bool recv(const char *response, ...) MBED_SCANF_METHOD(1, 2); | |||
|
|||
bool vrecv(const char *response, std::va_list args); | |||
int vrecvscanf(const char *response, std::va_list args, bool isscnf); |
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.
I think this now deserves its own doxygen documentation. vrecv
was kind of wrapped by recv
and vscanf
was wrapped by scanf
, so they never got their own doxygen. But now the new "Frankenstein's" vrecvscanf
has an extra parameter (currently with a typo isscnf
, but hopefully it would become something more descriptive, such as 'multiline' or sth similar) that is not documented anywhere and also its int
return value fits more under the scanf
's doxygen?
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.
Done
3d884a4
to
012625b
Compare
cec6129
to
04a64bb
Compare
Ok, I'll check and also inform the original author of the idea :) |
platform/ATCmdParser.h
Outdated
@@ -222,7 +222,23 @@ class ATCmdParser : private NonCopyable<ATCmdParser> { | |||
*/ | |||
bool recv(const char *response, ...) MBED_SCANF_METHOD(1, 2); | |||
|
|||
bool vrecv(const char *response, std::va_list args); | |||
/** |
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.
There is no need to change the API, the original functions could act as wrappers for the newly introduced vrecvscanf
.
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.
vrecv
and vscanf
:
- were already wrapped by
recv
andscanf
, - were not used anywhere else, but in
recv
andscanf
- were not documented properly with Doxygen
I understand they were mentioned in the header file, but I don't think they were ever really meant to be an API?
I would go with Marcin's solution - they can be safely removed.
But actually - should we perhaps move the function header and the doxygen of vrecvscanf
into the *.cpp file, to make this function private and pretend to be an API any more?
@mtomczykmobica , @VeijoPesonen , would that make sense?
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.
Agree with @michalpasztamobica. There is no reason to add another level of calls. recv and scanf are API and wrap old vrecv and vscanf/new vrecvscanf.
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.
Those are kind of points @kjbracey-arm should answer. My personal opinion is that once it's exposed as part of public API, undocumented or not, you can't remove it like that. Least what should be done is to mark the PR as breaking change. And yes, if the API is to be changed then the new function should be made as private.
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.
After consultation with @michalpasztamobica functions vrecv and vscanf come back to code. Function vrecvscanfk made private. PR type doesn't change.
04a64bb
to
1b89986
Compare
1b89986
to
f18ba4d
Compare
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.
Looks like everyone should be happy with the current version.
platform/ATCmdParser.h
Outdated
@@ -282,7 +300,7 @@ class ATCmdParser : private NonCopyable<ATCmdParser> { | |||
*/ | |||
int scanf(const char *format, ...) MBED_SCANF_METHOD(1, 2); | |||
|
|||
int vscanf(const char *format, std::va_list args); | |||
int vscanf(const char *response, std::va_list args); |
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 could be reverted back fully, to be in line with scanf
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.
Done
// If just peeking for OOBs, and at start of line, check | ||
// readability | ||
if (!response && j == 0 && !_fh->readable()) { | ||
return false; | ||
return -1; |
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.
Should this actually return 0
. That's at least the behavior of C++'s scanf function.
> On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.
- cstdio/scanf
Scratch that, that comment can be ignored.
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.
I assume you have tested this with ESP8266 and ran the socket tests.
f18ba4d
to
e8bb0a5
Compare
Yes, i've tested netsocket tests. |
Can you add unit tests for the new function please? |
@evedon , I currently do not see any unittests for |
I don't think we should create more tech debt. I think it is okay to create a JIRA task to add tests for the whole API but I would rather that the new function is tested in this PR. |
CI restarted |
76dc0d4
to
ea5e77e
Compare
There was an update, I restarted CI (aborted current one). |
Test run: FAILEDSummary: 3 of 4 test jobs failed Failed test jobs:
|
Test run: FAILEDSummary: 1 of 4 test jobs failed Failed test jobs:
|
@0xc0170 Problem is with valgrind. ATCmParser has some memory leaks, needs to be investigate and fix. |
b3b23bc
to
195a38a
Compare
@0xc0170 Valgrind problem fixed, please rerun CI job. |
@0xc0170 Valgrind proplem fixed, please rerun CI job. |
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
@mtomczykmobica Can you do a quick amend to your first commit for the new function addition? It should at least have this in :
Describe the new functionality (marked as refactor here?). |
…figuration parameter for this function which would indicate are we trying to find a match from one line(scanf) or do we might end up processing multiple lines(recv) to find a match.
195a38a
to
1d3a1b7
Compare
Commit description changed. |
👍 For future reference, keep the first line of the commit msg within 50 characters, the next paragraphs could be longer. I'll start CI |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
vrecv and vscanf should be merged together. The goal is to give a configuration parameter for this function which would indicate are we trying to find a match from one line(scanf) or do we might end up processing multiple lines(recv) to find a match.
Pull request type
Reviewers
@michalpasztamobica
@AnttiKauppila
Release Notes