Пример #1
0
        public void AddAlarmEventToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            if (bIsUpdatingAlarmEventList == false)
            {
                listView_AlarmEvents.StopSorting();
                listView_AlarmEvents.BeginUpdate();
                bIsUpdatingAlarmEventList = true;
            }

            ListViewItem lvItem = new ListViewItem(AlarmEvent.sTimeStamp);

            lvItem.SubItems.Add(AlarmObject.RoadSideObject.sComponentId + " / " + AlarmObject.RoadSideObject.sObject);
            lvItem.SubItems.Add(AlarmEvent.sMessageId);
            lvItem.SubItems.Add(AlarmEvent.sAlarmCodeId);
            lvItem.SubItems.Add(AlarmEvent.sDirection);
            lvItem.SubItems.Add(AlarmEvent.sEvent);

            foreach (cAlarmEventReturnValue AlarmReturnValues in AlarmEvent.AlarmEventReturnValues)
            {
                lvItem.SubItems.Add(AlarmReturnValues.sName);
                lvItem.SubItems.Add(AlarmReturnValues.sValue);
            }

            listView_AlarmEvents.Items.Add(lvItem);
        }
Пример #2
0
        public void CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation)
        {
            RSMP_Messages.AlarmHeader AlarmHeader;
            cAlarmEvent AlarmEvent = null;
            string      sSendBuffer;

            try
            {
                AlarmHeader = new RSMP_Messages.AlarmHeader();

                AlarmHeader.mType = "rSMsg";
                AlarmHeader.type  = "Alarm";
                AlarmHeader.mId   = System.Guid.NewGuid().ToString();

                AlarmHeader.ntsOId = AlarmObject.RoadSideObject.sNTSObjectId;
                AlarmHeader.xNId   = AlarmObject.RoadSideObject.sExternalNTSId;
                AlarmHeader.cId    = AlarmObject.RoadSideObject.sComponentId;
                AlarmHeader.aCId   = AlarmObject.sAlarmCodeId;
                AlarmHeader.xACId  = AlarmObject.sExternalAlarmCodeId;
                AlarmHeader.xNACId = AlarmObject.sExternalNTSAlarmCodeId;

                AlarmHeader.aSp = alarmSpecialisation.ToString();

                sSendBuffer = JSonSerializer.SerializeObject(AlarmHeader);

                AlarmEvent              = new cAlarmEvent();
                AlarmEvent.AlarmObject  = AlarmObject;
                AlarmEvent.sDirection   = "Sent";
                AlarmEvent.sTimeStamp   = CreateLocalTimeStamp();
                AlarmEvent.sMessageId   = AlarmHeader.mId;
                AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;
                AlarmEvent.sEvent       = AlarmHeader.aSp;

                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);

                /*
                 * if (RSMPGS_Main.bWriteEventsContinous)
                 * {
                 * RSMPGS.SysLog.EventLog("Alarm;{0}\tMId: {1}\tComponentId: {2}\tAlarmCodeId: {3}\tEvent: {4}",
                 *    AlarmEvent.sTimeStamp, AlarmEvent.sMessageId, AlarmHeader.cId, AlarmEvent.sAlarmCodeId, AlarmEvent.sEvent);
                 * }
                 */
                RSMPGS.JSon.SendJSonPacket(AlarmHeader.type, AlarmHeader.mId, sSendBuffer, true);
                if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeader.type + "/" + AlarmHeader.aSp + ", MsgId: " + AlarmHeader.mId);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create alarm message: {0}", e.Message);
            }
        }
Пример #3
0
        public void AddAlarmEventToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            ListViewItem lvItem = listView_AlarmEvents.Items.Add(AlarmEvent.sTimeStamp);

            lvItem.SubItems.Add(AlarmObject.RoadSideObject.sComponentId + " / " + AlarmObject.RoadSideObject.sObject);
            lvItem.SubItems.Add(AlarmEvent.sMessageId);
            lvItem.SubItems.Add(AlarmEvent.sAlarmCodeId);
            lvItem.SubItems.Add(AlarmEvent.sDirection);
            lvItem.SubItems.Add(AlarmEvent.sEvent);

            foreach (cAlarmEventReturnValue AlarmReturnValues in AlarmEvent.AlarmEventReturnValues)
            {
                lvItem.SubItems.Add(AlarmReturnValues.sName);
                lvItem.SubItems.Add(AlarmReturnValues.sValue);
            }
        }
