#include #include #include #include #include #include #include #include #include #include #include #define bzero(b,len) (memset((b), '\0' ,(len)), (void) 0) /* Included for Evidence server */ #define SERVER_NAME "ARDUINO" // Name to use in DIM #include "Evidence.h" #define NUM_VAL 10 /* baudrate settings are defined in , which is included by */ #define BAUDRATE B9600 /* change this definition for the correct port */ #define MODEMDEVICE "/dev/myArduino" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define TRUE 1 #define myPath "/ct3data/SlowData/" // will be used later on //#define myPath "" // for testing purposes FILE * openOutfile(char *path); static int poll_stdin_time(int microsekunden) ; volatile int STOP=FALSE; int main(int argc, char *argv[]) { int fd, res; struct termios oldtio,newtio; char buf[255]; /* Start Evidence server and create services */ EvidenceServer Srv(SERVER_NAME); float Val[NUM_VAL]; char Name[100]; DimService *Service[NUM_VAL]; for (int i=0; iupdateService(); } outfile = openOutfile(myPath); if (outfile == NULL) {return -1;} time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); struct timeval timeofday; gettimeofday(&timeofday, NULL); sprintf(outstring, "DALLAS Sensorvalues %04d %02d %02d %02d %02d %02d %03d %d %s", (*timeinfo).tm_year+1900, (*timeinfo).tm_mon+1, (*timeinfo).tm_mday, (*timeinfo).tm_hour, (*timeinfo).tm_min, (*timeinfo).tm_sec, (int) timeofday.tv_usec/1000, (int)rawtime, buf); printf("%s", outstring); fprintf(outfile, "%s", outstring); fflush(outfile); fclose(outfile); if (poll_stdin_time(1500000)==1) { STOP=TRUE; } } //end while(STOP==FALSE) /* restore the old port settings */ tcsetattr(fd,TCSANOW,&oldtio); /* Delete Evidence services */ for (int i=0; i12){ //then it is already tommorow rawtime += 86400; timeinfo = gmtime ( &rawtime ); } //generate filename char *outfilename; outfilename =(char*) calloc( strlen(path)+25 , sizeof(char)); if (outfilename ==NULL) { perror("could not allocate space for outputfilename"); return NULL; } sprintf(outfilename,"%sCLIM_%04d%02d%02d.slow", path, // from user (*timeinfo).tm_year+1900, (*timeinfo).tm_mon+1, (*timeinfo).tm_mday ); // there is no need to check if file is already existing. // if not fopen(name,"a") will create it. // if it exists // it will only be opened for appnendign outfile = fopen(outfilename,"a"); if (outfile==NULL){ perror("could not open outputfile"); return NULL;} return outfile; } static int poll_stdin_time(int microsekunden) { struct timeval timeout; fd_set read_fds; int c; int stdin_status; FD_ZERO(&read_fds); FD_SET(STDIN_FILENO, &read_fds); timeout.tv_sec = 0; timeout.tv_usec =microsekunden; stdin_status = select(STDIN_FILENO+1, &read_fds, NULL, NULL, &timeout); if (stdin_status == 1 ) { c=getchar(); fflush(stdin); if (c=='q') { return 1; } } else if (stdin_status ==0) { return 0; } else { perror("select()"); } return -1; }