forked from e-mission/e-mission-data-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add_ble_plumbing' into android_bluetooth
Conflict was due to the newly added transitions Per e-mission/e-mission-docs#1062 (comment) resolved conflict by removing transitions from this PR, and changing `beacon_found` to `ble_beacon_found`
- Loading branch information
Showing
11 changed files
with
285 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package edu.berkeley.eecs.emission.cordova.tracker.wrapper; | ||
|
||
/** | ||
* Created by shankari on 3/30/24. | ||
*/ | ||
public class BluetoothBLE { | ||
public String getEventType() { | ||
return eventType; | ||
} | ||
|
||
/* Not sure if we need to return the UUID, major and minor | ||
since we will only get callbacks for the registered UUID | ||
and we don't need to check the major or minor in native code | ||
only that it is **our** beacon. Let's hold off on them for now. | ||
**/ | ||
|
||
/* We do need to use proximity in the FSM to avoid spurious exits (e.g. a | ||
* personal car parked next to a fleet car may still see a region enter, | ||
* but we don't want to track the trip because the proximity is "far". | ||
*/ | ||
public String getProximity() { | ||
return proximity; | ||
} | ||
|
||
public double getTs() { | ||
return ts; | ||
} | ||
|
||
// Similarly, we store the accuracy and the rssi for the record, but the | ||
// underlying API already converts it to a proximity value, so we use that | ||
// instead | ||
|
||
private String eventType; | ||
private String uuid; | ||
private int major; | ||
private int minor; | ||
private String proximity; | ||
private double accuracy; | ||
private int rssi; | ||
|
||
private double ts; | ||
// Should we put newState in here as well? | ||
// If so, we will need to change the location of the save | ||
|
||
private BluetoothBLE() {} | ||
|
||
public static BluetoothBLE initRegionEnter(String uuid, double ts) { | ||
BluetoothBLE enterEvent = new BluetoothBLE(); | ||
enterEvent.eventType = "REGION_ENTER"; | ||
enterEvent.uuid = uuid; | ||
enterEvent.ts = ts; | ||
return enterEvent; | ||
} | ||
|
||
public static BluetoothBLE initRegionExit(String uuid, double ts) { | ||
BluetoothBLE exitEvent = new BluetoothBLE(); | ||
exitEvent.eventType = "REGION_EXIT"; | ||
exitEvent.uuid = uuid; | ||
exitEvent.ts = ts; | ||
return exitEvent; | ||
} | ||
|
||
public static BluetoothBLE initRangeUpdate(String uuid, double ts, | ||
int major, int minor, | ||
String proximity, double accuracy, int rssi) { | ||
BluetoothBLE rangeEvent = new BluetoothBLE(); | ||
rangeEvent.eventType = "RANGE_UPDATE"; | ||
rangeEvent.uuid = uuid; | ||
rangeEvent.ts = ts; | ||
|
||
rangeEvent.major = major; | ||
rangeEvent.minor = minor; | ||
rangeEvent.proximity = proximity; | ||
rangeEvent.accuracy = accuracy; | ||
rangeEvent.rssi = rssi; | ||
return rangeEvent; | ||
} | ||
|
||
public static BluetoothBLE initFake(String eventType, String uuid, int major, int minor) { | ||
BluetoothBLE fakeEvent = new BluetoothBLE(); | ||
fakeEvent.uuid = uuid; | ||
fakeEvent.eventType = eventType; | ||
fakeEvent.ts = System.currentTimeMillis() / 1000; // time is in seconds for us | ||
|
||
// we assume that we don't have major and minor entries for the | ||
// "monitor" responses | ||
if (eventType == "RANGE_UPDATE") { | ||
fakeEvent.major = major; | ||
fakeEvent.minor = minor; | ||
fakeEvent.proximity = "ProximityNear"; | ||
fakeEvent.accuracy = (int)(Math.random() * 100); | ||
fakeEvent.rssi = (int)(Math.random() * 10); | ||
} | ||
|
||
return fakeEvent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// Transition.h | ||
// CFC_Tracker | ||
// | ||
// Created by Kalyanaraman Shankari on 10/27/15. | ||
// Copyright © 2015 Kalyanaraman Shankari. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <CoreLocation/CoreLocation.h> | ||
|
||
@interface BluetoothBLE : NSObject | ||
|
||
- (instancetype)initWithCLBeacon:(CLBeacon *)beacon andEventType:(NSString *) eventType; | ||
- (instancetype)initFake:(NSString *)eventType anduuid:(NSString*) uuid andmajor:(int) major andminor:(int) minor; | ||
|
||
// fields from CLBeacon, modified to be easy to serialize and restore | ||
@property NSString* uuid; | ||
@property NSInteger major; | ||
@property NSInteger minor; | ||
@property NSString* proximity; | ||
@property CLLocationAccuracy accuracy; | ||
@property NSInteger rssi; | ||
@property NSString* eventType; | ||
@property double ts; | ||
|
||
+ (NSString*) proximityToString:(CLProximity) proximityObj; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// Transition.m | ||
// CFC_Tracker | ||
// | ||
// Created by Kalyanaraman Shankari on 10/27/15. | ||
// Copyright © 2015 Kalyanaraman Shankari. All rights reserved. | ||
// | ||
|
||
#import "BluetoothBLE.h" | ||
#import "DataUtils.h" | ||
#import <stdlib.h> | ||
|
||
@implementation BluetoothBLE | ||
|
||
-(id) initWithCLBeacon:(CLBeacon*) beacon andEventType:(NSString*) eventType { | ||
self = [super init]; | ||
self.uuid = beacon.UUID; | ||
self.major = beacon.major.integerValue; | ||
self.minor = beacon.minor.integerValue; | ||
self.proximity = [BluetoothBLE proximityToString:beacon.proximity]; | ||
self.accuracy = beacon.accuracy; | ||
self.rssi = beacon.rssi; | ||
|
||
self.eventType = eventType; | ||
self.ts = [DataUtils dateToTs:beacon.timestamp]; | ||
return self; | ||
} | ||
|
||
-(id) initFake:(NSString*) eventType anduuid:(NSString*) uuid andmajor:(int) major andminor:(int)minor { | ||
self = [super init]; | ||
self.uuid = uuid; | ||
self.eventType = eventType; | ||
self.ts = [DataUtils dateToTs:[NSDate now]]; | ||
|
||
if ([eventType isEqualToString:@"RANGE_UPDATE"]) { | ||
self.major = major; | ||
self.minor = minor; | ||
self.proximity = [BluetoothBLE proximityToString:CLProximityNear]; | ||
self.accuracy = arc4random_uniform(100); | ||
self.rssi = arc4random_uniform(10); | ||
} | ||
|
||
return self; | ||
} | ||
|
||
+ (NSString*) proximityToString:(CLProximity) proximityObj { | ||
if (proximityObj == CLProximityImmediate) { return @"ProximityImmediate"; }; | ||
if (proximityObj == CLProximityNear) { return @"ProximityNear"; }; | ||
if (proximityObj == CLProximityFar) { return @"ProximityFar"; }; | ||
return @"ProximityUnknown"; | ||
} | ||
|
||
|
||
@end |
Oops, something went wrong.