This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 01e2b11785c409770d1aaf42f26d6174087f09c5 Author: Alin Jerpelea <[email protected]> AuthorDate: Tue Dec 31 16:26:33 2019 +0900 system: zmodem: Improve zmodem send performance Introduce new configuration of CONFIG_SYSTEM_ZMODEM_SNDFILEBUF, which allocates cache buffer for reading file to be sent. This option can improve the performance of zmodem sending file by multiple bytes read of file, especially when the single read of file is very slow. --- system/zmodem/Kconfig | 9 +++++++++ system/zmodem/zm.h | 3 +++ system/zmodem/zm_send.c | 25 +++++++++++++++++++++---- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/system/zmodem/Kconfig b/system/zmodem/Kconfig index 2841751..21caa36 100644 --- a/system/zmodem/Kconfig +++ b/system/zmodem/Kconfig @@ -62,6 +62,15 @@ config SYSTEM_ZMODEM_SNDBUFSIZE The size of one transmit buffer used for composing messages sent to the remote peer. +config SYSTEM_ZMODEM_SNDFILEBUF + bool "Use cache buffer for file send" + default n + ---help--- + Read multiple bytes of file at once and store into a temporal buffer + which size is the same as SYSTEM_ZMODEM_SNDBUFSIZE. This is option + to improve the performance of file send, especially when the single + read of file is very slow. + config SYSTEM_ZMODEM_MOUNTPOINT string "Zmodem sandbox" default "/tmp" diff --git a/system/zmodem/zm.h b/system/zmodem/zm.h index 63df4aa..d393b77 100644 --- a/system/zmodem/zm.h +++ b/system/zmodem/zm.h @@ -358,6 +358,9 @@ struct zm_state_s uint8_t rcvbuf[CONFIG_SYSTEM_ZMODEM_RCVBUFSIZE]; uint8_t pktbuf[ZM_PKTBUFSIZE]; uint8_t scratch[CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE]; +#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF + uint8_t filebuf[CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE]; +#endif }; /* Receive state information */ diff --git a/system/zmodem/zm_send.c b/system/zmodem/zm_send.c index 24fb605..a12abe1 100644 --- a/system/zmodem/zm_send.c +++ b/system/zmodem/zm_send.c @@ -872,7 +872,6 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm) bool wait = false; int sndsize; int pktsize; - int ret; int i; /* Loop, sending packets while we can if the receiver supports streaming @@ -977,12 +976,24 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm) ptr = pzm->scratch; pktsize = 0; +#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF + /* Read multiple bytes of file and store into the temporal buffer */ + + zm_read(pzms->infd, pzm->filebuf, CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE); + + i = 0; +#endif + while (pktsize <= (CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE - 10) && - (ret = zm_getc(pzms->infd)) != EOF) + (pzms->offset < pzms->filesize)) { /* Add the new value to the accumulated CRC */ - uint8_t ch = (uint8_t)ret; +#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF + uint8_t ch = pzm->filebuf[i++]; +#else + uint8_t ch = zm_getc(pzms->infd); +#endif if (!bcrc32) { crc = (uint32_t)crc16part(&ch, 1, (uint16_t)crc); @@ -1007,6 +1018,12 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm) pzms->offset++; } +#ifdef CONFIG_SYSTEM_ZMODEM_SNDFILEBUF + /* Restore file position to be read next time */ + + lseek(pzms->infd, pzms->offset, SEEK_SET); +#endif + /* If we've reached file end, a ZEOF header will follow. If there's * room in the outgoing buffer for it, end the packet with ZCRCE and * append the ZEOF header. If there isn't room, we'll have to do a @@ -1014,7 +1031,7 @@ static int zms_sendpacket(FAR struct zm_state_s *pzm) */ pzm->flags &= ~ZM_FLAG_EOF; - if (ret == EOF) + if (pzms->offset == pzms->filesize) { pzm->flags |= ZM_FLAG_EOF; if (wait || (pzms->rcvmax != 0 && pktsize < 24))
