Beispiel #1
0
static pwr_tStatus ConnectAttribute (
  ldh_sMenuCall *ip
) {
  pwr_tStatus	    	sts;
  pwr_sMenuButton   	mb;
  pwr_sAttrRef	    	PattrRef;


  sts = ldh_ReadObjectBody(ip->PointedSession,
    ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));
  if (EVEN(sts)) return sts;

  // Assume RtBody or SysBody
  char *aname_p;
  pwr_tAName aname;
  int size;

  sts = ldh_AttrRefToName( ip->PointedSession, &ip->Pointed, ldh_eName_ArefVol, &aname_p, &size);
  if ( EVEN(sts)) return 0;
 
  strncpy( aname, aname_p, sizeof(aname));
  strncat( aname, ".", sizeof(aname));
  strncat( aname, mb.MethodArguments[0], sizeof(aname));

  sts = ldh_NameToAttrRef( ip->PointedSession, aname, &PattrRef);
  if (ODD(sts))
    sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &ip->Selected[0],
			     sizeof(pwr_tAttrRef));

  if ( ip->message_cb) {
    char msg[200];
    
    if ( ODD(sts)) {
      pwr_tOName name;

      sts = ldh_AttrRefToName( ip->PointedSession, &ip->Selected[0], ldh_eName_Hierarchy, 
			       &aname_p, &size);
      if ( ODD(sts))
	strncpy( name, aname_p, sizeof(name));
      else
	cdh_ObjidToString( name, ip->Selected[0].Objid, 1);
      snprintf( msg, sizeof(msg), "%s connected to:   %s", mb.MethodArguments[0], name);
      ip->wtt->message( 'I', msg);
    }
    else {
      msg_GetMsg( sts, msg, sizeof(msg));
      ip->wtt->message( 'E', msg);
    }
  }
  return LDH__SUCCESS;
}
Beispiel #2
0
static pwr_tStatus configure_object( ldh_sMenuCall *ip, pwr_sAttrRef *aref, 
				     unsigned int disable_mask)
{
  pwr_tStatus 	sts;
  pwr_tCid 	cid;
  ldh_sParDef 	*bodydef;
  int 		rows;
  int		i;
  pwr_sAttrRef  aaref, daref;
  pwr_tDisableAttr disable;
  int disableattr_cnt = 0;
  
  sts = ldh_GetAttrRefTid( ip->PointedSession, aref, &cid);
  if ( EVEN(sts)) return sts;

  sts = ldh_GetObjectBodyDef( ip->PointedSession, cid, "RtBody", 1,
				  &bodydef, &rows);
  if (EVEN(sts)) return sts;

  for ( i = 0; i < rows; i++) {
    if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_DISABLEATTR) {
      // Disable or enable dependent on mask
      sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref);
      if ( EVEN(sts)) return sts;

      daref = cdh_ArefToDisableAref( &aaref);

      if ( (1 << disableattr_cnt++) & disable_mask)
	disable = 1;
      else
	disable = 0;

      sts = ldh_WriteAttribute( ip->PointedSession, &daref, (void *)&disable, 
				sizeof(disable));
      if ( EVEN(sts)) return sts;
    }
#if 0
    if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_CLASS) {
      // Examine object attribute
      sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref);
      if ( EVEN(sts)) return sts;

      sts = configure_object( ip, &aaref, disable_mask, disableattr_cnt);
      if ( EVEN(sts)) return sts;
    }
