head 1.1; access ; symbols ; locks oasisa:1.1; strict; comment @ * @; 1.1 date 2001.06.19.13.00.47; author oasisa; state Exp; branches ; next ; desc @Periodic Update w/ changes to utils >> plus new utils 6/19/2001 (klh) @ 1.1 log @Initial revision @ text @/************************************************************************/ /* Copyright 1997 MBARI */ /************************************************************************/ /* $Header: argos.c,v 3.0 99/05/12 10:11:29 bobh Exp $ */ /* Summary : Program to analyze ARGOS receiver data */ /* Filename : argos.c */ /* Author : Bob Herlien (rah) */ /* Project : OASIS */ /* $Revision: 3.0 $ */ /* Created : 07/15/96 */ /* */ /* MBARI provides this documentation and code "as is", with no warranty, */ /* express or implied, of its quality or consistency. It is provided without*/ /* support and without obligation on the part of the Monterey Bay Aquarium */ /* Research Institute to assist in its use, correction, modification, or */ /* enhancement. This information should not be published or distributed to */ /* third parties without specific written permission from MBARI. */ /* */ /************************************************************************/ /* Modification History: */ /* 15jul96 rah - created */ /* $Log: argos.c,v $ * Revision 3.0 99/05/12 10:11:29 10:11:29 bobh (Bob Herlien) * Added tstring, misc changes * * Revision 2.9 98/08/24 13:45:58 13:45:58 bobh (Bob Herlien) * Archiving sources after M2/M3 & Eqpac deployments of 1998 * * Revision 2.8 98/03/17 11:11:44 11:11:44 bobh (Bob Herlien) * Archiving sources prior to porting to DOS/Windows * * Revision 1.1 97/10/27 09:53:18 09:53:18 bobh (Bob Herlien) * Initial revision * */ /************************************************************************/ #include /* Unix standard I/O */ #include /* Unix standard library */ #include /* MBARI standard types */ #include /* MBARI standard constants */ #include /* Unix time library */ #include /* OASIS data definitions */ #include /* Unix string library */ #include /* ARGOS buffer definitions */ #define SPEC_VOLTS FALSE #define NUM_MSGS 100 /* Max messages to store & compare */ #define BUFSIZE 1024 /* Line buffer size */ #define FLUOR_CHAN 0 /* Analog channel for Wetstar fluor*/ #define TEMP_CHAN 2 /* Analog channel for temperature */ #define OBATT_CHAN 3 /* Analog channel for OASIS battery*/ #define ABATT_CHAN 6 /* Analog channel for ARGOS battery*/ typedef enum /********************************/ { /* Return value from getXXXMsg */ MSG_OK, /* Successful conversion */ BAD_MSG, /* Bad message data */ END_OF_FILE /* End of input file */ } MsgRtn; /********************************/ typedef enum /********************************/ { /* Type of input */ SVC_ARGOS, /* From Serivce Argos */ RCVR_NORM, /* From local receiver, normal mode*/ RCVR_DIAG, /* Local receiver, diagnostic mode*/ ALPHA_OMEGA /* Alpha-Omega receiver */ } InputMode; /********************************/ /********************************/ /* External Functions */ /********************************/ Extern char *get_can_name( char *dataname ); Extern Nat16 getIntelword( Byte *p ); Extern Nat32 getIntellong( Byte *p ); Extern Status read_cfg( char **cfgname ); Extern double decode_prr_chan( Int16 ival, SpecChanCal *sccp ); Extern Flt64 decode_ac9_temp( Int32 count ); #ifdef WIN32 Extern Int getopt( Int argc, char **argv, char *fmt ); #endif /********************************/ /* External Data */ /********************************/ Extern char *optarg; /* Option argument from getopt() */ Extern Int optind; /* Option index from getopt() */ Extern Analog analog[ANALOG_CHANS]; /* Analog calibration */ Extern SpecCal spec_cal; /* Struct to hold Spect calibrations*/ Extern Int32 revision; /* Software & msg type revision nmbr*/ Extern MBool smallConfig; /* TRUE for single PTT config */ Extern Nat32 temp_offset; /* Offset for NO3 temperatures */ /********************************/ /* Module Local Data */ /********************************/ #ifdef WIN32 MLocal InputMode inputMode = RCVR_DIAG; #else MLocal InputMode inputMode = SVC_ARGOS; #endif MLocal MBool printChksumErrors = FALSE; MLocal char *cfgp = NULL; /* Ptr to name of OASIS config file */ MLocal MBool decode_all = TRUE; MLocal MBool decode_msg[NUM_MSG_TYPES]; MLocal Int32 gmt_offset = 0; MLocal Nat32 numMsgs = 0; MLocal Nat32 msgCnt = 0; MLocal Nat32 goodMsgs = 0; MLocal Nat32 badMsgs = 0; MLocal char buffer[BUFSIZE]; MLocal ArgosInMsg msgs[NUM_MSGS]; MLocal char *msgNamesRev2[] = { "Chemical", "Noon 0m Spectro", "1030 0m Spectro", "Misc", "Noon 20m Spectro", "AC-9 Part 1", "AC-9 Part 2" }; MLocal char *msgNamesRev3_4[] = { "Chemical", "Noon 0m Spectro", "1230 0m Spectro", "Misc", "Noon 20m Spectro", "1230 20m Spectro", "Shutter/SatDark", "Midnight 0m Spectro", "Midnight 20m Spectro", "Satlantic 1" }; MLocal Int32 msgTypesRev1[] = { CHEM, SPEC_0M_NOON, SPEC_0M_AM, SPEC_20M, AC9_1, AC9_2, MISC }; MLocal char *ac9ChanNames[] = { "a650", "a676", "a715", "c510", "c555", "c630", "a412", "a440", "a488", "c650", "c676", "c715", "a510", "a555", "a630", "c412", "c440", "c488" }; /********************************/ /* Forward Declarations */ /********************************/ MBool processCommandLine ( Int32 argc, char **argv ); Void decodeFile( char *filename ); Void printOneMsg( ArgosInMsg *msgp ); /************************************************************************/ /* Function : main */ /* Purpose : Main routine */ /* Inputs : argc, argv */ /* Outputs : Integer, 0 for success, 1 for failure */ /************************************************************************/ Int32 main( Int32 argc, char **argv ) { char *filename, *cp; Reg Int32 i; if ( !processCommandLine(argc, argv) ) exit( 1 ); putenv( "TZ=GMT0" ); for ( i = optind; i < argc; i++ ) { filename = argv[i]; get_can_name( filename ); cp = cfgp; if ( read_cfg(&cp) != OK ) printf("Can't read configuration file \"%s\"\n", cp); else decodeFile( filename ); } return( 0 ); } /* main() */ /************************************************************************/ /* Function : use_msg */ /* Purpose : Print Usage Message */ /* Inputs : Name of program */ /* Outputs : None */ /************************************************************************/ Void use_msg( char *s ) { fprintf( stderr, "Usage: %s [-b] [-c cfg_file] [-i msgnum] [-d] [-n] [-a] [-g gmt_offset]\n" ); fprintf( stderr, "-b prints messages with checksum errors\n" ); fprintf( stderr, "-c specifies a configuration file\n" ); fprintf( stderr, "-i decodes a specified message number\n" ); fprintf( stderr, "-d is for a Telonics receiver in diagnostic mode\n" ); fprintf( stderr, "-n is for a Telonics receiver in normal mode\n" ); fprintf( stderr, "-a is for an Alpha-Omega receiver\n" ); fprintf( stderr, "-e is for a email received from Service Argos\n" ); fprintf( stderr, "-g specifies the offset from GMT in hours for receiver\n"); #ifdef WIN32 fprintf( stderr, "default is for Telonics receiver in diagnostic mode\n" ); #else fprintf( stderr, "default is for email from Service Argos\n"); #endif } /* use_msg() */ /************************************************************************/ /* Function : processCommandLine */ /* Purpose : Read the arguments from the command line */ /* Inputs : argc, argv from main() routine */ /* Outputs : TRUE if arguments OK, else FALSE */ /************************************************************************/ MBool processCommandLine ( Int32 argc, char **argv ) { Int32 c, i; putenv( "TZ=GMT0" ); for ( i = 0; i < NUM_MSG_TYPES; i++ ) decode_msg[i] = FALSE; while ( (c = getopt(argc, argv, "abc:dei:g:n")) != EOF ) switch( c ) { case 'a': inputMode = ALPHA_OMEGA; break; case 'b': printChksumErrors = TRUE; break; case 'c': cfgp = optarg; break; case 'd': inputMode = RCVR_DIAG; break; case 'e': inputMode = SVC_ARGOS; break; case 'g': gmt_offset = atoi(optarg); break; case 'i': decode_all = FALSE; decode_msg[atoi(optarg)] = TRUE; break; case 'n': inputMode = RCVR_NORM; break; default: use_msg( argv[0] ); return( FALSE ); } return( TRUE ); } /* processCommandLine() */ /************************************************************************/ /* Function : getLine */ /* Purpose : Get one line of ARGOS message */ /* Inputs : FILE pointer, buffer ptr */ /* Outputs : MSG_OK or END_OF_FILE */ /************************************************************************/ MsgRtn getLine( FILE *fp, char * buffer ) { Reg Int32 len; buffer[0] = '\0'; while( TRUE ) { if ( fgets(buffer, BUFSIZE, fp) == NULL ) return( END_OF_FILE ); if ( (len = strlen(buffer)) > 0 ) { if ( buffer[len] == '\n' ) buffer[len] = '\0'; return( MSG_OK ); } } } /* getLine() */ /************************************************************************/ /* Function : getSvcArgosMsg */ /* Purpose : Get an ARGOS message in Service Argos format */ /* Inputs : FILE ptr, Buffer ptr, message ptr, time ptr, number of msgs*/ /* Outputs : Message return code */ /************************************************************************/ MsgRtn getSvcArgosMsg( FILE *fp, char *buffer, WordMsg *msgp, struct tm *tmPtr, Int32 *nmsgs ) { Nat32 i, j, dat[4]; if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %d-%d-%d %d:%d:%d %d %x %x %x %x", &tmPtr->tm_year, &tmPtr->tm_mon, &tmPtr->tm_mday, &tmPtr->tm_hour, &tmPtr->tm_min, &tmPtr->tm_sec, nmsgs, &dat[0], &dat[1], &dat[2], &dat[3]) < 11 ) return( BAD_MSG ); tmPtr->tm_year -= 1900; tmPtr->tm_mon -= 1; for ( i = 0; i < 4; i++ ) msgp->wd_data[i] = (Nat16)dat[i]; for ( i = 4; i < ARGOS_WORDS; i += 4 ) { if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %x %x %x %x", &dat[0], &dat[1], &dat[2], &dat[3]) < 4 ) return( BAD_MSG ); for ( j = 0; j < 4; j++ ) msgp->wd_data[i + j] = (Nat16)dat[j]; } return( MSG_OK ); } /* getSvcArgosMsg() */ /************************************************************************/ /* Function : getNormalMsg */ /* Purpose : Get an ARGOS message in normal format for local rcvr */ /* Inputs : FILE ptr, Buffer ptr, message ptr for return message */ /* Outputs : Message return code */ /************************************************************************/ MsgRtn getNormalMsg( FILE *fp, char *buffer, ByteMsg *msgp, struct tm *tmPtr ) { Nat32 i, j, dat[8]; if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %d-%d-%d %d:%d:%d", &tmPtr->tm_mon, &tmPtr->tm_mday, &tmPtr->tm_year, &tmPtr->tm_hour, &tmPtr->tm_min, &tmPtr->tm_sec) < 6 ) return( BAD_MSG ); tmPtr->tm_mon -= 1; for ( i = 0; i < ARGOS_LEN; i += 8 ) { if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %d %d %d %d %d %d %d %d", &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5], &dat[6], &dat[7]) < 8 ) return( BAD_MSG ); for ( j = 0; j < 8; j++ ) msgp->by_data[i + j] = (Byte)dat[j]; } return( MSG_OK ); } /* getNormalMsg() */ /************************************************************************/ /* Function : getDiagnosticMsg */ /* Purpose : Get an ARGOS message in diagnostic format for local rcvr*/ /* Inputs : FILE ptr, Buffer ptr, message ptr for return message */ /* Outputs : Message return code */ /************************************************************************/ MsgRtn getDiagnosticMsg( FILE *fp, char *buffer, ByteMsg *msgp, struct tm *tmPtr ) { Nat32 i, j, dat[8]; if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %d-%d-%d %d:%d:%d", &tmPtr->tm_mon, &tmPtr->tm_mday, &tmPtr->tm_year, &tmPtr->tm_hour, &tmPtr->tm_min, &tmPtr->tm_sec) < 6 ) return( BAD_MSG ); tmPtr->tm_mon -= 1; if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %*x %*x %*x %*x %*x %*x %x %x", &dat[0], &dat[1]) < 2) return( BAD_MSG ); msgp->by_data[0] = (Byte)dat[0]; msgp->by_data[1] = (Byte)dat[1]; for ( i = 2; i < ARGOS_LEN - 6; i += 8 ) { if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %x %x %x %x %x %x %x %x", &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5], &dat[6], &dat[7]) < 8 ) return( BAD_MSG ); for ( j = 0; j < 8; j++ ) msgp->by_data[i + j] = (Byte)dat[j]; } if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %x %x %x %x %x %x", &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5]) < 6 ) return( BAD_MSG ); for ( j = 0; j < 6; j++ ) msgp->by_data[i + j] = (Byte)dat[j]; getLine( fp, buffer ); return( MSG_OK ); } /* getDiagnosticMsg() */ /************************************************************************/ /* Function : getAlphaOmegaMsg */ /* Purpose : Get an ARGOS message in Alpha-Omega Receiver format */ /* Inputs : FILE ptr, Buffer ptr, message ptr for return message */ /* Outputs : Message return code */ /* Comment : Assumes A-O rcvr in byte format, which is not default */ /************************************************************************/ MsgRtn getAlphaOmegaMsg( FILE *fp, char *buffer, ByteMsg *msgp, struct tm *tmPtr ) { Nat32 pttNum, i, dat[32]; if ( getLine(fp, buffer) == END_OF_FILE ) return( END_OF_FILE ); if ( sscanf(buffer, " %d/%d/%d %d:%d:%d %d %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", &tmPtr->tm_mon, &tmPtr->tm_mday, &tmPtr->tm_year, &tmPtr->tm_hour, &tmPtr->tm_min, &tmPtr->tm_sec, &pttNum, &dat[0], &dat[1], &dat[2], &dat[3], &dat[4], &dat[5], &dat[6], &dat[7], &dat[8], &dat[9], &dat[10], &dat[11], &dat[12], &dat[13], &dat[14], &dat[15], &dat[16], &dat[17], &dat[18], &dat[19], &dat[20], &dat[21], &dat[22], &dat[23], &dat[24], &dat[25], &dat[26], &dat[27], &dat[28], &dat[29], &dat[30], &dat[31]) < 39 ) return( BAD_MSG ); tmPtr->tm_year -= 1900; tmPtr->tm_mon -= 1; for ( i = 0; i < 32; i++ ) msgp->by_data[i] = (Byte)dat[i]; return( MSG_OK ); } /* getAlhpaOmegaMsg() */ /************************************************************************/ /* Function : msgMatch */ /* Purpose : See if two ARGOS messages are the same */ /* Inputs : Two Message ptrs */ /* Outputs : TRUE if match, else FALSE */ /************************************************************************/ MBool msgMatch( ByteMsg *msgp1, ByteMsg *msgp2 ) { Int32 i; for ( i = 0; i < ARGOS_LEN; i++ ) if ( msgp1->by_data[i] != msgp2->by_data[i] ) return( FALSE ); return( TRUE ); } /* msgMatch() */ /************************************************************************/ /* Function : findMatchingMessage */ /* Purpose : Find a matching ARGOS message from those already received*/ /* Inputs : Message ptr */ /* Outputs : Message number of matching message, or ERROR */ /************************************************************************/ Int32 findMatchingMessage( ByteMsg *msgp ) { Nat32 i; for ( i = 0; i < msgCnt; i++ ) if ( msgMatch(msgp, &msgs[i].msg.rawb) ) return( i ); return( ERROR ); } /* findMatchingMessage() */ /************************************************************************/ /* Function : getMessages */ /* Purpose : Get all incoming ARGOS messages */ /* Inputs : FILE pointer */ /* Outputs : None */ /************************************************************************/ Void getMessages( FILE *fp, char *buffer ) { struct tm msgTime, *tmPtr; time_t msg_time_t; MsgRtn state; ArgosUnion msg; Int32 msgNum, nmsgs; numMsgs = msgCnt = 0; goodMsgs = badMsgs = 0; bzero( (void *)msgs, sizeof(msgs) ); time( &msg_time_t ); tmPtr = gmtime( &msg_time_t ); memcpy( (void *)&msgTime, (void *)tmPtr, sizeof(struct tm) ); msgTime.tm_isdst = 0; state = MSG_OK; while ( state != END_OF_FILE ) { nmsgs = 1; switch( inputMode ) { case SVC_ARGOS: state = getSvcArgosMsg( fp, buffer, &msg.raww, &msgTime, &nmsgs ); break; case RCVR_NORM: state = getNormalMsg( fp, buffer, &msg.rawb, &msgTime ); break; case RCVR_DIAG: state = getDiagnosticMsg( fp, buffer, &msg.rawb, &msgTime ); break; case ALPHA_OMEGA: state = getAlphaOmegaMsg( fp, buffer, &msg.rawb, &msgTime ); break; default: return; } if ( state == MSG_OK ) { msg_time_t = mktime( &msgTime ); msg_time_t -= 3600 * gmt_offset; if ( (msgNum = findMatchingMessage(&msg.rawb)) != ERROR ) { if ( msg_time_t < msgs[msgNum].first_msg ) msgs[msgNum].first_msg = msg_time_t; if ( msg_time_t > msgs[msgNum].last_msg ) msgs[msgNum].last_msg = msg_time_t; msgs[msgNum].msg_cnt += nmsgs; } else { if ( msgCnt >= NUM_MSGS ) { printOneMsg( msgs ); memmove( (void *)msgs, (void *)&msgs[1], (NUM_MSGS - 1) * sizeof(ArgosInMsg) ); msgCnt--; } msgs[msgCnt].first_msg = msg_time_t; msgs[msgCnt].last_msg = msg_time_t; msgs[msgCnt].msg_cnt = nmsgs; memcpy( (void *)&msgs[msgCnt].msg.rawb, (void *)&msg, sizeof(ArgosUnion) ); numMsgs += nmsgs; msgCnt++; } } } } /* getMessages() */ /************************************************************************/ /* Function : printTime */ /* Purpose : Print time to screen */ /* Inputs : Time */ /* Outputs : None */ /************************************************************************/ Void printTime( time_t timeToPrint ) { struct tm *tmPtr; tmPtr = gmtime( &timeToPrint ); printf( "%04d/%02d/%02d %02d:%02d:%02d", tmPtr->tm_year + 1900, tmPtr->tm_mon + 1, tmPtr->tm_mday, tmPtr->tm_hour, tmPtr->tm_min, tmPtr->tm_sec ); } /* printTime() */ /************************************************************************/ /* Function : printNO3 */ /* Purpose : Print an NO3 buffer */ /* Inputs : NO3 message ptr */ /* Outputs : None */ /************************************************************************/ Void printNO3( No3Msg *no3p ) { Nat32 i, val1, val2; Reg Byte *p; printf("NO3 "); p = no3p->no3; for ( i = 0; i < CHEM_SAMPLES/2; i++ ) { val1 = *p++ << 4; val1 |= ((*p >> 4) & 0x0f); val2 = ((*p++ & 0x0f) << 8); val2 |= *p++; printf( "%03d %03d ", val1, val2 ); } printf("\nTemp "); for ( i = 0; i < CHEM_SAMPLES; i++ ) printf("%5.2f ", (Flt32)((Nat32)(no3p->temp[i]) + temp_offset)/20.0); printf( "\n" ); } /* printNO3() */ /************************************************************************/ /* Function : printWetstar */ /* Purpose : Print a Wetstar buffer */ /* Inputs : Fluor message ptr */ /* Outputs : None */ /************************************************************************/ Void printWetstar( FluorMsg *fp ) { Nat32 i, val1, val2; Reg Byte *p; printf("0m Wetstar "); for ( i = 0; i < CHEM_SAMPLES; i++ ) printf("%3d ", fp->fl_0m[i]); printf("\n20m Wetstar "); p = fp->fl_20m; for ( i = 0; i < CHEM_SAMPLES/2; i++ ) { val1 = *p++ << 4; val1 |= ((*p >> 4) & 0x0f); val2 = ((*p++ & 0x0f) << 8); val2 |= *p++; printf( "%3d %3d ", val1, val2 ); } printf("\n"); } /* printWetstar() */ /************************************************************************/ /* Function : printWetstarRev4 */ /* Purpose : Print a Wetstar buffer */ /* Inputs : Fluor message ptr */ /* Outputs : None */ /************************************************************************/ Void printWetstarRev4( Misc4Msg *fp ) { Nat32 i, val1, val2; Reg Byte *p; Reg Nat16 *wp; Flt64 flt1, flt2; printf(" 0m Wetstar "); p = fp->fl_0m; for ( i = 0; i < CHEM_SAMPLES/2; i++ ) { val1 = *p++ << 4; val1 |= ((*p >> 4) & 0x0f); val2 = ((*p++ & 0x0f) << 8); val2 |= *p++; flt1 = (((analog[FLUOR_CHAN].a * (Flt32)(val1 >> 2)) + analog[FLUOR_CHAN].b) * analog[FLUOR_CHAN].c) + analog[FLUOR_CHAN].d; flt2 = (((analog[FLUOR_CHAN].a * (Flt32)(val2 >> 2)) + analog[FLUOR_CHAN].b) * analog[FLUOR_CHAN].c) + analog[FLUOR_CHAN].d; printf( "%6.3f %6.3f ", flt1, flt2 ); } printf("\n20m Wetstar "); for ( i = 0; i < FLUOR20_WORDS; i++ ) { val1 = getIntelword( (Byte *)&fp->fl_20m[i] ); flt1 = decode_prr_chan(val1, &spec_cal.spc_cal[2][11]); if ( flt1 < 20.0 ) printf( "%6.3f ", flt1 ); else printf(" Error "); } printf("\n"); } /* printWetstarRev4() */ /************************************************************************/ /* Function : printChem4Msg */ /* Purpose : Print the miscellaneous portion of the Chem msg for rev 4*/ /* Inputs : Chem4 message ptr */ /* Outputs : None */ /************************************************************************/ Void printChem4Msg( Chem4Msg *cp ) { Reg Byte *p; Nat16 ipitch, iroll, itemp, idepth; Nat32 i; Int32 val1, val2; printf("CO2 "); p = cp->ch_pco2; for ( i = 0; i < CHEM_SAMPLES/2; i++ ) { val1 = *p++ << 4; val1 |= ((*p >> 4) & 0x0f); if ( val1 & 0x800 ) val1 |= 0xfffff000; /* Sign extend */ val2 = ((*p++ & 0x0f) << 8); val2 |= *p++; if ( val2 & 0x800 ) val2 |= 0xfffff000; /* Sign extend */ printf( "%03d %03d ", val1, val2 ); } printf("\nNoon PRR pitch, roll, temp, depth: "); ipitch = getIntelword( (Byte *)&cp->ch_prr_pitch ); iroll = getIntelword( (Byte *)&cp->ch_prr_roll ); itemp = getIntelword( (Byte *)&cp->ch_prr_temp ); idepth = getIntelword( (Byte *)&cp->ch_prr_depth ); printf("%6.1f %6.1f %7.2f %7.2f\n", decode_prr_chan(ipitch, &spec_cal.spc_cal[0][10]), decode_prr_chan(iroll, &spec_cal.spc_cal[0][11]), decode_prr_chan(itemp, &spec_cal.spc_cal[2][8]), decode_prr_chan(idepth, &spec_cal.spc_cal[2][9]) ); printf("1230PM PRR pitch, roll, temp, depth: "); ipitch = getIntelword( (Byte *)&cp->ch_prr_pitch1230 ); iroll = getIntelword( (Byte *)&cp->ch_prr_roll1230 ); itemp = getIntelword( (Byte *)&cp->ch_prr_temp1230 ); idepth = getIntelword( (Byte *)&cp->ch_prr_depth1230 ); printf("%6.1f %6.1f %7.2f %7.2f\n", decode_prr_chan(ipitch, &spec_cal.spc_cal[0][10]), decode_prr_chan(iroll, &spec_cal.spc_cal[0][11]), decode_prr_chan(itemp, &spec_cal.spc_cal[2][8]), decode_prr_chan(idepth, &spec_cal.spc_cal[2][9]) ); } /* printChem4Msg() */ /************************************************************************/ /* Function : printSpec */ /* Purpose : Print a PRR Spectro message */ /* Inputs : Spectro message ptr, Address tags for Ed, Lu chans */ /* Outputs : None */ /************************************************************************/ Void printSpec( SpecMsg *msgp, Int32 edAdr, Int32 luAdr, Int32 edChan, Int32 luChan ) { Reg Int32 i; Reg Nat16 ival; for ( i = 0; i < ASPEC_CHANS; i++ ) { ival = getIntelword( (Byte *)&msgp->sp_ed[i] ); #if SPEC_VOLTS printf("%-5.5s %9.5f ", spec_cal.spc_cal[edAdr][i+edChan].name, decode_prr_chan(ival, NULL)); #else printf("%-5.5s %9.5f ", spec_cal.spc_cal[edAdr][i+edChan].name, decode_prr_chan(ival, &spec_cal.spc_cal[edAdr][i+edChan])); #endif if ( (i % 4) == 3 ) printf("\n"); } for ( i = 0; i < ASPEC_CHANS; i++ ) { if ( (i % 4) == 0 ) printf("\n"); ival = getIntelword( (Byte *)&msgp->sp_lu[i] ); #if SPEC_VOLTS printf("%-5.5s %9.5f ", spec_cal.spc_cal[luAdr][i+luChan].name, decode_prr_chan(ival, NULL)); #else printf("%-5.5s %9.5f ", spec_cal.spc_cal[luAdr][i+luChan].name, decode_prr_chan(ival, &spec_cal.spc_cal[luAdr][i+luChan])); #endif } } /* printSpec() */ /************************************************************************/ /* Function : crcOneWord */ /* Purpose : Check CRC-12 on one 16 bit word */ /* Inputs : Initial CRC, word to check */ /* Outputs : Resulting CRC */ /************************************************************************/ Nat16 crcOneWord( Nat16 initCRC, Nat16 wordToCheck ) { Reg Nat32 bitCnt; Reg Nat16 crc; crc = initCRC; for ( bitCnt = 0; bitCnt < 16; bitCnt++ ) { crc <<= 1; if ( wordToCheck & (0x8000 >> bitCnt) ) crc |= 1; if ( crc & CRC_MSB ) crc ^= CRC12; } return( crc ); } /* crcOneWord() */ /************************************************************************/ /* Function : checkCRC */ /* Purpose : Check CRC-12 on incoming message */ /* Inputs : Word Message Pointer */ /* Outputs : TRUE if CRC is OK, else FALSE */ /* Comment : OASIS uses the standard CRC-12 polynomial 0x180f */ /* However, it puts the checksum and type information in */ /* the first word of the message, which it checks LAST */ /************************************************************************/ MBool checkCRC( WordMsg *msgp ) { Reg Nat32 cnt; Reg Nat16 crc; for ( cnt = 1, crc = 0; cnt < ARGOS_WORDS; cnt++ ) crc = crcOneWord( crc, getIntelword((Byte *)&msgp->wd_data[cnt]) ); return( crcOneWord(crc, getIntelword((Byte *)&msgp->wd_data[0])) == 0 ); } /* checkCRC() */ /************************************************************************/ /* Function : checkSum */ /* Purpose : Calculate Checksum on incoming message (Revision 1) */ /* Inputs : Byte Message Pointer */ /* Outputs : TRUE if checksum is OK, else FALSE */ /* Comment : Revision 1 of OASIS software used a simple checksum */ /************************************************************************/ MBool checkSum( ByteMsg *msgp ) { Reg Nat32 cnt; Byte cksum; for ( cnt = 2, cksum = 0; cnt < ARGOS_LEN; cnt++ ) cksum ^= msgp->by_data[cnt]; return( cksum == msgp->by_data[1] ); } /* checkSum() */ /************************************************************************/ /* Function : printOneMsgRev2 */ /* Purpose : Print one received ARGOS message in Rev 1/2 format */ /* Inputs : Message Pointer */ /* Outputs : None */ /************************************************************************/ Void printOneMsgRev2( ArgosInMsg *msgp ) { Nat32 i, msgType, lval; Int32 ac9cnt; Flt64 flt1, flt2, flt3; Int16 co2; Nat16 val, msbs, mcp10, mcp30, fluor; MBool isGood; if ( revision == 1 ) { msgType = msgp->msg.rawb.by_data[0]; if ( (msgType & 0x0f) != ((msgType >> 4) & 0x0f) ) isGood = FALSE; else isGood = checkSum( &msgp->msg.rawb ); msgType = msgTypesRev1[msgType & 0x0f]; } else { msgType = (msgp->msg.rawb.by_data[1] >> 4) & 0x0f; isGood = checkCRC( &msgp->msg.raww ); } if ( isGood ) goodMsgs += msgp->msg_cnt; else { badMsgs += msgp->msg_cnt; if ( !printChksumErrors ) return; } if ( msgType >= NUM_MSG_TYPES_REV2 ) { printf("Bad Message Type %d received %d times\n", msgType, msgp->msg_cnt); return; } if ( !decode_all && !decode_msg[msgType] ) return; printf("%s Msg rcvd %d times from ", msgNamesRev2[msgType], msgp->msg_cnt); printTime( msgp->first_msg ); printf( " to " ); printTime( msgp->last_msg ); printf( " GMT\n" ); if ( !isGood ) printf("Checksum Error!\n"); for ( i = 0; i < ARGOS_LEN; i++ ) { printf("%02x ", msgp->msg.rawb.by_data[i]); if ( (i % 16) == 15 ) printf( "\n" ); } switch( msgType ) { case CHEM: printf("CO2 "); msbs = getIntelword( (Byte *)&msgp->msg.chem.ch_pco2_msbs ); for ( i = 0; i < CHEM_SAMPLES; i++ ) { co2 = msgp->msg.chem.ch_pco2[i] | (((msbs >> (i + i)) & 3) << 8); if ( co2 & 0x200 ) co2 |= 0xfc00; /* Sign extend */ printf( "%03d ", co2 ); } printf( "\n" ); printNO3( &msgp->msg.chem.ch_no3 ); break; case SPEC_0M_NOON: printSpec( &msgp->msg.spec0m, SPEC_0M_ED, SPEC_0M_LU, 0, SPEC_NOON_LU_CHAN ); fluor = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); flt1 = (((analog[FLUOR_CHAN].a * (Flt32)(fluor)) + analog[FLUOR_CHAN].b) * analog[FLUOR_CHAN].c) + analog[FLUOR_CHAN].d; printf( "Fluor %9.5f\n", flt1 ); break; case SPEC_0M_AM: printSpec( &msgp->msg.spec0m_1030, SPEC_0M_ED, SPEC_0M_LU, 0, SPEC_AM_LU_CHAN ); fluor = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); flt1 = (((analog[FLUOR_CHAN].a * (Flt32)(fluor)) + analog[FLUOR_CHAN].b) * analog[FLUOR_CHAN].c) + analog[FLUOR_CHAN].d; printf( "Fluor %9.5f\n", flt1 ); break; case SPEC_20M: printSpec( &msgp->msg.spec20m, SPEC_20M_ED, SPEC_20M_LU, 0, 0 ); fluor = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); #if SPEC_VOLTS printf("Fluor %9.5f\n", decode_prr_chan(fluor, NULL)); #else printf("Fluor %9.5f\n", decode_prr_chan(fluor, &spec_cal.spc_cal[2][12])); #endif break; case AC9_1: printf("AC-9 "); for ( i = 0; i < AC9_1_CHANS; i++ ) { val = getIntelword( (Byte *)&msgp->msg.ac9.ac_data[i] ); printf( "%s %5.3f ", ac9ChanNames[i], (Flt32)val / 1000.0 ); if ( (i % 6) == 5 ) printf( "\n " ); } printf( "\n" ); break; case AC9_2: printf("AC-9 "); for ( i = 0; i < AC9_2_CHANS; i++ ) { val = getIntelword( (Byte *)&msgp->msg.ac92.ac_data[i] ); printf( "%s %5.3f ", ac9ChanNames[i + AC9_1_CHANS], (Flt32)val / 1000.0 ); } ac9cnt = getIntelword( (Byte *)&msgp->msg.ac92.ac_temp ); flt1 = decode_ac9_temp( ac9cnt ); printf("Temp %5.3f", flt1); printf("\nAC-9 Chl "); for ( i = 0; i < CHEM_SAMPLES; i++ ) { val = getIntelword( (Byte *)&msgp->msg.ac92.ac_chl[i] ); printf( "%5.3f ", (Flt32)val / 1000.0 ); } printf( "\n" ); break; case MISC: val = getIntelword( (Byte *)&msgp->msg.misc.ms_pco2 ); co2 = val & 0x3ff; if ( co2 & 0x200 ) /* Sign extend */ co2 |= 0xfc00; printf( "CO2 Calibr %3d at %02d00 local\n", co2, ((val >> 10) & 7) * 3 ); lval = getIntellong( (Byte *)&msgp->msg.misc.ms_oasis ); flt1 = (((analog[TEMP_CHAN].a * (Flt32)(lval & 0x3ff)) + analog[TEMP_CHAN].b) * analog[TEMP_CHAN].c) + analog[TEMP_CHAN].d; flt2 = ((analog[OBATT_CHAN].a * (Flt32)((lval >> 10) & 0x3ff)) + analog[OBATT_CHAN].b) * analog[OBATT_CHAN].c; flt3 = ((analog[ABATT_CHAN].a * (Flt32)((lval >> 20) & 0x3ff)) + analog[ABATT_CHAN].b) * analog[ABATT_CHAN].c; printf("OASIS temp %5.2f C Battery %5.2f V Argos Batt %5.2f V\n", flt1, flt2, flt3); if ( !smallConfig ) { mcp10 = getIntelword( (Byte *)&msgp->msg.misc.ms_mcp10 ); mcp30 = getIntelword( (Byte *)&msgp->msg.misc.ms_mcp30 ); #if SPEC_VOLTS printf("10m MCP %9.5f 30m MCP %9.5f\n", decode_prr_chan(mcp10, NULL), decode_prr_chan(mcp30, NULL)); #else printf("10m MCP %9.5f 30m MCP %9.5f\n", decode_prr_chan(mcp10, &spec_cal.spc_cal[2][10]), decode_prr_chan(mcp30, &spec_cal.spc_cal[2][11])); #endif printNO3( &msgp->msg.misc.ms_no3 ); } break; default: printf("Bad Message Type\n"); } printf( "\n" ); } /* printOneMsgRev2() */ /************************************************************************/ /* Function : printOneMsgRev3_4 */ /* Purpose : Print one received ARGOS message in Rev 3 or 4 format */ /* Inputs : Message Pointer */ /* Outputs : None */ /************************************************************************/ Void printOneMsgRev3_4( ArgosInMsg *msgp, Int32 rev ) { Int32 msgType; Nat32 i, lval; Flt64 flt1, flt2, flt3; Int16 co2; Nat16 val, msbs, mcp10, mcp30, misc; MBool isGood; if ( (rev != 3) && (rev != 4) ) { printf("Internal error - wrong message revision\n"); return; } msgType = (msgp->msg.rawb.by_data[1] >> 4) & 0x0f; isGood = checkCRC( &msgp->msg.raww ); if ( isGood ) goodMsgs += msgp->msg_cnt; else { badMsgs += msgp->msg_cnt; if ( !printChksumErrors ) return; } if ( msgType >= ((rev == 3) ? NUM_MSG_TYPES_REV3 : NUM_MSG_TYPES_REV4) ) { printf("Bad Message Type %d received %d times\n", msgType, msgp->msg_cnt); return; } if ( !decode_all && !decode_msg[msgType] ) return; printf("%s Msg rcvd %d times from ", msgNamesRev3_4[msgType], msgp->msg_cnt); printTime( msgp->first_msg ); printf( " to " ); printTime( msgp->last_msg ); printf( " GMT\n" ); if ( !isGood ) printf("Checksum Error!\n"); for ( i = 0; i < ARGOS_LEN; i++ ) { printf("%02x ", msgp->msg.rawb.by_data[i]); if ( (i % 16) == 15 ) printf( "\n" ); } switch( msgType ) { case CHEM: if ( rev == 3 ) { printf("CO2 "); msbs = getIntelword( (Byte *)&msgp->msg.chem.ch_pco2_msbs ); for ( i = 0; i < CHEM_SAMPLES; i++ ) { co2 = msgp->msg.chem.ch_pco2[i] | (((msbs >> (i + i)) & 3) << 8); if ( co2 & 0x200 ) co2 |= 0xfc00; /* Sign extend */ printf( "%03d ", co2 ); } printf( "\n" ); printNO3( &msgp->msg.chem.ch_no3 ); } else printChem4Msg( &msgp->msg.chem4 ); break; case SPEC_0M_NOON: printSpec( &msgp->msg.spec0m, SPEC_0M_ED, SPEC_0M_LU, 0, SPEC_NOON_LU_CHAN ); misc = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); printf( "Err cnt %d\n", misc ); break; case SPEC_0M_1230: printSpec( &msgp->msg.spec0m_1230, SPEC_0M_ED, SPEC_0M_LU, 0, ((rev == 3) ? SPEC_1230_LU_CHAN : SPEC_1230_LU_CHAN_REV4) ); misc = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); printf( "Total chans %d\n", misc ); break; case SPEC_20M: printSpec( &msgp->msg.spec20m, SPEC_20M_ED, SPEC_20M_LU, 0, 0 ); misc = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); if ( rev == 3 ) printf( "Err cnt %d\n", misc ); else #if SPEC_VOLTS printf("10m MCP %9.5f\n", decode_prr_chan(misc, NULL)); #else printf("10m MCP %9.5f\n", decode_prr_chan(misc, &spec_cal.spc_cal[2][10])); #endif break; case SPEC_20M_1230: printSpec( &msgp->msg.spec20m, SPEC_20M_ED, SPEC_20M_LU, 0, 0 ); misc = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); if ( rev == 3 ) printf( "Total chans %d\n", misc ); else #if SPEC_VOLTS printf("Noon 30m MCP %9.5f\n", decode_prr_chan(misc, NULL)); #else printf("Noon 30m MCP %9.5f\n", decode_prr_chan(misc, &spec_cal.spc_cal[2][14])); #endif break; case SPEC_0M_DARK: printSpec( &msgp->msg.spec0m, SPEC_0M_ED, SPEC_0M_LU, 0, SPEC_NOON_LU_CHAN ); printf( "\n" ); break; case SPEC_20M_DARK: printSpec( &msgp->msg.spec20m, SPEC_20M_ED, SPEC_20M_LU, 0, 0 ); printf( "\n" ); break; case SAT1: printSpec( &msgp->msg.sat1, SAT1_ED, SAT1_LU, SAT1_ED_CHAN, SAT1_LU_CHAN ); printf( "\n" ); break; case MISC: val = getIntelword( (Byte *)&msgp->msg.misc3.ms_pco2 ); if ( rev == 3 ) { co2 = val & 0x3ff; if ( co2 & 0x200 ) /* Sign extend */ co2 |= 0xfc00; misc = (val >> 10) & 7; } else { co2 = val & 0xfff; if ( co2 & 0x800 ) /* Sign extend */ co2 |= 0xf000; misc = (val >> 12) & 7; } printf( "CO2 Calibr %3d at %02d00 local\n", co2, 3 * misc ); lval = getIntellong( (Byte *)&msgp->msg.misc3.ms_oasis ); flt1 = (((analog[TEMP_CHAN].a * (Flt32)(lval & 0x3ff)) + analog[TEMP_CHAN].b) * analog[TEMP_CHAN].c) + analog[TEMP_CHAN].d; flt2 = ((analog[OBATT_CHAN].a * (Flt32)((lval >> 10) & 0x3ff)) + analog[OBATT_CHAN].b) * analog[OBATT_CHAN].c; flt3 = ((analog[ABATT_CHAN].a * (Flt32)((lval >> 20) & 0x3ff)) + analog[ABATT_CHAN].b) * analog[ABATT_CHAN].c; printf("OASIS temp %5.2f C Battery %5.2f V Argos Batt %5.2f V\n", flt1, flt2, flt3); if ( rev == 3 ) { mcp10 = getIntelword( (Byte *)&msgp->msg.misc3.ms_mcp10 ); mcp30 = getIntelword( (Byte *)&msgp->msg.misc3.ms_mcp30 ); #if SPEC_VOLTS printf("10m MCP %9.5f 30m MCP %9.5f\n", decode_prr_chan(mcp10, NULL), decode_prr_chan(mcp30, NULL)); #else printf("10m MCP %9.5f 30m MCP %9.5f\n", decode_prr_chan(mcp10, &spec_cal.spc_cal[2][10]), decode_prr_chan(mcp30, &spec_cal.spc_cal[2][11])); #endif printWetstar( &msgp->msg.misc3.ms_wetstar ); } else printWetstarRev4( &msgp->msg.misc4 ); break; case SHUTTR: printf("%u total shutter attempts (incl retries), %u opens, %u closes\n", getIntelword((Byte *)&msgp->msg.shutter.sh_attempts), msgp->msg.shutter.sh_opens, msgp->msg.shutter.sh_closes); printf("%u shutter errors, %u timeouts, %u retry-outs, %u redundant\n", msgp->msg.shutter.sh_toterrs, msgp->msg.shutter.sh_errs[0], msgp->msg.shutter.sh_errs[1], msgp->msg.shutter.sh_errs[2]); printf("Last OASIS error vector %x\n", getIntelword((Byte *)&msgp->msg.shutter.sh_oasisErrs)); for ( i = 0; i < ASPEC_CHANS; i++ ) { misc = getIntelword( (Byte *)&msgp->msg.shutter.sh_satDark[i] ); #if SPEC_VOLTS printf("%-5.5s %9.5f ", spec_cal.spc_cal[SPEC_0M_LU][i+SPEC_1230_LU_CHAN].name, decode_prr_chan(misc, NULL)); #else printf("%-5.5s %9.5f ", spec_cal.spc_cal[SPEC_0M_LU][i+SPEC_1230_LU_CHAN].name, decode_prr_chan(misc, &spec_cal.spc_cal[SPEC_0M_LU][i+SPEC_1230_LU_CHAN])); #endif if ( (i % 4) == 3 ) printf("\n"); } printf( "\n" ); if ( rev == 4 ) { val = getIntelword( (Byte *)&msgp->msg.shutter.sh_ctd_temp ); misc = getIntelword( (Byte *)&msgp->msg.shutter.sh_ctd_cond ); printf("Noon CTD Temp %7.3f Conductivity %8.4f\n", ((double)val) / 1000., ((double)misc) / 10000.); } break; default: printf("Bad Message Type\n"); } printf( "\n" ); } /* printOneMsgRev3_4() */ /************************************************************************/ /* Function : printOneMsg */ /* Purpose : Print one received ARGOS message */ /* Inputs : Message Pointer */ /* Outputs : None */ /************************************************************************/ Void printOneMsg( ArgosInMsg *msgp ) { switch( revision ) { case 1: case 2: printOneMsgRev2( msgp ); break; case 3: printOneMsgRev3_4( msgp, 3 ); break; case 4: printOneMsgRev3_4( msgp, 4 ); break; default: printf( "Bad software revision number %d\n", revision ); } } /* printOneMsg() */ /************************************************************************/ /* Function : decodeFile */ /* Purpose : Decode one ARGOS message file */ /* Inputs : File name */ /* Outputs : None */ /************************************************************************/ Void decodeFile( char *filename ) { Reg Nat32 i; Reg FILE *fp; if ( (fp = fopen(filename, "rb")) == (FILE *)NULL ) printf("Cannot open %s\n", filename); else { getMessages( fp, buffer ); for ( i = 0; i < msgCnt; i++ ) printOneMsg( &msgs[i] ); printf(" %d valid messages, %d checksum errors\n\n", goodMsgs, badMsgs ); } } /* printMessages() */ @