static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); ANPacket28 obj = new ANPacket28(); }
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { try { anPacketDecoder.bufferLength += serialPort1.Read(anPacketDecoder.buffer, anPacketDecoder.bufferLength, anPacketDecoder.buffer.Length - anPacketDecoder.bufferLength); ANPacket packet = null; while ((packet = anPacketDecoder.packetDecode()) != null) { switch (packet.id) { case ANPacket.PACKET_ID_SYSTEM_STATE: if (packet.length == 100) { ANPacket20 anPacket20 = new ANPacket20(packet); this.Invoke((MethodInvoker) delegate { richTextBox1.AppendText("Received System State Packet\n"); textBoxLatitude.Text = (anPacket20.position[0] * 180 / Math.PI).ToString(); textBoxLongitude.Text = (anPacket20.position[1] * 180 / Math.PI).ToString(); textBoxHeight.Text = anPacket20.position[2].ToString(); textBoxRoll.Text = (anPacket20.orientation[0] * 180 / Math.PI).ToString(); textBoxPitch.Text = (anPacket20.orientation[1] * 180 / Math.PI).ToString(); textBoxYaw.Text = (anPacket20.orientation[2] * 180 / Math.PI).ToString(); }); } break; case ANPacket.PACKET_ID_RAW_SENSORS: if (packet.length == 48) { ANPacket28 anPacket28 = new ANPacket28(packet); this.Invoke((MethodInvoker) delegate { richTextBox1.AppendText("Received Raw Sensors Packet\n"); }); } break; } } } catch { } }
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { try { anPacketDecoder.bufferLength += serialPort1.Read(anPacketDecoder.buffer, anPacketDecoder.bufferLength, anPacketDecoder.buffer.Length - anPacketDecoder.bufferLength); ANPacket packet = null; while ((packet = anPacketDecoder.packetDecode()) != null) { switch (packet.id) { case ANPacket.PACKET_ID_SYSTEM_STATE: if (packet.length == 100) { ANPacket20 anPacket20 = new ANPacket20(packet); this.Invoke((MethodInvoker)delegate { richTextBox1.AppendText("Received System State Packet\n"); textBoxLatitude.Text = (anPacket20.position[0] * 180 / Math.PI).ToString(); textBoxLongitude.Text = (anPacket20.position[1] * 180 / Math.PI).ToString(); textBoxHeight.Text = anPacket20.position[2].ToString(); textBoxRoll.Text = (anPacket20.orientation[0] * 180 / Math.PI).ToString(); textBoxPitch.Text = (anPacket20.orientation[1] * 180 / Math.PI).ToString(); textBoxYaw.Text = (anPacket20.orientation[2] * 180 / Math.PI).ToString(); }); } break; case ANPacket.PACKET_ID_RAW_SENSORS: if (packet.length == 48) { ANPacket28 anPacket28 = new ANPacket28(packet); this.Invoke((MethodInvoker)delegate { richTextBox1.AppendText("Received Raw Sensors Packet\n"); }); } break; } } } catch { } }
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { try { anPacketDecoder.bufferLength += serialPort1.Read(anPacketDecoder.buffer, anPacketDecoder.bufferLength, anPacketDecoder.buffer.Length - anPacketDecoder.bufferLength); ANPacket packet = null; while ((packet = anPacketDecoder.packetDecode()) != null) { switch (packet.id) { /* case ANPacket.PACKET_ID_SYSTEM_STATE: * if (packet.length == 100) * { * ANPacket20 anPacket20 = new ANPacket20(packet); * this.Invoke((MethodInvoker)delegate * { * richTextBox1.AppendText("Received System State Packet\n"); * textBoxLatitude.Text = (anPacket20.position[0] * 180 / Math.PI).ToString(); * textBoxLongitude.Text = (anPacket20.position[1] * 180 / Math.PI).ToString(); * textBoxHeight.Text = anPacket20.position[2].ToString(); * textBoxRoll.Text = (anPacket20.orientation[0] * 180 / Math.PI).ToString(); * textBoxPitch.Text = (anPacket20.orientation[1] * 180 / Math.PI).ToString(); * textBoxYaw.Text = (anPacket20.orientation[2] * 180 / Math.PI).ToString(); * }); * } * break;*/ case ANPacket.PACKET_ID_RAW_SENSORS: if (packet.length == 48) { float sum = 0f; ANPacket28 anPacket28 = new ANPacket28(packet); float[] arr = new float[1000]; List <float> arr1 = new List <float>(); List <float> arr2 = new List <float>(); List <float> arr3 = new List <float>(); this.Invoke((MethodInvoker) delegate { richTextBox1.AppendText("Received Raw Sensors Packet\n"); String mystring1 = anPacket28.accelerometers[0].ToString(); String mystring2 = anPacket28.accelerometers[1].ToString(); String mystring3 = anPacket28.accelerometers[2].ToString(); textBox1.Text = (mystring1); textBox3.Text = (mystring2); textBox4.Text = (mystring3); String mystring4 = anPacket28.gyroscopes[0].ToString(); String mystring5 = anPacket28.gyroscopes[1].ToString(); String mystring6 = anPacket28.gyroscopes[2].ToString(); textBox2.Text = (mystring4); textBox5.Text = (mystring5); textBox6.Text = (mystring6); String mystring7 = anPacket28.magnetometers[0].ToString(); String mystring8 = anPacket28.magnetometers[1].ToString(); String mystring9 = anPacket28.magnetometers[2].ToString(); textBox9.Text = (mystring7); textBox8.Text = (mystring8); textBox7.Text = (mystring9); String mystring10 = anPacket28.pressure.ToString(); textBox10.Text = (mystring10); String mystring11 = anPacket28.pressureTemperature.ToString(); textBox11.Text = (mystring11); //Thread.Sleep(90); /* if (anPacket28.pressureTemperature == 0) * Console.WriteLine("Come Out"); * else * { * * * Console.WriteLine("AVG =" + arr.Average()); * * * }*/ //arr.Add(anPacket28.magnetometers[0]); /* for(int i=0;i<1000;i++) * { * arr[i] = anPacket28.magnetometers[0]; * sum =sum +arr[i]; * } * float avg = sum / 1000; * Console.WriteLine("Avg ="+(sum / 1000)); * * Console.WriteLine("Count =" + arr[20]);*/ for (int i = 0; i < 1000; i++) { arr1.Add(anPacket28.magnetometers[0]); sum = arr1.Sum(); } float avg = (sum / arr1.Count); Console.WriteLine(arr1.Count); String mystr = avg.ToString(); textBox16.Text = mystr; /* float avg = (sum / 500); * Console.WriteLine(arr1.Count); * * * * String mystr = avg.ToString(); * textBox16.Text = mystr;*/ }); } break; case ANPacket.PACKET_ID_SYSTEM_STATE: if (packet.length == 100) { ANPacket20 anPacket20 = new ANPacket20(packet); this.Invoke((MethodInvoker) delegate { richTextBox1.AppendText("Received System State Packet\n"); textBoxLatitude.Text = (anPacket20.position[0] * 180 / Math.PI).ToString(); textBoxLongitude.Text = (anPacket20.position[1] * 180 / Math.PI).ToString(); textBoxHeight.Text = anPacket20.position[2].ToString(); textBoxRoll.Text = (anPacket20.orientation[0] * 180 / Math.PI).ToString(); textBoxPitch.Text = (anPacket20.orientation[1] * 180 / Math.PI).ToString(); textBoxYaw.Text = (anPacket20.orientation[2] * 180 / Math.PI).ToString(); String mystring1 = anPacket20.position[0].ToString(); textBox15.Text = mystring1; String mystring2 = anPacket20.position[1].ToString(); textBox17.Text = mystring2; String mystring3 = anPacket20.position[2].ToString(); textBox18.Text = mystring3; String mystring4 = anPacket20.velocity[0].ToString(); String mystring5 = anPacket20.velocity[1].ToString(); String mystring6 = anPacket20.velocity[2].ToString(); textBox12.Text = mystring4; textBox13.Text = mystring5; textBox14.Text = mystring6; }); } break; } } } catch { } }