Пример #1
0
        public void CloneFromStatusObject(cStatusObject StatusObjectToCopy)
        {
            RoadSideObject  = StatusObjectToCopy.RoadSideObject;
            sObjectType     = StatusObjectToCopy.sObjectType;
            sSpecificObject = StatusObjectToCopy.sSpecificObject;
            sDescription    = StatusObjectToCopy.sDescription;
            sStatusCodeId   = StatusObjectToCopy.sStatusCodeId;

            StatusReturnValues.Clear();

            foreach (cStatusReturnValue StatusReturnValue in StatusObjectToCopy.StatusReturnValues)
            {
                cStatusReturnValue NewStatusReturnValue = new cStatusReturnValue(this);
                NewStatusReturnValue.StatusObject = StatusReturnValue.StatusObject;
                NewStatusReturnValue.sName        = StatusReturnValue.sName;
                NewStatusReturnValue.sComment     = StatusReturnValue.sComment;
                NewStatusReturnValue.Value        = new cValue(StatusReturnValue.Value.ValueTypeObject, true);

#if _RSMPGS2
                NewStatusReturnValue.sLastUpdateRate     = StatusReturnValue.sLastUpdateRate;
                NewStatusReturnValue.bLastUpdateOnChange = StatusReturnValue.bLastUpdateOnChange;
                NewStatusReturnValue.sQuality            = StatusReturnValue.sQuality;
#endif
                StatusReturnValues.Add(NewStatusReturnValue);
            }
        }
Пример #2
0
        private void button_StatusReq_Send_Click(object sender, EventArgs e)
        {
            List <cStatusReturnValue> lSelectedStatus = new List <cStatusReturnValue>();
            int i = 0;

            foreach (cStatusObject StatusObject in RoadSideObject.StatusObjects)
            {
                foreach (cStatusReturnValue StatusArguments in StatusObject.StatusReturnValues)
                {
                    if (this.dataGridView_Status.Rows[i].Cells[0].Value != null &&
                        (bool)this.dataGridView_Status.Rows[i].Cells[0].Value == true)
                    {
                        cStatusReturnValue StatusReturnValue = new cStatusReturnValue();
                        StatusReturnValue.sName            = StatusArguments.sName;
                        StatusReturnValue.sStatusCommandId = StatusArguments.sStatusCommandId;
                        StatusReturnValue.sType            = StatusArguments.sType;

                        if (bStatReq)
                        {
                            // Status Request
                        }
                        else if (bStatSub)
                        {
                            // Status subscribe
                            if (this.dataGridView_Status.Rows[i].Cells[this.dataGridView_Status.ColumnCount - 1].Value == null ||
                                this.dataGridView_Status.Rows[i].Cells[this.dataGridView_Status.ColumnCount - 1].Value.ToString().Trim().Length == 0)
                            {
                                MessageBox.Show("Can´t send message with empty value!");
                                return;
                            }

                            StatusReturnValue.sLastUpdateRate = this.dataGridView_Status.Rows[i].Cells[this.dataGridView_Status.ColumnCount - 1].Value.ToString().Trim();
                            StatusArguments.sLastUpdateRate   = StatusReturnValue.sLastUpdateRate;
                        }
                        else
                        {
                            // Status unsubscribe
                            StatusArguments.sLastUpdateRate = null;
                        }
                        lSelectedStatus.Add(StatusReturnValue);
                    }
                    i++;
                }
            }
            if (lSelectedStatus.Count > 0)
            {
                selectedStatus = lSelectedStatus;
                Close();
            }
            else
            {
                MessageBox.Show("No Status is selected!");
            }
        }
Пример #3
0
        public cSubscription(cStatusObject sO, cStatusReturnValue sS, float fUpdateRate, bool bAlwaysSendOnChange)
        {
            if (fUpdateRate <= 0)
            {
                SubscribeStatus = SubscribeMethod.OnChange;
                UpdateRate      = 0;
            }
            else
            {
                try
                {
                    UpdateRate = (int)fUpdateRate * 1000;
                }
                catch
                {
                    UpdateRate = 0;
                }

                // Interval 0 -> Always on change
                // > 0 could be borh interval and on change
                if (UpdateRate == 0)
                {
                    SubscribeStatus = SubscribeMethod.OnChange;
                }
                else
                {
                    if (bAlwaysSendOnChange)
                    {
                        SubscribeStatus = SubscribeMethod.IntervalAndOnChange;
                    }
                    else
                    {
                        SubscribeStatus = SubscribeMethod.Interval;
                    }
                }
            }
            LastUpdate        = DateTime.Now;
            StatusObject      = sO;
            StatusReturnValue = sS;
        }