Пример #4
0
        /*
         * private void listView_Alarms_SelectedIndexChanged(object sender, EventArgs e)
         * {
         * listView_AlarmEvents.Items.Clear();
         * if (listView_Alarms.SelectedItems.Count == 0)
         * {
         *  return;
         * }
         * cAlarmObject AlarmObject = (cAlarmObject)listView_Alarms.SelectedItems[0].Tag;
         * foreach (cAlarmEvent AlarmEvent in AlarmObject.AlarmEvents)
         * {
         *  AddAlarmEventToList(AlarmObject, listView_Alarms.SelectedItems[0], AlarmEvent);
         * }
         * }
         */

        public void AddAlarmEventToAlarmObjectAndToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            if (RSMPGS_Main.iMaxEventsPerObject <= 0)
            {
                return;
            }

            AlarmObject.AlarmEvents.Add(AlarmEvent);

            while (AlarmObject.AlarmEvents.Count > RSMPGS_Main.iMaxEventsPerObject)
            {
                listView_AlarmEvents.Items.RemoveAt(0);
            }

            AddAlarmEventToList(AlarmObject, AlarmEvent);
        }
Пример #5
0
        public void AddAlarmEventToAlarmObjectAndToList(cAlarmObject AlarmObject, cAlarmEvent AlarmEvent)
        {
            if (RSMPGS_Main.bWriteEventsContinous)
            {
                RSMPGS.SysLog.EventLog("Alarm;{0}\tMId: {1}\tComponentId: {2}\tAlarmCodeId: {3}\tDirection: {4}\tEvent: {5}",
                                       AlarmEvent.sTimeStamp, AlarmEvent.sMessageId, AlarmObject.RoadSideObject.sComponentId, AlarmEvent.sAlarmCodeId, AlarmEvent.sDirection, AlarmEvent.sEvent);
            }

            if (RSMPGS_Main.iMaxEventsPerObject <= 0)
            {
                return;
            }

            AlarmObject.AlarmEvents.Add(AlarmEvent);

            while (AlarmObject.AlarmEvents.Count > RSMPGS_Main.iMaxEventsPerObject)
            {
                listView_AlarmEvents.Items.RemoveAt(0);
            }

            AddAlarmEventToList(AlarmObject, AlarmEvent);
        }
