xiaoxiang781216 commented on code in PR #1627: URL: https://github.com/apache/nuttx-apps/pull/1627#discussion_r1126908488
########## system/ymodem/README.md: ########## @@ -0,0 +1,28 @@ +# Introduce + +This is [ymodem protocal](http://pauillac.inria.fr/~doligez/zmodem/ymodem.txt). +According to it, the sb rb application is realized, which is used to send files and receive files respectively + +# Usage + +In the ubuntu system, lszrz needs to be installed, can use `sudo apt install lszrz`. +Use minicom to communicate with the board. + +## Sendfile to pc + +use sb cmd like this `nsh> sb /tmp/test.c ...`, this command support send multiple files together +then use `<Ctrl + a> , r` chose `ymodem` to receive borad file. Review Comment: ```suggestion then use `<Ctrl + a> , r` chose `ymodem` to receive board file. ``` ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) +#else +# define ym_debug(...) +#endif + +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) +#define FILE_NAME_LENGTH (64) + +#define YM_FILE_RECV_NAME_PKT (0) +#define YM_RECV_DATA_PKT (1) +#define YM_FILE_SEND_NAME_PKT (2) +#define YM_SEND_DATA_PKT (3) +#define YM_SEND_LAST_PKT (4) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ymodem_ctx +{ + char header; + char seq[2]; + char data[PACKET_1K_SIZE]; Review Comment: ```suggestion uint8_t data[PACKET_1K_SIZE]; ``` ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) +#else +# define ym_debug(...) +#endif + +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) +#define FILE_NAME_LENGTH (64) + +#define YM_FILE_RECV_NAME_PKT (0) +#define YM_RECV_DATA_PKT (1) +#define YM_FILE_SEND_NAME_PKT (2) +#define YM_SEND_DATA_PKT (3) +#define YM_SEND_LAST_PKT (4) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ymodem_ctx +{ + char header; + char seq[2]; + char data[PACKET_1K_SIZE]; + char file_name[FILE_NAME_LENGTH]; + uint16_t packet_size; + int32_t file_length; + uint32_t timeout; + uint32_t packet_type; + CODE ssize_t (*send)(FAR struct ymodem_ctx *ctx, FAR uint8_t *buf, + size_t size, uint32_t timeout); + CODE ssize_t (*receive)(struct ymodem_ctx *ctx, uint8_t *buf, Review Comment: ```suggestion CODE ssize_t (*receive)(FAR struct ymodem_ctx *ctx, FAR uint8_t *buf, ``` ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) +#else +# define ym_debug(...) +#endif + +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) +#define FILE_NAME_LENGTH (64) + +#define YM_FILE_RECV_NAME_PKT (0) +#define YM_RECV_DATA_PKT (1) +#define YM_FILE_SEND_NAME_PKT (2) +#define YM_SEND_DATA_PKT (3) +#define YM_SEND_LAST_PKT (4) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ymodem_ctx +{ + char header; + char seq[2]; Review Comment: char to uint8_t ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) +#else +# define ym_debug(...) +#endif + +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) +#define FILE_NAME_LENGTH (64) + +#define YM_FILE_RECV_NAME_PKT (0) +#define YM_RECV_DATA_PKT (1) +#define YM_FILE_SEND_NAME_PKT (2) +#define YM_SEND_DATA_PKT (3) +#define YM_SEND_LAST_PKT (4) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct ymodem_ctx +{ + char header; + char seq[2]; + char data[PACKET_1K_SIZE]; + char file_name[FILE_NAME_LENGTH]; + uint16_t packet_size; + int32_t file_length; + uint32_t timeout; + uint32_t packet_type; + CODE ssize_t (*send)(FAR struct ymodem_ctx *ctx, FAR uint8_t *buf, + size_t size, uint32_t timeout); + CODE ssize_t (*receive)(struct ymodem_ctx *ctx, uint8_t *buf, + size_t size, uint32_t timeout); + CODE ssize_t (*packet_handler)(FAR struct ymodem_ctx *ctx); + FAR void *priv; + uint16_t need_sendfile_num; +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH + int debug_fd; +#endif +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int ymodem_rcv(FAR struct ymodem_ctx *ctx); Review Comment: ```suggestion int ymodem_recv(FAR struct ymodem_ctx *ctx); ``` ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) Review Comment: ym_->ymodem_ ########## system/ymodem/ym_utils.h: ########## @@ -0,0 +1,42 @@ +/**************************************************************************** + * apps/system/ymodem/ym_utils.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YM_UTILS_H +#define __APPS_SYSTEM_YMODEM_YM_UTILS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <fcntl.h> +#include <stdio.h> +#include "ymodem.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +ssize_t ym_receive(FAR struct ymodem_ctx *ctx, FAR uint8_t *buf, size_t size, Review Comment: ym_ to ymodem_ ########## system/ymodem/sb_main.c: ########## @@ -0,0 +1,177 @@ +/**************************************************************************** + * apps/system/ymodem/sb_main.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <fcntl.h> +#include <libgen.h> +#include <stdio.h> +#include <termios.h> +#include <sys/stat.h> +#include <nuttx/fs/ioctl.h> +#include "ymodem.h" +#include "ym_utils.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +struct ym_fd Review Comment: ym->ymodem ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) +#else +# define ym_debug(...) +#endif + +#define PACKET_SIZE (128) Review Comment: add prefix YMODE_ ########## system/ymodem/ymodem.h: ########## @@ -0,0 +1,84 @@ +/**************************************************************************** + * apps/system/ymodem/ymodem.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __APPS_SYSTEM_YMODEM_YMODEM_H +#define __APPS_SYSTEM_YMODEM_YMODEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> +#include <stdlib.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifdef CONFIG_SYSTEM_YMODEM_DEBUGFILE_PATH +# define ym_debug(...) dprintf(ctx->debug_fd, ##__VA_ARGS__) +#else +# define ym_debug(...) +#endif + +#define PACKET_SIZE (128) +#define PACKET_1K_SIZE (1024) +#define FILE_NAME_LENGTH (64) + +#define YM_FILE_RECV_NAME_PKT (0) Review Comment: YM_ to YMODEM_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
