00001 #ifndef _EGSEHMICOMP_H
00002 #define _EGSEHMICOMP_H
00003
00004
00005 #define MAXCONTEXTS (256)
00006
00007
00008 #define NMAX (16)
00009 #define NMIN (6)
00010 #define RMAX (8)
00011 #define RMIN (0)
00012 #define KMAX (7)
00013 #define KMIN (0)
00014
00015 #define UNPACK_FSN(H) (((unsigned int)(H)->ccdhead[0]<<16)+((unsigned int)(H)->ccdhead[1]))
00016 #define UNPACK_FID(H) (((unsigned int)(H)->ccdhead[2]<<16)+((unsigned int)(H)->ccdhead[3]))
00017 #define IMAGE_FSN(I) UNPACK_FSN(&(I->firstpacket))
00018 #define IMAGE_FID(I) UNPACK_FID(&(I->firstpacket))
00019 #define ID2FSN(ID) ((uint32_t) (ID) & 0xffffffff)
00020 #define ID2FID(ID) ((uint32_t) ((ID)>>32) & 0xffffffff)
00021 #define UNIQUEID(FSN,FID) ((int64_t)(FSN))
00022 #define unlikely(a) __builtin_expect((a), 0)
00023 #define likely(a) __builtin_expect((a), 1)
00024
00025
00026 #define MAX_CROPID ((1<<12)-1)
00027
00028
00029 #define MAX_LUTID ((1<<8)-1)
00030
00031 #define SUCCESS_HKCOMPLETE (3)
00032 #define SUCCESS_HK (2)
00033 #define SUCCESS_IMAGECOMPLETE (1)
00034 #define SUCCESS (0) // collides with a system define
00035 #define ERROR_BADOFFSET (-1)
00036 #define ERROR_CORRUPTDATA (-2)
00037 #define ERROR_BADHEADER (-3)
00038 #define ERROR_CTXOVERFLOW (-4)
00039 #define ERROR_INVALIDID (-5)
00040 #define ERROR_TOOMANYPIXELS (-6)
00041 #define ERROR_NOSUCHIMAGE (-7)
00042 #define ERROR_PARTIALOVERWRITE (-8)
00043 #define ERROR_WRONGPACKET (-9)
00044 #define ERROR_MISSING_FSN (-10)
00045 #define ERROR_MISSING_FID (-11)
00046 #define ERROR_INVALIDCROPID (-12)
00047 #define ERROR_NODATA (-13)
00048 #define ERROR_HK_UNKNOWN_APID (-14)
00049 #define ERROR_HK_CANNOT_FIND_VER_NUM (-15)
00050 #define ERROR_HK_CANNOT_LOAD_HK_VALUES (-16)
00051 #define ERROR_HK_CANNOT_LOAD_ENGR_VALUES (-17)
00052 #define ERROR_HK_INVALID_BITFIELD_LENGTH (-18)
00053 #define ERROR_HK_UNHANDLED_TYPE (-19)
00054 #define ERROR_HK_NOSUCHDIR (-20)
00055 #define ERROR_HK_CANNOT_LOAD_CONFIG (-21)
00056 #define ERROR_RAW_MODE_TRAILING_GARBAGE (-22)
00057 #define ERROR_BAD_OR_MISSING_CROP_TABLE (-23)
00058 #define ERROR_BAD_OR_MISSING_LOOKUP_TABLE (-24)
00059 #define ERROR_EMPTY_IMAGE_CONTEXT (-25)
00060
00061 #define PACKETHEADERWORDS (19)
00062 #define PACKETHEADERBYTES (2*19)
00063 #define PACKETHEADERBITS (16*19)
00064
00065 #define PACKETDATAWORDS (869)
00066 #define PACKETDATABYTES (2*869)
00067 #define PACKETDATABITS (16*869)
00068
00069 #define PACKETWORDS (PACKETHEADERWORDS+PACKETDATAWORDS)
00070 #define PACKETBYTES (PACKETHEADERBYTES+PACKETDATABYTES)
00071 #define PACKETBITS (PACKETHEADERBITS+PACKETDATABITS)
00072
00073 #define APID_HMI_SCIENCE_1 400
00074 #define APID_HMI_SCIENCE_2 410
00075 #define APID_HMI_TIME_1 405
00076 #define APID_HMI_TIME_2 415
00077 #define APID_HMI_IMSTAT_1 445
00078 #define APID_HMI_IMSTAT_2 475
00079
00080 #define APID_AIA_SCIENCE_1 500
00081 #define APID_AIA_SCIENCE_2 510
00082 #define APID_AIA_TIME_1 505
00083 #define APID_AIA_TIME_2 515
00084 #define APID_AIA_IMSTAT_1 529
00085 #define APID_AIA_IMSTAT_2 569
00086
00087 #define KEYWORD_NAME_SIZE 10
00088 #define KEYWORD_TYPE_SIZE 10
00089 #define TELEMETRY_MNEMONIC_SIZE 50
00090 #define HK_DECODER_SUCCESSFUL SUCCESS
00091 #define HK_DECODER_ERROR_UNKNOWN_APID ERROR_HK_UNKNOWN_APID
00092 #define HK_DECODER_ERROR_CANNOT_FIND_VER_NUM ERROR_HK_CANNOT_FIND_VER_NUM
00093 #define HK_DECODER_ERROR_CANNOT_LOAD_HK_VALUES ERROR_HK_CANNOT_LOAD_HK_VALUES
00094 #define HK_DECODER_ERROR_CANNOT_LOAD_ENGR_VALUES ERROR_HK_CANNOT_LOAD_ENGR_VALUES
00095 #define HK_DECODER_ERROR_UNKNOWN_ENV_VARIABLE ERROR_HK_CANNOT_LOAD_ENGR_VALUES
00096 #define MAX_CHAR_VERSION_NUMBER 10
00097 #define MAX_PACKET_ID_TYPE 100
00098 #define MAX_DATE_SIZE 15
00099 #define MAX_APID_POINTERS 4095
00100 #define MAX_FILE_NAME 300
00101 #define MAX_DIRECTORY_NAME 200
00102 #define MAX_SIZE_CHANGE_TIME 15
00103 #define MAX_SIZE_CHANGE_DATE 15
00104 #define MAX_HK_MNM 30
00105 #define MAX_HK_KYWD 10
00106 #define MAX_HK_VALUE_TYPE 10
00107 #define MAXLINE_IN_FILE 150
00108 #define MAX_VALUE_DSC 100
00109 #define MAX_NUMBER_COFFICIENTS 6
00110 #define SUCCESSFUL 0
00111 #define HMI_ID_TYPE "HMI"
00112 #define AIA_ID_TYPE "AIA"
00113 #define OTHER_ID_TYPE "SSIM"
00114 #define MAX_NUM_KW_LINES 3000
00115 #define MAX_NUM_ACON_LINES 1000
00116 #define MAXLINE_ACON_IN_FILE 200
00117 #define MAX_NUM_DCON_LINES 4000
00118 #define MAXLINE_DCON_IN_FILE 200
00119 #define HK_MAX_TLM_NAME 200
00120 #define ERROR_LOADING_HK_DATA 1
00121
00122
00123
00124 typedef struct CropTable_struct
00125 {
00126 unsigned int totalpix;
00127 unsigned int width, height;
00128 unsigned short *table;
00129 } CropTable_t;
00130
00131
00132 extern CropTable_t croptables[MAX_CROPID+1];
00133 extern unsigned short *lutables[MAX_LUTID+1];
00134 extern unsigned short *ilutables[MAX_LUTID+1];
00135
00136
00137
00138
00139
00140 #define RICE_ENCODE_OUT_OF_MEMORY -1
00141 #define RICE_ENCODE_OVERRUN -2
00142 #define RICE_DECODE_OVERRUN -3
00143 #define RICE_DECODE_TRUNCATED_INPUT -4
00144 #define RICE_DECODE_TRAILING_GARBAGE -5
00145
00146 extern int rice_encode1(const char *in, int nin, unsigned char *out, int bufsz, int blksz);
00147 extern int rice_encode2(const short *in, int nin, unsigned char *out, int bufsz, int blksz);
00148 extern int rice_encode4(const int *in, int nin, unsigned char *out, int bufsz, int blksz);
00149 extern int rice_decode1(const unsigned char *in, int nin, char *out, int nout, int blksz);
00150 extern int rice_decode2(const unsigned char *in, int nin, short *out, int nout, int blksz);
00151 extern int rice_decode4(const unsigned char *in, int nin, int *out, int nout, int blksz);
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 #ifndef LEV0SLOP
00162 typedef enum {DRMS_TYPE_INT8, DRMS_TYPE_INT16, DRMS_TYPE_INT32,
00163 DRMS_TYPE_INT64, DRMS_TYPE_UINT8, DRMS_TYPE_UINT16,
00164 DRMS_TYPE_UINT32, DRMS_TYPE_UINT64,
00165 DRMS_TYPE_FLOAT, DRMS_TYPE_DOUBLE,
00166 DRMS_TYPE_TIME, DRMS_TYPE_STRING} DRMS_Type_t;
00167
00168 typedef union DRMS_Type_Value
00169 {
00170 int8_t int8_val;
00171 int16_t int16_val;
00172 int32_t int32_val;
00173 int64_t int64_val;
00174 uint8_t uint8_val;
00175 uint16_t uint16_val;
00176 uint32_t uint32_val;
00177 uint64_t uint64_val;
00178 float float_val;
00179 double double_val;
00180 double time_val;
00181 char *string_val;
00182 } DRMS_Type_Value_t;
00183 #endif
00184
00185
00186 typedef struct Decompress_Stat_struct
00187 {
00188
00189 int64_t ID;
00190 time_t starttime;
00191
00192 unsigned short npackets;
00193 unsigned int numpix;
00194 unsigned int totalpix;
00195
00196 unsigned char backup_occured;
00197
00198
00199 unsigned char skip_occured;
00200
00201
00202 } Decompress_Stat_t;
00203
00204
00205
00206 typedef struct SciDataPacket_struct
00207 {
00208
00209 unsigned int shs;
00210 unsigned int shss;
00211 unsigned short ccdhead[4];
00212 short cropid;
00213 unsigned char romode;
00214 unsigned char headererr;
00215 unsigned char oflow;
00216
00217
00218
00219
00220 unsigned char tapcode;
00221 unsigned char bitselectid;
00222 unsigned char compid;
00223 unsigned char lutid;
00224 unsigned int offset;
00225
00226 unsigned short *data;
00227 } SciDataPacket_t;
00228
00229 #ifndef LEV0SLOP
00230
00231 #define MAX_KEYWORD_NAME_SIZE 64
00232 typedef struct HK_Keyword_struct {
00233 char name[MAX_KEYWORD_NAME_SIZE];
00234 char fitsname[9];
00235 int64_t raw_value;
00236
00237 DRMS_Type_t eng_type;
00238 DRMS_Type_Value_t eng_value;
00239 struct HK_Keyword_struct *next;
00240 } HK_Keyword_t;
00241
00242 typedef struct Image_struct
00243 {
00244
00245 int64_t ID;
00246
00247
00248 short width, height;
00249 short *data;
00250
00251
00252 struct Decompress_Stat_struct stat;
00253
00254
00255 SciDataPacket_t firstpacket;
00256 HK_Keyword_t *keywords;
00257
00258
00259
00260 struct Image_struct *next;
00261 } Image_t;
00262
00263
00264 typedef struct CCSDS_Packet_struct
00265 {
00266
00267 unsigned char version;
00268 unsigned char type;
00269 unsigned char shf;
00270 unsigned short apid;
00271 unsigned char sf;
00272 unsigned short ssc;
00273 unsigned short length;
00274
00275
00276 HK_Keyword_t *keywords;
00277
00278
00279 struct CCSDS_Packet_struct *next;
00280 } CCSDS_Packet_t;
00281 #endif
00282
00283
00284 typedef struct Decompress_Context_struct
00285 {
00286
00287 int64_t ID;
00288 unsigned short *pixelbuf;
00289
00290 struct Image_struct *image;
00291 } Decompress_Context_t;
00292
00293 int (*printk)(const char *fmt, ...);
00294 int (*printkerr)(const char *fmt, ...);
00295 void printk_set(int (*std)(const char *fmt, ...),
00296 int (*err)(const char *fmt, ...));
00297
00298 #ifndef LEV0SLOP
00299 int decompress_status_all(Decompress_Stat_t **stat);
00300 void decompress_print_status( Decompress_Stat_t *stat);
00301
00302
00303
00304 void decompress_undotransform(const unsigned int N, const unsigned int R,
00305 const unsigned int ILUTID,
00306 const unsigned int numpix, unsigned short *pixels);
00307
00308
00309
00310 void decompress_uncrop(const unsigned int CROPID, const unsigned int numpix,
00311 unsigned short *pixels, Image_t *image);
00312 Image_t *decompress_free_context(unsigned int ctx, int discard_image);
00313 int decompress_flush_image(unsigned int FSN, unsigned int FID,
00314 Image_t **image);
00315 int decompress_writefitsimage(const char* file, Image_t *image, int compress);
00316 void decompress_free_hk(CCSDS_Packet_t *p);
00317 void decompress_free_images(Image_t *image);
00318 void decompress_inittables(void);
00319 int decompress_read_croptable(const char *filename, const int cropid, CropTable_t *C);
00320 int decompress_read_lutable(const char *filename, const int lutid, unsigned short *ILUT);
00321 int check_completeness(Image_t **image);
00322 int decompress_next_vcdu(unsigned short vcdu[PACKETWORDS],
00323 Image_t **image, CCSDS_Packet_t **hk_packets);
00324 #endif
00325
00326
00327 #endif