//============================================================================ // // OBS sync program // // // Rev. Date By Description // ----------------------------------------------- // 0.1 24-aug-2002 OM Test version // //============================================================================ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #define ASHTECH_PORT "/dev/ttyS0" #define EIVA_PORT "/dev/ttyS0" #define TTT_PORT "/dev/ttyS1" void read_TTT(); void read_Eiva(); void read_Ashtech(); void initialize_serial_port(int FLAG, const char *com); // T y p e d e c l a r a t i o n typedef struct { char *day; char *ttt_time; } gpsTTT_type; typedef struct { char *north, *east; char *time, *date, *course, *speed; } gpsRMC_type; typedef struct { char *time, *date, *east, *north, *depth, *cmg, *kp; int event; } nav_type; typedef struct arg_t { const char *com; const char *profile; } arguments; /*typedef struct { unsigned short control1, control2, body_length; short two_bytes[46]; } input_buf;*/ // V a r i a b l e d e c l a r a t i o n gpsTTT_type gpsTTT; gpsRMC_type gpsRMC; nav_type nav; char *profile; long int event_no=0; int tttFlag=0; int eivaFlag=0; //============================================================== // M a i n p r o g r a m //============================================================= int main (int argc, char *argv[]) { pthread_t ashtech_thread, ttt_thread, eiva_thread; arguments ttt_arg, Ashtech_arg, Eiva_arg; FILE *log_fd; /* Configuring serial ports */ /*initialize_serial_port(0, ASHTECH_PORT); // 0 = ASCII format*/ initialize_serial_port(0, TTT_PORT); // ASCII initialize_serial_port(1, EIVA_PORT); // BINARY /*printf("Event number tagging of OBS shot events times coming from Ashtech TTT sentence\n");*/ /* Start threads */ if (log_fd = fopen("testlog.txt","w")) setlinebuf(log_fd); else exit(-1); ttt_arg.com = TTT_PORT; ttt_arg.profile = ""; pthread_create(&ttt_thread, NULL, (void*) read_TTT, (void *) &ttt_arg); /*Ashtech_arg.com = ASHTECH_PORT; Ashtech_arg.profile = ""; pthread_create(&ashtech_thread, NULL, (void*) read_Ashtech, (void *) &Ashtech_arg);*/ Eiva_arg.com = EIVA_PORT; Eiva_arg.profile = ""; pthread_create(&eiva_thread, NULL, (void*) read_Eiva, (void *) &Eiva_arg); /* Main loop */ while (1) { usleep(200000); if (tttFlag == 1){ if (eivaFlag == 1){ tttFlag=0; eivaFlag=0; printf("%i %s\n",event_no, gpsTTT.ttt_time); fprintf(log_fd,"%i %s\n",event_no, gpsTTT.ttt_time); } } //printf("."); } } //=================================================================== // E I V A N O R S T A R S T R I N G T O T R I A C Q //=================================================================== void read_Eiva (arguments *arg) { char eiva_string[256]; int bytes; int fd, n; FILE *eiva_fd; unsigned char in_buffer[256]; /*eiva_fd = fopen(arg->com,"r");*/ fd = open(arg->com, O_RDONLY | O_NOCTTY); while (1) { bytes=read(fd, &in_buffer, 228); event_no=in_buffer[7]+(in_buffer[6]*256); printf("%i ",event_no); usleep(800000); eivaFlag=1; /*printf("eiva: (%i) %i %i %i %i : %i\n", bytes,in_buffer[4],in_buffer[5],in_buffer[6],in_buffer[7],event_no);*/ } } //============================================================== // A S H T E C H G G 2 4 G P S T T T m e s s a g e //============================================================== void read_TTT(arguments *arg) { char ashtech_string[256]; char *str_ptr=ashtech_string; char *bytes, *NMEA; FILE *a_fd; a_fd = fopen(arg->com,"r"); while (1) { /* 1. Reads one line from file descriptor pointing at a RS232 port */ /* 2. Separates the string using strsep */ /* 3. Signals the waiting mutex in main */ bytes=fgets(ashtech_string,sizeof ashtech_string, a_fd); //printf("Read TTT thread\n"); str_ptr=ashtech_string; /* Pointer to a pointer to a string (strsep) */ NMEA=strsep(&str_ptr,","); if (strcmp("$PASHR",NMEA) == 0) { NMEA=strsep(&str_ptr,","); if (strcmp("TTT",NMEA) == 0) { gpsTTT.day=strsep(&str_ptr,","); /* Day */ gpsTTT.ttt_time=strsep(&str_ptr,","); /* Time */ gpsTTT.ttt_time=strsep(&gpsTTT.ttt_time,"*"); /* Strip off the * */ /*printf("%s\n", gpsTTT.ttt_time);*/ usleep(800000); tttFlag=1; } else printf("#1: Unknown GPS format: %s\n",NMEA); } //else //printf("#2: Unknown GPS format: %s\n",NMEA); /* Strip carrage return rubbish */ /*bytes=fgets(ashtech_string,sizeof ashtech_string, a_fd); pthread_cond_signal(&ttt_set);*/ } } //========================================================= // A S H T E C H G G 2 4 G P S r e c e i v e r //========================================================= void read_Ashtech(arguments *arg) { char ashtech_string[256]; char *str_ptr=ashtech_string; char *NMEA; long counter=0; char *bytes; FILE *a_fd; char datadir[256]; a_fd = fopen(arg->com,"r"); while (1) { bytes=fgets(ashtech_string,sizeof ashtech_string, a_fd); str_ptr=ashtech_string; // Pointer to a pointer to a string (strsep) counter++; NMEA=strsep(&str_ptr,","); if (strcmp("$GPRMC",NMEA) == 0) { NMEA=strsep(&str_ptr,","); printf("%s\n",NMEA); } } } //========================================================= // I n i t i a l i z e s e r i a l p o r t s //========================================================= void initialize_serial_port(int FLAG, const char *com) { // FLAG = 0, configure serial port com for ascii data // FLAG = 1, configure serial port com for binary stream int fd; struct termios options; fd = open(com, O_RDWR | O_NOCTTY ); if (fd <0) { perror(com); exit(-1); } if (FLAG == 0) { tcgetattr(fd,&options); /* Get current setting */ options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; /* Mask the character size bits */ options.c_cflag |= CS8; /* Select 8 data bits */ options.c_lflag |= (ICANON | ECHO | ECHOE); tcsetattr(fd, TCSANOW, &options); /* Apply changes */ /* Finished serial settings */ } else if (FLAG == 1) { tcgetattr(fd,&options); /* Get current setting */ cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; /* Mask the character size bits */ options.c_cflag |= CS8; /* Select 8 data bits */ options.c_cc[VMIN] = 228; options.c_cc[VTIME] = 1; options.c_lflag &= ~(ICANON | ECHO | ISIG); /* Setting for raw data */ tcsetattr(fd, TCSANOW, &options); /* Apply changes */ /* Finished serial settings */ } close(fd); }