IDとしてBluetooth Address を使用

parent 6f2ccd8c
......@@ -16,7 +16,7 @@
<ColumnDefinition Width="8*"/>
<ColumnDefinition Width="257*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Name="TextBlockokList" Margin="24,-31,-11,0" Height="52" VerticalAlignment="Top" RenderTransformOrigin="0.495,1.012" Grid.Column="2" Text="okList" />
<TextBlock x:Name="TextBlockRSSI" Margin="10,60,-1,-103" Height="267" VerticalAlignment="Top" Grid.ColumnSpan="3" RenderTransformOrigin="0.492,1.471" />
<TextBlock x:Name="TextBlockokList" Margin="24,-31,-11,0" Height="122" VerticalAlignment="Top" RenderTransformOrigin="0.495,1.012" Grid.Column="2" Text="okList" />
<TextBlock x:Name="TextBlockRSSI" Margin="10,108,-1,-103" Height="219" VerticalAlignment="Top" Grid.ColumnSpan="3" RenderTransformOrigin="0.492,1.471" />
</Grid>
</Window>
\ No newline at end of file
......@@ -7,7 +7,11 @@ using System.Windows;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.Advertisement;
public class Define
{
public const int OK_Num = 4;
public const string ERROR_MSG = "error message";
}
//special thanks
//https://blog.okazuki.jp/entry/2016/07/19/221226
......@@ -21,10 +25,13 @@ namespace WpfBleSampleApp
{
private BluetoothLEAdvertisementWatcher watcher;
private Dictionary<string, BluetoothLEDevice> devices = new Dictionary<string, BluetoothLEDevice>();
//private Dictionary<string, BluetoothLEDevice> devices = new Dictionary<string, BluetoothLEDevice>();
private Dictionary<ulong, BluetoothLEDevice> devices = new Dictionary<ulong, BluetoothLEDevice>();
private Mutex mutex = new Mutex();
private string[] okList =
/*private string[] okList =
{
"BluetoothLE#BluetoothLE98:5f:d3:d1:35:3f-74:99:95:70:e8:29",
"BluetoothLE#BluetoothLE98:5f:d3:d1:35:3f-4e:03:3e:8f:50:96",
......@@ -32,6 +39,15 @@ namespace WpfBleSampleApp
"",
"",
};*/
private ulong[] okList =
{
127275385815703,
79871770127683,
82423332791826,
108555962440447,
117605944835917,
};
public MainWindow()
......@@ -92,18 +108,18 @@ namespace WpfBleSampleApp
case Windows.Foundation.AsyncStatus.Completed://無事完了すれば
var device = task.GetResults();
if (device == null) return;
Debug.WriteLine($"device found: {device.Name}");
Debug.WriteLine($"device found:{device.Name},{device.BluetoothAddress}");
mutex.WaitOne();
devices[device.DeviceId] = device;//DeviceId と device を結び付けている
devices[device.BluetoothAddress] = device;//DeviceId と device を結び付けている
Debug.WriteLine("===========begin");
foreach (var x in devices)
{
var dev = x.Value;
var id = x.Key; // == dev.DeviceId
var id = x.Key; // == dev.BluetoothAddress
Debug.WriteLine($"{dev.Name}, {id}");
Debug.WriteLine($"{dev.Name}, {id}");// Name,BluetoothAddress
}
Debug.WriteLine("===========end");
mutex.ReleaseMutex();
......@@ -121,6 +137,8 @@ namespace WpfBleSampleApp
}
// OKリストの中身と何個一致しているか
//var count = okList.Count((okId) => devices.ContainsKey(okId));
var count = okList.Count((okId) => devices.ContainsKey(okId));
this.TextBlockRSSI.Text += $"ok count: {count}\n";
......
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "3E8643B1D2420B6754788BA2F1DE4AFABEF42E89"
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "2F825A43B7222DED9479B0ACCF25EC750A4607C9"
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
......
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "3E8643B1D2420B6754788BA2F1DE4AFABEF42E89"
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "2F825A43B7222DED9479B0ACCF25EC750A4607C9"
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment