Exemple #1
0
		public bool InterpreteRawDataToReadable(LogLinePair currentLogLinePair)
		{
			//here we need a big, big table to translate all the data in CAN DB...
			
			bool gotTheMsgTranslated = false;
			
			foreach(Object[] msgMapItem in MSG_FRAME_MAP)
			{				
				String canMsgName = (String)msgMapItem[INDEX_MSG];
				if(canMsgName.Equals(currentLogLinePair.CanMessageName))
				{
					int frameByteLength = (int)msgMapItem[INDEX_LENGTH]; //TODO: delete this field, it's not used. (redundant information)
					int dataIndex = 1; //TODO: ugly hard-coded: assortedLogLine contains its raw data from [1] to [8].
					currentLogLinePair.InitializeTransalatedLogLine();
					for(int mapIndex = INDEX_DATAFIELD_START; mapIndex < msgMapItem.Length; mapIndex += 1)
					{
						DataField dataField = (DataField)msgMapItem[mapIndex];
						String fieldName = dataField.FieldName;
						int fieldLength = dataField.FieldDataLength;
						
						String hexStr = String.Join("", currentLogLinePair.AssortedLogLine.ToArray(), dataIndex, fieldLength);
						dataIndex += fieldLength;
						
						String fieldData;
						if(fieldName.EndsWith("Bit"))
						{
							fieldData = HexConverter.HexStrToBinStr(hexStr);
						}
						else
						{
							fieldData = HexConverter.HexStrToDecInt(hexStr).ToString();
						}
						currentLogLinePair.ComposeTranslatedLogLine(new DataField(fieldName, fieldData));
					}
					gotTheMsgTranslated = true;
					break;
				}
				else
				{
					//Try next map item.
				}
			}
			
			return gotTheMsgTranslated;
		}
Exemple #2
0
		void ToolTip_OpenLogFileClick(object sender, EventArgs e)
		{			
			OpenFileDialog openFileDialog = new OpenFileDialog();
			if(openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				InitializeElements();
				
				if(!openFileDialog.FileName.Equals(this.LastLogFileName))
				{
					LastLogFileName = (String)openFileDialog.FileName.Clone();
					this.LogList.Clear();
					
					// Read raw log strings from the file
					System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName);	
					String rawLogLine = null;
					Char[] delimiterChars = {' ', ',', ';', '\t'};
					while((rawLogLine = sr.ReadLine()) != null)
					{
						String[] splitLogLine = new String(rawLogLine.ToCharArray()).Split(delimiterChars);
						LogList.Add(splitLogLine);
					}
					sr.Close();					
					
					this.LogFilePath.Text = openFileDialog.FileName;
					Debug.Log(String.Format("Opening Log File Complete ({0} lines, {1} items)", LogList.Count, ((object[])LogList[0]).Length));
					
					// Configure parsor
					this.RawLogItemConfigList.Clear();
					String[] sampleLogLine = (String[])LogList[0]; // Keep a sample line to let the user configure parsing rule.
					RawLogItemConfiguratorWindow configWindow = new RawLogItemConfiguratorWindow();
					RawLogItemConfigList = configWindow.GenerateConfigurationList(sampleLogLine).GetConfigurationList();
				}
				

				// Determine log line range to translate
				int fromLineNum, toLineNum;
				DetermineLogLineRangeToTranslate(1, LogList.Count, out fromLineNum, out toLineNum);
//				fromLineNum = 21105;
//				toLineNum = 21126;
				
				// Parse raw log strings
				CanMsgFinder canLookupTables = new CanMsgFinder();
				Debug.Log("Start parsing log file: " + openFileDialog.SafeFileName);
				for(int logLineIndex = fromLineNum-1; logLineIndex < toLineNum; logLineIndex += 1)
				{
					String[] aLogLine = (String[])LogList[logLineIndex];
					
					LogLinePair aLogLinePair = new LogLinePair(logLineIndex+1);
					bool logItemSearchResult = aLogLinePair.CreateAssortedLogLineItems(aLogLine, RawLogItemConfigList);
					if(logItemSearchResult == false)
					{
						return;
					}
					canLookupTables.FindMsgNameFrom(aLogLinePair);
					
					Debug.Log("Line#"+(logLineIndex+1) + ": " + aLogLinePair.CanMessageName
					              + ((aLogLinePair.TargetBankId > 0) ? ", TargetBankId="+aLogLinePair.TargetBankId : ""));
					
					//Now we have the unique message name. Go parsing. (we should have parsing rule based on msg frame interpreter)
					MsgFrameInterpreter frameInterpreter = new MsgFrameInterpreter();
					frameInterpreter.InterpreteRawDataToReadable(aLogLinePair);
					
					LogLinePairList.Add(aLogLinePair);
				}
				Debug.Log("Complete parsing log file: " + openFileDialog.SafeFileName);
				Debug.Log("Raw log line count = " + LogList.Count);
				Debug.Log("Translated log line count = " + LogLinePairList.Count);
				
				// Display LogLines in DataGridView
				List<String> rawLineRow = new List<String>();
				List<String> translatedLineRow = new List<String>();
				foreach(LogLinePair aLogLinePair in LogLinePairList)
				{
					rawLineRow.Clear();
					translatedLineRow.Clear();
					int lineIndex = aLogLinePair.LineIndex;
					String timestamp = "";
					rawLineRow.Add(lineIndex.ToString());
					rawLineRow.Add(timestamp);
					rawLineRow.AddRange(aLogLinePair.AssortedLogLine.ToArray());
					LogLineViewRaw.Rows.Add(rawLineRow.ToArray());
					
					translatedLineRow.Add(lineIndex.ToString());
					translatedLineRow.AddRange(aLogLinePair.TranslatedLogData);
					LogLineViewTranslated.Rows.Add(translatedLineRow.ToArray());
				}
				this.LogLineViewRaw.Visible = true;
				this.LogLineViewTranslated.Visible = true;
				this.CurrentlySelectedRow = 0;

			}
		}
