瀏覽代碼

1.文件上传初步调通

huangxiaodong 1 年之前
父節點
當前提交
2719641eb1

+ 4 - 4
创维盒子/双子星云手机.xcodeproj/project.pbxproj

@@ -163,7 +163,7 @@
 		6B3F96352AD2A15A008E349E /* netWorkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3F96332AD2A15A008E349E /* netWorkManager.m */; };
 		6B3F963A2AD2AD0B008E349E /* newWorkInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B3F96392AD2AD0B008E349E /* newWorkInterface.h */; };
 		6B7B65582AD9227700BE8CB3 /* PlayerViewController+otherDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B7B65562AD9227700BE8CB3 /* PlayerViewController+otherDelegate.h */; };
-		6B7B65592AD9227700BE8CB3 /* PlayerViewController+otherDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B7B65572AD9227700BE8CB3 /* PlayerViewController+otherDelegate.m */; };
+		6B7B65592AD9227700BE8CB3 /* PlayerViewController+otherDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B7B65572AD9227700BE8CB3 /* PlayerViewController+otherDelegate.mm */; };
 		6BBB35D92AE7645200E4A59B /* RunInBackground.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 6BBB35D62AE7645200E4A59B /* RunInBackground.mp3 */; };
 		6BBB35DD2AE76AD800E4A59B /* AudioSessionObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BBB35DB2AE76AD800E4A59B /* AudioSessionObject.h */; };
 		6BBB35DE2AE76AD800E4A59B /* AudioSessionObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBB35DC2AE76AD800E4A59B /* AudioSessionObject.m */; };
@@ -506,7 +506,7 @@
 		6B3F96332AD2A15A008E349E /* netWorkManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = netWorkManager.m; sourceTree = "<group>"; };
 		6B3F96392AD2AD0B008E349E /* newWorkInterface.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = newWorkInterface.h; sourceTree = "<group>"; };
 		6B7B65562AD9227700BE8CB3 /* PlayerViewController+otherDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PlayerViewController+otherDelegate.h"; sourceTree = "<group>"; };
-		6B7B65572AD9227700BE8CB3 /* PlayerViewController+otherDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PlayerViewController+otherDelegate.m"; sourceTree = "<group>"; };
+		6B7B65572AD9227700BE8CB3 /* PlayerViewController+otherDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "PlayerViewController+otherDelegate.mm"; sourceTree = "<group>"; };
 		6B7B65612ADEAE0300BE8CB3 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
 		6B7B65622ADEAE0400BE8CB3 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/HWAddBookmarkViewController.strings"; sourceTree = "<group>"; };
 		6B7B65632ADEAE0400BE8CB3 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/HWBookmarkViewController.strings"; sourceTree = "<group>"; };
@@ -958,7 +958,7 @@
 				18FCE5462AD15E730020F623 /* PlayerViewController+AppDelegate.h */,
 				18FCE5472AD15E750020F623 /* PlayerViewController+AppDelegate.m */,
 				6B7B65562AD9227700BE8CB3 /* PlayerViewController+otherDelegate.h */,
-				6B7B65572AD9227700BE8CB3 /* PlayerViewController+otherDelegate.m */,
+				6B7B65572AD9227700BE8CB3 /* PlayerViewController+otherDelegate.mm */,
 				183AE6B12A8C9F5800B11CB0 /* View */,
 				183AE6A52A8C9EA900B11CB0 /* RCCommandHelp.h */,
 				183AE6A72A8C9EAA00B11CB0 /* RCCommandHelp.m */,
@@ -1949,7 +1949,7 @@
 				A003F6ED27D84D9C00715CBF /* HWWebViewController.m in Sources */,
 				A031DD6D27EC1FCD00909527 /* HWBookmarkListCell.m in Sources */,
 				183AE6052A89CE3C00B11CB0 /* JSONModelError.m in Sources */,
