Esempio n. 1
0
//
// Set Scan filter
//
static pwr_tStatus SetScanFilter( xmenu_sMenuCall *ip)
{
    pwr_tObjid child;
    int sts;
    pwr_tBoolean local;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;
    pwr_sClass_windowplc *window_p;
    pwr_tClassId classid;
    int enable;

    if ( !ip->Priv & pwr_mPrv_System)
        return XNAV__INSENSITIVE;

    if ( strcmp( "Enable", ip->ItemList[ip->ChosenItem].FilterArguments[0]) == 0)
        enable = 1;
    else if ( strcmp( "Disable", ip->ItemList[ip->ChosenItem].FilterArguments[0]) == 0)
        enable = 0;
    else
        return XNAV__SUCCESS;

    // Only on local objects
    sts = gdh_GetObjectLocation( ip->Pointed.Objid, &local);
    if ( EVEN(sts) || !local)
        return XNAV__INSENSITIVE;

    // Only if simulate
    sts = gdh_GetClassList( pwr_cClass_IOHandler, &io_handler);
    if ( EVEN(sts)) return sts;

    sts = gdh_ObjidToPointer( io_handler, (void **) &io_handler_p);
    if ( EVEN(sts)) return sts;

    if ( !io_handler_p->IOSimulFlag)
        return XNAV__INSENSITIVE;

    sts = gdh_GetChild( ip->Pointed.Objid, &child);
    while( ODD(sts)) {
        sts = gdh_GetObjectClass( child, &classid);
        if ( EVEN(sts)) return sts;

        if ( classid == pwr_cClass_windowplc) {
            sts = gdh_ObjidToPointer( child, (void **) &window_p);
            if ( EVEN(sts)) return sts;

            if ( (enable && window_p->ScanOff) ||
                    (!enable && !window_p->ScanOff))
                return XNAV__SUCCESS;
            else
                return XNAV__INSENSITIVE;
        }
    }
    return XNAV__INVISIBLE;
}
Esempio n. 2
0
//
// Set scan
//
static pwr_tStatus SetScan( xmenu_sMenuCall *ip)
{
    pwr_tObjid child;
    int sts;
    pwr_tBoolean local;
    pwr_tObjid io_handler;
    pwr_sClass_IOHandler *io_handler_p;
    pwr_tBoolean value = 0;
    pwr_tOName name;
    pwr_tClassId classid;

    if ( strcmp( "Enable", ip->ItemList[ip->ChosenItem].MethodArguments[0]) == 0)
        value = 0;
    else if ( strcmp( "Disable", ip->ItemList[ip->ChosenItem].MethodArguments[0]) == 0)
        value = 1;
    else
        return XNAV__SUCCESS;

    // Only on local objects
    sts = gdh_GetObjectLocation( ip->Pointed.Objid, &local);
    if ( EVEN(sts) || !local)
        return 0;

    // Only if simulate
    sts = gdh_GetClassList( pwr_cClass_IOHandler, &io_handler);
    if ( EVEN(sts)) return sts;

    sts = gdh_ObjidToPointer( io_handler, (void **) &io_handler_p);
    if ( EVEN(sts)) return sts;

    if ( !io_handler_p->IOSimulFlag)
        return 0;

    sts = gdh_GetChild( ip->Pointed.Objid, &child);
    while( ODD(sts)) {
        sts = gdh_GetObjectClass( child, &classid);
        if ( EVEN(sts)) return sts;

        if ( classid == pwr_cClass_windowplc) {
            sts = gdh_ObjidToName( child, name, sizeof(name),
                                   cdh_mName_volumeStrict);
            if ( EVEN(sts)) return sts;
            strcat( name, ".ScanOff");
            sts = gdh_SetObjectInfo( name, (void *) &value, sizeof( value));
            if ( EVEN(sts)) return sts;

            return XNAV__SUCCESS;
        }
    }
    return 0;
}
Esempio n. 3
0
RtTraceMotif::RtTraceMotif( void *tr_parent_ctx, Widget tr_parent_wid, pwr_tObjid tr_objid,
			    pwr_tStatus *status) :
  RtTrace( tr_parent_ctx, tr_objid, status), parent_wid(tr_parent_wid)
{
  // FlowWidget	fwidget;
  char		uid_filename[120] = {"xtt_trace.uid"};
  char		*uid_filename_p = uid_filename;
  Arg 		args[20];
  unsigned long sts;
  pwr_tOName   	name;
  int		i;
  pwr_tObjid	window_objid;
  pwr_tClassId	cid;
  char   	title[220];
  pwr_tOName   	hostname;
  pwr_tOName   	plcconnect;
  MrmHierarchy s_DRMh;
  MrmType dclass;
  Widget	trace_widget;
  static MrmRegisterArg	reglist[] = {
        {(char*) "tra_ctx", 0 },
	{(char*) "tra_activate_close",(caddr_t)activate_close },
	{(char*) "tra_activate_print",(caddr_t)activate_print },
	{(char*) "tra_activate_printselect",(caddr_t)activate_printselect },
	{(char*) "tra_activate_savetrace",(caddr_t)activate_savetrace },
	{(char*) "tra_activate_restoretrace",(caddr_t)activate_restoretrace },
	{(char*) "tra_activate_cleartrace",(caddr_t)activate_cleartrace },
	{(char*) "tra_activate_trace",(caddr_t)activate_trace },
	{(char*) "tra_activate_display_object",(caddr_t)activate_display_object },
	{(char*) "tra_activate_open_object",(caddr_t)activate_open_object },
	{(char*) "tra_activate_show_cross",(caddr_t)activate_show_cross },
	{(char*) "tra_activate_open_classgraph",(caddr_t)activate_open_classgraph },
	{(char*) "tra_activate_collect_insert",(caddr_t)activate_collect_insert },
	{(char*) "tra_activate_view",(caddr_t)activate_view },
	{(char*) "tra_activate_simulate",(caddr_t)activate_simulate },
	{(char*) "tra_activate_zoomin",(caddr_t)activate_zoomin },
	{(char*) "tra_activate_zoomout",(caddr_t)activate_zoomout },
	{(char*) "tra_activate_zoomreset",(caddr_t)activate_zoomreset },
	{(char*) "tra_activate_scantime1",(caddr_t)activate_scantime1 },
	{(char*) "tra_activate_scantime2",(caddr_t)activate_scantime2 },
	{(char*) "tra_activate_scantime3",(caddr_t)activate_scantime3 },
	{(char*) "tra_activate_scantime4",(caddr_t)activate_scantime4 },
	{(char*) "tra_activate_scantime5",(caddr_t)activate_scantime5 },
	{(char*) "tra_activate_help",(caddr_t)activate_help },
	{(char*) "tra_activate_helpplc",(caddr_t)activate_helpplc },
	{(char*) "tra_create_form",(caddr_t)create_form },
	{(char*) "tra_create_menu",(caddr_t)create_menu }
	};

  static int	reglist_num = (sizeof reglist / sizeof reglist[0]);

  lng_get_uid( uid_filename, uid_filename);

  sts = gdh_ObjidToName( tr_objid, name, sizeof(name), cdh_mNName); 
  if (EVEN(sts)) {
    *status = sts;
    return;
  }
  strcpy( title, "Trace ");
  strcat( title, name);

  /* Find plcwindow */
  sts = gdh_GetObjectClass( tr_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep ))
  {

    sts = gdh_GetChild( tr_objid, &window_objid);
    if ( EVEN(sts)) {
      *status = sts;
      return;
    }
  }
  else
    window_objid = tr_objid; 

  sts = gdh_GetObjectClass( window_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep )) {
    *status = 0;
    return;
  }

  sts = get_filename( window_objid, filename, &m_has_host, hostname, 
		      plcconnect);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  /* Create object context */
  objid = window_objid;
  if ( m_has_host) {
    strcpy( m_hostname, hostname);
    strcpy( m_plcconnect, plcconnect);
  }
  reglist[0].value = (caddr_t) this;
 
  toplevel = XtCreatePopupShell( name, 
		topLevelShellWidgetClass, parent_wid, args, 0);

  /* Save the context structure in the widget */
  XtSetArg (args[0], XmNuserData, (XtPointer) this);

  sts = MrmOpenHierarchy( 1, &uid_filename_p, NULL, &s_DRMh);
  if (sts != MrmSUCCESS) printf("can't open %s\n", uid_filename);

  MrmRegisterNames(reglist, reglist_num);

  sts = MrmFetchWidgetOverride( s_DRMh, (char*) "trace_window", toplevel,
			title, args, 1, &trace_widget, &dclass);
  if (sts != MrmSUCCESS)  printf("can't fetch %s\n", name);

  MrmCloseHierarchy(s_DRMh);


  i = 0;
  XtSetArg(args[i],XmNwidth,800);i++;
  XtSetArg(args[i],XmNheight,600);i++;
  XtSetValues( toplevel ,args,i);
    
  XtManageChild( trace_widget);

  i = 0;
