A command is issued by the application and sent to the TPI. This class will handle creating the command and putting it into the correct format for the TPI.
예제 #1
0
        public void DumpZoneTimers()
        {
            // Send the appropriate command sequence
            TpiCommand tpiCmd = new TpiCommand(RequestCommand.DumpZoneTimers);

            _tpiSocket.ExecuteCommand(tpiCmd);
        }
예제 #2
0
        public void SoundAlarm()
        {
            // Send the appropriate command sequence (this is the police alarm)
            TpiCommand tpiCmd = new TpiCommand(RequestCommand.TriggerPanicAlarm, "3");

            _tpiSocket.ExecuteCommand(tpiCmd);
        }
예제 #3
0
        /// <summary>
        /// Listen for data coming from the TPI
        /// </summary>
        private void PollTpi()
        {
            // Start the first poll 10 seconds after start up
            Thread.Sleep(10 * 1000);

            //PollInterval
            while (true)
            {
                EnsureConnection();

                try
                {
                    TpiCommand req = new TpiCommand(RequestCommand.Poll);
                    ExecuteCommand(req);

                    req = new TpiCommand(RequestCommand.KeepAlive, "1");
                    ExecuteCommand(req);

                    // Dump the Zone Timers during the poll just to keep them relatively fresh!
                    //req = new TpiCommand(RequestCommand.DumpZoneTimers);
                    //ExecuteCommand(req);
                }
                catch (Exception ex)
                {
                    MyLogger.LogError($"Could not execute polling command {MyLogger.ExMsg(ex)}");
                }

                Thread.Sleep(PollInterval * 1000);
            }
        }
예제 #4
0
        public void AwayArmSystem(int partitionId)
        {
            // Send the appropriate command sequence
            string     cmd    = String.Format("{0}", partitionId);
            TpiCommand tpiCmd = new TpiCommand(RequestCommand.PartitionArmControl, cmd);

            _tpiSocket.ExecuteCommand(tpiCmd);
        }
예제 #5
0
        public void BypassZone(int zoneId)
        {
            // Send the appropriate command sequence
            int        partitionId = 1;
            string     cmd         = String.Format("{0}*1{1:D2}#", partitionId, zoneId);
            TpiCommand tpiCmd      = new TpiCommand(RequestCommand.SendKeystrokeString, cmd);

            _tpiSocket.ExecuteCommand(tpiCmd);
        }
예제 #6
0
        public void DisArmSystem(int partitionId)
        {
            if (String.IsNullOrEmpty(ArmingCode))
            {
                MyLogger.LogError("You must specify an arming code in the configuration");
                throw new Exception("You must specify an arming code in the configuration");
            }

            // Send the appropriate command sequence
            string     cmd    = String.Format("{0}{1}", partitionId, ArmingCode);
            TpiCommand tpiCmd = new TpiCommand(RequestCommand.PartitionDisarmControl, cmd);

            _tpiSocket.ExecuteCommand(tpiCmd);
        }
예제 #7
0
        /// <summary>
        /// Send a command to the TPI.  This method will issue a lock to prevent multiple threads
        /// from sending a command at the same time.
        /// </summary>
        /// <param name="tpiRequest"></param>
        public void ExecuteCommand(TpiCommand tpiRequest)
        {
            // Take a lock so only one request can be sent at a time
            lock (thisLock)
            {
                if (_client == null || _client.Connected == false)
                {
                    MyLogger.LogError($"Socket is not connected.  Cannot send command => {((int)tpiRequest.Command):D3}:{tpiRequest.Command.ToString().PadRight(20)} - {tpiRequest.CommandData}");
                    return;
                }

                MyLogger.LogInfo($"> {((int)tpiRequest.Command):D3}:{tpiRequest.Command.ToString().PadRight(20)} - {tpiRequest.CommandData}");

                // Send the request
                var data = Encoding.ASCII.GetBytes(tpiRequest.TPIData);
                var serverStream = _client.GetStream();
                serverStream.Write(data, 0, data.Length);
                serverStream.Flush();
            }
        }