-				6B7B65592AD9227700BE8CB3 /* PlayerViewController+otherDelegate.m in Sources */,
+				6B7B65592AD9227700BE8CB3 /* PlayerViewController+otherDelegate.mm in Sources */,
 				A08A950027E9A4E400C544BB /* FMDatabaseQueue.m in Sources */,
 				6BF52CA72AD7D3BE00A617DB /* customLaunchView.m in Sources */,
 				A031DD7A27EC713A00909527 /* HWSetViewController.m in Sources */,

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+otherDelegate.h

@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)beginGotoUploadFileFun:(NSNotification *)notification;
 
 - (void)applyUploadFileServiceResponseFun:(NSDictionary *)dataDict;
-- (void)upLoadFileFun;
+- (void)upLoadFileFunServiceResponseFun:(NSDictionary *)dataDict;
 @end
 
 NS_ASSUME_NONNULL_END

+ 77 - 26
创维盒子/双子星云手机/CloudPlayer/PlayerViewController+otherDelegate.m

@@ -89,17 +89,38 @@
     }
 }
 
-- (int)getBCC:(NSData*)data
+- (void)upLoadFileFunServiceResponseFun:(NSDictionary *)dataDict
 {
-    int bcc = 0;
-    for (int i = 0; i < [data length]; i++) {
-        Byte buffer;
-        [data getBytes:&buffer range:NSMakeRange(i, 1)];
-        bcc = (UInt8) (bcc ^ buffer);
+    if (self.indexOfUploadFlie < self.cutFileDataArr.count - 1) {
+        self.indexOfUploadFlie ++;
+        [self upLoadFileFun];
+        
         
-        //HLog(@"bcc 222 %d",bcc);
     }
-    
+    else{
+        HLog(@"上传完成");
+    }
+}
+//- (int)getBCC:(NSData*)data
+//{
+//    int bcc = 0;
+//    for (int i = 0; i < [data length]; i++) {
+//        Byte buffer;
+//        [data getBytes:&buffer range:NSMakeRange(i, 1)];
+//        bcc = (UInt8) (bcc ^ buffer);
+//
+//        //HLog(@"bcc 222 %d",bcc);
+//    }
+//
+//    return bcc;
+//}
+
+- (Byte)getBCC:(NSData *)data {
+    Byte bcc = 0;
+    unsigned char *bytes = (unsigned char *)[data bytes];
+    for (int i = 0; i < [data length]; i++) {
+        bcc = (Byte)(bcc ^ bytes[i]);
+    }
     return bcc;
 }
 
@@ -120,7 +141,7 @@
     
     NSUInteger allLength = data.length;
     
-    NSUInteger subs = 1*1024;//4096;//要切片的大小,我这里设置的是4096字节
+    NSUInteger subs = 5*1024;//4096;//要切片的大小,我这里设置的是4096字节
     
     NSInteger index = 0;//起始位置
 
@@ -159,19 +180,43 @@
     return dataArray;
 }
 
