예제 #1
0
static pwr_tStatus tlog_qual_to_time( 	char 		*in_str, 
					pwr_tTime 	*time)
{
	pwr_tStatus	sts;
	char		*s;
	pwr_tDeltaTime	one_day_time;
	pwr_tTime	current_time;
	char			str[64];
	char			timstr[64];


	if ( !strcmp( in_str, "") ||
	     !strncmp( in_str, "TODAY", strlen(in_str)))
	{
	  time_GetTime( &current_time);
	  time_AtoAscii( &current_time, time_eFormat_DateAndTime,
			timstr, sizeof(timstr));
	  timstr[12] = 0;
	  strcat( timstr, " 00:00:00.00");
	  sts = time_AsciiToA( timstr, time);
	}
	else if ( !strncmp( in_str, "YESTERDAY", strlen(in_str)))
	{
	  time_GetTime( &current_time);
	  time_AtoAscii( &current_time, time_eFormat_DateAndTime,
			timstr, sizeof(timstr));
	  timstr[12] = 0;
	  strcat( timstr, " 00:00:00.00");
	  sts = time_AsciiToA( timstr, &current_time);
	  strcpy( timstr, "1 00:00:00");
	  sts = time_AsciiToD( timstr, &one_day_time);
	  time_Dneg( &one_day_time, &one_day_time);
	  time_Aadd( time, &current_time, &one_day_time);
	}
	else
	{
	  strcpy( str, in_str);
	  if ( s = strchr( str, '-'))
	  {
	    /* Date is supplied, replace ':' to space */
	    if ( s = strchr( str, ':'))
	      *s = ' ';
	    strcpy( timstr, str);
	  }
	  else
	  {
	    /* No date is supplied, add current date as default */
	    time_GetTime( &current_time);
	    time_AtoAscii( &current_time, time_eFormat_DateAndTime,
			timstr, sizeof(timstr));
	    timstr[12] = 0;
 	    strcat( timstr, " ");
 	    strcat( timstr, str);
	  }
	  sts = time_AsciiToA( timstr, time);
	  if (EVEN(sts)) return sts;
	}
	return TLOG__SUCCESS;
}
예제 #2
0
파일: rt_qos.c 프로젝트: Strongc/proview
pwr_tBoolean
qos_WaitQue (
  pwr_tStatus		*status,
  qdb_sQue		*qp,
  int			tmo
)
{
  pwr_tDeltaTime	dtime;
  pwr_tTime             atime;
  struct timespec       atime_ts;
  int			ok;
  pwr_tBoolean		signal = FALSE;
  pwr_dStatus		(sts, status, QCOM__SUCCESS);

  qdb_AssumeLocked;

  if (tmo == qcom_cTmoNone)
    return FALSE;

  pthread_mutex_lock(&qp->lock.mutex);

  qp->lock.waiting = TRUE;
  qp->lock.pid     = 0;

  qdb_Unlock;

  if (tmo != qcom_cTmoEternal) {
    time_GetTime(&atime);
    time_MsToD(&dtime, tmo);
    time_Aadd(&atime, &atime, &dtime);
    atime_ts.tv_sec = atime.tv_sec;
    atime_ts.tv_nsec = atime.tv_nsec;

    ok = pthread_cond_timedwait(&qp->lock.cond, &qp->lock.mutex, &atime_ts);
  } else {
    ok = pthread_cond_wait(&qp->lock.cond, &qp->lock.mutex);
  }
      
  pthread_mutex_unlock(&qp->lock.mutex);
  
  qdb_Lock;

  if ((qp->lock.waiting) || (ok == ETIMEDOUT)) {
    *sts = QCOM__TMO;
    qp->lock.waiting = FALSE;
  } else {
    signal = TRUE;
  }

  return signal;
}
예제 #3
0
파일: rt_subcm.c 프로젝트: Strongc/proview
void
subcm_CheckTimeout ()
{
  pool_sQlink		*cl;
  sub_sClient		*cp;
  pwr_tTime		curtim;
  pwr_tTime		restim;
  pwr_tDeltaTime	tmotim;
  pwr_tInt32		n;
  pwr_tInt32		i;

  gdb_AssumeLocked;

  gdbroot->db->tmocnt++;  /* Statistics */

  time_GetTime( &curtim);

  /* Calculate # of remote object clients to process this time */

  n = gdbroot->db->subt_lc;
  if (n == 0) n = MIN(1, gdbroot->db->subt_lc);

  for (i=0; i<n; i++) {

    /* Temporarily remove the first entry from the queue for processing.  */

    cl = pool_QremoveSucc(NULL, gdbroot->pool, &gdbroot->db->subt_lh);
    cp = pool_Qitem(cl, sub_sClient, subt_ll);

    /* Find out if the client has timed out */

    if (!cp->old) {
      /* cp->tmo in 10ths of seconds */
      tmotim.tv_sec = cp->tmo / 10;
      tmotim.tv_nsec = (cp->tmo - tmotim.tv_sec * 10) * 100000000;
      time_Aadd(&restim, &cp->lastupdate, &tmotim);       

      /* curtim >= tmotim + lastupdate */
      if (time_Acomp(&curtim, &restim) >= 0) 
	subc_SetOld(cp);
    } /* If it was old already */

    /* Reinsert the entry last in the queue.  */
    
    pool_QinsertPred(NULL, gdbroot->pool, cl, &gdbroot->db->subt_lh);
  }
}
예제 #4
0
void sev_valuecache_double::write( int index) 
{
  int ii = idx(index);
  double wval, wtime;

  if ( m_type == sev_eCvType_Mean) {
    if ( fabs(m_last_k) < 1) {
      m_wval.val = m_wval.val + m_last_k * (m_val[ii].time - m_wval.time);
      m_wval.time = m_val[ii].time;
    }
    else {
      m_wval.time = m_wval.time + (m_val[ii].val - m_wval.val) / m_last_k;
      m_wval.val = m_val[ii].val;
    }
    wval = m_wval.val;
    wtime = m_wval.time;    
  }
  else {
    wval = m_val[ii].val;
    wtime = m_val[ii].time;
    m_wval = m_val[ii];
  }

  if ( index == 0) {
    m_last = m_first = 0;
    m_length = 0;
  }
  else {
    m_first = ii + 1;
    if ( m_first >= m_size)
      m_first -= m_size;
    m_length = m_last - m_first + 1;
    if ( m_length < 0)
      m_length += m_size;
  }
  if ( m_write_cb) {
    pwr_tTime time;
    time_Aadd( &time, &m_start_time, time_Float64ToD( 0, wtime));
    (m_write_cb)( m_userdata, m_useridx, &wval, &time);
  }
}
예제 #5
0
static void
scan_nodes ()
{
  LstLink(sNode) *nl;
  pwr_tStatus sts;
  pwr_tBoolean Old;
  pwr_tTime LastUpdate, Timeout, CurrentTime;
  pwr_tDeltaTime Delta;
  pwr_tBoolean LinkUp;

  time_GetTime(&CurrentTime);

  for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) {
    sNode *np = LstObj(nl);
    pwr_sClass_NodeLinkSup  *o = np->o;
    LinkUp = 0;
    sts = gdh_GetSubscriptionOldness (o->SubId, &Old, &LastUpdate, NULL);
    if (ODD(sts)) {
      /* IF (CurrentTime < LastUpdate + TimeoutTime) THEN LinkUp */
      Delta.tv_sec = o->TimeoutTime;
      Delta.tv_nsec = 0;
      time_Aadd(&Timeout, &LastUpdate, &Delta);
      if (time_Acomp(&CurrentTime, &Timeout) < 0) 
	LinkUp = 1;
      o->SystemStatus = *np->subvalue;
    }

    if (o->LinkUp && !LinkUp) {
      o->LinkUp = 0;
      o->DownTime = CurrentTime;
      o->SystemStatus = PWR__NETTIMEOUT;
    } else if (!o->LinkUp && LinkUp) {
      o->LinkUp = 1;
      o->UpTime = CurrentTime;
      o->UpCount++;
    }

    detect(o, 1, np);
  }
}
예제 #6
0
int main (int argc, char **argv)
{
  pwr_tStatus	    sts;
  pwr_tObjid	    ObjId;
  pwr_sClass_DsTrendConf *TConfP;
  pwr_tBoolean    InitOK;
  pwr_tTime		CurrentTime, LastScan, NextScan;
  pwr_tDeltaTime	ScanDeltaTime, WaitTime;
  qcom_sQid qini;
  qcom_sQattr qAttr;
  int tmo;
  char mp[2000];
  qcom_sQid qid = qcom_cNQid;
  qcom_sGet get;
  int swap = 0;
  trend_tCtx ctx;

  errh_Init("pwr_trend", errh_eAnix_trend);
  errh_SetStatus( PWR__SRVSTARTUP);

  sts = gdh_Init("ds_trend");
  If_Error_Log_Exit(sts, "gdh_Init");

  if (!qcom_Init(&sts, 0, "pwr_trend")) {
    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);
  }

  ctx = (trend_tCtx) calloc( 1, sizeof(trend_sCtx));

  /* Wait until local nethandler has started */
  while(EVEN(gdh_NethandlerRunning()))
    sleep(1);

  /* Fetch ScanTime */
  sts = gdh_GetClassList(pwr_cClass_DsTrendConf, &ObjId);
  if (EVEN(sts)) {
    errh_Info("Couldn't get the DsTrendConf object. Used ScanTime = 1 s");
    ctx->scantime = 1;
    ctx->scantime_tc = 1.0;
  } 
  else {
    gdh_ObjidToPointer(ObjId, (pwr_tAddress *)&TConfP);
    ctx->scantime = TConfP->ScanTime;
    if ( ctx->scantime > 3600)
      ctx->scantime = 3600;
    else if ( ctx->scantime < 1)
      ctx->scantime = 1;

    ctx->scantime_tc = TConfP->ScanTime;
    if ( ctx->scantime_tc > 3600)
      ctx->scantime_tc = 3600;
  }
  ctx->dstrend_multiple = (int) (ctx->scantime / ctx->scantime_tc + 0.5);

  aproc_RegisterObject( ObjId);

  InitOK = FALSE;
  sts = InitTrendList( ctx);
  if ( EVEN(sts)) { 
    /* This should be removed when we can wait for init messages. */
    errh_SetStatus(0);
    errh_Info("No DsTrend objects configured");
    exit(0);
  }

  /* If even sts, just wait for init message */

  time_GetTimeMonotonic(&LastScan);
  time_FloatToD( &ScanDeltaTime, ctx->scantime_tc);

  aproc_TimeStamp( ctx->scantime, 5.0);
  errh_SetStatus( PWR__SRUN);

  for (;;) {

    time_GetTimeMonotonic(&CurrentTime);
    time_Aadd(&NextScan, &LastScan, &ScanDeltaTime);
    if (time_Acomp(&CurrentTime, &NextScan) < 0) { 
      time_Adiff(&WaitTime, &NextScan, &CurrentTime);
      tmo = 1000 * time_DToFloat( 0, &WaitTime);

      get.maxSize = sizeof(mp);
      get.data = mp;
      qcom_Get( &sts, &qid, &get, tmo);
      if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
	if ( !swap)
	  StoreData( ctx);
      } 
      else {
	ini_mEvent  new_event;
	qcom_sEvent *ep = (qcom_sEvent*) get.data;

	new_event.m  = ep->mask;
	if (new_event.b.oldPlcStop && !swap) {
	  swap = 1;
	  errh_SetStatus( PWR__SRVRESTART);
	  CloseTrendList( ctx);
	} 
	else if (new_event.b.swapDone && swap) {
	  swap = 0;
	  sts = InitTrendList( ctx);
	  errh_SetStatus( PWR__SRUN);
	  errh_Info("Warm restart completed");
	}
	else if (new_event.b.terminate) {
	  exit(0);
	}
      }
    }
    else if ( !swap)
      StoreData( ctx);

    LastScan = NextScan;

    aproc_TimeStamp( ctx->scantime, 5.0);
  }

  return 1;
}
예제 #7
0
int main (int argc, char **argv)
{
  pwr_tStatus sts = 1;
  io_tCtx io_ctx;
  io_tCtx io_ctx_swap;
  pwr_sClass_IOHandler *ihp;
  int swap_io;
  int close_io;
  int init_io;
  qcom_sQid qid = qcom_cNQid;
  int tmo;
  char mp[2000];
  qcom_sGet get;
  pwr_tTime now;
  pwr_tTime next;
  pwr_tTime after;
  pwr_tDeltaTime cycle;
  lst_sEntry *csup_lh;
  int delay_action = 0;
  pwr_sNode *nodep;
  pwr_tBoolean old_emergency_break = 0;

  if ( argc > 1) {
    if ( strcmp( argv[1], "-m") == 0) {
      io_methods_print();
      exit(0);
    }
    if ( strcmp( argv[1], "-h") == 0) {
      usage();
      exit(0);
    }
  }

  ihp = init(&qid, &csup_lh, &nodep);

  plc_UtlWaitForPlc();

  /* Prepare the swap context */
  sts = io_init_swap(io_mProcess_IoComm, pwr_cNObjid, &io_ctx_swap, 1, ihp->CycleTimeBus);

  for (close_io = swap_io = 0, init_io = 1;;) {

    if (init_io) {
      double f;
      
      sts = io_init(io_mProcess_IoComm, pwr_cNObjid, &io_ctx, 1, ihp->CycleTimeBus);
      if ( ODD(sts)) 
	errh_SetStatus( PWR__SRUN);
#if defined(OS_ELN)
      ker$clear_event( &sts, io_comm_terminate);
      io_dioc_init();
      io_dioc_start();
#endif
      init_io = 0;
      tmo = ihp->CycleTimeBus * 1000.;
      f = floor(ihp->CycleTimeBus);
      cycle.tv_sec = f;
      cycle.tv_nsec = (ihp->CycleTimeBus - f) * 1.0e9;
      cycle.tv_nsec++;
      time_GetTimeMonotonic(&next);
      time_Aadd(NULL, &next, &cycle);
    }

    get.maxSize = sizeof(mp);
    get.data = mp;
    qcom_Get(&sts,&qid, &get, tmo);
    if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {

      if ( nodep->EmergBreakTrue && !old_emergency_break)
        sts = io_swap(io_ctx_swap, io_eEvent_IoCommEmergencyBreak);

      sts = io_read(io_ctx);
      if (EVEN(sts)) {
	ihp->IOReadWriteFlag = FALSE;
	errh_Error("IO read, %m", sts);
      }
      sts = io_write(io_ctx);
      if (EVEN(sts)) {
	ihp->IOReadWriteFlag = FALSE;
	errh_Error("IO write, %m", sts);
      }

      if ( nodep->EmergBreakTrue && !old_emergency_break)
        sts = io_swap(io_ctx, io_eEvent_EmergencyBreak);
      old_emergency_break = nodep->EmergBreakTrue;

      if (swap_io) 
      {
        sts = io_swap(io_ctx_swap, io_eEvent_IoCommSwap);
      }
      io_ScanSupLst( io_ctx->SupCtx);

      time_GetTime(&now);
      time_GetTimeMonotonic(&after);
      next = after;
      time_Aadd(NULL, &next, &cycle);
      delay_action = csup_Exec(&sts, csup_lh, (pwr_tDeltaTime *) &next,
                            (pwr_tDeltaTime *) &after, &now);
      if (delay_action == 2)
	ihp->IOReadWriteFlag = FALSE;

      aproc_TimeStamp(ihp->CycleTimeBus, 5);
    } else {
      ini_mEvent  new_event;
      qcom_sEvent *ep = (qcom_sEvent*) get.data;

      new_event.m  = ep->mask;
      if (new_event.b.oldPlcStop && !swap_io) {
        swap_io = 1;
	close_io = 1;
	errh_SetStatus(PWR__SRVRESTART);
      } else if (new_event.b.swapDone && swap_io) {
        swap_io = 0;
	init_io = 1;
      } else if (new_event.b.terminate) {
        exit(0);
      }
      if (close_io) {    
	io_close(io_ctx);
#if defined(OS_ELN)
	ker$signal( &sts, io_comm_terminate);
#endif
	close_io = 0;
      }
    }
  }
}