예제 #8
0
        /// <summary>
        /// Send a command to the TPI.  This method will issue a lock to prevent multiple threads
        /// from sending a command at the same time.
        /// </summary>
        /// <param name="tpiRequest"></param>
        public void ExecuteCommand(TpiCommand tpiRequest)
        {
            // Take a lock so only one request can be sent at a time
            lock (thisLock)
            {
                if (_client == null || _client.Connected == false)
                {
                    MyLogger.LogError($"Socket is not connected.  Cannot send command => {((int)tpiRequest.Command):D3}:{tpiRequest.Command.ToString().PadRight(20)} - {tpiRequest.CommandData}");
                    return;
                }

                MyLogger.LogInfo($"> {((int)tpiRequest.Command):D3}:{tpiRequest.Command.ToString().PadRight(20)} - {tpiRequest.CommandData}");

                // Send the request
                var data         = Encoding.ASCII.GetBytes(tpiRequest.TPIData);
                var serverStream = _client.GetStream();
                serverStream.Write(data, 0, data.Length);
                serverStream.Flush();
            }
        }
예제 #9
0
 public void DumpZoneTimers()
 {
     // Send the appropriate command sequence
     TpiCommand tpiCmd = new TpiCommand(RequestCommand.DumpZoneTimers);
     _tpiSocket.ExecuteCommand(tpiCmd);
 }
예제 #10
0
 public void BypassZone(int zoneId)
 {
     // Send the appropriate command sequence
     int partitionId = 1;
     string cmd = String.Format("{0}*1{1:D2}#", partitionId, zoneId);
     TpiCommand tpiCmd = new TpiCommand(RequestCommand.SendKeystrokeString, cmd);
     _tpiSocket.ExecuteCommand(tpiCmd);
 }
예제 #11
0
 public void SoundAlarm()
 {
     // Send the appropriate command sequence (this is the police alarm)
     TpiCommand tpiCmd = new TpiCommand(RequestCommand.TriggerPanicAlarm, "3");
     _tpiSocket.ExecuteCommand(tpiCmd);
 }
예제 #12
0
        public void DisArmSystem(int partitionId)
        {
            if (String.IsNullOrEmpty(ArmingCode))
            {
                MyLogger.LogError("You must specify an arming code in the configuration");
                throw new Exception("You must specify an arming code in the configuration");
            }

            // Send the appropriate command sequence
            string cmd = String.Format("{0}{1}", partitionId, ArmingCode);
            TpiCommand tpiCmd = new TpiCommand(RequestCommand.PartitionDisarmControl, cmd);
            _tpiSocket.ExecuteCommand(tpiCmd);
        }
예제 #13
0
 public void AwayArmSystem(int partitionId)
 {
     // Send the appropriate command sequence
     string cmd = String.Format("{0}", partitionId);
     TpiCommand tpiCmd = new TpiCommand(RequestCommand.PartitionArmControl, cmd);
     _tpiSocket.ExecuteCommand(tpiCmd);
 }
예제 #14
0
        /// <summary>
        /// Listen for data coming from the TPI
        /// </summary>
        private void PollTpi()
        {
            // Start the first poll 10 seconds after start up
            Thread.Sleep(10 * 1000);

            //PollInterval
            while (true)
            {
                EnsureConnection();

                try
                {
                    TpiCommand req = new TpiCommand(RequestCommand.Poll);
                    ExecuteCommand(req);

                    req = new TpiCommand(RequestCommand.KeepAlive, "1");
                    ExecuteCommand(req);

                    // Dump the Zone Timers during the poll just to keep them relatively fresh!
                    //req = new TpiCommand(RequestCommand.DumpZoneTimers);
                    //ExecuteCommand(req);
                }
                catch (Exception ex)
                {
                    MyLogger.LogError($"Could not execute polling command {MyLogger.ExMsg(ex)}");
                }

                Thread.Sleep(PollInterval * 1000);
            }
        }