+// int转NSData
+- (NSData *)int2Data:(int)i{
+    Byte b0 = i & 0xff;
+    Byte b1 = i >> 8 & 0xff;
+    Byte b2 = i >> 16 & 0xff;
+    Byte b3 = i >> 24 & 0xff;
+    // 有大小端模式问题?
+    //Byte result[] = {b0, b1, b2, b3};
+    Byte result[] = {b3, b2, b1, b0};
+    return [NSData dataWithBytes:result length:sizeof(result)];
+}
+
+// short转NSData
+- (NSData *)short2Data:(short)i{
+    Byte b0 = i & 0xff;
+    Byte b1 = i >> 8 & 0xff;
+    // 有大小端模式问题?
+    //Byte result[] = {b0, b1, b2, b3};
+    Byte result[] = { b1, b0};
+    return [NSData dataWithBytes:result length:sizeof(result)];
+}
+
 #pragma mark 可以发送文件了
 /*
 文件数据字节流byte[]
   格式1:下载日志文件压缩包
-       |head|msgType|taskId|datalen| curNum | totalNum|   data   |bcc校验|end|
-  长度:  1      1      6      4        2         2      datalen-4   1     1
+       |head|msgType|taskId|    datalen            | curNum | totalNum|   data   |bcc校验|end|
+  长度:  1      1      6 (curNum+totalNum+data)        4         4      datalen- 8   1     1
        0x68  0x0e                                                        0x16
     bcc校验从第1位 也就是从msgType起 到 校验位前(不包含校验位)数据作bcc校验
  */
 - (void)upLoadFileFun
 {
-    
-    //NSMutableArray *sendDataArray =[NSMutableArray new];
+    HLog(@"上传文件%ld/%ld",self.indexOfUploadFlie +1,self.cutFileDataArr.count);
+    //data
+    NSData *curData = self.cutFileDataArr[self.indexOfUploadFlie];
+    HLog(@"headData:%@",curData);
     
     //head
     unsigned char headNum = 104;
@@ -179,7 +224,8 @@
     HLog(@"headData:%@",headData);
     
     //msgType
-    unsigned char msgType = 12;
+    //unsigned char msgType = 12;
+    unsigned char msgType = 15;
     NSData *msgTypeData = [NSMutableData dataWithBytes:&msgType length:sizeof(msgType)];
     HLog(@"msgTypeData:%@",msgTypeData);
     
@@ -188,24 +234,25 @@
     HLog(@"taskIdData:%@",taskIdData);
     
     //datalen
-    int datalenNum = 1024;
-    NSData *datalenData = [NSData dataWithBytes:&datalenNum length:sizeof(datalenNum)];
+    int datalenNum = int([curData length] +(4+4));
+    //NSData *datalenData = [NSData dataWithBytes:&datalenNum length:sizeof(datalenNum)];
+    NSData *datalenData = [self int2Data:datalenNum];
     HLog(@"datalenData %@",datalenData);
     
+    
     //curNum
-    short curNum = (short)self.indexOfUploadFlie;
-    NSData *curNumData = [NSData dataWithBytes:&curNum length:sizeof(curNum)];
+    int curNum = (int)self.indexOfUploadFlie;
+    //NSData *curNumData = [NSData dataWithBytes:&curNum length:sizeof(curNum)];
+    NSData * curNumData = [self int2Data:curNum];
     HLog(@"curNumData:%@",curNumData);
     
     //totalNum
-    short totalNum = (short)self.cutFileDataArr.count;
-    NSData *totalNumData = [NSData dataWithBytes:&totalNum length:sizeof(totalNum)];
+    int totalNum = (int)self.cutFileDataArr.count;
+    //NSData *totalNumData = [NSData dataWithBytes:&totalNum length:sizeof(totalNum)];
+    NSData * totalNumData = [self int2Data:totalNum];
     HLog(@"totalNumData:%@",totalNumData);
     
-    //data
-    NSData *curData = self.cutFileDataArr[self.indexOfUploadFlie];
-    HLog(@"headData:%@",curData);
-    
+
     NSMutableData *checkBCCData = [NSMutableData new];
     [checkBCCData appendData:msgTypeData];
     [checkBCCData appendData:taskIdData];
@@ -214,11 +261,14 @@
     [checkBCCData appendData:totalNumData];
     [checkBCCData appendData:curData];
     
-    int bccCheck = [self getBCC:checkBCCData];
+    int length = [curData length];
+    HLog(@"curData length %d",length);
+    
+    Byte bccCheck = [self getBCC:checkBCCData];
     HLog(@"bcc 000 %d",bccCheck);
     
     //bcc校验
-    unsigned char bccNum = (unsigned char)bccCheck;
+    char bccNum = (char)bccCheck;
     NSData *bccData = [NSMutableData dataWithBytes:&bccNum length:sizeof(bccNum)];
     HLog(@"%@",bccData);
     
@@ -233,6 +283,7 @@
     [sendData appendData:bccData];
     [sendData appendData:endData];
     
+    HLog(@"sendData length %ld",[sendData length]);
     [self.commandChannelManager rc_sendData:sendData];
     HLog(@"文件上传sendData %@",sendData);
 }