Пример #4
0
        private void ToolStripMenuItem_Status_Click(object sender, EventArgs e)
        {
            cRoadSideObject RoadSideObject = null;

            bool bAlwaysUpdateOnChange = false;

            cJSon.StatusMsgType statusMsgType;

            ToolStripMenuItem menuitem = (ToolStripMenuItem)sender;

            string sUpdateRate = "";

            if (menuitem.Equals(ToolStripMenuItem_StatusRequest))
            {
                statusMsgType = cJSon.StatusMsgType.Request;
            }
            else if (menuitem.Equals(ToolStripMenuItem_StatusUnsubscribe))
            {
                statusMsgType = cJSon.StatusMsgType.UnSubscribe;
            }
            else if (menuitem.Equals(ToolStripMenuItem_StatusSubscribe_UpdateOnChangeOnly))
            {
                bAlwaysUpdateOnChange = true;
                sUpdateRate           = "0";
                statusMsgType         = cJSon.StatusMsgType.Subscribe;
            }
            else if (menuitem.Equals(ToolStripMenuItem_StatusSubscribe_UpdateOnInterval_Manually) || menuitem.Equals(ToolStripMenuItem_StatusSubscribe_UpdateOnChangeAndInterval_Manually))
            {
                if (cFormsHelper.InputBox("Enter Update Rate (seconds)", "UpdateRate:", ref sUpdateRate, false, true) != DialogResult.OK)
                {
                    return;
                }
                if (sUpdateRate == "")
                {
                    return;
                }
                bAlwaysUpdateOnChange = menuitem.OwnerItem.Equals(ToolStripMenuItem_StatusSubscribe_UpdateOnChangeAndInterval);
                statusMsgType         = cJSon.StatusMsgType.Subscribe;
            }
            else
            {
                sUpdateRate           = menuitem.Tag.ToString();
                bAlwaysUpdateOnChange = menuitem.OwnerItem.Equals(ToolStripMenuItem_StatusSubscribe_UpdateOnChangeAndInterval);
                statusMsgType         = cJSon.StatusMsgType.Subscribe;
            }

            // Each group belongs to a RoadSide object
            foreach (ListViewGroup lvGroup in listView_Status.Groups)
            {
                RoadSideObject = null;

                List <RSMP_Messages.StatusSubscribe_Status_Over_3_1_4> StatusSubscribeValues = new List <RSMP_Messages.StatusSubscribe_Status_Over_3_1_4>();

                foreach (ListViewItem lvItem in lvGroup.Items)
                {
                    if (lvItem.Selected)
                    {
                        cStatusReturnValue StatusReturnValue = (cStatusReturnValue)lvItem.Tag;

                        if (RoadSideObject == null)
                        {
                            RoadSideObject = StatusReturnValue.StatusObject.RoadSideObject;
                        }

                        RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 statusSubscribe_Status = new RSMP_Messages.StatusSubscribe_Status_Over_3_1_4();

                        statusSubscribe_Status.sCI = StatusReturnValue.StatusObject.sStatusCodeId;
                        statusSubscribe_Status.n   = StatusReturnValue.sName;

                        if (statusMsgType == cJSon.StatusMsgType.Subscribe)
                        {
                            statusSubscribe_Status.uRt = sUpdateRate;
                            statusSubscribe_Status.sOc = bAlwaysUpdateOnChange;
                        }
                        else
                        {
                            statusSubscribe_Status.uRt = null;
                            statusSubscribe_Status.sOc = false;
                        }

                        StatusReturnValue.sLastUpdateRate     = statusSubscribe_Status.uRt;
                        StatusReturnValue.bLastUpdateOnChange = statusSubscribe_Status.sOc;

                        StatusSubscribeValues.Add(statusSubscribe_Status);
                    }
                }

                if (StatusSubscribeValues.Count == 0 || RoadSideObject == null)
                {
                    continue;
                }


                switch (statusMsgType)
                {
                case cJSon.StatusMsgType.Subscribe:
                    RSMPGS.JSon.CreateAndSendSubscriptionMessage(RoadSideObject, StatusSubscribeValues);
                    break;

                case cJSon.StatusMsgType.Request:
                    RSMPGS.JSon.CreateAndSendStatusMessage(RoadSideObject, StatusSubscribeValues, "StatusRequest");
                    break;

                case cJSon.StatusMsgType.UnSubscribe:
                    RSMPGS.JSon.CreateAndSendStatusMessage(RoadSideObject, StatusSubscribeValues, "StatusUnsubscribe");
                    break;

                default:
                    return;
                }
            }
        }
