private void SerialDataReceived(Measurement m)
 {
     Controller.RunClient();
     var packet = new SerialDataPacket(m, Username);
     Send(packet);
     Controller.ReceiveTransmissionAsync();
 }
        private void HandleSerialDataPacket(JObject json)
        {
            Console.WriteLine("Handle SerialData Packet");
            var packet = new SerialDataPacket(json);

            var PatientUsername = Authentication.GetAllUsers()
                .Where(user => user.Username == packet.PatientUsername)
                .Select(user => user.Username).FirstOrDefault();

            ClientDataHandler.ReturnValue returnVal = _clientDataHandler.AddMeasurementToLastBikeTest(packet.Measurement);
            if (returnVal == ClientDataHandler.ReturnValue.NotStarted)
            {
#if DEBUG
                Console.WriteLine("Error: Tried to add measurement while BikeTest was not started of patient {0}", Authentication.GetUser(packet.PatientUsername).Nickname);
#endif
            }
            else
            {
#if DEBUG
                Console.WriteLine("Error: General error occured while tried to add measurement of patient {0}", Authentication.GetUser(packet.PatientUsername).Nickname);
#endif
            }

            //Generate PushPacket
            Packet pushPacket = new SerialDataPushPacket(packet.Measurement, packet.PatientUsername);

            // Determining the sockets to send the pushpacket (to send to all online doctors) 
            SendToAllOnlineDoctors(pushPacket);
#if DEBUG
            Console.WriteLine(packet);
#endif
        }