Exemple #3
0
		//
		// Returns: true if successfully found, false otherwise.
		//
		public bool FindMsgNameFrom(LogLinePair currentLogLinePair)
		{
			String[] assortedRawMessageLine = currentLogLinePair.AssortedLogLine.ToArray();
			
			MakeMessageTidy(assortedRawMessageLine);
			
			foreach(String[] canMsgItem in CAN_MSG_TABLE)
			{
				bool gotTheMsg = false;
				String canMsgName = null;
				
				if(canMsgItem[INDEX_CANID].Equals(assortedRawMessageLine[INDEX_RAW_CANID]))
				{
					gotTheMsg = GetMsgNameIfPossible(canMsgItem, assortedRawMessageLine, out canMsgName);
				}				
				else if(canMsgItem[INDEX_CANID].Equals(assortedRawMessageLine[INDEX_RAW_CANID].Substring(0, 2)))
				{
					gotTheMsg = GetMsgNameIfPossible(canMsgItem, assortedRawMessageLine, out canMsgName);
					
					if(gotTheMsg)
					{
						int targetBankId = 0;
						bool result = Int32.TryParse(assortedRawMessageLine[INDEX_RAW_CANID].Substring(2, 1), out targetBankId);	//TODO: The case with Bank of more than 9(0x09) is not considered yet.
						if(!result)
						{
							Debug.ErrorBox(assortedRawMessageLine[INDEX_RAW_CANID] + " contains invalid Bank ID.");
							return false; //routine stops in case of invalid Bank ID is detected. since msg already matched, no further lookup needed for this log line.
						}
						currentLogLinePair.TargetBankId = targetBankId; //bankID is updated only when msg name matches and id parsing was successful.
					}
				}
				else
				{
					//this msg item doesn't match the input raw data.
				}
				
				if(gotTheMsg)
				{
					currentLogLinePair.TxRx = canMsgItem[INDEX_TXRX];
					if("TX".Equals(canMsgItem[INDEX_TXRX]))
					{
						LastTxMessage = canMsgName; //save last Tx message for subsequent Rx determination.
						//TODO: to be perfect, LastTxMessage should be a List<String> to correspond to multiple banks.
					}
					currentLogLinePair.CanMessageName = canMsgName;
					return true;
				}
				else
				{
					//let's check the next canMsgItem...
				}
			}
			
			Debug.ErrorBox(assortedRawMessageLine[INDEX_RAW_CANID] + " is not valid CAN ID.");
			return false; //routine failed to find matching msg item in the whole list.
		}