Пример #6
0
        public void LoadProcessImageValues(RSMPGS_Main MainForm, string FileName)
        {
            bool bWeAreConnected = false;

            try
            {
                if (RSMPGS.RSMPConnection != null)
                {
                    bWeAreConnected = RSMPGS.RSMPConnection.ConnectionStatus() == cTcpSocket.ConnectionStatus_Connected;
                }

                List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>();

                //StreamReader swReferenceFile = new StreamReader((System.IO.Stream)File.OpenRead(FileName), encoding);
                //swReferenceFile.Close();

                /*
                 * [26108.AB+26108=881CG001.Passagedetektor.Passagedetektor DP1.AB+26108=881DP001.Alarms]
                 * A904.Active=True
                 *
                 * [26108.AB+26108=881CG001.Passagedetektor.Passagedetektor DP1.AB+26108=881DP001.AlarmEvents]
                 * A904.AlarmEvent_0.MessageId=f56ad0f6-7c4c-4b51-a602-8ba9fadf6ea8
                 * A904.AlarmEvent_0.TimeStamp=2011-11-16T12:52:39.437
                 * [26108.AB+26108=881CG001.Passagedetektor.Passagedetektor DP1.AB+26108=881DP001.Status]
                 * S0001.status 1.Status=10
                 */

                foreach (cRoadSideObject RoadSideObject in RSMPGS.ProcessImage.RoadSideObjects.Values)
                {
                    bool bSomeThingWasChangedInAggregatedStatus = false;

                    if (MainForm.checkBox_ProcessImageLoad_AlarmStatus.Checked)
                    {
                        foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                        {
                            string sSection   = RoadSideObject.UniqueId() + ".Alarms";
                            string sParameter = AlarmObject.sAlarmCodeId + ".Active";

                            cAlarmEvent  AlarmEvent     = null;
                            cAlarmObject NewAlarmObject = new cAlarmObject();

                            NewAlarmObject.bActive       = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + ".Active", 0) != 0;
                            NewAlarmObject.bSuspended    = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + ".Suspended", 0) != 0;
                            NewAlarmObject.bAcknowledged = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + ".Acknowledged", 0) != 0;

                            AlarmObject.AlarmEvents.Clear();

                            foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                            {
                                string sValue = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".Alarms", AlarmObject.sAlarmCodeId + "." + AlarmReturnValue.sName + ".Value", "?");

                                if (sValue != "?")
                                {
                                    AlarmReturnValue.Value.SetValue(sValue);
                                }
                            }

                            if (AlarmObject.bSuspended != NewAlarmObject.bSuspended)
                            {
                                AlarmObject.bSuspended = NewAlarmObject.bSuspended;
                                if (bWeAreConnected)
                                {
                                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Suspend);
                                }
                            }

                            if (AlarmObject.bActive != NewAlarmObject.bActive)
                            {
                                AlarmObject.bActive = NewAlarmObject.bActive;
                                if (bWeAreConnected)
                                {
                                    if (NewAlarmObject.bActive)
                                    {
                                        RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue, out AlarmEvent);
                                        if (AlarmEvent != null)
                                        {
                                            AlarmObject.AlarmEvents.Add(AlarmEvent);
                                        }
                                    }
                                    else
                                    {
                                        RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue);
                                        AlarmObject.AlarmEvents.Clear();
                                    }
                                }
                            }

                            if (AlarmObject.bAcknowledged != NewAlarmObject.bAcknowledged)
                            {
                                AlarmObject.bAcknowledged = NewAlarmObject.bAcknowledged;
                                if (bWeAreConnected)
                                {
                                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Acknowledge);
                                }
                                AlarmObject.AlarmEvents.Clear();
                            }

                            AlarmObject.AlarmCount = 0;


                            /*
                             *        sSection = sObjectUniqueId + ".AlarmEvents";
                             *
                             *        foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                             *        {
                             *          AlarmReturnValue.sValue = cPrivateProfile.GetIniFileString(FileName, sSection, AlarmObject.sAlarmCodeId + ".ReturnValue_" + AlarmReturnValue.sName + ".Value", "");
                             *        }
                             *        for (int iIndex = 0; ; iIndex++)
                             *        {
                             *          string sMsgId = cPrivateProfile.GetIniFileString(FileName, sSection, AlarmObject.sAlarmCodeId + ".AlarmEvent_" + iIndex.ToString() + ".MessageId", "");
                             *          string sTS = cPrivateProfile.GetIniFileString(FileName, sSection, AlarmObject.sAlarmCodeId + ".AlarmEvent_" + iIndex.ToString() + ".TimeStamp", "");
                             *          if (sMsgId.Length > 0)
                             *          {
                             *            cAlarmEvent AlarmEvent = new cAlarmEvent();
                             *            AlarmEvent.sMessageId = sMsgId;
                             *            AlarmEvent.sTimeStamp = sTS;
                             *            AlarmObject.AlarmEvents.Add(AlarmEvent);
                             *          }
                             *          else
                             *          {
                             *            break;
                             *          }
                             *
                             *        }
                             */
                        }
                    }

                    if (MainForm.checkBox_ProcessImageLoad_Status.Checked)
                    {
                        // Stored status
                        foreach (cStatusObject StatusObject in RoadSideObject.StatusObjects)
                        {
                            foreach (cStatusReturnValue StatusReturnValue in StatusObject.StatusReturnValues)
                            {
                                string sStatus = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".Status", StatusObject.sStatusCodeId + "." + StatusReturnValue.sName + ".Status", "?");
                                StatusReturnValue.bRecentlyChanged = false;
                                if (sStatus != "?")
                                {
                                    StatusReturnValue.bRecentlyChanged = StatusReturnValue.Value.GetValue().Equals(sStatus) ? false : true;
                                    StatusReturnValue.Value.SetValue(sStatus);
                                }
                            }
                        }
                        sS.Clear();
                        foreach (cSubscription Subscription in RoadSideObject.Subscriptions)
                        {
                            if (Subscription.SubscribeStatus == cSubscription.SubscribeMethod.OnChange || Subscription.SubscribeStatus == cSubscription.SubscribeMethod.IntervalAndOnChange)
                            {
                                if (Subscription.StatusReturnValue.bRecentlyChanged)
                                {
                                    RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
                                    s.sCI = Subscription.StatusObject.sStatusCodeId;
                                    s.n   = Subscription.StatusReturnValue.sName; // Subscription.StatusObject.StatusReturnValues .StatusReturnValues[iIndex].sName;
                                    UpdateStatusValue(ref s, Subscription.StatusReturnValue.Value.GetValueType(), Subscription.StatusReturnValue.Value.GetValue());
                                    sS.Add(s);
                                    Subscription.LastUpdate = DateTime.Now;
                                    Subscription.StatusReturnValue.bRecentlyChanged = false;
                                }
                            }
                        }

                        if (sS.Count > 0)
                        {
                            if (bWeAreConnected)
                            {
                                RSMPGS.JSon.CreateAndSendStatusUpdateMessage(RoadSideObject, sS);
                            }
                        }
                    }
                    if (MainForm.checkBox_ProcessImageLoad_AggregatedStatus.Checked)
                    {
                        if (RoadSideObject.bIsComponentGroup)
                        {
                            if (RoadSideObject.sFunctionalPosition.Equals(cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalPosition", "")) == false)
                            {
                                RoadSideObject.sFunctionalPosition     = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalPosition", "");
                                bSomeThingWasChangedInAggregatedStatus = true;
                            }
                            if (RoadSideObject.sFunctionalState.Equals(cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalState", "")) == false)
                            {
                                RoadSideObject.sFunctionalState        = cPrivateProfile.GetIniFileString(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "FunctionalState", "");
                                bSomeThingWasChangedInAggregatedStatus = true;
                            }
                            for (int iIndex = 0; iIndex < RoadSideObject.bBitStatus.GetLength(0); iIndex++)
                            {
                                if (RoadSideObject.bBitStatus[iIndex] != (cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "BitStatus_" + iIndex.ToString(), 0) != 0))
                                {
                                    RoadSideObject.bBitStatus[iIndex]      = cPrivateProfile.GetIniFileInt(FileName, RoadSideObject.UniqueId() + ".AggregatedStatus", "BitStatus_" + iIndex.ToString(), 0) != 0;
                                    bSomeThingWasChangedInAggregatedStatus = true;
                                }
                            }
                            if (bSomeThingWasChangedInAggregatedStatus)
                            {
                                if (MainForm.checkBox_AggregatedStatus_SendAutomaticallyWhenChanged.Checked)
                                {
                                    if (bWeAreConnected)
                                    {
                                        RSMPGS.JSon.CreateAndSendAggregatedStatusMessage(RoadSideObject);
                                    }
                                }
                            }
                        }
                    }

                    if (MainForm.treeView_SitesAndObjects.SelectedNode != null)
                    {
                        if (MainForm.treeView_SitesAndObjects.SelectedNode.Tag != null && MainForm.treeView_SitesAndObjects.SelectedNode.Parent != null)
                        {
                            if (RoadSideObject == (cRoadSideObject)MainForm.treeView_SitesAndObjects.SelectedNode.Tag)
                            {
                                MainForm.UpdateStatusListView(null, RoadSideObject);
                                MainForm.UpdateAlarmListView(null, RoadSideObject);
                                if (bSomeThingWasChangedInAggregatedStatus)
                                {
                                    for (int iIndex = 0; iIndex < RoadSideObject.bBitStatus.GetLength(0); iIndex++)
                                    {
                                        ListViewItem lvItem = MainForm.listView_AggregatedStatus_StatusBits.Items[iIndex];
                                        MainForm.SetStatusBitColor(lvItem, RoadSideObject.bBitStatus[iIndex]);
                                    }
                                    RSMPGS_Main.bIsCurrentlyChangingSelection = true;
                                    MainForm.listBox_AggregatedStatus_FunctionalPosition.ClearSelected();
                                    for (int iIndex = 0; iIndex < MainForm.listBox_AggregatedStatus_FunctionalPosition.Items.Count; iIndex++)
                                    {
                                        if (MainForm.listBox_AggregatedStatus_FunctionalPosition.Items[iIndex].Equals(RoadSideObject.sFunctionalPosition))
                                        {
                                            MainForm.listBox_AggregatedStatus_FunctionalPosition.SelectedIndex = iIndex;
                                        }
                                    }
                                    MainForm.listBox_AggregatedStatus_FunctionalState.ClearSelected();
                                    for (int iIndex = 0; iIndex < MainForm.listBox_AggregatedStatus_FunctionalState.Items.Count; iIndex++)
                                    {
                                        if (MainForm.listBox_AggregatedStatus_FunctionalState.Items[iIndex].Equals(RoadSideObject.sFunctionalState))
                                        {
                                            MainForm.listBox_AggregatedStatus_FunctionalState.SelectedIndex = iIndex;
                                        }
                                    }
                                    RSMPGS_Main.bIsCurrentlyChangingSelection = false;
                                }
                            }
                        }
                    }
                }


                /*
                 * listBox_AggregatedStatus_FunctionalPosition_SelectedIndexChanged(object sender, EventArgs e)
                 * listBox_AggregatedStatus_FunctionalState_SelectedIndexChanged(object sender, EventArgs e)
                 *
                 */
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Loaded Process data from '{0}'", FileName);
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to load Process data from '{0}' - {1}", FileName, e.Message);
            }
        }