Пример #5
0
        private bool DecodeAndParseStatusMessage(RSMP_Messages.Header packetHeader, StatusMsgType statusMsgType, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = true;

            // Values to return
            List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>();

            try
            {
                // StatusSubscribe, StatusUnsubscribe and StatusRequest are very much alike, differns by the uRt property only
                RSMP_Messages.StatusSubscribe_Over_3_1_4 StatusSubscribe = JSonSerializer.Deserialize <RSMP_Messages.StatusSubscribe_Over_3_1_4>(sJSon);

                foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribe_Status in StatusSubscribe.sS)
                {
                    if (StatusSubscribe_Status.sCI == null)
                    {
                        sError = "StatusCode Id (sCI) in " + packetHeader.type + " is missing";
                        return(false);
                    }
                }

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(StatusSubscribe.ntsOId, StatusSubscribe.cId, bUseCaseSensitiveIds);

                if (RoadSideObject != null)
                {
                    foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribe_Status in StatusSubscribe.sS)
                    {
                        RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
                        s.sCI = StatusSubscribe_Status.sCI;
                        s.n   = StatusSubscribe_Status.n;
                        s.s   = null;
                        // 3.1.1 = unknown
                        //s.q = "unknown";
                        // 3.1.2 = undefined ??
                        s.q = "undefined";
                        // Find status in object
                        cStatusObject      StatusObject      = RoadSideObject.StatusObjects.Find(x => x.sStatusCodeId.Equals(StatusSubscribe_Status.sCI, sc));
                        cStatusReturnValue StatusReturnValue = null;
                        if (StatusObject != null)
                        {
                            StatusReturnValue = StatusObject.StatusReturnValues.Find(x => x.sName.Equals(StatusSubscribe_Status.n, sc));
                        }
                        if (StatusReturnValue != null)
                        {
                            RSMPGS.ProcessImage.UpdateStatusValue(ref s, StatusReturnValue.Value.GetValueType(), StatusReturnValue.Value.GetValue());
                            switch (statusMsgType)
                            {
                            case StatusMsgType.Request:
                                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got status request (NTSObjectId: {0}, ComponentId: {1}, StatusCodeId: {2}, Name: {3}, Status: {4})", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusObject.sStatusCodeId, StatusReturnValue.sName, StatusReturnValue.Value.GetValue());
                                break;

                            case StatusMsgType.UnSubscribe:
                            case StatusMsgType.Subscribe:
                                // Delete subscription if it already exists
                                foreach (cSubscription Subscription in RoadSideObject.Subscriptions)
                                {
                                    if (Subscription.StatusReturnValue == StatusReturnValue)
                                    {
                                        RoadSideObject.Subscriptions.Remove(Subscription);
                                        break;
                                    }
                                }
                                if (statusMsgType == StatusMsgType.Subscribe)
                                {
                                    string sUpdateRate = StatusSubscribe_Status.uRt;
                                    float  fUpdateRate = 0;
                                    float.TryParse(StatusSubscribe_Status.uRt, out fUpdateRate);
                                    if (fUpdateRate == 0)
                                    {
                                        float.TryParse(StatusSubscribe_Status.uRt.Replace('.', ','), out fUpdateRate);
                                    }
                                    bool bAlwaysSendOnChange = StatusSubscribe_Status.sOc;
                                    RoadSideObject.Subscriptions.Add(new cSubscription(StatusObject, StatusReturnValue, fUpdateRate, bAlwaysSendOnChange));
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got status subscribe (NTSObjectId: {0}, ComponentId: {1}. StatusCodeId: {2}, Name: {3}, Status: {4})", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusObject.sStatusCodeId, StatusReturnValue.sName, StatusReturnValue.Value.GetValue());
                                }
                                else
                                {
                                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Got status unsubscribe, removed subscription (NTSObjectId: {0}, ComponentId: {1}. StatusCodeId: {2}, Name: {3}, Status: {4})", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusObject.sStatusCodeId, StatusReturnValue.sName, StatusReturnValue.Value.GetValue());
                                }
                                break;
                            }
                        }
                        if (s.s == null)
                        {
                            RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Got status request/subscribe, failed to update StatusCodeId or Object (could be unknown value) (NTSObjectId: {0}, ComponentId: {1}, StatusCodeId: {2}))", StatusSubscribe.ntsOId, StatusSubscribe.cId, StatusSubscribe_Status.sCI);
                        }

                        sS.Add(s);
                    }
                }
                else
                {
                    // Failed, fill return list with 'unknown'
                    foreach (RSMP_Messages.StatusSubscribe_Status_Over_3_1_4 StatusSubscribe_Status in StatusSubscribe.sS)
                    {
                        RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
                        s.sCI = StatusSubscribe_Status.sCI;
                        s.n   = StatusSubscribe_Status.n;
                        s.s   = null;
                        // 3.1.1 = unknown
                        //s.q = "unknown";
                        // 3.1.2 = undefined ??
                        s.q = "undefined";
                        sS.Add(s);
                    }
                    RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Got status message, failed to find object (NTSObjectId: {0}, ComponentId: {1})", StatusSubscribe.ntsOId, StatusSubscribe.cId);
                }

                if (statusMsgType != StatusMsgType.UnSubscribe)
                {
                    // Response message
                    RSMP_Messages.StatusResponse StatusResponse = new RSMP_Messages.StatusResponse();
                    // Send response to client
                    StatusResponse.mType  = "rSMsg";
                    StatusResponse.type   = (statusMsgType == StatusMsgType.Subscribe) ? "StatusUpdate" : "StatusResponse";
                    StatusResponse.mId    = System.Guid.NewGuid().ToString();
                    StatusResponse.ntsOId = StatusSubscribe.ntsOId;
                    StatusResponse.xNId   = StatusSubscribe.xNId;
                    StatusResponse.cId    = StatusSubscribe.cId;
                    StatusResponse.sTs    = CreateISO8601UTCTimeStamp();
                    StatusResponse.sS     = sS;
                    string sSendBuffer = JSonSerializer.SerializeObject(StatusResponse);
                    if (bHasSentAckOrNack == false)
                    {
                        bHasSentAckOrNack = SendPacketAck(true, packetHeader.mId, "");
                    }
                    RSMPGS.JSon.SendJSonPacket(StatusResponse.type, StatusResponse.mId, sSendBuffer, true);
                    if (RSMPGS.MainForm.checkBox_ViewOnlyFailedPackets.Checked == false)
                    {
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Info, "Sent StatusResponse message, Type: " + StatusResponse.type + ", MsgId: " + StatusResponse.mId);
                    }
                }
            }
            catch (Exception e)
            {
                sError   = "Failed to deserialize packet: " + e.Message;
                bSuccess = false;
            }

            return(bSuccess);
        }
