/// <summary> /// Update all the widgets related to the FuelCellDataPoint object /// </summary> /// <param name="fuelCellDataPoint"></param> private void updateFuelCellWidgets(FuelCellDataPoint fuelCellDataPoint) { Console.WriteLine("Updating Fuel Cell Widgets"); try { Console.WriteLine("Voltage - " + fuelCellDataPoint.voltage, ", current - " + fuelCellDataPoint.current + ", watt - " + fuelCellDataPoint.watt + ", energy - " + fuelCellDataPoint.energy + ", temp1 - " + fuelCellDataPoint.temperatures[0] + ", temp2 - " + fuelCellDataPoint.temperatures[1] + ", temp3 - " + fuelCellDataPoint.temperatures[2] + ", temp4 - " + fuelCellDataPoint.temperatures[3] + ", pressure - " + fuelCellDataPoint.pressure + ", status - " + fuelCellDataPoint.status); } catch { } DateTime now = DateTime.Now; SetAxisLimits(now); setFuelCellStatus(fuelCellDataPoint.status); updateVoltageValues(fuelCellDataPoint.voltage, now); updateCurrentValues(fuelCellDataPoint.current, now); updateWattValues(fuelCellDataPoint.watt, now); updateEnergyValues(fuelCellDataPoint.energy, now); updateTemperaturesValues(fuelCellDataPoint.temperatures, now); updatePressureValues(fuelCellDataPoint.pressure); }
/// <summary> /// Converts raw string into a FuelCellDataPoint object /// </summary> /// <param name="rawString"></param> /// <returns></returns> public static FuelCellDataPoint ParseFuelCellData(string rawString) { Console.WriteLine("ParseFuelCellData() called"); float voltage = 0f; float current = 0f; float energy = 0f; float[] temperatures = new float[] { 0f, 0f, 0f, 0f }; float pressure = 0f; float watt = 0f; string status = "No status"; string groundStationTimeStamp = ""; if (rawString != null && rawString.Length != 0) { // Split up the incoming raw string up at the space character (should get 15 substrings) string[] splitStrings = rawString.Split(' '); // Get current, try { string temp = splitStrings[1].Trim(); int length = temp.Length; current = float.Parse(temp.Substring(0, length - 1), CultureInfo.InvariantCulture.NumberFormat); // Length - 1 in order to get rid of the 'A' char } catch { } // Get Watt try { string temp = splitStrings[2].Trim(); int length = temp.Length; watt = float.Parse(temp.Substring(0, length - 1), CultureInfo.InvariantCulture.NumberFormat); // Length - 1 in order to get rid of the 'W' char } catch { } // Get Energy try { string temp = splitStrings[3].Trim(); int length = temp.Length; energy = float.Parse(temp.Substring(0, length - 2), CultureInfo.InvariantCulture.NumberFormat); // Length - 2 in order to get rid of the 'Wh' char } catch { } // Get the 4 temperatures try { for (int i = 0; i < 4; i++) { string temp = splitStrings[i + 4].Trim(); int length = temp.Length; temperatures[i] = float.Parse(temp.Substring(0, length - 1), CultureInfo.InvariantCulture.NumberFormat); // Length - 1 in order to get rid of the 'C' char } } catch { } // Get the pressure try { string temp = splitStrings[8].Trim(); int length = temp.Length; pressure = float.Parse(temp.Substring(0, length - 1), CultureInfo.InvariantCulture.NumberFormat); // Length - 1 in order to get rid of the 'B' char } catch { } // Get the voltage try { string temp = splitStrings[9].Trim(); int length = temp.Length; voltage = float.Parse(temp.Substring(0, length - 1), CultureInfo.InvariantCulture.NumberFormat); // Length - 1 in order to get rid of the 'V' char } catch { } try { status = splitStrings[11].Trim(); } catch { } try { groundStationTimeStamp = DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss").Trim(); } catch { } } FuelCellDataPoint fuelCellDataPoint = new FuelCellDataPoint(0, voltage, current, watt, energy, temperatures, pressure, status); fuelCellDataPoint.groundStationTimeStamp = groundStationTimeStamp; return(fuelCellDataPoint); }