serialsource.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef SERIALSOURCE_H
00018 #define SERIALSOURCE_H
00019 
00020 typedef struct serial_source *serial_source;
00021 
00022 
00023 typedef enum {
00024   msg_unknown_packet_type,      /* packet of unknown type received */
00025   msg_ack_timeout,              /* ack not received within timeout */
00026   msg_sync,                     /* sync achieved */
00027   msg_too_long,                 /* greater than MTU (256 bytes) */
00028   msg_too_short,                /* less than 4 bytes */
00029   msg_bad_sync,                 /* unexpected sync byte received */
00030   msg_bad_crc,                  /* received packet has bad crc */
00031   msg_closed,                   /* serial port closed itself */
00032   msg_no_memory,                /* malloc failed */
00033   msg_unix_error                /* check errno for details */
00034 } serial_source_msg;
00035 
00036 serial_source open_serial_source(const char *device, int baud_rate,
00037                                  int non_blocking,
00038                                  void (*message)(serial_source_msg problem));
00039 /* Effects: opens serial port device at specified baud_rate. If non_blocking
00040      is true, read_serial_packet calls will be non-blocking (writes are
00041      always blocking, for now at least)
00042      If non-null, message will be called to signal various problems during
00043      execution.
00044    Returns: descriptor for serial forwarder at host:port, or
00045      NULL for failure
00046  */
00047 
00048 int serial_source_fd(serial_source src);
00049 /* Returns: the file descriptor used by serial source src (useful when
00050      non-blocking reads were requested)
00051 */
00052 
00053 int serial_source_empty(serial_source src);
00054 /* Returns: true if serial source does not contain any pending data, i.e.,
00055      if the result is true and there is no data available on the source's
00056      file descriptor, then read_serial_packet will:
00057        - return NULL if the source is non-blocking
00058        - block if it is blocking
00059 
00060     (Note: the presence of this calls allows the serial_source to do some
00061     internal buffering)
00062 */
00063 
00064 int close_serial_source(serial_source src);
00065 /* Effects: closes serial source src
00066    Returns: 0 if successful, -1 if some problem occured (but source is
00067      considered closed anyway)
00068  */
00069 
00070 void *read_serial_packet(serial_source src, int *len);
00071 /* Effects: Read the serial source src. If a packet is available, return it.
00072      If in blocking mode and no packet is available, wait for one.
00073    Returns: the packet read (in newly allocated memory), with *len is
00074      set to the packet length, or NULL if no packet is yet available and
00075      the serial source is in non-blocking mode
00076 */
00077 
00078 int write_serial_packet(serial_source src, const void *packet, int len);
00079 /* Effects: writes len byte packet to serial source src
00080    Returns: 0 if packet successfully written, 1 if successfully written
00081      but not acknowledged, -1 otherwise
00082 */
00083 
00084 #endif

Generated on Sat Sep 8 08:36:18 2007 for DTN Reference Implementation by  doxygen 1.5.3