Пример #6
0
        private void button_BufferedMessages_CreateRandom_Click(object sender, EventArgs e)
        {
            if (comboBox_BufferedMessages_CreateRandom_Type.SelectedIndex < 0)
            {
                return;
            }

            int iMessageCount;

            if (Int32.TryParse(textBox_CreateRandomMessages_Count.Text, out iMessageCount) == false || iMessageCount > 30000)
            {
                MessageBox.Show("Invalid number or too many messages (>30000)", "Create buffered messages", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (iMessageCount <= 0)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();

            List <cAlarmObject>       AlarmObjects                    = new List <cAlarmObject>();
            List <cStatusReturnValue> StatusReturnValues              = new List <cStatusReturnValue>();
            List <cStatusReturnValue> ValidStatusReturnValues         = new List <cStatusReturnValue>();
            List <cRoadSideObject>    AggregatedStatusRoadSideObjects = new List <nsRSMPGS.cRoadSideObject>();

            foreach (cRoadSideObject RoadSideObject in RSMPGS.ProcessImage.RoadSideObjects.Values)
            {
                AlarmObjects.AddRange(RoadSideObject.AlarmObjects);
                foreach (cStatusObject StatusObject in RoadSideObject.StatusObjects)
                {
                    StatusReturnValues.AddRange(StatusObject.StatusReturnValues);
                    ValidStatusReturnValues.AddRange(StatusObject.StatusReturnValues.FindAll(srv => srv.Value.Quality == cValue.eQuality.recent));
                }
                if (RoadSideObject.bIsComponentGroup)
                {
                    AggregatedStatusRoadSideObjects.Add(RoadSideObject);
                }
            }

            Random rnd = new Random();

            ListView_BufferedMessages.StopSorting();
            ListView_BufferedMessages.BeginUpdate();

            //  RSMPGS.ProcessImage.AggregatedStatusObjects
            string sSendBuffer;

            for (int iIndex = 0; iIndex < iMessageCount; iIndex++)
            {
                switch (comboBox_BufferedMessages_CreateRandom_Type.SelectedIndex)
                {
                case 0:

                    if (AlarmObjects.Count > 0)
                    {
                        cAlarmObject AlarmObject = AlarmObjects[rnd.Next(0, AlarmObjects.Count - 1)];
                        cJSon.AlarmSpecialisation        alarmSpecialisation = new cJSon.AlarmSpecialisation[] { cJSon.AlarmSpecialisation.Acknowledge, cJSon.AlarmSpecialisation.Issue, cJSon.AlarmSpecialisation.Suspend }[rnd.Next(0, 2)];
                        RSMP_Messages.AlarmHeaderAndBody alarmHeaderAndBody  = RSMPGS.JSon.CreateAndSendAlarmMessage(AlarmObject, alarmSpecialisation, true, out sSendBuffer);
                        cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Alarm, alarmHeaderAndBody.type, alarmHeaderAndBody.mId, sSendBuffer);
                        AddBufferedMessageToListAndListView(BufferedMessage);
                    }
                    break;

                case 1:

                    if (AggregatedStatusRoadSideObjects.Count > 0)
                    {
                        cRoadSideObject RoadSideObject = AggregatedStatusRoadSideObjects[rnd.Next(0, AggregatedStatusRoadSideObjects.Count - 1)];
                        RSMP_Messages.AggregatedStatus aggregatedStatus = RSMPGS.JSon.CreateAndSendAggregatedStatusMessage(RoadSideObject, true, out sSendBuffer);
                        cBufferedMessage BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.AggregatedStatus, aggregatedStatus.type, aggregatedStatus.mId, sSendBuffer);
                        AddBufferedMessageToListAndListView(BufferedMessage);
                    }
                    break;

                case 2:

                    if (StatusReturnValues.Count > 0)
                    {
                        cStatusReturnValue StatusReturnValue = StatusReturnValues[rnd.Next(0, StatusReturnValues.Count - 1)];
                        List <RSMP_Messages.Status_VTQ> sS   = new List <RSMP_Messages.Status_VTQ>();
                        RSMP_Messages.Status_VTQ        s    = new RSMP_Messages.Status_VTQ();
                        s.sCI = StatusReturnValue.StatusObject.sStatusCodeId;
                        s.n   = StatusReturnValue.sName;
                        s.q   = StatusReturnValue.Value.Quality.ToString();
                        s.s   = StatusReturnValue.Value.Quality == cValue.eQuality.unknown ? null : StatusReturnValue.Value.GetValue();
                        sS.Add(s);

                        RSMP_Messages.StatusUpdate statusUpdate    = RSMPGS.JSon.CreateAndSendStatusUpdateMessage(StatusReturnValue.StatusObject.RoadSideObject, sS, true, out sSendBuffer);
                        cBufferedMessage           BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Status, statusUpdate.type, statusUpdate.mId, sSendBuffer);
                        AddBufferedMessageToListAndListView(BufferedMessage);
                    }
                    break;

                case 3:

                    if (ValidStatusReturnValues.Count > 0)
                    {
                        cStatusReturnValue StatusReturnValue = ValidStatusReturnValues[rnd.Next(0, ValidStatusReturnValues.Count - 1)];
                        List <RSMP_Messages.Status_VTQ> sS   = new List <RSMP_Messages.Status_VTQ>();
                        RSMP_Messages.Status_VTQ        s    = new RSMP_Messages.Status_VTQ();
                        s.sCI = StatusReturnValue.StatusObject.sStatusCodeId;
                        s.n   = StatusReturnValue.sName;
                        s.q   = StatusReturnValue.Value.Quality.ToString();
                        s.s   = StatusReturnValue.Value.Quality == cValue.eQuality.unknown ? null : StatusReturnValue.Value.GetValue();
                        sS.Add(s);

                        RSMP_Messages.StatusUpdate statusUpdate    = RSMPGS.JSon.CreateAndSendStatusUpdateMessage(StatusReturnValue.StatusObject.RoadSideObject, sS, true, out sSendBuffer);
                        cBufferedMessage           BufferedMessage = new cBufferedMessage(cBufferedMessage.eMessageType.Status, statusUpdate.type, statusUpdate.mId, sSendBuffer);
                        AddBufferedMessageToListAndListView(BufferedMessage);
                    }
                    break;
                }

                //cBufferedMessage
                //AddBufferedMessageToListAndListView(cBufferedMessage BufferedMessage)
            }

            ListView_BufferedMessages.EndUpdate();
            ListView_BufferedMessages.ResumeSorting();

            Cursor.Current = Cursors.Default;
        }
