serialsource.h

Go to the documentation of this file.
00001 #ifndef SERIALSOURCE_H
00002 #define SERIALSOURCE_H
00003 
00004 typedef struct serial_source *serial_source;
00005 
00006 
00007 typedef enum {
00008   msg_unknown_packet_type,      /* packet of unknown type received */
00009   msg_ack_timeout,              /* ack not received within timeout */
00010   msg_sync,                     /* sync achieved */
00011   msg_too_long,                 /* greater than MTU (256 bytes) */
00012   msg_too_short,                /* less than 4 bytes */
00013   msg_bad_sync,                 /* unexpected sync byte received */
00014   msg_bad_crc,                  /* received packet has bad crc */
00015   msg_closed,                   /* serial port closed itself */
00016   msg_no_memory,                /* malloc failed */
00017   msg_unix_error                /* check errno for details */
00018 } serial_source_msg;
00019 
00020 serial_source open_serial_source(const char *device, int baud_rate,
00021                                  int non_blocking,
00022                                  void (*message)(serial_source_msg problem));
00023 /* Effects: opens serial port device at specified baud_rate. If non_blocking
00024      is true, read_serial_packet calls will be non-blocking (writes are
00025      always blocking, for now at least)
00026      If non-null, message will be called to signal various problems during
00027      execution.
00028    Returns: descriptor for serial forwarder at host:port, or
00029      NULL for failure
00030  */
00031 
00032 int serial_source_fd(serial_source src);
00033 /* Returns: the file descriptor used by serial source src (useful when
00034      non-blocking reads were requested)
00035 */
00036 
00037 int serial_source_empty(serial_source src);
00038 /* Returns: true if serial source does not contain any pending data, i.e.,
00039      if the result is true and there is no data available on the source's
00040      file descriptor, then read_serial_packet will:
00041        - return NULL if the source is non-blocking
00042        - block if it is blocking
00043 
00044     (Note: the presence of this calls allows the serial_source to do some
00045     internal buffering)
00046 */
00047 
00048 int close_serial_source(serial_source src);
00049 /* Effects: closes serial source src
00050    Returns: 0 if successful, -1 if some problem occured (but source is
00051      considered closed anyway)
00052  */
00053 
00054 void *read_serial_packet(serial_source src, int *len);
00055 /* Effects: Read the serial source src. If a packet is available, return it.
00056      If in blocking mode and no packet is available, wait for one.
00057    Returns: the packet read (in newly allocated memory), with *len is
00058      set to the packet length, or NULL if no packet is yet available and
00059      the serial source is in non-blocking mode
00060 */
00061 
00062 int write_serial_packet(serial_source src, const void *packet, int len);
00063 /* Effects: writes len byte packet to serial source src
00064    Returns: 0 if packet successfully written, 1 if successfully written
00065      but not acknowledged, -1 otherwise
00066 */
00067 
00068 #endif

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1