From 9b09e14a23503140f80cbbaefc381e28fdab2998 Mon Sep 17 00:00:00 2001 From: fujr Date: Sat, 19 Apr 2025 00:08:57 +0800 Subject: [PATCH] tom_modem: improved stability --- application/tom_modem/Makefile | 2 +- application/tom_modem/src/modem_types.h | 8 +++++++- application/tom_modem/src/ttydevice.c | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/application/tom_modem/Makefile b/application/tom_modem/Makefile index 39c73cc..88ffd50 100644 --- a/application/tom_modem/Makefile +++ b/application/tom_modem/Makefile @@ -3,7 +3,7 @@ include $(INCLUDE_DIR)/kernel.mk PKG_NAME:= tom_modem PKG_RELEASE:=1 -PKG_VERSION:=1.0.0 +PKG_VERSION:=1.0.1 include $(INCLUDE_DIR)/package.mk diff --git a/application/tom_modem/src/modem_types.h b/application/tom_modem/src/modem_types.h index 31256d5..f07484e 100644 --- a/application/tom_modem/src/modem_types.h +++ b/application/tom_modem/src/modem_types.h @@ -55,7 +55,7 @@ #define SMS_BUF_SIZE 65536 #define LINE_BUF 1024 #define SMS_LIST_SIZE 128 -#define COMMON_BUF_SIZE 16384 +#define COMMON_BUF_SIZE 65536 #define PHONE_NUMBER_SIZE 64 #define SMS_TEXT_SIZE 256 #define SMS_PDU_STR_SIZE 512 @@ -108,6 +108,11 @@ typedef struct _SMS { char *sms_pdu; } SMS_T; +typedef struct _AT_MESSAGE { + char *message; + int len; +} AT_MESSAGE_T; + enum ERROR_CODES { COMM_ERROR = -1, SUCCESS = 0, @@ -116,6 +121,7 @@ enum ERROR_CODES { INVALID_PARAM, INVALID_HEX, UNKNOWN_ERROR, + BUFFER_OVERFLOW, }; enum SMS_CHARSET { diff --git a/application/tom_modem/src/ttydevice.c b/application/tom_modem/src/ttydevice.c index cfc7507..9d06160 100644 --- a/application/tom_modem/src/ttydevice.c +++ b/application/tom_modem/src/ttydevice.c @@ -91,6 +91,15 @@ int tty_open_device(PROFILE_T *profile,FDS_T *fds) err_msg("Error setting tty device"); return COMM_ERROR; } + + fds->tty_fd = open(profile->tty_dev, O_RDWR | O_NOCTTY | O_NONBLOCK); + fds->fdi = fdopen(fds->tty_fd, "r"); + if (setvbuf(fds->fdi , NULL, _IOFBF, 0)) + { + err_msg("Error setting buffer for fdi"); + return COMM_ERROR; + } + usleep(10000); tcflush(fds->tty_fd, TCIOFLUSH); if (fds->tty_fd >= 0) close(fds->tty_fd); @@ -138,6 +147,12 @@ int tty_read_keyword(FILE *fdi, char *output, int len, char *key_word, int soft_ { read_flag = 1; dbg_msg("%s", tmp); + if (msg_len + strlen(tmp) >= len) + { + err_msg("Error: output buffer is too small"); + exitcode = BUFFER_OVERFLOW; + break; + } if (output != NULL) msg_len += snprintf(output + msg_len, len - msg_len, "%s", tmp); @@ -177,7 +192,7 @@ int tty_read_keyword(FILE *fdi, char *output, int len, char *key_word, int soft_ } } #endif - usleep(10000); + usleep(5000); } if (read_flag == 0) {