Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

agInternal.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * E.S.O. - VLT project
00003 *
00004 * "@(#) $Id: agInternal.h,v 1.98 2003/11/11 14:58:39 vltsccm Exp $"
00005 *
00006 * who       when      what
00007 * --------  --------  ----------------------------------------------
00008 * rkarban 2002-02-11 move GetAgId to ag.h
00009 * gchiozzi 2000-11-03 Added errCloseStack() to asTASK_ERROR_RETURN
00010 * tcsmgr2 1999-12-01 Added meanLen to agGUIDE_CONFIG
00011 * tphan     22/03/99  Added pack/unpack to db macros
00012 * gchiozzi  24/02/99  Fixed bug in error macros
00013 * gchiozzi  19/02/99  Removed possibility of writing to logFile (spr 990011)
00014 * tcsmgr  17/10/98  Added handling of SETCVB command
00015 * gchiozzi  01/10/98  Removed piiAlphaOld and piiDeltaOld values. Now they are inside the PII struct
00016 * gchiozzi  30/09/98  Added maxIpFailure
00017 * tcsmgr  17/09/98  Added database definitions for ccdip checking configuration.
00018 * rkarban  05/08/98  add intensity to LAST_CORRECTTION structure
00019 * tcsmgr   12/05/98  Changed times from UINT32 to FLOAT to allow showing also msec 
00020 * tcsmgr  10/05/98  Added starting loop time in statData
00021 * tcsmgr  10/05/98  Added timestamps in lastCorrection
00022 * gchiozzi  09/05/98  Changed priority of agGuiding task from 95 to 25.
00023 * gchiozzi  08/05/98  Added freq attribute in stat data.
00024 * gchiozzi  07/05/98  Grouped guide configuration parameters in one structure.
00025 * gchiozzi  24/04/98  Remove agReplyMode. It is the only mode now.
00026 * rkarban  23/04/98  add member "data" to agGLOBAL
00027 * gchiozzi  23/04/98  Removed errorVectorReady. Not used any more.
00028 * gchiozzi  23/04/98  Removed agUfUsed. Not used any more.
00029 * gchiozzi  22/04/98  Removed agEventMode. Not supported any more. Only semaphore triggering used.
00030 * gchiozzi  20/04/98  Moved global variables allocation in ag.c
00031 * gchiozzi  20/04/98  Replaced lccMODULE_ID with agMOD  in logData and errAdd.
00032 * gchiozzi  31/03/98  Removed root point state attribute. Uses only std.state.
00033 * A.Wallan  13/01/94  First version
00034 * A.Wallan  01/03/96  cmm and new standards
00035 * tphan     10/03/96  Adapted for ag
00036 * awalland  13/12/96  Added variables for PII controller
00037 * tphan     20/01/98  Increased stack size from 40000 to 60000
00038 */
00039 
00040 /************************************************************************
00041 *   NAME
00042 *   
00043 * 
00044 *   SYNOPSIS
00045 *   
00046 * 
00047 *   DESCRIPTION
00048 *
00049 *   FILES
00050 *
00051 *   ENVIRONMENT
00052 *
00053 *   COMMANDS
00054 *
00055 *   RETURN VALUES
00056 *
00057 *   CAUTIONS 
00058 *
00059 *   EXAMPLES
00060 *
00061 *   SEE ALSO
00062 *
00063 *   BUGS   
00064 * 
00065 *------------------------------------------------------------------------
00066 */
00067 
00068 #ifndef AG_INTERNAL_H
00069 #define AG_INTERNAL_H
00070 
00071 /*
00072  * Object ag - Internal Definitions File
00073  */
00074 #define agRMS_TBL_SIZE            10
00075 
00076 /*
00077  * ag
00078  */
00079 
00080 /*
00081  * Constants
00082  */
00083 
00084 
00085 #define lccMODULE_ID          "ag"       /* LCC ID for the Auto Guide module */ 
00086 #define agMOD             "ag"       /* Name of the module               */
00087 #define agLOG_ID              111        /* log Id for ag TBD               */
00088 
00089 /*
00090  * Task spawn parameters for agServer
00091  */
00092  
00093 #define agSERVER_NAME         "agServer"  /* Name of the command interpreter */
00094                                           /* commands to ag LCU              */
00095 #define agSERVER_PRIORITY 80
00096 #define agSERVER_OPTIONS  VX_FP_TASK
00097 #define agSERVER_STACK    60000
00098   
00099 /*
00100  * Task spawn parameters for ag Guiding task
00101  */
00102  
00103 #define agTASK_NAME   "agGuiding"
00104 #define agTASK_PRIORITY   25
00105 #define agTASK_OPTIONS    VX_FP_TASK
00106 #define agTASK_STACK    60000
00107   
00108   
00109 #define agTIMEOUT   (5*TEN_MSEC)
00110 #define agTIMEOUT_TRK   (10*ONE_SEC)    /* 10 seconds for msgSetFilter*/
00111 
00112 
00113 /*
00114  * Types
00115  */
00116 typedef struct
00117 {
00118     vltDOUBLE x[agRMS_TBL_SIZE];
00119     vltDOUBLE y[agRMS_TBL_SIZE];
00120 } agRMS_TBL;
00121 
00122 typedef struct
00123 {
00124     vltINT32  nbrErrorVectors;
00125     vltINT32  nbrUsedErrorVectors;
00126     vltUINT32   startTime;      /* Time (sec)  of start of loop (start of first wipe) */
00127     vltUINT32   startTimeUsec;  /* Time (usec) of start of loop (start of first wipe) */
00128     vltDOUBLE   freq;
00129     vltINT32  errorTypeEncountered;
00130     vltDOUBLE errRaRms;    /* Rms of x-component of error vector over time (all images) */
00131     vltDOUBLE errDeclRms;  /* Rms of y-component of error vector over time (all images) */
00132 } agSTAT_DATA;
00133 
00134 /*
00135  * This structure contins all data necessary
00136  * to fully characterize exsposure and processing performances.
00137  * all times are expressed in ms
00138  *      wipeStart    is the time of the wipe start with
00139  *                   respect to the wipeStart of the previous iteration
00140  *      wipeTime     is the time used for the wipe
00141  *      expTime      is the actual exposure time
00142  *      readTime     is the actual readout time
00143  *      procTime     is the time spent in the CCD and ag/fs processes
00144  *                   to process data up to the send of corrections
00145  *      totalTime    sum of all previous time intervals  
00146  */
00147 typedef struct
00148 {
00149     vltFLOAT  wipeStart;
00150     vltFLOAT  wipeTime; 
00151     vltFLOAT  expTime;  
00152     vltFLOAT  readTime;   
00153     vltFLOAT  procTime;   
00154     vltFLOAT  totalTime;  
00155  
00156     vltDOUBLE deltaRa;   /* ra(alpha) component of error vector in arcsec */
00157     vltDOUBLE deltaDecl; /* decl (delta) component of error vector in arcsec */
00158     vltDOUBLE errRa;    /* x component of error vector in pixel */
00159     vltDOUBLE errDecl;  /* y component of error vector in pixel */
00160 
00161     vltDOUBLE xFWHM;
00162     vltDOUBLE yFWHM;
00163     vltDOUBLE xRms; /* Rms of x over the integration time of the last image */
00164     vltDOUBLE yRms; /* Rms of y over the integration time of the last image */
00165 
00166     vltDOUBLE   intensity; 
00167 } agLAST_CORRECTION;
00168 
00169 
00170 typedef struct
00171 {
00172     char    conversionFuncName[64];
00173     char    sendOffsetFuncName[64];
00174 
00175     FUNCPTR   conversionFuncPtr;
00176     FUNCPTR   sendOffsetFuncPtr;
00177 
00178     vltDOUBLE   sendFreq;   /* used sendPeriodMsec instead */
00179     vltINT32    sendPeriodMsec;
00180     vltINT32    errorVectorValues;
00181     vltINT32    meanLen;
00182     vltDOUBLE   errorVectorMin;
00183     vltDOUBLE   offsetMax;
00184     vltINT32    maxIpFailure;
00185 
00186     ccdipCVBUF          cvb;
00187     vltINT32            rejectionLimit;
00188 
00189     agPII               pii;
00190     agPII_HISTORY       piiAlpha;
00191     agPII_HISTORY       piiDelta;
00192     
00193 } agGUIDE_CONFIG;
00194 
00195 
00196 typedef struct
00197 {
00198     char    ccdName[64];
00199     dbSYMADDRESS  dbRoot;
00200     
00201     /* DB */
00202     vltINT32    trkAxisListUsed;
00203     agTRK_AXIS_LIST trkAxisList;
00204     
00205     agLAST_CORRECTION lastCorrection;
00206     agSTAT_DATA   statData;
00207     
00208     vltINT32    guidingActive;
00209     vltINT32    guidingNullCorr;
00210     vltINT32    guidingNonFatalErrorCtr;
00211     ccsERROR    guidingErrorStack;
00212 
00213     /* Guide configuration */
00214     agGUIDE_CONFIG      config;
00215 
00216     /* control */
00217     SEM_ID    mutexSem;
00218     
00219     vltLOGICAL    simulation;
00220     
00221     /* For Frequency of offset msg */
00222     vltINT32    evtAccumulatedForMsgCtr;
00223     agERROR_VECTOR  errorAccumulatedForMsg;
00224     
00225     /* For Periodic replies */
00226     vltINT32    replyCtr;
00227     agOFFSET    offsetAccumulatedForReply;
00228     
00229     /* For CCD database */
00230     dbDIRADDRESS  ipXCenDirAddr;
00231     dbDIRADDRESS  ipYCenDirAddr;
00232 
00233     /* For User function database */
00234     
00235     vltDOUBLE   xPixelSize;
00236     vltDOUBLE   yPixelSize;
00237     
00238     SEM_ID              errorVectorSynchroSem;
00239     
00240     vltDOUBLE   imageScale;   /* to be tuned */
00241     vltINT32    focusType;
00242                                                 /* In different foci, the  different
00243                number of mirrors, and so of reflections, 
00244                accounts for different signs in the
00245                conversion from (X,Y) to (alpha,delta)
00246                This is done in agConversion()
00247              */
00248 
00249     
00250     /* cai tables for DB access */
00251     char    *attrVector;
00252     char                *configVector;
00253 
00254     void                *data; /* general purpose pointer to extend the structure */
00255     
00256 } agGLOBAL;
00257 
00258 
00259 /*
00260  * Global data (allocated in ag.c)
00261  */
00262 extern char agVersion[];
00263 
00264 extern char agRecCmdStr[];
00265 extern char agExeCmdStr[];
00266 
00267 extern agGLOBAL  agGlobal;
00268 extern agGLOBAL *agGlobalPtr;
00269 
00270 extern agCcdipAGBUF agUfBuff;
00271 
00272 extern agRMS_TBL  agRmsCorrectionTbl;
00273 extern agRMS_TBL  agRmsErrorVectorTbl;
00274 
00275 /*
00276  * CCS Macro
00277  */
00278 #define agREGISTER_CCS()                      \
00279 {                                             \
00280     char vxProcName[6];                       \
00281     ccsPROCNAME ccsProcName;                  \
00282                                               \
00283 /*                                            \
00284  * get first 5 chars of vx procname and       \
00285  * mangle with taskId to get unique           \
00286  * ccs proc name                              \
00287  */                                           \
00288     strncpy(vxProcName,taskName(taskIdSelf()),5);                \
00289     vxProcName[5] = 0;                                           \
00290     sprintf(ccsProcName,"%s%x",vxProcName,taskIdSelf());         \
00291     if (ccsInit(ccsProcName,0,NULL,NULL,error) != SUCCESS)       \
00292         return FAILURE;                                          \
00293 }
00294 
00295 #define agEXIT_CCS()            \
00296 {                               \
00297     ccsERROR     error2;        \
00298                                 \
00299     errResetStack(&error2);     \
00300     ccsExit(&error2);           \
00301 }
00302 
00303 /*
00304  * Misc macro
00305  */
00306 #define agVERBOSE_CMD(str) \
00307 { \
00308     if (lcuVerbose(msg, str, error) != SUCCESS) \
00309         return FAILURE; \
00310 }
00311 
00312 /* Macro to compensate "bug" in lcc.
00313  * When a function returns a FAILURE without any errAdd, i.e. errorNumber null,
00314  * instead of an expected Error reply, no reply is sent back to the sender of
00315  * the command 
00316  */
00317 #define agCHECK_FAILURE \
00318 { \
00319     if ((status == FAILURE) && (error->errorNumber == 0))\
00320         agERROR_ADD(agERR_INTERNAL, "%s", \
00321         "Known lcc bug: return FAILURE but errorNumber still 0"); \
00322 }
00323 
00324 /*
00325  * error macro
00326  */
00327 #ifdef __FILE_LINE__
00328 #undef __FILE_LINE__
00329 #endif
00330 
00331 #define _ag_tostr(a) #a
00332 #define _ag_tostr_pass2(a) _ag_tostr(a)
00333 
00334 #define __FILE_LINE__   __FILE__ "(" _ag_tostr_pass2(__LINE__) ")"
00335 
00336 #define agERROR_ADD(errNum,format,args...) \
00337     { \
00338     /*printf("ERROR_ADD %s(%d): ",__FILE__,__LINE__);*/\
00339     /*printf(format, ##args);*/ \
00340     /*printf("\n");*/ \
00341     errAdd(error,agMOD,errNum,__FILE_LINE__,NULL,##args); \
00342     }                                                             
00343  
00344 #define agERROR_RETURN(errNum,format,args...) \
00345     { \
00346     printf("ERROR_RETURN %s(%d): ",__FILE__,__LINE__);\
00347     printf(format, ##args); \
00348     printf("\n"); \
00349     errAdd(error,agMOD,errNum,__FILE_LINE__,NULL,##args); \
00350     return FAILURE; \
00351     }                                                             
00352   
00353 #define agTASK_ERROR_RETURN(errNum,format,args...) \
00354     { \
00355     ptr->statData.errorTypeEncountered = errNum; \
00356     printf("ERROR_RETURN %s(%d): ",__FILE__,__LINE__);\
00357     printf(format, ##args); \
00358     printf("\n"); \
00359     errAdd(error,agMOD,errNum,__FILE_LINE__,NULL,##args); \
00360     errCloseStack(error); \
00361     return FAILURE; \
00362     }                                                             
00363   
00364 
00365 #define agTASK_ERROR_RETURN_NC(errNum,format,args...) \
00366     { \
00367     ptr->statData.errorTypeEncountered = errNum; \
00368     printf("ERROR_RETURN %s(%d): ",__FILE__,__LINE__);\
00369     printf(format, ##args); \
00370     printf("\n"); \
00371     errAdd(error,agMOD,errNum,__FILE_LINE__,NULL,##args); \
00372     semGive(*syncSem); \
00373     return FAILURE; \
00374     }                                                             
00375 /*
00376  * DB macro
00377  */
00378 #define agMEMCPY(s) \
00379 { \
00380     memcpy(ptr,&s,sizeof s); ptr += sizeof s; \
00381 }
00382 
00383 #define agDBWRITE_STAT() \
00384 {                                             \
00385     char bStream[sizeof(agSTAT_DATA)]; \
00386     char *ptr = bStream; \
00387     \
00388     agMEMCPY(agGlobalPtr->statData.nbrErrorVectors); \
00389     agMEMCPY(agGlobalPtr->statData.nbrUsedErrorVectors); \
00390     agMEMCPY(agGlobalPtr->statData.startTime); \
00391     agMEMCPY(agGlobalPtr->statData.startTimeUsec); \
00392     agMEMCPY(agGlobalPtr->statData.freq); \
00393     agMEMCPY(agGlobalPtr->statData.errorTypeEncountered); \
00394     agMEMCPY(agGlobalPtr->statData.errRaRms); \
00395     agMEMCPY(agGlobalPtr->statData.errDeclRms); \
00396     \
00397     if (caiWriteTable(agGlobalPtr->attrVector, agDB_STAT_DATA, \
00398         (void *)bStream, 0, 0, -1,-1, error) != SUCCESS) \
00399         agERROR_RETURN(agERR_DBWRITE,"%s", "caiWriteTable Statistic");\
00400 }
00401 
00402 #define agDBWRITE_LAST_CORRECTION() \
00403 {                                             \
00404     char bStream[sizeof(agLAST_CORRECTION)]; \
00405     char *ptr = bStream; \
00406     \
00407     agMEMCPY(agGlobalPtr->lastCorrection.wipeStart); \
00408     agMEMCPY(agGlobalPtr->lastCorrection.wipeTime); \
00409     agMEMCPY(agGlobalPtr->lastCorrection.expTime); \
00410     agMEMCPY(agGlobalPtr->lastCorrection.readTime); \
00411     agMEMCPY(agGlobalPtr->lastCorrection.procTime); \
00412     agMEMCPY(agGlobalPtr->lastCorrection.totalTime); \
00413     agMEMCPY(agGlobalPtr->lastCorrection.deltaRa); \
00414     agMEMCPY(agGlobalPtr->lastCorrection.deltaDecl); \
00415     agMEMCPY(agGlobalPtr->lastCorrection.errRa); \
00416     agMEMCPY(agGlobalPtr->lastCorrection.errDecl); \
00417     agMEMCPY(agGlobalPtr->lastCorrection.xFWHM); \
00418     agMEMCPY(agGlobalPtr->lastCorrection.yFWHM); \
00419     agMEMCPY(agGlobalPtr->lastCorrection.xRms); \
00420     agMEMCPY(agGlobalPtr->lastCorrection.yRms); \
00421     agMEMCPY(agGlobalPtr->lastCorrection.intensity); \
00422     \
00423     if (caiWriteTable(agGlobalPtr->attrVector, agDB_LAST_CORRECTION, \
00424         (void *)bStream, 0, 0, -1,-1, error) != SUCCESS) \
00425         agERROR_RETURN(agERR_DBWRITE,"%s", "caiWriteTable Last Correction");\
00426 }
00427 
00428 /*
00429  * mutex semaphore macro
00430  */
00431 #define MUTEX_ENTER \
00432 { \
00433 if(semTake(agGlobalPtr->mutexSem, 1) != OK) \
00434     { \
00435     agERROR_RETURN(agERR_VXWORKS, "Take Semaphore %d", errnoGet()) \
00436     }  \
00437 }
00438 
00439 #define MUTEX_EXIT \
00440 { \
00441 if(semGive(agGlobalPtr->mutexSem) != OK) \
00442     agERROR_RETURN(agERR_VXWORKS, "Give Semaphore %d", errnoGet()) \
00443 }
00444 
00445 
00446 /*
00447  * Function prototypes
00448  */ 
00449  
00450 ccsCOMPL_STAT agStdOff (
00451   IN  const char *moduleId,
00452   OUT ccsERROR *error);
00453  
00454 
00455 /*
00456  * agDbReadConfig.c
00457  */
00458 
00459 ccsCOMPL_STAT agDbReadConfig (
00460   OUT agGLOBAL  *ptr,
00461   OUT ccsERROR    *error);
00462 
00463 ccsCOMPL_STAT agDbReadConfigParams (
00464   IN  char            *configVector,
00465   OUT agGUIDE_CONFIG  *config,
00466   OUT ccsERROR        *error);
00467 
00468 ccsCOMPL_STAT agDbReadErrVecParams (IN  char            *configVector,
00469             OUT agGUIDE_CONFIG  *config,
00470             OUT ccsERROR        *error);
00471 
00472 ccsCOMPL_STAT agDbWriteErrVecParams (OUT  char          *configVector,
00473              OUT agGUIDE_CONFIG *config,
00474              OUT ccsERROR        *error);
00475 /*
00476  *
00477  */
00478 ccsCOMPL_STAT agWaitErrorVector (
00479   OUT vltLOGICAL    *newErrorVector,
00480   OUT ccsERROR    *error
00481   );
00482 ccsCOMPL_STAT agExitErrorVectorHook (
00483   OUT ccsERROR    *error
00484   );
00485 ccsCOMPL_STAT agInitErrorVectorHook (
00486   OUT ccsERROR    *error
00487   );
00488 
00489 ccsCOMPL_STAT agStdGetState(
00490     OUT lccDEV_MODE *agState,
00491     OUT ccsERROR    *error
00492             );
00493 ccsCOMPL_STAT agStdSetState(
00494                 IN  lccDEV_MODE  agState,
00495     OUT ccsERROR     *error
00496             );
00497 /*
00498  * agGuidingTask.c
00499  */
00500 ccsCOMPL_STAT agGuidingTaskLoop (IN  agGLOBAL   *ptr,
00501          OUT ccsERROR *error);
00502 
00503 ccsCOMPL_STAT agGuidingTask (IN   SEM_ID         *syncSem,
00504            OUT  ccsCOMPL_STAT  *initStatus,
00505            IN   vltDOUBLE  *rotAngle,
00506            IN   agGLOBAL   *ptr);
00507 /*
00508  * agSendPeriodicReply.c
00509  */
00510 ccsCOMPL_STAT agSendPeriodicReply (
00511       IN  msgMSG  *msg,
00512   IN  vltDOUBLE repFrq,
00513   OUT ccsERROR  *error);
00514 
00515 /*
00516  * agDbWriteGuidingActive.c
00517  */
00518 ccsCOMPL_STAT agDbWriteGuidingActive (
00519   OUT vltINT32  active,
00520   OUT ccsERROR    *error
00521   );
00522 
00523 /*
00524  * agDbReadRotAngle.c
00525  */
00526 ccsCOMPL_STAT agDbWriteRotAngle (OUT vltDOUBLE  rotAngle,
00527          OUT ccsERROR   *error);
00528 
00529 /*
00530  * agDbRWPIIParams.c
00531  */
00532 
00533 ccsCOMPL_STAT agDbReadPIIParams (IN  char      *configVector,
00534          OUT agPII     *pii,
00535          OUT ccsERROR  *error);
00536   
00537 ccsCOMPL_STAT agDbWritePIIParams (IN  char      *configVector,
00538           IN  agPII *pii,
00539           OUT ccsERROR  *error);
00540 
00541 /*
00542  * agConfigPIIParams.c
00543  */
00544 
00545 ccsCOMPL_STAT agConfigPIIParams ( IN  agPII_CMD   *pii,
00546           OUT ccsERROR    *error);
00547   
00548 /*
00549  * agDbRWCcdipParams.c
00550  */
00551 
00552 ccsCOMPL_STAT agDbReadCcdipParams (IN  char       *configVector,
00553            OUT ccdipCVBUF *cvb,
00554            OUT vltINT32   *pRejectionLimit,
00555            OUT ccsERROR   *error);
00556 
00557 ccsCOMPL_STAT agDbWriteCcdipParams (IN  char       *configVector,
00558             IN  ccdipCVBUF *cvb,
00559             IN  vltINT32    rejectionLimit,
00560             OUT ccsERROR   *error);
00561 
00562 /*
00563  * agConfigCcdipParams.c
00564  */
00565 
00566 ccsCOMPL_STAT agConfigCcdipParams ( IN  ccdipCVBUF *cvb,
00567             IN  vltINT32    rejectionLimit,
00568             OUT ccsERROR   *error);
00569   
00570 /*
00571  * agConfig.c
00572  */
00573 /* GCH - 30/11/1999
00574  * Here also the meanLen should be handled.
00575  * We do not do it now, since we do now want yet to modify the CONFIG command
00576  * adding a new parameter.
00577  */
00578 ccsCOMPL_STAT agConfig (
00579   IN  vltDOUBLE errorVectorMin,
00580   IN  vltDOUBLE offsetMax,
00581   IN  vltDOUBLE sendFreq,
00582   IN  vltINT32  errorVectorValues,
00583   OUT ccsERROR  *error);
00584 
00585 #endif /* !AG_INTERNAL_H */

Generated on Wed Dec 3 14:52:05 2003 for ATCS API by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001