50毫秒触发一次的方法。当我发完1024数据就跳出timer
{
dataCount = 0;
packageCount ++;
com.buff[0] = 0x55;
com.buff[1] = 0xaa;
com.buff[2] = 0x01;
com.buff[3] = 0x01;
com.buff[4] = packageCount;
chk = com.buff[0]+com.buff[1]+com.buff[2]+com.buff[3]+com.buff[4];
for (int i = 5; i < 1029; i++) {
if ([fileDataArray count]) {
int value;
sscanf([[fileDataArray firstObject] cStringUsingEncoding:NSUTF8StringEncoding], "%X", &value);
com.buff = value;
chkTemp += com.buff;
[fileDataArray removeObjectAtIndex:0];
}
chk += com.buff;
}
for (int i = 1029; i < 1039; i++) {
chk += com.buff;
}
com.buff[1039] = chk;
sendTimer = [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(sendDataPackage) userInfo:nil repeats:YES];
}
{
Command commandData;
for (int i = 0; i < 20; i++) {
commandData.buff = com.buff[dataCount];
dataCount++;
if (dataCount == 1040) {
[sendTimer invalidate];
}
}
NSData* data = [[NSData alloc] initWithBytes:(char *)&commandData.buff length:20];
[self write:selectPeripheral data:data];
if ([delegate respondsToSelector:@selector(onUploadProgress:totalParts:Package:)]) {
[delegate onUploadProgress:((1040.0*packageCount)+dataCount)/(1040.0*totalPackage) totalParts:1040*totalPackage Package:packageCount];
}
}