private void HandleSetResistance(string packet) { string bikeID = TagDecoder.GetValueByTag(Tag.ID, packet); string resistance = TagDecoder.GetValueByTag(Tag.SR, packet); this.server.WriteToSpecificErgo(bikeID, $"<{Tag.MT.ToString()}>ergo<{Tag.AC.ToString()}>resistance<{Tag.SR}>{resistance}<{Tag.EOF.ToString()}>"); }
private void HandlePacket(string packet) { //Console.WriteLine(packet); string mtValue = TagDecoder.GetValueByTag(Tag.MT, packet); if (mtValue == "doctor") { this.HandleInputDoctor(packet); } else if (mtValue == "ergo") { this.HandleInputErgo(packet); } // Fastest way to handle the data. foreach (Tag tag in (Tag[])Enum.GetValues(typeof(Tag))) { switch (mtValue) { case "data": string idValue = TagDecoder.GetValueByTag(Tag.ID, packet); string tsValue = TagDecoder.GetValueByTag(Tag.TS, packet); string pnuValue = TagDecoder.GetValueByTag(Tag.PNU, packet); this.HandleInputErgo(tag, TagDecoder.GetValueByTag(tag, packet), idValue, tsValue, pnuValue); break; // Default case should be changed to a real case x:, Will the value of mt also be an enum? >> If not should be a string / integer. } } }
private void HandleInputDoctor(string packet) { string action = TagDecoder.GetValueByTag(Tag.AC, packet); if (action == "login") { this.HandleDoctorLogin(packet); } else if (action == "emergencybrake") { this.HandleEmergencyBrake(packet); } else if (action == "brake") { this.HandleSessionStop(packet); } else if (action == "resistance") { this.HandleSetResistance(packet); } else if (action == "message") { this.HandleDoctorMessage(packet); } }
private void HandleInputErgo(string packet) { string action = TagDecoder.GetValueByTag(Tag.AC, packet); if (action == "setid") { this.HandleSetErgoID(packet); } }
private void HandleDoctorMessage(string packet) { string id = TagDecoder.GetValueByTag(Tag.ID, packet); string message = TagDecoder.GetValueByTag(Tag.DM, packet); if (id == "all") { this.server.BroadcastDoctorsMessage($"<{Tag.MT.ToString()}>ergo<{Tag.AC.ToString()}>message<{Tag.DM.ToString()}>{message}<{Tag.EOF.ToString()}>"); } else { this.server.WriteToSpecificErgo(id, $"<{Tag.MT.ToString()}>ergo<{Tag.AC.ToString()}>message<{Tag.DM.ToString()}>{message}<{Tag.EOF.ToString()}>"); } }
private void HandleDoctorLogin(string packet) { // TODO: Check if doctors password is valid string username = TagDecoder.GetValueByTag(Tag.UN, packet); string password = TagDecoder.GetValueByTag(Tag.PW, packet); if (FileWriter.CheckPassword(username, password)) { this.server.Doctor = this; this.server.Streaming = true; this.Write($"<{Tag.LR.ToString()}>true<{Tag.EOF.ToString()}>"); new Thread(new ThreadStart(this.server.StartStreamingDataToDoctor)).Start(); } }
private void HandleEmergencyBrake(string packet) { string bikeID = TagDecoder.GetValueByTag(Tag.ID, packet); this.server.WriteToSpecificErgo(bikeID, $"<{Tag.MT.ToString()}>ergo<{Tag.AC.ToString()}>emergencybrake<{Tag.EOF.ToString()}>"); }
private void HandleSessionStop(string packet) { string ergoID = TagDecoder.GetValueByTag(Tag.ID, packet); this.server.WriteToSpecificErgo(ergoID, $"<{Tag.MT.ToString()}>ergo<{Tag.AC.ToString()}>brake<{Tag.EOF.ToString()}>"); }
private void HandleSetErgoID(string packet) { this.ErgoID = TagDecoder.GetValueByTag(Tag.ID, packet); }