Commit 8a75e25170426a632d7e86f96edfa503db78312e

Authored by Imanol-Mikel Barba Sabariego
1 parent 43f91fb6

--no commit message

DUREX Vendor Control/CommunicationProtocol.h
... ... @@ -6,10 +6,12 @@
6 6 // Copyright (c) 2014 Emmoco. All rights reserved.
7 7 //
8 8  
  9 +@class CommunicationProtocol;
  10 +
9 11 #import <Foundation/Foundation.h>
10 12 #import "EMFramework.h"
11 13  
12   -#define SLEEP_MS ((int)100)
  14 +#define SLEEP_TIME ((NSTimeInterval)0.1)
13 15 #define MAX_STRING_LENGTH ((int)200)
14 16 #define MAX_RETRIES ((int)3)
15 17 #define MAX_PRODUCT_NAME_LENGTH ((int)64)
... ... @@ -21,16 +23,23 @@
21 23 #define SALE_STRING_LENGTH ((int)36)
22 24 #define REPORT_SERVER_URL @"http://seneca.upc.es:8090/machine"
23 25  
  26 +@protocol CommunicationProtocolDelegate <NSObject>
  27 +- (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response;
  28 +
  29 +@end
  30 +
24 31 @interface CommunicationProtocol : NSObject
25 32  
  33 +@property (nonatomic, strong) id <CommunicationProtocolDelegate> delegate;
  34 +
26 35 -(void) writeMessage: (NSString*) message;
27 36 -(void) readMessage;
28   --(Boolean) establishConnection;
29   --(Boolean) updateTime: (NSDateComponents*) date;
30   --(Boolean) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents;
31   --(Boolean) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name;
32   --(NSString*) readSensorData;
33   --(NSString*) readSalesLog: (NSDateComponents*) start : (NSDateComponents*) end;
  37 +-(void) establishConnection;
  38 +-(void) updateTime: (NSDateComponents*) date;
  39 +-(void) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents;
  40 +-(void) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name;
  41 +-(void) readSensorData;
  42 +-(void) readSalesLog: (NSDateComponents*) start : (NSDateComponents*) end;
34 43 +(id) sharedProtocol;
35 44  
36 45 @end
... ...
DUREX Vendor Control/CommunicationProtocol.m
... ... @@ -41,7 +41,7 @@
41 41 -(void) readMessage
42 42 {
43 43 self.numPackets = -1;
44   - [self waitForMessage];
  44 + [self waitForMessage: 0];
45 45 }
46 46  
47 47 - (void) readNextFragment
... ... @@ -66,7 +66,7 @@
66 66 {
67 67 NSLog(@"[CommunicationProtocol.m]: messageAvailableDevice set to FALSE");
68 68 NSLog(@"[CommunicationProtocol.m]: packet read");
69   - [self waitForMessage];
  69 + [self waitForMessage: 0];
70 70 }onFail:^(NSError *error)
71 71 {
72 72 NSLog(@"[CommunicationProtocol.m]: On setMessageAvailableDevice to FALSE: %@",error);
... ... @@ -85,7 +85,7 @@
85 85 }
86 86 else
87 87 {
88   - //processMessage
  88 + [[self delegate] processMessage:self didFinishEnteringItem:self.message];
89 89 }
90 90 }
91 91  
... ... @@ -103,81 +103,42 @@
103 103 }];
104 104 }
105 105  
106   -- (void) waitForMessage
  106 +- (void) waitForMessage: (uint8_t) retries
107 107 {
108   - NSLog(@"[CommunicationProtocol.m]: Reading messageAvailable from device");
109   - [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue)
110   - {
111   - [self setMessageAvailableDevice:[readValue intValue]];
112   - if(![self messageAvailableDevice])
113   - {
114   - NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying...");
115   - [NSThread sleepForTimeInterval:SLEEP_MS];
116   - [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue)
117   - {
118   - [self setMessageAvailableDevice:[readValue intValue]];
119   - if(![self messageAvailableDevice])
120   - {
121   - NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying...");
122   - [NSThread sleepForTimeInterval:SLEEP_MS];
123   - [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue)
124   - {
125   - [self setMessageAvailableDevice:[readValue intValue]];
126   - if(![self messageAvailableDevice])
127   - {
128   - NSLog(@"[CommunicationProtocol.m]: Device not ready.");
129   - NSLog(@"[CommunicationProtocol.m]: Timeout while expecting message");
130   - }
131   - else
132   - {
133   - if(self.numPackets == -1)
134   - {
135   - [self readNumPackets];
136   - }
137   - else
138   - {
139   - [self readNextFragment];
140   - }
141   - }
142   - }onFail:^(NSError *error)
143   - {
144   - NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error);
145   - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]];
146   - }];
147   - }
148   - else
149   - {
150   - if(self.numPackets == -1)
151   - {
152   - [self readNumPackets];
153   - }
154   - else
155   - {
156   - [self readNextFragment];
157   - }
158   - }
159   - }onFail:^(NSError *error)
160   - {
161   - NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error);
162   - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]];
163   - }];
164   - }
165   - else
166   - {
167   - if(self.numPackets == -1)
168   - {
169   - [self readNumPackets];
170   - }
171   - else
172   - {
173   - [self readNextFragment];
174   - }
175   - }
176   - }onFail:^(NSError *error)
177   - {
178   - NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error);
179   - [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]];
180   - }];
  108 + if(retries == MAX_RETRIES)
  109 + {
  110 + NSLog(@"[CommunicationProtocol.m]: Device not ready.");
  111 + NSLog(@"[CommunicationProtocol.m]: Timeout while expecting message");
  112 + }
  113 + else
  114 + {
  115 + NSLog(@"[CommunicationProtocol.m]: Reading messageAvailable from device");
  116 + [[EMConnectionManager sharedManager] readResource:@"messageAvailableDevice" onSuccess:^(id readValue)
  117 + {
  118 + [self setMessageAvailableDevice:[readValue intValue]];
  119 + if(![self messageAvailableDevice])
  120 + {
  121 + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying...");
  122 + [NSThread sleepForTimeInterval:SLEEP_TIME];
  123 + [self waitForMessage:retries + 1];
  124 + }
  125 + else
  126 + {
  127 + if(self.numPackets == -1)
  128 + {
  129 + [self readNumPackets];
  130 + }
  131 + else
  132 + {
  133 + [self readNextFragment];
  134 + }
  135 + }
  136 + }onFail:^(NSError *error)
  137 + {
  138 + NSLog(@"[CommunicationProtocol.m]: On waitForMessage: %@",error);
  139 + [self reportError:[NSString stringWithFormat:@"Error occurred while reading answer from device: %@",[error localizedDescription]]];
  140 + }];
  141 + }
