コード例 #1
0
 public BtDevice(ScannedBleDevice device)
 {
     this.Name       = !string.IsNullOrEmpty(device.DeviceName) ? device.DeviceName : "";
     this.Type       = device.GetType().ToString();
     this.MacAddress = device.MacAddress;
     this.Strength   = int.Parse(device.RSSI.ToString());
     this.Uuid       = device.IbeaconProximityUUID.ToString();
     this.UuidString = device.IbeaconProximityUUIDString;
     this.Major      = device.Major.ToString();
     this.MajorInt   = device.MajorInt;
     this.Minor      = device.Minor.ToString();
     this.MinorInt   = device.MinorInt;
     this.TimeFound  = (FromUnixTime(device.ScannedTime)).ToString();
 }
コード例 #2
0
ファイル: BLEParser.cs プロジェクト: ellistev/iBeaconIndexer
        // use this method to parse those bytes and turn to an object which defined proceeding.
        // the uuidMatcher works as a UUID filter, put null if you want parse any BLE advertising data around.
        public ScannedBleDevice ParseRawScanRecord(BluetoothDevice device, int rssi, byte[] advertisedData, byte[] uuidMatcher)
        {
            int startByte = 2;

            try {
                ScannedBleDevice parsedObj = new ScannedBleDevice();
                // parsedObj.BLEDevice = device;
                parsedObj.DeviceName = device.Name;
                parsedObj.MacAddress = device.Address;
                parsedObj.RSSI       = rssi;
                List <UUID> uuids            = new List <UUID>();
                int         skippedByteCount = advertisedData[0];
                int         magicStartIndex  = skippedByteCount + 1;
                int         magicEndIndex    = magicStartIndex
                                               + advertisedData[magicStartIndex] + 1;
                List <byte> magic = new List <byte>();
                for (int i = magicStartIndex; i < magicEndIndex; i++)
                {
                    magic.Add(advertisedData[i]);
                }

                byte[] companyId = new byte[2];
                companyId[0]        = magic[2];
                companyId[1]        = magic[3];
                parsedObj.CompanyId = companyId;

                byte[] ibeaconProximityUUID = new byte[16];
                for (int i = 0; i < 16; i++)
                {
                    if (magic.Count > (i + 6))
                    {
                        ibeaconProximityUUID[i] = magic[i + 6];
                    }
                }

                parsedObj.IbeaconProximityUUID = ibeaconProximityUUID;

                String hexString = bytesToHex(ibeaconProximityUUID);

                //Here is your UUID
                parsedObj.IbeaconProximityUUIDString = hexString.Substring(0, 8) + "-" +
                                                       hexString.Substring(8, 4) + "-" +
                                                       hexString.Substring(12, 4) + "-" +
                                                       hexString.Substring(16, 4) + "-" +
                                                       hexString.Substring(20, 12);

                byte[] major = new byte[2];
                byte[] minor = new byte[2];
                byte   tx    = 0;
                //try{

                major[0]           = magic[22];
                major[1]           = magic[23];
                parsedObj.Major    = major;
                parsedObj.MajorInt = (advertisedData[startByte + 23] & 0xff) * 0x100 + (advertisedData[startByte + 24] & 0xff);

                minor[0] = magic[24];
                minor[1] = magic[25];

                parsedObj.Minor    = minor;
                parsedObj.MinorInt = (advertisedData[startByte + 25] & 0xff) * 0x100 + (advertisedData[startByte + 26] & 0xff);

                tx           = magic[26];
                parsedObj.Tx = tx;

                //} catch (System.Exception ex) {
                //	parsedObj.Major = major;
                //	parsedObj.MajorInt  = 0;
                //	parsedObj.Minor = minor;
                //	parsedObj.MinorInt =  0;
                //	parsedObj.Tx = 0;
                //}

                parsedObj.ScannedTime = new Date().Time;
                return(parsedObj);
            } catch (System.Exception ex) {
                // Log.e(LOG_TAG,
                // "Exception in ParseRawScanRecord with advertisedData: "
                // + Util.BytesToHexString(advertisedData, " ")
                // + ", detail: " + ex.getMessage());
                return(null);
            }
        }