#*************************************************************************
# Copyright (c) 2012 UChicago Argonne LLC, as Operator of Argonne
#     National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************


=title Long String Output Record (lso)

The long string output record is used to write an arbitrary ASCII string with a
maximum length of 32767 characters.

This record type was included in base.dbd beginning with epics-base 3.15.0.2 .

=head2 Parameter Fields

The record-specific fields are described below, grouped by functionality.

=recordtype lso

=cut

recordtype(lso) {

=head3 Scan Parameters

The long string output record has the standard fields for specifying under what
circumstances it will be processed.
These fields are listed in L<Scan Fields|dbCommonRecord/Scan Fields>.

=head3 Desired Output Parameters

The long string output record must specify from where it gets its desired output
string. The first field that determines where the desired output originates is
the output mode select (OMSL) field, which can have two possible values:
C<closed_loop> or C<supervisory>. If C<closed_loop> is specified, the VAL
field's value is fetched from the address specified in the Desired Output Link
field (DOL) which can be either a database link or a channel access link. If
C<supervisory> is specified, DOL is ignored, the current value of VAL is
written, and VAL can be changed externally via dbPuts at run-time.

The maximum number of characters in VAL is given by SIZV, and cannot be larger
than 32767.

DOL can also be a constant instead of a link, in which case VAL is initialized
to the constant value. Most simple string constants are likely to be interpreted
as a CA link name though. To initialize a string output record it is simplest
to set the VAL field directly; alternatively use a JSON constant link type in
the DOL field.

=fields VAL, SIZV, DOL, OMSL

=head3 Output Specification

The output link specified in the OUT field specifies where the long string
output record is to write its string. The link can be a database or channel
access link. If the OUT field is a constant, no output will be written.

In addition, the appropriate device support module must be entered into the DTYP
field.


=fields OUT, DTYP

=head3 Monitor Parameters

These parameters are used to specify when the monitor post should be sent by the
C<monitor()> routine. There are two possible choices:

APST is used for archiver monitors and MPST  for all other type of monitors.

=fields MPST, APST


=head3 Operator Display Parameters

See L<Fields Common to All Record Types|dbCommonRecord/Operator Display
Parameters> for more on the record name (NAME) and description (DESC) fields.

=fields NAME, DESC

=head3 Alarm Parameters

The long string input record has the same alarm parameters common to all record
types. L<Alarm Fields|dbCommonRecord/Alarm Fields> lists the fields related to
alarms that are common to all record types.

The IVOA field specifies an action to take when the INVALID alarm is triggered.
When C<<< Set output to IVOV >>>, the value contained in the IVOV field is
written to the output link during an alarm condition. See
L<Invalid Output Action Fields|dbCommonOutput/Invalid Output Action Fields>
for more information on the IVOA and IVOV fields.

=fields IVOA, IVOV

=cut

    include "dbCommon.dbd"
    %
    %/* Declare Device Support Entry Table */
    %struct lsoRecord;
    %typedef struct lsodset {
    %    dset common;
    %    long (*write_string)(struct lsoRecord *prec);
    %} lsodset;
    %#define HAS_lsodset
    %
    field(VAL,DBF_NOACCESS) {
        prompt("Current Value")
        asl(ASL0)
        pp(TRUE)
        special(SPC_DBADDR)
        extra("char *val")
        #=type STRING or CHAR[SIZV]
        #=read Yes
        #=write Yes
    }
    field(OVAL,DBF_NOACCESS) {
        prompt("Previous Value")
        special(SPC_DBADDR)
        interest(3)
        extra("char *oval")
        #=type STRING or [SIZV]
        #=read Yes
        #=write No
    }
    field(SIZV,DBF_USHORT) {
        prompt("Size of buffers")
        promptgroup("50 - Output")
        special(SPC_NOMOD)
        interest(1)
        initial("41")
    }
    field(LEN,DBF_ULONG) {
        prompt("Length of VAL")
        special(SPC_NOMOD)
    }
    field(OLEN,DBF_ULONG) {
        prompt("Length of OVAL")
        special(SPC_NOMOD)
        interest(3)
    }
    field(DOL,DBF_INLINK) {
        prompt("Desired Output Link")
        promptgroup("40 - Input")
        interest(1)
    }
    field(IVOA,DBF_MENU) {
        prompt("INVALID Output Action")
        promptgroup("50 - Output")
        interest(2)
        menu(menuIvoa)
    }
    field(IVOV,DBF_STRING) {
        prompt("INVALID Output Value")
        promptgroup("50 - Output")
        interest(2)
        size(40)
    }
    field(OMSL,DBF_MENU) {
        prompt("Output Mode Select")
        promptgroup("50 - Output")
        interest(1)
        menu(menuOmsl)
    }
    field(OUT,DBF_OUTLINK) {
        prompt("Output Specification")
        promptgroup("50 - Output")
        interest(1)
    }
    field(MPST,DBF_MENU) {
        prompt("Post Value Monitors")
        promptgroup("80 - Display")
        interest(1)
        menu(menuPost)
    }
    field(APST,DBF_MENU) {
        prompt("Post Archive Monitors")
        promptgroup("80 - Display")
        interest(1)
        menu(menuPost)
    }


=head3 Run-time Parameters

The old value field (OVAL) of the long string input record is used to implement
value change monitors for VAL. If VAL is not equal to OVAL, then monitors are
triggered. LEN contains the length of the string in VAL, OLEN contains the
length of the string in OVAL.

=fields OVAL, LEN, OLEN

=head3 Simulation Mode Parameters

The following fields are used to operate the record in simulation mode.

If SIMM (fetched through SIML) is YES, the record is put in SIMS
severity and the value is written through SIOL.
SSCN sets a different SCAN mechanism to use in simulation mode.
SDLY sets a delay (in sec) that is used for asynchronous simulation
processing.

See L<Output Simulation Fields|dbCommonOutput/Output Simulation Fields>
for more information on simulation mode and its fields.

=fields SIML, SIMM, SIOL, SIMS, SDLY, SSCN

=cut

    field(SIML,DBF_INLINK) {
        prompt("Simulation Mode link")
        promptgroup("90 - Simulate")
        interest(1)
    }
    field(SIMM,DBF_MENU) {
        prompt("Simulation Mode")
        special(SPC_MOD)
        interest(1)
        menu(menuYesNo)
    }
    field(SIMS,DBF_MENU) {
        prompt("Simulation Mode Severity")
        promptgroup("90 - Simulate")
        interest(2)
        menu(menuAlarmSevr)
    }
    field(SIOL,DBF_OUTLINK) {
        prompt("Simulation Output Link")
        promptgroup("90 - Simulate")
        interest(1)
    }
    field(OLDSIMM,DBF_MENU) {
        prompt("Prev. Simulation Mode")
        special(SPC_NOMOD)
        interest(4)
        menu(menuSimm)
    }
    field(SSCN,DBF_MENU) {
        prompt("Sim. Mode Scan")
        promptgroup("90 - Simulate")
        interest(1)
        menu(menuScan)
        initial("65535")
    }
    field(SDLY,DBF_DOUBLE) {
        prompt("Sim. Mode Async Delay")
        promptgroup("90 - Simulate")
        interest(2)
        initial("-1.0")
    }
    %#include "callback.h"
    field(SIMPVT,DBF_NOACCESS) {
        prompt("Sim. Mode Private")
        special(SPC_NOMOD)
        interest(4)
        extra("epicsCallback            *simpvt")
    }
}


=head2 Device Support Interface

The record defines a device support entry table type C<lsodset> in the generated
lsoRecord.h file as follows:

 typedef struct lsodset {
     dset common;
     long (*write_string)(struct lsoRecord *prec);
 } lsodset;
 #define HAS_lsodset

The support module must set C<common.number> to at least 5, and provide a
pointer to its C<write_string()> routine; the other function pointers may be
C<NULL> if their associated functionality is not required for this support
layer.
Most device supports also provide a C<common.init_record()> routine to configure
the record instance and connect it to the hardware or driver support layer.


=head2 Device Support for Soft Records

Device support for DTYP C<Soft Channel> is provided for writing values to other
records or other software components.

Device support for DTYP C<stdio> is provided for writing values to the stdout,
stderr, or errlog streams. C<INST_IO> addressing C<@stdout>, C<@stderr> or
C<@errlog> is used on the OUT link field to select the desired stream.

=cut
