#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
Go to the source code of this file.
Data Structures | |
struct | client_info |
ISIS client runtime configuration table. More... | |
Defines | |
#define | ISIS_MSGSIZE 2048 |
Maximum size of an IMPv2 message. | |
#define | ISIS_NODESIZE 9 |
Maximum size of an IMPv2 host node name. | |
#define | LONG_STR_SIZE 4096 |
Length of a generic long string (longer than ISIS_MSGSIZE). | |
#define | MED_STR_SIZE 256 |
Length of a generic medium-sized string. | |
#define | BIG_STR_SIZE 512 |
Length of a generic "big" string, bigger than medium, smaller than long. | |
#define | SHORT_STR_SIZE 32 |
Length of a generic short string. | |
Typedefs | |
typedef client_info | isisclient_t |
ISIS client runtime configuration table. | |
typedef enum IMPv2_MsgType | MsgType |
Enumerations | |
enum | IMPv2_MsgType { REQ, EXEC, STATUS, DONE, ERROR, WARNING, FATAL } |
Functions | |
char * | ISISMessage (char *fromID, char *destID, MsgType msgtype, char *msgbody) |
Create an IMPv2 message string. | |
int | SplitMessage (char *msgstr, char *fromID, char *destID, MsgType *msgtype, char *msgbody) |
Split a raw IMPv2 message string into components. | |
int | InitISISServer (isisclient_t *) |
Initialize the ISIS server address information database. | |
int | OpenClientSocket (isisclient_t *) |
Open an ISIS client socket for this client application. | |
int | ReadClientSocket (isisclient_t *, char *) |
Read a message waiting on the ISIS client socket. | |
int | SendToISISServer (isisclient_t *, char *) |
Send a message to the active ISIS server. | |
int | ReplyToRemHost (isisclient_t *, char *) |
Reply to a remote host that sent us a previous message. | |
void | CloseClientSocket (isisclient_t *) |
Close the ISIS client socket. | |
int | OpenSerialPort (char *) |
Open a serial port. | |
void | CloseSerialPort (int) |
Close an open serial port. | |
int | SetSerialPort (int, int, int, int, int) |
Set the serial port attributes. | |
int | WriteSerialPort (int, char *) |
Write a message string to a serial port. | |
int | ReadSerialPort (int, char *) |
Read data from a serial port. | |
void | FlushSerialPort (int, int) |
Read data from a serial port. | |
void | LeftStr (char *substr, char *str, int nchar) |
Extract the n left-most characters from a given string. | |
void | RightStr (char *substr, char *str, int nchar) |
Extract the n right-most characters from a given string. | |
void | MidStr (char *substr, char *str, int start, int nchar) |
Extract n characters starting in the middle of a string. | |
void | SubStr (char *substr, char *str, int first, int last) |
Extracts a substring from inside a larger string. | |
void | UpperCase (char *str) |
Convert all characters in a string up uppercase. | |
void | GetArg (char *cmdstr, int argnum, char *argstr) |
Extract the n-th argument from a command string with arguments separated by spaces. | |
char * | UTCDate (void) |
Return the UTC date in ISO8601 format. | |
char * | UTCTime (void) |
Return the UTC Time in ISO8601 format. | |
char * | ISODate (void) |
Return the UTC date and time in ISO8601 format. | |
char * | UTCDateTag (void) |
Create a CCYYMMDD date tag string. | |
char * | GetFineTime (void) |
Return UTC time with microsecond precision. | |
double | SysTimestamp (void) |
Return elapsed time since UTC 1970 Jan 1 with microsecond precision. | |
int | MilliSleep (long) |
Pause execution for a certain number of msec. |
This is the main header file for the ISIS client applications library (libisis.a). Client applications only need to include isisclient.h, which encapsulates all of the various bits a client needs to become a basic ISIS client application.
The main client library is divided into 4 modules:
isismessage.c
IMPv2 message handling routines isissocket.c
ISIS UDP socket I/O handling routines isisserial.c
Serial port I/O handling routines isisutils.c
Handy client application utilties (string and time handling)
|
Maximum size of an IMPv2 message.
|
|
Maximum size of an IMPv2 host node name.
|
|
Length of a generic long string (longer than ISIS_MSGSIZE).
|
|
Length of a generic medium-sized string.
|
|
Length of a generic "big" string, bigger than medium, smaller than long.
|
|
Length of a generic short string.
|
|
ISIS client runtime configuration table. Contains the runtime parameters common to all ISIS client applications. Defines the isisclient_t typedef to be used by client applications. |
|
MsgType is a global typedef used by isismessage utilities and any user routines must access IMPv2 message-type codes. |
|
This enum is used by ISIS client routines to specify the IMPv2 message type. |
|
Create an IMPv2 message string.
|
|
Split a raw IMPv2 message string into components.
|
|
Initialize the ISIS server address information database.
To communicate with an active ISIS server, a client application needs to build a socket address database (sockaddr_in struct) with the correct host addressing information for the ISIS server. This information is stored in the isisAddr, a sockaddr_in struct that is a member of the isis_client struct. This routine handles host name resolution and builds the database. We do this once so that we can store all data resulting from DNS lookups, so we don't have to rebuild this info every time (saving time).
|
|
Open an ISIS client socket for this client application.
Once the client socket is opened and bound to its port, the global #ISISclient sockaddr_in struct is created with the socket address database. This way we do not need to regenerate the database each time we read the socket. If port=0 (deprecated), it assigns the client the next free port. Technically this is allowed, and the standard ISIS server will know how to route messages to this client, but if the client is being run in a standalone mode, it will be difficult for the remote application to know which port the client's socket is bound to.
|
|
Read a message waiting on the ISIS client socket.
The hostname and port number of the sending host are extracted and put into the hostname and port variables. This allows the calling application to craft replies to a remote host and send them back directly if the application is a "standalone" client. If instead the application is an ISIS client, it should send any replies back to the ISIS server (see InitISISServer() and SendToISISServer() functions). hostname is returned as an unresolved IP address.
|
|
Send a message to the active ISIS server.
The ISIS server address database must have been initialized by calling InitISISServer(). The ISISserver sockaddr_in struct is defined in global scope in the isissocket.h header file. If sending a message to an ISIS node other than the ISIS server proper, use the ReplyToRemHost() function.
|
|
Reply to a remote host that sent us a previous message.
If sending a message to the ISIS server proper, use the SendToISISServer() function.
|
|
Close the ISIS client socket.
|
|
Open a serial port.
|
|
Close an open serial port.
|
|
Set the serial port attributes.
corresponding to speed=9600, databits=8, stopbits=2, parity=0. The port must have already been opened using OpenSerialPort().
|
|
Write a message string to a serial port.
|
|
Read data from a serial port.
|
|
Read data from a serial port.
|
|
Extract the n left-most characters from a given string.
|
|
Extract the n right-most characters from a given string.
|
|
Extract n characters starting in the middle of a string.
|
|
Extracts a substring from inside a larger string.
|
|
Convert all characters in a string up uppercase.
|
|
Extract the n-th argument from a command string with arguments separated by spaces.
With the command verb itself being considerd argument "0". Returns a null string in argstr if argnum is out of range. |
|
Return the UTC date in ISO8601 format.
Reads the system clock and returns the UTC date in ISO8601-compliant
|
|
Return the UTC Time in ISO8601 format.
Reads the system clock and returns the UTC time in ISO8601-compliant time to the nearest second in
|
|
Return the UTC date and time in ISO8601 format. Reads the system clock and returns the UTC date and time in full ISO8601-compliant date/time format:
where:
|
|
Create a CCYYMMDD date tag string.
Reads the system timeclock and returns the UTC date in
|
|
Return UTC time with microsecond precision.
Reads the system's UTC time clock and returns a pointer to a string with the fine-grained UTC time in Based on gf_time() from Stevens, W.R., 1998, Unix Network Programming, Vol 2, Prentice Hall, Figure 15.6, but I make a string, and extract time to microsec instead of msec. Note: It returns microsecond precision, accuracy is quite another matter...
|
|
Return elapsed time since UTC 1970 Jan 1 with microsecond precision. Reads the system's time clock and returns a double-precision value with the time in seconds and microseconds since UTC 1970 January 1. The primary use of this function is to create a fine-grained numerical timestamp for the system, but other uses are possible. Note: It returns microsecond precision, accuracy is quite another matter...
|
|
Pause execution for a certain number of msec.
See "man 2 nanosleep" for details on the nanosleep() function. |