Esempio 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;
      }
    }
  }
}
Esempio n. 2
0
void rt_sysmon::scan()
{
  pwr_tStatus osts, sts;
  errh_eSeverity severity, oseverity;

  aproc_TimeStamp( scantime(), 5);

  // Find most severe status
  sts = PWR__SRUN;
  severity = errh_Severity( sts);
  for ( int i = 0; i < (int) objects.size(); i++) {
    objects[i]->scan();
    osts = objects[i]->status();
    oseverity = errh_Severity( osts);
    if ( oseverity > severity) {
      sts = osts;
      severity = oseverity;
    }
  }
  errh_SetStatus( sts);
}
Esempio n. 3
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;
}