Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 3 additions & 72 deletions app/src/sm_at_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,72 +466,6 @@ static int cmd_grammar_check(const char *cmd, size_t length)
return 0;
}

static char *strrstr(const char *str1, const char *str2)
{
size_t len1;
size_t len2;

if (str1 == NULL || str2 == NULL) {
return NULL;
}

len1 = strlen(str1);
len2 = strlen(str2);

if (len2 > len1 || len1 == 0 || len2 == 0) {
return NULL;
}

for (int i = len1 - len2; i >= 0; i--) {
if (strncmp(str1 + i, str2, len2) == 0) {
return (char *)str1 + i;
}
}

return NULL;
}

static void format_final_result(char *buf, size_t buf_len, size_t buf_max_len)
{
static const char ok_str[] = "OK\r\n";
static const char error_str[] = "ERROR\r\n";
static const char cme_error_str[] = "+CME ERROR:";
static const char cms_error_str[] = "+CMS ERROR:";
char *result = NULL;

result = strrstr(buf, ok_str);
if (result == NULL) {
result = strrstr(buf, error_str);
}

if (result == NULL) {
result = strrstr(buf, cme_error_str);
}

if (result == NULL) {
result = strrstr(buf, cms_error_str);
}

if (result == NULL) {
LOG_WRN("Final result not found");
return;
}

/* insert CRLF before final result if there is information response before it */
if (result != buf + strlen(CRLF_STR)) {
if (buf_len + strlen(CRLF_STR) < buf_max_len) {
memmove((void *)(result + strlen(CRLF_STR)), (void *)result,
strlen(result));
result[0] = CR;
result[1] = LF;
buf_len += strlen(CRLF_STR);
buf[buf_len] = '\0';
} else {
LOG_WRN("No room to insert CRLF");
}
}
}

static int sm_at_send_internal(const uint8_t *data, size_t len, bool urc,
enum sm_debug_print print_debug)
{
Expand Down Expand Up @@ -669,12 +603,9 @@ static void cmd_send(uint8_t *buf, size_t cmd_length, size_t buf_size, bool *sto
*/
buf[0] = CR;
buf[1] = LF;
if (strlen(buf) > strlen(CRLF_STR)) {
format_final_result(buf, strlen(buf), buf_size);
err = sm_at_send_str(buf);
if (err) {
LOG_ERR("AT command response failed: %d", err);
}
err = sm_at_send_str(buf);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This works well for the AT+ and AT%, but the SM AT# commands still send the additional \r\n:

OK
Ready
at#xsocket=1,1,0

#XSOCKET: 0,1,6

OK
at+cereg?

+CEREG: 0,4
OK

The first \r\n comes from:
https://github.com/nrfconnect/ncs-serial-modem/blob/main/app/src/sm_at_socket.c#L542

And the second one from lines above this. The first one should be removed from all the commands.

if (err) {
LOG_ERR("AT command response failed: %d", err);
}
}

Expand Down