181 142 }
182 143  
183 144 -(void) writeMessage: (NSString*) message
... ... @@ -228,7 +189,7 @@
228 189 {
229 190 NSLog(@"[CommunicationProtocol.m]: messageAvailableMobile set to TRUE");
230 191 NSLog(@"[CommunicationProtocol.m]: Packet written");
231   - [self readACK];
  192 + [self readACK: 0];
232 193 }onFail:^(NSError *error)
233 194 {
234 195 NSLog(@"[CommunicationProtocol.m]: On setMessageAvailable to TRUE: %@",error);
... ... @@ -247,6 +208,7 @@
247 208 }
248 209 else
249 210 {
  211 + NSLog(@"[CommunicationProtocol.m]: Finished sending message");
250 212 [self readMessage];
251 213 }
252 214  
... ... @@ -257,81 +219,45 @@
257 219 }];
258 220 }
259 221  
260   -- (void) readACK
  222 +- (void) readACK: (uint8_t) retries
261 223 {
262   - NSLog(@"[CommunicationProtocol.m]: Reading ACK from device");
263   - [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue)
  224 + if(retries == MAX_RETRIES)
264 225 {
265   - [self setMessageAvailableMobile:[readValue intValue]];
266   - if([self messageAvailableMobile])
  226 + NSLog(@"[CommunicationProtocol.m]: Device not ready.");
  227 + NSLog(@"[CommunicationProtocol.m]: Timeout while expecting ACK");
  228 + }
  229 + else
  230 + {
  231 + NSLog(@"[CommunicationProtocol.m]: Reading ACK from device");
  232 + [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue)
267 233 {
268   - NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying...");
269   - [NSThread sleepForTimeInterval:SLEEP_MS];
270   - [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue)
  234 + [self setMessageAvailableMobile:[readValue intValue]];
  235 + if([self messageAvailableMobile])
271 236 {
272   - [self setMessageAvailableMobile:[readValue intValue]];
273   - if([self messageAvailableMobile])
274   - {
275   - NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying...");
276   - [NSThread sleepForTimeInterval:SLEEP_MS];
277   - [[EMConnectionManager sharedManager] readResource:@"messageAvailableMobile" onSuccess:^(id readValue)
278   - {
279   - [self setMessageAvailableMobile:[readValue intValue]];
280   - if([self messageAvailableMobile])
281   - {
282   - NSLog(@"[CommunicationProtocol.m]: Device not ready.");
283   - NSLog(@"[CommunicationProtocol.m]: Timeout while expecting ACK");
284   - }
285   - else
286   - {
287   - [self sendNextFragment];
288   - }
289   - }onFail:^(NSError *error)
290   - {
291   - NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error);
292   - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]];
293   - }];
294   - }
295   - else
296   - {
297   - [self sendNextFragment];
298   - }
299   - }onFail:^(NSError *error)
  237 + NSLog(@"[CommunicationProtocol.m]: Device not ready. Retrying...");
  238 + [NSThread sleepForTimeInterval:SLEEP_TIME];
  239 + [self readACK:retries + 1];
  240 + }
  241 + else
300 242 {
301   - NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error);
302   - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]];
303   - }];
304   - }
305   - else
  243 + [self sendNextFragment];
  244 + }
  245 + }onFail:^(NSError *error)
306 246 {
307   - [self sendNextFragment];
308   - }
309   - }onFail:^(NSError *error)
310   - {
311   - NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error);
312   - [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]];
313   - }];
  247 + NSLog(@"[CommunicationProtocol.m]: On readACK: %@",error);
  248 + [self reportError:[NSString stringWithFormat:@"Error occurred while sending command to device: %@",[error localizedDescription]]];
  249 + }];
  250 + }
314 251 }
315 252  
316   --(Boolean) establishConnection
  253 +-(void) establishConnection
317 254 {
318 255 NSLog(@"[CommunicationProtocol.m]: Establishing connection...");
319   - if([self writeMessage:@"Hello"])
320   - {
321   - NSLog(@"[CommunicationProtocol.m]: Hello sent");
322   - NSString *answer = [self readMessage];
323   - NSLog(@"[CommunicationProtocol.m]: Answer received");
324   - if([answer isEqualToString:@"Hello"])
325   - {
326   - NSLog(@"[CommunicationProtocol.m]: Connection established");
327   - return TRUE;
328   - }
329   - }
330   - NSLog(@"[CommunicationProtocol.m]: Error while establishing connection");
331   - return TRUE; //HACK!
  256 + [self writeMessage:@"Hello"];
  257 + NSLog(@"[CommunicationProtocol.m]: Hello sent");
332 258 }
333 259  
334   --(Boolean) updateTime: (NSDateComponents*) date
  260 +-(void) updateTime: (NSDateComponents*) date
