Example #1
0
/**
Reset (acknoledge) alarm.

@param alarm_name Alarm name, defined in /alarms/alarms
@return AL_SUCCESS, AL_RESETE, AL_INVALID_NAME
*/
INT al_reset_alarm(const char *alarm_name)
{
   int status, size, i;
   HNDLE hDB, hkeyalarm, hkeyclass, hsubkey;
   KEY key;
   char str[256];
   ALARM a;
   ALARM_CLASS ac;

   cm_get_experiment_database(&hDB, NULL);

   if (alarm_name == NULL) {
      /* reset all alarms */
      db_find_key(hDB, 0, "/Alarms/Alarms", &hkeyalarm);
      if (hkeyalarm) {
         for (i = 0;; i++) {
            db_enum_link(hDB, hkeyalarm, i, &hsubkey);

            if (!hsubkey)
               break;

            db_get_key(hDB, hsubkey, &key);
            al_reset_alarm(key.name);
         }
      }
      return AL_SUCCESS;
   }

   /* find alarm and alarm class */
   sprintf(str, "/Alarms/Alarms/%s", alarm_name);
   db_find_key(hDB, 0, str, &hkeyalarm);
   if (!hkeyalarm) {
      /*cm_msg(MERROR, "al_reset_alarm", "Alarm %s not found in ODB", alarm_name);*/
      return AL_INVALID_NAME;
   }

   size = sizeof(a);
   status = db_get_record(hDB, hkeyalarm, &a, &size, 0);
   if (status != DB_SUCCESS) {
      cm_msg(MERROR, "al_reset_alarm", "Cannot get alarm record");
      return AL_ERROR_ODB;
   }

   sprintf(str, "/Alarms/Classes/%s", a.alarm_class);
   db_find_key(hDB, 0, str, &hkeyclass);
   if (!hkeyclass) {
      cm_msg(MERROR, "al_reset_alarm", "Alarm class %s not found in ODB", a.alarm_class);
      return AL_INVALID_NAME;
   }

   size = sizeof(ac);
   status = db_get_record(hDB, hkeyclass, &ac, &size, 0);
   if (status != DB_SUCCESS) {
      cm_msg(MERROR, "al_reset_alarm", "Cannot get alarm class record");
      return AL_ERROR_ODB;
   }

   if (a.triggered) {
      a.triggered = 0;
      a.time_triggered_first[0] = 0;
      a.time_triggered_last[0] = 0;
      a.checked_last = 0;

      ac.system_message_last = 0;
      ac.execute_last = 0;

      status = db_set_record(hDB, hkeyalarm, &a, sizeof(a), 0);
      if (status != DB_SUCCESS) {
         cm_msg(MERROR, "al_reset_alarm", "Cannot update alarm record");
         return AL_ERROR_ODB;
      }
      status = db_set_record(hDB, hkeyclass, &ac, sizeof(ac), 0);
      if (status != DB_SUCCESS) {
         cm_msg(MERROR, "al_reset_alarm", "Cannot update alarm class record");
         return AL_ERROR_ODB;
      }
      cm_msg(MINFO, "al_reset_alarm", "Alarm \"%s\" reset", alarm_name);
      return AL_RESET;
   }

   return AL_SUCCESS;
}
Example #2
0
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, &timesincefill);
    *timesincefill = 0;
    bk_close(pevent, ++timesincefill);

    return bk_size(pevent);
  }

  // Check the status
  bk_create(pevent, "LN2F", TID_DWORD, &timesincefill);
  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);
}