/// <summary> /// Converts raw string into a SpeedDataPoint object /// </summary> /// <param name="rawString"></param> /// <returns></returns> public static SpeedDataPoint ParseSpeedometerData(string rawString) { Console.WriteLine("ParseSpeedometerData() called"); int timeStamp; float speed; SpeedDataPoint speedDataPoint; string groundStationTimeStamp = ""; if (rawString != null && rawString.Length != 0) { // Split up the incoming raw string up at the tab character (should get 3 substrings) string[] splitStrings = rawString.Trim().Split(' '); Console.WriteLine("Number of split strings - " + splitStrings.Length); foreach (string s in splitStrings) { Console.WriteLine("ss - " + s); } // Parse the time stamp from string HEX into Int32 try { timeStamp = Convert.ToInt32(splitStrings[2].Trim(), 16); } catch { timeStamp = 0; } // Parse the Speed (km/h) string into float try { /* var culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); * culture.NumberFormat.NumberDecimalSeparator = "."; */// The parse uses the culture settings by default -- some places use comma as seperator like 5,2 to represent 5.2 speed = float.Parse(splitStrings[4].Trim(), CultureInfo.InvariantCulture.NumberFormat); } catch { speed = 0f; } speedDataPoint = new SpeedDataPoint(timeStamp, speed); try { groundStationTimeStamp = DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss").Trim(); } catch { } } else { speedDataPoint = new SpeedDataPoint(0, 0); speedDataPoint.groundStationTimeStamp = groundStationTimeStamp; } Console.WriteLine("Parsed SpeedDataPoint object, TimeStamp - " + speedDataPoint.timeStamp + ", Speed - " + speedDataPoint.getSpeed()); return(speedDataPoint); }
/// <summary> /// Update all the widgets related to the SpeedDataPoint object /// </summary> /// <param name="speedDataPoint"></param> private void updateSpeedWidgets(SpeedDataPoint speedDataPoint) { Console.WriteLine("Updating Speed Widgets"); Console.WriteLine(" Speed - " + speedDataPoint.getSpeed()); updateSpeedValues(speedDataPoint.getSpeed()); }