#endif
  }
  free( (char *)bodydef);

  return LDH__SUCCESS;
}
Beispiel #3
0
static pwr_tStatus Connect (
  ldh_sMenuCall *ip
) {
  pwr_tStatus	    	sts;
  pwr_sMenuButton   	mb;
  pwr_sAttrRef	    	PattrRef;
  pwr_sAttrRef 		aref = ip->Selected[0];


  sts = ldh_ReadObjectBody(ip->PointedSession,
    ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));
  if (EVEN(sts)) return sts;

  if ( strcmp( mb.MethodArguments[1], "") != 0) {
    char arg_cid_str[20][32];
    int arg_cid_cnt;
    int i;
    int cid_ok = 0;
    pwr_tCid		cid;
    pwr_tCid		arg_cid;

    // arg 1 holds the allowed class or classes to connect to
    arg_cid_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *) arg_cid_str, 
		sizeof( arg_cid_str) / sizeof( arg_cid_str[0]),
		sizeof( arg_cid_str[0]), 0);


    sts = ldh_GetAttrRefTid( ip->PointedSession, &ip->Selected[0], &cid);
    if ( EVEN(sts)) return 0;

    for ( i = 0; i < arg_cid_cnt; i++) {
      sts = ldh_ClassNameToId( ip->PointedSession, &arg_cid, arg_cid_str[i]);
      if ( EVEN(sts)) return 0;

      if ( cid == arg_cid) {
	cid_ok = 1;
	break;
      }
    }
    if ( !cid_ok)
      return 0;
  }

  if ( strcmp( mb.MethodArguments[2], "") != 0)
    // Body in MethodArguments 2, probably DevBody
    sts = ldh_SetObjectPar( ip->PointedSession, ip->Pointed.Objid, mb.MethodArguments[2],
		mb.MethodArguments[0], (char *) &ip->Selected[0], sizeof(ip->Selected[0]));
  else {
    char *name_p;
    pwr_tAName name;
    int size;
    pwr_tCid cid;

    // If Selected is a Template object in a classvolume, replace with 
    // symbol $IoConnect
    if ( cdh_IsClassVolume( aref.Objid.vid)) {
      sts = ldh_ObjidToName( ip->PointedSession, aref.Objid, ldh_eName_Object, 
			     name, sizeof(name), &size);
      if ( ODD(sts) &&  strcmp( name, "Template") == 0) {
	sts = ldh_GetObjectClass( ip->PointedSession, aref.Objid, &cid);
	if ( EVEN(sts)) return sts;

	aref.Objid.vid = ldh_cIoConnectVolume;
	aref.Objid.oix = cid;
      }
    }

    // Assume RtBody or SysBody
    sts = ldh_AttrRefToName(ip->PointedSession, &ip->Pointed, ldh_eName_VolPath,
			    &name_p, &size);
    if ( ODD(sts)) {
      strcpy( name, name_p);
      strcat( name, ".");
      strcat( name, mb.MethodArguments[0]);

      sts = ldh_NameToAttrRef( ip->PointedSession, name, &PattrRef);
      if (ODD(sts))
	sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &aref,
			     sizeof(aref));
    }
  }

    
  char msg[500];
  if ( ODD(sts)) {
    pwr_tAName name;
    char *name_p;
    int len;

    sts = ldh_AttrRefToName( ip->PointedSession, &aref, ldh_eName_Hierarchy, 
			     &name_p, &len);
    if ( EVEN(sts))
      cdh_ObjidToString( name, aref.Objid, 1);
    else
      strcpy( name, name_p);
    sprintf( msg, "%s connected to:   %s", mb.MethodArguments[0], name);
    ip->wtt->message( 'I', msg);
  }
  else {
    msg_GetMsg( sts, msg, sizeof(msg));
    ip->wtt->message( 'E', msg);
  }
  return PWRS__SUCCESS;
}
Beispiel #4
0
static pwr_tStatus IoConnect (
  ldh_sMenuCall *ip
) {
  pwr_tStatus	    	sts;
  pwr_sMenuButton   	mb;
  pwr_sAttrRef 		aref = ip->Selected[0];
  pwr_sAttrRef	    	PattrRef;
  char			*name_p;
  pwr_tAName   		name;
  int			size;

  sts = ldh_ReadObjectBody(ip->PointedSession,
    ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));
  if (EVEN(sts)) return sts;

  if ( strcmp( mb.MethodArguments[0], "") != 0) {
    char arg_cid_str[20][32];
    int arg_cid_cnt;
    int i;
    int cid_ok = 0;
    pwr_tCid		cid;
    pwr_tCid		arg_cid;

    // arg 0 holds the allowed class or classes to connect to
    arg_cid_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *) arg_cid_str, 
		sizeof( arg_cid_str) / sizeof( arg_cid_str[0]),
		sizeof( arg_cid_str[0]), 0);


    sts = ldh_GetAttrRefTid( ip->PointedSession, &ip->Selected[0], &cid);
    if ( EVEN(sts)) return 0;

    for ( i = 0; i < arg_cid_cnt; i++) {
      sts = ldh_ClassNameToId( ip->PointedSession, &arg_cid, arg_cid_str[i]);
      if ( EVEN(sts)) return 0;

      if ( cid == arg_cid) {
	cid_ok = 1;
	break;
      }
    }
    if ( !cid_ok)
      return 0;
  }

#if 0
  printf( "Here in IoConnect\n");

  wb_session *sp = (wb_session *)ip->PointedSession;

  wb_object o = sp->object( ip->Pointed.Objid);
  if ( !o) return o.sts();

  wb_attribute oa = sp->attribute( &ip->Pointed);
  if ( !oa) return oa.sts();

  replaceClass( sp, oa, &ip->Selected[0]);
