Class EPICSUtilities

java.lang.Object
org.scictrl.csshell.epics.EPICSUtilities

public final class EPICSUtilities extends Object
Convenience method for work with JCA and CAJ.
Author:
igor@scictrl.com
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static long
    Seconds of epoch start since UTC time start.
  • Method Summary

    Modifier and Type
    Method
    Description
    static final void
    appendShortErrorReport.
    static Timestamp
    convertTimestamp(gov.aps.jca.dbr.TimeStamp ts)
    Converts CA timestamp to DAL timestamp.
    static Object
    convertToDBRValue(Object value, gov.aps.jca.dbr.DBRType type)
    Convert java object to DBR value of provided DBR type.
    static final boolean
    deepEquals.
    static final BitSet
    fromLong(long value)
    Converts long value to BitSet.
    static void
    put(gov.aps.jca.Channel channel, Object value)
    Puts value of Object parameter to the Channel.
    static void
    put(gov.aps.jca.Channel channel, Object value, gov.aps.jca.event.PutListener listener)
    Puts value of Object parameter to the Channel.
    static Object
    suggestDefaultValue(gov.aps.jca.dbr.DBRType type)
    Tries to create dummy default value for provided DBRType.
    static Object
    suggestDefaultValue(gov.aps.jca.dbr.DBRType type, int count)
    Tries to create dummy default value for provided DBRType
    static DataType
    toDataType(gov.aps.jca.dbr.DBR dbr)
    Get DBR type from java object.
    static DataType
    toDataType(gov.aps.jca.dbr.DBRType type, int count)
    toDataType.
    static Date
    toDate(gov.aps.jca.dbr.TimeStamp ts)
    Converts CA timestamp to UTC Java time.
    static gov.aps.jca.dbr.DBRType
    Get DBR type from java object.
    static Object
    toDBRValue(Object value, gov.aps.jca.dbr.DBRType originalType)
    Convert java object to DBR value, it does expect that Java value is already of right data type, so only repackaging is necessary, no deep value conversion is done.
    static double
    Returns double value if possible or Double.NaN
    int
    Returns integer value if possible or Integer.MIN_VALUE
    static <T> T
    toJavaValue(gov.aps.jca.dbr.DBR dbr, Class<T> javaType, gov.aps.jca.dbr.DBRType originalType)
    Convert DBR to Java object.
    static long
    Returns double value if possible or Double.NaN
    static final long
    toLong(BitSet value)
    Converts BitSet to long value if possible.
    static final MetaData
    toMetaData(gov.aps.jca.Channel channel, gov.aps.jca.dbr.DBR dbr)
    toMetaData.
    static final String
    Checks the given type and constructs the data type name, that the given type is associated with.
    static final Status
    toStatus(gov.aps.jca.dbr.DBR dbr)
    toStatus.
    static String
    toString(Object value, gov.aps.jca.dbr.DBRType type, int count)
    toString.
    static gov.aps.jca.dbr.DBRType
    toTimeDBRType(gov.aps.jca.dbr.DBRType type)
    Get TIME DBR type.
    static gov.aps.jca.dbr.DBRType
    Get TIME DBR type.
    static Timestamp
    toTimestamp(gov.aps.jca.dbr.DBR dbr)
    Tries to extract timestamp from DBR.
    static gov.aps.jca.dbr.TimeStamp
    toTimeStamp(long utc)
    Converts Java (UTC) time to EPICS CA Timestamp.
    static long
    toUTC(gov.aps.jca.dbr.TimeStamp ts)
    Converts CA timestamp to UTC Java time.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TS_EPOCH_SEC_PAST_1970

      public static long TS_EPOCH_SEC_PAST_1970
      Seconds of epoch start since UTC time start.
  • Method Details

    • suggestDefaultValue

      public static Object suggestDefaultValue(gov.aps.jca.dbr.DBRType type)
      Tries to create dummy default value for provided DBRType.
      Parameters:
      type - a DBRType object
      Returns:
      new dummy default, basically 0 or empty string wrapped in corresponding primitive data type
    • suggestDefaultValue

      public static Object suggestDefaultValue(gov.aps.jca.dbr.DBRType type, int count)
      Tries to create dummy default value for provided DBRType
      Parameters:
      type - the DBRType to which returned dummy should correspond
      count - the requested value count, must be larger than 0
      Returns:
      new dummy default, basically 0 or empty string wrapped in corresponding primitive data type
    • toJavaValue

      public static <T> T toJavaValue(gov.aps.jca.dbr.DBR dbr, Class<T> javaType, gov.aps.jca.dbr.DBRType originalType)
      Convert DBR to Java object.
      Type Parameters:
      T - a T class
      Parameters:
      dbr - DBR to convet.
      javaType - type to convert to.
      originalType - a DBRType object
      Returns:
      converted java object.
    • toDBRType

      public static gov.aps.jca.dbr.DBRType toDBRType(DataType type) throws gov.aps.jca.CAException
      Get DBR type from java object.
      Parameters:
      type - a DataType object
      Returns:
      DBR type.
      Throws:
      gov.aps.jca.CAException - remote exception
      NullPointerException - parameter is null
    • toDataType

      public static DataType toDataType(gov.aps.jca.dbr.DBR dbr)
      Get DBR type from java object.
      Parameters:
      dbr - a DBR object
      Returns:
      DBR type.
      Throws:
      NullPointerException - parameter is null
    • toDataType

      public static DataType toDataType(gov.aps.jca.dbr.DBRType type, int count)

      toDataType.

      Parameters:
      type - a DBRType object
      count - a int
      Returns:
      a DataType object
    • toDBRValue

      public static Object toDBRValue(Object value, gov.aps.jca.dbr.DBRType originalType)
      Convert java object to DBR value, it does expect that Java value is already of right data type, so only repackaging is necessary, no deep value conversion is done.
      Parameters:
      value - java object to convert.
      originalType - a DBRType object
      Returns:
      DBR value.
      Throws:
      NullPointerException - parameter is null
    • convertToDBRValue

      public static Object convertToDBRValue(Object value, gov.aps.jca.dbr.DBRType type)
      Convert java object to DBR value of provided DBR type.
      Parameters:
      value - java object to convert.
      type - the channel field type of converted value
      Returns:
      Object value.
      Throws:
      NullPointerException - parameter is null
    • toString

      public static String toString(Object value, gov.aps.jca.dbr.DBRType type, int count)

      toString.

      Parameters:
      value - a Object object
      type - a DBRType object
      count - a int
      Returns:
      a String object
    • toDouble

      public static double toDouble(Object v)
      Returns double value if possible or Double.NaN
      Parameters:
      v - a Object object
      Returns:
      double value if possible or Double.NaN
    • toLong

      public static long toLong(Object v)
      Returns double value if possible or Double.NaN
      Parameters:
      v - a Object object
      Returns:
      double value if possible or Double.NaN
    • toInteger

      public int toInteger(Object v)
      Returns integer value if possible or Integer.MIN_VALUE
      Parameters:
      v - a Object object
      Returns:
      integer value if possible or Integer.MIN_VALUE
    • toTimeDBRType

      public static gov.aps.jca.dbr.DBRType toTimeDBRType(DataType type) throws gov.aps.jca.CAException
      Get TIME DBR type.
      Parameters:
      type - DBR type.
      Returns:
      TIME DBR type
      Throws:
      gov.aps.jca.CAException - remote exception
      NullPointerException - parameter is null
    • toTimeDBRType

      public static gov.aps.jca.dbr.DBRType toTimeDBRType(gov.aps.jca.dbr.DBRType type)
      Get TIME DBR type.
      Parameters:
      type - DBR type.
      Returns:
      TIME DBR type or input type if failed to convert to TIME.
      Throws:
      NullPointerException - parameter is null
    • toUTC

      public static long toUTC(gov.aps.jca.dbr.TimeStamp ts)
      Converts CA timestamp to UTC Java time.
      Parameters:
      ts - CA timestamp
      Returns:
      Java UTC
    • convertTimestamp

      public static Timestamp convertTimestamp(gov.aps.jca.dbr.TimeStamp ts)
      Converts CA timestamp to DAL timestamp.
      Parameters:
      ts - CA timestamp
      Returns:
      DAL timestamp
    • toDate

      public static Date toDate(gov.aps.jca.dbr.TimeStamp ts)
      Converts CA timestamp to UTC Java time.
      Parameters:
      ts - CA timestamp
      Returns:
      Java UTC
    • toLong

      public static final long toLong(BitSet value)
      Converts BitSet to long value if possible.
      Parameters:
      value - the BitSet object
      Returns:
      long representatnion of the bit set
    • fromLong

      public static final BitSet fromLong(long value)
      Converts long value to BitSet.
      Parameters:
      value - the long value
      Returns:
      the BitSet corresponding to the value
    • put

      public static void put(gov.aps.jca.Channel channel, Object value) throws gov.aps.jca.CAException
      Puts value of Object parameter to the Channel.
      Parameters:
      channel - the Channel to put value to.
      value - the Object parameter to put to the Channel.
      Throws:
      gov.aps.jca.CAException - remote exception
      NullPointerException - parameter is null
    • put

      public static void put(gov.aps.jca.Channel channel, Object value, gov.aps.jca.event.PutListener listener) throws gov.aps.jca.CAException
      Puts value of Object parameter to the Channel.
      Parameters:
      channel - the Channel to put value to.
      value - the Object parameter to put to the Channel.
      listener - the PutListener to use (if null no listener is used)
      Throws:
      gov.aps.jca.CAException - remote exception
      NullPointerException - parameter is null
    • toShortErrorReport

      public static final String toShortErrorReport(Throwable t)
      Checks the given type and constructs the data type name, that the given type is associated with.
      Parameters:
      t - a Throwable object
      Returns:
      the datatype
    • appendShortErrorReport

      public static final void appendShortErrorReport(Throwable t, Appendable buffer) throws IOException

      appendShortErrorReport.

      Parameters:
      t - a Throwable object
      buffer - a Appendable object
      Throws:
      IOException - if any.
    • toMetaData

      public static final MetaData toMetaData(gov.aps.jca.Channel channel, gov.aps.jca.dbr.DBR dbr)

      toMetaData.

      Parameters:
      channel - a Channel object
      dbr - a DBR object
      Returns:
      a MetaData object
    • toTimestamp

      public static Timestamp toTimestamp(gov.aps.jca.dbr.DBR dbr)
      Tries to extract timestamp from DBR. If this fails, then current time is returned.
      Parameters:
      dbr - reciving DBR
      Returns:
      timestamp from DBR if possible or current local time
    • toTimeStamp

      public static gov.aps.jca.dbr.TimeStamp toTimeStamp(long utc)
      Converts Java (UTC) time to EPICS CA Timestamp.
      Parameters:
      utc - JAva time
      Returns:
      EPICS CA TimeStamp
    • toStatus

      public static final Status toStatus(gov.aps.jca.dbr.DBR dbr)

      toStatus.

      Parameters:
      dbr - a DBR object
      Returns:
      a Status object
    • deepEquals

      public static final boolean deepEquals(Object o1, Object o2)

      deepEquals.

      Parameters:
      o1 - a Object object
      o2 - a Object object
      Returns:
      a boolean