private void BleBikeHandler_SubscriptionValueChanged(Avans.TI.BLE.BLESubscriptionValueChangedEventArgs args) { pageConversion = new PageConversion(); pageConversion.Page10Received += (e) => { if (started) { travelledDistanceStartingValue = args.Data[7]; started = false; } int t = args.Data[7] - travelledDistanceRawPrev; if (t < 0) { t += 256; } travelledDistance += t; travelledDistanceRawPrev = (byte)travelledDistance; this.currDistance = travelledDistance - travelledDistanceStartingValue; }; pageConversion.Page19Received += (e) => { int lsb = e.Data[4]; int msb = e.Data[5]; int work1 = lsb + (msb << 8); this.currSpeed = (int)Math.Round((double)(work1 / 1000), 0); }; this.currBikeData = args.Data; pageConversion.RegisterData(args.Data.SubArray(4, args.Data.Length - 4)); }
private void ClientServerWorker_SyncDataReceived(SyncDataArgs args) { pageConversion = new PageConversion(); pageConversion.Page10Received += (e) => { byte[] internalBikeData = args.BikeData.ParseRepString(); if (started) { travelledDistanceStartingValue = internalBikeData[7]; started = false; } int t = internalBikeData[7] - travelledDistanceRawPrev; if (t < 0) { t += 256; } travelledDistance += t; travelledDistanceRawPrev = (byte)travelledDistance; this.Invoke((MethodInvoker) delegate { lblDistance.Text = $"Distance: {travelledDistance - travelledDistanceStartingValue}m"; }); }; pageConversion.Page19Received += (e) => { int lsb = e.Data[4]; int msb = e.Data[5]; int work1 = lsb + (msb << 8); int currSpeed = (int)Math.Round((double)(work1 / 1000), 0); DrawSpeedOnChart(chrtSpeedIndexCounter, currSpeed); }; byte[] bikeData = args.BikeData.ParseRepString(); byte[] heartData = args.HeartData.ParseRepString(); if (bikeData.Length > 0) { pageConversion.RegisterData(bikeData.SubArray(4, bikeData.Length - 4)); } if (heartData.Length > 0) { DrawHeartRateOnChart(chrtBpmIndexCounter, heartData[1]); } else { DrawHeartRateOnChart(chrtBpmIndexCounter, 0); } this.historyBikeData.Add(bikeData); this.historyHeartData.Add(heartData); chrtBpmIndexCounter++; chrtSpeedIndexCounter++; }
private void ConnectBike(object sender, String bikeNumber) { this.bleBikeHandler.Connect(bikeNumber, "6e40fec1-b5a3-f393-e0a9-e50e24dcca9e"); this.started = true; this.bleBikeHandler.SubscriptionValueChanged += (args) => { byte[] receivedDataSubset = args.Data.SubArray(4, args.Data.Length - 2 - 4); pageConversion.RegisterData(receivedDataSubset); }; }
private void BtnSimulator_Click(object sender, EventArgs e) { this.bleBikeHandler.ConnectSim("FietsData_4sep.txt"); this.started = true; lstBikes.Enabled = false; lstHearts.Enabled = false; btnSimulator.Enabled = false; this.bleBikeHandler.SimValueChanged += (args) => { try { this.Invoke((MethodInvoker) delegate { lblSimPercentage.Text = $"{Math.Round(args.Percentage, 1)}%"; }); } catch (ObjectDisposedException) { } byte[] receivedDataSubset = args.DataLine.SubArray(4, args.DataLine.Length - 2 - 4); pageConversion.RegisterData(receivedDataSubset); }; this.bleBikeHandler.SimEnded += () => { // SimEnded event is still invoked from the running Simulator code on an asynchronous Task this.Invoke((MethodInvoker) delegate { lstBikes.Enabled = true; lstHearts.Enabled = true; btnSimulator.Enabled = true; }); }; }
public Form1() { InitializeComponent(); users = new Dictionary <string, string>(); jsonPacketBuilder = new JsonPacketBuilder(); serverConnection = new ServerConnectionVR(); connected = false; Connect(); Simulator sim = new Simulator(@"C:\Users\kjcox\Documents\School\Periode 2.1\Proftaak\Git\RemoteHealthcare\Sprint 1\FietsData_4sep.txt"); sim.DataReceived += (args) => { try { this.Invoke((MethodInvoker) delegate { //lblSimPercentage.Text = $"{Math.Round(args.Percentage, 1)}%"; }); } catch (ObjectDisposedException) { } byte[] receivedDataSubset = args.DataLine.SubArray(4, args.DataLine.Length - 2 - 4); pageConversion.RegisterData(receivedDataSubset); }; sim.Ended += () => { // SimEnded event is still invoked from the running Simulator code on an asynchronous Task this.Invoke((MethodInvoker) delegate { //lstBikes.Enabled = true; //lstHearts.Enabled = true; //btnSimulator.Enabled = true; }); }; //TcpClient client = new TcpClient(); //client.Connect("localhost", 80); //stream = client.GetStream(); //stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null); // Console.WriteLine("login\r\nJoëlle\r\nJoëlle\r\n\r\n"); //Console.WriteLine("Do you want to make account then type account do you wanna login then type login"); //string choice = Console.ReadLine(); /*if (choice.Equals("account")) { * * Console.WriteLine("choose a name"); * string name = Console.ReadLine(); * Console.WriteLine("choose a password"); * string wachtwoord = Console.ReadLine(); * * Write("Account\r\n" + name + "\r\n" + wachtwoord); * }else if (choice.Equals("login")) * { * Console.WriteLine("your name"); * string name = Console.ReadLine(); * Console.WriteLine("your password"); * string wachtwoord = Console.ReadLine(); * * Write("login\r\n" + name + "\r\n" + wachtwoord); * } * else * { * Console.WriteLine("wrong answer"); * //Application.Restart(); * //Application.Exit(); * }*/ //string name = ""; //string wachtwoord = ""; //Write("login\r\n" + name + "\r\n" + wachtwoord + "\r\n\r\n"); ////Write("login\r\nJoëlle\r\nJoëlle\r\n\r\n"); //writeVr("12"); //while (true) //{ // string line = Console.ReadLine(); // Write($"broadcast\r\n{line}\r\n\r\n"); //} }
private async void DateTimePicker1_ValueChanged(object sender, EventArgs e) { string rawResponse = await this.serverConnection.SendWithResponse($"Doctor/GetClientHistory\r\n{this.patientId}\r\n{dateTimePicker1.Value.ToString()}"); Tuple <string[], PacketType> response = packetHandler.HandlePacket(rawResponse); if (response.Item1.Length == 3) { string rawJson = response.Item1[2]; currClientData = JsonConvert.DeserializeObject <ClientData>(rawJson); int travelledDistance = 0; for (int i = 0; i < currClientData.bikeData.Count; i++) { byte[] internalBikeData = currClientData.bikeData[i]; if (internalBikeData.Length > 0) { pageConversion = new PageConversion(); pageConversion.Page10Received += (args) => { if (started) { travelledDistanceStartingValue = internalBikeData[7]; started = false; } int t = internalBikeData[7] - travelledDistanceRawPrev; if (t < 0) { t += 256; } travelledDistance += t; travelledDistanceRawPrev = (byte)travelledDistance; travelledDistance = travelledDistance - travelledDistanceStartingValue; }; pageConversion.Page19Received += (args) => { int lsb = internalBikeData[4]; int msb = internalBikeData[5]; int work1 = lsb + (msb << 8); int currSpeed = (int)Math.Round((double)(work1 / 1000), 0); DrawSpeedOnChart(chrtSpeedIndexCounter, currSpeed); }; pageConversion.RegisterData(internalBikeData.SubArray(4, internalBikeData.Length - 4)); chrtSpeedIndexCounter++; } else { DrawSpeedOnChart(chrtSpeedIndexCounter, 0); } } for (int i = 0; i < currClientData.heartRateData.Count; i++) { byte[] internalHeartData = currClientData.bikeData[i]; if (internalHeartData.Length > 0) { DrawHeartRateOnChart(chrtBpmIndexCounter, internalHeartData[1]); } else { DrawHeartRateOnChart(chrtBpmIndexCounter, 0); } chrtBpmIndexCounter++; } } }
private static void BleBikeSim_DataReceived(DataReceivedArgs args) { byte[] receivedDataSubset = args.DataLine.SubArray(4, args.DataLine.Length - 2 - 4); pageConversion.RegisterData(receivedDataSubset); }