335 261 {
336 262 NSMutableString *command = [NSMutableString stringWithFormat: @"A5"];
337 263 NSInteger year = [date year];
... ... @@ -339,27 +265,15 @@
339 265 [command appendString:[NSString stringWithFormat:@"%02ld",(long)year]];
340 266 [command appendString:[NSString stringWithFormat:@"%02ld%02ld%02ld%02ld%02ld",(long)[date month],(long)[date day],(long)[date hour],(long)[date minute],(long)[date second]]];
341 267 [self writeMessage:command];
342   - NSString *answer = [self readMessage];
343   - if([answer isEqualToString:@"P51"])
344   - {
345   - return TRUE;
346   - }
347   - return FALSE;
348 268 }
349 269  
350   --(Boolean) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents
  270 +-(void) updatePrice: (uint8_t) channel : (uint8_t) product : (uint8_t) eur : (uint8_t) cents
351 271 {
352 272 NSMutableString *command = [NSMutableString stringWithFormat: @"A6%01d%01d%02d%02d",channel,product,eur,cents];
353 273 [self writeMessage:command];
354   - NSString *answer = [self readMessage];
355   - if([answer isEqualToString:@"P61"])
356   - {
357   - return TRUE;
358   - }
359   - return FALSE;
360 274 }
361 275  
362   --(Boolean) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name
  276 +-(void) updateProductName: (uint8_t) channel : (uint8_t) product : (NSString*) name
363 277 {
364 278 if([name length] > MAX_PRODUCT_NAME_LENGTH)
365 279 {
... ... @@ -367,21 +281,14 @@
367 281 }
368 282 NSMutableString *command = [NSMutableString stringWithFormat: @"A7%01d%01d%@",channel,product,name];
369 283 [self writeMessage:command];
370   - NSString *answer = [self readMessage];
371   - if([answer isEqualToString:@"P71"])
372   - {
373   - return TRUE;
374   - }
375   - return FALSE;
376 284 }
377 285  
378   --(NSString*) readSensorData
  286 +-(void) readSensorData
379 287 {
380 288 NSString *command = @"A4";
381 289 [self writeMessage:command];
382   - //NSString *answer = [self readMessage];
383 290  
384   - NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400015000150001500000001001003005002000001002"];
  291 + /*NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P400015000150001500000001001003005002000001002"];
385 292 for(int i = 0; i < 4; i++)
386 293 {
387 294 [answer appendString:@"0"];
... ... @@ -394,17 +301,10 @@
394 301 }
395 302  
396 303 [answer appendString:@"0"];
397   - [answer appendString:@"0"];
398   -
399   - if([answer length] > 1 && [[answer substringToIndex:2]isEqualToString:@"P4"])
400   - {
401   - NSLog(@"[CommunicationProtocol.m]: sensorStatus returned: %@",answer);
402   - return answer;
403   - }
404   - return nil;
  304 + [answer appendString:@"0"];*/
405 305 }
406 306  
407   --(NSString*) readSalesLog : (NSDateComponents*) start : (NSDateComponents*) end
  307 +-(void) readSalesLog : (NSDateComponents*) start : (NSDateComponents*) end
408 308 {
409 309 NSMutableString *startDate = [NSMutableString stringWithString:@""];
410 310 NSMutableString *endDate = [NSMutableString stringWithString:@""];
... ... @@ -435,15 +335,8 @@
435 335 [command appendString:@"-"];
436 336 [command appendString:endDate];
437 337 [self writeMessage:command];
438   - //NSString *answer = [self readMessage];
439 338  
440   - NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21408161036000001000000110450000001P21409012216000100000000220900000100P21409032307000000010502330800000000P21409070540000000020000440350000001P2P2"];
441   - if([answer length] > 1 && [[answer substringToIndex:2]isEqualToString:@"P2"])
442   - {
443   - NSLog(@"[CommunicationProtocol.m]: saleLog returned: %@",answer);
444   - return answer;
445   - }
446   - return nil;
  339 + //NSMutableString *answer = [[NSMutableString alloc]initWithString:@"P21408161036000001000000110450000001P21409012216000100000000220900000100P21409032307000000010502330800000000P21409070540000000020000440350000001P2P2"];
447 340 }
448 341  
449 342 @end
... ...
DUREX Vendor Control/DUREX Vendor Control.xcodeproj/project.xcworkspace/xcuserdata/imanol.xcuserdatad/UserInterfaceState.xcuserstate
No preview for this file type
DUREX Vendor Control/DUREX Vendor Control.xcodeproj/xcuserdata/imanol.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
... ... @@ -26,11 +26,11 @@
26 26 ignoreCount = "0"
27 27 continueAfterRunningActions = "No"
28 28 filePath = "MenuTableViewController.m"
29   - timestampString = "432265160.899922"
  29 + timestampString = "434037601.622012"
30 30 startingColumnNumber = "9223372036854775807"
31 31 endingColumnNumber = "9223372036854775807"
32   - startingLineNumber = "717"
33   - endingLineNumber = "717"
  32 + startingLineNumber = "770"
  33 + endingLineNumber = "770"
34 34 landmarkName = "-tableView:cellForRowAtIndexPath:"
35 35 landmarkType = "5">
36 36 </BreakpointContent>
... ... @@ -42,11 +42,11 @@
42 42 ignoreCount = "0"
43 43 continueAfterRunningActions = "No"
44 44 filePath = "MenuTableViewController.m"
45   - timestampString = "432265160.899922"
  45 + timestampString = "434037601.622012"
46 46 startingColumnNumber = "9223372036854775807"
47 47 endingColumnNumber = "9223372036854775807"
48   - startingLineNumber = "659"
49   - endingLineNumber = "659"
  48 + startingLineNumber = "712"
  49 + endingLineNumber = "712"
50 50 landmarkName = "-tableView:cellForRowAtIndexPath:"
51 51 landmarkType = "5">
52 52 </BreakpointContent>
... ... @@ -58,11 +58,11 @@
58 58 ignoreCount = "0"
59 59 continueAfterRunningActions = "No"
60 60 filePath = "MenuTableViewController.m"
61   - timestampString = "432265052.909736"
  61 + timestampString = "434037601.622012"
