Esempio n. 1
0
 public virtual void OnStatusReceived(BeaconStatusEventArgs statusEventArgs)
 {
     if (StatusReceived != null)
     {
         StatusReceived.Invoke(this, statusEventArgs);
     }
 }
Esempio n. 2
0
        public HapticPlayer(Action <bool> connectionChanged, bool tryReconnect = true)
        {
            _sender = new WebSocketSender();
            _sender.StatusReceived += feedback =>
            {
                StatusReceived?.Invoke(feedback);

                lock (_activeKeys)
                {
                    _activeKeys.Clear();
                    _activeKeys.AddRange(feedback.ActiveKeys);
                }

                lock (_activePosition)
                {
                    _activePosition.Clear();
                    _activePosition.AddRange(feedback.ConnectedPositions);
                }
            };
            _sender.ConnectionChanged += (isConn) =>
            {
                connectionChanged?.Invoke(isConn);
            };
            _sender.Initialize(tryReconnect);
        }
Esempio n. 3
0
        //
        // Driver service data received
        //
        private void ProcessService_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data == null)
            {
                if (running)
                {
                    Stop();
                }
            }
            else
            {
                string line = e.Data;

                // Status line?
                if (line.Contains("[STATUS]"))
                {
                    // Parse status variable and value
                    Match match = Regex.Match(line, "^.+\\[STATUS\\] ([^ ]+) (.*?)$");
                    if (!match.Success)
                    {
                        return;
                    }

                    string variableName = match.Groups[1].ToString().ToLower();
                    string parameters   = match.Groups[2].ToString();

                    //
                    // Commands status message
                    //
                    if (variableName == "commands")
                    {
                        string[] commandNames = parameters.Split(' ');
                        string   lowerCaseName;
                        foreach (string name in commandNames)
                        {
                            lowerCaseName = name.Trim().ToLower();
                            if (lowerCaseName.Length > 0)
                            {
                                if (!commands.ContainsKey(lowerCaseName))
                                {
                                    commands.Add(lowerCaseName, name);
                                }
                            }
                        }
                    }

                    StatusReceived?.Invoke(this, new DriverEventArgs(DriverEventType.Status, variableName, parameters));
                }


                ConsoleAddText(e.Data);
                MessageReceived?.Invoke(this, new DriverEventArgs(DriverEventType.Message, e.Data, ""));
            }
        }
        private void MessageReceived(object o, MessageEventArgs args)
        {
            if (!_enable)
            {
                return;
            }
            var msg = args.Data;

            var response = PlayerResponse.ToObject(msg);

            StatusReceived?.Invoke(response);
        }
Esempio n. 5
0
        private async void Connect()
        {
            try
            {
                if (messageWebSocket == null)
                {
                    messageWebSocket = new MessageWebSocket();
                    messageWebSocket.Control.MessageType = SocketMessageType.Utf8;
                    messageWebSocket.MessageReceived    += (sender, args) =>
                    {
                        using (DataReader reader = args.GetDataReader())
                        {
                            reader.UnicodeEncoding = UnicodeEncoding.Utf8;

                            try
                            {
                                string read     = reader.ReadString(reader.UnconsumedBufferLength);
                                var    response = PlayerResponse.ToObject(read);
                                StatusReceived?.Invoke(response);
                            }
                            catch (Exception ex)
                            {
                                LogReceived?.Invoke(ex.Message);
                            }
                        }
                    };
                    messageWebSocket.Closed += (sender, args) =>
                    {
                        _websocketConnected = false;
                        ConnectionChanged?.Invoke(_websocketConnected);
                    };
                }

                await messageWebSocket.ConnectAsync(new Uri(WebsocketUrl));

                messageWriter = new DataWriter(messageWebSocket.OutputStream);

                _websocketConnected = true;
                ConnectionChanged?.Invoke(_websocketConnected);
                AddRegister(_registered);
            }
            catch (Exception)
            {
                _websocketConnected = false;
                ConnectionChanged?.Invoke(_websocketConnected);
                await Task.CompletedTask;
            }
        }
