//
//  RCCommandHelp.m
//  VclustersGemini
//
//  Created by APPLE on 2019/11/7.
//  Copyright © 2019 APPLE. All rights reserved.
//

#import "RCCommandHelp.h"
#import <objc/runtime.h>
#import "AppDelegate.h"

@implementation RCCommandHelp

#define USENEWCONTROLLCOMMONDNO500 YES

#pragma -mark- 设备控制指令拼接方式
+ (NSString *)commandAppending00StringWithSourStr:(NSString *)commondStr
{
    NSString *resultStr = @"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    resultStr = [resultStr substringToIndex:resultStr.length - commondStr.length];
    resultStr = [resultStr stringByAppendingString:commondStr];
//    KyoLog(@"\n %s = %lu",__func__,(unsigned long)resultStr.length);
    
    return resultStr;
}

+ (NSString *)commandAppendingHeadAndEndStrWithSourStr:(NSString *)commondStr
{
    NSString *resultStr = [@"#" stringByAppendingString:commondStr];
    resultStr = [resultStr stringByAppendingString:@"$"];
//    KyoLog(@"\n %s = %lu",__func__,(unsigned long)resultStr.length);
    
    return resultStr;
}

//#pragma -mark- 新设备控制指令
//+ (NSString *)mutTapCommand500DownWithTouches:(NSArray *)touches
//                                showImageView:(UIImageView *)showImageView
//                                        isLan:(BOOL)isLan
//{
//    /*比列换算*/
////    CGFloat ratex = (showImageView.frame.size.width > showImageView.frame.size.height)?(H_PHONE/showImageView.frame.size.width):(W_PHONE/showImageView.frame.size.width);
////    CGFloat ratey = (showImageView.frame.size.height > showImageView.frame.size.width)?(H_PHONE/showImageView.frame.size.height):(W_PHONE/showImageView.frame.size.height);
////    CGFloat ratex = W_PHONE/showImageView.frame.size.width;
////    CGFloat ratey = H_PHONE/showImageView.frame.size.height;
//
//    CGFloat ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
//    CGFloat ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
//
//
//    NSString *pointList = @"";
//    for (NSInteger nfori = 0;nfori < [touches count];nfori++)
//    {
//        UITouch *touch = [touches objectAtIndex:nfori];
//        CGPoint  lastPoint = [touch locationInView:showImageView];
//
//        /*换算后的坐标*/
////        CGFloat x = lastPoint.x*ratex;
////        CGFloat y = lastPoint.y*ratey;
//        CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
//        CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
//
//        pointList = [pointList stringByAppendingString:[NSString stringWithFormat:@"{\"action\":%ld,\"x\":\"%f\",\"y\":\"%f\"}",(long)nfori,x,y]];
//    }
//
//    pointList = [pointList stringByReplacingOccurrencesOfString:@"}{" withString:@"},{"];
//
//    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"fingerList\":[%@]},\"type\":\"morePortionDown\"}",pointList];
//
//    if (USENEWCONTROLLCOMMONDNO500)
//    {
////        dataStr = [CommondToStr commondAppendingHeadAndEndStrWithSourStr:dataStr];
//    }
//    else
//    {
//        dataStr = [RCCommandHelp commandAppending00StringWithSourStr:dataStr];
//    }
//
//    return dataStr;
//}
//
//+ (NSString *)mutTapCommand500UpWithTouches:(NSArray *)touches
//                              showImageView:(UIImageView *)showImageView
//                                      isLan:(BOOL)isLan
//{
//    /*比列换算*/
////    CGFloat ratex = (showImageView.frame.size.width > showImageView.frame.size.height)?(H_PHONE/showImageView.frame.size.width):(W_PHONE/showImageView.frame.size.width);
////    CGFloat ratey = (showImageView.frame.size.height > showImageView.frame.size.width)?(H_PHONE/showImageView.frame.size.height):(W_PHONE/showImageView.frame.size.height);
////    CGFloat ratex = W_PHONE/showImageView.frame.size.width;
////    CGFloat ratey = H_PHONE/showImageView.frame.size.height;
//    CGFloat ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
//    CGFloat ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
//
//    NSString *pointList = @"";
//    for (NSInteger nfori = 0;nfori < [touches count];nfori++)
//    {
//        UITouch *touch = [touches objectAtIndex:nfori];
//        CGPoint  lastPoint = [touch locationInView:showImageView];
//
//        /*换算后的坐标*/
////        CGFloat x = lastPoint.x*ratex;
////        CGFloat y = lastPoint.y*ratey;
//        CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
//        CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
//
//        pointList = [pointList stringByAppendingString:[NSString stringWithFormat:@"{\"action\":%ld,\"x\":\"%f\",\"y\":\"%f\"}",(long)nfori,x,y]];
//    }
//
//    pointList = [pointList stringByReplacingOccurrencesOfString:@"}{" withString:@"},{"];
//
//    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"fingerList\":[%@]},\"type\":\"morePortionUp\"}",pointList];
//
//
//    if (USENEWCONTROLLCOMMONDNO500)
//    {
////        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
//    }
//    else
//    {
//        dataStr = [self commandAppending00StringWithSourStr:dataStr];
//    }
//
//    return dataStr;
//}
//
//+ (NSString *)mutMoveCommand500UpWithTouches:(NSArray *)touches
//                               showImageView:(UIImageView *)showImageView
//                                       isLan:(BOOL)isLan
//{
//    /*比列换算*/
////    CGFloat ratex = (showImageView.frame.size.width  > showImageView.frame.size.height)?(H_PHONE/showImageView.frame.size.width):(W_PHONE/showImageView.frame.size.width);
////    CGFloat ratey = (showImageView.frame.size.height > showImageView.frame.size.width)?(H_PHONE/showImageView.frame.size.height):(W_PHONE/showImageView.frame.size.height);
////    CGFloat ratex = W_PHONE/showImageView.frame.size.width;
////    CGFloat ratey = H_PHONE/showImageView.frame.size.height;
//
//    CGFloat ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
//    CGFloat ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
//
//
//    NSString *pointList = @"";
//    for (NSInteger nfori = 0;nfori < [touches count];nfori++)
//    {
//        UITouch *touch = [touches objectAtIndex:nfori];
//        CGPoint  lastPoint = [touch locationInView:showImageView];
//
//        /*换算后的坐标*/
////        CGFloat x = lastPoint.x*ratex;
////        CGFloat y = lastPoint.y*ratey;
//        CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
//        CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
//
//        pointList = [pointList stringByAppendingString:[NSString stringWithFormat:@"{\"action\":0,\"x\":\"%f\",\"y\":\"%f\"}",x,y]];
//    }
//
//    pointList = [pointList stringByReplacingOccurrencesOfString:@"}{" withString:@"},{"];
//
//    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"fingerList\":[%@]},\"type\":\"morePortionMove\"}",pointList];
//
//    if (USENEWCONTROLLCOMMONDNO500)
//    {
////        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
//    }
//    else
//    {
//        dataStr = [self commandAppending00StringWithSourStr:dataStr];
//    }
//
//    return dataStr;
//}
//
//+ (NSString *)tapDownCommandTouches:(UITouch *)touch
//                         touchCount:(NSInteger)touchCount
//                      showImageView:(UIImageView *)showImageView
//                              isLan:(BOOL)isLan
//{
//    int touchid = 0;
//
//    if ([touch respondsToSelector:NSSelectorFromString(@"_touchIdentifier")])
//    {
//        touchid = [[touch valueForKey:@"touchIdentifier"] intValue];
//    }
//    else/*地址转int*/
//    {
//        NSString *ip = [NSString stringWithFormat:@"%p",touch];
//        ip = [ip substringFromIndex:2];
//        NSScanner* scanner = [NSScanner scannerWithString:ip];
//        [scanner scanInteger:&touchid];
//    }
//    CGPoint  lastPoint = [touch locationInView:showImageView];
//
//    CGFloat ratex = 0.0;
//    CGFloat ratey = 0.0;
//
//    /*横屏状态下需要坐标翻转*/
//    if(showImageView.frame.size.width > showImageView.frame.size.height){/*横屏模式*/
//        ratex = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.width;
//        ratey = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.height;
//    }else{
//        ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
//        ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
//    }
//    CGFloat x = lastPoint.x*ratex;
//    CGFloat y = lastPoint.y*ratey;
//
//    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"action\":0,\"count\":%ld,\"pointerId\":%d,\"x\":\"%.2f\",\"y\":\"%.2f\"},\"type\":\"event\"}",(long)touchCount,touchid,x,y];
//
//    return dataStr;
//}
//
//+ (NSString *)tapUpCommandTouches:(UITouch *)touch
//                       touchCount:(NSInteger)touchCount
//                    showImageView:(UIImageView *)showImageView
//                            isLan:(BOOL)isLan
//{
//    int touchid = 0;
//
//    if ([touch respondsToSelector:NSSelectorFromString(@"_touchIdentifier")])
//    {
//        touchid = [[touch valueForKey:@"touchIdentifier"] intValue];
//    }
//    else/*地址转int*/
//    {
//        NSString *ip = [NSString stringWithFormat:@"%p",touch];
//        ip = [ip substringFromIndex:2];
//        NSScanner* scanner = [NSScanner scannerWithString:ip];
//        [scanner scanInteger:&touchid];
//    }
//
//    CGFloat ratex = 0.0;
//    CGFloat ratey = 0.0;
//
//    CGPoint  lastPoint = [touch locationInView:showImageView];
//
//    /*横屏状态下需要坐标翻转*/
//    if(showImageView.frame.size.width > showImageView.frame.size.height){/*横屏模式*/
//        ratex = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.width;
//        ratey = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.height;
//    }else{
//        ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
//        ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
//    }
//    CGFloat x = lastPoint.x*ratex;
//    CGFloat y = lastPoint.y*ratey;
//
//    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"action\":1,\"count\":%ld,\"pointerId\":%d,\"x\":\"%.2f\",\"y\":\"%.2f\"},\"type\":\"event\"}",(long)touchCount,touchid,x,y];
//
//    return dataStr;
//}
//
//+ (NSString *)tapMoveCommandTouches:(UITouch *)touch
//                         touchCount:(NSInteger)touchCount
//                      showImageView:(UIImageView *)showImageView
//                              isLan:(BOOL)isLan
//{
//    int touchid = 0;
//
//    if ([touch respondsToSelector:NSSelectorFromString(@"_touchIdentifier")])
//    {
//        touchid = [[touch valueForKey:@"touchIdentifier"] intValue];
//    }
//    else/*地址转int*/
//    {
//        NSString *ip = [NSString stringWithFormat:@"%p",touch];
//        ip = [ip substringFromIndex:2];
//        NSScanner* scanner = [NSScanner scannerWithString:ip];
//        [scanner scanInteger:&touchid];
//    }
//
//    CGFloat ratex = 0.0;
//    CGFloat ratey = 0.0;
//
//    CGPoint  lastPoint = [touch locationInView:showImageView];
//
//    /*横屏状态下需要坐标翻转*/
//    if(showImageView.frame.size.width > showImageView.frame.size.height){/*横屏模式*/
//        ratex = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.width;
//        ratey = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.height;
//    }else{
//        ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
//        ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
//    }
//    CGFloat x = lastPoint.x*ratex;
//    CGFloat y = lastPoint.y*ratey;
//
//    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"action\":2,\"count\":%ld,\"pointerId\":%d,\"x\":\"%.2f\",\"y\":\"%.2f\"},\"type\":\"event\"}",(long)touchCount,touchid,x,y];
//
//    return dataStr;
//}

