Build/test framework for the Zmodem sz and rz commands which are on their way

This commit is contained in:
Gregory Nutt 2013-07-12 16:01:37 -06:00
parent 3a2eb439f7
commit 551af554c0
10 changed files with 632 additions and 1 deletions

View File

@ -601,3 +601,6 @@
* apps/examples/composite/composite_main.c: SourceForge But Ticket #19.
Change to prevent some false alarm debug assertions (From Chia Cheng
Tao, 2013-7-9).
* apps/system/zmodem: Add configuration support and a build framework
for the Zmodem sz and rz command (which don't actually exist yet).
(2013-7-12).

254
include/zmodem.h Normal file
View File

@ -0,0 +1,254 @@
/****************************************************************************
* apps/include/zmodem.h
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* References:
* "The ZMODEM Inter Application File Transfer Protocol", Chuck Forsberg,
* Omen Technology Inc., October 14, 1988
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __APPS_INCLUDE_ZMODEM_H
#define __APPS_INCLUDE_ZMODEM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* The size of one buffer used to read data from the remote peer */
#ifndef CONFIG_SYSTEM_ZMODEM_RCVBUFSIZE
# define CONFIG_SYSTEM_ZMODEM_RCVBUFSIZE 512
#endif
/* Data may be received in gulps of varying size and alignment. Received
* packets data is properly packed into a packet buffer of this size.
*/
#ifndef CONFIG_SYSTEM_ZMODEM_PKTBUFSIZE
# define CONFIG_SYSTEM_ZMODEM_PKTBUFSIZE 512
#endif
/* The size of one transmit buffer used for composing messages sent to the
* remote peer.
*/
#ifndef CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE
# define CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE 512
#endif
/* Absolute pathes are not accepted. This configuration value must be
* set to provide the path to the file storage directory (such as a
* mountpoint directory).
*/
#ifndef CONFIG_SYSTEM_ZMODEM_MOUNTPOINT
# define CONFIG_SYSTEM_ZMODEM_MOUNTPOINT "/tmp"
#endif
/* Response time for sender to respond to requests */
#ifndef CONFIG_SYSTEM_ZMODEM_RESPTIME
# define CONFIG_SYSTEM_ZMODEM_RESPTIME 10
#endif
/* Receiver serial number */
#ifndef CONFIG_SYSTEM_ZMODEM_SERIALNO
# define CONFIG_SYSTEM_ZMODEM_SERIALNO 1
#endif
/* Max receive errors before canceling the transfer */
#ifndef CONFIG_SYSTEM_ZMODEM_MAXERRORS
# define CONFIG_SYSTEM_ZMODEM_MAXERRORS 20
#endif
#ifndef CONFIG_SYSTEM_ZMODEM_MOUNTPOINT
# define CONFIG_SYSTEM_ZMODEM_MOUNTPOINT "/tmp"
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* Opaque handles returned by initialization functions */
typedef FAR void *ZMHANDLE;
typedef FAR void *ZMRHANDLE;
typedef FAR void *ZMSHANDLE;
/* Enumerations describing arguments to zms_initialize() */
enum zm_xfertype_e
{
XM_XFERTYPE_NORMAL = 0, /* Normal file transfer */
XM_XFERTYPE_BINARY = 1, /* Binary transfer */
XM_XFERTYPE_ASCII = 2, /* Convert \n to local EOL convention */
XM_XFERTYPE_RESUME = 3 /* Resume interrupted transfer or append to file. */
};
enum zm_option_e
{
XM_OPTION_NONE = 0, /* Transfer if source newer or longer */
XM_OPTION_NEWL = 1, /* Transfer if source newer or longer */
XM_OPTION_CRC = 2, /* Transfer if different CRC or length */
XM_OPTION_APPEND = 3, /* Append to existing file, if any */
XM_OPTION_REPLACE = 4, /* Replace existing file */
XM_OPTION_NEW = 5, /* Transfer if source is newer */
XM_OPTION_DIFF = 6, /* Transfer if dates or lengths different */
XM_OPTION_CREATE = 7, /* Protect: transfer only if dest doesn't exist */
XM_OPTION_RENAME = 8 /* Change filename if destination exists */
};
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: zmr_initialize
*
* Description:
* Initialize for Zmodem receive operation
*
* Input Parameters:
* remfd - The R/W file/socket descriptor to use for communication with the
* remote peer.
*
****************************************************************************/
ZMRHANDLE zmr_initialize(int remfd);
/****************************************************************************
* Name: zmr_release
*
* Description:
* Called by the user when there are no more files to receive.
*
****************************************************************************/
int zmr_release(ZMRHANDLE);
/****************************************************************************
* Name: zms_initialize
*
* Description:
* Initialize for Zmodem send operation. The overall usage is as follows:
*
* 1) Call zms_initialize() to create the partially initialized struct
* zm_state_s instance.
* 2) Make any custom settings in the struct zms_state_s instance.
* 3) Create a stream instance to get the "file" to transmit and add
* the filename to pzms
* 4) Call zms_upload() to transfer the file.
* 5) Repeat 3) and 4) to transfer as many files as desired.
* 6) Call zms_release() when the final file has been transferred.
*
* Input Parameters:
* remfd - The R/W file/socket descriptor to use for communication with the
* remote peer.
*
****************************************************************************/
ZMSHANDLE zms_initialize(int remfd);
/****************************************************************************
* Name: zms_send
*
* Description:
* Send a file.
*
* Input Parameters:
* handle - Handle previoulsy returned by xms_initialize()
* filename - The name of the local file to transfer
* rfilename - The name of the remote file name to create
* option - Describes optional transfer behavior
* f1 - The F1 transfer flags
* skip - True: Skip if file not present at receiving end.
*
****************************************************************************/
int zms_send(ZMSHANDLE handle, FAR const char *filename,
FAR const char *rfilename, enum zm_xfertype_e xfertype,
enum zm_option_e option, bool skip);
/****************************************************************************
* Name: zms_release
*
* Description:
* Called by the user when there are no more files to send.
*
****************************************************************************/
int zms_release(ZMSHANDLE handle);
/****************************************************************************
* Name: zms_hwflowcontrol
*
* Description:
* If CONFIG_SYSTEM_ZMODEM_FULLSTREAMING is defined, then the system
* must provide the following interface in order to enable/disable hardware
* flow control on the device used to communicate with the remote peer.
*
****************************************************************************/
#ifdef CONFIG_SYSTEM_ZMODEM_FULLSTREAMING
int zms_hwflowcontrol(int remfd, bool enable);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __APPS_INCLUDE_ZMODEM_H */

View File

@ -46,3 +46,7 @@ endmenu
menu "USB Monitor"
source "$APPSDIR/system/usbmonitor/Kconfig"
endmenu
menu "Zmodem Commands"
source "$APPSDIR/system/zmodem/Kconfig"
endmenu

View File

@ -77,3 +77,7 @@ endif
ifeq ($(CONFIG_SYSTEM_USBMONITOR),y)
CONFIGURED_APPS += system/usbmonitor
endif
ifeq ($(CONFIG_SYSTEM_ZMODEM),y)
CONFIGURED_APPS += system/zmodem
endif

View File

@ -38,7 +38,7 @@
# Sub-directories containing system task
SUBDIRS = flash_eraseall free i2c install poweroff ramtest ramtron readline
SUBDIRS += sdcard sysinfo usbmonitor
SUBDIRS += sdcard sysinfo usbmonitor zmodem
# Create the list of installed runtime modules (INSTALLED_DIRS)

11
system/zmodem/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
/Make.dep
/.depend
/.built
/*.asm
/*.obj
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src

104
system/zmodem/Kconfig Normal file
View File

@ -0,0 +1,104 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config SYSTEM_ZMODEM
bool "Zmodem commands"
default n
---help---
This selection enables the 'sz' and 'rz' NSH commands.
if SYSTEM_ZMODEM
config SYSTEM_ZMODEM_RCVBUFSIZE
int "Receive buffer size"
default 512
---help---
The size of one buffer used to read data from the remote peer.
config SYSTEM_ZMODEM_PKTBUFSIZE
int "Maximum packet size"
default 512
---help---
Data may be received in gulps of varying size and alignment.
Received packets data is properly packed into a packet buffer of
this size.
config SYSTEM_ZMODEM_SNDBUFSIZE
int "Send buffer size"
default 512
---help---
The size of one transmit buffer used for composing messages sent to
the remote peer.
config SYSTEM_ZMODEM_MOUNTPOINT
string "Zmodem sandbox"
default "/tmp"
---help---
Absolute pathes are not accepted. This configuration value must be
set to provide the path to the file storage directory (such as a
mountpoint directory).
config SYSTEM_ZMODEM_SENDSAMPLE
bool "Reverse channel"
default y
---help---
Sender can sample reverse channel
config SYSTEM_ZMODEM_SENDATTN
bool "Attn interrupt"
default y
---help---
Sender can be interrupted with ATTN
config SYSTEM_ZMODEM_ALWAYSSINT
bool "Send ZSINIT"
default y
---help---
Always send ZSINIT header
config SYSTEM_ZMODEM_TIMESTAMPS
bool "File timestamps"
default y
depends on RTC
---help---
File timestamps may be supported
config SYSTEM_ZMODEM_SENDATTN
bool "Send Attn string"
default n
---help---
Send attention string not yet supported
config SYSTEM_ZMODEM_FULLSTREAMING
bool "Full streaming"
default n
---help---
Full streaming is not yet supported
config SYSTEM_ZMODEM_SENDBRAK
bool "Can break"
default n
---help---
Can not yet send BREAK
config SYSTEM_ZMODEM_RESPTIME
bool "Response time"
default 10
---help---
Response time for sender to respond to requests.
config SYSTEM_ZMODEM_SERIALNO
int "Serial number"
default 0
---help---
Receiver serial number
config SYSTEM_ZMODEM_MAXERRORS
int "Max error"
default 20
---help---
Max receive errors before canceling the transfer.
endif

117
system/zmodem/Makefile Normal file
View File

@ -0,0 +1,117 @@
############################################################################
# apps/system/zmodem/Makefile
#
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
ifeq ($(WINTOOL),y)
INCDIROPT = -w
endif
# Zmodem sz and rz commands
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 768
ASRCS =
CSRCS = sz_main.c rz_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\libapps$(LIBEXT)
else
BIN = ../../libapps$(LIBEXT)
endif
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: context depend clean distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
$(Q) touch .built
# Register application
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(BUILTIN_REGISTRY)$(DELIM)sz.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,"sz",$(PRIORITY),$(STACKSIZE),sz_main)
$(BUILTIN_REGISTRY)$(DELIM)rz.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,"rz",$(PRIORITY),$(STACKSIZE),rz_main)
context: $(BUILTIN_REGISTRY)$(DELIM)sz.bdat $(BUILTIN_REGISTRY)$(DELIM)rz.bdat
else
context:
endif
# Create dependencies
.depend: Makefile $(SRCS)
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
$(Q) touch $@
depend: .depend
clean:
$(call DELFILE, .built)
$(call CLEAN)
distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)
-include Make.dep

67
system/zmodem/rz_main.c Normal file
View File

@ -0,0 +1,67 @@
/****************************************************************************
* system/xmodem/rz_main.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <apps/zmodem.h>
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: rz_main
****************************************************************************/
int rz_main(int argc, char *argv[])
{
printf("Not yet implemented!!\n");
return 0;
}

67
system/zmodem/sz_main.c Normal file
View File

@ -0,0 +1,67 @@
/****************************************************************************
* system/xmodem/sz_main.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <apps/zmodem.h>
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sz_main
****************************************************************************/
int sz_main(int argc, char *argv[])
{
printf("Not yet implemented!!\n");
return 0;
}