gpio  1.4.2
General Purpose I/O Package
gpioprobe

Macros

#define APP_EC_OK   0
 success exit code
 
#define APP_EC_ARGS   2
 command-line options/arguments error exit code
 
#define APP_EC_EXEC   4
 execution exit code
 

Functions

static int strToInt (const string &str, int &val)
 
static int strToBits (const string &str, byte_t *p)
 
static void mainInit (int argc, char *argv[])
 Main initialization. More...
 
static int sysfsProbe (gpio_info_t *pInfo)
 Probe GPIO state. More...
 
static int sysfsProbeAndPrint ()
 
int main (int argc, char *argv[])
 Main. More...
 

Variables

static char * Argv0
 the command
 
static char * OptsMethod = (char *)"sysfs"
 system file system
 
static int ArgsGpio
 gpio number
 
static OptsPgmInfo_T PgmInfo
 Program information. More...
 
static OptsInfo_T OptsInfo []
 Command line options information. More...
 

Detailed Description

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Main.

Parameters
argcCommand-line argument count.
argvCommand-line argument list.
Returns
Returns 0 on succes, non-zero on failure.

Definition at line 400 of file gpioprobe.cxx.

References APP_EC_ARGS, mainInit(), and OptsMethod.

401 {
402  int ec;
403 
404  mainInit(argc, argv);
405 
406  if( !strcmp(OptsMethod, "sysfs") )
407  {
408  ec = sysfsProbeAndPrint();
409  }
410 #ifdef MMAP_GPIO
411  else if( !strcmp(OptsMethod, "mmap") )
412  {
413  ec = mmapProbeAndPrint();
414  }
415 #endif // MMAP_GPIO
416  else
417  {
418  fprintf(stderr,"%s: Unknown GPIO access method.", OptsMethod);
419  ec = APP_EC_ARGS;
420  }
421 
422  return ec;
423 }
static void mainInit(int argc, char *argv[])
Main initialization.
Definition: gpioprobe.cxx:163
static char * OptsMethod
system file system
Definition: gpioprobe.cxx:58
#define APP_EC_ARGS
command-line options/arguments error exit code
Definition: gpioprobe.cxx:54
static void mainInit ( int  argc,
char *  argv[] 
)
static

Main initialization.

Parameters
argcCommand-line argument count.
argvCommand-line argument list.
Exits:
Program terminates on conversion error.

Definition at line 163 of file gpioprobe.cxx.

References APP_EC_ARGS, ArgsGpio, Argv0, OptsInfo, PgmInfo, and PkgInfo.

Referenced by main().

164 {
165  // name of this process
166  Argv0 = basename(argv[0]);
167 
168  // parse input options
169  argv = OptsGet(Argv0, &PkgInfo, &PgmInfo, OptsInfo, true, &argc, argv);
170 
171  if( argc == 0 )
172  {
173  fprintf(stderr, "%s: No exported GPIO/header pin number specified.\n",
174  Argv0);
175  fprintf(stderr, "Try '%s --help' for more information.\n", Argv0);
176  exit(APP_EC_ARGS);
177  }
178 
179  else if( strToInt(argv[0], ArgsGpio) < 0 )
180  {
181  fprintf(stderr, "%s: '%s': Bad GPIO number.\n", Argv0, argv[0]);
182  fprintf(stderr, "Try '%s --help' for more information.\n", Argv0);
183  exit(APP_EC_ARGS);
184  }
185 }
static int ArgsGpio
gpio number
Definition: gpioprobe.cxx:59
static char * Argv0
the command
Definition: gpioprobe.cxx:57
static OptsPgmInfo_T PgmInfo
Program information.
Definition: gpioprobe.cxx:64
static const PkgInfo_T PkgInfo
Definition: version.h:45
#define APP_EC_ARGS
command-line options/arguments error exit code
Definition: gpioprobe.cxx:54
static OptsInfo_T OptsInfo[]
Command line options information.
Definition: gpioprobe.cxx:82
static int sysfsProbe ( gpio_info_t pInfo)
static

Probe GPIO state.

Method: sysfs

Parameters
[out]pInfoPointer to GPIO info.
Returns
Application exit code.

Definition at line 196 of file gpioprobe.cxx.

References APP_EC_EXEC, APP_EC_OK, ArgsGpio, gpio_info_t::dir, gpio_info_t::edge, gpio_info_t::gpio, GPIO_DIR_IN, GPIO_DIR_IN_STR, GPIO_DIR_OUT, GPIO_DIR_OUT_STR, GPIO_EDGE_BOTH, GPIO_EDGE_BOTH_STR, GPIO_EDGE_FALLING, GPIO_EDGE_FALLING_STR, GPIO_EDGE_NONE, GPIO_EDGE_NONE_STR, GPIO_EDGE_RISING, GPIO_EDGE_RISING_STR, GPIO_PULL_DN, GPIO_PULL_DN_STR, GPIO_PULL_DS_STR, GPIO_PULL_UP, GPIO_PULL_UP_STR, gpioProbe(), gpio_info_t::pin, and gpio_info_t::value.

197 {
198  int ec;
199 
200  if( gpioProbe(ArgsGpio, pInfo) < 0 )
201  {
202  ec = APP_EC_EXEC;
203  }
204  else
205  {
206  ec = APP_EC_OK;
207  }
208 
209  return ec;
210 }
static int ArgsGpio
gpio number
Definition: gpioprobe.cxx:59
int gpioProbe(int gpio, gpio_info_t *p)
Safely probe GPIO parameters.
Definition: gpio.c:346
#define APP_EC_OK
success exit code
Definition: gpioprobe.cxx:53
#define APP_EC_EXEC
execution exit code
Definition: gpioprobe.cxx:55

Variable Documentation

OptsInfo_T OptsInfo[]
static
Initial value:
=
{
{NULL, }
}

Command line options information.

Definition at line 82 of file gpioprobe.cxx.

Referenced by mainInit().

OptsPgmInfo_T PgmInfo
static
Initial value:
=
{
"<gpio>",
"Safely probe GPIO settings and state.",
"The %P command probes the settings and state of GPIO exported number.",
NULL
}

Program information.

Definition at line 64 of file gpioprobe.cxx.

Referenced by mainInit().