public void OnLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { ScannedBleDevice parsedLEDevice = new BLEParser().ParseRawScanRecord(device, rssi, scanRecord, null); if (parsedLEDevice != null) { blueToothTextView = mBlueToothDiscover != null?mBlueToothDiscover.FindViewById <TextView>(Resource.Id.BlueToothResults) : null; BtDevice btDevice = new BtDevice(parsedLEDevice); int newBtDeviceId; //get gps location and string location = mBlueToothDiscover.CheckLocation(); Locations locationName = database.GetLocationName(btDevice.UuidString, btDevice.MajorInt, btDevice.MinorInt); btDeviceList.Add(btDevice); //only add if new, update if changed Location currentLocation = mBlueToothDiscover.GetCurrentLocationObject(); GPSLocation newGpsLocation = new GPSLocation(); newGpsLocation.LatitudeLongitude = String.Format("{0},{1}", currentLocation != null ? currentLocation.Latitude.ToString() : "", currentLocation != null ? currentLocation.Longitude.ToString() : ""); newGpsLocation.Address = location; newGpsLocation.Altitude = currentLocation != null?currentLocation.Altitude.ToString() : ""; newBtDeviceId = database.AddUpdateBtDevice(btDevice, newGpsLocation); blueToothTextView.Text += "\n Device found: " + btDevice.UuidString + ":" + btDevice.MajorInt + ":" + btDevice.MinorInt + " You are at " + locationName.Name + "(" + String.Format("{0},{1}", currentLocation != null ? currentLocation.Latitude.ToString() : "", currentLocation != null ? currentLocation.Longitude.ToString() : "") + location + ")"; OutputBlueToothList(mBlueToothDiscover); } }
public int AddUpdateBtDevice(BtDevice btdevice, GPSLocation gpsLocation) { int btDeviceId = 0; iBeacon_Indexer.BtDevices btDevicesIndividual = new BtDevices(); btDevicesIndividual.Name = btdevice.Name; btDevicesIndividual.Type = btdevice.Type; btDevicesIndividual.MacAddress = btdevice.MacAddress; btDevicesIndividual.Strength = btdevice.Strength; btDevicesIndividual.UUID = btdevice.UuidString; btDevicesIndividual.Major = btdevice.MajorInt; btDevicesIndividual.Minor = btdevice.MinorInt; btDevicesIndividual.TimeFound = btdevice.TimeFound.ToString(); BtDevices deviceAlreadyExists = GetBtDevice(btdevice.UuidString, btdevice.MajorInt, btdevice.MinorInt); if (deviceAlreadyExists == null) { btDeviceId = conn.Insert(btDevicesIndividual); gpsLocation.BtDevicesId = btDeviceId; conn.Insert(gpsLocation); } else { btDevicesIndividual.Id = deviceAlreadyExists.Id; conn.Update(btDevicesIndividual); GPSLocation existingGPSLocation = GetGpsLocation(btDevicesIndividual.Id); if (existingGPSLocation == null) { existingGPSLocation = new GPSLocation(); existingGPSLocation.BtDevicesId = btDeviceId; existingGPSLocation.Address = gpsLocation.Address; existingGPSLocation.Altitude = gpsLocation.Altitude; existingGPSLocation.LatitudeLongitude = gpsLocation.LatitudeLongitude; conn.Insert(gpsLocation); } else { existingGPSLocation.BtDevicesId = btDeviceId; existingGPSLocation.Address = gpsLocation.Address; existingGPSLocation.Altitude = gpsLocation.Altitude; existingGPSLocation.LatitudeLongitude = gpsLocation.LatitudeLongitude; conn.Update(existingGPSLocation); } } return(btDeviceId); }
public override void OnReceive(Context context, Intent intent) { String action = intent.Action; this.context = context; // blueToothTextView = mBlueToothDiscover != null ? mBlueToothDiscover.FindViewById<TextView>(Resource.Id.BlueToothResults) : null; if (BluetoothDevice.ActionFound == action && blueToothTextView != null) { BluetoothDevice device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); int rssi = intent.GetShortExtra(BluetoothDevice.ExtraRssi, Short.MinValue); string uuid = (string)intent.GetParcelableExtra(BluetoothDevice.ExtraUuid); blueToothTextView.Text += "\n Device: " + device.Name + ", " + device.Type + ", " + rssi + ", " + device; BtDevice btDevice = new BtDevice(); btDevice.Name = device.Name; btDevice.Type = device.Type.ToString(); btDevice.Strength = rssi; btDevice.MacAddress = device.ToString(); btDevice.Uuid = uuid; btDeviceList.Add(btDevice); } else { if (BluetoothDevice.ActionPairingRequest == action) { BluetoothDevice device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); IParcelable[] uuidExtra = intent.GetParcelableArrayExtra(BluetoothDevice.ExtraUuid); for (int i = 0; i < uuidExtra.Length; i++) { blueToothTextView.Text += "\n Device: " + device.Name + ", " + device + ", Service: " + uuidExtra[i].ToString(); } } else { if (BluetoothAdapter.ActionDiscoveryStarted == action) { blueToothTextView.Text += "\nDiscovery Started..."; } } } if (BluetoothAdapter.ActionDiscoveryFinished == action && blueToothTextView != null) { blueToothTextView.Text += "\nDiscovery Stopped For Some Reason..."; } }
public int AddNewBtDevice(BtDevice btdevice, GPSLocation newGpsLocation) { iBeacon_Indexer.BtDevices btDevicesIndividual = new BtDevices(); btDevicesIndividual.Name = btdevice.Name; btDevicesIndividual.Type = btdevice.Type; btDevicesIndividual.MacAddress = btdevice.MacAddress; btDevicesIndividual.Strength = btdevice.Strength; btDevicesIndividual.UUID = btdevice.UuidString; btDevicesIndividual.Major = btdevice.MajorInt; btDevicesIndividual.Minor = btdevice.MinorInt; int newBTDeviceId = conn.Insert(btDevicesIndividual);; newGpsLocation.BtDevicesId = newBTDeviceId; conn.Insert(newGpsLocation); return(newBTDeviceId); }