# Database for the records specific to the marCCD driver
# Mark Rivers
# October 31, 2008

# Status poll.  This can normally be Passive, except when ArrayCallbacks is 0 and Overlap is 1.
# In that case the state will appear to be busy when it is idle, and this polling should be
# turned on to avoid confusion

record(bo,"$(P)$(R)MarReadStatus") {
    field(DTYP,"asynInt32")
    field(OUT, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_READ_STATUS")
    field(VAL, "1")
    field(SCAN,"Passive")
}

record(longin,"$(P)$(R)MarState_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_STATE")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Task state")
}

# State word
record(longin,"$(P)$(R)MarState_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_STATE")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Task state")
}

# Status field for low order 4 bits (should only be IDLE, ERROR or BUSY)
record(mbbi,"$(P)$(R)MarStatus_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_STATUS")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Task status")
    field(ZRVL,"0")
    field(ZRST,"Idle")
    field(ZRSV,"NO_ALARM")
    field(ONVL,"1")
    field(ONST,"Unknown 1")
    field(ONSV, "INVALID")
    field(TWVL,"2")
    field(TWST,"Unknown 2")
    field(TWSV, "INVALID")
    field(THVL,"3")
    field(THST,"Undefined 3")
    field(THSV, "INVALID")
    field(FRVL,"4")
    field(FRST,"Error")
    field(FRSV, "MAJOR")
    field(FVVL,"5")
    field(FVST,"Undefined 5")
    field(FVSV, "INVALID")
    field(SXVL,"6")
    field(SXST,"Undefined 6")
    field(SXSV, "INVALID")
    field(SVVL,"7")
    field(SVST,"Undefined 7")
    field(SVSV, "INVALID")
    field(EIVL,"8")
    field(EIST,"Busy")
    field(EISV, "MINOR")
}

# Individual status fields for the Acquire, Readout, Correct, Writing, and Dezinger tasks
record(mbbi,"$(P)$(R)MarAcquireStatus_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_ACQUIRE_STATUS")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Acquire status")
    field(ZRVL,"0")
    field(ZRST,"Idle")
    field(ZRSV,"NO_ALARM")
    field(ONVL,"1")
    field(ONST,"Queued")
    field(ONSV, "MINOR")
    field(TWVL,"2")
    field(TWST,"Executing")
    field(TWSV, "MINOR")
    field(THVL,"3")
    field(THST,"Undefined 3")
    field(THSV, "INVALID")
    field(FRVL,"4")
    field(FRST,"Error")
    field(FRSV, "MAJOR")
    field(FVVL,"5")
    field(FVST,"Undefined 5")
    field(FVSV, "INVALID")
    field(SXVL,"6")
    field(SXST,"Undefined 6")
    field(SXSV, "INVALID")
    field(SVVL,"7")
    field(SVST,"Undefined 7")
    field(SVSV, "INVALID")
    field(EIVL,"8")
    field(EIST,"Reserved")
    field(EISV, "MINOR")
}

record(mbbi,"$(P)$(R)MarReadoutStatus_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_READOUT_STATUS")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Readout status")
    field(ZRVL,"0")
    field(ZRST,"Idle")
    field(ZRSV,"NO_ALARM")
    field(ONVL,"1")
    field(ONST,"Queued")
    field(ONSV, "MINOR")
    field(TWVL,"2")
    field(TWST,"Executing")
    field(TWSV, "MINOR")
    field(THVL,"3")
    field(THST,"Undefined 3")
    field(THSV, "INVALID")
    field(FRVL,"4")
    field(FRST,"Error")
    field(FRSV, "MAJOR")
    field(FVVL,"5")
    field(FVST,"Undefined 5")
    field(FVSV, "INVALID")
    field(SXVL,"6")
    field(SXST,"Undefined 6")
    field(SXSV, "INVALID")
    field(SVVL,"7")
    field(SVST,"Undefined 7")
    field(SVSV, "INVALID")
    field(EIVL,"8")
    field(EIST,"Reserved")
    field(EISV, "MINOR")
}

record(mbbi,"$(P)$(R)MarCorrectStatus_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_CORRECT_STATUS")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Correct status")
    field(ZRVL,"0")
    field(ZRST,"Idle")
    field(ZRSV,"NO_ALARM")
    field(ONVL,"1")
    field(ONST,"Queued")
    field(ONSV, "MINOR")
    field(TWVL,"2")
    field(TWST,"Executing")
    field(TWSV, "MINOR")
    field(THVL,"3")
    field(THST,"Undefined 3")
    field(THSV, "INVALID")
    field(FRVL,"4")
    field(FRST,"Error")
    field(FRSV, "MAJOR")
    field(FVVL,"5")
    field(FVST,"Undefined 5")
    field(FVSV, "INVALID")
    field(SXVL,"6")
    field(SXST,"Undefined 6")
    field(SXSV, "INVALID")
    field(SVVL,"7")
    field(SVST,"Undefined 7")
    field(SVSV, "INVALID")
    field(EIVL,"8")
    field(EIST,"Reserved")
    field(EISV, "MINOR")
}

record(mbbi,"$(P)$(R)MarWritingStatus_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_WRITING_STATUS")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Writing status")
    field(ZRVL,"0")
    field(ZRST,"Idle")
    field(ZRSV,"NO_ALARM")
    field(ONVL,"1")
    field(ONST,"Queued")
    field(ONSV, "MINOR")
    field(TWVL,"2")
    field(TWST,"Executing")
    field(TWSV, "MINOR")
    field(THVL,"3")
    field(THST,"Undefined 3")
    field(THSV, "INVALID")
    field(FRVL,"4")
    field(FRST,"Error")
    field(FRSV, "MAJOR")
    field(FVVL,"5")
    field(FVST,"Undefined 5")
    field(FVSV, "INVALID")
    field(SXVL,"6")
    field(SXST,"Undefined 6")
    field(SXSV, "INVALID")
    field(SVVL,"7")
    field(SVST,"Undefined 7")
    field(SVSV, "INVALID")
    field(EIVL,"8")
    field(EIST,"Reserved")
    field(EISV, "MINOR")
}

record(mbbi,"$(P)$(R)MarDezingerStatus_RBV") {
    field(DTYP,"asynInt32")
    field(INP, "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_DEZINGER_STATUS")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC,"Dezinger status")
    field(ZRVL,"0")
    field(ZRST,"Idle")
    field(ZRSV,"NO_ALARM")
    field(ONVL,"1")
    field(ONST,"Queued")
    field(ONSV, "MINOR")
    field(TWVL,"2")
    field(TWST,"Executing")
    field(TWSV, "MINOR")
    field(THVL,"3")
    field(THST,"Undefined 3")
    field(THSV, "INVALID")
    field(FRVL,"4")
    field(FRST,"Error")
    field(FRSV, "MAJOR")
    field(FVVL,"5")
    field(FVST,"Undefined 5")
    field(FVSV, "INVALID")
    field(SXVL,"6")
    field(SXST,"Undefined 6")
    field(SXSV, "INVALID")
    field(SVVL,"7")
    field(SVST,"Undefined 7")
    field(SVSV, "INVALID")
    field(EIVL,"8")
    field(EIST,"Reserved")
    field(EISV, "MINOR")
}

# Timeout waiting for TIFF file.
record(ao, "$(P)$(R)ReadTiffTimeout")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_TIFF_TIMEOUT")
    field(DESC, "Timeout for TIFF file")
    field(VAL,  "30")
    field(EGU,  "s")
    field(PREC, "3")
}

# Overlap operation
record(bo, "$(P)$(R)OverlapMode")
{
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_OVERLAP")
    field(PINI, "1")
    field(DESC, "Overlap or sequential")
    field(ZNAM, "Sequential")
    field(ONAM, "Overlap")
}

record(bi, "$(P)$(R)OverlapMode_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_OVERLAP")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC, "Overlap or sequential")
    field(ZNAM, "Sequential")
    field(ONAM, "Overlap")
}

# Frame shift
record(longout, "$(P)$(R)FrameShift")
{
    field(DTYP, "asynInt32")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_FRAME_SHIFT")
    field(PINI, "1")
    field(DESC, "Frame shift lines")
}

record(longin, "$(P)$(R)FrameShift_RBV")
{
    field(DTYP, "asynInt32")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_FRAME_SHIFT")
    field(SCAN, "I/O Intr")
    field(PINI, "1")
    field(DESC, "Frame shift lines")
}

# We replace the choice fields for FrameType from ADBase.template
record(mbbo, "$(P)$(R)FrameType")
{
   field(ZRST, "Normal")
   field(ZRVL, "0")
   field(ONST, "Background")
   field(ONVL, "1")
   field(TWST, "Raw")
   field(TWVL, "2")
   field(THST, "DblCorrelation")
   field(THVL, "3")
}

record(mbbi, "$(P)$(R)FrameType_RBV")
{
   field(ZRST, "Normal")
   field(ZRVL, "0")
   field(ONST, "Background")
   field(ONVL, "1")
   field(TWST, "Raw")
   field(TWVL, "2")
   field(THST, "DblCorrelation")
   field(THVL, "3")
   field(SCAN, "I/O Intr")
}

# We replace the file format choices from ADBase.template
record(mbbo, "$(P)$(R)FileFormat")
{
    field(ZRST, "TIFF")
    field(ZRVL, "0")
    field(ONST, "Invalid")
    field(ONVL, "1")
}

record(mbbi, "$(P)$(R)FileFormat_RBV")
{
    field(ZRST, "TIFF")
    field(ZRVL, "0")
    field(ONST, "Invalid")
    field(ONVL, "1")
    field(SCAN, "I/O Intr")
}

# asyn record for interactive communication with marServer
record(asyn, "$(P)$(R)marServerAsyn")
{
    field(PORT,  "$(MARSERVER_PORT)")
    field(IMAX, "64")
    field(OMAX, "64")
}

# Records with auxiliary information
record(ao, "$(P)$(R)DetectorDistance")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_DETECTOR_DISTANCE")
    field(PINI, "1")
    field(PREC, "3")
    field(EGU,  "mm")
}

record(ao, "$(P)$(R)BeamX")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_BEAM_X")
    field(PINI, "1")
    field(PREC, "3")
    field(EGU,  "mm")
}

record(ao, "$(P)$(R)BeamY")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_BEAM_Y")
    field(PINI, "1")
    field(PREC, "3")
    field(EGU,  "mm")
}

record(ao, "$(P)$(R)StartPhi")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_START_PHI")
    field(PINI, "1")
    field(PREC, "3")
    field(EGU,  "deg")
}

record(stringout, "$(P)$(R)RotationAxis")
{
    field(PINI, "1")
    field(DTYP, "asynOctetWrite")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_ROTATION_AXIS")
}

record(ao, "$(P)$(R)RotationRange")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_ROTATION_RANGE")
    field(PINI, "1")
    field(PREC, "3")
    field(EGU,  "deg")
}

record(ao, "$(P)$(R)Wavelength")
{
    field(DTYP, "asynFloat64")
    field(OUT,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_WAVELENGTH")
    field(PINI, "1")
    field(PREC, "4")
    field(EGU,  "Angstrom")
}

record(waveform, "$(P)$(R)FileComments")
{
    field(PINI, "1")
    field(DTYP, "asynOctetWrite")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_FILE_COMMENTS")
    field(FTVL, "UCHAR")
    field(NELM, "256")
}

record(waveform, "$(P)$(R)DatasetComments")
{
    field(PINI, "1")
    field(DTYP, "asynOctetWrite")
    field(INP,  "@asyn($(PORT),$(ADDR),$(TIMEOUT))MAR_DATASET_COMMENTS")
    field(FTVL, "UCHAR")
    field(NELM, "256")
}



