Skip to content

Commit

Permalink
Add support for diagnostic mode
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Sep 10, 2013
1 parent c7d4b6e commit 3973c59
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/usb_moded-doc.txt
Expand Up @@ -316,3 +316,11 @@ The different sections of the config file can be split out in different ini file
however take into account usb_moded will need to be restarted to merge these in a
new usb-moded.ini file. As usb_moded will check if new files were added to the /etc/usb-moded
directory and refresh the main ini file as needed on start-up.

diagnostic mode
---------------

Usb-moded supports a diagnostic mode. This requires a special command line parameter (-d).
One mode should be configured in /etc/usb-moded/diag and this will be automatically used.
This is a feature to allow for "hidden" or non-standard modes that are only of use for
testing/QA.
7 changes: 5 additions & 2 deletions src/usb_moded-dyn-config.c
Expand Up @@ -33,14 +33,17 @@

static struct mode_list_elem *read_mode_file(const gchar *filename);

GList *read_mode_list(void)
GList *read_mode_list(int diag)
{
GDir *confdir;
GList *modelist = NULL;
const gchar *dirname;
struct mode_list_elem *list_item;

confdir = g_dir_open(MODE_DIR_PATH, 0, NULL);
if(diag)
confdir = g_dir_open(DIAG_DIR_PATH, 0, NULL);
else
confdir = g_dir_open(MODE_DIR_PATH, 0, NULL);
if(confdir)
{
while((dirname = g_dir_read_name(confdir)) != NULL)
Expand Down
3 changes: 2 additions & 1 deletion src/usb_moded-dyn-config.h
Expand Up @@ -24,6 +24,7 @@


#define MODE_DIR_PATH "/etc/usb-moded/dyn-modes"
#define DIAG_DIR_PATH "/etc/usb-moded/diag"

#define MODE_ENTRY "mode"
#define MODE_NAME_KEY "name"
Expand Down Expand Up @@ -74,6 +75,6 @@ typedef struct mode_list_elem
}mode_list_elem;


GList *read_mode_list(void);
GList *read_mode_list(int diag);

#endif /* USB_MODED_DYN_CONFIG_H_ */
26 changes: 22 additions & 4 deletions src/usb_moded.c
Expand Up @@ -62,9 +62,10 @@ extern const char *log_name;
extern int log_level;
extern int log_type;

gboolean rescue_mode;

gboolean rescue_mode = FALSE;
gboolean diag_mode = FALSE;
gboolean hw_fallback = FALSE;

struct usb_mode current_mode;
guint charging_timeout = 0;
#ifdef NOKIA
Expand Down Expand Up @@ -188,6 +189,17 @@ void set_usb_connected_state(void)
set_usb_mode(MODE_DEVELOPER);
return;
}
if(diag_mode)
{
log_debug("Entering diagnostic mode!\n");
if(modelist)
{
GList *iter = modelist;
struct mode_list_elem *data = iter->data;
set_usb_mode(data->mode_name);
}
return;
}
#ifdef MEEGOLOCK
/* We check also if the device is in user state or not.
If not we do not export anything. We presume ACT_DEAD charging */
Expand Down Expand Up @@ -454,7 +466,7 @@ static void usb_moded_init(void)
#ifdef APP_SYNC
readlist();
#endif /* APP_SYNC */
modelist = read_mode_list();
modelist = read_mode_list(diag_mode);

#ifdef UDEV
if(check_trigger())
Expand Down Expand Up @@ -510,6 +522,7 @@ static void usage(void)
" -s, --force-syslog log to syslog\n"
" -T, --force-stderr log to stderr\n"
" -D, --debug turn on debug printing\n"
" -d, --diag turn on diag mode\n"
" -h, --help display this help and exit\n"
" -r, --rescue rescue mode\n"
" -v, --version output version information and exit\n"
Expand All @@ -527,6 +540,7 @@ int main(int argc, char* argv[])
{ "force-syslog", no_argument, 0, 's' },
{ "force-stderr", no_argument, 0, 'T' },
{ "debug", no_argument, 0, 'D' },
{ "diag", no_argument, 0, 'd' },
{ "help", no_argument, 0, 'h' },
{ "rescue", no_argument, 0, 'r' },
{ "version", no_argument, 0, 'v' },
Expand All @@ -536,7 +550,7 @@ int main(int argc, char* argv[])
log_name = basename(*argv);

/* Parse the command-line options */
while ((opt = getopt_long(argc, argv, "fsTDhrv", options, &opt_idx)) != -1)
while ((opt = getopt_long(argc, argv, "fsTDdhrv", options, &opt_idx)) != -1)
{
switch (opt)
{
Expand All @@ -555,6 +569,10 @@ int main(int argc, char* argv[])
log_level = LOG_DEBUG;
break;

case 'd':
diag_mode = TRUE;
break;

case 'h':
usage();
exit(0);
Expand Down

0 comments on commit 3973c59

Please sign in to comment.