#pragma -mark- 新设备控制指令
+ (NSString *)mutTapCommand500DownWithTouches:(NSArray *)touches
                                showImageView:(UIImageView *)showImageView
                                        isLan:(BOOL)isLan
{
    /*比列换算*/
//    CGFloat ratex = (showImageView.frame.size.width > showImageView.frame.size.height)?(H_PHONE/showImageView.frame.size.width):(W_PHONE/showImageView.frame.size.width);
//    CGFloat ratey = (showImageView.frame.size.height > showImageView.frame.size.width)?(H_PHONE/showImageView.frame.size.height):(W_PHONE/showImageView.frame.size.height);
//    CGFloat ratex = W_PHONE/showImageView.frame.size.width;
//    CGFloat ratey = H_PHONE/showImageView.frame.size.height;
    
    CGFloat ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
    CGFloat ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;

    
    NSString *pointList = @"";
    for (NSInteger nfori = 0;nfori < [touches count];nfori++)
    {
        UITouch *touch = [touches objectAtIndex:nfori];
        CGPoint  lastPoint = [touch locationInView:showImageView];
        
        /*换算后的坐标*/
//        CGFloat x = lastPoint.x*ratex;
//        CGFloat y = lastPoint.y*ratey;
        CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
        CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
        
        pointList = [pointList stringByAppendingString:[NSString stringWithFormat:@"{\"action\":%ld,\"x\":\"%f\",\"y\":\"%f\"}",(long)nfori,x,y]];
    }
    
    pointList = [pointList stringByReplacingOccurrencesOfString:@"}{" withString:@"},{"];
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"fingerList\":[%@]},\"type\":\"morePortionDown\"}",pointList];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [CommondToStr commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [RCCommandHelp commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)mutTapCommand500UpWithTouches:(NSArray *)touches
                              showImageView:(UIImageView *)showImageView
                                      isLan:(BOOL)isLan
{
    /*比列换算*/
//    CGFloat ratex = (showImageView.frame.size.width > showImageView.frame.size.height)?(H_PHONE/showImageView.frame.size.width):(W_PHONE/showImageView.frame.size.width);
//    CGFloat ratey = (showImageView.frame.size.height > showImageView.frame.size.width)?(H_PHONE/showImageView.frame.size.height):(W_PHONE/showImageView.frame.size.height);
//    CGFloat ratex = W_PHONE/showImageView.frame.size.width;
//    CGFloat ratey = H_PHONE/showImageView.frame.size.height;
    CGFloat ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
    CGFloat ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;

    NSString *pointList = @"";
    for (NSInteger nfori = 0;nfori < [touches count];nfori++)
    {
        UITouch *touch = [touches objectAtIndex:nfori];
        CGPoint  lastPoint = [touch locationInView:showImageView];
        
        /*换算后的坐标*/
//        CGFloat x = lastPoint.x*ratex;
//        CGFloat y = lastPoint.y*ratey;
        CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
        CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
        
        pointList = [pointList stringByAppendingString:[NSString stringWithFormat:@"{\"action\":%ld,\"x\":\"%f\",\"y\":\"%f\"}",(long)nfori,x,y]];
    }
    
    pointList = [pointList stringByReplacingOccurrencesOfString:@"}{" withString:@"},{"];
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"fingerList\":[%@]},\"type\":\"morePortionUp\"}",pointList];
    
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)mutMoveCommand500UpWithTouches:(NSArray *)touches
                               showImageView:(UIImageView *)showImageView
                                       isLan:(BOOL)isLan
{
    /*比列换算*/
//    CGFloat ratex = (showImageView.frame.size.width  > showImageView.frame.size.height)?(H_PHONE/showImageView.frame.size.width):(W_PHONE/showImageView.frame.size.width);
//    CGFloat ratey = (showImageView.frame.size.height > showImageView.frame.size.width)?(H_PHONE/showImageView.frame.size.height):(W_PHONE/showImageView.frame.size.height);
//    CGFloat ratex = W_PHONE/showImageView.frame.size.width;
//    CGFloat ratey = H_PHONE/showImageView.frame.size.height;

    CGFloat ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
    CGFloat ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;

    
    NSString *pointList = @"";
    for (NSInteger nfori = 0;nfori < [touches count];nfori++)
    {
        UITouch *touch = [touches objectAtIndex:nfori];
        CGPoint  lastPoint = [touch locationInView:showImageView];
        
        /*换算后的坐标*/
//        CGFloat x = lastPoint.x*ratex;
//        CGFloat y = lastPoint.y*ratey;
        CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
        CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
        
        pointList = [pointList stringByAppendingString:[NSString stringWithFormat:@"{\"action\":0,\"x\":\"%f\",\"y\":\"%f\"}",x,y]];
    }
    
    pointList = [pointList stringByReplacingOccurrencesOfString:@"}{" withString:@"},{"];
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"fingerList\":[%@]},\"type\":\"morePortionMove\"}",pointList];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)tapDownCommandTouches:(UITouch *)touch
                         touchCount:(NSInteger)touchCount
                      showImageView:(UIImageView *)showImageView
                              isLan:(BOOL)isLan
{
    int touchid = 0;
    
    if ([touch respondsToSelector:NSSelectorFromString(@"_touchIdentifier")])
    {
        touchid = [[touch valueForKey:@"touchIdentifier"] intValue];
    }
    else/*地址转int*/
    {
        NSString *ip = [NSString stringWithFormat:@"%p",touch];
        ip = [ip substringFromIndex:2];
        NSScanner* scanner = [NSScanner scannerWithString:ip];
        [scanner scanInteger:&touchid];
    }
    
    CGFloat ratex = 0.0;
    CGFloat ratey = 0.0;
    
    ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
    ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
    
    NSLog(@"kk is 1");
    
    CGPoint  lastPoint = [touch locationInView:showImageView];
            
    CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
    CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"action\":0,\"count\":%ld,\"pointerId\":%d,\"x\":\"%.2f\",\"y\":\"%.2f\"},\"type\":\"event\"}",(long)touchCount,touchid,x,y];
        
    return dataStr;
}

