public MySlaveDataStore() { _holdingRegisters = new MyPointSource <ushort>(ushort.MaxValue); _inputRegisters = new MyPointSource <ushort>(ushort.MaxValue); _coilDiscretes = new MyPointSource <bool>(ushort.MaxValue); _coilInputs = new MyPointSource <bool>(ushort.MaxValue); }
public InputService( IPointSource pointSource, ITriggerSource keySelectionTriggerSource) { this.pointSource = pointSource; this.keySelectionTriggerSource = keySelectionTriggerSource; }
public KeyboardKeyDownUpSource( Enums.Keys triggerKey, IPointSource pointSource) { this.triggerKey = (System.Windows.Forms.Keys)triggerKey; //Cast to the Windows.Forms.Keys enum this.pointSource = pointSource; keyboardHookListener = new KeyboardHookListener(new GlobalHooker()) { Enabled = true }; System.Windows.Application.Current.Exit += (sender, args) => { keyboardHookListener.Dispose(); Log.Debug("Keyboard hook listener disposed."); }; /* * Keys: http://msdn.microsoft.com/en-GB/library/system.windows.forms.keys.aspx * KeyDown: happens when the person presses a key (when the keyboard first detects a finger on a key, this happens when the key is pressed down). * KeyPress: happens when a key is pressed and then released. * KeyUp: happens when the key is released */ }
public InputService( IKeyStateService keyStateService, IDictionaryService dictionaryService, IAudioService audioService, ICapturingStateManager capturingStateManager, IPointSource pointSource, ITriggerSource eyeGestureTriggerSource, ITriggerSource keySelectionTriggerSource, ITriggerSource pointSelectionTriggerSource) { this.keyStateService = keyStateService; this.dictionaryService = dictionaryService; this.audioService = audioService; this.capturingStateManager = capturingStateManager; this.pointSource = pointSource; this.eyeGestureTriggerSource = eyeGestureTriggerSource; this.keySelectionTriggerSource = keySelectionTriggerSource; this.pointSelectionTriggerSource = pointSelectionTriggerSource; //Fixation key triggers also need the enabled state info and override times if (keySelectionTriggerSource is IFixationTriggerSource fixationTrigger) { fixationTrigger.KeyEnabledStates = keyStateService.KeyEnabledStates; OverrideTimesByKey = fixationTrigger.OverrideTimesByKey; } }
public MainWindow( IAudioService audioService, IDictionaryService dictionaryService, IInputService inputService, IKeyStateService keyStateService) { InitializeComponent(); this.audioService = audioService; this.dictionaryService = dictionaryService; this.inputService = inputService; this.keyStateService = keyStateService; defaultPointSource = inputService.PointSource; manualModePointSource = new MousePositionSource(Settings.Default.PointTtl) { State = RunningStates.Paused }; managementWindowRequest = new InteractionRequest <NotificationWithServicesAndState>(); managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow); toggleManualModeCommand = new DelegateCommand(ToggleManualMode, () => !(defaultPointSource is MousePositionSource)); quitCommand = new DelegateCommand(Quit); backCommand = new DelegateCommand(Back); restartCommand = new DelegateCommand(Restart); //Setup key binding (Alt+M and Shift+Alt+M) to open settings InputBindings.Add(new KeyBinding { Command = managementWindowRequestCommand, Modifiers = ModifierKeys.Alt, Key = Key.M }); InputBindings.Add(new KeyBinding { Command = managementWindowRequestCommand, Modifiers = ModifierKeys.Shift | ModifierKeys.Alt, Key = Key.M }); //Setup key binding (Alt+Enter and Shift+Alt+Enter) to open settings InputBindings.Add(new KeyBinding { Command = toggleManualModeCommand, Modifiers = ModifierKeys.Alt, Key = Key.Enter }); InputBindings.Add(new KeyBinding { Command = toggleManualModeCommand, Modifiers = ModifierKeys.Shift | ModifierKeys.Alt, Key = Key.Enter }); Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion); //Set the window size to 0x0 as this prevents a flicker where OptiKey would be displayed in the default position and then repositioned Width = 0; Height = 0; }
public InputService( IKeyStateService keyStateService, IDictionaryService dictionaryService, IAudioService audioService, ICapturingStateManager capturingStateManager, IPointSource pointSource, ITriggerSource keySelectionTriggerSource, ITriggerSource pointSelectionTriggerSource) { this.keyStateService = keyStateService; this.dictionaryService = dictionaryService; this.audioService = audioService; this.capturingStateManager = capturingStateManager; this.pointSource = pointSource; this.keySelectionTriggerSource = keySelectionTriggerSource; this.pointSelectionTriggerSource = pointSelectionTriggerSource; //Fixation key triggers also need the enabled state info var fixationTrigger = keySelectionTriggerSource as IFixationTriggerSource; if (fixationTrigger != null) { fixationTrigger.KeyEnabledStates = keyStateService.KeyEnabledStates; } }
/// <summary> /// Fills a caller-allocated target with a specified number of values from a source /// </summary> /// <param name="src">The random source</param> /// <param name="count">The number of values to send to the target</param> /// <param name="dst">A reference to the target location</param> /// <typeparam name="T">The element type</typeparam> public static void StreamTo <T>(this IPointSource <T> src, int count, ref T dst) where T : struct { for (var i = 0; i < count; i++) { Unsafe.Add(ref dst, i) = src.Next(); } }
public static PointStream Instance(IPointSource source) { if (instance == null || source != instance._source) { instance = new PointStream(source); } return(instance); }
public MainWindow( IAudioService audioService, IDictionaryService dictionaryService, IInputService inputService, IKeyStateService keyStateService) { InitializeComponent(); this.audioService = audioService; this.dictionaryService = dictionaryService; this.inputService = inputService; this.keyStateService = keyStateService; defaultPointSource = inputService.PointSource; manualModePointSource = new MousePositionSource(Settings.Default.PointTtl) { State = RunningStates.Paused }; managementWindowRequest = new InteractionRequest <NotificationWithServicesAndState>(); managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow); toggleManualModeCommand = new DelegateCommand(ToggleManualMode); quitCommand = new DelegateCommand(Quit); //Setup key binding (Alt+M and Shift+Alt+M) to open settings InputBindings.Add(new KeyBinding { Command = managementWindowRequestCommand, Modifiers = ModifierKeys.Alt, Key = Key.M }); InputBindings.Add(new KeyBinding { Command = managementWindowRequestCommand, Modifiers = ModifierKeys.Shift | ModifierKeys.Alt, Key = Key.M }); //Setup key binding (Alt+Enter and Shift+Alt+Enter) to open settings InputBindings.Add(new KeyBinding { Command = toggleManualModeCommand, Modifiers = ModifierKeys.Alt, Key = Key.Enter }); InputBindings.Add(new KeyBinding { Command = toggleManualModeCommand, Modifiers = ModifierKeys.Shift | ModifierKeys.Alt, Key = Key.Enter }); Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion); }
public MouseButtonDownUpSource( Enums.MouseButtons triggerButton, IPointSource pointSource) { this.triggerButton = (System.Windows.Forms.MouseButtons)triggerButton; //Cast to the Windows.Forms.MouseButtons enum this.pointSource = pointSource; mouseHookListener = new MouseHookListener(new GlobalHooker()) { Enabled = true }; }
/// <summary> /// Produces a random stream of unfiltered/unbounded points from a source /// </summary> /// <param name="src">The random source</param> /// <typeparam name="T">The point type</typeparam> public static IRandomStream <T> Stream <T>(this IPointSource <T> src) where T : struct { IEnumerable <T> produce() { while (true) { yield return(src.Next()); } } return(stream(produce(), src.RngKind)); }
public PointFixationSource( TimeSpan lockOnTime, TimeSpan timeToCompleteTrigger, double lockOnRadius, double fixationRadius, IPointSource pointSource) { this.lockOnTime = lockOnTime; this.timeToCompleteTrigger = timeToCompleteTrigger; this.lockOnRadiusSquared = lockOnRadius * lockOnRadius; this.fixationRadiusSquared = fixationRadius * fixationRadius; this.pointSource = pointSource; }
public KeyFixationSource( TimeSpan lockOnTime, bool resumeRequiresLockOn, TimeSpan defaultTimeToCompleteTrigger, IDictionary <KeyValue, TimeSpan> timeToCompleteTriggerByKey, TimeSpan incompleteFixationTtl, IPointSource pointSource) { this.lockOnTime = lockOnTime; this.resumeRequiresLockOn = resumeRequiresLockOn; this.defaultTimeToCompleteTrigger = defaultTimeToCompleteTrigger; this.timeToCompleteTriggerByKey = timeToCompleteTriggerByKey ?? new Dictionary <KeyValue, TimeSpan>(); this.incompleteFixationTtl = incompleteFixationTtl; this.pointSource = pointSource; incompleteFixationProgress = new ConcurrentDictionary <KeyValue, long>(); incompleteFixationTimeouts = new ConcurrentDictionary <KeyValue, IDisposable>(); }
public MouseButtonDownUpSource( Enums.MouseButtons triggerButton, IPointSource pointSource) { this.triggerButton = (System.Windows.Forms.MouseButtons)triggerButton; //Cast to the Windows.Forms.MouseButtons enum this.pointSource = pointSource; mouseHookListener = new MouseHookListener(new GlobalHooker()) { Enabled = true }; System.Windows.Application.Current.Exit += (sender, args) => { mouseHookListener.Dispose(); Log.Debug("Mouse hook listener disposed."); }; }
protected OpTime Benchmark <T>(IPointSource <T> src, string opname = null) where T : struct { var last = default(T); var sw = stopwatch(); for (var cycle = 0; cycle < CycleCount; cycle++) { for (var i = 0; i < SampleSize; i++) { last = src.Next(); } } OpTime time = (CycleCount * SampleSize, sw, opname ?? $"{src.RngKind}<{type<T>().DisplayName()}>"); Collect(time); return(time); }
private static void DrawDensityMap(QuadTree tree, IPointSource source) { var extentRatio = (tree._maxX - tree._minX) / (tree._maxY - tree._minY); var maxDisplayDimension = 64; var width = maxDisplayDimension; var height = maxDisplayDimension; if (extentRatio > 1) { height = (int)(maxDisplayDimension / extentRatio); } else if (extentRatio < 1) { width = (int)(maxDisplayDimension * extentRatio); } var cells = new int[height, width]; var maxCellCount = 0; foreach (var point in source.Points()) { var x = (int)Math.Min((point.X - tree._minX) / (tree._maxX - tree._minX) * width, width - 1); var y = (int)Math.Min((point.Y - tree._minY) / (tree._maxY - tree._minY) * height, height - 1); cells[y, x]++; maxCellCount = Math.Max(maxCellCount, cells[y, x]); } var chars = new[] { '█', '▓', '▒', '░' }; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var value = cells[y, x] == 0 ? " " : chars[Math.Min(chars.Length * cells[y, x] / maxCellCount, chars.Length - 1)].ToString(); Console.Write($"{value}{value}"); } Console.WriteLine(); } }
public InputService( IKeyStateService keyStateService, IDictionaryService dictionaryService, IAudioService audioService, ICapturingStateManager capturingStateManager, IPointSource pointSource, ITriggerSource keySelectionTriggerSource, ITriggerSource pointSelectionTriggerSource) { this.keyStateService = keyStateService; this.dictionaryService = dictionaryService; this.audioService = audioService; this.capturingStateManager = capturingStateManager; this.pointSource = pointSource; this.keySelectionTriggerSource = keySelectionTriggerSource; this.pointSelectionTriggerSource = pointSelectionTriggerSource; //Fixation key triggers also need the enabled state info var fixationTrigger = keySelectionTriggerSource as IFixationTriggerSource; if (fixationTrigger != null) { fixationTrigger.KeyEnabledStates = keyStateService.KeyEnabledStates; } }
private PointStream(IPointSource source) { this._source = source; }
/// <summary> /// Samples a subsequence from a point source determined by successive sequence widths /// </summary> /// <param name="src">The point source</param> /// <param name="batchsize">The number of samples per batch</param> /// <param name="widths">The subsequence width markers</param> public static Span <(ulong count, T value)> SubSeq <T>(this IPointSource <T> src, int batchsize, ReadOnlySpan <ulong> widths)
public static IRandomStream <Bit> ToBitStream <T>(this IPointSource <T> src) where T : unmanaged => BitSource <T> .From(src);
public EyeGestureSource(IPointSource pointSource) { this.pointSource = pointSource; }
protected override async Task ServiceTaskAsync(CancellationToken cancellationToken) { ArcController?.NewLogMessage(LogCode.ModbusStarting); Logger.Info("begin"); var tcpListener = new TcpListener(IPAddress.Any, TcpPort); var rtuListener = new TcpListener(IPAddress.Any, RtuOverTcpPort); Logger.Info("starting listener"); tcpListener.Start(); rtuListener.Start(); Logger.Info("generating slave net"); var factory = new ModbusFactory(); var tcpNetwork = factory.CreateSlaveNetwork(tcpListener); var rtuNetwork = factory.CreateRtuOverTcpSlaveNetwork(rtuListener); var slaveTcp = factory.CreateSlave(1); var slaveRtu = factory.CreateSlave(1, slaveTcp.DataStore); tcpNetwork.AddSlave(slaveTcp); rtuNetwork.AddSlave(slaveRtu); iRegisters = slaveTcp.DataStore.InputRegisters; hRegisters = slaveTcp.DataStore.HoldingRegisters; WfqydbServer.PropertyChanged += Wf_PropertyChanged; var timeOfStart = DateTime.Now.ToUnixTimestamp(); ushort[] timeOfStartBuffer = { (ushort)(timeOfStart >> 16), (ushort)(timeOfStart), }; var ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; ushort[] verBuffer = { (ushort)ver.Major, (ushort)ver.Minor, (ushort)ver.Build, }; byte[] myAddress = { 0x01, 0x00, 0x00, 0x00, }; iRegisters.WritePoints(0, verBuffer); iRegisters.WritePoints(3, timeOfStartBuffer); Logger.Info("starting slave net. step1"); var tcpListenerTask = tcpNetwork.ListenAsync(cancellationToken); var rtuListenerTask = rtuNetwork.ListenAsync(cancellationToken); Logger.Info($"starting slave net. step2 {WfqydbServer.ToString()}"); ArcController?.NewLogMessage(LogCode.ModbusStarted); ArcController?.NewLogMessage(LogCode.WFQYDBConnecting); //await WfqydbServer.PullBroadcastQuery().ConfigureAwait(false); //WfqydbServer.PullBroadcastQuery(); ArcController?.NewLogMessage(LogCode.WFQYDBConnected); const int waitTime = 100; //ms const int faultRestTime = 10_000; //ms const int responseTime = 500; //ms var lastRequestTime = DateTime.Now; var lastResetTime = DateTime.Now; var resetInterval = TimeSpan.FromSeconds(30); var faultRestTimer = 0; Logger.Info("entering inf loop"); // Главный цикл до отмены этой задачи. while (!cancellationToken.IsCancellationRequested) { try { // состояние связи iRegisters.WritePoints(5, new ushort[] { (ushort)WfqydbServer.ConnectionState }); // Habdle var buff = hRegisters.ReadPoints(10, 5); var cmd = buff[0]; var cmdState = buff[1]; if ((buff[2] + buff[3]) == 0) { // Чтобы не было пустого места на элкамрм hRegisters.WritePoints(12, new ushort[] { currentData[3], currentData[4], currentData[6] }); } // обработка команд по модбас if ((cmd > 0) && (cmdState == (ushort)CmdState.Rdy)) { var upFreq = (byte)buff[2]; var dnFreq = (byte)buff[3]; var stokeRate = (byte)buff[4]; hRegisters.WritePoints(10, new ushort[] { cmd, (ushort)CmdState.Working }); try { switch ((Cmd)cmd) { case Cmd.Reset: cmd = 0; cmdState = 0; hRegisters.WritePoints(10, new ushort[] { (ushort)Cmd.NoOp, (ushort)CmdState.Rdy }); break; case Cmd.BroadcastQuery: lastRequestTime = DateTime.Now; //await WfqydbServer.PullBroadcastQuery().ConfigureAwait(false); WfqydbServer.PullBroadcastQuery(); hRegisters.WritePoints(10, new ushort[] { (ushort)Cmd.NoOp, (ushort)CmdState.Rdy }); ArcController?.NewLogMessage(LogCode.WFQYDBCmdRead); break; case Cmd.AutoRun: lastRequestTime = DateTime.Now; //await WfqydbServer.PullAutoRun(upFreq, dnFreq, stokeRate).ConfigureAwait(false); WfqydbServer.PullAutoRun(upFreq, dnFreq, stokeRate); hRegisters.WritePoints(10, new ushort[] { (ushort)Cmd.NoOp, (ushort)CmdState.Rdy }); ArcController?.NewLogMessage(LogCode.WFQYDBCmdCtart, $"u:{upFreq}, d:{dnFreq}, sr:{stokeRate}"); break; case Cmd.Shutdown: lastRequestTime = DateTime.Now; //await WfqydbServer.PullShutdown().ConfigureAwait(false); WfqydbServer.PullShutdown(); hRegisters.WritePoints(10, new ushort[] { (ushort)Cmd.NoOp, (ushort)CmdState.Rdy }); ArcController?.NewLogMessage(LogCode.WFQYDBCmdCtop); break; case Cmd.ThrowException: throw new Exception("Test exception"); default: hRegisters.WritePoints(10, new ushort[] { cmd, (ushort)CmdState.NotImplementedCmd }); faultRestTimer = faultRestTime; break; } } catch (Exception ex) { hRegisters.WritePoints(10, new ushort[] { cmd, (ushort)CmdState.CommonError }); faultRestTimer = faultRestTime; FireOnError(ex); Logger.Alarm(ex.Message); ArcController?.NewLogMessage(LogCode.ModbusFailed); } } if (cmdState != (ushort)CmdState.Rdy) { if ((faultRestTimer -= waitTime) <= 0) { hRegisters.WritePoints(10, new ushort[] { (ushort)Cmd.NoOp, (ushort)CmdState.Rdy }); } } await Task.Delay(waitTime, cancellationToken).ConfigureAwait(false); // передернем сеть rtu. Так как она периодически подвисает. //var lastResetTime = DateTime.Now; //var resetInterval = TimeSpan.FromSeconds(30); if ((lastResetTime + resetInterval) < DateTime.Now) { lastResetTime = DateTime.Now; Logger.Info("restarting rtu"); //var rtuListener = new TcpListener(IPAddress.Any, RtuOverTcpPort); rtuListener.Stop(); rtuListener.Start(); // var rtuNetwork = factory.CreateRtuOverTcpSlaveNetwork(rtuListener); // var slaveRtu = factory.CreateSlave(1, slaveTcp.DataStore); // rtuNetwork.AddSlave(slaveRtu); // var rtuListenerTask = rtuNetwork.ListenAsync(cancellationToken); } } catch (Exception ex) { FireOnError(ex); Logger.Alarm(ex.Message); ArcController?.NewLogMessage(LogCode.ModbusFailed); await Task.Delay(waitTime, cancellationToken).ConfigureAwait(false); } }// while tcpListener.Stop(); rtuListener.Stop(); tcpNetwork.Dispose(); rtuNetwork.Dispose(); await tcpListenerTask.ConfigureAwait(true); await rtuListenerTask.ConfigureAwait(true); }
public BitSource(IPointSource <T> random) { this.RngKind = random.RngKind; this.Stream = random.Stream().GetEnumerator().ToBitStream(); this.BitQueue = new Queue <Bit>(BufferSize); }
public MainWindow( IAudioService audioService, IDictionaryService dictionaryService, IInputService inputService, IKeyStateService keyStateService) { InitializeComponent(); this.audioService = audioService; this.dictionaryService = dictionaryService; this.inputService = inputService; this.keyStateService = keyStateService; defaultPointSource = inputService.PointSource; manualModePointSource = new MousePositionSource(Settings.Default.PointTtl) { State = RunningStates.Paused }; managementWindowRequest = new InteractionRequest <NotificationWithServicesAndState>(); managementWindowRequestCommand = new DelegateCommand(RequestManagementWindow); toggleManualModeCommand = new DelegateCommand(ToggleManualMode, () => !(defaultPointSource is MousePositionSource)); quitCommand = new DelegateCommand(Quit); backCommand = new DelegateCommand(Back); restartCommand = new DelegateCommand(Restart); //Setup key binding (Alt+M and Shift+Alt+M) to open settings InputBindings.Add(new KeyBinding { Command = managementWindowRequestCommand, Modifiers = ModifierKeys.Alt, Key = Key.M }); InputBindings.Add(new KeyBinding { Command = managementWindowRequestCommand, Modifiers = ModifierKeys.Shift | ModifierKeys.Alt, Key = Key.M }); //Setup key binding (Alt+Enter and Shift+Alt+Enter) to open settings InputBindings.Add(new KeyBinding { Command = toggleManualModeCommand, Modifiers = ModifierKeys.Alt, Key = Key.Enter }); InputBindings.Add(new KeyBinding { Command = toggleManualModeCommand, Modifiers = ModifierKeys.Shift | ModifierKeys.Alt, Key = Key.Enter }); Title = string.Format(Properties.Resources.WINDOW_TITLE, DiagnosticInfo.AssemblyVersion); //Set the window size to 0x0 as this prevents a flicker where OptiKey would be displayed in the default position and then repositioned Width = 0; Height = 0; this.Closing += (sender, args) => { //https://stackoverflow.com/questions/26863458/handle-the-close-event-via-task-bar Log.Info("Main window closing event detected. In some circumstances, such as closing OptiKey from the taskbar when a background thread is running, OptiKey will not close and instead become a background process. Forcing a full shutdown."); Application.Current.Shutdown(); }; }
public static IRandomStream <Bit> From(IPointSource <T> src) => new BitSource <T>(src);