Skip to content

Commit fdf4c04

Browse files
committed
Modify the ymodem component to support multi-file reception
Co-authored-by: CUGLIJIE
1 parent 3550a8b commit fdf4c04

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

components/utilities/ymodem/ry_sy.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,22 @@ static enum rym_code _rym_recv_begin(
4747
rt_size_t len)
4848
{
4949
struct custom_ctx *cctx = (struct custom_ctx *)ctx;
50-
char insert_0 = '\0';
51-
char *ret;
5250
rt_err_t err;
53-
ret = strchr(cctx->fpath,insert_0);
54-
if(ret)
55-
{
56-
*ret = '/';
57-
}
58-
else
59-
{
60-
rt_kprintf("No end character\n");
61-
return RYM_ERR_ACK;
62-
}
63-
rt_strncpy(ret + 1, (const char *)buf, len - 1);
64-
cctx->fd = open(cctx->fpath, O_CREAT | O_WRONLY | O_TRUNC, 0);
51+
52+
/* support recv multiple files in one session */
53+
char user_path[DFS_PATH_MAX]={0};
54+
rt_snprintf(user_path, DFS_PATH_MAX, "%s%s", cctx->fpath, buf);
55+
cctx->fd = open(user_path, O_CREAT | O_WRONLY | O_TRUNC, 0);
56+
6557
if (cctx->fd < 0)
6658
{
6759
err = rt_get_errno();
68-
rt_kprintf("error creating file: %d\n", err);
60+
rt_kprintf("error creating file: %ld\n", err);
6961
return RYM_CODE_CAN;
7062
}
7163
cctx->flen = atoi(1 + (const char *)buf + rt_strnlen((const char *)buf, len - 1));
7264
if (cctx->flen == 0)
7365
cctx->flen = -1;
74-
7566
return RYM_CODE_ACK;
7667
}
7768

@@ -125,7 +116,7 @@ static enum rym_code _rym_send_begin(
125116
if (cctx->fd < 0)
126117
{
127118
err = rt_get_errno();
128-
rt_kprintf("error open file: %d\n", err);
119+
rt_kprintf("error open file: %ld\n", err);
129120
return RYM_ERR_FILE;
130121
}
131122
rt_memset(buf, 0, len);
@@ -146,7 +137,7 @@ static enum rym_code _rym_send_begin(
146137
}
147138
}
148139

149-
rt_sprintf((char *)buf, "%s%c%d", fdst, insert_0, file_buf.st_size);
140+
rt_sprintf((char *)buf, "%s%c%ld", fdst, insert_0, file_buf.st_size);
150141

151142
return RYM_CODE_SOH;
152143
}
@@ -257,7 +248,7 @@ static rt_err_t ry(uint8_t argc, char **argv)
257248
{
258249
rt_err_t res;
259250
rt_device_t dev;
260-
/* temporarily support 1 file*/
251+
261252
const char *file_path;
262253
if (argc < 2)
263254
{

0 commit comments

Comments
 (0)