Inheritance: System.EventArgs
Ejemplo n.º 1
0
        private void ProcessEvent(TpiResponse response)
        {
            // Send a password if requested
            if (response.Command == ResponseCommand.LoginInteraction && response.Data == "3")
            {
                _tpiSocket.ExecuteCommand(new TpiCommand(RequestCommand.NetworkLogin, Password));
                Thread.Sleep(500);
            }

            if (response.Command == ResponseCommand.LoginInteraction && response.Data == "1")
            {
                _tpiSocket.ExecuteCommand(new TpiCommand(RequestCommand.TimeStampControl, "1"));
                Thread.Sleep(1500);
                _tpiSocket.ExecuteCommand(new TpiCommand(RequestCommand.StatusReport));
            }

            if (response.Command == ResponseCommand.EnvisalinkZoneTimerDump)
            {
                for (int i = 0; i < 64; i++)
                {
                    Zone z = ZoneList.FirstOrDefault(x => x.Id == i + 1);
                    if (z != null)
                    {
                        z.SecondsSinceLastClose = response.SecondsSinceOpened[i];
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void TpiSocket_ResponseReceived(object sender, TpiResponse response)
        {
            switch (response.ResponseType)
            {
            case TpiResponseType.System:
                this.ProcessEvent(response);
                break;

            case TpiResponseType.Partition:
                // Find the partition and process it (ignore any partitions that are not defined in app settings)
                Partition p = PartitionList.FirstOrDefault(x => x.Id == response.PartitionId);
                if (p != null)
                {
                    p.ProcessEvent(response);
                }
                break;

            case TpiResponseType.Zone:
                // Find the zone and process it (ignore any zones that are not defined in app settings)
                Zone z = ZoneList.FirstOrDefault(x => x.Id == response.ZoneId);
                if (z != null)
                {
                    z.ProcessEvent(response);
                }
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process events that are received against this zone
        /// </summary>
        /// <param name="response"></param>
        public void ProcessEvent(TpiResponse response)
        {
            switch (response.Command)
            {
            case ResponseCommand.ZoneAlarm:
                Status  = ZoneStatus.Alarm;
                InAlarm = true;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneAlarmRestore:
                Status  = ZoneStatus.Closed;
                InAlarm = false;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneTamper:
                Status = ZoneStatus.Tamper;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneTamperRestore:
                Status = ZoneStatus.Closed;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneFault:
                Status = ZoneStatus.Fault;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneFaultRestore:
                Status = ZoneStatus.Closed;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneOpen:
                Status = ZoneStatus.Open;
                OnZoneChanged();
                break;

            case ResponseCommand.ZoneRestored:
                Status = ZoneStatus.Closed;
                OnZoneChanged();
                break;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Process events that are received against this zone
        /// </summary>
        /// <param name="response"></param>
        public void ProcessEvent(TpiResponse response)
        {
            switch (response.Command)
            {
                case ResponseCommand.ZoneAlarm:
                    Status = ZoneStatus.Alarm;
                    InAlarm = true;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneAlarmRestore:
                    Status = ZoneStatus.Closed;
                    InAlarm = false;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneTamper:
                    Status = ZoneStatus.Tamper;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneTamperRestore:
                    Status = ZoneStatus.Closed;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneFault:
                    Status = ZoneStatus.Fault;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneFaultRestore:
                    Status = ZoneStatus.Closed;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneOpen:
                    Status = ZoneStatus.Open;
                    OnZoneChanged();
                    break;

                case ResponseCommand.ZoneRestored:
                    Status = ZoneStatus.Closed;
                    OnZoneChanged();
                    break;
            }
        }
Ejemplo n.º 5
0
        public void ProcessEvent(TpiResponse response)
        {
            switch (response.Command)
            {
            case ResponseCommand.PartitionReady:
                AlarmActive = false;
                ReadyLed    = true;
                OnPartitionChanged();
                break;

            case ResponseCommand.PartitionNotReady:
                ReadyLed   = false;
                ArmingMode = TpiArmedMode.NotArmed;
                OnPartitionChanged();
                break;

            case ResponseCommand.KeypadLedStatePartition1Only:
            case ResponseCommand.KeypadLedflashStatePartition1Only:
                BitArray ba = new BitArray(StringToByteArray(response.Data));
                ReadyLed     = ba[0];
                ArmedLed     = ba[1];
                MemoryLed    = ba[2];
                BypassLed    = ba[3];
                TroubleLed   = ba[4];
                ProgramLed   = ba[5];
                FireLed      = ba[6];
                BacklightLed = ba[7];
                OnPartitionChanged();
                break;

            case ResponseCommand.PartitionInAlarm:
                AlarmActive = true;
                OnPartitionChanged();
                break;

            case ResponseCommand.PartitionArmed:
                ArmingMode = response.ArmingMode.Value;
                ArmedLed   = true;
                OnPartitionChanged();
                break;

            case ResponseCommand.PartitionDisarmed:
                AlarmActive = false;
                ArmedLed    = false;
                ArmingMode  = TpiArmedMode.NotArmed;
                OnPartitionChanged();
                break;

            case ResponseCommand.ExitDelayinProgress:
                ArmingMode = TpiArmedMode.ExitDelayInProgress;
                OnPartitionChanged();
                break;

            case ResponseCommand.EntryDelayinProgress:
                ArmingMode = TpiArmedMode.EntryDelayInProgress;
                OnPartitionChanged();
                break;

            case ResponseCommand.ChimeEnabled:
                ChimeEnabled = true;
                break;

            case ResponseCommand.ChimeDisabled:
                ChimeEnabled = false;
                break;

            case ResponseCommand.TroubleLedon:
                TroubleLed = true;
                break;

            case ResponseCommand.TroubleLedoff:
                TroubleLed = false;
                break;

            case ResponseCommand.UserClosing:
                UserId = response.UserId.Value;
                break;

            case ResponseCommand.UserOpening:
                UserId = response.UserId.Value;
                break;

            // These are related to the partition but are not actively tracked in this API
            case ResponseCommand.PartitionReadyForceArmingEnabled:
            case ResponseCommand.KeypadLockout:
            case ResponseCommand.PgmOutputisinProgress:
            case ResponseCommand.InvalidAccessCode:
            case ResponseCommand.FunctionNotAvailable:
            case ResponseCommand.FailuretoArm:
            case ResponseCommand.PartitionisBusy:
            case ResponseCommand.SystemArminginProgress:
            case ResponseCommand.SpecialClosing:
            case ResponseCommand.PartialClosing:
            case ResponseCommand.SpecialOpening:
                break;
            }
        }
Ejemplo n.º 6
0
        public void ProcessEvent (TpiResponse response)
        {
            switch (response.Command)
            {
                case ResponseCommand.PartitionReady:
                    AlarmActive = false;
                    ReadyLed = true;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.PartitionNotReady:
                    ReadyLed = false;
                    ArmingMode = TpiArmedMode.NotArmed;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.KeypadLedStatePartition1Only:
                case ResponseCommand.KeypadLedflashStatePartition1Only:
                    BitArray ba = new BitArray(StringToByteArray(response.Data));
                    ReadyLed = ba[0];
                    ArmedLed = ba[1];
                    MemoryLed = ba[2];
                    BypassLed = ba[3];
                    TroubleLed = ba[4];
                    ProgramLed = ba[5];
                    FireLed = ba[6];
                    BacklightLed = ba[7];
                    OnPartitionChanged();
                    break;

                case ResponseCommand.PartitionInAlarm:
                    AlarmActive = true;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.PartitionArmed:
                    ArmingMode = response.ArmingMode.Value;
                    ArmedLed = true;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.PartitionDisarmed:
                    AlarmActive = false;
                    ArmedLed = false;
                    ArmingMode = TpiArmedMode.NotArmed;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.ExitDelayinProgress:
                    ArmingMode = TpiArmedMode.ExitDelayInProgress;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.EntryDelayinProgress:
                    ArmingMode = TpiArmedMode.EntryDelayInProgress;
                    OnPartitionChanged();
                    break;

                case ResponseCommand.ChimeEnabled:
                    ChimeEnabled = true;
                    break;

                case ResponseCommand.ChimeDisabled:
                    ChimeEnabled = false;
                    break;

                case ResponseCommand.TroubleLedon:
                    TroubleLed = true;
                    break;

                case ResponseCommand.TroubleLedoff:
                    TroubleLed = false;
                    break;

                case ResponseCommand.UserClosing:
                    UserId = response.UserId.Value;
                    break;

                case ResponseCommand.UserOpening:
                    UserId = response.UserId.Value;
                    break;

                // These are related to the partition but are not actively tracked in this API
                case ResponseCommand.PartitionReadyForceArmingEnabled:
                case ResponseCommand.KeypadLockout:
                case ResponseCommand.PgmOutputisinProgress:
                case ResponseCommand.InvalidAccessCode:
                case ResponseCommand.FunctionNotAvailable:
                case ResponseCommand.FailuretoArm:
                case ResponseCommand.PartitionisBusy:
                case ResponseCommand.SystemArminginProgress:
                case ResponseCommand.SpecialClosing:
                case ResponseCommand.PartialClosing:
                case ResponseCommand.SpecialOpening:
                    break;
            }
        }
Ejemplo n.º 7
0
        private void ProcessEvent(TpiResponse response)
        {
            // Send a password if requested
            if (response.Command == ResponseCommand.LoginInteraction && response.Data == "3")
            {
                _tpiSocket.ExecuteCommand(new TpiCommand(RequestCommand.NetworkLogin, Password));
                Thread.Sleep(500);
            }

            if (response.Command == ResponseCommand.LoginInteraction && response.Data == "1")
            {
                _tpiSocket.ExecuteCommand(new TpiCommand(RequestCommand.TimeStampControl, "1"));
                Thread.Sleep(1500);
                _tpiSocket.ExecuteCommand(new TpiCommand(RequestCommand.StatusReport));
            }

            if (response.Command == ResponseCommand.EnvisalinkZoneTimerDump)
            {
                for (int i = 0; i < 64; i++)
                {
                    Zone z = ZoneList.FirstOrDefault(x => x.Id == i+1);
                    if (z != null)
                        z.SecondsSinceLastClose = response.SecondsSinceOpened[i];
                }
            }
        }
Ejemplo n.º 8
0
        private void TpiSocket_ResponseReceived(object sender, TpiResponse response)
        {
            switch (response.ResponseType)
            {
                case TpiResponseType.System:
                    this.ProcessEvent(response);
                    break;

                case TpiResponseType.Partition:
                    // Find the partition and process it (ignore any partitions that are not defined in app settings)
                    Partition p = PartitionList.FirstOrDefault(x => x.Id == response.PartitionId);
                    if (p != null)
                        p.ProcessEvent(response);
                    break;

                case TpiResponseType.Zone:
                    // Find the zone and process it (ignore any zones that are not defined in app settings)
                    Zone z = ZoneList.FirstOrDefault(x => x.Id == response.ZoneId);
                    if (z != null)
                        z.ProcessEvent(response);
                    break;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Listen for data coming from the TPI
        /// </summary>
        private void ListenForData()
        {
            // Listen forever 
            while (true)
            {
                EnsureConnection();

                string[] lines;
                NetworkStream clientStream = null;
                try
                {
                    clientStream = _client.GetStream();
                    var message = new byte[4096];

                    while (!_shutdown)
                    {
                        var bytesRead = 0;

                        try
                        {
                            //blocks until a client sends a message
                            bytesRead = clientStream.Read(message, 0, 4096);
                        }
                        catch (Exception ex)
                        {
                            //a socket error has occured
                            MyLogger.LogError($"ListenData Exception: {MyLogger.ExMsg(ex)}");

                            // Wait 5 seconds before trying to re-connect
                            MyLogger.LogInfo("Waiting 5 seconds before trying to re-connect");
                            Thread.Sleep(5000);

                            break;
                        }

                        if (bytesRead == 0)
                        {
                            //the client has disconnected from the server
                            break;
                        }

                        //message has successfully been received
                        var encoder = new ASCIIEncoding();


                        var value = encoder.GetString(message, 0, bytesRead);
                        lines = Regex.Split(value, "\r\n");
                        foreach (string line in lines)
                        {
                            if (!String.IsNullOrEmpty(line))
                            {
                                var r = new TpiResponse(line);

                                MyLogger.LogInfo($"< {((int)r.Command):D3}:{r.Command.ToString().PadRight(20)} - {r.Data}");

                                if (ResponseReceived != null)
                                    ResponseReceived(this, r);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MyLogger.LogError(MyLogger.ExMsg(ex));
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Listen for data coming from the TPI
        /// </summary>
        private void ListenForData()
        {
            // Listen forever
            while (true)
            {
                EnsureConnection();

                string[]      lines;
                NetworkStream clientStream = null;
                try
                {
                    clientStream = _client.GetStream();
                    var message = new byte[4096];

                    while (!_shutdown)
                    {
                        var bytesRead = 0;

                        try
                        {
                            //blocks until a client sends a message
                            bytesRead = clientStream.Read(message, 0, 4096);
                        }
                        catch (Exception ex)
                        {
                            //a socket error has occured
                            MyLogger.LogError($"ListenData Exception: {MyLogger.ExMsg(ex)}");

                            // Wait 5 seconds before trying to re-connect
                            MyLogger.LogInfo("Waiting 5 seconds before trying to re-connect");
                            Thread.Sleep(5000);

                            break;
                        }

                        if (bytesRead == 0)
                        {
                            //the client has disconnected from the server
                            break;
                        }

                        //message has successfully been received
                        var encoder = new ASCIIEncoding();


                        var value = encoder.GetString(message, 0, bytesRead);
                        lines = Regex.Split(value, "\r\n");
                        foreach (string line in lines)
                        {
                            if (!String.IsNullOrEmpty(line))
                            {
                                var r = new TpiResponse(line);

                                MyLogger.LogInfo($"< {((int)r.Command):D3}:{r.Command.ToString().PadRight(20)} - {r.Data}");

                                if (ResponseReceived != null)
                                {
                                    ResponseReceived(this, r);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MyLogger.LogError(MyLogger.ExMsg(ex));
                }
            }
        }