#endif

  sts = ldh_AttrRefToName(ip->PointedSession, &ip->Pointed, ldh_eName_VolPath,
			  &name_p, &size);
  if ( ODD(sts)) {
    strcpy( name, name_p);
    strcat( name, ".IoConnect");

    sts = ldh_NameToAttrRef( ip->PointedSession, name, &PattrRef);
    if (ODD(sts))
      sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &aref,
			       sizeof(aref));
  }

    
  char msg[500];
  if ( ODD(sts)) {
    pwr_tAName name;
    char *name_p;
    int len;

    sts = ldh_AttrRefToName( ip->PointedSession, &aref, ldh_eName_Hierarchy, 
			     &name_p, &len);
    if ( EVEN(sts))
      cdh_ObjidToString( name, aref.Objid, 1);
    else
      strcpy( name, name_p);
    sprintf( msg, "Io connected to:   %s", name);
    ip->wtt->message( 'I', msg);
  }
  else {
    msg_GetMsg( sts, msg, sizeof(msg));
    ip->wtt->message( 'E', msg);
  }
  return PWRS__SUCCESS;
}
static pwr_tStatus Connect (
  ldh_sMenuCall *ip
) {
  pwr_tStatus sts;
  pwr_sMenuButton mb;
  pwr_sAttrRef PattrRef;
  pwr_sAttrRef PattrXref;
  pwr_sAttrRef SattrRef;
  pwr_sAttrRef SattrXref;
  pwr_sAttrRef TattrRef;
  pwr_tUInt32 Pdim;
  pwr_tUInt32 Sdim;
  pwr_sAttrXRef PattrDef;
  pwr_sAttrXRef SattrDef;
  int i;

  sts = ldh_ReadObjectBody(ip->PointedSession,
    ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));
  if (EVEN(sts)) return sts;

  sts = ldh_GetAttrRef(ip->PointedSession, ip->Pointed.Objid,
    mb.MethodArguments[0], &PattrRef);
  if (EVEN(sts)) return sts;
  sts = ldh_GetAttrRef(ip->PointedSession, ip->Selected[0].Objid,
    mb.MethodArguments[1], &SattrRef);
  if (EVEN(sts)) return sts;

  sts = ldh_GetAttrXRefDef(ip->PointedSession, &PattrRef, &PattrDef);
  if (EVEN(sts)) return sts;
  sts = ldh_GetAttrXRefDef(ip->PointedSession, &SattrRef, &SattrDef);
  if (EVEN(sts)) return sts;

  if (strncmp(PattrDef.Identity, SattrDef.Identity, sizeof(SattrDef.Identity)) != 0)
    return PWRS__IDXREF;

  if (strncmp(PattrDef.Source, SattrDef.Target, sizeof(PattrDef.Source)) != 0)
    return PWRS__STXREF;

  if (strncmp(PattrDef.Target, SattrDef.Source, sizeof(SattrDef.Source)) != 0)
    return PWRS__STXREF;

  Pdim = PattrRef.Size / sizeof(pwr_sAttrRef);
  Sdim = SattrRef.Size / sizeof(pwr_sAttrRef);

  TattrRef = PattrRef;
  TattrRef.Size = sizeof(pwr_sAttrRef);
  for (i = 0; i < (int)Pdim; i++, TattrRef.Offset += sizeof(pwr_sAttrRef)) {
    /* find Sobject */
    sts = ldh_ReadAttribute(ip->PointedSession, &TattrRef, &PattrXref,
      sizeof(pwr_sAttrRef));
    if (EVEN(sts)) return sts;
    if (!cdh_ObjidIsEqual(PattrXref.Objid, ip->Selected[0].Objid))
      continue;
    sts = ldh_ReadAttribute(ip->PointedSession, &PattrXref, &SattrXref,
      sizeof(pwr_sAttrRef));
    if (EVEN(sts)) return sts;
    if (memcmp(&SattrXref, &TattrRef, sizeof(pwr_sAttrRef)) == 0)
      return PWRS__ALRCONN;
  }

  TattrRef = PattrRef;
  TattrRef.Size = sizeof(pwr_sAttrRef);
  for (i = 0; i < (int)Pdim; i++, TattrRef.Offset += sizeof(pwr_sAttrRef)) {
    /* find free slot */
    sts = ldh_ReadAttribute(ip->PointedSession, &TattrRef, &PattrXref,
      sizeof(pwr_sAttrRef));
    if (EVEN(sts)) return sts;
    if (cdh_ObjidIsNull(PattrXref.Objid))
      break;
  }
  if (i >= (int)Pdim) {
    return PWRS__PALRCONN;
  } else {
    PattrRef = TattrRef;
  }

  TattrRef = SattrRef;
  TattrRef.Size = sizeof(pwr_sAttrRef);
  for (i = 0; i < (int)Sdim; i++, TattrRef.Offset += sizeof(pwr_sAttrRef)) {
    /* find free slot */
    sts = ldh_ReadAttribute(ip->PointedSession, &TattrRef, &SattrXref,
      sizeof(pwr_sAttrRef));
    if (EVEN(sts)) return sts;
    if (cdh_ObjidIsNull(SattrXref.Objid))
      break;
  }
  if (i >= (int)Sdim) {
    return PWRS__SALRCONN;
  } else {
    SattrRef = TattrRef;
  }

  sts = ldh_WriteAttribute(ip->PointedSession, &SattrRef, &PattrRef,
    sizeof(pwr_sAttrRef));
  sts = ldh_WriteAttribute(ip->PointedSession, &PattrRef, &SattrRef,
    sizeof(pwr_sAttrRef));
  return PWRS__SUCCESS;
}
Beispiel #6
0
int pndevice_save_cb(void* sctx)
{
  device_sCtx* ctx = (device_sCtx*)sctx;
  pwr_tStatus sts;
  pwr_tOName name;
  int size;
  pwr_tOid oid;
  pwr_tStatus rsts = PB__SUCCESS;

  // Syntax check
  if (ctx->attr->attrnav->device_num == 0) {
    MsgWindow::message('E', "Device type not selected");
    return PB__SYNTAX;
  }

  for (unsigned int i = 1; i < ctx->attr->attrnav->dev_data.slot_data.size();
       i++) {
    if (ctx->attr->attrnav->dev_data.slot_data[i]->module_enum_number == 0
        && ctx->attr->attrnav->dev_data.slot_data[i]->module_class != 0) {
      // Module class selected but not module type
      char msg[20];

      sprintf(msg, "Slot %d", i);
      MsgWindow::message('E', "Module type not selected, ", msg);
      rsts = PB__MODULETYPE;
    }
    if (ctx->attr->attrnav->dev_data.slot_data[i]->module_class == 0
        && ctx->attr->attrnav->dev_data.slot_data[i]->module_enum_number != 0) {
      // Module type selected but not module class
      char msg[20];

      sprintf(msg, "Slot %d", i);
      MsgWindow::message('E', "Module class not selected, ", msg);
      rsts = PB__MODULECLASS;
    }
  }

  // Save configuration
  ((WNav*)ctx->editor_ctx)->set_nodraw();

  sts = ldh_ObjidToName(ctx->ldhses, ctx->aref.Objid, ldh_eName_Hierarchy, name,
      sizeof(name), &size);
  if (EVEN(sts))
    goto return_now;

  // Check that Slot attribute corresponds to the and module_oid
  for (unsigned int i = 1; i < ctx->attr->attrnav->dev_data.slot_data.size();
       i++)
    ctx->attr->attrnav->dev_data.slot_data[i]->module_oid = pwr_cNOid;

  for (sts = ldh_GetChild(ctx->ldhses, ctx->aref.Objid, &oid); ODD(sts);
       sts = ldh_GetNextSibling(ctx->ldhses, oid, &oid)) {
    unsigned int *slotnumberp, slotnumber;

    sts = ldh_GetObjectPar(
        ctx->ldhses, oid, "RtBody", "Slot", (char**)&slotnumberp, &size);
    if (EVEN(sts)) {
      MsgWindow::message(
          'E', "Not a Profinet module object", msgw_ePop_Yes, oid);
      continue;
    }
    slotnumber = *slotnumberp;
    free(slotnumberp);

    if (slotnumber >= ctx->attr->attrnav->dev_data.slot_data.size()) {
      MsgWindow::message('E', "Slot too large", msgw_ePop_Yes, oid);
      continue;
    }

    if (cdh_ObjidIsNotNull(
            ctx->attr->attrnav->dev_data.slot_data[slotnumber]->module_oid)) {
      MsgWindow::message('E', "Slot already used", msgw_ePop_Yes, oid);
      continue;
    }

    if (ctx->attr->attrnav->dev_data.slot_data[slotnumber]->module_class
        == pwr_cNCid)
      // Should be removed
      continue;

    ctx->attr->attrnav->dev_data.slot_data[slotnumber]->module_oid = oid;
  }

  // Remove modules that wasn't configured any more
  pwr_tOid moid[100];
  int mcnt;
  int found;
  mcnt = 0;
  for (sts = ldh_GetChild(ctx->ldhses, ctx->aref.Objid, &oid); ODD(sts);
       sts = ldh_GetNextSibling(ctx->ldhses, oid, &oid)) {
    found = 0;
    for (unsigned int i = 0; i < ctx->attr->attrnav->dev_data.slot_data.size();
         i++) {
      if (cdh_ObjidIsEqual(
              ctx->attr->attrnav->dev_data.slot_data[i]->module_oid, oid)) {
        found = 1;
        break;
      }
    }
    if (!found) {
      moid[mcnt++] = oid;
      if (mcnt > (int)(sizeof(moid) / sizeof(moid[0])))
        break;
    }
  }

  for (int i = 0; i < mcnt; i++)
    sts = ldh_DeleteObjectTree(ctx->ldhses, moid[i], 0);

  // Create new module objects
  for (unsigned int i = 0; i < ctx->attr->attrnav->dev_data.slot_data.size();
       i++) {
    GsdmlSlotData* slot = ctx->attr->attrnav->dev_data.slot_data[i];

    if (cdh_ObjidIsNull(slot->module_oid) && slot->module_class != pwr_cNCid) {
      char mname[20];
      sprintf(mname, "M%d", i);

      if (i == 1)
        sts = ldh_CreateObject(ctx->ldhses, &slot->module_oid, mname,
            slot->module_class, ctx->aref.Objid, ldh_eDest_IntoFirst);
      else {
        // Find sibling
        pwr_tOid dest_oid = pwr_cNOid;
        int dest_found = 0;
        for (int j = i - 1; j > 0; j--) {
          if (cdh_ObjidIsNotNull(
                  ctx->attr->attrnav->dev_data.slot_data[j]->module_oid)) {
            dest_oid = ctx->attr->attrnav->dev_data.slot_data[j]->module_oid;
            dest_found = 1;
            break;
          }
        }
        if (!dest_found)
          sts = ldh_CreateObject(ctx->ldhses, &slot->module_oid, mname,
              slot->module_class, ctx->aref.Objid, ldh_eDest_IntoFirst);
        else
          sts = ldh_CreateObject(ctx->ldhses, &slot->module_oid, mname,
              slot->module_class, dest_oid, ldh_eDest_After);
      }
      if (EVEN(sts)) {
        MsgWindow::message('E', "Error creating module object", mname);
        sts = 0;
        goto return_now;
      }

      pwr_tAttrRef aaref;
      pwr_tAttrRef modulearef = cdh_ObjidToAref(slot->module_oid);

      // Set Slot
      pwr_tUInt32 slotnumber = i;
      sts = ldh_ArefANameToAref(ctx->ldhses, &modulearef, "Slot", &aaref);
      if (EVEN(sts))
        goto return_now;

      sts = ldh_WriteAttribute(
          ctx->ldhses, &aaref, &slotnumber, sizeof(slotnumber));
      if (EVEN(sts))
        goto return_now;
    }
  }

  for (unsigned int i = 0; i < ctx->attr->attrnav->dev_data.slot_data.size();
       i++) {
    GsdmlSlotData* slot = ctx->attr->attrnav->dev_data.slot_data[i];

    if (i == 0) {
      std::vector<ChanItem> input_vect;
      std::vector<ChanItem> output_vect;

      sts = pndevice_check_io(ctx,
          ctx->attr->attrnav->device_item->VirtualSubmoduleList, input_vect,
          output_vect);
      if (sts == PB__CREATECHAN) {
        char msg[20];
        sprintf(msg, "Slot %d", i);
        MsgWindow::message(
            'W', "Unexpected datatype, channel not created, ", msg);
      }
    } else {
      if (slot->module_class == pwr_cClass_PnModule) {
        std::vector<ChanItem> input_vect;
        std::vector<ChanItem> output_vect;
        gsdml_UseableModules* um
            = ctx->gsdml->ApplicationProcess->DeviceAccessPointList
                  ->DeviceAccessPointItem[ctx->attr->attrnav->device_num - 1]
                  ->UseableModules;

        if (!um)
          continue;
        gsdml_ModuleItem* mi
            = (gsdml_ModuleItem*)um->ModuleItemRef[slot->module_enum_number - 1]
                  ->Body.ModuleItemTarget.p;

        sts = pndevice_check_io(
            ctx, mi->VirtualSubmoduleList, input_vect, output_vect);
        if (sts == PB__CREATECHAN) {
          char msg[20];
          sprintf(msg, "Slot %d", i);
          MsgWindow::message(
              'W', "Unexpected datatype, channel not created, ", msg);
        }

        // Create the channels
        if (EVEN(ldh_GetChild(ctx->ldhses, slot->module_oid, &oid))) {
          unsigned int chan_cnt = 0;
          for (unsigned int j = 0; j < input_vect.size(); j++) {
            char name[80];
            sprintf(name, "Ch%02u", chan_cnt++);
            sts = ldh_CreateObject(ctx->ldhses, &oid, name, input_vect[j].cid,
                slot->module_oid, ldh_eDest_IntoLast);
            if (EVEN(sts))
              goto return_now;

            pwr_tAttrRef aaref;
            pwr_tAttrRef chanaref = cdh_ObjidToAref(oid);

            // Set Representation
            pwr_tEnum representation = input_vect[j].representation;
            sts = ldh_ArefANameToAref(
                ctx->ldhses, &chanaref, "Representation", &aaref);
            if (EVEN(sts))
              goto return_now;

            sts = ldh_WriteAttribute(
                ctx->ldhses, &aaref, &representation, sizeof(representation));
            if (EVEN(sts))
              goto return_now;

            // Set Number
            pwr_tUInt16 number = input_vect[j].number;
            sts = ldh_ArefANameToAref(ctx->ldhses, &chanaref, "Number", &aaref);
            if (EVEN(sts))
              goto return_now;

            sts = ldh_WriteAttribute(
                ctx->ldhses, &aaref, &number, sizeof(number));
            if (EVEN(sts))
              goto return_now;

            // Set Description
            pwr_tString80 description;
            strncpy(
                description, input_vect[j].description, sizeof(description));
            sts = ldh_ArefANameToAref(
                ctx->ldhses, &chanaref, "Description", &aaref);
            if (EVEN(sts))
              goto return_now;

            sts = ldh_WriteAttribute(
                ctx->ldhses, &aaref, description, sizeof(description));
            if (EVEN(sts))
              goto return_now;
          }
          for (unsigned int j = 0; j < output_vect.size(); j++) {
            char name[80];
            sprintf(name, "Ch%02u", chan_cnt++);
            sts = ldh_CreateObject(ctx->ldhses, &oid, name, output_vect[j].cid,
                slot->module_oid, ldh_eDest_IntoLast);
            if (EVEN(sts))
              goto return_now;

            pwr_tAttrRef aaref;
            pwr_tAttrRef chanaref = cdh_ObjidToAref(oid);

            // Set Representation
            pwr_tEnum representation = output_vect[j].representation;
            sts = ldh_ArefANameToAref(
                ctx->ldhses, &chanaref, "Representation", &aaref);
            if (EVEN(sts))
              goto return_now;

            sts = ldh_WriteAttribute(
                ctx->ldhses, &aaref, &representation, sizeof(representation));
            if (EVEN(sts))
              goto return_now;

            // Set Number
            pwr_tUInt16 number = output_vect[j].number;
            sts = ldh_ArefANameToAref(ctx->ldhses, &chanaref, "Number", &aaref);
            if (EVEN(sts))
              goto return_now;

            sts = ldh_WriteAttribute(
                ctx->ldhses, &aaref, &number, sizeof(number));
            if (EVEN(sts))
              goto return_now;

            // Set Description
            pwr_tString80 description;
            strncpy(
                description, output_vect[j].description, sizeof(description));
            sts = ldh_ArefANameToAref(
                ctx->ldhses, &chanaref, "Description", &aaref);
            if (EVEN(sts))
              goto return_now;

            sts = ldh_WriteAttribute(
                ctx->ldhses, &aaref, description, sizeof(description));
            if (EVEN(sts))
              goto return_now;
          }
        }
      } else {
        // Remove existing channels
        std::vector<pwr_tOid> chanvect;
        pwr_tCid cid;

        for (sts = ldh_GetChild(ctx->ldhses, slot->module_oid, &oid); ODD(sts);
             sts = ldh_GetNextSibling(ctx->ldhses, oid, &oid)) {
          sts = ldh_GetObjectClass(ctx->ldhses, oid, &cid);
          if (EVEN(sts))
            goto return_now;

          switch (cid) {
          case pwr_cClass_ChanDi:
          case pwr_cClass_ChanDo:
          case pwr_cClass_ChanAi:
          case pwr_cClass_ChanAo:
          case pwr_cClass_ChanIi:
          case pwr_cClass_ChanIo:
            chanvect.push_back(oid);
            break;
          default:;
          }
        }
        for (unsigned int i = 0; i < chanvect.size(); i++) {
          sts = ldh_DeleteObject(ctx->ldhses, chanvect[i]);
          if (EVEN(sts))
            goto return_now;
        }
      }
    }
  }

  // Write data of all devices for profinet viewer
  // Data is device name, IP and MAC address
  sts = generate_viewer_data(ctx);

  sts = rsts;

return_now:
  ((WNav*)ctx->editor_ctx)->reset_nodraw();
  return sts;
}
Beispiel #7
0
static pwr_tStatus ConfigureComponent( ldh_sMenuCall *ip) 
{
  pwr_tStatus sts;
  unsigned int disable_mask;
  pwr_sMenuButton   mb;
  pwr_tEnum graph_configuration;
  pwr_sAttrRef aaref;
  char vect[10][80];
  char item[3][80];
  int i;
  int nr;
  int vect_cnt;
  
  sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));

  // Reset previoius disable configuration
  configure_object_reset( ip, &ip->Pointed, &mb);

  // Set disable attributes from argument 0
  if ( mb.MethodArguments[0][0] != '(') {
    // Old syntax, eg '7, CircuitBreaker 4, Contactor 5'
    vect_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *)vect, 
			   sizeof( vect) / sizeof( vect[0]), 
			   sizeof( vect[0]), 0);
  
    for ( i = 0; i < vect_cnt; i++) {
      nr = dcli_parse( vect[i], " 	", "", (char *)item,
		       sizeof( item) / sizeof( item[0]), 
		       sizeof( item[0]), 0);
      if ( nr == 1) {
	
	if ( sscanf( item[0], "%d", &disable_mask) != 1)
	  graph_configuration = 0;

	sts = configure_object( ip, &ip->Pointed, disable_mask);
	if ( EVEN(sts)) return sts;
      }
      else if ( nr == 2) {
	pwr_tAName aname;
	
	if ( sscanf( item[1], "%d", &disable_mask) != 1)
	  disable_mask = 0;

	strncpy( aname, item[0], sizeof(aname));
	
	sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				   &aaref);
	if ( ODD(sts)) {
	  sts = configure_object( ip, &aaref, disable_mask);
	  if ( EVEN(sts)) return sts;
	}
      }
    }
  }
  else {
    // New syntax, eg '(7 (CircuitBreaker 4, Contactor 5))'
    char str1[256];
    char *s;

    strncpy( str1, &mb.MethodArguments[0][1], sizeof(str1));
    s = strrchr( str1, ')');
    if ( !s)
      return LDH__COMPSYNTAX;

    *s = 0;
    
    dcli_trim( str1, str1);
    nr = sscanf( str1, "%d", &disable_mask);
    if ( nr != 1)
      return LDH__COMPSYNTAX;

    sts = configure_object( ip, &ip->Pointed, disable_mask);
    if ( EVEN(sts)) return sts;

    sts = configure_attrmask( ip, &ip->Pointed, str1);
    if ( EVEN(sts)) return sts;
  }

  // Set GraphConfiguration from argument 1
  vect_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *)vect, 
		   sizeof( vect) / sizeof( vect[0]), 
		   sizeof( vect[0]), 0);
  
  for ( i = 0; i < vect_cnt; i++) {
    nr = dcli_parse( vect[i], " 	", "", (char *)item,
		   sizeof( item) / sizeof( item[0]), 
		   sizeof( item[0]), 0);
    if ( nr == 1) {

      if ( sscanf( item[0], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, "GraphConfiguration", 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
    else if ( nr == 2) {
      pwr_tAName aname;

      if ( sscanf( item[1], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      strncpy( aname, item[0], sizeof(aname));
      strncat( aname, ".GraphConfiguration", sizeof(aname));

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
  }
  return 1;
}
Beispiel #8
0
static pwr_tStatus configure_object_reset( ldh_sMenuCall *ip, pwr_sAttrRef *aref,
					   pwr_sMenuButton *mb)
{
  pwr_tStatus 	sts;
  pwr_tCid 	cid;
  ldh_sParDef 	*bodydef;
  int 		rows;
  int		i, j;
  pwr_sAttrRef  aaref, daref;
  pwr_tDisableAttr disable = 0;
  char 		vect[10][80];
  int 		vect_cnt;
  int 		skip;
  char		*s;
  
  // Attribute objects in argument 2 are not controlled by the configure method
  if ( mb) {
    vect_cnt = dcli_parse( mb->MethodArguments[2], ",", "", (char *)vect, 
			   sizeof( vect) / sizeof( vect[0]), 
			   sizeof( vect[0]), 0);
    for ( j = 0; j < vect_cnt; j++)
      dcli_trim( vect[j], vect[j]);
  }
  else
    vect_cnt = 0;

  sts = ldh_GetAttrRefTid( ip->PointedSession, aref, &cid);
  if ( EVEN(sts)) return sts;

  sts = ldh_GetObjectBodyDef( ip->PointedSession, cid, "RtBody", 1,
				  &bodydef, &rows);
  if (EVEN(sts)) return sts;

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

    // Check if attribute is controlled by this method
    skip = 0;
    if ( mb) {
      // Remove leading Super.
      s = bodydef[i].ParName;
      while ( strncmp( s, "Super.", 6) == 0)
	s += 6;
      for ( j = 0; j < vect_cnt; j++) {
	if ( cdh_NoCaseStrcmp( vect[j], s) == 0) {
	  // This object should not be reset
	  skip = 1;
	  break;
	}
      }
      if ( skip)
	continue;
    }

    if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_DISABLEATTR) {
      // Enable all attributes
      sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref);
      if ( EVEN(sts)) return sts;

      daref = cdh_ArefToDisableAref( &aaref);

      sts = ldh_WriteAttribute( ip->PointedSession, &daref, (void *)&disable, 
				sizeof(disable));
      if ( EVEN(sts)) return sts;
    }

    if ( bodydef[i].Par->Param.Info.Flags & PWR_MASK_CLASS) {
      // Reset object attribute
      sts = ldh_ArefANameToAref( ip->PointedSession, aref, bodydef[i].ParName, &aaref);
      if ( EVEN(sts)) return sts;

      sts = configure_object_reset( ip, &aaref, 0);
      if ( EVEN(sts)) return sts;
    }
  }
  free( (char *)bodydef);

  return LDH__SUCCESS;
}
Beispiel #9
0
static pwr_tStatus ConfigureComponent( ldh_sMenuCall *ip) 
{
  pwr_tStatus sts;
  unsigned int disable_mask;
  pwr_sMenuButton   mb;
  pwr_tEnum graph_configuration;
  pwr_sAttrRef aaref;
  char vect[10][80];
  char item[3][80];
  int i;
  int nr;
  int vect_cnt;
  
  sts = ldh_ReadObjectBody(ip->PointedSession, ip->ItemList[ip->ChosenItem].MenuObject,
    "SysBody", &mb, sizeof(pwr_sMenuButton));

  // Reset previoius disable configuration
  configure_object_reset( ip, &ip->Pointed, &mb);

  // Set disable attributes from argument 0
  vect_cnt = dcli_parse( mb.MethodArguments[0], ",", "", (char *)vect, 
		   sizeof( vect) / sizeof( vect[0]), 
		   sizeof( vect[0]), 0);
  
  for ( i = 0; i < vect_cnt; i++) {
    nr = dcli_parse( vect[i], " 	", "", (char *)item,
		   sizeof( item) / sizeof( item[0]), 
		   sizeof( item[0]), 0);
    if ( nr == 1) {

      if ( sscanf( item[0], "%d", &disable_mask) != 1)
	graph_configuration = 0;

      sts = configure_object( ip, &ip->Pointed, disable_mask);
      if ( EVEN(sts)) return sts;
    }
    else if ( nr == 2) {
      pwr_tAName aname;

      if ( sscanf( item[1], "%d", &disable_mask) != 1)
	disable_mask = 0;

      strcpy( aname, item[0]);

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				 &aaref);
      if ( ODD(sts)) {
	sts = configure_object( ip, &aaref, disable_mask);
	if ( EVEN(sts)) return sts;
      }
    }
  }

  // Set GraphConfiguration from argument 1
  vect_cnt = dcli_parse( mb.MethodArguments[1], ",", "", (char *)vect, 
		   sizeof( vect) / sizeof( vect[0]), 
		   sizeof( vect[0]), 0);
  
  for ( i = 0; i < vect_cnt; i++) {
    nr = dcli_parse( vect[i], " 	", "", (char *)item,
		   sizeof( item) / sizeof( item[0]), 
		   sizeof( item[0]), 0);
    if ( nr == 1) {

      if ( sscanf( item[0], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, "GraphConfiguration", 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
    else if ( nr == 2) {
      pwr_tAName aname;

      if ( sscanf( item[1], "%d", &graph_configuration) != 1)
	graph_configuration = 0;

      strcpy( aname, item[0]);
      strcat( aname, ".GraphConfiguration");

      sts = ldh_ArefANameToAref( ip->PointedSession, &ip->Pointed, aname, 
				 &aaref);
      if ( ODD(sts)) {
	sts = ldh_WriteAttribute( ip->PointedSession, &aaref, (void *)&graph_configuration, 
				  sizeof(graph_configuration));
	if ( EVEN(sts)) return sts;
      }
    }
  }
  return 1;
}