示例#1
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                CommandFormat cf = new CommandFormat(1, int.MaxValue, "ignoreCrc");

                cf.Parse(args);
                verifyChecksum = !cf.GetOpt("ignoreCrc");
            }
示例#2
0
        /// <exception cref="System.Exception"/>
        public static void TestCommandFormat()
        {
            // This should go to TestFsShell.java when it is added.
            CommandFormat cf;

            cf = new CommandFormat("copyToLocal", 2, 2, "crc", "ignoreCrc");
            NUnit.Framework.Assert.AreEqual(cf.Parse(new string[] { "-get", "file", "-" }, 1)
                                            [1], "-");
            try
            {
                cf.Parse(new string[] { "-get", "file", "-ignoreCrc", "/foo" }, 1);
                Fail("Expected parsing to fail as it should stop at first non-option");
            }
            catch (Exception)
            {
            }
            // Expected
            cf = new CommandFormat("tail", 1, 1, "f");
            NUnit.Framework.Assert.AreEqual(cf.Parse(new string[] { "-tail", "fileName" }, 1)
                                            [0], "fileName");
            NUnit.Framework.Assert.AreEqual(cf.Parse(new string[] { "-tail", "-f", "fileName" }, 1)[0], "fileName");
            cf = new CommandFormat("setrep", 2, 2, "R", "w");
            NUnit.Framework.Assert.AreEqual(cf.Parse(new string[] { "-setrep", "-R", "2", "/foo/bar" }, 1)[1], "/foo/bar");
            cf = new CommandFormat("put", 2, 10000);
            NUnit.Framework.Assert.AreEqual(cf.Parse(new string[] { "-put", "-", "dest" }, 1)
                                            [1], "dest");
        }
示例#3
0
            // used by chown/chgrp
            ///allows only "allowedChars" above in names for owner and group
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                CommandFormat cf = new CommandFormat(2, int.MaxValue, "R");

                cf.Parse(args);
                SetRecursive(cf.GetOpt("R"));
                ParseOwnerGroup(args.RemoveFirst());
            }
示例#4
0
        /// <exception cref="System.IO.IOException"/>
        protected internal override void ProcessOptions(List <string> args)
        {
            CommandFormat cf = new CommandFormat(1, int.MaxValue, OptionFollowLink, OptionFollowArgLink
                                                 , null);

            cf.Parse(args);
            if (cf.GetOpt(OptionFollowLink))
            {
                GetOptions().SetFollowLink(true);
            }
            else
            {
                if (cf.GetOpt(OptionFollowArgLink))
                {
                    GetOptions().SetFollowArgLink(true);
                }
            }
            // search for first non-path argument (ie starts with a "-") and capture and
            // remove the remaining arguments as expressions
            List <string>        expressionArgs = new List <string>();
            IEnumerator <string> it             = args.GetEnumerator();
            bool isPath = true;

            while (it.HasNext())
            {
                string arg = it.Next();
                if (isPath)
                {
                    if (arg.StartsWith("-"))
                    {
                        isPath = false;
                    }
                }
                if (!isPath)
                {
                    expressionArgs.AddItem(arg);
                    it.Remove();
                }
            }
            if (args.IsEmpty())
            {
                args.AddItem(Path.CurDir);
            }
            Expression expression = ParseExpression(expressionArgs);

            if (!expression.IsAction())
            {
                Expression         and      = GetExpression(typeof(And));
                Deque <Expression> children = new List <Expression>();
                children.AddItem(GetExpression(typeof(Print)));
                children.AddItem(expression);
                and.AddChildren(children);
                expression = and;
            }
            SetRootExpression(expression);
        }
示例#5
0
            public CommandFormat Deserialize(byte[] buffer)
            {
                CommandFormat header = new CommandFormat(buffer[0], buffer[1]);

                for (int i = 0; i < 10; i++)
                {
                    header.Payload[i] = buffer[2 + i];
                }

                return(header);
            }
示例#6
0
        public bool IsCommandFormatSupported(CommandFormat format)
        {
            bool      supported = false;
            ErrorCode error     = VcWidgetIsCommandFormatSupported(_handle, format, out supported);

            if (error != ErrorCode.None)
            {
                Log.Error(LogTag, "IsCommandFormatSupported Failed with error " + error);
                throw ExceptionFactory.CreateException(error);
            }
            return(supported);
        }
