Ejemplo n.º 1
0
        public void Update(BMDatabase db)
        {
            Database = db;

            //alternate background
            //Background = (index%2==0)? Brushes.AliceBlue : Brushes.AntiqueWhite;
            //IsSelected = isSelected;

            BMRecordCurrent r = new BMRecordCurrent();

            if (db.Records.Count > 0)
            {
                r = db.Records.Last();
            }

            TimeSpan age = DateTime.Now - r.Date;

            IsActive = age.TotalSeconds < 60;

            Name = string.IsNullOrWhiteSpace(db.Device.DisplayName)?db.Device.Name : db.Device.DisplayName;
            System.Diagnostics.Debug.WriteLine("Display Name: " + Name);
            Address   = "(" + db.Device.GetAddressString() + ")";
            Interval  = "Int: " + r.LoggingInterval.ToString();
            Signal    = "Sig: " + r.RSSI;
            LogsCount = "Logs: " + db.Records.Count;
            Battery   = "Bat: " + r.BatteryLevel + "%";

            Temperature.Value = (r.GetTemperature(db.Units)).ToString("0.0");
            Temperature.Units = db.Units.TemperatureUnits.Desc;

            AirHumidity.Value = (r.GetAirHumidity()).ToString("0.0");
            AirHumidity.Units = db.Units.RelativeHumidityUnits.Desc;

            AirPressure.Value = (r.GetAirPressure(db.Units)).ToString("0.0");
            AirPressure.Units = db.Units.AirPressureUnits.Desc;

            AirDewPoint.Value = (r.GetAirDewPoint(db.Units)).ToString("0.0");
            AirDewPoint.Units = db.Units.TemperatureUnits.Desc;
        }
Ejemplo n.º 2
0
        private async void ProcessManufacturerData(BluetoothLEAdvertisementReceivedEventArgs e, MData m)
        {
            int idx = m.FindManufacturerId(BMRecordBase.MANUFACTURER_ID);

            if (idx < 0)
            {
                return;
            }

            if (!_blueMaestroDevices.ContainsKey(e.BluetoothAddress))
            {
                BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(e.BluetoothAddress);

                lock (_blueMaestroDevices)
                {
                    if (device != null)
                    {
                        _blueMaestroDevices[e.BluetoothAddress] = device;
                        _stopperBM = 0;
                    }
                }
            }

            if (_blueMaestroDevices.ContainsKey(e.BluetoothAddress))
            {
                BluetoothLEDeviceDisplay display = new BluetoothLEDeviceDisplay(_blueMaestroDevices[e.BluetoothAddress].DeviceInformation);
                Log.d("*BT* " + display.ToString());
            }

            if (m.ManufacturerData.Count > 0)
            {
                lock (_blueMaestroDevices)
                {
                    foreach (MData.Section section in m.ManufacturerData)
                    {
                        if (BMRecordCurrent.IsManufacturerID(section.CompanyId))
                        {
                            DateTime        date = DateTime.Now; // eventArgs.Timestamp.DateTime;
                            BluetoothDevice dev  = new BluetoothDevice(
                                e.Advertisement.LocalName,
                                e.BluetoothAddress,
                                e.AdvertisementType.ToString());

                            if (_averages == null)
                            {
                                _averages = new BMRecordAverages(dev, e.RawSignalStrengthInDBm, date, null);
                            }

                            if (_current == null)
                            {
                                _current = new BMRecordCurrent(dev, e.RawSignalStrengthInDBm, date, null);
                            }

                            if (section.Buffer.Length == 14)
                            {
                                if (BMDatabaseMap.INSTANCE.Contains(dev.Address))
                                {
                                    int count = BMDatabaseMap.INSTANCE[dev.Address].Records.Count;
                                    if (count > 0)
                                    {
                                        //time between readings
                                        TimeSpan tsElapsed = DateTime.Now - BMDatabaseMap.INSTANCE[dev.Address].Records.Last().Date;
                                        _lastCurrent = ", Curr Updated: " + tsElapsed.TotalSeconds.ToString("0s");
                                    }
                                }

                                _current = BMDatabaseMap.INSTANCE.AddRecord(dev, e.RawSignalStrengthInDBm, date, section.Buffer);
                            }
                            else if (section.Buffer.Length == 25)
                            {
                                //just update time
                                TimeSpan tsElapsed = DateTime.Now - _averages.Date;
                                _lastAverage = ", Avg Updated: " + tsElapsed.TotalSeconds.ToString("0s");

                                _averages.Set_sData(section.Buffer);
                            }
                            else
                            {
                                Log.e(" --- Unknown Length: " + section.Buffer.Length);
                            }

                            string recordsCount = "";
                            if (BMDatabaseMap.INSTANCE.Contains(dev.Address))
                            {
                                int count = BMDatabaseMap.INSTANCE[dev.Address].Records.Count;
                                recordsCount = "Records: " + count + " \n";
                            }

                            string message = recordsCount;
                            message += "Total: " + CommonTools.TimeSpanToString(TimeSpan.FromSeconds(_stopperBM)) + _lastAverage + _lastCurrent + " \n";
                            message += "Timestamp: " + date.ToString("MMM dd, HH:mm:ss") + " \n";
                            message += _current.ToString() + _averages.ToString();

                            OnBMDeviceMsgReceivedAction(message);
                        }
                    }
                }
            }
        }