年明け

parent bcc42f97
...@@ -9,7 +9,7 @@ using Windows.Devices.Bluetooth.Advertisement; ...@@ -9,7 +9,7 @@ using Windows.Devices.Bluetooth.Advertisement;
public class Define public class Define
{ {
public const int OK_Num = 4; public const int OK_Num = 3;
public const string ERROR_MSG = "error message"; public const string ERROR_MSG = "error message";
} }
...@@ -28,9 +28,9 @@ namespace WpfBleSampleApp ...@@ -28,9 +28,9 @@ namespace WpfBleSampleApp
//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 Dictionary<ulong, BluetoothLEDevice> devices = new Dictionary<ulong, BluetoothLEDevice>();
private Mutex mutex = new Mutex(); private Mutex mutex = new Mutex();
/*DeviceId*/
/*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-74:99:95:70:e8:29",
...@@ -40,15 +40,28 @@ namespace WpfBleSampleApp ...@@ -40,15 +40,28 @@ namespace WpfBleSampleApp
"", "",
};*/ };*/
/*BDアドレス*/
private ulong[] okList = private ulong[] okList =
{ {
127275385815703, /*82423332791826, //Bluetooth 4a:f6:ad:78:e6:12
79871770127683, //
82423332791826, //Bluetooth 4a:f6:ad:78:e6:12
108555962440447, //Bluetooth 62:bb:27:94:5a:ff 108555962440447, //Bluetooth 62:bb:27:94:5a:ff
117605944835917, 117605944835917,
76312922084733, //Bluetooth 45:67:fc:9c:d5:7d 自分の何か 76312922084733, //Bluetooth 45:67:fc:9c:d5:7d 自分の何か
139673612859991 // orutasu 12/19 139673612859991, // orutasu 12/19
95952497671738, // orutasu 12/19
104072803926013, // orutasu 12/19
112717208922713, //12/20 lab
*/
//12/23 自宅
72542603779210 ,//Bluetooth 41:fa:24:21:1c:8a,
119668175063121 ,//Bluetooth 6c:d6:6b:10:c8:51,
139563132157043,//Bluetooth 7e:ee:92:ea:7c:73,
//1/8 lab
140285132663853 ,//Bluetooth 7f:96:ad:7f:ec:2d,
83936478851746,//Bluetooth 4c:56:fc:01:72:a2,
}; };
/*private string[] okList = /*private string[] okList =
{ {
...@@ -64,6 +77,18 @@ namespace WpfBleSampleApp ...@@ -64,6 +77,18 @@ namespace WpfBleSampleApp
Bluetooth 45:67:fc:9c:d5:7d, 76312922084733 Bluetooth 45:67:fc:9c:d5:7d, 76312922084733
Bluetooth 45:da:1d:36:ba:a5, 76803095313061 Bluetooth 45:da:1d:36:ba:a5, 76803095313061
Bluetooth 6f:2b:60:01:42:b7, 122232084972215
Bluetooth 78:dc:79:ad:81:08, 132888329552136
Bluetooth 48:64:11:76:c7:0d, 79594626926349
Bluetooth 72:b0:e5:06:05:76, 126104082187638
Bluetooth 5e:a7:56:82:3f:fd, 104072803926013
Bluetooth 5e:dc:1f:04:ac:04, 104299506215940
Bluetooth 5d:cb:9f:e8:a2:f1, 103129142567665
Bluetooth 70:19:e9:5c:d2:55, 123256591667797 ,
Bluetooth 66:84:05:32:aa:59, 112717208922713 ,
Bluetooth 5f:85:83:41:60:a7, 105027037388967 ,
};*/ };*/
public MainWindow() public MainWindow()
...@@ -71,6 +96,7 @@ namespace WpfBleSampleApp ...@@ -71,6 +96,7 @@ namespace WpfBleSampleApp
InitializeComponent(); InitializeComponent();
this.watcher = new BluetoothLEAdvertisementWatcher(); this.watcher = new BluetoothLEAdvertisementWatcher();
//OK_List の表示
this.TextBlockokList.Text += $"\n"; this.TextBlockokList.Text += $"\n";
foreach (var ok in okList) foreach (var ok in okList)
{ {
...@@ -95,7 +121,7 @@ namespace WpfBleSampleApp ...@@ -95,7 +121,7 @@ namespace WpfBleSampleApp
this.watcher.SignalStrengthFilter.InRangeThresholdInDBm = -60; // >=-60dBm this.watcher.SignalStrengthFilter.InRangeThresholdInDBm = -60; // >=-60dBm
// rssi <= -65が2秒続いたら受信終わるっぽい // rssi <= -65が2秒続いたら受信終わるっぽい
this.watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -65; // <=-65dBm this.watcher.SignalStrengthFilter.OutOfRangeThresholdInDBm = -65; // <=-65dBm
this.watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(2000);// 2000ミリ秒以上遠ざかっていると受信終了 this.watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(3000);// 3000ミリ秒以上遠ざかっていると受信終了
this.watcher.Received += this.Watcher_Received; this.watcher.Received += this.Watcher_Received;
} }
...@@ -124,10 +150,20 @@ namespace WpfBleSampleApp ...@@ -124,10 +150,20 @@ namespace WpfBleSampleApp
case Windows.Foundation.AsyncStatus.Completed://無事完了すれば case Windows.Foundation.AsyncStatus.Completed://無事完了すれば
var device = task.GetResults(); var device = task.GetResults();
if (device == null) return; if (device == null) return;
Debug.WriteLine($"device found:{device.Name},{device.BluetoothAddress}"); Debug.WriteLine($"device found:{device.Name},{device.BluetoothAddress}");// ここでKeyを決める
Debug.WriteLine($"device found:{device.Name},{device.DeviceId},{device.BluetoothDeviceId.Id}");// ここでKeyを決める
if (device.WasSecureConnectionUsedForPairing) { //接続したことがあればSecure
Debug.WriteLine("####Secure####");
}
mutex.WaitOne(); mutex.WaitOne();
devices[device.BluetoothAddress] = device;//DeviceId と device を結び付けている devices[device.BluetoothAddress] = device;//DeviceId と device を結び付けている
//KeyにBDアドレスを選択
//RSSIが小さければ削除するコード(必要か?)
Debug.WriteLine("===========begin"); Debug.WriteLine("===========begin");
foreach (var x in devices) foreach (var x in devices)
...@@ -135,7 +171,7 @@ namespace WpfBleSampleApp ...@@ -135,7 +171,7 @@ namespace WpfBleSampleApp
var dev = x.Value; var dev = x.Value;
var id = x.Key; // == dev.BluetoothAddress var id = x.Key; // == dev.BluetoothAddress
Debug.WriteLine($"{dev.Name}, {id}");// Name,BluetoothAddress Debug.WriteLine($"{dev.Name}, {id} ,");// Name,BluetoothAddress
} }
Debug.WriteLine("===========end"); Debug.WriteLine("===========end");
mutex.ReleaseMutex(); mutex.ReleaseMutex();
...@@ -159,6 +195,10 @@ namespace WpfBleSampleApp ...@@ -159,6 +195,10 @@ namespace WpfBleSampleApp
this.TextBlockRSSI.Text += $"ok count: {count}\n"; this.TextBlockRSSI.Text += $"ok count: {count}\n";
if (count >= Define.OK_Num) {
this.TextBlockRSSI.Text += $"You are You!\n";
}
mutex.ReleaseMutex(); mutex.ReleaseMutex();
}); });
break; break;
......
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