Commit dd44fe48 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Moved help to corresponding files

And hopefully fixed readline-relate issues
parent 43f9d1cb
......@@ -29,7 +29,7 @@ public class AddCommand : Object, Command
if(args.length == 1) {
return error(Err.NAME_NOT_SPECIFIED);
}
if(args[0] == "fake") {
Serial.create_fake_port(args[0]);
stdout.printf("Warning: this action is not implemented in DSerial server\n");
......@@ -56,4 +56,11 @@ public class AddCommand : Object, Command
else
return {}; // => complete nothing
}
public void help(string[] args)
{
stdout.printf("Synopsis: add <fake|file> <port>\n");
stdout.printf("You can add file interfaces or fake ports using this method.\n");
stdout.printf("Warning: This is not implemented in DSerial server.\n");
}
}
......@@ -36,4 +36,12 @@ public class AutodetectCommand : Object, Command
{
return {}; // => nothing
}
public void help(string[] args)
{
stdout.printf("Synopsis: autodetect\n");
stdout.printf("Runs autodetection routine\n");
stdout.printf("Adds newly detected ports to list and removes now nonexisting ports\n");
stdout.printf("This is automatically run before bind/list/other commands when port is not bound\n");
}
}
......@@ -49,4 +49,12 @@ public class AutowriteCommand : Object, Command
return {};
}
}
public void help(string[] args)
{
stdout.printf("Synopsis: autowrite on|off\n");
stdout.printf("Turns automatic write command preparation on/off\n");
stdout.printf("Try \"autowrite on\" to check it out!\n");
stdout.printf("You can always delete write from input to enter different command\n");
}
}
......@@ -44,4 +44,12 @@ public class BindCommand : Object, Command
else
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: bind <port>\n");
stdout.printf("Interactive only\n");
stdout.printf("Other commands requiring port automatically get this value\n");
stdout.printf("It also makes them faster due to preexisting connection\n");
}
}
......@@ -50,4 +50,12 @@ public class CloseCommand : Object, Command
else
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: close <port>\n");
stdout.printf("Closes port and makes it available for applications not using\n");
stdout.printf("D-Bus Serial Interface.\n");
stdout.printf("Port is automatically closed 2 minutes after last use.\n");
}
}
......@@ -38,4 +38,5 @@ public interface Command : Object {
public abstract int execute(string[] args, ApplicationState state);
public abstract string name();
public abstract string[]? args(string[] args, ApplicationState state);
public abstract void help(string[] args);
}
......@@ -36,4 +36,11 @@ public class ExitCommand : Object, Command
{
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: exit\n");
stdout.printf("Interactive only\n");
stdout.printf("Exits session\n");
}
}
......@@ -74,4 +74,18 @@ public class GetCommand : Object, Command
}
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: get <port> <option>\n");
stdout.printf("Display value of one option\n");
stdout.printf("Available settings:\n");
stdout.printf("\t- baudrate\n");
stdout.printf("\t- databits\n");
stdout.printf("\t- stopbits\n");
stdout.printf("\t- parity\n");
stdout.printf("\t- flowcontrol\n");
stdout.printf("\t- accessmode\n");
stdout.printf("\t- name (cannot be set)\n");
}
}
......@@ -46,102 +46,10 @@ public class HelpCommand : Object, Command
stdout.printf("unbind\t\t\t\tRemoves binding (interactive only)\n");
stdout.printf("autowrite on|off\t\tSet whether every line should start with write\n");
stdout.printf("exit\t\t\t\tExits interactive session (interactive only)\n");
}else if(args[0] == "interactive") {
stdout.printf("Enters interactive session.\n");
}else if(args[0] == "exit") {
stdout.printf("Synopsis: exit\n");
stdout.printf("Interactive only\n");
stdout.printf("Exits session\n");
}else if(args[0] == "help") {
stdout.printf("Synopsis: help [command]\n");
stdout.printf("Displays help\n");
stdout.printf("If passed another command then it displays help for that command\n\n");
stdout.printf("Other help topics:\n");
stdout.printf("commands\tJust lists commands available on command line (not interactive)\n");
stdout.printf("topics\tJust lists available help topics\n");
stdout.printf("options\tLists both readonly and readwrite options\n");
stdout.printf("readoptions\tLists only readonly options\n");
}else if(args[0] == "list") {
stdout.printf("Synopsis: list\n");
stdout.printf("Lists all registered ports\n");
stdout.printf("Format - id: name\n");
stdout.printf("All other commands can be passed either id or name\n");
}else if(args[0] == "add") {
stdout.printf("Synopsis: add <fake|file> <port>\n");
stdout.printf("You can add file interfaces or fake ports using this method.\n");
stdout.printf("Warning: This is not implemented in DSerial server.\n");
}else if(args[0] == "info") {
stdout.printf("Synopsis: info <port>\n");
stdout.printf("Displays port settings\n");
stdout.printf("Format:\n");
stdout.printf("<setting>: <value>\n");
}else if(args[0] == "get") {
stdout.printf("Synopsis: get <port> <option>\n");
stdout.printf("Display value of one option\n");
print_available_settings();
}else if(args[0] == "set") {
stdout.printf("Synopsis: set <port> <option> <value>\n");
stdout.printf("Sets setting\n");
print_available_settings();
}else if(args[0] == "values") {
stdout.printf("Synopsis: values <option> [port]\n");
stdout.printf("Displays available option values for options\n");
stdout.printf("Port is required for:\n");
stdout.printf("\t- baudrate\n");
stdout.printf("\t- databits\n");
stdout.printf("\t- stopbits\n");
}else if(args[0] == "open") {
stdout.printf("Synopsis: open <port>\n");
stdout.printf("Opens port. Should not be needed as read and write automatically does open.\n");
}else if(args[0] == "close") {
stdout.printf("Synopsis: close <port>\n");
stdout.printf("Closes port and makes it available for applications not using\n");
stdout.printf("D-Bus Serial Interface.\n");
stdout.printf("Port is automatically closed 2 minutes after last use.\n");
}else if(args[0] == "write") {
stdout.printf("Synopsis: write <port> <message>\n");
stdout.printf("Writes message to port\n");
stdout.printf("[TODO] If message is - then it reads message from standart input.\n\n");
stdout.printf("If you want to write any byte (not only ascii) you write it as follows:\n");
stdout.printf("$Xnumber$\n");
stdout.printf("X is base. One of: \n\tx (hexadecimal)\n\tb (binary)\n\t0 (octal)\n\tnothing(decimal)\n");
stdout.printf("number is number in that base\n\n");
stdout.printf("This command tells you how many bytes and what bytes it sent\n");
stdout.printf("If you want to send ascii $ you write $$\n");
stdout.printf("Number can be arbitrarily sized (up to 10^19 decimal digits)\n");
}else if(args[0] == "read") {
stdout.printf("Synopsis: read <port> [format-string] [format-length]\n");
stdout.printf("Reads from port\n");
stdout.printf("Format string consists of (one or more) folowing letters:\n");
stdout.printf("\tX\tprints hexadecimal numbers (uppercase)\n");
stdout.printf("\tx\tprints hexadecimal numbers (lowercase)\n");
stdout.printf("\tc\tprints characters, nonprintable chars are replaced with dot\n");
stdout.printf("\ts\tsame as c but also prints \\n and \\t and ignores \\r\n");
stdout.printf("\td\tprints decimal numbers (i is same)\n");
stdout.printf("\tb\tprints binary representation\n");
stdout.printf("\tDefault value is Xc\n");
stdout.printf("Format length specifies number of characters per line\n");
stdout.printf("Default is determined automagically from terminal width\n");
}else if(args[0] == "autodetect") {
stdout.printf("Synopsis: autodetect\n");
stdout.printf("Runs autodetection routine\n");
stdout.printf("Adds newly detected ports to list and removes now nonexisting ports\n");
}else if(args[0] == "bind") {
stdout.printf("Synopsis: bind <port>\n");
stdout.printf("Interactive only\n");
stdout.printf("Other commands requiring port automatically get this value\n");
stdout.printf("It also makes them faster due to preexisting connection\n");
}else if(args[0] == "autowrite") {
stdout.printf("Synopsis: autowrite on|off\n");
stdout.printf("Turns automatic write command preparation on/off\n");
stdout.printf("Try \"autowrite on\" to check it out!\n");
}else if(args[0] == "unbind") {
stdout.printf("Synopsis: unbind\n");
stdout.printf("Interactive only\n");
stdout.printf("Removes binding created with bind\n");
}else if(args[0] == "commands") {
stdout.printf("interactive\nhelp\nlist\nadd\ninfo\nget\nset\n");
stdout.printf("values\nopen\nclose\nwrite\ndestroy\nread\nautodetect\n");
for( int i = 0; i < state.command_list.length; i++) {
stdout.printf("%s\n", state.command_list.index(i).name());
}
}else if(args[0] == "topics") {
foreach(string arg in this.args({}, state)) {
stdout.printf("%s\n",arg);
......@@ -151,7 +59,13 @@ public class HelpCommand : Object, Command
stdout.printf("name\n");
}else if(args[0] == "options") {
stdout.printf("baudrate\ndatabits\nstopbits\nparity\nflowcontrol\n");
}else {
} else {
for( int i = 0; i < state.command_list.length; i++) {
if (state.command_list.index(i).name() == args[0]) {
state.command_list.index(i).help(args);
return 0;
}
}
stdout.printf("Unknown help topic \"%s\"\n",args[0]);
}
return 0;
......@@ -171,14 +85,15 @@ public class HelpCommand : Object, Command
return {};
}
private void print_available_settings() {
stdout.printf("Available settings:\n");
stdout.printf("\t- baudrate\n");
stdout.printf("\t- databits\n");
stdout.printf("\t- stopbits\n");
stdout.printf("\t- parity\n");
stdout.printf("\t- flowcontrol\n");
stdout.printf("\t- accessmode\n");
stdout.printf("\t- name (cannot be set)\n");
}
public void help(string[] args)
{
stdout.printf("Synopsis: help [command]\n");
stdout.printf("Displays help\n");
stdout.printf("If passed another command then it displays help for that command\n\n");
stdout.printf("Other help topics:\n");
stdout.printf("commands\tJust lists commands available on command line (not interactive)\n");
stdout.printf("topics\tJust lists available help topics\n");
stdout.printf("options\tLists both readonly and readwrite options\n");
stdout.printf("readoptions\tLists only readonly options\n");
}
}
......@@ -58,4 +58,12 @@ public class InfoCommand : Object, Command
else
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: info <port>\n");
stdout.printf("Displays port settings\n");
stdout.printf("Format:\n");
stdout.printf("<setting>: <value>\n");
}
}
......@@ -59,14 +59,15 @@ public class InteractiveCommand : Object, Command
return (matches);
}
private static bool line_end = false;
private static string? static_line;
private static void readline_linehandler(string? line)
private static ApplicationState sstate;
private static int readline_predisplay()
{
line_end = true;
static_line = line;
if(sstate.autowrite)
Readline.insert_text("write ");
Readline.redisplay();
return 0;
}
public int execute(string[] args, ApplicationState state)
......@@ -78,24 +79,11 @@ public class InteractiveCommand : Object, Command
stdout.printf("Write help for help\n");
Readline.History.read(Environment.get_variable("HOME")+"/.dserial-history");
Readline.attempted_completion_function = readline_completion;
Readline.callback_handler_install("$ ", readline_linehandler);
Readline.pre_input_hook = readline_predisplay;
while(state.running) {
line_end = false;
Readline.set_prompt("$ ");
if(state.autowrite) {
Readline.insert_text("write ");
}
Readline.redisplay();
while(!line_end)
Readline.callback_read_char();
Readline.set_prompt("");
Readline.redisplay();
string? line = static_line;
sstate = state;
string? line = Readline.readline("$ ");
if (line == null) {
stdout.printf("\n");
run_func(state,{"exit"});
......@@ -136,4 +124,9 @@ public class InteractiveCommand : Object, Command
{
return {};
}
public void help(string[] args)
{
stdout.printf("Enters interactive session.\n");
}
}
......@@ -39,4 +39,10 @@ public class ListCommand : Object, Command
{
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: list\n");
stdout.printf("Lists all registered ports\n");
}
}
......@@ -50,4 +50,10 @@ public class OpenCommand : Object, Command
else
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: open <port>\n");
stdout.printf("Opens port. Should not be needed as read and write automatically does open.\n");
}
}
......@@ -74,7 +74,7 @@ public class ReadCommand : Object, Command
uint counter = 0;
uint8[print_length] tmpbuf = new uint8[print_length];
p.open();
p.closing.connect(() => {
p.open();
});
......@@ -196,4 +196,20 @@ public class ReadCommand : Object, Command
else
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: read <port> [format-string] [format-length]\n");
stdout.printf("Reads from port\n");
stdout.printf("Format string consists of (one or more) folowing letters:\n");
stdout.printf(" X\tprints hexadecimal numbers (uppercase)\n");
stdout.printf(" x\tprints hexadecimal numbers (lowercase)\n");
stdout.printf(" c\tprints characters, nonprintable chars are replaced with dot\n");
stdout.printf(" s\tsame as c but also prints \\n as newline and \\t as tab and ignores \\r\n");
stdout.printf(" d\tprints decimal numbers (i is same)\n");
stdout.printf(" b\tprints binary representation\n");
stdout.printf(" Default value is Xc\n");
stdout.printf("Format length specifies number of characters per line\n");
stdout.printf("Default is determined automagically from terminal width\n");
}
}
......@@ -120,4 +120,18 @@ public class SetCommand : Object, Command
}
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: set <port> <option> <value>\n");
stdout.printf("Sets setting\n");
stdout.printf("Available settings:\n");
stdout.printf("\t- baudrate\n");
stdout.printf("\t- databits\n");
stdout.printf("\t- stopbits\n");
stdout.printf("\t- parity\n");
stdout.printf("\t- flowcontrol\n");
stdout.printf("\t- accessmode\n");
stdout.printf("\t- name (cannot be set)\n");
}
}
......@@ -39,4 +39,11 @@ public class UnbindCommand : Object, Command
else
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: unbind\n");
stdout.printf("Interactive only\n");
stdout.printf("Removes binding created with bind\n");
}
}
......@@ -28,7 +28,7 @@ public class ValuesCommand : Object, Command
}
var s = args[0];
OptionValues vals;
if(OptionValues.requires_port(s)) {
Serial.SerialClient p;
......@@ -70,4 +70,14 @@ public class ValuesCommand : Object, Command
}
return {};
}
public void help(string[] args)
{
stdout.printf("Synopsis: values <option> [port]\n");
stdout.printf("Displays available option values for options\n");
stdout.printf("Port is required for:\n");
stdout.printf("\t- baudrate\n");
stdout.printf("\t- databits\n");
stdout.printf("\t- stopbits\n");
}
}
......@@ -166,4 +166,18 @@ public class WriteCommand : Object, Command
return {};
}
}
public void help(string[] args)
{
stdout.printf("Synopsis: write <port> <message>\n");
stdout.printf("Writes message to port\n");
stdout.printf("[TODO] If message is - then it reads message from standart input.\n\n");
stdout.printf("If you want to write any byte (not only ascii) you write it as follows:\n");
stdout.printf("$Xnumber$\n");
stdout.printf("X is base. One of: \n\tx (hexadecimal)\n\tb (binary)\n\t0 (octal)\n\tnothing(decimal)\n");
stdout.printf("number is number in that base\n\n");
stdout.printf("This command tells you how many bytes and what bytes it sent\n");
stdout.printf("If you want to send ascii $ you write $$\n");
stdout.printf("Number can be arbitrarily sized (up to 10^19 decimal digits)\n");
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment