-
Notifications
You must be signed in to change notification settings - Fork 0
/
GCEvent.m
49 lines (42 loc) · 1.13 KB
/
GCEvent.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* GCEvent.m
* libGlobalCache
*
* Created on 7/30/09.
* Copyright (c) 2009-2013 by NSDex. All rights reserved.
*/
#import "GCEvent.h"
@implementation GCEvent
@synthesize module;
@synthesize connector;
@synthesize sensorIsClosed;
+ (GCEvent*)checkIfEvent:(NSData*)data {
char *bytes = (char *)[data bytes];
int pos = 0;
if(!strncmp(bytes, "statechange", 11)) { //They are equal
#ifdef DEBUG
printf("%s - %s: Event of type statechange received\n", GCDebugHeader, "GCEvent");
#endif
GCEvent *newEvent = [[GCEvent alloc] init];
pos = 11;
if(bytes[pos] != ',') { [newEvent release]; return nil; }
pos++;
char buf[2];
buf[0] = bytes[pos]; buf[1] = '\0';
newEvent.module = atoi(buf);
pos++;
if(bytes[pos] != ':') { [newEvent release]; return nil; }
pos++;
buf[0] = bytes[pos]; buf[1] = '\0';
newEvent.connector = atoi(buf);
pos++;
if(bytes[pos] != ',') { [newEvent release]; return nil; }
pos++;
if(bytes[pos] == '1') newEvent.sensorIsClosed = YES;
else if(bytes[pos] == '0') newEvent.sensorIsClosed = NO;
else { [newEvent release]; return nil; }
return [newEvent autorelease];
}
return nil;
}
@end