2 // TFUSBControllerCommunicationBlock.h
5 // Created by Kalle Olavi Niemitalo on 2007-10-23, based on:
8 // Created by Nathan Oates on Sun Aug 01 2004.
9 // Copyright (c) 2004-7 Nathan Oates. All rights reserved.
10 // May also include parts of:
12 // Copyright (c) 2001 Kasima Tharnpipitchai <me@kasima.org>
14 // This source code is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU Public License as published
16 // by the Free Software Foundation; either version 2 of the License,
17 // or (at your option) any later version.
19 // This source code is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 // Please refer to the GNU Public License for more details.
24 // You should have received a copy of the GNU Public License along with
25 // this source code; if not, write to:
26 // Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #import "TFUSBController.h"
30 typedef enum TopfieldUSBCmd
{
31 USB_CmdNone
= 0x00000000,
33 USB_Fail
= 0x00000001,
34 USB_Success
= 0x00000002,
35 USB_Cancel
= 0x00000003,
37 USB_CmdReady
= 0x00000100,
38 USB_CmdReset
= 0x00000101,
39 USB_CmdTurbo
= 0x00000102,
42 USB_CmdHddSize
= 0x00001000,
43 USB_DataHddSize
= 0x00001001,
45 USB_CmdHddDir
= 0x00001002,
46 USB_DataHddDir
= 0x00001003,
47 USB_DataHddDirEnd
= 0x00001004,
49 USB_CmdHddDel
= 0x00001005,
50 USB_CmdHddRename
= 0x00001006,
51 USB_CmdHddCreateDir
= 0x00001007,
53 USB_CmdHddFileSend
= 0x00001008,
54 USB_DataHddFileStart
= 0x00001009,
55 USB_DataHddFileData
= 0x0000100A,
56 USB_DataHddFileEnd
= 0x0000100B,
59 // -----------------------------------------------------------------------------
61 typedef enum TopfieldUSBEcode
{
63 USB_Err_Crc
= 0x00000001,
64 USB_Err_UnknownCmd
= 0x00000002,
65 USB_Err_InvalidCmd
= 0x00000003,
66 USB_Err_Unknown
= 0x00000004,
67 USB_Err_Size
= 0x00000005,
68 USB_Err_RunFail
= 0x00000006,
69 USB_Err_Memory
= 0x00000007,
72 // -----------------------------------------------------------------------------
74 #define USB_FileToDevice 0x00
75 #define USB_FileToHost 0x01
77 // -----------------------------------------------------------------------------
79 #define USB_FileTypeFolder 0x01
80 #define USB_FileTypeNormal 0x02
82 // -----------------------------------------------------------------------------
83 #define USB_FileTypeSize 114
84 #define USB_FileNameSize 95
86 @interface
TFUSBController (CommunicationBlock
)
88 #pragma mark Framing of communication blocks
89 - (UInt16
) findCRC
:(const UInt8
*)p length
:(size_t)n
;
90 - (NSMutableData
*) swap
:(NSData
*)inData
;
91 - (NSData
*) prepareCommand
:(TopfieldUSBCmd
)cmd withData
:(NSData
*)inData
;
92 - (BOOL
) isCommunicationBlockValid
:(NSData
*)block
93 error
:(NSError
**)errorOut ecode
:(TopfieldUSBEcode
*)ecodeOut
;
94 - (UInt32
) cmdFromCommunicationBlock
:(NSData
*)block
;
96 #pragma mark Common ingredients
97 - (BOOL
) appendToData
:(NSMutableData
*)data fname
:(NSString
*)fname
;
98 - (BOOL
) appendToData
:(NSMutableData
*)data sizeAndFname
:(NSString
*)fname
;
99 - (NSString
*) fnameForFile
:(NSString
*)file atPath
:(NSString
*)path
;
101 #pragma mark Preparing communication blocks for various commands
102 - (NSData
*) prepareFailWithECode
:(TopfieldUSBEcode
)ecode
;
103 - (NSData
*) prepareSuccess
;
104 - (NSData
*) prepareCancel
;
105 - (NSData
*) prepareCmdHddDirWithPath
:(NSString
*)path
;
106 - (NSData
*) prepareCmdHddFileSendWithDirection
:(UInt8
)direction
107 fname
:(NSString
*)fname offset
:(UInt64
)offset
;
108 - (NSData
*) prepareDataHddFileEnd
;
109 - (NSData
*) prepareCmdTurboWithMode
:(SInt32
)mode
;
110 - (NSData
*) prepareCmdHddDelWithFname
:(NSString
*)fname
;
111 - (NSData
*) prepareCmdHddRenameFromFname
:(NSString
*)oldFname
112 toFname
:(NSString
*)newFname
;
113 - (NSData
*) prepareCmdHddCreateDirWithFname
:(NSString
*)fname
;