Exemplo n.º 1
0
        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()}>");
        }
Exemplo n.º 2
0
        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.
                }
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        private void HandleInputErgo(string packet)
        {
            string action = TagDecoder.GetValueByTag(Tag.AC, packet);

            if (action == "setid")
            {
                this.HandleSetErgoID(packet);
            }
        }
Exemplo n.º 5
0
        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()}>");
            }
        }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
        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()}>");
        }
Exemplo n.º 8
0
        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()}>");
        }
Exemplo n.º 9
0
 private void HandleSetErgoID(string packet)
 {
     this.ErgoID = TagDecoder.GetValueByTag(Tag.ID, packet);
 }