2011-03-30 14:14:22 +08:00
|
|
|
/*
|
2013-01-08 21:05:02 +08:00
|
|
|
* File : zstart.c
|
2011-03-30 14:14:22 +08:00
|
|
|
* the implemention of zmodem protocol.
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-03-08 18:19:04 +08:00
|
|
|
* 2011-03-29 itspy
|
2013-01-08 21:05:02 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <finsh.h>
|
|
|
|
#include <shell.h>
|
|
|
|
#include <dfs.h>
|
|
|
|
#include <dfs_file.h>
|
|
|
|
#include "zdef.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct zmodemf zmodem;
|
|
|
|
|
|
|
|
rt_err_t zmodem_rx_ind(rt_device_t dev, rt_size_t size)
|
|
|
|
{
|
|
|
|
/* release semaphore */
|
|
|
|
rt_sem_release(&zmodem.zsem);
|
|
|
|
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void finsh_rz(void *parameter)
|
|
|
|
{
|
2021-03-08 18:19:04 +08:00
|
|
|
char *path;
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
|
2021-03-08 18:19:04 +08:00
|
|
|
rt_uint8_t flag;
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2021-03-08 18:19:04 +08:00
|
|
|
flag = RT_DEVICE_FLAG_STREAM;
|
2013-01-08 21:05:02 +08:00
|
|
|
zmodem.device->flag &=(~flag);
|
|
|
|
rt_sem_init(&(zmodem.zsem), "zsem", 0, 0);
|
2021-03-08 18:19:04 +08:00
|
|
|
path = rt_thread_self()->parameter;
|
|
|
|
/* save old rx_indicate */
|
2013-01-08 21:05:02 +08:00
|
|
|
rx_indicate = zmodem.device->rx_indicate;
|
|
|
|
/* set new rx_indicate */
|
|
|
|
rt_device_set_rx_indicate(zmodem.device, RT_NULL);
|
2021-03-08 18:19:04 +08:00
|
|
|
/* start receive remote files */
|
2013-01-08 21:05:02 +08:00
|
|
|
zr_start(path);
|
2021-03-08 18:19:04 +08:00
|
|
|
zmodem.device->flag |=flag;
|
|
|
|
/* recovery old rx_indicate */
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_device_set_rx_indicate(zmodem.device, rx_indicate);
|
|
|
|
/* finsh>> */
|
|
|
|
rt_kprintf(FINSH_PROMPT);
|
|
|
|
}
|
|
|
|
void finsh_sz(void *parameter)
|
|
|
|
{
|
2021-03-08 18:19:04 +08:00
|
|
|
char *path;
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
|
2021-03-08 18:19:04 +08:00
|
|
|
rt_uint8_t flag;
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2021-03-08 18:19:04 +08:00
|
|
|
flag = RT_DEVICE_FLAG_STREAM;
|
2013-01-08 21:05:02 +08:00
|
|
|
zmodem.device->flag &=(~flag);
|
|
|
|
rt_sem_init(&(zmodem.zsem), "zsem", 0, 0);
|
2021-03-08 18:19:04 +08:00
|
|
|
path = rt_thread_self()->parameter;
|
|
|
|
/* save old rx_indicate */
|
2013-01-08 21:05:02 +08:00
|
|
|
rx_indicate = zmodem.device->rx_indicate;
|
2021-03-08 18:19:04 +08:00
|
|
|
/* set new rx_indicate */
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_device_set_rx_indicate(zmodem.device, zmodem_rx_ind);
|
2021-03-08 18:19:04 +08:00
|
|
|
zs_start(path);
|
|
|
|
zmodem.device->flag |=flag;
|
|
|
|
/* recovery old rx_indicate */
|
2013-01-08 21:05:02 +08:00
|
|
|
rt_device_set_rx_indicate(zmodem.device, rx_indicate);
|
|
|
|
/* finsh>> */
|
|
|
|
rt_kprintf(FINSH_PROMPT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_FINSH
|
|
|
|
#include <finsh.h>
|
|
|
|
#include <shell.h>
|
|
|
|
|
|
|
|
static void rz(char *para)
|
|
|
|
{
|
|
|
|
rt_thread_t init_thread;
|
|
|
|
rt_device_t device;
|
|
|
|
const char* device_name = finsh_get_device();
|
|
|
|
|
|
|
|
device = rt_device_find(device_name);
|
|
|
|
if( device == RT_NULL )
|
|
|
|
{
|
|
|
|
rt_kprintf("%s not find\r\n",device_name);
|
|
|
|
}
|
|
|
|
zmodem.device = device;
|
|
|
|
init_thread = rt_thread_create("rz",
|
|
|
|
finsh_rz,
|
|
|
|
(void*)para,
|
|
|
|
2048,
|
|
|
|
rt_thread_self()->current_priority+1,
|
|
|
|
20);
|
|
|
|
|
|
|
|
if (init_thread != RT_NULL) rt_thread_startup(init_thread);
|
|
|
|
}
|
|
|
|
FINSH_FUNCTION_EXPORT(rz, receive files by zmodem protocol)
|
|
|
|
static void sz(char *para)
|
|
|
|
{
|
|
|
|
rt_thread_t init_thread;
|
|
|
|
rt_device_t device;
|
|
|
|
const char* device_name = finsh_get_device();
|
|
|
|
|
|
|
|
device = rt_device_find(device_name);
|
|
|
|
if( device == RT_NULL )
|
|
|
|
{
|
|
|
|
rt_kprintf("%s not find\r\n",device_name);
|
|
|
|
}
|
|
|
|
zmodem.device = device;
|
|
|
|
init_thread = rt_thread_create("sz",
|
|
|
|
finsh_sz,
|
|
|
|
(void*)para,
|
|
|
|
2048,
|
|
|
|
rt_thread_self()->current_priority+1,
|
|
|
|
20);
|
|
|
|
|
|
|
|
if (init_thread != RT_NULL) rt_thread_startup(init_thread);
|
|
|
|
}
|
|
|
|
FINSH_FUNCTION_EXPORT(sz, send files by zmodem protocol)
|
|
|
|
#endif
|