/* $modname$ $version$ $date$ $time$ REVISION HISTORY: $log$ */ /* ************************************************************* * * * WOODS HOLE OCEANOGRAPHIC INSTITUTION * * UPPER OCEAN PROCESSES GROUP * * PHYSICAL OCEANOGRAPHY DEPT. * * WOODS HOLE, MASSACHUSETTS USA 02543 * * * * File: commscontrol.c * * * * Function: Comms Controller Mainline (Linux) * * * * Project: * * * * Programmer: G.A. * * * * Copyright (c) 2004 Woods Hole Oceanographic Institution * * * ************************************************************* */ /* 6/4/07: in addition to the hourly files, also output */ /* to one file that will be appended to as long as */ /* the program runs. fb */ #include #include #include #include "equates.h" #include "globals.h" #define uchar unsigned char // char copyright[] = {"Copyright (c) 2004 Woods Hole Oceanographic Institution"}; // char programmer[] = {"by Geoff Allsup"}; short inits(void); short init_serial(char); short get_response(char *, char, int); int main(int argc, char *argv[]) { FILE *fp1, *fp2; FILE *fp3; /* fb */ short error; char *month[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; char *fbase[16]; int curr_hour; // printf("\nComms Controller Test Program v2.0\n"); /* get the filename base, or default */ if (argc < 2) /* default filename base */ strcpy((char *)fbase,"AI"); else { /* copy up to 15 characters */ strncpy((char *)fbase,argv[1],15); /* and null terminate regardless */ fbase[sizeof(fbase)-1] = NULL; } // printf("%s\n",fbase); /* initialize remote serial port */ if ((error = init_serial(CONTROL_PORT))) { /* error message */ printf("ERROR: can't init control port\n"); /* fatal error */ exit(-1); } /* update the current time */ time(&curr_time); timeptr = localtime(&curr_time); /* create a filename - fbase-hh-ddMMMyy.txt */ sprintf(filename,"%s-%02d-%02d%s%02d.txt",fbase,timeptr->tm_hour,timeptr->tm_mday,month[timeptr->tm_mon],timeptr->tm_year - 100); printf("%s\n",filename); /* open the data file to record GPS */ if (!(fp2 = fopen(filename,"a"))) { /* open failed */ printf("ERROR: can't open data file\n"); /* fatal error - we MUST be able to write a data file */ exit(-1); } /* open the file that will be added to as long as the program runs */ sprintf(filename,"all_ai.txt"); printf("also opened %s\n",filename); printf("Date time bpr hrh atmp LWR prlev SST SWR wE wN spd hdg vane\n"); /* open the data file to record GPS */ if (!(fp3 = fopen(filename,"a"))) { /* open failed */ printf("ERROR: can't open data file\n"); /* fatal error - we MUST be able to write a data file */ exit(-1); } /* file opened OK, keep current hour */ curr_hour = timeptr->tm_hour; /* initialize the other serial ports (2 - 5 == ttyS16 - ttyS19) - no checking for now */ // init_serial(2); // init_serial(3); // init_serial(4); // init_serial(5); /* open ports 2 and 3 (ttyS16 and ttyS17) for MET data OUTPUT only */ // sf2 = fdopen(fd_comms[2],"w"); // sf3 = fdopen(fd_comms[3],"w"); /* init some stuff */ GO_mode = YES; // always start status.running = NO; // assume NOT currently running on cold start /* main loop */ while (1) { /* mode is GO */ if (!get_response(inbuf,'\n',500)) { printf("%s",inbuf); fflush(stdout); fprintf(fp2,"%s",inbuf); fflush(fp2); fprintf(fp3,"%s",inbuf); fflush(fp3); } /* every cycle, update status file */ // update_status(); /* update the current time */ time(&curr_time); timeptr = localtime(&curr_time); /* see if it's time to start a new data file */ if (curr_hour != timeptr->tm_hour) { /* new hour, so close the old file */ fclose(fp2); /* create the new filename - fbase-hh-ddMMMyy.txt */ sprintf(filename,"%s-%02d-%02d%s%02d.txt",fbase,timeptr->tm_hour,timeptr->tm_mday,month[timeptr->tm_mon],timeptr->tm_year - 100); printf("%s\n",filename); printf("Date time bpr hrh atmp LWR prlev SST SWR wE wN spd hdg vane\n"); /* open the data file to record GPS */ if (!(fp2 = fopen(filename,"a"))) { /* open failed */ printf("ERROR: can't open data file\n"); /* fatal error - we MUST be able to write a data file */ exit(-1); } /* file opened OK, keep current hour */ curr_hour = timeptr->tm_hour; } } /* end main while */ /* should never get here */ printf("\nth-th-th-that's all, folks!\n\n"); exit(0); }