62 62 startingColumnNumber = "9223372036854775807"
63 63 endingColumnNumber = "9223372036854775807"
64   - startingLineNumber = "511"
65   - endingLineNumber = "511"
  64 + startingLineNumber = "571"
  65 + endingLineNumber = "571"
66 66 landmarkName = "-tableView:didSelectRowAtIndexPath:"
67 67 landmarkType = "5">
68 68 </BreakpointContent>
... ... @@ -74,12 +74,12 @@
74 74 ignoreCount = "0"
75 75 continueAfterRunningActions = "No"
76 76 filePath = "CommunicationProtocol.m"
77   - timestampString = "433360607.314289"
  77 + timestampString = "434038085.179085"
78 78 startingColumnNumber = "9223372036854775807"
79 79 endingColumnNumber = "9223372036854775807"
80   - startingLineNumber = "363"
81   - endingLineNumber = "363"
82   - landmarkName = "-readNextFragment"
  80 + startingLineNumber = "341"
  81 + endingLineNumber = "341"
  82 + landmarkName = "-updateProductName:::"
83 83 landmarkType = "5">
84 84 </BreakpointContent>
85 85 </BreakpointProxy>
... ... @@ -90,12 +90,12 @@
90 90 ignoreCount = "0"
91 91 continueAfterRunningActions = "No"
92 92 filePath = "CommunicationProtocol.m"
93   - timestampString = "433360607.314289"
  93 + timestampString = "434038085.179085"
94 94 startingColumnNumber = "9223372036854775807"
95 95 endingColumnNumber = "9223372036854775807"
96   - startingLineNumber = "362"
97   - endingLineNumber = "362"
98   - landmarkName = "-readNextFragment"
  96 + startingLineNumber = "340"
  97 + endingLineNumber = "340"
  98 + landmarkName = "-updateProductName:::"
99 99 landmarkType = "5">
100 100 </BreakpointContent>
101 101 </BreakpointProxy>
... ... @@ -106,12 +106,12 @@
106 106 ignoreCount = "0"
107 107 continueAfterRunningActions = "No"
108 108 filePath = "CommunicationProtocol.m"
109   - timestampString = "433360607.314289"
  109 + timestampString = "434038085.179085"
110 110 startingColumnNumber = "9223372036854775807"
111 111 endingColumnNumber = "9223372036854775807"
112   - startingLineNumber = "381"
113   - endingLineNumber = "381"
114   - landmarkName = "-readNextFragment"
  112 + startingLineNumber = "353"
  113 + endingLineNumber = "353"
  114 + landmarkName = "-readSensorData"
115 115 landmarkType = "5">
116 116 </BreakpointContent>
117 117 </BreakpointProxy>
... ... @@ -186,11 +186,11 @@
186 186 ignoreCount = "0"
187 187 continueAfterRunningActions = "No"
188 188 filePath = "MenuTableViewController.m"
189   - timestampString = "432265160.899922"
  189 + timestampString = "434037601.622012"
190 190 startingColumnNumber = "9223372036854775807"
191 191 endingColumnNumber = "9223372036854775807"
192   - startingLineNumber = "768"
193   - endingLineNumber = "768"
  192 + startingLineNumber = "821"
  193 + endingLineNumber = "821"
194 194 landmarkName = "-tableView:cellForRowAtIndexPath:"
195 195 landmarkType = "5">
196 196 </BreakpointContent>
... ... @@ -202,27 +202,11 @@
202 202 ignoreCount = "0"
203 203 continueAfterRunningActions = "No"
204 204 filePath = "MenuTableViewController.m"
205   - timestampString = "432263020.427289"
206   - startingColumnNumber = "9223372036854775807"
207   - endingColumnNumber = "9223372036854775807"
208   - startingLineNumber = "92"
209   - endingLineNumber = "92"
210   - landmarkName = "-generateMaintenanceLevel"
211   - landmarkType = "5">
212   - </BreakpointContent>
213   - </BreakpointProxy>
214   - <BreakpointProxy
215   - BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
216   - <BreakpointContent
217   - shouldBeEnabled = "No"
218   - ignoreCount = "0"
219   - continueAfterRunningActions = "No"
220   - filePath = "MenuTableViewController.m"
221   - timestampString = "432265052.909736"
  205 + timestampString = "434037601.622012"
222 206 startingColumnNumber = "9223372036854775807"
223 207 endingColumnNumber = "9223372036854775807"
224   - startingLineNumber = "114"
225   - endingLineNumber = "114"
  208 + startingLineNumber = "105"
  209 + endingLineNumber = "105"
226 210 landmarkName = "-generateSaleListNavLevel"
227 211 landmarkType = "5">
228 212 </BreakpointContent>
... ... @@ -234,11 +218,11 @@
234 218 ignoreCount = "0"
235 219 continueAfterRunningActions = "No"
236 220 filePath = "MenuTableViewController.m"
237   - timestampString = "432265052.909736"
  221 + timestampString = "434037601.622012"
238 222 startingColumnNumber = "9223372036854775807"
239 223 endingColumnNumber = "9223372036854775807"
240   - startingLineNumber = "117"
241   - endingLineNumber = "117"
  224 + startingLineNumber = "108"
  225 + endingLineNumber = "108"
242 226 landmarkName = "-generateSaleListNavLevel"
243 227 landmarkType = "5">
244 228 </BreakpointContent>
... ... @@ -250,11 +234,11 @@
250 234 ignoreCount = "0"
251 235 continueAfterRunningActions = "No"
252 236 filePath = "MenuTableViewController.m"
253   - timestampString = "432265052.909736"
  237 + timestampString = "434037601.622012"