示例#7
0
        private void SendCommandInternal(
            byte cmd,
            byte channel,
            CommandFormat format,
            byte level0 = 0,
            byte level1 = 0,
            byte level2 = 0)
        {
            var data = new byte[] { 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

            data[2] = cmd;                      // command
            data[3] = (byte)format;             // format
            data[5] = channel;
            data[6] = level0;
            data[7] = level1;
            data[8] = level2;

            device.WriteFeatureData(data);
            System.Threading.Thread.Sleep(200);
        }
示例#8
0
        private static Command ReadCommand(BinaryReader s)
        {
            CommandFormat commandFormat = GetCommandFormat(s.ReadByte());
            Command       result        = default(Command);

            result.Kind = commandFormat.Kind;
            if (commandFormat.Length1 > 0)
            {
                result.Parameter1 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length1));
            }
            else
            {
                result.Parameter1 = commandFormat.ImmediateValue;
            }
            if (commandFormat.Length2 > 0)
            {
                result.Parameter2 = StreamHelpers.ConvertFromBigEndian(s.ReadBytes(commandFormat.Length2));
            }
            return(result);
        }
示例#9
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessOptions(List <string> args)
            {
                CommandFormat cf = new CommandFormat(2, int.MaxValue, "R", null);

                cf.Parse(args);
                SetRecursive(cf.GetOpt("R"));
                string modeStr = args.RemoveFirst();

                try
                {
                    pp = new ChmodParser(modeStr);
                }
                catch (ArgumentException)
                {
                    // TODO: remove "chmod : " so it's not doubled up in output, but it's
                    // here for backwards compatibility...
                    throw new ArgumentException("chmod : mode '" + modeStr + "' does not match the expected pattern."
                                                );
                }
            }
示例#10
0
        /// <exception cref="System.IO.IOException"/>
        protected internal override void ProcessOptions(LinkedList <string> args)
        {
            CommandFormat cf = new CommandFormat(2, int.MaxValue, "w");

            cf.Parse(new List <string>(args));
            waitOpt = cf.GetOpt("w");
            try
            {
                newLength = long.Parse(args.First.Value);
                args.RemoveFirst();
            }
            catch (FormatException nfe)
            {
                DisplayWarning("Illegal length, a non-negative integer expected");
                throw;
            }
            if (newLength < 0)
            {
                throw new ArgumentException("length must be >= 0");
            }
        }
示例#11
0
 public virtual void TestOldArgsWithIndex()
 {
     string[] arrayArgs = new string[] { "ignore", "-a", "b", "-c" };
     {
         CommandFormat  cf         = new CommandFormat(0, 9, "a", "c");
         IList <string> parsedArgs = cf.Parse(arrayArgs, 0);
         Assert.Equal(SetOf(), cf.GetOpts());
         Assert.Equal(ListOf("ignore", "-a", "b", "-c"), parsedArgs);
     }
     {
         CommandFormat  cf         = new CommandFormat(0, 9, "a", "c");
         IList <string> parsedArgs = cf.Parse(arrayArgs, 1);
         Assert.Equal(SetOf("a"), cf.GetOpts());
         Assert.Equal(ListOf("b", "-c"), parsedArgs);
     }
     {
         CommandFormat  cf         = new CommandFormat(0, 9, "a", "c");
         IList <string> parsedArgs = cf.Parse(arrayArgs, 2);
         Assert.Equal(SetOf(), cf.GetOpts());
         Assert.Equal(ListOf("b", "-c"), parsedArgs);
     }
 }
示例#12
0
        private static CommandFormat CheckArgLimits <T>(Type expectedErr, int min, int max
                                                        , params string[] opts)
        {
            CommandFormat  cf         = new CommandFormat(min, max, opts);
            IList <string> parsedArgs = new AList <string>(args);
            Type           cfError    = null;

            try
            {
                cf.Parse(parsedArgs);
            }
            catch (ArgumentException e)
            {
                System.Console.Out.WriteLine(e.Message);
                cfError = e.GetType();
            }
            Assert.Equal(expectedErr, cfError);
            if (expectedErr == null)
            {
                Assert.Equal(expectedArgs, parsedArgs);
                Assert.Equal(expectedOpts, cf.GetOpts());
            }
            return(cf);
        }