Пример #7
0
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation, bool bCreateMessageOnly, out string sSendBuffer, out cAlarmEvent AlarmEvent)
        {
            sSendBuffer = "";

            RSMP_Messages.AlarmHeaderAndBody AlarmHeaderAndBody;
            //      RSMP_Messages.AlarmHeader AlarmHeader;


            AlarmHeaderAndBody = new RSMP_Messages.AlarmHeaderAndBody();

            AlarmEvent = new cAlarmEvent();

            try
            {
                AlarmHeaderAndBody.mType  = "rSMsg";
                AlarmHeaderAndBody.type   = "Alarm";
                AlarmHeaderAndBody.mId    = System.Guid.NewGuid().ToString();
                AlarmHeaderAndBody.ntsOId = AlarmObject.RoadSideObject.sNTSObjectId;
                AlarmHeaderAndBody.xNId   = AlarmObject.RoadSideObject.sExternalNTSId;
                AlarmHeaderAndBody.cId    = AlarmObject.RoadSideObject.sComponentId;
                AlarmHeaderAndBody.aCId   = AlarmObject.sAlarmCodeId;
                AlarmHeaderAndBody.xACId  = AlarmObject.sExternalAlarmCodeId;
                AlarmHeaderAndBody.xNACId = AlarmObject.sExternalNTSAlarmCodeId;
                AlarmHeaderAndBody.rvs    = new List <RSMP_Messages.AlarmReturnValue>();


                AlarmEvent.AlarmObject = AlarmObject;

                AlarmHeaderAndBody.ack = AlarmObject.bAcknowledged ? "Acknowledged" : "notAcknowledged";
                AlarmHeaderAndBody.aS  = AlarmObject.bActive ? "Active" : "inActive";
                AlarmHeaderAndBody.sS  = AlarmObject.bSuspended ? "Suspended" : "notSuspended";

                switch (alarmSpecialisation)
                {
                case AlarmSpecialisation.Issue:
                    AlarmHeaderAndBody.aSp = "Issue";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.aS;
                    break;

                case AlarmSpecialisation.Acknowledge:
                    AlarmHeaderAndBody.aSp = "Acknowledge";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.ack;
                    break;

                case AlarmSpecialisation.Suspend:
                    AlarmHeaderAndBody.aSp = "Suspend";
                    AlarmEvent.sEvent      = AlarmHeaderAndBody.aSp + " / " + AlarmHeaderAndBody.sS;
                    break;
                }

                if (AlarmObject.bActive == false && AlarmObject.bAcknowledged)
                {
                    AlarmObject.AlarmCount = 0;
                }

                if (AlarmObject.dtLastChangedAlarmStatus == DateTime.MinValue)
                {
                    AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;
                }

                AlarmHeaderAndBody.aTs = CreateISO8601UTCTimeStamp(AlarmObject.dtLastChangedAlarmStatus);
                AlarmHeaderAndBody.cat = AlarmObject.sCategory;
                AlarmHeaderAndBody.pri = AlarmObject.sPriority;

                AlarmEvent.sAlarmCodeId = AlarmObject.sAlarmCodeId;
                AlarmEvent.sDirection   = "Sent";
                AlarmEvent.sTimeStamp   = UnpackISO8601UTCTimeStamp(AlarmHeaderAndBody.aTs); // String.Format("{0:yyyy-MM-dd}T{0:HH:mm:ss.fff}", UnpackISO8601UTCTimeStamp(AlarmHeaderAndBody.aTs));
                AlarmEvent.sMessageId   = AlarmHeaderAndBody.mId;

                foreach (cAlarmReturnValue AlarmReturnValue in AlarmObject.AlarmReturnValues)
                {
                    RSMP_Messages.AlarmReturnValue rv = new RSMP_Messages.AlarmReturnValue();
                    rv.n = AlarmReturnValue.sName;
                    rv.v = AlarmReturnValue.Value.GetValue();
                    AlarmHeaderAndBody.rvs.Add(rv);
                    AlarmEvent.AlarmEventReturnValues.Add(new nsRSMPGS.cAlarmEventReturnValue(rv.n, rv.v));
                }

                sSendBuffer = JSonSerializer.SerializeObject(AlarmHeaderAndBody);

                if (bCreateMessageOnly)
                {
                    return(AlarmHeaderAndBody);
                }

                if (RSMPGS.JSon.SendJSonPacket(AlarmHeaderAndBody.type, AlarmHeaderAndBody.mId, sSendBuffer, true))
                {
                    if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeaderAndBody.type + "/" + AlarmHeaderAndBody.aSp + "/" + AlarmHeaderAndBody.aS + ", MsgId: " + AlarmHeaderAndBody.mId);//, SequenceNumber: " + AlarmHeaderAndBody.sNr);
                    }
                }
                else
                {
                    if (cHelper.IsSettingChecked("BufferAndSendAlarmsWhenConnect"))
                    {
                        cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Alarm, AlarmHeaderAndBody.type, AlarmHeaderAndBody.mId, sSendBuffer);
                        RSMPGS.MainForm.AddBufferedMessageToListAndListView(BufferedMessage);
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Buffered alarm message, AlarmCode: " + AlarmObject.sAlarmCodeId + ", Type: " + AlarmHeaderAndBody.type + "/" + AlarmHeaderAndBody.aSp + "/" + AlarmHeaderAndBody.aS + ", MsgId: " + AlarmHeaderAndBody.mId);// + ", SequenceNumber: " + AlarmHeaderAndBody.sNr);
                    }
                }

                //        RSMPGS.ProcessImage.SequenceNumber_Alarm++;
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create alarm message: {0}", e.Message);
                AlarmEvent = null;
            }

            return(AlarmHeaderAndBody);
        }