254 238 startingColumnNumber = "9223372036854775807"
255 239 endingColumnNumber = "9223372036854775807"
256   - startingLineNumber = "125"
257   - endingLineNumber = "125"
  240 + startingLineNumber = "116"
  241 + endingLineNumber = "116"
258 242 landmarkName = "-generateSaleListNavLevel"
259 243 landmarkType = "5">
260 244 </BreakpointContent>
... ... @@ -266,11 +250,11 @@
266 250 ignoreCount = "0"
267 251 continueAfterRunningActions = "No"
268 252 filePath = "MenuTableViewController.m"
269   - timestampString = "432265052.909736"
  253 + timestampString = "434037601.622012"
270 254 startingColumnNumber = "9223372036854775807"
271 255 endingColumnNumber = "9223372036854775807"
272   - startingLineNumber = "197"
273   - endingLineNumber = "197"
  256 + startingLineNumber = "188"
  257 + endingLineNumber = "188"
274 258 landmarkName = "-changeNavLevel::"
275 259 landmarkType = "5">
276 260 </BreakpointContent>
... ... @@ -282,11 +266,11 @@
282 266 ignoreCount = "0"
283 267 continueAfterRunningActions = "No"
284 268 filePath = "MenuTableViewController.m"
285   - timestampString = "432265052.909736"
  269 + timestampString = "434037601.622012"
286 270 startingColumnNumber = "9223372036854775807"
287 271 endingColumnNumber = "9223372036854775807"
288   - startingLineNumber = "496"
289   - endingLineNumber = "496"
  272 + startingLineNumber = "556"
  273 + endingLineNumber = "556"
290 274 landmarkName = "-tableView:numberOfRowsInSection:"
291 275 landmarkType = "5">
292 276 </BreakpointContent>
... ... @@ -298,11 +282,11 @@
298 282 ignoreCount = "0"
299 283 continueAfterRunningActions = "No"
300 284 filePath = "MenuTableViewController.m"
301   - timestampString = "432265160.899922"
  285 + timestampString = "434037601.622012"
302 286 startingColumnNumber = "9223372036854775807"
303 287 endingColumnNumber = "9223372036854775807"
304   - startingLineNumber = "644"
305   - endingLineNumber = "644"
  288 + startingLineNumber = "697"
  289 + endingLineNumber = "697"
306 290 landmarkName = "-tableView:indentationLevelForRowAtIndexPath:"
307 291 landmarkType = "5">
308 292 </BreakpointContent>
... ... @@ -314,11 +298,11 @@
314 298 ignoreCount = "0"
315 299 continueAfterRunningActions = "No"
316 300 filePath = "MenuTableViewController.m"
317   - timestampString = "432265160.899922"
  301 + timestampString = "434037601.622012"
318 302 startingColumnNumber = "9223372036854775807"
319 303 endingColumnNumber = "9223372036854775807"
320   - startingLineNumber = "664"
321   - endingLineNumber = "664"
  304 + startingLineNumber = "717"
  305 + endingLineNumber = "717"
322 306 landmarkName = "-tableView:cellForRowAtIndexPath:"
323 307 landmarkType = "5">
324 308 </BreakpointContent>
... ... @@ -330,11 +314,11 @@
330 314 ignoreCount = "0"
331 315 continueAfterRunningActions = "No"
332 316 filePath = "MenuTableViewController.m"
333   - timestampString = "432265160.899922"
  317 + timestampString = "434037601.622012"
334 318 startingColumnNumber = "9223372036854775807"
335 319 endingColumnNumber = "9223372036854775807"
336   - startingLineNumber = "857"
337   - endingLineNumber = "857"
  320 + startingLineNumber = "910"
  321 + endingLineNumber = "910"
338 322 landmarkName = "-tableView:cellForRowAtIndexPath:"
339 323 landmarkType = "5">
340 324 </BreakpointContent>
... ... @@ -346,11 +330,11 @@
346 330 ignoreCount = "0"
347 331 continueAfterRunningActions = "No"
348 332 filePath = "MenuTableViewController.m"
349   - timestampString = "432265160.899922"
  333 + timestampString = "434037601.622012"
350 334 startingColumnNumber = "9223372036854775807"
351 335 endingColumnNumber = "9223372036854775807"
352   - startingLineNumber = "858"
353   - endingLineNumber = "858"
  336 + startingLineNumber = "911"
  337 + endingLineNumber = "911"
354 338 landmarkName = "-tableView:cellForRowAtIndexPath:"
355 339 landmarkType = "5">
356 340 </BreakpointContent>
... ... @@ -378,11 +362,11 @@
378 362 ignoreCount = "0"
379 363 continueAfterRunningActions = "No"
380 364 filePath = "MenuTableViewController.m"
381   - timestampString = "432265160.899922"
  365 + timestampString = "434037601.622012"
382 366 startingColumnNumber = "9223372036854775807"
383 367 endingColumnNumber = "9223372036854775807"
384   - startingLineNumber = "977"
385   - endingLineNumber = "977"
  368 + startingLineNumber = "1030"
  369 + endingLineNumber = "1030"
386 370 landmarkName = "-tableView:cellForRowAtIndexPath:"
387 371 landmarkType = "5">
388 372 </BreakpointContent>
... ... @@ -394,11 +378,11 @@
394 378 ignoreCount = "0"
395 379 continueAfterRunningActions = "No"
396 380 filePath = "MenuTableViewController.m"
397   - timestampString = "432265052.909736"
  381 + timestampString = "434037601.622012"
398 382 startingColumnNumber = "9223372036854775807"
399 383 endingColumnNumber = "9223372036854775807"
400   - startingLineNumber = "452"
401   - endingLineNumber = "452"
  384 + startingLineNumber = "512"
  385 + endingLineNumber = "512"
402 386 landmarkName = "-toggleDropList:"
403 387 landmarkType = "5">
404 388 </BreakpointContent>
... ... @@ -410,11 +394,11 @@
410 394 ignoreCount = "0"
411 395 continueAfterRunningActions = "No"
412 396 filePath = "MenuTableViewController.m"
413   - timestampString = "432265160.899922"
  397 + timestampString = "434037601.622012"