+ (NSString *)tapUpCommandTouches:(UITouch *)touch
                       touchCount:(NSInteger)touchCount
                    showImageView:(UIImageView *)showImageView
                            isLan:(BOOL)isLan
{
    int touchid = 0;
    
    if ([touch respondsToSelector:NSSelectorFromString(@"_touchIdentifier")])
    {
        touchid = [[touch valueForKey:@"touchIdentifier"] intValue];
    }
    else/*地址转int*/
    {
        NSString *ip = [NSString stringWithFormat:@"%p",touch];
        ip = [ip substringFromIndex:2];
        NSScanner* scanner = [NSScanner scannerWithString:ip];
        [scanner scanInteger:&touchid];
    }
    
    CGFloat ratex = 0.0;
    CGFloat ratey = 0.0;
    
    ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
    ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
    
    NSLog(@"kk is 3");
    
    CGPoint  lastPoint = [touch locationInView:showImageView];
            
    CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
    CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"action\":1,\"count\":%ld,\"pointerId\":%d,\"x\":\"%.2f\",\"y\":\"%.2f\"},\"type\":\"event\"}",(long)touchCount,touchid,x,y];
        
    return dataStr;
}

+ (NSString *)tapMoveCommandTouches:(UITouch *)touch
                         touchCount:(NSInteger)touchCount
                      showImageView:(UIImageView *)showImageView
                              isLan:(BOOL)isLan
{
    int touchid = 0;
    
    if ([touch respondsToSelector:NSSelectorFromString(@"_touchIdentifier")])
    {
        touchid = [[touch valueForKey:@"touchIdentifier"] intValue];
    }
    else/*地址转int*/
    {
        NSString *ip = [NSString stringWithFormat:@"%p",touch];
        ip = [ip substringFromIndex:2];
        NSScanner* scanner = [NSScanner scannerWithString:ip];
        [scanner scanInteger:&touchid];
    }
    
    CGFloat ratex = 0.0;
    CGFloat ratey = 0.0;
    
    ratex = ksharedAppDelegate.couldPhone_W_PHONE/showImageView.frame.size.width;
    ratey = ksharedAppDelegate.couldPhone_H_PHONE/showImageView.frame.size.height;
    
    NSLog(@"kk is 2");
    
    CGPoint  lastPoint = [touch locationInView:showImageView];
            
    CGFloat x = isLan?(lastPoint.y*ratey):(lastPoint.x*ratex);
    CGFloat y = isLan?((showImageView.frame.size.width - lastPoint.x)*ratex):lastPoint.y*ratey;
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"action\":2,\"count\":%ld,\"pointerId\":%d,\"x\":\"%.2f\",\"y\":\"%.2f\"},\"type\":\"event\"}",(long)touchCount,touchid,x,y];
        
    return dataStr;
}
+ (NSString *)toStopControllerDevice500
{
    NSString *stopContrStr    = [NSString stringWithFormat:@"{\"data\":{\"x\":\"%d\",\"y\":\"%d\"},\"type\":\"closeServer\"}",0,0];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        stopContrStr = [self commondAppendingHeadAndEndStrWithSourStr:stopContrStr];
    }
    else
    {
        stopContrStr = [self commandAppending00StringWithSourStr:stopContrStr];
    }
    
    return stopContrStr;
}