/*
  XtSetArg(args[i],XmNwidth,790);i++;
  XtSetArg(args[i],XmNheight,560);i++;
*/
  XtSetArg( args[i], XmNtopAttachment, XmATTACH_WIDGET);i++;
  XtSetArg( args[i], XmNtopWidget, menu);i++;
  XtSetArg( args[i], XmNrightAttachment, XmATTACH_FORM);i++;
  XtSetArg( args[i], XmNleftAttachment, XmATTACH_FORM);i++;
  XtSetArg( args[i], XmNbottomAttachment, XmATTACH_FORM);i++;
  flow_widget = FlowCreate( form, (char*) "Flow window", args, i, 
			    init_flow, (void *)this);

  XtManageChild( (Widget) flow_widget);
/*
  XtRealizeWidget(toplevel);
*/
  XtPopup( toplevel, XtGrabNone);

  // fwidget = (FlowWidget) flow_widget;
  // flow_ctx = (flow_tCtx)fwidget->flow.flow_ctx;
  // flow_SetCtxUserData( flow_ctx, this);

  /* Create navigator popup */

  i = 0;
  XtSetArg(args[i],XmNallowShellResize, TRUE); i++;
  XtSetArg(args[i],XmNallowResize, TRUE); i++;
  XtSetArg(args[i],XmNwidth,200);i++;
  XtSetArg(args[i],XmNheight,200);i++;
  XtSetArg(args[i],XmNx,500);i++;
  XtSetArg(args[i],XmNy,500);i++;

  nav_shell = XmCreateDialogShell( flow_widget, (char*) "Navigator",
        args, i);
  XtManageChild( nav_shell);

  i = 0;
  XtSetArg(args[i],XmNwidth,200);i++;
  XtSetArg(args[i],XmNheight,200);i++;
  nav_widget = FlowCreateNav( nav_shell, (char*) "navigator",
        args, i, flow_widget);
  XtManageChild( nav_widget);
  XtRealizeWidget( nav_shell);

  // Connect the window manager close-button to exit
  flow_AddCloseVMProtocolCb( toplevel, 
	(XtCallbackProc)activate_close, this);

  wow = new CoWowMotif( toplevel);
  trace_timerid = wow->timer_new();

  viewsetup();
  flow_Open( flow_ctx, filename);
  trasetup();
  trace_start();

#if defined OS_LINUX
  {
    struct stat info;

    if ( stat( filename, &info) != -1)
      version = info.st_ctime;    
  }
