Skip to content
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

Cellular: Fix for AT handler consume to tag #8350

Merged
merged 1 commit into from
Oct 23, 2018

Conversation

mirelachirica
Copy link
Contributor

Description

This PR addresses: #8308

"I'm trying to make a driver for a sim5320 using cellular framework, but ATHandler doesn't parse some responses correctly. After some investigation, I found that problem is caused by ATHandler::consume_to_tag method.

If sequence from buffer contains tag and a symbol before tag coincides with zero symbol of the tag, then the tag won't be detected. For example, if it consumes to a tag "\r\n" in a sequence "\r\r\nOK", the tag won't be found."

Pull request type

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

@0xc0170 0xc0170 requested a review from a team October 9, 2018 14:09
@@ -926,16 +926,14 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
int c = get_char();
if (c == -1) {
break;
} else if (c == tag[match_pos]) {
} else if (c == tag[match_pos] || (match_pos = 1 && c == tag[--match_pos])) {
Copy link
Contributor Author

@mirelachirica mirelachirica Oct 10, 2018

Choose a reason for hiding this comment

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

@AnttiKauppila there is compile warning about the "match_pos = 1": operation on 'match_pos' may be undefined. Is that something we have to avoid?
The alternative way which I tried to avoid is an else branch that in case c == tag[0] would have to do same operations as in this branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding parenthesis around "match_pos = 1" cancels the warning. I updated and added explanatory comments also.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is still causing a warning when compiling with IAR. Could be that we are using version 8 of IAR. Anyway, you could also do the assignment directly which does solve the warning for IAR:
} else if (c == tag[match_pos] || c == tag[match_pos = 0]) {

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

Fix looks good but the commit msg could have details from Description

If sequence from buffer contains tag and a symbol before tag coincides with zero symbol of the tag, then the tag won't be detected. For example, if it consumes to a tag "\r\n" in a sequence "\r\r\nOK", the tag won't be found."

To answer question - how this fixes the tag

If sequence from buffer contains tag but symbol before tag is same as
first symbol of the tag, then the tag wasn't detected.

For example, "\r\n" tag was not found from "\r\r\nOK" sequence.
@0xc0170
Copy link
Contributor

0xc0170 commented Oct 22, 2018

LGTM (cant approve as github is having issues), will start CI

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 22, 2018

Build : SUCCESS

Build number : 3426
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/8350/

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Oct 22, 2018

@mbed-ci
Copy link

mbed-ci commented Oct 22, 2018

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.

8 participants