Main Page | Data Structures | Directories | File List | Data Fields | Globals

comm.c File Reference

#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include "debug.h"
#include <cartcomm/comm.h>
#include <cartcomm/cframe.h>

Include dependency graph for comm.c:

Include dependency graph

Go to the source code of this file.

Defines

#define DEBUG_LEVEL   1

Functions

int cartcomm_connect (char *host, int port)
 Connect to the cart.
void cartcomm_disconnect (int sockfd)
 Disconnect from the cart.
int cartcomm_synchronize (int sockfd)
 Synchronize with the cart.
int cartcomm_connect_sync (char *host, int port)
 Connect and synchronize to the cart.
int cartcomm_read_msg (int sockfd, char *buf, int bufsize)
 Read a message from the cart.
int cartcomm_send_msg (int sockfd, char *buf)
 Send a message to the cart.


Define Documentation

#define DEBUG_LEVEL   1
 

Definition at line 15 of file comm.c.


Function Documentation

int cartcomm_connect char *  host,
int  port
 

Connect to the cart.

Parameters:
host host with which to connect
port port on which to connect
Returns:
socket's file descriptor number (or -1, on failure)

Definition at line 25 of file comm.c.

References DEBUG1, and DEBUG2.

Referenced by cartcomm_connect_sync().

int cartcomm_connect_sync char *  host,
int  port
 

Connect and synchronize to the cart.

Parameters:
host host with which to connect
port port on which to connect
Returns:
socket's file descriptor number (or -1, on failure)

Definition at line 143 of file comm.c.

References cartcomm_connect(), cartcomm_disconnect(), cartcomm_synchronize(), and DEBUG2.

Referenced by drive().

Here is the call graph for this function:

void cartcomm_disconnect int  sockfd  ) 
 

Disconnect from the cart.

Parameters:
sockfd socket's file descriptor number

Definition at line 85 of file comm.c.

Referenced by cartcomm_connect_sync(), and drive().

int cartcomm_read_msg int  sockfd,
char *  buf,
int  bufsize
 

Read a message from the cart.

Parameters:
sockfd socket's file descriptor number
buf buffer to read into
bufsize size of buf in bytes
Return values:
0 success
-1 failure
Note:
This function takes care of a variety of problems associated with using TCP as a datagram delivery protocol. We will gurantee that on success, we have a full frame; partial frames are discarded. If we have fallen behind, we will skip frames to get the latest frame available.
Warning:
This function blocks. Our read will timeout after 2x the communication cycle's length.

Definition at line 177 of file comm.c.

References DEBUG1, and MAX_MSG_SIZE.

Referenced by cartcomm_synchronize(), and drive().

int cartcomm_send_msg int  sockfd,
char *  buf
 

Send a message to the cart.

Parameters:
sockfd socket's file descriptor number
buf buffer containing the message to send
Return values:
0 success
-1 failure
Note:
We will retry up to MAX_RETRIES times to send the message.

Definition at line 240 of file comm.c.

References DEBUG1.

Referenced by cartcomm_synchronize(), and drive().

int cartcomm_synchronize int  sockfd  ) 
 

Synchronize with the cart.

Synchronization means we exchange messages back and forth with each other until the cart is happy with our communications.

Parameters:
sockfd socket's file descriptor number
Return values:
0 success
-1 failure

Definition at line 96 of file comm.c.

References cartcomm_decode_msg(), cartcomm_read_msg(), cartcomm_send_msg(), cframe_t, DEBUG1, DEBUG2, and cframe::status.

Referenced by cartcomm_connect_sync().

Here is the call graph for this function:


Generated on Thu Sep 6 13:13:15 2007 for driver by  doxygen 1.3.9.1