From eaec457e2d7b0d1ce8a9f5b8b1215ee6819c6df4 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Fri, 5 Sep 2014 20:51:05 +0000 Subject: [PATCH] --- DUREX Vendor Control/Base.lproj/DatePickerViewController.xib | 1 + DUREX Vendor Control/CommunicationProtocol.h | 10 ++++++++-- DUREX Vendor Control/CommunicationProtocol.m | 41 +++++++++++++++++++++++++++++++++++++++++ DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj | 8 +++++++- DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate | Bin 187673 -> 0 bytes DUREX Vendor Control/MenuTableViewController.h | 2 ++ DUREX Vendor Control/MenuTableViewController.m | 7 +++++-- DUREX Vendor Control/Sensors.h | 28 ++++++++++++++++++++++++++++ DUREX Vendor Control/Sensors.m | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate | Bin 108428 -> 0 bytes DUREX tests/DUREX test.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist | 16 ++++++++++++++++ TODO | 3 ++- 12 files changed, 255 insertions(+), 6 deletions(-) create mode 100644 DUREX Vendor Control/Sensors.h create mode 100644 DUREX Vendor Control/Sensors.m diff --git a/DUREX Vendor Control/Base.lproj/DatePickerViewController.xib b/DUREX Vendor Control/Base.lproj/DatePickerViewController.xib index 44d8229..3465ebf 100644 --- a/DUREX Vendor Control/Base.lproj/DatePickerViewController.xib +++ b/DUREX Vendor Control/Base.lproj/DatePickerViewController.xib @@ -6,6 +6,7 @@ + diff --git a/DUREX Vendor Control/CommunicationProtocol.h b/DUREX Vendor Control/CommunicationProtocol.h index 3395b7d..b4daf3b 100644 --- a/DUREX Vendor Control/CommunicationProtocol.h +++ b/DUREX Vendor Control/CommunicationProtocol.h @@ -12,9 +12,16 @@ #define MAX_STRING_LENGTH ((int)200) #define MAX_RETRIES ((int)3) #define MAX_PRODUCT_NAME_LENGTH ((int)64) +#define MAX_CHANNELS ((int)16) +#define MONEY_NUM_UNITS ((int)5) +#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; @@ -23,8 +30,7 @@ -(Boolean) updateTime: (NSDateComponents*) date; -(Boolean) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents; -(Boolean) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name; +-(NSString*) readSensorData; +(id) sharedProtocol; -@property Boolean messageAvailableMobile; -@property Boolean messageAvailableDevice; @end diff --git a/DUREX Vendor Control/CommunicationProtocol.m b/DUREX Vendor Control/CommunicationProtocol.m index 8ab5736..1c1560f 100644 --- a/DUREX Vendor Control/CommunicationProtocol.m +++ b/DUREX Vendor Control/CommunicationProtocol.m @@ -354,4 +354,45 @@ return FALSE; } +-(NSString*) readSensorData +{ + NSString *command = @"A4"; + [self writeMessage:command]; + //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) + { + command_str[i] = '0'; + command_str[i+1] = '0'; + command_str[i+2] = '0'; + } + for(int i = 40; i < 16; i+=2) + { + command_str[i] = '0'; + command_str[i+1] = '0'; + } + command_str[63] = '1'; + command_str[64] = '1'; + + NSMutableString *answer = [[NSMutableString alloc]init]; + [answer appendString:[NSString stringWithUTF8String:command_str]]; + + if([[answer substringToIndex:2] isEqualToString:@"P4"]) + { + return answer; + } + return nil; +} + @end diff --git a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj index 526a00a..1f5c6f3 100644 --- a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj +++ b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ F98356D8192E906600EA6821 /* bluetooth.png in Resources */ = {isa = PBXBuildFile; fileRef = F98356D7192E906600EA6821 /* bluetooth.png */; }; 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 */; }; 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 */; }; @@ -115,6 +116,8 @@ F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommunicationProtocol.m; sourceTree = SOURCE_ROOT; }; F98356DF192EC84700EA6821 /* MenuTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuTableViewController.h; sourceTree = SOURCE_ROOT; }; 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; }; 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; }; @@ -180,12 +183,13 @@ 34AAB877189804FF0019860D /* DUREXAppDelegate.m */, F98356D5192E835F00EA6821 /* InitialViewController.m */, F98356E0192EC84700EA6821 /* MenuTableViewController.m */, - F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */, F9A8EF7B192FE201009E7532 /* Stack.m */, + F98356DA192EAFD400EA6821 /* CommunicationProtocol.m */, F933F80219B6819400521B90 /* DatePickerViewController.m */, F92F567719B75F5E00A1EACA /* PriceChangerViewController.m */, F92F568E19B763FD00A1EACA /* NameChangerViewController.m */, 34AAB880189804FF0019860D /* main.m */, + F98446EF19B9EAE9005C4992 /* Sensors.m */, ); name = "DUREX Vendor Control"; path = TestAppExample; @@ -278,6 +282,7 @@ F933F80119B6819400521B90 /* DatePickerViewController.h */, F92F567619B75F5E00A1EACA /* PriceChangerViewController.h */, F92F568D19B763FD00A1EACA /* NameChangerViewController.h */, + F98446EE19B9EAE9005C4992 /* Sensors.h */, ); name = Headers; sourceTree = ""; @@ -383,6 +388,7 @@ 34AAB883189804FF0019860D /* DUREXAppDelegate.m in Sources */, F98356DB192EAFD400EA6821 /* CommunicationProtocol.m in Sources */, F98356E1192EC84700EA6821 /* MenuTableViewController.m in Sources */, + F98446F019B9EAE9005C4992 /* Sensors.m in Sources */, 34AAB889189804FF0019860D /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; 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 ff10a1a..2ad7c26 100644 Binary files a/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate and b/DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/DUREX Vendor Control/MenuTableViewController.h b/DUREX Vendor Control/MenuTableViewController.h index 167525e..7f3465c 100644 --- a/DUREX Vendor Control/MenuTableViewController.h +++ b/DUREX Vendor Control/MenuTableViewController.h @@ -13,6 +13,7 @@ #import "DatePickerViewController.h" #import "PriceChangerViewController.h" #import "NameChangerViewController.h" +#import "Sensors.h" #define num(x) [NSNumber numberWithUnsignedInt:x] @@ -48,6 +49,7 @@ enum { @property (strong,nonatomic) DatePickerViewController *datePickerViewController; @property (strong,nonatomic) PriceChangerViewController *priceChangerViewController; @property (strong,nonatomic) NameChangerViewController *nameChangerViewController; +@property (strong,nonatomic) Sensors *sensorStatus; - (void) navBack; diff --git a/DUREX Vendor Control/MenuTableViewController.m b/DUREX Vendor Control/MenuTableViewController.m index f2d4f0b..bdd3467 100644 --- a/DUREX Vendor Control/MenuTableViewController.m +++ b/DUREX Vendor Control/MenuTableViewController.m @@ -81,6 +81,8 @@ - (void) 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]]; if([[self maintenanceStructure] count] > 1) @@ -107,8 +109,6 @@ } } - - - (void) changeNavLevel: (uint8_t) level : (BOOL) push { NSLog(@"[MenuTableViewController.m]: navLevel is %d",level); @@ -215,6 +215,9 @@ self.currentNavLevel = 255; [self changeNavLevel:MENU:FALSE]; + //Initialize sensor status + [self setSensorStatus:[[Sensors alloc]init]]; + // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; diff --git a/DUREX Vendor Control/Sensors.h b/DUREX Vendor Control/Sensors.h new file mode 100644 index 0000000..8264b8c --- /dev/null +++ b/DUREX Vendor Control/Sensors.h @@ -0,0 +1,28 @@ +// +// Sensors.h +// DUREX Vendor Control +// +// Created by Imanol Barba on 9/5/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import +#import "CommunicationProtocol.h" + +@interface Sensors : NSObject + +@property (strong,nonatomic) NSString *response; +@property NSUInteger numChannels; +@property NSMutableArray *channelProductAvailability; +@property NSMutableArray *channelStatus; +@property Boolean doorOpen; +@property Boolean coilOpen; +@property NSMutableArray *moneyCollected; +@property NSMutableArray *moneyReturned; +@property NSMutableArray *productsSold; +@property NSMutableArray *changeAvailable; + +- (id) init; +- (void) setResponse:(NSString *)response; + +@end diff --git a/DUREX Vendor Control/Sensors.m b/DUREX Vendor Control/Sensors.m new file mode 100644 index 0000000..68f2ef7 --- /dev/null +++ b/DUREX Vendor Control/Sensors.m @@ -0,0 +1,145 @@ +// +// Sensors.m +// DUREX Vendor Control +// +// Created by Imanol Barba on 9/5/14. +// Copyright (c) 2014 Emmoco. All rights reserved. +// + +#import "Sensors.h" + +@interface Sensors () + +@end + +@implementation Sensors + +- (id) init +{ + [self setChannelProductAvailability:[[NSMutableArray alloc]init]]; + [self setChannelStatus:[[NSMutableArray alloc]init]]; + [self setMoneyCollected:[[NSMutableArray alloc]init]]; + [self setMoneyReturned:[[NSMutableArray alloc]init]]; + [self setChangeAvailable:[[NSMutableArray alloc] init]]; + + return self; +} + +- (void) setResponse:(NSString *)response +{ + self.response = response; + [self parseResponse]; +} + +- (void) parseResponse +{ + uint8_t channelCount = 0; + uint16_t channelStatus = 0; + uint16_t channelAvailability = 0; + uint16_t channelMotors = 0; + + + 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); + + for(int i = 0; i < MAX_CHANNELS; i++) + { + if(channelStatus & 0x01) + { + channelCount++; + } + channelStatus <<= 1; + } + [self setNumChannels:channelCount]; + + for(int i = 0; i < MAX_CHANNELS; i++) + { + if(channelAvailability & 0x01) + { + [[self channelProductAvailability] insertObject:[NSNumber numberWithBool:TRUE] atIndex:i]; + } + else + { + [[self channelProductAvailability] insertObject:[NSNumber numberWithBool:FALSE] atIndex:i]; + } + channelAvailability <<= 1; + } + + for(int i = 0; i < MAX_CHANNELS; i++) + { + if(channelMotors & 0x01) + { + [[self channelStatus] insertObject:[NSNumber numberWithBool:TRUE] atIndex:i]; + } + else + { + [[self channelStatus] insertObject:[NSNumber numberWithBool:FALSE] atIndex:i]; + } + channelMotors <<= 1; + } + + if([[self response] characterAtIndex:8] == '1') + { + [self setDoorOpen:TRUE]; + } + else + { + [self setDoorOpen:FALSE]; + } + + if([[self response] characterAtIndex:9] == '1') + { + [self setCoilOpen:TRUE]; + } + else + { + [self setCoilOpen:FALSE]; + } + NSRange substrRange; + substrRange.length = 3; + substrRange.location = 10; + + for(int i = 0; i < MONEY_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++) + { + [[self moneyReturned] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:substrRange] intValue]] atIndex:i]; + substrRange.location += 3; + } + + substrRange.length = 2; + for(int i = 0; i < MAX_PRODUCTS; i++) + { + [[self productsSold] insertObject:[NSNumber numberWithInt:[[[self response] substringWithRange:substrRange] intValue]] atIndex:i]; + substrRange.location += 2; + } + + if([[self response] characterAtIndex:64] == '1') + { + [[self changeAvailable]insertObject:[NSNumber numberWithBool:TRUE] atIndex:0]; + } + else + { + [[self changeAvailable]insertObject:[NSNumber numberWithBool:FALSE] atIndex:0]; + } + + if([[self response] characterAtIndex:65] == '1') + { + [[self changeAvailable]insertObject:[NSNumber numberWithBool:TRUE] atIndex:1]; + } + else + { + [[self changeAvailable]insertObject:[NSNumber numberWithBool:FALSE] atIndex:1]; + } + + +} + +@end 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 b941149..be0e308 100644 Binary files a/DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate and b/DUREX tests/DUREX test.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate differ 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 472035b..acdbafe 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 @@ -19,5 +19,21 @@ landmarkType = "4"> + + + + diff --git a/TODO b/TODO index d965014..e818eaf 100644 --- a/TODO +++ b/TODO @@ -4,13 +4,14 @@ BUGS: TODO: - Sensors class -- A4 command - A4 parser - Dropdown cells +- Generate view - Sale class - A2 command - Sale parser +- Generate view - Implement sensor status logging and sending to remote server - Lewis infrastructure for data viewing (SQL, Webpage, CSV parser) -- libgit2 0.22.2