Beispiel #1
0
        public static async Task <bool> OutputLog(GattDeviceService service)
        {
            try {
                Console.WriteLine($"Service.Uuid...{service.Uuid}");
                Console.WriteLine($"Service Name...{DebugMethods.GetServiceUUIDName(service.Uuid)}");
                Console.WriteLine($"Servicev.DeviceId...{service.DeviceId}");

                var characteristics = await service.GetCharacteristicsAsync(BluetoothCacheMode.Cached);

                foreach (var ch in characteristics.Characteristics)
                {
                    Console.WriteLine($"Characteristic...");
                    Console.WriteLine($"...AttributeHandle=0x{ch.AttributeHandle.ToString("X2")}");
                    Console.WriteLine($"...Properties={ch.CharacteristicProperties}");
                    Console.WriteLine($"...ProtectionLevel={ch.ProtectionLevel}");
                    Console.WriteLine($"...UUID={ch.Uuid}");
                }
            } catch (Exception) {
            }
            return(true);
        }
Beispiel #2
0
        public static void OutputLog(BluetoothLEAdvertisementReceivedEventArgs args)
        {
            try {
                Console.WriteLine("<< OutputLog >>");

                // タイムスタンプ(スキャン日時?)
                Console.WriteLine($"TimeStamp = {args.Timestamp:HH\\:mm\\:ss}");

                // アドバタイズパケット発信元の Bluetoothデバイスアドレス-48bit(6byte)
                Console.WriteLine($"BluetoothAddress = {args.BluetoothAddress.ToString("X")}");

                // シグナル強度
                Console.WriteLine($"RSSI = {args.RawSignalStrengthInDBm}");

                // アドバタイズパケット種別
                // https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementtype
                Console.WriteLine($"AdvertisementType = {args.AdvertisementType}");
                switch (args.AdvertisementType)
                {
                case BluetoothLEAdvertisementType.ConnectableUndirected:
                    Console.WriteLine($"-> ADV_IND:コネクション可能、スキャン可能");
                    break;

                case BluetoothLEAdvertisementType.ConnectableDirected:
                    Console.WriteLine($"-> ADV_DIRECT_IND:コネクション可能、スキャン×");
                    break;

                case BluetoothLEAdvertisementType.ScannableUndirected:
                    Console.WriteLine($"-> ADV_SCAN_IND:コネクション×、スキャン可能");
                    break;

                case BluetoothLEAdvertisementType.NonConnectableUndirected:
                    Console.WriteLine($"-> ADV_NONCONN_IND:コネクション×、スキャン×");
                    break;

                case BluetoothLEAdvertisementType.ScanResponse:
                    Console.WriteLine($"-> SCAN_RSP:スキャン要求に対するスキャン応答");
                    break;

                default:
                    Console.WriteLine($"-> ???");
                    break;
                }

                // アドバタイズデータ
                Console.WriteLine("");
                Console.WriteLine("<Data>");

                // Flags (DataSectionにも同じ情報あるが、こっちの方が見やすい)
                Console.WriteLine($"Flags = {args.Advertisement.Flags}");

                // LocalName (DataSectionにも同じ情報あるが、こっちの方が見やすい)
                Console.WriteLine($"LocalName = {args.Advertisement.LocalName}");

                // Service UUID (DataSectionにも同じ情報あるが、こっちの方が見やすい)
                {
                    var bleServiceUUIDs = args.Advertisement.ServiceUuids;
                    Console.WriteLine($"Service UUID Num = {bleServiceUUIDs.Count}");
                    foreach (var uuidone in bleServiceUUIDs)
                    {
                        // サービスUUIDってなに?→http://jellyware.jp/kurage/bluejelly/uuid.html
                        Console.WriteLine($"-> Service UUID = {uuidone} -> {DebugMethods.GetServiceUUIDName(uuidone)}");
                    }
                    Console.WriteLine("");
                }

                {
                    var manufacturerSections = args.Advertisement.ManufacturerData;
                    Console.WriteLine($"Manufacturer Num = {manufacturerSections.Count}");
                    if (manufacturerSections.Count > 0)
                    {
                        foreach (var manuone in manufacturerSections)
                        {
                            Console.WriteLine($"<Manufacturer>");
                            Console.WriteLine($"-> CompanyId = {manuone.CompanyId.ToString("X2")}");
                            Console.WriteLine($"-> Data Length = {manuone.Data.Length}");
                            if (manuone.Data.Length > 0)
                            {
                                var data = new byte[manuone.Data.Length];
                                using (var reader = Windows.Storage.Streams.DataReader.FromBuffer(manuone.Data)) {
                                    reader.ReadBytes(data);

                                    var tmp = BitConverter.ToString(data);
                                    Console.WriteLine($"-> Data = {tmp}");
                                }
                            }
                        }
                    }
                    Console.WriteLine("");
                }


                // DataSection
                {
                    var bleDataSections = args.Advertisement.DataSections;
                    Console.WriteLine($"Advertising Data Num = {bleDataSections.Count}");
                    foreach (var datasecone in bleDataSections)
                    {
                        byte type = datasecone.DataType;
                        Console.WriteLine($"<Data>");
                        Console.WriteLine($"-> AD Type = 0x{type.ToString("X2")} -> {DebugMethods.GetADTypeName(type)}");
                        Console.WriteLine($"-> Data Length = {datasecone.Data.Length}");

                        if (datasecone.Data.Length > 0)
                        {
                            var data = new byte[datasecone.Data.Length];
                            using (var reader = Windows.Storage.Streams.DataReader.FromBuffer(datasecone.Data)) {
                                reader.ReadBytes(data);

                                var tmp = BitConverter.ToString(data);
                                Console.WriteLine($"-> Data = {tmp}");
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Error");
            } finally {
                Console.WriteLine("<< END >>");
            }
            return;
        }