wpf

parent cb93aded
......@@ -5,9 +5,13 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:iBeaconScanner"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="1130.975">
Title="MainWindow" Height="350" Width="938.836">
<Grid>
<TextBox x:Name="textBox" Margin="0,35,0,0.5" TextWrapping="Wrap" Text=""/>
<TextBox x:Name="listBox" Margin="0,95,75,0.5" TextWrapping="Wrap" Text="around list" IsReadOnly="True"/>
<TextBox x:Name="RUNUBox" Margin="0,35,607,251.5" TextWrapping="Wrap" Text="" IsReadOnly="True"/>
<TextBox x:Name="textBox" Margin="332,35,394,251.5" TextWrapping="Wrap" Text="" IsReadOnly="True"/>
<TextBox x:Name="pass" HorizontalAlignment="Left" Height="36" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Margin="621,35,0,0"/>
<Button Content="Button1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="767,51,0,0" />
</Grid>
</Window>
......@@ -21,15 +21,19 @@ namespace iBeaconScanner
/* 定数 */
public static int CompanyID_Apple = 76;
public static int Length_of_iBeacon_Advertise_Packet = 23;
public static int OKnum = 1;
public static TimeSpan TIMEOUT = new TimeSpan(0,0,3);//3秒離れてたらタイムアウト
/* パラメータ */
public static int A_thresh = 2;//認証可能人数
public static double B_thresh = 0.3;//RU率
public static TimeSpan TIMEOUT = new TimeSpan(0,0,1);//3秒間離れてたら近くにいないと判断
public static TimeSpan LIMIT_TIME = new TimeSpan(0, 0, 5);//3秒パケットが取れなければ終了
static int RUcnt, NUcnt;
static HashSet<string> RU_uuid = new HashSet<string>(); //RUのハッシュセット
//static HashSet<string> Around_uuid = new HashSet<string>(); //周囲のuuidのハッシュセット
Dictionary<string,DateTimeOffset> Around_uuid = new Dictionary<string, DateTimeOffset>(); //周囲のuuidのハッシュセット
Stopwatch sw = new Stopwatch();
static HashSet<string> RU_uuid = new HashSet<string>(); //RUのハッシュセット
static Dictionary<string,DateTimeOffset> Around_uuid = new Dictionary<string, DateTimeOffset>(); //周囲のuuidたち
public MainWindow()
{
......@@ -38,6 +42,8 @@ namespace iBeaconScanner
/* 事前登録 */
RU_uuid.Add("48534442-4c45-4144-1234-dcba12345678");
RU_uuid.Add("48534442-4c45-4144-1234-abcd12345678");
RU_uuid.Add("48534442-4c45-4144-1234-abcd12345671");
RU_uuid.Add("48534442-4c45-4144-80c0-1800ffffffff");
this.advWatcher = new BluetoothLEAdvertisementWatcher();
......@@ -50,15 +56,41 @@ namespace iBeaconScanner
this.advWatcher.Received += this.Watcher_Received;
sw.Start();
// スキャン開始
this.advWatcher.Start();
}
private static Mutex mutex = new Mutex();
private void Button1_Click(object sender, EventArgs e)
{
//★★★TextBoxのテキストを取得★★★
string strText = pass.Text;
if (strText.Equals("1234")) {
this.textBox.Text = "OK!" + "\r\n";
}
Debug.WriteLine($"InSWARD");
}
private async void Watcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{
await this.Dispatcher.InvokeAsync(() =>
{
mutex.WaitOne();
Debug.WriteLine($"{sw.Elapsed}");//
if (sw.Elapsed > LIMIT_TIME)
{
advWatcher.Stop();
Debug.WriteLine($"Input PASSWARD");
this.textBox.Text = "Input PASSWARD" + "\r\n";
}
foreach (var manufacturerData in args.Advertisement.ManufacturerData)
{
/*
......@@ -70,7 +102,7 @@ namespace iBeaconScanner
Debug.WriteLine($"--------------");
*/
// mutex.WaitOne();
//mutex.WaitOne();
if (manufacturerData.CompanyId != CompanyID_Apple)
{
......@@ -111,69 +143,69 @@ namespace iBeaconScanner
var proximity_uuid = new Guid(uuidA, uuidB, uuidC, uuidD);
/* RUのハッシュセットを作成 *//*
if( !RU_uuid.Contains(proximity_uuid.ToString() ) )
{
RU_uuid.Add(proximity_uuid.ToString() );
}
foreach (var RU in RU_uuid)
{
Debug.WriteLine($" RU is {RU}");
Console.WriteLine($" RU is {RU}");
}
Console.WriteLine($"------------");
*/
Debug.WriteLine($"UUID:{proximity_uuid}, major: {major}, minor: {minor}, power: {power}");
/* 周囲のuuidのDictionaryを作成 */
if (!Around_uuid.Keys.Contains(proximity_uuid.ToString())) //新しいUUIDなら追加 ????????
if (!Around_uuid.ContainsKey(proximity_uuid.ToString())) //新しいUUIDなら追加
{
sw.Restart();
DateTime timeA = DateTime.Now;
Around_uuid.Add(proximity_uuid.ToString(),args.Timestamp);
Debug.WriteLine($"New!");
Debug.WriteLine($"UUID: {proximity_uuid}, major: {major}, minor: {minor}, power: {power}");
Debug.WriteLine($" It's New UUID!");
}
else //既にあるUUIDなら時間更新
{
Around_uuid[proximity_uuid.ToString()] = args.Timestamp;
Debug.WriteLine($"Time Refreshed...");
Debug.WriteLine($" Time Refreshed...");
}
/* 周囲にあるUUIDを表示 */
this.listBox.Text = this.listBox.Text + "---------------" + "\r\n";
foreach (var some in Around_uuid)
{
//Debug.WriteLine($"%%%{some.Value} UUID:{some.Key}");
this.listBox.Text = this.listBox.Text +" Arround uuid:"+ some.Value + ":::" + some.Key +"\r\n";
}//
}
/* Timestamp が古いものを削除 */
DateTime dt = DateTime.Now;
var removeTargetLst = Around_uuid.Where(kv => (dt - kv.Value) < TIMEOUT).ToList();
var removeTargetLst = Around_uuid.Where(kv => (dt - kv.Value) > TIMEOUT).ToList();
foreach (var item in removeTargetLst)
{
Around_uuid.Remove(item.Key); // ここで削除する。Keyを指定して削除出来る。
}
/* 周囲にあるUUID */
foreach (var some in Around_uuid)
{
Debug.WriteLine($"UUID:{some.Key} ,time:{some.Value}");
this.textBox.Text = this.textBox.Text + some.Value + ":" + some.Key +"\r\n";
}
/* 判定フェーズ↓ */
RUcnt = 0;
NUcnt = 0;
foreach (var N in RU_uuid)
foreach (string N in RU_uuid)
{
if (Around_uuid.Keys.Contains(N))
if (Around_uuid.ContainsKey(N))
{
RUcnt++;
continue;
}
else { NUcnt++; }
}
this.textBox.Text = this.textBox.Text + "RU:" + RUcnt + "人, NU" + NUcnt + "人" + "\r\n";
NUcnt = Around_uuid.Count - RUcnt;
if (RUcnt >= OKnum && RUcnt * 3 > NUcnt)//安全かどうかの判定
this.RUNUBox.Text = "RU:" + RUcnt + "人, NU" + NUcnt + "人" + "\r\n";
if (RUcnt >= A_thresh && RUcnt / (RUcnt + NUcnt) >= B_thresh)//安全かどうかの判定
{
this.textBox.Text = this.textBox.Text + "You are YOU!!" + "\r\n";
// watcher.Stop();
this.textBox.Text = "You are ACCEPTED!!" + "\r\n";
advWatcher.Stop();
Debug.WriteLine($"You are ACCEPTED!!");
}
/* 判定フェーズ↑ */
mutex.ReleaseMutex();
}
}
});
}
......
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "529B587B28CD66E92A7B94149F23D8EDF9A1A6D5"
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "1FF327C0534BE6044F07318BB02F5A77C7094ADD"
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
......@@ -43,11 +43,35 @@ namespace iBeaconScanner {
#line 10 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox listBox;
#line default
#line hidden
#line 11 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox RUNUBox;
#line default
#line hidden
#line 12 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox textBox;
#line default
#line hidden
#line 13 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox pass;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
......@@ -79,8 +103,17 @@ namespace iBeaconScanner {
switch (connectionId)
{
case 1:
this.listBox = ((System.Windows.Controls.TextBox)(target));
return;
case 2:
this.RUNUBox = ((System.Windows.Controls.TextBox)(target));
return;
case 3:
this.textBox = ((System.Windows.Controls.TextBox)(target));
return;
case 4:
this.pass = ((System.Windows.Controls.TextBox)(target));
return;
}
this._contentLoaded = true;
}
......
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "529B587B28CD66E92A7B94149F23D8EDF9A1A6D5"
#pragma checksum "..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "1FF327C0534BE6044F07318BB02F5A77C7094ADD"
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
......@@ -43,11 +43,35 @@ namespace iBeaconScanner {
#line 10 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox listBox;
#line default
#line hidden
#line 11 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox RUNUBox;
#line default
#line hidden
#line 12 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox textBox;
#line default
#line hidden
#line 13 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.TextBox pass;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
......@@ -79,8 +103,17 @@ namespace iBeaconScanner {
switch (connectionId)
{
case 1:
this.listBox = ((System.Windows.Controls.TextBox)(target));
return;
case 2:
this.RUNUBox = ((System.Windows.Controls.TextBox)(target));
return;
case 3:
this.textBox = ((System.Windows.Controls.TextBox)(target));
return;
case 4:
this.pass = ((System.Windows.Controls.TextBox)(target));
return;
}
this._contentLoaded = true;
}
......
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