Exemplo n.º 1
0
        public static void SendResults(IPresentation pre, byte address, eTaskType taskType, int phoneNumberId = 0)
        {
            lock (_staticSyncObj)
            {
                var dbResults = NovaAlertCommon.GetResults(taskType, phoneNumberId);

                for (int i = 0; i < dbResults.Count; i++)
                {
                    var item = dbResults[i];
                    var msg  = new LP_ResultMessage()
                    {
                        TypeDest = eDevice.LedPanel,
                        Address  = address,
                        Id       = (byte)item.DisplayId,
                        Alert    = (byte)item.Task,
                        Level    = (byte)item.Level
                    };

                    if (item.TimeReceive.HasValue && item.TimeChange.HasValue)
                    {
                        msg.Result = 3;
                    }
                    else
                    {
                        if (item.TimeChange.HasValue)
                        {
                            msg.Result = 2;
                        }
                        else
                        {
                            if (item.TimeReceive.HasValue)
                            {
                                msg.Result = 1;
                            }
                        }
                    }

                    pre.SendData(msg);
                    System.Threading.Thread.Sleep(51);
                }
            }
        }
 List <ResultData> INovaAlertConfigService.GetResults(eTaskType taskType)
 {
     return(NovaAlertCommon.GetResults(taskType));
 }
Exemplo n.º 3
0
        public void WaitAndReplyCommandFromServer(Func <bool> act)
        {
            this.Modem.SelectedPanelId = 255;

            LogService.Logger.Info("Client: start waiting for server");
            System.Diagnostics.Debug.WriteLine("Client start waiting command from server");
            var  ret      = this.Modem.WaitForTSLResult(TSL_WaitTime * 6);
            bool done     = false;
            int  curIndex = 0;

            while (ret != null && !done)
            {
                if (ret is TSL_Message)
                {
                    var r_msg = ret as TSL_Message;
                    LogService.Logger.Info(string.Format("Client: receive {0}", r_msg.Control));

                    if (r_msg.Control == eControl.TSL_ENQ)
                    {
                        ret = this.Modem.SendTSLMessageAndWaitForResult(new TSL_Message()
                        {
                            Control = eControl.ACK
                        }, TSL_WaitTime);
                    }
                    else if (r_msg.Control == eControl.TSL_Prepare)
                    {
                        bool ack = (act != null) ? act() : false;

                        if (ack)
                        {
                            this.SendMessage(eControl.ACK);
                        }
                        else
                        {
                            this.SendMessage(eControl.NAK);
                        }
                    }
                    else if (r_msg.Control == eControl.TSL_ResultRequest)
                    {
                        // send result
                        List <Entities.ResultData> results = null;
                        if (results == null)
                        {
                            results = NovaAlertCommon.GetResults(Entities.eTaskType.CTT);
                        }

                        if (curIndex < results.Count)
                        {
                            var obj = results[curIndex++];
                            this.Modem.SendMessage(obj);
                        }
                        else
                        {
                            this.SendMessage(eControl.TSL_ResultEnd);
                        }
                    }
                    else if (r_msg.Control == eControl.TSL_EOT)
                    {
                        done = true;
                    }

                    ret = this.Modem.WaitForTSLResult(TSL_WaitTime);
                }
                else
                {
                    LogService.Logger.Info("Client: receive undefined message");
                }
            }

            this.Modem.HangUp();
            this.Modem.ClearBuffer();
            this.Modem.SelectedPanelId = null;
        }