head 2.9; access ; symbols ; locks ; strict; comment @ * @; 2.9 date 98.08.24.13.45.58; author bobh; state Exp; branches ; next 2.8; 2.8 date 98.03.17.11.11.44; author bobh; state Exp; branches ; next 1.1; 1.1 date 97.10.27.09.53.18; author bobh; state Exp; branches ; next ; desc @Program to decode ARGOS data from EqPac moorings @ 2.9 log @Archiving sources after M2/M3 & Eqpac deployments of 1998 @ text @/************************************************************************/ /* Copyright 1997 MBARI */ /************************************************************************/ /* $Header: argos.c,v 2.8 98/03/17 11:11:44 bobh Exp $ */ /* Summary : Program to analyze ARGOS receiver data */ /* Filename : argos.c */ /* Author : Bob Herlien (rah) */ /* Project : OASIS */ /* $Revision: 2.8 $ */ /* Created : 07/15/96 */ /************************************************************************/ /* Modification History: */ /* 15jul96 rah - created */ /* $Log: argos.c,v $ * 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*/ } 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 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[] = { "Chemical", "Noon 0m Spectro", "1230 0m Spectro", "Misc", "Noon 20m Spectro", "1230 20m Spectro", "Shutter/SatDark", "Midnight 0m Spectro", "Midnight 20m Spectro" }; 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]\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 local receiver in diagnostic mode\n" ); fprintf( stderr, "-n is for a local receiver in normal mode\n" ); fprintf( stderr, "-e is for a email received from Service Argos\n" ); #ifdef WIN32 fprintf( stderr, "default is for local 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; for ( i = 0; i < NUM_MSG_TYPES; i++ ) decode_msg[i] = FALSE; while ( (c = getopt(argc, argv, "bc:dei:n")) != EOF ) switch( c ) { case 'b': printChksumErrors = TRUE; break; case 'c': cfgp = optarg; break; case 'd': inputMode = RCVR_DIAG; break; case 'e': inputMode = SVC_ARGOS; 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 : 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; default: return; } if ( state == MSG_OK ) { msg_time_t = mktime( &msgTime ); 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 : 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 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].name, decode_prr_chan(ival, NULL)); #else printf("%-5.5s %9.5f ", spec_cal.spc_cal[edAdr][i].name, decode_prr_chan(ival, &spec_cal.spc_cal[edAdr][i])); #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, 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, 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 ); 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 */ /* Purpose : Print one received ARGOS message in Rev 3 format */ /* Inputs : Message Pointer */ /* Outputs : None */ /************************************************************************/ Void printOneMsgRev3( ArgosInMsg *msgp ) { Nat32 i, msgType, lval; Flt64 flt1, flt2, flt3; Int16 co2; Nat16 val, msbs, mcp10, mcp30, misc; MBool isGood; 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_REV3 ) { 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[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, 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, SPEC_1230_LU_CHAN ); 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 ); misc = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); printf( "Err cnt %d\n", misc ); break; case SPEC_20M_1230: printSpec( &msgp->msg.spec20m, SPEC_20M_ED, SPEC_20M_LU, 0 ); misc = getIntelword( (Byte *)&msgp->msg.spec0m.sp_misc ); printf( "Total chans %d\n", misc ); break; case SPEC_0M_DARK: printSpec( &msgp->msg.spec0m, SPEC_0M_ED, SPEC_0M_LU, SPEC_NOON_LU_CHAN ); printf( "\n" ); break; case SPEC_20M_DARK: printSpec( &msgp->msg.spec20m, SPEC_20M_ED, SPEC_20M_LU, 0 ); printf( "\n" ); break; case MISC: val = getIntelword( (Byte *)&msgp->msg.misc3.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.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); 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 ); 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" ); break; default: printf("Bad Message Type\n"); } printf( "\n" ); } /* printOneMsgRev3() */ /************************************************************************/ /* 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( msgp ); 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() */ @ 2.8 log @Archiving sources prior to porting to DOS/Windows @ text @d4 1 a4 1 /* $Header: argos.c,v 1.1 97/10/27 09:53:18 bobh Exp $ */ d9 1 a9 1 /* $Revision: 1.1 $ */ d15 3 d26 2 a27 2 #include /* MBARI standard types */ #include /* MBARI standard constants */ d61 2 d66 3 d88 3 d92 1 d159 2 d179 7 a185 2 fprintf( stderr, "default is for data from Service Argos\n"); d203 1 a203 1 while ( (c = getopt(argc, argv, "bc:di:n")) != EOF ) d218 4 d550 3 a552 2 printf( "%02d/%02d %02d:%02d:%02d", tmPtr->tm_mon + 1, tmPtr->tm_mday, tmPtr->tm_hour, tmPtr->tm_min, tmPtr->tm_sec ); d752 1 a752 1 Nat32 i, msgType, val, msbs; d756 1 a756 1 Nat16 mcp10, mcp30, fluor; d758 1 a758 1 d901 2 a902 2 val = getIntellong( (Byte *)&msgp->msg.misc.ms_oasis ); flt1 = (((analog[TEMP_CHAN].a * (Flt32)(val & 0x3ff)) + d905 1 a905 1 flt2 = ((analog[OBATT_CHAN].a * (Flt32)((val >> 10) & 0x3ff)) + d907 1 a907 1 flt3 = ((analog[ABATT_CHAN].a * (Flt32)((val >> 20) & 0x3ff)) + d947 1 a947 2 Nat32 i, msgType, val, msbs; Int32 ac9cnt; d950 1 a950 1 Nat16 mcp10, mcp30, misc; d952 1 a952 1 d1054 2 a1055 2 val = getIntellong( (Byte *)&msgp->msg.misc3.ms_oasis ); flt1 = (((analog[TEMP_CHAN].a * (Flt32)(val & 0x3ff)) + d1058 1 a1058 1 flt2 = ((analog[OBATT_CHAN].a * (Flt32)((val >> 10) & 0x3ff)) + d1060 1 a1060 1 flt3 = ((analog[ABATT_CHAN].a * (Flt32)((val >> 20) & 0x3ff)) + d1080 1 a1080 1 printf("%u total shutter attempts (incl retries), %u opens, %u closes\n", d1086 2 a1087 1 printf("Last OASIS error vector %x\n", msgp->msg.shutter.sh_oasisErrs); d1089 1 a1089 1 for ( i = 0; i < ASPEC_CHANS; i++ ) @ 1.1 log @Initial revision @ text @d4 1 a4 1 /* $Header$ */ d9 1 a9 1 /* $Revision$ */ d14 4 a17 1 /* $Log$ d30 1 d84 1 a84 1 MLocal MBool decode_msg[SENSORS]; d92 2 a93 1 MLocal char *msgNames[] = d97 5 d496 1 a496 1 printOneMsg( &msgs[0] ); d568 34 d616 1 d618 3 d622 1 d634 4 d641 1 d720 2 a721 2 /* Function : printOneMsg */ /* Purpose : Print one received ARGOS messages */ d726 1 a726 1 printOneMsg( ArgosInMsg *msgp ) d759 7 d769 1 a769 1 printf( "%s Msg rcvd %d times from ", msgNames[msgType], msgp->msg_cnt ); d806 1 a806 1 fluor = getIntelword( (Byte *)&msgp->msg.spec0m.sp_fluor ); d816 1 a816 1 fluor = getIntelword( (Byte *)&msgp->msg.spec0m.sp_fluor ); d825 4 a828 1 fluor = getIntelword( (Byte *)&msgp->msg.spec0m.sp_fluor ); d831 1 d893 1 d895 156 a1050 1 decode_prr_chan(mcp10, &spec_cal.spc_cal[2][10]), d1052 3 d1056 24 a1079 1 printNO3( &msgp->msg.misc.ms_no3 ); d1081 2 d1091 27 d1138 1 a1138 1 @