├── README.md ├── UDisk.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── zhushuai.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── UDisk.xcscheme │ └── xcschememanagement.plist ├── UDisk ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── EADSessionController.h ├── EADSessionController.m ├── FileIO.c ├── FileIO.h ├── FileItemModel.h ├── FileItemModel.m ├── FileSystem.h ├── FileSystem.m ├── Filelist.h ├── Filelist.m ├── Filelist.xib ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m ├── UDiskTests ├── Info.plist └── UDiskTests.m └── UDiskUITests ├── Info.plist └── UDiskUITests.m /README.md: -------------------------------------------------------------------------------- 1 | # iOS u盘文件系统示范 2 | 3 | 1、我不负责实现iAP2协议,协议层在我的外设上是底层实现的。 4 | 2、文件读写的scsi函数在fileio里,我只做读取列表没有写入。 5 | 3、文件系统的逻辑都在filesystem里,可以自行参考,fat32、16都有。 6 | -------------------------------------------------------------------------------- /UDisk.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B8A8862C1D59A1C500459CE7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A8862B1D59A1C500459CE7 /* main.m */; }; 11 | B8A8862F1D59A1C500459CE7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A8862E1D59A1C500459CE7 /* AppDelegate.m */; }; 12 | B8A886321D59A1C500459CE7 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A886311D59A1C500459CE7 /* ViewController.m */; }; 13 | B8A886351D59A1C500459CE7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B8A886331D59A1C500459CE7 /* Main.storyboard */; }; 14 | B8A886371D59A1C500459CE7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B8A886361D59A1C500459CE7 /* Assets.xcassets */; }; 15 | B8A8863A1D59A1C500459CE7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B8A886381D59A1C500459CE7 /* LaunchScreen.storyboard */; }; 16 | B8A886451D59A1C500459CE7 /* UDiskTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A886441D59A1C500459CE7 /* UDiskTests.m */; }; 17 | B8A886501D59A1C500459CE7 /* UDiskUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A8864F1D59A1C500459CE7 /* UDiskUITests.m */; }; 18 | B8A8865F1D59A1D600459CE7 /* FileSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A8865E1D59A1D600459CE7 /* FileSystem.m */; }; 19 | B8A886681D59A88B00459CE7 /* FileItemModel.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A886671D59A88B00459CE7 /* FileItemModel.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 20 | B8A8866B1D59AAB200459CE7 /* FileIO.c in Sources */ = {isa = PBXBuildFile; fileRef = B8A886691D59AAB200459CE7 /* FileIO.c */; }; 21 | B8A8866E1D59AAD700459CE7 /* EADSessionController.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A8866D1D59AAD700459CE7 /* EADSessionController.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 22 | B8A886731D59B72A00459CE7 /* Filelist.m in Sources */ = {isa = PBXBuildFile; fileRef = B8A886711D59B72A00459CE7 /* Filelist.m */; }; 23 | B8A886741D59B72A00459CE7 /* Filelist.xib in Resources */ = {isa = PBXBuildFile; fileRef = B8A886721D59B72A00459CE7 /* Filelist.xib */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXContainerItemProxy section */ 27 | B8A886411D59A1C500459CE7 /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = B8A8861F1D59A1C500459CE7 /* Project object */; 30 | proxyType = 1; 31 | remoteGlobalIDString = B8A886261D59A1C500459CE7; 32 | remoteInfo = UDisk; 33 | }; 34 | B8A8864C1D59A1C500459CE7 /* PBXContainerItemProxy */ = { 35 | isa = PBXContainerItemProxy; 36 | containerPortal = B8A8861F1D59A1C500459CE7 /* Project object */; 37 | proxyType = 1; 38 | remoteGlobalIDString = B8A886261D59A1C500459CE7; 39 | remoteInfo = UDisk; 40 | }; 41 | /* End PBXContainerItemProxy section */ 42 | 43 | /* Begin PBXFileReference section */ 44 | B8A886271D59A1C500459CE7 /* UDisk.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UDisk.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | B8A8862B1D59A1C500459CE7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 46 | B8A8862D1D59A1C500459CE7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 47 | B8A8862E1D59A1C500459CE7 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 48 | B8A886301D59A1C500459CE7 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 49 | B8A886311D59A1C500459CE7 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 50 | B8A886341D59A1C500459CE7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 51 | B8A886361D59A1C500459CE7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 52 | B8A886391D59A1C500459CE7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 53 | B8A8863B1D59A1C500459CE7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | B8A886401D59A1C500459CE7 /* UDiskTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UDiskTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | B8A886441D59A1C500459CE7 /* UDiskTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UDiskTests.m; sourceTree = ""; }; 56 | B8A886461D59A1C500459CE7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 57 | B8A8864B1D59A1C500459CE7 /* UDiskUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UDiskUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | B8A8864F1D59A1C500459CE7 /* UDiskUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UDiskUITests.m; sourceTree = ""; }; 59 | B8A886511D59A1C500459CE7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 60 | B8A8865D1D59A1D600459CE7 /* FileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystem.h; sourceTree = ""; }; 61 | B8A8865E1D59A1D600459CE7 /* FileSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileSystem.m; sourceTree = ""; }; 62 | B8A886661D59A88B00459CE7 /* FileItemModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileItemModel.h; sourceTree = ""; }; 63 | B8A886671D59A88B00459CE7 /* FileItemModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileItemModel.m; sourceTree = ""; }; 64 | B8A886691D59AAB200459CE7 /* FileIO.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = FileIO.c; sourceTree = ""; }; 65 | B8A8866A1D59AAB200459CE7 /* FileIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileIO.h; sourceTree = ""; }; 66 | B8A8866C1D59AAD700459CE7 /* EADSessionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EADSessionController.h; sourceTree = ""; }; 67 | B8A8866D1D59AAD700459CE7 /* EADSessionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EADSessionController.m; sourceTree = ""; }; 68 | B8A886701D59B72A00459CE7 /* Filelist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Filelist.h; sourceTree = ""; }; 69 | B8A886711D59B72A00459CE7 /* Filelist.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Filelist.m; sourceTree = ""; }; 70 | B8A886721D59B72A00459CE7 /* Filelist.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Filelist.xib; sourceTree = ""; }; 71 | /* End PBXFileReference section */ 72 | 73 | /* Begin PBXFrameworksBuildPhase section */ 74 | B8A886241D59A1C500459CE7 /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | ); 79 | runOnlyForDeploymentPostprocessing = 0; 80 | }; 81 | B8A8863D1D59A1C500459CE7 /* Frameworks */ = { 82 | isa = PBXFrameworksBuildPhase; 83 | buildActionMask = 2147483647; 84 | files = ( 85 | ); 86 | runOnlyForDeploymentPostprocessing = 0; 87 | }; 88 | B8A886481D59A1C500459CE7 /* Frameworks */ = { 89 | isa = PBXFrameworksBuildPhase; 90 | buildActionMask = 2147483647; 91 | files = ( 92 | ); 93 | runOnlyForDeploymentPostprocessing = 0; 94 | }; 95 | /* End PBXFrameworksBuildPhase section */ 96 | 97 | /* Begin PBXGroup section */ 98 | B8A8861E1D59A1C500459CE7 = { 99 | isa = PBXGroup; 100 | children = ( 101 | B8A886291D59A1C500459CE7 /* UDisk */, 102 | B8A886431D59A1C500459CE7 /* UDiskTests */, 103 | B8A8864E1D59A1C500459CE7 /* UDiskUITests */, 104 | B8A886281D59A1C500459CE7 /* Products */, 105 | ); 106 | sourceTree = ""; 107 | }; 108 | B8A886281D59A1C500459CE7 /* Products */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | B8A886271D59A1C500459CE7 /* UDisk.app */, 112 | B8A886401D59A1C500459CE7 /* UDiskTests.xctest */, 113 | B8A8864B1D59A1C500459CE7 /* UDiskUITests.xctest */, 114 | ); 115 | name = Products; 116 | sourceTree = ""; 117 | }; 118 | B8A886291D59A1C500459CE7 /* UDisk */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | B8A886751D59BD1000459CE7 /* Filesystem */, 122 | B8A8862D1D59A1C500459CE7 /* AppDelegate.h */, 123 | B8A8862E1D59A1C500459CE7 /* AppDelegate.m */, 124 | B8A886301D59A1C500459CE7 /* ViewController.h */, 125 | B8A886311D59A1C500459CE7 /* ViewController.m */, 126 | B8A886331D59A1C500459CE7 /* Main.storyboard */, 127 | B8A886361D59A1C500459CE7 /* Assets.xcassets */, 128 | B8A886381D59A1C500459CE7 /* LaunchScreen.storyboard */, 129 | B8A8863B1D59A1C500459CE7 /* Info.plist */, 130 | B8A8862A1D59A1C500459CE7 /* Supporting Files */, 131 | ); 132 | path = UDisk; 133 | sourceTree = ""; 134 | }; 135 | B8A8862A1D59A1C500459CE7 /* Supporting Files */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | B8A8862B1D59A1C500459CE7 /* main.m */, 139 | ); 140 | name = "Supporting Files"; 141 | sourceTree = ""; 142 | }; 143 | B8A886431D59A1C500459CE7 /* UDiskTests */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | B8A886441D59A1C500459CE7 /* UDiskTests.m */, 147 | B8A886461D59A1C500459CE7 /* Info.plist */, 148 | ); 149 | path = UDiskTests; 150 | sourceTree = ""; 151 | }; 152 | B8A8864E1D59A1C500459CE7 /* UDiskUITests */ = { 153 | isa = PBXGroup; 154 | children = ( 155 | B8A8864F1D59A1C500459CE7 /* UDiskUITests.m */, 156 | B8A886511D59A1C500459CE7 /* Info.plist */, 157 | ); 158 | path = UDiskUITests; 159 | sourceTree = ""; 160 | }; 161 | B8A886751D59BD1000459CE7 /* Filesystem */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | B8A8865D1D59A1D600459CE7 /* FileSystem.h */, 165 | B8A8865E1D59A1D600459CE7 /* FileSystem.m */, 166 | B8A886661D59A88B00459CE7 /* FileItemModel.h */, 167 | B8A886671D59A88B00459CE7 /* FileItemModel.m */, 168 | B8A886691D59AAB200459CE7 /* FileIO.c */, 169 | B8A8866A1D59AAB200459CE7 /* FileIO.h */, 170 | B8A8866C1D59AAD700459CE7 /* EADSessionController.h */, 171 | B8A8866D1D59AAD700459CE7 /* EADSessionController.m */, 172 | B8A886701D59B72A00459CE7 /* Filelist.h */, 173 | B8A886711D59B72A00459CE7 /* Filelist.m */, 174 | B8A886721D59B72A00459CE7 /* Filelist.xib */, 175 | ); 176 | name = Filesystem; 177 | sourceTree = ""; 178 | }; 179 | /* End PBXGroup section */ 180 | 181 | /* Begin PBXNativeTarget section */ 182 | B8A886261D59A1C500459CE7 /* UDisk */ = { 183 | isa = PBXNativeTarget; 184 | buildConfigurationList = B8A886541D59A1C500459CE7 /* Build configuration list for PBXNativeTarget "UDisk" */; 185 | buildPhases = ( 186 | B8A886231D59A1C500459CE7 /* Sources */, 187 | B8A886241D59A1C500459CE7 /* Frameworks */, 188 | B8A886251D59A1C500459CE7 /* Resources */, 189 | ); 190 | buildRules = ( 191 | ); 192 | dependencies = ( 193 | ); 194 | name = UDisk; 195 | productName = UDisk; 196 | productReference = B8A886271D59A1C500459CE7 /* UDisk.app */; 197 | productType = "com.apple.product-type.application"; 198 | }; 199 | B8A8863F1D59A1C500459CE7 /* UDiskTests */ = { 200 | isa = PBXNativeTarget; 201 | buildConfigurationList = B8A886571D59A1C500459CE7 /* Build configuration list for PBXNativeTarget "UDiskTests" */; 202 | buildPhases = ( 203 | B8A8863C1D59A1C500459CE7 /* Sources */, 204 | B8A8863D1D59A1C500459CE7 /* Frameworks */, 205 | B8A8863E1D59A1C500459CE7 /* Resources */, 206 | ); 207 | buildRules = ( 208 | ); 209 | dependencies = ( 210 | B8A886421D59A1C500459CE7 /* PBXTargetDependency */, 211 | ); 212 | name = UDiskTests; 213 | productName = UDiskTests; 214 | productReference = B8A886401D59A1C500459CE7 /* UDiskTests.xctest */; 215 | productType = "com.apple.product-type.bundle.unit-test"; 216 | }; 217 | B8A8864A1D59A1C500459CE7 /* UDiskUITests */ = { 218 | isa = PBXNativeTarget; 219 | buildConfigurationList = B8A8865A1D59A1C500459CE7 /* Build configuration list for PBXNativeTarget "UDiskUITests" */; 220 | buildPhases = ( 221 | B8A886471D59A1C500459CE7 /* Sources */, 222 | B8A886481D59A1C500459CE7 /* Frameworks */, 223 | B8A886491D59A1C500459CE7 /* Resources */, 224 | ); 225 | buildRules = ( 226 | ); 227 | dependencies = ( 228 | B8A8864D1D59A1C500459CE7 /* PBXTargetDependency */, 229 | ); 230 | name = UDiskUITests; 231 | productName = UDiskUITests; 232 | productReference = B8A8864B1D59A1C500459CE7 /* UDiskUITests.xctest */; 233 | productType = "com.apple.product-type.bundle.ui-testing"; 234 | }; 235 | /* End PBXNativeTarget section */ 236 | 237 | /* Begin PBXProject section */ 238 | B8A8861F1D59A1C500459CE7 /* Project object */ = { 239 | isa = PBXProject; 240 | attributes = { 241 | LastUpgradeCheck = 0730; 242 | ORGANIZATIONNAME = "两仪式"; 243 | TargetAttributes = { 244 | B8A886261D59A1C500459CE7 = { 245 | CreatedOnToolsVersion = 7.3.1; 246 | DevelopmentTeam = RZJX863SMT; 247 | }; 248 | B8A8863F1D59A1C500459CE7 = { 249 | CreatedOnToolsVersion = 7.3.1; 250 | TestTargetID = B8A886261D59A1C500459CE7; 251 | }; 252 | B8A8864A1D59A1C500459CE7 = { 253 | CreatedOnToolsVersion = 7.3.1; 254 | TestTargetID = B8A886261D59A1C500459CE7; 255 | }; 256 | }; 257 | }; 258 | buildConfigurationList = B8A886221D59A1C500459CE7 /* Build configuration list for PBXProject "UDisk" */; 259 | compatibilityVersion = "Xcode 3.2"; 260 | developmentRegion = English; 261 | hasScannedForEncodings = 0; 262 | knownRegions = ( 263 | en, 264 | Base, 265 | ); 266 | mainGroup = B8A8861E1D59A1C500459CE7; 267 | productRefGroup = B8A886281D59A1C500459CE7 /* Products */; 268 | projectDirPath = ""; 269 | projectRoot = ""; 270 | targets = ( 271 | B8A886261D59A1C500459CE7 /* UDisk */, 272 | B8A8863F1D59A1C500459CE7 /* UDiskTests */, 273 | B8A8864A1D59A1C500459CE7 /* UDiskUITests */, 274 | ); 275 | }; 276 | /* End PBXProject section */ 277 | 278 | /* Begin PBXResourcesBuildPhase section */ 279 | B8A886251D59A1C500459CE7 /* Resources */ = { 280 | isa = PBXResourcesBuildPhase; 281 | buildActionMask = 2147483647; 282 | files = ( 283 | B8A8863A1D59A1C500459CE7 /* LaunchScreen.storyboard in Resources */, 284 | B8A886741D59B72A00459CE7 /* Filelist.xib in Resources */, 285 | B8A886371D59A1C500459CE7 /* Assets.xcassets in Resources */, 286 | B8A886351D59A1C500459CE7 /* Main.storyboard in Resources */, 287 | ); 288 | runOnlyForDeploymentPostprocessing = 0; 289 | }; 290 | B8A8863E1D59A1C500459CE7 /* Resources */ = { 291 | isa = PBXResourcesBuildPhase; 292 | buildActionMask = 2147483647; 293 | files = ( 294 | ); 295 | runOnlyForDeploymentPostprocessing = 0; 296 | }; 297 | B8A886491D59A1C500459CE7 /* Resources */ = { 298 | isa = PBXResourcesBuildPhase; 299 | buildActionMask = 2147483647; 300 | files = ( 301 | ); 302 | runOnlyForDeploymentPostprocessing = 0; 303 | }; 304 | /* End PBXResourcesBuildPhase section */ 305 | 306 | /* Begin PBXSourcesBuildPhase section */ 307 | B8A886231D59A1C500459CE7 /* Sources */ = { 308 | isa = PBXSourcesBuildPhase; 309 | buildActionMask = 2147483647; 310 | files = ( 311 | B8A8865F1D59A1D600459CE7 /* FileSystem.m in Sources */, 312 | B8A886731D59B72A00459CE7 /* Filelist.m in Sources */, 313 | B8A886681D59A88B00459CE7 /* FileItemModel.m in Sources */, 314 | B8A886321D59A1C500459CE7 /* ViewController.m in Sources */, 315 | B8A8866E1D59AAD700459CE7 /* EADSessionController.m in Sources */, 316 | B8A8866B1D59AAB200459CE7 /* FileIO.c in Sources */, 317 | B8A8862F1D59A1C500459CE7 /* AppDelegate.m in Sources */, 318 | B8A8862C1D59A1C500459CE7 /* main.m in Sources */, 319 | ); 320 | runOnlyForDeploymentPostprocessing = 0; 321 | }; 322 | B8A8863C1D59A1C500459CE7 /* Sources */ = { 323 | isa = PBXSourcesBuildPhase; 324 | buildActionMask = 2147483647; 325 | files = ( 326 | B8A886451D59A1C500459CE7 /* UDiskTests.m in Sources */, 327 | ); 328 | runOnlyForDeploymentPostprocessing = 0; 329 | }; 330 | B8A886471D59A1C500459CE7 /* Sources */ = { 331 | isa = PBXSourcesBuildPhase; 332 | buildActionMask = 2147483647; 333 | files = ( 334 | B8A886501D59A1C500459CE7 /* UDiskUITests.m in Sources */, 335 | ); 336 | runOnlyForDeploymentPostprocessing = 0; 337 | }; 338 | /* End PBXSourcesBuildPhase section */ 339 | 340 | /* Begin PBXTargetDependency section */ 341 | B8A886421D59A1C500459CE7 /* PBXTargetDependency */ = { 342 | isa = PBXTargetDependency; 343 | target = B8A886261D59A1C500459CE7 /* UDisk */; 344 | targetProxy = B8A886411D59A1C500459CE7 /* PBXContainerItemProxy */; 345 | }; 346 | B8A8864D1D59A1C500459CE7 /* PBXTargetDependency */ = { 347 | isa = PBXTargetDependency; 348 | target = B8A886261D59A1C500459CE7 /* UDisk */; 349 | targetProxy = B8A8864C1D59A1C500459CE7 /* PBXContainerItemProxy */; 350 | }; 351 | /* End PBXTargetDependency section */ 352 | 353 | /* Begin PBXVariantGroup section */ 354 | B8A886331D59A1C500459CE7 /* Main.storyboard */ = { 355 | isa = PBXVariantGroup; 356 | children = ( 357 | B8A886341D59A1C500459CE7 /* Base */, 358 | ); 359 | name = Main.storyboard; 360 | sourceTree = ""; 361 | }; 362 | B8A886381D59A1C500459CE7 /* LaunchScreen.storyboard */ = { 363 | isa = PBXVariantGroup; 364 | children = ( 365 | B8A886391D59A1C500459CE7 /* Base */, 366 | ); 367 | name = LaunchScreen.storyboard; 368 | sourceTree = ""; 369 | }; 370 | /* End PBXVariantGroup section */ 371 | 372 | /* Begin XCBuildConfiguration section */ 373 | B8A886521D59A1C500459CE7 /* Debug */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | ALWAYS_SEARCH_USER_PATHS = NO; 377 | CLANG_ANALYZER_NONNULL = YES; 378 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 379 | CLANG_CXX_LIBRARY = "libc++"; 380 | CLANG_ENABLE_MODULES = YES; 381 | CLANG_ENABLE_OBJC_ARC = YES; 382 | CLANG_WARN_BOOL_CONVERSION = YES; 383 | CLANG_WARN_CONSTANT_CONVERSION = YES; 384 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 385 | CLANG_WARN_EMPTY_BODY = YES; 386 | CLANG_WARN_ENUM_CONVERSION = YES; 387 | CLANG_WARN_INT_CONVERSION = YES; 388 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 389 | CLANG_WARN_UNREACHABLE_CODE = YES; 390 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 391 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 392 | COPY_PHASE_STRIP = NO; 393 | DEBUG_INFORMATION_FORMAT = dwarf; 394 | ENABLE_STRICT_OBJC_MSGSEND = YES; 395 | ENABLE_TESTABILITY = YES; 396 | GCC_C_LANGUAGE_STANDARD = gnu99; 397 | GCC_DYNAMIC_NO_PIC = NO; 398 | GCC_NO_COMMON_BLOCKS = YES; 399 | GCC_OPTIMIZATION_LEVEL = 0; 400 | GCC_PREPROCESSOR_DEFINITIONS = ( 401 | "DEBUG=1", 402 | "$(inherited)", 403 | ); 404 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 405 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 406 | GCC_WARN_UNDECLARED_SELECTOR = YES; 407 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 408 | GCC_WARN_UNUSED_FUNCTION = YES; 409 | GCC_WARN_UNUSED_VARIABLE = YES; 410 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 411 | MTL_ENABLE_DEBUG_INFO = YES; 412 | ONLY_ACTIVE_ARCH = YES; 413 | SDKROOT = iphoneos; 414 | TARGETED_DEVICE_FAMILY = "1,2"; 415 | }; 416 | name = Debug; 417 | }; 418 | B8A886531D59A1C500459CE7 /* Release */ = { 419 | isa = XCBuildConfiguration; 420 | buildSettings = { 421 | ALWAYS_SEARCH_USER_PATHS = NO; 422 | CLANG_ANALYZER_NONNULL = YES; 423 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 424 | CLANG_CXX_LIBRARY = "libc++"; 425 | CLANG_ENABLE_MODULES = YES; 426 | CLANG_ENABLE_OBJC_ARC = YES; 427 | CLANG_WARN_BOOL_CONVERSION = YES; 428 | CLANG_WARN_CONSTANT_CONVERSION = YES; 429 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 430 | CLANG_WARN_EMPTY_BODY = YES; 431 | CLANG_WARN_ENUM_CONVERSION = YES; 432 | CLANG_WARN_INT_CONVERSION = YES; 433 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 434 | CLANG_WARN_UNREACHABLE_CODE = YES; 435 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 436 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 437 | COPY_PHASE_STRIP = NO; 438 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 439 | ENABLE_NS_ASSERTIONS = NO; 440 | ENABLE_STRICT_OBJC_MSGSEND = YES; 441 | GCC_C_LANGUAGE_STANDARD = gnu99; 442 | GCC_NO_COMMON_BLOCKS = YES; 443 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 444 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 445 | GCC_WARN_UNDECLARED_SELECTOR = YES; 446 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 447 | GCC_WARN_UNUSED_FUNCTION = YES; 448 | GCC_WARN_UNUSED_VARIABLE = YES; 449 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 450 | MTL_ENABLE_DEBUG_INFO = NO; 451 | SDKROOT = iphoneos; 452 | TARGETED_DEVICE_FAMILY = "1,2"; 453 | VALIDATE_PRODUCT = YES; 454 | }; 455 | name = Release; 456 | }; 457 | B8A886551D59A1C500459CE7 /* Debug */ = { 458 | isa = XCBuildConfiguration; 459 | buildSettings = { 460 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 461 | CODE_SIGN_IDENTITY = "iPhone Developer"; 462 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 463 | GCC_PRECOMPILE_PREFIX_HEADER = NO; 464 | GCC_PREFIX_HEADER = ""; 465 | HEADER_SEARCH_PATHS = ""; 466 | INFOPLIST_FILE = UDisk/Info.plist; 467 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 468 | PRODUCT_BUNDLE_IDENTIFIER = com.shiki.test.UDisk; 469 | PRODUCT_NAME = "$(TARGET_NAME)"; 470 | PROVISIONING_PROFILE = ""; 471 | }; 472 | name = Debug; 473 | }; 474 | B8A886561D59A1C500459CE7 /* Release */ = { 475 | isa = XCBuildConfiguration; 476 | buildSettings = { 477 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 478 | CODE_SIGN_IDENTITY = "iPhone Developer"; 479 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 480 | GCC_PRECOMPILE_PREFIX_HEADER = NO; 481 | GCC_PREFIX_HEADER = ""; 482 | HEADER_SEARCH_PATHS = ""; 483 | INFOPLIST_FILE = UDisk/Info.plist; 484 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 485 | PRODUCT_BUNDLE_IDENTIFIER = com.shiki.test.UDisk; 486 | PRODUCT_NAME = "$(TARGET_NAME)"; 487 | PROVISIONING_PROFILE = ""; 488 | }; 489 | name = Release; 490 | }; 491 | B8A886581D59A1C500459CE7 /* Debug */ = { 492 | isa = XCBuildConfiguration; 493 | buildSettings = { 494 | BUNDLE_LOADER = "$(TEST_HOST)"; 495 | INFOPLIST_FILE = UDiskTests/Info.plist; 496 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 497 | PRODUCT_BUNDLE_IDENTIFIER = com.shiki.test.UDiskTests; 498 | PRODUCT_NAME = "$(TARGET_NAME)"; 499 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UDisk.app/UDisk"; 500 | }; 501 | name = Debug; 502 | }; 503 | B8A886591D59A1C500459CE7 /* Release */ = { 504 | isa = XCBuildConfiguration; 505 | buildSettings = { 506 | BUNDLE_LOADER = "$(TEST_HOST)"; 507 | INFOPLIST_FILE = UDiskTests/Info.plist; 508 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 509 | PRODUCT_BUNDLE_IDENTIFIER = com.shiki.test.UDiskTests; 510 | PRODUCT_NAME = "$(TARGET_NAME)"; 511 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UDisk.app/UDisk"; 512 | }; 513 | name = Release; 514 | }; 515 | B8A8865B1D59A1C500459CE7 /* Debug */ = { 516 | isa = XCBuildConfiguration; 517 | buildSettings = { 518 | INFOPLIST_FILE = UDiskUITests/Info.plist; 519 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 520 | PRODUCT_BUNDLE_IDENTIFIER = com.shiki.test.UDiskUITests; 521 | PRODUCT_NAME = "$(TARGET_NAME)"; 522 | TEST_TARGET_NAME = UDisk; 523 | }; 524 | name = Debug; 525 | }; 526 | B8A8865C1D59A1C500459CE7 /* Release */ = { 527 | isa = XCBuildConfiguration; 528 | buildSettings = { 529 | INFOPLIST_FILE = UDiskUITests/Info.plist; 530 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 531 | PRODUCT_BUNDLE_IDENTIFIER = com.shiki.test.UDiskUITests; 532 | PRODUCT_NAME = "$(TARGET_NAME)"; 533 | TEST_TARGET_NAME = UDisk; 534 | }; 535 | name = Release; 536 | }; 537 | /* End XCBuildConfiguration section */ 538 | 539 | /* Begin XCConfigurationList section */ 540 | B8A886221D59A1C500459CE7 /* Build configuration list for PBXProject "UDisk" */ = { 541 | isa = XCConfigurationList; 542 | buildConfigurations = ( 543 | B8A886521D59A1C500459CE7 /* Debug */, 544 | B8A886531D59A1C500459CE7 /* Release */, 545 | ); 546 | defaultConfigurationIsVisible = 0; 547 | defaultConfigurationName = Release; 548 | }; 549 | B8A886541D59A1C500459CE7 /* Build configuration list for PBXNativeTarget "UDisk" */ = { 550 | isa = XCConfigurationList; 551 | buildConfigurations = ( 552 | B8A886551D59A1C500459CE7 /* Debug */, 553 | B8A886561D59A1C500459CE7 /* Release */, 554 | ); 555 | defaultConfigurationIsVisible = 0; 556 | defaultConfigurationName = Release; 557 | }; 558 | B8A886571D59A1C500459CE7 /* Build configuration list for PBXNativeTarget "UDiskTests" */ = { 559 | isa = XCConfigurationList; 560 | buildConfigurations = ( 561 | B8A886581D59A1C500459CE7 /* Debug */, 562 | B8A886591D59A1C500459CE7 /* Release */, 563 | ); 564 | defaultConfigurationIsVisible = 0; 565 | defaultConfigurationName = Release; 566 | }; 567 | B8A8865A1D59A1C500459CE7 /* Build configuration list for PBXNativeTarget "UDiskUITests" */ = { 568 | isa = XCConfigurationList; 569 | buildConfigurations = ( 570 | B8A8865B1D59A1C500459CE7 /* Debug */, 571 | B8A8865C1D59A1C500459CE7 /* Release */, 572 | ); 573 | defaultConfigurationIsVisible = 0; 574 | defaultConfigurationName = Release; 575 | }; 576 | /* End XCConfigurationList section */ 577 | }; 578 | rootObject = B8A8861F1D59A1C500459CE7 /* Project object */; 579 | } 580 | -------------------------------------------------------------------------------- /UDisk.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UDisk.xcodeproj/xcuserdata/zhushuai.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /UDisk.xcodeproj/xcuserdata/zhushuai.xcuserdatad/xcschemes/UDisk.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /UDisk.xcodeproj/xcuserdata/zhushuai.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UDisk.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B8A886261D59A1C500459CE7 16 | 17 | primary 18 | 19 | 20 | B8A8863F1D59A1C500459CE7 21 | 22 | primary 23 | 24 | 25 | B8A8864A1D59A1C500459CE7 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /UDisk/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /UDisk/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | [self redirectNSlogToDocumentFolder]; 20 | return YES; 21 | } 22 | 23 | - (void)redirectNSlogToDocumentFolder 24 | { 25 | NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 26 | NSString *documentDirectory = [paths objectAtIndex:0]; 27 | NSString *fileName = [NSString stringWithFormat:@"dr.log"];//注意不是NSData! 28 | NSString *logFilePath = [documentDirectory stringByAppendingPathComponent:fileName]; 29 | //先删除已经存在的文件 30 | NSFileManager *defaultManager = [NSFileManager defaultManager]; 31 | [defaultManager removeItemAtPath:logFilePath error:nil]; 32 | 33 | // 将log输入到文件 34 | freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+", stdout); 35 | freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+", stderr); 36 | } 37 | 38 | 39 | - (void)applicationWillResignActive:(UIApplication *)application { 40 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 41 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 42 | } 43 | 44 | - (void)applicationDidEnterBackground:(UIApplication *)application { 45 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 46 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 47 | } 48 | 49 | - (void)applicationWillEnterForeground:(UIApplication *)application { 50 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 51 | } 52 | 53 | - (void)applicationDidBecomeActive:(UIApplication *)application { 54 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 55 | } 56 | 57 | - (void)applicationWillTerminate:(UIApplication *)application { 58 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /UDisk/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /UDisk/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /UDisk/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /UDisk/EADSessionController.h: -------------------------------------------------------------------------------- 1 | // 2 | // EADSessionController.h 3 | // OCSendTest 4 | // 5 | // Created by mwang on 2/19/16. 6 | // Copyright © 2016 nuvoton. All rights reserved. 7 | // 8 | 9 | #ifndef EADSessionController_h 10 | #define EADSessionController_h 11 | 12 | 13 | 14 | #import 15 | #import 16 | 17 | extern NSString *EADSessionDataReceivedNotification; 18 | 19 | // NOTE: EADSessionController is not threadsafe, calling methods from different threads will lead to unpredictable results 20 | @interface EADSessionController : NSObject { 21 | EAAccessory *_accessory; 22 | NSString *_protocolString; 23 | 24 | NSMutableData *_writeData; 25 | NSMutableData *_readData; 26 | } 27 | 28 | + (EADSessionController *)sharedController; 29 | 30 | - (void)setupControllerForAccessory:(EAAccessory *)accessory withProtocolString:(NSString *)protocolString; 31 | 32 | - (BOOL)openSession; 33 | - (void)closeSession; 34 | 35 | - (void)writeData:(NSData *)data; 36 | 37 | - (NSUInteger)readBytesAvailable; 38 | - (NSData *)readData:(NSUInteger)bytesToRead; 39 | @property(nonatomic,strong) EASession *_session; 40 | 41 | @property (nonatomic, readonly) EAAccessory *accessory; 42 | @property (nonatomic, readonly) NSString *protocolString; 43 | 44 | @end 45 | 46 | 47 | #endif /* EADSessionController_h */ 48 | -------------------------------------------------------------------------------- /UDisk/EADSessionController.m: -------------------------------------------------------------------------------- 1 | // 2 | // EADSessionController.m 3 | // OCSendTest 4 | // 5 | // Created by mwang on 2/19/16. 6 | // Copyright © 2016 nuvoton. All rights reserved. 7 | // 8 | 9 | #import 10 | /* 11 | 12 | File: EADSessionController.m 13 | Abstract: n/a 14 | Version: 1.1 15 | 16 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple 17 | Inc. ("Apple") in consideration of your agreement to the following 18 | terms, and your use, installation, modification or redistribution of 19 | this Apple software constitutes acceptance of these terms. If you do 20 | not agree with these terms, please do not use, install, modify or 21 | redistribute this Apple software. 22 | 23 | In consideration of your agreement to abide by the following terms, and 24 | subject to these terms, Apple grants you a personal, non-exclusive 25 | license, under Apple's copyrights in this original Apple software (the 26 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 27 | Software, with or without modifications, in source and/or binary forms; 28 | provided that if you redistribute the Apple Software in its entirety and 29 | without modifications, you must retain this notice and the following 30 | text and disclaimers in all such redistributions of the Apple Software. 31 | Neither the name, trademarks, service marks or logos of Apple Inc. may 32 | be used to endorse or promote products derived from the Apple Software 33 | without specific prior written permission from Apple. Except as 34 | expressly stated in this notice, no other rights or licenses, express or 35 | implied, are granted by Apple herein, including but not limited to any 36 | patent rights that may be infringed by your derivative works or by other 37 | works in which the Apple Software may be incorporated. 38 | 39 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 40 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 41 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 42 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 43 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 44 | 45 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 46 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 47 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 48 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 49 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 50 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 51 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 52 | POSSIBILITY OF SUCH DAMAGE. 53 | 54 | Copyright (C) 2010 Apple Inc. All Rights Reserved. 55 | 56 | 57 | */ 58 | 59 | #import "EADSessionController.h" 60 | 61 | NSString *EADSessionDataReceivedNotification = @"EADSessionDataReceivedNotification"; 62 | 63 | @implementation EADSessionController 64 | 65 | @synthesize accessory = _accessory; 66 | @synthesize protocolString = _protocolString; 67 | 68 | #pragma mark Internal 69 | 70 | // low level write method - write data to the accessory while there is space available and data to write 71 | - (void)_writeData { 72 | while (([[__session outputStream] hasSpaceAvailable]) && ([_writeData length] > 0)) 73 | { 74 | NSInteger bytesWritten = [[__session outputStream] write:[_writeData bytes] maxLength:[_writeData length]]; 75 | if (bytesWritten == -1) 76 | { 77 | NSLog(@"write error"); 78 | break; 79 | } 80 | else if (bytesWritten > 0) 81 | { 82 | [_writeData replaceBytesInRange:NSMakeRange(0, bytesWritten) withBytes:NULL length:0]; 83 | } 84 | } 85 | } 86 | 87 | // low level read method - read data while there is data and space available in the input buffer 88 | - (void)_readData { 89 | #define EAD_INPUT_BUFFER_SIZE 128 90 | uint8_t buf[EAD_INPUT_BUFFER_SIZE]; 91 | 92 | while ([[__session inputStream] hasBytesAvailable]) 93 | { 94 | NSInteger bytesRead = [[__session inputStream] read:buf maxLength:EAD_INPUT_BUFFER_SIZE]; 95 | if (_readData == nil) { 96 | _readData = [[NSMutableData alloc] init]; 97 | } 98 | [_readData appendBytes:(void *)buf length:bytesRead]; 99 | //NSLog(@"read %d bytes from input stream", bytesRead); 100 | } 101 | 102 | [[NSNotificationCenter defaultCenter] postNotificationName:EADSessionDataReceivedNotification object:self userInfo:nil]; 103 | } 104 | 105 | #pragma mark Public Methods 106 | 107 | + (EADSessionController *)sharedController 108 | { 109 | static EADSessionController *sessionController = nil; 110 | if (sessionController == nil) { 111 | sessionController = [[EADSessionController alloc] init]; 112 | } 113 | 114 | return sessionController; 115 | } 116 | 117 | - (void)dealloc 118 | { 119 | [self closeSession]; 120 | [self setupControllerForAccessory:nil withProtocolString:nil]; 121 | 122 | [super dealloc]; 123 | } 124 | 125 | // initialize the accessory with the protocolString 126 | - (void)setupControllerForAccessory:(EAAccessory *)accessory withProtocolString:(NSString *)protocolString 127 | { 128 | [_accessory release]; 129 | _accessory = [accessory retain]; 130 | [_protocolString release]; 131 | _protocolString = [protocolString copy]; 132 | } 133 | 134 | // open a session with the accessory and set up the input and output stream on the default run loop 135 | - (BOOL)openSession 136 | { 137 | [_accessory setDelegate:self]; 138 | __session = [[EASession alloc] initWithAccessory:_accessory forProtocol:_protocolString]; 139 | //_session = [[EASession alloc] initWithAccessory:_accessory forProtocol:_protocolString]; 140 | 141 | if (__session) 142 | { 143 | [[__session inputStream] setDelegate:self]; 144 | [[__session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 145 | [[__session inputStream] open]; 146 | 147 | [[__session outputStream] setDelegate:self]; 148 | [[__session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 149 | [[__session outputStream] open]; 150 | } 151 | else 152 | { 153 | NSLog(@"creating session failed"); 154 | } 155 | 156 | return (__session != nil); 157 | } 158 | 159 | // close the session with the accessory. 160 | - (void)closeSession 161 | { 162 | [[__session inputStream] close]; 163 | [[__session inputStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 164 | [[__session inputStream] setDelegate:nil]; 165 | [[__session outputStream] close]; 166 | [[__session outputStream] removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 167 | [[__session outputStream] setDelegate:nil]; 168 | 169 | [__session release]; 170 | __session = nil; 171 | 172 | [_writeData release]; 173 | _writeData = nil; 174 | [_readData release]; 175 | _readData = nil; 176 | } 177 | 178 | // high level write data method 179 | - (void)writeData:(NSData *)data 180 | { 181 | if (_writeData == nil) { 182 | _writeData = [[NSMutableData alloc] init]; 183 | } 184 | 185 | [_writeData appendData:data]; 186 | [self _writeData]; 187 | } 188 | 189 | // high level read method 190 | - (NSData *)readData:(NSUInteger)bytesToRead 191 | { 192 | NSData *data = nil; 193 | if ([_readData length] >= bytesToRead) { 194 | NSRange range = NSMakeRange(0, bytesToRead); 195 | data = [_readData subdataWithRange:range]; 196 | [_readData replaceBytesInRange:range withBytes:NULL length:0]; 197 | } 198 | return data; 199 | } 200 | 201 | // get number of bytes read into local buffer 202 | - (NSUInteger)readBytesAvailable 203 | { 204 | return [_readData length]; 205 | } 206 | 207 | #pragma mark EAAccessoryDelegate 208 | - (void)accessoryDidDisconnect:(EAAccessory *)accessory 209 | { 210 | // do something ... 211 | } 212 | 213 | #pragma mark NSStreamDelegateEventExtensions 214 | 215 | // asynchronous NSStream handleEvent method 216 | - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode 217 | { 218 | switch (eventCode) { 219 | case NSStreamEventNone: 220 | break; 221 | case NSStreamEventOpenCompleted: 222 | break; 223 | case NSStreamEventHasBytesAvailable: 224 | [self _readData]; 225 | break; 226 | case NSStreamEventHasSpaceAvailable: 227 | [self _writeData]; 228 | break; 229 | case NSStreamEventErrorOccurred: 230 | break; 231 | case NSStreamEventEndEncountered: 232 | break; 233 | default: 234 | break; 235 | } 236 | } 237 | 238 | - (NSString *)description 239 | { 240 | NSString *message = @""; 241 | message = [message stringByAppendingString:_accessory.description]; 242 | return message; 243 | } 244 | @end 245 | -------------------------------------------------------------------------------- /UDisk/FileIO.c: -------------------------------------------------------------------------------- 1 | // 2 | // FileIO.c 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #include "FileIO.h" 10 | #include 11 | #include 12 | #include 13 | struct FAT_PARA SD_para; //声明两个结构体变量 14 | struct FAT_OFFSET SD_offset; 15 | struct CBW cbwCmd; 16 | 17 | void read_10(uint32_t logicalBlockAddress, uint32_t blockNum) 18 | 19 | { 20 | uint32_t tmp; 21 | uint8_t *p = cbwCmd.au8Data; 22 | cbwCmd.dCBWSignature = 0x43425355;// 23 | cbwCmd.dCBWTag = arc4random();//dCBWTag 24 | cbwCmd.dCBWDataTransferLength = blockNum * 512;// 25 | cbwCmd.bmCBWFlags = 0x80;//device to host 26 | cbwCmd.bCBWLUN = 0x00; 27 | cbwCmd.bCBWCBLength = 0x0A;//read10 command 10 bytes 28 | cbwCmd.u8OPCode = 0x28;//opcode 29 | cbwCmd.u8LUN = 0x00;//para1 30 | memset(p, 0, 14); 31 | tmp = logicalBlockAddress; 32 | *((uint8_t *)(p+0)) = *((uint8_t *)&tmp+3); 33 | *((uint8_t *)(p+1)) = *((uint8_t *)&tmp+2); 34 | *((uint8_t *)(p+2)) = *((uint8_t *)&tmp+1); 35 | *((uint8_t *)(p+3)) = *((uint8_t *)&tmp+0); 36 | tmp = blockNum; 37 | *((uint8_t *)(p+5)) = *((uint8_t *)&tmp+1); 38 | *((uint8_t *)(p+6)) = *((uint8_t *)&tmp+0); 39 | 40 | } 41 | void write10(uint32_t logicalBlockAddress,uint32_t blockNum){ 42 | uint32_t tmp; 43 | uint8_t *p = cbwCmd.au8Data; 44 | cbwCmd.dCBWSignature = 0x43425355;//dCBWSignature 55 53 42 43 cbw包验证戳 45 | cbwCmd.dCBWTag = arc4random();//CBw包TAG 46 | cbwCmd.dCBWDataTransferLength = blockNum * 512;//cbw包接收指令长度 47 | cbwCmd.bmCBWFlags = 0x00;//cbw标识主机到device 48 | cbwCmd.bCBWLUN = 0x00;//逻辑驱动器数量 49 | cbwCmd.bCBWCBLength = 0x0A;//scsi写指令长度10个字节 50 | cbwCmd.u8OPCode = 0x2a;//scsi写指令操作码 51 | cbwCmd.u8LUN = 0x00;//指令逻辑驱动器下标 52 | memset(p, 0, 14); 53 | tmp = logicalBlockAddress; 54 | *((uint8_t *)(p+0)) = *((uint8_t *)&tmp+3);//扇区MSB 55 | *((uint8_t *)(p+1)) = *((uint8_t *)&tmp+2);//扇区MSB 56 | *((uint8_t *)(p+2)) = *((uint8_t *)&tmp+1);//扇区LSB 57 | *((uint8_t *)(p+3)) = *((uint8_t *)&tmp+0);//扇区LSB 58 | tmp = blockNum; 59 | *((uint8_t *)(p+5)) = *((uint8_t *)&tmp+1);//扇区数MSB 60 | *((uint8_t *)(p+6)) = *((uint8_t *)&tmp+0);//扇区数LSB 61 | } 62 | -------------------------------------------------------------------------------- /UDisk/FileIO.h: -------------------------------------------------------------------------------- 1 | // 2 | // FileIO.h 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #ifndef FileIO_h 10 | #define FileIO_h 11 | #define U16 uint16_t 12 | #define U8 uint8_t 13 | #define U32 uint32_t 14 | #include 15 | struct CBW{ 16 | 17 | uint32_t dCBWSignature; 18 | uint32_t dCBWTag; 19 | uint32_t dCBWDataTransferLength; 20 | uint8_t bmCBWFlags; 21 | uint8_t bCBWLUN; 22 | uint8_t bCBWCBLength; 23 | uint8_t u8OPCode; 24 | uint8_t u8LUN; 25 | uint8_t au8Data[14]; 26 | 27 | }; 28 | struct FAT_PARA 29 | { 30 | U16 BytesPerSector; //每个扇区多少字节 31 | U8 SectorsPerCluster; //每个簇有多少个扇区 32 | U16 ReserveSectors; //保留扇区数 33 | U8 FatTableNums; //有多少个FAT表 34 | U16 RootDirRegNums; //根目录允许的登记项数目 35 | U16 SectorsPerFat; //每个FAT表有多少个扇区 36 | U32 SectorNums; //总的扇区数 37 | U8 FileType[7]; //文件系统类型 38 | }; 39 | /** 40 | * FAT OFFSET 41 | */ 42 | struct FAT_OFFSET 43 | { 44 | U32 Logic; //引导扇(逻辑扇区0)对物理0扇区里的偏移地址 45 | U32 FAT1; 46 | U32 FAT2; 47 | U32 FDT; 48 | U32 Cluster; //数据簇的偏移地址 49 | }; 50 | extern struct FAT_PARA SD_para; //声明两个结构体变量 51 | extern struct FAT_OFFSET SD_offset; 52 | extern struct CBW cbwCmd; 53 | 54 | void write10(uint32_t logicalBlockAddress, uint32_t blockNum); 55 | void read_10(uint32_t logicalBlockAddress, uint32_t blockNum); 56 | 57 | #endif /* FileIO_h */ 58 | -------------------------------------------------------------------------------- /UDisk/FileItemModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // FileItemModel.h 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FileItemModel : NSObject 12 | @property(nonatomic,strong)NSString *name; 13 | @property(nonatomic,assign)int filesector; 14 | @property(nonatomic,assign)uintmax_t filesize; 15 | @property(nonatomic,strong)NSString *longname; 16 | @property(nonatomic,strong)NSString *filetype; 17 | 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /UDisk/FileItemModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // FileItemModel.m 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import "FileItemModel.h" 10 | 11 | @implementation FileItemModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /UDisk/FileSystem.h: -------------------------------------------------------------------------------- 1 | // 2 | // FileSystem.h 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "FileItemModel.h" 11 | 12 | @interface FileSystem : NSObject{ 13 | 14 | NSString *FinalStr; 15 | } 16 | 17 | -(void )clearsTRTodata:(NSData *)data; 18 | -(Boolean )isFAT32; 19 | -(Boolean )isFAT16; 20 | -(void)translateFAT32datafordata:(NSData *)data; 21 | -(void)translateFAT16datafordata:(NSData *)data; 22 | -(void)getFileDir; 23 | -(Byte *)clearData:(Byte *)arg1; 24 | -(BOOL)readlongfile:(Byte *)dataByte; 25 | -(FileItemModel *)read32shortfile:(Byte *)dataByte; 26 | -(FileItemModel *)read16shortfile:(Byte *)dataByte; 27 | -(Byte *)readdata:(Byte *)dataa andoffset:(int)offset andcount:(int )count; 28 | -(void)deleteFF:(Byte*)by andcount:(int)count; 29 | -(NSString *)readbyte:(Byte *)databyte andoffset:(int)offset andcount:(int)count; 30 | -(void)getMBRNumberTodata:(NSData *)data; 31 | -(uint64_t )seekFreeCluster; 32 | -(uint64_t )seekAllFreeCluster; 33 | @property(nonatomic,strong)NSString *sa2; 34 | @property(nonatomic,assign)uint64_t sectorpercu; 35 | @property(nonatomic,strong)NSMutableString *fileitem; //final string 36 | @property(nonatomic,strong)NSData *data; 37 | @property(nonatomic,strong)FileItemModel *mode; 38 | @property(nonatomic,strong)NSString *filesystemType; 39 | @property(nonatomic,strong)NSMutableArray *finalArray; 40 | @property(nonatomic,strong)NSMutableArray *countArr; 41 | @property(nonatomic,assign)unsigned long restcount; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /UDisk/FileSystem.m: -------------------------------------------------------------------------------- 1 | // 2 | // FileSystem.m 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import "FileSystem.h" 10 | #import "FileIO.h" 11 | int count = 0; 12 | 13 | @implementation FileSystem 14 | /** 15 | * 删除data中多余的csw包以及数据 16 | * 17 | * @param data 目标data 18 | */ 19 | -(void )clearsTRTodata:(NSData *)data{ 20 | 21 | NSRange ra = [data.description rangeOfString:@"55534253"]; 22 | NSString *saaa = [data.description substringWithRange:NSMakeRange(0, ra.location-1)]; 23 | NSString *sa1 = [saaa stringByReplacingOccurrencesOfString:@" " withString:@""]; 24 | 25 | self.sa2 = [sa1 substringFromIndex:1]; 26 | } 27 | /** 28 | * 判断是否是fat32系统 29 | * 30 | * @return 判断 31 | */ 32 | -(Boolean )isFAT32{ 33 | 34 | Boolean isfat32 = false; 35 | 36 | Byte p[[_sa2 length]]; 37 | for (int i = 0; i<[_sa2 length]; i+=2) { 38 | NSString *sa3 = [_sa2 substringWithRange:NSMakeRange(i, 2)]; 39 | uint64_t mac = strtoul([sa3 UTF8String], 0, 16); 40 | 41 | p[i] = mac; 42 | } 43 | Byte pa[5] = {p[164],p[166],p[168],p[170],p[172]}; 44 | NSData *dataa = [NSData dataWithBytes:&pa length:5]; 45 | NSString *saa = [[NSString alloc]initWithData:dataa encoding:NSASCIIStringEncoding]; 46 | if ([saa isEqualToString:@"FAT32"]) { 47 | isfat32=true; 48 | } 49 | return isfat32; 50 | 51 | } 52 | /** 53 | * 判断是否是fat16 54 | * 55 | * @return 56 | */ 57 | -(Boolean )isFAT16{ 58 | 59 | Boolean isfat16 = FALSE; 60 | Byte p[[_sa2 length]]; 61 | for (int i = 0; i<[_sa2 length]; i+=2) { 62 | NSString *sa3 = [_sa2 substringWithRange:NSMakeRange(i, 2)]; 63 | uint64_t mac = strtoul([sa3 UTF8String], 0, 16); 64 | 65 | p[i] = mac; 66 | } 67 | Byte pa[5] = {p[108],p[110],p[112],p[114],p[116]}; 68 | NSData *dataa = [NSData dataWithBytes:&pa length:5]; 69 | NSString *saa = [[NSString alloc]initWithData:dataa encoding:NSASCIIStringEncoding]; 70 | if ([saa rangeOfString:@"FAT16"].location!=NSNotFound) { 71 | isfat16 = true; 72 | } 73 | return isfat16; 74 | 75 | } 76 | /** 77 | * 根据data解析fat数据 78 | * 79 | * @param data 参数data 80 | */ 81 | -(void)translateFAT32datafordata:(NSData *)data{ 82 | uint64_t * p = [self clearString:data.description andlength:1024]; 83 | uint64_t p9 = p[11]; 84 | uint64_t p10 = p[12]; 85 | SD_para.BytesPerSector = p10 * 256 + p9; 86 | //每扇区字节数 87 | uint64_t p1 = p[36]; 88 | uint64_t p2 = p[37]*256; 89 | uint64_t p3 = p[38]*65536; 90 | uint64_t p4 = p[39]*16777216; 91 | SD_para.SectorsPerFat = p1+p2+p3+p4;//每个fat表占用的扇区数 92 | SD_para.FatTableNums = p[16];//fat表个数 93 | uint64_t p13 = p[14] ; 94 | uint64_t p14 = p[15]*256 ; 95 | _sectorpercu = p[13]; 96 | 97 | SD_para.ReserveSectors = p13+p14;//保留扇区数 98 | // 数据区起始扇区号 = 保留扇区数 + 每个FAT表大小扇区数 × FAT表个数 99 | SD_offset.Cluster = SD_para.ReserveSectors + SD_para.SectorsPerFat * SD_para.FatTableNums; 100 | 101 | 102 | } 103 | 104 | /** 105 | * 将数据装入byte数组 106 | * 107 | * @param dataString 清除后的字符串 108 | * @param length 装入的长度 109 | * 110 | * @return 存储后的数组 111 | */ 112 | -(uint64_t*)clearString:(NSString *)dataString andlength:(int)length{ 113 | 114 | uint64_t * p = malloc(length * sizeof(uint64_t)); 115 | for (int i =0; i 394 | */ 395 | -(void)getMBRNumberTodata:(NSData *)data{ 396 | uint64_t * p = [self clearString:data.description andlength:1024]; 397 | uint64_t p1 = p[454]+p[455]*256+p[456]*256*256+p[457]*256*256*256; 398 | self.fileitem = [[NSMutableString alloc]init]; 399 | 400 | SD_offset.Logic = (U32)p1; 401 | } 402 | -(uint64_t)seekFreeCluster{ 403 | uint64_t freeCluster = 0; 404 | if (_restcount%512==0) { 405 | 406 | int clust = ceil(_restcount/512/2); 407 | freeCluster = SD_offset.Cluster+clust; 408 | 409 | }else{ 410 | 411 | int clust = ceil(_restcount/512/2)+1; 412 | freeCluster = SD_offset.Cluster+clust; 413 | 414 | 415 | } 416 | 417 | return freeCluster; 418 | 419 | } 420 | /** 421 | * 找到根目录的最后一个地址 422 | * 423 | * @return <#return value description#> 424 | */ 425 | -(uint64_t)seekAllFreeCluster{ 426 | uint64_t freeCluster = 0; 427 | 428 | return freeCluster; 429 | } 430 | /** 431 | * 文件系统解析方法 432 | */ 433 | -(void)getFileDir{ 434 | self.finalArray = [[NSMutableArray alloc]init]; 435 | self.countArr = [[NSMutableArray alloc]init]; 436 | Byte bya[32 * 512]; 437 | for (int i =0; i 10 | 11 | @interface Filelist : UITableViewCell 12 | @property (retain, nonatomic) IBOutlet UIImageView *filetypeimg; 13 | @property (retain, nonatomic) IBOutlet UILabel *filenamelabel; 14 | @property (retain, nonatomic) IBOutlet UILabel *sizelabel; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /UDisk/Filelist.m: -------------------------------------------------------------------------------- 1 | // 2 | // Filelist.m 3 | // OCSendTest 4 | // 5 | // Created by 朱帅 on 16/7/1. 6 | // Copyright © 2016年 nuvoton. All rights reserved. 7 | // 8 | 9 | #import "Filelist.h" 10 | 11 | @implementation Filelist 12 | 13 | - (void)awakeFromNib { 14 | [super awakeFromNib]; 15 | // Initialization code 16 | } 17 | 18 | -(instancetype)initWithFrame:(CGRect)frame{ 19 | self = [super initWithFrame:frame]; 20 | if (self) { 21 | 22 | } 23 | return self; 24 | } 25 | 26 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 27 | [super setSelected:selected animated:animated]; 28 | 29 | // Configure the view for the selected state 30 | } 31 | 32 | 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /UDisk/Filelist.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /UDisk/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIBackgroundModes 6 | 7 | "App communicates with an accessory" 8 | 9 | "App communicates with an accessory" 10 | 11 | 12 | 13 | UIFileSharingEnabled 14 | 15 | UISupportedExternalAccessoryProtocols 16 | 17 | com.nuvoton.protocol 18 | 19 | CFBundleDevelopmentRegion 20 | en 21 | CFBundleExecutable 22 | $(EXECUTABLE_NAME) 23 | CFBundleIdentifier 24 | $(PRODUCT_BUNDLE_IDENTIFIER) 25 | CFBundleInfoDictionaryVersion 26 | 6.0 27 | CFBundleName 28 | $(PRODUCT_NAME) 29 | CFBundlePackageType 30 | APPL 31 | CFBundleShortVersionString 32 | 1.0 33 | LSApplicationCategoryType 34 | 35 | CFBundleSignature 36 | ???? 37 | CFBundleVersion 38 | 1 39 | LSRequiresIPhoneOS 40 | 41 | UILaunchStoryboardName 42 | LaunchScreen 43 | UIMainStoryboardFile 44 | Main 45 | UIRequiredDeviceCapabilities 46 | 47 | armv7 48 | 49 | UISupportedInterfaceOrientations 50 | 51 | UIInterfaceOrientationPortrait 52 | UIInterfaceOrientationLandscapeLeft 53 | UIInterfaceOrientationLandscapeRight 54 | 55 | UISupportedInterfaceOrientations~ipad 56 | 57 | UIInterfaceOrientationPortrait 58 | UIInterfaceOrientationPortraitUpsideDown 59 | UIInterfaceOrientationLandscapeLeft 60 | UIInterfaceOrientationLandscapeRight 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /UDisk/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EADSessionController.h" 11 | 12 | @interface ViewController : UIViewController{ 13 | 14 | EAAccessory *_selectedAccessory; 15 | uint32_t _totalBytesRead; 16 | NSMutableArray *_accessoryList; 17 | NSData *data; 18 | int readcount; 19 | int touchcount; 20 | Boolean isfat32; 21 | Boolean isfat16; 22 | int reada; 23 | uintmax_t resttime; 24 | int lesstime; 25 | uint32_t fielsec; 26 | uintmax_t currentsize; 27 | int filetpe; 28 | uint64_t bad; 29 | uint64_t nextCluster; 30 | Byte *filena; 31 | 32 | 33 | 34 | } 35 | @property(nonatomic,strong) EADSessionController *_eaSessionController; 36 | 37 | 38 | @end 39 | 40 | -------------------------------------------------------------------------------- /UDisk/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "FileSystem.h" 11 | #import "Filelist.h" 12 | #import "FileIO.h" 13 | extern struct CBW cbwCmd; 14 | @interface ViewController () 15 | @property(nonatomic,strong)UITableView *table; 16 | @property(nonatomic,strong)NSMutableArray *backArray; 17 | @property(nonatomic,strong)FileSystem *system; 18 | @property(nonatomic,strong)NSArray *supportMediaFiletype; 19 | @property(nonatomic,strong)NSArray *supportDocumentFiletype; 20 | @property(nonatomic,strong)NSArray *supportImageFileType; 21 | @property(nonatomic,strong)NSMutableArray *finalArray; 22 | @property(nonatomic,strong)NSString *currentname; 23 | @property(nonatomic,strong)NSString *_currenttype; 24 | @property(nonatomic,strong)NSURL *finalurl; 25 | 26 | @end 27 | 28 | @implementation ViewController 29 | - (void)viewDidLoad { 30 | [super viewDidLoad]; 31 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil]; 32 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil]; 33 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_sessionDataReceived:) name:EADSessionDataReceivedNotification object:nil]; 34 | [[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications]; 35 | self.table = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain]; 36 | self.system = [[FileSystem alloc]init]; 37 | [self.view addSubview:self.table]; 38 | self.table.delegate = self; 39 | self.table.dataSource = self; 40 | [self.table registerNib:[UINib nibWithNibName:@"Filelist" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"123"]; 41 | self._eaSessionController = [EADSessionController sharedController]; 42 | self.supportImageFileType = @[@"jpg",@"png",@"bmp",@"jpeg",@"gif"]; 43 | self.supportMediaFiletype = @[@"mp3",@"wav",@"flv",@"mp4",@"flac"]; 44 | self.supportDocumentFiletype = @[@"doc",@"xls",@"pdf",@"ppt",@"pages",@"keynots",@"numbers",@"docx"]; 45 | 46 | } 47 | #pragma mark - EADelegate 48 | - (void)_accessoryDidConnect:(NSNotification *)notification{ 49 | 50 | EAAccessory *connectedAccessory = [[notification userInfo] objectForKey:EAAccessoryKey]; 51 | 52 | [self._eaSessionController setupControllerForAccessory:connectedAccessory withProtocolString:[connectedAccessory.protocolStrings objectAtIndex:0]]; 53 | [self._eaSessionController openSession] ; 54 | if (self._eaSessionController._session!=nil) { 55 | readcount++; 56 | read_10(0, 1); 57 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 58 | } 59 | 60 | } 61 | - (void)_accessoryDidDisconnect:(NSNotification *)notification 62 | { 63 | [self.backArray removeAllObjects]; 64 | readcount = 0; 65 | [self.system.finalArray removeAllObjects]; 66 | [self.system.countArr removeAllObjects]; 67 | [self.table reloadData]; 68 | } 69 | 70 | - (void)_sessionDataReceived:(NSNotification *)notification{ 71 | EADSessionController *sessionController = (EADSessionController *)[notification object]; 72 | NSInteger bytesAvailable = 0; 73 | while ((bytesAvailable = [sessionController readBytesAvailable]) > 0) { 74 | data = [sessionController readData:bytesAvailable]; 75 | if (data) { 76 | _totalBytesRead += bytesAvailable; 77 | 78 | } 79 | 80 | } 81 | switch (readcount) { 82 | case 1:{ 83 | [self.system clearsTRTodata:data]; 84 | readcount++; 85 | [self.system getMBRNumberTodata:data]; 86 | read_10(SD_offset.Logic, 1); 87 | [__eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 88 | break; 89 | } 90 | 91 | case 2:{ 92 | [self.system clearsTRTodata:data]; 93 | readcount++; 94 | [self.system translateFAT32datafordata:data]; 95 | read_10(SD_offset.Cluster+SD_offset.Logic, 32); 96 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 97 | NSNumber *mem = [NSNumber numberWithUnsignedInt:SD_offset.Cluster+SD_offset.Logic]; 98 | [self.backArray insertObject:mem atIndex:touchcount]; 99 | self.system.filesystemType = @"fat32"; 100 | break; 101 | } 102 | case 3:{ 103 | [self.system clearsTRTodata:data]; 104 | [self.system getFileDir]; 105 | self.finalArray = self.system.finalArray; 106 | nextCluster = [self.system seekFreeCluster]; 107 | // [self sendFiledata]; 108 | readcount = 8; 109 | read_10((uint32_t)nextCluster+1+8192, 1); 110 | NSLog(@"%llu",nextCluster+1); 111 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 112 | [self.table reloadData]; 113 | break; 114 | } 115 | case 4:{ 116 | 117 | [self.system clearsTRTodata:data]; 118 | [self.finalArray removeAllObjects]; 119 | [self.system.countArr removeAllObjects]; 120 | [self.system getFileDir]; 121 | [self.table reloadData]; 122 | break; 123 | } 124 | case 5:{ 125 | [self.system clearsTRTodata:data]; 126 | [self.finalArray removeAllObjects]; 127 | [self.system.countArr removeAllObjects]; 128 | [self.system getFileDir]; 129 | [self.table reloadData]; 130 | break; 131 | } 132 | case 6:{ 133 | 134 | [self.system clearsTRTodata:data]; 135 | Byte file[SD_para.BytesPerSector]; 136 | for (int i = 0; i<2*SD_para.BytesPerSector; i+=2) { 137 | NSString *sa3 = [self.system.sa2 substringWithRange:NSMakeRange(i, 2)]; 138 | uint64_t mac = strtoul([sa3 UTF8String], 0, 16); 139 | file[i/2] = mac; 140 | } 141 | [self read10KtoFile:file]; 142 | memset(file, 0, sizeof(file)); 143 | [self sendread10]; 144 | break; 145 | 146 | break;} 147 | case 7:{ 148 | // NSString *p = [data.description substringWithRange:NSMakeRange(data.description.length-2, 1)]; 149 | // if ([p isEqualToString:@"0"]) { 150 | // readcount = 8; 151 | // write10((uint32_t)nextCluster+1+SD_offset.Logic+SD_offset.Logic, 1); 152 | // [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 153 | // Byte p[512]; 154 | // memset(p, 24, 512); 155 | // [self._eaSessionController writeData:[NSData dataWithBytes:p length:512]]; 156 | // NSLog(@"执行"); 157 | // break; 158 | // } 159 | break; 160 | } 161 | case 8:{ 162 | NSLog(@"%@",data.description); 163 | 164 | }case 9:{ 165 | } 166 | 167 | default: 168 | break; 169 | } 170 | 171 | 172 | } 173 | #pragma mark - 写入文件接口 174 | -(void )sendFiledata{ 175 | readcount = 7; 176 | write10((uint32_t)nextCluster+1+8192, 1); 177 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 178 | NSLog(@"%@",[NSData dataWithBytes:&cbwCmd length:32]); 179 | 180 | Byte p[512] = {0x34,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x78,0x74}; 181 | 182 | [self._eaSessionController writeData:[NSData dataWithBytes:p length:512]]; 183 | 184 | } 185 | 186 | #pragma mark - 文件读取 187 | -(void)sendread10{ 188 | readcount = 6; 189 | read_10(fielsec+reada+SD_offset.Logic, 1); 190 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 191 | reada++; 192 | } 193 | 194 | -(void)getFileName{ 195 | 196 | 197 | } 198 | 199 | -(void)read10KtoFile:(Byte *)file{ 200 | 201 | 202 | } 203 | 204 | 205 | #pragma mark - TableViewDelegate 206 | -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 207 | return 1; 208 | 209 | } 210 | 211 | 212 | -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 213 | return _system.countArr.count; 214 | 215 | } 216 | -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 217 | Filelist *cell = [tableView dequeueReusableCellWithIdentifier:@"123"]; 218 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 219 | cell.backgroundColor = [UIColor clearColor]; 220 | if (cell==nil) { 221 | cell = [[Filelist alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"123"]; 222 | } 223 | Boolean p =[[self.finalArray[indexPath.row]filetype]isEqualToString:@"folder"]; 224 | cell.filenamelabel.text = [self.finalArray[indexPath.row]longname]; 225 | 226 | if ([cell.filenamelabel.text isEqualToString:@"empty"]) { 227 | 228 | NSString *p = [self.finalArray[indexPath.row]name]; 229 | NSString *p1 = [self.finalArray[indexPath.row]filetype]; 230 | cell.filenamelabel.text = [p stringByAppendingString:[NSString stringWithFormat:@".%@",p1]]; 231 | } 232 | if (p==true) 233 | { 234 | cell.filetypeimg.image = [UIImage imageNamed:@"filesystem_icon_folder"]; 235 | cell.filenamelabel.text = [self.finalArray[indexPath.row]longname]; 236 | if ([cell.filenamelabel.text isEqualToString:@"empty"]) { 237 | 238 | NSString *p = [self.finalArray[indexPath.row]name]; 239 | cell.filenamelabel.text = p; 240 | } 241 | 242 | }else{ 243 | 244 | NSString *tyepList = [self.finalArray[indexPath.row] filetype]; 245 | Boolean media = [self.supportMediaFiletype containsObject:tyepList]; 246 | Boolean doc = [self.supportDocumentFiletype containsObject:tyepList]; 247 | Boolean image = [self.supportImageFileType containsObject:tyepList]; 248 | 249 | if (media==true) { 250 | 251 | cell.filetypeimg.image = [UIImage imageNamed:@"filesystem_icon_music"]; 252 | 253 | }else if (doc==true){ 254 | cell.filetypeimg.image = [UIImage imageNamed:@"filesystem_icon_text"]; 255 | 256 | }else if(image==true){ 257 | cell.filetypeimg.image = [UIImage imageNamed:@"filesystem_icon_photo"]; 258 | }else{ 259 | cell.filetypeimg.image = [UIImage imageNamed:@"filesystem_icon_default"]; 260 | }} 261 | return cell; 262 | 263 | 264 | } 265 | 266 | 267 | 268 | #pragma mark - 阅读上一级目录 269 | -(void)ReadlastDir{ 270 | 271 | readcount = 5; 272 | NSNumber * p = self.backArray[touchcount-1]; 273 | int p1 = p.intValue; 274 | read_10(p1, 32); 275 | [self.backArray removeLastObject]; 276 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 277 | touchcount--; 278 | } 279 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 280 | 281 | NSString * p =[self.finalArray[indexPath.row] filetype]; 282 | Boolean b = [p isEqualToString:@"folder"]; 283 | _currentname = [self.finalArray[indexPath.row]longname]; 284 | if ([_currentname isEqualToString:@"empty" 285 | ]) { 286 | _currentname = [self.finalArray[indexPath.row]name]; 287 | } 288 | 289 | if (b==true) { 290 | touchcount++; 291 | 292 | readcount = 4; 293 | NSString *name= [self.finalArray[indexPath.row]longname]; 294 | if ([name isEqualToString:@"empty"]) { 295 | name = [self.finalArray[indexPath.row]name]; 296 | 297 | } 298 | fielsec = [self.finalArray[indexPath.row]filesector]; 299 | read_10(fielsec+SD_offset.Logic, 32); 300 | NSNumber *next = [NSNumber numberWithUnsignedInt:fielsec+SD_offset.Logic]; 301 | [self.backArray insertObject:next atIndex:touchcount]; 302 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 303 | 304 | }else{ 305 | fielsec = [self.finalArray[indexPath.row]filesector]; 306 | uintmax_t p1 = [self.finalArray[indexPath.row]filesize]; 307 | currentsize = p1; 308 | __currenttype = p; 309 | NSString *tyepList = [self.finalArray[indexPath.row] filetype]; 310 | Boolean media = [self.supportMediaFiletype containsObject:tyepList]; 311 | Boolean doc = [self.supportDocumentFiletype containsObject:tyepList]; 312 | Boolean image = [self.supportImageFileType containsObject:tyepList]; 313 | 314 | if (media==true) { 315 | filetpe = 1; 316 | 317 | }else if (doc==true){ 318 | 319 | filetpe = 2; 320 | 321 | }else if(image==true){ 322 | filetpe = 3; 323 | 324 | 325 | }else if([tyepList isEqualToString:@"txt"]){ 326 | 327 | filetpe = 4; 328 | } 329 | readcount = 6; 330 | uintmax_t p3 = p1/256; 331 | if (currentsize%256!=0) { 332 | resttime = p3+1; 333 | lesstime = currentsize%256; 334 | read_10(SD_offset.Logic+fielsec, 1); 335 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 336 | reada++; 337 | }else{ 338 | resttime = p3; 339 | lesstime = 0; 340 | read_10(SD_offset.Logic+fielsec, 1); 341 | [self._eaSessionController writeData:[NSData dataWithBytes:&cbwCmd length:32]]; 342 | reada++; 343 | 344 | }}} 345 | 346 | 347 | - (void)didReceiveMemoryWarning { 348 | [super didReceiveMemoryWarning]; 349 | // Dispose of any resources that can be recreated. 350 | } 351 | 352 | @end 353 | -------------------------------------------------------------------------------- /UDisk/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UDisk 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /UDiskTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /UDiskTests/UDiskTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // UDiskTests.m 3 | // UDiskTests 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UDiskTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation UDiskTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /UDiskUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /UDiskUITests/UDiskUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // UDiskUITests.m 3 | // UDiskUITests 4 | // 5 | // Created by shiki on 16/8/9. 6 | // Copyright © 2016年 两仪式. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UDiskUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation UDiskUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------