2017-02-22 22 views
0

EddyStoneビーコンのデータを読み込もうとしているので、URLで何かできることがあります。ただし、フォーマットを継続するときには???goo.gl/..CでEddystoneのURLを書式設定する方法

受信したBluetoothデータにデータを記録するコードを書きました。

private void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs) 
{ 
    // We only need the scannable devices containing data 
    if (eventArgs.AdvertisementType != BluetoothLEAdvertisementType.ConnectableUndirected || eventArgs.Advertisement.DataSections.Count < 3) 
     return; 

    // Do whatever you want with the advertisement 
    Encoding asciiEncoding = ASCIIEncoding.ASCII; 

    System.Diagnostics.Debug.WriteLine("=========================================================================================== NEW ADVERTISEMENT ==========================================================================================="); 
    System.Diagnostics.Debug.WriteLine("Address: " + eventArgs.BluetoothAddress); 
    System.Diagnostics.Debug.WriteLine("Type: " + eventArgs.AdvertisementType); 
    System.Diagnostics.Debug.WriteLine("Strength: " + eventArgs.RawSignalStrengthInDBm); 
    System.Diagnostics.Debug.WriteLine("Datasections Count: " + eventArgs.Advertisement.DataSections.Count); 
    System.Diagnostics.Debug.WriteLine("Flags: " + eventArgs.Advertisement.Flags); 
    System.Diagnostics.Debug.WriteLine("LocalName: " + eventArgs.Advertisement.LocalName); 
    System.Diagnostics.Debug.WriteLine("Uuids: " + eventArgs.Advertisement.ServiceUuids[0]); 

    string output = ""; 
    int i = 1; 
    foreach(BluetoothLEAdvertisementDataSection data in eventArgs.Advertisement.DataSections) 
    { 
     var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(data.Data); 
     System.Diagnostics.Debug.WriteLine("Data Length: " + data.Data.Length + "/DataReader: " + dataReader.UnconsumedBufferLength); 
     byte[] fileContent = new byte[dataReader.UnconsumedBufferLength]; 
     dataReader.ReadBytes(fileContent); 

     string hexString = BitConverter.ToString(fileContent); 
     System.Diagnostics.Debug.WriteLine("Datasection" + i + ": " + BitConverter.ToString(fileContent)); 
     string dataSectionOutput = asciiEncoding.GetString(fileContent, 0, fileContent.Length); 
     System.Diagnostics.Debug.WriteLine("Datasection" + i + ": " + dataSectionOutput); 

     output += dataSectionOutput; 
     output = output.Replace("?", ""); 

     i++; 
    } 

    System.Diagnostics.Debug.WriteLine("Output: " + output.ToString()); 
} 

これが私たちの出力我々が使用しなければならないのは何のエンコード/デコード

Address: 220868346281848 
Type: ConnectableUndirected 
Strength: -75 
Datasections Count: 3 
Flags: GeneralDiscoverableMode, ClassicNotSupported 
LocalName: 
Uuids: 0000feaa-0000-1000-8000-00805f9b34fb 
Data Length: 1/DataReader: 1 
Datasection1: 06 
Datasection1: 
Data Length: 2/DataReader: 2 
Datasection2: AA-FE 
Datasection2: ?? 
Data Length: 18/DataReader: 18 
Datasection3: AA-FE-10-EB-03-67-6F-6F-2E-67-6C-2F-79-54-35-56-61-64 
Datasection3: ???goo.gl/yT5Vad 
Output: goo.gl/yT5Vad 

のですか?

答えて

4

EddyStone specによると、EddyStoneフレームは、バイトAA-FEで始まります。その後、フレームタイプを指定する1バイトが続きます。 0x10は、URLフレームの識別子です。
その後、送信電力を表す1バイトが含まれますが、おそらく無視できます。
その後、1バイトを表すスキームが続き、そのあとのurlが続きます。 urlはASCIIの印刷可能部分を使用してエンコードされ、印刷できない文字は圧縮に使用されます。

正しいセクション(つまり、AA-FE-10で始まる)を特定したら、解析は比較的簡単です。

関連する問題