Ejemplo n.º 1
0
/* Supervise emon server process */
void
pwrs_Node_SupEmon (
)
{
  int i = errh_eAnix_emon - 1;
  pwr_tTime current_time;
  pwr_tDeltaTime diff;
  static float timeout = 3;

  if ( !np) {
    pwr_tOid oid;
    pwr_tStatus sts;

    sts = gdh_GetNodeObject( 0, &oid);
    if ( ODD(sts))
      gdh_ObjidToPointer( oid, (void **) &np);
    if ( EVEN(sts)) return;
  }

  if ( !np)
    return;

  if ( np->ProcStatus[i] != 0 && np->ProcStatus[i] != PWR__PTIMEOUT) {
    time_GetTime( &current_time);
    time_Adiff( &diff, &current_time, &np->ProcTimeStamp[i]);

    if ( time_DToFloat( 0, &diff) > timeout) {
      if ( errh_Severity( np->ProcStatus[i]) < errh_Severity(PWR__PTIMEOUT)) {
	np->ProcStatus[i] = PWR__PTIMEOUT;
	np->SystemStatus = PWR__PTIMEOUT;
      }
    }
  }
}
Ejemplo n.º 2
0
int Op::sup_init()
{
  pwr_tOid node_oid;
  pwr_tOid sup_oid;
  pwr_tAName aname;
  pwr_tStatus sts;
  

  // Index 0 is current node
  sts = gdh_GetNodeObject( 0, &node_oid);
  if ( EVEN(sts)) return sts;

  OpSup sup;
  sup.node_oid = node_oid;
  sts = gdh_ObjidToName( node_oid, sup.object_name, sizeof(sup.object_name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) return sts;

  strcpy( aname, sup.object_name);
  strcat( aname, ".SystemStatus");
  sts = gdh_RefObjectInfo( aname, (void **)&sup.p, &sup.refid, sizeof(pwr_tStatus));
  if ( EVEN(sts)) return sts;

  syi_NodeName( &sts, sup.node_name, sizeof(sup.node_name));

  sup_vect.push_back(sup);			 

  // Add nodes in NodeLinkSup objects
  for ( sts = gdh_GetClassList( pwr_cClass_NodeLinkSup, &sup_oid);
	ODD(sts);
	sts = gdh_GetNextObject( sup_oid, &sup_oid)) {
    pwr_sClass_NodeLinkSup *sup_p;
    qcom_sNode 		qnode;
    pwr_tNid		nid;

    sts = gdh_ObjidToPointer( sup_oid, (void **)&sup_p);

    OpSup nsup;

    nsup.node_oid = sup_p->Node;

    sts = gdh_ObjidToName( nsup.node_oid, nsup.object_name, sizeof(nsup.object_name), 
			   cdh_mName_volumeStrict);
    if ( EVEN(sts)) strcpy( nsup.object_name, "");
    
    sts = gdh_ObjidToName( sup_oid, aname, sizeof(aname), cdh_mName_volumeStrict);
    if ( EVEN(sts)) return sts;
    
    strcat( aname, ".SystemStatus");
    sts = gdh_RefObjectInfo( aname, (void **)&nsup.p, &sup.refid, sizeof(pwr_tStatus));
    if ( EVEN(sts)) return sts;

    int found = 0;
    for (nid = qcom_cNNid; qcom_NextNode(&sts, &qnode, nid); nid = qnode.nid) {
      if ( qnode.nid == nsup.node_oid.vid) {
	strcpy( nsup.node_name, qnode.name);
	found = 1;
	break;
      }
    }
    if ( !found)
      strcpy( nsup.node_name, "Unknown");

    sup_vect.push_back(nsup);			 
  }
  return 1;
}
Ejemplo n.º 3
0
static pwr_tStatus 
init_plc (
  plc_sProcess	*pp
)
{
  pwr_tStatus	sts = PLC__SUCCESS;
  pwr_tObjid   	oid;
  pwr_tObjid   	pp_oid;
  pwr_tObjid   	io_oid;
  pwr_tObjid	thread_oid;
  int		sec;
  int		msec;
  int		i;
  pwr_tCid	cid;

  sts = gdh_GetNodeObject(0, &oid);
  if (EVEN(sts)) {
    errh_Fatal("gdh_GetNodeObject, %m", sts);
    exit(sts);
  }

  sts = gdh_ObjidToPointer(oid, (void *)&pp->Node);
  if (EVEN(sts)) return sts;

  sts = gdh_GetClassList(pwr_cClass_PlcProcess, &pp_oid);
  if (EVEN(sts)) {
    errh_Error("Found no PlcProcess-object\n%m", sts);
    return sts;
  }

  sts = gdh_ObjidToPointer(pp_oid, (void *)&pp->PlcProcess);
  if (EVEN(sts)) return sts;

  i = 0;
  sts = gdh_GetChild( pp_oid, &thread_oid);
  while ( ODD(sts)) {
    sts = gdh_GetObjectClass( thread_oid, &cid);
    if ( EVEN(sts)) return sts;
    
    if ( cid == pwr_cClass_PlcThread)
      pp->PlcProcess->PlcThreadObjects[i++] = thread_oid;

    sts = gdh_GetNextSibling( thread_oid, &thread_oid);
  }
  for ( ; i > sizeof(pp->PlcProcess->PlcThreadObjects)/sizeof(pp->PlcProcess->PlcThreadObjects[0]); i++)
    pp->PlcProcess->PlcThreadObjects[i] = pwr_cNObjid;

  aproc_RegisterObject( pp_oid);

  sts = gdh_GetClassList(pwr_cClass_IOHandler, &io_oid);
  if (EVEN(sts)) {
    errh_Error("Found no IOHandler-object\n%m", sts);
    return sts;
  }

  sts = gdh_ObjidToPointer(io_oid, (void *)&pp->IOHandler);
  if (EVEN(sts)) return sts;

  /* Set subscription defaults for PLC job */

  sts = gdh_SetSubscriptionDefaults(
    (pwr_tInt32)(pp->PlcProcess->SubscriptionInterval * 1000.), 10000);

  sec = pp->PlcProcess->SubscriptionInterval;
  msec = (int)((pp->PlcProcess->SubscriptionInterval - sec) * 1000.);
  errh_Info("Setting subscription defaults to %d.%03d seconds", sec, msec);

  sts = gdh_ObjidToName(oid, pp->nodeName, sizeof(pp->nodeName), cdh_mNName);
  if (EVEN(sts)) return sts;

  init_grafcet(pp);
  link_io_base_areas(pp);

  return sts;
}
Ejemplo n.º 4
0
int rtt_show_signals(
    menu_ctx parent_ctx, char* filename, char* windowname, int debug)
{
  pwr_tFileName default_filename;
  FILE* file;
  char line[500];
  int window_spaces;
  pwr_tOName window;
  pwr_tOName object;
  pwr_tOName objname;
  int spaces = 30;
  int sts;
  char* s;
  int wildcard;
  char title[250];
  char classname[32];
  int j;
  int index = 0;
  pwr_tObjid objid;
  pwr_tObjid childobjid;
  rtt_t_menu* menulist = 0;
  char filestr[80];
  int lines;
  int window_found;
  pwr_tVolumeId volid;

  window_found = 0;
  rtt_toupper(windowname, windowname);

  /* Check if wildcard */
  s = strchr(windowname, '*');
  if (s == 0)
    wildcard = 0;
  else
    wildcard = 1;

  /* Open file */
  if (filename == NULL) {
    /* Open file, first get the volume id */
    if (!wildcard) {
      sts = gdh_NameToObjid(windowname, &objid);
      if (EVEN(sts)) {
        rtt_message('E', "Window not found");
        return RTT__NOPICTURE;
      }
      volid = objid.vid;
    } else {
      sts = gdh_GetNodeObject(0, &objid);
      if (EVEN(sts))
        return sts;
      volid = objid.vid;
    }

    sprintf(default_filename, "%srtt_plc_%s.dat", rtt_pwr_dir("pwrp_load"),
        rtt_VolumeIdToStr(volid));
    rtt_get_defaultfilename(default_filename, filestr, NULL);
    file = fopen(filestr, "r");
  } else {
    rtt_get_defaultfilename(filename, filestr, ".lis");
    file = fopen(filestr, "r");
  }

  if (file == 0) {
    rtt_message('E', "Unable to open file");
    return RTT__NOPICTURE;
  }

  /* First line is a header, skip it */
  sts = rtt_get_signal_line(
      file, line, sizeof(line), &window_spaces, object, &lines);
  if (EVEN(sts))
    return RTT__NOFILE;

  /* Get the hierarchy */
  while (spaces >= 30) {
    /* This is still the header */
    sts = rtt_get_signal_line(
        file, line, sizeof(line), &spaces, object, &lines);
    if (EVEN(sts))
      return RTT__NOFILE;
  }
  window_spaces = spaces;

  while (1) {
    while (spaces != window_spaces) {
      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
    }
    strcpy(window, object);
    rtt_toupper(window, window);

    sts = rtt_wildcard(windowname, window);
    if (!sts) {
      window_found = 1;
      /* Hit, print the window */
      /* Get objid for the object */
      sts = gdh_NameToObjid(window, &objid);
      if (EVEN(sts)) {
        sts = rtt_get_signal_line(
            file, line, sizeof(line), &spaces, object, &lines);
        if (EVEN(sts))
          goto finish;
        continue;
      }

      /* Get the object name */
      sts = gdh_ObjidToName(objid, objname, sizeof(objname), cdh_mNName);
      if (EVEN(sts))
        return sts;

      /* Get class name */
      sts = rtt_objidtoclassname(objid, classname);
      if (EVEN(sts))
        return sts;

      /* Add class name to objname in title */
      strcpy(title, objname);
      for (j = strlen(title); j < 45; j++)
        strcat(title, " ");
      strcat(title, " ");
      strcat(title, classname);

      /* Mark if the object has children */
      sts = gdh_GetChild(objid, &childobjid);
      if (ODD(sts))
        strcat(title, " *");

      if (!debug) {
        sts = rtt_menu_list_add(&menulist, index, 0, title,
            &rtt_hierarchy_child, &rtt_object_parameters, &rtt_crossref_signal,
            objid, 0, 0, 0, 0);
        if (EVEN(sts))
          return sts;
        index++;
      }

      /* Find the signal list */
      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
      while (spaces > window_spaces) {
        if (streq(object, "Signals")) {
          /* This is the signals */
          sts = rtt_get_signal_line(
              file, line, sizeof(line), &spaces, object, &lines);
          if (EVEN(sts))
            goto finish;
          lines = 1;
          while ((spaces > window_spaces) && (lines == 1)) {
            /* Insert the object in menulist */

            /* Get objid for the object */
            sts = gdh_NameToObjid(object, &objid);
            if (EVEN(sts)) {
              /* End of this list, read next line and continue */
              sts = rtt_get_signal_line(
                  file, line, sizeof(line), &spaces, object, &lines);
              if (EVEN(sts))
                goto finish;
              continue;
            }
            /* Get the object name */
            sts = gdh_ObjidToName(objid, objname, sizeof(objname), cdh_mNName);
            if (EVEN(sts))
              return sts;

            /* Get class name */
            sts = rtt_objidtoclassname(objid, classname);
            if (EVEN(sts))
              return sts;

            /* Add class name to objname in title */
            strcpy(title, "    ");
            strcat(title, objname);
            for (j = strlen(title); j < 45; j++)
              strcat(title, " ");
            strcat(title, " ");
            strcat(title, classname);

            if (!debug) {
              sts = rtt_menu_list_add(&menulist, index, 0, title,
                  &rtt_hierarchy_child, &rtt_object_parameters,
                  &rtt_crossref_signal, objid, 0, 0, 0, 0);
              if (EVEN(sts))
                return sts;
              index++;
            } else {
              sts = rtt_debug_object_add(
                  objid, (rtt_t_menu_upd**)&menulist, &index, &one, 0, 0);
              if (EVEN(sts))
                return sts;
            }

            sts = rtt_get_signal_line(
                file, line, sizeof(line), &spaces, object, &lines);
            if (EVEN(sts))
              goto finish;
            /* Check if end of signals !! */
          }
        } else {
          sts = rtt_get_signal_line(
              file, line, sizeof(line), &spaces, object, &lines);
          if (EVEN(sts))
            goto finish;
        }
      }
      if (!wildcard)
        goto finish;
    } else {
      if (window_found)
        goto finish;

      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
    }
  }

finish:
  fclose(file);

  if (menulist != 0) {
    strcpy(title, "LIST OF SIGNALS");
    /*	  sts = rtt_menu_bubblesort( menulist);*/
    if (!debug)
      sts = rtt_menu_new(
          parent_ctx, pwr_cNObjid, &menulist, title, 0, RTT_MENUTYPE_DYN);
    else
      sts = rtt_menu_upd_new(parent_ctx, pwr_cNObjid,
          (rtt_t_menu_upd**)&menulist, title, 0, RTT_MENUTYPE_DYN);
    if (sts == RTT__FASTBACK)
      return sts;
    else if (sts == RTT__BACKTOCOLLECT)
      return sts;
    else if (EVEN(sts))
      return sts;
  } else {
    rtt_message('E', "No windows found");
    return RTT__NOPICTURE;
  }

  return RTT__SUCCESS;
}
Ejemplo n.º 5
0
int rtt_crr_code(
    char* filename, char* str, int brief, int func, int case_sensitive)
{
  pwr_tFileName default_filename;
  FILE* file;
  char line[500];
  char tst_line[500];
  pwr_tAName object;
  pwr_tOName objname;
  int spaces;
  int first;
  int sts;
  char* s;
  int signalcount = 0;
  char filestr[80];
  int lines;
  char* buff;
  pwr_tVolumeId volid;
  pwr_tObjid objid;
  int buffcnt = 0;
  int len;
  int i;
  int objname_written;
  int hit;
  char* tst_char;

  /* Open file */
  if (filename == NULL) {
    sts = gdh_GetNodeObject(0, &objid);
    if (EVEN(sts))
      return sts;
    volid = objid.vid;

    sprintf(default_filename, "%srtt_crrc_%s.dat", rtt_pwr_dir("pwrp_load"),
        rtt_VolumeIdToStr(volid));
    rtt_get_defaultfilename(default_filename, filestr, NULL);
    file = fopen(filestr, "r");
  } else {
    rtt_get_defaultfilename(filename, filestr, ".lis");
    file = fopen(filestr, "r");
  }

  if (file == 0) {
    rtt_message('E', "Unable to open file");
    return RTT__NOPICTURE;
  }

  /* Case sensitive if any lowercase */
  if (!case_sensitive)
    for (s = str; *s != 0; s++) {
      if (!isupper(*s))
        case_sensitive = 1;
    }

  buff = calloc(1, CRR_BUFF_SIZE);
  if (!buff) {
    rtt_message('E', "Unable to allocate memory");
    fclose(file);
    return RTT__NOPICTURE;
  }

  /* Get the hierarchy */
  while (!str_StartsWith(line, " _Obj_ ")) {
    sts = rtt_get_signal_line(
        file, line, sizeof(line), &spaces, object, &lines);
    if (EVEN(sts))
      goto finish;
  }

  first = 1;
  while (1) {
    strcpy(objname, &line[7]);
    for (s = objname; !(*s == 32 || *s == 9 || *s == 0); s++)
      ;
    *s = 0;

    sts = rtt_get_signal_line(
        file, line, sizeof(line), &spaces, object, &lines);
    objname_written = 0;
    while (!str_StartsWith(line, " _Obj_ ")) {
      if (!case_sensitive)
        rtt_toupper(tst_line, line);
      else
        strcpy(tst_line, line);

      hit = 0;
      if (!func) {
        if (strstr(tst_line, str) != 0)
          hit = 1;
      } else {
        if ((s = strstr(tst_line, str)) != 0) {
          hit = 1;
          /* Check char after */
          tst_char = s + strlen(str);
          if (isalpha(*tst_char) || isdigit(*tst_char) || *tst_char == '_')
            hit = 0;
          /* Check char before */
          if (s != tst_line) {
            tst_char = s - 1;
            if (isalpha(*tst_char) || isdigit(*tst_char) || *tst_char == '_')
              hit = 0;
          }
        }
      }
      if (hit) {
        /* Hit, print this object */
        if (signalcount == 0) {
          rtt_clear_screen();
          if (func)
            buffcnt
                = sprintf(buff, "Crossreferens list Function  \"%s\"\n\n", str);
          else
            buffcnt
                = sprintf(buff, "Crossreferens list String    \"%s\"\n\n", str);
        }
        signalcount++;

        if (buffcnt > CRR_BUFF_SIZE - 100) {
          buffcnt += sprintf(
              buff + buffcnt, "RTT-E-QUOTAEXC, Crossref quota exceeded");
          goto finish;
        }
        if (!objname_written) {
          len = sprintf(buff + buffcnt, " %s", objname);
          objname_written = 1;
        } else
          len = 0;
        for (i = len; i < 45; i++) {
          strcat(buff + buffcnt + len, " ");
          len++;
        }
        buffcnt += len;

        buffcnt += sprintf(buff + buffcnt, " \"%s\"\n", line);

        if (brief) {
          while (!str_StartsWith(line, " _Obj_ ")) {
            sts = rtt_get_signal_line(
                file, line, sizeof(line), &spaces, object, &lines);
            if (EVEN(sts))
              goto finish;
          }
        } else {
          sts = rtt_get_signal_line(
              file, line, sizeof(line), &spaces, object, &lines);
          if (EVEN(sts))
            goto finish;
        }
      } else {
        sts = rtt_get_signal_line(
            file, line, sizeof(line), &spaces, object, &lines);
        if (EVEN(sts))
          goto finish;
      }
    }
  }

finish:
  fclose(file);

  if (signalcount > 0) {
    sts = rtt_view(0, 0, buff, "Crossreference list", RTT_VIEWTYPE_BUF);
    return sts;
  } else {
    if (func)
      rtt_message('E', "String not found");
    else
      rtt_message('E', "Function not found");
    return RTT__NOPICTURE;
  }
}
Ejemplo n.º 6
0
int rtt_crr_object(char* filename, char* objectname)
{
  pwr_tFileName default_filename;
  FILE* file;
  char line[200];
  int object_spaces;
  char object[80];
  pwr_tOName objname;
  char show_objname[80];
  int spaces;
  int first;
  int sts;
  char* s;
  int wildcard;
  int signalcount = 0;
  pwr_tFileName filestr;
  int lines;
  char* buff;
  pwr_tVolumeId volid;
  pwr_tObjid objid;
  int buffcnt = 0;

  rtt_toupper(objectname, objectname);

  /* Check if wildcard */
  s = strchr(objectname, '*');
  if (s == 0)
    wildcard = 0;
  else
    wildcard = 1;

  /* Open file */
  if (filename == NULL) {
    /* Open file, first get the volume id */
    if (!wildcard) {
      sts = gdh_NameToObjid(objectname, &objid);
      if (EVEN(sts)) {
        rtt_message('E', "Object not found");
        return RTT__NOPICTURE;
      }
      volid = objid.vid;
    } else {
      sts = gdh_GetNodeObject(0, &objid);
      if (EVEN(sts))
        return sts;
      volid = objid.vid;
    }

    sprintf(default_filename, "%srtt_crro_%s.dat", rtt_pwr_dir("pwrp_load"),
        rtt_VolumeIdToStr(volid));
    rtt_get_defaultfilename(default_filename, filestr, NULL);
    file = fopen(filestr, "r");
  } else {
    rtt_get_defaultfilename(filename, filestr, ".lis");
    file = fopen(filestr, "r");
  }

  if (file == 0) {
    rtt_message('E', "Unable to open file");
    return RTT__NOPICTURE;
  }

  buff = calloc(1, CRR_BUFF_SIZE);
  if (!buff) {
    rtt_message('E', "Unable to allocate memory");
    fclose(file);
    return RTT__NOPICTURE;
  }

  /* Get the object */
  sts = rtt_get_signal_line(file, line, sizeof(line), &spaces, object, &lines);
  if (EVEN(sts))
    goto finish;
  object_spaces = spaces;

  first = 1;
  while (1) {
    if ((s = strchr(object, ':')))
      strcpy(objname, s + 1);
    else
      strcpy(objname, object);

    strcpy(show_objname, objname);
    rtt_toupper(objname, objname);

    sts = rtt_wildcard(objectname, objname);
    if (sts) {
      pwr_tAName subname;
      strcpy(subname, objectname);
      strcat(subname, ".*");

      sts = rtt_wildcard(subname, objname);
    }
    if (!sts) {
      /* Hit, print this object */
      if (signalcount == 0) {
        rtt_clear_screen();
        buffcnt = sprintf(buff, "Crossreferens list   %s\n\n", show_objname);
      }
      signalcount++;

      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
      while (spaces > object_spaces) {
        str_trim(line, line);

        if (buffcnt > CRR_BUFF_SIZE - 100) {
          buffcnt += sprintf(
              buff + buffcnt, "RTT-E-QUOTAEXC, Crossref quota exceeded");
          goto finish;
        }

        buffcnt += sprintf(buff + buffcnt, " %s\n", line);

        sts = rtt_get_signal_line(
            file, line, sizeof(line), &spaces, object, &lines);
        if (EVEN(sts))
          goto finish;
      }
    } else {
      if (!wildcard && signalcount)
        goto finish;

      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
    }

    while (spaces != object_spaces) {
      sts = rtt_get_signal_line(
          file, line, sizeof(line), &spaces, object, &lines);
      if (EVEN(sts))
        goto finish;
    }
  }

finish:
  fclose(file);

  if (signalcount > 0) {
    sts = rtt_view(0, 0, buff, "Crossreference list", RTT_VIEWTYPE_BUF);
    return sts;
  } else {
    rtt_message('E', "Object not found");
    return RTT__NOPICTURE;
  }
}
Ejemplo n.º 7
0
void
pwrs_Node_Exec (
)
{
  int i;
  pwr_tTime current_time;
  pwr_tDeltaTime diff;
  errh_eSeverity severity;
  errh_eSeverity system_severity;
  errh_eSeverity plc_severity;
  int new_idx = -1;
  static int supervise[80] = {
    0,0,0,0,1,1,1,0,1,1,
    1,1,1,0,0,1,0,1,1,1,
    1,1,1,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    1,1,1,1,1,1,1,1,1,1,
    1,1,1,1,1,1,1,1,1,1};
  static int reboot_done = 0;

  if ( !np) {
    pwr_tOid oid;
    pwr_tStatus sts;

    sts = gdh_GetNodeObject( 0, &oid);
    if ( ODD(sts))
      gdh_ObjidToPointer( oid, (void **) &np);
    if ( EVEN(sts)) return;
  }

  if ( !np)
    return;

  if ( np->EmergBreakTrue) {
    switch ( np->EmergBreakSelect) {
    case 1: {
      /* Reboot */
      int sts;

      if ( !reboot_done) {
	errh_Fatal( "Emergency break action: reboot");
	sts = system("rt_prio --reboot");
	if ( sts != 0) 
	  errh_Fatal("Unable to reboot, sts %d", sts);
	reboot_done = 1;
      }
      break;
    }
    default: ;
    }
  }
  else
    reboot_done = 0;

  /* Calculate plc status */
  new_idx = -1;
  plc_severity = errh_Severity( np->ProcStatus[errh_eAnix_plc-1]);
  for ( i = errh_eAnix_plc1 - 1; i < errh_eAnix_plc1 - 1 + errh_cAnix_PlcSize; i++) {
    severity = errh_Severity( np->ProcStatus[i]);
    if ( np->ProcStatus[i] != 0 && EVEN(np->ProcStatus[i])) {
      if ( severity >= plc_severity) {
	new_idx = i;
        plc_severity = severity;
      }
    }
  }
  if ( new_idx != -1)
    np->ProcStatus[errh_eAnix_plc-1] = np->ProcStatus[new_idx];
  else if ( EVEN(np->ProcStatus[errh_eAnix_plc-1]))
    np->ProcStatus[errh_eAnix_plc-1] = PWR__SRUN;

  /* Calculate system status and check timestamp */
  new_idx = -1;
  system_severity = errh_Severity( np->SystemStatus);
  time_GetTime( &current_time);
  for ( i = 0; i < sizeof(np->ProcStatus)/sizeof(np->ProcStatus[0]); i++) {
    if ( np->ProcStatus[i] != 0 && supervise[i]) {
      time_Adiff( &diff, &np->ProcTimeStamp[i], &current_time);

      if ( time_Dcomp( &diff, 0) < 0) {
	if ( errh_Severity( np->ProcStatus[i]) < errh_Severity(PWR__PTIMEOUT))
	  np->ProcStatus[i] = PWR__PTIMEOUT;
      }
      else if ( np->ProcStatus[i] == PWR__PTIMEOUT) {
	np->ProcStatus[i] = (i < errh_cAnix_SrvSize) ? PWR__SRUN : PWR__ARUN;
      }
    }

    severity = errh_Severity( np->ProcStatus[i]);
    if ( np->ProcStatus[i] != 0 && EVEN(np->ProcStatus[i])) {
      if ( severity >= system_severity) {
	new_idx = i;
	system_severity = severity;
      }
    }

  }
  if ( new_idx != -1)
    np->SystemStatus = np->ProcStatus[new_idx];
  else if ( EVEN(np->SystemStatus))
    np->SystemStatus = PWR__RUNNING;
}
Ejemplo n.º 8
0
static pwr_sClass_IOHandler *
init (qcom_sQid *qid, lst_sEntry **csup_lh, pwr_sNode **nodep)
{
  pwr_tStatus sts = 1;
  pwr_sClass_IOHandler *ihp;
  qcom_sQattr qAttr;
  qcom_sQid qini;
  pwr_tOid oid;
  pwr_tOid node_oid;

  errh_Init("pwr_io", errh_eAnix_io);

#if defined(OS_ELN)
  /* Event to kill dioc */
  ker$create_event(&sts, &io_comm_terminate, EVENT$CLEARED);
#endif

  if (!qcom_Init(&sts, 0, "pwr_io")) {
    errh_Fatal("qcom_Init, %m", sts);
    exit(sts);
  } 

  qAttr.type = qcom_eQtype_private;
  qAttr.quota = 100;
  if (!qcom_CreateQ(&sts, qid, &qAttr, "events")) {
    errh_Fatal("qcom_CreateQ, %m", sts);
    exit(sts);
  } 

  qini = qcom_cQini;
  if (!qcom_Bind(&sts, qid, &qini)) {
    errh_Fatal("qcom_Bind(Qini), %m", sts);
    exit(-1);
  }

  sts = gdh_Init("pwr_io");
  if (EVEN(sts)) {
    errh_Fatal("rt_io_comm aborted\n%m", sts);
    exit(sts);
  }

  sts = io_get_iohandler_object(&ihp, &oid);
  if (EVEN(sts)) {
    errh_Fatal("rt_io_comm aborted, no IoHandler object found\n%m", sts);
    exit(sts);
  }

  sts = gdh_GetNodeObject( 0, &node_oid);
  if (EVEN(sts)) {
    errh_Fatal("rt_io_comm aborted, no node object found\n%m", sts);
    exit(sts);
  }

  sts = gdh_ObjidToPointer( node_oid, (void **)nodep);
  if (EVEN(sts)) {
    errh_Fatal("rt_io_comm aborted, no node object found\n%m", sts);
    exit(sts);
  }

  aproc_RegisterObject( oid);

  *csup_lh = csup_Init(&sts, oid, ihp->CycleTimeBus);

  return ihp;
}