#endif

}
Esempio n. 4
0
pwr_tStatus xtt_pb_dp_slave_create_ctx( pwr_tAttrRef aref, void *editor_ctx, 
					xtt_slave_sCtx **ctxp)
{
  pwr_tAName name;
  pwr_tString80 gsdfile;
  int sts;
  pwr_tFileName fname;
  pwr_tCid cid;
  pwr_tOid oid;
  int found;
  int mc_cnt;
  int module_cnt;
  pwr_tAttrRef aaref;

  sts = gdh_ObjidToName( aref.Objid, 
			name, sizeof(name), cdh_mName_volumeStrict);
  if ( EVEN(sts)) return sts;

  sts = gdh_ArefANameToAref( &aref, "GSDFile", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, gsdfile, sizeof(gsdfile));
  if ( EVEN(sts)) return sts;
  if ( strcmp( gsdfile, "") == 0) {
    return PB__GSDATTR;
  }

  xtt_slave_sCtx *ctx = (xtt_slave_sCtx *) calloc( 1, sizeof(xtt_slave_sCtx));
  ctx->aref = aref;

  // Count modules
  module_cnt = 0;
  for ( sts = gdh_GetChild( aref.Objid, &oid);
	ODD(sts);
	sts = gdh_GetNextSibling( oid, &oid)) {
    module_cnt++;
  }

  ctx->mc = (gsd_sModuleClass *) calloc( module_cnt + 2, sizeof(gsd_sModuleClass));
  mc_cnt = 0;
  ctx->editor_ctx = editor_ctx;
  
  ctx->mc[0].cid = pwr_cClass_Pb_Module;
  sts = gdh_ObjidToName( cdh_ClassIdToObjid(ctx->mc[0].cid),  
			 ctx->mc[0].name, sizeof(ctx->mc[0].name), cdh_mName_object);
  if ( EVEN(sts)) return sts;
  mc_cnt++;

  for ( sts = gdh_GetChild( aref.Objid, &oid);
	ODD(sts);
	sts = gdh_GetNextSibling( oid, &oid)) {
    sts = gdh_GetObjectClass( oid, &cid);
    if ( EVEN(sts)) return sts;

    found = 0;
    for ( int i = 0; i < mc_cnt; i++) {
      if ( ctx->mc[i].cid == cid) {
	found = 1;
	break;
      }
    }
    if ( found)
      continue;

    ctx->mc[mc_cnt].cid = cid;
    sts = gdh_ObjidToName( cdh_ClassIdToObjid(cid),
			   ctx->mc[mc_cnt].name, sizeof(ctx->mc[0].name), cdh_mName_object);
    if ( EVEN(sts)) return sts;
    mc_cnt++;
  }

  if ( strchr( gsdfile, '/') == 0) {
    strcpy( fname, "$pwrp_exe/");
    strcat( fname, gsdfile);
  }
  else
    strcpy( fname, gsdfile);
    
  ctx->gsd = new pb_gsd();
  sts = ctx->gsd->read( fname);
  if ( EVEN(sts))
    return sts;
    
  ctx->gsd->set_classes( ctx->mc);

  sts = xtt_pb_dp_slave_load_modules( ctx);
  if ( EVEN(sts)) return sts;

  *ctxp = ctx;
  return 1;
}
Esempio n. 5
0
static pwr_tStatus xtt_pb_dp_slave_load_modules( xtt_slave_sCtx *ctx)
{
  pwr_tOid oid;
  pwr_tCid cid;
  int found;
  pwr_tObjName name;
  pwr_tString40 module_name;
  int sts;
  pwr_tAttrRef maref, aaref;

  for ( sts = gdh_GetChild( ctx->aref.Objid, &oid);
	ODD(sts);
	sts = gdh_GetNextSibling( oid, &oid)) {

    // Check that this is a module
    sts = gdh_GetObjectClass( oid, &cid);
    if ( EVEN(sts)) return sts;

    found = 0;
    for ( int i = 0; ; i++) {
      if ( ctx->gsd->module_classlist[i].cid == 0)
	break;
      if ( ctx->gsd->module_classlist[i].cid == cid) {
	found = 1;
	break;
      }
    }
    if ( !found)
      // This is not a known module object
      continue;

    // Get name
    sts = gdh_ObjidToName( oid, name, sizeof(name), cdh_mName_object);
    if ( EVEN(sts)) return sts;

    maref = cdh_ObjidToAref( oid);

    // Get ModuleName attribute
    sts = gdh_ArefANameToAref( &maref, "ModuleName", &aaref);
    if ( EVEN(sts)) return sts;
      
    sts = gdh_GetObjectInfoAttrref( &aaref, module_name, sizeof(module_name));
    if ( EVEN(sts)) return sts;

    ctx->gsd->add_module_conf( cid, oid, name, module_name);
  }

  // Set address
  pwr_tUInt16 address;
  
  sts = gdh_ArefANameToAref( &ctx->aref, "SlaveAddress", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, &address, sizeof(address));
  if ( EVEN(sts)) return sts;

  ctx->gsd->address = address;

  // Set byte order
  pwr_tByteOrderingEnum byte_order;
  
  sts = gdh_ArefANameToAref( &ctx->aref, "ByteOrdering", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, &byte_order, sizeof(byte_order));
  if ( EVEN(sts)) return sts;

  ctx->gsd->byte_order = byte_order;

  // Set Ext_User_Prm_Data
  pwr_tUInt8 prm_user_data[256];
  pwr_tUInt16 prm_user_data_len;
  int len;
  
  sts = gdh_ArefANameToAref( &ctx->aref, "PrmUserData", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, prm_user_data, sizeof(prm_user_data));
  if ( EVEN(sts)) return sts;

  sts = gdh_ArefANameToAref( &ctx->aref, "PrmUserDataLen", &aaref);
  if ( EVEN(sts)) return sts;

  sts = gdh_GetObjectInfoAttrref( &aaref, &prm_user_data_len, sizeof(prm_user_data_len));
  if ( EVEN(sts)) return sts;

  len = prm_user_data_len;
  if ( len != 0) {
    sts = ctx->gsd->unpack_ext_user_prm_data( (char *)prm_user_data, len);
    if ( EVEN(sts)) return sts;
  }
  return 1;
}
Esempio n. 6
0
/*
* Name:    
*   io_ConnectToAnaSupLstSerial
*
*
* Function:
*   Initialize list of ASup object for serial connected analog in- och output 
*   signals.
* Description:
*   
*/
pwr_tStatus io_ConnectToAnaSupLstSerial (
    pwr_tClassId 	Class,
    pwr_tObjid		ObjId,
    pwr_tAddress	ObjP	/* Pointer to the object */
)
{
    pwr_tStatus	  Sts;
    pwr_sClass_ASup *ASupP;
    pwr_sClass_Ai *AiP;
    pwr_sClass_Ao *AoP;
    pwr_tFloat32  *Float32P;
    pwr_tObjid	  SupId;
    pwr_tClassId  ObjClass;
    sASupLstLink  *ASupLstP;
    sASupLstLink  *NextASupLstP, *NextP;

    switch (Class) {
      case pwr_cClass_Ai:
        AiP = (pwr_sClass_Ai *) ObjP;
        Float32P = gdh_TranslateRtdbPointer( (pwr_tUInt32)AiP->ActualValue ); 
	break;

      case pwr_cClass_Ao:
        AoP = (pwr_sClass_Ao *) ObjP;
        Float32P = gdh_TranslateRtdbPointer( (pwr_tUInt32)AoP->ActualValue ); 
	break;

      default:
	return ( IO__SUCCESS );
	break;
    }


    /* Get child with class ASup */
    Sts = gdh_GetChild ( ObjId, &SupId);
    while ( ODD(Sts)) {
       Sts = gdh_GetObjectClass ( SupId, &ObjClass);  
       if ( EVEN(Sts)) return (Sts);

       if ( ObjClass == pwr_cClass_ASup ) {
         Sts = gdh_ObjidToPointer ( SupId, (pwr_tAddress *)&ASupP); 
 	 if (EVEN(Sts)) return ( Sts );

         ASupLstP = (sASupLstLink *) calloc( 1, sizeof(sASupLstLink) );
         ASupLstP->SupP = ASupP;
         ASupLstP->ValueP = Float32P;

         if ( ASupAnaSerialLstP == NULL ) {
           ASupAnaSerialLstP = ASupLstP;
         }
         else {
           if ( ASupAnaSerialLstP->NextP == NULL ) {
             ASupAnaSerialLstP->NextP = ASupLstP;
           }             
           else {
	     NextP = ASupAnaSerialLstP->NextP;
	     while ( NextP != NULL ) {
	       NextASupLstP = NextP;
	       NextP = NextP->NextP;
	     } 
             NextASupLstP->NextP = ASupLstP;
           }
	 }
       }

       Sts = gdh_GetNextSibling ( SupId, &SupId);
    }		

    return IO__SUCCESS;
} /* END io_ConnectToAnaSupLstSerial */
Esempio n. 7
0
/*
* Name:    
*   io_ConnectToDigSupLstSerial
*
*
* Function:
*   Initialize list of DSup object for digitala in- och output signals.
* Description:
*   
*/
pwr_tStatus io_ConnectToDigSupLstSerial (
    pwr_tClassId 	Class,
    pwr_tObjid		ObjId,
    pwr_tAddress	ObjP	/* Pointer to the object */
)
{
    pwr_tStatus	  Sts;
    pwr_sClass_DSup *DSupP;
    pwr_sClass_Di *DiP;
    pwr_sClass_Do *DoP;
    pwr_sClass_Po *PoP;
    pwr_tBoolean  *BooleanP;
    pwr_tObjid	  SupId;
    pwr_tClassId  ObjClass;
    sDSupLstLink  *DSupLstP;
    sDSupLstLink  *NextDSupLstP, *NextP;
    

    switch (Class) {
      case pwr_cClass_Di:
        DiP = (pwr_sClass_Di *) ObjP;
        BooleanP = gdh_TranslateRtdbPointer( (pwr_tUInt32)DiP->ActualValue ); 
	break;

      case pwr_cClass_Do:
        DoP = (pwr_sClass_Do *) ObjP;
        BooleanP = gdh_TranslateRtdbPointer( (pwr_tUInt32)DoP->ActualValue ); 
	break;

      case pwr_cClass_Po:
        PoP = (pwr_sClass_Po *) ObjP;
        BooleanP = gdh_TranslateRtdbPointer( (pwr_tUInt32)PoP->ActualValue ); 
	break;

      default:
	return ( IO__SUCCESS );
	break;
    }


    /* Get child with class DSup */
    Sts = gdh_GetChild ( ObjId, &SupId);

    while ( ODD(Sts)) {
       Sts = gdh_GetObjectClass ( SupId, &ObjClass);  
       if ( EVEN(Sts)) return (Sts);

       if ( ObjClass == pwr_cClass_DSup ) {
         Sts = gdh_ObjidToPointer ( SupId, (pwr_tAddress *)&DSupP); 
 	 if (EVEN(Sts)) return ( Sts );

         DSupLstP = (sDSupLstLink *) calloc( 1, sizeof(sDSupLstLink) );
         DSupLstP->SupP = DSupP;
         DSupLstP->ValueP = BooleanP;
         
         if ( DSupDigSerialLstP == NULL ) {
           DSupDigSerialLstP = DSupLstP;
         }
         else {
           if ( DSupDigSerialLstP->NextP == NULL ) {
             DSupDigSerialLstP->NextP = DSupLstP;
           }             
           else {
	     NextP = DSupDigSerialLstP->NextP;
	     while ( NextP != NULL ) {
	       NextDSupLstP = NextP;
	       NextP = NextP->NextP;
	     } 
             NextDSupLstP->NextP = DSupLstP;
           }
	 }
       }

       Sts = gdh_GetNextSibling ( SupId, &SupId);
    }		

    return IO__SUCCESS;
} /* END io_ConnectToDigSupLstSerial */
Esempio n. 8
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;
}
Esempio n. 9
0
RtTraceGtk::RtTraceGtk( void *tr_parent_ctx, GtkWidget *tr_parent_wid, pwr_tObjid tr_objid,
			pwr_tStatus *status) :
  RtTrace( tr_parent_ctx, tr_objid, status), parent_wid(tr_parent_wid), toplevel(0), nav_shell(0)
{

  const int	window_width = 900;
  const int    	window_height = 800;
  const int    	nav_width = 180;
  pwr_tStatus 	sts;
  pwr_tObjid	window_objid;
  pwr_tClassId	cid;
  char   	title[220];
  pwr_tOName   	hostname;
  pwr_tOName   	plcconnect;
  pwr_tFileName fname;

  sts = gdh_ObjidToName( tr_objid, name, sizeof(name), cdh_mNName); 
  if (EVEN(sts)) {
    *status = sts;
    return;
  }
  strcpy( title, "Trace ");
  strcat( title, name);

  /* Find plcwindow */
  sts = gdh_GetObjectClass( tr_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep )) {
    sts = gdh_GetChild( tr_objid, &window_objid);
    if ( EVEN(sts)) {
      *status = sts;
      return;
    }
  }
  else
    window_objid = tr_objid; 

  sts = gdh_GetObjectClass( window_objid, &cid);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  if ( !(cid == pwr_cClass_windowplc ||
         cid == pwr_cClass_windowcond ||
         cid == pwr_cClass_windoworderact ||
         cid == pwr_cClass_windowsubstep )) {
    *status = 0;
    return;
  }

  sts = get_filename( window_objid, filename, &m_has_host, hostname, 
		      plcconnect);
  if ( EVEN(sts)) {
    *status = sts;
    return;
  }

  /* Create object context */
  objid = window_objid;
  if ( m_has_host) {
    strcpy( m_hostname, hostname);
    strcpy( m_plcconnect, plcconnect);
  }

  char *titleutf8 = g_convert( title, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);

  // Gtk
  toplevel = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
					 "default-height", window_height,
					 "default-width", window_width,
					 "title", titleutf8,
					 NULL);
  g_free( titleutf8);

  g_signal_connect( toplevel, "delete_event", G_CALLBACK(delete_event), this);
  g_signal_connect( toplevel, "destroy", G_CALLBACK(destroy_event), this);

  CoWowGtk::SetWindowIcon( toplevel);

  GtkAccelGroup *accel_g = (GtkAccelGroup *) g_object_new(GTK_TYPE_ACCEL_GROUP, NULL);
  gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_g);

  GtkMenuBar *menu_bar = (GtkMenuBar *) g_object_new(GTK_TYPE_MENU_BAR, NULL);

  // File Entry
  // Submenu Print
  GtkWidget *file_print = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Print"));
  g_signal_connect( file_print, "activate", 
		    G_CALLBACK(activate_print), this);

  GtkWidget *file_print_select = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Print _Selected Documents"));
  g_signal_connect( file_print_select, "activate", 
		    G_CALLBACK(activate_printselect), this);

  GtkWidget *file_savetrace = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Save _Trace"));
  g_signal_connect( file_savetrace, "activate", 
		    G_CALLBACK(activate_savetrace), this);

  GtkWidget *file_restoretrace = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Restore Trace"));
  g_signal_connect( file_restoretrace, "activate", 
		    G_CALLBACK(activate_restoretrace), this);

  GtkWidget *file_cleartrace = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("C_lear Trace"));
  g_signal_connect( file_cleartrace, "activate", 
		    G_CALLBACK(activate_cleartrace), this);

  GtkWidget *file_close = gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, accel_g);
  g_signal_connect(file_close, "activate", G_CALLBACK(activate_close), this);

  GtkMenu *file_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print_select);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_savetrace);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_restoretrace);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_cleartrace);
  gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);

  GtkWidget *file = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_File"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), file);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), GTK_WIDGET(file_menu));

  // Functions Entry
  GtkWidget *functions_open_object = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Open Object"));
  g_signal_connect( functions_open_object, "activate", 
		    G_CALLBACK(activate_open_object), this);
  gtk_widget_add_accelerator( functions_open_object, "activate", accel_g,
  			      'a', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_open_subwindow = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("Open S_ubwindow"));
  g_signal_connect( functions_open_subwindow, "activate", 
		    G_CALLBACK(activate_open_subwindow), this);
  gtk_widget_add_accelerator( functions_open_subwindow, "activate", accel_g,
  			      'l', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_display_object = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Display object in Navigator"));
  g_signal_connect( functions_display_object, "activate", 
		    G_CALLBACK(activate_display_object), this);
  gtk_widget_add_accelerator( functions_display_object, "activate", accel_g,
  			      'd', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_show_cross = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Show Crossreferences"));
  g_signal_connect( functions_show_cross, "activate", 
		    G_CALLBACK(activate_show_cross), this);
  gtk_widget_add_accelerator( functions_show_cross, "activate", accel_g,
  			      'r', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_open_classgraph = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Open ObjectGraph"));
  g_signal_connect( functions_open_classgraph, "activate", 
		    G_CALLBACK(activate_open_classgraph), this);
  gtk_widget_add_accelerator( functions_open_classgraph, "activate", accel_g,
  			      'g', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *functions_collect_insert = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Collect Insert"));
  g_signal_connect( functions_collect_insert, "activate", 
		    G_CALLBACK(activate_collect_insert), this);
  gtk_widget_add_accelerator( functions_collect_insert, "activate", accel_g,
  			      'v', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkMenu *functions_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_open_object);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_open_subwindow);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_display_object);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_show_cross);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_open_classgraph);
  gtk_menu_shell_append(GTK_MENU_SHELL(functions_menu), functions_collect_insert);

  GtkWidget *functions = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Functions"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), functions);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(functions), GTK_WIDGET(functions_menu));


  // View Entry

  GtkWidget *view_zoom_in = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_IN, NULL);
  g_signal_connect( view_zoom_in, "activate", 
		    G_CALLBACK(activate_zoomin), this);
  gtk_widget_add_accelerator( view_zoom_in, "activate", accel_g,
  			      'i', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *view_zoom_out = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_OUT, NULL);
  g_signal_connect( view_zoom_out, "activate", 
		    G_CALLBACK(activate_zoomout), this);
  gtk_widget_add_accelerator( view_zoom_out, "activate", accel_g,
  			      'o', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  GtkWidget *view_zoom_reset = gtk_image_menu_item_new_from_stock(GTK_STOCK_ZOOM_100, NULL);
  g_signal_connect( view_zoom_reset, "activate", 
		    G_CALLBACK(activate_zoomreset), this);
  gtk_widget_add_accelerator( view_zoom_reset, "activate", accel_g,
  			      'b', GdkModifierType(GDK_CONTROL_MASK), 
  			      GTK_ACCEL_VISIBLE);

  // Submenu ScanTime
  GSList *view_sc_group = NULL;
  GtkWidget *view_scantime1 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.50 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime1, "activate", 
		    G_CALLBACK(activate_scantime1), this);

  GtkWidget *view_scantime2 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.20 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime2, "activate", 
		    G_CALLBACK(activate_scantime2), this);

  GtkWidget *view_scantime3 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.10 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime3, "activate", 
		    G_CALLBACK(activate_scantime3), this);

  GtkWidget *view_scantime4 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.05 s");
  view_sc_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(view_scantime1));
  g_signal_connect( view_scantime4, "activate", 
		    G_CALLBACK(activate_scantime4), this);

  GtkWidget *view_scantime5 = gtk_radio_menu_item_new_with_mnemonic( view_sc_group, 
									"0.02 s");
  g_signal_connect( view_scantime5, "activate", 
		    G_CALLBACK(activate_scantime5), this);

  GtkWidget *view_sc = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_ScanTime"));
  GtkMenu *view_sc_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime1);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime2);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime3);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime4);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_sc_menu), view_scantime5);

  gtk_menu_item_set_submenu(GTK_MENU_ITEM(view_sc),
			    GTK_WIDGET(view_sc_menu));

  GtkMenu *view_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_in);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_out);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_zoom_reset);
  gtk_menu_shell_append(GTK_MENU_SHELL(view_menu), view_sc);

  GtkWidget *view = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_View"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), view);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), GTK_WIDGET(view_menu));

  // Mode entry
  GSList *mode_group = NULL;
  GtkWidget *mode_view = gtk_radio_menu_item_new_with_mnemonic( mode_group, CoWowGtk::translate_utf8("V_iew"));
  mode_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(mode_view));
  g_signal_connect( mode_view, "activate", 
		    G_CALLBACK(activate_view), this);

  GtkWidget *mode_trace = gtk_radio_menu_item_new_with_mnemonic( mode_group, CoWowGtk::translate_utf8("_Trace"));
  mode_group = gtk_radio_menu_item_get_group( GTK_RADIO_MENU_ITEM(mode_trace));
  g_signal_connect( mode_trace, "activate", 
		    G_CALLBACK(activate_trace), this);

  GtkWidget *mode_simulate = gtk_radio_menu_item_new_with_mnemonic( mode_group, CoWowGtk::translate_utf8("_Simulate"));
  gtk_widget_add_accelerator( mode_simulate, "activate", accel_g,
  			      's', GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK), 
  			      GTK_ACCEL_VISIBLE);
  g_signal_connect( mode_simulate, "activate", 
		    G_CALLBACK(activate_simulate), this);

  GtkMenu *mode_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(mode_menu), mode_view);
  gtk_menu_shell_append(GTK_MENU_SHELL(mode_menu), mode_trace);
  gtk_menu_shell_append(GTK_MENU_SHELL(mode_menu), mode_simulate);

  GtkWidget *mode = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Mode"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), mode);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(mode), GTK_WIDGET(mode_menu));

  // Menu Help
  GtkWidget *help_help = gtk_image_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("On _Trace"));
  gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(help_help), 
				 gtk_image_new_from_stock( "gtk-help", GTK_ICON_SIZE_MENU));
  g_signal_connect(help_help, "activate", G_CALLBACK(activate_help), this);
  gtk_widget_add_accelerator( help_help, "activate", accel_g,
			      'h', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

  GtkWidget *help_plcpgm = gtk_check_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("On _PlcPgm"));
  g_signal_connect( help_plcpgm, "activate", 
		    G_CALLBACK(activate_helpplc), this);

  GtkMenu *help_menu = (GtkMenu *) g_object_new( GTK_TYPE_MENU, NULL);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_help);
  gtk_menu_shell_append(GTK_MENU_SHELL(help_menu), help_plcpgm);

  GtkWidget *help = gtk_menu_item_new_with_mnemonic( CoWowGtk::translate_utf8("_Help"));
  gtk_menu_shell_append(GTK_MENU_SHELL(menu_bar), help);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), GTK_WIDGET(help_menu));

  // Toolbar
  GtkToolbar *tools = (GtkToolbar *) g_object_new(GTK_TYPE_TOOLBAR, NULL);

  GtkWidget *tools_display_object = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_navigator.png");
  gtk_container_add( GTK_CONTAINER(tools_display_object), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_display_object, "clicked", G_CALLBACK(activate_display_object), this);
  gtk_toolbar_append_widget( tools, tools_display_object, "Display object in Navigator", "");
  
  GtkWidget *tools_show_cross = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_crossref.png");
  gtk_container_add( GTK_CONTAINER(tools_show_cross), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_show_cross, "clicked", G_CALLBACK(activate_show_cross), this);
  gtk_toolbar_append_widget( tools, tools_show_cross, "Show Crossreferences", "");
  
  GtkWidget *tools_zoom_in = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_in.png");
  gtk_container_add( GTK_CONTAINER(tools_zoom_in), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_zoom_in, "clicked", G_CALLBACK(activate_zoomin), this);
  gtk_toolbar_append_widget( tools, tools_zoom_in, "Zoom in", "");

  GtkWidget *tools_zoom_out = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_out.png");
  gtk_container_add( GTK_CONTAINER(tools_zoom_out), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_zoom_out, "clicked", G_CALLBACK(activate_zoomout), this);
  gtk_toolbar_append_widget( tools, tools_zoom_out, "Zoom out", "");

  GtkWidget *tools_zoom_reset = gtk_button_new();
  dcli_translate_filename( fname, "$pwr_exe/xtt_zoom_reset.png");
  gtk_container_add( GTK_CONTAINER(tools_zoom_reset), 
		     gtk_image_new_from_file( fname));
  g_signal_connect(tools_zoom_reset, "clicked", G_CALLBACK(activate_zoomreset), this);
  gtk_toolbar_append_widget( tools, tools_zoom_reset, "Zoom reset", "");

  // Flow widget
  GtkWidget *flow_scrolled = scrolledflowwidgetgtk_new( init_flow, 
							this, &flow_widget);
  gtk_widget_show_all(flow_widget);

  nav_widget = flownavwidgetgtk_new( flow_widget);

  GtkWidget *paned = gtk_hpaned_new();
  gtk_paned_pack1( GTK_PANED(paned), flow_scrolled, TRUE, TRUE);
  gtk_paned_pack2( GTK_PANED(paned), nav_widget, FALSE, TRUE);

  GtkWidget *vbox = gtk_vbox_new( FALSE, 0);
  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(menu_bar), FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(tools), FALSE, FALSE, 0);
  gtk_box_pack_start( GTK_BOX(vbox), GTK_WIDGET(paned), TRUE, TRUE, 0);

  gtk_container_add( GTK_CONTAINER(toplevel), vbox);
  gtk_widget_show_all( toplevel);

  gtk_paned_set_position( GTK_PANED(paned), window_width - nav_width);