/**
* @brief 摇一摇
*
*/
+ (NSString *)commandShake{
    NSString *stopContrStr    = @"{\"data\":{},\"type\":\"shakeit\"}";
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        stopContrStr = [self commondAppendingHeadAndEndStrWithSourStr:stopContrStr];
    }
    else
    {
        stopContrStr = [self commandAppending00StringWithSourStr:stopContrStr];
    }
    
    return stopContrStr;
}


/**
* @brief 开启本地键盘透传
*
*/
+ (NSString *)commandOpenLoaclKeyboad{
    NSString *stopContrStr    = @"{\"data\":{\"type\":1},\"type\":\"InputMethod\"}";
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        stopContrStr = [self commondAppendingHeadAndEndStrWithSourStr:stopContrStr];
    }
    else
    {
        stopContrStr = [self commandAppending00StringWithSourStr:stopContrStr];
    }
    
    return stopContrStr;
}

/**
* @brief 关闭本地键盘透传
*
*/
+ (NSString *)commandCloseLoaclKeyboad{
    NSString *stopContrStr    = @"{\"data\":{\"type\":2},\"type\":\"InputMethod\"}";
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        stopContrStr = [self commondAppendingHeadAndEndStrWithSourStr:stopContrStr];
    }
    else
    {
        stopContrStr = [self commandAppending00StringWithSourStr:stopContrStr];
    }
    
    return stopContrStr;
}

