// Constructor public Radio() { physicalSerialPort = new SerialPort("COM2", rate, Parity.None, 8, StopBits.One); physicalSerialPort.DataReceived += new SerialDataReceivedEventHandler(physicalSerialPort_DataReceived); physicalSerialPort.Open(); sizeAttNav = AttNav.Serialize(new AttNav()).Length; // Get size of a serialized AttNav completeAttNav = new byte[sizeAttNav]; sizeDLC = DeadLedControl.Serialize(new DeadLedControl()).Length; completeDLC = new byte[sizeDLC]; }
} // end Parse // AttNavCreated Event Handler to send positionMe to the other plane void positionComputer_AttNavCreated(AttNav positionMe) { byte[] buffer = AttNav.Serialize(positionMe); UInt16 checkSum = CheckSumCalc(buffer); // Convert the uInt16 checksum to a byte[] byte[] checkSumBuffer = new byte[2]; checkSumBuffer[0] = (byte)(checkSum >> 8); checkSumBuffer[1] = (byte)(checkSum); // Casting (byte)(checkSum) just took the least significant (second half of the 16 bits) byte and put it in byte[1] physicalSerialPort.Write(attNavHeader, 0, attNavHeader.Length); physicalSerialPort.Write(buffer, 0, buffer.Length); physicalSerialPort.Write(checkSumBuffer, 0, checkSumBuffer.Length); physicalSerialPort.Write(attNavFooter, 0, attNavFooter.Length); }
public void Testing() { AttNav tAttNav = new AttNav(-234847615, -379916876, 453814132, 1600, 3100, 780, 456486502, -121722502, 150000, 1, 10000); DeadLedControl tDLC = new DeadLedControl(1); byte[] tDlCSerialized = DeadLedControl.Serialize(tDLC); byte[] tAttNavSerialized = AttNav.Serialize(tAttNav); byte[] fakeRadioStream1 = new byte[51]; fakeRadioStream1[0] = 0x00; // This is a dummy byte because InsertTestBuffer uses tailindex, which is often 1 because the datareceived event triggers on startup. fakeRadioStream1[1] = 0xB0; fakeRadioStream1[2] = 0xB1; Array.Copy(tAttNavSerialized, 0, fakeRadioStream1, 3, tAttNavSerialized.Length); UInt16 checkSum = Radio.CheckSumCalc(tAttNavSerialized); fakeRadioStream1[47] = (byte)(checkSum >> 8); fakeRadioStream1[48] = (byte)(checkSum); fakeRadioStream1[49] = 0x0D; fakeRadioStream1[50] = 0x0A; byte[] fakeRadioStream2 = new byte[16]; fakeRadioStream2[0] = 0x44; fakeRadioStream2[1] = 0x4C; fakeRadioStream2[2] = 0x43; Array.Copy(tDlCSerialized, 0, fakeRadioStream2, 3, tDlCSerialized.Length); UInt16 checkSumtDLC = Radio.CheckSumCalc(tDlCSerialized); fakeRadioStream2[7] = (byte)(checkSumtDLC >> 8); fakeRadioStream2[8] = (byte)(checkSumtDLC); fakeRadioStream2[9] = 0x0D; fakeRadioStream2[10] = 0x0A; fakeRadioStream2[11] = 0xAA; // Pretty sure these next bytes (11-15) are just noise, intended to make sure the parsing engine can handle noise showing up with real infomation. fakeRadioStream2[12] = 0xAB; fakeRadioStream2[13] = 0xAC; fakeRadioStream2[14] = 0x0F; fakeRadioStream2[15] = 0x01; xbee.InsertTestBuffer(fakeRadioStream1); // Thread.Sleep(10); // shitty sleep xbee.InsertTestBuffer(fakeRadioStream2); }