diff --git a/DUREX Vendor Control/Base.lproj/Localizable.strings b/DUREX Vendor Control/Base.lproj/Localizable.strings index 19ba2b1..34e23b3 100644 --- a/DUREX Vendor Control/Base.lproj/Localizable.strings +++ b/DUREX Vendor Control/Base.lproj/Localizable.strings @@ -101,4 +101,8 @@ "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"; -"Connection lost" = "Connection lost"; \ No newline at end of file +"Connection lost" = "Connection lost"; +"Device answer timeout occurred" = "Device answer timeout occurred"; +"Incident log" = "Incident log"; +"Error Code" = "Error Code"; +"Error Value" = "Error Value"; \ No newline at end of file diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h index 0fac449..fcebb5a 100644 --- a/DUREX Vendor Control/CommunicationProtocol.h +++ b/DUREX Vendor Control/CommunicationProtocol.h @@ -21,6 +21,7 @@ #define CHANGE_NUM_UNITS ((int)2) #define MAX_PRODUCTS ((int)16) #define SALE_STRING_LENGTH ((int)36) +#define INCIDENT_STRING_LENGTH ((int)20) #define REPORT_SERVER_URL @"http://seneca.upc.es:8090/machine" @protocol CommunicationProtocolDelegate @@ -41,6 +42,7 @@ -(void) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name; -(void) readSensorData; -(void) readSalesLog: (NSDateComponents*) start : (NSDateComponents*) end; +-(void) readIncidentLog: (NSDateComponents*) start : (NSDateComponents*) end; +(id) sharedProtocol; @end diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m index a3b6a23..5105392 100644 --- a/DUREX Vendor Control/CommunicationProtocol.m +++ b/DUREX Vendor Control/CommunicationProtocol.m @@ -321,4 +321,38 @@ //NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21408161036000001000000110450000001P21409012216000100000000220900000100P21409032307000000010502330800000000P21409070540000000020000440350000001P2P2"]; } +-(void) readIncidentLog:(NSDateComponents *)start :(NSDateComponents *)end +{ + NSMutableString *startDate = [NSMutableString stringWithString:@""]; + NSMutableString *endDate = [NSMutableString stringWithString:@""]; + NSMutableString *command = [NSMutableString stringWithString:@"A3"]; + if(start == nil) + { + [startDate setString:@""]; + } + else + { + NSInteger year = [start year]; + year = year - (year/100)*100; + [startDate appendString:[NSString stringWithFormat:@"%02ld",(long)year]]; + [startDate appendString:[NSString stringWithFormat:@"%02ld%02ld%02ld%02ld",(long)[start month],(long)[start day],(long)[start hour],(long)[start minute]]]; + } + if(end == nil) + { + [endDate setString:@""]; + } + else + { + NSInteger year = [end year]; + year = year - (year/100)*100; + [endDate appendString:[NSString stringWithFormat:@"%02ld",(long)year]]; + [endDate appendString:[NSString stringWithFormat:@"%02ld%02ld%02ld%02ld",(long)[end month],(long)[end day],(long)[end hour],(long)[end minute]]]; + } + [command appendString:startDate]; + [command appendString:@"-"]; + [command appendString:endDate]; + [self writeMessage:command]; +} + + @end diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj index a277936..861e90e 100644 --- a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj +++ b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj @@ -44,6 +44,8 @@ F989B60219BCE28C00657DD9 /* SalesLog.m in Sources */ = {isa = PBXBuildFile; fileRef = F989B60119BCE28C00657DD9 /* SalesLog.m */; }; F996591219CC7F3D00667BEC /* DateRangePickerViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = F996591419CC7F3D00667BEC /* DateRangePickerViewController_iPad.xib */; }; F9A8EF7C192FE201009E7532 /* Stack.m in Sources */ = {isa = PBXBuildFile; fileRef = F9A8EF7B192FE201009E7532 /* Stack.m */; }; + F9B9100919E59773006D4D06 /* IncidentLog.m in Sources */ = {isa = PBXBuildFile; fileRef = F9B9100819E59773006D4D06 /* IncidentLog.m */; }; + F9B9100C19E5A0A1006D4D06 /* Incident.m in Sources */ = {isa = PBXBuildFile; fileRef = F9B9100B19E5A0A1006D4D06 /* Incident.m */; }; F9C77F50192CDE30002DBE8A /* system.json in Resources */ = {isa = PBXBuildFile; fileRef = F9C77F4F192CDE30002DBE8A /* system.json */; }; F9CED59A19BE086E008F3764 /* UIView+Toast.m in Sources */ = {isa = PBXBuildFile; fileRef = F9CED59919BE086E008F3764 /* UIView+Toast.m */; }; F9E4D8FD19B8FD32009A7359 /* EMConnectingView_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = F9E4D8FF19B8FD32009A7359 /* EMConnectingView_iPad.xib */; }; @@ -142,6 +144,10 @@ F996591819CC7F4500667BEC /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/DateRangePickerViewController_iPad.strings; sourceTree = ""; }; F9A8EF7A192FE201009E7532 /* Stack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Stack.h; sourceTree = SOURCE_ROOT; }; F9A8EF7B192FE201009E7532 /* Stack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Stack.m; sourceTree = SOURCE_ROOT; }; + F9B9100719E59773006D4D06 /* IncidentLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IncidentLog.h; sourceTree = SOURCE_ROOT; }; + F9B9100819E59773006D4D06 /* IncidentLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IncidentLog.m; sourceTree = SOURCE_ROOT; }; + F9B9100A19E5A0A1006D4D06 /* Incident.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Incident.h; sourceTree = SOURCE_ROOT; }; + F9B9100B19E5A0A1006D4D06 /* Incident.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Incident.m; sourceTree = SOURCE_ROOT; }; F9C77F4F192CDE30002DBE8A /* system.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = system.json; sourceTree = SOURCE_ROOT; }; F9CED59819BE086E008F3764 /* UIView+Toast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Toast.h"; sourceTree = SOURCE_ROOT; }; F9CED59919BE086E008F3764 /* UIView+Toast.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Toast.m"; sourceTree = SOURCE_ROOT; }; @@ -218,6 +224,8 @@ F98446EF19B9EAE9005C4992 /* Sensors.m */, F989B5FE19BCD7A100657DD9 /* Sale.m */, F989B60119BCE28C00657DD9 /* SalesLog.m */, + F9B9100B19E5A0A1006D4D06 /* Incident.m */, + F9B9100819E59773006D4D06 /* IncidentLog.m */, ); name = "DUREX Vendor Control"; path = TestAppExample; @@ -324,6 +332,8 @@ F98446EE19B9EAE9005C4992 /* Sensors.h */, F989B5FD19BCD7A100657DD9 /* Sale.h */, F989B60019BCE28C00657DD9 /* SalesLog.h */, + F9B9100A19E5A0A1006D4D06 /* Incident.h */, + F9B9100719E59773006D4D06 /* IncidentLog.h */, ); name = Headers; sourceTree = ""; @@ -431,9 +441,11 @@ F933F80419B6819400521B90 /* DatePickerViewController.m in Sources */, F989B5FF19BCD7A100657DD9 /* Sale.m in Sources */, F98356D6192E835F00EA6821 /* InitialViewController.m in Sources */, + F9B9100C19E5A0A1006D4D06 /* Incident.m in Sources */, F9CED59A19BE086E008F3764 /* UIView+Toast.m in Sources */, F9A8EF7C192FE201009E7532 /* Stack.m in Sources */, 34AAB885189804FF0019860D /* EMDevicePickerViewController.m in Sources */, + F9B9100919E59773006D4D06 /* IncidentLog.m in Sources */, F989B60219BCE28C00657DD9 /* SalesLog.m in Sources */, F92F567919B75F5E00A1EACA /* PriceChangerViewController.m in Sources */, 34AAB883189804FF0019860D /* DUREXAppDelegate.m in Sources */, 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 af25ee5..fc0a123 100644 --- 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 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 c2aa62e..33c7df4 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 @@ -31,7 +31,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "776" endingLineNumber = "776" - landmarkName = "-tableView:cellForRowAtIndexPath:" + landmarkName = "-numberOfSectionsInTableView:" landmarkType = "5"> @@ -47,8 +47,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "718" endingLineNumber = "718" - landmarkName = "@implementation MenuTableViewController" - landmarkType = "3"> + landmarkName = "-tableView:didSelectRowAtIndexPath:" + landmarkType = "5"> + endingLineNumber = "337" + landmarkName = "-readIncidentLog::" + landmarkType = "5"> + endingLineNumber = "336" + landmarkName = "-readIncidentLog::" + landmarkType = "5"> + endingLineNumber = "349" + landmarkName = "-readIncidentLog::" + landmarkType = "5"> @@ -441,7 +447,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "767" endingLineNumber = "767" - landmarkName = "-tableView:cellForRowAtIndexPath:" + landmarkName = "-tableView:indentationLevelForRowAtIndexPath:" landmarkType = "5"> @@ -521,7 +527,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "1237" endingLineNumber = "1237" - landmarkName = "-passDateRangeViewController:didFinishEnteringItem::" + landmarkName = "-passPriceViewController:didFinishEnteringItem:" landmarkType = "5"> @@ -537,7 +543,7 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "1222" endingLineNumber = "1222" - landmarkName = "-passNameViewController:didFinishEnteringItem:" + landmarkName = "-passPriceViewController:didFinishEnteringItem:" landmarkType = "5"> diff --git a/DUREX Vendor Control/Incident.h b/DUREX Vendor Control/Incident.h new file mode 100644 index 0000000..68703b2 --- /dev/null +++ b/DUREX Vendor Control/Incident.h @@ -0,0 +1,18 @@ +// +// Incident.h +// DUREX Vendor Control +// +// Created by Imanol Barba on 10/8/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import +#import "CommunicationProtocol.h" + +@interface Incident : NSObject + +@property NSString *errorCode; +@property NSString *errorValue; +@property NSDate *incidentTime; + +@end \ No newline at end of file diff --git a/DUREX Vendor Control/Incident.m b/DUREX Vendor Control/Incident.m new file mode 100644 index 0000000..7187121 --- /dev/null +++ b/DUREX Vendor Control/Incident.m @@ -0,0 +1,13 @@ +// +// Incident.m +// DUREX Vendor Control +// +// Created by Imanol Barba on 10/8/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import "Incident.h" + +@implementation Incident + +@end \ No newline at end of file diff --git a/DUREX Vendor Control/IncidentLog.h b/DUREX Vendor Control/IncidentLog.h new file mode 100644 index 0000000..42139c0 --- /dev/null +++ b/DUREX Vendor Control/IncidentLog.h @@ -0,0 +1,21 @@ +// +// IncidentLog.h +// DUREX Vendor Control +// +// Created by Imanol Barba on 10/8/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import +#import "CommunicationProtocol.h" +#import "Incident.h" + +@interface IncidentLog : NSObject + +@property (strong,nonatomic) NSString *response; +@property (strong,nonatomic) NSMutableArray *incidents; + +- (id) init; +- (void) setResponseValue:(NSString *)response; + +@end diff --git a/DUREX Vendor Control/IncidentLog.m b/DUREX Vendor Control/IncidentLog.m new file mode 100644 index 0000000..04be29e --- /dev/null +++ b/DUREX Vendor Control/IncidentLog.m @@ -0,0 +1,55 @@ +// +// IncidentLog.m +// DUREX Vendor Control +// +// Created by Imanol Barba on 10/8/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import "IncidentLog.h" + +@implementation IncidentLog + +- (id) init +{ + [self setIncidents:[[NSMutableArray alloc] init]]; + return self; +} + +- (void) setResponseValue:(NSString *)response +{ + [self setResponse: response]; + [self parseResponse]; +} + +- (void) parseResponse +{ + NSInteger currentIncident = 0; + NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit; + NSDateComponents *incidentDate = [[NSDateComponents alloc] init]; + NSInteger currentYear = [[calendar components:units fromDate:[NSDate date]] year]; + currentYear = (currentYear/100)*100; + while(![[[self response] substringWithRange:NSMakeRange((currentIncident*INCIDENT_STRING_LENGTH), 4)] isEqualToString:@"P3P3"]) + { + Incident *incident = [[Incident alloc] init]; + [incidentDate setYear:(currentYear + [[[self response] substringWithRange:NSMakeRange(2 + currentIncident*SALE_STRING_LENGTH, 2)] intValue])]; + [incidentDate setMonth:[[[self response] substringWithRange:NSMakeRange(4 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]]; + [incidentDate setDay:[[[self response] substringWithRange:NSMakeRange(6 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]]; + [incidentDate setHour:[[[self response] substringWithRange:NSMakeRange(8 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]]; + [incidentDate setMinute:[[[self response] substringWithRange:NSMakeRange(10 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]]; + [incidentDate setMinute:[[[self response] substringWithRange:NSMakeRange(12 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]]; + [incident setIncidentTime:[calendar dateFromComponents:incidentDate]]; + NSLog(@"date: %@",[calendar dateFromComponents:incidentDate]); + [incident setErrorCode:[[self response] substringWithRange:NSMakeRange(14 + currentIncident*SALE_STRING_LENGTH, 2)]]; + NSLog(@"errorCode: %@",[incident errorCode]); + [incident setErrorValue:[[self response] substringWithRange:NSMakeRange(16 + currentIncident*SALE_STRING_LENGTH, 4)]]; + NSLog(@"errorValue: %@",[incident errorValue]); + [[self incidents] insertObject:incident atIndex:currentIncident]; + currentIncident++; + } + NSLog(@"%@",[self incidents]); +} + +@end + diff --git a/DUREX Vendor Control/MenuTableViewController.h b/DUREX Vendor Control/MenuTableViewController.h index 4d731ba..7576ae0 100644 --- a/DUREX Vendor Control/MenuTableViewController.h +++ b/DUREX Vendor Control/MenuTableViewController.h @@ -16,6 +16,7 @@ #import "DateRangePickerViewController.h" #import "Sensors.h" #import "SalesLog.h" +#import "IncidentLog.h" #import "UIView+Toast.h" #define num(x) [NSNumber numberWithUnsignedInt:x] @@ -41,6 +42,10 @@ #define SALE_CELLS_PER_SECTION num(5) #define SALE_HEADERS nil +#define INCIDENT_ELEMENTS @">[5000]Error Code",@"[5001]Error Value" +#define INCIDENT_CELLS_PER_SECTION num(2) +#define INCIDENT_HEADERS nil + #define CONFIGURATION_ELEMENTS @"[4000]Update Date & Time",@"[4001]Update product price",@"[4002]Update product name" #define CONFIGURATION_CELLS_PER_SECTION num(3) #define CONFIGURATION_HEADERS nil @@ -52,6 +57,8 @@ enum { MAINTENANCE, SALE_LIST, SALE, + INCIDENT_LIST, + INCIDENT, BASIC_CONFIGURATION, REPORT, } navigationLevel; @@ -64,6 +71,8 @@ enum { A5, A6, A7, + INVALID_COMMAND, + NONE, } commandTypes; enum { diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m index 9c0e077..a27e35b 100644 --- a/DUREX Vendor Control/MenuTableViewController.m +++ b/DUREX Vendor Control/MenuTableViewController.m @@ -31,6 +31,14 @@ @property (nonatomic,strong) const NSMutableArray *saleStructure; @property (nonatomic,strong) const NSMutableArray *saleHeaders; +@property (nonatomic,strong) const NSMutableArray *incidentListElements; +@property (nonatomic,strong) const NSMutableArray *incidentListStructure; +@property (nonatomic,strong) const NSMutableArray *incidentListHeaders; + +@property (nonatomic,strong) const NSMutableArray *incidentElements; +@property (nonatomic,strong) const NSMutableArray *incidentStructure; +@property (nonatomic,strong) const NSMutableArray *incidentHeaders; + @property (nonatomic,strong) const NSMutableArray *configElements; @property (nonatomic,strong) const NSMutableArray *configStructure; @property (nonatomic,strong) const NSMutableArray *configHeaders; @@ -41,10 +49,13 @@ @property (nonatomic,strong) CommunicationProtocol* protocol; @property (strong,nonatomic) NSString *machineMACAddr; @property (strong,nonatomic) Stack *parentLayout; +@property (strong,nonatomic) NSTimer *timeoutTimer; @property (strong,nonatomic) Sensors *sensorStatus; @property (strong,nonatomic) SalesLog *salesLog; @property (strong,nonatomic) Sale *currentSale; +@property (strong,nonatomic) IncidentLog *incidentLog; +@property (strong,nonatomic) Incident *currentIncident; @property uint8_t requestedLog; @property uint8_t sentCommand; @@ -137,6 +148,38 @@ return TRUE; } +- (void) generateIncidentListNavLevel +{ + NSMutableArray *dateArray = [[NSMutableArray alloc] init]; + for(int i = 0; i < [[[self incidentLog] incidents]count]; i++) + { + Incident *currentIncident = [[[self incidentLog] incidents]objectAtIndex:i]; + NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit; + NSDateComponents *components = [calendar components:units fromDate:[currentIncident incidentTime]]; + [dateArray insertObject:[NSString stringWithFormat:@"[%d%d%d%d%d]%02d/%02d/%d %02d:%02d",[components day],[components month],[components year],[components hour],[components minute],[components day],[components month],[components year],[components hour],[components minute]] atIndex:i]; + } + [self setIncidentListElements:[[NSMutableArray alloc] initWithArray:dateArray]]; + [self setIncidentListStructure:[[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:[dateArray count]], nil]]; + [self setIncidentListHeaders:nil]; +} + +- (Boolean) generateIncidentNavLevel : (NSInteger) numIncident +{ + [self setIncidentElements:[[NSMutableArray alloc] initWithObjects:INCIDENT_ELEMENTS, nil]]; + [self setIncidentStructure:[[NSMutableArray alloc] initWithObjects:INCIDENT_CELLS_PER_SECTION, nil]]; + if([[self incidentStructure] count] > 1) + { + [self setIncidentHeaders:[[NSMutableArray alloc] initWithObjects:INCIDENT_HEADERS, nil]]; + } + else + { + [self setIncidentHeaders:nil]; + } + [self setCurrentIncident:[[[self incidentLog]incidents]objectAtIndex:numIncident]]; + return TRUE; +} + - (void) changeNavLevel: (uint8_t) level : (BOOL) push { NSLog(@"[MenuTableViewController.m]: navLevel is %d",level); @@ -178,6 +221,23 @@ [self setCurrentStructure:[self saleStructure]]; [self setCurrentHeaders:[self saleHeaders]]; } + else if([self currentNavLevel] == INCIDENT_LIST) + { + [[self navigationItem] setTitle:NSLocalizedString(@"Incident log", nil)]; + [self setCurrentElements:[self incidentListElements]]; + [self setCurrentStructure:[self incidentListStructure]]; + [self setCurrentHeaders:[self incidentListHeaders]]; + } + else if([self currentNavLevel] == INCIDENT) + { + NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit; + NSDateComponents *components = [calendar components:units fromDate:[[self currentIncident] incidentTime]]; + [[self navigationItem] setTitle:[NSString stringWithFormat:@"%@ %02d/%02d/%d %02d:%02d",NSLocalizedString(@"Incident on", nil),[components day],[components month],[components year],[components hour],[components minute]]]; + [self setCurrentElements:[self incidentElements]]; + [self setCurrentStructure:[self incidentStructure]]; + [self setCurrentHeaders:[self incidentHeaders]]; + } else if([self currentNavLevel] == BASIC_CONFIGURATION) { [[self navigationItem] setTitle:NSLocalizedString(@"Basic Configuration", nil)]; @@ -263,6 +323,7 @@ - (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response { NSLog(@"[MenuTableViewController.m]: Answer received: %@",response); + [self.timeoutTimer invalidate]; if(self.sentCommand == HELLO) { if([response isEqualToString:@"Hello"]) @@ -289,7 +350,11 @@ } else if(self.sentCommand == A3 && [[response substringToIndex:2]isEqualToString:@"P3"]) { - + NSLog(@"[MenuTableViewController.m]: Received A3 answer"); + [self setIncidentLog:[[IncidentLog alloc]init]]; + [[self incidentLog] setResponseValue:response]; + [self generateIncidentListNavLevel]; + [self changeNavLevel:INCIDENT_LIST:TRUE]; } else if(self.sentCommand == A4 && [[response substringToIndex:2]isEqualToString:@"P4"]) { @@ -342,6 +407,29 @@ { NSLog(@"[MenuTableViewController]: Unknown response received. Data discarded."); } + [self setSentCommand:NONE]; +} + +- (void) startTimeoutTimer +{ + self.timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:10 + target:self + selector:@selector(commandDidTimeout:) + userInfo:nil + repeats:NO]; +} + +- (void) commandDidTimeout:(NSTimer *) timer +{ + if(self.currentNavLevel == 255) + { + [self processMessage:nil didFinishEnteringItem:@"ERROR"]; + } + else + { + [self setSentCommand:INVALID_COMMAND]; + [self.view makeToast:NSLocalizedString(@"Device answer timeout occurred", 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)viewDidLoad @@ -375,6 +463,7 @@ self.currentNavLevel = 255; [_protocol establishConnection]; [self setSentCommand:HELLO]; + [self startTimeoutTimer]; } -(void)didReceiveNotification:(NSNotification*) notification @@ -591,9 +680,13 @@ { if([cellName isEqualToString:NSLocalizedString(@"Maintenance", nil)]) { - NSLog(@"[MenuTableViewController.m]: Changing to navLevel: MAINTENANCE"); - [[self protocol] readSensorData]; - [self setSentCommand:A4]; + if(self.sentCommand == NONE) + { + NSLog(@"[MenuTableViewController.m]: Changing to navLevel: MAINTENANCE"); + [[self protocol] readSensorData]; + [self setSentCommand:A4]; + [self startTimeoutTimer]; + } } else if([cellName isEqualToString:NSLocalizedString(@"Basic Configuration", nil)]) { @@ -602,7 +695,13 @@ } else if([cellName isEqualToString:NSLocalizedString(@"Sending a Report", nil)]) { - + //TEST TIMEOUT + if(self.sentCommand == NONE) + { + [_protocol writeMessage:@"A9"]; + [self setSentCommand:INVALID_COMMAND]; + [self startTimeoutTimer]; + } } } //Cells in MAINTENANCE @@ -620,20 +719,41 @@ } else if([cellName isEqualToString:NSLocalizedString(@"Sales log", nil)]) { - [self setRequestedLog:SALES_LOG]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if(self.sentCommand == NONE) { - self.dateRangePickerViewController = [[DateRangePickerViewController alloc] initWithNibName:@"DateRangePickerViewController_iPad" bundle:nil]; - self.dateRangePickerViewController.delegate = self; - [self.dateRangePickerViewController showInView:self.navigationController.view animated:YES]; + [self setRequestedLog:SALES_LOG]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + self.dateRangePickerViewController = [[DateRangePickerViewController alloc] initWithNibName:@"DateRangePickerViewController_iPad" bundle:nil]; + self.dateRangePickerViewController.delegate = self; + [self.dateRangePickerViewController showInView:self.navigationController.view animated:YES]; + } + else + { + self.dateRangePickerViewController = [[DateRangePickerViewController alloc] initWithNibName:@"DateRangePickerViewController" bundle:nil]; + self.dateRangePickerViewController.delegate = self; + [self.dateRangePickerViewController showInView:self.navigationController.view animated:YES]; + } } - else + } + else if([cellName isEqualToString:NSLocalizedString(@"Incident log", nil)]) + { + if(self.sentCommand == NONE) { - self.dateRangePickerViewController = [[DateRangePickerViewController alloc] initWithNibName:@"DateRangePickerViewController" bundle:nil]; - self.dateRangePickerViewController.delegate = self; - [self.dateRangePickerViewController showInView:self.navigationController.view animated:YES]; + [self setRequestedLog:INCIDENT_LOG]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + self.dateRangePickerViewController = [[DateRangePickerViewController alloc] initWithNibName:@"DateRangePickerViewController_iPad" bundle:nil]; + self.dateRangePickerViewController.delegate = self; + [self.dateRangePickerViewController showInView:self.navigationController.view animated:YES]; + } + else + { + self.dateRangePickerViewController = [[DateRangePickerViewController alloc] initWithNibName:@"DateRangePickerViewController" bundle:nil]; + self.dateRangePickerViewController.delegate = self; + [self.dateRangePickerViewController showInView:self.navigationController.view animated:YES]; + } } - } else if([cellName isEqualToString:NSLocalizedString(@"Send report", nil)]) { @@ -650,49 +770,58 @@ //Update Date & Time command if([cellName isEqualToString:NSLocalizedString(@"Update Date & Time", nil)]) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if(self.sentCommand == NONE) { - self.datePickerViewController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerViewController_iPad" bundle:nil]; - self.datePickerViewController.delegate = self; - [self.datePickerViewController showInView:self.navigationController.view animated:YES]; - } - else - { - self.datePickerViewController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerViewController" bundle:nil]; - self.datePickerViewController.delegate = self; - [self.datePickerViewController showInView:self.navigationController.view animated:YES]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + self.datePickerViewController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerViewController_iPad" bundle:nil]; + self.datePickerViewController.delegate = self; + [self.datePickerViewController showInView:self.navigationController.view animated:YES]; + } + else + { + self.datePickerViewController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerViewController" bundle:nil]; + self.datePickerViewController.delegate = self; + [self.datePickerViewController showInView:self.navigationController.view animated:YES]; + } } } //Update Product Price command else if([cellName isEqualToString:NSLocalizedString(@"Update product price", nil)]) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if(self.sentCommand == NONE) { - self.priceChangerViewController = [[PriceChangerViewController alloc] initWithNibName:@"PriceChangerViewController_iPad" bundle:nil]; - self.priceChangerViewController.delegate = self; - [self.priceChangerViewController showInView:self.navigationController.view animated:YES]; - } - else - { - self.priceChangerViewController = [[PriceChangerViewController alloc] initWithNibName:@"PriceChangerViewController" bundle:nil]; - self.priceChangerViewController.delegate = self; - [self.priceChangerViewController showInView:self.navigationController.view animated:YES]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + self.priceChangerViewController = [[PriceChangerViewController alloc] initWithNibName:@"PriceChangerViewController_iPad" bundle:nil]; + self.priceChangerViewController.delegate = self; + [self.priceChangerViewController showInView:self.navigationController.view animated:YES]; + } + else + { + self.priceChangerViewController = [[PriceChangerViewController alloc] initWithNibName:@"PriceChangerViewController" bundle:nil]; + self.priceChangerViewController.delegate = self; + [self.priceChangerViewController showInView:self.navigationController.view animated:YES]; + } } } //Update Product Name command else if([cellName isEqualToString:NSLocalizedString(@"Update product name", nil)]) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) - { - self.nameChangerViewController = [[NameChangerViewController alloc] initWithNibName:@"NameChangerViewController_iPad" bundle:nil]; - self.nameChangerViewController.delegate = self; - [self.nameChangerViewController showInView:self.navigationController.view animated:YES]; - } - else + if(self.sentCommand == NONE) { - self.nameChangerViewController = [[NameChangerViewController alloc] initWithNibName:@"NameChangerViewController" bundle:nil]; - self.nameChangerViewController.delegate = self; - [self.nameChangerViewController showInView:self.navigationController.view animated:YES]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + { + self.nameChangerViewController = [[NameChangerViewController alloc] initWithNibName:@"NameChangerViewController_iPad" bundle:nil]; + self.nameChangerViewController.delegate = self; + [self.nameChangerViewController showInView:self.navigationController.view animated:YES]; + } + else + { + self.nameChangerViewController = [[NameChangerViewController alloc] initWithNibName:@"NameChangerViewController" bundle:nil]; + self.nameChangerViewController.delegate = self; + [self.nameChangerViewController showInView:self.navigationController.view animated:YES]; + } } } } @@ -712,6 +841,13 @@ } } + else if([self currentNavLevel] == INCIDENT_LIST) + { + if([self generateIncidentNavLevel: [indexPath row]]) + { + [self changeNavLevel:INCIDENT:TRUE]; + } + } } #pragma mark - Table view data source @@ -1140,6 +1276,23 @@ } } } + else if([self currentNavLevel] == INCIDENT) + { + [[[cell contentView] viewWithTag:CELL_CARAT_TAG] removeFromSuperview]; + [[cell detailTextLabel] setText:@""]; + [cell setAccessoryView:nil]; + [cell setAccessoryType:UITableViewCellAccessoryNone]; + if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Error Code",nil)]) + { + [[cell detailTextLabel] setText:[self.currentIncident errorCode]]; + [cell setAccessoryView:nil]; + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Error Value",nil)]) + { + [[cell detailTextLabel] setText:[self.currentIncident errorCode]]; + [cell setAccessoryView:nil]; + } + } return cell; } @@ -1152,6 +1305,7 @@ NSLog(@"[MenuTableViewController.m]: %@", components); [_protocol updateTime: components]; [self setSentCommand:A5]; + [self startTimeoutTimer]; } - (void)passPriceViewController:(PriceChangerViewController *)controller didFinishEnteringItem:(NSArray *)data @@ -1193,6 +1347,7 @@ NSArray *price = [priceString componentsSeparatedByString:@"."]; [_protocol updatePrice:channel :code :[[price objectAtIndex:0] intValue] :[[price objectAtIndex:1] intValue]]; [self setSentCommand:A6]; + [self startTimeoutTimer]; } } @@ -1229,6 +1384,7 @@ int code = [codeString intValue]; [_protocol updateProductName:channel :code :name]; [self setSentCommand:A7]; + [self startTimeoutTimer]; } } @@ -1252,10 +1408,28 @@ componentsTo = [calendar components:units fromDate:to]; } [_protocol readSalesLog: componentsFrom : componentsTo]; + [self setSentCommand:A2]; + [self startTimeoutTimer]; } else if([self requestedLog] == INCIDENT_LOG) { + NSLog(@"[MenuTableViewController.m]: Changing to navLevel: INCIDENT_LIST"); + NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; + NSDateComponents *componentsFrom = nil; + NSDateComponents *componentsTo = nil; + if(from != nil) + { + componentsFrom = [calendar components:units fromDate:from]; + } + if(to != nil) + { + componentsTo = [calendar components:units fromDate:to]; + } + [_protocol readIncidentLog: componentsFrom : componentsTo]; + [self setSentCommand:A3]; + [self startTimeoutTimer]; } } diff --git a/DUREX Vendor Control/en.lproj/Localizable.strings b/DUREX Vendor Control/en.lproj/Localizable.strings index 527f3f0..9eb4c02 100644 --- a/DUREX Vendor Control/en.lproj/Localizable.strings +++ b/DUREX Vendor Control/en.lproj/Localizable.strings @@ -101,4 +101,8 @@ "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"; -"Connection lost" = "Connection lost"; \ No newline at end of file +"Connection lost" = "Connection lost"; +"Device answer timeout occurred" = "Device answer timeout occurred"; +"Incident log" = "Incident log"; +"Error Code" = "Error Code"; +"Error Value" = "Error Value"; \ 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 7cea80a..88528b4 100644 --- a/DUREX Vendor Control/es.lproj/Localizable.strings +++ b/DUREX Vendor Control/es.lproj/Localizable.strings @@ -101,4 +101,8 @@ "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"; -"Connection lost" = "Conexión perdida"; \ No newline at end of file +"Connection lost" = "Conexión perdida"; +"Device answer timeout occurred" = "El tiempo de espera de respuesta del dispositivo ha expirado"; +"Incident log" = "Registro de incidencias"; +"Error Code" = "Código de error"; +"Error Value" = "Valor del error"; \ No newline at end of file diff --git a/TODO b/TODO index fcf7c9e..c8b59e2 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,14 @@ TESTS: - Multiple fragments - +- Timeout +- A3 command +- A2 command +- Prevent multiple commands sending + BUGS: - On date change, response is overwritten by previous query, trimming needed according to numBytes TODO: -- Incident class -- Incident parser -- A3 command - Channels and codes to 2 ciphers - Add landscape layout and inverted layout - Month/Year headers on sale list