From 43f91fb6411537add6b28aeae2f325edc95c5fbf Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Fri, 26 Sep 2014 17:25:29 +0000 Subject: [PATCH] --- DUREX Vendor Control/CommunicationProtocol.h | 7 +++---- DUREX Vendor Control/CommunicationProtocol.m | 455 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate | Bin 247165 -> 0 bytes DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist | 80 +++++++++++++++++++++++++++++++++++++++----------------------------------------- DUREX Vendor Control/DateRangePickerViewController.m | 26 ++++++++++++++++---------- DUREX Vendor Control/MenuTableViewController.m | 3 ++- TODO | 9 ++++++--- 7 files changed, 303 insertions(+), 277 deletions(-) diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h index ec8b4d5..e047bc1 100644 --- a/DUREX Vendor Control/CommunicationProtocol.h +++ b/DUREX Vendor Control/CommunicationProtocol.h @@ -9,6 +9,7 @@ #import #import "EMFramework.h" +#define SLEEP_MS ((int)100) #define MAX_STRING_LENGTH ((int)200) #define MAX_RETRIES ((int)3) #define MAX_PRODUCT_NAME_LENGTH ((int)64) @@ -22,10 +23,8 @@ @interface CommunicationProtocol : NSObject --(Boolean) waitForMessageAvailableMobile: (Boolean) status; --(Boolean) waitForMessageAvailableDevice: (Boolean) status; --(Boolean) writeMessage: (NSString*) message; --(NSString*) readMessage; +-(void) writeMessage: (NSString*) message; +-(void) readMessage; -(Boolean) establishConnection; -(Boolean) updateTime: (NSDateComponents*) date; -(Boolean) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents; diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m index 2deea0b..1b5c157 100644 --- a/DUREX Vendor Control/CommunicationProtocol.m +++ b/DUREX Vendor Control/CommunicationProtocol.m @@ -12,6 +12,10 @@ @property Boolean messageAvailableMobile; @property Boolean messageAvailableDevice; +@property NSMutableString *message; +@property NSUInteger currentIndex; +@property NSUInteger remainingBytes; +@property NSInteger numPackets; @end @@ -29,269 +33,284 @@ return shared; } --(void) readMessageAvailableMobile +- (void) reportError : (NSString*) error { - [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue) - { - [self setMessageAvailableMobile:[readValue intValue]]; - if([self messageAvailableMobile]) - { - NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile read: TRUE"); - } - else - { - NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile read: FALSE"); - } - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - }]; + } --(void) readMessageAvailableDevice +-(void) readMessage { - [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue) - { - [self setMessageAvailableDevice:[readValue intValue]]; - if([self messageAvailableDevice]) - { - NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice read: TRUE"); - } - else - { - NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice read: FALSE"); - } - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - }]; + self.numPackets = -1; + [self waitForMessage]; } --(Boolean) waitForMessageAvailableMobile: (Boolean) status +- (void) readNextFragment { - uint8_t retries = 0; - [self readMessageAvailableMobile]; - while([self messageAvailableMobile] != status) + __block NSUInteger numBytes; + if(self.numPackets) { - [NSThread sleepForTimeInterval:5]; - [self readMessageAvailableMobile]; - if([self messageAvailableMobile] != status) + [[EMConnectionManager sharedManager] readResource:@"numBytes" onSuccess:^(id readValue) { - if(retries++ == MAX_RETRIES) + numBytes = [readValue unsignedCharValue]; + NSLog(@"[CommunicationProtocol.m]: numBytes read: %d",numBytes); + [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) { - NSLog(@"[CommunicationProtocol.m]: Timeout while waiting for answer"); - return FALSE; - } - } + NSString *readData = [readValue substringToIndex:numBytes]; + if([readValue length] < numBytes) + { + NSLog(@"[CommunicationProtocol.m]: WARNING: Device issued wrong numBytes, possible truncated message."); + } + [self.message appendString:readData]; + NSLog(@"[CommunicationProtocol.m]: data read: %@",readData); + [[EMConnectionManager sharedManager] writeValue:@"0" toResource:@"messageAvailableDevice" onSuccess:^ + { + NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice set to FALSE"); + NSLog(@"[CommunicationProtocol.m]: packet read"); + [self waitForMessage]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableDevice to FALSE: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On readData: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On readNumBytes: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; + } + else + { + //processMessage } - return TRUE; } --(Boolean) waitForMessageAvailableDevice: (Boolean) status +- (void) readNumPackets { - uint8_t retries = 0; - [self readMessageAvailableDevice]; - while([self messageAvailableDevice] != status) + [[EMConnectionManager sharedManager] readResource:@"numPackets" onSuccess:^(id readValue) { - [NSThread sleepForTimeInterval:5]; - [self readMessageAvailableDevice]; - if([self messageAvailableDevice] != status) - { - if(retries++ == MAX_RETRIES) - { - NSLog(@"[CommunicationProtocol.m]: Timeout while waiting for answer"); - return FALSE; - } - } - } - return TRUE; + self.numPackets = [readValue unsignedCharValue]; + NSLog(@"[CommunicationProtocol.m]: numPackets read: %d",self.numPackets); + [self readNextFragment]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On readNumPackets: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; } --(NSString*) readMessage +- (void) waitForMessage { - __block uint8_t numPackets = 1, numBytes; //HACK! - __block NSMutableString *message = [[NSMutableString alloc] init]; - [message setString:@""]; - //if([self waitForMessageAvailableDevice:TRUE]) - if(1) //HACK! - { - [[EMConnectionManager sharedManager] readResource:@"numPackets" onSuccess:^(id readValue) + NSLog(@"[CommunicationProtocol.m]: Reading messageAvailable from device"); + [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue) + { + [self setMessageAvailableDevice:[readValue intValue]]; + if(![self messageAvailableDevice]) { - numPackets = (uint8_t) [readValue unsignedCharValue]; - NSLog(@"[CommunicationProtocol.m]: numPackets read: %d",numPackets); + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying..."); + [NSThread sleepForTimeInterval:SLEEP_MS]; + [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue) + { + [self setMessageAvailableDevice:[readValue intValue]]; + if(![self messageAvailableDevice]) + { + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying..."); + [NSThread sleepForTimeInterval:SLEEP_MS]; + [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue) + { + [self setMessageAvailableDevice:[readValue intValue]]; + if(![self messageAvailableDevice]) + { + NSLog(@"[CommunicationProtocol.m]: Device not ready."); + NSLog(@"[CommunicationProtocol.m]: Timeout while expecting message"); + } + else + { + if(self.numPackets == -1) + { + [self readNumPackets]; + } + else + { + [self readNextFragment]; + } + } + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; + } + else + { + if(self.numPackets == -1) + { + [self readNumPackets]; + } + else + { + [self readNextFragment]; + } + } + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; } - onFail:^(NSError *error) + else { - NSLog(@"[CommunicationProtocol.m]: %@",error); - numPackets = 0; - }]; - if(numPackets) - { - for(int i = 0; i < numPackets; i++) - { - //if([self waitForMessageAvailableDevice:TRUE]) - if(1)//HACK! - { - [[EMConnectionManager sharedManager] readResource:@"numBytes" onSuccess:^(id readValue) - { - numBytes = (uint8_t) [readValue unsignedCharValue]; - NSLog(@"[CommunicationProtocol.m]: numBytes read: %d",numBytes); - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - numBytes = 0; - }]; - if(numBytes) - { - [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) - { - if([readValue length] < numBytes) - { - NSLog(@"[CommunicationProtocol.m]: WARNING: Device issued wrong numBytes, possible truncated message."); - } - [message appendString:[readValue substringToIndex:numBytes]]; - NSLog(@"[CommunicationProtocol.m]: data read: %@",message); - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - }]; - } - [[EMConnectionManager sharedManager] writeValue:@"0" toResource:@"messageAvailableDevice" onSuccess:^ - { - NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice set to FALSE"); - NSLog(@"[CommunicationProtocol.m]: packet read"); - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - } - ]; - } - else - { - NSLog(@"[CommunicationProtocol.m]: Error, resetting message"); - [message setString:@""]; - } - } - } - } - NSLog(@"[CommunicationProtocol.m]: Message received: %@",message); - return message; + if(self.numPackets == -1) + { + [self readNumPackets]; + } + else + { + [self readNextFragment]; + } + } + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + }]; } --(Boolean) writeMessage: (NSString*) message +-(void) writeMessage: (NSString*) message { - unsigned long remainingBytes = [message length]; - uint8_t numBytes, current_index = 0; - __block Boolean status = TRUE; //HACK - __block Boolean blockCompleted = TRUE; //HACK! - [[EMConnectionManager sharedManager] writeValue:@"0" toResource:@"messageAvailableMobile" onSuccess:^ - { - status = TRUE; - NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to FALSE"); - blockCompleted = TRUE; - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - status = FALSE; - blockCompleted = TRUE; - }]; - while(blockCompleted != TRUE) - { - [NSThread sleepForTimeInterval:1]; - } - NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile write block completed"); - blockCompleted = FALSE; + NSLog(@"[CommunicationProtocol.m]: Sending message: %@",message); + [self setMessage:[NSMutableString stringWithString:message]]; + [self setRemainingBytes:[message length]]; + [self setCurrentIndex:0]; [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithUnsignedChar:(unsigned char)([message length]/MAX_STRING_LENGTH)+1] toResource:@"numPackets" onSuccess:^ { - status = TRUE; NSLog(@"[CommunicationProtocol.m]: numPackets set to %u",([message length]/MAX_STRING_LENGTH) + 1); - } - onFail:^(NSError *error) + [self sendNextFragment]; + }onFail:^(NSError *error) { - NSLog(@"[CommunicationProtocol.m]: %@",error); - status = FALSE; - } - ]; - NSLog(@"[CommunicationProtocol.m]: status is: %d",status); - if(status != FALSE) + NSLog(@"[CommunicationProtocol.m]: On setNumPackets: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; +} + +- (void) sendNextFragment +{ + NSLog(@"[CommunicationProtocol.m]: Sending next fragment"); + [[EMConnectionManager sharedManager] writeValue:@"0" toResource:@"messageAvailableMobile" onSuccess:^ { - NSLog(@"[CommunicationProtocol.m]: Carrying on after numPackets..."); - while(remainingBytes) + NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to FALSE"); + NSUInteger numBytes; + if(self.remainingBytes) { - if(![self waitForMessageAvailableMobile:FALSE]) - { - status = FALSE; - break; - } - NSLog(@"[CommunicationProtocol.m]: Device is ready for next packet"); - if(remainingBytes > MAX_STRING_LENGTH) + if(self.remainingBytes > MAX_STRING_LENGTH) { numBytes = MAX_STRING_LENGTH; - remainingBytes -= MAX_STRING_LENGTH; + self.remainingBytes -= MAX_STRING_LENGTH; } else { - numBytes = remainingBytes; - remainingBytes = 0; + numBytes = self.remainingBytes; + self.remainingBytes = 0; } [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithUnsignedChar:(unsigned char)numBytes] toResource:@"numBytes" onSuccess:^ { NSLog(@"[CommunicationProtocol.m]: numBytes set to %d", numBytes); - status = TRUE; - } - onFail:^(NSError *error) + NSString *data = [self.message substringWithRange:NSMakeRange(self.currentIndex, numBytes)]; + self.currentIndex += numBytes; + [[EMConnectionManager sharedManager] writeValue:data toResource:@"data" onSuccess:^ + { + NSLog(@"[CommunicationProtocol.m]: data set to: %@",data); + [[EMConnectionManager sharedManager] writeValue:@"1" toResource:@"messageAvailableMobile" onSuccess:^ + { + NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to TRUE"); + NSLog(@"[CommunicationProtocol.m]: Packet written"); + [self readACK]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setMessageAvailable to TRUE: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setData: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; + }onFail:^(NSError *error) { - NSLog(@"[CommunicationProtocol.m]: %@",error); - status = FALSE; - } - ]; - if(status != FALSE) + NSLog(@"[CommunicationProtocol.m]: On setNumBytes: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; + } + else + { + [self readMessage]; + } + + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableMobile to FALSE: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; +} + +- (void) readACK +{ + NSLog(@"[CommunicationProtocol.m]: Reading ACK from device"); + [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue) + { + [self setMessageAvailableMobile:[readValue intValue]]; + if([self messageAvailableMobile]) + { + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying..."); + [NSThread sleepForTimeInterval:SLEEP_MS]; + [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue) { - NSLog(@"[CommunicationProtocol.m]: Carrying on after numBytes..."); - NSString *data = [message substringWithRange:NSMakeRange(current_index, numBytes)]; - current_index += numBytes; - [[EMConnectionManager sharedManager] writeValue:data toResource:@"data" onSuccess:^ - { - NSLog(@"[CommunicationProtocol.m]: data set to: %@",data); - status = TRUE; - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - status = FALSE; - } - ]; - if(status != FALSE) + [self setMessageAvailableMobile:[readValue intValue]]; + if([self messageAvailableMobile]) { - NSLog(@"[CommunicationProtocol.m]: Carrying on after data..."); - [[EMConnectionManager sharedManager] writeValue:@"1" toResource:@"messageAvailableMobile" onSuccess:^ - { - status = TRUE; - NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to TRUE"); - NSLog(@"[CommunicationProtocol.m]: Packet written"); - } - onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: %@",error); - status = FALSE; - } - ]; - NSLog(@"[CommunicationProtocol.m]: Carrying on after messageAvailableMobile..."); + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying..."); + [NSThread sleepForTimeInterval:SLEEP_MS]; + [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue) + { + [self setMessageAvailableMobile:[readValue intValue]]; + if([self messageAvailableMobile]) + { + NSLog(@"[CommunicationProtocol.m]: Device not ready."); + NSLog(@"[CommunicationProtocol.m]: Timeout while expecting ACK"); + } + else + { + [self sendNextFragment]; + } + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; } - } + else + { + [self sendNextFragment]; + } + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; } - } - if(![self waitForMessageAvailableMobile:FALSE]) + else + { + [self sendNextFragment]; + } + }onFail:^(NSError *error) { - NSLog(@"[CommunicationProtocol.m]: Device has processed the message"); - } - return status; + NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; } -(Boolean) establishConnection diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate index f42b4f9..4973f42 100644 Binary files a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate and b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 2816d05..3dbf2ba 100644 --- a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -74,12 +74,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "432263020.427289" + timestampString = "433360607.314289" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "362" - endingLineNumber = "362" - landmarkName = "-readSensorData" + startingLineNumber = "363" + endingLineNumber = "363" + landmarkName = "-readNextFragment" landmarkType = "5"> @@ -90,12 +90,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "432263020.427289" + timestampString = "433360607.314289" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "361" - endingLineNumber = "361" - landmarkName = "-readSensorData" + startingLineNumber = "362" + endingLineNumber = "362" + landmarkName = "-readNextFragment" landmarkType = "5"> @@ -106,12 +106,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "432263020.427289" + timestampString = "433360607.314289" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "380" - endingLineNumber = "380" - landmarkName = "-readSensorData" + startingLineNumber = "381" + endingLineNumber = "381" + landmarkName = "-readNextFragment" landmarkType = "5"> @@ -201,22 +201,6 @@ shouldBeEnabled = "No" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "CommunicationProtocol.m" - timestampString = "432263020.427289" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "213" - endingLineNumber = "213" - landmarkName = "-writeMessage:" - landmarkType = "5"> - - - - @@ -538,11 +522,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "DateRangePickerViewController.m" - timestampString = "432833512.682389" + timestampString = "433360688.202825" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "155" - endingLineNumber = "155" + startingLineNumber = "159" + endingLineNumber = "159" landmarkName = "-toggleToDate:" landmarkType = "5"> @@ -554,11 +538,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "DateRangePickerViewController.m" - timestampString = "432833512.682389" + timestampString = "433360688.202825" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "154" - endingLineNumber = "154" + startingLineNumber = "158" + endingLineNumber = "158" landmarkName = "-toggleToDate:" landmarkType = "5"> @@ -602,14 +586,28 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "DateRangePickerViewController.m" - timestampString = "432833363.738094" + timestampString = "433360688.202825" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "102" - endingLineNumber = "102" - landmarkName = "-resizeViewHeight::" + startingLineNumber = "141" + endingLineNumber = "141" + landmarkName = "-toggleFromDate:" landmarkType = "5"> + + + + diff --git a/DUREX Vendor Control/DateRangePickerViewController.m b/DUREX Vendor Control/DateRangePickerViewController.m index e4a0e0a..1803ec1 100644 --- a/DUREX Vendor Control/DateRangePickerViewController.m +++ b/DUREX Vendor Control/DateRangePickerViewController.m @@ -11,6 +11,7 @@ @interface DateRangePickerViewController () @property uint8_t isExtended; +@property NSUInteger currentHeight; @end @@ -40,6 +41,8 @@ [self setIsExtended:0]; + [self setCurrentHeight:[self scrollView].frame.size.height]; + [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } @@ -97,19 +100,19 @@ [UIView commitAnimations]; } -- (void) resizeViewHeight : (UIView*) view : (NSInteger) height +- (void) resizeViewHeight : (UIView*) view : (NSInteger) height : (Boolean) ignoreHeight { CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenHeight = screenRect.size.height; - if((view.frame.size.height + height > screenHeight) && (height > 0)) + if((height > screenHeight) && !ignoreHeight) { NSLog(@"[DateRangePickerViewController.m]: Screen height limit reached"); } - else if(((height < 0) && ([self isExtended] != 0)) || ((height > 0) && ([self isExtended] != 2))) + else { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; - view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width,view.frame.size.height + height); + view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width,height); [UIView commitAnimations]; } if(height < 0) @@ -120,8 +123,7 @@ { [self setIsExtended: [self isExtended] + 1]; } - [self.scrollView setContentSize:CGSizeMake([self scrolledView].frame.size.width,[self scrolledView].frame.size.height)]; - NSLog(@"ScrollView height: %f",[self scrollView].frame.size.height); + [self.scrollView setContentSize:CGSizeMake([self scrolledView].frame.size.width,[self currentHeight])]; } - (IBAction)toggleFromDate:(id)sender @@ -135,7 +137,8 @@ [self moveDown:[self toDate] :height]; [self moveDown:[self doneButton] :height]; [self moveDown:[self toLabel] :height]; - [self resizeViewHeight : [self scrollView] : height + 20]; + [self setCurrentHeight:[self currentHeight] + height + 20]; + [self resizeViewHeight : [self scrollView] : [self currentHeight] : FALSE]; } else { @@ -145,7 +148,8 @@ [self moveUp:[self toDate] :height]; [self moveUp:[self doneButton] :height]; [self moveUp:[self toLabel] :height]; - [self resizeViewHeight : [self scrollView] : - height - 20]; + [self setCurrentHeight:[self currentHeight] - height - 20]; + [self resizeViewHeight : [self scrollView] : [self currentHeight] : FALSE]; } } - (IBAction)toggleToDate:(id)sender @@ -156,14 +160,16 @@ [[self toDate] setEnabled:TRUE]; [[self toDate] setHidden:FALSE]; [self moveDown:[self doneButton] :height]; - [self resizeViewHeight : [self scrollView] : height + 20]; + [self setCurrentHeight:[self currentHeight] + height + 20]; + [self resizeViewHeight : [self scrollView] : [self currentHeight] : FALSE]; } else { [[self toDate] setEnabled:FALSE]; [[self toDate] setHidden:TRUE]; [self moveUp:[self doneButton] :height]; - [self resizeViewHeight : [self scrollView] : - height - 20]; + [self setCurrentHeight:[self currentHeight] - height - 20]; + [self resizeViewHeight : [self scrollView] : [self currentHeight] : FALSE]; } } diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m index df68321..6288c2a 100644 --- a/DUREX Vendor Control/MenuTableViewController.m +++ b/DUREX Vendor Control/MenuTableViewController.m @@ -333,7 +333,8 @@ { if ([[EMConnectionManager sharedManager] connectionState] == EMConnectionStateDisrupted) { - [[self navigationController] popToRootViewControllerAnimated:YES]; + UIViewController *previous = [[[self navigationController] viewControllers] objectAtIndex:[[[self navigationController] viewControllers] count]-2]; + [[self navigationController] popToViewController:previous animated:YES]; } } } diff --git a/TODO b/TODO index a932eb2..a983e02 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,16 @@ +TESTS: +- Test disconnection + BUGS: - On date change, response is overwritten by previous query, trimming needed according to numBytes TODO: - -- Reimplement protocol with async pattern -- Handle disconnects properly +- processMessage with Delegate +- Error reporting function - Incident class - Incident parser - A3 command +- BYE command - Channels and codes to 2 ciphers - Add landscape layout and inverted layout - Month/Year headers on sale list -- libgit2 0.22.2