414 398 startingColumnNumber = "9223372036854775807"
415 399 endingColumnNumber = "9223372036854775807"
416   - startingLineNumber = "1062"
417   - endingLineNumber = "1062"
  400 + startingLineNumber = "1115"
  401 + endingLineNumber = "1115"
418 402 landmarkName = "-tableView:cellForRowAtIndexPath:"
419 403 landmarkType = "5">
420 404 </BreakpointContent>
... ... @@ -426,11 +410,11 @@
426 410 ignoreCount = "0"
427 411 continueAfterRunningActions = "No"
428 412 filePath = "MenuTableViewController.m"
429   - timestampString = "432265160.899922"
  413 + timestampString = "434037601.622012"
430 414 startingColumnNumber = "9223372036854775807"
431 415 endingColumnNumber = "9223372036854775807"
432   - startingLineNumber = "1054"
433   - endingLineNumber = "1054"
  416 + startingLineNumber = "1107"
  417 + endingLineNumber = "1107"
434 418 landmarkName = "-tableView:cellForRowAtIndexPath:"
435 419 landmarkType = "5">
436 420 </BreakpointContent>
... ... @@ -442,11 +426,11 @@
442 426 ignoreCount = "0"
443 427 continueAfterRunningActions = "No"
444 428 filePath = "MenuTableViewController.m"
445   - timestampString = "432265160.899922"
  429 + timestampString = "434037601.622012"
446 430 startingColumnNumber = "9223372036854775807"
447 431 endingColumnNumber = "9223372036854775807"
448   - startingLineNumber = "849"
449   - endingLineNumber = "849"
  432 + startingLineNumber = "902"
  433 + endingLineNumber = "902"
450 434 landmarkName = "-tableView:cellForRowAtIndexPath:"
451 435 landmarkType = "5">
452 436 </BreakpointContent>
... ... @@ -458,11 +442,11 @@
458 442 ignoreCount = "0"
459 443 continueAfterRunningActions = "No"
460 444 filePath = "MenuTableViewController.m"
461   - timestampString = "432265160.899922"
  445 + timestampString = "434037601.622012"
462 446 startingColumnNumber = "9223372036854775807"
463 447 endingColumnNumber = "9223372036854775807"
464   - startingLineNumber = "847"
465   - endingLineNumber = "847"
  448 + startingLineNumber = "900"
  449 + endingLineNumber = "900"
466 450 landmarkName = "-tableView:cellForRowAtIndexPath:"
467 451 landmarkType = "5">
468 452 </BreakpointContent>
... ... @@ -474,11 +458,11 @@
474 458 ignoreCount = "0"
475 459 continueAfterRunningActions = "No"
476 460 filePath = "MenuTableViewController.m"
477   - timestampString = "432265160.899922"
  461 + timestampString = "434037601.622012"
478 462 startingColumnNumber = "9223372036854775807"
479 463 endingColumnNumber = "9223372036854775807"
480   - startingLineNumber = "708"
481   - endingLineNumber = "708"
  464 + startingLineNumber = "761"
  465 + endingLineNumber = "761"
482 466 landmarkName = "-tableView:cellForRowAtIndexPath:"
483 467 landmarkType = "5">
484 468 </BreakpointContent>
... ... @@ -554,11 +538,11 @@
554 538 ignoreCount = "0"
555 539 continueAfterRunningActions = "No"
556 540 filePath = "MenuTableViewController.m"
557   - timestampString = "432823134.280139"
  541 + timestampString = "434037601.622012"
558 542 startingColumnNumber = "9223372036854775807"
559 543 endingColumnNumber = "9223372036854775807"
560   - startingLineNumber = "1176"
561   - endingLineNumber = "1176"
  544 + startingLineNumber = "1230"
  545 + endingLineNumber = "1230"
562 546 landmarkName = "-passDateRangeViewController:didFinishEnteringItem::"
563 547 landmarkType = "5">
564 548 </BreakpointContent>
... ... @@ -570,11 +554,11 @@
570 554 ignoreCount = "0"
571 555 continueAfterRunningActions = "No"
572 556 filePath = "MenuTableViewController.m"
573   - timestampString = "432823146.488089"
  557 + timestampString = "434037601.622012"
574 558 startingColumnNumber = "9223372036854775807"
575 559 endingColumnNumber = "9223372036854775807"
576   - startingLineNumber = "1159"
577   - endingLineNumber = "1159"
  560 + startingLineNumber = "1215"
  561 + endingLineNumber = "1215"