示例#13
0
 internal static extern ErrorCode VcWidgetIsCommandFormatSupported(IntPtr widget, CommandFormat format, out bool support);
示例#14
0
        private void SaharaDownloadProgrammer()
        {
            if (comm.IsOpen)
            {
                string msg1 = string.Format("[{0}]:{1}", comm.serialPort.PortName, "start flash.");
                FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), "read hello packet", "flashing", false);
                Log.w(comm.serialPort.PortName, msg1);
                comm.getRecData();
                if (comm.recData.Length == 0)
                {
                    comm.recData = new byte[48];
                }
                sahara_packet       saharaPacket = new sahara_packet();
                sahara_hello_packet stuct1       = (sahara_hello_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_hello_packet));
                stuct1.Reserved = new uint[6];
                sahara_hello_response saharaHelloResponse = new sahara_hello_response();
                saharaHelloResponse.Reserved = new uint[6];
                sahara_switch_Mode_packet  switchModePacket     = new sahara_switch_Mode_packet();
                sahara_readdata_packet     saharaReaddataPacket = new sahara_readdata_packet();
                sahara_64b_readdata_packet obj = new sahara_64b_readdata_packet();
                sahara_end_transfer_packet endTransferPacket  = new sahara_end_transfer_packet();
                sahara_done_response       saharaDoneResponse = new sahara_done_response();
                int num = 20;
                while (num-- > 0 && (int)stuct1.Command != 1)
                {
                    string str1 = "cannot receive hello packet,try agian";
                    Log.w(comm.serialPort.PortName, str1);
                    FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), str1, "flashing", false);
                    if (comm.recData.Length == 0)
                    {
                        comm.recData = new byte[48];
                    }
                    stuct1 = (sahara_hello_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_hello_packet));
                    Thread.Sleep(500);
                    if (num == 10)
                    {
                        string str2 = "cannot receive hello packet,try to reset";
                        Log.w(comm.serialPort.PortName, str2);
                        FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), str2, "flashing", false);
                        saharaHelloResponse.Command     = 2U;
                        saharaHelloResponse.Length      = (uint)Marshal.SizeOf(saharaHelloResponse);
                        saharaHelloResponse.Version     = 2U;
                        saharaHelloResponse.Version_min = 1U;
                        saharaHelloResponse.Mode        = 3U;
                        comm.WritePort(CommandFormat.StructToBytes(saharaHelloResponse), 0, Marshal.SizeOf(saharaHelloResponse));
                        string str3 = "Switch mode back";
                        Log.w(comm.serialPort.PortName, str3);
                        FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), str3, "flashing", false);
                        switchModePacket.Command = 12U;
                        switchModePacket.Length  = (uint)Marshal.SizeOf(switchModePacket);
                        switchModePacket.Mode    = 0U;
                        comm.WritePort(CommandFormat.StructToBytes(switchModePacket), 0, Marshal.SizeOf(switchModePacket));
                        if (comm.recData.Length == 0)
                        {
                            comm.recData = new byte[48];
                        }
                        stuct1 = (sahara_hello_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_hello_packet));
                    }
                }
                if ((int)stuct1.Command == 1)
                {
                    string str = "received hello packet";
                    FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), str, "flashing", false);
                    Log.w(comm.serialPort.PortName, str);
                }
                else
                {
                    string str = "cannot receive hello packet";
                    FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), str, "flashing", false);
                    Log.w(comm.serialPort.PortName, str);
                }
                saharaHelloResponse.Command     = 2U;
                saharaHelloResponse.Length      = 48U;
                saharaHelloResponse.Version     = 2U;
                saharaHelloResponse.Version_min = 1U;
                byte[] bytes1 = CommandFormat.StructToBytes(saharaHelloResponse);
                comm.WritePort(bytes1, 0, bytes1.Length);
                string[] strArray = FileSearcher.SearchFiles(swPath, SoftwareImage.ProgrammerPattern);
                if (strArray.Length != 1)
                {
                    throw new Exception("can not found programmer file.");
                }
                string   str4     = strArray[0];
                FileInfo fileInfo = new FileInfo(str4);
                if (fileInfo.Name.ToLower().IndexOf("firehose") >= 0)
                {
                    programmerType = Programmer.firehose;
                }
                if (fileInfo.Name.ToLower().IndexOf("ufs") >= 0)
                {
                    storageType = Storage.ufs;
                }
                else if (fileInfo.Name.ToLower().IndexOf("emmc") >= 0)
                {
                    storageType = Storage.emmc;
                }
                comm.intSectorSize = storageType == Storage.ufs ? comm.SECTOR_SIZE_UFS : comm.SECTOR_SIZE_EMMC;
                Log.w(comm.serialPort.PortName, "donwload programmer " + str4);
                FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(0.0f), "download programmer " + str4, "flashing", false);
                FileTransfer fileTransfer = new FileTransfer(comm.serialPort.PortName, str4);
                bool         flag;
                do
                {
                    flag = false;
                    comm.getRecData();
                    byte[] recData = comm.recData;
                    saharaPacket = (sahara_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_packet));
                    switch (saharaPacket.Command)
                    {
                    case 3:
                        sahara_readdata_packet stuct3 = (sahara_readdata_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_readdata_packet));
                        string msg2 = string.Format("sahara read data:imgID {0}, offset {1},length {2}", stuct3.Image_id, stuct3.Offset, stuct3.SLength);
                        fileTransfer.transfer(comm.serialPort, (int)stuct3.Offset, (int)stuct3.SLength);
                        Log.w(comm.serialPort.PortName, msg2);
                        break;

                    case 4:
                        sahara_end_transfer_packet stuct4 = (sahara_end_transfer_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_end_transfer_packet));
                        string msg3 = string.Format("sahara read end  imgID:{0} status:{1}", stuct4.Image_id, stuct4.Status);
                        if ((int)stuct4.Status != 0)
                        {
                            Log.w(comm.serialPort.PortName, string.Format("sahara read end error with status:{0}", stuct4.Status));
                        }
                        flag = true;
                        Log.w(comm.serialPort.PortName, msg3);
                        break;

                    case 18:
                        sahara_64b_readdata_packet stuct5 = (sahara_64b_readdata_packet)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_64b_readdata_packet));
                        string msg4 = string.Format("sahara read 64b data:imgID {0},offset {1},length {2}", stuct5.Image_id, stuct5.Offset, stuct5.SLength);
                        fileTransfer.transfer(comm.serialPort, (int)stuct5.Offset, (int)stuct5.SLength);
                        Log.w(comm.serialPort.PortName, msg4);
                        break;

                    default:
                        Log.w(comm.serialPort.PortName, string.Format("invalid command:{0}", saharaPacket.Command));
                        break;
                    }
                }while (!flag);
                saharaPacket.Command = 5U;
                saharaPacket.Length  = 8U;
                byte[] bytes2 = CommandFormat.StructToBytes(saharaPacket, 8);
                for (int index = 8; index < bytes2.Length; ++index)
                {
                    bytes2[index] = 0;
                }
                comm.WritePort(bytes2, 0, bytes2.Length);
                comm.getRecData();
                if (comm.recData.Length == 0)
                {
                    comm.recData = new byte[48];
                }
                if ((int)((sahara_done_response)CommandFormat.BytesToStuct(comm.recData, typeof(sahara_done_response))).Command == 6)
                {
                    string str1 = string.Format("file {0} transferred successfully", str4);
                    Thread.Sleep(2000);
                    Log.w(comm.serialPort.PortName, str1);
                    FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(1f), str1, "flashing", false);
                }
                else
                {
                    string str1 = "programmer transfer error";
                    Log.w(comm.serialPort.PortName, str1);
                    FlashingDevice.UpdateDeviceStatus(comm.serialPort.PortName, new float?(), str1, "flashing", false);
                }
            }
            else
            {
                Log.w(comm.serialPort.PortName, string.Format("port {0} is not open.", comm.serialPort.PortName));
            }
        }
