コード例 #1
0
        /// <summary>
        /// Called when information on a discovered BLE device has changed
        /// </summary>
        /// <param name="sender">Device watcher which discovered the device</param>
        /// <param name="device_info">BLE device information</param>
        private void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate device_info)
        {
            // Retrieve device information
            BleDeviceInformation ble_device_info = new BleDeviceInformation();

            ble_device_info.Id = device_info.Id;
            try
            {
                ble_device_info.MacAddress = device_info.Properties["System.Devices.Aep.DeviceAddress"].ToString();
            }
            catch (KeyNotFoundException)
            {
                ble_device_info.MacAddress = "";
            }
            try
            {
                ble_device_info.IsConnected = (bool)device_info.Properties["System.Devices.Aep.IsConnected"];
            }
            catch (KeyNotFoundException)
            {
                ble_device_info.IsConnected = false;
            }
            try
            {
                ble_device_info.IsConnectable = (bool)device_info.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"];
            }
            catch (KeyNotFoundException)
            {
                ble_device_info.IsConnectable = false;
            }

            // Notify device update
            DeviceUpdated?.Invoke(this, ble_device_info);
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: GimpArm/smartfriends-bridge
        private void HandleMessage(Message message)
        {
            if (message == null)
            {
                return;
            }

            switch (message?.ResponseMessage)
            {
            case "newDeviceValue":
                DeviceUpdated?.Invoke(this, message.Response.ToObject <DeviceValue>());
                break;

            case "newSwitchingSequenceInfo":
                _logger.LogInformation($"Received Switch Sequence Info: {message.Response["switchingSequenceID"]}, nextActivationTime: {message.Response["nextActivationTime"]}");
                break;

            case "newSwitchingSequenceStatus":
                _logger.LogInformation($"Received Switch Sequence: {message.Response["switchingSequenceID"]}, status: {message.Response["status"]}");
                break;

            case "newDeviceInfo":
                _logger.LogInformation($"Received new device: {message.Response}");
                break;

            default:
                _messageQueue.Enqueue(message);
                break;
            }
        }
コード例 #3
0
ファイル: Explorer.cs プロジェクト: marrob/MCEL181123.SW
        public bool UpdateTask(CanMsg msg)
        {
            if (CanDb.GetNodeTypeId(msg.ArbId) == CanDb.Instance.Nodes.FirstOrDefault(n => n.Name == NodeCollection.NODE_MCEL).NodeTypeId)
            {
                byte node  = CanDb.GetNodeAddress(msg.ArbId);
                byte msgId = CanDb.GetMsgId(msg.ArbId);

                if (Devices.FirstOrDefault(n => n.Address == node) is IDevice item)
                {
                    item.Update(msgId, msg.Data);
                    DeviceUpdated?.Invoke(this, item);
                }
                else
                {
                    var newitem = new MCEL181123DeviceItem(node, msgId, msg.Data);
                    Devices.Add(newitem);
                    NewDeviceArrived?.Invoke(this, newitem);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        private void ClientDeviceUpdated(object sender, DeviceValue value)
        {
            var masterId = value.MasterDeviceId == 0 ? value.DeviceId : value.MasterDeviceId;
            var device   = GetDevice(masterId);

            if (device?.SetValues(value) ?? false)
            {
                DeviceUpdated?.Invoke(this, value);
            }
        }
コード例 #5
0
 public void HandleData(GlobalUpdate eventData)
 {
     GlobalUpdated?.Invoke(this, new NestGlobalEventArgs(eventData));
     DeviceUpdated?.Invoke(this, new NestDeviceEventArgs(eventData.Devices));
     StructureUpdated?.Invoke(this, new NestStructureEventArgs(eventData.Structures));
     ThermostatUpdated?.Invoke(this, new NestThermostatEventArgs(eventData.Thermostats));
     CameraUpdated?.Invoke(this, new NestCameraEventArgs(eventData.Cameras));
     SmokeCOAlarmUpdated?.Invoke(this, new NestSmokeCOAlarmEventArgs(eventData.SmokeCOAlarms));
     MetadataUpdated?.Invoke(this, new NestMetadataEventArgs(eventData.Metadata));
 }
コード例 #6
0
        private void StartScannerThread()
        {
            EndPoint localEp = _localEp;

            _cancellationTokenSource = new CancellationTokenSource();
            CancellationToken ct = _cancellationTokenSource.Token;

            _scannerThread = Task.Run(async() =>
            {
                while (!ct.IsCancellationRequested)
                {
                    try
                    {
                        byte[] response = new byte[8000];
                        int no          = _socket.ReceiveFrom(response, ref localEp);
                        string str      = Encoding.UTF8.GetString(Decrypt(response.Take(no).ToArray()));

                        JObject obj = ParserHelpers.ParseGetSysInfo(str);

                        if (obj == null)
                        {
                            continue;
                        }

                        DeviceType deviceType = ParserHelpers.GetDeviceType(obj);

                        if (GetDeviceTypeFilter()?.Contains(deviceType) == false)
                        {
                            Debug.WriteLine("Excluded device");
                            continue;
                        }

                        var requestContext    = new RequestContext(obj, (localEp as IPEndPoint)?.Address);
                        DeviceStateInfo state = await _deviceManager.AddOrUpdate(requestContext).ConfigureAwait(false);

                        switch (state.State)
                        {
                        case DeviceState.Added:
                            DeviceDiscovered?.Invoke(this, new DeviceEventArgs(state.Device));
                            break;

                        case DeviceState.Updated:
                            DeviceUpdated?.Invoke(this, new DeviceEventArgs(state.Device));
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            }, ct);
        }
コード例 #7
0
ファイル: DevicesContext.cs プロジェクト: uxifiit/UXC
        public bool TryUpdateDevice(DeviceType device, DeviceState state, out DeviceStatus status)
        {
            if (_devices.TryGetValue(device, out status) && status.State != state)
            {
                status           = status.Update(state, DateTime.Now);
                _devices[device] = status;

                DeviceUpdated?.Invoke(this, status);
                return(true);
            }

            return(false);
        }
コード例 #8
0
        private void Reader(object input)
        {
            try
            {
                var token = (CancellationToken)input;
                while (!token.IsCancellationRequested)
                {
                    var buffer      = new byte[2048];
                    var messageData = new StringBuilder();
                    int bytes;
                    do
                    {
                        bytes = _stream.ReadAsync(buffer, 0, buffer.Length, token).Result;

                        var decoder = Encoding.UTF8.GetDecoder();
                        var chars   = new char[decoder.GetCharCount(buffer, 0, bytes)];
                        decoder.GetChars(buffer, 0, bytes, chars, 0);
                        messageData.Append(chars);

                        if (chars.Last() == '\n')
                        {
                            break;
                        }
                    } while (bytes != 0 && !token.IsCancellationRequested);

                    var message = Deserialize <Message>(messageData.ToString());
                    if (message.ResponseMessage == "newDeviceValue")
                    {
                        _logger.LogInformation($"Received Status: {messageData}");
                        DeviceUpdated?.Invoke(this, message.Response.ToObject <DeviceValue>());
                    }
                    else
                    {
                        _messageQueue.Enqueue(message);
                    }
                }
            }
            catch (Exception e)
            {
                //Only log if still connected.
                if (Connected)
                {
                    _logger.LogError(e, "Connection closed");
                    Close().ConfigureAwait(false);
                }
            }
        }
コード例 #9
0
ファイル: DeviceGroup.cs プロジェクト: letheascetic/CANLogger
        public bool Update(Device device)
        {
            if (device == null)
            {
                return(false);
            }

            if (GetDevice(device.DeviceType, device.DeviceIndex) == null)
            {
                Logger.Info(string.Format("update device failed, no this device[{0}] in device group", device.GetDeviceName()));
                return(false);
            }

            if (DeviceUpdated != null)
            {
                DeviceUpdated.Invoke(device, null);
            }
            return(true);
        }
コード例 #10
0
 protected virtual void OnDeviceUpdated(Events.DeviceUpdatedEventArgs e)
 {
     DeviceUpdated?.Invoke(this, e);
 }
コード例 #11
0
 internal Task InternalDeviceUpdatedAsync(Device before, Device after)
 {
     return(DeviceUpdated is null ? Task.CompletedTask : DeviceUpdated.Invoke(before, after));
 }
コード例 #12
0
ファイル: AbsDevice.cs プロジェクト: OldaHavelka/Reception
 protected virtual void OnDeviceUpdated(object source, EventArgs e)
 {
     DeviceUpdated?.Invoke(this, EventArgs.Empty);
 }
コード例 #13
0
 private void OnDeviceUpdated(DeviceWatcher sender, DeviceInformationUpdate args)
 {
     DeviceUpdated.Invoke(this, null);
     RaisePropertyChanged(new PropertyChangedEventArgs(nameof(RemoteDevices)));
 }