# cmd.c File Reference

This file contains functions to parse the telnet commands. More...

`#include <string.h>`
`#include <stdio.h>`
`#include <sys/socket.h>`
`#include <sys/time.h>`
`#include <net/route.h>`
`#include <netinet/inet.h>`
`#include <iwconfig.h>`
`#include "cmd.h"`
`#include "raven.h"`
`#include "server.h"`

Include dependency graph for cmd.c:

## Data Structures
struct | cmd_desc
| shell command structure More...
## Defines
#define | MIN(x, y) ((x<y)?x:y)
| simple macro that returns the smaller of two values
## Typedefs
typedef int | cmd_fun_t (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| shell command helper function type
typedef struct cmd_desc | cmd_desc_t
## Functions
int | help_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| function decalarations
int | ledOn_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that turns on the LED
int | ledOff_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that turns off the LED
int | blink_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that sets the number of blinks in the blink interval
int | lcd_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that prints a message to the LCD
int | temp_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that samples the temperature using the onboard sensor
int | time_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that prints the local time at the raven
int | rte_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that prints the route information
int | if_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that invokes iwconfig() with option STATUS to get the wireless interface information
int | exit_fun (char *msg, char *buf, int curindex, int len, int16_t sockfd)
| helper function that closes the TCP connection by returning -1
void | iwconfig_status_handler (event_t event, void *cbargs, void *context)
| callback for iwconfig() invoked with STATUS flag
void | prompt (int16_t sockfd)
| this function sends a prompt to a TCP socket
uint8_t | skip (char *str, uint8_t i, uint8_t e, char *skips)
| Skip over chars.
int | processCmd (char *cmd, int curindex, int len, int16_t sockfd)
| process shell command
## Variables
cmd_desc_t | cmd_table []
| data base of supported shell commands
static net_device_info_t | fs_lpan0_info
| Network interface information from iwconfig.
static int16_t | fs_sockfd
| file scope socket descriptor

## Detailed Description

This file contains functions to parse the telnet commands.

## Define Documentation

#define MIN | ( | x,
|  | y |  | ) | ((x<y)?x:y)

simple macro that returns the smaller of two values

## Typedef Documentation

typedef struct cmd_desc cmd_desc_t

typedef int cmd_fun_t(char *msg, char *buf, int curindex, int len, int16_t sockfd)

shell command helper function type

## Function Documentation

int blink_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that sets the number of blinks in the blink interval

blink_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

int exit_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that closes the TCP connection by returning -1

exit_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  -1: close command shell

int help_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

function decalarations

helper function that prints the help text at the prompt

help_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

int if_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that invokes iwconfig() with option STATUS to get the wireless interface information

if_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  1: waiting for callback from iwconfig_status_handler()

Here is the call graph for this function:

void iwconfig_status_handler | ( | event_t | event,
|  | void * | cbargs,
|  | void * | context |
| ) |  |  |

callback for iwconfig() invoked with STATUS flag

iwconfig_status_handler

Parameters:

  | event | equals to IWCONFIG as this is a iwconfig() STATUS callback
  | cbargs | passes dev_info back from iwconfig() STATUS call
  | context | passes context back from iwconfig() STATUS call

Returns:
  none

Here is the call graph for this function:

int lcd_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that prints a message to the LCD

lcd_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

int ledOff_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that turns off the LED

ledOff_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

int ledOn_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that turns on the LED

ledOn_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

int processCmd | ( | char * | cmd,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

process shell command

processCmd

Process command in command buffer cmd[] starting at cmd[curindex] and ending at cmd[len] Dispatches to individual command handlers

Parameters:

  | cmd | is the pointer to the string of shell command
  | curindex | is always zero
  | len | is the number of characters in the shell command
  | sockfd | is the TCP socket descriptor

Returns:
  0 or positive integers : Normal

  negative integers : Close

Here is the call graph for this function:

void prompt | ( | int16_t | sockfd | ) |

this function sends a prompt to a TCP socket

prompt

Parameters:

  | sockfd | is the descriptor of the socket

Returns:
  none

Here is the call graph for this function:

int rte_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that prints the route information

rte_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

uint8_t skip | ( | char * | str,
|  | uint8_t | i,
|  | uint8_t | e,
|  | char * | skips |
| ) |  |  |

Skip over chars.

skip

Parameters:

  | str | is the pointer to the string to process (skip)
  | i | is the starting position within str
  | e | is the length of the str
  | skips | is a pointer to the array of characters to stop on

Returns:
  curindex of first non-skip char

  -1 if none encountered

int temp_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that samples the temperature using the onboard sensor

temp_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

int time_fun | ( | char * | msg,
|  | char * | buf,
|  | int | curindex,
|  | int | len,
|  | int16_t | sockfd |
| ) |  |  |

helper function that prints the local time at the raven

time_fun

Parameters:

  | msg | is a pointer to the response message
  | buf | is a pointer to the shell command received
  | curindex | is the starting position of the shell command argument within buf
  | len | is the total length of the shell command (command + argument)
  | sockfd | is the socket descriptor

Returns:
  0: ready for next prompt

Here is the call graph for this function:

## Variable Documentation

cmd_desc_t cmd_table[]

Initial value:

     {
      {help_fun,   "?",     "print cmds"},
      {ledOn_fun,  "lon",   "LED on"},
      {ledOff_fun, "loff",  "LED off"},
      {blink_fun,  "blink", "Blink N"},
      {lcd_fun,    "lcd",   "display msg"},
      {temp_fun,   "temp",  "display temp"},
      {time_fun,   "time",  "time of day"},
      {rte_fun,    "route", "info"},
      {if_fun,     "ifconfig", "IP config"},
      {exit_fun,   "exit",  "exit shell"}
    }

data base of supported shell commands

net_device_info_t fs_lpan0_info`[static]`

Network interface information from iwconfig.

int16_t fs_sockfd`[static]`

file scope socket descriptor