void scfe_error(const char *error) { char str[256]; printf("why dis\n"); strlcpy(str, error, sizeof(str)); cm_msg(MERROR, "scfe_error", str); al_trigger_alarm("MSCB", str, "MSCB Alarm", "Communication Problem", AT_INTERNAL); }
/** Scan ODB for alarms. @return AL_SUCCESS */ INT al_check() { if (rpc_is_remote()) return rpc_call(RPC_AL_CHECK); #ifdef LOCAL_ROUTINES { INT i, status, size, semaphore; HNDLE hDB, hkeyroot, hkey; KEY key; ALARM a; char str[256], value[256]; time_t now; PROGRAM_INFO program_info; BOOL flag; ALARM_CLASS_STR(alarm_class_str); ALARM_ODB_STR(alarm_odb_str); ALARM_PERIODIC_STR(alarm_periodic_str); cm_get_experiment_database(&hDB, NULL); if (hDB == 0) return AL_SUCCESS; /* called from server not yet connected */ /* check online mode */ flag = TRUE; size = sizeof(flag); db_get_value(hDB, 0, "/Runinfo/Online Mode", &flag, &size, TID_INT, TRUE); if (!flag) return AL_SUCCESS; /* check global alarm flag */ flag = TRUE; size = sizeof(flag); db_get_value(hDB, 0, "/Alarms/Alarm system active", &flag, &size, TID_BOOL, TRUE); if (!flag) return AL_SUCCESS; /* request semaphore */ cm_get_experiment_semaphore(&semaphore, NULL, NULL, NULL); status = ss_semaphore_wait_for(semaphore, 100); if (status == SS_TIMEOUT) return AL_SUCCESS; /* someone else is doing alarm business */ if (status != SS_SUCCESS) { printf("al_check: Something is wrong with our semaphore, ss_semaphore_wait_for() returned %d, aborting.\n", status); //abort(); // DOES NOT RETURN printf("al_check: Cannot abort - this will lock you out of odb. From this point, MIDAS will not work correctly. Please read the discussion at https://midas.triumf.ca/elog/Midas/945\n"); // NOT REACHED return AL_SUCCESS; } /* check ODB alarms */ db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyroot); if (!hkeyroot) { /* create default ODB alarm */ status = db_create_record(hDB, 0, "/Alarms/Alarms/Demo ODB", strcomb(alarm_odb_str)); db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyroot); if (!hkeyroot) { ss_semaphore_release(semaphore); return AL_SUCCESS; } status = db_create_record(hDB, 0, "/Alarms/Alarms/Demo periodic", strcomb(alarm_periodic_str)); db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyroot); if (!hkeyroot) { ss_semaphore_release(semaphore); return AL_SUCCESS; } /* create default alarm classes */ status = db_create_record(hDB, 0, "/Alarms/Classes/Alarm", strcomb(alarm_class_str)); status = db_create_record(hDB, 0, "/Alarms/Classes/Warning", strcomb(alarm_class_str)); if (status != DB_SUCCESS) { ss_semaphore_release(semaphore); return AL_SUCCESS; } } for (i = 0;; i++) { status = db_enum_key(hDB, hkeyroot, i, &hkey); if (status == DB_NO_MORE_SUBKEYS) break; db_get_key(hDB, hkey, &key); size = sizeof(a); status = db_get_record(hDB, hkey, &a, &size, 0); if (status != DB_SUCCESS || a.type < 1 || a.type > AT_LAST) { /* make sure alarm record has right structure */ db_check_record(hDB, hkey, "", strcomb(alarm_odb_str), TRUE); size = sizeof(a); status = db_get_record(hDB, hkey, &a, &size, 0); if (status != DB_SUCCESS || a.type < 1 || a.type > AT_LAST) { cm_msg(MERROR, "al_check", "Cannot get alarm record"); continue; } } /* check periodic alarm only when active */ if (a.active && a.type == AT_PERIODIC && a.check_interval > 0 && (INT) ss_time() - (INT) a.checked_last > a.check_interval) { /* if checked_last has not been set, set it to current time */ if (a.checked_last == 0) { a.checked_last = ss_time(); db_set_record(hDB, hkey, &a, size, 0); } else al_trigger_alarm(key.name, a.alarm_message, a.alarm_class, "", AT_PERIODIC); } /* check alarm only when active and not internal */ if (a.active && a.type == AT_EVALUATED && a.check_interval > 0 && (INT) ss_time() - (INT) a.checked_last > a.check_interval) { /* if condition is true, trigger alarm */ if (al_evaluate_condition(a.condition, value)) { sprintf(str, a.alarm_message, value); al_trigger_alarm(key.name, str, a.alarm_class, "", AT_EVALUATED); } else { a.checked_last = ss_time(); status = db_set_value(hDB, hkey, "Checked last", &a.checked_last, sizeof(DWORD), 1, TID_DWORD); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_check", "Cannot change alarm record"); continue; } } } } /* check /programs alarms */ db_find_key(hDB, 0, "/Programs", &hkeyroot); if (hkeyroot) { for (i = 0;; i++) { status = db_enum_key(hDB, hkeyroot, i, &hkey); if (status == DB_NO_MORE_SUBKEYS) break; db_get_key(hDB, hkey, &key); /* don't check "execute on xxx" */ if (key.type != TID_KEY) continue; size = sizeof(program_info); status = db_get_record(hDB, hkey, &program_info, &size, 0); if (status != DB_SUCCESS) { cm_msg(MERROR, "al_check", "Cannot get program info record"); continue; } now = ss_time(); rpc_get_name(str); str[strlen(key.name)] = 0; if (!equal_ustring(str, key.name) && cm_exist(key.name, FALSE) == CM_NO_CLIENT) { if (program_info.first_failed == 0) { program_info.first_failed = (DWORD) now; db_set_record(hDB, hkey, &program_info, sizeof(program_info), 0); } /* fire alarm when not running for more than what specified in check interval */ if (now - program_info.first_failed >= program_info.check_interval / 1000) { /* if not running and alarm calss defined, trigger alarm */ if (program_info.alarm_class[0]) { sprintf(str, "Program %s is not running", key.name); al_trigger_alarm(key.name, str, program_info.alarm_class, "Program not running", AT_PROGRAM); } /* auto restart program */ if (program_info.auto_restart && program_info.start_command[0]) { ss_system(program_info.start_command); program_info.first_failed = 0; cm_msg(MTALK, "al_check", "Program %s restarted", key.name); } } } else { if (program_info.first_failed != 0) { program_info.first_failed = 0; db_set_record(hDB, hkey, &program_info, sizeof(program_info), 0); } } } } ss_semaphore_release(semaphore); } #endif /* LOCAL_COUTINES */ return SUCCESS; }
INT ge_ln2_read(char *pevent, INT off) { static INT status, size; static DWORD lastfilled, now, timelimit; static BOOL justfilled; static DWORD *timesincefill; bk_init(pevent); timesincefill = NULL; // Get recent values size = sizeof(lastfilled); status = db_get_value(hDB, 0, sLastFilled, &lastfilled, &size, TID_DWORD, FALSE); if (status != DB_SUCCESS) { cm_msg(MERROR, "ge_ln2_read", "Error getting last filled time"); return 0; } size = sizeof(justfilled); status = db_get_value(hDB, 0, sJustFilled, &justfilled, &size, TID_BOOL, FALSE); if (status != DB_SUCCESS) { cm_msg(MERROR, "ge_ln2_read", "Error getting just filled status"); return 0; } size = sizeof(timelimit); status = db_get_value(hDB, 0, sTimeLimit, &timelimit, &size, TID_DWORD, FALSE); if (status != DB_SUCCESS) { cm_msg(MERROR, "ge_ln2_read", "Error getting time limit between fills"); return 0; } // If just filled, write time to ODB if (justfilled == TRUE) { lastfilled = (DWORD)time(NULL); status = db_set_value(hDB, 0, sLastFilled, &lastfilled, sizeof(lastfilled), 1, TID_DWORD); if (status != DB_SUCCESS) { cm_msg(MERROR, "gn_ln2_read", "Error setting last filled time"); return 0; } justfilled = FALSE; status = db_set_value(hDB, 0, sJustFilled, &justfilled, sizeof(justfilled), 1, TID_BOOL); if (status != DB_SUCCESS) { cm_msg(MERROR, "gn_ln2_read", "Error setting just filled status"); return 0; } al_reset_alarm(sAlarmName); bk_create(pevent, "LN2F", TID_DWORD, ×incefill); *timesincefill = 0; bk_close(pevent, ++timesincefill); return bk_size(pevent); } // Check the status bk_create(pevent, "LN2F", TID_DWORD, ×incefill); now = (DWORD) time(NULL); *timesincefill = now - lastfilled; if (*timesincefill > timelimit) { al_trigger_alarm(sAlarmName, "Germanium must be filled!", "Alarm", "", AT_INTERNAL); printf("Alarm!\n"); } bk_close(pevent, ++timesincefill); return bk_size(pevent); }