Building Controls Virtual Test Bed
|
#include "utilSocket.h"
Go to the source code of this file.
Functions | |
int | save_append (char **buffer, const char *toAdd, int *bufLen) |
Appends a character array to another character array. More... | |
int | assembleBuffer (int flag, int nDbl, int nInt, int nBoo, double curSimTim, double dblVal[], int intVal[], int booVal[], char **buffer, int *bufLen) |
Assembles the buffer that will be exchanged through the IPC. More... | |
int | getIntCheckError (const char *nptr, char **endptr, const int base, int *val) |
Gets an integer and does the required error checking. More... | |
int | getDoubleCheckError (const char *nptr, char **endptr, double *val) |
Gets a double and does the required error checking. More... | |
int | disassembleHeaderBuffer (const char *buffer, char **endptr, const int base, int *fla, int *nDbl, int *nInt, int *nBoo) |
Disassembles the header of the buffer that has been received through the IPC. More... | |
int | disassembleBuffer (const char *buffer, int *fla, int *nDbl, int *nInt, int *nBoo, double *curSimTim, double dblVal[], int intVal[], int booVal[]) |
Disassembles the buffer that has been received through the IPC. More... | |
int | getsocketportnumber (const char *const docname) |
Gets the port number for the BSD socket communication. More... | |
int | getmainversionnumber () |
Returns the version number of the client. More... | |
int | getsockethost (const char *const docname, char *const hostname) |
Gets the hostname for the BSD socket communication. More... | |
int | establishclientsocket (const char *const docname) |
Establishes a connection to the socket. More... | |
int | writetosocket (const int *sockfd, const int *flaWri, const int *nDblWri, const int *nIntWri, const int *nBooWri, double *curSimTim, double dblValWri[], int intValWri[], int booValWri[]) |
Writes data to the socket. More... | |
int | sendclientmessage (const int *sockfd, const int *flaWri) |
Writes a message flag to the socket stream. More... | |
int | getRequiredReadBufferLength (const int *sockfd) |
Returns the required socket buffer length by reading from the socket how many data it contains. More... | |
int | getrequiredbufferlength (const int nDbl, const int nInt, const int nBoo) |
Returns the required socket buffer length. More... | |
int | readfromsocket (const int *sockfd, int *flaRea, int *nDblRea, int *nIntRea, int *nBooRea, double *curSimTim, double dblValRea[], int intValRea[], int booValRea[]) |
Reads data from the socket. More... | |
int | readbufferfromsocket (const int *sockfd, char *buffer, int *bufLen) |
Reads a character buffer from the socket. More... | |
int | exchangewithsocket (const int *sockfd, const int *flaWri, int *flaRea, const int *nDblWri, const int *nIntWri, const int *nBooWri, int *nDblRea, int *nIntRea, int *nBooRea, double *simTimWri, double dblValWri[], int intValWri[], int booValWri[], double *simTimRea, double dblValRea[], int intValRea[], int booValRea[]) |
Exchanges data with the socket. More... | |
int | exchangedoubleswithsocket (const int *sockfd, const int *flaWri, int *flaRea, const int *nDblWri, int *nDblRea, double *simTimWri, double dblValWri[], double *simTimRea, double dblValRea[]) |
Exchanges data with the socket. More... | |
int | exchangedoubleswithsocketFMU (const int *sockfd, const int *flaWri, int *flaRea, const int *nDblWri, int *nDblRea, double *simTimWri, double dblValWri[], double *simTimRea, double dblValRea[], const int *flaExport) |
Exchanges data with the socket. More... | |
int | closeipc (int *sockfd) |
Closes the inter process communication socket. More... | |
int | main (int argc, const char *argv[]) |
Variables | |
int | FMUEXPORT = 0 |
int assembleBuffer | ( | int | flag, |
int | nDbl, | ||
int | nInt, | ||
int | nBoo, | ||
double | curSimTim, | ||
double | dblVal[], | ||
int | intVal[], | ||
int | booVal[], | ||
char ** | buffer, | ||
int * | bufLen | ||
) |
Assembles the buffer that will be exchanged through the IPC.
flag | The communication flag. |
nDbl | The number of double values. |
nInt | The number of integer values. |
nBoo | The number of boolean values. |
dblVal | The array that stores the double values. |
intVal | The array that stores the integer values. |
booVal | The array that stores the boolean values. |
buffer | The buffer into which the values will be written. |
bufLen | The buffer length prior and after the call. |
Definition at line 159 of file util/utilSocket.c.
References i, MAINVERSION, retVal, and save_append().
Referenced by writetosocket().
int closeipc | ( | int * | sockfd | ) |
Closes the inter process communication socket.
sockfd | Socket file descripter. |
close
function. Definition at line 1193 of file util/utilSocket.c.
Referenced by closeBSDSocket(), closeModelicaClient(), and main().
int disassembleBuffer | ( | const char * | buffer, |
int * | fla, | ||
int * | nDbl, | ||
int * | nInt, | ||
int * | nBoo, | ||
double * | curSimTim, | ||
double | dblVal[], | ||
int | intVal[], | ||
int | booVal[] | ||
) |
Disassembles the buffer that has been received through the IPC.
buffer | The buffer that contains the values to be parsed. |
flag | The communication flag. |
nDbl | The number of double values received. |
nInt | The number of integer values received. |
nBoo | The number of boolean values received. |
dblVal | The array that stores the double values. |
intVal | The array that stores the integer values. |
booVal | The array that stores the boolean values. |
Definition at line 343 of file util/utilSocket.c.
References disassembleHeaderBuffer(), f1, fprintf(), getDoubleCheckError(), getIntCheckError(), i, and retVal.
Referenced by readfromsocket().
int disassembleHeaderBuffer | ( | const char * | buffer, |
char ** | endptr, | ||
const int | base, | ||
int * | fla, | ||
int * | nDbl, | ||
int * | nInt, | ||
int * | nBoo | ||
) |
Disassembles the header of the buffer that has been received through the IPC.
This method is separated from disassemblebuffer since in the first call, we only need to peek at the header to assign a long enough buffer for the read operation.
buffer | The buffer that contains the values to be parsed. |
flag | The communication flag. |
nDbl | The number of double values received. |
nInt | The number of integer values received. |
nBoo | The number of boolean values received. |
Definition at line 297 of file util/utilSocket.c.
References getIntCheckError(), i, retVal, and SERVER_VERSION.
Referenced by disassembleBuffer(), and getRequiredReadBufferLength().
int establishclientsocket | ( | const char *const | docname | ) |
Establishes a connection to the socket.
This method establishes the client socket.
docname | Name of xml file that contains the socket information. |
Definition at line 468 of file util/utilSocket.c.
Referenced by establishBSDSocket(), establishModelicaClient(), first(), and main().
int exchangedoubleswithsocket | ( | const int * | sockfd, |
const int * | flaWri, | ||
int * | flaRea, | ||
const int * | nDblWri, | ||
int * | nDblRea, | ||
double * | simTimWri, | ||
double | dblValWri[], | ||
double * | simTimRea, | ||
double | dblValRea[] | ||
) |
Exchanges data with the socket.
Clients can call this method to exchange data through the socket.
sockfd | Socket file descripter |
flaWri | Communication flag to write to the socket stream. |
flaRea | Communication flag read from the socket stream. |
nDblWri | Number of double values to write. |
nDblRea | Number of double values to read. |
simTimWri | Current simulation time in seconds to write. |
dblValWri | Double values to write. |
simTimRea | Current simulation time in seconds read from socket. |
dblValRea | Double values read from socket. |
send
or read
, or a negative value if an error occured. Definition at line 1119 of file util/utilSocket.c.
Referenced by exchangeDoublesWithBSDSocket(), exchangeModelicaClient(), first(), and main().
int exchangedoubleswithsocketFMU | ( | const int * | sockfd, |
const int * | flaWri, | ||
int * | flaRea, | ||
const int * | nDblWri, | ||
int * | nDblRea, | ||
double * | simTimWri, | ||
double | dblValWri[], | ||
double * | simTimRea, | ||
double | dblValRea[], | ||
const int * | flaExport | ||
) |
Exchanges data with the socket.
Clients can call this method to exchange data through the socket. This methods differs from the exchangedoubleswithsocket. It has a flag that is used to set a global variable in readbufferfromsocket.
sockfd | Socket file descripter |
flaWri | Communication flag to write to the socket stream. |
flaRea | Communication flag read from the socket stream. |
nDblWri | Number of double values to write. |
nDblRea | Number of double values to read. |
simTimWri | Current simulation time in seconds to write. |
dblValWri | Double values to write. |
simTimRea | Current simulation time in seconds read from socket. |
dblValRea | Double values read from socket. |
flaexport | Flag for FMUExport. |
send
or read
, or a negative value if an error occured. Definition at line 1160 of file util/utilSocket.c.
References exchangewithsocket(), and FMUEXPORT.
int exchangewithsocket | ( | const int * | sockfd, |
const int * | flaWri, | ||
int * | flaRea, | ||
const int * | nDblWri, | ||
const int * | nIntWri, | ||
const int * | nBooWri, | ||
int * | nDblRea, | ||
int * | nIntRea, | ||
int * | nBooRea, | ||
double * | simTimWri, | ||
double | dblValWri[], | ||
int | intValWri[], | ||
int | booValWri[], | ||
double * | simTimRea, | ||
double | dblValRea[], | ||
int | intValRea[], | ||
int | booValRea[] | ||
) |
Exchanges data with the socket.
Clients can call this method to exchange data through the socket.
sockfd | Socket file descripter |
flaWri | Communication flag to write to the socket stream. |
flaRea | Communication flag read from the socket stream. |
nDblWri | Number of double values to write. |
nIntWri | Number of integer values to write. |
nBooWri | Number of boolean values to write. |
nDblRea | Number of double values to read. |
nIntRea | Number of integer values to read. |
nBooRea | Number of boolean values to read. |
simTimWri | Current simulation time in seconds to write. |
dblValWri | Double values to write. |
intValWri | Integer values to write. |
boolValWri | Boolean values to write. |
simTimRea | Current simulation time in seconds read from socket. |
dblValRea | Double values read from socket. |
intValRea | Integer values read from socket. |
boolValRea | Boolean values read from socket. |
send
or read
, or a negative value if an error occured. Definition at line 1049 of file util/utilSocket.c.
References f1, fprintf(), getrequiredbufferlength(), readfromsocket(), REQUIRED_WRITE_LENGTH, retVal, and writetosocket().
Referenced by exchangedoubleswithsocket(), and exchangedoubleswithsocketFMU().
int getDoubleCheckError | ( | const char * | nptr, |
char ** | endptr, | ||
double * | val | ||
) |
Gets a double and does the required error checking.
nptr | Pointer to character buffer that contains the number. |
endptr | After return, this variable contains a pointer to the character after the last character of the number. |
The | value contained in the character buffer. |
Definition at line 264 of file util/utilSocket.c.
References fprintf().
Referenced by disassembleBuffer().
int getIntCheckError | ( | const char * | nptr, |
char ** | endptr, | ||
const int | base, | ||
int * | val | ||
) |
Gets an integer and does the required error checking.
nptr | Pointer to character buffer that contains the number. |
endptr | After return, this variable contains a pointer to the character after the last character of the number. |
base | Base for the integer. |
The | value contained in the character buffer. |
Definition at line 227 of file util/utilSocket.c.
References FMUEXPORT, and fprintf().
Referenced by disassembleBuffer(), and disassembleHeaderBuffer().
int getmainversionnumber | ( | ) |
Returns the version number of the client.
Returns the main version number.
Returns the main version number of the client.
This method returns the version number of the client. A negative return value is used in a dummy dll to check in EnergyPlus whether the BCVTB has been installed.
Definition at line 443 of file util/utilSocket.c.
int getrequiredbufferlength | ( | const int | nDbl, |
const int | nInt, | ||
const int | nBoo | ||
) |
Returns the required socket buffer length.
nDbl | Number of double values to read or write. |
nInt | Number of integer values to read or write. |
nBoo | Number of boolean values to read or write. |
Definition at line 867 of file util/utilSocket.c.
References fprintf(), HEADER_LENGTH, and retVal.
Referenced by exchangewithsocket(), and getRequiredReadBufferLength().
int getRequiredReadBufferLength | ( | const int * | sockfd | ) |
Returns the required socket buffer length by reading from the socket how many data it contains.
This method also set the global variable SERVER_VERSION
sockfd | Socket file descripter |
Definition at line 830 of file util/utilSocket.c.
References disassembleHeaderBuffer(), getrequiredbufferlength(), HEADER_LENGTH, and retVal.
Referenced by readfromsocket().
int getsockethost | ( | const char *const | docname, |
char *const | hostname | ||
) |
Gets the hostname for the BSD socket communication.
This method parses the xml file for the socket host name.
docname | Name of xml file. |
hostname | The hostname will be written to this argument. |
Definition at line 454 of file util/utilSocket.c.
References BUFFER_LENGTH, getxmlvalue(), i, and r.
Referenced by establishclientsocket().
int getsocketportnumber | ( | const char *const | docname | ) |
Gets the port number for the BSD socket communication.
This method parses the xml file for the socket number.
docname | Name of xml file. |
Definition at line 413 of file util/utilSocket.c.
Referenced by establishclientsocket().
int main | ( | int | argc, |
const char * | argv[] | ||
) |
Definition at line 1202 of file util/utilSocket.c.
References fprintf().
int readbufferfromsocket | ( | const int * | sockfd, |
char * | buffer, | ||
int * | bufLen | ||
) |
Reads a character buffer from the socket.
This method is called by readfromsocket
.
sockfd | The socket file descripter. |
buffer | The buffer into which the values will be written. |
bufLen | The buffer length prior to the call. |
read
command. Definition at line 977 of file util/utilSocket.c.
References f1, fprintf(), REQUIRED_READ_LENGTH, retVal, and SERVER_VERSION.
Referenced by readfromsocket(), and sendclientmessage().
int readfromsocket | ( | const int * | sockfd, |
int * | flaRea, | ||
int * | nDblRea, | ||
int * | nIntRea, | ||
int * | nBooRea, | ||
double * | curSimTim, | ||
double | dblValRea[], | ||
int | intValRea[], | ||
int | booValRea[] | ||
) |
Reads data from the socket.
Clients can call this method to exchange data through the socket.
sockfd | Socket file descripter |
flaRea | Communication flag read from the socket stream. |
nDblRea | Number of double values to read. |
nIntRea | Number of integer values to read. |
nBooRea | Number of boolean values to read. |
curSimTim | Current simulation time in seconds read from socket. |
dblValRea | Double values read from socket. |
intValRea | Integer values read from socket. |
boolValRea | Boolean values read from socket. |
Definition at line 899 of file util/utilSocket.c.
References disassembleBuffer(), f1, fprintf(), getRequiredReadBufferLength(), i, readbufferfromsocket(), REQUIRED_READ_LENGTH, and retVal.
Referenced by exchangewithsocket().
int save_append | ( | char ** | buffer, |
const char * | toAdd, | ||
int * | bufLen | ||
) |
Appends a character array to another character array.
The array size of buffer
may be extended by this function to prevent a buffer overflow. If realloc
fails to allocate new memory, then this function calls perror
(...) and returns EXIT_FAILURE
.
buffer | The buffer to which the character array will be added. |
toAdd | The character array that will be appended to buffer |
bufLen | The length of the character array buffer . This parameter will be set to the new size of buffer if memory was reallocated. |
Definition at line 125 of file util/utilSocket.c.
Referenced by assembleBuffer().
int sendclientmessage | ( | const int * | sockfd, |
const int * | flaWri | ||
) |
Writes a message flag to the socket stream.
This method should be used by clients if they need to send a flag to the BCVTB.
The flag flaWri is defined as follows: +1: simulation reached end time. -1: simulation terminates due to an (unspecified) error. -10: simulation terminates due to error during initialization. -20: simulation terminates due to error during time integration.
sendclientmessage
insteadsockfd | Socket file descripter |
flaWri | Flag to be sent to the BCVTB |
Definition at line 785 of file util/utilSocket.c.
Referenced by closeModelicaClient(), and main().
int writetosocket | ( | const int * | sockfd, |
const int * | flaWri, | ||
const int * | nDblWri, | ||
const int * | nIntWri, | ||
const int * | nBooWri, | ||
double * | curSimTim, | ||
double | dblValWri[], | ||
int | intValWri[], | ||
int | booValWri[] | ||
) |
Writes data to the socket.
Clients can call this method to write data to the socket.
sockfd | Socket file descripter |
flaWri | Communication flag to write to the socket stream. |
nDblWri | Number of double values to write. |
nIntWri | Number of integer values to write. |
nBooWri | Number of boolean values to write. |
curSimTim | Current simulation time in seconds. |
dblValWri | Double values to write. |
intValWri | Integer values to write. |
boolValWri | Boolean values to write. |
send
, or a negative value if an error occured. Definition at line 670 of file util/utilSocket.c.
References assembleBuffer(), f1, fprintf(), REQUIRED_WRITE_LENGTH, and retVal.
Referenced by exchangewithsocket(), and sendclientmessage().
int FMUEXPORT = 0 |
Definition at line 111 of file util/utilSocket.c.
Referenced by exchangedoubleswithsocketFMU(), and getIntCheckError().