public void SendUART(SerialPort sp, bool bidir, Listener listener) { int pages = maxaddr / 512; byte crc = 0; //UInt32 lfsr = 0x11223344; if (maxaddr % 512 == 0) { sp.Open(); sp.Write("$"); sp.Write("A"); sp.Write("T"); sp.Write("C"); if (listener != null) { listener.Invoke(Fase.DELETE, 0.0f); } //enviamos el número de pages sp.Write(new byte[] { (byte)pages }, 0, 1); Thread.Sleep(3000); // 125pages*20ms flash pages = 2.5s if (listener != null) { listener.Invoke(Fase.PROGRAM, 0.0f); } for (int i = 0; i < pages; i++) { byte[] buff = new byte[512]; for (int j = 0; j < 512; j++) { byte b = rom[512 * i + j]; CRC.CCITT8(b, ref crc); buff[j] = b; } sp.Write(buff, 0, 512); if (listener != null) { listener.Invoke(Fase.PROGRAM, (i + 1.0f) / pages); } } sp.Write(new byte[] { crc }, 0, 1); sp.Close(); if (listener != null) { listener.Invoke(Fase.END, 1.0f); } } }
protected bool ParsePacket(byte[] packet) { tramas_rx++; if (packet != null && packet[0] == DATALEN) { byte crc = CRC.CCITT8(packet, packet[0] - 1); byte t = packet[packet[0] - 1]; if (crc == t && crc != 255 && crc != 0) { tramas_ok++; int i = 1; if (planeState == null) { planeState = new PlaneState(); } planeState.Lon = USBXpress.USBXpress.tofloat(packet, ref i); planeState.Lat = USBXpress.USBXpress.tofloat(packet, ref i); planeState.Alt = USBXpress.USBXpress.toint16(packet, ref i); planeState.Rumbo = USBXpress.USBXpress.tochar(packet, ref i) * 360.0f / 256.0f; planeState.Knots = USBXpress.USBXpress.tobyte(packet, ref i); planeState.vertSpeed = USBXpress.USBXpress.tochar(packet, ref i); planeState.WptIndex = USBXpress.USBXpress.tochar(packet, ref i); planeState.homeLon = USBXpress.USBXpress.tofloat(packet, ref i); planeState.homeLat = USBXpress.USBXpress.tofloat(packet, ref i); planeState.v1 = USBXpress.USBXpress.tobyte(packet, ref i) / 10.0f; planeState.v2 = USBXpress.USBXpress.tobyte(packet, ref i) / 10.0f; planeState.pitch = USBXpress.USBXpress.tochar(packet, ref i) * 180 / 127.0f; planeState.roll = USBXpress.USBXpress.tochar(packet, ref i) * 180 / 127.0f; planeState.RSSI = USBXpress.USBXpress.tobyte(packet, ref i); if (CheckPlaneState(planeState)) { planeState.lastrx = true; Log(); return(true); } else { planeState.lastrx = false; planeState = null; return(false); } } } if (planeState != null) { planeState.lastrx = false; } return(false); }