private void OnRaiseSystemEvents(object state)
        {
            try {
                var e = new SystemEventState(null);

                e.Initialize(
                    SystemContext,
                    null,
                    EventSeverity.Medium,
                    new LocalizedText("Raising Events"));

                e.SetChildValue(SystemContext, BrowseNames.SourceNode, ObjectIds.Server, false);
                e.SetChildValue(SystemContext, BrowseNames.SourceName, "Internal", false);

                Server.ReportEvent(e);

                var ae = new AuditEventState(null);

                ae.Initialize(
                    SystemContext,
                    null,
                    EventSeverity.Medium,
                    new LocalizedText("Events Raised"),
                    true,
                    DateTime.UtcNow);

                ae.SetChildValue(SystemContext, BrowseNames.SourceNode, ObjectIds.Server, false);
                ae.SetChildValue(SystemContext, BrowseNames.SourceName, "Internal", false);

                Server.ReportEvent(ae);
            }
            catch (Exception e) {
                Utils.Trace(e, "Unexpected error in OnRaiseSystemEvents");
            }
        }
        private void OnRaiseSystemEvents(object state)
        {
            try
            {
                SystemEventState e = new SystemEventState(null);

                e.Initialize(
                    SystemContext,
                    null,
                    EventSeverity.Medium,
                    new LocalizedText("Raising Events"));

                e.SetChildValue(SystemContext, BrowseNames.SourceNode, ObjectIds.Server, false);
                e.SetChildValue(SystemContext, BrowseNames.SourceName, "Internal", false);

                Server.ReportEvent(e);

                AuditEventState ae = new AuditEventState(null);

                ae.Initialize(
                    SystemContext,
                    null,
                    EventSeverity.Medium,
                    new LocalizedText("Events Raised"),
                    true,
                    DateTime.UtcNow);

                ae.SetChildValue(SystemContext, BrowseNames.SourceNode, ObjectIds.Server, false);
                ae.SetChildValue(SystemContext, BrowseNames.SourceName, "Internal", false);

                Server.ReportEvent(ae);
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error in OnRaiseSystemEvents");
            }
        }
Exemple #3
0
        private void DoSimulation(object state)
        {
            try
            {
                lock (Lock)
                {
                    var    now = DateTime.Now;
                    double dt  = (now - timestamp).TotalMilliseconds;
                    timestamp = now;

                    var mode = (short)modeState.Value;
                    if (mode != 1) // if not in man mode
                    {
                        double period = 30000;
                        switch ((short)speedState.Value)
                        {
                        case 1:
                            period = 20000;
                            break;

                        case 2:
                            period = 10000;
                            break;

                        case 3:
                            period = 5000;
                            break;

                        default:
                            period = 30000;
                            break;
                        }
                        if (mode == 2)                                     // auto mode
                        {
                            masterAxis = (masterAxis + dt / period) % 1.0; // 0.0 to 1.0
                        }
                        axis1State.Value = (float)(Math.Sin(masterAxis * 2.0 * Math.PI) * 45.0);
                        axis2State.Value = (float)(Math.Cos(masterAxis * 2.0 * Math.PI) * 45.0);
                        axis3State.Value = (float)(Math.Sin(((masterAxis * 2.0) % 1.0) * 2.0 * Math.PI) * 45.0);
                        axis4State.Value = (float)(Math.Cos(masterAxis * 2.0 * Math.PI) * -180.0);
                    }
                    axis1State.Timestamp = now;
                    axis1State.ClearChangeMasks(SystemContext, false);
                    axis2State.Timestamp = now;
                    axis2State.ClearChangeMasks(SystemContext, false);
                    axis3State.Timestamp = now;
                    axis3State.ClearChangeMasks(SystemContext, false);
                    axis4State.Timestamp = now;
                    axis4State.ClearChangeMasks(SystemContext, false);

                    if (mode != prevmode)
                    {
                        prevmode = mode;

                        var e = new SystemEventState(null);
                        switch (mode)
                        {
                        case 1:
                            e.Initialize(SystemContext, this.robot1State, EventSeverity.Medium, new LocalizedText("Mode to Hand"));
                            break;

                        case 2:
                            e.Initialize(SystemContext, this.robot1State, EventSeverity.Medium, new LocalizedText("Mode to Auto"));
                            break;

                        default:
                            e.Initialize(SystemContext, this.robot1State, EventSeverity.Medium, new LocalizedText("Mode to Off"));
                            break;
                        }
                        this.robot1State.ReportEvent(SystemContext, e);
                    }

                    var laser = (bool)this.laserState.Value;
                    if (laser != prevlaser)
                    {
                        prevlaser = laser;

                        var e = new SystemEventState(null);
                        e.Initialize(SystemContext, this.robot1State, EventSeverity.Medium, new LocalizedText(laser ? "Laser activated." : "Laser deactivated."));
                        this.robot1State.ReportEvent(SystemContext, e);
                    }
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error doing simulation.");
            }
        }