Difference between revisions of "V4 DBD Statement Syntax"

From EPICSWIKI
Line 1: Line 1:
Record Instance Syntax Sept 22 2005
DBD Statement Syntax Sept 27 2005
= Overview =
= Overview =
This document presents the syntax for V4 database definition files.
<center>
= General Statements =
</center>


== include ==


The syntax used for record instances has to change in EPICS V4, since we now have to support structured data. While it would have been possible to modify the V3 syntax to allow for this, a complete redesign of the syntax has been done to help improve parsing, and to provide commonality between the syntax of a DB file and the string representation of structured data values passed through Channel Access.
include "filename"


where


= Document Conventions =
; <tt>filename</tt>
: must be a valid filename


This syntax is presented below in the form of a grammar. The conventions I'm using are as follows:
The file system search path that will be used to look for the file is determined by the build system, and cannot be modified by the DBD file itself.


;''symbolBeingDefined:''
Include statements can be used at the top level, or inside the braces of a <tt>menu</tt>, <tt>struct</tt> or <tt>record</tt> definition.
: ''otherSymbol''
: ''alternateSymbolFollowedBy'' <tt>literal</tt>
: ''one of:'' <tt>list of posible literal values</tt>


== # comment ==


= Common Symbols =
# anything


The symbols described in this section are used in the grammar, but may be implemented as lexical tokens.
Anything on a line after a <tt>#</tt> character is a comment, and will be ignored. Comments may appear on a line by themselves, or at the end of another statement.  They may not appear inside the parentheses belonging to another statement, but they are permitted inside braces. Inside a single- or double- quoted string the <tt>#</tt> character has no special meaning.


;''identifier:''
: A legal C99 identifier. Note that C99 permits implementations to allow extended characters to be used in identifiers, but does not require it, so the use of extended characters may reduce portability and is not recommended.


== Integer Constants ==
== menu ==


;''integerConstant:''
A menu is an enumerated type where the choice strings are defined once for each IOC.  Menus are defined like this:
: ''positiveInteger''


;''positiveInteger:''
menu(menuName) {
: ''octalConstant''
    choice(choiceName, "choiceValue")
: ''hexConstant''
    ...
: ''decimalConstant''
}


;''octalConstant:''
where
: <tt>0</tt>
: ''octalConstant'' ''octalDigit''


;''octalDigit:''
; <tt>menuName</tt>
: ''one of:'' <tt>0-7</tt>
: Must be a valid, unique C identifier.
; <tt>choiceName</tt>
: Must be a valid, unique C identifier. By convention, every choiceName should start with the menuName it belongs to. These names are only available to C/C++ source code using the header file generated from the menu definition; they are not stored in the IOC itself.
; <tt>choiceValue</tt>
: Can be any UTF-8 compatible string, which should be unique within the context of this menu.


;''hexConstant:''
In general menus should only be definable once, in the DBD file (first definition seen wins in the event of duplicates, give a warning for duplicates and error if subsequent definition is different).  However we may want to include a syntax that allows specific menu definitions to be extended at database load time.
: <tt>0x</tt> ''hexDigit''
: <tt>0X</tt> ''hexDigit''
: ''hexConstant'' ''hexDigit''


;''hexDigit:''
Example:
: ''one of:'' <tt>0-9 a-f A-F</tt>


;''decimalConstant:''
menu(menuScan) {
: ''one of:'' <tt>1-9</tt>
    choice(menuScanPassive, "Passive")
: ''decimalConstant'' ''decimalDigit''
    choice(menuScanEvent, "Event")
    choice(menuScanInterrupt, "Interrupt")
    choice(menuScan10second, "10 second")
    choice(menuScan5second, "5 second")
    choice(menuScan2second, "2 second")
    choice(menuScan1second, "1 second")
    choice(menuScan_5second, ".5 second")
    choice(menuScan_2second, ".2 second")
    choice(menuScan_1second, ".1 second")
}


;''decimalDigit:''
<center>
: ''one of:'' <tt>0-9</tt>
= Structures, Record types, Fields and Views =
</center>


This was meant to be a description of the C99 standard integer representation, but I made it up myself so it may be flawedNote that we will not accept the C99 numeric suffixes u/U and l/L since (unlike a C compiler) we know the type of the number we're expecting.
Structures and record types have significant commonality in that they both define a data structure type containing fieldsThe main difference is that you can't create or populate an instance of a structure outside of a record; only records can appear at the very top level.  Record types also define views of the record, which is not possible for a structure.


== Floating Point Constants ==
== struct ==


;''realConstant:''
A structure is defined as follows:
:'' positiveReal''
: <tt>-</tt> ''positiveReal''


