Skip to content

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

Merged
merged 2 commits into from
Nov 21, 2019

Conversation

mtomczykmobica
Copy link

@mtomczykmobica mtomczykmobica commented Oct 21, 2019

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

[ ] Fix
[x] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@michalpasztamobica
@AnttiKauppila

Release Notes

@mtomczykmobica mtomczykmobica force-pushed the ONME-4405 branch 2 times, most recently from 611b6be to 3d884a4 Compare October 21, 2019 13:59
@ciarmcom
Copy link
Member

@mtomczykmobica, thank you for your changes.
@AnttiKauppila @michalpasztamobica @ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@michalpasztamobica michalpasztamobica left a 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.

}

bool ATCmdParser::vrecv(const char *response, std::va_list args)
int ATCmdParser::vrecvscanf(const char *response, std::va_list args, bool issacnf)
Copy link
Contributor

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?

Copy link
Author

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;
if (!issacnf && !response && j == 0 && !_fh->readable()) {
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}

// Command parsing with line handling
bool ATCmdParser::vsend(const char *command, std::va_list args)
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

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

Done

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

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?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@mtomczykmobica mtomczykmobica force-pushed the ONME-4405 branch 2 times, most recently from cec6129 to 04a64bb Compare October 22, 2019 05:47
@VeijoPesonen
Copy link
Contributor

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.

Ok, I'll check and also inform the original author of the idea :)
@kjbracey-arm , for your information if you would like to have a look.

@@ -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);
/**
Copy link
Contributor

@VeijoPesonen VeijoPesonen Oct 22, 2019

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.

Copy link
Contributor

@michalpasztamobica michalpasztamobica Oct 22, 2019

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 and scanf,
  • were not used anywhere else, but in recv and scanf
  • 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?

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

@michalpasztamobica michalpasztamobica left a 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.

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

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

Copy link
Author

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

@VeijoPesonen VeijoPesonen Oct 22, 2019

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.

Copy link
Contributor

@VeijoPesonen VeijoPesonen left a 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.

@mtomczykmobica
Copy link
Author

I assume you have tested this with ESP8266 and ran the socket tests.

Yes, i've tested netsocket tests.

@evedon
Copy link
Contributor

evedon commented Oct 23, 2019

Can you add unit tests for the new function please?

@michalpasztamobica
Copy link
Contributor

@evedon , I currently do not see any unittests for platform/ATCmdParser.
Adding them from scratch would be quite a large task, because it would make most sense if we tested the whole API, not just the newly added vrecvscanf?
Would it be OK, if we created some work item (internal JIRA ticket, preferably) and planned it for the future, rather than adding it within this PR?

@evedon
Copy link
Contributor

evedon commented Oct 23, 2019

@evedon , I currently do not see any unittests for platform/ATCmdParser.
Adding them from scratch would be quite a large task, because it would make most sense if we tested the whole API, not just the newly added vrecvscanf?
Would it be OK, if we created some work item (internal JIRA ticket, preferably) and planned it for the future, rather than adding it within this PR?

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.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 19, 2019

CI restarted

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 19, 2019

There was an update, I restarted CI (aborted current one).

@mbed-ci
Copy link

mbed-ci commented Nov 19, 2019

Test run: FAILED

Summary: 3 of 4 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_unittests
  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@mbed-ci
Copy link

mbed-ci commented Nov 19, 2019

Test run: FAILED

Summary: 1 of 4 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_unittests

@mtomczykmobica
Copy link
Author

@0xc0170 Problem is with valgrind. ATCmParser has some memory leaks, needs to be investigate and fix.

@mtomczykmobica mtomczykmobica force-pushed the ONME-4405 branch 2 times, most recently from b3b23bc to 195a38a Compare November 20, 2019 07:10
@mtomczykmobica
Copy link
Author

@0xc0170 Valgrind problem fixed, please rerun CI job.

@mtomczykmobica
Copy link
Author

@0xc0170 Valgrind proplem fixed, please rerun CI job.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 20, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Nov 20, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 4
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 20, 2019

@mtomczykmobica Can you do a quick amend to your first commit for the new function addition? It should at least have this in :

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

Describe the new functionality (marked as refactor here?).

Marcin Tomczyk added 2 commits November 20, 2019 22:35
…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.
@mtomczykmobica
Copy link
Author

@mtomczykmobica Can you do a quick amend to your first commit for the new function addition? It should at least have this in :

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

Describe the new functionality (marked as refactor here?).

Commit description changed.
This is not new functionality because it is exactly the same but implemented in different way. (using one function with parameter against to two functions).

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 21, 2019

👍

For future reference, keep the first line of the commit msg within 50 characters, the next paragraphs could be longer.

I'll start CI

@mbed-ci
Copy link

mbed-ci commented Nov 21, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 5
Build artifacts

@0xc0170 0xc0170 removed the needs: CI label Nov 21, 2019
@0xc0170 0xc0170 merged commit 2bde658 into ARMmbed:master Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants