00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef STRAP_LCU_H
00012 #define STRAP_LCU_H
00013
00014
00015
00016 #include <vxWorks.h>
00017 #include <semLib.h>
00018 #include <string.h>
00019 #include <ctype.h>
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <ioLib.h>
00023 #include <symLib.h>
00024 #include <sysSymTbl.h>
00025 #include <sysLib.h>
00026 #include <taskLib.h>
00027 #include <tickLib.h>
00028 #include <usrLib.h>
00029 #include <errnoLib.h>
00030 #include <vxLib.h>
00031 #include <math.h>
00032 #include <lcudrv.h>
00033
00034
00035
00036 #include "ccs.h"
00037 #include "log.h"
00038 #include "err.h"
00039 #include "db.h"
00040 #include "cmd.h"
00041
00042 #include "lsfDefines.h"
00043
00044
00045 #define strapSET_STATUS_BIT(key) \
00046 strapInfo.boardStatus.ui32 = strapInfo.boardStatus.ui32 | key ;\
00047 if (strapInfo.verbose) printf("SET_BIT key 0x%08x 0x%08x Hex.\n",key,strapInfo.boardStatus.ui32);
00048
00049 #define strapRSET_STATUS_BIT(key) \
00050 strapInfo.boardStatus.ui32 = strapInfo.boardStatus.ui32 & ~key ;\
00051 if (strapInfo.verbose) printf("RESET_BIT key 0x%08x 0x%08x Hex.\n",key,strapInfo.boardStatus.ui32);
00052
00053
00054
00055
00056 #define IN
00057 #define OUT
00058 #define INOUT
00059
00060 #define DD2R 0.017453292519943295769236907684886127134428718885417
00061 #define M_PI 3.14159265358979323846
00062 #define strapDB_TIMEBASE 0.250
00063 #define strapDEVICE "/strapdv0"
00064
00065 #define strapSIZE_FILE_NAME 512
00066 #define strapNULL_GATE 1
00067 #define strapFULL_GATE 32
00068
00069 #define strapTEMP_GAP 4
00070
00071 #define strapSETUP_STATIC 1
00072 #define strapSETUP_DYNAMIC 2
00073
00074 #define strapSETUP_BUF_SIZE 50
00075
00076 #define strapMAX_CHOP_POS 5
00077
00078
00079
00080 #define strapST_UNKNOWN 0
00081 #define strapST_OFF lsfSTATE_OFF
00082 #define strapST_LOADED lsfSTATE_LOADED
00083 #define strapST_STANDBY lsfSTATE_STANDBY
00084 #define strapST_ONLINE lsfSTATE_ONLINE
00085
00086 #define strapSTR_UNKNOWN "UNKNOWN"
00087 #define strapSTR_OFF "LOADED"
00088 #define strapSTR_LOADED "LOADED"
00089 #define strapSTR_STANDBY "STANDBY"
00090 #define strapSTR_ONLINE "ONLINE"
00091
00092
00093
00094 #define strapSS_IDLE lsfSUBSTATE_IDLE
00095 #define strapSS_ERROR lsfSUBSTATE_ERROR
00096 #define strapSS_TIMEOUT lsfSUBSTATE_TIMEOUT
00097 #define strapSS_INITIALIZING lsfSUBSTATE_INITIALIZING
00098 #define strapSS_ACTIVE lsfSUBSTATE_ACTIVE
00099
00100
00101
00102
00103
00104
00105 #define strapSTART_OPEN 3
00106 #define strapSTART_CLOSE 4
00107 #define strapSTART_CALIB 5
00108
00109 #define strapSTART_STR_OPEN "open"
00110 #define strapSTART_STR_CLOSE "close"
00111 #define strapSTART_STR_CALIB "calibrate"
00112
00113 #define strapNDF_FIND 0
00114 #define strapNDF_DECREASE -1
00115 #define strapNDF_INCREASE 1
00116
00117
00118
00119 #define strapST_HV 0
00120 #define strapST_TEMP 4
00121 #define strapST_CURR 5
00122 #define strapST_GATE 6
00123 #define strapST_MASK 7
00124
00125
00126
00127 typedef vltINT32 strapDEV_HANDLE;
00128
00129 typedef union
00130 {
00131 vltUINT16 ui16[2];
00132 vltUINT32 ui32;
00133 } strapBOARD_STATUS;
00134
00135
00136 typedef struct
00137 {
00138 vltLOGICAL flag;
00139 FILE *filePtr;
00140 char name[512];
00141 vltINT32 curLines;
00142 vltINT32 maxLines;
00143 } strapLOG_FILE;
00144
00145
00146
00147 typedef struct {
00148 strapDEV_HANDLE dh;
00149 INT32 statusPoll;
00150 INT32 statusCnt;
00151 INT32 debugLevel;
00152 vltUINT16 distMaxSize;
00153 vltUINT8 dataFieldCnt;
00154 vltUINT16 dataMaxSize;
00155 vltUINT32 dataRecSize;
00156 dbTYPE dataRecType[10];
00157 vltLOGICAL disableTempCtrl;
00158 vltLOGICAL setHvOff;
00159 vltLOGICAL verbose;
00160 vltLOGICAL statistic;
00161 vltLOGICAL initStatistic;
00162 vltLOGICAL logFitsFlux;
00163 vltLOGICAL noDriver;
00164 vltLOGICAL settingTemp;
00165 vltFLOAT spotX;
00166 vltFLOAT spotY;
00167 UINT16 buffLen;
00168 dbDIRADDRESS dataDirAddr;
00169 dbDIRADDRESS disturbDirAddr;
00170 msgRECEIVEFILTER filter;
00171 vltFLOAT ticksToMsec;
00172 msgPROCESSID myId;
00173 ccsPROCNAME myName;
00174 vltUINT32 requestId;
00175 vltINT16 filterMode;
00176
00177
00178
00179 vltFLOAT diagMEAN[8];
00180 vltFLOAT diagRMS[8];
00181
00182
00183 vltBYTES256 ndfDbPoint;
00184 vltBYTES64 ndfServer;
00185 vltINT16 nfdNumFilters;
00186 vltDOUBLE *ndfFilters;
00187 vltINT32 ndfFilterIdx;
00188 vltINT32 ndfOpenIdx;
00189 vltINT32 ndfCloseIdx;
00190 vltINT32 ndfDarkIdx;
00191 vltINT32 ndfBrightIdx;
00192 FUNCPTR procSetNDF;
00193 FUNCPTR procGetNDF;
00194
00195
00196
00197
00198
00199 vltINT32 diagFitsCnt;
00200 vltINT32 diagFitsRate;
00201 vltINT32 logFitsDiag;
00202
00203
00204
00205 vltINT8 diagState;
00206 vltINT8 diagMode;
00207 vltINT8 rtMode;
00208 vltINT8 rtGuideMode;
00209 vltUINT8 busy;
00210
00211 SEM_ID diagSemId;
00212 SEM_ID rtSemId;
00213
00214
00215
00216
00217 vltUINT16 arcsecToBit;
00218 vltUINT16 intTime;
00219 vltUINT16 dataRecs;
00220 vltUINT16 diagRate;
00221 vltUINT16 thomsonFreq;
00222 vltFLOAT intMatrix[4];
00223 vltFLOAT maxMirrorSwing;
00224 vltINT16 refTemperature;
00225 vltINT32 lowFluxThr;
00226 vltINT32 skyBackground;
00227 vltUINT32 countLimit;
00228 vltFLOAT fluxQuality;
00229 vltINT16 maxWaterTemp;
00230 vltUINT16 actualHV[4];
00231
00232
00233
00234 vltINT32 state;
00235 vltINT32 substate;
00236 vltINT8 simulMode;
00237 vltLOGICAL init;
00238 vltINT8 statusMask[32];
00239 vltUINT16 gate;
00240 vltUINT8 hvState;
00241 vltINT16 temperature;
00242 vltINT16 current;
00243 vltINT32 serverSubState;
00244 strapBOARD_STATUS boardStatus;
00245
00246 vltUINT16 ptrData[20];
00247
00248
00249 ccsERROR tmpError;
00250 strapLOG_FILE logFile;
00251
00252
00253
00254 vltUINT16 simStatus[20];
00255 vltINT8 simApdCounts[4];
00256 vltINT8 actualApdCounts[4];
00257 } strapGlobalStruct;
00258
00259
00260
00261
00262 typedef struct {
00263 vltUINT16 intTime;
00264 vltUINT16 thFreq;
00265 vltUINT16 skyBack;
00266 vltUINT16 diagRate;
00267 vltUINT16 dataRecs;
00268 vltINT32 flux;
00269 vltFLOAT spotx;
00270 vltFLOAT spoty;
00271 vltFLOAT intMatrix[4];
00272 } strapSET_PARAMS;
00273
00274
00275
00276
00277
00278
00279 extern strapGlobalStruct strapInfo;
00280
00281
00282
00283
00284
00285 ccsCOMPL_STAT strapStdOff (ccsERROR *error);
00286 ccsCOMPL_STAT strapStdOnline (ccsERROR *error);
00287 ccsCOMPL_STAT strapStdStandby (ccsERROR *error);
00288 ccsCOMPL_STAT strapStdInit (ccsERROR *error);
00289 ccsCOMPL_STAT strapStdStop (ccsERROR *error);
00290 ccsCOMPL_STAT strapStdSetup (ccsERROR *error);
00291
00292
00293 ccsCOMPL_STAT strapSetIntMatrix (vltFLOAT *im, ccsERROR *error);
00294 ccsCOMPL_STAT strapSetDataRecs (vltUINT16 dataRecs, ccsERROR *error);
00295 ccsCOMPL_STAT strapSetGate (vltINT32 gate, ccsERROR *error);
00296 ccsCOMPL_STAT strapStdStart (vltINT32 mode, ccsERROR *error);
00297 ccsCOMPL_STAT strapSetChoppingMode (vltLOGICAL mode, ccsERROR *error);
00298 ccsCOMPL_STAT strapSetFluxThr (vltINT32 value, ccsERROR *error);
00299 ccsCOMPL_STAT strapSetSkyBackground (vltINT32 counts, ccsERROR *error);
00300 ccsCOMPL_STAT strapSetAFD (vltDOUBLE value, ccsERROR *error);
00301 ccsCOMPL_STAT strapGetAFD (vltDOUBLE *value, ccsERROR *error);
00302 ccsCOMPL_STAT strapDeg2IntMatrix (vltDOUBLE angle, ccsERROR *error);
00303 ccsCOMPL_STAT strapOptimize (vltDOUBLE starMag, ccsERROR *error);
00304 ccsCOMPL_STAT strapGetTotFlux (vltINT32 *totFlux, ccsERROR *error );
00305
00306 ccsCOMPL_STAT strapStartCalib (ccsERROR *error);
00307
00308 ccsCOMPL_STAT strapSetSetup (strapSET_PARAMS *parList, ccsERROR *error);
00309 ccsCOMPL_STAT strapGetSetup (strapSET_PARAMS *parList, ccsERROR *error);
00310 vltUINT16 strapGetIntTime();
00311
00312 vltINT32 strapNextNDF(vltINT8 flag, vltDOUBLE refFilter);
00313 void strapLogFits(vltINT32 what );
00314
00315
00316 ccsCOMPL_STAT strapSetNDF (
00317 vltINT32 idx,
00318 ccsERROR *error
00319 );
00320
00321 ccsCOMPL_STAT strapGetNDF (
00322 vltINT32 *filterIndex,
00323 vltDOUBLE *filterFactor,
00324 ccsERROR *error
00325 );
00326
00327 ccsCOMPL_STAT strapRtServerMode(
00328 vltINT32 rtMode,
00329 vltINT32 rtDataType,
00330 ccsERROR *error
00331 );
00332
00333 ccsCOMPL_STAT strapSetTilt(
00334 vltDOUBLE xtilt,
00335 vltDOUBLE ytilt,
00336 ccsERROR *error
00337 );
00338
00339 ccsCOMPL_STAT strapSetChopPos (
00340 vltUINT16 numPos,
00341 vltFLOAT *chopPosX,
00342 vltFLOAT *chopPosY,
00343 ccsERROR *error
00344 );
00345
00346 ccsCOMPL_STAT strapStdSet(
00347 vltUINT16 intTime,
00348 vltUINT16 thFreq,
00349 vltUINT16 skyBack,
00350 vltUINT16 diagRate,
00351 vltUINT16 dataRecs,
00352 vltINT32 flux,
00353 vltFLOAT spotx,
00354 vltFLOAT spoty,
00355 vltFLOAT intMatrix[4],
00356 ccsERROR *error
00357 );
00358
00359
00360 ccsCOMPL_STAT strapOptimizeNDF(
00361 vltINT32 minFlux,
00362 vltINT32 maxFlux,
00363 vltINT32 ccdFlux,
00364 vltLOGICAL selfSearch,
00365 ccsERROR *error
00366 );
00367
00368
00369
00370
00371 ccsCOMPL_STAT ndfDummySet ( vltINT32 idx, ccsERROR *error);
00372 ccsCOMPL_STAT ndfDummyGet ( vltINT32 *idx, ccsERROR *error);
00373 #endif
00374