1 |
#ident "$Header: /home/cvsuser/cvsroot/JSOC/proj/lev0/apps/load_hk_config_files_iris.c,v 1.1 2013/01/24 18:39:37 jim Exp $" |
2 |
/***************************************************************************** |
3 |
* Filename: load_hk_config_files.c * |
4 |
* Author: Carl Cimilluca * |
5 |
* Create Date: August, 5, 2005 * |
6 |
* Description: This file contains modules to load from files the * |
7 |
* housekeeping data into memory and into a link list data * |
8 |
* structure for modules in file decode_hk.c to use to decode * |
9 |
* housekeeping data from the stream of packets from a EGSE * |
10 |
* telemetry simulator or from DDS * |
11 |
* Global Variables: * |
12 |
* ---------------------- ------------------------- --------------------- * |
13 |
* Type Name Description * |
14 |
* ---------------------- ------------------------- --------------------- * |
15 |
* APID_Pointer_HK_Configs* global_apid_configs Top pointer to the * |
16 |
* link list used to hold* |
17 |
* configuration data * |
18 |
* Used in 4 places to * |
19 |
* make deallocate easier* |
20 |
* from other functions * |
21 |
* to make it easier for * |
22 |
* decode_hk functions to* |
23 |
* use data in list * |
24 |
* GTCIDS_Version_Number* global_gtcids_vn Top pointer to the * |
25 |
* link list used to hold* |
26 |
* the Ground to code ids* |
27 |
* file's file-version- * |
28 |
* number and packet- * |
29 |
* version-number data * |
30 |
* pairs. Use in 4 places* |
31 |
* to make deallocate * |
32 |
* easier from other * |
33 |
* functions. * |
34 |
* SHCIDS_Version_Number* global_shcids_vn Top pointer to the * |
35 |
* link list used to hold* |
36 |
* the SDO HK Code ids * |
37 |
* file's file-version- * |
38 |
* number and packet- * |
39 |
* date-time data * |
40 |
* pairs. * |
41 |
* (C) Stanford University, 2005 * |
42 |
* Revision History: * |
43 |
*****************************************************************************/ |
44 |
|
45 |
|
46 |
|
47 |
#include <stdio.h> |
48 |
#include <stdlib.h> |
49 |
#include <string.h> |
50 |
#include <math.h> |
51 |
#include <time.h> |
52 |
#include <sys/types.h> |
53 |
#include <sys/stat.h> |
54 |
#include <sys/vfs.h> |
55 |
#include <fcntl.h> |
56 |
#include <unistd.h> |
57 |
#include <libgen.h> |
58 |
#include "drms_types.h" // I have no idea why this is needed |
59 |
#include "egsehmicomp.h" |
60 |
#include "printk.h" |
61 |
#include "decode_hk.h" |
62 |
#include <dirent.h> |
63 |
#include "write_hk_to_drms.h" |
64 |
|
65 |
#define LOAD_HK_C |
66 |
#include "load_hk_config_files.h" |
67 |
#undef LOAD_HK_C |
68 |
|
69 |
/***************************** function prototypes ****************************/ |
70 |
APID_HKPFD_Files * allocate_apid_hkpfd_files_nodes(int *ptrFirstTimeFlag); |
71 |
void load_gtcids_data( GTCIDS_Version_Number* top_ptr_gtcids_data, |
72 |
APID_Pointer_HK_Configs *top_apid_ptr_hk_configs); |
73 |
int check_for_sdo_apid(int apid); |
74 |
|
75 |
#define LOAD_HK_C |
76 |
#include "load_hk_config_files.h" |
77 |
#undef LOAD_HK_C |
78 |
|
79 |
/***************************** function prototypes ****************************/ |
80 |
APID_HKPFD_Files * allocate_apid_hkpfd_files_nodes(int *ptrFirstTimeFlag); |
81 |
void load_gtcids_data( GTCIDS_Version_Number* top_ptr_gtcids_data, |
82 |
APID_Pointer_HK_Configs *top_apid_ptr_hk_configs); |
83 |
int check_for_sdo_apid(int apid); |
84 |
void deallocate_apid_hkpfd_files_nodes(APID_HKPFD_Files *top_ptr_apid_hkpfd_files_ptr) ; |
85 |
char * find_file_version_number(GTCIDS_Version_Number *top,char p_version_number[MAX_CHAR_VERSION_NUMBER], int apid); |
86 |
char * find_fvn_from_shcids(SHCIDS_Version_Number *top,char pkt_date[MAX_SIZE_PKT_DATE],int apid); |
87 |
/***************************** global variables ******************************/ |
88 |
APID_Pointer_HK_Configs *global_apid_configs; |
89 |
GTCIDS_Version_Number *global_gtcids_vn; |
90 |
SHCIDS_Version_Number *global_shcids_vn; |
91 |
|
92 |
|
93 |
|
94 |
/**********housekeeping load configuration and formats routines***************/ |
95 |
/***************************************************************************** |
96 |
* Load All APIDS HK Configs |
97 |
* Module Name: |
98 |
* Description: This is the top level function to decode housekeeping keywords. |
99 |
* Status load_all_apids_hk_configs(): Tested |
100 |
* |
101 |
*!!NOTE: JA 07Mar2012 Modified for simplicity for IRIS. There may be vestigial |
102 |
* stuff left over from SDO. |
103 |
*****************************************************************************/ |
104 |
int load_all_apids_hk_configs(int apid, char version_number[MAX_CHAR_VERSION_NUMBER], char pkt_date[MAX_SIZE_PKT_DATE]) |
105 |
{ |
106 |
/* declarations */ |
107 |
APID_Pointer_HK_Configs *apid_ptr_hk_configs; |
108 |
APID_Pointer_HK_Configs *top_apid_ptr_hk_configs; |
109 |
APID_HKPFD_Files *top_apid_hkpfd_files; |
110 |
APID_HKPFD_Files *hkpfd_files; |
111 |
GTCIDS_Version_Number *top_ptr_gtcids_data; |
112 |
SHCIDS_Version_Number *top_ptr_shcids_data; |
113 |
int apid_array[MAX_APID_POINTERS]; |
114 |
char apidstr_array[MAX_APID_POINTERS][10]; |
115 |
int number_of_apids, i; |
116 |
char file_version_number[MAX_CHAR_VERSION_NUMBER]; |
117 |
char *ptr_fvn; |
118 |
//HK_Config_Files *hk_configs; /* used to print results which is commented out*/ |
119 |
// Keyword_Parameter *hk_keyword;/* used to print results which is commented out*/ |
120 |
|
121 |
/* Init parameter */ |
122 |
//ptr_fvn=file_version_number; |
123 |
ptr_fvn=version_number; //use same version # in IRIS case |
124 |
|
125 |
/* Load data from ground to code ids file for apid 1-63,400's and 500's*/ |
126 |
top_ptr_gtcids_data = read_gtcids_hk_file(); |
127 |
|
128 |
//NOOP for IRIS? |
129 |
/* Load data from sdo hk ids file for apids 129,etc */ |
130 |
top_ptr_shcids_data = read_shcids_hk_file(); |
131 |
|
132 |
/* get file version number*/ |
133 |
if(check_for_sdo_apid(apid)) |
134 |
{ |
135 |
/* Check for file version number in ground to code ids file */ |
136 |
ptr_fvn=find_fvn_from_shcids(top_ptr_shcids_data, pkt_date, apid); |
137 |
} |
138 |
else |
139 |
{ |
140 |
/* Check for file version number in ground to code ids file */ |
141 |
ptr_fvn=find_file_version_number(top_ptr_gtcids_data, version_number, apid); |
142 |
} |
143 |
|
144 |
/* load HK_Config_Files structures for each apid */ |
145 |
if ((top_apid_hkpfd_files = read_all_hk_config_files(apid, ptr_fvn, version_number)) == NULL) |
146 |
return ERROR_HK_NOSUCHDIR; |
147 |
|
148 |
/* get list of unique apids to read and allocate space for*/ |
149 |
number_of_apids = 0; |
150 |
memset(apid_array, 0, sizeof(apid_array)); |
151 |
for(i=0; i < MAX_APID_POINTERS; i++) |
152 |
{ |
153 |
memset(apidstr_array[i],'\0', 10); |
154 |
} |
155 |
for(hkpfd_files=top_apid_hkpfd_files; hkpfd_files; |
156 |
hkpfd_files=hkpfd_files->next) |
157 |
{ |
158 |
/* See if we already have this apid. */ |
159 |
for (i=0; i<number_of_apids; i++) |
160 |
{ |
161 |
|
162 |
if (apid_array[i] == hkpfd_files->apid) |
163 |
{ |
164 |
/* apid is already there in array so skip setting */ |
165 |
break; |
166 |
} |
167 |
} |
168 |
if (i >= number_of_apids) |
169 |
{ |
170 |
/* Nope this was a new one. Insert apid number in the apid_array. */ |
171 |
apid_array[i]= hkpfd_files->apid; |
172 |
|
173 |
/* set apid string value in apidstr_array*/ |
174 |
strcpy(apidstr_array[i], hkpfd_files->apid_name); |
175 |
number_of_apids++; |
176 |
} |
177 |
} |
178 |
/* load apid pointer to HK Configs structure apid-value and allocate nodes */ |
179 |
for ( i=0; i < number_of_apids; i++) |
180 |
{ |
181 |
if ( i == 0) |
182 |
{ |
183 |
/* create and load first node */ |
184 |
apid_ptr_hk_configs = (APID_Pointer_HK_Configs *)malloc(sizeof(APID_Pointer_HK_Configs)); |
185 |
top_apid_ptr_hk_configs = apid_ptr_hk_configs; |
186 |
} |
187 |
else |
188 |
{ |
189 |
/* create and load next node */ |
190 |
apid_ptr_hk_configs->next = (APID_Pointer_HK_Configs *)malloc(sizeof(APID_Pointer_HK_Configs)); |
191 |
apid_ptr_hk_configs = apid_ptr_hk_configs->next; |
192 |
} |
193 |
|
194 |
/* set apid number and apid string in structure to use to lookup apids during decoding */ |
195 |
apid_ptr_hk_configs->apid = apid_array[i]; |
196 |
strcpy(apid_ptr_hk_configs->apid_name, apidstr_array[i]); |
197 |
|
198 |
/* set other values in node */ |
199 |
apid_ptr_hk_configs->next= NULL; |
200 |
apid_ptr_hk_configs->ptr_hk_configs= (HK_Config_Files*)NULL; |
201 |
} |
202 |
|
203 |
/* set moving pointer to top of list */ |
204 |
apid_ptr_hk_configs = top_apid_ptr_hk_configs; |
205 |
for(i=0; i < number_of_apids; i++) |
206 |
{ |
207 |
load_config_data( top_apid_hkpfd_files, apid_ptr_hk_configs); |
208 |
apid_ptr_hk_configs = apid_ptr_hk_configs->next; |
209 |
} /*End for*/ |
210 |
|
211 |
//NOOP for IRIS TBD?? |
212 |
/* load file_version_number based on packet version number */ |
213 |
load_gtcids_data(top_ptr_gtcids_data, top_apid_ptr_hk_configs); |
214 |
|
215 |
/* set global variable to use for decode_hk modules */ |
216 |
global_apid_configs = top_apid_ptr_hk_configs; |
217 |
|
218 |
/* deallocate top_apid_hkpfd_files link list */ |
219 |
deallocate_apid_hkpfd_files_nodes(top_apid_hkpfd_files) ; |
220 |
|
221 |
/******PRINT RESULTS FOR DEBUGGING**********/ |
222 |
/*** |
223 |
for (apid_ptr_hk_configs=global_apid_configs; apid_ptr_hk_configs; |
224 |
apid_ptr_hk_configs=apid_ptr_hk_configs->next) |
225 |
{ |
226 |
if( apid_ptr_hk_configs->apid == 445) |
227 |
{ |
228 |
printf("APID_Pointer_HK_Configs apid is %d\n", apid_ptr_hk_configs->apid); |
229 |
for (hk_configs=apid_ptr_hk_configs->ptr_hk_configs; hk_configs; |
230 |
hk_configs=hk_configs->next) |
231 |
{ |
232 |
printf("HK_Configs file version number is %s\n", hk_configs->file_version_number ); |
233 |
if (!strcmp(hk_configs->file_version_number, "1.38")) |
234 |
{ |
235 |
printf("HK_Configs file version number is %s\n", hk_configs->file_version_number ); |
236 |
for ( hk_keyword = hk_configs->keywords;hk_keyword; |
237 |
hk_keyword = hk_keyword->next) |
238 |
{ |
239 |
printf("Keywords is %s\n", hk_configs->keywords->keyword_name ); |
240 |
} |
241 |
} |
242 |
} |
243 |
} |
244 |
} |
245 |
***/ |
246 |
/******END PRINT RESULTS FOR DEBUGGING *******/ |
247 |
|
248 |
/* return status */ |
249 |
return HK_SUCCESSFUL; |
250 |
}/*End Module: load_all_apids_hk_configs */ |
251 |
|
252 |
|
253 |
|
254 |
/***************************************************************************** |
255 |
* Load Config Data |
256 |
* Module Name: load_config_data |
257 |
* Description: This module uses filenames loaded in structure to open files |
258 |
* and read data in HK_Config_Files structure. This includes |
259 |
* reading in apid and version # and all keyword values. |
260 |
*****************************************************************************/ |
261 |
void load_config_data(APID_HKPFD_Files *hkpfd_files, |
262 |
APID_Pointer_HK_Configs *hk_configs) |
263 |
{ |
264 |
/*declarations*/ |
265 |
APID_HKPFD_Files* p; |
266 |
FILE* file_ptr; |
267 |
char filename[MAX_FILE_NAME]; |
268 |
int apid; |
269 |
|
270 |
/* FOR LOOP through all files in directory */ |
271 |
apid = hk_configs->apid; |
272 |
p = hkpfd_files; |
273 |
while(p) |
274 |
{ |
275 |
if ( p->apid == apid ) |
276 |
{ |
277 |
sprintf(filename,"%s/%s",p->directory_name, p->filename); |
278 |
file_ptr = fopen( filename ,"r"); |
279 |
(void)save_hdpf_new_formats(file_ptr, hk_configs); |
280 |
fclose(file_ptr); |
281 |
} |
282 |
p = p->next; |
283 |
} |
284 |
} |
285 |
|
286 |
/***************************************************************************** |
287 |
* Load Filenames From Directory |
288 |
* Module Name: load_filenames_from_directory |
289 |
* Description: This module opens a directory and loads all apid-<apid#>- |
290 |
* version<version#>.txt files and GTCIDS file. Assume all |
291 |
* files will be in one directory called for now |
292 |
* .../HK-CONFIG-FILES. |
293 |
*****************************************************************************/ |
294 |
APID_HKPFD_Files* read_all_hk_config_files(int apid, char f_version_number[MAX_CHAR_VERSION_NUMBER],char p_version_number[MAX_CHAR_VERSION_NUMBER]) |
295 |
{ |
296 |
/*declarations */ |
297 |
APID_HKPFD_Files *top, *p; |
298 |
DIR *dir_p; |
299 |
char dirname[200]; |
300 |
char *dn; |
301 |
int curr_pvn_wn,curr_pvn_dn; |
302 |
struct dirent *dir_entry_p; |
303 |
|
304 |
/* intialize variables */ |
305 |
int file_loaded_flag=0; |
306 |
memset(dirname, 0x0, sizeof(dirname)); |
307 |
|
308 |
/* get directory name */ |
309 |
if(check_for_sdo_apid(apid)) |
310 |
{ |
311 |
dn = getenv("HK_SHCIDS_DIRECTORY"); |
312 |
if(dn == NULL) |
313 |
{ |
314 |
printkerr("ERROR at %s, line %d: Could not get directory environment\n" |
315 |
"variable:<HK_SHCIDS_DIRECTORY>. Set the env variable " |
316 |
"HK_SHCIDS_DIRECTORY to point to the config file directory.\n", |
317 |
__FILE__,__LINE__,dn); |
318 |
return NULL; |
319 |
} |
320 |
} |
321 |
else |
322 |
{ |
323 |
dn = getenv("HK_CONFIG_DIRECTORY"); |
324 |
if(dn == NULL) |
325 |
{ |
326 |
printkerr("ERROR at %s, line %d: Could not get directory environment\n" |
327 |
"variable:<HK_CONFIG_DIRECTORY>. Set the env variable " |
328 |
"HK_CONFIG_DIRECTORY to point to the config file directory.\n", |
329 |
__FILE__,__LINE__,dn); |
330 |
return NULL; |
331 |
} |
332 |
} |
333 |
|
334 |
/* Add file version number to directory path */ |
335 |
strcpy( dirname, dn); |
336 |
strcat(dirname, f_version_number); |
337 |
strcat(dirname,"\0"); |
338 |
|
339 |
/* open directory */ |
340 |
if ((dir_p = opendir(dirname)) == NULL) |
341 |
{ |
342 |
printkerr("ERROR at %s, line %d: Could not open directory <%s>. " |
343 |
"The directory with < %s > version number does not exist. " |
344 |
"Run make_hkpdf.pl script to create directory and config files.\n", |
345 |
__FILE__,__LINE__,dirname, f_version_number); |
346 |
return NULL; |
347 |
} |
348 |
|
349 |
/* read each hk config file entry until NULL.*/ |
350 |
top = NULL; |
351 |
while( (dir_entry_p = readdir(dir_p)) != NULL ) |
352 |
{ |
353 |
/****OLD SDO checks*************** |
354 |
if( !strncmp(dir_entry_p->d_name,"apid",4) || !strncmp(dir_entry_p->d_name,"HMI-",4) || !strncmp(dir_entry_p->d_name,"AIA-",4) || !strncmp(dir_entry_p->d_name,"SDO-",4)) |
355 |
**********************************/ |
356 |
if( !strncmp(dir_entry_p->d_name,"IRIS-",5)) |
357 |
;//this is valid file |
358 |
else |
359 |
continue; /* not an APID config file - skip*/ |
360 |
|
361 |
if( top == NULL ) |
362 |
top = p = malloc(sizeof(APID_HKPFD_Files)); |
363 |
else |
364 |
{ |
365 |
p->next = malloc(sizeof(APID_HKPFD_Files)); |
366 |
p = p->next; |
367 |
} |
368 |
p->next = NULL; |
369 |
|
370 |
/* load dir and filename in structure link list */ |
371 |
strcpy(p->filename, dir_entry_p->d_name); |
372 |
strcpy(p->directory_name, dirname); |
373 |
|
374 |
if (check_for_sdo_apid(apid)) |
375 |
{ |
376 |
/* for sdo 129 set pvn to merged case to pickup SDO-ASD-PVN-TO-JSVN file */ |
377 |
/* also to go into merged case logic below */ |
378 |
curr_pvn_wn= HK_LEV0_START_MERGED_PVNW; |
379 |
curr_pvn_dn= HK_LEV0_START_MERGED_PVND; |
380 |
} |
381 |
else |
382 |
{ |
383 |
/* get number value of packet version number to check if greater or equal to merged data series threshold */ |
384 |
sscanf(p_version_number,"%3d.%3d",&curr_pvn_wn, &curr_pvn_dn); |
385 |
} |
386 |
|
387 |
/* check if reached packet version whole and decimal are greater or equal to merged threshold */ |
388 |
//Elim for IRIS |
389 |
// if(curr_pvn_wn >= HK_LEV0_START_MERGED_PVNW && curr_pvn_dn >= HK_LEV0_START_MERGED_PVND) |
390 |
// { |
391 |
/* check if HMI-ISP HK filename or others */ |
392 |
if( !strncmp(dir_entry_p->d_name,"IRIS-ISP",8) ) |
393 |
{ |
394 |
/* parse filenames like IRIS-ISP-version-6.89 to set pkt-version-number an apid-name */ |
395 |
sscanf(p->filename, "%*4s-%3s-%*7s-%s", p->apid_name, p->version_number); |
396 |
p->apid=56; //set to apid value used for HK configuration data |
397 |
} |
398 |
else if( !strncmp(dir_entry_p->d_name,"HMI-ISP",7) ) |
399 |
{ |
400 |
/* parse filenames like HMI-ISP-version-1.163 to set pkt-version-number an apid-name */ |
401 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
402 |
p->apid=445; //set to apid value used for HK configuration data from Stanford file |
403 |
} |
404 |
else if( !strncmp(dir_entry_p->d_name,"AIA-ISP",7) ) |
405 |
{ |
406 |
/* parse filenames like AIA-ISP-version-1.163 to set pkt-version-number an apid-name */ |
407 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
408 |
p->apid=529; //set to apid value used for HK configuration data from Stanford file |
409 |
} |
410 |
else if( !strncmp(dir_entry_p->d_name,"HMI-SEQ",7) ) |
411 |
{ |
412 |
/* parse filenames like HMI-SEQ-version-1.163 to set pkt-version-number an apid-name*/ |
413 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
414 |
p->apid=451; //set to apid value used for HK configuration data from Stanford file |
415 |
} |
416 |
else if( !strncmp(dir_entry_p->d_name,"AIA-SEQ",7) ) |
417 |
{ |
418 |
/* parse filenames like AIA-SEQ-version-1.163 to set pkt-version-number an apid-name */ |
419 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
420 |
p->apid=536; //set to apid value used for HK configuration data from Stanford file |
421 |
} |
422 |
else if( !strncmp(dir_entry_p->d_name,"HMI-OBT",7) ) |
423 |
{ |
424 |
/* parse filenames like HMI-OBT-version-1.163 to set pkt-version-number an apid-name*/ |
425 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
426 |
p->apid=448; //set to apid value used for HK configuration data from Stanford file |
427 |
} |
428 |
else if( !strncmp(dir_entry_p->d_name,"AIA-OBT",7) ) |
429 |
{ |
430 |
/* parse filenames like AIA-OBT-version-1.163 to set pkt-version-number an apid-name */ |
431 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
432 |
p->apid=540; //set to apid value used for HK configuration data from Stanford file |
433 |
} |
434 |
else if( !strncmp(dir_entry_p->d_name,"SDO-ASD",7) ) |
435 |
{ |
436 |
/* parse filenames like SDO-ASD-version-1.1 to set pkt-version-number an apid-name */ |
437 |
sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number); |
438 |
p->apid=129; //set to apid value used for HK configuration data from Stanford file |
439 |
} |
440 |
else if( !strncmp(dir_entry_p->d_name,"AIA-",4) ) |
441 |
{ |
442 |
/* parse filenames like AIA-244-version-1.163 to set pkt-version-number an apid-name */ |
443 |
sscanf(p->filename, "%*3s-%x-%*7s-%s", &p->apid, p->version_number); |
444 |
sprintf(p->apid_name,"0x%03x", p->apid); |
445 |
} |
446 |
else if( !strncmp(dir_entry_p->d_name,"HMI-",4) ) |
447 |
{ |
448 |
/* parse filenames like HMI-001-version-1.163 to set pkt-version-number an apid-name */ |
449 |
sscanf(p->filename, "%*3s-%x-%*7s-%s", &p->apid, p->version_number); |
450 |
sprintf(p->apid_name,"0x%03x", p->apid); |
451 |
} |
452 |
else |
453 |
{ |
454 |
/* parse older version filenames like apid-1BD-version-1.163 */ |
455 |
sscanf(p->filename, "%*4s-%x-%*7s-%s", &p->apid, p->version_number); |
456 |
sprintf(p->apid_name,"0x%03x", p->apid); |
457 |
printkerr("WARNING at %s, line %d: This is not a valid config file " |
458 |
"name < %s > for merged apid case. Updates HKPDF files with correct " |
459 |
"format of files(<HMI|AIA|SDO>-<APID-NAME>-version-<file version number>. " |
460 |
"This occurred for apid < %d >.\n", |
461 |
__FILE__,__LINE__, dir_entry_p->d_name, p->apid ); |
462 |
} |
463 |
// } |
464 |
// else |
465 |
// { |
466 |
// /* non-merged data series case- parse older version filenames like apid-1BD-version-1.163 */ |
467 |
// sscanf(p->filename, "%*4s-%x-%*7s-%s", &p->apid, p->version_number); |
468 |
// sprintf(p->apid_name,"0x%03x", p->apid); |
469 |
// } |
470 |
file_loaded_flag=1; /*set flag if found a file and loaded it in struct */ |
471 |
}/*end while */ |
472 |
|
473 |
closedir(dir_p); |
474 |
|
475 |
/* check if at least one file loaded and exists in directory*/ |
476 |
if ( !file_loaded_flag) |
477 |
{ |
478 |
/*Took out too many messages in log |
479 |
printkerr("ERROR at %s, line %d: Could not find config file(s) " |
480 |
"in directory < %s >. Check if file(s) exists for " |
481 |
"file version number <%s>, if don't exist, then " |
482 |
"run make_hkpdf.pl script to create config files.\n", |
483 |
__FILE__,__LINE__,dirname, f_version_number); |
484 |
*/ |
485 |
} |
486 |
return top; |
487 |
}/* END-Module: load_hk_filenames_from_directory */ |
488 |
|
489 |
|
490 |
|
491 |
/***************************************************************************** |
492 |
* save New HDPF Formats |
493 |
* Module Name: save_hdpf_new_formats |
494 |
* Description: |
495 |
* This is the top level function to decode housekeeping keywords. |
496 |
* Parameters Passed: |
497 |
* File* file_ptr = Reference pointer to |
498 |
* HK_Config_Files *ptr_config_node= Reference pointer |
499 |
* HK_Config_Files *top_ptr_config_node= Reference pointer |
500 |
* Functions Called: |
501 |
* Status save_hdpf_new_formats(): Tested |
502 |
* |
503 |
*****************************************************************************/ |
504 |
int save_hdpf_new_formats(FILE* file_ptr,APID_Pointer_HK_Configs *p_apid_ptr_hk_configs) |
505 |
{ |
506 |
/* declarations */ |
507 |
int err_status[3]; |
508 |
HK_Config_Files *ptr_config_node; |
509 |
HK_Config_Files *previous_ptr_config_node; |
510 |
int status; |
511 |
int i, j, k; |
512 |
char line[MAXLINE_IN_FILE]; |
513 |
char keyword_lines[MAX_NUM_KW_LINES][MAXLINE_IN_FILE]; |
514 |
char acon_lines[MAX_NUM_ACON_LINES][MAXLINE_ACON_IN_FILE]; |
515 |
char dcon_lines[MAX_NUM_DCON_LINES][MAXLINE_DCON_IN_FILE]; |
516 |
|
517 |
/*Assume format contents of file using functional spec formats */ |
518 |
/* Check if first node exists*/ |
519 |
if (p_apid_ptr_hk_configs->ptr_hk_configs == NULL) |
520 |
{ |
521 |
/* create first HK Config node */ |
522 |
p_apid_ptr_hk_configs->ptr_hk_configs =malloc( sizeof(HK_Config_Files)); |
523 |
ptr_config_node = p_apid_ptr_hk_configs->ptr_hk_configs; |
524 |
ptr_config_node->next = NULL; |
525 |
ptr_config_node->keywords = NULL; |
526 |
} /*END-if first node exists */ |
527 |
else |
528 |
{ |
529 |
/* search for new null node in HK_Config Link list */ |
530 |
for(ptr_config_node = p_apid_ptr_hk_configs->ptr_hk_configs, |
531 |
previous_ptr_config_node = ptr_config_node; |
532 |
ptr_config_node; |
533 |
previous_ptr_config_node = ptr_config_node, |
534 |
ptr_config_node = ptr_config_node->next) |
535 |
{ |
536 |
;/* continue loop*/ |
537 |
} |
538 |
/* create next node */ |
539 |
ptr_config_node = malloc( sizeof(HK_Config_Files)); |
540 |
previous_ptr_config_node->next = ptr_config_node; |
541 |
ptr_config_node->next = NULL; |
542 |
ptr_config_node->keywords = NULL; |
543 |
} |
544 |
/* load keyword, dsc, or alg lines in hk configuration structures */ |
545 |
for(i=0, j=0, k=0; fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL; ) |
546 |
{ |
547 |
if (!strncmp(line, "#", 1)) |
548 |
{ |
549 |
continue; /*skip comments */ |
550 |
} |
551 |
else if (!strncmp(line, "KWD", 3)) |
552 |
{ |
553 |
strcpy( keyword_lines[i++], line); |
554 |
} |
555 |
else if (!strncmp(line, "DCON", 4)) |
556 |
{ |
557 |
|
558 |
if(j >= MAX_NUM_DCON_LINES) |
559 |
{ |
560 |
printkerr("WARNING: Maximum lines for array exceeded.\n" |
561 |
" Skipping saving DCON config data since array too small.\n" |
562 |
" Update define variable MAX_NUM_DCON_LINES. \n"); |
563 |
} |
564 |
else |
565 |
{ |
566 |
strncpy( dcon_lines[j++], line, MAXLINE_DCON_IN_FILE); |
567 |
} |
568 |
} |
569 |
else if (! strncmp(line, "ACON", 4)) |
570 |
{ |
571 |
if(k >= MAX_NUM_ACON_LINES) |
572 |
{ |
573 |
printkerr("WARNING: Maximum lines for array exceeded.\n" |
574 |
" Skipping saving ACON config data since array too small.\n" |
575 |
" Update define variable MAX_NUM_ACON_LINES. \n"); |
576 |
} |
577 |
else |
578 |
{ |
579 |
strcpy( acon_lines[k++], line); |
580 |
} |
581 |
} |
582 |
else if (!strncmp(line, "FILE", 4)) |
583 |
{ |
584 |
sscanf(line," %*s %*s %s ", ptr_config_node->file_version_number); |
585 |
} |
586 |
else if (!strncmp(line, "APID", 4)) |
587 |
{ |
588 |
/* parse APID line in HK Config file */ |
589 |
if( strstr(line, "HMIKER") ) |
590 |
{ |
591 |
/* new-load apid_name in struct for pkt string name*/ |
592 |
sscanf( line,"%*s %s %d %s %s", |
593 |
ptr_config_node->apid_name, |
594 |
&(ptr_config_node->number_bytes_used), |
595 |
ptr_config_node->packet_id_type, |
596 |
ptr_config_node->date); |
597 |
} |
598 |
else if( strstr(line, "AIAKER") ) |
599 |
{ |
600 |
/* new-load apid_name in struct for pkt string name*/ |
601 |
sscanf( line,"%*s %s %d %s %s", |
602 |
ptr_config_node->apid_name, |
603 |
&(ptr_config_node->number_bytes_used), |
604 |
ptr_config_node->packet_id_type, |
605 |
ptr_config_node->date); |
606 |
} |
607 |
else if( strstr(line, "IRIS") ) |
608 |
{ |
609 |
/* new-load apid_name in struct for pkt string name*/ |
610 |
sscanf( line,"%*s %s %d %s %s", |
611 |
ptr_config_node->apid_name, |
612 |
&(ptr_config_node->number_bytes_used), |
613 |
ptr_config_node->packet_id_type, |
614 |
ptr_config_node->date); |
615 |
ptr_config_node->apid_number = 56; //special for IRIS |
616 |
} |
617 |
else if( strstr(line, "HMI") ) |
618 |
{ |
619 |
/* new-load apid_name in struct for pkt string name*/ |
620 |
sscanf( line,"%*s %s %d %s %s", |
621 |
ptr_config_node->apid_name, |
622 |
&(ptr_config_node->number_bytes_used), |
623 |
ptr_config_node->packet_id_type, |
624 |
ptr_config_node->date); |
625 |
} |
626 |
else if( strstr(line, "AIA") ) |
627 |
{ |
628 |
/* new-load apid_name in struct for pkt string name */ |
629 |
sscanf( line,"%*s %s %d %s %s", |
630 |
ptr_config_node->apid_name, |
631 |
&(ptr_config_node->number_bytes_used), |
632 |
ptr_config_node->packet_id_type, |
633 |
ptr_config_node->date); |
634 |
} |
635 |
else if( strstr(line, "SDO") ) |
636 |
{ |
637 |
/* new-load apid_name in struct for pkt string name */ |
638 |
sscanf( line,"%*s %s %d %*s %s", |
639 |
ptr_config_node->apid_name, |
640 |
&(ptr_config_node->number_bytes_used), |
641 |
ptr_config_node->date); |
642 |
/* set to SDO */ |
643 |
strcpy(ptr_config_node->packet_id_type,"SDO"); |
644 |
sscanf( line,"%*s %x", &(ptr_config_node->apid_number)); |
645 |
} |
646 |
else if( strstr(line, "SSIM") ) |
647 |
{ |
648 |
/* new-load apid_name in struct for pkt string name */ |
649 |
sscanf( line,"%*s %5s %d %*s %s", |
650 |
ptr_config_node->apid_name, |
651 |
&(ptr_config_node->number_bytes_used), |
652 |
ptr_config_node->date); |
653 |
/* set to default HMI */ |
654 |
strcpy(ptr_config_node->packet_id_type,"HMI"); |
655 |
} |
656 |
else |
657 |
{ |
658 |
/* Backward compatible case for apid-#-version-# created* |
659 |
* using older(before 6-30-2006) make_hpf.pl script */ |
660 |
sscanf( line,"%*s %x %d %s", |
661 |
&(ptr_config_node->apid_number), |
662 |
&(ptr_config_node->number_bytes_used), |
663 |
ptr_config_node->date); |
664 |
|
665 |
/* set to default HMI */ |
666 |
strcpy(ptr_config_node->packet_id_type,"HMI"); |
667 |
printkerr("WARNING: Could not find line valid value in APID line in apid-#-version-# file. " |
668 |
"Got line:<%s> so default setting to instrument flag to HMI. Probably need to " |
669 |
"update make_hkpdf.pl script or rerun to fix older HK files.\n", line); |
670 |
} |
671 |
} |
672 |
else |
673 |
{ |
674 |
printkerr("WARNING: Could not find line with this keyword in apid-#-version-# file. Possible bad data in STANFORD file.\n"); |
675 |
printkerr("WARNING: Line tried to parse is < %s >\n", line); |
676 |
} |
677 |
} |
678 |
/* Set to null the end of array*/ |
679 |
strcpy(keyword_lines[i],""); |
680 |
strcpy(dcon_lines[j],""); |
681 |
strcpy(acon_lines[k],""); |
682 |
/*Load keyword, alg and dsc lines values in configuration structures */ |
683 |
err_status[0] = load_hdpf_keyword_lines(keyword_lines,i,ptr_config_node); |
684 |
err_status[1] = load_hdpf_dsc_lines(dcon_lines,j,ptr_config_node); |
685 |
err_status[2] = load_hdpf_alg_lines(acon_lines,k,ptr_config_node); |
686 |
/* return values */ |
687 |
/* return top_hk_config_nodes by setting value if first node*/ |
688 |
/* return error status when do error checks. Where |
689 |
status 0 = no errors and status 1 equals errors */ |
690 |
for ( i=0; i < sizeof(err_status); i++) |
691 |
{ |
692 |
if ( err_status[i] != ERROR_LOADING_HK_DATA ) |
693 |
continue; |
694 |
else |
695 |
status= err_status[i]; |
696 |
}/* END-for */ |
697 |
return status; |
698 |
} |
699 |
|
700 |
|
701 |
/***************************************************************************** |
702 |
* Create Memory Load HDPF keyword lines |
703 |
* Module Name: load_hdpf_keyword_lines |
704 |
* Description: This function loads the keyword config data in HK_Config_Files |
705 |
* structure's Keyword_Parameter link list nodes. |
706 |
* Status load_hdpf_keyword_lines(): Tested |
707 |
*****************************************************************************/ |
708 |
int load_hdpf_keyword_lines(char keyword_lines[MAX_NUM_KW_LINES][MAXLINE_IN_FILE],int number_of_lines,HK_Config_Files *ptr_hk_config_node) |
709 |
{ |
710 |
/* declarations */ |
711 |
Keyword_Parameter *keyword_node; |
712 |
int k=0; |
713 |
|
714 |
/*create space for keyword_parameter link list nodes */ |
715 |
keyword_node= create_hdpf_keyword_nodes( ptr_hk_config_node, number_of_lines ); |
716 |
/* load keyword values in Keyword_Parameter nodes */ |
717 |
for(k=0; keyword_lines[k][0] != '\0'; |
718 |
k++,keyword_node=keyword_node->next) |
719 |
{ |
720 |
sscanf(keyword_lines[k]," %*s %s %s %d %d %d %s %c %*s", |
721 |
keyword_node->keyword_name, |
722 |
keyword_node->telemetry_mnemonic_name, |
723 |
&(keyword_node->start_byte), |
724 |
&(keyword_node->start_bit_number), |
725 |
&(keyword_node->bit_length), |
726 |
keyword_node->type, |
727 |
&keyword_node->conv_type); |
728 |
strcat(keyword_node->telemetry_mnemonic_name,"\0");/*fix ticket #278*/ |
729 |
strcat(keyword_node->keyword_name,"\0");/* fix ticket #278 */ |
730 |
keyword_node->dsc_ptr = (DSC_Conversion *)NULL; |
731 |
keyword_node->alg_ptr = (ALG_Conversion *)NULL; |
732 |
} |
733 |
return HK_SUCCESSFUL; |
734 |
} /*END-module: load_hdpf_keyword_lines */ |
735 |
|
736 |
|
737 |
/***************************************************************************** |
738 |
* Load HDPF dsc lines |
739 |
* Module Name: load_hdpf_dsc_lines |
740 |
* Description: This function loads the dsc config data in HK_Config_Files |
741 |
* structure's Keyword_Parameter link list nodes. |
742 |
* Status load_hdpf_dsc_lines(): entered code & Need to test and Review |
743 |
*****************************************************************************/ |
744 |
int load_hdpf_dsc_lines(char dsc_lines[MAX_NUM_DCON_LINES][MAXLINE_DCON_IN_FILE ], int number_of_lines, HK_Config_Files *ptr_hk_config_node) |
745 |
{ |
746 |
/* declarations */ |
747 |
DSC_Conversion *dsc_node; |
748 |
int i=0; |
749 |
char tlm_name[HK_MAX_TLM_NAME]; |
750 |
Keyword_Parameter *kw; |
751 |
|
752 |
/* loop throught each of the telemetry names in keywords node link list |
753 |
with conv type equal to D. Search for line in array with telemetry |
754 |
name equal to keyword node in link list. When found, create DSC node |
755 |
and load values from line. |
756 |
*/ |
757 |
for ( kw= ptr_hk_config_node->keywords ; kw; kw=kw->next) |
758 |
{ |
759 |
/* find D type KWDs */ |
760 |
if ( kw->conv_type == 'D') |
761 |
{ |
762 |
kw->dsc_ptr=(DSC_Conversion*)NULL; |
763 |
/* find line with tlm name the same as Keywords tlm name */ |
764 |
for (i=0; i < number_of_lines; i++) |
765 |
{ |
766 |
sscanf ( dsc_lines[i], "%*s %s %*d %*d %*d %*d %*d %*d", tlm_name); |
767 |
strcat( tlm_name, ""); |
768 |
strcat( tlm_name, "\0");/* fix ticket #278 */ |
769 |
if( !strcmp( kw->telemetry_mnemonic_name, tlm_name)) |
770 |
{ |
771 |
/* create dsc node memory */ |
772 |
dsc_node = create_hdpf_dsc_nodes( kw); |
773 |
/* load values in dsc node*/ |
774 |
sscanf(dsc_lines[i]," %*s %*s %d %d %s %*s", |
775 |
&(dsc_node->low_range), &(dsc_node->high_range), |
776 |
dsc_node->dsc_value); |
777 |
dsc_node->next = NULL; /*set link list to null at end node*/ |
778 |
} /* end of if tlm name equal */ |
779 |
} /* end of for number of lines */ |
780 |
} /* end of if D type keyword */ |
781 |
} /* end of for each keyword */ |
782 |
return 0; |
783 |
} /*END-module: load_hdpf_dsc_lines */ |
784 |
|
785 |
|
786 |
|
787 |
/***************************************************************************** |
788 |
* Create Memory Load HDPF alg lines |
789 |
* Module Name: load_hdpf_alg_lines |
790 |
* Description: This function loads the keyword config data in HK_Config_Files |
791 |
* structure's Keyword_Parameter link list node which points to |
792 |
* ALG_Conversion node. |
793 |
* Status load_hdpf_alg_lines():Reviewed and Tested. |
794 |
*****************************************************************************/ |
795 |
int load_hdpf_alg_lines(char alg_lines[MAX_NUM_ACON_LINES][MAXLINE_ACON_IN_FILE],int number_of_lines,HK_Config_Files *ptr_hk_config_node) |
796 |
{ |
797 |
/* declarations */ |
798 |
ALG_Conversion *alg_node; |
799 |
int i, k; |
800 |
char tlm_name[HK_MAX_TLM_NAME]; |
801 |
Keyword_Parameter *kw; |
802 |
|
803 |
/* Loop throught each of the telemetry names in keywords node link list |
804 |
with conv type equal to A.Search for line in array with telemetry |
805 |
name equal to keyword node in link list. When found, create ALG node |
806 |
and load values from liner. |
807 |
*/ |
808 |
for ( kw= ptr_hk_config_node->keywords ; kw; kw=kw->next) |
809 |
{ |
810 |
/* find "A" type KWDs */ |
811 |
if ( kw->conv_type == 'A') |
812 |
{ |
813 |
/* find line with tlm name the same as Keywords tlm name */ |
814 |
for (i=0; i < number_of_lines; i++) |
815 |
{ |
816 |
/* get tlm name from line */ |
817 |
sscanf ( alg_lines[i], "%*s %s %*d %*d %*d %*d %*d %*d %*d", tlm_name); |
818 |
strcat( tlm_name, ""); |
819 |
if( !strncmp( kw->telemetry_mnemonic_name, tlm_name, sizeof(tlm_name))) |
820 |
{ |
821 |
/* create alg node memory */ |
822 |
kw->alg_ptr = (ALG_Conversion*)malloc (sizeof (ALG_Conversion)); |
823 |
alg_node= kw->alg_ptr; |
824 |
|
825 |
/* load values in alg node-assume number of coeffs to be 6*/ |
826 |
k=0; |
827 |
sscanf(alg_lines[i]," %*s %*s %d %lf %lf %lf %lf %lf %lf %*s", |
828 |
&(alg_node->number_of_coeffs), &(alg_node->coeff[k++]), |
829 |
&(alg_node->coeff[k++]), &(alg_node->coeff[k++]), |
830 |
&(alg_node->coeff[k++]), &(alg_node->coeff[k++]), &(alg_node->coeff[k]) ); |
831 |
if(alg_node->number_of_coeffs != 6 && alg_node->number_of_coeffs != 5) |
832 |
{ |
833 |
printkerr("WARNING: Receive data value for number of coefficients that were not expected values " |
834 |
"which are <5 or 6>. If value larger then 6 then will exceed array allowed size. " |
835 |
"Number of coefficients got was:<%d> \n",alg_node->number_of_coeffs); |
836 |
} |
837 |
break; |
838 |
} /* end of if tlm name equal */ |
839 |
} /* end of for number of lines */ |
840 |
} /* end of if "A" type keyword */ |
841 |
} /* end of for each keyword */ |
842 |
return HK_SUCCESSFUL; |
843 |
} /*END-module: load_hdpf_alg_lines */ |
844 |
|
845 |
|
846 |
|
847 |
/***************************************************************************** |
848 |
* Create (Memory) HDPF keyword Nodes |
849 |
* Module Name: create_hdfd_keyword_nodes |
850 |
* Description: This function creates memory for Keyword_Parameter structure |
851 |
* nodes |
852 |
* Status create_hdfd_keyword_nodes(): Reviewed and Tested |
853 |
*****************************************************************************/ |
854 |
Keyword_Parameter* create_hdpf_keyword_nodes(HK_Config_Files *ptr_hk_config, |
855 |
int number_of_lines) |
856 |
{ |
857 |
/* declarations */ |
858 |
Keyword_Parameter *p; |
859 |
int k; |
860 |
|
861 |
/* initialize variables */ |
862 |
p = ptr_hk_config->keywords = NULL; |
863 |
|
864 |
for( k=0; k<number_of_lines; k++) |
865 |
{ |
866 |
if(ptr_hk_config->keywords == NULL) |
867 |
{ |
868 |
/* Create first node for keyword */ |
869 |
p = ptr_hk_config->keywords = malloc( sizeof(Keyword_Parameter) ); |
870 |
} |
871 |
else |
872 |
{ |
873 |
/*Create all other keyword_parameter nodes required */ |
874 |
p->next = malloc(sizeof(Keyword_Parameter )); |
875 |
p = p->next; |
876 |
} |
877 |
p->next = NULL; |
878 |
} |
879 |
return (ptr_hk_config->keywords); |
880 |
} |
881 |
|
882 |
|
883 |
|
884 |
/***************************************************************************** |
885 |
* Create Memory For DSC Nodes |
886 |
* Module Name: create_hdfd_dsc_nodes |
887 |
* Description: This function creates memory for DSC_Conversion structure nodes. |
888 |
* Status create_hdfd_dsc_nodes(): Tested and Reviewed |
889 |
*****************************************************************************/ |
890 |
DSC_Conversion* create_hdpf_dsc_nodes(Keyword_Parameter *ptr_hk_keyword) |
891 |
{ |
892 |
/* declarations */ |
893 |
DSC_Conversion *p; |
894 |
|
895 |
/* initializations */ |
896 |
p = ptr_hk_keyword->dsc_ptr ; |
897 |
|
898 |
if ( p == NULL) |
899 |
{ |
900 |
/*create first node for dsc data */ |
901 |
p = (DSC_Conversion *) malloc(sizeof(DSC_Conversion)); |
902 |
ptr_hk_keyword->dsc_ptr= p; /* add connection 5-17-2006*/ |
903 |
} |
904 |
else |
905 |
{ |
906 |
while ( p->next != (DSC_Conversion *)(NULL)) |
907 |
{ |
908 |
p= p->next; |
909 |
} |
910 |
/*create all other DSC Conversion nodes */ |
911 |
p->next = (DSC_Conversion *) malloc (sizeof(DSC_Conversion)); |
912 |
p=p->next; |
913 |
} |
914 |
p->next= NULL; |
915 |
return(p); |
916 |
}/*end-create_hdpf_dsc_nodes module */ |
917 |
|
918 |
|
919 |
|
920 |
/***************************************************************************** |
921 |
* Check Packet Version Number |
922 |
* Module Name: check_file_version_number |
923 |
* Description: This function checks version number in the HK_Config_Files |
924 |
* structure. For encode_hk checked parameter-version-numbers. |
925 |
* Status check_version_number():Reviewed & Tested-used by decode_hk functions |
926 |
*****************************************************************************/ |
927 |
HK_Config_Files* check_packet_version_number( HK_Config_Files *ptr_to_configs, |
928 |
char *version_number ) |
929 |
{ |
930 |
while(ptr_to_configs != NULL ) |
931 |
{ |
932 |
#ifdef DEBUG_LOAD_HK_CONFIG_FILE |
933 |
printkerr("DEBUG:Message at %s, line %d: Packet Version Number looking for:<%s>\n", __FILE__, __LINE__,version_number); |
934 |
printkerr("DEBUG:Message at %s, line %d: Packet Version Number found in config structure:<%s>\n", __FILE__, __LINE__,ptr_to_configs->parameter_version_number); |
935 |
#endif |
936 |
if(!strcmp(ptr_to_configs->parameter_version_number, version_number)) |
937 |
{ |
938 |
break; |
939 |
} |
940 |
ptr_to_configs = ptr_to_configs->next; |
941 |
} |
942 |
return ptr_to_configs; |
943 |
} |
944 |
/***************************************************************************** |
945 |
* Check File Version Number |
946 |
* Module Name: check__file_version_number |
947 |
* Description: This function checks version number in the HK_Config_Files |
948 |
* structure. For encode_hk checked file-version-numbers. |
949 |
* Status check_version_number():Reviewed & Tested-used by decode_hk functions |
950 |
*****************************************************************************/ |
951 |
HK_Config_Files* check_file_version_number( HK_Config_Files *ptr_to_configs, |
952 |
char *version_number ) |
953 |
{ |
954 |
while(ptr_to_configs != NULL ) |
955 |
{ |
956 |
if(!strcmp(ptr_to_configs->file_version_number, version_number)) |
957 |
break; |
958 |
ptr_to_configs = ptr_to_configs->next; |
959 |
} |
960 |
return ptr_to_configs; |
961 |
} |
962 |
|
963 |
/***************************************************************************** |
964 |
* CHECK FREE CONFIG FLAG |
965 |
* Module Name:check_free_configs_flag |
966 |
* Description:This function is used to decide whether to free config structures |
967 |
* dynamically by check if file name exists in directory. |
968 |
* If file name exist returns 1 and if not returns 0. |
969 |
* Status check_free_configs_flag: Reviewd and Tested on 6-28-2006 |
970 |
*****************************************************************************/ |
971 |
int check_free_configs_flag(void) |
972 |
{ |
973 |
/*declarations */ |
974 |
int status; |
975 |
FILE *file_ptr; |
976 |
char *directory ; |
977 |
char *filename; |
978 |
char directory_filename[MAX_FILE_NAME]; |
979 |
|
980 |
/* get directory and file name */ |
981 |
directory = getenv("HK_CONFIG_DIRECTORY"); |
982 |
filename= getenv("HK_FREE_FLAG_FILE"); |
983 |
if(filename == NULL) |
984 |
filename = "HK_FREE_CONFIG_FLAG_FILE"; |
985 |
if(directory == NULL) |
986 |
directory = "../../tables/hk_config_file"; |
987 |
sprintf(directory_filename, "%s/%s", directory, filename); |
988 |
/*open file-if exists then clear configs each time*/ |
989 |
file_ptr = fopen(directory_filename, "r"); |
990 |
if (file_ptr == NULL) |
991 |
{ |
992 |
status =0; |
993 |
} |
994 |
else |
995 |
{ |
996 |
status = 1; |
997 |
fclose(file_ptr); |
998 |
} |
999 |
return status; |
1000 |
} |
1001 |
|
1002 |
|
1003 |
|
1004 |
/***************************************************************************** |
1005 |
* Free Allocated Memory for HK_Configs, etc |
1006 |
* Module Name:deallocate_apid_ptr_hk_config_nodes |
1007 |
* Description:This function free any memory in APID_Pointer_HK_Configs |
1008 |
* HK_Config_Files, Keyword_Parameter, DSC_Conversion, and |
1009 |
* ALG Conversion link list structures. This structure is used to |
1010 |
* hold in-memory configuration data used decode keywords. The call |
1011 |
* to this function frees everything that was read in since the |
1012 |
* process has been up and running. |
1013 |
* Status deallocate_apid_ptr_hk_config_nodes(): Tested and Reviewed |
1014 |
*****************************************************************************/ |
1015 |
void deallocate_apid_ptr_hk_config_nodes(void) |
1016 |
{ |
1017 |
extern APID_Pointer_HK_Configs *global_apid_configs; |
1018 |
APID_Pointer_HK_Configs *tmp_apid_ptr_hk_configs; |
1019 |
APID_Pointer_HK_Configs *prev_apid_ptr_hk_configs; |
1020 |
HK_Config_Files *tmp_ptr_hk_configs; |
1021 |
HK_Config_Files *prev_ptr_hk_configs; |
1022 |
Keyword_Parameter *tmp_keyword_node; |
1023 |
Keyword_Parameter *prev_keyword_node; |
1024 |
DSC_Conversion *tmp_dsc_node; |
1025 |
DSC_Conversion *prev_dsc_node; |
1026 |
ALG_Conversion *tmp_alg_node; |
1027 |
|
1028 |
/* check if want to free all stored configurations */ |
1029 |
if (!( check_free_configs_flag())) |
1030 |
{ |
1031 |
/*skip deallocating configuration data kept in memory*/ |
1032 |
return; |
1033 |
} |
1034 |
|
1035 |
/* assign top of link list of config data to tmp ptr */ |
1036 |
tmp_apid_ptr_hk_configs=global_apid_configs; |
1037 |
|
1038 |
/* Loop throught and free nodes */ |
1039 |
for(prev_apid_ptr_hk_configs=tmp_apid_ptr_hk_configs; |
1040 |
tmp_apid_ptr_hk_configs; |
1041 |
prev_apid_ptr_hk_configs = tmp_apid_ptr_hk_configs ) |
1042 |
{ |
1043 |
for(prev_ptr_hk_configs=tmp_ptr_hk_configs=tmp_apid_ptr_hk_configs->ptr_hk_configs; |
1044 |
tmp_ptr_hk_configs; |
1045 |
prev_ptr_hk_configs =tmp_ptr_hk_configs) |
1046 |
{ |
1047 |
for(prev_keyword_node=tmp_keyword_node= |
1048 |
tmp_ptr_hk_configs->keywords; |
1049 |
tmp_keyword_node; |
1050 |
prev_keyword_node =tmp_keyword_node) |
1051 |
{ |
1052 |
/* free dsc nodes */ |
1053 |
for(prev_dsc_node=tmp_dsc_node=tmp_keyword_node->dsc_ptr; |
1054 |
tmp_dsc_node; prev_dsc_node = tmp_dsc_node) |
1055 |
{ |
1056 |
tmp_dsc_node= tmp_dsc_node->next; |
1057 |
free( prev_dsc_node); |
1058 |
} |
1059 |
/* free alg node */ |
1060 |
tmp_alg_node=tmp_keyword_node->alg_ptr; |
1061 |
if (tmp_keyword_node) |
1062 |
{ |
1063 |
free( tmp_alg_node ); |
1064 |
} |
1065 |
tmp_keyword_node=tmp_keyword_node->next; |
1066 |
free(prev_keyword_node); |
1067 |
} |
1068 |
tmp_ptr_hk_configs =tmp_ptr_hk_configs->next; |
1069 |
free(prev_ptr_hk_configs); |
1070 |
} |
1071 |
tmp_apid_ptr_hk_configs = tmp_apid_ptr_hk_configs->next ; |
1072 |
free(prev_apid_ptr_hk_configs); |
1073 |
} |
1074 |
//ADDED 6-28 to test deallocate |
1075 |
global_apid_configs=NULL; |
1076 |
|
1077 |
} |
1078 |
|
1079 |
|
1080 |
/***************************************************************************** |
1081 |
* Read GTCIDS(Ground_to_code_ids) HK Files |
1082 |
* Module Name: read_gtcids_hk_file |
1083 |
* Description: This function reads the GTCIDS file and loads data into the |
1084 |
* GTCIDS_Version_Number structure. |
1085 |
* Status read_gtcids_hk_fi1e(): Reviewed and Tested |
1086 |
*****************************************************************************/ |
1087 |
GTCIDS_Version_Number * read_gtcids_hk_file() |
1088 |
{ |
1089 |
/*declarations*/ |
1090 |
char *hk_gtcids_directory ; |
1091 |
char *hk_gtcids_filename; |
1092 |
char hk_gtcids_directory_filename[MAX_FILE_NAME]; |
1093 |
FILE *file_ptr; |
1094 |
char line[MAXLINE_IN_FILE]; |
1095 |
GTCIDS_Version_Number *top_ptr_gtcids_vn; |
1096 |
GTCIDS_Version_Number *ptr_gtcids_vn; |
1097 |
|
1098 |
/* get directory and file name */ |
1099 |
hk_gtcids_directory = getenv("HK_CONFIG_DIRECTORY"); |
1100 |
hk_gtcids_filename= getenv("HK_GTCIDS_FILE"); |
1101 |
if(hk_gtcids_filename == NULL) |
1102 |
hk_gtcids_filename = "gtcids.txt"; |
1103 |
if(hk_gtcids_directory == NULL) |
1104 |
hk_gtcids_directory = "../../tables/hk_config_file"; |
1105 |
sprintf(hk_gtcids_directory_filename, "%s/%s", hk_gtcids_directory, |
1106 |
hk_gtcids_filename); |
1107 |
/*open file & read data into GTCIDS_Version_Number link list structure*/ |
1108 |
file_ptr = fopen(hk_gtcids_directory_filename, "r"); |
1109 |
if(!file_ptr) |
1110 |
{ |
1111 |
printkerr("ERROR:Couldn't open Ground To Code IDS file %s.\n",hk_gtcids_directory_filename); |
1112 |
printkerr("Set the enviroment variables HK_CONFIG_DIRECTORY" |
1113 |
" to point to config directory and HK_GTCIDS_FILE" |
1114 |
" environment variable to point to the correct file name\n"); |
1115 |
return NULL; |
1116 |
} |
1117 |
top_ptr_gtcids_vn = NULL; |
1118 |
while( fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL ) |
1119 |
{ |
1120 |
if((line[0] == '#') || (line[0] == '\n')) |
1121 |
continue; /* skip comments */ |
1122 |
else |
1123 |
{ |
1124 |
if (top_ptr_gtcids_vn == NULL) |
1125 |
{ |
1126 |
top_ptr_gtcids_vn = ptr_gtcids_vn = malloc(sizeof(GTCIDS_Version_Number)); |
1127 |
ptr_gtcids_vn->next = (GTCIDS_Version_Number*)NULL; |
1128 |
} |
1129 |
else |
1130 |
{ |
1131 |
ptr_gtcids_vn->next = malloc(sizeof(GTCIDS_Version_Number)); |
1132 |
ptr_gtcids_vn = ptr_gtcids_vn->next; |
1133 |
ptr_gtcids_vn->next = (GTCIDS_Version_Number*)NULL; |
1134 |
} |
1135 |
ptr_gtcids_vn->next= NULL; |
1136 |
/*Parse key values- HMI ID and Stanford ID */ |
1137 |
/*Locate column for HMI_ID value and STANFORD_TLM_HMI_AIA values*/ |
1138 |
/*HMI_ID Column is 4th column with | as delimiter*/ |
1139 |
/*STANFORD_TLM_HMI_AIA values are in 7th column*/ |
1140 |
/*Assume always above, otherwise more code required here*/ |
1141 |
sscanf( line, |
1142 |
"%s %s |%*s | %s | %s | %s | %*s | %s | %*s", |
1143 |
ptr_gtcids_vn->change_date, |
1144 |
ptr_gtcids_vn->change_time, |
1145 |
ptr_gtcids_vn->ker_id_version_number, |
1146 |
ptr_gtcids_vn->hmi_id_version_number, |
1147 |
ptr_gtcids_vn->aia_id_version_number, |
1148 |
ptr_gtcids_vn->file_version_number); |
1149 |
} |
1150 |
} /* END-for fgets line */ |
1151 |
fclose(file_ptr); |
1152 |
|
1153 |
global_gtcids_vn = top_ptr_gtcids_vn; /* set global */ |
1154 |
return(top_ptr_gtcids_vn); |
1155 |
}/* END-Module: read_gtcids_hk_file */ |
1156 |
|
1157 |
|
1158 |
|
1159 |
/***************************************************************************** |
1160 |
* Load GTCIDS(Ground_to_code_ids) Version Number Values |
1161 |
* Module Name: load_gtcids_vn_values |
1162 |
* Description: This function loads parameter version number into the |
1163 |
* the APID_-Pointer and HK-Config_File structure based on |
1164 |
* the file_version_number values in the HK_Config_Files and |
1165 |
* GTCIDS_Version_Number structures. |
1166 |
* Status: load_gtcids_vn_values():Tested |
1167 |
*****************************************************************************/ |
1168 |
void load_gtcids_data( GTCIDS_Version_Number* top_ptr_gtcids_data, |
1169 |
APID_Pointer_HK_Configs *top_apid_ptr_hk_configs) |
1170 |
{ |
1171 |
/* declarations */ |
1172 |
GTCIDS_Version_Number* tmp_ptr_gtcids_data; |
1173 |
APID_Pointer_HK_Configs *tmp_apid_ptr_hk_configs; |
1174 |
HK_Config_Files *tmp_ptr_hk_configs; |
1175 |
|
1176 |
/* Initialize data */ |
1177 |
tmp_ptr_gtcids_data= top_ptr_gtcids_data; |
1178 |
tmp_apid_ptr_hk_configs= top_apid_ptr_hk_configs; |
1179 |
|
1180 |
/* load gtcids data in APID-PTR and HK-Config-Files structures */ |
1181 |
for(tmp_apid_ptr_hk_configs = top_apid_ptr_hk_configs; |
1182 |
tmp_apid_ptr_hk_configs ; |
1183 |
tmp_apid_ptr_hk_configs= tmp_apid_ptr_hk_configs->next) |
1184 |
{ |
1185 |
for( tmp_ptr_hk_configs = tmp_apid_ptr_hk_configs->ptr_hk_configs; |
1186 |
tmp_ptr_hk_configs ; |
1187 |
tmp_ptr_hk_configs= tmp_ptr_hk_configs->next) |
1188 |
{ |
1189 |
for (tmp_ptr_gtcids_data=top_ptr_gtcids_data;tmp_ptr_gtcids_data ; |
1190 |
tmp_ptr_gtcids_data=tmp_ptr_gtcids_data->next) |
1191 |
{ |
1192 |
if( !strcmp(tmp_ptr_gtcids_data->file_version_number, |
1193 |
tmp_ptr_hk_configs->file_version_number)) |
1194 |
{ |
1195 |
if(!strcmp(tmp_ptr_hk_configs->packet_id_type, HMI_ID_TYPE)) |
1196 |
{ |
1197 |
strcpy(tmp_ptr_hk_configs->parameter_version_number, |
1198 |
tmp_ptr_gtcids_data->hmi_id_version_number); |
1199 |
} |
1200 |
else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, AIA_ID_TYPE)) |
1201 |
{ |
1202 |
strcpy(tmp_ptr_hk_configs->parameter_version_number, |
1203 |
tmp_ptr_gtcids_data->aia_id_version_number); |
1204 |
} |
1205 |
else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, IRIS_ID_TYPE)) |
1206 |
{ |
1207 |
strcpy(tmp_ptr_hk_configs->parameter_version_number, |
1208 |
tmp_ptr_gtcids_data->hmi_id_version_number); |
1209 |
} |
1210 |
else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, AIAKER_ID_TYPE)) |
1211 |
{ |
1212 |
strcpy(tmp_ptr_hk_configs->parameter_version_number, |
1213 |
tmp_ptr_gtcids_data->ker_id_version_number); |
1214 |
} |
1215 |
else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, HMIKER_ID_TYPE)) |
1216 |
{ |
1217 |
strcpy(tmp_ptr_hk_configs->parameter_version_number, |
1218 |
tmp_ptr_gtcids_data->ker_id_version_number); |
1219 |
} |
1220 |
else |
1221 |
{ /*default set to HMI type */ |
1222 |
strcpy(tmp_ptr_hk_configs->parameter_version_number, |
1223 |
tmp_ptr_gtcids_data->hmi_id_version_number); |
1224 |
} |
1225 |
break; |
1226 |
} |
1227 |
} /* End-for thru gtcid data */ |
1228 |
} /*End-for loop thru hk config nodes */ |
1229 |
} /*End-for loop thru apid-ptr */ |
1230 |
} /* END-module : load_gtcids_data*/ |
1231 |
|
1232 |
|
1233 |
|
1234 |
/***************************************************************************** |
1235 |
* Deallocate GTCIDS Version Numbers |
1236 |
* Module Name: deallocate_GTCIDS_Version_Number |
1237 |
* Description: This function deallocates GTCIDS_Version_Number Structure |
1238 |
* link list. |
1239 |
*****************************************************************************/ |
1240 |
void deallocate_GTCIDS_Version_Number(void) |
1241 |
{ |
1242 |
/*declarations */ |
1243 |
GTCIDS_Version_Number *p,*tmp; |
1244 |
|
1245 |
/* deallocate nodes in link list */ |
1246 |
p = global_gtcids_vn; |
1247 |
|
1248 |
while(p) |
1249 |
{ |
1250 |
tmp = p->next; |
1251 |
free(p); |
1252 |
p = tmp; |
1253 |
} |
1254 |
} |
1255 |
/***************************************************************************** |
1256 |
* Deallocate SHCIDS Version Numbers |
1257 |
* Module Name: deallocate_SHCIDS_Version_Number |
1258 |
* Description: This function deallocates GTCIDS_Version_Number Structure |
1259 |
* link list. |
1260 |
*****************************************************************************/ |
1261 |
void deallocate_SHCIDS_Version_Number(void) |
1262 |
{ |
1263 |
/*declarations */ |
1264 |
SHCIDS_Version_Number *p,*tmp; |
1265 |
|
1266 |
/* deallocate nodes in link list */ |
1267 |
p = global_shcids_vn; |
1268 |
|
1269 |
while(p) |
1270 |
{ |
1271 |
tmp = p->next; |
1272 |
free(p); |
1273 |
p = tmp; |
1274 |
} |
1275 |
} |
1276 |
|
1277 |
/***************************************************************************** |
1278 |
* DE-Allocate Memory APID HKPFD FILES NODES |
1279 |
* Module Name: deallocate_apid_hkpfd_files_nodes; |
1280 |
* Description: deAllocate memory for a link list of directory |
1281 |
* and filename's. |
1282 |
* Status allocate_apid_hkpfd_files_nodes(): initial coding started only |
1283 |
*****************************************************************************/ |
1284 |
void deallocate_apid_hkpfd_files_nodes(APID_HKPFD_Files *ptr) |
1285 |
{ |
1286 |
/*declarations*/ |
1287 |
APID_HKPFD_Files *tmp; |
1288 |
|
1289 |
while(ptr) |
1290 |
{ |
1291 |
tmp = ptr->next; |
1292 |
free(ptr); |
1293 |
ptr = tmp; |
1294 |
} |
1295 |
return; |
1296 |
} |
1297 |
|
1298 |
|
1299 |
|
1300 |
/***************************************************************************** |
1301 |
* ReRead All APID-<#>-VERSION-<#> files |
1302 |
* Module Name: |
1303 |
* Description: |
1304 |
* |
1305 |
* Status reread_all_files(): initial coding |
1306 |
*****************************************************************************/ |
1307 |
HK_Config_Files* reread_all_files(APID_Pointer_HK_Configs *apid_ptr_configs, |
1308 |
char version_number[MAX_CHAR_VERSION_NUMBER], char pkt_date[MAX_SIZE_PKT_DATE]) |
1309 |
{ |
1310 |
/*declarations*/ |
1311 |
APID_HKPFD_Files *hkpfd_files; |
1312 |
APID_HKPFD_Files *top_hkpfd_files; |
1313 |
APID_Pointer_HK_Configs *p, *prev_p; |
1314 |
GTCIDS_Version_Number *ptr_gtcids_data; |
1315 |
SHCIDS_Version_Number *ptr_shcids_data; |
1316 |
char file_version_number[50]; |
1317 |
char *ptr_fvn; |
1318 |
int apid; |
1319 |
int found_flag; |
1320 |
|
1321 |
/* init values */ |
1322 |
ptr_fvn=file_version_number; |
1323 |
|
1324 |
/*save apid value to look up later */ |
1325 |
apid= apid_ptr_configs->apid; |
1326 |
|
1327 |
|
1328 |
/* deallocate GTCIDS_VERSION and SHCIDS_VERSION nodes and reread gtcids.txt and shcids.txt files */ |
1329 |
deallocate_GTCIDS_Version_Number(); |
1330 |
deallocate_SHCIDS_Version_Number(); |
1331 |
read_gtcids_hk_file(); |
1332 |
read_shcids_hk_file(); |
1333 |
ptr_gtcids_data = global_gtcids_vn; |
1334 |
ptr_shcids_data = global_shcids_vn; |
1335 |
|
1336 |
if(check_for_sdo_apid(apid)) |
1337 |
{ |
1338 |
ptr_fvn=find_fvn_from_shcids(ptr_shcids_data, pkt_date, apid); |
1339 |
#ifdef DEBUG_LOAD_HK_CONFIG_FILE |
1340 |
printkerr("DEBUG:Message at %s, line %d: Rereading config files and shcids file to find file version:<%s> apid:<%d>\n", __FILE__, __LINE__, ptr_fvn, apid); |
1341 |
#endif |
1342 |
} |
1343 |
else |
1344 |
{ |
1345 |
/* find file version number directory to read in files */ |
1346 |
ptr_fvn=find_file_version_number(ptr_gtcids_data, version_number, apid); |
1347 |
#ifdef DEBUG_LOAD_HK_CONFIG_FILE |
1348 |
printkerr("DEBUG:Message at %s, line %d: Rereading config files and gtcids file to find file version:<%s> apid:<%d>\n", __FILE__, __LINE__,ptr_fvn, apid); |
1349 |
#endif |
1350 |
} |
1351 |
|
1352 |
/* load HK_Config_Files structures for each apid */ |
1353 |
if ((top_hkpfd_files = read_all_hk_config_files(apid,ptr_fvn,version_number)) == NULL) |
1354 |
return (HK_Config_Files*)NULL; |
1355 |
/* check which apid node to add */ |
1356 |
for(hkpfd_files=top_hkpfd_files; hkpfd_files; |
1357 |
hkpfd_files=hkpfd_files->next) |
1358 |
{ |
1359 |
found_flag=0; |
1360 |
for(p=global_apid_configs; p ; p=p->next) |
1361 |
{ |
1362 |
/* compare packet names- note:change from if ( p->apid == hkpfd_files->apid) to below*/ |
1363 |
if (!strcmp(p->apid_name, hkpfd_files->apid_name)) |
1364 |
{ |
1365 |
found_flag=1; |
1366 |
break; |
1367 |
} |
1368 |
prev_p=p; |
1369 |
} |
1370 |
if (!found_flag) |
1371 |
{ |
1372 |
/* add apid node to link list */ |
1373 |
prev_p->next = (APID_Pointer_HK_Configs *) malloc (sizeof (APID_Pointer_HK_Configs)); |
1374 |
prev_p->next->next= NULL; |
1375 |
prev_p->next->ptr_hk_configs= (HK_Config_Files*) NULL; |
1376 |
/* copy in packet name. note:changed from this prev_p->next->apid=hkpfd_files->apid;to below*/ |
1377 |
strcpy(prev_p->next->apid_name, hkpfd_files->apid_name); |
1378 |
} |
1379 |
} |
1380 |
/*set moving pointer to top of list and load config data */ |
1381 |
for(p=global_apid_configs; p ; p=p->next) |
1382 |
{ |
1383 |
load_config_data(top_hkpfd_files, p); |
1384 |
} |
1385 |
|
1386 |
if (!check_for_sdo_apid(apid)) |
1387 |
{ |
1388 |
/* load data for packet version numbers in hk config format link list*/ |
1389 |
p=global_apid_configs; |
1390 |
load_gtcids_data(ptr_gtcids_data, p); |
1391 |
} |
1392 |
|
1393 |
/* deallocate top_apid_hkpfd_files link list */ |
1394 |
hkpfd_files=top_hkpfd_files; |
1395 |
deallocate_apid_hkpfd_files_nodes(hkpfd_files) ; |
1396 |
|
1397 |
/* locate top HK_Config_Files Node for APID_Pointer node equal to lookup apid value */ |
1398 |
p = global_apid_configs; |
1399 |
while (p) |
1400 |
{ |
1401 |
if( p->apid == apid ) |
1402 |
{ |
1403 |
return p->ptr_hk_configs; |
1404 |
}/* if apid equal p->apid */ |
1405 |
p = p->next; //added 1-19-2006 |
1406 |
} |
1407 |
/* APID not found, return NULL. */ |
1408 |
return (HK_Config_Files*)NULL; |
1409 |
} |
1410 |
|
1411 |
|
1412 |
/***************************************************************************** |
1413 |
* FIND FILE VERSION NUMBER |
1414 |
* Module Name: find_file_version_number() |
1415 |
* Description: Gets file version number based on packet version number. |
1416 |
* |
1417 |
* Status find_file_version_number(): Coded and Tested |
1418 |
*****************************************************************************/ |
1419 |
char * find_file_version_number(GTCIDS_Version_Number *top, char p_version_number[MAX_CHAR_VERSION_NUMBER],int aid) |
1420 |
{ |
1421 |
/*declarations*/ |
1422 |
GTCIDS_Version_Number *tmp_ptr; |
1423 |
|
1424 |
for(tmp_ptr=top;tmp_ptr;tmp_ptr=tmp_ptr->next) |
1425 |
{ |
1426 |
/* if aid is KERNAL type then lookup packet version number using KER_ID column in gtcids file */ |
1427 |
if (aid == HK_HSB_HMI_OBT_1 || aid == HK_HSB_HMI_OBT_2 || aid == HK_HSB_AIA_OBT_1 || aid == HK_HSB_AIA_OBT_2 || aid == HK_LR_AIA_OBT || aid == HK_LR_HMI_OBT || aid == HK_LR_HMI_KER_TELEM || aid == HK_LR_AIA_KER_TELEM) |
1428 |
{ |
1429 |
if( !strcmp(tmp_ptr->ker_id_version_number, p_version_number)) |
1430 |
{ |
1431 |
return tmp_ptr->file_version_number; |
1432 |
} |
1433 |
} |
1434 |
else if ((aid >= HK_HSB_HMI_LRANGE && aid <= HK_HSB_HMI_HRANGE ) || (aid >= HK_LR_HMI_LRANGE && aid <= HK_LR_HMI_HRANGE)) |
1435 |
{ |
1436 |
if( !strcmp(tmp_ptr->hmi_id_version_number, p_version_number)) |
1437 |
{ |
1438 |
return tmp_ptr->file_version_number; |
1439 |
} |
1440 |
} |
1441 |
else if ((aid >= HK_HSB_AIA_LRANGE && aid <= HK_HSB_AIA_HRANGE ) || (aid >= HK_LR_AIA_LRANGE && aid <= HK_LR_AIA_HRANGE)) |
1442 |
{ |
1443 |
if( !strcmp(tmp_ptr->aia_id_version_number, p_version_number)) |
1444 |
{ |
1445 |
return tmp_ptr->file_version_number; |
1446 |
} |
1447 |
} |
1448 |
} /* End-for */ |
1449 |
return (""); |
1450 |
} |
1451 |
/***************************************************************************** |
1452 |
* Read SHCIDS(sdo_hk_code_ids.txt or shcids.txt) HK Files |
1453 |
* Module Name: read_shcids_hk_file |
1454 |
* Description: This function reads the SHCIDS file and loads data into the |
1455 |
* SHCIDS_Version_Number structure. |
1456 |
* Status read_shcids_hk_fi1e(): Review and Test open tasks |
1457 |
*****************************************************************************/ |
1458 |
SHCIDS_Version_Number * read_shcids_hk_file() |
1459 |
{ |
1460 |
/*declarations*/ |
1461 |
char *hk_shcids_directory ; |
1462 |
char *hk_shcids_filename; |
1463 |
char hk_shcids_directory_filename[MAX_FILE_NAME]; |
1464 |
FILE *file_ptr; |
1465 |
char line[MAXLINE_IN_FILE]; |
1466 |
SHCIDS_Version_Number *top_ptr_shcids_vn; |
1467 |
SHCIDS_Version_Number *ptr_shcids_vn; |
1468 |
char new_str[9];//yyyymmdd |
1469 |
|
1470 |
/* get directory and file name */ |
1471 |
hk_shcids_directory = getenv("HK_SHCIDS_DIRECTORY"); |
1472 |
hk_shcids_filename= getenv("HK_SHCIDS_FILE"); |
1473 |
if(hk_shcids_filename == NULL) |
1474 |
hk_shcids_filename = "shcids.txt"; |
1475 |
if(hk_shcids_directory == NULL) |
1476 |
hk_shcids_directory = "/home/production/cvs/TBL_JSOC/lev0/hk_config_file/sdo_hk"; |
1477 |
sprintf(hk_shcids_directory_filename, "%s/%s", hk_shcids_directory, |
1478 |
hk_shcids_filename); |
1479 |
|
1480 |
/*open file & read data into SHCIDS_Version_Number link list structure*/ |
1481 |
file_ptr = fopen(hk_shcids_directory_filename, "r"); |
1482 |
if(!file_ptr) |
1483 |
{ |
1484 |
printkerr("ERROR:Couldn't open SDO HK Code IDS file %s.\n",hk_shcids_directory_filename); |
1485 |
printkerr("Set the enviroment variables HK_SHCIDS_DIRECTORY" |
1486 |
" to point to config directory and HK_SHCIDS_FILE" |
1487 |
" environment variable to point to the correct file name\n"); |
1488 |
return NULL; |
1489 |
} |
1490 |
top_ptr_shcids_vn = NULL; |
1491 |
while( fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL ) |
1492 |
{ |
1493 |
if(line[0] == '#') |
1494 |
continue; /* skip comments */ |
1495 |
else |
1496 |
{ |
1497 |
if (top_ptr_shcids_vn == NULL) |
1498 |
{ |
1499 |
top_ptr_shcids_vn = ptr_shcids_vn = malloc(sizeof(SHCIDS_Version_Number)); |
1500 |
ptr_shcids_vn->next = (SHCIDS_Version_Number*)NULL; |
1501 |
} |
1502 |
else |
1503 |
{ |
1504 |
ptr_shcids_vn->next = malloc(sizeof(SHCIDS_Version_Number)); |
1505 |
ptr_shcids_vn = ptr_shcids_vn->next; |
1506 |
ptr_shcids_vn->next = (SHCIDS_Version_Number*)NULL; |
1507 |
} |
1508 |
ptr_shcids_vn->next= NULL; |
1509 |
/*Parse key values from file where header is:*/ |
1510 |
/*# Start Dayfile Date/Time | APID | File Version ID | Master File and version*/ |
1511 |
/*Assume always above, otherwise more code required here*/ |
1512 |
sscanf( line, |
1513 |
"%s %s |%d |%s | %*s", |
1514 |
ptr_shcids_vn->change_date, |
1515 |
ptr_shcids_vn->change_time, |
1516 |
&ptr_shcids_vn->apid, |
1517 |
ptr_shcids_vn->file_version_number); |
1518 |
|
1519 |
/* add change date as integer value */ |
1520 |
for(int i=0; i < 9; new_str[i++]='\0'); |
1521 |
strncpy(new_str,ptr_shcids_vn->change_date,4); //get yyyy |
1522 |
strncat(new_str,&ptr_shcids_vn->change_date[5],2);//get mm |
1523 |
strncat(new_str,&ptr_shcids_vn->change_date[8],2);//get dd |
1524 |
sscanf(new_str,"%d",&ptr_shcids_vn->date); //convert to int |
1525 |
} |
1526 |
} /* END-for fgets line */ |
1527 |
fclose(file_ptr); |
1528 |
global_shcids_vn = top_ptr_shcids_vn; /* set global */ |
1529 |
return(top_ptr_shcids_vn); |
1530 |
}/* END-Module: read_shcids_hk_file */ |
1531 |
/***************************************************************************** |
1532 |
* FIND FILE VERSION NUMBER IN SDO HK CODE IDS |
1533 |
* Module Name: find_fvn_from_shcids() |
1534 |
* Description: Gets file version number based on packet time |
1535 |
* |
1536 |
* Status find_fvn_from_shcids(): Coded and Tested |
1537 |
*****************************************************************************/ |
1538 |
char * find_fvn_from_shcids(SHCIDS_Version_Number *top, char p_date[MAX_SIZE_PKT_DATE], int apid) |
1539 |
{ |
1540 |
/*declarations*/ |
1541 |
SHCIDS_Version_Number *tmp_ptr; |
1542 |
char new_str[9]; |
1543 |
char *saved_fvn; |
1544 |
char saved_fvn_str[50]; |
1545 |
int current_date; |
1546 |
int pkt_date; |
1547 |
int saved_date; |
1548 |
int saved_flg=0; |
1549 |
saved_fvn=saved_fvn_str; |
1550 |
|
1551 |
/* change string date to integer value to make easier to compare */ |
1552 |
for(int i=0; i < 9; new_str[i++]='\0'); |
1553 |
strncpy(new_str,p_date,4); //get yyyy |
1554 |
strncat(new_str,&p_date[5],2); //get mm |
1555 |
strncat(new_str,&p_date[8],2); //get dd |
1556 |
sscanf(new_str,"%d",&pkt_date); //convert to int |
1557 |
|
1558 |
/* loop thru shcids.txt files data to find file version number */ |
1559 |
for(tmp_ptr=top;tmp_ptr;tmp_ptr=tmp_ptr->next) |
1560 |
{ |
1561 |
if(pkt_date >= tmp_ptr->date && tmp_ptr->apid == apid) |
1562 |
{ |
1563 |
if(saved_flg) |
1564 |
{ |
1565 |
current_date=tmp_ptr->date; |
1566 |
if(current_date >= saved_date) |
1567 |
{ |
1568 |
/*use latest date for fvn */ |
1569 |
saved_date=current_date; |
1570 |
saved_fvn=tmp_ptr->file_version_number; |
1571 |
} |
1572 |
} |
1573 |
else |
1574 |
{ |
1575 |
/* found fvn */ |
1576 |
saved_date=tmp_ptr->date; |
1577 |
saved_fvn=tmp_ptr->file_version_number; |
1578 |
saved_flg=1; |
1579 |
} |
1580 |
} |
1581 |
} /* End-for */ |
1582 |
if(saved_flg) |
1583 |
{ |
1584 |
return ((char*)saved_fvn); |
1585 |
} |
1586 |
else |
1587 |
{ |
1588 |
/* if did not find file version from SHCIDS file then set to zero */ |
1589 |
strcpy(saved_fvn,"BAD PKT DATE"); |
1590 |
printkerr("ERROR at %s, line %d: Could not find date in shcids.txt file " |
1591 |
"to look up file version to reference for config files. " |
1592 |
"Problem Packet Date used was:<%s>. Probably bad data for timecodes\n", |
1593 |
__FILE__,__LINE__,new_str); |
1594 |
return ((char*)saved_fvn); |
1595 |
} |
1596 |
} |
1597 |
/***************************************************************************** |
1598 |
* CHECK FOR SDO HK APID |
1599 |
* Module Name: check_for_sdo_apid() |
1600 |
* Description: checks for sdo hk apid and returns 1 if true or 0 if false. |
1601 |
*****************************************************************************/ |
1602 |
int check_for_sdo_apid(int apid) |
1603 |
{ |
1604 |
//NOTE!! For IRIS always return false. |
1605 |
//See Rock's mail "Re: iris hk apid" 06Mar2012 12:18 |
1606 |
//to check for values less than 96 decimal |
1607 |
//JJA 06Mar2012 |
1608 |
return(0); |
1609 |
|
1610 |
if ((apid >= 96) && (apid <= 399)) |
1611 |
{ |
1612 |
return (1);//This is sdo hk apid |
1613 |
} |
1614 |
else |
1615 |
{ |
1616 |
return (0);//This is hk apid between 1-63,400's or 500's |
1617 |
} |
1618 |
|
1619 |
} |
1620 |
|