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); } }
public cStatusReturnValue(cStatusObject StatusObject, string sCompleteRow, ref int iIndex) { this.StatusObject = StatusObject; sName = cHelper.Item(sCompleteRow, iIndex++, ';').Trim(); if (IsValid()) { string sType = cHelper.Item(sCompleteRow, iIndex++, ';').Trim(); string sValueRange = cHelper.Item(sCompleteRow, iIndex++, ';').Trim(); string sCommentFromFile = cHelper.Item(sCompleteRow, iIndex++, ';').Trim(); sComment = sCommentFromFile.Replace("\"", "").Replace("\n", " / ").Trim(); string sValueTypeKey = StatusObject.sObjectType + "\t" + "alarms" + "\t" + StatusObject.sStatusCodeId + "\t" + StatusObject.sSpecificObject + "\t" + sName; RSMPGS.ProcessImage.CreateAndAddValueTypeObject(sValueTypeKey, sName, sType, sValueRange, sComment); Value = new cValue(sValueTypeKey, true); } }
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; }
public cStatusReturnValue(cStatusObject ParentStatusObject) { StatusObject = ParentStatusObject; }
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); }
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); } }
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); }