00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define MAX_STRING_LENGTH 64
00024 #define OSIRIS_ERROR_MESSAGES 20 // 10 !
00025 #define OSIRIS_ERROR_MESSAGE_LENGTH 255
00026
00027
00028
00031 int CheckStaLtaBounds(void)
00032 {
00033 char line[512],kw[12];
00034 int i,ch,minA,maxA;
00035 FILE *f;
00036 int staMin[MAX_CHANNEL];
00037 int staMax[MAX_CHANNEL];
00038 int ltaMin[MAX_CHANNEL];
00039 int ltaMax[MAX_CHANNEL];
00040 for (i=0; i<MAX_CHANNEL; i++)
00041 {
00042 staMin[i]=staMax[i]=ltaMin[i]=ltaMax[i]=-1;
00043 }
00044 f=fopen("stalta","rt");
00045 if (f==NULL)
00046 {
00047 return(0);
00048 }
00049 while (fgets(line,254,f)!=NULL)
00050 {
00051 PrintError("line: %s\n",line);
00052 if (line[0]=='#')
00053 {
00054 continue;
00055 }
00056 if (2!=sscanf(line,"%3s%d",kw,&ch))
00057 {
00058 continue;
00059 }
00060 PrintError("kw: %s ch: %d\n",kw,ch);
00061 if (ch>=MAX_CHANNEL)
00062 {
00063 continue;
00064 }
00065 if (2!=sscanf(line,"%*s %d %d",&minA,&maxA))
00066 {
00067 continue;
00068 }
00069 PrintError("minA: %d maxA: %d\n",minA,maxA);
00070 if (0==strcasecmp(kw,"sta"))
00071 {
00072 staMin[ch]=minA;
00073 staMax[ch]=maxA;
00074 }
00075 if (0==strcasecmp(kw,"lta"))
00076 {
00077 ltaMin[ch]=minA;
00078 ltaMax[ch]=maxA;
00079 }
00080 }
00081 fclose(f);
00082 #define CHECKSTALTA(n) \
00083 { \
00084 if ((staMin[n]>0)&&(acquisit_Sta##n.valid)) \
00085 { \
00086 if ((staMin[n]>0)&&(acquisit_Sta##n.value.d<staMin[n])) \
00087 { \
00088 return(1); \
00089 } \
00090 if ((staMax[n]>0)&&(acquisit_Sta##n.value.d>staMax[n])) \
00091 { \
00092 return(1); \
00093 } \
00094 } \
00095 if ((ltaMin[n]>0)&&(acquisit_Lta##n.valid)) \
00096 { \
00097 if ((ltaMin[n]>0)&&(acquisit_Lta##n.value.d<ltaMin[n])) \
00098 { \
00099 return(1); \
00100 } \
00101 if ((ltaMax[n]>0)&&(acquisit_Lta##n.value.d>ltaMax[n])) \
00102 { \
00103 return(1); \
00104 } \
00105 } \
00106 }
00107 CHECKSTALTA(0); CHECKSTALTA(1); CHECKSTALTA(2); CHECKSTALTA(3); CHECKSTALTA(4); CHECKSTALTA(5);
00108 CHECKSTALTA(6); CHECKSTALTA(7); CHECKSTALTA(8); CHECKSTALTA(9); CHECKSTALTA(10); CHECKSTALTA(11);
00109 CHECKSTALTA(12); CHECKSTALTA(13); CHECKSTALTA(14); CHECKSTALTA(15); CHECKSTALTA(16); CHECKSTALTA(17);
00110 CHECKSTALTA(18); CHECKSTALTA(19); CHECKSTALTA(20); CHECKSTALTA(21); CHECKSTALTA(22); CHECKSTALTA(23);
00111 return(0);
00112 }
00113
00115
00118 int CheckProcessOshWww(void)
00119 {
00120 if (myShi.valid==0) { return(0); }
00121 if (myMessage.state[7]&(1<<7)) { return(0); }
00122 return(1);
00123 }
00124
00127 int CheckProcessOshCmd(void)
00128 {
00129 if (myShi.valid==0) { return(0); }
00130 if (myMessage.state[7]&(1<<6)) { return(0); }
00131 return(1);
00132 }
00133
00136 int CheckProcessTrigger(void)
00137 {
00138 if (myShi.valid==0) { return(0); }
00139 if (myMessage.state[7]&(1<<5)) { return(0); }
00140 return(1);
00141 }
00142
00145 int CheckProcessSysd(void)
00146 {
00147 if (myShi.valid==0) { return(0); }
00148 if (myMessage.state[7]&(1<<4)) { return(0); }
00149 return(1);
00150 }
00151
00154 int CheckProcessConfiguration(void)
00155 {
00156 if (myShi.valid==0) { return(0); }
00157 if (myMessage.state[7]&(1<<3)) { return(0); }
00158 return(1);
00159 }
00160
00163 int CheckProcessGpsd(void)
00164 {
00165 if (myShi.valid==0) { return(0); }
00166 if (myMessage.state[7]&(1<<2)) { return(0); }
00167 return(1);
00168 }
00169
00172 int CheckProcessDiskmgr(void)
00173 {
00174 if (myShi.valid==0) { return(0); }
00175 if (myMessage.state[7]&(1<<1)) { return(0); }
00176 return(1);
00177 }
00178
00181 int CheckProcessAcquisit(void)
00182 {
00183 if (myShi.valid==0) { return(0); }
00184 if (myMessage.state[7]&(1<<0)) { return(0); }
00185 return(1);
00186 }
00187
00190 int CheckGeneralError(void)
00191 {
00192
00193 if (comd_MessageFlag.valid==0)
00194 {
00195 return(0);
00196 }
00197 if (comd_MessageFlag.value.d&0x1)
00198 {
00199 return(1);
00200 }
00201 return(0);
00202 }
00203
00206 int CheckBootTime(void)
00207 {
00208
00209 if (sysd_StartTime.valid==0)
00210 {
00211 return(0);
00212 }
00213
00214 if (
00215 (0==strcmp(sysd_OsirisModel.value.s,"SAGE-PC"))||
00216 (0==strcmp(sysd_OsirisModel.value.s,"MYKERINOS-PC"))
00217 )
00218 {
00219 return(0);
00220 }
00221 if (
00222 (0==strcasecmp(sysd_OsirisModel.value.s,"MYKERINOS-R"))||
00223 (0==strcasecmp(sysd_OsirisModel.value.s,"MYKERINOSR"))
00224 )
00225 {
00226 if (abs(sysd_StartTime.value.d-time(NULL))<3600)
00227 {
00228 return(1);
00229 }
00230 else
00231 {
00232 return(0);
00233 }
00234 }
00235 if (abs(sysd_StartTime.value.d-time(NULL))<REBOOT_DELAY)
00236 {
00237 return(1);
00238 }
00239 return(0);
00240 }
00241
00244 int CheckGps(void)
00245 {
00246
00247 if (gpsd_GpsState.valid==0)
00248 {
00249 return(0);
00250 }
00251 if (
00252 (strstr(gpsd_GpsState.value.s,"error"))||
00253 (strstr(gpsd_GpsState.value.s,"ERROR"))
00254 )
00255 {
00256 return(1);
00257 }
00258 return(0);
00259 }
00260
00263 int CheckBatteryETR(void)
00264 {
00265
00266 if (sysd_BattRemaining.valid==0)
00267 {
00268 return(0);
00269 }
00270 if (sysd_BattRemaining.value.d<(POWER_REMAINING_THRESHOLD/3600))
00271 {
00272 return(1);
00273 }
00274 return(0);
00275 }
00276
00279 int CheckBatteryLevel(void)
00280 {
00281
00282 if (sysd_ExtBat.valid==0)
00283 {
00284 return(0);
00285 }
00286
00287 if (sysd_OsirisModel.valid==0)
00288 {
00289 return(0);
00290 }
00291
00292 if (
00293 (sysd_ExtBat.value.f<1.0)||
00294 (sysd_ExtBat.value.f>30.0)
00295 )
00296 {
00297 return(0);
00298 }
00299
00300 if (
00301 (NULL==strstr(sysd_OsirisModel.value.s,"SAGE-PC"))&&
00302 (NULL==strstr(sysd_OsirisModel.value.s,"MYKERINOS-PC"))
00303 )
00304 {
00305 if (sysd_ExtBat.value.f<POWER_LEVEL_THRESHOLD)
00306 {
00307 return(1);
00308 }
00309 }
00310 return(0);
00311 }
00312
00315 int CheckInternalBatteryLevel(void)
00316 {
00317
00318 if (sysd_IntBat.valid==0)
00319 {
00320 return(0);
00321 }
00322
00323 if (sysd_OsirisModel.valid==0)
00324 {
00325 return(0);
00326 }
00327
00328 if (
00329 (sysd_IntBat.value.f<1.0)||
00330 (sysd_IntBat.value.f>30.0)
00331 )
00332 {
00333 return(0);
00334 }
00335
00336 if (
00337 (NULL==strstr(sysd_OsirisModel.value.s,"SAGE-PC"))&&
00338 (NULL==strstr(sysd_OsirisModel.value.s,"MYKERINOS-PC"))
00339 )
00340 {
00341 if (
00342 (sysd_IntBat.value.f<INTERNAL_BATTERY_MIN_LEVEL)||
00343 (sysd_IntBat.value.f>INTERNAL_BATTERY_MAX_LEVEL)
00344 )
00345 {
00346 return(1);
00347 }
00348 }
00349 return(0);
00350 }
00351
00354 int CheckDriftAmplitude(void)
00355 {
00356
00357 if (acquisit_Drift.valid==0)
00358 {
00359 return(0);
00360 }
00361
00362 if (sysd_OsirisModel.valid==0)
00363 {
00364 return(0);
00365 }
00366
00367
00368 if (
00369 (NULL!=strstr(sysd_OsirisModel.value.s,"MYKERINOS-T"))||
00370 (NULL!=strstr(sysd_OsirisModel.value.s,"SAGE-PC"))||
00371 (NULL!=strstr(sysd_OsirisModel.value.s,"TITAN"))||
00372 0
00373 )
00374 {
00375 return(fabs(acquisit_Drift.value.f)<15.?0:1);
00376 }
00377 if (
00378 (NULL!=strstr(sysd_OsirisModel.value.s,"KEPHREN"))||
00379 (NULL!=strstr(sysd_OsirisModel.value.s,"SAGE"))||
00380 (NULL!=strstr(sysd_OsirisModel.value.s,"OSIRIS"))||
00381 0
00382 )
00383 {
00384 return(fabs(acquisit_Drift.value.f)<1.0?0:1);
00385 }
00386 return(0);
00387 }
00388
00391 int CheckTimeShiftAmplitude(void)
00392 {
00393
00394 if (acquisit_LastShift.valid==0)
00395 {
00396 return(0);
00397 }
00398
00399 if (sysd_OsirisModel.valid==0)
00400 {
00401 return(0);
00402 }
00404 if (
00405 (NULL!=strstr(sysd_OsirisModel.value.s,"MYKERINOS-T"))||
00406 (NULL!=strstr(sysd_OsirisModel.value.s,"MYKERINOS-PC"))||
00407 (NULL!=strstr(sysd_OsirisModel.value.s,"SAGE-PC"))||
00408 (NULL!=strstr(sysd_OsirisModel.value.s,"TITAN"))
00409 )
00410 {
00411 return((fabs(acquisit_LastShift.value.f)<20.)?0:1);
00412 }
00413 return(0);
00414 }
00415
00418 int CheckLastInformationTime(void)
00419 {
00420
00421 if (gpsd_SystemTime.valid==0)
00422 {
00423 return(0);
00424 }
00425
00426 if (abs(gpsd_SystemTime.value.d-time(NULL))>MAX_LONGINFOS_AGE_TIMEOUT)
00427 {
00428 return(0);
00429 }
00430
00431
00432 if (abs(gpsd_SystemTime.value.d-time(NULL))>MAX_LONGINFOS_AGE)
00433 {
00434 return(1);
00435 }
00436 return(0);
00437 }
00438
00441 int CheckStorageError(void)
00442 {
00443
00444 if (myShi.storageError==1)
00445 {
00446 return(1);
00447 }
00448 if (strstr(diskmgr_StorageStatus.value.s,"/error"))
00449 {
00450 return(1);
00451 }
00452 return(0);
00453 }
00454
00457 int CheckStorageDisk(void)
00458 {
00459
00460 if (0==strncmp(diskmgr_StorageStatus.value.s,"detected",8))
00461 {
00462 return(0);
00463 }
00464 if (myShi.storageDetected!=1)
00465 {
00466 return(0);
00467 }
00468 return(1);
00469 }
00470
00473 int CheckAgeOfLastPulse(void)
00474 {
00475
00476 if (abs(gpsd_SystemTime.value.d-time(NULL))>MAX_GPS_TOP_OLDNESS)
00477 {
00478 return(0);
00479 }
00480
00481 if (
00482 (NULL!=strstr(sysd_OsirisModel.value.s,"MYKERINOS"))||
00483 (NULL!=strstr(sysd_OsirisModel.value.s,"SAGE-PC"))
00484 )
00485 {
00486 if (acquisit_LastGpsTop.valid==0)
00487 {
00488 return(0);
00489 }
00490 }
00491 if (acquisit_LastGpsTop.value.d==0)
00492 {
00493 return(0);
00494 }
00495
00496 if (abs(acquisit_LastGpsTop.value.d-time(NULL))>MAX_GPS_TOP_OLDNESS)
00497 {
00498 return(1);
00499 }
00500 return(0);
00501 }
00502
00505 int CheckSageLastData(void)
00506 {
00507 struct stat st;
00508
00509 if (NULL==strstr(sysd_OsirisModel.value.s,"SAGE"))
00510 {
00511 return(0);
00512 }
00513
00514 if (0!=access("SageLastFile",R_OK))
00515 {
00516 return(0);
00517 }
00518
00519 if (0!=stat("SageLastFile",&st))
00520 {
00521 return(0);
00522 }
00523
00524 if (abs(time(NULL)-st.st_mtime)>MAX_LONGINFOS_AGE_TIMEOUT)
00525 {
00526 return(0);
00527 }
00528
00529 if (abs(time(NULL)-st.st_mtime)>MAX_SAGEDATA_AGE)
00530 {
00531 return(1);
00532 }
00533
00534 return(0);
00535 }
00536
00539 int CheckSageLastEventList(void)
00540 {
00541 struct stat st;
00542
00543 if (NULL==strstr(sysd_OsirisModel.value.s,"SAGE"))
00544 {
00545 return(0);
00546 }
00547
00548 if (0!=access("SageLastEventList",R_OK))
00549 {
00550 return(0);
00551 }
00552
00553 if (0!=stat("SageLastEventList",&st))
00554 {
00555 return(0);
00556 }
00557
00558 if (abs(time(NULL)-st.st_mtime)>MAX_LONGINFOS_AGE_TIMEOUT)
00559 {
00560 return(0);
00561 }
00562
00563 if (abs(time(NULL)-st.st_mtime)>MAX_SAGEDATA_AGE)
00564 {
00565 return(1);
00566 }
00567
00568 return(0);
00569 }
00570
00571
00573 int CheckRecordingAge(void)
00574 {
00575 time_t t=-2;
00576 if (diskmgr_lastWriteTime.valid==0)
00577 {
00578 return(0);
00579 }
00580 if (gpsd_SystemTime.valid==0)
00581 {
00582 t=gpsd_SystemTime.value.d;
00583 }
00584 if (t==-2)
00585 {
00586 return(0);
00587 }
00588 if (strcasecmp(trigger_RecordingMode.value.s,"continuous")==0)
00589 {
00590 if (abs(diskmgr_lastWriteTime.value.d-t)>MAX_FUZZYNESS)
00591 {
00592 return(1);
00593 }
00594 }
00595 return(0);
00596 }
00597
00598
00600 int CheckAcquisitDiskmgrTime(void)
00601 {
00602 if (diskmgr_LastAcquisitCorrectedTime.valid==0)
00603 {
00604 return(0);
00605 }
00606 if (acquisit_CorrectedTime.valid==0)
00607 {
00608 return(0);
00609 }
00610 if (abs(diskmgr_LastAcquisitCorrectedTime.value.d-acquisit_CorrectedTime.value.d)>MAX_FUZZYNESS)
00611 {
00612 return(1);
00613 }
00614 return(0);
00615 }
00616
00617
00619 int CheckContinuousRecording(void)
00620 {
00621 if (strcasecmp(trigger_RecordingMode.value.s,"continuous")==0)
00622 {
00623 if (diskmgr_Record.value.d==0)
00624 {
00625 return(1);
00626 }
00627 }
00628 return(0);
00629 }
00630
00631
00633 int CheckNoiseLevel(void)
00634 {
00635
00636 if (sysd_OsirisModel.valid==0)
00637 {
00638 return(0);
00639 }
00641 if (
00642 (NULL!=strstr(sysd_OsirisModel.value.s,"MYKERINOS"))||
00643 (NULL!=strstr(sysd_OsirisModel.value.s,"SAGE-PC"))
00644 )
00645 {
00646 return(0);
00647 }
00648 #define DoCheckNoiseLevel(i) \
00649 if ((acquisit_Lta##i.valid==1)&&(acquisit_Sta##i.valid==1)&&(acquisit_Fs##i.valid==1)&&(acquisit_Fs##i.value.d>5)) \
00650 { \
00651 if (((acquisit_Lta##i.value.d==0)||((acquisit_Lta##i.value.d>>8)>=(1<<24)-1))&& \
00652 ((acquisit_Sta##i.value.d==0)||((acquisit_Sta##i.value.d>>8)>=(1<<24)-1))) \
00653 { \
00654 return(1); \
00655 } \
00656 }
00657 DoCheckNoiseLevel( 0); DoCheckNoiseLevel( 1); DoCheckNoiseLevel( 2); DoCheckNoiseLevel( 3);
00658 DoCheckNoiseLevel( 4); DoCheckNoiseLevel( 5); DoCheckNoiseLevel( 6); DoCheckNoiseLevel( 7);
00659 DoCheckNoiseLevel( 8); DoCheckNoiseLevel( 9); DoCheckNoiseLevel(10); DoCheckNoiseLevel(11);
00660 DoCheckNoiseLevel(11); DoCheckNoiseLevel(13); DoCheckNoiseLevel(14); DoCheckNoiseLevel(15);
00661 DoCheckNoiseLevel(16); DoCheckNoiseLevel(17); DoCheckNoiseLevel(18); DoCheckNoiseLevel(19);
00662 DoCheckNoiseLevel(20); DoCheckNoiseLevel(21); DoCheckNoiseLevel(22); DoCheckNoiseLevel(23);
00663 return(0);
00664 }
00665
00667 struct OsirisAlert AlertTable[] =
00668 {
00669 { "NOINFO", 0, "No information since more than 1 day", CheckLastInformationTime },
00670 { "OLDPULSE", 0, "Last GPS synchronization pulse older than 24 hours", CheckAgeOfLastPulse } ,
00671 { "BIGSHIFT", 0, "The time shift is larger than 20 seconds, please set time", CheckTimeShiftAmplitude } ,
00672 { "BIGDRIFT", 0, "The clock drift is too high", CheckDriftAmplitude } ,
00673 { "LOWPOWER", 0, "Main power level too low", CheckBatteryLevel } ,
00674 { "INTPOWER", 0, "Internal battery out of bounds", CheckInternalBatteryLevel } ,
00675 { "SHORTPOWER",0,"External power will be exhausted within less than 3 days", CheckBatteryETR } ,
00676 { "DISKERROR", 0,"Mass storage error", CheckStorageError } ,
00677 { "NODISK", 0, "No external mass storage detected", CheckStorageDisk } ,
00678 { "REBOOT", 0, "Station has booted less than 12 hours ago", CheckBootTime } ,
00679 { "GENERAL", 0, "The general error flag is raised", CheckGeneralError } ,
00680 { "GPS", 0, "GPS error detected", CheckGps } ,
00681
00682
00683 { "OSHWWW", 0, "Process osh/www is not running", CheckProcessOshWww } ,
00684 { "OSHCMD", 0, "Process osh/cmd is not running", CheckProcessOshCmd } ,
00685 { "TRIGGER", 0, "Process trigger is not running", CheckProcessTrigger } ,
00686 { "DISKMGR", 0, "Process diskmgr is not running", CheckProcessDiskmgr } ,
00687 { "ACQUISIT", 0, "Process acquisit is not running", CheckProcessAcquisit } ,
00688 { "CONFIGURATION", 0, "Process configuration is not running", CheckProcessConfiguration } ,
00689 { "SYSD", 0, "Process sysd is not running", CheckProcessConfiguration } ,
00690 { "GPSD", 0, "Process gpsd is not running", CheckProcessGpsd } ,
00691
00692 { "OLDWRITE", 0, "Time inconcistency for the last data on disk, check recording mode", CheckRecordingAge } ,
00693 { "NORECORD", 0, "Station is not recording while in continuous mode", CheckContinuousRecording } ,
00694 { "BUGGYTIME",0, "Time inconcistency, please check", CheckAcquisitDiskmgrTime } ,
00695 { "NOISE", 0, "The noise level is too low or too high, please check the signal", CheckNoiseLevel } ,
00696 { "NOISEOOB", 0, "Out of bound noise detected", CheckStaLtaBounds } ,
00697 { "SAGEPORT22", 0, "Last data from SAGE is too old (port 22)", CheckSageLastData } ,
00698 { "SAGEPORT79", 0, "Last change of the event list is too old (port 79)", CheckSageLastEventList } ,
00699 { 0, 0, 0 }
00700 };
00701
00703 struct OsirisAlert MykerinosRAlertTable[] =
00704 {
00705 { "LOWPOWER", 0, "Main power level too low", CheckBatteryLevel } ,
00706
00707 { "REBOOT", 0, "Station has booted less than 1 hour ago", CheckBootTime } ,
00708 { "GENERAL", 0, "The general error flag is raised", CheckGeneralError } ,
00709 { 0, 0, 0 }
00710 };
00711
00713 struct OsirisAlert WarningTable[] =
00714 {
00715 { "OLDPULSE", 0, "Last GPS synchronization pulse older than 24 hours", CheckAgeOfLastPulse } ,
00716 { 0, 0, 0 }
00717 };