578 562 landmarkName = "-passDateRangeViewController:didFinishEnteringItem::"
579 563 landmarkType = "5">
580 564 </BreakpointContent>
... ...
DUREX Vendor Control/FirstAppExample/EMDevicePickerViewController.m
... ... @@ -106,7 +106,7 @@
106 106  
107 107 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
108 108 {
109   - [self performSegueWithIdentifier:@"ConnectionSegue" sender:self];
  109 + //[self performSegueWithIdentifier:@"ConnectionSegue" sender:self];
110 110 if(![[[[tableView cellForRowAtIndexPath:indexPath] textLabel] text] isEqualToString:NSLocalizedString(@"Searching for devices...",nil)])
111 111 {
112 112 [self _showConnectingView];
... ...
DUREX Vendor Control/MenuTableViewController.h
... ... @@ -57,11 +57,21 @@ enum {
57 57 } navigationLevel;
58 58  
59 59 enum {
  60 + HELLO = 0,
  61 + A2,
  62 + A3,
  63 + A4,
  64 + A5,
  65 + A6,
  66 + A7,
  67 +} commandTypes;
  68 +
  69 +enum {
60 70 SALES_LOG = 0,
61 71 INCIDENT_LOG,
62 72 } logType;
63 73  
64   -@interface MenuTableViewController : UITableViewController <DatePickerViewControllerDelegate,PriceChangerViewControllerDelegate,NameChangerViewControllerDelegate, DateRangePickerViewControllerDelegate, NSURLConnectionDataDelegate>
  74 +@interface MenuTableViewController : UITableViewController <DatePickerViewControllerDelegate,PriceChangerViewControllerDelegate,NameChangerViewControllerDelegate, DateRangePickerViewControllerDelegate, CommunicationProtocolDelegate, NSURLConnectionDataDelegate>
65 75  
66 76 @property (strong,nonatomic) Stack *parentLayout;
67 77 @property (strong,nonatomic) DatePickerViewController *datePickerViewController;
... ...
DUREX Vendor Control/MenuTableViewController.m
... ... @@ -43,6 +43,7 @@
43 43 @property const NSMutableArray *currentHeaders;
44 44  
45 45 @property uint8_t requestedLog;
  46 +@property uint8_t sentCommand;
46 47 @end
47 48  
48 49 @implementation MenuTableViewController
... ... @@ -84,18 +85,9 @@
84 85 [self setCellIdentifiers:[[NSArray alloc] initWithObjects:CELL_IDENTIFIERS, nil]];
85 86 }
86 87  
87   -- (Boolean) generateMaintenanceLevel
  88 +- (void) generateMaintenanceLevel
88 89 {
89 90 //Initialize sensor status
90   - [self setSensorStatus:[[Sensors alloc]init]];
91   -
92   - NSString *sensorData = [_protocol readSensorData];
93   - if(sensorData == nil)
94   - {
95   - NSLog(@"[MenuTableViewController.m]: Error reading sensor data");
96   - return FALSE;
97   - }
98   - [[self sensorStatus] setResponseValue:sensorData];
99 91 [self setMaintenanceElements:[[NSMutableArray alloc] initWithObjects:MAINTENANCE_ELEMENTS, nil]];
100 92 [self setMaintenanceStructure:[[NSMutableArray alloc] initWithObjects:MAINTENANCE_CELLS_PER_SECTION, nil]];
101 93 if([[self maintenanceStructure] count] > 1)
... ... @@ -106,7 +98,6 @@
106 98 {
107 99 [self setMaintenanceHeaders:nil];
108 100 }
109   - return TRUE;
110 101 }
111 102  
112 103 - (void) generateSaleListNavLevel
... ... @@ -263,6 +254,87 @@
263 254 [self.view makeToast:NSLocalizedString(@"Connection to server failed", nil) duration:3 position:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)] title:NSLocalizedString(@"Error", nil) image:[UIImage imageNamed:@"icon_delete"]];
264 255 }
265 256  
  257 +- (void)processMessage:(CommunicationProtocol*)protocol didFinishEnteringItem:(NSString*) response
  258 +{
  259 + NSLog(@"[MenuTableViewController.m]: Answer received");
  260 + if(self.sentCommand == HELLO)
  261 + {
  262 + if([response isEqualToString:@"Hello"])
  263 + {
  264 + NSLog(@"[MenuTableViewController.m]: Connection established");
  265 + [self changeNavLevel:MENU:FALSE];
  266 + }
  267 + else
  268 + {
  269 + NSLog(@"[CommunicationProtocol.m]: Error while establishing connection");
  270 + UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication error",nil) message:NSLocalizedString(@"Error while trying to connect to the device",nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil];
  271 + [alert show];
  272 + UIViewController *previous = [[[self navigationController] viewControllers] objectAtIndex:[[[self navigationController] viewControllers] count]-2];
  273 + [[self navigationController] popToViewController:previous animated:YES];
  274 + }
  275 + }
  276 + else if(self.sentCommand == A2 && [[response substringToIndex:2]isEqualToString:@"P2"])
  277 + {
  278 + NSLog(@"[MenuTableViewController.m]: Received A2 answer");
  279 + [self setSalesLog:[[SalesLog alloc]init]];
  280 + [[self salesLog] setResponseValue:response];
  281 + [self generateSaleListNavLevel];
  282 + [self changeNavLevel:SALE_LIST:TRUE];
  283 + }
  284 + else if(self.sentCommand == A3 && [[response substringToIndex:2]isEqualToString:@"P3"])
  285 + {
  286 +
  287 + }
  288 + else if(self.sentCommand == A4 && [[response substringToIndex:2]isEqualToString:@"P4"])
  289 + {
  290 + NSLog(@"[MenuTableViewController.m]: Received A4 answer");
  291 + [self setSensorStatus:[[Sensors alloc]init]];
  292 + [[self sensorStatus] setResponseValue:response];
  293 + [self generateMaintenanceLevel];
  294 + [self changeNavLevel:MAINTENANCE:TRUE];
  295 + }
  296 + else if(self.sentCommand == A5 && [[response substringToIndex:2]isEqualToString:@"P5"])
  297 + {
  298 + NSLog(@"[MenuTableViewController.m]: Received A5 answer");
  299 + if([response isEqualToString:@"P51"])
  300 + {
  301 +
  302 + }
  303 + else if([response isEqualToString:@"P52"])
  304 + {
  305 + NSLog(@"[MenuTableViewController.m]: Device returned error for command A5");
  306 + }
  307 + }
  308 + else if(self.sentCommand == A6 && [[response substringToIndex:2]isEqualToString:@"P6"])
  309 + {
  310 + NSLog(@"[MenuTableViewController.m]: Received A6 answer");
  311 + if([response isEqualToString:@"P61"])
  312 + {
  313 +
  314 + }
  315 + else if([response isEqualToString:@"P62"])
  316 + {
  317 + NSLog(@"[MenuTableViewController.m]: Device returned error for command A6");
  318 + }
  319 + }
  320 + else if(self.sentCommand == A7 && [[response substringToIndex:2]isEqualToString:@"P7"])
  321 + {
  322 + NSLog(@"[MenuTableViewController.m]: Received A7 answer");
  323 + if([response isEqualToString:@"P71"])
  324 + {
  325 +
  326 + }
  327 + else if([response isEqualToString:@"P72"])
  328 + {
  329 + NSLog(@"[MenuTableViewController.m]: Device returned error for command A7");
  330 + }
  331 + }
  332 + else
  333 + {
  334 + NSLog(@"[MenuTableViewController]: Unknown response received. Data discarded.");
  335 + }
  336 +}
  337 +