Пример #8
0
        public RSMP_Messages.AlarmHeaderAndBody CreateAndSendAlarmMessage(cAlarmObject AlarmObject, AlarmSpecialisation alarmSpecialisation, out cAlarmEvent AlarmEvent)
        {
            string sSendBuffer;

            return(CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation, false, out sSendBuffer, out AlarmEvent));
        }
Пример #9
0
        private bool DecodeAndParseAlarmMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bPacketWasProperlyHandled = false;

            try
            {
                RSMP_Messages.AlarmHeader AlarmHeader = JSonSerializer.Deserialize <RSMP_Messages.AlarmHeader>(sJSon);

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(AlarmHeader.ntsOId, AlarmHeader.cId, bUseStrictProtocolAnalysis);

                if (RoadSideObject != null)
                {
                    foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                    {
                        if (AlarmObject.sAlarmCodeId.Equals(AlarmHeader.aCId, sc))
                        {
                            cAlarmEvent AlarmEvent = new cAlarmEvent();
                            AlarmEvent.AlarmObject  = AlarmObject;
                            AlarmEvent.sDirection   = "Received";
                            AlarmEvent.sTimeStamp   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                            AlarmEvent.sMessageId   = AlarmHeader.mId;
                            AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;
                            AlarmEvent.sEvent       = AlarmHeader.aSp;

                            AlarmSpecialisation alarmSpecialisation = cJSon.AlarmSpecialisation.Unknown;

                            switch (AlarmHeader.aSp.ToLower())
                            {
                            case "acknowledge":
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Ack of alarm, AlarmCodeId: {0}", AlarmHeader.aCId);
                                AlarmObject.bAcknowledged = true;
                                alarmSpecialisation       = cJSon.AlarmSpecialisation.Acknowledge;
                                break;

                            case "suspend":
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Suspend of alarm, AlarmCodeId: {0}", AlarmHeader.aCId);
                                AlarmObject.bSuspended = true;
                                alarmSpecialisation    = cJSon.AlarmSpecialisation.Suspend;
                                break;

                            case "resume":
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Resume of alarm, AlarmCodeId: {0}", AlarmHeader.aCId);
                                AlarmObject.bSuspended = false;
                                alarmSpecialisation    = cJSon.AlarmSpecialisation.Suspend;
                                break;

                            case "request":
                                if (cHelper.IsSettingChecked("AllowRequestsOfAlarmsAndAggStatus"))
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Request of alarm status, AlarmCodeId: {0}", AlarmHeader.aCId);
                                    alarmSpecialisation = cJSon.AlarmSpecialisation.Issue;
                                }
                                else
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Request of alarm status, AlarmCodeId: {0}. RSMP settings prevent us from answering.", AlarmHeader.aCId);
                                }
                                break;
                            }

                            if (bHasSentAckOrNack == false)
                            {
                                if (alarmSpecialisation == AlarmSpecialisation.Unknown)
                                {
                                    bHasSentAckOrNack = SendPacketAck(false, packetHeader.mId, "Unknown Alarm Specialisation: " + AlarmHeader.aSp);
                                }
                                else
                                {
                                    bHasSentAckOrNack = SendPacketAck(true, packetHeader.mId, "");
                                }
                            }

                            bPacketWasProperlyHandled = true;

                            if (alarmSpecialisation != AlarmSpecialisation.Unknown)
                            {
                                if (AlarmObject.bActive == false && AlarmObject.bAcknowledged && alarmSpecialisation != AlarmSpecialisation.Unknown)
                                {
                                    AlarmObject.AlarmCount = 0;
                                }

                                if (AlarmHeader.aSp.ToLower() != "request")
                                {
                                    AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;
                                }

                                CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation);

                                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);

                                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);
                            }
                        }
                    }
                }
                if (bPacketWasProperlyHandled == false)
                {
                    sError = "Failed to handle alarm message, AlarmCodeId " + AlarmHeader.aCId + " could not be found)";
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "{0}", sError);
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to deserialize packet: {0}", e.Message);
            }

            return(bPacketWasProperlyHandled);
        }
