Commit 248230af authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Grzegorz Daniluk

shell: support for multiple GUI (non-batch) commands, move GUI refresh from…

shell: support for multiple GUI (non-batch) commands, move GUI refresh from wrc_main to the shell code
parent a8e94519
......@@ -42,5 +42,6 @@ void shell_show_build_init(void);
void shell_register_command( struct wrc_shell_cmd* cmd );
void shell_list_cmds(void);
void shell_register_commands();
void shell_activate_ui_command( int (*callback)() );
#endif
......@@ -3,15 +3,19 @@
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <wrc.h>
#include "shell.h"
static int cmd_gui(const char *args[])
{
wrc_ui_mode = UI_GUI_MODE;
shell_activate_ui_command( wrc_mon_gui );
return 0;
}
DEFINE_WRC_COMMAND(gui) = {
DEFINE_WRC_COMMAND(gui) =
{
.name = "gui",
.exec = cmd_gui,
};
......@@ -30,6 +30,7 @@
#define SH_PROMPT 0
#define SH_INPUT 1
#define SH_EXEC 2
#define SH_EXEC_UI 3
#define ESCAPE_FLAG 0x10000
......@@ -49,6 +50,7 @@ static struct wrc_shell_cmd *cmds[ SHELL_MAX_COMMANDS ];
static int n_cmds = 0;
int shell_is_interacting;
int (*shell_ui_callback)();
static int insert(char c)
{
......@@ -142,6 +144,7 @@ void shell_init()
{
cmd_len = cmd_pos = 0;
state = SH_PROMPT;
shell_ui_callback = NULL;
}
int shell_interactive()
......@@ -223,8 +226,22 @@ int shell_interactive()
case SH_EXEC:
cmd_buf[cmd_len] = 0;
_shell_exec();
// fixme: ugly hack, we should manage the shell FSM state in a cleaner way.
if( state == SH_EXEC_UI )
return 1;
state = SH_PROMPT;
return 1;
case SH_EXEC_UI:
if( !shell_ui_callback || shell_ui_callback() < 0 || console_getc() == 27 )
{
cmd_buf[cmd_len] = 0;
state = SH_PROMPT;
}
return 1;
}
return 0;
}
......@@ -380,6 +397,14 @@ void shell_list_cmds()
}
}
void shell_activate_ui_command( int (*callback)() )
{
shell_ui_callback = callback;
state = SH_EXEC_UI;
pp_printf("Activateui: %p\n", callback );
cmd_len = 0;
}
#define REGISTER_WRC_COMMAND(_name) \
{ extern struct wrc_shell_cmd __wrc_cmd_ ## _name; shell_register_command( &__wrc_cmd_ ## _name ); }
......
......@@ -56,9 +56,6 @@
#include "lib/snmp.h"
#endif
int wrc_ui_mode = UI_SHELL_MODE;
int wrc_ui_refperiod = TICS_PER_SECOND; /* 1 sec */
int wrc_phase_tracking = 1;
char wrc_hw_name[HW_NAME_LENGTH];
uint32_t cal_phase_transition = 2389;
......@@ -103,7 +100,6 @@ static void wrc_initialize(void)
wrc_board_init();
wrc_ui_mode = UI_SHELL_MODE;
_endram = ENDRAM_MAGIC;
wrc_ptp_set_mode(WRC_MODE_SLAVE);
......@@ -154,18 +150,7 @@ static int wrc_check_link(void)
static int ui_update(void)
{
int ret;
if (wrc_ui_mode == UI_GUI_MODE) {
ret = wrc_mon_gui();
if ( console_getc() == 27 || wrc_ui_refperiod == 0) {
shell_init();
wrc_ui_mode = UI_SHELL_MODE;
}
} else {
ret = shell_interactive();
}
return ret;
return shell_interactive();
}
/* initialize functions to be called after reset in check_reset function */
......
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