#include #include #include #include #include #include #include #include #include "definitions.h" #include "net.h" /* vrsi_command_tcpip function that passed the command to the ACU for intrepretation. The argruements are command = pointer to the string containing the command that will be passed to the Vertex RSI command. The command should not have the terminating "CR". This will be appended to the string in the function automatically. responce = array of string pointers that will contain the reply from the ACU. If response==NULL, response_buffer_length==0, or number_of_terminators==0 then no reply is expected. response_buffer_length = length of the reply buffer string. This is the maximum size of the reply buffer any string beyond this will not be read in. number_of_terminators = number of "\n" (carrage returns) expected from the reply of the ACU. This is to allow for reading of multiple line replies from the ACU. net_address = currently is the numerical form of the ip address stored as a character. For example "192.168.140.1" would be a correct form of the net_address. It is the address of the ACU. port = integer that holds port number for communication to the ACU. 5001 or 5002. Initial version of this software was written by Robert C. Berrington. Please contact for questions regarding the code at rberring@uwyo.edu. Modified for Vertex RSI ACU. JSW 9 June 08 */ int vrsi_command_tcpip(char *command, char **response, int response_buffer_length, int number_of_terminators, char *net_address, int port) { int j=0; int outgoing_socket=0; int response_successfully_read=0; struct sockaddr_in compumotor_interface; char *command_with_terminator=NULL; if (command == NULL) { fprintf(stderr, "'command' buffer pointer passed was NULL. No command sent.\n"); fflush(stderr); return NULL_ARGUEMENT; } if ((response_buffer_length>0) && (response==NULL)) { fprintf(stderr, "'response' buffer pointer passed was NULL with positive expected buffer length!\n"); fflush(stderr); return NULL_ARGUEMENT; } if (number_of_terminators==0) { fprintf(stderr, "*WARNING* expected number of terminators was %d! No reply expected\n", number_of_terminators); fflush(stderr); } /* First lets clear out the responce buffer for accepting the reply */ if ((response != NULL) && (response_buffer_length > 0)) { for (j=0; j= response_buffer_length ) { fprintf(stderr, "*ERROR* Filled the response buffer!\n"); return FAILURE; } } } /* Close the socket established for communication with the ACU. */ if (close(outgoing_socket)==-1) { fprintf(stderr, "*ERROR* Failed to close the socket!\n"); return FAILURE; } free(command_with_terminator); return SUCCESS; }