Example #1
0
        public void CreateEV3File(String fullname, byte[] content)
        {
            int chunksize   = 900;
            int pos         = 0;
            int transfernow = Math.Min(content.Length - pos, chunksize - fullname.Length);

            // start the transfer
            BinaryBuffer b = new BinaryBuffer();

            b.Append32(content.Length);
            b.AppendZeroTerminated(fullname);
            b.AppendBytes(content, pos, transfernow);

            byte[] response = SystemCommand(BEGIN_DOWNLOAD, b);

            if (response == null)
            {
                throw new Exception("No response to BEGIN_DOWNLOAD");
            }
            if (response.Length < 2)
            {
                throw new Exception("Response too short for BEGIN_DOWNLOAD");
            }
            if (response[0] != SUCCESS && response[0] != END_OF_FILE)
            {
                throw new Exception("Unexpected status at BEGIN_DOWNLOAD: " + response[0]);
            }

            pos += transfernow;

            int handle = response[1] & 0xff;

            // transfer bytes in small chunks
            while (pos < content.Length)
            {
                transfernow = Math.Min(content.Length - pos, chunksize);
                b.Clear();
                b.Append8(handle);
                b.AppendBytes(content, pos, transfernow);
                response = SystemCommand(CONTINUE_DOWNLOAD, b);

                if (response == null)
                {
                    throw new Exception("No response to CONTINUE_DOWNLOAD");
                }
                if (response.Length < 2)
                {
                    throw new Exception("Response too short for CONTINUE_DOWNLOAD");
                }
                if (response[0] != SUCCESS && response[0] != END_OF_FILE)
                {
                    throw new Exception("Unexpected status at CONTINUE_DOWNLOAD: " + response[0]);
                }

                pos += transfernow;
            }
        }
Example #2
0
 public void CopyTo(BinaryBuffer target)
 {
     target.AppendBytes(buffer, 0, len);
 }