/**
* @brief 关闭云手机键盘透传
*
*/
+ (NSString *)commandClosePhoneKeyboad{
    NSString *stopContrStr    = @"{\"data\":{\"keyCode\":66},\"type\":\"keyCode\"}";
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        stopContrStr = [self commondAppendingHeadAndEndStrWithSourStr:stopContrStr];
    }
    else
    {
        stopContrStr = [self commandAppending00StringWithSourStr:stopContrStr];
    }
    
    return stopContrStr;
}

/**
* @brief 发送透传文字给云手机/输入或者删除
*
* @param  str 输入的内容 为nil时为删除
*
*/
+ (NSString *)commandKeyboadInputStr:( NSString* _Nullable )str{
    NSString *stopContrStr    = [NSString stringWithFormat:@"{\"data\":{\"KeyBoardData\":\"%@\",\"position\":1},\"type\":\"KeyoardInfo\"}",str];
    if (str == nil){
        stopContrStr    = @"{\"data\":{\"KeyBoardData\":\"\",\"position\":-1},\"type\":\"KeyoardInfo\"}";
    }else{
        
    }
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        stopContrStr = [self commondAppendingHeadAndEndStrWithSourStr:stopContrStr];
    }
    else
    {
        stopContrStr = [self commandAppending00StringWithSourStr:stopContrStr];
    }
    
    return stopContrStr;
}



