Esempio n. 1
0
        private void readOnePage(BinaryReader br)
        {
            byte head = br.ReadByte();

            if (head == A_Page.header)
            {
                pages.a.Update(br);
                lock (fileSemaphore) { pages.DumpA(csv_A); }
                Console.Write("[A page]:");
                Console.WriteLine(
                    pages.a.ax + "," + pages.a.ay + "," + pages.a.az + "," +
                    pages.a.gx + "," + pages.a.gy + "," + pages.a.gz);

                AHRS.Update(
                    (float)pages.a.cal_gx / 180 * (float)Math.PI,
                    (float)pages.a.cal_gy / 180 * (float)Math.PI,
                    (float)pages.a.cal_gz / 180 * (float)Math.PI,
                    (float)pages.a.cal_ax, (float)pages.a.cal_ay, (float)pages.a.cal_az);
                //AHRS.Update((float)gx, (float)gy, (float)gz, (float)ax, (float)ay, (float)az, (float)mx, (float)my, (float)mz);
                AHRS.Quaternion2Euler(AHRS.Quaternion);
            }
            else if (head == P_Page.header)
            {
                pages.p.Update(br);
                lock (fileSemaphore) { pages.DumpP(csv_P); }
                Console.Write("[P page]:");
                Console.WriteLine(pages.p.pressure * 0.01 + "(hPa)");
            }
            else if (head == M_Page.header)
            {
                pages.m.Update(br);
                lock (fileSemaphore) { pages.DumpM(csv_M); }
                double conv = 0.1;
                Console.Write("[M page]:");
                Console.WriteLine(pages.m.mx * conv + "," + pages.m.my * conv + "," + pages.m.mz * conv);
            }
            else if (head == G_Page.header)
            {
                pages.g.Update(br);
                lock (fileSemaphore) { pages.DumpG(nmea_G, ubx_G); }
                Console.Write("[G page]:");
                Console.WriteLine(pages.g.ubx_raw);
            }
        }
Esempio n. 2
0
        private void buttonSDConvert_Click(object sender, EventArgs e)
        {
            string input_file    = textBox3.Text;
            string output_folder = textBox1.Text;
            string file_name     = textBox4.Text;

            string A_file   = output_folder + "\\" + file_name + "_A.csv";
            string P_file   = output_folder + "\\" + file_name + "_P.csv";
            string M_file   = output_folder + "\\" + file_name + "_M.csv";
            string G_file   = output_folder + "\\" + file_name + "_G.nmea";
            string UBX_file = output_folder + "\\" + file_name + ".ubx";

            // ファイルが既に存在していたら警告を出す。キャンセルボタンを押すとメソッドを抜ける
            if (File.Exists(A_file) || File.Exists(P_file) ||
                File.Exists(M_file) || File.Exists(G_file) || File.Exists(UBX_file))
            {
                DialogResult res = MessageBox.Show("Are you sure you want to overwrite the files?",
                                                   "Overwrite save",
                                                   MessageBoxButtons.OKCancel,
                                                   MessageBoxIcon.Exclamation);

                if (res == DialogResult.Cancel)
                {
                    MessageBox.Show("Abort overwrite save", "Information",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    return;
                }
            }

            BinaryReader br = new BinaryReader(File.OpenRead(input_file));

            StreamWriter csv_A_sd  = new StreamWriter(A_file, false);
            StreamWriter csv_P_sd  = new StreamWriter(P_file, false);
            StreamWriter csv_M_sd  = new StreamWriter(M_file, false);
            StreamWriter nmea_G_sd = new StreamWriter(G_file, false);
            BinaryWriter ubx_G_sd  = new BinaryWriter(File.OpenWrite(UBX_file));

            SylphidePages.WriteCSVHeaderA(csv_A_sd);
            SylphidePages.WriteCSVHeaderM(csv_M_sd);
            SylphidePages.WriteCSVHeaderP(csv_P_sd);

            var tokenSource = new CancellationTokenSource();
            var token       = tokenSource.Token;

            convertingTask = Task.Factory.StartNew(() =>
            {
                SylphidePages pages_sd = new SylphidePages();

                while (true)
                {
                    token.ThrowIfCancellationRequested();

                    // LOG.DATの場合はProtocolのheaderの頭出しは必要ない
                    byte head = br.ReadByte();
                    if (head == A_Page.header)
                    {
                        pages_sd.a.Update(br);
                        pages_sd.DumpA(csv_A_sd);
                    }
                    else if (head == P_Page.header)
                    {
                        pages_sd.p.Update(br);
                        pages_sd.DumpP(csv_P_sd);
                    }
                    else if (head == M_Page.header)
                    {
                        pages_sd.m.Update(br);
                        pages_sd.DumpM(csv_M_sd);
                    }
                    else if (head == G_Page.header)
                    {
                        pages_sd.g.Update(br);
                        pages_sd.DumpG(nmea_G_sd, ubx_G_sd);
                    }
                }
            }, token).ContinueWith(t =>
            {
                csv_A_sd.Close();
                csv_P_sd.Close();
                csv_M_sd.Close();
                nmea_G_sd.Close();
                ubx_G_sd.Close();

                cancelConvertTokenSource.Dispose();
                cancelConvertTokenSource = null;
                loggingTask = null;

                if (closing)
                {
                    return;
                }
                DialogResult result = MessageBox.Show("Complete to output CSV files");

                Invoke((MethodInvoker)(() =>
                {
                    buttonSDConvert.Text = "Convert";
                    buttonSDConvert.Enabled = true;
                }));
            });

            cancelConvertTokenSource = tokenSource;
            buttonSDConvert.Enabled  = false;
            buttonSDConvert.Text     = "Converting...";
        }