Пример #7
0
        private void listView_Status_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListView     listview = (ListView)sender;
            ListViewItem lvItem;

            if (listview.SelectedItems.Count == 0)
            {
                return;
            }

            lvItem = listview.SelectedItems[0];
            cStatusReturnValue StatusReturnValue = (cStatusReturnValue)lvItem.Tag;
            cStatusObject      StatusObject      = StatusReturnValue.StatusObject;

            try
            {
                string sText = StatusReturnValue.Value.GetValue();
                if (cFormsHelper.InputStatusBoxValueType("Enter new status", ref sText, StatusReturnValue.Value, StatusReturnValue.sComment, true) == DialogResult.OK)
                {
                    StatusReturnValue.Value.SetValue(sText);
                    lvItem.SubItems[4].Text = sText;
                    // Find out if this status is subscribed
                    foreach (cSubscription Subscription in StatusObject.RoadSideObject.Subscriptions)
                    {
                        if (Subscription.StatusReturnValue == StatusReturnValue)
                        {
                            if (Subscription.SubscribeStatus == cSubscription.SubscribeMethod.OnChange || Subscription.SubscribeStatus == cSubscription.SubscribeMethod.IntervalAndOnChange)
                            {
                                List <RSMP_Messages.Status_VTQ> sS = new List <RSMP_Messages.Status_VTQ>();
                                RSMP_Messages.Status_VTQ        s  = new RSMP_Messages.Status_VTQ();
                                s.sCI = StatusObject.sStatusCodeId;
                                s.n   = StatusReturnValue.sName;
                                RSMPGS.ProcessImage.UpdateStatusValue(ref s, StatusReturnValue.Value.GetValueType(), StatusReturnValue.Value.GetValue());
                                sS.Add(s);
                                RSMPGS.JSon.CreateAndSendStatusUpdateMessage(StatusObject.RoadSideObject, sS);
                            }
                        }
                    }
                }
            }
            catch
            {
            }


            /*
             * int iSelectedColumn = 0;
             *
             * if (listview.SelectedItems.Count == 0)
             * {
             * return;
             * }
             *
             * lvItem = listview.SelectedItems[0];
             *
             * ListViewHitTestInfo lvHitTest = listview.HitTest(LastMouseX, LastMouseY);
             *
             * foreach (ListViewItem.ListViewSubItem ScanSubItem in lvItem.SubItems)
             * {
             * if (lvHitTest.SubItem == ScanSubItem)
             * {
             *  break;
             * }
             * iSelectedColumn++;
             * }
             *
             * try
             * {
             *                        // Tag is ex Status_2
             * if (listview.Columns[iSelectedColumn].Tag.ToString().StartsWith("Status", StringComparison.OrdinalIgnoreCase))
             * {
             *  string sType = lvItem.SubItems[iSelectedColumn - 1].Text;
             *  string sText = lvHitTest.SubItem.Text;
             *                                int iIndex = Int32.Parse(listview.Columns[iSelectedColumn].Tag.ToString().Substring(7));
             *  if (cFormsHelper.InputBox("Enter new status", "Status", ref sText, sType.Equals("base64", StringComparison.OrdinalIgnoreCase), true) == DialogResult.OK)
             *  {
             *                                        cStatusObject StatusObject = (cStatusObject)lvItem.Tag;
             *    StatusObject.StatusReturnValues[iIndex].sStatus = sText;
             *    lvHitTest.SubItem.Text = sText;
             *    // Find out if this status is subscribed
             *    foreach (cSubscription Subscription in StatusObject.RoadSideObject.Subscriptions)
             *    {
             *      if (Subscription.StatusReturnValue == StatusObject.StatusReturnValues[iIndex])
             *      {
             *        if (Subscription.SubscribeStatus == cSubscription.Subscribe_OnChange)
             *        {
             *          List<RSMP_Messages.Status_VTQ> sS = new List<RSMP_Messages.Status_VTQ>();
             *          RSMP_Messages.Status_VTQ s = new RSMP_Messages.Status_VTQ();
             *          s.sCI = StatusObject.sStatusCodeId;
             *          s.n = StatusObject.StatusReturnValues[iIndex].sName;
             *          RSMPGS.ProcessImage.UpdateStatusValue(ref s, StatusObject.StatusReturnValues[iIndex].sType, StatusObject.StatusReturnValues[iIndex].sStatus);
             *          sS.Add(s);
             *                                                                RSMPGS.JSon.CreateAndSendStatusUpdateMessage(StatusObject.RoadSideObject, sS);
             *        }
             *      }
             *    }
             * }
             * }
             * }
             * catch
             * {
             * }
             */
        }
        public void LoadProcessImageValues(string FileName)
        {
            try
            {
                if (!File.Exists(FileName))
                {
                    var hFile = File.Create(FileName);
                    hFile.Close();
                }
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to create file {0}", e.Message, FileName);
            }

            try
            {
                StreamReader swReferenceFile = new StreamReader((System.IO.Stream)File.OpenRead(FileName), Encoding.UTF8);


                string sLine;

                while ((sLine = swReferenceFile.ReadLine()) != null)
                {
                    cRoadSideObject RoadSideObject;
                    sLine = sLine.Trim();
                    if (sLine.StartsWith(";") || sLine.Length == 0 || sLine.StartsWith("["))
                    {
                        continue;
                    }
                    try
                    {
                        RoadSideObject = RSMPGS.JSon.JSonSerializer.Deserialize <cRoadSideObject>(sLine);
                    }
                    catch
                    {
                        continue;
                    }

                    cRoadSideObject gRoadSide = cHelper.FindRoadSideObject(RoadSideObject.sNTSObjectId, RoadSideObject.sComponentId, false);

                    if (gRoadSide != null)
                    {
                        gRoadSide.bBitStatus = RoadSideObject.bBitStatus;

                        //foreach (cAlarmEvent AlarmEvent in RoadSideObject.AlarmEvents)
                        //{
                        //	gRoadSide.AlarmEvents.Add(AlarmEvent);
                        //}
                        foreach (cCommandEvent CommandEvent in RoadSideObject.CommandEvents)
                        {
                            gRoadSide.CommandEvents.Add(CommandEvent);
                        }
                        foreach (cStatusEvent StatusEvent in RoadSideObject.StatusEvents)
                        {
                            gRoadSide.StatusEvents.Add(StatusEvent);
                        }
                        foreach (cAggregatedStatusEvent AggregatedStatusEvent in RoadSideObject.AggregatedStatusEvents)
                        {
                            gRoadSide.AggregatedStatusEvents.Add(AggregatedStatusEvent);
                        }
                        foreach (cStatusObject StatusObject in RoadSideObject.StatusObjects)
                        {
                            if (StatusObject.StatusReturnValues != null && StatusObject.StatusReturnValues.Count > 0)
                            {
                                cStatusObject StatusObject2 = gRoadSide.getStatusObject(StatusObject.sStatusCodeId); // .StatusReturnValues[0].sStatusCommandId);
                                if (StatusObject2 != null)
                                {
                                    foreach (cStatusReturnValue StatusReturnValues in StatusObject.StatusReturnValues)
                                    {
                                        cStatusReturnValue StatusReturnValues2 = StatusObject2.getStatusReturnValueByName(StatusReturnValues.sName);
                                        if (StatusReturnValues2 != null)
                                        {
                                            StatusReturnValues2.sLastUpdateRate     = StatusReturnValues.sLastUpdateRate;
                                            StatusReturnValues2.bLastUpdateOnChange = StatusReturnValues.bLastUpdateOnChange;
                                            StatusReturnValues2.Value.SetValue(StatusReturnValues.Value.GetValue());
                                            StatusReturnValues2.sQuality = StatusReturnValues.sQuality;
                                        }
                                    }
                                }
                            }
                        }
                        //foreach (cAlarmObject AlarmObject in RoadSideObject.AlarmObjects)
                        //{
                        //    cAlarmObject AlarmObject2 = gRoadSide.getAlarmObject(AlarmObject.sAlarmCodeId);
                        //    if (AlarmObject2 != null)
                        //    {
                        //        AlarmObject2.bAcknowledged = AlarmObject.bAcknowledged;
                        //        AlarmObject2.bActive = AlarmObject.bActive;
                        //        AlarmObject2.bSuspended = AlarmObject.bSuspended;
                        //    }
                        //}

                        foreach (cCommandObject CommandObject in RoadSideObject.CommandObjects)
                        {
                            if (CommandObject.CommandReturnValues != null && CommandObject.CommandReturnValues.Count > 0)
                            {
                                cCommandObject CommandObject2 = gRoadSide.getCommandObject(CommandObject.sCommandCodeId);
                                if (CommandObject2 != null)
                                {
                                    foreach (cCommandReturnValue CommandReturnValue in CommandObject.CommandReturnValues)
                                    {
                                        cCommandReturnValue CommandReturnValue2 = CommandObject2.getCommandReturnValueByName(CommandReturnValue.sName);
                                        if (CommandReturnValue2 != null)
                                        {
                                            CommandReturnValue2.sLastRecAge   = CommandReturnValue.sLastRecAge;
                                            CommandReturnValue2.sLastRecValue = CommandReturnValue.sLastRecValue;
                                            CommandReturnValue2.sAge          = CommandReturnValue.sAge;
                                            CommandReturnValue2.Value.SetValue(CommandReturnValue.Value.GetValue());
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //System.Windows.Forms.MessageBox.Show("Did not find roadside object");
                    }
                }

                swReferenceFile.Close();
            }
            catch (Exception e)
            {
                RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, "Failed to open file {0}", e.Message, FileName);
            }
        }
Пример #9
0
        private bool DecodeAndParseStatusMessage(RSMP_Messages.Header packetHeader, string sJSon, bool bUseStrictProtocolAnalysis, bool bUseCaseSensitiveIds, ref bool bHasSentAckOrNack, ref string sError)
        {
            StringComparison sc = bUseCaseSensitiveIds ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

            bool bSuccess = false;

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

                cRoadSideObject RoadSideObject = cHelper.FindRoadSideObject(StatusResponse.ntsOId, StatusResponse.cId, bUseCaseSensitiveIds);

                foreach (RSMP_Messages.Status_VTQ Reply in StatusResponse.sS)
                {
                    cStatusObject StatusObject = RoadSideObject.StatusObjects.Find(x => x.sStatusCodeId.Equals(Reply.sCI, sc));

                    if (StatusObject == null)
                    {
                        continue;
                    }

                    cStatusReturnValue StatusReturnValue = StatusObject.StatusReturnValues.Find(x => x.sName.Equals(Reply.n, sc));

                    if (StatusReturnValue == null)
                    {
                        continue;
                    }

                    if (StatusReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                    {
                        if (RSMPGS.MainForm.ToolStripMenuItem_StoreBase64Updates.Checked)
                        {
                            StatusReturnValue.Value.SetValue(RSMPGS.SysLog.StoreBase64DebugData(Reply.s));
                        }
                        else
                        {
                            StatusReturnValue.Value.SetValue("base64");
                        }
                    }
                    else
                    {
                        StatusReturnValue.Value.SetValue(Reply.s);
                    }
                    StatusReturnValue.sQuality = Reply.q;

                    if (ValidateTypeAndRange(StatusReturnValue.Value.GetValueType(), Reply.s))
                    {
                        bSuccess = true;
                    }
                    else
                    {
                        string sStatusValue;
                        if (Reply.s == null)
                        {
                            sStatusValue = "(null)";
                        }
                        else
                        {
                            sStatusValue = (Reply.s.Length < 10) ? Reply.s : Reply.s.Substring(0, 9) + "...";
                        }
                        sError = "Value and/or type is out of range or invalid for this RSMP protocol version, type: " + StatusReturnValue.Value.GetValueType() + ", quality: " + StatusReturnValue.sQuality + ", statusvalue: " + sStatusValue;
                        RSMPGS.SysLog.SysLog(cSysLogAndDebug.Severity.Error, sError);
                    }

                    cStatusEvent StatusEvent = new cStatusEvent();
                    StatusEvent.sTimeStamp       = UnpackISO8601UTCTimeStamp(StatusResponse.sTs);
                    StatusEvent.sMessageId       = StatusResponse.mId;
                    StatusEvent.sEvent           = "Received status";
                    StatusEvent.sStatusCommandId = Reply.sCI;
                    StatusEvent.sName            = Reply.n;
                    if (StatusReturnValue.Value.GetValueType().Equals("base64", StringComparison.OrdinalIgnoreCase))
                    {
                        StatusEvent.sStatus = "base64";
                    }
                    else
                    {
                        StatusEvent.sStatus = Reply.s;
                    }
                    StatusEvent.sQuality = Reply.q;
                    if (RSMPGS_Main.bWriteEventsContinous)
                    {
                        RSMPGS.SysLog.EventLog("Status;{0}\tMId: {1}\tComponentId: {2}\tStatusCommandId: {3}\tName: {4}\tStatus: {5}\tQuality: {6}\tUpdateRate: {7}\tUpdateOnChange: {8}\tEvent: {9}",
                                               StatusEvent.sTimeStamp, StatusEvent.sMessageId, StatusResponse.cId, StatusEvent.sStatusCommandId,
                                               StatusEvent.sName, StatusEvent.sStatus, StatusEvent.sQuality, StatusEvent.sUpdateRate, StatusEvent.bUpdateOnChange, StatusEvent.sEvent);
                    }
                    RoadSideObject.StatusEvents.Add(StatusEvent);
                    RSMPGS.MainForm.HandleStatusListUpdate(RoadSideObject, StatusEvent, false);
                }
            }
            catch (Exception e)
            {
                sError   = "Failed to deserialize packet: " + e.Message;
                bSuccess = false;
            }
            return(bSuccess);
        }