Beispiel #1
0
static pwr_sClass_IOHandler *
init (qcom_sQid *qid, lst_sEntry **csup_lh)
{
  pwr_tStatus sts = 1;
  pwr_sClass_IOHandler *ihp;
  qcom_sQattr qAttr;
  qcom_sQid qini;
  pwr_tObjid 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);
  }

  aproc_RegisterObject( oid);

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

  return ihp;
}
Beispiel #2
0
void rt_sysmon::open()
{
  pwr_tStatus sts;
  pwr_sAttrRef aref;
  pwr_tObjid oid;

  // Open server configuration object SysMonConfig
  sts = gdh_GetClassList( pwr_cClass_SysMonConfig, &oid);
  if ( ODD(sts)) {
    aref = cdh_ObjidToAref( oid);
    sts = gdh_DLRefObjectInfoAttrref( &aref, (void **)&conf, &conf_dlid); 
    if ( EVEN(sts)) throw co_error(sts);
  }

  if ( ODD(sts)) {
    scan_time = 1.0 / conf->ScanTime;
  }
  else {
    scan_time = 1;
    errh_Info( "No sysmon configuration, using base frequency 1 Hz");
    oid = pwr_cNObjid;
    conf = 0;
  }

  aproc_RegisterObject( oid);

  // Open DiskSup objects
  for ( sts = gdh_GetClassListAttrRef( pwr_cClass_DiskSup, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef( pwr_cClass_DiskSup, &aref, &aref)) {
    disksup_object *o = new disksup_object( &aref);
    objects.push_back( o);
    try {
      o->open( scan_time);
      if ( conf)
	conf->DiskSupObjects[sysmon_cnt] = aref.Objid;
      sysmon_cnt++;
    }    
    catch ( co_error& e) {
      delete o;
      objects.pop_back();
      errh_Error( "DiskSup configuration error: &s", (char *)e.what().c_str());
    }
  }
}
Beispiel #3
0
void rt_fast::open()
{
  pwr_tStatus sts;
  pwr_sAttrRef aref;
  pwr_tObjid oid;
  pwr_sClass_DsFastConf *conf_p;

  // Open server configuration object DsFastConf
  sts = gdh_GetClassList( pwr_cClass_DsFastConf, &oid);
  if ( ODD(sts)) {
    sts = gdh_ObjidToPointer( oid, (void **)&conf_p);
    if ( EVEN(sts)) throw co_error( sts);

    scan_time = 1.0 / conf_p->BaseFrequency;
  }
  else {
    scan_time = 0.1;
    errh_Info( "No fast configuration, using base frequency 10 Hz");
    oid = pwr_cNObjid;
  }

  aproc_RegisterObject( oid);

  // Open FastCurve object
  for ( sts = gdh_GetClassListAttrRef( pwr_cClass_DsFastCurve, &aref);
	ODD(sts);
	sts = gdh_GetNextAttrRef( pwr_cClass_DsFastCurve, &aref, &aref)) {
    fastobject *o = new fastobject( &aref);
    objects.push_back( o);
    try {
      o->open( scan_time);
      fast_cnt++;
    }    
    catch ( co_error& e) {
      delete o;
      objects.pop_back();
      errh_Error( "DsFastCurve configuration error: &s", (char *)e.what().c_str());
    }
  }
}
Beispiel #4
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;
}
Beispiel #5
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;
}
Beispiel #6
0
void rt_post::open()
{
  pwr_tStatus sts;
  pwr_tObjid oid;
  pwr_tFileName filename;

  // Open server configuration object PostConfig
  sts = gdh_GetClassList( pwr_cClass_PostConfig, &oid);
  if ( ODD(sts)) {
    sts = gdh_ObjidToPointer( oid, (void **)&conf);
    if ( EVEN(sts)) throw co_error( sts);

    aproc_RegisterObject( oid);
  }
  else {
    errh_Info( "No Post configuration");
    errh_SetStatus( 0);
    exit(0);
  }

  conf->Status = PWR__SRVSTARTUP;

  // Connect to mh
  mh_UtilWaitForMh();

  sts = mh_OutunitConnect(
		oid,
		mh_eOutunitType_Post,
		0,
		mh_ack_bc,
		mh_alarm_bc,
		mh_block_bc,
		mh_cancel_bc,
		mh_clear_alarmlist_bc,
		mh_clear_blocklist_bc,
		mh_info_bc,
		mh_return_bc,
		NULL
		);
  if ( EVEN(sts)) {
    errh_Error( "Post terminated: %m", sts);
    conf->Status = sts;
    exit(0);
  }

  // Load user database
	
  sts = gdh_GetObjectInfo( "pwrNode-System.SystemGroup", &systemgroup, 
			   sizeof(systemgroup));
  if ( EVEN(sts)) {
    errh_Error( "Post terminated: %m", sts);
    conf->Status = sts;
    exit(0);
  }

  udb = new GeUser();
  sts = dcli_get_defaultfilename( user_cFilename, filename, "");
  udb->load( filename);

  conf->Status = PWR__SRUN;

}
Beispiel #7
0
int main(int argc, char** argv)
{
  pwr_tStatus sts;
  io_tCtx io_ctx;
  float ctime = 1;

  pwr_sClass_EplHandler* plhp;
  pwr_tOid oid;
  int tmo;
  char mp[2000];
  qcom_sGet get;
  qcom_sQattr qAttr;
  qcom_sQid qini;
  qcom_sQid qid = qcom_cNQid;

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

  // Make connection to error handler
  errh_Init("pwr_powerlink", errh_eAnix_powerlink);
  errh_SetStatus(PWR__SRVSTARTUP);

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

  // Make connection to realtime database
  sts = gdh_Init("rt_powerlink");
  if (EVEN(sts)) {
    errh_Fatal("rt_powerlink aborted, gdh_Init failed\n%m", sts);
    errh_SetStatus(PWR__SRVTERM);
    exit(sts);
  }

  sts = gdh_GetClassList(pwr_cClass_Epl_CNServer, &oid);
  if (ODD(sts)) {
    system("rt_powerlink_cn &");
    exit(0);
  }

  // Get Powerlink handler object
  sts = io_get_plhandler_object(&plhp, &oid);
  if (EVEN(sts)) {
    errh_SetStatus(0);
    errh_Info("rt_powerlink terminated, no EplHandler object found");
    exit(sts);
  }

  // Create context and call init functions of all agent,
  // rack and cardobjects
  sts = io_init(io_mProcess_Powerlink, pwr_cNObjid, &io_ctx, 1, ctime);
  if (EVEN(sts)) {
    errh_SetStatus(PWR__SRVTERM);
    errh_Fatal("rt_powerlink aborted, io_init() failed\n%m", sts);
    exit(sts);
  }

  tmo = (plhp->CycleTime) * 1000;

  aproc_TimeStamp(plhp->CycleTime, 5.0);
  errh_SetStatus(PWR__SRUN);
  aproc_RegisterObject(oid);

  // Call IoAgentRead() IoAgentWrite() IoCardRead() IoCardWrite()
  // IoModuleRead() IoModuleWrite() forever
  for (;;) {
    get.maxSize = sizeof(mp);
    get.data = mp;
    qcom_Get(&sts, &qid, &get, tmo);
    if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
      sts = io_read(io_ctx);
      sts = io_write(io_ctx);

      aproc_TimeStamp(plhp->CycleTime, 5.0);

    } else {
      ini_mEvent new_event;
      qcom_sEvent* ep = (qcom_sEvent*)get.data;

      new_event.m = ep->mask;
      if (new_event.b.oldPlcStop) {
        // TODO
      } else if (new_event.b.swapDone) {
        // TODO
      } else if (new_event.b.terminate) {
        // io_close(io_ctx);
        exit(0);
      }
    }
  }
}