Skip to content

Infinite loop #2

Description

@duvh93

Use case:

AT+CMGF=1
OK
AT+CMGS=+31628870634
> This is the text message.→
+CMGS: 45
OK

Line of code where it gets stuck:

do {
line = fgets(buf, (int)sizeof(buf), modem);
if (line == NULL) {
fprintf(stderr, "EOF from modem\n");
return EXIT_FAILURE;
}
strcpy(buf2, line);
strip_cr(buf2);
res = fputs(buf2, output);
if (res < 0) {
fprintf(stderr, "failed to write '%s' to output file (res = %d)\n", buf2, res);
return EXIT_FAILURE;
}
} while (! is_final_result(line));

DISCLAIMER: I am far from being a sw developer, just wanted to write my linux sms utility using this nice piece of code.

If the device expects to be written again then it will never provide the "end of transmission" hence the fgets keeps listening.

Using a serial terminal emulators you can see that (look at the usecase I have reported) and you (user) keep writing giving the expected terminator at the end (ascii 26 in my case).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions