Пример #1
0
        void ServiceResetActivity()
        {
            using (var eeLog = new Logging.EnterExitTrace(Log))
            {
                // clear the enable auto load and enable auto unload values

                if (enableAutoLoadIVA.Update().VC.GetValue <bool>(false))
                {
                    enableAutoLoadIVA.Set(false);
                }

                if (enableAutoUnloadIVA.Update().VC.GetValue <bool>(false))
                {
                    enableAutoUnloadIVA.Set(false);
                }

                IValueAccessor a2pPinsStateIVA = SelectedActiveToPassivePinsStateIVA;
                IValueAccessor p2aPinsStateIVA = SelectedPassiveToActivePinsStateIVA;

                IActiveToPassivePinsState a2pPinsState = new ActiveToPassivePinsState(a2pPinsStateIVA.Update().VC);
                IPassiveToActivePinsState p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

                if (!a2pPinsState.IsIdle)
                {
                    lastSetA2PPins           = new ActiveToPassivePinsState();
                    lastSetA2PPins.IFaceName = PartID;
                    lastSetA2PPins.XferILock = true;
                    a2pPinsStateIVA.Set(lastSetA2PPins as IActiveToPassivePinsState);
                }

                if (config.GetConfigKeyAccessOnce("E84Sim.ResetForcesESandHO").GetValue <bool>(false) && !p2aPinsState.IsSelectable)
                {
                    p2aPinsStateIVA.Set(new PassiveToActivePinsState(p2aPinsState)
                    {
                        ES = true, HO_AVBL = true
                    } as IPassiveToActivePinsState);
                }

                Spin(TimeSpan.FromSeconds(0.5));

                a2pPinsState = new ActiveToPassivePinsState(a2pPinsStateIVA.Update().VC);
                p2aPinsState = new PassiveToActivePinsState(p2aPinsStateIVA.Update().VC);

                if (!p2aPinsState.IsSelectable)
                {
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("Reset complete with E84 P->A pins not selectable [{0}]", p2aPinsState));
                }
                else if (!a2pPinsState.IsIdle)
                {
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("Reset complete with E84 A->P pins not idle [{0}]", a2pPinsState));
                }
                else
                {
                    SetCurrentActivity(ActivitySelect.Ready, "Reset complete and Ready for select");
                }
            }
        }
        void ServiceResetActivity()
        {
            using (var eeLog = new Logging.EnterExitTrace(Log))
            {
                LPMSim.State lpmState = lpmSimPart.PublicState;
                IActiveToPassivePinsState a2pPinsState = lpmState.InputsState.GetE84InputsBits(pioSelect);
                if (!a2pPinsState.IsIdle)
                {
                    lastSetA2PPins = new ActiveToPassivePinsState();
                    lastSetA2PPins.IFaceName = PartID;
                    lastSetA2PPins.XferILock = true;
                    IBasicAction clearPinsAction = lpmSimPart.CreateSetE084ActivePins(pioSelect, lastSetA2PPins);
                    clearPinsAction.Run();
                    if (clearPinsAction.ActionState.Failed)
                    {
                        Log.Error.Emit("Reset failed: unable to clear E084 pins:{0}", clearPinsAction);
                        SetCurrentActivity(ActivitySelect.Offline, "Reset failed: unable to clear E084 A2P pins");
                        return;
                    }
                }

                Spin(TimeSpan.FromSeconds(0.5));

                lpmState = lpmSimPart.PublicState;
                a2pPinsState = lpmState.InputsState.GetE84InputsBits(pioSelect);
                IPassiveToActivePinsState p2aPinsState = lpmState.OutputsState.GetE84OutputBits(pioSelect);

                if (!p2aPinsState.IsSelectable)
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("Reset complete with E84 P->A pins not selectable [{0}]", p2aPinsState));
                else if (!a2pPinsState.IsIdle)
                    SetCurrentActivity(ActivitySelect.WaitForPinsReady, Utils.Fcns.CheckedFormat("Reset complete with E84 A->P pins not idle [{0}]", a2pPinsState));
                else
                    SetCurrentActivity(ActivitySelect.Ready, "Reset complete and Ready for select");
            }
        }
Пример #3
0
        private void ThreadEntryPoint()
        {
            using (var eeTrace = new Logging.EnterExitTrace(Trace, "ThreadEntryPoint"))
            {
                List<TableItem> tableItemList = new List<TableItem>();
                Dictionary<Socket, TableItem> referenceTable = new Dictionary<Socket, TableItem>();
                List<Socket> referenceReadList = new List<Socket>();
                List<Socket> referenceWriteList = new List<Socket>();
                List<Socket> referenceErrorList = new List<Socket>();
                bool setIsEmpty = true;

                List<Socket> readList = new List<Socket>();
                List<Socket> writeList = new List<Socket>();
                List<Socket> errorList = new List<Socket>();

                List<Socket> dropList = new List<Socket>();

                rebuildTablesFromUserTable = true;

                for (; ; )
                {
                    if (stopThread)
                        break;

                    if (rebuildTablesFromUserTable)
                    {
                        rebuildTablesFromUserTable = false;

                        tableItemList.Clear();
                        referenceTable.Clear();
                        referenceReadList.Clear();
                        referenceWriteList.Clear();
                        referenceErrorList.Clear();

                        dropList.Clear();

                        lock (userTableMutex)
                        {
                            foreach (KeyValuePair<Socket, TableItem> kvp in userTableDictionary)
                            {
                                TableItem tableItem = kvp.Value;

                                if (tableItem.IsUsable)
                                    tableItemList.Add(tableItem);
                                else
                                    dropList.Add(kvp.Key);
                            }

                            if (dropList.Count > 0)
                            {
                                foreach (Socket s in dropList)
                                    userTableDictionary.Remove(s);
                            }
                        }

                        if (dropList.Count > 0)
                        {
                            Logger.Warning.Emit("Dropped {0} invalid Socket select TableItems", dropList.Count);
                        }

                        foreach (TableItem tableItem in tableItemList)
                        {
                            referenceTable.Add(tableItem.s, tableItem);

                            if (tableItem.read)
                                referenceReadList.Add(tableItem.s);
                            if (tableItem.write)
                                referenceWriteList.Add(tableItem.s);
                            if (tableItem.error)
                                referenceErrorList.Add(tableItem.s);
                        }

                        setIsEmpty = ((referenceReadList.Count == 0) && (referenceWriteList.Count == 0) && (referenceErrorList.Count == 0));

                        Logger.Debug.Emit("Select table rebuilt.  Contains {0} sockets", tableItemList.Count);
                    }

                    if (setIsEmpty)
                    {
                        threadWaitEventNotifier.WaitMSec(emptySetWaitMSec);
                    }
                    else
                    {
                        try
                        {
                            readList.Clear(); writeList.Clear(); errorList.Clear();
                            readList.AddRange(referenceReadList); writeList.AddRange(referenceWriteList); errorList.AddRange(referenceErrorList);

                            Socket.Select(readList, writeList, errorList, selectWaitMicroSec);

                            SetTableItemTouchedFlags(referenceTable, readList);
                            SetTableItemTouchedFlags(referenceTable, writeList);
                            SetTableItemTouchedFlags(referenceTable, errorList);

                            bool anyTouched = false;
                            foreach (TableItem tableItem in tableItemList)
                            {
                                if (tableItem.touched)
                                {
                                    tableItem.notifyTarget.Notify();
                                    tableItem.touched = false;
                                    anyTouched = true;
                                }
                            }

                            if (anyTouched)
                                System.Threading.Thread.Sleep(10);      // prevent free spin of this thread when signaling events.
                        }
                        catch (System.Exception ex)
                        {
                            Trace.Debug.Emit("Select failed: {0}", ex.Message);

                            threadWaitEventNotifier.WaitMSec(selectThrewWaitMSec);
                            rebuildTablesFromUserTable = true;
                        }
                    }
                }
            }
        }
Пример #4
0
        private void ThreadEntryPoint()
        {
            using (var eeTrace = new Logging.EnterExitTrace(Logger, "ThreadEntryPoint", mesgType: Logging.MesgType.Debug))
            {
                rebuildTablesFromUserTable = true;

                for (; ;)
                {
                    if (stopThread)
                    {
                        break;
                    }

                    if (!inactiveTableItemArray.IsNullOrEmpty() && rebuildTableItemsTimer.StartIfNeeded().IsTriggered)
                    {
                        rebuildTablesFromUserTable = true;
                    }

                    if (rebuildTablesFromUserTable)
                    {
                        RebuildTablesFromUserTable();
                    }

                    try
                    {
                        selectReadSocketListParam.Clear();
                        selectWriteSocketListParam.Clear();
                        selectErrorSocketListParam.Clear();

                        selectReadSocketListParam.AddRange(activeReadSocketArray);
                        selectWriteSocketListParam.AddRange(activeWriteSocketArray);
                        selectErrorSocketListParam.AddRange(activeErrorSocketArray);

                        if (!selectReadSocketListParam.IsNullOrEmpty() || !selectWriteSocketListParam.IsNullOrEmpty() || !selectErrorSocketListParam.IsNullOrEmpty())
                        {
                            Socket.Select(selectReadSocketListParam, selectWriteSocketListParam, selectErrorSocketListParam, selectWaitMicroSec);
                        }
                        else
                        {
                            threadWaitEventNotifier.WaitMSec(emptySetWaitMSec);
                        }

                        SetTableItemTouchedFlags(referenceActiveTableItemDictionary, selectReadSocketListParam);
                        SetTableItemTouchedFlags(referenceActiveTableItemDictionary, selectWriteSocketListParam);
                        SetTableItemTouchedFlags(referenceActiveTableItemDictionary, selectErrorSocketListParam);

                        bool anyTouched = false;
                        foreach (TableItem tableItem in activeTableItemArray)
                        {
                            if (tableItem.touched)
                            {
                                tableItem.notifyTarget.Notify();
                                tableItem.touched = false;
                                anyTouched        = true;
                            }
                        }

                        if (anyTouched)
                        {
                            System.Threading.Thread.Sleep(1);      // prevent free spin of this thread when signaling events.
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Trace.Debug.Emit("Select failed: {0}", ex.ToString(ExceptionFormat.TypeAndMessage));

                        threadWaitEventNotifier.WaitMSec(selectThrewWaitMSec);
                        rebuildTablesFromUserTable = true;
                    }
                }
            }
        }