Ejemplo n.º 1
0
        void readEEPROM()
        {
            if (serialPort1.BytesToRead < 256)
            {
                return;
            }
            StreamWriter CSV = new StreamWriter("EEPROM_DATA.CSV", true);


            byte[] newBytes = new byte[256];
            serialPort1.Read(newBytes, 0, 256);
            string Str = BitConverter.ToString(newBytes, 0, 256);

            richTextBox1.Invoke(new MethodInvoker(delegate() { richTextBox1.AppendText(Str + Environment.NewLine + Environment.NewLine); }));
            TelemetryPacket packet = new TelemetryPacket();

            for (int i = 0; i <= 12; i++)
            {
                if (newBytes[21 * i] == 0x03 && newBytes[21 * i + 1] == 0xE9)
                {
                    packet.team_id = 1001;

                    packet.time = ((int)newBytes[21 * i + 2] << 8) + (int)newBytes[21 * i + 3];

                    packet.altitude = unchecked ((short)(((ushort)newBytes[21 * i + 4] << 8) + newBytes[21 * i + 5]));

                    packet.outside_temp = (((int)newBytes[21 * i + 6] << 8) + (int)newBytes[21 * i + 7]) / 10;

                    packet.inside_temp = (((int)newBytes[21 * i + 8] << 8) + (int)newBytes[21 * i + 9]) / 10;

                    packet.voltage = unchecked ((ushort)(((ushort)newBytes[21 * i + 10] << 8) + newBytes[21 * i + 11]));
                    packet.voltage = unchecked ((float)(((packet.voltage) / 65535) * (maxVoltage * voltageScale)));

                    packet.state = packet.stateName((int)newBytes[21 * i + 12]);

                    packet.x_accel = unchecked ((short)(((ushort)newBytes[21 * i + 13] << 8) + newBytes[21 * i + 14]));
                    packet.x_accel = unchecked ((float)(packet.x_accel / 16384));

                    packet.y_accel = unchecked ((short)(((ushort)newBytes[21 * i + 15] << 8) + newBytes[21 * i + 16]));
                    packet.y_accel = unchecked ((float)(packet.y_accel / 16384));

                    packet.z_accel = unchecked ((short)(((ushort)newBytes[21 * i + 17] << 8) + newBytes[21 * i + 18]));
                    packet.z_accel = unchecked ((float)(packet.z_accel / 16384));

                    packet.count = ((int)newBytes[21 * i + 19] << 8) + (int)newBytes[21 * i + 20];

                    string[] packetStr = HandleData.packetToString(packet);

                    string row = String.Format("{0, 8}, {1, 8}, {2, 8}, {3, 14}, {4, 14}, {5, 8}, {6, 6}, {7, 6}, {8, 6}, {9, 6}, {10, 6}", packetStr[0], packetStr[1], packetStr[2], packetStr[3],
                                               packetStr[4], packetStr[5], packetStr[6], packetStr[7], packetStr[8], packetStr[9], packetStr[10]);
                    CSV.WriteLine(row);
                }
            }
            CSV.Close();
            //MessageBox.Show("Done");
        }
Ejemplo n.º 2
0
        void parsePacket(ref TelemetryPacket packet, byte[] fullData)
        {
            packet.team_id      = ((int)fullData[15] << 8) + (int)fullData[16];
            packet.time         = ((int)fullData[17] << 8) + (int)fullData[18];
            packet.altitude     = unchecked ((short)(((ushort)fullData[19] << 8) + fullData[20]));
            packet.outside_temp = (((int)fullData[21] << 8) + (int)fullData[22]) / 10;
            packet.inside_temp  = (((int)fullData[23] << 8) + (int)fullData[24]) / 10;

            packet.voltage = unchecked ((ushort)(((ushort)fullData[25] << 8) + fullData[26]));
            packet.voltage = unchecked ((float)(((packet.voltage) / 65536) * (maxVoltage * voltageScale)));
            packet.state   = packet.stateName((int)fullData[27]);
            packet.x_accel = unchecked ((short)(((ushort)fullData[28] << 8) + fullData[29]));
            packet.x_accel = unchecked ((float)(packet.x_accel / 16384));
            packet.y_accel = unchecked ((short)(((ushort)fullData[30] << 8) + fullData[31]));
            packet.y_accel = unchecked ((float)(packet.y_accel / 16384));
            packet.z_accel = unchecked ((short)(((ushort)fullData[32] << 8) + fullData[33]));
            packet.z_accel = unchecked ((float)(packet.z_accel / 16384));
            packet.count   = ((int)fullData[34] << 8) + (int)fullData[35];
        }