コード例 #1
0
        public ScanEventSource()
        {
            ScanResults = Observable.FromEvent<ScanResult>(h => OnDeviceDetected += h, h => OnDeviceDetected -= h);
            var appContext = Application.Context;
            var builder = new ScanSettings.Builder();
            builder.SetReportDelay(0);
            builder.SetScanMode(ScanMode.LowLatency);
            var manager = (BluetoothManager)appContext.GetSystemService(Context.BluetoothService);
            var adapter = manager.Adapter;
            bluetoothLeScanner = adapter.BluetoothLeScanner;
            var simpleScanCallback = new SimpleScanCallback(result =>
            {
                var payload = result.ScanRecord.GetBytes();
                var majorId = payload[26];
                if (payload[5] == 76 && majorId == Constants.MajorId)
                {
                    var txPower = 255 - payload[29];
                    var minorId = (payload[27] << 8) + payload[28];

                    var deviceId = new DeviceIdentifier(new Guid(), majorId, minorId);
                    var data = new ScanResult(deviceId, result.Rssi, txPower);
                    OnDeviceDetected?.Invoke(data);
                }
            });
            // taken from https://www.pubnub.com/blog/2015-04-15-build-android-beacon-ibeacon-detector/ , but not detecting our beacons
            //bluetoothLeScanner.StartScan(new List<ScanFilter> {CreateScanFilter()}, CreateScanSettings(), simpleScanCallback);
            bluetoothLeScanner.StartScan(simpleScanCallback);
        }
コード例 #2
0
 public async Task StartActivity(ActivityData activity, Station station, DeviceIdentifier identifier)
 {
     var dto = new Activity
     {
         Difficulty = activity.Difficulty,
         Type = activity.Type,
         ConnectedBeacon = Serializer.Serialize(identifier)
     };
     await service.StartActivity(dto, station.Id);
 }
コード例 #3
0
 public static ConnectedBeacon Serialize(DeviceIdentifier identifier)
 {
     return new ConnectedBeacon { Id = identifier.MinorId };
 }
コード例 #4
0
 public async Task StopActivity(Station station, DeviceIdentifier identifier)
 {
     await service.StopActivity(station.Id);
 }
コード例 #5
0
 public async Task<UserData> GetForDevice(DeviceIdentifier id)
 {
     var dto = await dataLoader.GetUser(Serializer.Serialize(id));
     return Serializer.Deserialize(dto);
 }
コード例 #6
0
 protected bool Equals(DeviceIdentifier other)
 {
     return MinorId == other.MinorId;
 }