+ 10 - 1
创维盒子/双子星云手机/CloudPlayer/PlayerViewController.mm

@@ -469,6 +469,11 @@ ComontAlretViewControllerDelegate>
                 });
             }
         } receive:^(id message, FLSocketCloudPhoneReceiveType type) {
+            
+            if([message isKindOfClass:[NSData class]] && [message length] == 0){
+                return;
+            }
+            
             HLog(@"webSocket指令通道接收消息:------------------\n%@",message);
             
             if([message isKindOfClass:[NSMutableString class]] || [message isKindOfClass:[NSString class]])
@@ -685,9 +690,13 @@ ComontAlretViewControllerDelegate>
                 [self->hidenTextField becomeFirstResponder];
 //                [self->hidenTextField setText:@"1234"];
                 [self->hidenTextField setEnabled:YES];
-            }else if ([messageType isEqualToString:@"FileReady"]){/*申请文件上传得到答复*/
+            }else if ([messageType isEqualToString:@"FileRandomReady"]){/*申请文件上传得到答复*/
                 [weakSelf applyUploadFileServiceResponseFun:dataDict];
             }
+            else if ([messageType isEqualToString:@"uploadFileRandomRet"]){/*文件上传得到答复*/
+                [weakSelf upLoadFileFunServiceResponseFun:dataDict];
+            }
+            
             
         } failure:^(NSError *error) {
             

+ 1 - 1
创维盒子/双子星云手机/CloudPlayer/RCCommandHelp.m

@@ -981,7 +981,7 @@
 
 + (NSString *)applyForUploadFileBy:(NSString*)taskUid filePath:(NSString *)filePath
 {
-    NSString *dataStr =[NSString stringWithFormat:@"{\"data\":{\"taskUid\":\"%@\",\"filePath\":\"%@\"},\"type\":\"uploadFile\"}",taskUid,filePath];
+    NSString *dataStr =[NSString stringWithFormat:@"{\"data\":{\"taskUid\":\"%@\",\"filePath\":\"%@\"},\"type\":\"uploadFileRandom\"}",taskUid,filePath];
     
     if (USENEWCONTROLLCOMMONDNO500)
     {

+ 1 - 1
创维盒子/双子星云手机/Helpers/iTools.h

@@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 + (UIWindow *)getKeyWindow;
 
-//ypp add 推流业务随机生成6位数的字符串
+//
 + (NSString *)getTaskUidStr;
 @end
 

+ 18 - 5
创维盒子/双子星云手机/Helpers/iTools.m

@@ -951,10 +951,23 @@ static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq
 }
 
 
-//ypp add 推流业务随机生成6位数的字符串
-+ (NSString *)getTaskUidStr {
-    int randomNumber = (int) arc4random_uniform(999999) + 100000;
-    NSString *strRandom = [NSString stringWithFormat:@"%d",randomNumber];
-    return strRandom;
++ (NSString *)getTaskUidStr
+{
+    NSInteger num = 6;
+    NSString *string = [[NSString alloc]init];
+    for (int i = 0; i < num; i++) {
+        int number = arc4random() % 36;
+        if (number < 10) {
+            int figure = arc4random() % 10;
+            NSString *tempString = [NSString stringWithFormat:@"%d", figure];
+            string = [string stringByAppendingString:tempString];
+        }else {
+            int figure = (arc4random() % 26) + 97;
+            char character = figure;
+            NSString *tempString = [NSString stringWithFormat:@"%c", character];
+            string = [string stringByAppendingString:tempString];
+        }
+    }
+    return string;
 }
 @end