Exemplo n.º 1
0
        public override void Load(ByteReader br)
        {
            #region Read Timestamp
            if (!(br.ReadByte(b)))
                throw new Exception("Error: reading first byte in PLFormat file");

            //read a complete timestamp
            if (b[0] == ((int)255))
            {
                if (!(br.ReadBytes(b6)))
                    throw new Exception("Error: reading full timestamp in PLFormat file");

                lastUnixTime = WocketsTimer.DecodeUnixTimeCodeBytesFixed(b6);
            }
            else //read a differential timestamp
                lastUnixTime += (int)b[0];

            #endregion Read Timestamp

            DateTime dt = new DateTime();
            WocketsTimer.GetDateTime((long)lastUnixTime, out dt);

            if (!br.ReadByte(header))
                throw new Exception("Error: reading data in PLFormat file");
            pdu[0] = header[0];

            int len = 0;
            if ((header[0] & 0x60) > 0)
                len = 3;
            else
                len = 5;
            if (!(br.ReadBytes(pdu, 1, len)))
                throw new Exception("Error: reading data in PLFormat file");

            int lastDecodedIndex = 0;
            //Successfully decoded a packet
            if (this.Decode(this._ID, pdu, len) == 1)
            {
                if (this._Head == 0)
                    lastDecodedIndex = this._Data.Length - 1;
                else
                    lastDecodedIndex = this._Head - 1;
                this._Data[lastDecodedIndex].UnixTimeStamp = lastUnixTime;
                return;
            }
            else
                throw new Exception("Failed to decode data");
        }
Exemplo n.º 2
0
        //        private String[] SplitString(String aString)
        //        {
        //            return (new Regex(" ")).Split(aString);
        //        }
        /// <summary>
        /// Test method
        /// </summary>
        static void Main()
        {
            String inFile = "\\My Documents\\testBytes.txt";
            Console.WriteLine("Infile: " + inFile);
            ByteReader br = new ByteReader(inFile);
            br.OpenFile();
            bool gotByte = false;
            int[] i = new int[1];
            //byte[] b = new byte[1];

            do
            {
                //gotByte = br.ReadByte(b);
                gotByte = br.ReadInt(i);
                if (gotByte)
                {
                    Console.Write(i);
                }
                else
                    Console.WriteLine("Could not read an int as bytes");
            } while (gotByte);

            br.CloseFile();
        }
Exemplo n.º 3
0
 public override void Load(ByteReader br)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Sets up the next binary file to read the data from
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private bool SetupNextFiles(int index)
        {
            if (br != null)
                br.CloseFile();

            br = null;
            string f = ((string)someBinaryFiles[index]);

            if (f != "")
            {
                br = new ByteReader(f);
                br.OpenFile();
                Console.WriteLine("Opening file for read: " + f);
            }

            if (br == null)
                return false;
            else
                return true;
        }
Exemplo n.º 5
0
 public abstract void Load(ByteReader br);