private void SendKeyStrokes(DeviceIdentifier deviceIdentifier, IEnumerable <KeyStroke> keyStrokes, KeyStroke[] receiveKeyStrokes)
        {
            foreach (var keyStroke in keyStrokes)
            {
                if (keyStroke.Code == KeyStroke.SleepCode)
                {
                    var time = keyStroke.Information;
                    __logger.Debug("Sleep for " + time + " milliseconds");
                    Thread.Sleep((int)time);
                }
                else if (keyStroke.Code == KeyStroke.ForwardCode)
                {
                    __logger.Debug("Begin forwarding...");
                    SendKeyStrokes(deviceIdentifier, keyStroke.BuildForwardKeyStrokes(receiveKeyStrokes), null);
                    __logger.Debug("End forwarding.");
                }
                else
                {
                    __logger.Debug("Sending code={0}, state={1}", keyStroke.Code, keyStroke.State);
                    _sendingKeystrokes[0] = keyStroke;
                    _context.Send(deviceIdentifier, _sendingKeystrokes, 1);

                    Thread.Sleep(_keyStrokeTimeMilliseconds);
                }
            }
        }
Beispiel #2
0
        public InputDevice(IDriver driver, IDeviceEndpoint device, TabletConfiguration configuration, DeviceIdentifier identifier)
            : base(device, driver.GetReportParser(identifier))
        {
            if (driver == null || device == null || configuration == null || identifier == null)
            {
                string argumentName = driver == null?nameof(driver) :
                                          device == null?nameof(device) :
                                              configuration == null?nameof(configuration) :
                                                  nameof(identifier);

                throw new ArgumentNullException(argumentName);
            }

            Endpoint      = device;
            Configuration = configuration;
            Identifier    = identifier;

            if (Configuration.Attributes.TryGetValue(DELAY_ATTRIBUTE_KEY_NAME, out var delayStr))
            {
                if (!uint.TryParse(delayStr, out _featureInitDelayMs))
                {
                    Log.Write("Device", $"Could not parse '{delayStr}' from attribute {DELAY_ATTRIBUTE_KEY_NAME}", LogLevel.Warning);
                }
            }

            Start();
        }
Beispiel #3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasFeatureIdentifier)
            {
                hash ^= FeatureIdentifier.GetHashCode();
            }
            if (HasFeatureVersion)
            {
                hash ^= FeatureVersion.GetHashCode();
            }
            if (HasViewUri)
            {
                hash ^= ViewUri.GetHashCode();
            }
            if (HasExternalReferrer)
            {
                hash ^= ExternalReferrer.GetHashCode();
            }
            if (HasReferrerIdentifier)
            {
                hash ^= ReferrerIdentifier.GetHashCode();
            }
            if (HasDeviceIdentifier)
            {
                hash ^= DeviceIdentifier.GetHashCode();
            }
            hash ^= featureClasses_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #4
0
        public async Task HandleCommand(DeviceIdentifier deviceIdentifier, double value, ePairControlUse control)
        {
            if (deviceIdentifier.DeviceId != Device.Id)
            {
                throw new ArgumentException("Invalid Device Identifier");
            }

            // This function runs in separate thread than main run

            MPowerConnector connectorCopy;
            await rootDeviceDataLock.WaitAsync(Token);

            try
            {
                connectorCopy = connector;
                if (connectorCopy == null)
                {
                    throw new HspiException(Invariant($"No connection to Device for {Device.DeviceIP}"));
                }
                await rootDeviceData.HandleCommand(deviceIdentifier, Token, connectorCopy, value, control);
            }
            finally
            {
                rootDeviceDataLock.Release();
            }

            await connectorCopy.UpdateAllSensorData(Token);
        }
        public void Configurations_DeviceIdentifier_NonEquality_DeviceStrings_SelfTest()
        {
            var identifier = new DeviceIdentifier
            {
                VendorID      = 1,
                ProductID     = 1,
                DeviceStrings = new Dictionary <byte, string>
                {
                    [1] = "Test"
                },
                InputReportLength  = 1,
                OutputReportLength = 1
            };
            var otherIdentifier = new DeviceIdentifier
            {
                VendorID      = 1,
                ProductID     = 1,
                DeviceStrings = new Dictionary <byte, string>
                {
                    [1] = "Test",
                    [2] = "Test2"
                },
                InputReportLength  = 1,
                OutputReportLength = 1
            };

            var equality = IsEqual(identifier, otherIdentifier, new DeviceStringsComparer());

            Assert.False(equality);
        }
        private NameValueCollection GetCurrentDeviceImportDevices()
        {
            HSHelper hsHelper         = new HSHelper(HS);
            var      deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration;

            var currentDevices    = new NameValueCollection();
            var importDevicesData = pluginConfig.ImportDevicesData;

            do
            {
                DeviceClass device = deviceEnumerator.GetNext();
                if ((device != null) &&
                    (device.get_Interface(HS) != null) &&
                    (device.get_Interface(HS).Trim() == PlugInData.PlugInName))
                {
                    string address = device.get_Address(HS);

                    var childDeviceData = DeviceIdentifier.Identify(device);
                    if (childDeviceData != null)
                    {
                        if (pluginConfig.ImportDevicesData.TryGetValue(childDeviceData.DeviceId, out var importDeviceData))
                        {
                            currentDevices.Add(device.get_Ref(HS).ToString(CultureInfo.CurrentCulture), hsHelper.GetName(device));
                        }
                    }
                }
            } while (!deviceEnumerator.Finished);

            return(currentDevices);
        }
