00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef AG_INTERNAL_H
00069 #define AG_INTERNAL_H
00070
00071
00072
00073
00074 #define agRMS_TBL_SIZE 10
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 #define lccMODULE_ID "ag"
00086 #define agMOD "ag"
00087 #define agLOG_ID 111
00088
00089
00090
00091
00092
00093 #define agSERVER_NAME "agServer"
00094
00095 #define agSERVER_PRIORITY 80
00096 #define agSERVER_OPTIONS VX_FP_TASK
00097 #define agSERVER_STACK 60000
00098
00099
00100
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)
00111
00112
00113
00114
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;
00127 vltUINT32 startTimeUsec;
00128 vltDOUBLE freq;
00129 vltINT32 errorTypeEncountered;
00130 vltDOUBLE errRaRms;
00131 vltDOUBLE errDeclRms;
00132 } agSTAT_DATA;
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
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;
00157 vltDOUBLE deltaDecl;
00158 vltDOUBLE errRa;
00159 vltDOUBLE errDecl;
00160
00161 vltDOUBLE xFWHM;
00162 vltDOUBLE yFWHM;
00163 vltDOUBLE xRms;
00164 vltDOUBLE yRms;
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;
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
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
00214 agGUIDE_CONFIG config;
00215
00216
00217 SEM_ID mutexSem;
00218
00219 vltLOGICAL simulation;
00220
00221
00222 vltINT32 evtAccumulatedForMsgCtr;
00223 agERROR_VECTOR errorAccumulatedForMsg;
00224
00225
00226 vltINT32 replyCtr;
00227 agOFFSET offsetAccumulatedForReply;
00228
00229
00230 dbDIRADDRESS ipXCenDirAddr;
00231 dbDIRADDRESS ipYCenDirAddr;
00232
00233
00234
00235 vltDOUBLE xPixelSize;
00236 vltDOUBLE yPixelSize;
00237
00238 SEM_ID errorVectorSynchroSem;
00239
00240 vltDOUBLE imageScale;
00241 vltINT32 focusType;
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 char *attrVector;
00252 char *configVector;
00253
00254 void *data;
00255
00256 } agGLOBAL;
00257
00258
00259
00260
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
00277
00278 #define agREGISTER_CCS() \
00279 { \
00280 char vxProcName[6]; \
00281 ccsPROCNAME ccsProcName; \
00282 \
00283
00284
00285
00286
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
00305
00306 #define agVERBOSE_CMD(str) \
00307 { \
00308 if (lcuVerbose(msg, str, error) != SUCCESS) \
00309 return FAILURE; \
00310 }
00311
00312
00313
00314
00315
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
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 \
00339 \
00340 \
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
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
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
00448
00449
00450 ccsCOMPL_STAT agStdOff (
00451 IN const char *moduleId,
00452 OUT ccsERROR *error);
00453
00454
00455
00456
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
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
00509
00510 ccsCOMPL_STAT agSendPeriodicReply (
00511 IN msgMSG *msg,
00512 IN vltDOUBLE repFrq,
00513 OUT ccsERROR *error);
00514
00515
00516
00517
00518 ccsCOMPL_STAT agDbWriteGuidingActive (
00519 OUT vltINT32 active,
00520 OUT ccsERROR *error
00521 );
00522
00523
00524
00525
00526 ccsCOMPL_STAT agDbWriteRotAngle (OUT vltDOUBLE rotAngle,
00527 OUT ccsERROR *error);
00528
00529
00530
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
00543
00544
00545 ccsCOMPL_STAT agConfigPIIParams ( IN agPII_CMD *pii,
00546 OUT ccsERROR *error);
00547
00548
00549
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
00564
00565
00566 ccsCOMPL_STAT agConfigCcdipParams ( IN ccdipCVBUF *cvb,
00567 IN vltINT32 rejectionLimit,
00568 OUT ccsERROR *error);
00569
00570
00571
00572
00573
00574
00575
00576
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