|
|
// |
|
|
// BLEBaseBl.m |
|
|
// BluetoothDemo |
|
|
// |
|
|
// Created by mac on 17/3/13. |
|
|
// Copyright © 2017年 . All rights reserved. |
|
|
// |
|
|
|
|
|
#import "BLEBaseBl.h" |
|
|
#import "Bluetooth.h" |
|
|
#import "L2DataParse.h" |
|
|
#import "BLEConst.h" |
|
|
#import "BLETools.h" |
|
|
#import <JL_BLEKit/JL_BLEKit.h> |
|
|
#import <JLDialUnit/JLDialUnit.h> |
|
|
#import "JL_RunSDK.h" |
|
|
#import "NSString+SelectString.h" |
|
|
#import <SVProgressHUD/SVProgressHUD.h> |
|
|
|
|
|
#define LOne_Version 0 //L1层版本 |
|
|
#define LTwo_Version 0 //L2层版本 |
|
|
#define LOne_Length 5 //L2层无Value是的总长度 |
|
|
#define Identification 0xCB //识别标志 |
|
|
|
|
|
@interface BLEBaseBl() <BluetoothDataSource> |
|
|
|
|
|
@property (nonatomic, strong)Bluetooth *blueTooth; |
|
|
|
|
|
@end |
|
|
|
|
|
@implementation BLEBaseBl |
|
|
|
|
|
+ (nullable instancetype)shareInstance |
|
|
{ |
|
|
static BLEBaseBl *share = nil; |
|
|
static dispatch_once_t oneToken; |
|
|
dispatch_once(&oneToken, ^{ |
|
|
share = [[self alloc] init]; |
|
|
}); |
|
|
return share; |
|
|
} |
|
|
|
|
|
- (instancetype)init |
|
|
{ |
|
|
if (self = [super init]) { |
|
|
self.blueTooth = [Bluetooth shareInstance]; |
|
|
} |
|
|
return self; |
|
|
} |
|
|
|
|
|
/** |
|
|
查找设备 |
|
|
*/ |
|
|
- (void)findDeviceWithBleCmdType:(BleCMD)cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
设置时间 |
|
|
*/ |
|
|
- (void)setIngTimeWithBleCmdType:(BleCMD )cmd { |
|
|
NSData *value = [[NSData alloc] init]; |
|
|
// 手环设置时间最后拼接一个12/24小时制,hasAMPM NO:24小时 YES:12小时 |
|
|
NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]]; |
|
|
NSRange containsA = [formatStringForHours rangeOfString:@"a"]; |
|
|
BOOL hasAMPM = containsA.location != NSNotFound; |
|
|
NSMutableData *data = [NSMutableData dataWithData:[BluetoothTool getTimeDataWithTime:@[[NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]] cmdType:BleCMD_setIngTime]]; |
|
|
[data appendBytes:&(hasAMPM) length:1]; |
|
|
value = data; |
|
|
BlueToothItem *item = [self getCmd:cmd value:value]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
绑定请求 |
|
|
*/ |
|
|
- (void)bindingDeviceWithBleCmdType:(BleCMD )cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
同步联系人 |
|
|
*/ |
|
|
- (void)syncContactWithBleCmdType:(BleCMD )cmd |
|
|
contentArr:(NSArray *)contentArr |
|
|
{ |
|
|
|
|
|
NSMutableData *bookData = [NSMutableData new]; |
|
|
for (NSString *book in contentArr) |
|
|
{ |
|
|
NSArray *array = [book componentsSeparatedByString:@"\n"]; |
|
|
NSString *name = [NSString stringWithFormat:@"%@",array[0]]; |
|
|
NSString *phone = [NSString stringWithFormat:@"%@",array[1]]; |
|
|
|
|
|
phone = [phone stringByReplacingOccurrencesOfString:@" " withString:@""]; |
|
|
phone = [phone stringByReplacingOccurrencesOfString:@"+86" withString:@""]; |
|
|
|
|
|
NSData *namedata = [name dataUsingEncoding:NSUTF16LittleEndianStringEncoding]; |
|
|
NSData *phonedata = [phone dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
NSLog(@"data-->%@",namedata); |
|
|
|
|
|
|
|
|
unsigned long len = [namedata length]; |
|
|
[bookData appendBytes:&len length:1]; |
|
|
[bookData appendData:namedata]; |
|
|
|
|
|
unsigned long len1 = [phonedata length]; |
|
|
[bookData appendBytes:&len1 length:1]; |
|
|
[bookData appendData:phonedata]; |
|
|
} |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:bookData]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
二维码推送 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param payType 收款码类型 1:支付宝收款码,2:微信收款码,3:Paypal收款码,4.个人微信码 |
|
|
@param qrCodeImg 二维码字符串 |
|
|
*/ |
|
|
- (void)qrCodePushWithBleCmdType:(BleCMD )cmd |
|
|
PayType:(NSInteger)payType |
|
|
qrCodeImg:(UIImage *)qrCodeImg |
|
|
{ |
|
|
NSString *qrcodeStr = [self readQRCodeFromImage:qrCodeImg]; |
|
|
if (qrcodeStr.length > 0) |
|
|
{ |
|
|
NSMutableData *imgData = [NSMutableData new]; |
|
|
NSData *ImgData = [qrcodeStr dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
unsigned long imgLen = [ImgData length]; |
|
|
|
|
|
[imgData appendBytes:&payType length:1]; |
|
|
[imgData appendBytes:&imgLen length:2]; |
|
|
[imgData appendData:ImgData]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:imgData]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
else |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
手表WIFI |
|
|
*/ |
|
|
- (void)watchWifiWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
协助输入开始 |
|
|
*/ |
|
|
- (void)inputStartWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
发送协助输入 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param content 输入的内容 |
|
|
*/ |
|
|
- (void)inputSendWithBleCmdType:(BleCMD )cmd |
|
|
content:(NSString *)content { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[content dataUsingEncoding:NSUTF8StringEncoding]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
发送剪切板数据 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param content 剪切板内容 |
|
|
*/ |
|
|
- (void)shearPlateWithBleCmdType:(BleCMD )cmd |
|
|
content:(NSString *)content { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[content dataUsingEncoding:NSUTF8StringEncoding]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
协助输入结束 |
|
|
*/ |
|
|
- (void)inputEndWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
表盘推送 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param dialType 表盘类型 |
|
|
*/ |
|
|
- (void)dialPushWithBleCmdType:(BleCMD )cmd |
|
|
dialType:(NSInteger)dialType { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[[NSString stringWithFormat:@"%ld",dialType] dataUsingEncoding:NSUTF8StringEncoding]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
紧急拨号 |
|
|
|
|
|
使用#分割手机号 |
|
|
@param cmd 命令类型 |
|
|
@param urgentNumber 紧急拨号的号码 |
|
|
*/ |
|
|
- (void)urgentDialWithBleCmdType:(BleCMD )cmd |
|
|
urgentNumber:(NSString *)urgentNumber { |
|
|
|
|
|
//NSString *urgentStr = @"13480905523^13554564776"; |
|
|
NSData *data = [urgentNumber dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:data]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
同步健康数据(key 0xA0) |
|
|
|
|
|
@param type 1:睡眠,2:心率,3:计步,4:运动模式 (手环使用,72平台传0同步所有) 5:血压 6:血氧 |
|
|
@param timeArr 时间戳数组(三个时间),传空则为获取所有 |
|
|
*/ |
|
|
- (void)syncHealthWithBleCmdType:(BleCMD )cmd |
|
|
Type:(NSInteger)type |
|
|
timeArr:(NSArray *)timeArr { |
|
|
NSMutableData *value = [[NSMutableData alloc] init]; |
|
|
[value appendBytes:&type length:1]; |
|
|
[value appendData:timeArr.count ? [BluetoothTool getTimeDataWithTime:timeArr cmdType:cmd] : 0]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:value]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
同步表盘数据 |
|
|
*/ |
|
|
- (void)syncDialPush |
|
|
{ |
|
|
BleCMD cmd = BleCMD_dialRequest; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
/** |
|
|
WIFI需要密码 |
|
|
*/ |
|
|
- (void)wifiPassWordWithBleCmdType:(BleCMD )cmd |
|
|
SSID:(NSString *)SSID |
|
|
PassWord:(NSString *)passWord { |
|
|
|
|
|
NSData *SSIDData = [SSID dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
NSData *passWordData = [passWord dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
NSData *divisionData = [@"|" dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
NSMutableData *value = [[NSMutableData alloc] init]; |
|
|
[value appendData:SSIDData]; |
|
|
[value appendData:divisionData]; |
|
|
[value appendData:passWordData]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:value]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
已保存的WIFI |
|
|
*/ |
|
|
- (void)wifiLinkWithBleCmdType:(BleCMD )cmd |
|
|
NetworkId:(NSString *)networkId { |
|
|
|
|
|
NSData *value = [networkId dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:value]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
WIFI无需密码 |
|
|
*/ |
|
|
- (void)wifiNoPassWordWithBleCmdType:(BleCMD )cmd |
|
|
SSID:(NSString *)SSID { |
|
|
|
|
|
NSData *value = [SSID dataUsingEncoding:NSUTF8StringEncoding]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:value]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** 固件升级启动 |
|
|
|
|
|
@param updateData 固件升级包数据 |
|
|
*/ |
|
|
- (void)firmwareUpdateWithBleCmdType:(BleCMD )cmd |
|
|
UpdateData:(NSData *)updateData { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:updateData]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
获取设备固件版本信息 |
|
|
*/ |
|
|
- (void)firmwareVersionWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
闹钟设置 |
|
|
|
|
|
@param alarmClockArr 闹钟数组(时间戳字符串&&周期字符串) |
|
|
*/ |
|
|
- (void)setAlarmClockWithBleCmdType:(BleCMD )cmd |
|
|
AlarmClockArr:(NSArray *)alarmClockArr { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[BluetoothTool getAlarmClockDataWithArr:alarmClockArr]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
用户信息设置 |
|
|
|
|
|
@param gender 性别 |
|
|
@param age 年龄 |
|
|
@param height 身高 |
|
|
@param weight 体重 |
|
|
@param goal 运动目标 |
|
|
*/ |
|
|
- (void)setUserInfoWithBleCmdType:(BleCMD )cmd |
|
|
gender:(NSString *)gender |
|
|
age:(NSString *)age |
|
|
height:(NSString *)height |
|
|
weight:(NSString *)weight |
|
|
Goal:(NSString *)goal |
|
|
BMI:(NSString *)BMI |
|
|
{ |
|
|
// 拼接成八个字节的数据 |
|
|
NSInteger goals = [goal integerValue]; |
|
|
Byte buffer[9]; |
|
|
buffer[0] = (Byte)[gender integerValue]; |
|
|
buffer[1] = (Byte)[age integerValue]; |
|
|
buffer[2] = (Byte)[height integerValue]; |
|
|
buffer[3] = (Byte)[weight integerValue]; |
|
|
buffer[4] = (Byte)(goals); |
|
|
buffer[5] = (Byte)(goals >> 8); |
|
|
buffer[6] = (Byte)(goals >> 16); |
|
|
buffer[7] = 0; |
|
|
buffer[8] = (Byte)[BMI integerValue]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:9]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
防丢设置 |
|
|
|
|
|
@param ONOFF 0:关闭 1:开启 |
|
|
*/ |
|
|
- (void)setTheLostWithBleCmdType:(BleCMD )cmd |
|
|
ONOFF:(BOOL)ONOFF { |
|
|
|
|
|
Byte buffer[2]; |
|
|
buffer[0] = 1; |
|
|
buffer[1] = ONOFF; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:2]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
久坐设置 |
|
|
|
|
|
@param ONOFF 0:关闭 1:开启 |
|
|
@param StartTime 开始时间 |
|
|
@param endTime 结束时间 |
|
|
@param cycle 周期 |
|
|
@param sittingTime 久坐时间 |
|
|
@param sittingThreshold 久坐阈值 |
|
|
*/ |
|
|
- (void)setSedentaryWithBleCmdType:(BleCMD )cmd |
|
|
ONOFF:(BOOL)ONOFF |
|
|
StartTime:(NSString *)StartTime |
|
|
EndTime:(NSString *)endTime |
|
|
Cycle:(NSString *)cycle |
|
|
SittingTime:(NSString *)sittingTime |
|
|
SittingThreshold:(NSString *)sittingThreshold { |
|
|
|
|
|
Byte buffer[8]; |
|
|
buffer[0] = ONOFF; |
|
|
buffer[1] = StartTime.intValue; |
|
|
buffer[2] = endTime.intValue; |
|
|
// 周期 |
|
|
const char *cycleStr = [cycle cStringUsingEncoding:NSUTF8StringEncoding]; |
|
|
// 二进制字符串转成整数 |
|
|
int cycleValue = 0; |
|
|
for (int j = 0; j < 7; j ++) { |
|
|
if (cycleStr[j] == '1') { |
|
|
cycleValue += 1 * pow(2, j); |
|
|
} |
|
|
} |
|
|
buffer[3] = cycleValue; |
|
|
buffer[4] = [sittingTime intValue]; |
|
|
buffer[5] = ([sittingTime intValue] >> 8); |
|
|
buffer[6] = ([sittingThreshold intValue] & 0xff); |
|
|
buffer[7] = [sittingThreshold intValue] >> 8; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:8]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
自动睡眠设置 (暂不使用) |
|
|
|
|
|
@param ONOFF 0:关闭 1:开启 |
|
|
*/ |
|
|
- (void)setSleepWithBleCmdType:(BleCMD )cmd |
|
|
ONOFF:(BOOL)ONOFF { |
|
|
|
|
|
Byte buffer[1]; |
|
|
buffer[0] = ONOFF; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
系统用户设置(key 0x27) |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)setSystemUserWithBleCmdType:(BleCMD )cmd { |
|
|
// 1. 0:中文 1:英文 2.俄罗斯语 3.西班牙语 4.德国 5.意大利 6.法国 7.葡萄牙 8.波兰语 9.荷兰 10.希腊 11.土耳其 12.罗马尼亚 13.日语 14.繁体(目前只支持M6) 15.希伯来语 16.丹麦语 17.塞尔维亚语 18:其他 |
|
|
// 2. 0:24小时制 1: 12小时制 3. 单位秒,范围0-255 |
|
|
Byte buffer[4]; |
|
|
NSString *language = [BLETools getCurrentLanguage]; |
|
|
if ([language hasPrefix:@"zh"]) { |
|
|
buffer[0] = 0; |
|
|
// 单独处理有繁体的手环设备 |
|
|
if ([language hasPrefix:@"zh-Hant"]) { |
|
|
buffer[0] = 14; |
|
|
} |
|
|
}else if ([language hasPrefix:@"en"]) { |
|
|
buffer[0] = 1; |
|
|
}else if ([language hasPrefix:@"ru"]) { |
|
|
buffer[0] = 2; |
|
|
}else if ([language hasPrefix:@"es"]) { |
|
|
buffer[0] = 3; |
|
|
}else if ([language hasPrefix:@"de"]) { |
|
|
buffer[0] = 4; |
|
|
}else if ([language hasPrefix:@"it"]) { |
|
|
buffer[0] = 5; |
|
|
}else if ([language hasPrefix:@"fr"]) { |
|
|
buffer[0] = 6; |
|
|
}else if ([language hasPrefix:@"pt"]) { |
|
|
buffer[0] = 7; |
|
|
}else if ([language hasPrefix:@"pl"]) { |
|
|
buffer[0] = 8; |
|
|
}else if ([language hasPrefix:@"nl"]) { |
|
|
buffer[0] = 9; |
|
|
}else if ([language hasPrefix:@"el"]) { |
|
|
buffer[0] = 10; |
|
|
}else if ([language hasPrefix:@"tr"]) { |
|
|
buffer[0] = 11; |
|
|
}else if ([language hasPrefix:@"ro"]) { |
|
|
buffer[0] = 12; |
|
|
}else if ([language hasPrefix:@"ja"]) { |
|
|
buffer[0] = 13; |
|
|
}else if ([language hasPrefix:@"he"]) { |
|
|
buffer[0] = 15; |
|
|
}else if ([language hasPrefix:@"da"]) { |
|
|
buffer[0] = 16; |
|
|
}else if ([language hasPrefix:@"sr"]) { |
|
|
buffer[0] = 17; |
|
|
}else { |
|
|
buffer[0] = 18; |
|
|
} |
|
|
// 手环设置时间最后拼接一个12/24小时制,hasAMPM NO:24小时 YES:12小时 |
|
|
NSString *formatStringForHours = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]]; |
|
|
NSRange containsA = [formatStringForHours rangeOfString:@"a"]; |
|
|
BOOL hasAMPM = containsA.location != NSNotFound; |
|
|
buffer[1] = hasAMPM; |
|
|
buffer[2] = 0; |
|
|
buffer[3] = 1; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:4]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
喝水提醒设置(key 0x28) |
|
|
|
|
|
@param ONOFF 喝水使能 0:关 1:开 |
|
|
@param startTime 开始时间 小时+分钟 |
|
|
@param endTime 结束时间 小时+分钟 |
|
|
@param cycle 周期 |
|
|
@param interval 喝水间隔设置 分钟 |
|
|
*/ |
|
|
- (void)setDrinkRemindWithBleCmdType:(BleCMD )cmd |
|
|
DrinkONOFF:(BOOL)ONOFF |
|
|
StartTime:(NSString *)startTime |
|
|
EndTime:(NSString *)endTime |
|
|
Cycle:(NSString *)cycle |
|
|
Interval:(NSString *)interval { |
|
|
|
|
|
Byte buffer[8]; |
|
|
buffer[0] = ONOFF; |
|
|
// 开始&&结束时间 |
|
|
NSArray *startArr = [startTime componentsSeparatedByString:@":"]; |
|
|
NSArray *endArr = [endTime componentsSeparatedByString:@":"]; |
|
|
buffer[1] = [startArr[0] intValue]; |
|
|
buffer[2] = [startArr[1] intValue]; |
|
|
buffer[3] = [endArr[0] intValue]; |
|
|
buffer[4] = [endArr[1] intValue]; |
|
|
// 周期 |
|
|
const char *cycleStr = [cycle cStringUsingEncoding:NSUTF8StringEncoding]; |
|
|
// 二进制字符串转成整数 |
|
|
int cycleValue = 0; |
|
|
for (int j = 0; j < 7; j ++) { |
|
|
|
|
|
if (cycleStr[j] == '1') { |
|
|
|
|
|
cycleValue += 1 * pow(2, j); |
|
|
} |
|
|
} |
|
|
buffer[5] = cycleValue; |
|
|
buffer[6] = [interval intValue] & 0xff; |
|
|
buffer[7] = [interval intValue] >> 8; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:8]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
设备电量请求 |
|
|
*/ |
|
|
- (void)requestBatteryWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
解除绑定请求(key 0x42) |
|
|
*/ |
|
|
- (void)unbundledDeviceWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
拍照开关(key 0x46) ->手环使用 |
|
|
|
|
|
@param ONOFF 0:相机已关闭 1:相机已打开 |
|
|
*/ |
|
|
- (void)cameraSwitchWithBleCmdType:(BleCMD )cmd |
|
|
ONOFF:(BOOL)ONOFF { |
|
|
|
|
|
Byte buffer[1]; |
|
|
buffer[0] = ONOFF; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
横竖显示(key 0x49) |
|
|
|
|
|
@param isVertical 0:横屏1:竖屏 |
|
|
*/ |
|
|
- (void)relationDisplayWithBleCmdType:(BleCMD )cmd |
|
|
IsVertical:(BOOL)isVertical { |
|
|
|
|
|
Byte buffer[1]; |
|
|
buffer[0] = isVertical; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
抬手亮屏显示(key 0x4A) |
|
|
|
|
|
@param hand 0:左手 1:右手 |
|
|
@param raise 0:抬手亮屏关闭 1:抬手亮屏开启 |
|
|
@param flip 0:翻腕亮屏关闭 1:翻腕亮屏开启 |
|
|
*/ |
|
|
- (void)gesturesControlWithBleCmdType:(BleCMD )cmd |
|
|
Hand:(NSInteger)hand |
|
|
Raise:(BOOL)raise |
|
|
Flip:(BOOL)flip { |
|
|
|
|
|
Byte buffer[3]; |
|
|
buffer[0] = hand; |
|
|
buffer[1] = raise; |
|
|
buffer[2] = flip; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:3]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
勿扰模式(key 0x2A) |
|
|
|
|
|
@param ONOFF 勿扰使能 1: 开启 0: 关闭 |
|
|
@param startTime 开始时间 |
|
|
@param endTime 结束时间 |
|
|
*/ |
|
|
- (void)notDisturbWithBleCmdType:(BleCMD )cmd |
|
|
ONOFF:(BOOL)ONOFF |
|
|
StartTime:(NSString *)startTime |
|
|
EndTime:(NSString *)endTime { |
|
|
|
|
|
Byte buffer[5]; |
|
|
buffer[0] = ONOFF; |
|
|
|
|
|
// 开始&&结束时间 |
|
|
NSArray *startArr = [startTime componentsSeparatedByString:@":"]; |
|
|
NSArray *endArr = [endTime componentsSeparatedByString:@":"]; |
|
|
buffer[1] = [startArr[0] intValue]; |
|
|
buffer[2] = [startArr[1] intValue]; |
|
|
buffer[3] = [endArr[0] intValue]; |
|
|
buffer[4] = [endArr[1] intValue]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:5]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
提醒模式(key 0x2B) |
|
|
|
|
|
@param remindType 提醒方式 1:亮屏 2:震动 3:亮屏+震动 |
|
|
*/ |
|
|
- (void)remindModelWithBleCmdType:(BleCMD )cmd |
|
|
RemindType:(NSInteger)remindType { |
|
|
|
|
|
Byte buffer[1]; |
|
|
buffer[0] = remindType; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
同步实时数据(key 0xB0) |
|
|
|
|
|
@param syncType 1:睡眠 2:心率 3:计步 4:运动模式 5:血压 6: 心电 7:血氧 8:体温 |
|
|
*/ |
|
|
- (void)realTimesyncWithBleCmdType:(BleCMD )cmd |
|
|
SyncType:(NSInteger)syncType { |
|
|
Byte buffer[1]; |
|
|
buffer[0] = syncType; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
读取手环设置请求(key 0x2D) |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)readBraceletSetWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
读取手环配置请求(key 0x2E) |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)readProfileWithBleCmdType:(BleCMD )cmd { |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
运动目标设置 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param targetSteps 运动目标步数 |
|
|
@param sportMode 运动模式 0:计步 1:跑步 2:骑行 3:爬山 |
|
|
*/ |
|
|
- (void)setSportTargetWithBleCmdType:(BleCMD )cmd |
|
|
TargetSteps:(NSInteger)targetSteps |
|
|
SportMode:(NSInteger)sportMode { |
|
|
|
|
|
NSMutableData *value = [[NSMutableData alloc] init]; |
|
|
[value appendBytes:&targetSteps length:3]; |
|
|
[value appendBytes:&sportMode length:1]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:value]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
设置推送 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param value 推送值 |
|
|
*/ |
|
|
- (void)setPushWithBleCmdType:(BleCMD )cmd |
|
|
value:(NSInteger)value { |
|
|
NSData *data = [NSData dataWithBytes:&value length:2]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:data]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
心率检测设置 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param ONOFF 开关 |
|
|
@param startTime 开始时间 |
|
|
@param endTime 结束时间 |
|
|
@param interval 间隔时间 |
|
|
*/ |
|
|
- (void)setHeartRateCheckWithBleCmdType:(BleCMD )cmd |
|
|
RateONOFF:(BOOL)ONOFF |
|
|
StartTime:(NSString *)startTime |
|
|
EndTime:(NSString *)endTime |
|
|
Interval:(NSString *)interval { |
|
|
// 开始&&结束时间 |
|
|
NSArray *startArr = [startTime componentsSeparatedByString:@":"]; |
|
|
NSArray *endArr = [endTime componentsSeparatedByString:@":"]; |
|
|
Byte buffer[6]; |
|
|
buffer[0] = ONOFF; |
|
|
buffer[1] = [startArr[0] intValue]; |
|
|
buffer[2] = [startArr[1] intValue]; |
|
|
buffer[3] = [endArr[0] intValue]; |
|
|
buffer[4] = [endArr[1] intValue]; |
|
|
buffer[5] = [interval intValue]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:6]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/// 天气推送(最多三天,当天、明天、后天) |
|
|
/// @param cmd 命令类型 |
|
|
/// @param weathers 天气数组{lowTemperature: Strting, highTemperature: Strting, currenTemperature: Strting, weatherType: Int} |
|
|
- (void)setWeatherPushWithBleCmdType:(BleCMD )cmd |
|
|
Weathers:(NSArray *)weathers { |
|
|
NSInteger length = 4 * weathers.count; |
|
|
Byte buffer[length]; |
|
|
for (int i = 0; i < weathers.count; i ++) { |
|
|
NSDictionary *dict = weathers[i]; |
|
|
buffer[0 + i * 4] = [dict[@"lowTemperature"] intValue]; |
|
|
buffer[1 + i * 4] = [dict[@"highTemperature"] intValue]; |
|
|
buffer[2 + i * 4] = [dict[@"weatherType"] intValue]; |
|
|
buffer[3 + i * 4] = [dict[@"currenTemperature"] intValue]; |
|
|
} |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:length]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
推送两天的天气 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param lowTemperature 低温1 |
|
|
@param highTemperature 高温1 |
|
|
@param weatherType 天气类型1 |
|
|
@param lowTemperature2 低温2 |
|
|
@param highTemperature2 高温2 |
|
|
@param weatherType2 天气类型2 |
|
|
*/ |
|
|
- (void)setWeather2PushWithBleCmdType:(BleCMD)cmd |
|
|
LowTemperature:(NSString *)lowTemperature |
|
|
HighTemperature:(NSString *)highTemperature |
|
|
WeatherType:(NSInteger)weatherType |
|
|
LowTemperature2:(NSString *)lowTemperature2 |
|
|
HighTemperature2:(NSString *)highTemperature2 |
|
|
WeatherType2:(NSInteger)weatherType2 |
|
|
{ |
|
|
Byte buffer[6]; |
|
|
buffer[0] = [lowTemperature intValue]; |
|
|
buffer[1] = [highTemperature intValue]; |
|
|
buffer[2] = weatherType; |
|
|
buffer[3] = [lowTemperature2 intValue]; |
|
|
buffer[4] = [highTemperature2 intValue]; |
|
|
buffer[5] = weatherType2; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:6]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
气象指数推送 |
|
|
|
|
|
@param cmd 命令类型0 |
|
|
@param UV 紫外线 |
|
|
@param pressure 气压 |
|
|
@param altitude 海拔 |
|
|
*/ |
|
|
- (void)weatherIndexWithBleCmdType:(BleCMD )cmd |
|
|
UV:(NSString *)UV |
|
|
Pressure:(NSString *)pressure |
|
|
Altitude:(NSString *)altitude { |
|
|
Byte buffer[5]; |
|
|
buffer[0] = [UV intValue]; |
|
|
buffer[1] = [pressure intValue] & 0xff; |
|
|
buffer[2] = [pressure intValue] >> 8; |
|
|
buffer[3] = [altitude intValue] & 0xff; |
|
|
buffer[4] = [altitude intValue] >> 8; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:5]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
恢复出厂设置 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)restoreFactoryWithBleCmdType:(BleCMD )cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
单位设置 |
|
|
|
|
|
@param cmd 命令类型 (key 0x01) |
|
|
@param measure 度量单位 (0:公制 1:英制) |
|
|
@param temperature 温度 (0: 摄氏度 1:华氏摄氏度) |
|
|
*/ |
|
|
- (void)unitSettingWithBleCmdType:(BleCMD)cmd |
|
|
measure:(NSInteger)measure |
|
|
temperature:(NSInteger)temperature { |
|
|
Byte buffer[2]; |
|
|
buffer[0] = measure; |
|
|
buffer[1] = temperature; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:2]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
呼吸设置 |
|
|
*/ |
|
|
- (void)breatheWithBleCmdType:(BleCMD)cmd withTime:(int)time { |
|
|
Byte buffer[1]; buffer[0] = time; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
GPS信号强度同步到设备 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param dialType 信号强度 |
|
|
*/ |
|
|
- (void)GPSSignalStrengthWithBleCmdType:(BleCMD )cmd |
|
|
dialType:(NSInteger)dialType { |
|
|
Byte buffer[1]; buffer[0] = dialType; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:1]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
准备启动Esim服务 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)startEsimWithBleCmdType:(BleCMD)cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
结束Esim服务 |
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)endEsimWithBleCmdType:(BleCMD)cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
获取设备EID |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)getDeviceEidWithBleCmdType:(BleCMD)cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
获取设备IMEI号 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)getDeviceIMEIWithBleCmdType:(BleCMD)cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
获取手表的profile列表 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)getProfileListWithBleCmdType:(BleCMD)cmd { |
|
|
BlueToothItem *item = [self getCmd:cmd value:0]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
开启profile |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)enableProfileWithBleCmdType:(BleCMD)cmd iccid:(NSString *)iccid { |
|
|
NSData *data = [BLETools convertHexStrToData: iccid]; |
|
|
|
|
|
BlueToothItem *item = [self getCmd:cmd value:data]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
禁用profile |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)disableProfileWithBleCmdType:(BleCMD)cmd iccid:(NSString *)iccid{ |
|
|
NSData *data = [BLETools convertHexStrToData: iccid]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:data]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
删除profile |
|
|
|
|
|
@param cmd 命令类型 |
|
|
*/ |
|
|
- (void)deleteProfileWithBleCmdType:(BleCMD)cmd iccid:(NSString *)iccid{ |
|
|
NSData *data = [BLETools convertHexStrToData: iccid]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:data]; |
|
|
|
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
发送数据到设备 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param message sdk出来的数据 |
|
|
*/ |
|
|
- (void)sendMessageWithBleCmdType:(BleCMD )cmd |
|
|
message:(NSString *)message { |
|
|
NSData *data = [BLETools convertHexStrToData: message]; |
|
|
BlueToothItem *item = [self getCmd:cmd value: data]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/// 发送FLASH数据命令 |
|
|
/// @param cmd 命令类型 |
|
|
/// @param data 数据 |
|
|
- (void)falshSendWithBleCmdType:(BleCMD )cmd |
|
|
total:(NSInteger)total |
|
|
curren:(NSInteger)curren |
|
|
lenght:(NSInteger)lenght |
|
|
data:(NSData *)data { |
|
|
NSInteger crc = 0xff; |
|
|
for (int i = 0; i < data.length; i++) { |
|
|
crc^= ((Byte*)([data bytes]))[i] & 0xFF; |
|
|
for (int j = 0; j < 8; j++) { |
|
|
if((crc & 1) !=0){ |
|
|
crc >>=1; |
|
|
crc^=0xB8; |
|
|
}else{ |
|
|
crc>>=1; |
|
|
} |
|
|
} |
|
|
} |
|
|
NSMutableData *value = [NSMutableData dataWithBytes:&total length:2]; |
|
|
[value appendData:[NSData dataWithBytes:¤ length:2]]; |
|
|
[value appendData:[NSData dataWithBytes:&lenght length:2]]; |
|
|
[value appendData:[NSData dataWithBytes:&crc length:2]]; |
|
|
[value appendData:data]; |
|
|
BlueToothItem *item = [self getCmd:cmd value: value]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/// 推送表盘 |
|
|
/// @param cmd 命令类型 |
|
|
/// @param number 第几个表盘 |
|
|
/// @param type 0:删除表盘 1:增加表盘 2:更新表盘 |
|
|
/// @param fileLenght 文件大小 |
|
|
- (void)newDialPushWithBleCmdType:(BleCMD )cmd |
|
|
number:(NSInteger)number |
|
|
type:(NSInteger)type |
|
|
fileLenght:(NSInteger)fileLenght { |
|
|
Byte buffer[2]; |
|
|
buffer[0] = number; |
|
|
buffer[1] = type; |
|
|
NSMutableData *data = [NSMutableData dataWithBytes:buffer length:2]; |
|
|
[data appendData:[NSData dataWithBytes:&fileLenght length:4]]; |
|
|
BlueToothItem *item = [self getCmd:cmd value: data]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
体温检测设置 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param ONOFF 开关 |
|
|
@param startTime 开始时间 |
|
|
@param endTime 结束时间 |
|
|
@param interval 间隔时间 |
|
|
*/ |
|
|
- (void)setTemperatureCheckWithBleCmdType:(BleCMD )cmd |
|
|
RateONOFF:(BOOL)ONOFF |
|
|
StartTime:(NSString *)startTime |
|
|
EndTime:(NSString *)endTime |
|
|
Interval:(NSString *)interval { |
|
|
// 开始&&结束时间 |
|
|
NSArray *startArr = [startTime componentsSeparatedByString:@":"]; |
|
|
NSArray *endArr = [endTime componentsSeparatedByString:@":"]; |
|
|
Byte buffer[6]; |
|
|
buffer[0] = ONOFF; |
|
|
buffer[1] = [startArr[0] intValue]; |
|
|
buffer[2] = [startArr[1] intValue]; |
|
|
buffer[3] = [endArr[0] intValue]; |
|
|
buffer[4] = [endArr[1] intValue]; |
|
|
buffer[5] = [interval intValue]; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:6]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
/** |
|
|
根据类型获取对应数据 |
|
|
|
|
|
@param cmd 蓝牙指令类型 |
|
|
*/ |
|
|
- (NSDictionary *)dataFromCmd:(BleCMD)cmd { |
|
|
|
|
|
NSInteger bleCMDBranch;//小分类 |
|
|
NSInteger bleCMDMain;//常识性的注释 大分类 |
|
|
|
|
|
switch (cmd) { |
|
|
case BleCMD_setIngTime: // 时间设置 0X20 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0X20; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_bindingDevice: // 绑定请求 0X44 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0X44; |
|
|
bleCMDMain = 0X04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_cameraSwitch: // 拍照开关 0X46 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0X46; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
case BleCMD_cameraOFF: // 拍照退出 0X48 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0X48; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_syncContact: // 同步联系人 0X4B |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0X4C; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
// case BleCMD_watchWifi: // 手表WIFI 0X4C |
|
|
// { |
|
|
// |
|
|
// bleCMDBranch = 0x4c; |
|
|
// bleCMDMain = 0x04; |
|
|
// |
|
|
// } |
|
|
// break; |
|
|
|
|
|
case BleCMD_inputStart: // 协助输入开始 0X4D |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x4d; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_inputSend: // 发送协助输入 0X16 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x16; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_shearPlate: // 发送剪切板数据 0X17 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x17; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_inputEnd: // 协助输入结束 0X18 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x18; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_dialPush: // 表盘推送 0X4E |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x4E; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_urgentDial: // 紧急拨号 0X15 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x15; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_findDevice: // 查找设备 0X50 |
|
|
{ |
|
|
bleCMDBranch = 0x50; |
|
|
bleCMDMain = 0x05; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_syncHealth: // 同步健康数据指令 0xA0 |
|
|
{ |
|
|
bleCMDBranch = 0xA0; |
|
|
bleCMDMain = 0x0A; |
|
|
|
|
|
} |
|
|
break; |
|
|
case BleCMD_sportStateToDevice: //!< 运动状态同步到设备 0xB3 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0xB3; |
|
|
bleCMDMain = 0x0A; |
|
|
|
|
|
} |
|
|
break; |
|
|
case BleCMD_GPSSignalStrength: //!< GPS信号强度同步到设备 0xB5 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0xB5; |
|
|
bleCMDMain = 0x0A; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
|
|
|
case BleCMD_wifiPassWord: // WIFI需要密码 0x1A |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x1A; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_wifiLink: // 已保存的WIFI 0X1B |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x1B; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_wifiNoPassWord: // WIFI无需密码 0X1C |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x1C; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_firmwareUpdate: // 固件升级 0x10 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x10; |
|
|
bleCMDMain = 0x01; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_firmwareVersion: // 固件版本信息 0x12 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x12; |
|
|
bleCMDMain = 0x01; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setAlarmClock: // 闹钟设置 0x21 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x21; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setUserInfo: // 用户信息设置 0x23 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x23; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setTheLost: // 防丢设置 0x24 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x24; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setSedentary: // 久坐设置 0x25 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x25; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setSleep: // 自动睡眠设置 0x26 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x26; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setSystemUser: // 系统用户设置 0x27 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x27; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setDrinkRemind: // 喝水提醒设置 0x28 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x28; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_requestBattery: // 设备电量请求 0x40 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x40; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_unbundledDevice: // 解除绑定命令 0x42 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x42; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_relationDisplay: // 横竖显示 0x49 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x49; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_gesturesControl: // 抬手亮屏 0x4A |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x4A; |
|
|
bleCMDMain = 0x04; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_remindSwitch: // 提醒开关 0x60 |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x60; |
|
|
bleCMDMain = 0x06; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_notDisturb: // 勿扰模式 0x2A |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x2A; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_remindModel: // 提醒模式 0x2B |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0x2B; |
|
|
bleCMDMain = 0x02; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_realTimesync: |
|
|
{ |
|
|
|
|
|
bleCMDBranch = 0xB0; |
|
|
bleCMDMain = 0x0A; |
|
|
|
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setPush: // 推送设置 0x29 |
|
|
{ |
|
|
bleCMDBranch = 0x29; |
|
|
bleCMDMain = 0x02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_readBraceletSet: // 读取手环设置请求 0x2D |
|
|
{ |
|
|
bleCMDBranch = 0x2D; |
|
|
bleCMDMain = 0x02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_readProfile: // 读取手环配置请求 0x2E |
|
|
{ |
|
|
bleCMDBranch = 0x2E; |
|
|
bleCMDMain = 0x02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_setSportTarget: // 设置运动目标(手环使用) |
|
|
{ |
|
|
bleCMDBranch = 0x22; |
|
|
bleCMDMain = 0x02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_heartRateCheck: // 心率检测 |
|
|
{ |
|
|
bleCMDBranch = 0x2C; |
|
|
bleCMDMain = 0x02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_weatherPush: // 天气推送 |
|
|
{ |
|
|
bleCMDBranch = 0x30; |
|
|
bleCMDMain = 0x03; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_qrCodePush: // 二维码推送 |
|
|
{ |
|
|
bleCMDBranch = 0xE0; |
|
|
bleCMDMain = 0x0E; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_restoreFactory: // 恢复出厂 |
|
|
{ |
|
|
bleCMDBranch = 0xC7; |
|
|
bleCMDMain = 0x0C; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_weatherIndex: // 气象指数推送 |
|
|
{ |
|
|
bleCMDBranch = 0xE1; |
|
|
bleCMDMain = 0x0E; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_unitSetting: //单位设置 |
|
|
{ |
|
|
bleCMDBranch = 0x01; |
|
|
bleCMDMain = 0x02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_braceletPialPush: // 手环表盘推送 |
|
|
{ |
|
|
bleCMDBranch = 0xE2; |
|
|
bleCMDMain = 0x0E; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_dialRequest: // 表盘请求 0X4F |
|
|
{ |
|
|
bleCMDBranch = 0X4F; |
|
|
bleCMDMain = 0X04; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_breathe: //!< 呼吸设置 0x30 |
|
|
{ |
|
|
bleCMDBranch = 0X30; |
|
|
bleCMDMain = 0X02; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_falshSend: |
|
|
{ |
|
|
bleCMDBranch = 0X03; |
|
|
bleCMDMain = 0X14; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_newDialPush: |
|
|
{ |
|
|
bleCMDBranch = 0X05; |
|
|
bleCMDMain = 0X16; |
|
|
} |
|
|
break; |
|
|
|
|
|
case BleCMD_temperatureCheck: |
|
|
{ |
|
|
bleCMDBranch = 0X35; |
|
|
bleCMDMain = 0X02; |
|
|
} |
|
|
break; |
|
|
|
|
|
default: |
|
|
// 查找设备 0X50 |
|
|
bleCMDBranch = 0x50; |
|
|
bleCMDMain = 0x05; |
|
|
break; |
|
|
} |
|
|
return @{@"bleCMDBranch":@(bleCMDBranch),@"bleCMDMain":@(bleCMDMain)}; |
|
|
} |
|
|
|
|
|
|
|
|
#pragma mark ------------新协议 组建命令 |
|
|
|
|
|
- (BlueToothItem *)getCmd:(BleCMD)cmd value:(NSData *)buffer { |
|
|
|
|
|
// 序号 |
|
|
NSInteger sid = [self getSendCmdID]; |
|
|
|
|
|
// 命令类型 && key |
|
|
NSDictionary *dict = [self dataFromCmd:cmd]; |
|
|
NSInteger command = [dict[@"bleCMDMain"] integerValue]; |
|
|
NSInteger key = [dict[@"bleCMDBranch"] integerValue]; |
|
|
|
|
|
// 1.CRC计算 |
|
|
Byte cmdKeybyte[5]; |
|
|
cmdKeybyte[0] = command; |
|
|
cmdKeybyte[1] = LTwo_Version; |
|
|
cmdKeybyte[2] = key; |
|
|
cmdKeybyte[3] = (Byte)(buffer.length >> 8); |
|
|
cmdKeybyte[4] = (Byte)(buffer.length & 0xff); |
|
|
|
|
|
// L2层数据构建 |
|
|
NSMutableData *contentData = [NSMutableData new]; |
|
|
[contentData appendBytes:cmdKeybyte length:5]; |
|
|
[contentData appendData:buffer]; |
|
|
|
|
|
// 8位CRC计算 |
|
|
int crc = 0xff; |
|
|
for (int i = 0; i < contentData.length; i++) { |
|
|
crc^= ((Byte*)([contentData bytes]))[i] & 0xFF; |
|
|
for (int j = 0; j < 8; j++) { |
|
|
if((crc & 1) !=0){ |
|
|
crc >>=1; |
|
|
crc^=0xB8; |
|
|
}else{ |
|
|
crc>>=1; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//2.包头L1 (8bytes) |
|
|
Byte byte[8]; |
|
|
byte[0] = Identification;//识别标志 |
|
|
byte[1] = [BluetoothTool stitchWithErr:1 Ack:0 Vision:0]; |
|
|
byte[2] = (Byte)(contentData.length >> 8);//取高八位 |
|
|
byte[3] = (Byte)(contentData.length & 0xff);//取低八位 |
|
|
byte[4] = (Byte)(crc >> 8);//CRC 高八位 |
|
|
byte[5] = (Byte)(crc & 0xff);//CRC 低八位 |
|
|
byte[6] = (Byte)(sid >> 8);//序列号 高八位 |
|
|
byte[7] = (Byte)(sid & 0xff);//序列号 低八位 |
|
|
|
|
|
// 3.L2数据(5bytes+buffer) + L1 |
|
|
NSMutableData *data = [[NSMutableData alloc] initWithBytes:byte length:8]; |
|
|
[data appendData:contentData]; |
|
|
|
|
|
// 4.构建请求体 |
|
|
return [[BlueToothItem alloc] initWithbyteBuffer:data |
|
|
sid:sid |
|
|
cmd:cmd |
|
|
dataSource:self]; |
|
|
} |
|
|
|
|
|
/** |
|
|
序号 |
|
|
*/ |
|
|
- (NSInteger)getSendCmdID { |
|
|
static NSInteger nSendCmdID = 0; |
|
|
nSendCmdID ++; |
|
|
return nSendCmdID; |
|
|
} |
|
|
|
|
|
#pragma mark - BluetoothDelegate |
|
|
|
|
|
/** |
|
|
蓝牙指令成功回调 |
|
|
|
|
|
@param manager 蓝牙管理器 |
|
|
@param sid 请求需要 |
|
|
@param data 返回数据 |
|
|
@param cmdId 请求类型 |
|
|
*/ |
|
|
- (void)bluetoothManager:(Bluetooth *)manager |
|
|
sequenceID:(NSInteger)sid |
|
|
didCompleteWithData:(id)data |
|
|
cmdId:(BleCMD)cmdId { |
|
|
|
|
|
// 解析数据 |
|
|
// <ba30001c 1c800000 00000000 00000000 00000000 00070072 00000700 71000007 00730000> |
|
|
// 完整数据收到解析处理 |
|
|
//NSLog(@"我是接收到的完整数据 -------%@",data); |
|
|
|
|
|
NSDictionary *dict = [L2DataParse L2_ParseData:data type:cmdId]; |
|
|
|
|
|
if (IsDelegate(self.delegate, finishedHandle:data:cmd:)) { |
|
|
|
|
|
[self.delegate finishedHandle:self data:dict cmd:cmdId]; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
蓝牙指令失败回调 |
|
|
|
|
|
@param manager 蓝牙管理器 |
|
|
@param sid 请求需要 |
|
|
@param data 返回数据 |
|
|
@param cmdId 请求类型 |
|
|
*/ |
|
|
- (void)bluetoothManager:(Bluetooth *)manager |
|
|
sequenceID:(NSInteger)sid |
|
|
didErrorWithData:(id)data |
|
|
cmdId:(BleCMD)cmdId { |
|
|
|
|
|
if (IsDelegate(self.delegate, failedHandle:data:cmd:)) { |
|
|
|
|
|
[self.delegate failedHandle:self data:data cmd:cmdId]; |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
蓝牙指令超时回调 |
|
|
|
|
|
@param manager 蓝牙管理器 |
|
|
@param sid 请求需要 |
|
|
@param data 返回数据 |
|
|
@param cmdId 请求类型 |
|
|
*/ |
|
|
- (void)bluetoothManager:(Bluetooth *)manager |
|
|
sequenceID:(NSInteger)sid |
|
|
didTimeOutWithData:(id)data |
|
|
cmdId:(BleCMD)cmdId { |
|
|
|
|
|
if (IsDelegate(self.delegate, timeOutHandle:data:cmd:)) { |
|
|
|
|
|
[self.delegate timeOutHandle:self data:data cmd:cmdId]; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
表盘发送完成 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param pushType 推送类型 |
|
|
*/ |
|
|
- (void)braceletDialPushComplete:(BleCMD )cmd |
|
|
pushType:(NSInteger)pushType{ |
|
|
Byte buffer[1]; |
|
|
buffer[0] = pushType; |
|
|
NSData *completeData = [NSData dataWithBytes:buffer length:1]; |
|
|
[self braceletPialPush:cmd valuesData:completeData]; |
|
|
} |
|
|
|
|
|
/** |
|
|
发送表盘数据内容 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param pushType 推送类型 |
|
|
@param Offset 偏移 |
|
|
@param keep 保留 |
|
|
@param DialPushData 图的数据 |
|
|
*/ |
|
|
- (void)braceletDialPushData:(BleCMD )cmd |
|
|
pushType:(NSInteger)pushType |
|
|
offset:(NSInteger)Offset |
|
|
keep:(NSInteger)keep |
|
|
dialPushData:(NSData *)DialPushData{ |
|
|
Byte buffer[6]; |
|
|
buffer[0] = pushType; |
|
|
buffer[1] = (Offset >> 24) & 0xff; |
|
|
buffer[2] = (Offset >> 16) & 0xff; |
|
|
buffer[3] = (Offset >> 8) & 0xff; |
|
|
buffer[4] = Offset & 0xff; |
|
|
buffer[5] = keep & 0xff; |
|
|
NSMutableData *sendDialData = [NSMutableData dataWithBytes:buffer length:6]; |
|
|
[sendDialData appendData:DialPushData]; |
|
|
[self braceletPialPush:cmd valuesData:[NSData dataWithData:sendDialData]]; |
|
|
} |
|
|
|
|
|
/** |
|
|
手机推送表盘的信息 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param pushType 推送类型 |
|
|
@param dialID 表盘ID |
|
|
@param fileSize 文件大小 |
|
|
*/ |
|
|
- (void)braceletDialPush:(BleCMD )cmd |
|
|
pushType:(NSInteger)pushType |
|
|
dialID:(NSInteger)dialID |
|
|
fileSize:(NSInteger)fileSize{ |
|
|
Byte buffer[9]; |
|
|
buffer[0] = pushType; |
|
|
buffer[1] = (dialID >> 24) & 0xff; |
|
|
buffer[2] = (dialID >> 16) & 0xff; |
|
|
buffer[3] = (dialID >> 8) & 0xff; |
|
|
buffer[4] = dialID & 0xff; |
|
|
buffer[5] = (fileSize >> 24) & 0xff; |
|
|
buffer[6] = (fileSize >> 16) & 0xff; |
|
|
buffer[7] = (fileSize >> 8) & 0xff; |
|
|
buffer[8] = fileSize & 0xff; |
|
|
|
|
|
NSData *dialData = [NSData dataWithBytes:buffer length:9]; |
|
|
[self braceletPialPush:cmd valuesData:dialData]; |
|
|
|
|
|
} |
|
|
/** |
|
|
发送表盘命令 |
|
|
|
|
|
@param cmd 命令类型 |
|
|
@param valuesData 表盘数据 |
|
|
*/ |
|
|
- (void)braceletPialPush:(BleCMD )cmd |
|
|
valuesData:(NSData * )valuesData { |
|
|
BlueToothItem *item = [self getCmd:cmd value:valuesData]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
/** |
|
|
运动状态同步到设备 0xB3 |
|
|
*/ |
|
|
- (void)sportStateToDeviceWithBleCmdType:(BleCMD )cmd isOn:(int)on sportType:(int)sportType { |
|
|
Byte buffer[2]; buffer[0] = on; buffer[1] = sportType; |
|
|
BlueToothItem *item = [self getCmd:cmd value:[NSData dataWithBytes:buffer length:2]]; |
|
|
[self.blueTooth writeWithBleItem:item]; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 二维码识别 |
|
|
/// - Parameter qrcodeImage: 二维码图片 |
|
|
- (NSString *)readQRCodeFromImage:(UIImage *)qrcodeImage |
|
|
{ |
|
|
//if (qrcodeImage) |
|
|
{ |
|
|
//1. 初始化扫描仪,设置设别类型和识别质量 |
|
|
CIDetector*detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }]; |
|
|
//2. 扫描获取的特征组 |
|
|
NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:qrcodeImage.CGImage]]; |
|
|
//3. 获取扫描结果 |
|
|
CIQRCodeFeature *feature = [features objectAtIndex:0]; |
|
|
NSString *scannedResult = feature.messageString; |
|
|
NSLog(@"扫描到的结果 %@",scannedResult); |
|
|
return scannedResult; |
|
|
} |
|
|
} |
|
|
|
|
|
/// 杰里表盘推送 |
|
|
- (void)newJerryDialPush:(NSString *)path urlName:(NSString *)urlName fileData:(NSData *)fileData |
|
|
{ |
|
|
NSString *fileName = [NSString stringWithFormat:@"/%@",[self stringIntercepting:urlName]]; |
|
|
[JL_Tools removePath:path]; |
|
|
|
|
|
NSString *binPath = [JL_Tools createOn:NSDocumentDirectory MiddlePath:@"" File:[self stringIntercepting:urlName]]; |
|
|
[JL_Tools writeData:fileData fillFile:binPath]; |
|
|
NSData *pathData = [NSData dataWithContentsOfFile:binPath]; |
|
|
|
|
|
|
|
|
// NSString *fileName = [NSString stringWithFormat:@"/%@",[binPath lastPathComponent]]; |
|
|
NSLog(@"-->添加自定义表盘的路径:%@",binPath); |
|
|
NSLog(@"-->添加自定义表盘的大小:%lld",(long long)pathData.length); |
|
|
|
|
|
[DialManager listFile:^(DialOperateType type, NSArray * _Nullable array) { |
|
|
if (type == DialOperateTypeSuccess && array.count > 0) |
|
|
{ |
|
|
if ([array containsObject:[self stringIntercepting:urlName]]) |
|
|
{ |
|
|
[DialManager deleteFile:[NSString stringWithFormat:@"/%@",[self stringIntercepting:urlName]] Result:^(DialOperateType type, float progress) { |
|
|
if (type == DialOperateTypeSuccess) |
|
|
{ |
|
|
[self JerryDialPush:fileName pathData:pathData]; |
|
|
} |
|
|
}]; |
|
|
} |
|
|
else |
|
|
[self JerryDialPush:fileName pathData:pathData]; |
|
|
|
|
|
} |
|
|
}]; |
|
|
|
|
|
} |
|
|
- (void)JerryDialPush:(NSString *)fileName pathData:(NSData *)pathData |
|
|
{ |
|
|
[DialManager repaceFile:fileName Content:pathData Result:^(DialOperateType type, float progress) { |
|
|
if (type == DialOperateTypeNoSpace) { |
|
|
NSLog(@"空间不足"); |
|
|
// [SVProgressHUD dismiss]; |
|
|
// [SVProgressHUD showErrorWithStatus:@"空间不足"]; |
|
|
[DialManager listFile:^(DialOperateType type, NSArray * _Nullable array) { |
|
|
if (type == DialOperateTypeSuccess && array.count > 0) |
|
|
{ |
|
|
NSString *str = [NSString stringWithFormat:@"/%@",array[array.count-1]]; |
|
|
[DialManager deleteFile:str Result:^(DialOperateType type, float progress) { |
|
|
if (type == DialOperateTypeSuccess) |
|
|
[self JerryDialPush:fileName pathData:pathData]; |
|
|
|
|
|
}]; |
|
|
} |
|
|
}]; |
|
|
} |
|
|
if (type == DialOperateTypeFail) { |
|
|
NSLog(@"添加失败"); |
|
|
[SVProgressHUD dismiss]; |
|
|
[SVProgressHUD showErrorWithStatus:@"推送失败"]; |
|
|
} |
|
|
if (type == DialOperateTypeDoing) { |
|
|
[SVProgressHUD showWithStatus:[NSString stringWithFormat:@"%@:%.1f%%",NSLocalizedString(@"推送中", nil),progress*100.0f]]; |
|
|
} |
|
|
if (type == DialOperateTypeSuccess) { |
|
|
NSLog(@"添加完成"); |
|
|
[SVProgressHUD show]; |
|
|
//[SVProgressHUD showInfoWithStatus:@"添加完成"]; |
|
|
/*--- 更新缓存 ---*/ |
|
|
[self activeCustomWatch:fileName];//设置自定义表盘 |
|
|
} |
|
|
}]; |
|
|
} |
|
|
|
|
|
|
|
|
- (void)activeCustomWatch:(NSString *)fileName |
|
|
{ |
|
|
[[Bluetooth shareInstance].mAssist.mCmdManager.mFlashManager cmdWatchFlashPath:fileName Flag:JL_DialSettingActivateCustomDial |
|
|
Result:^(uint8_t flag, uint32_t size, |
|
|
NSString * _Nullable path, |
|
|
NSString * _Nullable describe) { |
|
|
[JL_Tools mainTask:^{ |
|
|
[SVProgressHUD showInfoWithStatus:NSLocalizedString((flag != 0) ? @"设置失败" : @"设置成功", nil)]; |
|
|
if (flag == 0) |
|
|
{ |
|
|
[[Bluetooth shareInstance].mAssist.mCmdManager.mFlashManager cmdWatchFlashPath:fileName Flag:JL_DialSettingSetDial Result:^(uint8_t flag, uint32_t size, NSString * _Nullable path, NSString * _Nullable describe) { |
|
|
|
|
|
}]; |
|
|
} |
|
|
}]; |
|
|
}]; |
|
|
} |
|
|
|
|
|
|
|
|
- (NSString *)stringIntercepting:(NSString *)filePath |
|
|
{ |
|
|
NSString *fileName = [NSString stringWithFormat:@"%@",[[NSFileManager defaultManager] displayNameAtPath:filePath]]; |
|
|
// if ([fileName hasSuffix:@".bin"]) |
|
|
// { |
|
|
// fileName = [fileName stringByReplacingOccurrencesOfString:@".bin" withString:@""]; |
|
|
// } |
|
|
if ([fileName containsString:@"_"]) |
|
|
{ |
|
|
if ([fileName hasSuffix:@".bin"]) |
|
|
fileName = [fileName selcteStringWithSelectSatrt:@"_" selecteEnd:@".bin"]; |
|
|
} |
|
|
|
|
|
return [fileName uppercaseString]; |
|
|
} |
|
|
|
|
|
|
|
|
@end
|
|
|
|