public override void Update() { serialCommunicator.SendMessage("ST"); string data = serialCommunicator.ReadInput(); data = data.Replace("\r", ""); string[] dataSplitted = data.Split('\t'); BikeData bikeData = new BikeData( int.Parse(dataSplitted[0]), int.Parse(dataSplitted[1]), dataSplitted[2], int.Parse(dataSplitted[3]), int.Parse(dataSplitted[4]), int.Parse(dataSplitted[5]), dataSplitted[6], int.Parse(dataSplitted[7])); if (RecordedData.Count == 0) { RecordedData.Add(bikeData); } else if (RecordedData.Last().Time != bikeData.Time) { RecordedData.Add(bikeData); } client.SendMessage(bikeData); SetDataToGUI(); }
public void SetDataToGUI() { BikeData bikeData = RecordedData.Last(); try { console.Invoke((MethodInvoker) delegate { // Running on the UI thread console.SetPulse(bikeData.Pulse.ToString()); console.SetRoundMin(bikeData.Rpm.ToString()); console.SetSpeed(bikeData.Speed.ToString()); console.SetDistance((bikeData.Distance * 100).ToString()); console.SetResistance(bikeData.Resistance.ToString()); console.SetEnergy(bikeData.Energy.ToString()); console.SetTime(((bikeData.Time < TimeSpan.Zero) ? "-" : "") + bikeData.Time.ToString(@"mm\:ss")); console.SetWatt(bikeData.Power.ToString()); console.SetDisplay(bikeData.Pulse, bikeData.Speed, bikeData.Distance, bikeData.Rpm, bikeData.Resistance, bikeData.Energy, bikeData.Time.ToString(), bikeData.Power); }); } catch (InvalidOperationException e) { System.Console.WriteLine(e.StackTrace); } catch (InvalidAsynchronousStateException e) { System.Console.WriteLine(e.StackTrace); } }
public void SendMessage(BikeData data) { NetworkStream stream = client.GetStream(); byte[] buffer; string json = JsonConvert.SerializeObject(data); byte[] prefixArray = BitConverter.GetBytes(json.Length); byte[] requestArray = Encoding.Default.GetBytes(json); buffer = new Byte[prefixArray.Length + json.Length]; prefixArray.CopyTo(buffer, 0); requestArray.CopyTo(buffer, prefixArray.Length); stream.Write(buffer, 0, buffer.Length); }
public override void Update() { serialCommunicator.SendMessage("ST"); string data = serialCommunicator.ReadInput(); data = data.Replace("\r", ""); string[] dataSplitted = data.Split('\t'); BikeData bikeData = new BikeData( int.Parse(dataSplitted[0]), int.Parse(dataSplitted[1]), dataSplitted[2], int.Parse(dataSplitted[3]), int.Parse(dataSplitted[4]), int.Parse(dataSplitted[5]), dataSplitted[6], int.Parse(dataSplitted[7])); if (RecordedData.Count == 0) { RecordedData.Add(bikeData); } else if (RecordedData.Last().Time != bikeData.Time) { RecordedData.Add(bikeData); } latestData = RecordedData.Last(); FormAstrand.setAll(latestData.Time.ToString(), latestData.Speed, latestData.Resistance, latestData.Energy, latestData.Power, latestData.Pulse, latestData.Rpm); RpmCheck(latestData.Rpm); SetDataToGUI(); AstradAvans(); client.SendMessage(new { id = "update", data = new { bikeData = bikeData } }); }