summaryrefslogtreecommitdiff
path: root/components/utilities
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-03-08 18:19:04 +0800
committerMeco Man <[email protected]>2021-03-08 18:19:04 +0800
commit3c05a4e7193ee553bf502560e7de4be6489c7629 (patch)
tree69771215353ad4697e7c12a969f9bada32129265 /components/utilities
parentce86058201432e865b8d7c4096b3675642a43a42 (diff)
[compoenets] auto & manual formatted
Diffstat (limited to 'components/utilities')
-rw-r--r--components/utilities/ulog/backend/console_be.c2
-rw-r--r--components/utilities/ulog/syslog/syslog.c2
-rw-r--r--components/utilities/ulog/syslog/syslog.h2
-rw-r--r--components/utilities/ulog/ulog.c2
-rw-r--r--components/utilities/ulog/ulog.h2
-rw-r--r--components/utilities/ulog/ulog_def.h8
-rw-r--r--components/utilities/utest/utest.c2
-rw-r--r--components/utilities/utest/utest.h60
-rw-r--r--components/utilities/utest/utest_assert.h10
-rw-r--r--components/utilities/utest/utest_log.h2
-rw-r--r--components/utilities/ymodem/ymodem.c4
-rw-r--r--components/utilities/ymodem/ymodem.h2
-rw-r--r--components/utilities/zmodem/crc.h12
-rw-r--r--components/utilities/zmodem/rz.c572
-rw-r--r--components/utilities/zmodem/sz.c446
-rw-r--r--components/utilities/zmodem/zcore.c1344
-rw-r--r--components/utilities/zmodem/zdef.h208
-rw-r--r--components/utilities/zmodem/zdevice.c102
-rw-r--r--components/utilities/zmodem/zstart.c36
19 files changed, 1409 insertions, 1409 deletions
diff --git a/components/utilities/ulog/backend/console_be.c b/components/utilities/ulog/backend/console_be.c
index 95dd547426..b84cd95d09 100644
--- a/components/utilities/ulog/backend/console_be.c
+++ b/components/utilities/ulog/backend/console_be.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/ulog/syslog/syslog.c b/components/utilities/ulog/syslog/syslog.c
index 4c290bed52..a081db6eb6 100644
--- a/components/utilities/ulog/syslog/syslog.c
+++ b/components/utilities/ulog/syslog/syslog.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/ulog/syslog/syslog.h b/components/utilities/ulog/syslog/syslog.h
index 43eec7125f..8e4d5ba15f 100644
--- a/components/utilities/ulog/syslog/syslog.h
+++ b/components/utilities/ulog/syslog/syslog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/ulog/ulog.c b/components/utilities/ulog/ulog.c
index b4571f4920..e903a707b2 100644
--- a/components/utilities/ulog/ulog.c
+++ b/components/utilities/ulog/ulog.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2019, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/ulog/ulog.h b/components/utilities/ulog/ulog.h
index 670644bb30..3754828e56 100644
--- a/components/utilities/ulog/ulog.h
+++ b/components/utilities/ulog/ulog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/ulog/ulog_def.h b/components/utilities/ulog/ulog_def.h
index 771e76a601..d51c6f0d84 100644
--- a/components/utilities/ulog/ulog_def.h
+++ b/components/utilities/ulog/ulog_def.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -102,8 +102,8 @@ extern "C" {
#define ulog_hex(TAG, width, buf, size) ulog_hexdump(TAG, width, buf, size)
#else
#define ulog_hex(TAG, width, buf, size)
-#endif /* (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG) */
-
+#endif /* (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG) */
+
/* assert for developer. */
#ifdef ULOG_ASSERT_ENABLE
#define ULOG_ASSERT(EXPR) \
@@ -142,7 +142,7 @@ extern "C" {
#define log_d LOG_D
#define log_v LOG_D
#define log_raw LOG_RAW
-#define log_hex LOG_HEX
+#define log_hex LOG_HEX
#define ELOG_LVL_ASSERT LOG_LVL_ASSERT
#define ELOG_LVL_ERROR LOG_LVL_ERROR
#define ELOG_LVL_WARN LOG_LVL_WARNING
diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c
index 6500ae2fbe..325823de8a 100644
--- a/components/utilities/utest/utest.c
+++ b/components/utilities/utest/utest.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/utest/utest.h b/components/utilities/utest/utest.h
index e2d72a931d..33d50efddb 100644
--- a/components/utilities/utest/utest.h
+++ b/components/utilities/utest/utest.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -22,13 +22,13 @@ extern "C" {
/**
* utest_error
- *
+ *
* @brief Test result.
- *
+ *
* @member UTEST_PASSED Test success.
* @member UTEST_FAILED Test failed.
* @member UTEST_PASSED Test skipped.
- *
+ *
*/
enum utest_error
{
@@ -40,13 +40,13 @@ typedef enum utest_error utest_err_e;
/**
* utest
- *
+ *
* @brief utest data structure.
- *
+ *
* @member error Error number from enum `utest_error`.
* @member passed_num Total number of tests passed.
* @member failed_num Total number of tests failed.
- *
+ *
*/
struct utest
{
@@ -58,16 +58,16 @@ typedef struct utest *utest_t;
/**
* utest_tc_export
- *
+ *
* @brief utest testcase data structure.
* Will export the data to `UtestTcTab` section in flash.
- *
+ *
* @member name Testcase name.
* @member run_timeout Testcase maximum test time (Time unit: seconds).
* @member init Necessary initialization before executing the test case function.
* @member tc Total number of tests failed.
* @member cleanup Total number of tests failed.
- *
+ *
*/
struct utest_tc_export {
const char *name;
@@ -80,61 +80,61 @@ typedef struct utest_tc_export *utest_tc_export_t;
/**
* test_unit_func
- *
+ *
* @brief Unit test handler function pointer.
- *
+ *
*/
typedef void (*test_unit_func)(void);
/**
* utest_unit_run
- *
+ *
* @brief Unit test function executor.
* No need for the user to call this function directly
- *
+ *
* @param func Unit test function.
* @param unit_func_name Unit test function name.
- *
+ *
* @return void
- *
+ *
*/
void utest_unit_run(test_unit_func func, const char *unit_func_name);
/**
* utest_handle_get
- *
+ *
* @brief Get the utest data structure handle.
* No need for the user to call this function directly
- *
+ *
* @param void
- *
+ *
* @return utest_t type. (struct utest *)
- *
+ *
*/
utest_t utest_handle_get(void);
/**
* UTEST_NAME_MAX_LEN
- *
+ *
* @brief Testcase name maximum length.
- *
+ *
*/
#define UTEST_NAME_MAX_LEN (128u)
/**
* UTEST_TC_EXPORT
- *
+ *
* @brief Export testcase function to `UtestTcTab` section in flash.
* Used in application layer.
- *
+ *
* @param testcase The testcase function.
* @param name The testcase name.
* @param init The initialization function of the test case.
* @param cleanup The cleanup function of the test case.
* @param timeout Testcase maximum test time (Time unit: seconds).
- *
+ *
* @return None
- *
+ *
*/
#define UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout) \
RT_USED static const struct utest_tc_export _utest_testcase \
@@ -149,14 +149,14 @@ utest_t utest_handle_get(void);
/**
* UTEST_UNIT_RUN
- *
+ *
* @brief Unit test function executor.
* Used in `testcase` function in application.
- *
+ *
* @param test_unit_func Unit test function
- *
+ *
* @return None
- *
+ *
*/
#define UTEST_UNIT_RUN(test_unit_func) \
utest_unit_run(test_unit_func, #test_unit_func); \
diff --git a/components/utilities/utest/utest_assert.h b/components/utilities/utest/utest_assert.h
index d83279272e..2e2007e773 100644
--- a/components/utilities/utest/utest_assert.h
+++ b/components/utilities/utest/utest_assert.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -30,10 +30,10 @@ void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equa
/**
* uassert_x macros
- *
+ *
* @brief Get the utest data structure handle.
* No need for the user to call this function directly.
- *
+ *
* @macro uassert_true if @value is true, not assert, means passing.
* @macro uassert_false if @value is false, not assert, means passing.
* @macro uassert_null if @value is null, not assert, means passing.
@@ -46,7 +46,7 @@ void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equa
* @macro uassert_buf_not_equal if @a not equal to @b, not assert, means passing. buf type test.
* @macro uassert_in_range if @value is in range of min and max, not assert, means passing.
* @macro uassert_not_in_range if @value is not in range of min and max, not assert, means passing.
- *
+ *
*/
#define uassert_true(value) __utest_assert(value, "(" #value ") is false")
#define uassert_false(value) __utest_assert(!(value), "(" #value ") is true")
@@ -62,7 +62,7 @@ void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equa
#define uassert_buf_equal(a, b, sz) utest_assert_buf((const char*)(a), (const char*)(b), (sz), RT_TRUE, __FILE__, __LINE__, __func__, "buf not equal")
#define uassert_buf_not_equal(a, b, sz) utest_assert_buf((const char*)(a), (const char*)(b), (sz), RT_FALSE, __FILE__, __LINE__, __func__, "buf equal")
-#define uassert_in_range(value, min, max) __utest_assert(((value >= min) && (value <= max)), "(" #value ") not in range("#min","#max")")
+#define uassert_in_range(value, min, max) __utest_assert(((value >= min) && (value <= max)), "(" #value ") not in range("#min","#max")")
#define uassert_not_in_range(value, min, max) __utest_assert(!((value >= min) && (value <= max)), "(" #value ") in range("#min","#max")")
#ifdef __cplusplus
diff --git a/components/utilities/utest/utest_log.h b/components/utilities/utest/utest_log.h
index 0403268351..6aa54386a8 100644
--- a/components/utilities/utest/utest_log.h
+++ b/components/utilities/utest/utest_log.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c
index 07055db615..a74237689d 100644
--- a/components/utilities/ymodem/ymodem.c
+++ b/components/utilities/ymodem/ymodem.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (C) 2012, Real-Thread Information Technology Ltd
+ * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd
* All rights reserved
*
* SPDX-License-Identifier: Apache-2.0
@@ -13,7 +13,7 @@
#include <rthw.h>
#include "ymodem.h"
-#ifdef YMODEM_USING_CRC_TABLE
+#ifdef YMODEM_USING_CRC_TABLE
static const rt_uint16_t ccitt_table[256] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
diff --git a/components/utilities/ymodem/ymodem.h b/components/utilities/ymodem/ymodem.h
index 8419290e13..7006cf268d 100644
--- a/components/utilities/ymodem/ymodem.h
+++ b/components/utilities/ymodem/ymodem.h
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (C) 2012, Real-Thread Information Technology Ltd
+ * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd
* All rights reserved
*
* SPDX-License-Identifier: Apache-2.0
diff --git a/components/utilities/zmodem/crc.h b/components/utilities/zmodem/crc.h
index fd11c1960a..c5251a7aa1 100644
--- a/components/utilities/zmodem/crc.h
+++ b/components/utilities/zmodem/crc.h
@@ -39,14 +39,14 @@ static unsigned short crctab[256] = {
};
/*
- * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
+ * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
* NOTE: First srgument must be in range 0 to 255.
* Second argument is referenced twice.
- *
- * Programmers may incorporate any or all code into their programs,
- * giving proper credit within the source. Publication of the
- * source routines is permitted so long as proper credit is given
- * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
+ *
+ * Programmers may incorporate any or all code into their programs,
+ * giving proper credit within the source. Publication of the
+ * source routines is permitted so long as proper credit is given
+ * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
* Omen Technology.
*/
diff --git a/components/utilities/zmodem/rz.c b/components/utilities/zmodem/rz.c
index 1324b5994b..1845fd24c2 100644
--- a/components/utilities/zmodem/rz.c
+++ b/components/utilities/zmodem/rz.c
@@ -1,11 +1,11 @@
/*
* File : rz.c
- * the implemention of receiving files from the remote computers
+ * the implemention of receiving files from the remote computers
* through the zmodem protocol.
* Change Logs:
* Date Author Notes
- * 2011-03-29 itspy
- * 2011-12-12 aozima fixed syntax error.
+ * 2011-03-29 itspy
+ * 2011-12-12 aozima fixed syntax error.
*/
#include <rtthread.h>
@@ -35,293 +35,293 @@ void zr_start(char *path)
{
struct zfile *zf;
rt_uint8_t n;
- char ch,*p,*q;
- rt_err_t res = -RT_ERROR;
+ char ch,*p,*q;
+ rt_err_t res = -RT_ERROR;
- zf = rt_malloc(sizeof(struct zfile));
- if (zf == RT_NULL)
- {
- rt_kprintf("zf: out of memory\r\n");
- return;
- }
- memset(zf, 0, sizeof(struct zfile));
+ zf = rt_malloc(sizeof(struct zfile));
+ if (zf == RT_NULL)
+ {
+ rt_kprintf("zf: out of memory\r\n");
+ return;
+ }
+ memset(zf, 0, sizeof(struct zfile));
zf->fname = path;
- zf->fd = -1;
- res = zrec_files(zf);
- p = zf->fname;
- for (;;)
- {
- q = strstr(p,"/");
- if (q == RT_NULL) break;
- p = q+1;
- }
+ zf->fd = -1;
+ res = zrec_files(zf);
+ p = zf->fname;
+ for (;;)
+ {
+ q = strstr(p,"/");
+ if (q == RT_NULL) break;
+ p = q+1;
+ }
if (res == RT_EOK)
- {
+ {
rt_kprintf("\b\b\bfile: %s \r\n",p);
- rt_kprintf("size: %ld bytes\r\n",zf->bytes_received);
- rt_kprintf("receive completed.\r\n");
- close(zf->fd);
- rt_free(zf->fname);
+ rt_kprintf("size: %ld bytes\r\n",zf->bytes_received);
+ rt_kprintf("receive completed.\r\n");
+ close(zf->fd);
+ rt_free(zf->fname);
}
else
{
rt_kprintf("\b\b\bfile: %s \r\n",p);
- rt_kprintf("size: 0 bytes\r\n");
- rt_kprintf("receive failed.\r\n");
- if (zf->fd >= 0)
- {
- close(zf->fd);
- unlink(zf->fname); /* remove this file */
- rt_free(zf->fname);
- }
+ rt_kprintf("size: 0 bytes\r\n");
+ rt_kprintf("receive failed.\r\n");
+ if (zf->fd >= 0)
+ {
+ close(zf->fd);
+ unlink(zf->fname); /* remove this file */
+ rt_free(zf->fname);
+ }
+ }
+ rt_free(zf);
+ /* waiting,clear console buffer */
+ rt_thread_delay(RT_TICK_PER_SECOND/2);
+ while(1)
+ {
+ n=rt_device_read(shell->device, 0, &ch, 1);
+ if (n == 0) break;
}
- rt_free(zf);
- /* waiting,clear console buffer */
- rt_thread_delay(RT_TICK_PER_SECOND/2);
- while(1)
- {
- n=rt_device_read(shell->device, 0, &ch, 1);
- if (n == 0) break;
- }
- return ;
+ return ;
}
/* receiver init, wait for ack */
static rt_err_t zrec_init(rt_uint8_t *rxbuf, struct zfile *zf)
{
rt_uint8_t err_cnt = 0;
- rt_err_t res = -RT_ERROR;
+ rt_err_t res = -RT_ERROR;
- for (;;)
- {
- zput_pos(0L);
- tx_header[ZF0] = ZF0_CMD;
- tx_header[ZF1] = ZF1_CMD;
- tx_header[ZF2] = ZF2_CMD;
- zsend_hex_header(ZRINIT, tx_header);
+ for (;;)
+ {
+ zput_pos(0L);
+ tx_header[ZF0] = ZF0_CMD;
+ tx_header[ZF1] = ZF1_CMD;
+ tx_header[ZF2] = ZF2_CMD;
+ zsend_hex_header(ZRINIT, tx_header);
again:
res = zget_header(rx_header);
- switch(res)
- {
- case ZFILE:
- ZF0_CMD = rx_header[ZF0];
- ZF1_CMD = rx_header[ZF1];
- ZF2_CMD = rx_header[ZF2];
- ZF3_CMD = rx_header[ZF3];
- res = zget_data(rxbuf, RX_BUFFER_SIZE);
- if (res == GOTCRCW)
- {
- if ((res =zget_file_info((char*)rxbuf,zf))!= RT_EOK)
- {
- zsend_hex_header(ZSKIP, tx_header);
- return (res);
- }
- return RT_EOK;;
- }
- zsend_hex_header(ZNAK, tx_header);
- goto again;
- case ZSINIT:
- if (zget_data((rt_uint8_t*)Attn, ZATTNLEN) == GOTCRCW) /* send zack */
- {
- zsend_hex_header(ZACK, tx_header);
- goto again;
- }
- zsend_hex_header(ZNAK, tx_header); /* send znak */
- goto again;
- case ZRQINIT:
- continue;
- case ZEOF:
- continue;
- case ZCOMPL:
- goto again;
- case ZFIN: /* end file session */
- zrec_ack_bibi();
- return res;
- default:
- if (++err_cnt >1000) return -RT_ERROR;
- continue;
- }
- }
+ switch(res)
+ {
+ case ZFILE:
+ ZF0_CMD = rx_header[ZF0];
+ ZF1_CMD = rx_header[ZF1];
+ ZF2_CMD = rx_header[ZF2];
+ ZF3_CMD = rx_header[ZF3];
+ res = zget_data(rxbuf, RX_BUFFER_SIZE);
+ if (res == GOTCRCW)
+ {
+ if ((res =zget_file_info((char*)rxbuf,zf))!= RT_EOK)
+ {
+ zsend_hex_header(ZSKIP, tx_header);
+ return (res);
+ }
+ return RT_EOK;;
+ }
+ zsend_hex_header(ZNAK, tx_header);
+ goto again;
+ case ZSINIT:
+ if (zget_data((rt_uint8_t*)Attn, ZATTNLEN) == GOTCRCW) /* send zack */
+ {
+ zsend_hex_header(ZACK, tx_header);
+ goto again;
+ }
+ zsend_hex_header(ZNAK, tx_header); /* send znak */
+ goto again;
+ case ZRQINIT:
+ continue;
+ case ZEOF:
+ continue;
+ case ZCOMPL:
+ goto again;
+ case ZFIN: /* end file session */
+ zrec_ack_bibi();
+ return res;
+ default:
+ if (++err_cnt >1000) return -RT_ERROR;
+ continue;
+ }
+ }
}
/* receive files */
static rt_err_t zrec_files(struct zfile *zf)
{
- rt_uint8_t *rxbuf;
- rt_err_t res = -RT_ERROR;
+ rt_uint8_t *rxbuf;
+ rt_err_t res = -RT_ERROR;
- zinit_parameter();
- rxbuf = rt_malloc(RX_BUFFER_SIZE*sizeof(rt_uint8_t));
- if (rxbuf == RT_NULL)
- {
- rt_kprintf("rxbuf: out of memory\r\n");
- return -RT_ERROR;
- }
- rt_kprintf("\r\nrz: ready...\r\n"); /* here ready to receive things */
- if ((res = zrec_init(rxbuf,zf))!= RT_EOK)
- {
- rt_kprintf("\b\b\breceive init failed\r\n");
- rt_free(rxbuf);
- return -RT_ERROR;
- }
- res = zrec_file(rxbuf,zf);
- if (res == ZFIN)
- {
- rt_free(rxbuf);
- return RT_EOK; /* if finish session */
- }
- else if (res == ZCAN)
- {
+ zinit_parameter();
+ rxbuf = rt_malloc(RX_BUFFER_SIZE*sizeof(rt_uint8_t));
+ if (rxbuf == RT_NULL)
+ {
+ rt_kprintf("rxbuf: out of memory\r\n");
+ return -RT_ERROR;
+ }
+ rt_kprintf("\r\nrz: ready...\r\n"); /* here ready to receive things */
+ if ((res = zrec_init(rxbuf,zf))!= RT_EOK)
+ {
+ rt_kprintf("\b\b\breceive init failed\r\n");
+ rt_free(rxbuf);
+ return -RT_ERROR;
+ }
+ res = zrec_file(rxbuf,zf);
+ if (res == ZFIN)
+ {
rt_free(rxbuf);
- return ZCAN; /* cancel by sender */
- }
- else
- {
- zsend_can();
- rt_free(rxbuf);
- return res;
- }
+ return RT_EOK; /* if finish session */
+ }
+ else if (res == ZCAN)
+ {
+ rt_free(rxbuf);
+ return ZCAN; /* cancel by sender */
+ }
+ else
+ {
+ zsend_can();
+ rt_free(rxbuf);
+ return res;
+ }
}
/* receive file */
static rt_err_t zrec_file(rt_uint8_t *rxbuf, struct zfile *zf)
{
- rt_err_t res = - RT_ERROR;
- rt_uint16_t err_cnt = 0;
+ rt_err_t res = - RT_ERROR;
+ rt_uint16_t err_cnt = 0;
- do
- {
- zput_pos(zf->bytes_received);
- zsend_hex_header(ZRPOS, tx_header);
+ do
+ {
+ zput_pos(zf->bytes_received);
+ zsend_hex_header(ZRPOS, tx_header);
again:
res = zget_header(rx_header);
- switch (res)
- {
- case ZDATA:
- zget_pos(Rxpos);
- if (Rxpos != zf->bytes_received)
- {
- zsend_break(Attn);
- continue;
- }
- err_cnt = 0;
- res = zrec_file_data(rxbuf,zf);
- if (res == -RT_ERROR)
- {
- zsend_break(Attn);
- continue;
- }
- else if (res == GOTCAN) return res;
- else goto again;
- case ZRPOS:
- zget_pos(Rxpos);
- continue;
- case ZEOF:
- err_cnt = 0;
- zget_pos(Rxpos);
- if (Rxpos != zf->bytes_received || Rxpos != zf->bytes_total)
- {
- continue;
- }
- return (zrec_init(rxbuf,zf)); /* resend ZRINIT packet,ready to receive next file */
+ switch (res)
+ {
+ case ZDATA:
+ zget_pos(Rxpos);
+ if (Rxpos != zf->bytes_received)
+ {
+ zsend_break(Attn);
+ continue;
+ }
+ err_cnt = 0;
+ res = zrec_file_data(rxbuf,zf);
+ if (res == -RT_ERROR)
+ {
+ zsend_break(Attn);
+ continue;
+ }
+ else if (res == GOTCAN) return res;
+ else goto again;
+ case ZRPOS:
+ zget_pos(Rxpos);
+ continue;
+ case ZEOF:
+ err_cnt = 0;
+ zget_pos(Rxpos);
+ if (Rxpos != zf->bytes_received || Rxpos != zf->bytes_total)
+ {
+ continue;
+ }
+ return (zrec_init(rxbuf,zf)); /* resend ZRINIT packet,ready to receive next file */
case ZFIN:
- zrec_ack_bibi();
- return ZCOMPL;
- case ZCAN:
+ zrec_ack_bibi();
+ return ZCOMPL;
+ case ZCAN:
#ifdef ZDEBUG
rt_kprintf("error code: sender cancelled \r\n");
#endif
- zf->bytes_received = 0L; /* throw the received data */
- return res;
- case ZSKIP:
- return res;
- case -RT_ERROR:
- zsend_break(Attn);
- continue;
- case ZNAK:
- case TIMEOUT:
- default:
- continue;
- }
- } while(++err_cnt < 100);
+ zf->bytes_received = 0L; /* throw the received data */
+ return res;
+ case ZSKIP:
+ return res;
+ case -RT_ERROR:
+ zsend_break(Attn);
+ continue;
+ case ZNAK:
+ case TIMEOUT:
+ default:
+ continue;
+ }
+ } while(++err_cnt < 100);
- return res;
+ return res;
}
/* proccess file infomation */
static rt_err_t zget_file_info(char *name, struct zfile *zf)
{
- char *p;
- char *full_path,*ptr;
- rt_uint16_t i,len;
- rt_err_t res = -RT_ERROR;
- struct statfs buf;
- struct stat finfo;
+ char *p;
+ char *full_path,*ptr;
+ rt_uint16_t i,len;
+ rt_err_t res = -RT_ERROR;
+ struct statfs buf;
+ struct stat finfo;
- if (zf->fname == RT_NULL) /* extract file path */
+ if (zf->fname == RT_NULL) /* extract file path */
{
- len = strlen(name)+2;
- }
- else
- len = strlen(zf->fname)+strlen(name)+2;
+ len = strlen(name)+2;
+ }
+ else
+ len = strlen(zf->fname)+strlen(name)+2;
full_path = rt_malloc(len);
- if (full_path == RT_NULL)
- {
- zsend_can();
- rt_kprintf("\b\b\bfull_path: out of memory\n");
- rt_free(full_path);
- return -RT_ERROR;
- }
- memset(full_path,0,len);
+ if (full_path == RT_NULL)
+ {
+ zsend_can();
+ rt_kprintf("\b\b\bfull_path: out of memory\n");
+ rt_free(full_path);
+ return -RT_ERROR;
+ }
+ memset(full_path,0,len);
for (i=0,ptr=zf->fname;i<len-strlen(name)-2;i++)
- full_path[i] = *ptr++;
+ full_path[i] = *ptr++;
full_path[len-strlen(name)-2] = '/';
- /* check if is a directory */
- if ((zf->fd=open(full_path, DFS_O_DIRECTORY,0)) < 0)
- {
- zsend_can();
- rt_kprintf("\b\b\bcan not open file:%s\r\n",zf->fname+1);
- close(zf->fd);
- zf->fd = -1;
- rt_free(full_path);
- return res;
- }
- fstat(zf->fd, &finfo);
- if ((finfo.st_mode&S_IFDIR) != S_IFDIR)
- {
- close(zf->fd);
- zf->fd = -1;
- return res;
- }
- close(zf->fd);
- /* get fullpath && file attributes */
+ /* check if is a directory */
+ if ((zf->fd=open(full_path, DFS_O_DIRECTORY,0)) < 0)
+ {
+ zsend_can();
+ rt_kprintf("\b\b\bcan not open file:%s\r\n",zf->fname+1);
+ close(zf->fd);
+ zf->fd = -1;
+ rt_free(full_path);
+ return res;
+ }
+ fstat(zf->fd, &finfo);
+ if ((finfo.st_mode&S_IFDIR) != S_IFDIR)
+ {
+ close(zf->fd);
+ zf->fd = -1;
+ return res;
+ }
+ close(zf->fd);
+ /* get fullpath && file attributes */
strcat(full_path,name);
zf->fname = full_path;
- p = strlen(name)+name+1;
- sscanf((const char *)p, "%ld%lo%o", &zf->bytes_total,&zf->ctime,&zf->mode);
+ p = strlen(name)+name+1;
+ sscanf((const char *)p, "%ld%lo%o", &zf->bytes_total,&zf->ctime,&zf->mode);
#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
- dfs_statfs(working_directory,&buf);
- if (zf->bytes_total > (buf.f_blocks * buf.f_bfree))
- {
- zsend_can();
- rt_kprintf("\b\b\bnot enough disk space\r\n");
- zf->fd = -1;
- rt_free(full_path);
- return -RT_ERROR;
- }
+ dfs_statfs(working_directory,&buf);
+ if (zf->bytes_total > (buf.f_blocks * buf.f_bfree))
+ {
+ zsend_can();
+ rt_kprintf("\b\b\bnot enough disk space\r\n");
+ zf->fd = -1;
+ rt_free(full_path);
+ return -RT_ERROR;
+ }
#else
buf = buf;
#endif
- zf->bytes_received = 0L;
- if ((zf->fd = open(zf->fname,DFS_O_CREAT|DFS_O_WRONLY,0)) < 0) /* create or replace exist file */
- {
- zsend_can();
- rt_kprintf("\b\b\bcan not create file:%s \r\n",zf->fname);
- return -RT_ERROR;
- }
+ zf->bytes_received = 0L;
+ if ((zf->fd = open(zf->fname,DFS_O_CREAT|DFS_O_WRONLY,0)) < 0) /* create or replace exist file */
+ {
+ zsend_can();
+ rt_kprintf("\b\b\bcan not create file:%s \r\n",zf->fname);
+ return -RT_ERROR;
+ }
- return RT_EOK;
+ return RT_EOK;
}
/* receive file data,continously, no ack */
@@ -330,72 +330,72 @@ static rt_err_t zrec_file_data(rt_uint8_t *buf, struct zfile *zf)
rt_err_t res = -RT_ERROR;
more_data:
- res = zget_data(buf,RX_BUFFER_SIZE);
- switch(res)
- {
- case GOTCRCW: /* zack received */
- zwrite_file(buf,Rxcount,zf);
- zf->bytes_received += Rxcount;
- zput_pos(zf->bytes_received);
- zsend_line(XON);
- zsend_hex_header(ZACK, tx_header);
- return RT_EOK;
- case GOTCRCQ:
- zwrite_file(buf,Rxcount,zf);
- zf->bytes_received += Rxcount;
- zput_pos(zf->bytes_received);
- zsend_hex_header(ZACK, tx_header);
- goto more_data;
- case GOTCRCG:
- zwrite_file(buf,Rxcount,zf);
- zf->bytes_received += Rxcount;
- goto more_data;
- case GOTCRCE:
- zwrite_file(buf,Rxcount,zf);
- zf->bytes_received += Rxcount;
- return RT_EOK;
- case GOTCAN:
+ res = zget_data(buf,RX_BUFFER_SIZE);
+ switch(res)
+ {
+ case GOTCRCW: /* zack received */
+ zwrite_file(buf,Rxcount,zf);
+ zf->bytes_received += Rxcount;
+ zput_pos(zf->bytes_received);
+ zsend_line(XON);
+ zsend_hex_header(ZACK, tx_header);
+ return RT_EOK;
+ case GOTCRCQ:
+ zwrite_file(buf,Rxcount,zf);
+ zf->bytes_received += Rxcount;
+ zput_pos(zf->bytes_received);
+ zsend_hex_header(ZACK, tx_header);
+ goto more_data;
+ case GOTCRCG:
+ zwrite_file(buf,Rxcount,zf);
+ zf->bytes_received += Rxcount;
+ goto more_data;
+ case GOTCRCE:
+ zwrite_file(buf,Rxcount,zf);
+ zf->bytes_received += Rxcount;
+ return RT_EOK;
+ case GOTCAN:
#ifdef ZDEBUG
- rt_kprintf("error code : ZCAN \r\n");
+ rt_kprintf("error code : ZCAN \r\n");
#endif
- return res;
- case TIMEOUT:
- return res;
+ return res;
+ case TIMEOUT:
+ return res;
case -RT_ERROR:
- zsend_break(Attn);
- return res;
- default:
- return res;
- }
+ zsend_break(Attn);
+ return res;
+ default:
+ return res;
+ }
}
/* write file */
static rt_err_t zwrite_file(rt_uint8_t *buf,rt_uint16_t size, struct zfile *zf)
{
- return (write(zf->fd,buf,size));
+ return (write(zf->fd,buf,size));
}
/* ack bibi */
static void zrec_ack_bibi(void)
{
- rt_uint8_t i;
+ rt_uint8_t i;
- zput_pos(0L);
- for (i=0;i<3;i++)
- {
- zsend_hex_header(ZFIN, tx_header);
- switch (zread_line(100))
- {
- case 'O':
- zread_line(1);
- return;
- case RCDO:
- return;
- case TIMEOUT:
- default:
- break;
- }
- }
+ zput_pos(0L);
+ for (i=0;i<3;i++)
+ {
+ zsend_hex_header(ZFIN, tx_header);
+ switch (zread_line(100))
+ {
+ case 'O':
+ zread_line(1);
+ return;
+ case RCDO:
+ return;
+ case TIMEOUT:
+ default:
+ break;
+ }
+ }
}
/* end of rz.c */
diff --git a/components/utilities/zmodem/sz.c b/components/utilities/zmodem/sz.c
index 0fde4165f6..0b0b5515f0 100644
--- a/components/utilities/zmodem/sz.c
+++ b/components/utilities/zmodem/sz.c
@@ -1,10 +1,10 @@
/*
* File : sz.c
- * the implemention of sending files to the remote computers
+ * the implemention of sending files to the remote computers
* through the zmodem protocol.
* Change Logs:
* Date Author Notes
- * 2011-03-29 itspy
+ * 2011-03-29 itspy
*/
#include <rtthread.h>
@@ -17,10 +17,10 @@
#include "zdef.h"
-static rt_uint8_t TX_BUFFER[TX_BUFFER_SIZE]; /* sender buffer */
-static rt_uint8_t file_cnt = 0; /* count of number of files opened */
-static rt_uint8_t Rxflags = 0; /* rx parameter flags */
-static rt_uint8_t ZF2_OP; /* file transfer option */
+static rt_uint8_t TX_BUFFER[TX_BUFFER_SIZE]; /* sender buffer */
+static rt_uint8_t file_cnt = 0; /* count of number of files opened */
+static rt_uint8_t Rxflags = 0; /* rx parameter flags */
+static rt_uint8_t ZF2_OP; /* file transfer option */
void zs_start(char *path);
static void zsend_init(void);
@@ -38,233 +38,233 @@ static void zsay_bibi(void);
void zs_start(char *path)
{
struct zfile *zf;
- rt_err_t res = RT_ERROR;
+ rt_err_t res = RT_ERROR;
char *p,*q;
- zf = rt_malloc(sizeof(struct zfile));
- if (zf == RT_NULL)
- {
- rt_kprintf("zf: out of memory\r\n");
- return;
- }
- rt_kprintf("\r\nsz: ready...\r\n"); /* here ready to send things */
- memset(zf, 0, sizeof(struct zfile));
+ zf = rt_malloc(sizeof(struct zfile));
+ if (zf == RT_NULL)
+ {
+ rt_kprintf("zf: out of memory\r\n");
+ return;
+ }
+ rt_kprintf("\r\nsz: ready...\r\n"); /* here ready to send things */
+ memset(zf, 0, sizeof(struct zfile));
zf->fname = path;
- zf->fd = -1;
- res = zsend_files(zf);
- p = zf->fname;
- for (;;)
- {
- q = strstr(p,"/");
- if (q == RT_NULL) break;
- p = q+1;
- }
+ zf->fd = -1;
+ res = zsend_files(zf);
+ p = zf->fname;
+ for (;;)
+ {
+ q = strstr(p,"/");
+ if (q == RT_NULL) break;
+ p = q+1;
+ }
if (res == RT_EOK)
{
rt_kprintf("\r\nfile: %s \r\nsize: %ld bytes\r\nsend completed.\r\n",
- p,zf->bytes_received);
+ p,zf->bytes_received);
}
else
{
rt_kprintf("\r\nfile: %s \r\nsize: 0 bytes\r\nsend failed.\r\n",p);
}
- rt_free(zf);
+ rt_free(zf);
- return;
+ return;
}
/* init the parameters */
static void zsend_init(void)
{
- rt_err_t res = -RT_ERROR;
+ rt_err_t res = -RT_ERROR;
- zinit_parameter();
- for(;;) /* wait ZPAD */
- {
- res = zread_line(800);
- if (res == ZPAD) break;
- }
- for (;;)
- {
- res = zget_header(rx_header);
- if (res == ZRINIT) break;
- }
- if ((rx_header[ZF1] & ZRQNVH))
- {
- zput_pos(0x80L); /* Show we can var header */
- zsend_hex_header(ZRQINIT, tx_header);
- }
- Rxflags = rx_header[ZF0] & 0377;
- if (Rxflags & CANFC32) Txfcs32 = 1; /* used 32bits CRC check */
+ zinit_parameter();
+ for(;;) /* wait ZPAD */
+ {
+ res = zread_line(800);
+ if (res == ZPAD) break;
+ }
+ for (;;)
+ {
+ res = zget_header(rx_header);
+ if (res == ZRINIT) break;
+ }
+ if ((rx_header[ZF1] & ZRQNVH))
+ {
+ zput_pos(0x80L); /* Show we can var header */
+ zsend_hex_header(ZRQINIT, tx_header);
+ }
+ Rxflags = rx_header[ZF0] & 0377;
+ if (Rxflags & CANFC32) Txfcs32 = 1; /* used 32bits CRC check */
- if (ZF2_OP == ZTRLE && (Rxflags & CANRLE)) /* for RLE packet */
- Txfcs32 = 2;
- else
- ZF2_OP = 0;
+ if (ZF2_OP == ZTRLE && (Rxflags & CANRLE)) /* for RLE packet */
+ Txfcs32 = 2;
+ else
+ ZF2_OP = 0;
/* send SINIT cmd */
- return;
+ return;
}
/* send files */
static rt_err_t zsend_files(struct zfile *zf)
{
- char *p,*q;
- char *str = "/";
- struct stat finfo;
- rt_err_t res = -RT_ERROR;
+ char *p,*q;
+ char *str = "/";
+ struct stat finfo;
+ rt_err_t res = -RT_ERROR;
- if (zf->fname == RT_NULL)
- {
- rt_kprintf("\r\nerror: no file to be send.\r\n");
- return res;
- }
- if ((zf->fd=open(zf->fname, DFS_O_RDONLY,0)) <0)
- {
- rt_kprintf("\r\ncan not open file:%s\r\n",zf->fname+1);
- return res;
- }
+ if (zf->fname == RT_NULL)
+ {
+ rt_kprintf("\r\nerror: no file to be send.\r\n");
+ return res;
+ }
+ if ((zf->fd=open(zf->fname, DFS_O_RDONLY,0)) <0)
+ {
+ rt_kprintf("\r\ncan not open file:%s\r\n",zf->fname+1);
+ return res;
+ }
- zf->file_end = 0;
- ++file_cnt;
- /* extract file name */
- p = zf->fname;
- for (;;)
- {
- q = strstr(p,str);
- if (q == RT_NULL) break;
- p = q+1;
- }
- q = (char*)TX_BUFFER;
- for (;;)
- {
- *q++ = *p++;
- if (*p == 0) break;
- }
- *q++ = 0;
- p=q;
- while (q < (char*)(TX_BUFFER + 1024))
- *q++ = 0;
- /* get file attributes */
- fstat(zf->fd,&finfo);
- Left_sizes += finfo.st_size;
- rt_sprintf(p, "%lu %lo %o 3 %d %ld", (long)finfo.st_size, finfo.st_mtime,
- finfo.st_mode, file_cnt, Left_sizes);
- Left_sizes -= finfo.st_size;
- TX_BUFFER[127] = (finfo.st_size + 127) >>7;
- TX_BUFFER[126] = (finfo.st_size + 127) >>15;
+ zf->file_end = 0;
+ ++file_cnt;
+ /* extract file name */
+ p = zf->fname;
+ for (;;)
+ {
+ q = strstr(p,str);
+ if (q == RT_NULL) break;
+ p = q+1;
+ }
+ q = (char*)TX_BUFFER;
+ for (;;)
+ {
+ *q++ = *p++;
+ if (*p == 0) break;
+ }
+ *q++ = 0;
+ p=q;
+ while (q < (char*)(TX_BUFFER + 1024))
+ *q++ = 0;
+ /* get file attributes */
+ fstat(zf->fd,&finfo);
+ Left_sizes += finfo.st_size;
+ rt_sprintf(p, "%lu %lo %o 3 %d %ld", (long)finfo.st_size, finfo.st_mtime,
+ finfo.st_mode, file_cnt, Left_sizes);
+ Left_sizes -= finfo.st_size;
+ TX_BUFFER[127] = (finfo.st_size + 127) >>7;
+ TX_BUFFER[126] = (finfo.st_size + 127) >>15;
- zsend_init();
- /* start sending files */
- res = zsend_file(zf,TX_BUFFER, (p-(char*)TX_BUFFER)+strlen(p)+1);
- zsay_bibi();
- close(zf->fd);
-
- return res;
+ zsend_init();
+ /* start sending files */
+ res = zsend_file(zf,TX_BUFFER, (p-(char*)TX_BUFFER)+strlen(p)+1);
+ zsay_bibi();
+ close(zf->fd);
+
+ return res;
}
/* send file name and related info */
static rt_err_t zsend_file(struct zfile *zf, rt_uint8_t *buf, rt_uint16_t len)
{
- rt_uint8_t cnt;
- rt_err_t res = -RT_ERROR;
+ rt_uint8_t cnt;
+ rt_err_t res = -RT_ERROR;
- for (cnt=0;cnt<5;cnt++)
- {
- tx_header[ZF0] = ZF0_CMD; /* file conversion option */
- tx_header[ZF1] = ZF1_CMD; /* file management option */
- tx_header[ZF2] = (ZF3_CMD|ZF2_OP); /* file transfer option */
- tx_header[ZF3] = ZF3_CMD;
- zsend_bin_header(ZFILE, tx_header);
- zsend_bin_data(buf, len, ZCRCW);
+ for (cnt=0;cnt<5;cnt++)
+ {
+ tx_header[ZF0] = ZF0_CMD; /* file conversion option */
+ tx_header[ZF1] = ZF1_CMD; /* file management option */
+ tx_header[ZF2] = (ZF3_CMD|ZF2_OP); /* file transfer option */
+ tx_header[ZF3] = ZF3_CMD;
+ zsend_bin_header(ZFILE, tx_header);
+ zsend_bin_data(buf, len, ZCRCW);
loop:
- res = zget_header(rx_header);
- switch (res)
- {
- case ZRINIT:
- while ((res = zread_line(50)) > 0)
- {
- if (res == ZPAD)
- {
- goto loop;
- }
- }
- break;
- case ZCAN:
- case TIMEOUT:
- case ZABORT:
- case ZFIN:
+ res = zget_header(rx_header);
+ switch (res)
+ {
+ case ZRINIT:
+ while ((res = zread_line(50)) > 0)
+ {
+ if (res == ZPAD)
+ {
+ goto loop;
+ }
+ }
+ break;
+ case ZCAN:
+ case TIMEOUT:
+ case ZABORT:
+ case ZFIN:
+ break;
+ case -RT_ERROR:
+ case ZNAK:
+ break;
+ case ZCRC: /* no CRC request */
+ goto loop;
+ case ZFERR:
+ case ZSKIP:
break;
- case -RT_ERROR:
- case ZNAK:
- break;
- case ZCRC: /* no CRC request */
- goto loop;
- case ZFERR:
- case ZSKIP:
- break;
- case ZRPOS: /* here we want */
- zget_pos(Rxpos);
- Txpos = Rxpos;
- return(zsend_file_data(zf));
- default:
- break;
- }
- }
+ case ZRPOS: /* here we want */
+ zget_pos(Rxpos);
+ Txpos = Rxpos;
+ return(zsend_file_data(zf));
+ default:
+ break;
+ }
+ }
- return res;
+ return res;
}
/* send the file data */
static rt_err_t zsend_file_data(struct zfile *zf)
{
- rt_int16_t cnt;
- rt_uint8_t cmd;
- rt_err_t res = -RT_ERROR;
- /* send ZDATA packet, start to send data */
+ rt_int16_t cnt;
+ rt_uint8_t cmd;
+ rt_err_t res = -RT_ERROR;
+ /* send ZDATA packet, start to send data */
start_send:
- zput_pos(Txpos);
- zsend_bin_header(ZDATA, tx_header);
- do
- {
- cnt = zfill_buffer(zf,TX_BUFFER,RX_BUFFER_SIZE);
- if (cnt < RX_BUFFER_SIZE )
- cmd = ZCRCE;
- else
- cmd = ZCRCG;
- zsend_bin_data(TX_BUFFER, cnt, cmd);
- zf->bytes_received= Txpos += cnt;
- if (cmd == ZCRCW)
- goto get_syn1;
- } while (cnt == RX_BUFFER_SIZE);
- for (;;) /* get ack and check if send finish */
- {
- zput_pos(Txpos);
- zsend_bin_header(ZEOF, tx_header);
+ zput_pos(Txpos);
+ zsend_bin_header(ZDATA, tx_header);
+ do
+ {
+ cnt = zfill_buffer(zf,TX_BUFFER,RX_BUFFER_SIZE);
+ if (cnt < RX_BUFFER_SIZE )
+ cmd = ZCRCE;
+ else
+ cmd = ZCRCG;
+ zsend_bin_data(TX_BUFFER, cnt, cmd);
+ zf->bytes_received= Txpos += cnt;
+ if (cmd == ZCRCW)
+ goto get_syn1;
+ } while (cnt == RX_BUFFER_SIZE);
+ for (;;) /* get ack and check if send finish */
+ {
+ zput_pos(Txpos);
+ zsend_bin_header(ZEOF, tx_header);
get_syn1:
res = zget_sync();
- switch (res)
- {
- case ZACK:
- goto get_syn1;
- case ZNAK:
- continue;
- case ZRPOS: /* resend here */
- lseek(zf->fd,Txpos,0);
- goto start_send;
- case ZRINIT: /* send finish,then begin to send next file */
- return RT_EOK;
- case ZSKIP:
- case -RT_ERROR:
- return res;
- default:
+ switch (res)
+ {
+ case ZACK:
+ goto get_syn1;
+ case ZNAK:
+ continue;
+ case ZRPOS: /* resend here */
+ lseek(zf->fd,Txpos,0);
+ goto start_send;
+ case ZRINIT: /* send finish,then begin to send next file */
+ return RT_EOK;
+ case ZSKIP:
+ case -RT_ERROR:
return res;
- }
- }
+ default:
+ return res;
+ }
+ }
}
/* fill file data to buffer*/
static rt_uint16_t zfill_buffer(struct zfile *zf, rt_uint8_t *buf, rt_uint16_t size)
{
- return (read(zf->fd,buf,size));
+ return (read(zf->fd,buf,size));
}
/* wait sync(ack) from the receiver */
@@ -272,50 +272,50 @@ static rt_err_t zget_sync(void)
{
rt_err_t res = -RT_ERROR;
- for (;;)
- {
- res = zget_header(rx_header);
- switch (res)
- {
- case ZCAN:
- case ZABORT:
- case ZFIN:
- case TIMEOUT:
- return -RT_ERROR;
- case ZRPOS: /* get pos, need to resend */
- zget_pos(Rxpos);
- Txpos = Rxpos;
- return res;
- case ZACK:
- return res;
- case ZRINIT: /* get ZRINIT indicate that the prev file send completed */
- return res;
- case ZSKIP:
- return res;
- case -RT_ERROR:
- default:
- zsend_bin_header(ZNAK, tx_header);
- continue;
- }
- }
+ for (;;)
+ {
+ res = zget_header(rx_header);
+ switch (res)
+ {
+ case ZCAN:
+ case ZABORT:
+ case ZFIN:
+ case TIMEOUT:
+ return -RT_ERROR;
+ case ZRPOS: /* get pos, need to resend */
+ zget_pos(Rxpos);
+ Txpos = Rxpos;
+ return res;
+ case ZACK:
+ return res;
+ case ZRINIT: /* get ZRINIT indicate that the prev file send completed */
+ return res;
+ case ZSKIP:
+ return res;
+ case -RT_ERROR:
+ default:
+ zsend_bin_header(ZNAK, tx_header);
+ continue;
+ }
+ }
}
/* say "bibi" to the receiver */
static void zsay_bibi(void)
{
- for (;;)
- {
- zput_pos(0L); /* reninit position of next file*/
- zsend_hex_header(ZFIN, tx_header); /* send finished session cmd */
- switch (zget_header(rx_header))
- {
- case ZFIN:
- zsend_line('O');
- zsend_line('O');
- case ZCAN:
- case TIMEOUT:
- return;
- }
- }
+ for (;;)
+ {
+ zput_pos(0L); /* reninit position of next file*/
+ zsend_hex_header(ZFIN, tx_header); /* send finished session cmd */
+ switch (zget_header(rx_header))
+ {
+ case ZFIN:
+ zsend_line('O');
+ zsend_line('O');
+ case ZCAN:
+ case TIMEOUT:
+ return;
+ }
+ }
}
/* end of sz.c */
diff --git a/components/utilities/zmodem/zcore.c b/components/utilities/zmodem/zcore.c
index 02ffbba830..75d9647348 100644
--- a/components/utilities/zmodem/zcore.c
+++ b/components/utilities/zmodem/zcore.c
@@ -3,7 +3,7 @@
* the core functions of implementing zmodem protocol
* Change Logs:
* Date Author Notes
- * 2011-03-29 itspy
+ * 2011-03-29 itspy
*/
#include <rtthread.h>
@@ -16,22 +16,22 @@
#include <stdio.h>
#include "zdef.h"
-char ZF0_CMD; /* file conversion request */
-char ZF1_CMD; /* file management request */
-char ZF2_CMD; /* file transport request */
-char ZF3_CMD;
-rt_uint8_t Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
-rt_uint16_t Rxcount; /* received count*/
-char header_type; /* header type */
-rt_uint8_t rx_header[4]; /* received header */
-rt_uint8_t tx_header[4]; /* transmitted header */
-rt_uint32_t Rxpos; /* received file position */
-rt_uint32_t Txpos; /* transmitted file position */
-rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */
-rt_uint8_t TxCRC; /* controls 32 bit CRC being sent */
-rt_uint8_t RxCRC; /* indicates/controls 32 bit CRC being received */
+char ZF0_CMD; /* file conversion request */
+char ZF1_CMD; /* file management request */
+char ZF2_CMD; /* file transport request */
+char ZF3_CMD;
+rt_uint8_t Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
+rt_uint16_t Rxcount; /* received count*/
+char header_type; /* header type */
+rt_uint8_t rx_header[4]; /* received header */
+rt_uint8_t tx_header[4]; /* transmitted header */
+rt_uint32_t Rxpos; /* received file position */
+rt_uint32_t Txpos; /* transmitted file position */
+rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */
+rt_uint8_t TxCRC; /* controls 32 bit CRC being sent */
+rt_uint8_t RxCRC; /* indicates/controls 32 bit CRC being received */
/* 0 == CRC16, 1 == CRC32, 2 == CRC32 + RLE */
-char Attn[ZATTNLEN+1]; /* attention string rx sends to tx on err */
+char Attn[ZATTNLEN+1]; /* attention string rx sends to tx on err */
void zinit_parameter(void);
void zsend_bin_header(rt_uint8_t type, rt_uint8_t *hdr);
@@ -52,670 +52,670 @@ rt_int16_t zread_byte(void);
rt_int16_t zxor_read(void);
void zput_pos(rt_uint32_t pos);
void zget_pos(rt_uint32_t pos);
-
-
+
+
void zinit_parameter(void)
{
rt_uint8_t i;
- ZF0_CMD = CANFC32|CANFDX|CANOVIO; /* not chose CANFC32,CANRLE,although it have been supported */
- ZF1_CMD = 0; /* fix header length,not support CANVHDR */
- ZF2_CMD = 0;
- ZF3_CMD = 0;
- Rxframeind =0;
- header_type = 0;
- Rxcount = 0;
- for (i=0;i<4;i++) rx_header[i] = tx_header[i] = 0;
- Rxpos = Txpos = 0;
- RxCRC = 0;
- Txfcs32 = 0;
+ ZF0_CMD = CANFC32|CANFDX|CANOVIO; /* not chose CANFC32,CANRLE,although it have been supported */
+ ZF1_CMD = 0; /* fix header length,not support CANVHDR */
+ ZF2_CMD = 0;
+ ZF3_CMD = 0;
+ Rxframeind =0;
+ header_type = 0;
+ Rxcount = 0;
+ for (i=0;i<4;i++) rx_header[i] = tx_header[i] = 0;
+ Rxpos = Txpos = 0;
+ RxCRC = 0;
+ Txfcs32 = 0;
- return ;
+ return ;
}
/* send binary header */
void zsend_bin_header(rt_uint8_t type, rt_uint8_t *hdr)
{
- rt_uint8_t i;
- rt_uint32_t crc;
+ rt_uint8_t i;
+ rt_uint32_t crc;
- zsend_byte(ZPAD);
- zsend_byte(ZDLE);
- TxCRC = Txfcs32;
- if (TxCRC == 0)
- {
- zsend_byte(ZBIN);
- zsend_zdle_char(type);
- /* add 16bits crc */
- crc = 0L;
- crc = updcrc16(type, 0);
- for (i=0;i<4;i++)
- {
- zsend_zdle_char(*hdr);
- crc = updcrc16((0377 & *hdr++),crc);
- }
- crc = updcrc16(0,updcrc16(0,crc));
- zsend_zdle_char(((int)(crc>>8)));
- zsend_zdle_char(crc);
- }
- else if(TxCRC == 1)
- {
+ zsend_byte(ZPAD);
+ zsend_byte(ZDLE);
+ TxCRC = Txfcs32;
+ if (TxCRC == 0)
+ {
+ zsend_byte(ZBIN);
+ zsend_zdle_char(type);
+ /* add 16bits crc */
+ crc = 0L;
+ crc = updcrc16(type, 0);
+ for (i=0;i<4;i++)
+ {
+ zsend_zdle_char(*hdr);
+ crc = updcrc16((0377 & *hdr++),crc);
+ }
+ crc = updcrc16(0,updcrc16(0,crc));
+ zsend_zdle_char(((int)(crc>>8)));
+ zsend_zdle_char(crc);
+ }
+ else if(TxCRC == 1)
+ {
zsend_byte(ZBIN32);
- zsend_zdle_char(type);
- /* add 32bits crc */
- crc = 0xffffffffL;
- crc = updcrc32(type, crc);
+ zsend_zdle_char(type);
+ /* add 32bits crc */
+ crc = 0xffffffffL;
+ crc = updcrc32(type, crc);
for (i=0;i<4;i++)
- {
- zsend_zdle_char(*hdr);
- crc = updcrc32((0377 & *hdr++), crc);
- }
- crc = ~crc;
- for (i=0; i<4;i++)
- {
- zsend_zdle_char(crc);
- crc >>= 8;
- }
- }
- else if (TxCRC == 2)
- {
- zsend_byte(ZBINR32);
- zsend_zdle_char(type);
- /* add 32bits crc */
- crc = 0xffffffffL;
- crc = updcrc32(type, crc);
+ {
+ zsend_zdle_char(*hdr);
+ crc = updcrc32((0377 & *hdr++), crc);
+ }
+ crc = ~crc;
+ for (i=0; i<4;i++)
+ {
+ zsend_zdle_char(crc);
+ crc >>= 8;
+ }
+ }
+ else if (TxCRC == 2)
+ {
+ zsend_byte(ZBINR32);
+ zsend_zdle_char(type);
+ /* add 32bits crc */
+ crc = 0xffffffffL;
+ crc = updcrc32(type, crc);
for (i=0;i<4;i++)
- {
- zsend_zdle_char(*hdr);
- crc = updcrc32((0377 & *hdr++), crc);
- }
- crc = ~crc;
- for (i=0; i<4;i++)
- {
- zsend_zdle_char(crc);
- crc >>= 8;
- }
- }
+ {
+ zsend_zdle_char(*hdr);
+ crc = updcrc32((0377 & *hdr++), crc);
+ }
+ crc = ~crc;
+ for (i=0; i<4;i++)
+ {
+ zsend_zdle_char(crc);
+ crc >>= 8;
+ }
+ }
- return;
+ return;
}
/* send hex header */
void zsend_hex_header(rt_uint8_t type, rt_uint8_t *hdr)
{
- rt_uint8_t i;
- rt_uint16_t crc;
+ rt_uint8_t i;
+ rt_uint16_t crc;
- zsend_line(ZPAD); zsend_line(ZPAD); zsend_line(ZDLE);
- zsend_line(ZHEX);
- zsend_ascii(type);
- crc = updcrc16(type, 0);
- for (i=0; i<4; i++)
- {
- zsend_ascii(*hdr);
- crc = updcrc16((0377 & *hdr++), crc);
- }
- crc = updcrc16(0,updcrc16(0,crc));
- zsend_ascii(crc>>8);
- zsend_ascii(crc);
- /* send display control cmd */
- zsend_line(015); zsend_line(0212);
- if (type != ZFIN && type != ZACK)
- zsend_line(021);
- TxCRC = 0; /* clear tx crc type */
+ zsend_line(ZPAD); zsend_line(ZPAD); zsend_line(ZDLE);
+ zsend_line(ZHEX);
+ zsend_ascii(type);
+ crc = updcrc16(type, 0);
+ for (i=0; i<4; i++)
+ {
+ zsend_ascii(*hdr);
+ crc = updcrc16((0377 & *hdr++), crc);
+ }
+ crc = updcrc16(0,updcrc16(0,crc));
+ zsend_ascii(crc>>8);
+ zsend_ascii(crc);
+ /* send display control cmd */
+ zsend_line(015); zsend_line(0212);
+ if (type != ZFIN && type != ZACK)
+ zsend_line(021);
+ TxCRC = 0; /* clear tx crc type */
- return;
+ return;
}
/* send binary data,with frameend */
void zsend_bin_data(rt_uint8_t *buf, rt_int16_t len, rt_uint8_t frameend)
{
rt_int16_t i,c,tmp;
- rt_uint32_t crc;
+ rt_uint32_t crc;
if (TxCRC == 0) /* send binary data with 16bits crc check */
- {
- crc = 0x0L;
- for (i=0;i<len;i++)
- {
- zsend_zdle_char(*buf);
- crc = updcrc16((0377 & *buf++), crc);
- }
- zsend_byte(ZDLE); zsend_byte(frameend);
- crc = updcrc16(frameend, crc);
- crc = updcrc16(0,updcrc16(0,crc));
- zsend_zdle_char(crc>>8);
- zsend_zdle_char(crc);
- }
- else if (TxCRC == 1) /* send binary data with 32 bits crc check */
- {
- crc = 0xffffffffL;
- for (i=0;i<len;i++)
- {
- c = *buf++ & 0377;
- zsend_zdle_char(c);
- crc = updcrc32(c, crc);
- }
- zsend_byte(ZDLE); zsend_byte(frameend);
- crc = updcrc32(frameend, crc);
- crc = ~crc;
- for (i=0;i<4;i++)
- {
- zsend_zdle_char((int)crc); crc >>= 8;
- }
- }
- else if (TxCRC == 2) /* send binary data with 32bits crc check,RLE encode */
- {
- crc = 0xffffffffL;
+ {
+ crc = 0x0L;
+ for (i=0;i<len;i++)
+ {
+ zsend_zdle_char(*buf);
+ crc = updcrc16((0377 & *buf++), crc);
+ }
+ zsend_byte(ZDLE); zsend_byte(frameend);
+ crc = updcrc16(frameend, crc);
+ crc = updcrc16(0,updcrc16(0,crc));
+ zsend_zdle_char(crc>>8);
+ zsend_zdle_char(crc);
+ }
+ else if (TxCRC == 1) /* send binary data with 32 bits crc check */
+ {
+ crc = 0xffffffffL;
+ for (i=0;i<len;i++)
+ {
+ c = *buf++ & 0377;
+ zsend_zdle_char(c);
+ crc = updcrc32(c, crc);
+ }
+ zsend_byte(ZDLE); zsend_byte(frameend);
+ crc = updcrc32(frameend, crc);
+ crc = ~crc;
+ for (i=0;i<4;i++)
+ {
+ zsend_zdle_char((int)crc); crc >>= 8;
+ }
+ }
+ else if (TxCRC == 2) /* send binary data with 32bits crc check,RLE encode */
+ {
+ crc = 0xffffffffL;
tmp = *buf++ & 0377;
- for (i = 0; --len >= 0; ++buf)
- {
- if ((c = *buf & 0377) == tmp && i < 126 && len>0)
- {
- ++i; continue;
- }
- if (i==0)
- {
- zsend_zdle_char(tmp);
- crc = updcrc32(tmp, crc);
- if (tmp == ZRESC)
- {
- zsend_zdle_char(0100); crc = updcrc32(0100, crc);
- }
- tmp = c;
- }
- else if (i == 1)
- {
- if (tmp != ZRESC)
- {
- zsend_zdle_char(tmp); zsend_zdle_char(tmp);
- crc = updcrc32(tmp, crc);
- crc = updcrc32(tmp, crc);
- i = 0; tmp = c;
- }
+ for (i = 0; --len >= 0; ++buf)
+ {
+ if ((c = *buf & 0377) == tmp && i < 126 && len>0)
+ {
+ ++i; continue;
+ }
+ if (i==0)
+ {
+ zsend_zdle_char(tmp);
+ crc = updcrc32(tmp, crc);
+ if (tmp == ZRESC)
+ {
+ zsend_zdle_char(0100); crc = updcrc32(0100, crc);
+ }
+ tmp = c;
+ }
+ else if (i == 1)
+ {
+ if (tmp != ZRESC)
+ {
+ zsend_zdle_char(tmp); zsend_zdle_char(tmp);
+ crc = updcrc32(tmp, crc);
+ crc = updcrc32(tmp, crc);
+ i = 0; tmp = c;
+ }
- }
- else
- {
- zsend_zdle_char(ZRESC); crc = updcrc32(ZRESC, crc);
- if (tmp == 040 && i < 34)
- {
- i += 036;
- zsend_zdle_char(i);
- crc = updcrc32(i, crc);
- }
- else
- {
- i += 0101;
- zsend_zdle_char(i); crc = updcrc32(i, crc);
- zsend_zdle_char(tmp); crc = updcrc32(tmp, crc);
- }
- i = 0; tmp = c;
- }
- }
- zsend_byte(ZDLE); zsend_byte(frameend);
- crc = updcrc32(frameend, crc);
- crc = ~crc;
- for (i=0;i<4;i++)
- {
- zsend_zdle_char(crc);
- crc >>= 8;
- }
- }
- if (frameend == ZCRCW)
- zsend_byte(XON);
+ }
+ else
+ {
+ zsend_zdle_char(ZRESC); crc = updcrc32(ZRESC, crc);
+ if (tmp == 040 && i < 34)
+ {
+ i += 036;
+ zsend_zdle_char(i);
+ crc = updcrc32(i, crc);
+ }
+ else
+ {
+ i += 0101;
+ zsend_zdle_char(i); crc = updcrc32(i, crc);
+ zsend_zdle_char(tmp); crc = updcrc32(tmp, crc);
+ }
+ i = 0; tmp = c;
+ }
+ }
+ zsend_byte(ZDLE); zsend_byte(frameend);
+ crc = updcrc32(frameend, crc);
+ crc = ~crc;
+ for (i=0;i<4;i++)
+ {
+ zsend_zdle_char(crc);
+ crc >>= 8;
+ }
+ }
+ if (frameend == ZCRCW)
+ zsend_byte(XON);
- return;
+ return;
}
/* receive data,with 16bits CRC check */
static rt_int16_t zrec_data16(rt_uint8_t *buf, rt_uint16_t len)
{
- rt_int16_t c,crc_cnt;
- rt_uint16_t crc;
- rt_err_t res = -RT_ERROR;
- rt_uint8_t *p,flag = 0;
+ rt_int16_t c,crc_cnt;
+ rt_uint16_t crc;
+ rt_err_t res = -RT_ERROR;
+ rt_uint8_t *p,flag = 0;
- p = buf;
- crc_cnt = 0; crc = 0L;
- Rxcount = 0;
- while(buf <= p+len)
- {
- if ((res = zread_byte()) & ~0377)
- {
- if (res == GOTCRCE || res == GOTCRCG ||
- res == GOTCRCQ || res == GOTCRCW)
- {
- c = res;
- c = res;
- crc = updcrc16(res&0377, crc);
- flag = 1;
- continue;
- }
- else if (res == GOTCAN) return ZCAN;
- else if (res == TIMEOUT) return TIMEOUT;
- else return res;
+ p = buf;
+ crc_cnt = 0; crc = 0L;
+ Rxcount = 0;
+ while(buf <= p+len)
+ {
+ if ((res = zread_byte()) & ~0377)
+ {
+ if (res == GOTCRCE || res == GOTCRCG ||
+ res == GOTCRCQ || res == GOTCRCW)
+ {
+ c = res;
+ c = res;
+ crc = updcrc16(res&0377, crc);
+ flag = 1;
+ continue;
+ }
+ else if (res == GOTCAN) return ZCAN;
+ else if (res == TIMEOUT) return TIMEOUT;
+ else return res;
- }
- else
- {
- if (flag)
- {
- crc = updcrc16(res, crc);
- crc_cnt++;
- if (crc_cnt < 2) continue;
- if ((crc & 0xffff))
- {
+ }
+ else
+ {
+ if (flag)
+ {
+ crc = updcrc16(res, crc);
+ crc_cnt++;
+ if (crc_cnt < 2) continue;
+ if ((crc & 0xffff))
+ {
#ifdef ZDEBUG
- rt_kprintf("error code: CRC16 error \r\n");
+ rt_kprintf("error code: CRC16 error \r\n");
#endif
- return -RT_ERROR;
- }
+ return -RT_ERROR;
+ }
return c;
- }
- else
- {
- *buf++ = res;
- Rxcount++;
- crc = updcrc16(res, crc);
- }
- }
- }
+ }
+ else
+ {
+ *buf++ = res;
+ Rxcount++;
+ crc = updcrc16(res, crc);
+ }
+ }
+ }
- return -RT_ERROR;
+ return -RT_ERROR;
}
/* receive data,with 32bits CRC check */
static rt_int16_t zrec_data32(rt_uint8_t *buf, rt_int16_t len)
{
- rt_int16_t c,crc_cnt;
- rt_uint32_t crc;
- rt_err_t res = -RT_ERROR;
- rt_uint8_t *p,flag = 0;
+ rt_int16_t c,crc_cnt;
+ rt_uint32_t crc;
+ rt_err_t res = -RT_ERROR;
+ rt_uint8_t *p,flag = 0;
- crc_cnt = 0; crc = 0xffffffffL;
- Rxcount = 0;
- while (buf <= p+len)
- {
- if ((res = zread_byte()) & ~0377)
- {
- if (res == GOTCRCE || res == GOTCRCG ||
- res == GOTCRCQ || res == GOTCRCW)
- {
- c = res;
- crc = updcrc32(res&0377, crc);
- flag = 1;
- continue;
- }
- else if (res == GOTCAN) return ZCAN;
- else if (res == TIMEOUT) return TIMEOUT;
- else return res;
+ crc_cnt = 0; crc = 0xffffffffL;
+ Rxcount = 0;
+ while (buf <= p+len)
+ {
+ if ((res = zread_byte()) & ~0377)
+ {
+ if (res == GOTCRCE || res == GOTCRCG ||
+ res == GOTCRCQ || res == GOTCRCW)
+ {
+ c = res;
+ crc = updcrc32(res&0377, crc);
+ flag = 1;
+ continue;
+ }
+ else if (res == GOTCAN) return ZCAN;
+ else if (res == TIMEOUT) return TIMEOUT;
+ else return res;
- }
- else
- {
- if (flag)
- {
- crc = updcrc32(res, crc);
- crc_cnt++;
- if (crc_cnt < 4) continue;
- if ((crc & 0xDEBB20E3))
- {
+ }
+ else
+ {
+ if (flag)
+ {
+ crc = updcrc32(res, crc);
+ crc_cnt++;
+ if (crc_cnt < 4) continue;
+ if ((crc & 0xDEBB20E3))
+ {
#ifdef ZDEBUG
- rt_kprintf("error code: CRC32 error \r\n");
+ rt_kprintf("error code: CRC32 error \r\n");
#endif
- return -RT_ERROR;
- }
+ return -RT_ERROR;
+ }
return c;
- }
- else
- {
- *buf++ = res;
- Rxcount++;
- crc = updcrc32(res, crc);
- }
- }
- }
+ }
+ else
+ {
+ *buf++ = res;
+ Rxcount++;
+ crc = updcrc32(res, crc);
+ }
+ }
+ }
- return -RT_ERROR;
+ return -RT_ERROR;
}
/* receive data,with RLE encoded,32bits CRC check */
static rt_int16_t zrec_data32r(rt_uint8_t *buf, rt_int16_t len)
{
- rt_int16_t c,crc_cnt;
- rt_uint32_t crc;
- rt_err_t res = -RT_ERROR;
- rt_uint8_t *p,flag = 0;
+ rt_int16_t c,crc_cnt;
+ rt_uint32_t crc;
+ rt_err_t res = -RT_ERROR;
+ rt_uint8_t *p,flag = 0;
- crc_cnt = 0; crc = 0xffffffffL;
- Rxcount = 0;
- p = buf;
- while (buf <= p+len)
- {
- if ((res = zread_byte()) & ~0377)
- {
- if (res == GOTCRCE || res == GOTCRCG ||
- res == GOTCRCQ || res == GOTCRCW)
- {
- c = res;
- crc = updcrc32(res&0377, crc);
- flag = 1;
- continue;
- }
- else if (res == GOTCAN) return ZCAN;
- else if (res == TIMEOUT) return TIMEOUT;
- else return res;
+ crc_cnt = 0; crc = 0xffffffffL;
+ Rxcount = 0;
+ p = buf;
+ while (buf <= p+len)
+ {
+ if ((res = zread_byte()) & ~0377)
+ {
+ if (res == GOTCRCE || res == GOTCRCG ||
+ res == GOTCRCQ || res == GOTCRCW)
+ {
+ c = res;
+ crc = updcrc32(res&0377, crc);
+ flag = 1;
+ continue;
+ }
+ else if (res == GOTCAN) return ZCAN;
+ else if (res == TIMEOUT) return TIMEOUT;
+ else return res;
- }
- else
- {
- if (flag)
- {
- crc = updcrc32(res, crc);
- crc_cnt++;
- if (crc_cnt < 4) continue;
- if ((crc & 0xDEBB20E3))
- {
+ }
+ else
+ {
+ if (flag)
+ {
+ crc = updcrc32(res, crc);
+ crc_cnt++;
+ if (crc_cnt < 4) continue;
+ if ((crc & 0xDEBB20E3))
+ {
#ifdef ZDEBUG
- rt_kprintf("error code: CRC32 error \r\n");
+ rt_kprintf("error code: CRC32 error \r\n");
#endif
- return -RT_ERROR;
- }
+ return -RT_ERROR;
+ }
return c;
- }
- else
- {
- crc = updcrc32(res, crc);
- switch (c)
- {
- case 0:
- if (res == ZRESC)
- {
- c = -1; continue;
- }
- *buf++ = res;
- Rxcount++;
- continue;
- case -1:
- if (res >= 040 && res < 0100)
- {
- c = res - 035; res = 040;
- goto spaces;
- }
- if (res == 0100)
- {
- c = 0;
- *buf++ = ZRESC;
- Rxcount++;
- continue;
- }
- c = res; continue;
- default:
- c -= 0100;
- if (c < 1)
- goto end;
+ }
+ else
+ {
+ crc = updcrc32(res, crc);
+ switch (c)
+ {
+ case 0:
+ if (res == ZRESC)
+ {
+ c = -1; continue;
+ }
+ *buf++ = res;
+ Rxcount++;
+ continue;
+ case -1:
+ if (res >= 040 && res < 0100)
+ {
+ c = res - 035; res = 040;
+ goto spaces;
+ }
+ if (res == 0100)
+ {
+ c = 0;
+ *buf++ = ZRESC;
+ Rxcount++;
+ continue;
+ }
+ c = res; continue;
+ default:
+ c -= 0100;
+ if (c < 1)
+ goto end;
spaces:
- if ((buf + c) > p+len)
- goto end;
- while ( --res >= 0)
- {
- *buf++ = res;
- Rxcount++;
- }
- c = 0; continue;
- }
- }
- } // if -else
+ if ((buf + c) > p+len)
+ goto end;
+ while ( --res >= 0)
+ {
+ *buf++ = res;
+ Rxcount++;
+ }
+ c = 0; continue;
+ }
+ }
+ } // if -else
- }
+ }
end:
- return -RT_ERROR;
+ return -RT_ERROR;
}
rt_int16_t zget_data(rt_uint8_t *buf, rt_uint16_t len)
{
- rt_int16_t res = -RT_ERROR;
+ rt_int16_t res = -RT_ERROR;
- if (RxCRC == 0)
- {
- res = zrec_data16(buf,len);
- }
- else if (RxCRC == 1)
- {
- res = zrec_data32(buf, len);
- }
- else if (RxCRC == 2)
- {
- res = zrec_data32r(buf, len);
- }
+ if (RxCRC == 0)
+ {
+ res = zrec_data16(buf,len);
+ }
+ else if (RxCRC == 1)
+ {
+ res = zrec_data32(buf, len);
+ }
+ else if (RxCRC == 2)
+ {
+ res = zrec_data32r(buf, len);
+ }
- return res;
+ return res;
}
/* get type and cmd of header, fix lenght */
rt_int16_t zget_header(rt_uint8_t *hdr)
{
- rt_int16_t c,prev_char;
- rt_uint32_t bit;
- rt_uint16_t get_can,step_out;
+ rt_int16_t c,prev_char;
+ rt_uint32_t bit;
+ rt_uint16_t get_can,step_out;
- bit = get_device_baud(); /* get console baud rate */
- Rxframeind = header_type = 0;
+ bit = get_device_baud(); /* get console baud rate */
+ Rxframeind = header_type = 0;
step_out = 0;
- prev_char = 0xff;
- for (;;)
- {
- c = zread_line(100);
- switch(c)
- {
- case 021:
- case 0221:
- if (prev_char == CAN) break;
- if (prev_char == ZCRCW) goto start_again;
- break;
- case RCDO:
- goto end;
- case TIMEOUT:
- if (prev_char == CAN) break;
- if (prev_char == ZCRCW)
- {
- c = -RT_ERROR; goto end;
- }
- goto end;
- case ZCRCW:
- if (prev_char == CAN) goto start_again;
- break;
- case CAN:
+ prev_char = 0xff;
+ for (;;)
+ {
+ c = zread_line(100);
+ switch(c)
+ {
+ case 021:
+ case 0221:
+ if (prev_char == CAN) break;
+ if (prev_char == ZCRCW) goto start_again;
+ break;
+ case RCDO:
+ goto end;
+ case TIMEOUT:
+ if (prev_char == CAN) break;
+ if (prev_char == ZCRCW)
+ {
+ c = -RT_ERROR; goto end;
+ }
+ goto end;
+ case ZCRCW:
+ if (prev_char == CAN) goto start_again;
+ break;
+ case CAN:
get_can:
- if (++get_can > 5)
- {
- c = ZCAN; goto end;
+ if (++get_can > 5)
+ {
+ c = ZCAN; goto end;
}
- break;
- case ZPAD:
- if (prev_char == CAN) break;
- if (prev_char == ZCRCW) goto start_again;
- step_out = 1;
- break;
- default:
- if (prev_char == CAN) break;
- if (prev_char == ZCRCW) goto start_again;
+ break;
+ case ZPAD:
+ if (prev_char == CAN) break;
+ if (prev_char == ZCRCW) goto start_again;
+ step_out = 1;
+ break;
+ default:
+ if (prev_char == CAN) break;
+ if (prev_char == ZCRCW) goto start_again;
start_again:
- if (--bit == 0)
- {
- c = GCOUNT; goto end;
- }
- get_can = 0;
- break;
- }
- prev_char = c;
- if (step_out) break; /* exit loop */
- }
- step_out = get_can = 0;
- for (;;)
- {
- c = zxor_read();
- switch(c)
- {
- case ZPAD:
- break;
- case RCDO:
- case TIMEOUT:
- goto end;
- case ZDLE:
- step_out = 1;
- break;
- default:
- goto start_again;
- }
- if (step_out) break;
- }
-
- Rxframeind = c = zxor_read();
- switch (c)
- {
- case ZBIN32:
- RxCRC = 1; c = zget_bin_fcs(hdr); break;
- case ZBINR32:
- RxCRC = 2; c = zget_bin_fcs(hdr); break;
- case ZBIN:
- RxCRC = 0; c = zget_bin_header(hdr); break;
- case ZHEX:
- RxCRC = 0; c = zget_hex_header(hdr); break;
- case CAN:
- goto get_can;
- case RCDO:
- case TIMEOUT:
- goto end;
- default:
- goto start_again;
- }
+ if (--bit == 0)
+ {
+ c = GCOUNT; goto end;
+ }
+ get_can = 0;
+ break;
+ }
+ prev_char = c;
+ if (step_out) break; /* exit loop */
+ }
+ step_out = get_can = 0;
+ for (;;)
+ {
+ c = zxor_read();
+ switch(c)
+ {
+ case ZPAD:
+ break;
+ case RCDO:
+ case TIMEOUT:
+ goto end;
+ case ZDLE:
+ step_out = 1;
+ break;
+ default:
+ goto start_again;
+ }
+ if (step_out) break;
+ }
+
+ Rxframeind = c = zxor_read();
+ switch (c)
+ {
+ case ZBIN32:
+ RxCRC = 1; c = zget_bin_fcs(hdr); break;
+ case ZBINR32:
+ RxCRC = 2; c = zget_bin_fcs(hdr); break;
+ case ZBIN:
+ RxCRC = 0; c = zget_bin_header(hdr); break;
+ case ZHEX:
+ RxCRC = 0; c = zget_hex_header(hdr); break;
+ case CAN:
+ goto get_can;
+ case RCDO:
+ case TIMEOUT:
+ goto end;
+ default:
+ goto start_again;
+ }
end:
- return c;
+ return c;
}
/* receive a binary header */
static rt_int16_t zget_bin_header(rt_uint8_t *hdr)
{
- rt_int16_t res, i;
- rt_uint16_t crc;
+ rt_int16_t res, i;
+ rt_uint16_t crc;
- if ((res = zread_byte()) & ~0377)
- return res;
- header_type = res;
- crc = updcrc16(res, 0);
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ header_type = res;
+ crc = updcrc16(res, 0);
- for (i=0;i<4;i++)
- {
- if ((res = zread_byte()) & ~0377)
- return res;
- crc = updcrc16(res, crc);
- *hdr++ = res;
- }
- if ((res = zread_byte()) & ~0377)
- return res;
- crc = updcrc16(res, crc);
- if ((res = zread_byte()) & ~0377)
- return res;
- crc = updcrc16(res, crc);
- if (crc & 0xFFFF)
- {
- rt_kprintf("CRC error\n");
- return -RT_ERROR;
- }
+ for (i=0;i<4;i++)
+ {
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ crc = updcrc16(res, crc);
+ *hdr++ = res;
+ }
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ crc = updcrc16(res, crc);
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ crc = updcrc16(res, crc);
+ if (crc & 0xFFFF)
+ {
+ rt_kprintf("CRC error\n");
+ return -RT_ERROR;
+ }
- return header_type;
+ return header_type;
}
/* receive a binary header,with 32bits FCS */
static rt_int16_t zget_bin_fcs(rt_uint8_t *hdr)
{
- rt_int16_t res, i;
- rt_uint32_t crc;
+ rt_int16_t res, i;
+ rt_uint32_t crc;
- if ((res = zread_byte()) & ~0377)
- return res;
- header_type = res;
- crc = 0xFFFFFFFFL;
- crc = updcrc32(res, crc);
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ header_type = res;
+ crc = 0xFFFFFFFFL;
+ crc = updcrc32(res, crc);
- for (i=0;i<4;i++) /* 4headers */
- {
- if ((res = zread_byte()) & ~0377)
- return res;
- crc = updcrc32(res, crc);
- *hdr++ = res;
+ for (i=0;i<4;i++) /* 4headers */
+ {
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ crc = updcrc32(res, crc);
+ *hdr++ = res;
- }
- for (i=0;i<4;i++) /* 4bytes crc */
- {
- if ((res = zread_byte()) & ~0377)
- return res;
- crc = updcrc32(res, crc);
+ }
+ for (i=0;i<4;i++) /* 4bytes crc */
+ {
+ if ((res = zread_byte()) & ~0377)
+ return res;
+ crc = updcrc32(res, crc);
- }
- if (crc != 0xDEBB20E3)
- {
+ }
+ if (crc != 0xDEBB20E3)
+ {
#ifdef ZDEBUG
- rt_kprintf("CRC error\n");
+ rt_kprintf("CRC error\n");
#endif
- return -RT_ERROR;
- }
+ return -RT_ERROR;
+ }
- return header_type;
+ return header_type;
}
/* receive a hex style header (type and position) */
rt_int16_t zget_hex_header(rt_uint8_t *hdr)
{
- rt_int16_t res,i;
- rt_uint16_t crc;
+ rt_int16_t res,i;
+ rt_uint16_t crc;
- if ((res = zget_hex()) < 0)
- return res;
- header_type = res;
- crc = updcrc16(res, 0);
+ if ((res = zget_hex()) < 0)
+ return res;
+ header_type = res;
+ crc = updcrc16(res, 0);
- for (i=0;i<4;i++)
- {
- if ((res = zget_hex()) < 0)
- return res;
- crc = updcrc16(res, crc);
- *hdr++ = res;
- }
- if ((res = zget_hex()) < 0)
- return res;
- crc = updcrc16(res, crc);
- if ((res = zget_hex()) < 0)
- return res;
- crc = updcrc16(res, crc);
- if (crc & 0xFFFF)
- {
+ for (i=0;i<4;i++)
+ {
+ if ((res = zget_hex()) < 0)
+ return res;
+ crc = updcrc16(res, crc);
+ *hdr++ = res;
+ }
+ if ((res = zget_hex()) < 0)
+ return res;
+ crc = updcrc16(res, crc);
+ if ((res = zget_hex()) < 0)
+ return res;
+ crc = updcrc16(res, crc);
+ if (crc & 0xFFFF)
+ {
#ifdef ZDEBUG
- rt_kprintf("error code : CRC error\r\n");
+ rt_kprintf("error code : CRC error\r\n");
#endif
- return -RT_ERROR;
- }
- res = zread_line(100);
- if (res < 0)
- return res;
- res = zread_line(100);
- if (res < 0)
- return res;
+ return -RT_ERROR;
+ }
+ res = zread_line(100);
+ if (res < 0)
+ return res;
+ res = zread_line(100);
+ if (res < 0)
+ return res;
- return header_type;
+ return header_type;
}
/* convert to ascii */
static void zsend_ascii(rt_uint8_t c)
{
- const char hex[] = "0123456789abcdef";
+ const char hex[] = "0123456789abcdef";
- zsend_line(hex[(c&0xF0)>>4]);
- zsend_line(hex[(c)&0xF]);
+ zsend_line(hex[(c&0xF0)>>4]);
+ zsend_line(hex[(c)&0xF]);
- return;
+ return;
}
/*
@@ -723,54 +723,54 @@ static void zsend_ascii(rt_uint8_t c)
*/
void zsend_zdle_char(rt_uint16_t ch)
{
- rt_uint16_t res;
+ rt_uint16_t res;
- res = ch & 0377;
- switch (res)
- {
- case 0377:
- zsend_byte(res);
- break;
- case ZDLE:
- zsend_byte(ZDLE);
- res ^= 0100;
- zsend_byte(res);
- break;
- case 021:
- case 023:
- case 0221:
- case 0223:
- zsend_byte(ZDLE);
- res ^= 0100;
- zsend_byte(res);
- break;
- default:
- zsend_byte(res);
- }
+ res = ch & 0377;
+ switch (res)
+ {
+ case 0377:
+ zsend_byte(res);
+ break;
+ case ZDLE:
+ zsend_byte(ZDLE);
+ res ^= 0100;
+ zsend_byte(res);
+ break;
+ case 021:
+ case 023:
+ case 0221:
+ case 0223:
+ zsend_byte(ZDLE);
+ res ^= 0100;
+ zsend_byte(res);
+ break;
+ default:
+ zsend_byte(res);
+ }
}
/* decode two lower case hex digits into an 8 bit byte value */
static rt_int16_t zget_hex(void)
{
- rt_int16_t res,n;
+ rt_int16_t res,n;
- if ((res = zxor_read()) < 0)
- return res;
- n = res - '0';
- if (n > 9)
- n -= ('a' - ':');
- if (n & ~0x0f)
- return -RT_ERROR;
- if ((res = zxor_read()) < 0)
- return res;
- res -= '0';
- if (res > 9)
- res -= ('a' - ':');
- if (res & ~0x0f)
- return -RT_ERROR;
- res += (n<<4);
+ if ((res = zxor_read()) < 0)
+ return res;
+ n = res - '0';
+ if (n > 9)
+ n -= ('a' - ':');
+ if (n & ~0x0f)
+ return -RT_ERROR;
+ if ((res = zxor_read()) < 0)
+ return res;
+ res -= '0';
+ if (res > 9)
+ res -= ('a' - ':');
+ if (res & ~0x0f)
+ return -RT_ERROR;
+ res += (n<<4);
- return res;
+ return res;
}
@@ -780,58 +780,58 @@ static rt_int16_t zget_hex(void)
*/
rt_int16_t zread_byte(void)
{
- register int res;
+ register int res;
again:
- /* Quick check for non control characters */
- if ((res = zread_line(100)) & 0140)
- return res;
- switch (res)
- {
- case ZDLE:
- break;
- case 023:
- case 0223:
- case 021:
- case 0221:
- goto again;
- default:
- return res;
- }
+ /* Quick check for non control characters */
+ if ((res = zread_line(100)) & 0140)
+ return res;
+ switch (res)
+ {
+ case ZDLE:
+ break;
+ case 023:
+ case 0223:
+ case 021:
+ case 0221:
+ goto again;
+ default:
+ return res;
+ }
again2:
- if ((res = zread_line(100)) < 0)
- return res;
- if (res == CAN && (res = zread_line(100)) < 0)
- return res;
- if (res == CAN && (res = zread_line(100)) < 0)
- return res;
- if (res == CAN && (res = zread_line(100)) < 0)
- return res;
- switch (res)
- {
- case CAN:
- return GOTCAN;
- case ZCRCE:
- case ZCRCG:
- case ZCRCQ:
- case ZCRCW:
- return (res | GOTOR);
- case ZRUB0:
- return 0177;
- case ZRUB1:
- return 0377;
- case 023:
- case 0223:
- case 021:
- case 0221:
- goto again2;
- default:
- if ((res & 0140) == 0100)
- return (res ^ 0100);
- break;
- }
+ if ((res = zread_line(100)) < 0)
+ return res;
+ if (res == CAN && (res = zread_line(100)) < 0)
+ return res;
+ if (res == CAN && (res = zread_line(100)) < 0)
+ return res;
+ if (res == CAN && (res = zread_line(100)) < 0)
+ return res;
+ switch (res)
+ {
+ case CAN:
+ return GOTCAN;
+ case ZCRCE:
+ case ZCRCG:
+ case ZCRCQ:
+ case ZCRCW:
+ return (res | GOTOR);
+ case ZRUB0:
+ return 0177;
+ case ZRUB1:
+ return 0377;
+ case 023:
+ case 0223:
+ case 021:
+ case 0221:
+ goto again2;
+ default:
+ if ((res & 0140) == 0100)
+ return (res ^ 0100);
+ break;
+ }
- return -RT_ERROR;
+ return -RT_ERROR;
}
/*
@@ -840,46 +840,46 @@ again2:
*/
rt_int16_t zxor_read(void)
{
- rt_int16_t res;
+ rt_int16_t res;
- for (;;)
- {
- if ((res = zread_line(100)) < 0)
- return res;
- switch (res &= 0177) {
- case XON:
- case XOFF:
- continue;
- case '\r':
- case '\n':
- case ZDLE:
- default:
- return res;
- }
- }
+ for (;;)
+ {
+ if ((res = zread_line(100)) < 0)
+ return res;
+ switch (res &= 0177) {
+ case XON:
+ case XOFF:
+ continue;
+ case '\r':
+ case '\n':
+ case ZDLE:
+ default:
+ return res;
+ }
+ }
}
/* put file posistion into the header*/
void zput_pos(rt_uint32_t pos)
{
- tx_header[ZP0] = pos;
- tx_header[ZP1] = pos>>8;
- tx_header[ZP2] = pos>>16;
- tx_header[ZP3] = pos>>24;
+ tx_header[ZP0] = pos;
+ tx_header[ZP1] = pos>>8;
+ tx_header[ZP2] = pos>>16;
+ tx_header[ZP3] = pos>>24;
- return;
+ return;
}
/* Recover a long integer from a header */
void zget_pos(rt_uint32_t pos)
{
- Rxpos = (rx_header[ZP3] & 0377);
- Rxpos = (Rxpos << 8) | (rx_header[ZP2] & 0377);
- Rxpos = (Rxpos << 8) | (rx_header[ZP1] & 0377);
- Rxpos = (Rxpos << 8) | (rx_header[ZP0] & 0377);
+ Rxpos = (rx_header[ZP3] & 0377);
+ Rxpos = (Rxpos << 8) | (rx_header[ZP2] & 0377);
+ Rxpos = (Rxpos << 8) | (rx_header[ZP1] & 0377);
+ Rxpos = (Rxpos << 8) | (rx_header[ZP0] & 0377);
- return;
+ return;
}
/* end of zcore.c */
diff --git a/components/utilities/zmodem/zdef.h b/components/utilities/zmodem/zdef.h
index 3568bdfd96..cfb9784f30 100644
--- a/components/utilities/zmodem/zdef.h
+++ b/components/utilities/zmodem/zdef.h
@@ -3,133 +3,133 @@
#include <rtthread.h>
#include "crc.h"
-#define ZPAD '*' /* 052 padding character begins frames */
-#define ZDLE 030 /* ctrl-X ZMODEM escape - `ala BISYNC DLE */
-#define ZDLEE (ZDLE^0100) /* escaped ZDLE as transmitted */
-#define ZBIN 'A' /* binary frame indicator (CRC-16) */
-#define ZHEX 'B' /* hex frame indicator */
-#define ZBIN32 'C' /* binary frame with 32 bit FCS */
-#define ZBINR32 'D' /* RLE packed Binary frame with 32 bit FCS */
-#define ZVBIN 'a' /* binary frame indicator (CRC-16) */
-#define ZVHEX 'b' /* hex frame indicator */
-#define ZVBIN32 'c' /* binary frame with 32 bit FCS */
-#define ZVBINR32 'd' /* RLE packed Binary frame with 32 bit FCS */
-#define ZRESC 0176 /* RLE flag/escape character */
+#define ZPAD '*' /* 052 padding character begins frames */
+#define ZDLE 030 /* ctrl-X ZMODEM escape - `ala BISYNC DLE */
+#define ZDLEE (ZDLE^0100) /* escaped ZDLE as transmitted */
+#define ZBIN 'A' /* binary frame indicator (CRC-16) */
+#define ZHEX 'B' /* hex frame indicator */
+#define ZBIN32 'C' /* binary frame with 32 bit FCS */
+#define ZBINR32 'D' /* RLE packed Binary frame with 32 bit FCS */
+#define ZVBIN 'a' /* binary frame indicator (CRC-16) */
+#define ZVHEX 'b' /* hex frame indicator */
+#define ZVBIN32 'c' /* binary frame with 32 bit FCS */
+#define ZVBINR32 'd' /* RLE packed Binary frame with 32 bit FCS */
+#define ZRESC 0176 /* RLE flag/escape character */
/* Frame types */
-#define ZRQINIT 0 /* request receive init */
+#define ZRQINIT 0 /* request receive init */
#define ZRINIT 1 /* receive init */
-#define ZSINIT 2 /* send init sequence (optional) */
-#define ZACK 3 /* ACK to above */
-#define ZFILE 4 /* file name from sender */
-#define ZSKIP 5 /* ro sender: skip this file */
-#define ZNAK 6 /* last packet was garbled */
-#define ZABORT 7 /* abort batch transfers */
-#define ZFIN 8 /* finish session */
-#define ZRPOS 9 /* resume data trans at this position */
+#define ZSINIT 2 /* send init sequence (optional) */
+#define ZACK 3 /* ACK to above */
+#define ZFILE 4 /* file name from sender */
+#define ZSKIP 5 /* ro sender: skip this file */
+#define ZNAK 6 /* last packet was garbled */
+#define ZABORT 7 /* abort batch transfers */
+#define ZFIN 8 /* finish session */
+#define ZRPOS 9 /* resume data trans at this position */
#define ZDATA 10 /* data packet(s) follow */
#define ZEOF 11 /* end of file */
#define ZFERR 12 /* fatal Read or Write error Detected */
#define ZCRC 13 /* request for file CRC and response */
#define ZCHALLENGE 14 /* receiver's Challenge */
-#define ZCOMPL 15 /* request is complete */
-#define ZCAN 16 /* other end canned session with CAN*5 */
-#define ZFREECNT 17 /* request for free bytes on filesystem */
-#define ZCOMMAND 18 /* command from sending program */
+#define ZCOMPL 15 /* request is complete */
+#define ZCAN 16 /* other end canned session with CAN*5 */
+#define ZFREECNT 17 /* request for free bytes on filesystem */
+#define ZCOMMAND 18 /* command from sending program */
/* ZDLE sequfences */
-#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
-#define ZCRCG 'i' /* CRC next, frame continues nonstop */
-#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
-#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
-#define ZRUB0 'l' /* translate to rubout 0177 */
-#define ZRUB1 'm' /* translate to rubout 0377 */
+#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
+#define ZCRCG 'i' /* CRC next, frame continues nonstop */
+#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
+#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
+#define ZRUB0 'l' /* translate to rubout 0177 */
+#define ZRUB1 'm' /* translate to rubout 0377 */
/* zdlread return values (internal) */
/* -1 is general error, -2 is timeout */
#define GOTOR 0400
-#define GOTCRCE (ZCRCE|GOTOR) /* ZDLE-ZCRCE received */
-#define GOTCRCG (ZCRCG|GOTOR) /* ZDLE-ZCRCG received */
-#define GOTCRCQ (ZCRCQ|GOTOR) /* ZDLE-ZCRCQ received */
-#define GOTCRCW (ZCRCW|GOTOR) /* ZDLE-ZCRCW received */
-#define GOTCAN (GOTOR|030) /* CAN*5 seen */
+#define GOTCRCE (ZCRCE|GOTOR) /* ZDLE-ZCRCE received */
+#define GOTCRCG (ZCRCG|GOTOR) /* ZDLE-ZCRCG received */
+#define GOTCRCQ (ZCRCQ|GOTOR) /* ZDLE-ZCRCQ received */
+#define GOTCRCW (ZCRCW|GOTOR) /* ZDLE-ZCRCW received */
+#define GOTCAN (GOTOR|030) /* CAN*5 seen */
/* Byte positions within header array */
-#define ZF0 3 /* first flags byte */
-#define ZF1 2
-#define ZF2 1
-#define ZF3 0
-#define ZP0 0 /* low order 8 bits of position */
-#define ZP1 1
-#define ZP2 2
-#define ZP3 3 /* high order 8 bits of file position */
+#define ZF0 3 /* first flags byte */
+#define ZF1 2
+#define ZF2 1
+#define ZF3 0
+#define ZP0 0 /* low order 8 bits of position */
+#define ZP1 1
+#define ZP2 2
+#define ZP3 3 /* high order 8 bits of file position */
/* parameters for ZRINIT header */
-#define ZRPXWN 8 /* 9th byte in header contains window size/256 */
-#define ZRPXQQ 9 /* 10th to 14th bytes contain quote mask */
+#define ZRPXWN 8 /* 9th byte in header contains window size/256 */
+#define ZRPXQQ 9 /* 10th to 14th bytes contain quote mask */
/* bit Masks for ZRINIT flags byte ZF0 */
-#define CANFDX 0x01 /* rx can send and receive true FDX */
-#define CANOVIO 0x02 /* rx can receive data during disk I/O */
-#define CANBRK 0x04 /* rx can send a break signal */
-#define CANRLE 0x10 /* receiver can decode RLE */
-#define CANLZW 0x20 /* receiver can uncompress */
-#define CANFC32 0x28 /* receiver can use 32 bit Frame Check */
-#define ESCCTL 0x64 /* receiver expects ctl chars to be escaped */
-#define ESC8 0xc8 /* receiver expects 8th bit to be escaped */
+#define CANFDX 0x01 /* rx can send and receive true FDX */
+#define CANOVIO 0x02 /* rx can receive data during disk I/O */
+#define CANBRK 0x04 /* rx can send a break signal */
+#define CANRLE 0x10 /* receiver can decode RLE */
+#define CANLZW 0x20 /* receiver can uncompress */
+#define CANFC32 0x28 /* receiver can use 32 bit Frame Check */
+#define ESCCTL 0x64 /* receiver expects ctl chars to be escaped */
+#define ESC8 0xc8 /* receiver expects 8th bit to be escaped */
/* bit Masks for ZRINIT flags byte ZF1 */
-#define CANVHDR 01 /* variable headers OK */
-#define ZRRQWN 8 /* receiver specified window size in ZRPXWN */
-#define ZRRQQQ 16 /* additional control chars to quote in ZRPXQQ */
-#define ZRQNVH (ZRRQWN|ZRRQQQ) /* variable len hdr reqd to access info */
+#define CANVHDR 01 /* variable headers OK */
+#define ZRRQWN 8 /* receiver specified window size in ZRPXWN */
+#define ZRRQQQ 16 /* additional control chars to quote in ZRPXQQ */
+#define ZRQNVH (ZRRQWN|ZRRQQQ) /* variable len hdr reqd to access info */
/* Parameters for ZSINIT frame */
-#define ZATTNLEN 32 /* max length of attention string */
-#define ALTCOFF ZF1 /* offset to alternate canit string, 0 if not used */
+#define ZATTNLEN 32 /* max length of attention string */
+#define ALTCOFF ZF1 /* offset to alternate canit string, 0 if not used */
/* Parameters for ZFILE frame */
/* Conversion options one of these in ZF0 */
-#define ZCBIN 1 /* binary transfer - inhibit conversion */
-#define ZCNL 2 /* convert NL to local end of line convention */
-#define ZCRESUM 3 /* resume interrupted file transfer */
+#define ZCBIN 1 /* binary transfer - inhibit conversion */
+#define ZCNL 2 /* convert NL to local end of line convention */
+#define ZCRESUM 3 /* resume interrupted file transfer */
/* management include options, one of these ored in ZF1 */
#define ZMSKNOLOC 0200 /* skip file if not present at rx */
/* management options, one of these ored in ZF1 */
-#define ZMMASK 037 /* mask for the choices below */
-#define ZMNEWL 1 /* transfer if source newer or longer */
-#define ZMCRC 2 /* transfer if different file CRC or length */
-#define ZMAPND 3 /* append contents to existing file (if any) */
-#define ZMCLOB 4 /* replace existing file */
-#define ZMNEW 5 /* transfer if source newer */
+#define ZMMASK 037 /* mask for the choices below */
+#define ZMNEWL 1 /* transfer if source newer or longer */
+#define ZMCRC 2 /* transfer if different file CRC or length */
+#define ZMAPND 3 /* append contents to existing file (if any) */
+#define ZMCLOB 4 /* replace existing file */
+#define ZMNEW 5 /* transfer if source newer */
/* number 5 is alive ... */
-#define ZMDIFF 6 /* transfer if dates or lengths different */
-#define ZMPROT 7 /* protect destination file */
-#define ZMCHNG 8 /* change filename if destination exists */
+#define ZMDIFF 6 /* transfer if dates or lengths different */
+#define ZMPROT 7 /* protect destination file */
+#define ZMCHNG 8 /* change filename if destination exists */
/* transport options, one of these in ZF2 */
-#define ZTLZW 1 /* lempel-Ziv compression */
-#define ZTRLE 3 /* run Length encoding */
+#define ZTLZW 1 /* lempel-Ziv compression */
+#define ZTRLE 3 /* run Length encoding */
/* extended options for ZF3, bit encoded */
-#define ZXSPARS 64 /* encoding for sparse file operations */
+#define ZXSPARS 64 /* encoding for sparse file operations */
#define ZCANVHDR 01 /* variable headers OK */
/* receiver window size override */
-#define ZRWOVR 4 /* byte position for receive window override/256 */
+#define ZRWOVR 4 /* byte position for receive window override/256 */
/* parameters for ZCOMMAND frame ZF0 (otherwise 0) */
-#define ZCACK1 1 /* acknowledge, then do command */
-extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
+#define ZCACK1 1 /* acknowledge, then do command */
+extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
/* globals used by ZMODEM functions */
extern rt_uint8_t Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
-extern char header_type; /* type of header received */
+extern char header_type; /* type of header received */
extern rt_uint8_t rx_header[4]; /* received header */
extern rt_uint8_t tx_header[4]; /* transmitted header */
-extern rt_uint8_t Txfcs32; /* TRUE means send binary frames with 32 bit FCS */
-extern rt_uint16_t Rxcount; /* count of data bytes received */
+extern rt_uint8_t Txfcs32; /* TRUE means send binary frames with 32 bit FCS */
+extern rt_uint16_t Rxcount; /* count of data bytes received */
extern rt_uint16_t Rxtimeout; /* tenths of seconds to wait for something */
-extern rt_uint32_t Rxpos; /* received file position */
-extern rt_uint32_t Txpos; /* transmitted file position */
-extern rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */
+extern rt_uint32_t Rxpos; /* received file position */
+extern rt_uint32_t Txpos; /* transmitted file position */
+extern rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */
/* ward Christensen / CP/M parameters - Don't change these! */
#define ENQ 005
@@ -141,34 +141,34 @@ extern rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit
#define ETX 3
#define SYN 026
#define ESC 033
-#define WANTG 0107 /* send G not NAK to get nonstop batch xmsn */
+#define WANTG 0107 /* send G not NAK to get nonstop batch xmsn */
#define EOT 4
#define ACK 6
#define NAK 025
#define CPMEOF 032
-#define WANTCRC 0103 /* send C not NAK to get crc not checksum */
+#define WANTCRC 0103 /* send C not NAK to get crc not checksum */
#define TIMEOUT (-2)
#define RCDO (-3)
#define GCOUNT (-4)
#define ERRORMAX 5
#define RETRYMAX 5
#define WCEOT (-10)
-
-
+
+
#define BITRATE 115200
#define TX_BUFFER_SIZE 1024
-#define RX_BUFFER_SIZE 1024 /* sender or receiver's max buffer size */
-extern char ZF0_CMD; /* local ZMODEM file conversion request */
-extern char ZF1_CMD; /* local ZMODEM file management request */
-extern char ZF2_CMD; /* local ZMODEM file management request */
-extern char ZF3_CMD; /* local ZMODEM file management request */
+#define RX_BUFFER_SIZE 1024 /* sender or receiver's max buffer size */
+extern char ZF0_CMD; /* local ZMODEM file conversion request */
+extern char ZF1_CMD; /* local ZMODEM file management request */
+extern char ZF2_CMD; /* local ZMODEM file management request */
+extern char ZF3_CMD; /* local ZMODEM file management request */
extern rt_uint32_t Baudrate ;
extern rt_uint32_t Left_bytes;
extern rt_uint32_t Left_sizes;
-
+
struct zmodemf
{
@@ -179,18 +179,18 @@ extern struct zmodemf zmodem;
struct zfile
{
- char *fname;
- rt_int32_t fd;
- rt_uint32_t ctime;
+ char *fname;
+ rt_int32_t fd;
+ rt_uint32_t ctime;
rt_uint32_t mode;
- rt_uint32_t bytes_total;
- rt_uint32_t bytes_sent;
- rt_uint32_t bytes_received;
- rt_uint32_t file_end;
-
+ rt_uint32_t bytes_total;
+ rt_uint32_t bytes_sent;
+ rt_uint32_t bytes_received;
+ rt_uint32_t file_end;
+
};
extern struct finsh_shell* shell;
-
+
#define ZDEBUG 0
/* sz.c */
extern void zs_start(char *path);
@@ -213,5 +213,5 @@ extern void zsend_line(rt_uint16_t c);
extern rt_int16_t zread_line(rt_uint16_t timeout);
extern void zsend_break(char *cmd);
extern void zsend_can(void);
-
+
#endif /* __ZDEF_H__ */
diff --git a/components/utilities/zmodem/zdevice.c b/components/utilities/zmodem/zdevice.c
index 1562cc5f5c..3a144e79de 100644
--- a/components/utilities/zmodem/zdevice.c
+++ b/components/utilities/zmodem/zdevice.c
@@ -3,7 +3,7 @@
* the implemention of zmodem protocol.
* Change Logs:
* Date Author Notes
- * 2011-03-29 itspy
+ * 2011-03-29 itspy
*/
#include <rtthread.h>
@@ -15,11 +15,11 @@
#include <dfs_posix.h>
#include "zdef.h"
-
-rt_uint32_t Line_left = 0; /* left number of data in the read line buffer*/
-rt_uint32_t Left_sizes = 0; /* left file sizes */
-rt_uint32_t Baudrate = BITRATE; /* console baudrate */
-
+
+rt_uint32_t Line_left = 0; /* left number of data in the read line buffer*/
+rt_uint32_t Left_sizes = 0; /* left file sizes */
+rt_uint32_t Baudrate = BITRATE; /* console baudrate */
+
rt_uint32_t get_device_baud(void)
@@ -34,7 +34,7 @@ rt_uint32_t get_sys_time(void)
void zsend_byte(rt_uint16_t ch)
{
- rt_device_write(zmodem.device, 0, &ch,1);
+ rt_device_write(zmodem.device, 0, &ch,1);
return;
}
@@ -43,38 +43,38 @@ void zsend_line(rt_uint16_t c)
{
rt_uint16_t ch;
- ch = (c & 0377);
- rt_device_write(zmodem.device, 0, &ch, 1);
+ ch = (c & 0377);
+ rt_device_write(zmodem.device, 0, &ch, 1);
return;
}
rt_int16_t zread_line(rt_uint16_t timeout)
{
- char *str;
- static char buf[10];
+ char *str;
+ static char buf[10];
- if (Line_left > 0)
- {
- Line_left -= 1;
- return (*str++ & 0377);
- }
- Line_left = 0;
- timeout/=5;
- while (1)
- {
- Line_left = rt_device_read(shell->device, 0, buf, 1);
- if (Line_left)
- {
- Line_left = Line_left;
- str = buf;
- break;
- }
- }
- if (Line_left < 1) return TIMEOUT;
- Line_left -=1;
+ if (Line_left > 0)
+ {
+ Line_left -= 1;
+ return (*str++ & 0377);
+ }
+ Line_left = 0;
+ timeout/=5;
+ while (1)
+ {
+ Line_left = rt_device_read(shell->device, 0, buf, 1);
+ if (Line_left)
+ {
+ Line_left = Line_left;
+ str = buf;
+ break;
+ }
+ }
+ if (Line_left < 1) return TIMEOUT;
+ Line_left -=1;
- return (*str++ & 0377);
+ return (*str++ & 0377);
}
/*
@@ -83,32 +83,32 @@ rt_int16_t zread_line(rt_uint16_t timeout)
*/
void zsend_break(char *cmd)
{
-
- while (*cmd++)
- {
- switch (*cmd)
- {
- case '\336':
- continue;
- case '\335':
- rt_thread_delay(RT_TICK_PER_SECOND);
- continue;
- default:
- zsend_line(*cmd);
- break;
- }
- }
+
+ while (*cmd++)
+ {
+ switch (*cmd)
+ {
+ case '\336':
+ continue;
+ case '\335':
+ rt_thread_delay(RT_TICK_PER_SECOND);
+ continue;
+ default:
+ zsend_line(*cmd);
+ break;
+ }
+ }
}
/* send cancel string to get the other end to shut up */
void zsend_can(void)
{
- static char cmd[] = {24,24,24,24,24,24,24,24,24,24,0};
+ static char cmd[] = {24,24,24,24,24,24,24,24,24,24,0};
- zsend_break(cmd);
- rt_kprintf("\x0d");
- Line_left=0; /* clear Line_left */
+ zsend_break(cmd);
+ rt_kprintf("\x0d");
+ Line_left=0; /* clear Line_left */
- return;
+ return;
}
/* end of zdevice.c */
diff --git a/components/utilities/zmodem/zstart.c b/components/utilities/zmodem/zstart.c
index e5a36ca7ab..5c44ee86a7 100644
--- a/components/utilities/zmodem/zstart.c
+++ b/components/utilities/zmodem/zstart.c
@@ -3,7 +3,7 @@
* the implemention of zmodem protocol.
* Change Logs:
* Date Author Notes
- * 2011-03-29 itspy
+ * 2011-03-29 itspy
*/
#include <rtthread.h>
@@ -27,43 +27,43 @@ rt_err_t zmodem_rx_ind(rt_device_t dev, rt_size_t size)
void finsh_rz(void *parameter)
{
- char *path;
+ char *path;
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
- rt_uint8_t flag;
+ rt_uint8_t flag;
- flag = RT_DEVICE_FLAG_STREAM;
+ flag = RT_DEVICE_FLAG_STREAM;
zmodem.device->flag &=(~flag);
rt_sem_init(&(zmodem.zsem), "zsem", 0, 0);
- path = rt_thread_self()->parameter;
- /* save old rx_indicate */
+ path = rt_thread_self()->parameter;
+ /* save old rx_indicate */
rx_indicate = zmodem.device->rx_indicate;
/* set new rx_indicate */
rt_device_set_rx_indicate(zmodem.device, RT_NULL);
- /* start receive remote files */
+ /* start receive remote files */
zr_start(path);
- zmodem.device->flag |=flag;
- /* recovery old rx_indicate */
+ zmodem.device->flag |=flag;
+ /* recovery old rx_indicate */
rt_device_set_rx_indicate(zmodem.device, rx_indicate);
/* finsh>> */
rt_kprintf(FINSH_PROMPT);
}
void finsh_sz(void *parameter)
{
- char *path;
+ char *path;
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
- rt_uint8_t flag;
+ rt_uint8_t flag;
- flag = RT_DEVICE_FLAG_STREAM;
+ flag = RT_DEVICE_FLAG_STREAM;
zmodem.device->flag &=(~flag);
rt_sem_init(&(zmodem.zsem), "zsem", 0, 0);
- path = rt_thread_self()->parameter;
- /* save old rx_indicate */
+ path = rt_thread_self()->parameter;
+ /* save old rx_indicate */
rx_indicate = zmodem.device->rx_indicate;
- /* set new rx_indicate */
+ /* set new rx_indicate */
rt_device_set_rx_indicate(zmodem.device, zmodem_rx_ind);
- zs_start(path);
- zmodem.device->flag |=flag;
- /* recovery old rx_indicate */
+ zs_start(path);
+ zmodem.device->flag |=flag;
+ /* recovery old rx_indicate */
rt_device_set_rx_indicate(zmodem.device, rx_indicate);
/* finsh>> */
rt_kprintf(FINSH_PROMPT);