예제 #1
0
 public void AddSendNotifyTelegram(Telegram t)
 {
     lock (_lockSendNotifyTelegram)
         SendNotifyTelegrams.Add(t);
     _newSendNotifyTelegram.Set();
 }
예제 #2
0
        public override void SendThreading()
        {
            LastSendTime = DateTime.Now;
            Telegram tel = null;

            while (Thread.CurrentThread.ThreadState == ThreadState.Background)
            {
                try
                {
                    lock (_lockSendTelegram)
                        tel = SendTelegrams.FirstOrDefault(prop => prop.CommSendStatus < Telegram.CommSendStatusEnum.Ack);
                    if (tel != null)
                    {
                        if (INotifyTelegramCallBack == null)
                        {
                            throw new TelegramException(String.Format("Callback for {0} is not registered.", Name));
                        }
                        INotifyTelegramCallBack?.Invoke(tel);
                        Log?.AddLog(Log.Severity.EVENT, Name, "MFCSCommunicator.SendThreading Telegram written", tel.ToString());
                        do
                        {
                            WaitHandle.WaitAny(new WaitHandle[] { _newSendNotifyTelegram }, (int)SendTimeOut.TotalMilliseconds, true); // TODO it is a long time
                            Telegram tel1 = null;
                            lock (_lockSendNotifyTelegram)
                                tel1 = SendNotifyTelegrams.FirstOrDefault();
                            if (tel1 == null)
                            {
                                if (!INotifyLongWait.Invoke(tel))
                                {
                                    throw new TelegramException("Long wait without knowledge of service communicator...");
                                }
                            }
                            if (tel1 != null)
                            {
                                // check if both telegrams are completely identical
                                tel.Sequence        = tel1.Sequence;
                                tel1.CommSendStatus = tel.CommSendStatus;
                                tel.SetCRC();
                                tel1.SetCRC();
                                if (tel.CRC != tel1.CRC)
                                {
                                    Log?.AddLog(Log.Severity.EXCEPTION, Name, "MFCSCommunicator.SendThreadind:tel={0}", tel.ToString());
                                    Log?.AddLog(Log.Severity.EXCEPTION, Name, "MFCSCommunicator.SendThreadind:tel1={0}", tel1.ToString());
                                    throw new TelegramException(String.Format("SendNotify telegram CRC does not match ({0},{1})", tel.CRC, tel1.CRC));
                                }
                                lock (_lockSendTelegram)
                                    SendTelegrams.Remove(tel);
                                lock (_lockSendNotifyTelegram)
                                    SendNotifyTelegrams.Remove(tel1);
                                Log?.AddLog(Log.Severity.EVENT, Name, "MFCSCommunicator.SendThreading send phase finished", tel.ToString());
                                tel = null;
                            }
                        } while (tel != null);
                    }
                    else
                    {
                        WaitHandle.WaitAny(new WaitHandle[] { _newSendTelegram, _newSendNotifyTelegram }, 100, true);
                    }
                }
                catch (TelegramException ex)
                {
                    Log?.AddLog(Log.Severity.EXCEPTION, Name, "MFCSCommunicator.SendThread::TelegramException", ex.Message);
                    Thread.Sleep(1000);
                }
            }