;''positiveReal:''
struct(name) {
: ''digitSequence''
    field(fieldName, fieldType) {
: ''digitSequence'' <tt>.</tt>
        fieldAttribute(attributeValue)
: ''digitSequence'' <tt>.</tt> ''exponentPart''
        ...
: ''digitSequence'' <tt>.</tt> ''digitSequence''
    }
: ''digitSequence'' <tt>.</tt> ''digitSequence'' ''exponentPart''
    ...
: <tt>.</tt> ''digitSequence''
}
: <tt>.</tt> ''digitSequence'' ''exponentPart''
: ''digitSequence'' ''exponentPart''


;''digitSequence:''
where
: ''decimalDigit''
: ''digitSequence'' ''decimalDigit''


;''exponentPart:''
; <tt>name</tt>
: <tt>e</tt> ''signedExponent''
: The structure name must be a valid, unique C identifier.
: <tt>E</tt> ''signedExponent''
; <tt>fieldName</tt>
: Must be a valid C identifier, unique within the context of this particular structure.
; <tt>fieldType</tt>
: See [[#fieldType|fieldType]] below.
; <tt>fieldAttribute</tt> and <tt>attributeValue</tt>
: See [[#fieldAttribute|fieldAttribute]] below.


;''signedExponent:''
== record ==
: <tt>-</tt> ''digitSequence''
: <tt>+</tt> ''digitSequence''
: ''digitSequence''


In ANSI C source code, a sequence of decimal digits with neither a decimal point nor an exponent is an integer constant, not a floating-point constant.  We will permit this however, since we always know the field type in advance.
A record type is defined as follows:


== Boolean Constants ==
include "dbCommon.dbd"
record(name) extends RecordCommon {
    field(fieldName, fieldType) {
        fieldAttribute(attributeValue)
        ...
    }
    ...
    view(viewName) {
        property(propName, fieldPath)
        ...
    }
    ...
}


We can afford to be generous in what we accept as a boolean value:
; <tt>name</tt>
: The record type name. It must be a valid, unique C identifier.
; <tt>extends RecordCommon</tt>
: This states that the record type extends the set of fields defined in "V4 DB RecordCommon". It should be permissable to name other record types instead of RecordCommon here, as long as the inheritance tree starts at RecordCommon.  Inheritance from multiple record types is not supported; you can only have one <tt>extends</tt> phrase.
; <tt>fieldName</tt>
: Must be a valid C identifier, unique within the context of this particular record type and its parents (extends ...).
; <tt>fieldType</tt>
: See [[#fieldType|fieldType]] below.
; <tt>fieldAttribute</tt> and <tt>attributeValue</tt>
: See [[#fieldAttribute|fieldAttribute]] below.
; <tt>viewName</tt>, <tt>propName</tt> and <tt>fieldPath</tt>
: See [[#Views of a record|Views of a record]] below.


;''booleanConstant:''
== fieldType ==
: ''booleanTrue''
: <tt>"</tt> ''booleanTrue'' <tt>"</tt>
: ''booleanFalse''
: <tt>"</tt> ''booleanFalse'' <tt>"</tt>


;''booleanTrue:''
Both <tt>struct</tt> and <tt>record</tt> define a field as:
: ''one of:'' <tt>1 T TRUE t true True Y YES Yes y yes</tt>
    field(fieldName, fieldType) {
        fieldAttribute(attributeValue)
        ...
    }


;''booleanFalse:''
The syntax for <tt>fieldType</tt> depends of the field type.  For the more complex types the field definition needs additional information to be provided, which is given inside parentheses following the type name.
: ''one of:'' <tt>0 F FALSE f false False N NO No n no</tt>


'''I'm proposing all these possibilities for true/false as they are all obvious in meaning, and will allow a CA Put of any of these strings to a boolean field. We might even want to allow registration of boolean strings in other languages...'''
<blockquote>


== String Constants ==
=== Basic types: octet, boolean, numerics, and string ===


;''stringConstant:''
The following field types have no arguments:
: <tt>"</tt> ''escapedCharacterList'' <tt>"</tt>
<tt>octet</tt>, <tt>bool</tt>, <tt>int16</tt>, <tt>int32</tt>,  <tt>int64</tt>,
<tt>float32</tt>, <tt>float64</tt>,  and <tt>string</tt>.


;''escapedCharacterList:''
Examples:  
: A series of characters, using the C99 ''escapeSequence'' syntax defined below:
    field(description,string)
    field(value,float64)


;''escapeSequence:''
=== enum ===
: ''simpleEscapeSequence''
: ''octalEscapeSequence''
: ''hexEscapeSequence''
: ''universalCharacterName''


;''simpleEscapeSequence:''
An <tt>enum</tt> field takes one argument after the type name:
: ''one of:'' <tt>\' \" \? \\ \a \b \f \n \r \t \v</tt>


;''octalEscapeSequence:''
    enum(fieldName)
: <tt>\</tt> ''octalDigit''
: <tt>\</tt> ''octalDigit'' ''octalDigit''
: <tt>\</tt> ''octalDigit'' ''octalDigit'' ''octalDigit''


;''hexEscapeSequence:''
where fieldName is the name of another field in the same record that must be of type <tt>array(string[])</tt>.  The values in this other field at runtime define the available choice strings for the enum field.
: <tt>\x</tt> ''hexDigit''
: ''hexEscapeSequence'' ''hexDigit''


Note: C99 does not limit the number of hexadecimal digits that can appear in a ''hexEscapeSequence'', but it does state that the behaviour is undefined if the resulting character value exceeds that of the largest character.
Examples:


;''universalCharacterName:''
    field(choices, array(string[])
: <tt>\u</tt> ''hexQuad''
    field(value, enum(choices))
: <tt>\U</tt> ''hexQuad'' ''hexQuad''


;''hexQuad:''
=== menu ===
: ''hexDigit'' ''hexDigit'' ''hexDigit'' ''hexDigit''


A <tt>menu</tt> field is defined like this:
    menu(menuName)


= Database File =
where <tt>menuName</tt> is the name of the menu.


This section will eventually define what can appear in a .db file.  That currently means:
Example:
    field(scan, menu(menuScan))


* record instances
=== struct ===
* comments
* macro instances, including where they will be allowed
* template files and substitution macro definitions
* port definitions for template instances
* data for tools such as VDCT, that will not be discarded by .db processing tools.


The templates, macros and ports design should be very similar to the ideas produced for R3.14 VDCT templates.
A <tt>struct</tt> field is declared using the type name
    struct(structName)


= Record Definitions =
where <tt>structName</tt> is the name of a struct which must have been previously defined.


;''recordDefinition:''
: ''recordType'' ''recordName'' <tt>= {</tt> ''recordBody'' <tt>}</tt>


;''recordType:''
Example:
: ''identifier''
      struct(Point) {
          field(x,float64)
          field(y,float64)
          field(z,float64)
      }
      ...
      record(haspoint) extends RecordCommon {
          ...
          field(point, struct(point))
      }


;''recordName:''
=== array ===
: ''recordNameChar''
: ''recordName'' ''recordNameChar''


;''recordNameChar:''
An array field uses definitions like these:
: ''one of:'' <tt>0-9 A-Z a-z _ - : ; < > [ ]</tt>
: Any Unicode/UTF-8 character outside of the Basic Latin set


This extends the character set available to a V3 record name, adding all possible multi-byte characters. However, EPICS sites are strongly advised to confirm that such record names can be processed using all of their database and CA client tools before actually making use of this particular extension.
; 1-dimensional array
: <tt>array(arrayType[capacity])</tt>
; multi-dimensional array
: <tt>array(arrayType[capacityX, capacityY, ...])</tt>
; arbitrarily dimensioned array
: <tt>array(arrayType)</tt>


;''recordBody:''
; 1-dimensional array of unknown size
: ''recordBodyItem''
: <tt>array(arrayType[])</tt>
: ''recordBody'' ''recordBodyItem''
; 3-dimensional array of unknown size
: <tt>array(arrayType[,,])</tt>


Record instance definitions in EPICS V4 look very similar to a C99 structure definition with initialization. For example:
; 1-dimensional array of unknown type
: <tt>array([capacity])</tt>
; multi-dimensional array of unknown type
: <tt>array([capacityX, capacityY, ...])</tt>
; arbitrarily dimensioned array of unknown type
: <tt>array()</tt>


  ai foo:bar:temperature = {
; 1-dimensional array of unknown type or size
      ...
: <tt>array([])</tt>
  }
; 2-dimensional array of unknown type or size
: <tt>array([,])</tt>
 
* <tt>arrayType</tt> may be any fieldType except <tt>array</tt>, or may be omitted completely in which case the data type stored is determined by record instance. If the record instance defines the type, it can only be one of the types listed above under [[#Basic types: boolean, numerics, octet, and string|Basic types]]
* <tt>capacity</tt> is the array's size in the relevent dimension, and must be specified for all dimensions or for none. If not specified by the record type, the record instance determines an array's dimensionality and size.
 
Examples:
    field(VAL1D,array(float64[]))  #1d array with arbitrary capacity
    field(VAL2D,array(float64[,])) #2d array with arbitrary capacities
    field(anyTypeAnyD,array())    #arbitrary type,number of dimensions, and capacities
 
=== link ===
 
This field type can get or put data from/to some source outside of the record.
Link fields replace the DBF_INLINK, DBF_OUTLINK, and DTYP fields from EPICS V3.


Inside the body of the record definition, there are three possible kinds of statements, similar to a C assignment statement. Note these statements must be terminated with a semi-colon (which is different from inside a struct).  The reason for this difference is to prevent database instance files from becoming dependent on the order of fields in a record; if we permit record instances to be created from a single comma-separated list of field values without the field names, it could lead to significant confusion if the field order ever changes.
A link field's choices come from link definitions - see the [[#link]] section below for more details.
A link can be a link to another database record, to hardware device support,
or something else.


;''recordBodyItem:''
The syntax is:
: ''infoAssignment''
: ''fieldAssignment''
: ''extraFieldAssigment''


== Information Fields ==
    link(linkDirection,array(string[])= {name,...})


;''infoAssignment:''
where
: <tt>info</tt> ''infoName'' <tt>=</tt> ''stringConstant'' <tt>;</tt>
* <tt>linkDirection</tt> : <tt>none</tt>, <tt>in</tt>, <tt>out</tt>, <tt>process</tt>, or <tt>inout</tt>. The direction <tt>none</tt> means there is no direction associated with this interface.  For <tt>inout</tt> the direction is determined by the particular <tt>link</tt> that the record instance selects.
* <tt>array(string[])</tt> : Each string is the name of Link Interface implemented by link support and used by record support.


;''infoName:''
Examples:
: ''identifier''
    field(disableLink,
: ''stringConstant''
        link(in,array(string[4]) = {
          "monitorLinkInt32",
          "inputLinkInt32",
          "monitorLinkFloat64",
          "inputLinkFloat64"
        } ))
    )
    field(process, link(process,array(string[1])= {processLink}))
    field(inp,
        link(in, array(string[3]) = {
          "monitorLinkInt32",
          "inputLinkInt32",
            "digitalIO"
        }))
    )
</blockquote>


Info items provide additional configuration data about this record that can be accessed by other software running on the IOC.
<b>Andrew: Do we want the above syntax? Another possibility is just:
    link(linkDirection,interface(string,...))
</b>


  info savePeriod = "30.0";
== fieldAttribute ==
  info restorePhase = "1";
  info "my favourite things" = "raindrops on roses";


== Field Assignment ==
Each field definition has several associated attributes, the values of which are set like this:


;''fieldAssignment:''
    default("fieldValue")
: ''fieldName'' <tt>=</tt> ''initializer'' <tt>;</tt>
    readonly(yesNo)
    design(yesNo)
    special(yesNo)
    asl(securityLevel)
    link(yesNo)


;''fieldName:''
'''Marty thinks we should get rid of these two:'''
: ''identifier''
    prompt("promptString")
    group("promptGroup")


;''initializer:''
'''I am thinking about combining readonly and design into a single attribute called access, which takes one of four choices: design (the default), runtime, readonly, or none.'''
: ''constant''
: ''structInitializer''
: ''arrayInitializer''
: ''devlinkInitializer''


;''initializerList:''
The attribute parameter values have the following meanings:
: ''initializer''
: ''initializerList'' <tt>,</tt> ''initializer''


The ''initializer'' in a field assignment is also the exact same syntax that will be used when converting a string value from a CA client for example into a field value that is being put into a field.
; <tt>default("fieldValue")</tt>
: Default value for an instance of this field, using the [[V4 DB Record Instance Syntax|record instance value syntax]].  If a default is not specified, the field will initialize to all zero bits.
: If the field is itself a structure, the default value for the instance of the whole structure can override default values declared for individual fields inside that structure.  This can occur at multiple levels.


=== Basic and Enumerated Initializers ===
; <tt>readonly(yesNo)</tt>
: Can this field be modified via channel access or database links?  Takes the value No if not specified.


;''constant:''
; <tt>design(yesNo)</tt>
: ''booleanConstant''
: Should a Database Configuration Tool allow the field to be configured at design time?  If No, values for the field cannot be set when loading record instance data at startup.  Takes the value Yes if not specified.
: ''integerConstant''
: ''realConstant''
: ''stringConstant''


The syntax for the field initializer depends on the data type represented by fieldName.  Basic types (numeric or string) should need no comment other than to note that values for numeric fields must not be given inside quotes (unlike EPICS V3).  Menu field values may be given as either a string or an integer. For enum fields, if the related field that contains the strings is defined first, the enum field may be specified using a string; otherwise it can only be set using an integer value.
; <tt>special(yesNo)</tt>
: Does the record have to take special action if the field is modified?  If this is Yes, the record types special processing will be invoked to actually change the field value, which will allow it to perform value checks or additional processing.  Takes the value No if not specified.


Examples:
; <tt>asl(securityLevel)</tt>
  ai foo:bar:temperature = {
: Channel Access security level for this field, 0 or 1.  Takes the value 1 if not specified.
      inputSmoothing = 0.98;
 
      invalidValue = 1000;
; <tt>link</tt>
      units = "Celcius";
: This is only valid for string fields. It signifies the the field is the name of an external record. This is for use by Database Configuration Tools.
      scan = "Interrupt";
      ...
  }


''These attributes may disappear, see comment above:''


=== Structure Initializers ===
; <tt>prompt("promptString")</tt>
: A description of this field for the database designer, this string will be displayed by a Database Configuration Tool.  Empty if not specified.  Not used within the IOC.


;''structInitializer:''
; <tt>group("promptGroup")</tt>
: <tt>{</tt> ''structAssignmentList'' <tt>}</tt>
: A name that can be used by a Database Configuration Tool to group similar or related fields together.  Empty if not specified.  Not used within the IOC.


;''structAssignmentList:''
== view ==
: ''initializerList''
: ''fieldName'' <tt>=</tt> ''initializerList''
: ''structAssignmentList'' <tt>;</tt> ''fieldName'' <tt>=</tt> ''initializerList''


Initializers for a structure field look similar to a nested record body, but the rules are slightly different:
There needs to be more than one way to look at a record remotely (via Channel Access or some other similar network protocol).  Often we just want to get the contents of the value field and some metadata associated with that value, but there are often several fields which can share metadata - engineering units for example.  We can't do metadata using structures because that would mean replicating this metadata, so we add a level of indirection to allow us to group fields together.
* You can give a series of values for adjacent items using a simple comma-separated list (for a record body, you ''must'' name each field)
* Semi-colons are required between a value and a following named item.


For example:
A view of a record provides a hierarchical mapping of some of the record's fields from a named Data Access property catalog that can be reached using Channel Access.  Records automatically get a view named "field" that provides direct access to the individual public fields of the record, with no metadata.  Beyond that, record types can declare additional hierarchical views and define the fields that appear in them inside the DBD file.  The first view defined for a record type is used as its default view (if no views are defined, the field view will become the default view; view parameters may not be permitted).


  ai foo:temperature:sensor = {
A simple view looks like this:
      linearConvert = {
          mode = "Linear";
          low = -12.5, 133.5
      };
      displayLimit = { 0, 100 };
      ...
  }


=== Link and Device Initializers ===
view(viewName) {
    property(propName) {
        property(propName, fieldPath)
        ...
    }
    property(propName, fieldPath)
    ...
}


;''devlinkInitializer:''
; <tt>viewName</tt>
: ''choiceName'' <tt>(</tt> ''structAssignmentList'' <tt>)</tt>
: The view name must be a valid C identifier, which must be unique in the context of the particular record type.
; <tt>propName</tt>
: A Data Access property name, which must be a valid C identifier.
; <tt>fieldPath</tt>
: The path to a field in this record type. To use a field inside a structure field, give the full path to that field: <tt>controlLimit.upper</tt> for example.
: If <tt>fieldPath</tt> resolves to a structure, a property catalog containing the whole structure will be sent, with property names matching the structure's field names.
: The <tt>fieldPath</tt> may be omitted as long as there is a subordinate property catalog below this property.


;''choiceName:''
Example:
: ''identifier''


These select a particular link or device support for the field, and set its address according to the structure type defined for that link or device type.
record(ao) extends RecordCommon {
    field(value, float64) { ... }
    field(outValue, float64) { ... }
    field(rawValue, int32) { ... }
    field(units, string) { ... }
    field(displayLimit, struct(displayLimit)) { ... }
    ...
    view(value)
        property(value, value) {
            property(units, units)
            property(timeStamp, time)
            property(alarmSeverity, alarmSeverity)
            property(alarmStatus, alarmStatus)
            property(displayLimit, displayLimit)
        }
    }
    view(outValue)
        property(value, outValue) {
            property(units, units)
            property(timeStamp, time)
            property(alarmSeverity, alarmSeverity)
            property(alarmStatus, alarmStatus)
        }
    }
    view(rawValue)
        property(value, rawValue) {
            property(timeStamp, time)
        }
    }
    ...
}


  calcout foo:temperature:controller = {
<center>
      output = ca("fum:baz:heater"; pp=y);
= link =
      input = [2] {
</center>
          {link = {
              MonitorLink{
                  pvname = "foo:temperature:setpoint";
                  process = false
              }
          }
          {link = {
              InputLink{
                  pvname = "foo:temperature:sensor";
                  process = true;
                  inheritSeverity = true
              }
          }
      };
      expression = "(setpoint - current) > 0";
      ...
  }


  mbbi foo:bar:door = {
A <tt>link</tt> statement describes an implementation of support for a link
      input = acro9440(0, 5);
field. the support can be any of the following:
      ...
* A link to another record either local or remote
  }
* A link to hardware support
* Something else.


=== Array Initializers ===
The syntax for these is:


;''arrayInitializer:''
device(dir, choiceName, interfaceName, dataStructName)
: <tt>{</tt> ''arrayAssignmentList'' <tt>}</tt>
: ''arrayType'' <tt>{</tt> ''arrayAssignmentList'' <tt>}</tt>
: <tt>[</tt> ''arrayCapacity'' <tt>] {</tt> ''arrayAssignmentList'' <tt>}</tt>
: ''arrayType'' <tt>[</tt> ''arrayCapacity'' <tt>] {</tt> ''arrayAssignmentList'' <tt>}</tt>


;''arrayAssignmentList:''
where
: ''initializerList''
: <tt>[</tt> ''integerConstant'' <tt>] =</tt> ''initializerList''
: ''arrayAssignmentList'' <tt>; [</tt> ''integerConstant'' <tt>] =</tt> ''initializerList''


;''arrayType:''
; <tt>dir</tt>
: ''one of:'' <tt>bool</tt> <tt>int16</tt> <tt>uint16</tt> <tt>int32</tt> <tt>uint32</tt>
: Must be one of <tt>none</tt>,<tt>in</tt>,<tt>out</tt>,<tt>process</tt>, or <tt>inout</tt>. Compatible checks are made to match the interface with a field.
: ''one of:'' <tt>float32</tt> <tt>float64</tt> <tt>octet</tt> <tt>string</tt>
: '''Q: What are the rules?'''
:: ''It certainly doesn't seem to make sense to have a none or inout link for instance.''


;''arrayCapacity:''
; <tt>choiceName</tt>
: ''integerConstant''
: UTF-8 string that describes the choice
: ''arrayCapacity'' <tt>,</tt> ''integerConstant''


If the definition of the array field being set did not do so, an array field initialization must include the size of the array and/or the type of the data stored in it. Inside the braces data values are given in a comma-separated list; the index can also be set to initialize individual values, and any mixture of the two can be used as desired:
; <tt>interfaceName</tt>
: The name of an interface via which record support communicates with device support.


  mbbi foo:bar:door = {
; <tt>dataStructName</tt>
      stateNames = [4] {"Broken", "Closed", "Open", "Moving"};
: The name of a <tt>struct</tt> that the interface understands. This interface can contain data and configuration information. The <tt>struct</tt> must be defined before record instances can be created that assign values to it.
      stateSeverity = [4] {"Major"; [3] = "Minor"};
:: ''Need to rewrite this paragraph to clarify.''
      ...
  }


For multi-dimensional arrays, data values can only appear inside the inner-most sets of braces, although index settings are permitted outside of these. These two definitions give the same result:
When a record instance is created the choiceName selects the support
to attach to a record link. The interfaceName must be one of the
interface names the record has listed as a valid type and dir must be compatible
with the dir the record type specified.


  matrix identity1 = {
Examples:
      value = float32 [3,3] { {1, 0, 0}, {0, 1, 0}, {1, 0, 0}};
    link(in,"monitorLinkInt16","monitorLinkInt16",MonitorLinkData);
  }
    link(in,"inputLinkInt16","inputLinkInt16",InputLinkData);
  matrix identity2 = {
    link(out,"outputLinkFloat64","outputLinkFloat64",OutputLinkData);
      value = float32 [3,3] { {1}, {[1] = 1}, {[2] = 1}};
    link(process,"processLink",ProcessLink,ProcessLinkData);
  }

Revision as of 15:16, 27 September 2005

DBD Statement Syntax Sept 27 2005

Overview

This document presents the syntax for V4 database definition files.

General Statements

include

include "filename"

where

filename
must be a valid filename

The file system search path that will be used to look for the file is determined by the build system, and cannot be modified by the DBD file itself.

Include statements can be used at the top level, or inside the braces of a menu, struct or record definition.

# comment

# anything

Anything on a line after a # character is a comment, and will be ignored. Comments may appear on a line by themselves, or at the end of another statement. They may not appear inside the parentheses belonging to another statement, but they are permitted inside braces. Inside a single- or double- quoted string the # character has no special meaning.


menu

A menu is an enumerated type where the choice strings are defined once for each IOC. Menus are defined like this:

menu(menuName) {
    choice(choiceName, "choiceValue")
    ...
}

where

menuName
Must be a valid, unique C identifier.
choiceName
Must be a valid, unique C identifier. By convention, every choiceName should start with the menuName it belongs to. These names are only available to C/C++ source code using the header file generated from the menu definition; they are not stored in the IOC itself.
choiceValue
Can be any UTF-8 compatible string, which should be unique within the context of this menu.

In general menus should only be definable once, in the DBD file (first definition seen wins in the event of duplicates, give a warning for duplicates and error if subsequent definition is different). However we may want to include a syntax that allows specific menu definitions to be extended at database load time.

Example:

menu(menuScan) {
    choice(menuScanPassive, "Passive")
    choice(menuScanEvent, "Event")
    choice(menuScanInterrupt, "Interrupt")
    choice(menuScan10second, "10 second")
    choice(menuScan5second, "5 second")
    choice(menuScan2second, "2 second")
    choice(menuScan1second, "1 second")
    choice(menuScan_5second, ".5 second")
    choice(menuScan_2second, ".2 second")
    choice(menuScan_1second, ".1 second")
}

Structures, Record types, Fields and Views

Structures and record types have significant commonality in that they both define a data structure type containing fields. The main difference is that you can't create or populate an instance of a structure outside of a record; only records can appear at the very top level. Record types also define views of the record, which is not possible for a structure.

struct

A structure is defined as follows:

struct(name) {
    field(fieldName, fieldType) {
        fieldAttribute(attributeValue)
        ...
    }
    ...
}

where

name
The structure name must be a valid, unique C identifier.
fieldName
Must be a valid C identifier, unique within the context of this particular structure.
fieldType
See fieldType below.
fieldAttribute and attributeValue
See fieldAttribute below.

record

A record type is defined as follows:

include "dbCommon.dbd"
record(name) extends RecordCommon {
    field(fieldName, fieldType) {
        fieldAttribute(attributeValue)
        ...
    }
    ...
    view(viewName) {
        property(propName, fieldPath)
        ...
    }
    ...
}
name
The record type name. It must be a valid, unique C identifier.
extends RecordCommon
This states that the record type extends the set of fields defined in "V4 DB RecordCommon". It should be permissable to name other record types instead of RecordCommon here, as long as the inheritance tree starts at RecordCommon. Inheritance from multiple record types is not supported; you can only have one extends phrase.
fieldName
Must be a valid C identifier, unique within the context of this particular record type and its parents (extends ...).
fieldType
See fieldType below.
fieldAttribute and attributeValue
See fieldAttribute below.
viewName, propName and fieldPath
See Views of a record below.

fieldType

Both struct and record define a field as:

    field(fieldName, fieldType) {
        fieldAttribute(attributeValue)
        ...
    }

The syntax for fieldType depends of the field type. For the more complex types the field definition needs additional information to be provided, which is given inside parentheses following the type name.

Basic types: octet, boolean, numerics, and string

The following field types have no arguments: octet, bool, int16, int32, int64, float32, float64, and string.

Examples: field(description,string) field(value,float64)

enum

An enum field takes one argument after the type name:

enum(fieldName)

where fieldName is the name of another field in the same record that must be of type array(string[]). The values in this other field at runtime define the available choice strings for the enum field.

Examples:

field(choices, array(string[]) field(value, enum(choices))

menu

A menu field is defined like this: menu(menuName)

where menuName is the name of the menu.

Example: field(scan, menu(menuScan))

struct

A struct field is declared using the type name struct(structName)

where structName is the name of a struct which must have been previously defined.


Example: struct(Point) { field(x,float64) field(y,float64) field(z,float64) } ... record(haspoint) extends RecordCommon { ... field(point, struct(point)) }

array

An array field uses definitions like these:

1-dimensional array
array(arrayType[capacity])
multi-dimensional array
array(arrayType[capacityX, capacityY, ...])
arbitrarily dimensioned array
array(arrayType)
1-dimensional array of unknown size
array(arrayType[])
3-dimensional array of unknown size
array(arrayType[,,])
1-dimensional array of unknown type
array([capacity])
multi-dimensional array of unknown type
array([capacityX, capacityY, ...])
arbitrarily dimensioned array of unknown type
array()
1-dimensional array of unknown type or size
array([])
2-dimensional array of unknown type or size
array([,])
  • arrayType may be any fieldType except array, or may be omitted completely in which case the data type stored is determined by record instance. If the record instance defines the type, it can only be one of the types listed above under Basic types
  • capacity is the array's size in the relevent dimension, and must be specified for all dimensions or for none. If not specified by the record type, the record instance determines an array's dimensionality and size.

Examples: field(VAL1D,array(float64[])) #1d array with arbitrary capacity field(VAL2D,array(float64[,])) #2d array with arbitrary capacities field(anyTypeAnyD,array()) #arbitrary type,number of dimensions, and capacities

link

This field type can get or put data from/to some source outside of the record. Link fields replace the DBF_INLINK, DBF_OUTLINK, and DTYP fields from EPICS V3.

A link field's choices come from link definitions - see the #link section below for more details. A link can be a link to another database record, to hardware device support, or something else.

The syntax is:

link(linkDirection,array(string[])= {name,...})

where

  • linkDirection : none, in, out, process, or inout. The direction none means there is no direction associated with this interface. For inout the direction is determined by the particular link that the record instance selects.
  • array(string[]) : Each string is the name of Link Interface implemented by link support and used by record support.

Examples: field(disableLink, link(in,array(string[4]) = { "monitorLinkInt32", "inputLinkInt32", "monitorLinkFloat64", "inputLinkFloat64" } )) ) field(process, link(process,array(string[1])= {processLink})) field(inp, link(in, array(string[3]) = { "monitorLinkInt32", "inputLinkInt32", "digitalIO" })) )

Andrew: Do we want the above syntax? Another possibility is just:

   link(linkDirection,interface(string,...))

fieldAttribute

Each field definition has several associated attributes, the values of which are set like this:

    default("fieldValue")
    readonly(yesNo)
    design(yesNo)
    special(yesNo)
    asl(securityLevel)
    link(yesNo)

Marty thinks we should get rid of these two:

    prompt("promptString")
    group("promptGroup")

I am thinking about combining readonly and design into a single attribute called access, which takes one of four choices: design (the default), runtime, readonly, or none.

The attribute parameter values have the following meanings:

default("fieldValue")
Default value for an instance of this field, using the record instance value syntax. If a default is not specified, the field will initialize to all zero bits.
If the field is itself a structure, the default value for the instance of the whole structure can override default values declared for individual fields inside that structure. This can occur at multiple levels.
readonly(yesNo)
Can this field be modified via channel access or database links? Takes the value No if not specified.
design(yesNo)
Should a Database Configuration Tool allow the field to be configured at design time? If No, values for the field cannot be set when loading record instance data at startup. Takes the value Yes if not specified.
special(yesNo)
Does the record have to take special action if the field is modified? If this is Yes, the record types special processing will be invoked to actually change the field value, which will allow it to perform value checks or additional processing. Takes the value No if not specified.
asl(securityLevel)
Channel Access security level for this field, 0 or 1. Takes the value 1 if not specified.
link
This is only valid for string fields. It signifies the the field is the name of an external record. This is for use by Database Configuration Tools.

These attributes may disappear, see comment above:

prompt("promptString")
A description of this field for the database designer, this string will be displayed by a Database Configuration Tool. Empty if not specified. Not used within the IOC.
group("promptGroup")
A name that can be used by a Database Configuration Tool to group similar or related fields together. Empty if not specified. Not used within the IOC.

view

There needs to be more than one way to look at a record remotely (via Channel Access or some other similar network protocol). Often we just want to get the contents of the value field and some metadata associated with that value, but there are often several fields which can share metadata - engineering units for example. We can't do metadata using structures because that would mean replicating this metadata, so we add a level of indirection to allow us to group fields together.

A view of a record provides a hierarchical mapping of some of the record's fields from a named Data Access property catalog that can be reached using Channel Access. Records automatically get a view named "field" that provides direct access to the individual public fields of the record, with no metadata. Beyond that, record types can declare additional hierarchical views and define the fields that appear in them inside the DBD file. The first view defined for a record type is used as its default view (if no views are defined, the field view will become the default view; view parameters may not be permitted).

A simple view looks like this:

view(viewName) {
    property(propName) {
        property(propName, fieldPath)
        ...
    }
    property(propName, fieldPath)
    ...
}
viewName
The view name must be a valid C identifier, which must be unique in the context of the particular record type.
propName
A Data Access property name, which must be a valid C identifier.
fieldPath
The path to a field in this record type. To use a field inside a structure field, give the full path to that field: controlLimit.upper for example.
If fieldPath resolves to a structure, a property catalog containing the whole structure will be sent, with property names matching the structure's field names.
The fieldPath may be omitted as long as there is a subordinate property catalog below this property.

Example:

record(ao) extends RecordCommon {
    field(value, float64) { ... }
    field(outValue, float64) { ... }
    field(rawValue, int32) { ... }
    field(units, string) { ... }
    field(displayLimit, struct(displayLimit)) { ... }
    ...
    view(value)
        property(value, value) {
            property(units, units)
            property(timeStamp, time)
            property(alarmSeverity, alarmSeverity)
            property(alarmStatus, alarmStatus)
            property(displayLimit, displayLimit)
        }
    }
    view(outValue)
        property(value, outValue) {
            property(units, units)
            property(timeStamp, time)
            property(alarmSeverity, alarmSeverity)
            property(alarmStatus, alarmStatus)
        }
    }
    view(rawValue)
        property(value, rawValue) {
            property(timeStamp, time)
        }
    }
    ...
}

link

A link statement describes an implementation of support for a link field. the support can be any of the following:

  • A link to another record either local or remote
  • A link to hardware support
  • Something else.

The syntax for these is:

device(dir, choiceName, interfaceName, dataStructName)

where

dir
Must be one of none,in,out,process, or inout. Compatible checks are made to match the interface with a field.
Q: What are the rules?
It certainly doesn't seem to make sense to have a none or inout link for instance.
choiceName
UTF-8 string that describes the choice
interfaceName
The name of an interface via which record support communicates with device support.
dataStructName
The name of a struct that the interface understands. This interface can contain data and configuration information. The struct must be defined before record instances can be created that assign values to it.
Need to rewrite this paragraph to clarify.

When a record instance is created the choiceName selects the support to attach to a record link. The interfaceName must be one of the interface names the record has listed as a valid type and dir must be compatible with the dir the record type specified.

Examples:

    link(in,"monitorLinkInt16","monitorLinkInt16",MonitorLinkData);
    link(in,"inputLinkInt16","inputLinkInt16",InputLinkData);
    link(out,"outputLinkFloat64","outputLinkFloat64",OutputLinkData);
    link(process,"processLink",ProcessLink,ProcessLinkData);