mmtty: make sure \r\n is removed from the user line

This commit is contained in:
Aleksander Morgado
2021-03-31 00:43:32 +02:00
parent 9f7bbf28d2
commit 3ca80d8e51

View File

@@ -125,12 +125,21 @@ input_callback (GIOChannel *channel,
status = g_io_channel_read_line (channel, &line, NULL, NULL, &error); status = g_io_channel_read_line (channel, &line, NULL, NULL, &error);
switch (status) { switch (status) {
case G_IO_STATUS_NORMAL: case G_IO_STATUS_NORMAL: {
gsize line_len = 0;
/* remove \r\n before running as AT command */
line_len = strlen (line);
while (line_len > 0 && (line[line_len - 1] == '\r' || line[line_len - 1] == '\n')) {
line[line_len - 1] = '\0';
line_len--;
}
mm_port_serial_at_command (port, line, 60, FALSE, FALSE, NULL, mm_port_serial_at_command (port, line, 60, FALSE, FALSE, NULL,
(GAsyncReadyCallback) at_command_ready, NULL); (GAsyncReadyCallback) at_command_ready, NULL);
g_free (line); g_free (line);
return TRUE; return TRUE;
}
case G_IO_STATUS_ERROR: case G_IO_STATUS_ERROR:
g_printerr ("error: %s\n", error->message); g_printerr ("error: %s\n", error->message);
g_error_free (error); g_error_free (error);