Exemplo n.º 1
0
        private static void GetDiveProfile(byte tocIndex)
        {
            WriteByte(sp, OSTCCommands.GET_DIVE_PROFILE);
            if (!(sp.ReadByte() == OSTCCommands.GET_DIVE_PROFILE))
            {
                throw new InvalidDataException("Expected " + OSTCCommands.GET_DIVE_PROFILE.ToString("X2"));
            }

            WriteByte(sp, tocIndex);

            byte[] diveHeaderBuffer = new byte[256];
            int    bytesLeft        = 256;

            do
            {
                int bytesRead = sp.Read(diveHeaderBuffer, (int)(256 - bytesLeft), bytesLeft);
                bytesLeft -= bytesRead;
                Console.WriteLine("got " + bytesRead.ToString() + " bytes " + bytesLeft.ToString() + " remaining!");
            }while (bytesLeft > 0);

            OSTCBinaryReader reader = new OSTCBinaryReader(new MemoryStream(diveHeaderBuffer));
            OSTCDiveHeader   header = reader.ReadDiveHeader(tocIndex);


            int bytesToRead = (int)header.ProfileDataLength - 2;

            bytesLeft = bytesToRead;
            byte[] buffer = new byte[bytesToRead];
            do
            {
                int bytesRead = sp.Read(buffer, (int)(bytesToRead - bytesLeft), bytesLeft);
                bytesLeft -= bytesRead;
                Console.WriteLine("got " + bytesRead.ToString() + " bytes " + bytesLeft.ToString() + " remaining!");
            }while (bytesLeft > 0);

            File.WriteAllBytes("dive_profile_" + tocIndex.ToString() + ".bin", buffer);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            FileStream            fs      = File.OpenRead("dive_headers.bin");
            OSTCBinaryReader      br      = new OSTCBinaryReader(fs);
            List <OSTCDiveHeader> headers = new List <OSTCDiveHeader>();
            byte tocIndex = 0;

            while (true)
            {
                OSTCDiveHeader header = br.ReadDiveHeader(tocIndex++);
                if (header != null)
                {
                    headers.Add(header);
                }
                else
                {
                    break;
                }
            }

            string jsonHeader = Newtonsoft.Json.JsonConvert.SerializeObject(headers, Newtonsoft.Json.Formatting.Indented);

            File.WriteAllText("headers.json", jsonHeader);

            Console.ReadKey();
            return;

            sp             = new SerialPort("COM3");
            sp.BaudRate    = 115200;
            sp.ReadTimeout = 3000;
            sp.Open();

            try
            {
                WriteByte(sp, OSTCCommands.START_COMMUNICATION);

                if (!(sp.ReadByte() == OSTCCommands.START_COMMUNICATION))
                {
                    throw new InvalidDataException("Expected 0xBB");
                }
                if (!(sp.ReadByte() == OSTCReplys.READY_FOR_COMMAND))
                {
                    throw new InvalidDataException("Expected 0x4D");
                }

                for (int c = 0; c <= 20; c++)
                {
                    GetDiveProfile((byte)c);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Got exceptioN!: " + ex.ToString());
            }
            finally
            {
                try
                {
                    WriteByte(sp, OSTCCommands.CLOSE_COMMUNICATION);
                }
                catch (Exception eoce)
                {
                    Console.WriteLine("Exception while sending END OF COM" + eoce.ToString());
                }

                sp.Close();
            }

            Console.WriteLine("END!");
            Console.ReadLine();
        }