#if 0
  // Navigator window
  nav_shell = (GtkWidget *) g_object_new( GTK_TYPE_WINDOW, 
					  "default-height", 200,
					  "default-width", 200,
					  "title", "Navigator",
					  NULL);
  g_signal_connect( nav_shell, "delete_event", G_CALLBACK(nav_delete_event), this);

  nav_widget = flownavwidgetgtk_new( flow_widget);
  gtk_container_add( GTK_CONTAINER(nav_shell), nav_widget);
  gtk_widget_show_all( nav_shell);
#endif

  wow = new CoWowGtk( toplevel);
  trace_timerid = wow->timer_new();

  viewsetup();
  flow_Open( flow_ctx, filename);

  gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( mode_trace), TRUE);
  gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( view_scantime1), TRUE);

  //trasetup();
  //trace_start();

#if defined OS_LINUX
  {
    struct stat info;

    if ( stat( filename, &info) != -1)
      version = info.st_ctime;    
  }
#endif

  // Check version
  unsigned int flow_version;
  pwr_tUInt32 window_version;
  pwr_tAName aname;

  flow_GetCtxUserVersion( flow_ctx, &flow_version);

  strcpy( aname, name);
  strcat( aname, ".Version");

  sts = gdh_GetObjectInfo( aname, &window_version, sizeof(window_version));
  if ( EVEN(sts)) return;

  if ( flow_version > window_version)
    wow->DisplayError( "Version mismatch", "Trace file is newer than database version");
  else if ( flow_version < window_version)
    wow->DisplayError( "Version mismatch", "Trace file is older than database version");
}
Esempio n. 10
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;
}
Esempio n. 11
0
int XNav::getAllMenuItems( xmenu_sMenuCall	*ip,
			   xmenu_sMenuItem	**Item,
			   pwr_tObjid		objid,
			   pwr_tUInt32		Level,
			   int			*nItems,
			   int			AddSeparator,
			   pwr_sAttrRef		*CurrentObject)
{
  int                   sts;
  pwr_tCid	        classid;
  pwr_tObjid            child;
  pwr_sMenuButton	*mbp;
  pwr_sMenuCascade	*mcp;
  pwr_sMenuRef		*mrp;
  pwr_tStatus           (*filter)( xmenu_sMenuCall *);
  int                   sensitive;
  int                   i;


  Level++;
  memset(*Item, 0, sizeof(**Item));

  if(AddSeparator) {
    (*Item)->Level = Level;
    (*Item)->Item = xmenu_eMenuItem_Separator;
    (*Item)->MenuObject = pwr_cNObjid;
    (*Item)++;
    (*nItems)++;
  } 
  else {
    sts = gdh_GetObjectClass( objid, &classid);
    if ( EVEN(sts)) return sts;

    if ( classid == pwr_eClass_MenuButton) {
      sts = gdh_ObjidToPointer( objid, (void **) &mbp);
      if ( EVEN(sts)) return sts;

      
      ip->ChosenItem = *nItems;
      for ( i = 0; i < 5; i++) {
        strcpy( (*Item)->FilterArguments[i], mbp->FilterArguments[i]);
      }

      // Call any filter method
      (*Item)->CurrentObject = *CurrentObject;
      sensitive = 1;
      if ( strcmp( mbp->FilterName, "") != 0) {
        sts = GetMethod( mbp->FilterName, &filter);
        if ( ODD(sts)) {
          sts = (filter) ( ip);
	  if ( sts == XNAV__INSENSITIVE) 
            sensitive = 0;
        }
      }
      else
        sts = XNAV__SUCCESS;

      if ( ODD(sts)) {
        (*Item)->Level = Level;
        (*Item)->Item = xmenu_eMenuItem_Button;
        (*Item)->MenuObject = objid;

        (*Item)->Flags.f.Sensitive = sensitive;
        if (strcmp( mbp->MethodName, "")  == 0)
          (*Item)->Flags.f.Sensitive = 0;

        strcpy((*Item)->Name, mbp->ButtonName);
        strcpy( (*Item)->Method, mbp->MethodName);
        strcpy( (*Item)->Filter, mbp->FilterName);
        for ( i = 0; i < 5; i++) {
          strcpy( (*Item)->MethodArguments[i], mbp->MethodArguments[i]);
        }
        (*Item)++;
        (*nItems)++;
      }
    } 
    else if ( classid == pwr_eClass_MenuSeparator) {
      (*Item)->Level = Level;
      (*Item)->Item = xmenu_eMenuItem_Separator;
      (*Item)->MenuObject = objid;
      (*Item)++;
      (*nItems)++;
    } 
    else if ( classid == pwr_eClass_MenuCascade) {
      sts = gdh_ObjidToPointer( objid, (void **) &mcp);
      if ( EVEN(sts)) return sts;

      // Call any filter method
      (*Item)->CurrentObject = *CurrentObject;
      if ( strcmp( mcp->FilterName, "") != 0) {
        sts = GetMethod( mcp->FilterName, &filter);
        if ( ODD(sts)) {
          sts = (filter) ( ip);
        }
      }
      else
        sts = XNAV__SUCCESS;

      if ( ODD(sts)) {
        (*Item)->Level = Level;
        (*Item)->Item = xmenu_eMenuItem_Cascade;
        (*Item)->Flags.f.Sensitive = 1;
        strcpy((*Item)->Name, mcp->ButtonName);
        (*Item)->MenuObject = objid;
        (*Item)++;
        (*nItems)++;
     
        sts = gdh_GetChild( objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems(ip, Item, child, Level, nItems, 0, CurrentObject);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( classid == pwr_eClass_MenuRef && 
	      cdh_ObjidIsNull( CurrentObject->Objid)) {
      pwr_tAName aname;
      pwr_sAttrRef currentar;
      pwr_tCid current_cid;
      pwr_tTid a_tid;
      pwr_tUInt32 a_size, a_offs, a_elem;

      sts = gdh_ObjidToPointer( objid, (void **) &mrp);
      if ( EVEN(sts)) return sts;

      // Call any filter method
      (*Item)->CurrentObject = *CurrentObject;
      if ( strcmp( mrp->FilterName, "") != 0) {
        sts = GetMethod( mrp->FilterName, &filter);
        if ( ODD(sts)) {
          sts = (filter) ( ip);
        }
      }
      else
        sts = XNAV__SUCCESS;

      if ( ODD(sts)) {
	int create_object_button = 0;

	if ( strcmp( mrp->RefAttribute, "_SelfObject") == 0) {
	  // Object entry for attributes
	  char *s;

	  sts = gdh_AttrrefToName( &ip->Pointed, aname, sizeof(aname), cdh_mName_volumeStrict);
	  if ( EVEN(sts)) return sts;
	  if ( (s = strrchr( aname, '.')))
	    *s = 0;

	  sts = gdh_NameToAttrref( pwr_cNOid, aname, &currentar);
	  if ( EVEN(sts)) return sts;
	}
	else {
	  sts = gdh_AttrrefToName( &ip->Pointed, aname, sizeof(aname), cdh_mName_volumeStrict);
	  if ( EVEN(sts)) return sts;
	  strcat( aname, ".");
	  strcat( aname, mrp->RefAttribute);
	  
	  sts = gdh_GetAttributeCharacteristics( aname, &a_tid, &a_size,
						 &a_offs, &a_elem);
	  if ( ODD(sts)) {
	    switch ( a_tid) {
	    case pwr_eType_AttrRef:
	      sts = gdh_GetObjectInfo( aname, &currentar, sizeof(currentar));
	      break;
	    case pwr_eType_Objid: {
	      pwr_tOid oid;
	      
	      currentar = pwr_cNAttrRef;
	      sts = gdh_GetObjectInfo( aname, &oid, sizeof(oid));
	      currentar = cdh_ObjidToAref( oid);
	      break;
	    }
	    default:
	      sts = 0;
	  }
	  }
	  create_object_button = 0;
	}
	if ( ODD(sts) && cdh_ObjidIsNotNull( currentar.Objid)) {
	  (*Item)->Level = Level;
	  (*Item)->Item = xmenu_eMenuItem_Ref;
	  (*Item)->Flags.f.Sensitive = 1;
	  strcpy((*Item)->Name, mrp->ButtonName);
	  (*Item)->MenuObject = objid;
	  (*Item)++;
	  (*nItems)++;

	  // Create a label with current object name
	  sts = gdh_AttrrefToName( &currentar, aname, sizeof(aname), 
				   cdh_mNName);
	  if ( ODD(sts) && create_object_button) {
	    (*Item)->Level = Level;
	    (*Item)->Item = xmenu_eMenuItem_Button;
	    (*Item)->MenuObject = pwr_cNObjid;
	    strncpy((*Item)->Name, aname, sizeof((*Item)->Name));
	    (*Item)->Name[sizeof((*Item)->Name)-1] = 0;
	    (*Item)->MenuObject = pwr_cNObjid;
	    (*Item)->CurrentObject = currentar;
	    (*Item)->Flags.f.Sensitive = 1;
	    strcpy( (*Item)->Method, "$Object-OpenObject");
	    (*Item)++;
	    (*nItems)++;
	  }

	  sts = gdh_GetAttrRefTid( &currentar, &current_cid);
	  if ( EVEN(sts)) return sts;

	  xmenu_eItemType item_type = ip->ItemType;
	  if ( currentar.Flags.b.Object)
	    ip->ItemType =  xmenu_eItemType_Object;
	  else
	    ip->ItemType =  xmenu_eItemType_AttrObject;

	  sts = GetObjectMenu(ip, current_cid, Item, Level, nItems, 0, &currentar);
	  if ( EVEN(sts)) return sts;

	  ip->ItemType = item_type;
        }
      }
    }
  }
  return XNAV__SUCCESS;
}
Esempio n. 12
0
int XNav::GetObjectMenu( xmenu_sMenuCall	*ip,
			 pwr_tCid		classid,
			 xmenu_sMenuItem	**Item,
			 pwr_tUInt32		Level,
			 int			*nItems,
			 int			AddSeparator,
			 pwr_sAttrRef		*CurrentObject)
{
  int                   sts;
  pwr_tObjid            child;
  pwr_tObjid		menu_objid;
  char  		menu[80];
  pwr_tOName  		classname;
  pwr_sAttrRef		currentar = pwr_cNAttrRef;
  pwr_tCid		supercid;


  if ( cdh_ObjidIsNotNull( CurrentObject->Objid))
    currentar = *CurrentObject;

    if ( ip->ItemType == xmenu_eItemType_Object) {
      // Popup-menu for an object
      if ( !cdh_tidIsCid( classid))
	return XNAV__SUCCESS;


      // Get the RtXtt common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXtt");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, Level, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }

      // Get the RtXtt menu-objects for superclasses
      // TODO shadow overlayed methods...
      sts = gdh_GetSuperClass( classid, &supercid, CurrentObject->Objid);
      while ( ODD(sts)) {
	sts = gdh_ObjidToName( cdh_ClassIdToObjid( supercid), classname, 
			       sizeof(classname), cdh_mName_volumeStrict);
	if ( EVEN(sts)) return sts;

	sprintf( menu, "%s-RtXtt", classname);
	sts = gdh_NameToObjid( menu, &menu_objid);
	if ( ODD(sts)) {
	  sts = gdh_GetChild( menu_objid, &child);
	  while( ODD(sts)) {
	    sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
	    if ( EVEN(sts)) return sts;
	    sts = gdh_GetNextSibling( child, &child);
	  }
	}
	sts = gdh_GetSuperClass( supercid, &supercid, CurrentObject->Objid);
      }

      // Get the RtXtt menu-objects for this class, or for superclasses
      sts = gdh_ObjidToName( cdh_ClassIdToObjid( classid), classname, 
		     sizeof(classname), cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;

      sprintf( menu, "%s-RtXtt", classname);
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( ip->ItemType == xmenu_eItemType_AttrObject) {   
      // Find attribute object methods...
      if ( !cdh_tidIsCid( classid))
	return XNAV__SUCCESS;

      // Get the RtXtt common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXttAttrObject");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }

      // Get the RtXtt menu-objects for this class
      sts = gdh_ObjidToName( cdh_ClassIdToObjid( classid), classname, 
		     sizeof(classname), cdh_mName_volumeStrict);
      if ( EVEN(sts)) return sts;

      sprintf( menu, "%s-RtXtt", classname);
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( ip->ItemType == xmenu_eItemType_Attribute) {   
      // Find attribute methods...
      // Get the RtXttAttribute common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXttAttribute");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }
    else if ( ip->ItemType == xmenu_eItemType_Crossref) {   
      // Find attribute methods...
      // Get the RtXttCrossref common menu-objects
      strcpy( menu, "pwrs:Class-$Object-RtXttCrossref");
      sts = gdh_NameToObjid( menu, &menu_objid);
      if ( ODD(sts)) {
        sts = gdh_GetChild( menu_objid, &child);
        while( ODD(sts)) {
          sts = getAllMenuItems( ip, Item, child, 0, nItems, 0, &currentar);
          if ( EVEN(sts)) return sts;
          sts = gdh_GetNextSibling( child, &child);
        }
      }
    }

  return XNAV__SUCCESS;
}
Esempio n. 13
0
static void pwrsrv_Oid( rpvd_sMsgOid *msg)
{
  rpvd_sMsgObject rmsg;
  pwr_tOid fth;
  pwr_tOid fch;
  pwr_tOid lch;
  pwr_tOid bws;
  pwr_tOid fws;
  pwr_tCid cid;
  pwr_tObjName name;
  pwr_tOid o;
  pwr_tStatus sts;
  pwr_tOid plist[200];
  int psize = 0;
  int i, j;
  char *s;

  rmsg.Type = rpvd_eMsg_Object;
  rmsg.Id = msg->Id;
  rmsg.Status = 1;
  rmsg.Oid = msg->Oid;

  sts = gdh_GetObjectClass( msg->Oid, &cid);
  if ( EVEN(sts)) {
    rmsg.Status = sts;
    udp_Send( (char *)&rmsg, sizeof(rmsg));
    return;
  }

  plist[psize++] = msg->Oid;
  for ( sts = gdh_GetParent( plist[psize-1], &o); 
	ODD(sts);
	sts = gdh_GetParent( plist[psize-1], &o)) {
    plist[psize++] = o;
  }
  /* Add volume object */
  plist[psize].oix = 0;
  plist[psize++].vid = msg->Oid.vid;

  for ( j = 0; j < psize; j++) {
    i = psize - j - 1;

    sts = gdh_GetObjectClass( plist[i], &cid);

    if ( i == psize - 1) {
      /* Volume object */
      fth.oix = 0;

      sts = gdh_GetRootList( &fch);
      if ( EVEN(sts)) {
	fch.oix = 0;
	lch.oix = 0;
      }
      else {
	sts = 1;
	for ( lch = fch; ODD(sts); sts = gdh_GetNextSibling( lch, &o)) {
	  lch = o;
	}
      }
      fws.oix = 0;
      bws.oix = 0;

      sts = gdh_ObjidToName( plist[i], name, sizeof(name), cdh_mName_volume);
      if ( (s = strrchr( name, ':')))
	*s = 0;
    }
    else {
      sts = gdh_GetParent( plist[i], &fth);
      if ( EVEN(sts)) 
	fth.oix = 0;
      sts = gdh_GetChild( plist[i], &fch);
      if ( EVEN(sts)) {
	fch.oix = 0;
	lch.oix = 0;
      }
      else {
	lch = fch;
	for ( sts = gdh_GetNextSibling( lch, &o); 
	      ODD(sts); 
	      sts = gdh_GetNextSibling( lch, &o)) {
	  lch = o;
	}
      }
      sts = gdh_GetNextSibling( plist[i], &fws);
      if ( EVEN(sts))
	fws.oix = rmsg.o[j-1].fchoix;
      sts = gdh_GetPreviousSibling( plist[i], &bws);
      if ( EVEN(sts))
	bws.oix = rmsg.o[j-1].lchoix;
      sts = gdh_ObjidToName( plist[i], name, sizeof(name), cdh_mName_object);
    }
    rmsg.o[j].oix = plist[i].oix;
    rmsg.o[j].fthoix = fth.oix;
    rmsg.o[j].fchoix = fch.oix;
    rmsg.o[j].lchoix = lch.oix;
    rmsg.o[j].fwsoix = fws.oix;
    rmsg.o[j].bwsoix = bws.oix;
    rmsg.o[j].cid = cid;
    strcpy( rmsg.o[j].name, name);
  }
  rmsg.OSize = psize;
  udp_Send( (char *)&rmsg, sizeof(rmsg));
}
Esempio n. 14
0
/*----------------------------------------------------------------------------*\
   Init method for the Pb_profiboard agent  
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoAgentInit (
  io_tCtx	ctx,
  io_sAgent	*ap
) 
{
  pwr_sClass_Pb_Profiboard *op;
  pwr_tUInt16 sts;
  pwr_tStatus status;
  T_PROFI_DEVICE_HANDLE *hDevice;
  io_sAgentLocal	*local;

  char ok;

  pwr_tObjid slave_objid;
  pwr_tClassId slave_class;

  pwr_sClass_Pb_DP_Slave *sop;
  char name[196];

  struct timespec rqtp = {0, 20000000}; // 20 ms  
  
  int retry;
    
  count=0;

  /* Allocate area for local data structure */
  ap->Local = calloc(1, sizeof(io_sAgentLocal));
  if (!ap->Local) {
    errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "calloc");
    return IO__ERRINIDEVICE;
  }
    
  hDevice = (T_PROFI_DEVICE_HANDLE *) ap->Local;

  local = (io_sAgentLocal *) ap->Local;

  op = (pwr_sClass_Pb_Profiboard *) ap->op;

  op->Status = PB__NOTINIT;

  /* Initialize interface */
  
  if (ctx->Node->Restarts > 0) {
    nanosleep(&rqtp, NULL);
  }
  
  errh_Info( "Initializing interface for Profibus DP Master %s", ap->Name);
  sts = profi_init(hDevice, (unsigned char) op->BusNumber - 1, 0, 0);

  if (sts != E_OK)
  {
    /* Can't open driver */
    op->Status = PB__INITFAIL;
    errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "open device");
    ctx->Node->EmergBreakTrue = 1;
    return IO__ERRDEVICE;
  }

  /* If this is not the Profibus I/O process, return */
  
  if ((op->Process & io_mProcess_Profibus) && (ctx->Process != io_mProcess_Profibus)) {
    op->Status = PB__NOTINIT;
    errh_Info( "Init template I/O agent for Profibus DP Master %s, %d", ap->Name, ctx->Process );
    return IO__SUCCESS;
  }
  
  if (ctx->Node->Restarts > 0) {
    errh_Info( "Warm restart - Skipping config of Profibus DP Master %s", ap->Name);
    op->Status = PB__NORMAL;
//    return IO__SUCCESS;
  }
  
  errh_Info( "Config of Profibus DP Master %s", ap->Name);
      
  if (op->DisableBus != 1) {
  
    ok = FALSE;
    
    if (ctx->Node->Restarts == 0) {

      retry = 0;
      while (!ok) {
    
        op->Status = PB__NOTINIT;
      
        /* Set FMB configuration */

        sts = fmb_set_configuration(hDevice,  op); 
        if (!sts) {
          op->Status = PB__INITFAIL;
          errh_Error( "ERROR config Profibus DP  Master %s - %s", ap->Name, "fmb set configuration");
	  retry++;
	  if (retry < 2) {
            nanosleep(&rqtp, NULL);
	    continue;
	  } 
          return IO__ERRINIDEVICE;
        }

        /* Set DP master parameters */

        sts = dp_init_master(hDevice); 
        if (!sts) {
          op->Status = PB__INITFAIL;
          errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "dp init master");
          return IO__ERRINIDEVICE;
        }

        /* Download DP bus parameters */

        sts = dp_download_bus(hDevice,  op); 
        if (!sts) {
          op->Status = PB__INITFAIL;
          errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "dp download bus");
          return IO__ERRINIDEVICE;
        }
      
        /* Loop through all slaves (traverse agent's children) and initialize them */

        op->NumberSlaves = 0;
        status = gdh_GetChild(ap->Objid, &slave_objid);
  
        while (ODD(status)) {
          status = gdh_GetObjectClass(slave_objid, &slave_class);

          status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress *) &sop);
          status = gdh_ObjidToName(slave_objid, (char *) &name, sizeof(name), cdh_mNName);
  
          errh_Info( "Download Profibus DP Slave config - %s", name );

          status = dp_download_slave(hDevice, sop);

          if (!status) {
            errh_Error( "ERROR Init Profibus DP slave %s", name);
	  }

          op->NumberSlaves++;
          status = gdh_GetNextSibling(slave_objid, &slave_objid);
        }

        /* Calculate offsets of inputs and outputs for a slave */
      
        status = gdh_GetChild(ap->Objid, &slave_objid);
  
        while (ODD(status)) {
          status = gdh_GetObjectClass(slave_objid, &slave_class);
          status = gdh_ObjidToPointer(slave_objid, (pwr_tAddress *) &sop);

          status = dp_io_offsets(hDevice, sop);

          status = gdh_GetNextSibling(slave_objid, &slave_objid);
        }

        /* Move to STOP mode, this will fix the DPRAM layout */

        sts = dp_act_param_loc(hDevice, DP_OP_MODE_STOP);
        if (sts != E_OK) {
          op->Status = PB__INITFAIL;
          errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to STOPPED");
          return IO__ERRINIDEVICE;
        }
	      
        ok = TRUE;
	
      }  /* End - While !ok */
    }  /* End - Initialization only if not restart   */
/*    else {
       Move to STOP mode, this will fix the DPRAM layout 

      sts = dp_act_param_loc(hDevice, DP_OP_MODE_STOP);
      if (sts != E_OK) {
        op->Status = PB__INITFAIL;
        errh_Error( "ERROR config Profibus DP Master %s - %s", ap->Name, "act param loc to STOPPED");
        return IO__ERRINIDEVICE;
      }
    } */
  }    
  else
    op->Status = PB__DISABLED;
  
  return IO__SUCCESS;
}