#include #include #include #include #include #include #include #include #include "definitions.h" #include "net.h" /* Compumotor_command_tcpip function that passed the command to the compumotor for intrepretation. The argruements are command = pointer to the string containing the command that will be passed to the compumotor command. The command should not have the terminating ":". This will be appended to the string in the function automatically. responce = array of string pointers that will contain the reply from the compumotor. 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 compumotor. This is to allow for reading of multiple line replies from the compumotor. net_address = currently is the numerical form of the ip address stored as a chareacter. For example "10.212.212.111" would be a correct form of the net_address. It is the address of the compumotor. port = integer that holds port number for communication to the compumotor. Initial version of this software was written by Robert C. Berrington. Please contact for questions regarding the code at rberring@uwyo.edu. */ int compumotor_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 compumotor. */ if (close(outgoing_socket)==-1) { fprintf(stderr, "*ERROR* Failed to close the socket!\n"); return FAILURE; } free(command_with_terminator); return SUCCESS; }