Пример #1
0
        protected static int ProcessArguments(string[] args)
        {
            int iReturn = -1; // -1=Nothing done; 0=Failed; 1=Success

            bool   bVersion    = false;
            bool   bHelp       = false;
            bool   bScan       = false;
            bool   bDumpConfig = false;
            bool   bDaemon     = false;
            byte   iSoftReset  = 0;
            byte   iHardReset  = 0;
            byte   iGetIdent   = 0;
            byte   iSetAddr    = 0;
            byte   iSetType    = 0;
            byte   iSetDesc    = 0;
            string sSetDesc    = null;

            if (args.Length > 0)
            {
                int i = 0;
                int l = 0;
                while (i < args.Length)
                {
                    if (args[i] == "--version")
                    {
                        bVersion = true;
                    }
                    else if (args[i] == "--help")
                    {
                        bVersion = true;
                        bHelp    = true;
                    }
                    else if (args[i] == "--scan")
                    {
                        bScan = true;
                    }
                    else if (args[i] == "--dumpconfig")
                    {
                        bDumpConfig = true;
                    }
                    else if (args[i] == "--daemon")
                    {
                        bDaemon = true;
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--ident", 1, ref iGetIdent)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--setaddr", 1, ref iSetAddr)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--settype", 1, ref iSetType)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--setdesc", 2, ref iSetDesc)) != 0)
                    {
                        if (l > 0)
                        {
                            sSetDesc = args[i + 2];
                            if (sSetDesc.Length > ICCConstants.DESCSIZE)
                            {
                                Console.WriteLine(string.Format("Description too long in argument passed to {0} {1} {2}\n", args[i], args[i + 1], args[i + 2]));
                                return(0);
                            }
                            i += 2;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--softreset", 1, ref iSoftReset)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else if ((l = CheckArgumentGetByte(args, i, "--hardreset", 1, ref iHardReset)) != 0)
                    {
                        if (l > 0)
                        {
                            i++;
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unknown argument %s\n", args[i]);
                        return(0);
                    }
                    i++;
                }
            }

            if (bVersion && args.Length > 2)
            {
                Console.WriteLine("Argument --version should be used alone.\n");
                return(0);
            }
            if (bHelp && args.Length > 2)
            {
                Console.WriteLine("Argument --help should be used alone.\n");
                return(0);
            }
            if (bScan && args.Length > 2)
            {
                Console.WriteLine("Argument --scan should be used alone.\n");
                return(0);
            }
            if (bDumpConfig && args.Length > 2)
            {
                Console.WriteLine("Argument --dumpconfig should be used alone.\n");
                return(0);
            }
            if (bDaemon && args.Length > 2)
            {
                Console.WriteLine("Argument --daemon should be used alone.\n");
                return(0);
            }

            if (bVersion)
            {
                PrintVersion();
                iReturn = 1;
            }

            if (bHelp)
            {
                PrintHelp(args[0]);
                iReturn = 1;
            }

            if (bScan)
            {
                PrintModuleList();
                iReturn = 1;
            }

            if (bDumpConfig)
            {
                var sw = new StreamWriter(Console.OpenStandardOutput());
                sw.AutoFlush = true;
                Console.SetOut(sw);
                Conf.Display(sw);
                iReturn = 1;
            }

            if (bDaemon)
            {
                var d = new DaemonManager(Biccp, Conf, Log);
                return(d.Start() ? 1 : 0);
            }

            if (iGetIdent != 0)
            {
                if (Conf.Modules.ContainsKey(iGetIdent))
                {
                    var ccMod = Conf.Modules[iGetIdent];
                    Console.WriteLine("\n");
                    Console.WriteLine(string.Format("    Version     : {0}.{1}.{2}", ccMod.Major, ccMod.Minor, ccMod.Build));
                    Console.WriteLine(string.Format("    Address     : 0x{0:x2}", iGetIdent));
                    Console.WriteLine(string.Format("    Type        : 0x{0:x2} - {1}", ccMod.Type, ccMod.TypeDescription));
                    Console.WriteLine(string.Format("    Description : {0}", ccMod.Description));
                    Console.WriteLine("\n");
                }
                iReturn = 1;
            }
            if (iSetAddr != 0)
            {
                var mod = new NewModule()
                {
                    ID = 0x77, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SetAddress(iSetAddr);
                iReturn = 1;
            }
            if (iSetType != 0)
            {
                var mod = new NewModule()
                {
                    ID = 0x77, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SetType(iSetType);
                iReturn = 1;
            }
            if (iSetDesc != 0)
            {
                var mod = new NewModule()
                {
                    ID = iSetDesc, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SetDescription(sSetDesc);
                iReturn = 1;
            }
            if (iSoftReset != 0)
            {
                var mod = new NewModule()
                {
                    ID = iSoftReset, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.SoftReset();
                iReturn = 1;
            }
            if (iHardReset != 0)
            {
                var mod = new NewModule()
                {
                    ID = iHardReset, Log = Log
                };
                mod.ActionRaised += Mod_ActionRaised;
                mod.HardReset();
                iReturn = 1;
            }

            return(iReturn);
        }