Ejemplo n.º 1
0
        /// <summary>
        /// Adds the given value to the characteristics dictionary and triggers the BoardCharacteristicChanged event.
        /// </summary>
        /// <param name="uuid">The UUID of the characteristic.</param>
        /// <param name="value">The value of the characteristics.</param>
        /// <param name="timestamp">A when did the value change?</param>
        /// <returns>True if the value is not the same as already stored for this characteristic.</returns>
        internal bool AddToDictionary(Guid uuid, byte[] value, DateTime timestamp)
        {
            if (value is null)
            {
                return(false);
            }

            byte[] oldValue = null;
            lock (CHARACTERISTICS_LOCK)
            {
                if (CHARACTERISTICS.ContainsKey(uuid))
                {
                    oldValue = CHARACTERISTICS[uuid];
                    CHARACTERISTICS[uuid] = value;
                    if (!oldValue.SequenceEqual(value))
                    {
                        Logger.Debug("Bluetooth characteristic " + uuid.ToString() + " has a new value: " + CryptoUtils.byteArrayToHexString(value));
                        CharacteristicChanged?.Invoke(this, new CharacteristicChangedEventArgs(uuid, oldValue, value));
                    }
                }
                else
                {
                    CHARACTERISTICS[uuid] = value;
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
 public override void OnCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
 {
     CharacteristicChanged?.Invoke(this, characteristic);
 }
Ejemplo n.º 3
0
 public void OnCharacteristicChange(IBLECharacteristic characteristic)
 {
     CharacteristicChanged?.Invoke(null, new CharacteristicEventArgs(characteristic));
 }
Ejemplo n.º 4
0
 protected void onCharacteristicChanged()
 {
     CharacteristicChanged?.Invoke(this, new System.EventArgs());
 }
Ejemplo n.º 5
0
 private void CharacteristicIncreasing(string characteristic, double previousValue, double currentValue)
 {
     CharacteristicChanged?.Invoke(this, new CharactericticEventArgs {
         Message = $"{characteristic} +{currentValue - previousValue}"
     });
 }
        public override void OnCharacteristicChanged(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic)
        {
            base.OnCharacteristicChanged(gatt, characteristic);

            CharacteristicChanged?.Invoke(this, new CharacteristicChangedEventArgs(gatt, characteristic));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds the given value to the characteristics dictionary and triggers the BoardCharacteristicChanged event.
        /// </summary>
        /// <param name="uuid">The UUID of the characteristic.</param>
        /// <param name="value">The value of the characteristics.</param>
        /// <param name="timestamp">A when did the value change?</param>
        /// <param name="updateMockObjects">Whether to update the mock objects</param>
        /// <returns>True if the value is not the same as already stored for this characteristic.</returns>
        internal bool AddToDictionary(Guid uuid, byte[] value, DateTime timestamp, bool shouldUpdateMockObjects)
        {
            if (value is null)
            {
                return(false);
            }

            byte[] oldValue = null;
            lock (CHARACTERISTICS_LOCK)
            {
                if (CHARACTERISTICS.ContainsKey(uuid))
                {
                    oldValue = CHARACTERISTICS[uuid];
                    CHARACTERISTICS[uuid] = value;
                }
                else
                {
                    CHARACTERISTICS[uuid] = value;
                }
            }

            if (!uuid.Equals(CHARACTERISTIC_UART_SERIAL_READ) && !uuid.Equals(CHARACTERISTIC_UART_SERIAL_WRITE))
            {
                if (oldValue == value || (!(oldValue is null) && oldValue.SequenceEqual(value)))
                {
                    // Values are the same, no need to update anything:
                    return(false);
                }
            }

            if (!DONT_SEND_ON_CHANGED_NOTIFICATIONS_CHARACTERISTICS.Contains(uuid))
            {
                CharacteristicChanged?.Invoke(this, new CharacteristicChangedEventArgs(uuid, oldValue, value));
            }

            if (shouldUpdateMockObjects)
            {
                UpdateMockObjects(uuid, value);
            }

            // Add battery level values to the DB:
            if (uuid.Equals(CHARACTERISTIC_BATTERY_LEVEL))
            {
                BATTERY_HANDLER.onBatteryChargeChanged(GetUint(value), timestamp);
            }
            // Add speed values to the DB:
            else if (uuid.Equals(CHARACTERISTIC_SPEED_RPM))
            {
                uint rpm = GetUint(value);
                SPEED_HANDLER.onRpmChanged(rpm, timestamp);
            }
            else if (uuid.Equals(CHARACTERISTIC_BATTERY_TEMPERATUR))
            {
                THERMAL_HANDLER.onTempChanged(OnewheelThermalHandler.BATTERY_TEMP, value[1], timestamp);
            }
            else if (uuid.Equals(CHARACTERISTIC_MOTOR_CONTROLLER_TEMPERATURE))
            {
                THERMAL_HANDLER.onTempChanged(OnewheelThermalHandler.CONTROLLER_TEMP, value[0], timestamp);
                THERMAL_HANDLER.onTempChanged(OnewheelThermalHandler.MOTOR_TEMP, value[1], timestamp);
            }
            return(true);
        }