Examples of TDevice


Examples of de.desy.tine.server.devices.TDevice

    return filter;
  }
  private int metaprpQueryCall(String devName, TDataType dout, TDataType din, TAccess devAccess)
  { // use in calls for "METAPROPERTIES"
    int cc = 0, filter = getMetaPrpsCallFilter(din);
    TDevice dev = getDeviceList().getDevice(devName);
    LinkedList<String> lst = null;
   
    if (dev != null && (lst=dev.getPropertyList()) != null)
    {
      propertyList.setDeviceOriented(true);
      String[] slst = new String[lst.size()];
      lst.toArray(slst);
      LinkedList<TExportProperty> plst = new LinkedList<TExportProperty>();
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

    };
    TPropertyHandler devMaskHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          int[] newMask = new int[1];
          if ((cc=din.getData(newMask)) != 0) return cc;
          tdv.setMask(newMask[0]);         
          int[] m = new int[deviceList.getNumberOfDevices()];
          for (int i=0; i<m.length; i++) m[i] = deviceList.getDevice(i).getMask();
          saveStockPropertyValues("DEVMASK",devName,new TDataType(m));
        }               
        int mask = tdv.getMask();
        return dout.putData(mask);
      }     
    };
    TPropertyHandler devRegionHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          String[] newrg = new String[1];
          switch (din.dFormat)
          {
            case TFormat.CF_INT32:
              int[] irg = new int[1];
              if ((cc=din.getData(irg)) != 0) return cc;
              newrg[0] = TRegion.getRegion(irg[0]);
              break;
            default:
              if ((cc=din.getData(newrg)) != 0) return cc;
              break;
             
          }
          tdv.setRegion(newrg[0]);         
          int[] rg = new int[deviceList.getNumberOfDevices()];
          for (int i=0; i<rg.length; i++) rg[i] = deviceList.getDevice(i).getRegionCode();
          saveStockPropertyValues("DEVREGION",devName,new TDataType(rg));
        }
        switch (dout.dFormat)
        {
          case TFormat.CF_INT32:
            return dout.putData(tdv.getRegionCode());
          default:
            return dout.putData(tdv.getRegion());
        }
      }
    };   
    stockList.addProperty(TStockProperties.SRVSUBSYSTEM, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        String subs = getSubsystem();
        return dout.putData(subs == null ? "" : subs);
      }
    });
    TPropertyHandler alarmWatchStructHandler = new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        synchronized (gAlarmWatchList)
        {
          int almwtblsize = gAlarmWatchList.size();
          int awssize = TStructRegistry.getSizeInBytes("AWSr4");
          byte[] tba = new byte[almwtblsize * awssize];
          TAlarmWatchEntry[] aws = (TAlarmWatchEntry[])gAlarmWatchList.toArray(new TAlarmWatchEntry[0])
          if (devAccess.isWrite())
          {
            if (din.getFormat() != TFormat.CF_STRUCT) return TErrorList.illegal_format;
            if (din.getTag().compareTo("AWSr4") == 0)
            {
              TAlarmWatchEntry[] awe = new TAlarmWatchEntry[1];
              awe[0] = new TAlarmWatchEntry();
              din.getData(awe);
              awe[0].setEquipmentModule(getLocalName());
              boolean isNew = true;
              for (int i=0; i<aws.length; i++)
              {
                if (aws[i].equals(awe[0]))
                {
                  aws[i].adjustFrom(awe[0]);
                  isNew = false;
                  break;
                }
              }
              if (isNew)
              { // wasn't in list
                TExportProperty p = propertyList.getFirstProperty(awe[0].getPrp());
                if (p == null) return TErrorList.illegal_property;
                if (awe[0].getSiz() <= 0 || awe[0].getSiz() > p.getOutputSize())
                {
                  awe[0].setSiz(p.getOutputSize());
                }
                awe[0].setFmt(p.getOutputFormat());
                gAlarmWatchList.add(awe[0]);
              }
            }
            else
            {
              return TErrorList.invalid_structure_tag;           
            }
          }
          if (dout == null || dout.dArrayLength == 0) return 0;
          if (dout.dFormat != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (dout.getTag().compareTo("AWSr4") == 0)
          { // modern
            for (int i=0; i<almwtblsize; i++)
            {
              System.arraycopy(aws[i].toByteArray(), 0, tba, i*awssize, awssize);
            }
            if (almwtblsize < dout.getArrayLength()) dout.setArrayLength(almwtblsize);
            return dout.putData(tba, "AWSr4");
          }
          else
          {
            return TErrorList.invalid_structure_tag;
          }
        }
      }
    };
    stockList.addProperty(TStockProperties.NALARMS, new TPropertyHandler()
    {
      int nalmdefs = alarmDefinitionList.size();
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int devnr = -1;
       
        if (!devName.contains("*") && !devName.startsWith("#"))
        {
          devnr = deviceList.getDeviceNumber(devName);
        }
        if (casName != null  && !hasCasAttached) isCasInClientList();
        int[] nalms = new int[6];
        if (devnr < 0)
        { // all of them
          nalms[0] = deviceList.getNumberOfAlarms();
          nalms[1] = deviceList.getMostRecentAlarmTimestamp(nalms,3);
          nalms[2] = deviceList.getHighestAlarmSeverity(nalms,4);
          nalms[5] = nalmdefs;
          if (nalms[0] > TAlarm.getAlmCollapseWindow())
          {
            nalms[1] = almDynSet.timestamp;
            nalms[4] = nalms[3] = nalms[0] = 1;
          }
        }
        else
        { // just the device given ...
          int mrts = 0, ts, hsv = 0, sv, nts = 0, nsv = 0;
          TDevice[] dlst = deviceList.getDeviceList();
          if (devnr >= dlst.length) return TErrorList.device_not_connected;
          TAlarm[] alms = dlst[devnr].getAlarmList();
          nalms[0] = alms.length;
          for (int i=0; i<alms.length; i++)
          {
            if ((ts=alms[i].getTimeStamp()) > mrts)
            {
              mrts = ts;
              nts = 0;
            }
            if (ts == mrts) nts++;
            if ((sv=alms[i].getSeverity()) > hsv)
            {
              hsv = sv;
              nsv = 0;
            }
            if (sv == hsv) nsv++;
          }
          nalms[1] = mrts;
          nalms[2] = hsv;
          nalms[3] = nts;
          nalms[4] = nsv;
          nalms[5] = nalmdefs;
        }
        if (dout.dArrayLength > 5) nalms[5] = getAlarmDefinitionList().size();
        return dout.putData(nalms);
      }
    });
    stockList.addProperty(TStockProperties.NALARMDEFS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)alarmDefinitionList.size());
      }
    });
    stockList.addProperty(TStockProperties.NALMWATCH, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)gAlarmWatchList.size());
      }
    });
    stockList.addProperty(TStockProperties.ALARMS, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMSEXT, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMSEXT_STRUCTIN, alarmsStructHandler);
    stockList.addProperty(TStockProperties.ALARMDEFS, alarmDefsStructHandler);
    stockList.addProperty(TStockProperties.ALMWATCHTBL, alarmWatchStructHandler);
    stockList.addProperty(TStockProperties.NHISTORIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData((short)gLclHstList.size());
      }
    });
    stockList.addProperty(TStockProperties.HISTORIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return hstCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.HISTORIES_STRUCT, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return hstCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.ADDHISTORY, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (devAccess.isWrite())
        {
          if (din.getFormat() != TFormat.CF_STRUCT) return TErrorList.illegal_format;
          if (din.getTag().compareTo("HRSr4") == 0)
          {
            THistoryRecordStruct[] hrs = new THistoryRecordStruct[1];
            hrs[0] = new THistoryRecordStruct();
            din.getData(hrs);
            String prp = hrs[0].getProperty();
            String dev = hrs[0].getDevice();
            THistoryRecord hr = getLocalHistoryRecord(prp,dev);
            if (hr == null)            
            { // wasn't in list
              TExportProperty p = getPropertyList().getFirstProperty(prp);
              TPropertyDescription pd = p.getDescription();
              int at = pd != null ? pd.getArrayType() : TArrayType.AT_UNKNOWN;
              int idx = TEquipmentModuleFactory.getInstance().getNextHistoryRecordIndex();
              THistorySpecification hspec = new THistorySpecification(hrs[0].getPollingRate(), hrs[0].getArchiveRate(), hrs[0].getDepthShort(), hrs[0].getDepthLong(), hrs[0].getHeartbeat(), hrs[0].getPercentTolerance(), hrs[0].getAbsoluteTolerance(), null);
              addLocalHistoryRecord(idx, dev, prp, hrs[0].getSize(), hrs[0].getFormat(),at,hspec);
              dumpHistoryManifest();
            }
            else
            { // just an edit ...
              THistorySpecification hsp = hr.getHspec();
              hsp.setAbsoluteTolerance(hrs[0].getAbsoluteTolerance());
              hsp.setPercentTolerance(hrs[0].getPercentTolerance());
              hsp.setArchiveRate(hrs[0].getArchiveRate());
              hsp.setPollngRate(hrs[0].getPollingRate());
              hsp.setDepthLong(hrs[0].getDepthLong());
              hsp.setDepthShort(hrs[0].getDepthShort());
              hsp.setHeartbeat(hrs[0].getHeartbeat());
            }
            return 0;
          }
          else
          {
            return TErrorList.invalid_structure_tag;           
          }
        }
        return TErrorList.illegal_read_write;
      }            
    });
    stockList.addProperty(TStockProperties.ADDHISTORY_STR, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        if (devAccess.isWrite())
        {
          short fmt = din.getFormat();
          if (!TFormat.isName(fmt) && fmt != TFormat.CF_CHAR) return TErrorList.illegal_format;
          NAME64[] tgt = new NAME64[1];
          int cc = din.getData(tgt);
          if (cc != 0) return cc;
          String prp = tgt[0].getName();
          TExportProperty p = getPropertyList().getFirstProperty(prp);
          if (p == null) return TErrorList.invalid_property;
          int hfmt = p.getOutputFormat();
          int hsiz = p.getOutputSize();
          int idx = gEqmFactory.getNextHistoryRecordIndex(getLocalName(),prp,devName,hfmt,hsiz);
          addLocalHistoryRecord(idx, devName, prp, hsiz, hfmt);
          dumpHistoryManifest();
          return 0;
        }
        return TErrorList.illegal_read_write;
      }            
    });
    //TODO: finish these ...
    stockList.addProperty(TStockProperties.METAPROPERTIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return metaprpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.METAPROPS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return metaprpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.METAPROPERTIES_STRUCT, metapropertiesStructHandler);
    stockList.addProperty(TStockProperties.METAPROPS_STRUCT, metapropertiesStructHandler);
    stockList.addProperty(TStockProperties.DEVLOCATION, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          char[] newLocation = new char[64];
          if ((cc=din.getData(newLocation)) != 0) return cc;
          tdv.setLocation(new String(newLocation));         
          String[] loc = new String[deviceList.getNumberOfDevices()];
          for (int i=0; i<loc.length; i++) loc[i] = deviceList.getDevice(i).getLocation();
          saveStockPropertyValues("DEVLOCATION",devName,new TDataType(loc));
        }       
        String dloc = tdv.getLocation();
        if (dloc == null) dloc = gEqmFactory.getFecLocation();
        if (dloc != null && dloc.startsWith("<"))
        { /* redirection character */
          String rdrstr = null, envstr;
          dloc = dloc.substring(1); dloc.trim();
          if (dloc.startsWith("$"))
          {
            int idx = dloc.indexOf('/');
            if (idx < 0) idx = dloc.length();
            envstr = dloc.substring(1, idx);
            rdrstr = System.getenv(envstr);
            if (rdrstr == null) MsgLog.log("TEquipmentModule:DEVLOCATION", "environment variable "+envstr+" not set",TErrorList.not_defined,null,0);
            dloc = dloc.substring(idx);
          }
          if (rdrstr == null) rdrstr = "";
          rdrstr += dloc;
          if (rdrstr.indexOf('[') < 0) rdrstr += "[Location]";
          return gEqmFactory.setRedirectionString(rdrstr);
        }      
        return dout.putData(dloc == null ? "" : dloc);
      }
    });   
    stockList.addProperty(TStockProperties.DEVMASK, devMaskHandler);
    stockList.addProperty(TStockProperties.SYS_MASK, devMaskHandler);
    stockList.addProperty(TStockProperties.ZPOSITION, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          try
          {
            int cc = 0;
            float[] newZPos = new float[1];
            if ((cc=din.getData(newZPos)) != 0) return cc;
            tdv.setZposition(newZPos[0]);
            float[] zp = new float[deviceList.getNumberOfDevices()];
            for (int i=0; i<zp.length; i++) zp[i] = deviceList.getDevice(i).getZposition();
            saveStockPropertyValues("ZPOSITION",devName,new TDataType(zp));
          }
          catch (Exception x) { x.printStackTrace(); }
        }               
        float p = tdv.getZposition();
        return dout.putData(p);
      }
    });   
    stockList.addProperty(TStockProperties.DEVONLINE, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          int[] newFlg = new int[1];
          if ((cc=din.getData(newFlg)) != 0) return cc;
          tdv.setOffline(newFlg[0] == 0 ? true : false);         
          boolean[] m = new boolean[deviceList.getNumberOfDevices()];
          for (int i=0; i<m.length; i++) m[i] = !deviceList.getDevice(i).isOffline();
          saveStockPropertyValues("DEVONLINE",devName,new TDataType(m));
        }               
        boolean p = !tdv.isOffline();
        return dout.putData(p);
      }
    });   
    stockList.addProperty(TStockProperties.PROPERTIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return prpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.PROPERTIES_USTRING, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return prpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.PROPERTIES_STRUCT, propertiesStructHandler);
    stockList.addProperty(TStockProperties.PROPS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return prpQueryCall(devName,dout,din,devAccess);
      }
    });
    stockList.addProperty(TStockProperties.PROPS_USTRING, new TPropertyHandler()
        {
          public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
          {
            return prpQueryCall(devName,dout,din,devAccess);
          }
        });
    stockList.addProperty(TStockProperties.PROPS_STRUCT, propertiesStructHandler);
    stockList.addProperty(TStockProperties.NPROPERTIES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData(propertyList.countUniqueProperties());
      }
    });
    // Same as NPROPERTIES
    stockList.addProperty(TStockProperties.NPROPS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        return dout.putData(propertyList.countUniqueProperties());
      }
    });
    stockList.addProperty(TStockProperties.NDEVICES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        //return dout.putData(deviceList.size());
        return dout.putData(deviceList.getNumberOfDevices());
      }
    });
    stockList.addProperty(TStockProperties.DEVICES, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        String[] namlst;
        if (devName.compareTo("*") != 0 && devName.indexOf("*") != -1)
        { // query for a subset of device names ...
          WildcardMatch wc = new WildcardMatch(devName);
          TDevice dev;
          LinkedList<String> nl = new LinkedList<String>();
          String dn;
          int n = 0, mask = 0;
          if (din != null && din.dArrayLength == 1 && din.dFormat == TFormat.CF_INT32)
          {
            int[] msk = new int[1];
            din.getData(msk);
            mask = msk[0];
          }
          for (int i=0; i<deviceList.getNumberOfDevices(); i++)
          {
            if ((dev=deviceList.getDevice(i)) == null) continue;
            if (dev.isOffline()) continue;
            if (mask > 0 && !dev.isMaskSet(mask)) continue;
            dn = dev.getName();
            if (!wc.matches(dn)) continue;
            nl.add(dn);
            n++;
          }
          namlst = nl.toArray(new String[n]);
        }
        else
        {
          namlst = deviceList.getDeviceNameList();
        }
        int cc = dout.putData(StringToName.stringArrayToName64(namlst));
        if (cc == 0)
        {
          if (dout.getArrayLength() > namlst.length) dout.setArrayLength(namlst.length);
          if (getDeviceList().isPropertyOriented())
            cc = TErrorList.has_query_function | TErrorList.CE_SENDDATA;
        }
        return cc;
      }
    });
    stockList.addProperty(TStockProperties.DEVDESCRIPTION, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        TDevice tdv = deviceList.getDevice(devName);
        if (tdv == null) return TErrorList.illegal_device;
        if (din != null && devAccess.isWrite())
        {
          int cc = 0;
          char[] newDesc = new char[64];
          if ((cc=din.getData(newDesc)) != 0) return cc;
          tdv.setDescription(new String(newDesc));         
          String[] dsc = new String[deviceList.getNumberOfDevices()];
          for (int i=0; i<dsc.length; i++) dsc[i] = deviceList.getDevice(i).getDescription();
          saveStockPropertyValues("DEVDESCRIPTION",devName,new TDataType(dsc));
        }       
        String dsc = tdv.getDescription();
        return dout.putData(dsc == null ? "" : dsc);
      }
    });   
    stockList.addProperty(TStockProperties.DEVREGION, devRegionHandler);   
    stockList.addProperty(TStockProperties.DEVREGION_N64, devRegionHandler);   
    stockList.addProperty(TStockProperties.SRVSUBSYSTEM, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        String subs = getSubsystem();
        return dout.putData(subs == null ? "" : subs);
      }
    });   
    stockList.addProperty(TStockProperties.SRVIDLE, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int cc = 0;
        int[] idleState = new int[1];
        if (din != null && devAccess.isWrite())
        {
          if ((cc=din.getData(idleState)) != 0) return cc;
          isIdle = idleState[0] == 0 ? false : true;
        }
        if (dout != null && dout.dArrayLength > 0)
        {
          idleState[0] = isIdle ? -1 : 0;
          cc = dout.putData(idleState);
        }
        return cc;
      }
    });
    stockList.addProperty(TStockProperties.SRVINIT, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int cc = 0;
        if (!devAccess.isWrite()) return TErrorList.illegal_read_write;
        {
          if (eqpIni == null) return TErrorList.not_implemented;
          cc = eqpIni.initialize();
        }
        return cc;
      }
    });
    stockList.addProperty(TStockProperties.SRVADDR, new TPropertyHandler()
    {
      protected int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        NAME32[] n32 = new NAME32[dout.dArrayLength];
        String eqm, exp;
        TEquipmentModule eq;
        int cc = 0;
        if (gEqmFactory.isServiceRequest(moduleName))
        {
          NAME32[] tgt = new NAME32[3];
          if ((cc=din.getData(tgt)) != 0) return cc;
          String ctxName = tgt[0].getName();
          //String eqmName = tgt[1].getName();
          String expName = tgt[2].getName();
          if ((eq=gEqmFactory.getEquipmentModuleFromExportName(expName)) == null)
            return TErrorList.invalid_data;
          if (eq.context.compareToIgnoreCase(ctxName) != 0) return TErrorList.invalid_data;
          eqm = eq.moduleName;
          exp = eq.exportName;
        }       
        else
        {
          eqm = moduleName;
          exp = exportName;
        }
        cc = gEqmFactory.getSrvAddress(n32,eqm,exp);
        return (short) dout.putData(n32);
      }
    });
    stockList.addProperty(TStockProperties.USERS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        NAME16[] n16 = getRegisteredUsers();
        if (din != null && din.dArrayLength > 0)
        {
          if (!TFormat.isString(din.dFormat)) return TErrorList.illegal_format;
          char[] data = new char[TStrings.PROPERTY_NAME_SIZE];
          int cc = din.getData(data);
          if (cc != 0) return cc;
          String str = new String(data).trim();
          TExportProperty txp = getPropertyList().getFirstProperty(str);
          if (txp != null)
          { // property name given as input
            n16 = txp.getRegisteredUsers();
          }
          else
          { // maybe a device name then ...
            TDevice dev = getDeviceList().getDevice(str);
            if (dev != null) n16 = dev.getRegisteredUsers();
            else return TErrorList.invalid_keyword;
          }
        }
        if (n16 == null)
        {
          n16 = new NAME16[1];
          n16[0] = new NAME16("");
        }
        dout.dArrayLength = n16 == null ? 0 : n16.length;
        return n16 == null ? 0 : dout.putData(n16);
      }
    });
    stockList.addProperty(TStockProperties.NUSERS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        short n = (short)gRegisteredUsersList.size();
        if (din != null && din.dArrayLength > 0)
        {
          if (!TFormat.isString(din.dFormat)) return TErrorList.illegal_format;
          char[] data = new char[TStrings.PROPERTY_NAME_SIZE];
          int cc = din.getData(data);
          if (cc != 0) return cc;
          String str = new String(data).trim();
          TExportProperty txp = getPropertyList().getFirstProperty(str);
          if (txp != null)
          { // property name given as input
            n = (short)txp.getNumberRegisteredUsers();
          }
          else
          { // maybe a device name then ...
            TDevice dev = getDeviceList().getDevice(str);
            if (dev != null) n = (short)dev.getNumberRegisteredUsers();
            else return TErrorList.invalid_keyword;
          }
        }
        return dout.putData(n);
      }
    });
    stockList.addProperty(TStockProperties.ADDUSER, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int cc;
        if (din != null && devAccess.isWrite())
        {
          NAME16[] usr = new NAME16[1];
          if ((cc=din.getData(usr)) != 0) return cc;
          return addRegisteredUser(usr[0].getName());
        }
        return TErrorList.illegal_read_write;
      }
    });
    stockList.addProperty(TStockProperties.DELUSER, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        int cc;
        if (din != null && devAccess.isWrite())
        {
          NAME16[] usr = new NAME16[1];
          if ((cc=din.getData(usr)) != 0) return cc;
          return removeRegisteredUser(usr[0].getName());
        }
        return TErrorList.illegal_read_write;
      }
    });
    stockList.addProperty(TStockProperties.IPNETS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        NAME16[] n16 = getRegisteredNets();
        if (din != null && din.dArrayLength > 0)
        {
          if (!TFormat.isString(din.dFormat)) return TErrorList.illegal_format;
          char[] data = new char[TStrings.PROPERTY_NAME_SIZE];
          int cc = din.getData(data);
          if (cc != 0) return cc;
          String str = new String(data).trim();
          TExportProperty txp = getPropertyList().getFirstProperty(str);
          if (txp != null)
          { // property name given as input
            n16 = txp.getRegisteredNets();
          }
          else
          { // maybe a device name then ...
            TDevice dev = getDeviceList().getDevice(str);
            if (dev != null) n16 = dev.getRegisteredNets();
            else return TErrorList.invalid_keyword;
          }
        }
        dout.dArrayLength = n16 == null ? 0 : n16.length;
        return n16 == null ? 0 : dout.putData(n16);
      }
    });
    stockList.addProperty(TStockProperties.NIPNETS, new TPropertyHandler()
    {
      public int call(String devName, TDataType dout, TDataType din, TAccess devAccess)
      {
        short n = (short)gRegisteredNetsList.size();
        if (din != null && din.dArrayLength > 0)
        {
          if (!TFormat.isString(din.dFormat)) return TErrorList.illegal_format;
          char[] data = new char[TStrings.PROPERTY_NAME_SIZE];
          int cc = din.getData(data);
          if (cc != 0) return cc;
          String str = new String(data).trim();
          TExportProperty txp = getPropertyList().getFirstProperty(str);
          if (txp != null)
          { // property name given as input
            n = (short)txp.getNumberRegisteredUsers();
          }
          else
          { // maybe a device name then ...
            TDevice dev = getDeviceList().getDevice(str);
            if (dev != null) n = (short)dev.getNumberRegisteredNets();
            else return TErrorList.invalid_keyword;
          }
        }
        return dout.putData(n);
      }
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

  {
    if (numberOfDevices <= 0) return;
    TDevice[] devices = new TDevice[numberOfDevices];
    for (int i=0; i<numberOfDevices; i++)
    {
      devices[i] = new TDevice(i);
      devices[i].setEqm(this);
      deviceList.addDevice(devices[i]);
    }
  }
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

                catch (Exception ignore) {}; // then mask stays = 0
              }
            }
            if (chkOn || chkMask)
            {
              TDevice dev;
              LinkedList<String> dl = new LinkedList<String>();
              for (int i=0; i<deviceList.getNumberOfDevices(); i++)
              {
                if ((dev=deviceList.getDevice(i)) == null) continue;
                if (chkOn && dev.isOffline()) continue;
                if (chkMask && !dev.isMaskSet(mask)) continue;
                dl.add(dev.getName());
              }
              slst = dl.toArray(new String[0]);
            }
          }
          return (short)dout.putData(StringToName.stringArrayToName64(slst));
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

          int ndevs = dlst.getNumberOfDevices();
          if (ndevs == 0) return TErrorList.device_not_connected;
          LinkedList<DeviceCfg> dl = ec.getDeviceList();
          for (DeviceCfg dc : dl)
          {
            TDevice tdv = dlst.getDevice(dc.getNumber().getValue());
            if (tdv == null) return TErrorList.device_not_connected;
            prpSet = dc.getPropertySet();
            if (prpSet != null && prpSet.length() > 0)
            { // is there a device-specific property list ?
              for (NameCfgList nc : nl)
              { // yes ! find it
                if (nc.getName().compareToIgnoreCase(prpSet) == 0)
                { // assign the names list
                  tdv.setPropertyList(nc.getMembers());
                }
              }
              propertyList.setDeviceOriented(true);
            }
            String oldName = tdv.getName();
            if (dc.getName().compareTo(oldName) != 0)
            {
              dlst.renameDevice(oldName,dc.getName());
            }
            deviceRedirection = dc.getRedirection();
            if (deviceRedirection != null && deviceRedirection.length() > 0)
            {
              tdv.setRedirection(deviceRedirection);
              deviceRedirection = null; // reset this !
            }
            deviceDescription = dc.getDescription();
            if (deviceDescription != null && deviceDescription.length() > 0)
            {
              tdv.setDescription(deviceDescription);
              deviceDescription = null; // reset this !
            }
            deviceRegion = dc.getRegion();
            if (deviceRegion != null && deviceRegion.length() > 0)
            {
              tdv.setDescription(deviceRegion);
              deviceRegion = null; // reset this !
            }
          }
          break;
        }
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

      int ndevs = dlst.getNumberOfDevices();
      if (ndevs == 0) return TErrorList.device_not_connected;
      if (deviceNumber < 0 && deviceNumber >= ndevs) return TErrorList.illegal_equipment_number;
      if (!isPrpOriented)
      {
        TDevice tdv = dlst.getDevice(deviceNumber);
        if (tdv == null) return TErrorList.device_not_connected;
        String oldName = tdv.getName();
        if (deviceName.compareTo(oldName) != 0)
        {
          dlst.renameDevice(oldName,deviceName);
        }
        if (deviceRedirection != null && deviceRedirection.length() > 0)
        {
          tdv.setRedirection(deviceRedirection);
          deviceRedirection = null; // reset this !
        }
        if (deviceDescription != null && deviceDescription.length() > 0)
        {
          tdv.setDescription(deviceDescription);
          deviceDescription = null; // reset this !
        }
        if (prpListFile != null && prpListFile.length() > 0)
        {
          getRegisteredPropertyListFromFile(tdv,prpListFile);
          propertyList.setDeviceOriented(true);
          prpListFile = null; // reset this !
        }
        if (deviceLocation != null && deviceLocation.length() > 0)
        {
          tdv.setLocation(deviceLocation);
        }
        if (deviceMask != 0) tdv.setMask(deviceMask);
        if (deviceOffline != 0) tdv.setOffline(true);
        if (deviceRegion == null || deviceRegion.length() == 0)
        { // take the common setting if not set per device ...
          deviceRegion = region;
        }
        tdv.setRegion(deviceRegion);
        if (deviceZPosition != 0) tdv.setZposition(deviceZPosition);
      }
      else
      {
        if (prp != null)
        {
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

            atag += ": "+addstr;
          } catch (Exception e) {}
        }
      }
      pushString(atag,alarmTag);
      TDevice dv = eqm.getDevice(dev);
      alarmMask[0] = (dv != null) ? dv.getRegionCode() : TRegion.DEV_REGION_CENTRAL;
      alarmDataFormat[0] = (byte)adef.getAlarmDataFormat();
      alarmDataArraySize[0] = (byte)adef.getAlarmDataArraySize();
      severity[0] = (byte)adef.getAlarmSeverity();
      alarmSystem[0] = (short)adef.getAlarmSystem();
      alarmOscillationWindow[0] = (byte)adef.getAlarmOscillationWindow();
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

      int ndevs = dlst.getNumberOfDevices();
      if (ndevs == 0) return TErrorList.device_not_connected;
      if (deviceNumber < 0 && deviceNumber >= ndevs) return TErrorList.illegal_equipment_number;
      if (!isPrpOriented)
      {
        TDevice tdv = dlst.getDevice(deviceNumber);
        if (tdv == null) return TErrorList.device_not_connected;
        String oldName = tdv.getName();
        if (deviceName.compareTo(oldName) != 0)
        {
          dlst.renameDevice(oldName,deviceName);
        }
        if (deviceRedirection != null && deviceRedirection.length() > 0)
        {
          tdv.setRedirection(deviceRedirection);
          deviceRedirection = null; // reset this !
        }
        if (deviceDescription != null && deviceDescription.length() > 0)
        {
          tdv.setDescription(deviceDescription);
          deviceDescription = null; // reset this !
        }
        if (prpListFile != null && prpListFile.length() > 0)
        {
          getRegisteredPropertyListFromFile(tdv,prpListFile);
          propertyList.setDeviceOriented(true);
          prpListFile = null; // reset this !
        }
        if (deviceLocation != null && deviceLocation.length() > 0)
        {
          tdv.setLocation(deviceLocation);
        }
        if (deviceMask != 0) tdv.setMask(deviceMask);
        if (deviceOffline != 0) tdv.setOffline(true);
        if (deviceZPosition != 0) tdv.setZposition(deviceZPosition);
      }
      else
      {
        if (prp != null)
        {
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

    TDataType din = new TDataType();
    TAccess access = new TAccess(TAccess.CA_ALARM + TAccess.CA_READ);
    TAlarmWatchEntry awe = null;
    TAlarmDefinition adef = null;
    TAlarm alm = null;
    TDevice dev = null;
    int cc = 0, cnt = 0, siz = 0, sev = 0, devNr, code = 0, asys = 0;
    String tag = null;
    float fvals[] = null;
    int ivals[] = null;
    byte[] abytes = null;
    synchronized (gAlarmWatchList)
    {
      TEquipmentModuleFactory f = getEquipmentModuleFactory();
      f.setCurrentContractEntry(f.awtcon);
      int awlength = gAlarmWatchList.size();
      for (int i=0; i<awlength; i++)
      {
        awe = (TAlarmWatchEntry)gAlarmWatchList.get(i);
        int chk = awe.checkNormal();
        if (chk != 0)
        {
          ivals = new int[awe.getSiz()];
          dout = new TDataType(ivals);
          cc = callProperty(awe.getPrp(),awe.getDev(),dout,din,access);
        }
        else
        {
          fvals = new float[awe.getSiz()];
          dout = new TDataType(fvals);
          cc = callProperty(awe.getPrp(),awe.getDev(),dout,din,access);
        }
        if (cc != 0) continue;
        boolean hasAlarm = false;
        devNr = deviceList.getDeviceNumber(awe.getDev());
        cnt = 0; siz = awe.getSiz();
        for (int j=0; j<siz; j++)
        {
          if (awe.getAtyp() == TArrayType.AT_CHANNEL) devNr = j;
          if (awe.getAtyp() != TArrayType.AT_WAVEFORM && siz == deviceList.getNumberOfDevices())
            devNr = j; /* assume array of devices */
          dev = deviceList.getDevice(devNr);
          hasAlarm = false;
          if (ivals != null)
          {   
            int nval = awe.getNormal();
            if ((chk == 1 && nval != (awe.getMask() & ivals[j])) ||
                (chk == -1 && nval == (awe.getMask() & ivals[j])) )
            {
             if (TEquipmentModuleFactory.debugLevel > 1)
               DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
                   " alarm state ! : "+(awe.getMask() & ivals[j])+" vs "+nval);
              code = awe.getCode();
              if (code == 0) code = TErrorList.invalid_data;
              sev = awe.getSev();
              asys = awe.getAsys();
              hasAlarm = true;
            }
            abytes = Swap.LongToBytes(ivals[j]);
          }
          else if (fvals != null)
          {
            if (fvals[j] > awe.getHi())
            {
              if (TEquipmentModuleFactory.debugLevel > 1)
                DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
                    " alarm state ! : "+fvals[j]+" > "+awe.getHi());
              code = awe.getCode();
              if (code == 0) code = awe.getCodeHigh();
              if (code == 0) code = TErrorList.value_too_high;
              sev = awe.getSev();
              asys = awe.getAsys();
              tag = awe.getTagHigh();
              hasAlarm = true;
            }
            else if (fvals[j] > awe.getHiwarn())
            {
              if (TEquipmentModuleFactory.debugLevel > 1)
                DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
                    " warn state ! : "+fvals[j]+" > "+awe.getHiwarn());
              code = awe.getCode();
              if (code == 0) code = awe.getCodeHigh();
              if (code == 0) code = TErrorList.warn_too_high;         
              sev = awe.getSev()-2;
              asys = awe.getAsys();
              tag = awe.getTagHigh();
              hasAlarm = true;
            }
            else if (fvals[j] < awe.getLo())
            {
              if (TEquipmentModuleFactory.debugLevel > 1)
                DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
                    " alarm state ! : "+fvals[j]+" < "+awe.getLo());
              code = awe.getCode();
              if (code == 0) code = awe.getCodeLow();
              if (code == 0) code = TErrorList.value_too_low;         
              sev = awe.getSev();
              asys = awe.getAsys();
              tag = awe.getTagLow();
              hasAlarm = true;
            }
            else if (fvals[j] < awe.getLowarn())
            {
              if (TEquipmentModuleFactory.debugLevel > 1)
                DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
                    " warn state ! : "+fvals[j]+" < "+awe.getLowarn());
              code = awe.getCode();
              if (code == 0) code = awe.getCodeLow();
              if (code == 0) code = TErrorList.warn_too_low;         
              sev = awe.getSev()-2;
              asys = awe.getAsys();
              tag = awe.getTagLow();
              hasAlarm = true;
            }
            abytes = Swap.Float(fvals[j]);
          }
          if (!hasAlarm)
          { // run through clearAlarm()
            dev.clearAlarm(TErrorList.invalid_data,awe);
            dev.clearAlarm(TErrorList.value_too_high,awe);
            dev.clearAlarm(TErrorList.value_too_low,awe);
            dev.clearAlarm(TErrorList.warn_too_high,awe);
            dev.clearAlarm(TErrorList.warn_too_low,awe);
            if (awe.getCode() > 0) dev.clearAlarm(awe.getCode(),awe);
            if (awe.getCodeHigh() > 0) dev.clearAlarm(awe.getCodeHigh(),awe);
            if (awe.getCodeLow() > 0) dev.clearAlarm(awe.getCodeLow(),awe);
            continue;
          }
          if (code == 0) continue;
          cnt = awe.getCnt() + 1;
          awe.setCnt(cnt);
          if (cnt > awe.getCntThreshold() && dev != null)
          {
            alm = dev.setAlarm(code,abytes,awe);
            if (alm != null)
            {
              adef = alm.getAlmDef();
              if (sev != 0) adef.setAlarmSeverity(sev);
              if (asys != 0) adef.setAlarmSystem(asys);
View Full Code Here

Examples of de.desy.tine.server.devices.TDevice

   * Registers the equipment module's stock properties
   */
  private int prpQueryCall(String devName, TDataType dout, TDataType din, TAccess devAccess)
  { // use in calls for "PROPS" or "PROPERTIES"
    int cc = 0;
    TDevice dev = getDeviceList().getDevice(devName);
    LinkedList<String> lst = null;
    boolean checkWildCard = (devName.compareTo("*") != 0 && devName.indexOf("*") != -1);
   
    if (dev != null && (lst=dev.getPropertyList()) != null)
    {
      String[] slst = new String[lst.size()];
      lst.toArray(slst);
      if (checkWildCard) slst = StringToName.matchStringsInArray(slst,devName);
      if (dout.getFormat() == TFormat.CF_USTRING)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.