266 338 - (void)viewDidLoad
267 339 {
268 340 [super viewDidLoad];
... ... @@ -284,6 +356,7 @@
284 356 _protocol = [CommunicationProtocol sharedProtocol];
285 357 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:kEMConnectionDidReceiveIndicatorNotificationName object:nil];
286 358 [[EMConnectionManager sharedManager] addObserver:self forKeyPath:@"connectionState" options:0 context:NULL];
  359 + self.protocol.delegate = self;
287 360  
288 361 //Initialize parentLayout stack
289 362 [self setParentLayout:[[Stack alloc]init]];
... ... @@ -291,21 +364,8 @@
291 364 //Set navigation level
292 365 [self initializeMenuEntries];
293 366 self.currentNavLevel = 255;
294   - [self changeNavLevel:MENU:FALSE];
295   - }
296   -
297   --(void)viewDidAppear:(BOOL)animated
298   -{
299   - [super viewDidAppear:animated];
300   -
301   - //DUREX protocol
302   - if(![_protocol establishConnection])
303   - {
304   - UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Communication error",nil) message:NSLocalizedString(@"Error while trying to connect to the device",nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil];
305   - [alert show];
306   - UIViewController *previous = [[[self navigationController] viewControllers] objectAtIndex:[[[self navigationController] viewControllers] count]-2];
307   - [[self navigationController] popToViewController:previous animated:YES];
308   - }
  367 + [_protocol establishConnection];
  368 + [self setSentCommand:HELLO];
309 369 }
310 370  
311 371 -(void)didReceiveNotification:(NSNotification*) notification
... ... @@ -509,15 +569,8 @@
509 569 if([cellName isEqualToString:NSLocalizedString(@"Maintenance", nil)])
510 570 {
511 571 NSLog(@"[MenuTableViewController.m]: Changing to navLevel: MAINTENANCE");
512   - if([self generateMaintenanceLevel])
513   - {
514   - [NSThread sleepForTimeInterval:1]; //HACK!
515   - [self changeNavLevel:MAINTENANCE:TRUE];
516   - }
517   - else
518   - {
519   - NSLog(@"[MenuTableViewController.m]: Error while changing to navLevel: MAINTENANCE");
520   - }
  572 + [[self protocol] readSensorData];
  573 + [self setSentCommand:A4];
521 574 }
522 575 else if([cellName isEqualToString:NSLocalizedString(@"Basic Configuration", nil)])
523 576 {
... ... @@ -1074,6 +1127,7 @@
1074 1127 NSDateComponents *components = [calendar components:units fromDate:date];
1075 1128 NSLog(@"[MenuTableViewController.m]: %@", components);
1076 1129 [_protocol updateTime: components];
  1130 + [self setSentCommand:A5];
1077 1131 }
1078 1132  
1079 1133 - (void)passPriceViewController:(PriceChangerViewController *)controller didFinishEnteringItem:(NSArray *)data
... ... @@ -1114,6 +1168,7 @@
1114 1168 int code = [codeString intValue];
1115 1169 NSArray *price = [priceString componentsSeparatedByString:@"."];
1116 1170 [_protocol updatePrice:channel :code :[[price objectAtIndex:0] intValue] :[[price objectAtIndex:1] intValue]];
  1171 + [self setSentCommand:A6];
1117 1172 }
1118 1173 }
1119 1174  
... ... @@ -1149,6 +1204,7 @@
1149 1204 int channel = [channelString intValue];
1150 1205 int code = [codeString intValue];
1151 1206 [_protocol updateProductName:channel :code :name];
  1207 + [self setSentCommand:A7];
1152 1208 }
1153 1209 }
1154 1210  
... ... @@ -1159,9 +1215,6 @@
1159 1215 {
1160 1216 NSLog(@"[MenuTableViewController.m]: Changing to navLevel: SALE_LIST");
1161 1217  
1162   - //Initialize sales log
1163   - [self setSalesLog:[[SalesLog alloc]init]];
1164   -
1165 1218 NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
1166 1219 NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
1167 1220 NSDateComponents *componentsFrom = nil;
... ... @@ -1174,17 +1227,7 @@
1174 1227 {
1175 1228 componentsTo = [calendar components:units fromDate:to];
1176 1229 }
1177   - NSString *salesData = [_protocol readSalesLog: componentsFrom : componentsTo];
1178   - if(salesData == nil)
1179   - {
1180   - NSLog(@"[MenuTableViewController.m]: Error reading sales log");
1181   - }
1182   - else
1183   - {
1184   - [[self salesLog] setResponseValue:salesData];
1185   - [self generateSaleListNavLevel];
1186   - [self changeNavLevel:SALE_LIST:TRUE];
1187   - }
  1230 + [_protocol readSalesLog: componentsFrom : componentsTo];
1188 1231 }
1189 1232 else if([self requestedLog] == INCIDENT_LOG)
1190 1233 {
... ...
... ... @@ -5,8 +5,8 @@ BUGS:
5 5 - On date change, response is overwritten by previous query, trimming needed according to numBytes
6 6  
7 7 TODO:
8   -- processMessage with Delegate
9 8 - Error reporting function
  9 +- Toast if success or error on processMessage (except nav changes)
10 10 - Incident class
11 11 - Incident parser
12 12 - A3 command
... ...