PlayerViewController+otherDelegate.mm 23 KB

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