//
//  MiscXmodem.h -- XMODEM/YMODEM file transfer over serial line
//          Written by W. Eric Norum Copyright (c) 1997 by W. Eric Norum.
//          $Revision: 2.1 $   $Date: 1997/04/02 15:32:59 $
//          All rights reserved.
//          This notice may not be removed from this source code.
//
//      This object is included in the MiscKit by permission from the author
//      and its use is governed by the MiscKit license, found in the file
//      "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//      for a list of all applicable permissions and restrictions.
//      

#import <Foundation/NSTimer.h>
#import "MiscSerialPort.h"

/*
 * The following notifications are sent to the default notification center.
 * In all cases, the object in the notification is the MiscXmodem object
 * used to start the transfer.
 */
extern NSString *MiscXmodemPacketNotification;
extern NSString *MiscXmodemRetryNotification;
extern NSString *MiscXmodemCompletionNotification;

/*
 * The userinfo dictionary associated with the
 * MiscXmodemCompletionNotification may contain items
 * with the following keys.
 */
extern NSString *MiscXmodemCompletionNotificationDataItem;
extern NSString *MiscXmodemCompletionNotificationFailureReason;

@interface MiscXmodem:MiscSerialPort
{
	BOOL			isText;
	BOOL			use1kPackets;
	BOOL			useDynamicCheck;
	BOOL			useCRC;
	BOOL			isReceiving;

	NSMutableData   *data;

	unsigned char   pkBuffer[1024+5];
	int				lastPacketNumber;
	int				pkIndex;
	int				pkCount;

	BOOL			transferInProgress;
	int				transferPacketCount;
	int				transferByteCount;
	int				transferRetryCount;
	int				nakCount;

	BOOL			rxExpectPacket;
	BOOL			rxSendDynamicCheck;
	BOOL			rxCRC;

	BOOL			tx1kPackets;
	BOOL			txNewline;
	BOOL			txCRC;
	unsigned int	txCount;

	NSTimer			*timer;
}

- (void)xmodemSetFileTypeText:(BOOL)flag;
- (void)xmodemSet1kPackets:(BOOL)flag;
- (void)xmodemSetCheckTypeDynamic:(BOOL)flag;
- (void)xmodemSetCheckTypeCRC:(BOOL)flag;
- (BOOL)xmodemIs1kPackets;
- (BOOL)xmodemIsCheckTypeDynamic;
- (BOOL)xmodemIsCheckTypeCRC;
- (BOOL)xmodemIsFileTypeText;

- (unsigned int)xmodemTransferPacketCount;
- (unsigned int)xmodemTransferByteCount;
- (unsigned int)xmodemTransferRetryCount;

- (BOOL)xmodemStartSending:(NSData *)dataSource;
- (BOOL)xmodemStartReceiving;
- (void)xmodemCancelTransfer;

@end
