From cf609976b4acf01daf351c68ff35b2639b2c7637 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Sat, 4 Oct 2014 17:48:45 +0000 Subject: [PATCH] --- DUREX Vendor Control/Base.lproj/Localizable.strings | 10 +++++++++- DUREX Vendor Control/CommunicationProtocol.h | 3 ++- DUREX Vendor Control/CommunicationProtocol.m | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------- DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate | Bin 166170 -> 0 bytes DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------- DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m | 2 +- DUREX Vendor Control/MenuTableViewController.h | 10 ---------- DUREX Vendor Control/MenuTableViewController.m | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- DUREX Vendor Control/en.lproj/Localizable.strings | 10 +++++++++- DUREX Vendor Control/es.lproj/Localizable.strings | 10 +++++++++- TODO | 3 --- 11 files changed, 245 insertions(+), 248 deletions(-) diff --git a/DUREX Vendor Control/Base.lproj/Localizable.strings b/DUREX Vendor Control/Base.lproj/Localizable.strings index ccc6f2c..a516cfa 100644 --- a/DUREX Vendor Control/Base.lproj/Localizable.strings +++ b/DUREX Vendor Control/Base.lproj/Localizable.strings @@ -92,4 +92,12 @@ "Entered product code has an invalid format" = "Entered product code has an invalid format"; "Entered channel has an invalid format" = "Entered channel has an invalid format"; "Missing channel" = "Missing channel"; -"Missing product code" = "Missing product code"; \ No newline at end of file +"Missing product code" = "Missing product code"; +"Time and Date changed successfully" = "Time and Date changed successfully"; +"Time and Date change returned error" = "Time and Date change returned error"; +"Product price changed successfully" = "Product price changed successfully"; +"Product price change returned error" = "Product price change returned error"; +"Product name changed successfully" = "Product name changed successfully"; +"Product name change returned error" = "Product name change returned error"; +"Error occurred while reading answer from device" = "Error occurred while reading answer from device"; +"Error occurred while sending command to device" = "Error occurred while sending command to device"; \ No newline at end of file diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h index 4e24ad8..0fac449 100644 --- a/DUREX Vendor Control/CommunicationProtocol.h +++ b/DUREX Vendor Control/CommunicationProtocol.h @@ -25,7 +25,7 @@ @protocol CommunicationProtocolDelegate - (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response; - +- (void) reportProtocolError: (CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) error; @end @interface CommunicationProtocol : NSObject @@ -35,6 +35,7 @@ -(void) writeMessage: (NSString*) message; -(void) readMessage; -(void) establishConnection; +-(void) disconnect; -(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; diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m index c7a9f7b..649eb8b 100644 --- a/DUREX Vendor Control/CommunicationProtocol.m +++ b/DUREX Vendor Control/CommunicationProtocol.m @@ -33,11 +33,6 @@ return shared; } -- (void) reportError : (NSString*) error -{ - -} - -(void) readMessage { self.numPackets = -1; @@ -47,46 +42,47 @@ - (void) readNextFragment { __block NSUInteger numBytes; - if(self.numPackets) + [[EMConnectionManager sharedManager] readResource:@"numBytes" onSuccess:^(id readValue) { - [[EMConnectionManager sharedManager] readResource:@"numBytes" onSuccess:^(id readValue) + numBytes = [readValue unsignedCharValue]; + NSLog(@"[CommunicationProtocol.m]: numBytes read: %d",numBytes); + [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) { - numBytes = [readValue unsignedCharValue]; - NSLog(@"[CommunicationProtocol.m]: numBytes read: %d",numBytes); - [[EMConnectionManager sharedManager] readResource:@"data" onSuccess:^(id readValue) + NSString *readData = [readValue substringToIndex:numBytes]; + if([readValue length] < numBytes) { - 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]: 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.numPackets--; + if(self.numPackets) { - NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice set to FALSE"); - NSLog(@"[CommunicationProtocol.m]: packet read"); [self waitForMessage: 0]; - }onFail:^(NSError *error) + } + else { - NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableDevice to FALSE: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; - }]; + [[self delegate] processMessage:self didFinishEnteringItem:self.message]; + } }onFail:^(NSError *error) { - NSLog(@"[CommunicationProtocol.m]: On readData: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableDevice to FALSE: %@",error); + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while reading answer from device",nil),[error localizedDescription]]]; }]; }onFail:^(NSError *error) { - NSLog(@"[CommunicationProtocol.m]: On readNumBytes: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + NSLog(@"[CommunicationProtocol.m]: On readData: %@",error); + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while reading answer from device",nil),[error localizedDescription]]]; }]; - } - else + }onFail:^(NSError *error) { - [[self delegate] processMessage:self didFinishEnteringItem:self.message]; - } + NSLog(@"[CommunicationProtocol.m]: On readNumBytes: %@",error); + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while reading answer from device",nil),[error localizedDescription]]]; + }]; } - (void) readNumPackets @@ -99,7 +95,7 @@ }onFail:^(NSError *error) { NSLog(@"[CommunicationProtocol.m]: On readNumPackets: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while reading answer from device",nil),[error localizedDescription]]]; }]; } @@ -136,7 +132,7 @@ }onFail:^(NSError *error) { NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]]; + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while reading answer from device",nil),[error localizedDescription]]]; }]; } } @@ -154,69 +150,60 @@ }onFail:^(NSError *error) { NSLog(@"[CommunicationProtocol.m]: On setNumPackets: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while sending command to device",nil),[error localizedDescription]]]; }]; } - (void) sendNextFragment { - NSLog(@"[CommunicationProtocol.m]: Sending next fragment"); - [[EMConnectionManager sharedManager] writeValue:@"0" toResource:@"messageAvailableMobile" onSuccess:^ + if(self.remainingBytes) { - NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to FALSE"); + NSLog(@"[CommunicationProtocol.m]: Sending next fragment"); NSUInteger numBytes; - if(self.remainingBytes) + if(self.remainingBytes > MAX_STRING_LENGTH) { - if(self.remainingBytes > MAX_STRING_LENGTH) - { - numBytes = MAX_STRING_LENGTH; - self.remainingBytes -= MAX_STRING_LENGTH; - } - else - { - 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); - 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: 0]; - }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]: On setNumBytes: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; - }]; + numBytes = MAX_STRING_LENGTH; + self.remainingBytes -= MAX_STRING_LENGTH; } else { - NSLog(@"[CommunicationProtocol.m]: Finished sending message"); - [self readMessage]; + numBytes = self.remainingBytes; + self.remainingBytes = 0; } - - }onFail:^(NSError *error) + [[EMConnectionManager sharedManager] writeValue:[NSNumber numberWithUnsignedChar:(unsigned char)numBytes] toResource:@"numBytes" onSuccess:^ + { + NSLog(@"[CommunicationProtocol.m]: numBytes set to %d", numBytes); + 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: 0]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setMessageAvailable to TRUE: %@",error); + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while sending command to device",nil),[error localizedDescription]]]; + }]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setData: %@",error); + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while sending command to device",nil),[error localizedDescription]]]; + }]; + }onFail:^(NSError *error) + { + NSLog(@"[CommunicationProtocol.m]: On setNumBytes: %@",error); + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while sending command to device",nil),[error localizedDescription]]]; + }]; + } + else { - NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableMobile to FALSE: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; - }]; + NSLog(@"[CommunicationProtocol.m]: Finished sending message"); + [self readMessage]; + } } - (void) readACK: (uint8_t) retries @@ -245,7 +232,7 @@ }onFail:^(NSError *error) { NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error); - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]]; + [[self delegate] reportProtocolError:self didFinishEnteringItem:[NSString stringWithFormat:@"%@: %@",NSLocalizedString(@"Error occurred while sending command to device",nil),[error localizedDescription]]]; }]; } } @@ -257,6 +244,13 @@ NSLog(@"[CommunicationProtocol.m]: Hello sent"); } +-(void) disconnect +{ + NSLog(@"[CommunicationProtocol.m]: Terminating connection..."); + [self writeMessage:@"Bye"]; + NSLog(@"[CommunicationProtocol.m]: Bye sent"); +} + -(void) updateTime: (NSDateComponents*) date { NSMutableString *command = [NSMutableString stringWithFormat: @"A5"]; @@ -288,20 +282,7 @@ NSString *command = @"A4"; [self writeMessage:command]; - /*NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400015000150001500000001001003005002000001002"]; - for(int i = 0; i < 4; i++) - { - [answer appendString:@"0"]; - [answer appendString:@"1"]; - } - for(int i = 0; i < 12; i++) - { - [answer appendString:@"0"]; - [answer appendString:@"0"]; - } - - [answer appendString:@"0"]; - [answer appendString:@"0"];*/ + /*NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P4000150001500015000000010010030050020000010020101010100000000000000000000000000"];*/ } -(void) readSalesLog : (NSDateComponents*) start : (NSDateComponents*) 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 031775c..5459830 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 ceaab41..10a5544 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 = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "770" - endingLineNumber = "770" + startingLineNumber = "774" + endingLineNumber = "774" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -42,12 +42,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "712" - endingLineNumber = "712" - landmarkName = "-tableView:cellForRowAtIndexPath:" + startingLineNumber = "716" + endingLineNumber = "716" + landmarkName = "-tableView:indentationLevelForRowAtIndexPath:" landmarkType = "5"> @@ -58,11 +58,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "571" - endingLineNumber = "571" + startingLineNumber = "575" + endingLineNumber = "575" landmarkName = "-tableView:didSelectRowAtIndexPath:" landmarkType = "5"> @@ -74,13 +74,13 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "434038085.179085" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "341" - endingLineNumber = "341" - landmarkName = "-updateProductName:::" - landmarkType = "5"> + startingLineNumber = "336" + endingLineNumber = "336" + landmarkName = "@implementation CommunicationProtocol" + landmarkType = "3"> @@ -106,13 +106,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "CommunicationProtocol.m" - timestampString = "434038085.179085" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "353" - endingLineNumber = "353" - landmarkName = "-readSensorData" - landmarkType = "5"> + startingLineNumber = "348" + endingLineNumber = "348"> @@ -202,12 +200,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434127499.570083" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "105" - endingLineNumber = "105" - landmarkName = "-generateSaleListNavLevel" + startingLineNumber = "101" + endingLineNumber = "101" + landmarkName = "-generateMaintenanceLevel" landmarkType = "5"> @@ -218,12 +216,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434127499.570083" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "108" - endingLineNumber = "108" - landmarkName = "-generateSaleListNavLevel" + startingLineNumber = "104" + endingLineNumber = "104" + landmarkName = "-generateMaintenanceLevel" landmarkType = "5"> @@ -234,11 +232,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434127499.570083" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "116" - endingLineNumber = "116" + startingLineNumber = "112" + endingLineNumber = "112" landmarkName = "-generateSaleListNavLevel" landmarkType = "5"> @@ -250,11 +248,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434127499.570083" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "188" - endingLineNumber = "188" + startingLineNumber = "184" + endingLineNumber = "184" landmarkName = "-changeNavLevel::" landmarkType = "5"> @@ -266,28 +264,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" - startingColumnNumber = "9223372036854775807" - endingColumnNumber = "9223372036854775807" - startingLineNumber = "556" - endingLineNumber = "556" - landmarkName = "-tableView:numberOfRowsInSection:" - landmarkType = "5"> - - - - @@ -298,12 +280,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "717" - endingLineNumber = "717" - landmarkName = "-tableView:cellForRowAtIndexPath:" + startingLineNumber = "721" + endingLineNumber = "721" + landmarkName = "-numberOfSectionsInTableView:" landmarkType = "5"> @@ -314,11 +296,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "910" - endingLineNumber = "910" + startingLineNumber = "914" + endingLineNumber = "914" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -330,11 +312,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "911" - endingLineNumber = "911" + startingLineNumber = "915" + endingLineNumber = "915" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -362,11 +344,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1030" - endingLineNumber = "1030" + startingLineNumber = "1034" + endingLineNumber = "1034" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -378,11 +360,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "512" - endingLineNumber = "512" + startingLineNumber = "505" + endingLineNumber = "505" landmarkName = "-toggleDropList:" landmarkType = "5"> @@ -394,11 +376,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1115" - endingLineNumber = "1115" + startingLineNumber = "1119" + endingLineNumber = "1119" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -410,11 +392,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1107" - endingLineNumber = "1107" + startingLineNumber = "1111" + endingLineNumber = "1111" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -426,11 +408,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "902" - endingLineNumber = "902" + startingLineNumber = "906" + endingLineNumber = "906" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -442,11 +424,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "900" - endingLineNumber = "900" + startingLineNumber = "904" + endingLineNumber = "904" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -458,11 +440,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "761" - endingLineNumber = "761" + startingLineNumber = "765" + endingLineNumber = "765" landmarkName = "-tableView:cellForRowAtIndexPath:" landmarkType = "5"> @@ -538,11 +520,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1230" - endingLineNumber = "1230" + startingLineNumber = "1235" + endingLineNumber = "1235" landmarkName = "-passDateRangeViewController:didFinishEnteringItem::" landmarkType = "5"> @@ -554,12 +536,12 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "MenuTableViewController.m" - timestampString = "434037601.622012" + timestampString = "434133664.559575" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "1215" - endingLineNumber = "1215" - landmarkName = "-passDateRangeViewController:didFinishEnteringItem::" + startingLineNumber = "1220" + endingLineNumber = "1220" + landmarkName = "-passNameViewController:didFinishEnteringItem:" landmarkType = "5"> diff --git a/DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m b/DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m index fd7cd66..c0b1605 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 7325dc2..4d731ba 100644 --- a/DUREX Vendor Control/MenuTableViewController.h +++ b/DUREX Vendor Control/MenuTableViewController.h @@ -73,16 +73,6 @@ enum { @interface MenuTableViewController : UITableViewController -@property (strong,nonatomic) Stack *parentLayout; -@property (strong,nonatomic) DatePickerViewController *datePickerViewController; -@property (strong,nonatomic) PriceChangerViewController *priceChangerViewController; -@property (strong,nonatomic) NameChangerViewController *nameChangerViewController; -@property (strong,nonatomic) DateRangePickerViewController *dateRangePickerViewController; -@property (strong,nonatomic) Sensors *sensorStatus; -@property (strong,nonatomic) SalesLog *salesLog; -@property (strong,nonatomic) Sale *currentSale; -@property (strong,nonatomic) NSString *machineMACAddr; - - (void) navBack; @end diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m index 701843a..34573e6 100644 --- a/DUREX Vendor Control/MenuTableViewController.m +++ b/DUREX Vendor Control/MenuTableViewController.m @@ -13,6 +13,8 @@ IBOutlet UIActivityIndicatorView *_activityIndicator; NSTimer *_writeTimer; } + +//NAVIGATION LEVELS LAYOUT AND CELL IDENTIFIERS @property (nonatomic,strong) const NSMutableArray *menuElements; @property (nonatomic,strong) const NSMutableArray *menuStructure; @property (nonatomic,strong) const NSMutableArray *menuHeaders; @@ -35,29 +37,32 @@ @property (nonatomic,strong) const NSArray *cellIdentifiers; +//GENERAL ATTRIBUTES @property (nonatomic,strong) CommunicationProtocol* protocol; -@property uint8_t currentNavLevel; -@property NSString *currentCellIdentifier; -@property const NSMutableArray *currentElements; -@property const NSMutableArray *currentStructure; -@property const NSMutableArray *currentHeaders; +@property (strong,nonatomic) NSString *machineMACAddr; +@property (strong,nonatomic) Stack *parentLayout; +@property (strong,nonatomic) Sensors *sensorStatus; +@property (strong,nonatomic) SalesLog *salesLog; +@property (strong,nonatomic) Sale *currentSale; @property uint8_t requestedLog; @property uint8_t sentCommand; + +@property uint8_t currentNavLevel; +@property (strong,nonatomic) NSString *currentCellIdentifier; +@property (strong,nonatomic) const NSMutableArray *currentElements; +@property (strong,nonatomic) const NSMutableArray *currentStructure; +@property (strong,nonatomic) const NSMutableArray *currentHeaders; + +@property (strong,nonatomic) DatePickerViewController *datePickerViewController; +@property (strong,nonatomic) PriceChangerViewController *priceChangerViewController; +@property (strong,nonatomic) NameChangerViewController *nameChangerViewController; +@property (strong,nonatomic) DateRangePickerViewController *dateRangePickerViewController; @end @implementation MenuTableViewController -- (id)initWithStyle:(UITableViewStyle)style -{ - self = [super initWithStyle:style]; - if (self) - { - // Custom initialization - } - return self; -} - +//NAVIGATION LEVELS GENERATION AND NAVIGATION - (void) initializeMenuEntries { [self setMenuElements:[[NSMutableArray alloc] initWithObjects:MENU_ELEMENTS, nil]]; @@ -203,16 +208,6 @@ [self changeNavLevel: prevLevel.intValue : FALSE]; } -- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section -{ - NSString *title = @""; - if([self currentHeaders] != nil) - { - title = [[self currentHeaders] objectAtIndex:section]; - } - return title; -} - - (void) backButtonPressed: (id) sender { NSLog(@"[MenuTableViewController.m]: Navigation Stack has %ld remaining levels",(long)[[self parentLayout] count]); @@ -224,10 +219,12 @@ else { NSLog(@"[MenuTableViewController.m]: No more navigation levels in stack, falling to previous view"); + [_protocol disconnect]; [self.navigationController popViewControllerAnimated:YES]; } } +//MAINTENANCE REPORT SENDING - (void) sendMaintenanceReport : (NSString*) status : (NSString*) date : (NSString*) machineid { NSString *content = [NSString stringWithFormat:@"status=%@&date=%@&machineid=%@",status,date,machineid]; @@ -235,15 +232,11 @@ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:REPORT_SERVER_URL]]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[content dataUsingEncoding:NSUTF8StringEncoding]]; - - // generates an autoreleased NSURLConnection [NSURLConnection connectionWithRequest:request delegate:self]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - // Append the new data to receivedData. - // receivedData is an instance variable declared elsewhere. NSLog(@"[MenuTableViewController.m]: Received response from report server: %@",[NSString stringWithUTF8String:[data bytes]]); [self.view makeToast:NSLocalizedString(@"Report sent successfully", nil) duration:3 position:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)] title:NSLocalizedString(@"Success!", nil) image:[UIImage imageNamed:@"icon_checkmark"]]; } @@ -253,7 +246,20 @@ NSLog(@"[MenuTableViewController.m]: Error connecting to server: %@ %@",[error localizedDescription],[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); [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"]]; } +//PROTOCOL ERROR CALLBACK +- (void) reportProtocolError: (CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) error +{ + if(self.currentNavLevel == 255) + { + [self processMessage:protocol didFinishEnteringItem:@"ERROR"]; + } + else + { + [self.view makeToast:error 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"]]; + } +} +//MESSAGE RECEIVED CALLBACK - (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response { NSLog(@"[MenuTableViewController.m]: Answer received"); @@ -298,11 +304,12 @@ NSLog(@"[MenuTableViewController.m]: Received A5 answer"); if([response isEqualToString:@"P51"]) { - + [self.view makeToast:NSLocalizedString(@"Time and Date changed successfully", nil) duration:3 position:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)] title:nil image:[UIImage imageNamed:@"icon_checkmark"]]; } else if([response isEqualToString:@"P52"]) { NSLog(@"[MenuTableViewController.m]: Device returned error for command A5"); + [self.view makeToast:NSLocalizedString(@"Time and Date change returned error", 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"]]; } } else if(self.sentCommand == A6 && [[response substringToIndex:2]isEqualToString:@"P6"]) @@ -310,11 +317,12 @@ NSLog(@"[MenuTableViewController.m]: Received A6 answer"); if([response isEqualToString:@"P61"]) { - + [self.view makeToast:NSLocalizedString(@"Product price changed successfully", nil) duration:3 position:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)] title:nil image:[UIImage imageNamed:@"icon_checkmark"]]; } else if([response isEqualToString:@"P62"]) { NSLog(@"[MenuTableViewController.m]: Device returned error for command A6"); + [self.view makeToast:NSLocalizedString(@"Product price change returned error", 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"]]; } } else if(self.sentCommand == A7 && [[response substringToIndex:2]isEqualToString:@"P7"]) @@ -322,11 +330,12 @@ NSLog(@"[MenuTableViewController.m]: Received A7 answer"); if([response isEqualToString:@"P71"]) { - + [self.view makeToast:NSLocalizedString(@"Product name changed successfully", nil) duration:3 position:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)] title:nil image:[UIImage imageNamed:@"icon_checkmark"]]; } else if([response isEqualToString:@"P72"]) { NSLog(@"[MenuTableViewController.m]: Device returned error for command A7"); + [self.view makeToast:NSLocalizedString(@"Product name change returned error", 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"]]; } } else @@ -402,6 +411,7 @@ #pragma mark - Table view delegate +//CELL PROCESSING AND CUSTOMIZATION - (void) addTags : (NSMutableArray*) rows : (NSInteger) tag { for(int i = 0; i < [rows count]; i++) @@ -552,6 +562,17 @@ [[self currentStructure] replaceObjectAtIndex:[indexPath section] withObject:[NSNumber numberWithInt:([[[self currentStructure] objectAtIndex:[indexPath section]] intValue] - numRows)]]; } +//UITABLEVIEWCONTROLLER FUNCTIONS +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + NSString *title = @""; + if([self currentHeaders] != nil) + { + title = [[self currentHeaders] objectAtIndex:section]; + } + return title; +} + - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[[self currentStructure] objectAtIndex:section] intValue]; @@ -1120,6 +1141,7 @@ return cell; } +//DELEGATE FUNCTIONS - (void)passDateViewController:(DatePickerViewController *)controller didFinishEnteringItem:(NSDate *)date { NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; diff --git a/DUREX Vendor Control/en.lproj/Localizable.strings b/DUREX Vendor Control/en.lproj/Localizable.strings index 8fd9144..5515505 100644 --- a/DUREX Vendor Control/en.lproj/Localizable.strings +++ b/DUREX Vendor Control/en.lproj/Localizable.strings @@ -92,4 +92,12 @@ "Entered product code has an invalid format" = "Entered product code has an invalid format"; "Entered channel has an invalid format" = "Entered channel has an invalid format"; "Missing channel" = "Missing channel"; -"Missing product code" = "Missing product code"; \ No newline at end of file +"Missing product code" = "Missing product code"; +"Time and Date changed successfully" = "Time and Date changed successfully"; +"Time and Date change returned error" = "Time and Date change returned error"; +"Product price changed successfully" = "Product price changed successfully"; +"Product price change returned error" = "Product price change returned error"; +"Product name changed successfully" = "Product name changed successfully"; +"Product name change returned error" = "Product name change returned error"; +"Error occurred while reading answer from device" = "Error occurred while reading answer from device"; +"Error occurred while sending command to device" = "Error occurred while sending command to device"; \ No newline at end of file diff --git a/DUREX Vendor Control/es.lproj/Localizable.strings b/DUREX Vendor Control/es.lproj/Localizable.strings index 0ccd65e..96fa772 100644 --- a/DUREX Vendor Control/es.lproj/Localizable.strings +++ b/DUREX Vendor Control/es.lproj/Localizable.strings @@ -92,4 +92,12 @@ "Entered code has an invalid format" = "El código de producto introducido está en un formato incorrecto"; "Entered channel has an invalid format" = "El canal introducido está en un formato incorrecto"; "Missing channel" = "Falta el canal"; -"Missing product code" = "Falta el código del producto"; \ No newline at end of file +"Missing product code" = "Falta el código del producto"; +"Time and Date changed successfully" = "Fecha y hora cambiadas con éxito"; +"Time and Date change returned error" = "Error al cambiar la fecha y hora"; +"Product price changed successfully" = "El precio del producto se cambió con éxito"; +"Product price change returned error" = "Error al cambiar el precio del producto"; +"Product name changed successfully" = "El nombre del producto se cambió con éxito"; +"Product name change returned error" = "Error al cambiar el nombre del producto"; +"Error occurred while reading answer from device" = "Error al leer la respuesta del dispositivo"; +"Error occurred while sending command to device" = "Error al mandar el comando al dispositivo"; \ No newline at end of file diff --git a/TODO b/TODO index 565ccde..54705ef 100644 --- a/TODO +++ b/TODO @@ -5,12 +5,9 @@ BUGS: - On date change, response is overwritten by previous query, trimming needed according to numBytes TODO: -- Error reporting function -- Toast if success or error on processMessage (except nav changes) - 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