Commit 4147945c authored by Alén Arias Vázquez's avatar Alén Arias Vázquez 😎

added gateware command

parent 42a40879
Pipeline #3823 canceled with stages
in 14 minutes and 3 seconds
......@@ -13,13 +13,6 @@
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <byteswap.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <time.h>
#include <limits.h>
#include <stdint.h>
#include <readline/readline.h>
#include <readline/history.h>
......@@ -36,6 +29,7 @@
#include "util.h"
#include "fru_utils.h"
#include "fpga_device.h"
#define DTB_HW_VER_FILE "/sys/firmware/devicetree/base/chosen/hw_ver"
#define DTB_MODEBOOT_FILE "/sys/firmware/devicetree/base/chosen/modeboot"
......@@ -95,10 +89,10 @@ struct command_entry commands_list[] = {
{ .cmd_name = "fantray", .cmd_func = cmd_fantray, .cmd_help_string = "Commands for fantray module. Type \"help "
"fantray\" for more information about "
"subcommands\n", .cmd_params = NULL},
{ .cmd_name = "gateware", .cmd_func = cmd_fpga, .cmd_help_string = "Print information related to the gateware. Type help for more information\n", .cmd_params = NULL},
{ .cmd_name = NULL }
};
int cmd_help(char *params)
{
struct command_entry *entry = commands_list;
......@@ -106,14 +100,14 @@ int cmd_help(char *params)
/* Print fantray's help if requested */
if (params && !strncmp(params, "fantray", strlen("fantray")))
entry = commands_list_fantray;
printf("diot_util for HW version %d\n", SB_VER);
printf("Avaiable commands:\n");
while (entry->cmd_name) {
sprintf(buf, "%s %s", entry->cmd_name,
entry->cmd_params ? entry->cmd_params : "");
printf("%-18s - %s", buf, entry->cmd_help_string);
entry++;
entry = commands_list_fantray;
printf("diot_util for HW version %d\n", SB_VER);
printf("Available commands:\n");
while (entry->cmd_name) {
sprintf(buf, "%s %s", entry->cmd_name,
entry->cmd_params ? entry->cmd_params : "");
printf("%-18s - %s", buf, entry->cmd_help_string);
entry++;
}
return 0;
......@@ -480,7 +474,7 @@ int main(int argc, char **argv)
/* Copy command like readline would do */
line_read = strndup(curr_script_cmd, cmd_len);
}
} else {
} else {
/* Get a line from the user. */
line_read = readline (READLINE_PROMPT);
}
......@@ -540,6 +534,9 @@ int main(int argc, char **argv)
char *
command_name_generator_fantray(const char *text, int state);
char *
command_name_generator_gateware(const char *text, int state);
char **
command_completion(const char *text, int start, int end)
{
......@@ -547,13 +544,17 @@ command_completion(const char *text, int start, int end)
rl_attempted_completion_over = 1;
/* Call completion function if the first word */
if (start == 0)
return rl_completion_matches(text, command_name_generator);
if (start == 0){
return rl_completion_matches(text, command_name_generator);
}
if (!strncmp(rl_line_buffer, "fantray load_fw", strlen("fantray load_fw"))) {
return rl_completion_matches(text, rl_filename_completion_function);
return rl_completion_matches(text, rl_filename_completion_function);
}
if (!strncmp(rl_line_buffer, "fantray", strlen("fantray"))) {
return rl_completion_matches(text, command_name_generator_fantray);
return rl_completion_matches(text, command_name_generator_fantray);
}
if (!strncmp(rl_line_buffer, "gateware", strlen("gateware"))) {
return rl_completion_matches(text, command_name_generator_gateware);
}
return NULL;
}
......@@ -597,3 +598,23 @@ char *command_name_generator_fantray(const char *text, int state)
return NULL;
}
/* command name generator for fantray */
char *command_name_generator_gateware(const char *text, int state)
{
static int list_index, len;
char *name;
if (!state) {
list_index = 0;
len = strlen(text);
}
while ((commands_list_fpga_device[list_index].cmd_name) && (name = commands_list_fpga_device[list_index++].cmd_name)) {
if (strncmp(name, text, len) == 0) {
return strdup(name);
}
}
return NULL;
}
\ No newline at end of file
Markdown is supported
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