示例#15
0
 internal static extern ErrorCode VcMgrIsCommandFormatSupported(CommandFormat format, out bool support);
示例#16
0
        public void WriteSparseFileToDevice(SerialPortDevice portCnn, string pszPartitionStartSector,
                                            string pszPartitionSectorNumber, string pszImageFile, string pszFileStartSector,
                                            string pszSectorSizeInBytes, string pszPhysicalPartitionNumber)
        {
            var  int32_1 = Convert.ToInt32(pszPartitionStartSector);
            var  int32_2 = Convert.ToInt32(pszPartitionSectorNumber);
            var  int32_3 = Convert.ToInt32(pszFileStartSector);
            long offset1 = 0;
            var  int32_4 = Convert.ToInt32(pszSectorSizeInBytes);

            Convert.ToInt32(pszPhysicalPartitionNumber);
            var sparseImageHeader = new SparseImageHeader();
            var str = "";

            if (int32_3 != 0)
            {
                str = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, str);
            }

            if (int32_4 == 0)
            {
                str = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
            }

            var size1  = Marshal.SizeOf(sparseImageHeader);
            var n      = 0;
            var stuct1 = (SparseImageHeader)CommandFormat.BytesToStuct(GetBytesFromFile(offset1, size1, out n),
                                                                       typeof(SparseImageHeader));
            var offset2 = offset1 + stuct1.uFileHeaderSize;

            if ((int)stuct1.uMagic != -316211398)
            {
                str = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
            }

            if (stuct1.uMajorVersion != 1)
            {
                str = "ERROR_UNSUPPORTED_TYPE";
                Log.w(portCnn.comm.serialPort.PortName, "ERROR_UNSUPPORTED_TYPE");
            }

            if (stuct1.uBlockSize % int32_4 != 0L)
            {
                str = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
            }

            if (int32_2 != 0 && stuct1.uBlockSize * stuct1.uTotalBlocks / int32_4 > int32_2)
            {
                str = "ERROR_FILE_TOO_LARGE";
                Log.w(portCnn.comm.serialPort.PortName, "ERROR_FILE_TOO_LARGE");
            }

            if (!string.IsNullOrEmpty(str))
            {
                FlashingDevice.UpdateDeviceStatus(portName, new float?(), str, "error", false);
            }
            else
            {
                for (var index = 0; index < stuct1.uTotalChunks; ++index)
                {
                    Log.w(portCnn.comm.serialPort.PortName,
                          string.Format("total chunks {0}, current chunk {1}", stuct1.uTotalChunks, index));
                    var size2  = Marshal.SizeOf(new SparseChunkHeader());
                    var stuct2 = (SparseChunkHeader)CommandFormat.BytesToStuct(GetBytesFromFile(offset2, size2, out n),
                                                                               typeof(SparseChunkHeader));
                    offset2 += stuct1.uChunkHeaderSize;
                    var num1 = (int)stuct1.uBlockSize * (int)stuct2.uChunkSize;
                    var num2 = num1 / int32_4;
                    switch (stuct2.uChunkType)
                    {
                    case 51905:
                        if (stuct2.uTotalSize != stuct1.uChunkHeaderSize + num1)
                        {
                            Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
                            FlashingDevice.UpdateDeviceStatus(portName, new float?(), "ERROR_BAD_FORMAT", "error",
                                                              false);
                            return;
                        }

                        var strPartitionStartSector  = int32_1.ToString();
                        var strPartitionSectorNumber = num2.ToString();
                        var strFileStartSector       = (offset2 / int32_4).ToString();
                        var strFileSectorOffset      = (offset2 % int32_4).ToString();
                        WriteFile(portCnn, strPartitionStartSector, strPartitionSectorNumber, pszImageFile,
                                  strFileStartSector, strFileSectorOffset, pszSectorSizeInBytes,
                                  pszPhysicalPartitionNumber);
                        offset2 += int32_4 * num2;
                        int32_1 += num2;
                        break;

                    case 51907:
                        if ((int)stuct2.uTotalSize != stuct1.uChunkHeaderSize)
                        {
                            Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
                        }
                        int32_1 += num2;
                        break;

                    default:
                        Log.w(portCnn.comm.serialPort.PortName, "ERROR_UNSUPPORTED_TYPE");
                        break;
                    }
                }
            }
        }
示例#17
0
        // Token: 0x060000FD RID: 253 RVA: 0x0000DC64 File Offset: 0x0000BE64
        public void WriteSparseFileToDevice(SerialPortDevice portCnn, string pszPartitionStartSector, string pszPartitionSectorNumber, string pszImageFile, string pszFileStartSector, string pszSectorSizeInBytes, string pszPhysicalPartitionNumber, string addtionalFirehose)
        {
            int  num  = Convert.ToInt32(pszPartitionStartSector);
            int  num2 = Convert.ToInt32(pszPartitionSectorNumber);
            int  num3 = Convert.ToInt32(pszFileStartSector);
            long num4 = 0L;
            int  num5 = Convert.ToInt32(pszSectorSizeInBytes);

            Convert.ToInt32(pszPhysicalPartitionNumber);
            SparseImageHeader sparseImageHeader = default(SparseImageHeader);
            string            text = "";

            if (num3 != 0)
            {
                text = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, text);
            }
            if (num5 == 0)
            {
                text = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
            }
            int size = Marshal.SizeOf(sparseImageHeader);
            int num6 = 0;

            byte[] bytesFromFile = this.GetBytesFromFile(num4, size, out num6);
            sparseImageHeader = (SparseImageHeader)CommandFormat.BytesToStuct(bytesFromFile, typeof(SparseImageHeader));
            num4 += (long)((ulong)sparseImageHeader.uFileHeaderSize);
            if (sparseImageHeader.uMagic != 3978755898u)
            {
                text = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_BAD_FORMAT {0}", sparseImageHeader.uMagic.ToString()));
            }
            if (sparseImageHeader.uMajorVersion != 1)
            {
                text = "ERROR_UNSUPPORTED_TYPE";
                Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_UNSUPPORTED_TYPE {0}", sparseImageHeader.uMajorVersion.ToString()));
            }
            if ((ulong)sparseImageHeader.uBlockSize % (ulong)((long)num5) != 0UL)
            {
                text = "ERROR_BAD_FORMAT";
                Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_BAD_FORMAT {0}", sparseImageHeader.uBlockSize.ToString()));
            }
            if (num2 != 0 && (ulong)(sparseImageHeader.uBlockSize * sparseImageHeader.uTotalBlocks) / (ulong)((long)num5) > (ulong)((long)num2))
            {
                text = "ERROR_FILE_TOO_LARGE";
                Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_FILE_TOO_LARGE size {0} ullPartitionSectorNumber {1}", ((long)((ulong)(sparseImageHeader.uBlockSize * sparseImageHeader.uTotalBlocks) / (ulong)((long)num5))).ToString(), num2.ToString()));
            }
            if (!string.IsNullOrEmpty(text))
            {
                throw new Exception(text);
            }
            int num7 = 0;
            int num8 = 1;

            while ((long)num8 <= (long)((ulong)sparseImageHeader.uTotalChunks))
            {
                Log.w(portCnn.comm.serialPort.PortName, string.Format("total chunks {0}, current chunk {1}", sparseImageHeader.uTotalChunks, num8));
                SparseChunkHeader sparseChunkHeader = default(SparseChunkHeader);
                size = Marshal.SizeOf(sparseChunkHeader);
                float num9 = 0f;
                bytesFromFile     = this.GetBytesFromFile(num4, size, out num6, out num9);
                sparseChunkHeader = (SparseChunkHeader)CommandFormat.BytesToStuct(bytesFromFile, typeof(SparseChunkHeader));
                num4 += (long)((ulong)sparseImageHeader.uChunkHeaderSize);
                int num10 = (int)(sparseImageHeader.uBlockSize * sparseChunkHeader.uChunkSize);
                int num11 = num10 / num5;
                if (sparseChunkHeader.uChunkType == 51905)
                {
                    if ((ulong)sparseChunkHeader.uTotalSize != (ulong)((long)((int)sparseImageHeader.uChunkHeaderSize + num10)))
                    {
                        Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
                        throw new Exception("ERROR_BAD_FORMAT");
                    }
                    string strPartitionStartSector  = num.ToString();
                    string strPartitionSectorNumber = num11.ToString();
                    string strFileStartSector       = (num4 / (long)num5).ToString();
                    string strFileSectorOffset      = (num4 % (long)num5).ToString();
                    num7++;
                    bool chkAck = false;
                    int  value  = 0;
                    if (sparseImageHeader.uTotalChunks <= 10u)
                    {
                        if ((long)num8 == (long)((ulong)sparseImageHeader.uTotalChunks))
                        {
                            value  = num7;
                            chkAck = true;
                        }
                    }
                    else
                    {
                        if (num7 % 10 == 0)
                        {
                            value  = 10;
                            chkAck = true;
                        }
                        if ((long)num8 == (long)((ulong)sparseImageHeader.uTotalChunks))
                        {
                            value  = num7 % 10;
                            chkAck = true;
                        }
                    }
                    this.WriteFile(portCnn, strPartitionStartSector, strPartitionSectorNumber, pszImageFile, strFileStartSector, strFileSectorOffset, pszSectorSizeInBytes, pszPhysicalPartitionNumber, addtionalFirehose, chkAck, new int?(value));
                    num4 += (long)(num5 * num11);
                    num  += num11;
                }
                else if (sparseChunkHeader.uChunkType == 51907)
                {
                    if (sparseChunkHeader.uTotalSize != (uint)sparseImageHeader.uChunkHeaderSize)
                    {
                        Log.w(portCnn.comm.serialPort.PortName, "ERROR_BAD_FORMAT");
                    }
                    num += num11;
                    if ((long)num8 == (long)((ulong)sparseImageHeader.uTotalChunks))
                    {
                        int num12 = num7 % 10;
                        if (num12 > 0)
                        {
                            string message = null;
                            if (!portCnn.comm.chkRspAck(out message, num12))
                            {
                                throw new Exception(message);
                            }
                        }
                    }
                }
                else
                {
                    Log.w(portCnn.comm.serialPort.PortName, string.Format("ERROR_UNSUPPORTED_TYPE {0}", sparseChunkHeader.uChunkType.ToString()));
                }
                num8++;
            }
        }
