Пример #1
0
static void DeleteObjectYesCb (
  void *Ctx,
  void *CallbackData
) {
  ldh_sMenuCall *mc = (ldh_sMenuCall *)CallbackData;

  ldh_DeleteObjectTree(mc->PointedSession, mc->Pointed.Objid, 0);

  free ((char *) mc);
}
Пример #2
0
static void DeleteObjectsYesCb (
  void *Ctx,				
  void *CallbackData
) {
  ldh_sMenuCall	  *mc	  = (ldh_sMenuCall *)CallbackData;
  int		  i;

  for (i = 0; mc->SelectCount; i++) {	/* count number of selected objects */
    if (cdh_ObjidIsNull(mc->Selected[i].Objid))
      break;
    ldh_DeleteObjectTree(mc->PointedSession, mc->Selected[i].Objid, 0);
  }
  free((char *) mc->Selected);
  free((char *) mc);
}
Пример #3
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;
}