diff --git a/DUREX Vendor Control/Base.lproj/Localizable.strings b/DUREX Vendor Control/Base.lproj/Localizable.strings index 86c82c5..f635f11 100644 --- a/DUREX Vendor Control/Base.lproj/Localizable.strings +++ b/DUREX Vendor Control/Base.lproj/Localizable.strings @@ -34,8 +34,10 @@ "Channel Engine Status" = "Channel Engine Status"; "Door Sensor" = "Door Sensor"; "Coil Sensor" = "Coil Sensor"; +"OPEN" = "OPEN"; +"CLOSED" = "CLOSED"; "Money Collected" = "Money Collected"; -"Money Given" = "Money Given"; +"Money Returned" = "Money Returned"; "Products Sold" = "Products Sold"; "Product 1" = "Product 1"; "Product 2" = "Product 2"; @@ -72,7 +74,7 @@ "50c Coins" = "50c Coins"; "Channel" = "Channel"; "Product Code" = "Product Code"; -"Nominal Price" = "Nominal Price"; +"Normal Price" = "Normal Price"; "Discounted Price" = "Discounted Price"; "1€ Change" = "1€ Change"; "50c Change" = "50c Change"; diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h index b4daf3b..acfe69a 100644 --- a/DUREX Vendor Control/CommunicationProtocol.h +++ b/DUREX Vendor Control/CommunicationProtocol.h @@ -13,15 +13,14 @@ #define MAX_RETRIES ((int)3) #define MAX_PRODUCT_NAME_LENGTH ((int)64) #define MAX_CHANNELS ((int)16) -#define MONEY_NUM_UNITS ((int)5) +#define MONEY_IN_NUM_UNITS ((int)5) +#define MONEY_OUT_NUM_UNITS ((int)3) +#define CHANGE_NUM_UNITS ((int)2) #define MAX_PRODUCTS ((int)16) @interface CommunicationProtocol : NSObject -@property Boolean messageAvailableMobile; -@property Boolean messageAvailableDevice; - -(Boolean) waitForMessageAvailableMobile: (Boolean) status; -(Boolean) waitForMessageAvailableDevice: (Boolean) status; -(Boolean) writeMessage: (NSString*) message; @@ -31,6 +30,7 @@ -(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: (NSDate*) start : (NSDate*) end; +(id) sharedProtocol; @end diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m index 1c1560f..bd2c827 100644 --- a/DUREX Vendor Control/CommunicationProtocol.m +++ b/DUREX Vendor Control/CommunicationProtocol.m @@ -10,6 +10,9 @@ @interface CommunicationProtocol () +@property Boolean messageAvailableMobile; +@property Boolean messageAvailableDevice; + @end @implementation CommunicationProtocol @@ -20,6 +23,8 @@ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ shared = [[self alloc] init]; + [shared setMessageAvailableDevice:FALSE]; + [shared setMessageAvailableMobile:FALSE]; }); return shared; } @@ -358,37 +363,61 @@ { NSString *command = @"A4"; [self writeMessage:command]; - //NSString *answer = [self readMessage]; + NSString *answer = [self readMessage]; - char command_str[65]; - command_str[0] = 'P'; - command_str[1] = '4'; - command_str[2] = 255; - command_str[3] = 0; - command_str[4] = 255; - command_str[5] = 0; - command_str[6] = 255; - command_str[7] = 0; - command_str[8] = '1'; - command_str[9] = '0'; - for(int i = 10; i < 10; i+=3) + /*NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400255002550025510"]; + for(int i = 0; i < 15; i++) + { + [answer appendString:@"0"]; + } + for(int i = 0; i < 9; i++) + { + [answer appendString:@"4"]; + } + for(int i = 0; i < 32; i++) { - command_str[i] = '0'; - command_str[i+1] = '0'; - command_str[i+2] = '0'; + [answer appendString:@"2"]; } - for(int i = 40; i < 16; i+=2) + [answer appendString:@"1"]; + [answer appendString:@"1"];*/ + + if([[answer substringToIndex:2]isEqualToString:@"P4"]) { - command_str[i] = '0'; - command_str[i+1] = '0'; + return answer; } - command_str[63] = '1'; - command_str[64] = '1'; + return nil; +} + +-(NSString*) readSalesLog : (NSDate*) start : (NSDate*) end +{ + NSMutableString *startDate = [[NSMutableString alloc] init]; + NSMutableString *endDate = [[NSMutableString alloc] init]; + NSMutableString *command = [NSMutableString stringWithString:@"A2"]; + if(start == nil) + { + [startDate setString:@""]; + } + else + { + + } + if(end == nil) + { + [endDate setString:@""]; + } + else + { + + } + [command appendString:startDate]; + [command appendString:@"-"]; + [command appendString:endDate]; + [self writeMessage:command]; + //NSString *answer = [self readMessage]; - NSMutableString *answer = [[NSMutableString alloc]init]; - [answer appendString:[NSString stringWithUTF8String:command_str]]; + NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21405141651102416090662045001500512P21406141651102416090662045001500512P2P2"]; - if([[answer substringToIndex:2] isEqualToString:@"P4"]) + if([[answer substringToIndex:2]isEqualToString:@"P2"]) { return answer; } diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj index 1f5c6f3..658a587 100644 --- a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj +++ b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj @@ -36,6 +36,10 @@ F98356DB192EAFD400EA6821 /* CommunicationProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */; }; F98356E1192EC84700EA6821 /* MenuTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F98356E0192EC84700EA6821 /* MenuTableViewController.m */; }; F98446F019B9EAE9005C4992 /* Sensors.m in Sources */ = {isa = PBXBuildFile; fileRef = F98446EF19B9EAE9005C4992 /* Sensors.m */; }; + F989B5FB19BBC80300657DD9 /* carat-open.png in Resources */ = {isa = PBXBuildFile; fileRef = F989B5F919BBC80300657DD9 /* carat-open.png */; }; + F989B5FC19BBC80300657DD9 /* carat.png in Resources */ = {isa = PBXBuildFile; fileRef = F989B5FA19BBC80300657DD9 /* carat.png */; }; + F989B5FF19BCD7A100657DD9 /* Sale.m in Sources */ = {isa = PBXBuildFile; fileRef = F989B5FE19BCD7A100657DD9 /* Sale.m */; }; + F989B60219BCE28C00657DD9 /* SalesLog.m in Sources */ = {isa = PBXBuildFile; fileRef = F989B60119BCE28C00657DD9 /* SalesLog.m */; }; F9A8EF7C192FE201009E7532 /* Stack.m in Sources */ = {isa = PBXBuildFile; fileRef = F9A8EF7B192FE201009E7532 /* Stack.m */; }; F9C77F50192CDE30002DBE8A /* system.json in Resources */ = {isa = PBXBuildFile; fileRef = F9C77F4F192CDE30002DBE8A /* system.json */; }; F9E4D8FD19B8FD32009A7359 /* EMConnectingView_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = F9E4D8FF19B8FD32009A7359 /* EMConnectingView_iPad.xib */; }; @@ -118,6 +122,12 @@ F98356E0192EC84700EA6821 /* MenuTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuTableViewController.m; sourceTree = SOURCE_ROOT; }; F98446EE19B9EAE9005C4992 /* Sensors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sensors.h; sourceTree = SOURCE_ROOT; }; F98446EF19B9EAE9005C4992 /* Sensors.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sensors.m; sourceTree = SOURCE_ROOT; }; + F989B5F919BBC80300657DD9 /* carat-open.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "carat-open.png"; sourceTree = SOURCE_ROOT; }; + F989B5FA19BBC80300657DD9 /* carat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = carat.png; sourceTree = SOURCE_ROOT; }; + F989B5FD19BCD7A100657DD9 /* Sale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sale.h; sourceTree = SOURCE_ROOT; }; + F989B5FE19BCD7A100657DD9 /* Sale.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sale.m; sourceTree = SOURCE_ROOT; }; + F989B60019BCE28C00657DD9 /* SalesLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SalesLog.h; sourceTree = SOURCE_ROOT; }; + F989B60119BCE28C00657DD9 /* SalesLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SalesLog.m; sourceTree = SOURCE_ROOT; }; 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; }; F9C77F4F192CDE30002DBE8A /* system.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = system.json; sourceTree = SOURCE_ROOT; }; @@ -190,6 +200,8 @@ F92F568E19B763FD00A1EACA /* NameChangerViewController.m */, 34AAB880189804FF0019860D /* main.m */, F98446EF19B9EAE9005C4992 /* Sensors.m */, + F989B5FE19BCD7A100657DD9 /* Sale.m */, + F989B60119BCE28C00657DD9 /* SalesLog.m */, ); name = "DUREX Vendor Control"; path = TestAppExample; @@ -283,6 +295,8 @@ F92F567619B75F5E00A1EACA /* PriceChangerViewController.h */, F92F568D19B763FD00A1EACA /* NameChangerViewController.h */, F98446EE19B9EAE9005C4992 /* Sensors.h */, + F989B5FD19BCD7A100657DD9 /* Sale.h */, + F989B60019BCE28C00657DD9 /* SalesLog.h */, ); name = Headers; sourceTree = ""; @@ -291,6 +305,8 @@ isa = PBXGroup; children = ( 34AAB88C189805300019860D /* Images.xcassets */, + F989B5F919BBC80300657DD9 /* carat-open.png */, + F989B5FA19BBC80300657DD9 /* carat.png */, F97B90C919B859F500DDA9EF /* icon_checkmark.png */, F97B90CA19B859F500DDA9EF /* icon_delete.png */, F961D80E199A5F2D00E9282C /* back_arrow.png */, @@ -360,6 +376,7 @@ F9015D9719B7305E006C7882 /* DatePickerViewController_iPad.xib in Resources */, F961D819199A711300E9282C /* EMConnectingView.xib in Resources */, F9C77F50192CDE30002DBE8A /* system.json in Resources */, + F989B5FC19BBC80300657DD9 /* carat.png in Resources */, F92F569B19B76A5D00A1EACA /* NameChangerViewController_iPad.xib in Resources */, F92F567D19B7609C00A1EACA /* PriceChangerViewController.xib in Resources */, F92F569219B7665F00A1EACA /* NameChangerViewController.xib in Resources */, @@ -367,6 +384,7 @@ F961D816199A5FA000E9282C /* Localizable.strings in Resources */, F97B90CB19B859F500DDA9EF /* icon_checkmark.png in Resources */, 34AAB88D189805300019860D /* Images.xcassets in Resources */, + F989B5FB19BBC80300657DD9 /* carat-open.png in Resources */, F92F568419B760A800A1EACA /* PriceChangerViewController_iPad.xib in Resources */, F961D804199A5F1000E9282C /* MainStoryboard.storyboard in Resources */, ); @@ -381,9 +399,11 @@ files = ( F92F569019B763FD00A1EACA /* NameChangerViewController.m in Sources */, F933F80419B6819400521B90 /* DatePickerViewController.m in Sources */, + F989B5FF19BCD7A100657DD9 /* Sale.m in Sources */, F98356D6192E835F00EA6821 /* InitialViewController.m in Sources */, F9A8EF7C192FE201009E7532 /* Stack.m in Sources */, 34AAB885189804FF0019860D /* EMDevicePickerViewController.m in Sources */, + F989B60219BCE28C00657DD9 /* SalesLog.m in Sources */, F92F567919B75F5E00A1EACA /* PriceChangerViewController.m in Sources */, 34AAB883189804FF0019860D /* DUREXAppDelegate.m in Sources */, F98356DB192EAFD400EA6821 /* CommunicationProtocol.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 2ad7c26..63ef1aa 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 82b8f96..fe2b454 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 @@ -2,86 +2,4 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard b/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard index aa6cdb3..3efc01b 100644 --- a/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard +++ b/DUREX Vendor Control/FirstAppExample/Base.lproj/MainStoryboard.storyboard @@ -7,7 +7,6 @@ - @@ -49,6 +48,7 @@ + diff --git a/DUREX Vendor Control/FirstAppExample/main.m b/DUREX Vendor Control/FirstAppExample/main.m index 12cf982..68b8059 100644 --- a/DUREX Vendor Control/FirstAppExample/main.m +++ b/DUREX Vendor Control/FirstAppExample/main.m @@ -1,4 +1,4 @@ -// + // // main.m // TestAppExample // diff --git a/DUREX Vendor Control/MenuTableViewController.h b/DUREX Vendor Control/MenuTableViewController.h index 7f3465c..a47ba40 100644 --- a/DUREX Vendor Control/MenuTableViewController.h +++ b/DUREX Vendor Control/MenuTableViewController.h @@ -14,22 +14,30 @@ #import "PriceChangerViewController.h" #import "NameChangerViewController.h" #import "Sensors.h" +#import "SalesLog.h" #define num(x) [NSNumber numberWithUnsignedInt:x] -#define MENU_ELEMENTS @"Maintenance",@"Basic Configuration",@"Sending a Report" +#define CELL_CARAT_TAG 100 + +#define MENU_ELEMENTS @"[1000]Maintenance",@"[1001]Basic Configuration",@"[1002]Sending a Report" #define MENU_CELLS_PER_SECTION num(3) -#define MENU_HEADERS nil +#define MENU_HEADERS nil -#define MAINTENANCE_ELEMENTS @"Channels Present",@"Product Present in Channel",@"Channel Engine Status",@"Door Sensor",@"Coil sensor",@"Money Collected",@"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Money given",@"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Products Sold",@"Change Available",@"1€ Coins",@"50c Coins",@"Sales log",@"Incident report",@"Send report" -#define MAINTENANCE_CELLS_PER_SECTION num(21),num(3) +#define MAINTENANCE_ELEMENTS @">[2000]Channels Present",@">[2001]Product Present in Channel",@">[2002]Channel Engine Status",@"[2003]Door Sensor",@"[2004]Coil Sensor",@">[2005]Money Collected",@">[2006]Money Returned",@">[2007]Products Sold",@">[2008]Change Available",@"[2009]Sales log",@"[2010]Incident report",@"[2011]Send report" +#define MAINTENANCE_CHANNELS @"*Channel 1",@"*Channel 2",@"*Channel 3",@"*Channel 4",@"*Channel 5",@"*Channel 6",@"*Channel 7",@"*Channel 8",@"*Channel 9",@"*Channel 10",@"*Channel 11",@"*Channel 12",@"*Channel 13",@"*Channel 14",@"*Channel 15",@"*Channel 16" +#define MAINTENANCE_MONEY_IN @"*10€ Notes",@"*5€ Notes",@"*2€ Coins",@"*1€ Coins",@"*50c Coins" +#define MAINTENANCE_MONEY_OUT @"*2€ Coins",@"*1€ Coins",@"*50c Coins" +#define MAINTENANCE_CHANGE @"*1€ Coins",@"*50c Coins" +#define MAINTENANCE_PRODUCTS @"*Product 1",@"*Product 2",@"*Product 3",@"*Product 4",@"*Product 5",@"*Product 6",@"*Product 7",@"*Product 8",@"*Product 9",@"*Product 10",@"*Product 11",@"*Product 12",@"*Product 13",@"*Product 14",@"*Product 15",@"*Product 16" +#define MAINTENANCE_CELLS_PER_SECTION num(9),num(3) #define MAINTENANCE_HEADERS NSLocalizedString(@"Sensors", nil),NSLocalizedString(@"Commands", nil) -#define SALES_ELEMENTS @"20€ Notes",@"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Channel",@"Product Code",@"Nominal Price",@"Discounted Price",@"1€ Change",@"50c Change",@"20€ Notes",@"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Channel",@"Product Code",@"Nominal Price",@"Discounted Price",@"1€ Change",@"50c Change",@"20€ Notes",@"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Channel",@"Product Code",@"Nominal Price",@"Discounted Price",@"1€ Change",@"50c Change" -#define SALES_CELLS_PER_SECTION num(12),num(12),num(12) -#define SALES_HEADERS @"14/06/2014",@"25/06/2014",@"05/07/2014" +#define SALES_ELEMENTS @"10€ Notes",@"5€ Notes",@"2€ Coins",@"1€ Coins",@"50c Coins",@"Channel",@"Product Code",@"Normal Price",@"Discounted Price",@"1€ Change",@"50c Change" +#define SALES_CELLS_PER_SECTION num(11) +#define SALES_HEADERS @"14/06/2014" -#define CONFIGURATION_ELEMENTS @"Update Date & Time",@"Update product price",@"Update product name" +#define CONFIGURATION_ELEMENTS @"[3000]Update Date & Time",@"[3001]Update product price",@"[3002]Update product name" #define CONFIGURATION_CELLS_PER_SECTION num(3) #define CONFIGURATION_HEADERS nil @@ -50,6 +58,7 @@ enum { @property (strong,nonatomic) PriceChangerViewController *priceChangerViewController; @property (strong,nonatomic) NameChangerViewController *nameChangerViewController; @property (strong,nonatomic) Sensors *sensorStatus; +@property (strong,nonatomic) SalesLog *salesLog; - (void) navBack; diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m index bdd3467..091f383 100644 --- a/DUREX Vendor Control/MenuTableViewController.m +++ b/DUREX Vendor Control/MenuTableViewController.m @@ -13,30 +13,30 @@ IBOutlet UIActivityIndicatorView *_activityIndicator; NSTimer *_writeTimer; } -@property (nonatomic,strong) const NSArray *menuElements; -@property (nonatomic,strong) const NSArray *menuStructure; -@property (nonatomic,strong) const NSArray *menuHeaders; +@property (nonatomic,strong) const NSMutableArray *menuElements; +@property (nonatomic,strong) const NSMutableArray *menuStructure; +@property (nonatomic,strong) const NSMutableArray *menuHeaders; -@property (nonatomic,strong) const NSArray *maintenanceElements; -@property (nonatomic,strong) const NSArray *maintenanceStructure; -@property (nonatomic,strong) const NSArray *maintenanceHeaders; +@property (nonatomic,strong) const NSMutableArray *maintenanceElements; +@property (nonatomic,strong) const NSMutableArray *maintenanceStructure; +@property (nonatomic,strong) const NSMutableArray *maintenanceHeaders; -@property (nonatomic,strong) const NSArray *salesElements; -@property (nonatomic,strong) const NSArray *salesStructure; -@property (nonatomic,strong) const NSArray *salesHeaders; +@property (nonatomic,strong) const NSMutableArray *salesElements; +@property (nonatomic,strong) const NSMutableArray *salesStructure; +@property (nonatomic,strong) const NSMutableArray *salesHeaders; -@property (nonatomic,strong) const NSArray *configElements; -@property (nonatomic,strong) const NSArray *configStructure; -@property (nonatomic,strong) const NSArray *configHeaders; +@property (nonatomic,strong) const NSMutableArray *configElements; +@property (nonatomic,strong) const NSMutableArray *configStructure; +@property (nonatomic,strong) const NSMutableArray *configHeaders; @property (nonatomic,strong) const NSArray *cellIdentifiers; @property (nonatomic,strong) CommunicationProtocol* protocol; @property uint8_t currentNavLevel; @property NSString *currentCellIdentifier; -@property const NSArray *currentElements; -@property const NSArray *currentStructure; -@property const NSArray *currentHeaders; +@property const NSMutableArray *currentElements; +@property const NSMutableArray *currentStructure; +@property const NSMutableArray *currentHeaders; @end @@ -54,22 +54,22 @@ - (void) initializeMenuEntries { - [self setMenuElements:[[NSArray alloc] initWithObjects:MENU_ELEMENTS, nil]]; - [self setMenuStructure:[[NSArray alloc] initWithObjects:MENU_CELLS_PER_SECTION, nil]]; + [self setMenuElements:[[NSMutableArray alloc] initWithObjects:MENU_ELEMENTS, nil]]; + [self setMenuStructure:[[NSMutableArray alloc] initWithObjects:MENU_CELLS_PER_SECTION, nil]]; if([[self menuStructure] count] > 1) { - [self setMenuHeaders:[[NSArray alloc] initWithObjects:MENU_HEADERS, nil]]; + [self setMenuHeaders:[[NSMutableArray alloc] initWithObjects:MENU_HEADERS, nil]]; } else { [self setMenuHeaders:nil]; } - [self setConfigElements:[[NSArray alloc] initWithObjects:CONFIGURATION_ELEMENTS, nil]]; - [self setConfigStructure:[[NSArray alloc] initWithObjects:CONFIGURATION_CELLS_PER_SECTION, nil]]; + [self setConfigElements:[[NSMutableArray alloc] initWithObjects:CONFIGURATION_ELEMENTS, nil]]; + [self setConfigStructure:[[NSMutableArray alloc] initWithObjects:CONFIGURATION_CELLS_PER_SECTION, nil]]; if([[self configStructure] count] > 1) { - [self setConfigHeaders:[[NSArray alloc] initWithObjects:CONFIGURATION_HEADERS, nil]]; + [self setConfigHeaders:[[NSMutableArray alloc] initWithObjects:CONFIGURATION_HEADERS, nil]]; } else { @@ -79,34 +79,49 @@ [self setCellIdentifiers:[[NSArray alloc] initWithObjects:CELL_IDENTIFIERS, nil]]; } -- (void) generateMaintenanceLevel +- (Boolean) generateMaintenanceLevel { - [[self sensorStatus] setResponse:[_protocol readSensorData]]; - //DO SUM SHIET - [self setMaintenanceElements:[[NSArray alloc] initWithObjects:MAINTENANCE_ELEMENTS, nil]]; - [self setMaintenanceStructure:[[NSArray alloc] initWithObjects:MAINTENANCE_CELLS_PER_SECTION, nil]]; + 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) { - [self setMaintenanceHeaders:[[NSArray alloc] initWithObjects:MAINTENANCE_HEADERS, nil]]; + [self setMaintenanceHeaders:[[NSMutableArray alloc] initWithObjects:MAINTENANCE_HEADERS, nil]]; } else { [self setMaintenanceHeaders:nil]; } + return TRUE; } -- (void) generateSalesNavLevel +- (Boolean) generateSalesNavLevel { - [self setSalesElements:[[NSArray alloc] initWithObjects:SALES_ELEMENTS, nil]]; - [self setSalesStructure:[[NSArray alloc] initWithObjects:SALES_CELLS_PER_SECTION, nil]]; + //LAUNCH DATE RANGE SELECTOR + NSString *salesData = [_protocol readSalesLog: nil : nil]; + if(salesData == nil) + { + NSLog(@"[MenuTableViewController.m]: Error reading sales log"); + return FALSE; + } + [[self salesLog] setResponseValue:salesData]; + [self setSalesElements:[[NSMutableArray alloc] initWithObjects:SALES_ELEMENTS, nil]]; + [self setSalesStructure:[[NSMutableArray alloc] initWithObjects:SALES_CELLS_PER_SECTION, nil]]; if([[self salesStructure] count] > 1) { - [self setSalesHeaders:[[NSArray alloc] initWithObjects:SALES_HEADERS, nil]]; + [self setSalesHeaders:[[NSMutableArray alloc] initWithObjects:SALES_HEADERS, nil]]; } else { [self setSalesHeaders:nil]; } + return TRUE; } - (void) changeNavLevel: (uint8_t) level : (BOOL) push @@ -147,10 +162,15 @@ [self setCurrentHeaders:[self configHeaders]]; } //AND SO ON... + [self reloadTable:UITableViewRowAnimationAutomatic]; +} + +- (void) reloadTable: (UITableViewRowAnimation) animation +{ [[self tableView] reloadData]; NSRange range = NSMakeRange(0, [self numberOfSectionsInTableView:[self tableView]]); NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range]; - [[self tableView] reloadSections:sections withRowAnimation:UITableViewRowAnimationAutomatic]; + [[self tableView] reloadSections:sections withRowAnimation:animation]; } - (void) navBack @@ -217,12 +237,6 @@ //Initialize sensor status [self setSensorStatus:[[Sensors alloc]init]]; - - // Uncomment the following line to preserve selection between presentations. - // self.clearsSelectionOnViewWillAppear = NO; - - // Uncomment the following line to display an Edit button in the navigation bar for this view controller. - // self.navigationItem.rightBarButtonItem = self.editButtonItem; } -(void)viewDidAppear:(BOOL)animated @@ -230,8 +244,6 @@ [super viewDidAppear:animated]; //DUREX protocol - [_protocol setMessageAvailableMobile:false]; - [_protocol setMessageAvailableDevice:false]; if(![_protocol establishConnection]) { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Communication error" message:@"Error while trying to connect to the device" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; @@ -243,7 +255,7 @@ -(void)didReceiveNotification:(NSNotification*) notification { - + } -(void)dealloc @@ -274,94 +286,267 @@ #pragma mark - Table view delegate -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +- (void) addTags : (NSMutableArray*) rows : (NSInteger) tag { - NSLog(@"Section: %ld Row: %ld",(long)[indexPath section],(long)[indexPath row]); - [tableView deselectRowAtIndexPath:indexPath animated:YES]; - NSString *cellName = [[[[self tableView] cellForRowAtIndexPath:indexPath]textLabel]text]; - if([cellName isEqualToString:NSLocalizedString(@"Maintenance", nil)] && [self currentNavLevel] == MENU) + for(int i = 0; i < [rows count]; i++) { - NSLog(@"[MenuTableViewController.m]: Changing to navLevel: MAINTENANCE"); - [self generateMaintenanceLevel]; - [self changeNavLevel:MAINTENANCE:TRUE]; + NSMutableString *name = [NSMutableString stringWithString:[rows objectAtIndex:i]]; + [name insertString:[NSString stringWithFormat:@"[%d]",tag] atIndex:1]; + [rows replaceObjectAtIndex:i withObject:name]; } - else if([cellName isEqualToString:NSLocalizedString(@"Sales log", nil)] && [self currentNavLevel] == MAINTENANCE) +} + +- (void) toggleDropList : (NSIndexPath*) index +{ + Boolean folded = FALSE; + NSString *elementName = [[self currentElements] objectAtIndex:index.row]; + NSMutableString *newElementName = [[NSMutableString alloc] init]; + if([elementName characterAtIndex:0] == '>') { - NSLog(@"[MenuTableViewController.m]: Changing to navLevel: SALES"); - [self generateSalesNavLevel]; - [self changeNavLevel:SALES:TRUE]; + [newElementName setString:@"v"]; + [newElementName appendString:[elementName substringFromIndex:1]]; + folded = TRUE; } - else if([cellName isEqualToString:NSLocalizedString(@"Basic Configuration", nil)] && [self currentNavLevel] == MENU) + else { - NSLog(@"[MenuTableViewController.m]: Changing to navLevel: BASIC_CONFIGURATION"); - [self changeNavLevel:BASIC_CONFIGURATION:TRUE]; + [newElementName setString:@">"]; + [newElementName appendString:[elementName substringFromIndex:1]]; } - //Update Date & Time command - else if([cellName isEqualToString:NSLocalizedString(@"Update Date & Time", nil)] && [self currentNavLevel] == BASIC_CONFIGURATION) + [[self currentElements] replaceObjectAtIndex:index.row withObject:newElementName]; + NSMutableString *cellName = [NSMutableString stringWithString:[elementName substringFromIndex:1]]; + NSInteger lastPos = [cellName rangeOfString:@"]"].location; + NSInteger cellTag = [[cellName substringWithRange:NSMakeRange(1,lastPos)] intValue]; + [cellName setString:[cellName substringFromIndex:lastPos+1]]; + + //Cells in MENU + if([self currentNavLevel] == MAINTENANCE) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if([cellName isEqualToString:@"Channels Present"] || + [cellName isEqualToString:@"Product Present in Channel"] || + [cellName isEqualToString:@"Channel Engine Status"]) { - self.datePickerViewController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerViewController_iPad" bundle:nil]; - self.datePickerViewController.delegate = self; - [self.datePickerViewController showInView:self.navigationController.view animated:YES]; + NSMutableArray *newRows = [[NSMutableArray alloc] initWithObjects:MAINTENANCE_CHANNELS, nil]; + [newRows setArray:[newRows subarrayWithRange:NSMakeRange(0, [[self sensorStatus] numChannels])]]; + if(folded) + { + [self addTags: newRows : cellTag]; + [self addRowsAtIndexPath: newRows : index]; + } + else + { + [self removeRowsAtIndexPath: [newRows count] : index]; + } } - else + else if([cellName isEqualToString:@"Money Collected"]) { - self.datePickerViewController = [[DatePickerViewController alloc] initWithNibName:@"DatePickerViewController" bundle:nil]; - self.datePickerViewController.delegate = self; - [self.datePickerViewController showInView:self.navigationController.view animated:YES]; + NSMutableArray *newRows = [[NSMutableArray alloc] initWithObjects:MAINTENANCE_MONEY_IN, nil]; + if(folded) + { + [self addTags: newRows : cellTag]; + [self addRowsAtIndexPath: newRows : index]; + } + else + { + [self removeRowsAtIndexPath: [newRows count] : index]; + } + } + else if([cellName isEqualToString:@"Money Returned"]) + { + NSMutableArray *newRows = [[NSMutableArray alloc] initWithObjects:MAINTENANCE_MONEY_OUT, nil]; + if(folded) + { + [self addTags: newRows : cellTag]; + [self addRowsAtIndexPath: newRows : index]; + } + else + { + [self removeRowsAtIndexPath: [newRows count] : index]; + } + } + else if([cellName isEqualToString:@"Products Sold"]) + { + NSMutableArray *newRows = [[NSMutableArray alloc] initWithObjects:MAINTENANCE_PRODUCTS, nil]; + if(folded) + { + [self addTags: newRows : cellTag]; + [self addRowsAtIndexPath: newRows : index]; + } + else + { + [self removeRowsAtIndexPath: [newRows count] : index]; + } + } + else if([cellName isEqualToString:@"Change Available"]) + { + NSMutableArray *newRows = [[NSMutableArray alloc] initWithObjects:MAINTENANCE_CHANGE, nil]; + if(folded) + { + [self addTags: newRows : cellTag]; + [self addRowsAtIndexPath: newRows : index]; + } + else + { + [self removeRowsAtIndexPath: [newRows count] : index]; + } } } - //Update Product Price command - else if([cellName isEqualToString:NSLocalizedString(@"Update product price", nil)] && [self currentNavLevel] == BASIC_CONFIGURATION) + [self reloadTable:UITableViewRowAnimationNone]; +} + +- (void) addRowsAtIndexPath : (NSArray*) rows : (NSIndexPath*) indexPath +{ + NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange([indexPath row] + 1, [rows count])]; + [[self currentElements] insertObjects:rows atIndexes:indexSet]; + [[self currentStructure] replaceObjectAtIndex:[indexPath section] withObject:[NSNumber numberWithInt:([[[self currentStructure] objectAtIndex:[indexPath section]] intValue] + [rows count])]]; +} + +- (void) removeRowsAtIndexPath : (NSUInteger) numRows : (NSIndexPath*) indexPath +{ + NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange([indexPath row] + 1, numRows)]; + [[self currentElements] removeObjectsAtIndexes:indexSet]; + [[self currentStructure] replaceObjectAtIndex:[indexPath section] withObject:[NSNumber numberWithInt:([[[self currentStructure] objectAtIndex:[indexPath section]] intValue] - numRows)]]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [[[self currentStructure] objectAtIndex:section] intValue]; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSLog(@"Section: %ld Row: %ld",(long)[indexPath section],(long)[indexPath row]); + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + UITableViewCell *cell = [[self tableView] cellForRowAtIndexPath:indexPath]; + NSString *cellName = [[cell textLabel]text]; + //Cells in MENU + if([self currentNavLevel] == MENU) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if([cellName isEqualToString:NSLocalizedString(@"Maintenance", nil)]) { - self.priceChangerViewController = [[PriceChangerViewController alloc] initWithNibName:@"PriceChangerViewController_iPad" bundle:nil]; - self.priceChangerViewController.delegate = self; - [self.priceChangerViewController showInView:self.navigationController.view animated:YES]; + NSLog(@"[MenuTableViewController.m]: Changing to navLevel: MAINTENANCE"); + if([self generateMaintenanceLevel]) + { + [self changeNavLevel:MAINTENANCE:TRUE]; + } + else + { + NSLog(@"[MenuTableViewController.m]: Error while changing to navLevel: MAINTENANCE"); + } } - else + else if([cellName isEqualToString:NSLocalizedString(@"Basic Configuration", nil)]) { - self.priceChangerViewController = [[PriceChangerViewController alloc] initWithNibName:@"PriceChangerViewController" bundle:nil]; - self.priceChangerViewController.delegate = self; - [self.priceChangerViewController showInView:self.navigationController.view animated:YES]; + NSLog(@"[MenuTableViewController.m]: Changing to navLevel: BASIC_CONFIGURATION"); + [self changeNavLevel:BASIC_CONFIGURATION:TRUE]; + } + else if([cellName isEqualToString:NSLocalizedString(@"Sending a Report", nil)]) + { + } } - //Update Product Name command - else if([cellName isEqualToString:NSLocalizedString(@"Update product name", nil)] && [self currentNavLevel] == BASIC_CONFIGURATION) + //Cells in MAINTENANCE + else if([self currentNavLevel] == MAINTENANCE) { - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + if([cellName isEqualToString:NSLocalizedString(@"Channels Present", nil)] || + [cellName isEqualToString:NSLocalizedString(@"Product Present in Channel", nil)] || + [cellName isEqualToString:NSLocalizedString(@"Channel Engine Status", nil)] || + [cellName isEqualToString:NSLocalizedString(@"Money Collected", nil)] || + [cellName isEqualToString:NSLocalizedString(@"Money Returned", nil)] || + [cellName isEqualToString:NSLocalizedString(@"Products Sold", nil)] || + [cellName isEqualToString:NSLocalizedString(@"Change Available", nil)]) { - self.nameChangerViewController = [[NameChangerViewController alloc] initWithNibName:@"NameChangerViewController_iPad" bundle:nil]; - self.nameChangerViewController.delegate = self; - [self.nameChangerViewController showInView:self.navigationController.view animated:YES]; + [self toggleDropList:indexPath]; } - else + else if([cellName isEqualToString:NSLocalizedString(@"Sales log", nil)]) + { + NSLog(@"[MenuTableViewController.m]: Changing to navLevel: SALES"); + if([self generateSalesNavLevel]) + { + [self changeNavLevel:SALES:TRUE]; + } + else + { + NSLog(@"[MenuTableViewController.m]: Error while changing to navLevel: SALES"); + } + } + } + //Cells in BASIC_CONFIGURATION + else if([self currentNavLevel] == BASIC_CONFIGURATION) + { + //Update Date & Time command + if([cellName isEqualToString:NSLocalizedString(@"Update Date & Time", nil)]) + { + 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)]) { - 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.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 + { + self.nameChangerViewController = [[NameChangerViewController alloc] initWithNibName:@"NameChangerViewController" bundle:nil]; + self.nameChangerViewController.delegate = self; + [self.nameChangerViewController showInView:self.navigationController.view animated:YES]; + } } } } #pragma mark - Table view data source -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +-(NSInteger)tableView: (UITableView *)tableView indentationLevelForRowAtIndexPath: (NSIndexPath *)indexPath { - return [[self currentStructure] count]; + NSInteger indent = 0; + if([[[self currentElements] objectAtIndex:indexPath.row] characterAtIndex:0] == '*') + { + indent++; + } + return indent; } -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [[[self currentStructure]objectAtIndex:section] integerValue]; + return [[self currentStructure] count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + Boolean needsIndent = FALSE; + Boolean foldedList = FALSE; + Boolean unfoldedList = FALSE; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self currentCellIdentifier] forIndexPath:indexPath]; - + //INSTANTIATE CELL IF NEEDED if (cell == nil) { NSLog(@"[MenuTableViewController.m]: Initializing cell"); @@ -375,6 +560,7 @@ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:[self currentCellIdentifier]]; } } + //CALCULATE TRUE ROW TO RETRIEVE NAME uint8_t offset = 0; if([indexPath section] ) { @@ -383,24 +569,263 @@ offset += [[[self currentStructure] objectAtIndex:i] unsignedCharValue]; } } - [[cell textLabel] setText:NSLocalizedString([[self currentElements] objectAtIndex:[indexPath row]+offset],nil)]; + //RETRIEVE NAME + NSMutableString *cellText = [NSMutableString stringWithString:[[self currentElements] objectAtIndex:[indexPath row]+offset]]; + //SET INDENT + [cell setIndentationWidth:10]; + //PARSE AND REMOVE CELL MODIFIER + if([cellText characterAtIndex:0] == '>') + { + foldedList = TRUE; + [cellText setString:[cellText substringFromIndex:1]]; + } + else if([cellText characterAtIndex:0] == 'v') + { + unfoldedList = TRUE; + [cellText setString:[cellText substringFromIndex:1]]; + } + else if([cellText characterAtIndex:0] == '*') + { + needsIndent = TRUE; + [cellText setString:[cellText substringFromIndex:1]]; + } + //PARSE AND REMOVE TAG + NSInteger lastPos = [cellText rangeOfString:@"]"].location; + NSInteger cellTag = [[cellText substringWithRange:NSMakeRange(1,lastPos)] intValue]; + [cell setTag:cellTag]; + [cellText setString:[cellText substringFromIndex:lastPos+1]]; + //SET FINAL TEXT + [[cell textLabel] setText:NSLocalizedString(cellText,nil)]; + + //MAINTENANCE CELLS if([self currentNavLevel] == MAINTENANCE) { - if( [[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Sales log",nil)] || [[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Incident report",nil)] || [[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Send report",nil)]) + [[[cell contentView] viewWithTag:CELL_CARAT_TAG] removeFromSuperview]; + [[cell detailTextLabel] setText:@""]; + [cell setAccessoryView:nil]; + [cell setAccessoryType:UITableViewCellAccessoryNone]; + if(foldedList) { - [[cell detailTextLabel] setText:@""]; + NSInteger cellHeight = cell.contentView.frame.size.height; + UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,cellHeight/2 - (11/2),11,11)]; + imageView.image = [UIImage imageNamed:@"carat.png"]; + imageView.tag = CELL_CARAT_TAG; + [cell.contentView addSubview:imageView]; + } + else if(unfoldedList) + { + NSInteger cellHeight = cell.contentView.frame.size.height; + UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,cellHeight/2 - (11/2),11,11)]; + imageView.image = [UIImage imageNamed:@"carat-open.png"]; + imageView.tag = CELL_CARAT_TAG; + [cell.contentView addSubview:imageView]; + } + if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Channels Present",nil)]) + { + [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%d",[[self sensorStatus] numChannels]]]; [cell setAccessoryView:nil]; - [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } - else + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Product Present in Channel",nil)]) { - [[cell detailTextLabel] setText:@"VALUE"]; [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; - if( [[[cell textLabel] text] isEqualToString:NSLocalizedString(@"CH4 presence",nil)]) + for(int i = 0; i < [[self sensorStatus] numChannels]; i++) + { + if([[[[self sensorStatus] channelProductAvailability] objectAtIndex:i] intValue] != 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + break; + } + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Channel Engine Status",nil)]) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + for(int i = 0; i < [[self sensorStatus] numChannels]; i++) + { + if([[[[self sensorStatus] channelStatus] objectAtIndex:i] intValue] != 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + break; + } + } + } + else if([[NSRegularExpression regularExpressionWithPattern:@"Channel (\\d+)" options:0 error:NULL] numberOfMatchesInString:[[cell textLabel] text] options:0 range:(NSMakeRange(0,[[[cell textLabel] text] length]))] != 0) + { + NSUInteger index = [[[[cell textLabel] text] substringFromIndex:8] intValue] - 1; + if([cell tag] == 2001) // Products Present in Channel tag + { + if([[[[self sensorStatus] channelProductAvailability] objectAtIndex:index] intValue] == 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + } + else + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + } + } + else if([cell tag] == 2002) // Channel engine status tag + { + if([[[[self sensorStatus] channelStatus] objectAtIndex:index] intValue] == 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + } + else + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + } + } + + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Door Sensor",nil)]) + { + if([[self sensorStatus] doorOpen]) { + [[cell detailTextLabel] setText:NSLocalizedString(@"OPEN",nil)]; [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; } - + else + { + [[cell detailTextLabel] setText:NSLocalizedString(@"CLOSED",nil)]; + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Coil Sensor",nil)]) + { + if([[self sensorStatus] coilOpen]) + { + [[cell detailTextLabel] setText:NSLocalizedString(@"OPEN",nil)]; + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + } + else + { + [[cell detailTextLabel] setText:NSLocalizedString(@"CLOSED",nil)]; + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Money Collected",nil)]) + { + double numCollected = 0; + numCollected += [[[[self sensorStatus] moneyCollected] objectAtIndex:0] intValue] * 10; + numCollected += [[[[self sensorStatus] moneyCollected] objectAtIndex:1] intValue] * 5; + numCollected += [[[[self sensorStatus] moneyCollected] objectAtIndex:2] intValue] * 2; + numCollected += [[[[self sensorStatus] moneyCollected] objectAtIndex:3] intValue] * 1; + numCollected += [[[[self sensorStatus] moneyCollected] objectAtIndex:4] intValue] * 0.50; + [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%.2f",numCollected]]; + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Money Returned",nil)]) + { + double numReturned = 0; + numReturned += [[[[self sensorStatus] moneyReturned] objectAtIndex:0] intValue] * 2; + numReturned += [[[[self sensorStatus] moneyReturned] objectAtIndex:1] intValue] * 1; + numReturned += [[[[self sensorStatus] moneyReturned] objectAtIndex:2] intValue] * 0.50; + [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%.2f",numReturned]]; + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Products Sold",nil)]) + { + NSInteger numSold = 0; + for(int i = 0; i < MAX_PRODUCTS; i++) + { + numSold += [[[[self sensorStatus] productsSold] objectAtIndex:i] intValue]; + } + [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%d",numSold]]; + } + else if([[NSRegularExpression regularExpressionWithPattern:@"Product (\\d+)" options:0 error:NULL] numberOfMatchesInString:[[cell textLabel] text] options:0 range:(NSMakeRange(0,[[[cell textLabel] text] length]))] != 0) + { + NSUInteger index = [[[[cell textLabel] text] substringFromIndex:8] intValue] - 1; + if([cell tag] == 2007) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] productsSold] objectAtIndex:index] stringValue]]; + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Change Available",nil)]) + { + [[cell detailTextLabel] setText:@""]; + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + for(int i = 0; i < CHANGE_NUM_UNITS; i++) + { + if([[[[self sensorStatus] changeAvailable] objectAtIndex:i] intValue] != 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + break; + } + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"10€ Notes",nil)]) + { + if([cell tag] == 2005) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyCollected] objectAtIndex:0] stringValue]]; + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"5€ Notes",nil)]) + { + if([cell tag] == 2005) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyCollected] objectAtIndex:1] stringValue]]; + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"2€ Coins",nil)]) + { + if([cell tag] == 2005) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyCollected] objectAtIndex:2] stringValue]]; + } + else if([cell tag] == 2006) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyReturned] objectAtIndex:0] stringValue]]; + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"1€ Coins",nil)]) + { + if([cell tag] == 2005) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyCollected] objectAtIndex:3] stringValue]]; + } + else if([cell tag] == 2006) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyReturned] objectAtIndex:1] stringValue]]; + } + else if([cell tag] == 2008) + { + if([[[[self sensorStatus] changeAvailable] objectAtIndex:0] intValue] == 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + } + else + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + } + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"50c Coins",nil)]) + { + if([cell tag] == 2005) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyCollected] objectAtIndex:4] stringValue]]; + } + else if([cell tag] == 2006) + { + [[cell detailTextLabel] setText:[[[[self sensorStatus] moneyReturned] objectAtIndex:2] stringValue]]; + } + else if([cell tag] == 2008) + { + if([[[[self sensorStatus] changeAvailable] objectAtIndex:1] intValue] == 1) + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_checkmark"]]]; + } + else + { + [cell setAccessoryView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_delete"]]]; + } + } + } + else if([[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Sales log",nil)] || + [[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Incident report",nil)] || + [[[cell textLabel] text] isEqualToString:NSLocalizedString(@"Send report",nil)]) + { + [[cell detailTextLabel] setText:@""]; + [cell setAccessoryView:nil]; + [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } } return cell; @@ -435,54 +860,4 @@ [_protocol updateProductName:channel :code :name]; } - -/* -// Override to support conditional editing of the table view. -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Return NO if you do not want the specified item to be editable. - return YES; -} -*/ - -/* -// Override to support editing the table view. -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (editingStyle == UITableViewCellEditingStyleDelete) { - // Delete the row from the data source - [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; - } else if (editingStyle == UITableViewCellEditingStyleInsert) { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view - } -} -*/ - -/* -// Override to support rearranging the table view. -- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath -{ -} -*/ - -/* -// Override to support conditional rearranging of the table view. -- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Return NO if you do not want the item to be re-orderable. - return YES; -} -*/ - -/* -#pragma mark - Navigation - -// In a storyboard-based application, you will often want to do a little preparation before navigation -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender -{ - // Get the new view controller using [segue destinationViewController]. - // Pass the selected object to the new view controller. -} -*/ - @end diff --git a/DUREX Vendor Control/Sale.h b/DUREX Vendor Control/Sale.h new file mode 100644 index 0000000..0c15b80 --- /dev/null +++ b/DUREX Vendor Control/Sale.h @@ -0,0 +1,23 @@ +// +// Sale.h +// DUREX Vendor Control +// +// Created by Imanol Barba on 07/09/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import +#import "CommunicationProtocol.h" + +@interface Sale : NSObject + +@property (strong,nonatomic) NSMutableArray *moneyPaid; +@property (strong,nonatomic) NSMutableArray *moneyReturned; +@property NSString *productCode; +@property NSString *normalPrice; +@property NSString *discountedPrice; +@property NSDate *saleTime; + +- (id) init; + +@end diff --git a/DUREX Vendor Control/Sale.m b/DUREX Vendor Control/Sale.m new file mode 100644 index 0000000..a8b3b7c --- /dev/null +++ b/DUREX Vendor Control/Sale.m @@ -0,0 +1,20 @@ +// +// Sale.m +// DUREX Vendor Control +// +// Created by Imanol Barba on 07/09/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import "Sale.h" + +@implementation Sale + +- (id) init +{ + [self setMoneyPaid:[[NSMutableArray alloc]init]]; + [self setMoneyReturned:[[NSMutableArray alloc]init]]; + return self; +} + +@end diff --git a/DUREX Vendor Control/SalesLog.h b/DUREX Vendor Control/SalesLog.h new file mode 100644 index 0000000..88c2df6 --- /dev/null +++ b/DUREX Vendor Control/SalesLog.h @@ -0,0 +1,19 @@ +// +// SalesLog.h +// DUREX Vendor Control +// +// Created by Imanol Barba on 07/09/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import + +@interface SalesLog : NSObject + +@property (strong,nonatomic) NSString *response; +@property (strong,nonatomic) NSMutableArray *sales; + +- (id) init; +- (void) setResponseValue:(NSString *)response; + +@end diff --git a/DUREX Vendor Control/SalesLog.m b/DUREX Vendor Control/SalesLog.m new file mode 100644 index 0000000..fbff0a8 --- /dev/null +++ b/DUREX Vendor Control/SalesLog.m @@ -0,0 +1,30 @@ +// +// SalesLog.m +// DUREX Vendor Control +// +// Created by Imanol Barba on 07/09/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import "SalesLog.h" + +@implementation SalesLog + +- (id) init +{ + [self setSales:[[NSMutableArray alloc] init]]; + return self; +} + +- (void) setResponseValue:(NSString *)response +{ + [self setResponse: response]; + [self parseResponse]; +} + +- (void) parseResponse +{ + +} + +@end diff --git a/DUREX Vendor Control/Sensors.h b/DUREX Vendor Control/Sensors.h index 8264b8c..081dd97 100644 --- a/DUREX Vendor Control/Sensors.h +++ b/DUREX Vendor Control/Sensors.h @@ -13,16 +13,16 @@ @property (strong,nonatomic) NSString *response; @property NSUInteger numChannels; -@property NSMutableArray *channelProductAvailability; -@property NSMutableArray *channelStatus; +@property (strong,nonatomic) NSMutableArray *channelProductAvailability; +@property (strong,nonatomic) NSMutableArray *channelStatus; @property Boolean doorOpen; @property Boolean coilOpen; -@property NSMutableArray *moneyCollected; -@property NSMutableArray *moneyReturned; -@property NSMutableArray *productsSold; -@property NSMutableArray *changeAvailable; +@property (strong,nonatomic) NSMutableArray *moneyCollected; +@property (strong,nonatomic) NSMutableArray *moneyReturned; +@property (strong,nonatomic) NSMutableArray *productsSold; +@property (strong,nonatomic) NSMutableArray *changeAvailable; - (id) init; -- (void) setResponse:(NSString *)response; +- (void) setResponseValue:(NSString *)response; @end diff --git a/DUREX Vendor Control/Sensors.m b/DUREX Vendor Control/Sensors.m index 68f2ef7..15d2667 100644 --- a/DUREX Vendor Control/Sensors.m +++ b/DUREX Vendor Control/Sensors.m @@ -20,14 +20,15 @@ [self setChannelStatus:[[NSMutableArray alloc]init]]; [self setMoneyCollected:[[NSMutableArray alloc]init]]; [self setMoneyReturned:[[NSMutableArray alloc]init]]; + [self setProductsSold:[[NSMutableArray alloc]init]]; [self setChangeAvailable:[[NSMutableArray alloc] init]]; return self; } -- (void) setResponse:(NSString *)response +- (void) setResponseValue:(NSString *)response { - self.response = response; + [self setResponse:response]; [self parseResponse]; } @@ -38,13 +39,18 @@ uint16_t channelAvailability = 0; uint16_t channelMotors = 0; + NSRange substrRange; + substrRange.length = 5; + substrRange.location = 2; + + channelStatus = [[[self response] substringWithRange:substrRange] intValue]; + substrRange.location += 5; + + channelAvailability = [[[self response] substringWithRange:substrRange] intValue]; + substrRange.location += 5; - channelStatus |= [[self response] characterAtIndex:2]; - channelStatus |= ([[self response] characterAtIndex:3] << 8); - channelAvailability |= [[self response] characterAtIndex:4]; - channelAvailability |= ([[self response] characterAtIndex:5] << 8); - channelMotors |= [[self response] characterAtIndex:6]; - channelMotors |= ([[self response] characterAtIndex:7] << 8); + channelMotors = [[[self response] substringWithRange:substrRange] intValue]; + substrRange.location += 5; for(int i = 0; i < MAX_CHANNELS; i++) { @@ -52,7 +58,7 @@ { channelCount++; } - channelStatus <<= 1; + channelStatus >>= 1; } [self setNumChannels:channelCount]; @@ -66,7 +72,7 @@ { [[self channelProductAvailability] insertObject:[NSNumber numberWithBool:FALSE] atIndex:i]; } - channelAvailability <<= 1; + channelAvailability >>= 1; } for(int i = 0; i < MAX_CHANNELS; i++) @@ -79,10 +85,10 @@ { [[self channelStatus] insertObject:[NSNumber numberWithBool:FALSE] atIndex:i]; } - channelMotors <<= 1; + channelMotors >>= 1; } - if([[self response] characterAtIndex:8] == '1') + if([[self response] characterAtIndex:17] == '1') { [self setDoorOpen:TRUE]; } @@ -91,7 +97,7 @@ [self setDoorOpen:FALSE]; } - if([[self response] characterAtIndex:9] == '1') + if([[self response] characterAtIndex:18] == '1') { [self setCoilOpen:TRUE]; } @@ -99,16 +105,15 @@ { [self setCoilOpen:FALSE]; } - NSRange substrRange; substrRange.length = 3; - substrRange.location = 10; + substrRange.location = 19; - for(int i = 0; i < MONEY_NUM_UNITS; i++) + for(int i = 0; i < MONEY_IN_NUM_UNITS; i++) { [[self moneyCollected] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:substrRange] intValue]] atIndex:i]; substrRange.location += 3; } - for(int i = 0; i < MONEY_NUM_UNITS; i++) + for(int i = 0; i < MONEY_OUT_NUM_UNITS; i++) { [[self moneyReturned] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:substrRange] intValue]] atIndex:i]; substrRange.location += 3; @@ -121,7 +126,7 @@ substrRange.location += 2; } - if([[self response] characterAtIndex:64] == '1') + if([[self response] characterAtIndex:75] == '1') { [[self changeAvailable]insertObject:[NSNumber numberWithBool:TRUE] atIndex:0]; } @@ -130,7 +135,7 @@ [[self changeAvailable]insertObject:[NSNumber numberWithBool:FALSE] atIndex:0]; } - if([[self response] characterAtIndex:65] == '1') + if([[self response] characterAtIndex:76] == '1') { [[self changeAvailable]insertObject:[NSNumber numberWithBool:TRUE] atIndex:1]; } @@ -138,8 +143,6 @@ { [[self changeAvailable]insertObject:[NSNumber numberWithBool:FALSE] atIndex:1]; } - - } @end diff --git a/DUREX Vendor Control/carat-open.png b/DUREX Vendor Control/carat-open.png new file mode 100644 index 0000000..11c7038 --- /dev/null +++ b/DUREX Vendor Control/carat-open.png diff --git a/DUREX Vendor Control/carat.png b/DUREX Vendor Control/carat.png new file mode 100644 index 0000000..ffa0011 --- /dev/null +++ b/DUREX Vendor Control/carat.png diff --git a/DUREX Vendor Control/en.lproj/Localizable.strings b/DUREX Vendor Control/en.lproj/Localizable.strings index 86c82c5..f635f11 100644 --- a/DUREX Vendor Control/en.lproj/Localizable.strings +++ b/DUREX Vendor Control/en.lproj/Localizable.strings @@ -34,8 +34,10 @@ "Channel Engine Status" = "Channel Engine Status"; "Door Sensor" = "Door Sensor"; "Coil Sensor" = "Coil Sensor"; +"OPEN" = "OPEN"; +"CLOSED" = "CLOSED"; "Money Collected" = "Money Collected"; -"Money Given" = "Money Given"; +"Money Returned" = "Money Returned"; "Products Sold" = "Products Sold"; "Product 1" = "Product 1"; "Product 2" = "Product 2"; @@ -72,7 +74,7 @@ "50c Coins" = "50c Coins"; "Channel" = "Channel"; "Product Code" = "Product Code"; -"Nominal Price" = "Nominal Price"; +"Normal Price" = "Normal Price"; "Discounted Price" = "Discounted Price"; "1€ Change" = "1€ Change"; "50c Change" = "50c Change"; diff --git a/DUREX Vendor Control/es.lproj/Localizable.strings b/DUREX Vendor Control/es.lproj/Localizable.strings index 131174b..cf09c07 100644 --- a/DUREX Vendor Control/es.lproj/Localizable.strings +++ b/DUREX Vendor Control/es.lproj/Localizable.strings @@ -34,8 +34,10 @@ "Channel Engine Status" = "Estado de los motores"; "Door Sensor" = "Sensor de puerta"; "Coil Sensor" = "Sensor de bobina"; +"OPEN" = "ABIERTO"; +"CLOSED" = "CERRADO"; "Money Collected" = "Recaudación efectuada"; -"Money Given" = "Efectivo devuelto"; +"Money Returned" = "Efectivo devuelto"; "Products Sold" = "Productos vendidos"; "Product 1" = "Producto 1"; "Product 2" = "Producto 2"; @@ -72,7 +74,7 @@ "50c Coins" = "Monedas de 50c"; "Channel" = "Canal"; "Product Code" = "Código del producto"; -"Nominal Price" = "Precio Nominal"; +"Normal Price" = "Precio Normal"; "Discounted Price" = "Precio con descuento"; "1€ Change" = "Cambio de 1€"; "50c Change" = "Cambio de 50c"; diff --git a/DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate b/DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate index be0e308..cc4c17b 100644 --- a/DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate +++ b/DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate diff --git a/DUREX tests/DUREX test.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DUREX tests/DUREX test.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index acdbafe..709d7ce 100644 --- a/DUREX tests/DUREX test.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/DUREX tests/DUREX test.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -31,8 +31,8 @@ endingColumnNumber = "9223372036854775807" startingLineNumber = "32" endingLineNumber = "32" - landmarkName = "-viewDidLoad" - landmarkType = "5"> + landmarkName = "@implementation InitialViewController" + landmarkType = "3"> diff --git a/TODO b/TODO index e818eaf..c6a04fd 100644 --- a/TODO +++ b/TODO @@ -1,14 +1,11 @@ BUGS: - messageAvailable checks and status checks NOT working (long operations) - On date change, response is overwritten by previous query, trimming needed according to numBytes +- Sanitize input on name/price change +- Seemingly random crashes TODO: -- Sensors class -- A4 parser -- Dropdown cells -- Generate view -- Sale class - A2 command - Sale parser - Generate view @@ -16,6 +13,8 @@ TODO: - Implement sensor status logging and sending to remote server - Lewis infrastructure for data viewing (SQL, Webpage, CSV parser) +- Channels and codes to 2 ciphers + - Incident class - Incident parser - A3 command