/**
 * @brief 获取发给安卓手机的指令字符串
 *
 * @param  code 指令类型 3:home 4:back  25:声音-键  24:声音+键  187:后台切换
 *
 */
+ (NSString *)commandBackOrHomeVolum500WithKeyCode:(int)code
{
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"keyCode\":\"%d\"},\"type\":\"keyCode\"}",code];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
 * @brief 获取发给安卓手机设置分辨率的指令字符串
 *
 * @param  type 200:极速  400:高速  600:标清  800:自动  1000:高清
 *
 */
+ (NSString *)commandResolution500WithType:(NSUInteger)type
{
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"definition\":%ld,\"clientType\":\"ios\",\"sceneType\":\"cloudPhone\"},\"type\":2}",type];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)commandSetFps{
    NSString *dataStr = @"{\"data\":{\"frame_rate\":25,\"clientType\":\"ios\"},\"type\":5}";
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
* @brief 云手机预览图指令
*/
+ (NSString *)commandGetScreenPicWithTaskUid:(NSString *)taskUid intervalTime:(int)intervalTime
{
    NSString *dataStr = [NSString stringWithFormat:@"{\"type\":\"getScreenPic\",\"data\":{\"taskUid\":\"%@\",\"intervalTime\":\"%d\"}}",taskUid,intervalTime];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
* @brief 云手机截图指令
*/
+ (NSString *)commandCloudPhoneScreenshotWithTaskUid:(NSString *)taskUid
{
    NSString *dataStr = [NSString stringWithFormat:@"{\"type\":\"shortCat\",\"data\":{\"taskUid\":\"%@\"}}",taskUid];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
* @brief 云手机下载透传指令（云游戏下载透传到云手机）
*/
+ (NSString *)commandCloudPhoneDownloadWithTaskUid:(NSString *)taskUid apkUrl:(NSString *)apkUrl {
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"type\":\"downAndInstallApk\",\"data\":{\"taskUid\":\"%@\",\"apkUrl\":\"%@\"}}",taskUid,apkUrl];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
* @brief 云游戏支付透传指令 （云游戏在本地支付完成透传到云手机）payResult 0:失败 1:成功
*/
+ (NSString *)commandCloudPhonePayWithTaskUid:(NSString *)taskUid payResult:(int)payResult {
    
    NSString *dataStr = [NSString stringWithFormat:@"{\"type\":\"payResult\",\"data\":{\"result\":\"%d\"}}",payResult];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
* @brief 剪切板接口
*
* @param  str 要剪切的文本
*
*/
+ (NSString *)commandCuttingWithContent:(NSString *)str
{
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"str\":\"%@\"},\"type\":\"cutting\"}",str];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

/**
 * @brief 记录推流开始时间
 *
 * @param  deviceid 云手机id
 *
 */
+ (NSString *)commandConnectedWithDeviceId:(NSString *)deviceid
{
    NSString *eventId = @"7";
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"deviceId\":\"%@\"},\"type\":\"%@\"}",deviceid,eventId];
    if (USENEWCONTROLLCOMMONDNO500)
    {
        
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    return dataStr;
}


+ (NSArray *)getAllIvar:(id)object
{
    NSMutableArray *array = [NSMutableArray array];

    unsigned int count;
    Ivar *ivars = class_copyIvarList([object class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char *keyChar = ivar_getName(ivar);
        NSString *keyStr = [NSString stringWithCString:keyChar encoding:NSUTF8StringEncoding];
        @try {
            id valueStr = [object valueForKey:keyStr];
            NSDictionary *dic = nil;
            if (valueStr) {
                dic = @{keyStr : valueStr};
            } else {
                dic = @{keyStr : @"值为nil"};
            }
            [array addObject:dic];
        }
        @catch (NSException *exception) {}
    }
    return [array copy];
}

+ (NSString *)askControllcommandWithUseName:(NSString*)useName{
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"code\":\"3000\",\"userName\":\"%@\",\"desc\":\"询问是否有在控制\"},\"type\":\"forwardMsg\"}",useName];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)faceBackControllcommandWithUseName:(NSString*)useName haveControl:(BOOL)haveControl{
    NSString *code = @"4000";
    NSString *desc = @"有在控制";
    
    if (haveControl == NO) {
        code = @"4100";
        desc = @"未控制";
    }
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"code\":\"%@\",\"userName\":\"%@\",\"desc\":\"%@\"},\"type\":\"forwardMsg\"}",code,useName,desc];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)getBackControllcommandWithUseName:(NSString*)useName{
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"code\":\"5000\",\"userName\":\"%@\",\"desc\":\"控制权限收回\"},\"type\":\"forwardMsg\"}",useName];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)getPhoneSizecommand{
    NSString *dataStr = [NSString stringWithFormat:@"{\"type\":\"getPhoneSize\"}"];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)setPhoneSizecommandWithWidth:(NSInteger)width high:(NSInteger)high dpi:(NSInteger)dpi{
    NSString *dataStr = [NSString stringWithFormat:@"{\"data\":{\"width\":\"%ld\",\"height\":\"%ld\",\"dpi\":\"%ld\"},\"type\":\"setPhoneSize\"}",width,high,dpi];
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)noSyncWifiBack{
    NSString *dataStr = @"{\"data\":\"2\",\"type\":\"sync_wifi_back\"}";
    //    dataStr = [NSString stringWithFormat:@"%ld%@",dataStr.length,dataStr];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)downLoadAppWithAppUrl:(NSString*)appurl appId:(NSString *)appid{
    NSString *dataStr =[NSString stringWithFormat:@"{\"data\":{\"apkUrl\":\"%@\",\"taskUid\":\"%@\"},\"type\":\"downAndInstallApk\"}",appurl,appid];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

+ (NSString *)applyForUploadFileBy:(NSString*)taskUid filePath:(NSString *)filePath
{
    NSString *dataStr =[NSString stringWithFormat:@"{\"data\":{\"taskUid\":\"%@\",\"filePath\":\"%@\"},\"type\":\"uploadFileRandom\"}",taskUid,filePath];
    
    if (USENEWCONTROLLCOMMONDNO500)
    {
//        dataStr = [self commondAppendingHeadAndEndStrWithSourStr:dataStr];
    }
    else
    {
        dataStr = [self commandAppending00StringWithSourStr:dataStr];
    }
    
    return dataStr;
}

@end