Beispiel #7
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                var deviceClass = (DeviceClass)HS.GetDeviceByRef(deviceId);

                if (deviceClass.get_Interface(HS) == PlugInData.PlugInName)
                {
                    var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);
                    if (deviceIdentifier != null)
                    {
                        return(configPage.GetDeviceImportTab(deviceIdentifier));
                    }
                }
                else
                {
                    return(configPage.GetDeviceHistoryTab(deviceId));
                }
                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
        public string GetDeviceImportTab(DeviceIdentifier deviceIdentifier)
        {
            foreach (var device in pluginConfig.ImportDevicesData)
            {
                if (device.Key == deviceIdentifier.DeviceId)
                {
                    StringBuilder stb = new StringBuilder();

                    stb.Append(@"<table style='width:100%;border-spacing:0px;'");
                    stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
                    stb.Append(Invariant($"<tr><td class='tableheader' colspan=3>Import Settings</td></tr>"));
                    stb.Append(Invariant($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>{HtmlEncode(device.Value.Name)}</td></tr>"));
                    stb.Append(Invariant($"<tr><td class='tablecell'>Sql:</td><td class='tablecell' colspan=2>{HtmlEncode(device.Value.Sql)}</td></tr>"));
                    stb.Append(Invariant($"<tr><td class='tablecell'>Refresh Interval(seconds):</td><td class='tablecell' colspan=2>{HtmlEncode(device.Value.Interval.TotalSeconds)}</td></tr>"));
                    stb.Append(Invariant($"<tr><td class='tablecell'>Unit:</td><td class='tablecell' colspan=2>{HtmlEncode(device.Value.Unit)}</td></tr>"));
                    stb.Append(Invariant($"</td><td></td></tr>"));
                    stb.Append("<tr height='5'><td colspan=3></td></tr>");
                    stb.Append("<tr><td colspan=3>");
                    stb.Append(PageTypeButton(Invariant($"Edit{device.Value.Id}"), "Edit", EditDeviceImportPageType, id: device.Value.Id));
                    stb.Append("</td></tr>");
                    stb.Append(@" </table>");

                    return(stb.ToString());
                }
            }

            return(string.Empty);
        }
Beispiel #9
0
        public override void SetIOMulti(List <CAPI.CAPIControl> colSend)
        {
            foreach (var control in colSend)
            {
                try
                {
                    int         refId       = control.Ref;
                    DeviceClass deviceClass = (DeviceClass)HS.GetDeviceByRef(refId);

                    var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                    lock (connectorManagerLock)
                    {
                        if (connectorManager.TryGetValue(deviceIdentifier.DeviceId, out var connector))
                        {
                            connector.HandleCommand(deviceIdentifier, control.ControlValue, control.ControlUse).Wait();
                        }
                        else
                        {
                            throw new HspiException(Invariant($"{refId} Device Not Found for processing."));
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogError(Invariant($"Failed With {ExceptionHelper.GetFullMessage(ex)}"));
                }
            }
        }
 protected EnumeratableDevice(UID uid, DeviceIdentifier deviceIdentifier)
 {
     UID = uid;
     DeviceIdentifier = deviceIdentifier;
     Position = 'a'; //TODO: better default depending on brick/bricklet?
     ConnectedUID = new UID(0);
     HardwareVersion = new Version(1, 0, 0);
     FirmwareVersion = new Version(1, 0, 0);
 }
        private bool IsEqual(DeviceIdentifier a, DeviceIdentifier b, DeviceStringsComparer comparerInstance)
        {
            var pidMatch    = a.VendorID == b.VendorID && a.ProductID == b.ProductID;
            var stringMatch = !a.DeviceStrings.Any() || !b.DeviceStrings.Any() || a.DeviceStrings.SequenceEqual(b.DeviceStrings, comparerInstance);
            var inputMatch  = a.InputReportLength == b.InputReportLength || a.InputReportLength is null || b.InputReportLength is null;
            var outputMatch = a.OutputReportLength == b.OutputReportLength || a.OutputReportLength is null || b.OutputReportLength is null;

            return(pidMatch && stringMatch && inputMatch && outputMatch);
        }
 protected EnumeratableDevice(UID uid, DeviceIdentifier deviceIdentifier)
 {
     UID = uid;
     DeviceIdentifier = deviceIdentifier;
     Position         = 'a'; //TODO: better default depending on brick/bricklet?
     ConnectedUID     = new UID(0);
     HardwareVersion  = new Version(1, 0, 0);
     FirmwareVersion  = new Version(1, 0, 0);
 }
Beispiel #13
0
        public async Task HandleCommand(DeviceIdentifier deviceIdentifier, string stringValue, double value, ePairControlUse control)
        {
            if (deviceIdentifier.CameraId != CameraSettings.Id)
            {
                throw new ArgumentException("Invalid Device Identifier", nameof(deviceIdentifier));
            }

            await rootDeviceData.HandleCommand(deviceIdentifier, camera, stringValue, value, control).ConfigureAwait(false);
        }
 public TabletStatus(
     TabletConfiguration tabletProperties,
     DigitizerIdentifier tabletIdentifier,
     DeviceIdentifier auxiliaryIdentifier
     )
 {
     TabletProperties    = tabletProperties;
     TabletIdentifier    = tabletIdentifier;
     AuxiliaryIdentifier = auxiliaryIdentifier;
 }
Beispiel #15
0
 public TabletState(
     TabletConfiguration tabletProperties,
     DigitizerIdentifier digitizer,
     DeviceIdentifier auxiliary
     )
 {
     TabletProperties = tabletProperties;
     Digitizer        = digitizer;
     Auxiliary        = auxiliary;
 }
Beispiel #16
0
        internal DeviceInformation(DeviceIdentifier deviceIdentifier, Dictionary <string, object> properties)
        {
            if (deviceIdentifier is null)
            {
                throw new ArgumentNullException(nameof(deviceIdentifier));
            }

            Id         = deviceIdentifier.ToString();
            Properties = properties;
        }
Beispiel #17
0
 public DeviceManager(PlayerConfiguration playerConfiguration, string musicServerUrl, DeviceIdentifier identifier,
                      Broadcaster broadcaster, ILoggerFactory lf)
 {
     this.playerConfiguration = playerConfiguration;
     this.musicServerUrl      = musicServerUrl;
     this.loggerFactory       = lf;
     this.log         = loggerFactory.CreateLogger <DeviceManager>();
     this.identifier  = identifier;
     this.broadcaster = broadcaster;
     log.Information($"player configuration: {playerConfiguration.ToJson()}");
 }
Beispiel #18
0
        private static async Task <MidiInPort> FromIdInternalAsync(DeviceIdentifier identifier)
        {
            if (!await WasmMidiAccess.RequestAsync())
            {
                throw new UnauthorizedAccessException("User declined access to MIDI.");
            }
            var managedId      = Guid.NewGuid().ToString();
            var initialization = $"{JsType}.createPort('{managedId}','{Uri.EscapeDataString(identifier.Id)}')";

            WebAssemblyRuntime.InvokeJS(initialization);
            return(new MidiInPort(identifier.ToString(), managedId));
        }
 /// <summary>
 /// Returns a string representation of the object
 /// </summary>
 /// <returns>The string representation</returns>
 public override string ToString()
 {
     return
         (DeviceIdentifier.ToString() +
          (DeviceIdentifier.HasValue ? "." : string.Empty) +
          (ObjectType)ObjectIdentifier.Type +
          ObjectIdentifier.Instance +
          "." +
          PropertyIdentifier +
          (PropertyArrayIndex.HasValue ? "[" : string.Empty) +
          PropertyArrayIndex.ToString() +
          (PropertyArrayIndex.HasValue ? "]" : string.Empty));
 }
Beispiel #20
0
        private static async Task <MidiInPort> FromIdInternalAsync(DeviceIdentifier identifier)
        {
            var provider         = new MidiInDeviceClassProvider();
            var nativeDeviceInfo = provider.GetNativeEndpoint(identifier.Id);

            if (nativeDeviceInfo == null)
            {
                throw new InvalidOperationException(
                          "Given MIDI out device does not exist or is no longer connected");
            }

            return(new MidiInPort(identifier.ToString(), nativeDeviceInfo));
        }
Beispiel #21
0
        private static async Task <IMidiOutPort> FromIdInternalAsync(DeviceIdentifier identifier)
        {
            var provider         = new MidiOutDeviceClassProvider();
            var nativeDeviceInfo = provider.GetNativeDeviceInfo(identifier.Id);

            if (nativeDeviceInfo == (null, null))
            {
                throw new InvalidOperationException("Given MIDI out device does not exist");
            }

            var port = new MidiOutPort(identifier.ToString(), nativeDeviceInfo.device, nativeDeviceInfo.port);
            await port.OpenAsync();

            return(port);
        }
Beispiel #22
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                var deviceClass      = (DeviceClass)HS.GetDeviceByRef(deviceId);
                var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                if (deviceIdentifier != null)
                {
                    foreach (var camera in pluginConfig.HikvisionIsapiCameras)
                    {
                        if (camera.Key == deviceIdentifier.CameraId)
                        {
                            StringBuilder stb = new StringBuilder();

                            stb.Append(@"<table style='width:100%;border-spacing:0px;'");
                            stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
                            stb.Append($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>");
                            stb.Append(PageHelper.HtmlEncode(camera.Value.Name));
                            stb.Append("</td></tr>");
                            stb.Append($"<tr><td class='tablecell'>Uri:</td><td class='tablecell' colspan=2>");
                            stb.Append(Invariant($"<a href=\"{PageHelper.HtmlEncode(camera.Value.CameraHost)}\" target=\"_blank\">{PageHelper.HtmlEncode(camera.Value.CameraHost)}</a>"));
                            stb.Append("</td></tr>");
                            stb.Append($"<tr><td class='tablecell'>Type:</td><td class='tablecell' colspan=2>");
                            stb.Append(PageHelper.HtmlEncode(deviceIdentifier.DeviceType));
                            stb.Append("</td></tr>");
                            stb.Append(Invariant($"</td><td></td></tr>"));
                            stb.Append("<tr height='5'><td colspan=3></td></tr>");
                            stb.Append(@" </table>");

                            return(stb.ToString());
                        }
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (DeviceIdentifier.Length != 0)
            {
                hash ^= DeviceIdentifier.GetHashCode();
            }
            hash ^= subscribeTopics_.GetHashCode();
            hash ^= unsubscribeTopics_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #24
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                DeviceClass deviceClass      = (DeviceClass)HS.GetDeviceByRef(deviceId);
                var         deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                if (deviceIdentifier != null)
                {
                    foreach (var device in pluginConfig.Devices)
                    {
                        if (device.Key == deviceIdentifier.DeviceId)
                        {
                            StringBuilder stb = new StringBuilder();

                            stb.Append(@"<table style='width:100%;border-spacing:0px;'");
                            stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
                            stb.Append(Invariant($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>{ConfigPage.HtmlEncode(device.Value.Name)}</td></tr>"));
                            stb.Append(Invariant($"<tr><td class='tablecell'>Device IP:</td><td class='tablecell' colspan=2>{ConfigPage.HtmlEncode(device.Value.DeviceIP)}</td></tr>"));
                            stb.Append(Invariant($"<tr><td class='tablecell'>Port:</td><td class='tablecell' colspan=2>{ConfigPage.HtmlEncode(deviceIdentifier.Port)}</td></tr>"));
                            stb.Append(Invariant($"<tr><td class='tablecell'>Type:</td><td class='tablecell' colspan=2>{EnumHelper.GetDescription(deviceIdentifier.DeviceType)}</td></tr>"));
                            stb.Append(Invariant($"</td><td></td></tr>"));
                            stb.Append("<tr height='5'><td colspan=3></td></tr>");
                            stb.Append(@" </table>");

                            return(stb.ToString());
                        }
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
Beispiel #25
0
        private static DeviceIdentifier ValidateAndParseDeviceId(string deviceId)
        {
            if (deviceId is null)
            {
                throw new ArgumentNullException(nameof(deviceId));
            }

            if (!DeviceIdentifier.TryParse(deviceId, out var deviceIdentifier))
            {
                throw new ArgumentException("Device identifier is not valid", nameof(deviceId));
            }

            if (deviceIdentifier.DeviceClass != DeviceClassGuids.MidiIn)
            {
                throw new InvalidOperationException("Given device is not a MIDI in device");
            }

            return(deviceIdentifier);
        }
 public void StopDeviceAsync(DeviceIdentifier identifier)
 {
     if (managers.ContainsKey(identifier))
     {
         var dm = managers[identifier];
         dm.Stop();
         managers.Remove(identifier);
         if (managers.Count() == 0)
         {
             var broadcaster = this.schedulerService.GetRealtimeTask <Broadcaster>();
             broadcaster.SetWebPlayerBroadcastIntervalShort();
         }
         log.Debug($"{dm.GetType().Name} stopped");
     }
     else
     {
         log.Debug($"Device Manager for {identifier.DeviceName} not found");
     }
 }
Beispiel #27
0
        public InputDevice(IDriver driver, IDeviceEndpoint device, TabletConfiguration configuration, DeviceIdentifier identifier)
            : base(device, driver.GetReportParser(identifier))
        {
            if (driver == null || device == null || configuration == null || identifier == null)
            {
                string argumentName = driver == null?nameof(driver) :
                                          device == null?nameof(device) :
                                              configuration == null?nameof(configuration) :
                                                  nameof(identifier);

                throw new ArgumentNullException(argumentName);
            }

            Endpoint      = device;
            Configuration = configuration;
            Identifier    = identifier;

            Start();
        }
        public async Task <DeviceManager> GetManagerAsync(DeviceIdentifier identifier)
        {
            if (!string.IsNullOrWhiteSpace(musicServerUrl))
            {
                if (!managers.ContainsKey(identifier))
                {
                    DeviceManager dm          = null;
                    var           broadcaster = this.schedulerService.GetRealtimeTask <Broadcaster>();
                    switch (identifier.Type)
                    {
                    //case AudioDeviceType.Asio:
                    //    dm = new AsioManager(musicServerUrl, identifier, lf.CreateLogger<AsioManager>());
                    //    break;
                    //case AudioDeviceType.DirectSoundOut:
                    //    dm = new DirectSoundManager(musicServerUrl, identifier, lf.CreateLogger<DirectSoundManager>());
                    //    break;
                    case AudioDeviceType.Wasapi:
                        dm = new WasapiManager(playerConfiguration, musicServerUrl, identifier, broadcaster, loggerFactory);
                        break;
                        //case AudioDeviceType.Logitech:
                        //    dm = new LogitechManager(musicServerUrl, identifier, lf.CreateLogger<LogitechManager>());
                        //    break;
                    }
                    dm.LocalStore = Path.Combine(env.ContentRootPath, "music.cache");
                    if (!Directory.Exists(dm.LocalStore))
                    {
                        Directory.CreateDirectory(dm.LocalStore);
                    }
                    await dm.StartAsync();

                    managers.Add(identifier, dm);
                    broadcaster.SetWebPlayerBroadcastIntervalLong();
                    log.Debug($"{dm.GetType().Name} started");
                }
                return(managers[identifier]);
            }
            else
            {
                log.Warning($"cannot access any device managers without a music server url");
                return(null);
            }
        }
        public void Configurations_DeviceIdentifier_Equality_NullOutput_SelfTest()
        {
            var identifier = new DeviceIdentifier
            {
                VendorID           = 1,
                ProductID          = 1,
                InputReportLength  = 1,
                OutputReportLength = 1
            };
            var otherIdentifier = new DeviceIdentifier
            {
                VendorID           = 1,
                ProductID          = 1,
                InputReportLength  = 1,
                OutputReportLength = null
            };

            var equality = IsEqual(identifier, otherIdentifier, new DeviceStringsComparer());

            Assert.True(equality);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (DeviceIdentifier.Length != 0)
            {
                hash ^= DeviceIdentifier.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDataRecord)
            {
                hash ^= TopicDataRecord.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Error)
            {
                hash ^= Error.GetHashCode();
            }
            hash ^= (int)typeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #31
0
 public virtual IReportParser <IDeviceReport> GetReportParser(DeviceIdentifier identifier)
 {
     return(reportParserDict[identifier.ReportParser].Invoke());
 }
 public ScanResult(DeviceIdentifier deviceIdentifier, long rssi, int txPower)
 {
     DeviceIdentifier = deviceIdentifier;
     Rssi = rssi;
     TxPower = txPower;
 }
 public EnrichedData(DeviceIdentifier deviceIdentifier, double distance)
 {
     DeviceIdentifier = deviceIdentifier;
     Distance = distance;
 }