Skip to content

Commit

Permalink
add timeout to cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandra Keßler committed Apr 19, 2016
1 parent 0a9f9aa commit 9ad6a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Pod/Classes/blueReader.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ @interface BlueReader () <UARTPeripheralDelegate,CBCentralManagerDelegate>
@property NSMutableArray* cmds;
@property BOOL handlingCmd;
@property NSString* incompleteAnswer;
@property NSTimer* timerout;

@end

@implementation BlueReader
Expand Down Expand Up @@ -138,6 +140,8 @@ - (void) centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBP
self.currentPeripheral = nil;
self.cmds = nil;
self.handlingCmd = NO;
self.incompleteAnswer=nil;

self.readerStatus = UNKNOWN;
}
}
Expand Down Expand Up @@ -261,6 +265,16 @@ -(void) identifyReader
[self handleCmd];
}

-(void) failed
{
NSLog(@"failed to complete cmd %@ withhin timeout",[self.cmds objectAtIndex:0]);
[[self cmds] removeAllObjects];
self.handlingCmd = NO;
self.incompleteAnswer=nil;

[self closeConnection];
}

-(void) handleCmd
{
if(self.handlingCmd)
Expand All @@ -277,6 +291,7 @@ -(void) handleCmd
NSString* firstCMD = [self.cmds objectAtIndex:0];
[self.currentPeripheral writeString:firstCMD];
self.handlingCmd = YES;
_timerout = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(failed) userInfo:nil repeats:NO];
}
}

Expand Down Expand Up @@ -335,13 +350,17 @@ -(void) didReceiveData:(NSString *)string
{
foundStart = YES;
isOK = YES;
[_timerout invalidate];
_timerout = nil;
}
break;
case '-':
if(!foundStart)
{
foundStart = YES;
isOK = NO;
[_timerout invalidate];
_timerout = nil;
}
break;
case '!':
Expand Down
2 changes: 1 addition & 1 deletion libBlueReader.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "libBlueReader"
s.version = "0.0.6"
s.version = "0.0.7"
s.summary = "libBlueReader is the companion library to the open-source blueReader Hardware"
s.description = <<-DESC
The blueReader NFC-BLE-Adapter is a ready to buy or diy Hardware for reading and writing nfc-tags via a bluetooth enabled Device. This library implements the interfaces for iOS to find a blueReader Bluetooth device, configure the device, and read/ write Tags
Expand Down

0 comments on commit 9ad6a61

Please sign in to comment.