示例#18
0
        /// <summary>Main entry point.</summary>
        /// <param name="args">command-line arguments</param>
        public static void Main(string[] args)
        {
            if (args.Length < 1 || args[0].Equals("-h") || args[0].Equals("--help"))
            {
                System.Console.Out.WriteLine(usage);
                return;
            }
            // Copy args, because CommandFormat mutates the list.
            IList <string> argsList = new AList <string>(Arrays.AsList(args));
            CommandFormat  cf       = new CommandFormat(0, int.MaxValue, "-glob", "-jar");

            try
            {
                cf.Parse(argsList);
            }
            catch (CommandFormat.UnknownOptionException)
            {
                Terminate(1, "unrecognized option");
                return;
            }
            string classPath = Runtime.GetProperty("java.class.path");

            if (cf.GetOpt("-glob"))
            {
                // The classpath returned from the property has been globbed already.
                System.Console.Out.WriteLine(classPath);
            }
            else
            {
                if (cf.GetOpt("-jar"))
                {
                    if (argsList.IsEmpty() || argsList[0] == null || argsList[0].IsEmpty())
                    {
                        Terminate(1, "-jar option requires path of jar file to write");
                        return;
                    }
                    // Write the classpath into the manifest of a temporary jar file.
                    Path   workingDir = new Path(Runtime.GetProperty("user.dir"));
                    string tmpJarPath;
                    try
                    {
                        tmpJarPath = FileUtil.CreateJarWithClassPath(classPath, workingDir, Runtime.GetEnv
                                                                         ())[0];
                    }
                    catch (IOException e)
                    {
                        Terminate(1, "I/O error creating jar: " + e.Message);
                        return;
                    }
                    // Rename the temporary file to its final location.
                    string jarPath = argsList[0];
                    try
                    {
                        FileUtil.ReplaceFile(new FilePath(tmpJarPath), new FilePath(jarPath));
                    }
                    catch (IOException e)
                    {
                        Terminate(1, "I/O error renaming jar temporary file to path: " + e.Message);
                        return;
                    }
                }
            }
        }
示例#19
0
 internal static extern Interop.VoiceControl.ErrorCode VcCmdSetFormat(SafeCommandHandle vcCommand, CommandFormat format);
示例#20
0
 internal static extern Interop.VoiceControlWidget.ErrorCode VcCmdGetFormat(SafeCommandHandle vcCommand, out CommandFormat format);
示例#21
0
            public CommandFormat Deserialize(byte[] buffer)
            {
                CommandFormat header = new CommandFormat(buffer[0], buffer[1]);

                for (int i = 0; i < 10; i++)
                {
                    header.Payload[i] = buffer[2 + i];
                }

                return header;
            }