コード例 #1
0
 public Upload(string workDir, Uart uart, string port)
 {
     this.workDir = workDir;
     this.uart    = uart;
     this.port    = port;
     if (UserConfig.Exists())
     {
         this.config = UserConfig.Load();
     }
 }
コード例 #2
0
ファイル: DevMode.cs プロジェクト: espjs/espjs-cli
 public DevMode(string workDir, Uart uart, string port)
 {
     this.workDir = workDir;
     this.uart    = uart;
     this.port    = port;
     if (UserConfig.Exists())
     {
         hasUserConfig = true;
         config        = UserConfig.Load();
     }
 }
コード例 #3
0
        /// <summary>
        /// 程序入口
        /// </summary>
        /// <param name="args">用户输入的参数</param>
        public void Run(string[] args)
        {
            this.args = args;

            if (IsBaseCommand())
            {
                Next();
            }
            else if (!Uart.HasPort())
            {
                Console.WriteLine("没有可用端口");
                Next();
            }
            else
            {
                UartCommand();
                Next();
            }
        }
コード例 #4
0
ファイル: InputMode.cs プロジェクト: espjs/espjs-cli
        public static void Run(Uart uart, string port)
        {
            string code = "";

            while (true)
            {
                Console.Write("# ");
                string newLine = Console.ReadLine();
                if (newLine == "<<<")
                {
                    break;
                }
                code += "\n" + newLine;
            }
            Console.Write("是否运行代码(y/n): ");
            if (Console.ReadLine() != "n")
            {
                uart.SendCode(port, code);
            }
        }
コード例 #5
0
        public static void Run(Uart uart, string port)
        {
            Console.WriteLine("已进入shell模式, 输入exit可以退出shell模式.");
            uart.newLinePrev = "# ";
            while (true)
            {
                Console.Write("# ");
                string newLine = Console.ReadLine();
                if (newLine == "exit" || newLine == "quit")
                {
                    Console.WriteLine("退出shell模式.");
                    break;
                }

                if (newLine != "")
                {
                    uart.SendCode(port, newLine);
                }
            }
            uart.newLinePrev = "> ";
        }
コード例 #6
0
        public App(bool runOnce = false)
        {
            if (Uart.HasPort())
            {
                port = Uart.GetPort();
            }

            this.runOnce = runOnce;

            if (!runOnce)
            {
                Console.WriteLine("输入help获取帮助信息");
            }

            // 设置工作目录
            this.workDir = Directory.GetCurrentDirectory();
            string execFile = System.Reflection.Assembly.GetExecutingAssembly().Location;

            this.execDir = Directory.GetParent(execFile).FullName;

            // 加载基础配置
            this.config      = Config.Load();
            uart.sp.BaudRate = this.config.BaudRate;

            // 加载用户配置
            if (UserConfig.Exists())
            {
                this.hasUserConfig = true;
                this.userConfig    = UserConfig.Load();

                // 设置串口参数
                this.uart.sp.BaudRate = this.userConfig.BaudRate;
            }
            else
            {
                // 设置串口参数
                this.uart.sp.BaudRate = config.BaudRate;
            }
        }
コード例 #7
0
        public static void Run(Uart uart, string port, string[] args)
        {
            string cmd = "list";

            if (args.Length <= 1)
            {
                cmd = args[0];
            }
            else
            {
                cmd = args[1];
            }
            switch (cmd)
            {
            case "ll":
            case "ls":
            case "dir":
            case "list":
                uart.SendCode(port, @"(function(){var list=require('Storage').list();console.log(list.join('\n'));})();");
                break;

            case "free":
                uart.SendCode(port, "(_=>{");
                uart.SendCode(port, "mem=process.memory();");
                uart.SendCode(port, "usage=mem.usage*mem.blocksize + 'B';");
                uart.SendCode(port, "total=mem.total*mem.blocksize + 'B';");
                uart.SendCode(port, "s=require('Storage').getFree() + 'B';");
                uart.SendCode(port, "console.log('storage free: ', s);");
                uart.SendCode(port, "console.log('memory used: ' + usage + '/' + total);");
                uart.SendCode(port, "})();");
                break;

            case "clear":
                uart.SendCode(port, "require('Storage').eraseAll();E.reboot();");
                break;

            case "delete":
            case "remove":
                if (args.Length <= 1)
                {
                    Console.WriteLine("请输入Storage的名称");
                    return;
                }
                uart.SendCode(port, "require('Storage').erase('" + args[2] + "')");
                break;

            case "cat":
            case "get":
            case "read":
                if (args.Length <= 1)
                {
                    Console.WriteLine("请输入Storage的名称");
                    return;
                }
                uart.SendCode(port, "console.log(require('Storage').read('" + args[2] + "'))");
                break;

            case "save":
            case "write":
                if (args.Length <= 3)
                {
                    Console.WriteLine("Storage的名称或内容不能为空");
                    return;
                }
                uart.SendCode(port, "require('Storage').write('" + args[2] + "','" + args[3] + "')");
                break;
            }
        }