Example #1
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;
}
Example #2
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;
}
Example #3
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 */
Example #4
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 */
Example #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;
}
Example #6
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;
}
Example #7
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;
}
Example #8
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));
}
Example #9
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;
}