using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using TEST; using UTILS; namespace WIFI { // Some generic shell commands public static class ShellCommands { // Binds to the Shell Core public static void Bind(ShellCore Shell) { Shell.OnCommandReceived += new ShellCore.CommandReceived(Shell_OnCommandReceived); Shell.OnConnected += new ShellCore.ConnectionStateChange(Shell_OnConnected); } // Unbinds from the Shell Core public static void Unbind(ShellCore Shell) { Shell.OnConnected -= new ShellCore.ConnectionStateChange(Shell_OnConnected); Shell.OnCommandReceived -= new ShellCore.CommandReceived(Shell_OnCommandReceived); } // Triggered when the connection has been made private static void Shell_OnConnected(ShellCore Shell, string RemoteAddress, DateTime Time) { Shell.TelnetServer.Color(TelnetServer.Colors.White, TelnetServer.Colors.Black); Shell.TelnetServer.ClearScreen(); _SendMotd(Shell.TelnetServer); } // Sends the MOTD private static void _SendMotd(TelnetServer Server) { Server.Color(TelnetServer.Colors.HighIntensityWhite); Server.Print("Welcome to the Coastal Profiler Telnet Server, Connected to: " + Server.RemoteAddress); Server.Print("Copyright MBARI @ 2013, All rights reserved."); Server.Print("Type HELP to see a list of all supported commands"); Server.Print(""); Server.Color(TelnetServer.Colors.White); } // Triggered when a command has been given private static void Shell_OnCommandReceived(ShellCore Shell, string[] Arguments, ref bool SuspressError, DateTime Time) { switch (Arguments[0].ToUpper()) { case "CLS": Shell.TelnetServer.ClearScreen(); SuspressError = true; break; case "MOTD": _SendMotd(Shell.TelnetServer); SuspressError = true; break; case "ECHO": Shell.TelnetServer.Print(Shell.LastCommandline.Substring(5)); SuspressError = true; break; case "REBOOT": Shell.TelnetServer.Print("Rebooting..."); Thread.Sleep(100); Shell.TelnetServer.Close(); PowerState.RebootDevice(false); SuspressError = true; break; case "QUIT": Shell.TelnetServer.Print("Bye!"); Thread.Sleep(100); Shell.TelnetServer.Close(); SuspressError = true; break; case "INFO": Shell.TelnetServer.Print("Manufacturer: " + SystemInfo.OEMString); Shell.TelnetServer.Print("Firmware version: " + SystemInfo.Version.ToString()); Shell.TelnetServer.Print("Memory available: " + Tools.MetricPrefix(Debug.GC(false), true) + "B"); if (PowerState.Uptime.Days == 0) Shell.TelnetServer.Print("Uptime: " + PowerState.Uptime.ToString()); else Shell.TelnetServer.Print("Uptime: " + PowerState.Uptime.Days.ToString() + " days, " + PowerState.Uptime.ToString()); Shell.TelnetServer.Print("Hardware provider: " + Tools.HardwareProvider); Shell.TelnetServer.Print("System clock: " + Tools.MetricPrefix(Cpu.SystemClock) + "hz"); Shell.TelnetServer.Print("Endianness: " + (SystemInfo.IsBigEndian ? "Big Endian" : "Little Endian")); Shell.TelnetServer.Print("Debugger: " + (System.Diagnostics.Debugger.IsAttached ? "attached" : "not attached")); SuspressError = true; break; case "START": if (FSM.SurfaceOpsState) { FSM.Command = FSM.Commands.Run; Shell.TelnetServer.Print("Starting the CPF"); } else { Shell.TelnetServer.Print("CPF is not in the Surface Operation State"); } SuspressError = true; break; case "LOG": if (FSM.SurfaceOpsState) { FSM.Command = FSM.Commands.DumpLog; FSM.WaitForLogReady(); FSM.Stop(); Shell.TelnetServer.Print("Retrieving the log data."); while (!Log.EndOfFile()) Shell.TelnetServer.Print(Log.Read()); FSM.Command = FSM.Commands.LogOpsDone; // PlatformVelocityController.Initialize(0.0, -3000.0, 3000.0, 0.75, 200.0, 50000.0, 1.0, 2.0, 100.0, 1.0); //FSM.Initialize(); FSM.Start(0.75, 2000); } else { Shell.TelnetServer.Print("CPF is not in the Surface Operation State"); } SuspressError = true; break; case "VER": System.Reflection.Assembly[] Assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < Assemblies.Length; ++i) Shell.TelnetServer.Print(Assemblies[i].FullName); SuspressError = true; break; case "HELP": bool PageFound = false; if (Arguments.Length == 1) PageFound = DoHelp(Shell.TelnetServer, ""); else PageFound = DoHelp(Shell.TelnetServer, Arguments[1].ToUpper()); if (PageFound) SuspressError = true; break; } } // Shows a specific help page private static bool DoHelp(TelnetServer Server, string Page) { switch (Page) { case "": Server.Print("CLS Clears the screen"); Server.Print("ECHO [TEXT] Prints out the text"); Server.Print("MOTD Shows the message of the day"); Server.Print("QUIT Closes the connection"); Server.Print("VER Shows the version of all loaded assemblies"); Server.Print("INFO Shows some system info"); Server.Print("REBOOT Restarts the device"); Server.Print("************ CPF SPECIFIC COMMANDS ************************"); Server.Print("START Starts the CPF"); Server.Print("LOG Retrieves the log data"); return true; case "VER": Server.Print("VER Shows the version of all loaded assemblies"); return true; case "POSITION": Server.Print("POSITION NUM Moves the bellows to NUM mm"); return true; case "REBOOT": Server.Print("REBOOT Restarts the device"); return true; case "MOTD": Server.Print("MOTD Shows the message of the day"); return true; case "INFO": Server.Print("INFO Shows some system info"); return true; case "CLS": Server.Print("CLS Clears the screen"); return true; case "ECHO": Server.Print("ECHO [TEXT] Prints out the text"); Server.Print("- [TEXT] Text to print out"); return true; case "QUIT": Server.Print("QUIT Closes the connection"); return true; case "START": Server.Print("START Starts the CPF"); return true; case "LOG": Server.Print("STOP Retrieves the log data"); return true; default: return false; } } } }