From 8a75e25170426a632d7e86f96edfa503db78312e Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Fri, 3 Oct 2014 17:26:39 +0000 Subject: [PATCH] --- DUREX Vendor Control/CommunicationProtocol.h | 23 ++++++++++++++++------- DUREX Vendor Control/CommunicationProtocol.m | 255 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate | Bin 154212 -> 0 bytes DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m | 2 +- DUREX Vendor Control/MenuTableViewController.h | 12 +++++++++++- DUREX Vendor Control/MenuTableViewController.m | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------- TODO | 2 +- 8 files changed, 273 insertions(+), 334 deletions(-) diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h index e047bc1..4e24ad8 100644 --- a/DUREX Vendor Control/CommunicationProtocol.h +++ b/DUREX Vendor Control/CommunicationProtocol.h @@ -6,10 +6,12 @@ // Copyright (c) 2014 Emmoco. All rights reserved. // +@class CommunicationProtocol; + #import #import "EMFramework.h" -#define SLEEP_MS ((int)100) +#define SLEEP_TIME ((NSTimeInterval)0.1) #define MAX_STRING_LENGTH ((int)200) #define MAX_RETRIES ((int)3) #define MAX_PRODUCT_NAME_LENGTH ((int)64) @@ -21,16 +23,23 @@ #define SALE_STRING_LENGTH ((int)36) #define REPORT_SERVER_URL @"http://seneca.upc.es:8090/machine" +@protocol CommunicationProtocolDelegate +- (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response; + +@end + @interface CommunicationProtocol : NSObject +@property (nonatomic, strong) id delegate; + -(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; --(Boolean) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name; --(NSString*) readSensorData; --(NSString*) readSalesLog: (NSDateComponents*) start : (NSDateComponents*) end; +-(void) establishConnection; +-(void) updateTime: (NSDateComponents*) date; +-(void) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents; +-(void) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name; +-(void) readSensorData; +-(void) readSalesLog: (NSDateComponents*) start : (NSDateComponents*) end; +(id) sharedProtocol; @end diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m index 1b5c157..c7a9f7b 100644 --- a/DUREX Vendor Control/CommunicationProtocol.m +++ b/DUREX Vendor Control/CommunicationProtocol.m @@ -41,7 +41,7 @@ -(void) readMessage { self.numPackets = -1; - [self waitForMessage]; + [self waitForMessage: 0]; } - (void) readNextFragment @@ -66,7 +66,7 @@ { NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice set to FALSE"); NSLog(@"[CommunicationProtocol.m]: packet read"); - [self waitForMessage]; + [self waitForMessage: 0]; }onFail:^(NSError *error) { NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableDevice to FALSE: %@",error); @@ -85,7 +85,7 @@ } else { - //processMessage + [[self delegate] processMessage:self didFinishEnteringItem:self.message]; } } @@ -103,81 +103,42 @@ }]; } -- (void) waitForMessage +- (void) waitForMessage: (uint8_t) retries { - NSLog(@"[CommunicationProtocol.m]: Reading messageAvailable from device"); - [[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. 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]]]; - }]; - } - 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]]]; - }]; + if(retries == MAX_RETRIES) + { + NSLog(@"[CommunicationProtocol.m]: Device not ready."); + NSLog(@"[CommunicationProtocol.m]: Timeout while expecting message"); + } + else + { + NSLog(@"[CommunicationProtocol.m]: Reading messageAvailable from device"); + [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue) + { + [self setMessageAvailableDevice:[readValue intValue]]; + if(![self messageAvailableDevice]) + { + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying..."); + [NSThread sleepForTimeInterval:SLEEP_TIME]; + [self waitForMessage:retries + 1]; + } + 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]]]; + }]; + } } -(void) writeMessage: (NSString*) message @@ -228,7 +189,7 @@ { NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to TRUE"); NSLog(@"[CommunicationProtocol.m]: Packet written"); - [self readACK]; + [self readACK: 0]; }onFail:^(NSError *error) { NSLog(@"[CommunicationProtocol.m]: On setMessageAvailable to TRUE: %@",error); @@ -247,6 +208,7 @@ } else { + NSLog(@"[CommunicationProtocol.m]: Finished sending message"); [self readMessage]; } @@ -257,81 +219,45 @@ }]; } -- (void) readACK +- (void) readACK: (uint8_t) retries { - NSLog(@"[CommunicationProtocol.m]: Reading ACK from device"); - [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue) + if(retries == MAX_RETRIES) { - [self setMessageAvailableMobile:[readValue intValue]]; - if([self messageAvailableMobile]) + NSLog(@"[CommunicationProtocol.m]: Device not ready."); + NSLog(@"[CommunicationProtocol.m]: Timeout while expecting ACK"); + } + else + { + NSLog(@"[CommunicationProtocol.m]: Reading ACK from device"); + [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue) { - 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]) { - [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) - { - [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]: Device not ready. Retrying..."); + [NSThread sleepForTimeInterval:SLEEP_TIME]; + [self readACK:retries + 1]; + } + else { - 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) { - [self sendNextFragment]; - } - }onFail:^(NSError *error) - { - NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; - }]; + NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error); + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + }]; + } } --(Boolean) establishConnection +-(void) establishConnection { NSLog(@"[CommunicationProtocol.m]: Establishing connection..."); - if([self writeMessage:@"Hello"]) - { - NSLog(@"[CommunicationProtocol.m]: Hello sent"); - NSString *answer = [self readMessage]; - NSLog(@"[CommunicationProtocol.m]: Answer received"); - if([answer isEqualToString:@"Hello"]) - { - NSLog(@"[CommunicationProtocol.m]: Connection established"); - return TRUE; - } - } - NSLog(@"[CommunicationProtocol.m]: Error while establishing connection"); - return TRUE; //HACK! + [self writeMessage:@"Hello"]; + NSLog(@"[CommunicationProtocol.m]: Hello sent"); } --(Boolean) updateTime: (NSDateComponents*) date +-(void) updateTime: (NSDateComponents*) date { NSMutableString *command = [NSMutableString stringWithFormat: @"A5"]; NSInteger year = [date year]; @@ -339,27 +265,15 @@ [command appendString:[NSString stringWithFormat:@"%02ld",(long)year]]; [command appendString:[NSString stringWithFormat:@"%02ld%02ld%02ld%02ld%02ld",(long)[date month],(long)[date day],(long)[date hour],(long)[date minute],(long)[date second]]]; [self writeMessage:command]; - NSString *answer = [self readMessage]; - if([answer isEqualToString:@"P51"]) - { - return TRUE; - } - return FALSE; } --(Boolean) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents +-(void) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents { NSMutableString *command = [NSMutableString stringWithFormat: @"A6%01d%01d%02d%02d",channel,product,eur,cents]; [self writeMessage:command]; - NSString *answer = [self readMessage]; - if([answer isEqualToString:@"P61"]) - { - return TRUE; - } - return FALSE; } --(Boolean) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name +-(void) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name { if([name length] > MAX_PRODUCT_NAME_LENGTH) { @@ -367,21 +281,14 @@ } NSMutableString *command = [NSMutableString stringWithFormat: @"A7%01d%01d%@",channel,product,name]; [self writeMessage:command]; - NSString *answer = [self readMessage]; - if([answer isEqualToString:@"P71"]) - { - return TRUE; - } - return FALSE; } --(NSString*) readSensorData +-(void) readSensorData { NSString *command = @"A4"; [self writeMessage:command]; - //NSString *answer = [self readMessage]; - NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400015000150001500000001001003005002000001002"]; + /*NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400015000150001500000001001003005002000001002"]; for(int i = 0; i < 4; i++) { [answer appendString:@"0"]; @@ -394,17 +301,10 @@ } [answer appendString:@"0"]; - [answer appendString:@"0"]; - - if([answer length] > 1 && [[answer substringToIndex:2]isEqualToString:@"P4"]) - { - NSLog(@"[CommunicationProtocol.m]: sensorStatus returned: %@",answer); - return answer; - } - return nil; + [answer appendString:@"0"];*/ } --(NSString*) readSalesLog : (NSDateComponents*) start : (NSDateComponents*) end +-(void) readSalesLog : (NSDateComponents*) start : (NSDateComponents*) end { NSMutableString *startDate = [NSMutableString stringWithString:@""]; NSMutableString *endDate = [NSMutableString stringWithString:@""]; @@ -435,15 +335,8 @@ [command appendString:@"-"]; [command appendString:endDate]; [self writeMessage:command]; - //NSString *answer = [self readMessage]; - NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21408161036000001000000110450000001P21409012216000100000000220900000100P21409032307000000010502330800000000P21409070540000000020000440350000001P2P2"]; - if([answer length] > 1 && [[answer substringToIndex:2]isEqualToString:@"P2"]) - { - NSLog(@"[CommunicationProtocol.m]: saleLog returned: %@",answer); - return answer; - } - return nil; + //NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21408161036000001000000110450000001P21409012216000100000000220900000100P21409032307000000010502330800000000P21409070540000000020000440350000001P2P2"]; } @end 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 4973f42..031775c 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 3dbf2ba..ceaab41 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 @@ -26,11 +26,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "717" - endingLineNumber = "717" + startingLineNumber = "770" + endingLineNumber = "770" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -42,11 +42,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "659" - endingLineNumber = "659" + startingLineNumber = "712" + endingLineNumber = "712" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -58,11 +58,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265052.909736" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "511" - endingLineNumber = "511" + startingLineNumber = "571" + endingLineNumber = "571" landmarkName = "-tableView:didSelectRowAtIndexPath:" landmarkType = "5"> @@ -74,12 +74,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "433360607.314289" + timestampString = "434038085.179085" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "363" - endingLineNumber = "363" - landmarkName = "-readNextFragment" + startingLineNumber = "341" + endingLineNumber = "341" + landmarkName = "-updateProductName:::" landmarkType = "5"> @@ -90,12 +90,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "433360607.314289" + timestampString = "434038085.179085" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "362" - endingLineNumber = "362" - landmarkName = "-readNextFragment" + startingLineNumber = "340" + endingLineNumber = "340" + landmarkName = "-updateProductName:::" landmarkType = "5"> @@ -106,12 +106,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "433360607.314289" + timestampString = "434038085.179085" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "381" - endingLineNumber = "381" - landmarkName = "-readNextFragment" + startingLineNumber = "353" + endingLineNumber = "353" + landmarkName = "-readSensorData" landmarkType = "5"> @@ -186,11 +186,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "768" - endingLineNumber = "768" + startingLineNumber = "821" + endingLineNumber = "821" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -202,27 +202,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432263020.427289" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "92" - endingLineNumber = "92" - landmarkName = "-generateMaintenanceLevel" - landmarkType = "5"> - - - - @@ -234,11 +218,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265052.909736" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "117" - endingLineNumber = "117" + startingLineNumber = "108" + endingLineNumber = "108" landmarkName = "-generateSaleListNavLevel" landmarkType = "5"> @@ -250,11 +234,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265052.909736" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "125" - endingLineNumber = "125" + startingLineNumber = "116" + endingLineNumber = "116" landmarkName = "-generateSaleListNavLevel" landmarkType = "5"> @@ -266,11 +250,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265052.909736" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "197" - endingLineNumber = "197" + startingLineNumber = "188" + endingLineNumber = "188" landmarkName = "-changeNavLevel::" landmarkType = "5"> @@ -282,11 +266,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265052.909736" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "496" - endingLineNumber = "496" + startingLineNumber = "556" + endingLineNumber = "556" landmarkName = "-tableView:numberOfRowsInSection:" landmarkType = "5"> @@ -298,11 +282,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "644" - endingLineNumber = "644" + startingLineNumber = "697" + endingLineNumber = "697" landmarkName = "-tableView:indentationLevelForRowAtIndexPath:" landmarkType = "5"> @@ -314,11 +298,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "664" - endingLineNumber = "664" + startingLineNumber = "717" + endingLineNumber = "717" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -330,11 +314,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "857" - endingLineNumber = "857" + startingLineNumber = "910" + endingLineNumber = "910" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -346,11 +330,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "858" - endingLineNumber = "858" + startingLineNumber = "911" + endingLineNumber = "911" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -378,11 +362,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "977" - endingLineNumber = "977" + startingLineNumber = "1030" + endingLineNumber = "1030" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -394,11 +378,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265052.909736" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "452" - endingLineNumber = "452" + startingLineNumber = "512" + endingLineNumber = "512" landmarkName = "-toggleDropList:" landmarkType = "5"> @@ -410,11 +394,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1062" - endingLineNumber = "1062" + startingLineNumber = "1115" + endingLineNumber = "1115" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -426,11 +410,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1054" - endingLineNumber = "1054" + startingLineNumber = "1107" + endingLineNumber = "1107" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -442,11 +426,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "849" - endingLineNumber = "849" + startingLineNumber = "902" + endingLineNumber = "902" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -458,11 +442,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "847" - endingLineNumber = "847" + startingLineNumber = "900" + endingLineNumber = "900" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -474,11 +458,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432265160.899922" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "708" - endingLineNumber = "708" + startingLineNumber = "761" + endingLineNumber = "761" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -554,11 +538,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432823134.280139" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1176" - endingLineNumber = "1176" + startingLineNumber = "1230" + endingLineNumber = "1230" landmarkName = "-passDateRangeViewController:didFinishEnteringItem::" landmarkType = "5"> @@ -570,11 +554,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "432823146.488089" + timestampString = "434037601.622012" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1159" - endingLineNumber = "1159" + startingLineNumber = "1215" + endingLineNumber = "1215" landmarkName = "-passDateRangeViewController:didFinishEnteringItem::" landmarkType = "5"> diff --git a/DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m b/DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m index c0b1605..fd7cd66 100644 --- a/DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m +++ b/DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m @@ -106,7 +106,7 @@ -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [self performSegueWithIdentifier:@"ConnectionSegue" sender:self]; + //[self performSegueWithIdentifier:@"ConnectionSegue" sender:self]; if(![[[[tableView cellForRowAtIndexPath:indexPath] textLabel] text] isEqualToString:NSLocalizedString(@"Searching for devices...",nil)]) { [self _showConnectingView]; diff --git a/DUREX Vendor Control/MenuTableViewController.h b/DUREX Vendor Control/MenuTableViewController.h index 2aa92f9..7325dc2 100644 --- a/DUREX Vendor Control/MenuTableViewController.h +++ b/DUREX Vendor Control/MenuTableViewController.h @@ -57,11 +57,21 @@ enum { } navigationLevel; enum { + HELLO = 0, + A2, + A3, + A4, + A5, + A6, + A7, +} commandTypes; + +enum { SALES_LOG = 0, INCIDENT_LOG, } logType; -@interface MenuTableViewController : UITableViewController +@interface MenuTableViewController : UITableViewController @property (strong,nonatomic) Stack *parentLayout; @property (strong,nonatomic) DatePickerViewController *datePickerViewController; diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m index 6288c2a..701843a 100644 --- a/DUREX Vendor Control/MenuTableViewController.m +++ b/DUREX Vendor Control/MenuTableViewController.m @@ -43,6 +43,7 @@ @property const NSMutableArray *currentHeaders; @property uint8_t requestedLog; +@property uint8_t sentCommand; @end @implementation MenuTableViewController @@ -84,18 +85,9 @@ [self setCellIdentifiers:[[NSArray alloc] initWithObjects:CELL_IDENTIFIERS, nil]]; } -- (Boolean) generateMaintenanceLevel +- (void) generateMaintenanceLevel { //Initialize sensor status - [self setSensorStatus:[[Sensors alloc]init]]; - - NSString *sensorData = [_protocol readSensorData]; - if(sensorData == nil) - { - NSLog(@"[MenuTableViewController.m]: Error reading sensor data"); - return FALSE; - } - [[self sensorStatus] setResponseValue:sensorData]; [self setMaintenanceElements:[[NSMutableArray alloc] initWithObjects:MAINTENANCE_ELEMENTS, nil]]; [self setMaintenanceStructure:[[NSMutableArray alloc] initWithObjects:MAINTENANCE_CELLS_PER_SECTION, nil]]; if([[self maintenanceStructure] count] > 1) @@ -106,7 +98,6 @@ { [self setMaintenanceHeaders:nil]; } - return TRUE; } - (void) generateSaleListNavLevel @@ -263,6 +254,87 @@ [self.view makeToast:NSLocalizedString(@"Connection to server failed", nil) duration:3 position:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)] title:NSLocalizedString(@"Error", nil) image:[UIImage imageNamed:@"icon_delete"]]; } +- (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response +{ + NSLog(@"[MenuTableViewController.m]: Answer received"); + if(self.sentCommand == HELLO) + { + if([response isEqualToString:@"Hello"]) + { + NSLog(@"[MenuTableViewController.m]: Connection established"); + [self changeNavLevel:MENU:FALSE]; + } + else + { + NSLog(@"[CommunicationProtocol.m]: Error while establishing connection"); + UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication error",nil) message:NSLocalizedString(@"Error while trying to connect to the device",nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil]; + [alert show]; + UIViewController *previous = [[[self navigationController] viewControllers] objectAtIndex:[[[self navigationController] viewControllers] count]-2]; + [[self navigationController] popToViewController:previous animated:YES]; + } + } + else if(self.sentCommand == A2 && [[response substringToIndex:2]isEqualToString:@"P2"]) + { + NSLog(@"[MenuTableViewController.m]: Received A2 answer"); + [self setSalesLog:[[SalesLog alloc]init]]; + [[self salesLog] setResponseValue:response]; + [self generateSaleListNavLevel]; + [self changeNavLevel:SALE_LIST:TRUE]; + } + else if(self.sentCommand == A3 && [[response substringToIndex:2]isEqualToString:@"P3"]) + { + + } + else if(self.sentCommand == A4 && [[response substringToIndex:2]isEqualToString:@"P4"]) + { + NSLog(@"[MenuTableViewController.m]: Received A4 answer"); + [self setSensorStatus:[[Sensors alloc]init]]; + [[self sensorStatus] setResponseValue:response]; + [self generateMaintenanceLevel]; + [self changeNavLevel:MAINTENANCE:TRUE]; + } + else if(self.sentCommand == A5 && [[response substringToIndex:2]isEqualToString:@"P5"]) + { + NSLog(@"[MenuTableViewController.m]: Received A5 answer"); + if([response isEqualToString:@"P51"]) + { + + } + else if([response isEqualToString:@"P52"]) + { + NSLog(@"[MenuTableViewController.m]: Device returned error for command A5"); + } + } + else if(self.sentCommand == A6 && [[response substringToIndex:2]isEqualToString:@"P6"]) + { + NSLog(@"[MenuTableViewController.m]: Received A6 answer"); + if([response isEqualToString:@"P61"]) + { + + } + else if([response isEqualToString:@"P62"]) + { + NSLog(@"[MenuTableViewController.m]: Device returned error for command A6"); + } + } + else if(self.sentCommand == A7 && [[response substringToIndex:2]isEqualToString:@"P7"]) + { + NSLog(@"[MenuTableViewController.m]: Received A7 answer"); + if([response isEqualToString:@"P71"]) + { + + } + else if([response isEqualToString:@"P72"]) + { + NSLog(@"[MenuTableViewController.m]: Device returned error for command A7"); + } + } + else + { + NSLog(@"[MenuTableViewController]: Unknown response received. Data discarded."); + } +} + - (void)viewDidLoad { [super viewDidLoad]; @@ -284,6 +356,7 @@ _protocol = [CommunicationProtocol sharedProtocol]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:kEMConnectionDidReceiveIndicatorNotificationName object:nil]; [[EMConnectionManager sharedManager] addObserver:self forKeyPath:@"connectionState" options:0 context:NULL]; + self.protocol.delegate = self; //Initialize parentLayout stack [self setParentLayout:[[Stack alloc]init]]; @@ -291,21 +364,8 @@ //Set navigation level [self initializeMenuEntries]; self.currentNavLevel = 255; - [self changeNavLevel:MENU:FALSE]; - } - --(void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - - //DUREX protocol - if(![_protocol establishConnection]) - { - UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication error",nil) message:NSLocalizedString(@"Error while trying to connect to the device",nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil]; - [alert show]; - UIViewController *previous = [[[self navigationController] viewControllers] objectAtIndex:[[[self navigationController] viewControllers] count]-2]; - [[self navigationController] popToViewController:previous animated:YES]; - } + [_protocol establishConnection]; + [self setSentCommand:HELLO]; } -(void)didReceiveNotification:(NSNotification*) notification @@ -509,15 +569,8 @@ if([cellName isEqualToString:NSLocalizedString(@"Maintenance", nil)]) { NSLog(@"[MenuTableViewController.m]: Changing to navLevel: MAINTENANCE"); - if([self generateMaintenanceLevel]) - { - [NSThread sleepForTimeInterval:1]; //HACK! - [self changeNavLevel:MAINTENANCE:TRUE]; - } - else - { - NSLog(@"[MenuTableViewController.m]: Error while changing to navLevel: MAINTENANCE"); - } + [[self protocol] readSensorData]; + [self setSentCommand:A4]; } else if([cellName isEqualToString:NSLocalizedString(@"Basic Configuration", nil)]) { @@ -1074,6 +1127,7 @@ NSDateComponents *components = [calendar components:units fromDate:date]; NSLog(@"[MenuTableViewController.m]: %@", components); [_protocol updateTime: components]; + [self setSentCommand:A5]; } - (void)passPriceViewController:(PriceChangerViewController *)controller didFinishEnteringItem:(NSArray *)data @@ -1114,6 +1168,7 @@ int code = [codeString intValue]; NSArray *price = [priceString componentsSeparatedByString:@"."]; [_protocol updatePrice:channel :code :[[price objectAtIndex:0] intValue] :[[price objectAtIndex:1] intValue]]; + [self setSentCommand:A6]; } } @@ -1149,6 +1204,7 @@ int channel = [channelString intValue]; int code = [codeString intValue]; [_protocol updateProductName:channel :code :name]; + [self setSentCommand:A7]; } } @@ -1159,9 +1215,6 @@ { NSLog(@"[MenuTableViewController.m]: Changing to navLevel: SALE_LIST"); - //Initialize sales log - [self setSalesLog:[[SalesLog alloc]init]]; - NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDateComponents *componentsFrom = nil; @@ -1174,17 +1227,7 @@ { componentsTo = [calendar components:units fromDate:to]; } - NSString *salesData = [_protocol readSalesLog: componentsFrom : componentsTo]; - if(salesData == nil) - { - NSLog(@"[MenuTableViewController.m]: Error reading sales log"); - } - else - { - [[self salesLog] setResponseValue:salesData]; - [self generateSaleListNavLevel]; - [self changeNavLevel:SALE_LIST:TRUE]; - } + [_protocol readSalesLog: componentsFrom : componentsTo]; } else if([self requestedLog] == INCIDENT_LOG) { diff --git a/TODO b/TODO index a983e02..565ccde 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,8 @@ BUGS: - On date change, response is overwritten by previous query, trimming needed according to numBytes TODO: -- processMessage with Delegate - Error reporting function +- Toast if success or error on processMessage (except nav changes) - Incident class - Incident parser - A3 command -- libgit2 0.22.2