PlayerViewController+upLoadFile.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. //
  2. // PlayerViewController+upLoadFile.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2024/1/3.
  6. //
  7. #import "PlayerViewController+upLoadFile.h"
  8. @implementation PlayerViewController (upLoadFile)
  9. #pragma mark 监听文件开始的的通知
  10. - (void)beginGotoUploadFileFun:(NSNotification *)notification
  11. {
  12. self.isSuspendUploadType = NO;
  13. uploadFileDataModel *uploadFileDataMod = [notification object];
  14. //HLog(@"%@",uploadFileDataMod);
  15. // if(self.curUploadFileDataMod && uploadFileDataMod.bg_id.integerValue == self.curUploadFileDataMod.bg_id.integerValue){
  16. // return;
  17. // }
  18. self.curUploadFileDataMod = uploadFileDataMod;
  19. if(![uploadFileDataMod isKindOfClass:[uploadFileDataMod class]]){
  20. HLog(@"上传的文件类型不对");
  21. return;
  22. }
  23. [self ApplyUploadFileFun];
  24. }
  25. - (void)applyUploadFileServiceResponseFun:(NSDictionary *)dataDict
  26. {
  27. if([dataDict isKindOfClass:[NSDictionary class]]){
  28. if ([[dataDict allKeys] containsObject:@"data"]) {
  29. NSDictionary *data = dataDict[@"data"];
  30. if ([[data allKeys] containsObject:@"status"]) {
  31. NSString *status = [data objectForKey:@"status"];
  32. if(![status isKindOfClass:[NSString class]]){
  33. status = [[NSString alloc] initWithFormat:@"%@",status];
  34. }
  35. //if(1)
  36. if([status isEqualToString:@"1"])
  37. {
  38. //[self tryAgainApplyUploadFun];
  39. [self clearUploadFileDataFun];
  40. [[uploadFileManager shareInstance] uploadFileFailFun];
  41. }else if ([status isEqualToString:@"0"]){
  42. if ([[data allKeys] containsObject:@"taskUid"]) {
  43. NSString *taskUid = data[@"taskUid"];
  44. if(![status isKindOfClass:[NSString class]]){
  45. taskUid = [[NSString alloc] initWithFormat:@"%@",taskUid];
  46. }
  47. if(taskUid && [taskUid isEqualToString:self.taskUid]){
  48. NSNumber * fileLengthNum = @0;
  49. if ([[data allKeys] containsObject:@"fileLength"])
  50. {
  51. fileLengthNum = data[@"fileLength"];
  52. }
  53. // [[uploadFileManager shareInstance] changeUploadFileState:uploadStateUploading withDidUploadBytes:[fileLengthNum integerValue] withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
  54. //
  55. // }];
  56. if([fileLengthNum integerValue] == self.curUploadFileDataMod.totalBytes && self.curUploadFileDataMod.totalBytes != 0){
  57. self.taskUid = nil;
  58. self.curUploadFileDataMod.curUploadStateType = uploadStateDone;
  59. NSMutableArray *delArr = [NSMutableArray new];
  60. [delArr addObject:self.curUploadFileDataMod];
  61. [[uploadFileManager shareInstance] deleteUploadFileRecordBy:delArr withDelCache:NO complete:^(BOOL isSuccess) {
  62. if (isSuccess) {
  63. }
  64. }];
  65. mainBlock(^{
  66. [[iToast makeText:NSLocalizedString(@"File_upload_file_already_exists",nil)] show];
  67. });
  68. HLog(@"hxd already 上传文件已存在")
  69. return;
  70. }
  71. self.curUploadPostion = [fileLengthNum longValue];
  72. if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeImage){
  73. [self beginGotoUploadImageFun:fileLengthNum];
  74. }
  75. else{
  76. [self beginGotoUploadVidelFun:fileLengthNum];
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. else{
  84. //异常
  85. [self tryAgainApplyUploadFun];
  86. }
  87. }
  88. else{
  89. //异常
  90. [self tryAgainApplyUploadFun];
  91. }
  92. }
  93. #pragma mark 图片上传
  94. -(void)beginGotoUploadImageFun:(NSNumber*)fileLengthNum{
  95. self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
  96. if(!self.cutFileDataArr || self.cutFileDataArr.count == 0){
  97. [self clearUploadFileDataFun];
  98. [[uploadFileManager shareInstance] uploadFileFailFun];
  99. HLog(@"hxd fail 上传任务异常终止")
  100. return;
  101. }
  102. //答复的taskUid 跟申请的一致 开发发送内容
  103. [self upLoadFileFun];
  104. }
  105. #pragma mark 视频上传
  106. //每次从文件重新切一片 传一片
  107. -(void)beginGotoUploadVidelFun:(NSNumber*)fileLengthNum{
  108. NSData *data = [self cutVideoFileFunAtIndex:fileLengthNum.longLongValue];
  109. HLog(@"data leng:%ld",[data length]);
  110. if([data length] == 0){
  111. if(self.curUploadFileDataMod.curUploadStateType == uploadStateDone){
  112. [[uploadFileManager shareInstance] uploadFileDoneFun];
  113. }
  114. else{
  115. [[uploadFileManager shareInstance] uploadFileFailFun];
  116. }
  117. [self clearUploadFileDataFun];
  118. return;
  119. }
  120. self.AllFileData = data;
  121. self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:0];
  122. self.indexOfUploadFlie = 0;
  123. //return;
  124. // NSString*videoPathStr = [cachesFileManager getFilePathWithName:self.curUploadFileDataMod.filename type:uploadFileTypeVideo];
  125. // self.AllFileData = [NSData dataWithContentsOfFile:videoPathStr];
  126. // self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData withDidUpLoadSize:[fileLengthNum integerValue]];
  127. if(!self.cutFileDataArr ||self.cutFileDataArr.count ==0){
  128. [self clearUploadFileDataFun];
  129. [[uploadFileManager shareInstance] uploadFileFailFun];
  130. HLog(@"hxd fail 上传任务异常终止")
  131. return;
  132. }
  133. //答复的taskUid 跟申请的一致 开发发送内容
  134. [self upLoadFileFun];
  135. }
  136. #pragma mark 分段读视频文件
  137. -(NSData*)cutVideoFileFunAtIndex:(NSUInteger)dataIndex{
  138. NSString *filePath = [cachesFileManager getFilePathWithName:self.curUploadFileDataMod.filename type:uploadFileTypeVideo]; // 文件路径
  139. NSFileManager *manager0 = [NSFileManager defaultManager];
  140. if(![manager0 fileExistsAtPath:filePath]) {
  141. return [NSData new];
  142. }
  143. NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; // 创建文件句柄
  144. // 设置分段读取的大小,这里以每次读取1KB为例
  145. //const NSUInteger chunkSize = 50 * 1024 *1024;
  146. const NSUInteger chunkSize = cutVideoPieceSzie;//5 * 1024 *1024;
  147. NSMutableData *data = [NSMutableData data];
  148. if (fileHandle) {
  149. long long endOfFile = [fileHandle seekToEndOfFile];
  150. if(self.curUploadFileDataMod.totalBytes == 0
  151. || self.curUploadFileDataMod.totalBytes < endOfFile){//异常处理
  152. self.curUploadFileDataMod.totalBytes = endOfFile;
  153. }
  154. //异常处理
  155. if(endOfFile == dataIndex){
  156. self.curUploadFileDataMod.totalBytes = endOfFile;
  157. self.curUploadFileDataMod.didUploadBytes = endOfFile;
  158. self.curUploadFileDataMod.curUploadStateType = uploadStateDone;
  159. [fileHandle closeFile];
  160. return data;
  161. }
  162. if (endOfFile >= chunkSize) {
  163. // 读取文件的分段数据到某个位置
  164. [fileHandle seekToFileOffset:dataIndex];
  165. // 读取文件的分段数据
  166. NSData* chunk = [fileHandle readDataOfLength:chunkSize];
  167. if (chunk) {
  168. [data appendData:chunk];
  169. }
  170. }
  171. else{
  172. // 读取文件的分段数据到某个位置
  173. [fileHandle seekToFileOffset:dataIndex];
  174. [data appendData:[fileHandle readDataToEndOfFile]];
  175. }
  176. // 在这里可以对文件内容进行处理
  177. // ...
  178. // 关闭文件句柄
  179. [fileHandle closeFile];
  180. }
  181. return data;
  182. }
  183. - (void)upLoadFileFunServiceResponseFun:(NSDictionary *)dataDict
  184. {
  185. //{"type":"uploadFileRandomRet","data":{"progress":"9\/10","filePath":"/sdcard/Download/IMG_0036.JPG","status":"0","msg":"success"}}
  186. if([dataDict isKindOfClass:[NSDictionary class]]){
  187. if ([[dataDict allKeys] containsObject:@"data"]) {
  188. NSDictionary *data = dataDict[@"data"];
  189. if ([[data allKeys] containsObject:@"status"]) {
  190. NSString *status = [data objectForKey:@"status"];
  191. if(![status isKindOfClass:[NSString class]]){
  192. status = [[NSString alloc] initWithFormat:@"%@",status];
  193. }
  194. if ([status isEqualToString:@"0"]){
  195. NSNumber * fileLengthNum = @0;
  196. if ([[data allKeys] containsObject:@"fileLenth"])
  197. {
  198. fileLengthNum = data[@"fileLenth"];
  199. }
  200. if (fileLengthNum && fileLengthNum.longLongValue >= self.curUploadFileDataMod.totalBytes)
  201. {//
  202. //告诉代理 完成了
  203. NSString *commandStr = [RCCommandHelp uploadOrBackupsDoneBy:self.taskUid withFileName:self.fileName withType:YES];
  204. [self.commandChannelManager rc_sendData:commandStr];
  205. [self clearUploadFileDataFun];
  206. [[uploadFileManager shareInstance] uploadFileDoneFun];
  207. }
  208. else{
  209. //异常处理
  210. if([fileLengthNum longValue] - self.curUploadPostion > EachPieceSzie){
  211. HLog(@"发现上传后返回的长度 出错");
  212. if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeVideo)
  213. {//清除已经取出来的数据 后面会根据fileLengthNum 重新拿数据
  214. self.cutFileDataArr = [NSMutableArray new];
  215. }
  216. else{
  217. NSInteger curIndex = [fileLengthNum longValue] % EachPieceSzie;
  218. //把当前的上传位置指定已经上传的前一片,后续++
  219. self.indexOfUploadFlie = curIndex -1;
  220. }
  221. }
  222. self.curUploadPostion = [fileLengthNum longValue];
  223. [self handleUploadingFun:fileLengthNum];
  224. }
  225. }
  226. else if ([status isEqualToString:@"2"]) {
  227. [self clearUploadFileDataFun];
  228. [[uploadFileManager shareInstance] suspendUploadFileFun:YES];
  229. NSString *tipStr = NSLocalizedString(@"disk_not_find_tip",nil);
  230. mainBlock(^{
  231. [[iToast makeText:tipStr] show];
  232. });
  233. }
  234. else if ([status isEqualToString:@"5"]) {
  235. [self clearUploadFileDataFun];
  236. [[uploadFileManager shareInstance] suspendUploadFileFun:YES];
  237. NSString *tipStr = NSLocalizedString(@"disk_space_not_tip",nil);
  238. mainBlock(^{
  239. [[iToast makeText:tipStr] show];
  240. });
  241. }
  242. else //if ([status isEqualToString:@"1"])
  243. {
  244. //[self tryAgainApplyUploadFun];
  245. [self clearUploadFileDataFun];
  246. [[uploadFileManager shareInstance] uploadFileFailFun];
  247. }
  248. }
  249. }
  250. else{
  251. //异常
  252. [self tryAgainApplyUploadFun];
  253. }
  254. }
  255. else{
  256. //异常
  257. [self tryAgainApplyUploadFun];
  258. }
  259. }
  260. #pragma mark 申请上传文件
  261. - (void)ApplyUploadFileFun
  262. {
  263. //if(!self.taskUid){
  264. self.taskUid = [iTools getTaskUidStr];
  265. if([self.taskUid isEqualToString:self.downloadFileTaskUid]
  266. ||[self.taskUid isEqualToString:self.backupsTaskUid]
  267. ||[self.taskUid isEqualToString:self.downloadThumbnailTaskUid])
  268. {//重新生成taskUid
  269. [self ApplyUploadFileFun];
  270. return;
  271. }
  272. self.fileName = self.curUploadFileDataMod.filename;
  273. if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeVideo){
  274. //self.AllFileData = self.curUploadFileDataMod.videoData;
  275. }
  276. else{
  277. self.AllFileData = self.curUploadFileDataMod.imageData;
  278. }
  279. self.indexOfUploadFlie = 0;
  280. //HLog(@"%@ %@",self.taskUid,self.fileName);
  281. //self.cutFileDataArr = [self fileCutPartsBy:self.AllFileData];
  282. //}
  283. NSString * commandStr = [RCCommandHelp applyForUploadFileBy:self.taskUid filePath:self.fileName];
  284. [self.commandChannelManager rc_sendData:commandStr];
  285. }
  286. #pragma mark 遇到异常时 重新上传
  287. - (void)tryAgainApplyUploadFun
  288. {
  289. self.taskUid = nil;
  290. [self ApplyUploadFileFun];
  291. }
  292. #pragma mark 处理上传过程
  293. - (void)handleUploadingFun:(NSNumber*)fileLengthNum
  294. {
  295. //异常处理
  296. if(fileLengthNum.longValue < 0)
  297. {
  298. return;
  299. }
  300. BOOL isCanUseCellular = [HWDataManager getBoolWithKey:stringKeyAddSn(Const_file_Transfe_canUse_Cellular_all)];
  301. if(!isCanUseCellular){//不允许流量备份
  302. //
  303. if([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN){
  304. self.isSuspendUploadType = YES;
  305. }
  306. }
  307. if(self.isSuspendUploadType){
  308. //暂停
  309. self.taskUid = nil;
  310. //NSInteger didUploadSize = (self.indexOfUploadFlie+1) * (self.cutFileEachPieceSzie);
  311. NSInteger didUploadSize = fileLengthNum.longLongValue;
  312. [[uploadFileManager shareInstance] changeUploadFileState:uploadStateSuspend withDidUploadBytes:didUploadSize withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
  313. }];
  314. return;
  315. }
  316. if(self.cutFileDataArr.count > 0
  317. && self.indexOfUploadFlie < (self.cutFileDataArr.count -1)) {
  318. //NSInteger didUploadSize = (self.indexOfUploadFlie+1) * (self.cutFileEachPieceSzie);
  319. NSInteger didUploadSize = fileLengthNum.longLongValue;
  320. [[uploadFileManager shareInstance] changeUploadFileState:uploadStateUploading withDidUploadBytes:didUploadSize withModel:self.curUploadFileDataMod complete:^(BOOL isSuccess) {
  321. }];
  322. self.indexOfUploadFlie ++;
  323. [self upLoadFileFun];
  324. }
  325. else if(self.curUploadFileDataMod.curUploadFileType == uploadFileTypeVideo && fileLengthNum && fileLengthNum.longLongValue < self.curUploadFileDataMod.totalBytes){
  326. //视频做了二次切割 不一定上传完了
  327. HLog(@"视频上传传完一片 再来一片");
  328. [self beginGotoUploadVidelFun:fileLengthNum];
  329. }
  330. else{
  331. HLog(@"上传完成");
  332. //告诉代理 完成了
  333. NSString *commandStr = [RCCommandHelp uploadOrBackupsDoneBy:self.taskUid withFileName:self.fileName withType:YES];
  334. [self.commandChannelManager rc_sendData:commandStr];
  335. [self clearUploadFileDataFun];
  336. [[uploadFileManager shareInstance] uploadFileDoneFun];
  337. }
  338. }
  339. -(void)clearUploadFileDataFun{
  340. //上传数据清空
  341. self.taskUid = nil;
  342. self.fileName = nil;
  343. self.AllFileData = nil;
  344. self.indexOfUploadFlie = 0;
  345. self.cutFileDataArr = nil;
  346. self.curUploadFileDataMod = nil;
  347. self.isSuspendUploadType = NO;
  348. }
  349. - (Byte)getBCC:(NSData *)data {
  350. Byte bcc = 0;
  351. unsigned char *bytes = (unsigned char *)[data bytes];
  352. for (int i = 0; i < [data length]; i++) {
  353. bcc = (Byte)(bcc ^ bytes[i]);
  354. }
  355. return bcc;
  356. }
  357. #pragma mark 文件切片
  358. -(NSMutableArray *)fileCutPartsBy:(NSData*)curData withDidUpLoadSize:(NSInteger)didLoadSize{
  359. NSData * data = curData;
  360. NSUInteger allLength = data.length;
  361. NSUInteger subs = EachPieceSzie;//1*1024*1024;//4096;//要切片的大小,我这里设置的是4096字节
  362. //NSUInteger subs = 31*1024;//4096;//要切片的大小,内存没有暴增
  363. self.cutFileEachPieceSzie = subs;
  364. NSInteger index = 0;//起始位置
  365. if(didLoadSize != 0){
  366. if (didLoadSize % subs != 0){
  367. //出错了
  368. return nil;
  369. }
  370. else{
  371. // index = didLoadSize/subs;
  372. // allLength = allLength - didLoadSize;
  373. self.indexOfUploadFlie = didLoadSize/subs;
  374. }
  375. }
  376. NSMutableArray *dataArray =[NSMutableArray new];
  377. do {
  378. //@autoreleasepool {
  379. if (allLength>subs) {
  380. NSRange range =NSMakeRange(index*subs, subs);
  381. index++;
  382. //NSLog(@"%@",NSStringFromRange(range));
  383. [dataArray addObject:[data subdataWithRange:range]];
  384. allLength = allLength - subs;
  385. }else{
  386. NSRange range = NSMakeRange(index*subs, allLength);
  387. //NSLog(@"%@",NSStringFromRange(range));
  388. NSData *subdata = [data subdataWithRange:range];
  389. if(subdata){
  390. [dataArray addObject:subdata];
  391. }
  392. allLength = 0;
  393. }
  394. //}
  395. } while (allLength>0);
  396. HLog(@"dataArray leng:%ld",dataArray.count);//最后得到切片的结果,数组里面是NSData对象
  397. return dataArray;
  398. }
  399. // int转NSData
  400. - (NSData *)int2Data:(int)i{
  401. Byte b0 = i & 0xff;
  402. Byte b1 = i >> 8 & 0xff;
  403. Byte b2 = i >> 16 & 0xff;
  404. Byte b3 = i >> 24 & 0xff;
  405. // 有大小端模式问题?
  406. //Byte result[] = {b0, b1, b2, b3};
  407. Byte result[] = {b3, b2, b1, b0};
  408. return [NSData dataWithBytes:result length:sizeof(result)];
  409. }
  410. // long转NSData
  411. - (NSData *)long2Data:(long)i{
  412. Byte b0 = i & 0xff;
  413. Byte b1 = i >> 8 & 0xff;
  414. Byte b2 = i >> 16 & 0xff;
  415. Byte b3 = i >> 24 & 0xff;
  416. Byte b4 = i >> 32 & 0xff;
  417. Byte b5 = i >> 40 & 0xff;
  418. Byte b6 = i >> 48 & 0xff;
  419. Byte b7 = i >> 56 & 0xff;
  420. // 有大小端模式问题?
  421. //Byte result[] = {b0, b1, b2, b3};
  422. //Byte result[] = {b3, b2, b1, b0};
  423. Byte result[] = {b7, b6, b5,b4,b3, b2, b1, b0};
  424. return [NSData dataWithBytes:result length:sizeof(result)];
  425. }
  426. // short转NSData
  427. - (NSData *)short2Data:(short)i{
  428. Byte b0 = i & 0xff;
  429. Byte b1 = i >> 8 & 0xff;
  430. // 有大小端模式问题?
  431. //Byte result[] = {b0, b1, b2, b3};
  432. Byte result[] = { b1, b0};
  433. return [NSData dataWithBytes:result length:sizeof(result)];
  434. }
  435. #pragma mark 可以发送文件了
  436. /*
  437. 文件数据字节流byte[]
  438. 格式1:下载日志文件压缩包
  439. |head|msgType|taskId| datalen | curNum | totalNum| data |bcc校验|end|
  440. 长度: 1 1 6 (curNum+totalNum+data) 4 4 datalen- 8 1 1
  441. 0x68 0x0e 0x16
  442. bcc校验从第1位 也就是从msgType起 到 校验位前(不包含校验位)数据作bcc校验
  443. */
  444. - (void)upLoadFileFun
  445. {
  446. //HLog(@"上传文件%ld/%ld",self.indexOfUploadFlie +1,self.cutFileDataArr.count);
  447. if(self.cutFileDataArr.count <= self.indexOfUploadFlie)
  448. {
  449. return;
  450. }
  451. //data
  452. NSData *curData = self.cutFileDataArr[self.indexOfUploadFlie];
  453. //HLog(@"headData:%@",curData);
  454. //head
  455. unsigned char headNum = 104;
  456. NSData *headData = [NSMutableData dataWithBytes:&headNum length:sizeof(headNum)];
  457. //HLog(@"headData:%@",headData);
  458. //msgType
  459. //unsigned char msgType = 12;
  460. //unsigned char msgType = 15;
  461. unsigned char msgType = 20;
  462. NSData *msgTypeData = [NSMutableData dataWithBytes:&msgType length:sizeof(msgType)];
  463. //HLog(@"msgTypeData:%@",msgTypeData);
  464. //taskId
  465. NSData *taskIdData = [self.taskUid dataUsingEncoding:NSUTF8StringEncoding];
  466. //HLog(@"taskIdData:%@",taskIdData);
  467. //datalen
  468. //int datalenNum = int([curData length] +(4+4));
  469. int datalenNum = [curData length] + (4+4);
  470. //NSData *datalenData = [NSData dataWithBytes:&datalenNum length:sizeof(datalenNum)];
  471. NSData *datalenData = [self int2Data:datalenNum];
  472. //HLog(@"datalenData %@",datalenData);
  473. //curNum
  474. int curNum = (int)self.indexOfUploadFlie ;//+ 1;
  475. //NSData *curNumData = [NSData dataWithBytes:&curNum length:sizeof(curNum)];
  476. NSData * curNumData = [self int2Data:curNum];
  477. //HLog(@"curNumData:%@",curNumData);
  478. //totalNum
  479. int totalNum = (int)self.cutFileDataArr.count;
  480. //NSData *totalNumData = [NSData dataWithBytes:&totalNum length:sizeof(totalNum)];
  481. NSData * totalNumData = [self int2Data:totalNum];
  482. //HLog(@"totalNumData:%@",totalNumData);
  483. long Postion = self.curUploadPostion;
  484. //long Postion = 100000000000;
  485. NSData * PostionData = [self long2Data:Postion];
  486. HLog(@"PostionData:%@",PostionData);
  487. NSMutableData *checkBCCData = [NSMutableData new];
  488. [checkBCCData appendData:msgTypeData];
  489. [checkBCCData appendData:taskIdData];
  490. [checkBCCData appendData:datalenData];
  491. [checkBCCData appendData:curNumData];
  492. [checkBCCData appendData:totalNumData];
  493. [checkBCCData appendData:PostionData];
  494. [checkBCCData appendData:curData];
  495. long length = [curData length];
  496. //HLog(@"curData length %d",length);
  497. Byte bccCheck = [self getBCC:checkBCCData];
  498. //HLog(@"bcc 000 %d",bccCheck);
  499. //bcc校验
  500. char bccNum = (char)bccCheck;
  501. NSData *bccData = [NSMutableData dataWithBytes:&bccNum length:sizeof(bccNum)];
  502. //HLog(@"%@",bccData);
  503. //end
  504. unsigned char endNum = 22;
  505. NSData *endData = [NSMutableData dataWithBytes:&endNum length:sizeof(endNum)];
  506. //HLog(@"%@",endData);
  507. NSMutableData *sendData = [NSMutableData new];
  508. [sendData appendData:headData];
  509. [sendData appendData:checkBCCData];
  510. [sendData appendData:bccData];
  511. [sendData appendData:endData];
  512. //HLog(@"sendData length %ld",[sendData length]);
  513. [self.commandChannelManager rc_sendData:sendData];
  514. //HLog(@"文件上传sendData %@",sendData);
  515. }
  516. - (void)suspendUploadFileFun:(NSNotification *)notification
  517. {
  518. self.isSuspendUploadType = YES;
  519. }
  520. @end