![]() |
i2c
1.4.2
RoadNarrows Robotics I2C Package
|
Simple I2C Bus Command-Line Shell. More...
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <libgen.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/opts.h"
#include "rnr/i2c.h"
#include "version.h"
Go to the source code of this file.
Classes | |
struct | shcmd_t |
Shell Command Info. More... | |
Macros | |
#define | RC_QUIT (RC_ERROR-1) |
quit shell return code | |
Typedefs | |
typedef int( | execfunc_t) (i2c_t *, int, const char *[]) |
Command execution function type. | |
Functions | |
static int | StrToUnsigned (const char *s, uint_t *pVal) |
Convert string to unsigned integer. More... | |
static int | StrToByte (const char *s, byte_t *pByte) |
Convert string to byte. More... | |
static const char ** | makeargs (char *sLine, int *pArgc) |
Make array of arguments separated with white-space. More... | |
static char * | readline (const char *prompt) |
Read an input line from stdin. More... | |
static int | execRead (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute I2C slave device read. More... | |
static int | execWrite (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute I2C slave device write. More... | |
static int | execTransaction (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute I2C slave device write/read transaction. More... | |
static int | scanCallback (i2c_t *pI2C, i2c_addr_t addr, void *context) |
Found scanned device callback. More... | |
static int | execScan (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute I2C slave device scan. More... | |
static int | execCheck (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute I2C slave device check. More... | |
static int | execVerbose (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute enabling/disabling verbose printing. More... | |
static int | execHelp (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute shell help. More... | |
static int | execQuit (i2c_t *pI2C, int nArgc, const char *sArgv[]) |
Execute quit shell. More... | |
static void | MainInit (int argc, char *argv[], i2c_t *pI2C) |
Command initialization. More... | |
static void | MainLoop (i2c_t *pI2C) |
Shell main loop. More... | |
int | main (int argc, char *argv[]) |
i2csh main() More... | |
Variables | |
static char * | Argv0 |
command name | |
static int | OptVerbose = 0 |
verbose option | |
static char * | OptDevName = "/dev/i2c/0" |
i2c bus device option | |
static OptsPgmInfo_T | I2CShPgmInfo |
Program Information. More... | |
static OptsInfo_T | I2CShOptsInfo [] |
Command Line Options Information. More... | |
static shcmd_t | I2CCmds [] |
forward declaration of shell commands More... | |
Simple I2C Bus Command-Line Shell.
Definition in file i2csh.c.
|
static |
Execute I2C slave device check.
check <addr>
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 627 of file i2csh.c.
References i2c_exists(), OptVerbose, and StrToByte().
Referenced by execQuit().
|
static |
Execute shell help.
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 730 of file i2csh.c.
References shcmd_t::m_sCmd, shcmd_t::m_sHelpArgs, and shcmd_t::m_sHelpBrief.
Referenced by execQuit().
|
static |
Execute quit shell.
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 756 of file i2csh.c.
References execCheck(), execHelp(), execRead(), execScan(), execTransaction(), execVerbose(), execWrite(), i2c_close(), and RC_QUIT.
|
static |
Execute I2C slave device read.
read <addr> <readlength>
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 297 of file i2csh.c.
References i2c_read(), OptVerbose, StrToByte(), and StrToUnsigned().
Referenced by execQuit().
|
static |
Execute I2C slave device scan.
scan
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 587 of file i2csh.c.
References i2c_scan(), OptVerbose, and scanCallback().
Referenced by execQuit().
|
static |
Execute I2C slave device write/read transaction.
transaction <addr> <wbyte0> [<wbyte1> ...] <readlength>
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 469 of file i2csh.c.
References i2c_transfer(), OptVerbose, StrToByte(), and StrToUnsigned().
Referenced by execQuit().
|
static |
Execute enabling/disabling verbose printing.
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 690 of file i2csh.c.
References OptVerbose.
Referenced by execQuit().
|
static |
Execute I2C slave device write.
write <addr> <wbyte0> [<wbyte1> ...]
pI2C | Pointer to I2C handle. |
nArgc | Number of input arguments. |
sArgv | Array of input argument strings. |
Definition at line 386 of file i2csh.c.
References i2c_write(), OptVerbose, and StrToByte().
Referenced by execQuit().
int main | ( | int | argc, |
char * | argv[] | ||
) |
i2csh main()
argc | Count of command-line options and arguments. |
argv | Array of command-line options and arguments. |
Definition at line 929 of file i2csh.c.
References MainInit(), and MainLoop().
|
static |
Command initialization.
argc | Command-line argument count. |
argv | Command-line arguments. |
pI2C | Pointer to I2C handle. |
Definition at line 832 of file i2csh.c.
References Argv0, i2c_open(), I2CShOptsInfo, I2CShPgmInfo, OptDevName, OptVerbose, and PkgInfo.
Referenced by main().
|
static |
Shell main loop.
pI2C | Pointer to I2C handle. |
Definition at line 866 of file i2csh.c.
References shcmd_t::m_fnExec, shcmd_t::m_sCmd, makeargs(), RC_QUIT, and readline().
Referenced by main().
|
static |
Make array of arguments separated with white-space.
sLine | Input line. | |
[out] | pArgc | Number of parsed arguments |
Definition at line 218 of file i2csh.c.
Referenced by MainLoop().
|
static |
Read an input line from stdin.
This function is used only if there is no readline functionality.
prompt | User prompt string. |
Definition at line 243 of file i2csh.c.
Referenced by MainLoop().
|
static |
Found scanned device callback.
pI2C | Pointer to I2C handle. |
addr | Slave device address. |
context | User provided context. |
Definition at line 570 of file i2csh.c.
Referenced by execScan().
|
static |
Convert string to byte.
s | String. | |
[out] | pByte | Pointer to converted value. |
Definition at line 191 of file i2csh.c.
References StrToUnsigned().
Referenced by execCheck(), execRead(), execTransaction(), and execWrite().
|
static |
Convert string to unsigned integer.
s | String. | |
[out] | pVal | Pointer to converted value. |
Definition at line 156 of file i2csh.c.
Referenced by execRead(), execTransaction(), and StrToByte().
|
static |
|
static |
Command Line Options Information.
Definition at line 114 of file i2csh.c.
Referenced by MainInit().
|
static |
Program Information.
Definition at line 103 of file i2csh.c.
Referenced by MainInit().