private void bnOpen_Click(object sender, EventArgs e) { Settings.BaudRate = Convert.ToInt32(cbBaudRate.Text); Settings.PortName = cbCommPort.Text; SP = new CommProtocol(Settings.PortName, Settings.BaudRate, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One, 1000, this); SP.ResponseTimeout += new CommProtocol.ResponseTimeoutEventHandler(SP_ResponseTimeout); SP.ExpectedResponseReceived += new CommProtocol.ExpectedResponseReceivedEventHandler(SP_ExpectedResponseReceived); }
void ComProt_ExpectedResponseReceived(object sender, CommProtocol.ExpectedResponseReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; }
void ComProt_BatteryStatusPacketReceived(object sender, CommProtocol.BatteryStatusPacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; BattStat = e.BattStat; BatteryVoltageGauge.Value = BattStat.Voltage; BatteryTemperatureGauge.Value = BattStat.Temperature; BatteryCurrentGauge.Value = BattStat.CurrentDraw; }
void cp_AttitudePacketReceived(object sender, CommProtocol.AttitudePacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; attitude = e.attitude; textBox1.AppendText("Attitude packet received: PITCH: " + attitude.Pitch + " ROLL: " + attitude.Roll + " YAW: " + attitude.Yaw + "\r\n"); if (!ManualMode) { InsertRowToReceived_packetsTable("Attitude", "PITCH: " + attitude.Pitch + " ROLL: " + attitude.Roll + " YAW: " + attitude.Yaw); } }
void SP_ResponseTimeout(object sender, CommProtocol.ResponseTimeoutEventArgs e) { string hexbuffer = ""; foreach (char c in e.BufferContents) { hexbuffer += string.Format("{0:x2} ", (int)c); } /*bad_text += hexbuffer + "\r\n";*/ txt_bad.Text += hexbuffer + "\r\n"; }
private void btnConnect_Click(object sender, EventArgs e) { if (ComProt == null) { ComProt = new CommProtocol( cbxComPortSelect.SelectedItem.ToString(), 19200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One, 500, this); if (ComProt.SerialPortOpen) { //event handlers ComProt.LocationPacketReceived += new CommProtocol.LocationPacketReceivedEventHandler(ComProt_LocationPacketReceived); ComProt.BadPacketReceived += new CommProtocol.BadPacketReceivedEventHandler(ComProt_BadPacketReceived); ComProt.OnBoardErrorPacketReceived += new CommProtocol.OnBoardErrorPacketReceivedEventHandler(ComProt_OnBoardErrorPacketReceived); ComProt.ResponseTimeout += new CommProtocol.ResponseTimeoutEventHandler(ComProt_ResponseTimeout); ComProt.BatteryStatusPacketReceived += new CommProtocol.BatteryStatusPacketReceivedEventHandler(ComProt_BatteryStatusPacketReceived); ComProt.HeadingSpeedAltitudePacketReceived += new CommProtocol.HeadingSpeedAltitudePacketReceivedEventHandler(ComProt_HeadingSpeedAltitudePacketReceived); ComProt.AttitudePacketReceived += new CommProtocol.AttitudePacketReceivedEventHandler(ComProt_AttitudePacketReceived); ComProt.ExpectedResponseReceived += new CommProtocol.ExpectedResponseReceivedEventHandler(ComProt_ExpectedResponseReceived); ComProt.HandShakeAckReceived += new CommProtocol.HandShakeAckReceivedEventHandler(ComProt_HandShakeAckReceived); ComProt.PreFlightPacketReceived += new CommProtocol.PreFlightPacketReceivedEventHandler(ComProt_PreFlightPacketReceived); ComProt.MotorRPMPacketReceived += new CommProtocol.MotorRPMPacketReceivedEventHandler(ComProt_MotorRPMPacketReceived); RequestInfoTimer.Start(); } else { ComProt.Dispose(); } } }
void ComProt_PreFlightPacketReceived(object sender, CommProtocol.PreFlightPacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; pfp = e.PFP; }
void ComProt_MotorRPMPacketReceived(object sender, CommProtocol.MotorRPMPacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; RPM = e.RPM; RPMGauge.Value = RPM; }
void cp_MotorRPMPacketReceived(object sender, CommProtocol.MotorRPMPacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; textBox1.AppendText("RPM packet received. RPM:" + e.RPM + "\r\n"); if(!ManualMode) { InsertRowToReceived_packetsTable("RPM", e.RPM.ToString()); } }
private void cp_LocationPacketReceived(object sender, CommProtocol.LocationPacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; Lat = e.Lat; Lon = e.Long; Double Longitude = -(Lon.Degrees + Lon.Minutes / 60.0 + (double)(Lon.FractionalMinutes) / 60000.0); Double Latitude = Lat.Degrees + Lat.Minutes / 60.0 + (double)(Lat.FractionalMinutes) / 60000.0; textBox1.AppendText("Location packet received: Location" + " Lat degrees: " + Lat.Degrees + " Lat minutes: " + Lat.Minutes + " Lat minutes remainder: " + Lat.FractionalMinutes + " North: " + Lat.North + " floating Latitude: " + Latitude + " Long degrees: " + Lon.Degrees + " Long minutes: " + Lon.Minutes + " Long minutes remainder: " + Lon.FractionalMinutes + " East: " + Lon.East + " floating Longitude: " + Longitude + "\r\n"); if (!ManualMode) { InsertRowToReceived_packetsTable("Location", " Lat degrees: " + Lat.Degrees + " Lat minutes: " + Lat.Minutes + " Lat minutes remainder: " + Lat.FractionalMinutes + " North: " + Lat.North + " Long degrees: " + Lon.Degrees + " Long minutes: " + Lon.Minutes + " Long minutes remainder: " + Lon.FractionalMinutes + " East: " + Lon.East); } }
void cp_HeadingSpeedAltitudePacketReceived(object sender, CommProtocol.HeadingSpeedAltitudePacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; HSA = e.HSA; textBox1.AppendText("Heading/Speed/Altitude packet received: Altitude: " + HSA.Altitude + " Heading: " + HSA.Heading + " Speed: " + HSA.Speed + "\r\n"); if (!ManualMode) { InsertRowToReceived_packetsTable("HSA", "Altitude: " + HSA.Altitude + " Heading: " + HSA.Heading + " Speed: " + HSA.Speed); } }
void cp_GPDataReceived(object sender, CommProtocol.GPDataReceivedEventArgs e) { string data = ""; foreach(byte b in e.data) { data += string.Format("{0:x2}", b); } textBox1.AppendText("GP packet receieved: " + data + "\r\n"); }
void cp_ExpectedResponseReceived(object sender, CommProtocol.ExpectedResponseReceivedEventArgs e) { ConsecutiveBadPackets = 0; //e.ReceivedPacket; textBox1.AppendText("Expected response recieved: "+e.Name+"\r\n"); textBox1.ScrollToCaret(); if (!ManualMode) { string Received_Packet = ""; foreach(char c in e.ReceivedPacket) { Received_Packet += CharToHex(c); } InsertRowToReceived_packetsTable("Expected Response receieved " + e.Name, Received_Packet); } }
void cp_BatteryStatusPacketReceived(object sender, CommProtocol.BatteryStatusPacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; Battery_Status = e.BattStat; textBox1.AppendText("Battery status packet received: Current: " + Battery_Status.CurrentDraw + " Temperature: " + Battery_Status.Temperature + " Voltage: " + Battery_Status.Voltage + "\r\n"); if (!ManualMode) { InsertRowToReceived_packetsTable("BatteryStatus", "Current: " + Battery_Status.CurrentDraw + " Temperature: " + Battery_Status.Temperature + " Voltage: " + Battery_Status.Voltage); } }
private void cp_BadPacketReceived(object sender, CommProtocol.BadPacketReceivedEventArgs e) { if (ConsecutiveBadPackets >= 5) { mtimer.Period = 1000; //back off the packet rate ConsecutiveBadPackets = 0; } ConsecutiveBadPackets++; string BadPacketHex = ""; textBox1.AppendText( e.ErrorMessage+ ". ");// + e.BadPacket); foreach (char c in e.BadPacket) { BadPacketHex += CharToHex(c) + " "; } textBox1.AppendText(BadPacketHex + "\r\n"); textBox1.ScrollToCaret(); if (!ManualMode) { InsertRowToReceived_packetsTable("BadPacket", e.ErrorMessage + " " + BadPacketHex); } }
void ComProt_HeadingSpeedAltitudePacketReceived(object sender, CommProtocol.HeadingSpeedAltitudePacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; HSA = e.HSA; SpeedGauge.Value = HSA.Speed; HeadingGauge.Value = HSA.Heading; AltitudeGauge.Value = HSA.Altitude; }
void ComProt_LocationPacketReceived(object sender, CommProtocol.LocationPacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; if (e.Long.Degrees != 0 && e.Lat.Degrees != 0) { Lon = e.Long; Lat = e.Lat; double Longitude = -(Lon.Degrees + ((Lon.Minutes + (Lon.FractionalMinutes / 10000.0)) / 60.0)); double Latitude = Lat.Degrees + ((Lat.Minutes + (Lat.FractionalMinutes / 10000.0)) / 60.0); GoogleMapCtrl.GotoLoc(Latitude, Longitude); } }
private void cp_OnBoardErrorPacketReceived(object sender, CommProtocol.OnBoardErrorPacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; textBox1.AppendText("Error received: "+ e.ErrorCode.ToString() + "\r\n"); textBox1.ScrollToCaret(); InsertRowToReceived_packetsTable("Error Packet", e.ErrorCode.ToString()); }
void ComProt_OnBoardErrorPacketReceived(object sender, CommProtocol.OnBoardErrorPacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; }
void cp_PreFlightPacketReceived(object sender, CommProtocol.PreFlightPacketReceivedEventArgs e) { ConsecutiveBadPackets = 0; PFP = e.PFP; textBox1.AppendText(" battery temperature: " + PFP.BatteryTemp + " GPS Altitude: " + PFP.GPSAltitude + " Lat degrees: " + PFP.Lat.Degrees + " Lat minutes: " + PFP.Lat.Minutes + " Lat minutes remainder: " + (float)(PFP.Lat.FractionalMinutes)/1000.0f + " North degrees: " + PFP.Lat.North + " Long degrees: " + PFP.Long.Degrees + " Long minutes: " + PFP.Long.Minutes + " Long minutes remainder: " + (float)(PFP.Long.FractionalMinutes) /1000.0f+ " East degrees: " + PFP.Long.East + " sensor status: " + string.Format("{0:x2}", PFP.SensorStatus) + " sonar altitude: " + PFP.SonarAltitude + "\r\n"); if (!ManualMode) { InsertRowToReceived_packetsTable("PreFlightPacket", " battery temperature: " + PFP.BatteryTemp + " GPS Altitude: " + PFP.GPSAltitude + " Lat degrees: " + PFP.Lat.Degrees + " Lat minutes: " + PFP.Lat.Minutes + " Lat minutes remainder: " + (float)(PFP.Lat.FractionalMinutes) / 1000.0f + " North degrees: " + PFP.Lat.North + " Long degrees: " + PFP.Long.Degrees + " Long minutes: " + PFP.Long.Minutes + " Long minutes remainder: " + (float)(PFP.Long.FractionalMinutes) / 1000.0f + " East degrees: " + PFP.Long.East + " sensor status: " + string.Format("{0:x2}", PFP.SensorStatus) + " sonar altitude: " + PFP.SonarAltitude); } }
void ComProt_ResponseTimeout(object sender, CommProtocol.ResponseTimeoutEventArgs e) { PacketTimeoutLight.BlinkRate = 1500; PacketTimeoutLight.OneShot = true; PacketTimeoutLight.Blink = true; }
void cp_ResponseTimeout(object sender, CommProtocol.ResponseTimeoutEventArgs e) { string _BufferContents = ""; textBox1.AppendText("Timeout for " + e.ExpectedResponse.Name + "."); if (e.ExpectedResponse.ExpectedPacket != "UNDEFINED") { textBox1.AppendText(" Expected: "); foreach (char c in e.ExpectedResponse.ExpectedPacket) { textBox1.AppendText(CharToHex(c) + " "); } } textBox1.AppendText(" Buffer contents:"); foreach (char c in e.BufferContents) { _BufferContents += CharToHex(c) + " "; } textBox1.AppendText(_BufferContents + "\r\n"); textBox1.ScrollToCaret(); if (!ManualMode) { InsertRowToTimeoutTable(_BufferContents); } }
void SP_ExpectedResponseReceived(object sender, CommProtocol.ExpectedResponseReceivedEventArgs e) { string hexbuffer = ""; foreach (char c in e.ReceivedPacket) { hexbuffer += string.Format("{0:x2} ", (int)c); } //text += e.Name + "\t" + hexbuffer + "\r\n"; txt_rcvd.Text += e.Name + "\t" + hexbuffer + "\r\n"; }
void ComProt_AttitudePacketReceived(object sender, CommProtocol.AttitudePacketReceivedEventArgs e) { CommPacketRXLight.On = true; PacketReceived = true; Att = e.attitude; compass.Angle = Att.Yaw; if (Att.Roll > 128) { Arthorizon.Roll = -(255 - Att.Roll); } else { Arthorizon.Roll = Att.Roll; } if (Att.Pitch > 128) { Arthorizon.Pitch = -(255 - Att.Pitch); } else { Arthorizon.Pitch = Att.Pitch; } }
void ComProt_BadPacketReceived(object sender, CommProtocol.BadPacketReceivedEventArgs e) { BadPacketLight.BlinkRate = 500; BadPacketLight.OneShot = true; BadPacketLight.Blink = true; }
private void btnConnect_Click(object sender, EventArgs e) { cp = new CommProtocol(comboBox1.SelectedItem.ToString(),19200, Parity.None, 8, StopBits.One, 200, this); if (cp != null) { //event handlers cp.LocationPacketReceived += new CommProtocol.LocationPacketReceivedEventHandler(cp_LocationPacketReceived); cp.BadPacketReceived += new CommProtocol.BadPacketReceivedEventHandler(cp_BadPacketReceived); cp.OnBoardErrorPacketReceived += new CommProtocol.OnBoardErrorPacketReceivedEventHandler(cp_OnBoardErrorPacketReceived); cp.ResponseTimeout += new CommProtocol.ResponseTimeoutEventHandler(cp_ResponseTimeout); cp.BatteryStatusPacketReceived += new CommProtocol.BatteryStatusPacketReceivedEventHandler(cp_BatteryStatusPacketReceived); cp.HeadingSpeedAltitudePacketReceived += new CommProtocol.HeadingSpeedAltitudePacketReceivedEventHandler(cp_HeadingSpeedAltitudePacketReceived); cp.AttitudePacketReceived += new CommProtocol.AttitudePacketReceivedEventHandler(cp_AttitudePacketReceived); cp.ExpectedResponseReceived += new CommProtocol.ExpectedResponseReceivedEventHandler(cp_ExpectedResponseReceived); cp.HandShakeAckReceived += new CommProtocol.HandShakeAckReceivedEventHandler(cp_HandShakeAckReceived); cp.PreFlightPacketReceived += new CommProtocol.PreFlightPacketReceivedEventHandler(cp_PreFlightPacketReceived); cp.MotorRPMPacketReceived += new CommProtocol.MotorRPMPacketReceivedEventHandler(cp_MotorRPMPacketReceived); cp.GPDataReceived += new CommProtocol.GPDataReceivedEventHandler(cp_GPDataReceived); } }