Пример #10
0
        private void ToolStripMenuItem_SendAlarmEvent_Click(object sender, EventArgs e)
        {
            if (listView_Alarms.SelectedItems.Count == 0)
            {
                return;
            }

            ToolStripMenuItem menuitem    = (ToolStripMenuItem)sender;
            ListViewItem      lvItem      = listView_Alarms.SelectedItems[0];
            cAlarmObject      AlarmObject = (cAlarmObject)lvItem.Tag;
            cAlarmEvent       AlarmEvent  = null;

            AlarmObject.dtLastChangedAlarmStatus = DateTime.Now;

            switch (menuitem.Tag.ToString())
            {
            case "ActiveAndSend":

                AlarmObject.bActive = AlarmObject.bActive == false;
                if (AlarmObject.bActive)
                {
                    AlarmObject.AlarmCount++;
                    AlarmObject.bAcknowledged = false;
                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue, out AlarmEvent);
                }
                else
                {
                    RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Issue, out AlarmEvent);
                }
                break;

            case "AcknowledgeAndSend":

                AlarmObject.bAcknowledged = true;
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Acknowledge, out AlarmEvent);
                //JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation_Acknowledge);
                //foreach (cAlarmEvent ScanAlarmEvent in AlarmObject.AlarmEvents)
                //{
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Local ack of alarm: " + AlarmObject.sAlarmCodeId);
                //RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Local ack of alarm, TimeStamp: " + ScanAlarmEvent.sTimeStamp + ", MsgId: " + ScanAlarmEvent.sMessageId);// + ", SequenceNumber: " + ScanAlarmEvent.sSequenceNumber);
                //}
                //AlarmObject.AlarmEvents.Clear();
                //while (AlarmObject.AlarmEvents.Count > 0) AlarmObject.AlarmEvents.RemoveAt(0);
                //listView_AlarmEvents.Items.Clear();
                break;

            case "SuspendAndSend":

                AlarmObject.bSuspended = AlarmObject.bSuspended == false;
                RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation.Suspend, out AlarmEvent);
                //JSon.CreateAndSendAlarmMessage(AlarmObject, cJSon.AlarmSpecialisation_Suspend);
                break;
            }

            if (AlarmEvent != null)
            {
                AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
            }

            UpdateAlarmListView(AlarmObject);
        }
