From d6da6b18c417aad5c89ade350136fd39b0acecd2 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 7 Oct 2020 16:40:41 +0200 Subject: [PATCH] added value update to panel and adjusted speed to match, only need to display speed with 1 decimal --- Client/Client.cs | 21 +++++++++++++++++++++ Client/EngineConnection.cs | 35 ++++++++++++++++++++++++++++------- RH-Engine/Command.cs | 14 ++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/Client/Client.cs b/Client/Client.cs index 008c09d..f7ae1cc 100644 --- a/Client/Client.cs +++ b/Client/Client.cs @@ -208,6 +208,14 @@ namespace Client throw new ArgumentNullException("no bytes"); } byte[] message = DataParser.GetRawDataMessage(bytes); + + if (engineConnection.Connected && engineConnection.FollowingRoute) + { + engineConnection.BikeBPM = bytes[1]; + engineConnection.UpdateInfoPanel(); + } + + this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } @@ -226,6 +234,19 @@ namespace Client throw new ArgumentNullException("no bytes"); } byte[] message = DataParser.GetRawDataMessage(bytes); + switch (bytes[0]) + { + case 0x10: + + engineConnection.BikeSpeed = (bytes[4] | (bytes[5] << 8)) * 0.01f; + break; + case 0x19: + engineConnection.BikePower = (bytes[5]) | (bytes[6] & 0b00001111) << 8; + break; + } + if (engineConnection.Connected && engineConnection.FollowingRoute) + engineConnection.UpdateInfoPanel(); + this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); } diff --git a/Client/EngineConnection.cs b/Client/EngineConnection.cs index 5a89713..9d0d4e5 100644 --- a/Client/EngineConnection.cs +++ b/Client/EngineConnection.cs @@ -37,6 +37,11 @@ namespace Client private static string bikeId = string.Empty; private static string headId = string.Empty; + public float BikeSpeed { get; set; } + public float BikePower { get; set; } + public float BikeBPM { get; set; } + public float BikeResistance { get; set; } + public bool FollowingRoute = false; private static NetworkStream stream; @@ -48,7 +53,10 @@ namespace Client EngineConnection() { - + BikeSpeed = 0; + BikePower = 0; + BikeBPM = 0; + BikeResistance = 50; } /// @@ -193,11 +201,9 @@ namespace Client { panelId = JSONParser.getPanelID(message); + WriteTextMessage(mainCommand.ColorPanel(panelId)); - WriteTextMessage(mainCommand.ClearPanel(panelId)); - - - showPanel(mainCommand, 5.3, 83, 52, 53); + UpdateInfoPanel(); while (cameraId == string.Empty) { } SetFollowSpeed(5.0f); @@ -205,8 +211,17 @@ namespace Client }); } - private void showPanel(Command mainCommand, double bikeSpeed, int bpm, int power, int resistance) + public void UpdateInfoPanel() { + ShowPanel(BikeSpeed, (int)BikeBPM, (int)BikePower, (int)BikeResistance); + WriteTextMessage(mainCommand.RouteSpeed(BikeSpeed, bikeId)); + WriteTextMessage(mainCommand.RouteSpeed(BikeSpeed, cameraId)); + } + + public void ShowPanel(double bikeSpeed, int bpm, int power, int resistance) + { + WriteTextMessage(mainCommand.ClearPanel(panelId)); + SendMessageAndOnResponse(mainCommand.showBikespeed(panelId, "bikeSpeed", bikeSpeed), "bikeSpeed", (message) => { @@ -252,7 +267,13 @@ namespace Client /// the code to be executed upon reveiving a reply from the server with the specified serial public void SendMessageAndOnResponse(string message, string serial, HandleSerial action) { - serialResponses.Add(serial, action); + if (serialResponses.ContainsKey(serial)) + { + serialResponses[serial] = action; + } else + { + serialResponses.Add(serial, action); + } WriteTextMessage(message); } diff --git a/RH-Engine/Command.cs b/RH-Engine/Command.cs index ba8a6c0..18a93ec 100644 --- a/RH-Engine/Command.cs +++ b/RH-Engine/Command.cs @@ -424,6 +424,20 @@ namespace RH_Engine return JsonConvert.SerializeObject(Payload(payload)); } + public string RouteSpeed(float speedValue,string nodeID) + { + dynamic payload = new + { + id = "route/follow/speed", + data = new + { + node = nodeID, + speed = speedValue + } + }; + return JsonConvert.SerializeObject(Payload(payload)); + } + public string RoadCommand(string uuid_route) { Console.WriteLine("road");