Esempio n. 6
0
        public async void Run()
        {
            IsRunning = true;

            await Task.Run(async() =>
            {
                while (IsRunning)
                {
                    try
                    {
                        string response = await conn.WaitForResponse();
                        Tuple <string[], PacketType> packet = packetHandler.HandlePacket(response);

                        switch (packet.Item2)
                        {
                        case PacketType.Status:
                            StatusReceived?.Invoke(new StatusArgs(packet.Item1[1]));
                            break;

                        case PacketType.SyncData:
                            SyncDataReceived?.Invoke(new SyncDataArgs(packet.Item1));
                            break;

                        case PacketType.Heart:
                            HeartReceived?.Invoke(new HeartArgs(packet.Item1[1]));
                            break;

                        case PacketType.ClientDisconnect:
                            ClientDisconnectReceived?.Invoke(new EventArgs());
                            break;

                        case PacketType.Broadcast:
                            BroadcastReceived?.Invoke(new BroadcastArgs(packet.Item1[1]));
                            break;

                        case PacketType.Message:
                            MessageReceived?.Invoke(new MessageArgs(packet.Item1[1]));
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        IsRunning = false;
                    }
                }
            });
        }
Esempio n. 7
0
        //
        // Process driver message line
        //
        private void ProcessDriverMessageLine(string line)
        {
            //ConsoleAddLine("Message line: '" + line + "'");

            // Status line?
            if (line.Contains("[STATUS]"))
            {
                // Parse status variable and value
                Match match = Regex.Match(line, "^.+\\[STATUS\\] ([^ ]+) (.*?)$");
                if (match.Success)
                {
                    string variableName = match.Groups[1].ToString().ToLower();
                    string parameters   = match.Groups[2].ToString();

                    //
                    // Commands status message
                    //
                    if (variableName == "commands")
                    {
                        string[] commandNames = parameters.Split(' ');
                        string   lowerCaseName;
                        foreach (string name in commandNames)
                        {
                            lowerCaseName = name.Trim().ToLower();
                            if (lowerCaseName.Length > 0)
                            {
                                if (!commands.ContainsKey(lowerCaseName))
                                {
                                    commands.Add(lowerCaseName, name);
                                }
                            }
                        }
                    }

                    StatusReceived?.Invoke(this, new DriverEventArgs(DriverEventType.Status, variableName, parameters));
                }
            }

            ConsoleAddLine(line);
            MessageReceived?.Invoke(this, new DriverEventArgs(DriverEventType.Message, line, ""));
        }
Esempio n. 8
0
        public ConnService(HubConnection connection)
        {
            this._connection = connection;

            /* All signalR responses are received here and respective action invoke*/

            _connection.On <StatusModel>("ReceiveStatus", (status) => StatusReceived?.Invoke(status));
            _connection.On <Sender>("UpdateAlerts", (sender) => HandleEventReceived?.Invoke(sender));
            _connection.On <CasesModel>("AlertBroadcast", (sender) => AlertReceived?.Invoke(sender));
            _connection.On <string, string, string>("SMSSendingSuccess", (Sid, view, agent) => SendingSuccess?.Invoke(Sid, view, agent));
            _connection.On <string, string>("SMSResponseSuccess", (Sid, response) => ResponseSuccess?.Invoke(Sid, response));
            _connection.On <string>("NewUserConnected", (id) => NewUserSync?.Invoke(id));
            _connection.On <List <UsersRank> >("UsersRank", (rank) => Ranking?.Invoke(rank));
            _connection.On <string>("DisconnectUser", (connId) => DisconnectUser?.Invoke(connId));
            _connection.On <ResponseViewModel, string>("ProgressReportA", (obj, id) => ProgressReportA?.Invoke(obj, id));
            _connection.On <EMTInfo, string>("ProgressReportB", (obj, id) => ProgressReportB?.Invoke(obj, id));
            _connection.On <MedicalInfo, string>("ProgressReportC", (obj, id) => ProgressReportC?.Invoke(obj, id));
            _connection.On <string>("Test", (obj) => Test?.Invoke(obj));
            _connection.On <string>("RestartedResponse", (obj) => Restarted?.Invoke(obj));
            _connection.On <string, string, string>("CallSuccess", (sid, sender, agent) => CallSuccess?.Invoke(sid, sender, agent));
        }
Esempio n. 9
0
        /// <summary>
        /// Parses a recevied status report (answer to '?')
        /// </summary>
        private void ParseStatus(string line)
        {
            MatchCollection statusMatch = StatusEx.Matches(line);

            if (statusMatch.Count == 0)
            {
                NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line));
                return;
            }

            bool posUpdate      = false;
            bool overrideUpdate = false;
            bool pinStateUpdate = false;
            bool resetPins      = true;

            foreach (Match m in statusMatch)
            {
                if (m.Index == 1)
                {
                    Status = m.Groups[1].Value;
                    continue;
                }

                if (m.Groups[1].Value == "Ov")
                {
                    try
                    {
                        string[] parts = m.Groups[2].Value.Split(',');
                        FeedOverride    = int.Parse(parts[0]);
                        RapidOverride   = int.Parse(parts[1]);
                        SpindleOverride = int.Parse(parts[2]);
                        overrideUpdate  = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "WCO")
                {
                    try
                    {
                        string OffsetString = m.Groups[2].Value;

                        if (Properties.Settings.Default.IgnoreAdditionalAxes)
                        {
                            string[] parts = OffsetString.Split(',');
                            if (parts.Length > 3)
                            {
                                Array.Resize(ref parts, 3);
                                OffsetString = string.Join(",", parts);
                            }
                        }

                        WorkOffset = Vector3.Parse(OffsetString);
                        posUpdate  = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (SyncBuffer && m.Groups[1].Value == "Bf")
                {
                    try
                    {
                        int availableBytes = int.Parse(m.Groups[2].Value.Split(',')[1]);
                        int used           = Properties.Settings.Default.ControllerBufferSize - availableBytes;

                        if (used < 0)
                        {
                            used = 0;
                        }

                        BufferState = used;
                        RaiseEvent(Info, $"Buffer State Synced ({availableBytes} bytes free)");
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "Pn")
                {
                    resetPins = false;

                    string states = m.Groups[2].Value;

                    bool stateX = states.Contains("X");
                    if (stateX != PinStateLimitX)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateLimitX = stateX;

                    bool stateY = states.Contains("Y");
                    if (stateY != PinStateLimitY)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateLimitY = stateY;

                    bool stateZ = states.Contains("Z");
                    if (stateZ != PinStateLimitZ)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateLimitZ = stateZ;

                    bool stateP = states.Contains("P");
                    if (stateP != PinStateProbe)
                    {
                        pinStateUpdate = true;
                    }
                    PinStateProbe = stateP;
                }

                else if (m.Groups[1].Value == "F")
                {
                    try
                    {
                        FeedRateRealtime = double.Parse(m.Groups[2].Value, Constants.DecimalParseFormat);
                        posUpdate        = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }

                else if (m.Groups[1].Value == "FS")
                {
                    try
                    {
                        string[] parts = m.Groups[2].Value.Split(',');
                        FeedRateRealtime     = double.Parse(parts[0], Constants.DecimalParseFormat);
                        SpindleSpeedRealtime = double.Parse(parts[1], Constants.DecimalParseFormat);
                        posUpdate            = true;
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            SyncBuffer = false;             //only run this immediately after button press

            //run this later to catch work offset changes before parsing position
            Vector3 NewMachinePosition = MachinePosition;

            foreach (Match m in statusMatch)
            {
                if (m.Groups[1].Value == "MPos" || m.Groups[1].Value == "WPos")
                {
                    try
                    {
                        string PositionString = m.Groups[2].Value;

                        if (Properties.Settings.Default.IgnoreAdditionalAxes)
                        {
                            string[] parts = PositionString.Split(',');
                            if (parts.Length > 3)
                            {
                                Array.Resize(ref parts, 3);
                                PositionString = string.Join(",", parts);
                            }
                        }

                        NewMachinePosition = Vector3.Parse(PositionString);

                        if (m.Groups[1].Value == "WPos")
                        {
                            NewMachinePosition += WorkOffset;
                        }

                        if (NewMachinePosition != MachinePosition)
                        {
                            posUpdate       = true;
                            MachinePosition = NewMachinePosition;
                        }
                    }
                    catch { NonFatalException.Invoke(string.Format("Received Bad Status: '{0}'", line)); }
                }
            }

            if (posUpdate && Connected && PositionUpdateReceived != null)
            {
                PositionUpdateReceived.Invoke();
            }

            if (overrideUpdate && Connected && OverrideChanged != null)
            {
                OverrideChanged.Invoke();
            }

            if (resetPins)                                                                         //no pin state received in status -> all zero
            {
                pinStateUpdate = PinStateLimitX | PinStateLimitY | PinStateLimitZ | PinStateProbe; //was any pin set before

                PinStateLimitX = false;
                PinStateLimitY = false;
                PinStateLimitZ = false;
                PinStateProbe  = false;
            }

            if (pinStateUpdate && Connected && PinStateChanged != null)
            {
                PinStateChanged.Invoke();
            }

            if (Connected && StatusReceived != null)
            {
                StatusReceived.Invoke(line);
            }
        }
Esempio n. 10
0
 private void OnStatusReceived(IRuntimeStatusInfo statusinfo)
 {
     StatusReceived?.Invoke(statusinfo);
 }
Esempio n. 11
0
 internal void StatusResponse(ServoStatusResponse status)
 {
     //fire the event
     StatusReceived?.Invoke(_arm, new DataEventArg <ServoStatusResponse>(status));
 }
Esempio n. 12
0
 void StatusResponse(SoundStatusResponse status)
 {
     //fire the event
     StatusReceived?.Invoke(_arm, new DataEventArg <SoundStatusResponse>(status));
 }
Esempio n. 13
0
 private void OnStatusReceived(AMCPEventArgs e)
 {
     StatusReceived?.Invoke(this, e);
 }
Esempio n. 14
0
 public void Accept(StatusMessage msg)
 {
     statusMessage = msg;
     StatusReceived?.Invoke(this, msg);
 }
 public void RaiseIntermediateStatusEvent(IntermediateStatus status)
 {
     StatusReceived?.Invoke(status);
 }
Esempio n. 16
0
 protected virtual void OnStatusReceived(JEnumerable <JToken> e)
 {
     StatusReceived?.Invoke(this, e);
 }