Пример #11
0
        private bool DecodeAndParseAlarmMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bPacketWasProperlyHandled = false;

            try
            {
                RSMP_Messages.AlarmHeaderAndBody AlarmHeader = JSonSerializer.Deserialize <RSMP_Messages.AlarmHeaderAndBody>(sJSon);

                if (AlarmHeader.cat != null && AlarmHeader.cat != "")
                {
                    cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(AlarmHeader.ntsOId, AlarmHeader.cId, bUseCaseSensitiveIds);
                    if (RoadSideObject != null)
                    {
                        foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                        {
                            if (AlarmObject.sAlarmCodeId.Equals(AlarmHeader.aCId, sc))
                            {
                                cAlarmEvent AlarmEvent = new cAlarmEvent();
                                AlarmEvent.AlarmObject  = AlarmObject;
                                AlarmEvent.sDirection   = "Received";
                                AlarmEvent.sTimeStamp   = UnpackISO8601UTCTimeStamp(AlarmHeader.aTs);
                                AlarmEvent.sMessageId   = AlarmHeader.mId;
                                AlarmEvent.sAlarmCodeId = AlarmHeader.aCId;

                                //foreach (cAlarmReturnValue AlarmReturnValue in AlarmHeader.rvs)
                                if (AlarmHeader.rvs != null)
                                {
                                    foreach (RSMP_Messages.AlarmReturnValue AlarmReturnValue in AlarmHeader.rvs)
                                    {
                                        AlarmEvent.AlarmEventReturnValues.Add(new cAlarmEventReturnValue(AlarmReturnValue.n, AlarmReturnValue.v));
                                    }
                                }
                                switch (AlarmHeader.aSp.ToLower())
                                {
                                case "issue":
                                    AlarmEvent.sEvent = AlarmHeader.aSp + " / " + AlarmHeader.aS;
                                    if (AlarmHeader.aS.Equals("active", StringComparison.OrdinalIgnoreCase))
                                    {
                                        AlarmObject.AlarmCount++;
                                    }
                                    bPacketWasProperlyHandled = true;
                                    break;

                                case "acknowledge":
                                    AlarmEvent.sEvent         = AlarmHeader.aSp + " / " + AlarmHeader.ack;
                                    bPacketWasProperlyHandled = true;
                                    break;

                                case "suspend":
                                    AlarmEvent.sEvent         = AlarmHeader.aSp + " / " + AlarmHeader.sS;
                                    bPacketWasProperlyHandled = true;
                                    break;

                                default:
                                    AlarmEvent.sEvent = "(unknown: " + AlarmHeader.aSp + ")";
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Warning, "Could not parse correct alarm state {0} (corresponding MsgId {1}) ", AlarmHeader.aSp, AlarmHeader.mId);
                                    break;
                                }

                                if (bPacketWasProperlyHandled)
                                {
                                    AlarmObject.bActive = AlarmHeader.aS.Equals("active", StringComparison.OrdinalIgnoreCase)
                      ? true : false;
                                    AlarmObject.bAcknowledged = AlarmHeader.ack.Equals("acknowledged", StringComparison.OrdinalIgnoreCase)
                      ? true : false;
                                    AlarmObject.bSuspended = AlarmHeader.sS.Equals("suspended", StringComparison.OrdinalIgnoreCase)
                      ? true : false;
                                    if (AlarmObject.bActive == false && AlarmObject.bAcknowledged)
                                    {
                                        AlarmObject.AlarmCount = 0;
                                    }
                                }
                                RSMPGS.MainForm.AddAlarmEventToAlarmObjectAndToList(AlarmObject, AlarmEvent);
                                RSMPGS.MainForm.UpdateAlarmListView(AlarmObject);
                                break;
                            }
                        }
                    }
                    if (bPacketWasProperlyHandled == false)
                    {
                        sError = "Failed to handle Alarm message, could not find object, ntsOId: '" + AlarmHeader.ntsOId + "', cId: '" + AlarmHeader.cId + "', aCId: '" + AlarmHeader.aCId + "'";
                    }
                }
                else
                {
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got alarm message from SCADA, aSp: {0} (corresponding MsgId {1}) ", AlarmHeader.aSp, AlarmHeader.mId);
                }
            }
            catch (Exception e)
            {
                sError = "Failed to deserialize packet: " + e.Message;
                bPacketWasProperlyHandled = false;
            }

            return(bPacketWasProperlyHandled);
        }