00001 #ident "$Header: /home/cvsuser/cvsroot/JSOC/proj/lev0/apps/load_hk_config_files.c,v 1.12 2013/03/07 23:28:50 arta Exp $"
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 #include <stdio.h>
00048 #include <stdlib.h>
00049 #include <string.h>
00050 #include <math.h>
00051 #include <time.h>
00052 #include <sys/types.h>
00053 #include <sys/stat.h>
00054 #include <sys/vfs.h>
00055 #include <fcntl.h>
00056 #include <unistd.h>
00057 #include <libgen.h>
00058 #include "drms_types.h"
00059 #include "egsehmicomp.h"
00060 #include "printk.h"
00061 #include "decode_hk.h"
00062 #include <dirent.h>
00063 #include "write_hk_to_drms.h"
00064
00065 #define LOAD_HK_C
00066 #include "load_hk_config_files.h"
00067 #undef LOAD_HK_C
00068
00069
00070 APID_HKPFD_Files * allocate_apid_hkpfd_files_nodes(int *ptrFirstTimeFlag);
00071 void load_gtcids_data( GTCIDS_Version_Number* top_ptr_gtcids_data,
00072 APID_Pointer_HK_Configs *top_apid_ptr_hk_configs);
00073 int check_for_sdo_apid(int apid);
00074
00075 #define LOAD_HK_C
00076 #include "load_hk_config_files.h"
00077 #undef LOAD_HK_C
00078
00079
00080 APID_HKPFD_Files * allocate_apid_hkpfd_files_nodes(int *ptrFirstTimeFlag);
00081 void load_gtcids_data( GTCIDS_Version_Number* top_ptr_gtcids_data,
00082 APID_Pointer_HK_Configs *top_apid_ptr_hk_configs);
00083 int check_for_sdo_apid(int apid);
00084 void deallocate_apid_hkpfd_files_nodes(APID_HKPFD_Files *top_ptr_apid_hkpfd_files_ptr) ;
00085 char * find_file_version_number(GTCIDS_Version_Number *top,char p_version_number[MAX_CHAR_VERSION_NUMBER], int apid);
00086 char * find_fvn_from_shcids(SHCIDS_Version_Number *top,char pkt_date[MAX_SIZE_PKT_DATE],int apid);
00087
00088 APID_Pointer_HK_Configs *global_apid_configs;
00089 GTCIDS_Version_Number *global_gtcids_vn;
00090 SHCIDS_Version_Number *global_shcids_vn;
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 int load_all_apids_hk_configs(int apid, char version_number[MAX_CHAR_VERSION_NUMBER], char pkt_date[MAX_SIZE_PKT_DATE])
00102 {
00103
00104 APID_Pointer_HK_Configs *apid_ptr_hk_configs;
00105 APID_Pointer_HK_Configs *top_apid_ptr_hk_configs;
00106 APID_HKPFD_Files *top_apid_hkpfd_files;
00107 APID_HKPFD_Files *hkpfd_files;
00108 GTCIDS_Version_Number *top_ptr_gtcids_data;
00109 SHCIDS_Version_Number *top_ptr_shcids_data;
00110 int apid_array[MAX_APID_POINTERS];
00111 char apidstr_array[MAX_APID_POINTERS][10];
00112 int number_of_apids, i;
00113 char file_version_number[MAX_CHAR_VERSION_NUMBER];
00114 char *ptr_fvn;
00115
00116
00117
00118
00119 ptr_fvn=file_version_number;
00120
00121
00122 top_ptr_gtcids_data = read_gtcids_hk_file();
00123
00124
00125 top_ptr_shcids_data = read_shcids_hk_file();
00126
00127
00128 if(check_for_sdo_apid(apid))
00129 {
00130
00131 ptr_fvn=find_fvn_from_shcids(top_ptr_shcids_data, pkt_date, apid);
00132 }
00133 else
00134 {
00135
00136 ptr_fvn=find_file_version_number(top_ptr_gtcids_data, version_number, apid);
00137 }
00138
00139
00140 if ((top_apid_hkpfd_files = read_all_hk_config_files(apid, ptr_fvn, version_number)) == NULL)
00141 return ERROR_HK_NOSUCHDIR;
00142
00143
00144 number_of_apids = 0;
00145 memset(apid_array, 0, sizeof(apid_array));
00146 for(i=0; i < MAX_APID_POINTERS; i++)
00147 {
00148 memset(apidstr_array[i],'\0', 10);
00149 }
00150 for(hkpfd_files=top_apid_hkpfd_files; hkpfd_files;
00151 hkpfd_files=hkpfd_files->next)
00152 {
00153
00154 for (i=0; i<number_of_apids; i++)
00155 {
00156
00157 if (apid_array[i] == hkpfd_files->apid)
00158 {
00159
00160 break;
00161 }
00162 }
00163 if (i >= number_of_apids)
00164 {
00165
00166 apid_array[i]= hkpfd_files->apid;
00167
00168
00169 strcpy(apidstr_array[i], hkpfd_files->apid_name);
00170 number_of_apids++;
00171 }
00172 }
00173
00174 for ( i=0; i < number_of_apids; i++)
00175 {
00176 if ( i == 0)
00177 {
00178
00179 apid_ptr_hk_configs = (APID_Pointer_HK_Configs *)malloc(sizeof(APID_Pointer_HK_Configs));
00180 top_apid_ptr_hk_configs = apid_ptr_hk_configs;
00181 }
00182 else
00183 {
00184
00185 apid_ptr_hk_configs->next = (APID_Pointer_HK_Configs *)malloc(sizeof(APID_Pointer_HK_Configs));
00186 apid_ptr_hk_configs = apid_ptr_hk_configs->next;
00187 }
00188
00189
00190 apid_ptr_hk_configs->apid = apid_array[i];
00191 strcpy(apid_ptr_hk_configs->apid_name, apidstr_array[i]);
00192
00193
00194 apid_ptr_hk_configs->next= NULL;
00195 apid_ptr_hk_configs->ptr_hk_configs= (HK_Config_Files*)NULL;
00196 }
00197
00198
00199 apid_ptr_hk_configs = top_apid_ptr_hk_configs;
00200 for(i=0; i < number_of_apids; i++)
00201 {
00202 load_config_data( top_apid_hkpfd_files, apid_ptr_hk_configs);
00203 apid_ptr_hk_configs = apid_ptr_hk_configs->next;
00204 }
00205
00206
00207 load_gtcids_data(top_ptr_gtcids_data, top_apid_ptr_hk_configs);
00208
00209
00210 global_apid_configs = top_apid_ptr_hk_configs;
00211
00212
00213 deallocate_apid_hkpfd_files_nodes(top_apid_hkpfd_files) ;
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 return HK_SUCCESSFUL;
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 void load_config_data(APID_HKPFD_Files *hkpfd_files,
00256 APID_Pointer_HK_Configs *hk_configs)
00257 {
00258
00259 APID_HKPFD_Files* p;
00260 FILE* file_ptr;
00261 char filename[MAX_FILE_NAME];
00262 int apid;
00263
00264
00265 apid = hk_configs->apid;
00266 p = hkpfd_files;
00267 while(p)
00268 {
00269 if ( p->apid == apid )
00270 {
00271 sprintf(filename,"%s/%s",p->directory_name, p->filename);
00272 file_ptr = fopen( filename ,"r");
00273 (void)save_hdpf_new_formats(file_ptr, hk_configs);
00274 fclose(file_ptr);
00275 }
00276 p = p->next;
00277 }
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 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])
00289 {
00290
00291 APID_HKPFD_Files *top, *p;
00292 DIR *dir_p;
00293 char dirname[200];
00294 char *dn;
00295 int curr_pvn_wn,curr_pvn_dn;
00296 struct dirent *dir_entry_p;
00297
00298
00299 int file_loaded_flag=0;
00300 memset(dirname, 0x0, sizeof(dirname));
00301
00302
00303 if(check_for_sdo_apid(apid))
00304 {
00305 dn = getenv("HK_SHCIDS_DIRECTORY");
00306 if(dn == NULL)
00307 {
00308 printkerr("ERROR at %s, line %d: Could not get directory environment\n"
00309 "variable:<HK_SHCIDS_DIRECTORY>. Set the env variable "
00310 "HK_SHCIDS_DIRECTORY to point to the config file directory.\n",
00311 __FILE__,__LINE__,dn);
00312 return NULL;
00313 }
00314 }
00315 else
00316 {
00317 dn = getenv("HK_CONFIG_DIRECTORY");
00318 if(dn == NULL)
00319 {
00320 printkerr("ERROR at %s, line %d: Could not get directory environment\n"
00321 "variable:<HK_CONFIG_DIRECTORY>. Set the env variable "
00322 "HK_CONFIG_DIRECTORY to point to the config file directory.\n",
00323 __FILE__,__LINE__,dn);
00324 return NULL;
00325 }
00326 }
00327
00328
00329 strcpy( dirname, dn);
00330 strcat(dirname, f_version_number);
00331 strcat(dirname,"\0");
00332
00333
00334 if ((dir_p = opendir(dirname)) == NULL)
00335 {
00336 printkerr("ERROR at %s, line %d: Could not open directory <%s>. "
00337 "The directory with < %s > version number does not exist. "
00338 "Run make_hkpdf.pl script to create directory and config files.\n",
00339 __FILE__,__LINE__,dirname, f_version_number);
00340 return NULL;
00341 }
00342
00343
00344 top = NULL;
00345 while( (dir_entry_p = readdir(dir_p)) != NULL )
00346 {
00347 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))
00348 ;
00349 else
00350 continue;
00351
00352 if( top == NULL )
00353 top = p = malloc(sizeof(APID_HKPFD_Files));
00354 else
00355 {
00356 p->next = malloc(sizeof(APID_HKPFD_Files));
00357 p = p->next;
00358 }
00359 p->next = NULL;
00360
00361
00362 strcpy(p->filename, dir_entry_p->d_name);
00363 strcpy(p->directory_name, dirname);
00364
00365 if (check_for_sdo_apid(apid))
00366 {
00367
00368
00369 curr_pvn_wn= HK_LEV0_START_MERGED_PVNW;
00370 curr_pvn_dn= HK_LEV0_START_MERGED_PVND;
00371 }
00372 else
00373 {
00374
00375 sscanf(p_version_number,"%3d.%3d",&curr_pvn_wn, &curr_pvn_dn);
00376 }
00377
00378
00379 if(curr_pvn_wn >= HK_LEV0_START_MERGED_PVNW && curr_pvn_dn >= HK_LEV0_START_MERGED_PVND)
00380 {
00381
00382 if( !strncmp(dir_entry_p->d_name,"HMI-ISP",7) )
00383 {
00384
00385 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00386 p->apid=445;
00387 }
00388 else if( !strncmp(dir_entry_p->d_name,"AIA-ISP",7) )
00389 {
00390
00391 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00392 p->apid=529;
00393 }
00394 else if( !strncmp(dir_entry_p->d_name,"HMI-SEQ",7) )
00395 {
00396
00397 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00398 p->apid=451;
00399 }
00400 else if( !strncmp(dir_entry_p->d_name,"AIA-SEQ",7) )
00401 {
00402
00403 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00404 p->apid=536;
00405 }
00406 else if( !strncmp(dir_entry_p->d_name,"HMI-OBT",7) )
00407 {
00408
00409 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00410 p->apid=448;
00411 }
00412 else if( !strncmp(dir_entry_p->d_name,"AIA-OBT",7) )
00413 {
00414
00415 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00416 p->apid=540;
00417 }
00418 else if( !strncmp(dir_entry_p->d_name,"SDO-ASD",7) )
00419 {
00420
00421 sscanf(p->filename, "%*3s-%3s-%*7s-%s", p->apid_name, p->version_number);
00422 p->apid=129;
00423 }
00424 else if( !strncmp(dir_entry_p->d_name,"AIA-",4) )
00425 {
00426
00427 sscanf(p->filename, "%*3s-%x-%*7s-%s", &p->apid, p->version_number);
00428 sprintf(p->apid_name,"0x%03x", p->apid);
00429 }
00430 else if( !strncmp(dir_entry_p->d_name,"HMI-",4) )
00431 {
00432
00433 sscanf(p->filename, "%*3s-%x-%*7s-%s", &p->apid, p->version_number);
00434 sprintf(p->apid_name,"0x%03x", p->apid);
00435 }
00436 else
00437 {
00438
00439 sscanf(p->filename, "%*4s-%x-%*7s-%s", &p->apid, p->version_number);
00440 sprintf(p->apid_name,"0x%03x", p->apid);
00441 printkerr("WARNING at %s, line %d: This is not a valid config file "
00442 "name < %s > for merged apid case. Updates HKPDF files with correct "
00443 "format of files(<HMI|AIA|SDO>-<APID-NAME>-version-<file version number>. "
00444 "This occurred for apid < %d >.\n",
00445 __FILE__,__LINE__, dir_entry_p->d_name, p->apid );
00446 }
00447 }
00448 else
00449 {
00450
00451 sscanf(p->filename, "%*4s-%x-%*7s-%s", &p->apid, p->version_number);
00452 sprintf(p->apid_name,"0x%03x", p->apid);
00453 }
00454 file_loaded_flag=1;
00455 }
00456
00457 closedir(dir_p);
00458
00459
00460 if ( !file_loaded_flag)
00461 {
00462
00463
00464
00465
00466
00467
00468
00469 }
00470 return top;
00471 }
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 int save_hdpf_new_formats(FILE* file_ptr,APID_Pointer_HK_Configs *p_apid_ptr_hk_configs)
00489 {
00490
00491 int err_status[3];
00492 HK_Config_Files *ptr_config_node;
00493 HK_Config_Files *previous_ptr_config_node;
00494 int status;
00495 int i, j, k;
00496 char line[MAXLINE_IN_FILE];
00497 char keyword_lines[MAX_NUM_KW_LINES][MAXLINE_IN_FILE];
00498 char acon_lines[MAX_NUM_ACON_LINES][MAXLINE_ACON_IN_FILE];
00499 char dcon_lines[MAX_NUM_DCON_LINES][MAXLINE_DCON_IN_FILE];
00500
00501
00502
00503 if (p_apid_ptr_hk_configs->ptr_hk_configs == NULL)
00504 {
00505
00506 p_apid_ptr_hk_configs->ptr_hk_configs =malloc( sizeof(HK_Config_Files));
00507 ptr_config_node = p_apid_ptr_hk_configs->ptr_hk_configs;
00508 ptr_config_node->next = NULL;
00509 ptr_config_node->keywords = NULL;
00510 }
00511 else
00512 {
00513
00514 for(ptr_config_node = p_apid_ptr_hk_configs->ptr_hk_configs,
00515 previous_ptr_config_node = ptr_config_node;
00516 ptr_config_node;
00517 previous_ptr_config_node = ptr_config_node,
00518 ptr_config_node = ptr_config_node->next)
00519 {
00520 ;
00521 }
00522
00523 ptr_config_node = malloc( sizeof(HK_Config_Files));
00524 previous_ptr_config_node->next = ptr_config_node;
00525 ptr_config_node->next = NULL;
00526 ptr_config_node->keywords = NULL;
00527 }
00528
00529 for(i=0, j=0, k=0; fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL; )
00530 {
00531 if (!strncmp(line, "#", 1))
00532 {
00533 continue;
00534 }
00535 else if (!strncmp(line, "KWD", 3))
00536 {
00537 strcpy( keyword_lines[i++], line);
00538 }
00539 else if (!strncmp(line, "DCON", 4))
00540 {
00541
00542 if(j >= MAX_NUM_DCON_LINES)
00543 {
00544 printkerr("WARNING: Maximum lines for array exceeded.\n"
00545 " Skipping saving DCON config data since array too small.\n"
00546 " Update define variable MAX_NUM_DCON_LINES. \n");
00547 }
00548 else
00549 {
00550 strncpy( dcon_lines[j++], line, MAXLINE_DCON_IN_FILE);
00551 }
00552 }
00553 else if (! strncmp(line, "ACON", 4))
00554 {
00555 if(k >= MAX_NUM_ACON_LINES)
00556 {
00557 printkerr("WARNING: Maximum lines for array exceeded.\n"
00558 " Skipping saving ACON config data since array too small.\n"
00559 " Update define variable MAX_NUM_ACON_LINES. \n");
00560 }
00561 else
00562 {
00563 strcpy( acon_lines[k++], line);
00564 }
00565 }
00566 else if (!strncmp(line, "FILE", 4))
00567 {
00568 sscanf(line," %*s %*s %s ", ptr_config_node->file_version_number);
00569 }
00570 else if (!strncmp(line, "APID", 4))
00571 {
00572
00573 if( strstr(line, "HMIKER") )
00574 {
00575
00576 sscanf( line,"%*s %s %d %s %s",
00577 ptr_config_node->apid_name,
00578 &(ptr_config_node->number_bytes_used),
00579 ptr_config_node->packet_id_type,
00580 ptr_config_node->date);
00581 }
00582 else if( strstr(line, "AIAKER") )
00583 {
00584
00585 sscanf( line,"%*s %s %d %s %s",
00586 ptr_config_node->apid_name,
00587 &(ptr_config_node->number_bytes_used),
00588 ptr_config_node->packet_id_type,
00589 ptr_config_node->date);
00590 }
00591 else if( strstr(line, "HMI") )
00592 {
00593
00594 sscanf( line,"%*s %s %d %s %s",
00595 ptr_config_node->apid_name,
00596 &(ptr_config_node->number_bytes_used),
00597 ptr_config_node->packet_id_type,
00598 ptr_config_node->date);
00599 }
00600 else if( strstr(line, "AIA") )
00601 {
00602
00603 sscanf( line,"%*s %s %d %s %s",
00604 ptr_config_node->apid_name,
00605 &(ptr_config_node->number_bytes_used),
00606 ptr_config_node->packet_id_type,
00607 ptr_config_node->date);
00608 }
00609 else if( strstr(line, "SDO") )
00610 {
00611
00612 sscanf( line,"%*s %s %d %*s %s",
00613 ptr_config_node->apid_name,
00614 &(ptr_config_node->number_bytes_used),
00615 ptr_config_node->date);
00616
00617 strcpy(ptr_config_node->packet_id_type,"SDO");
00618 sscanf( line,"%*s %x", &(ptr_config_node->apid_number));
00619 }
00620 else if( strstr(line, "SSIM") )
00621 {
00622
00623 sscanf( line,"%*s %5s %d %*s %s",
00624 ptr_config_node->apid_name,
00625 &(ptr_config_node->number_bytes_used),
00626 ptr_config_node->date);
00627
00628 strcpy(ptr_config_node->packet_id_type,"HMI");
00629 }
00630 else
00631 {
00632
00633
00634 sscanf( line,"%*s %x %d %s",
00635 &(ptr_config_node->apid_number),
00636 &(ptr_config_node->number_bytes_used),
00637 ptr_config_node->date);
00638
00639
00640 strcpy(ptr_config_node->packet_id_type,"HMI");
00641 printkerr("WARNING: Could not find line valid value in APID line in apid-#-version-# file. "
00642 "Got line:<%s> so default setting to instrument flag to HMI. Probably need to "
00643 "update make_hkpdf.pl script or rerun to fix older HK files.\n", line);
00644 }
00645 }
00646 else
00647 {
00648 printkerr("WARNING: Could not find line with this keyword in apid-#-version-# file. Possible bad data in STANFORD file.\n");
00649 printkerr("WARNING: Line tried to parse is < %s >\n", line);
00650 }
00651 }
00652
00653 strcpy(keyword_lines[i],"");
00654 strcpy(dcon_lines[j],"");
00655 strcpy(acon_lines[k],"");
00656
00657 err_status[0] = load_hdpf_keyword_lines(keyword_lines,i,ptr_config_node);
00658 err_status[1] = load_hdpf_dsc_lines(dcon_lines,j,ptr_config_node);
00659 err_status[2] = load_hdpf_alg_lines(acon_lines,k,ptr_config_node);
00660
00661
00662
00663
00664 for ( i=0; i < sizeof(err_status); i++)
00665 {
00666 if ( err_status[i] != ERROR_LOADING_HK_DATA )
00667 continue;
00668 else
00669 status= err_status[i];
00670 }
00671 return status;
00672 }
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682 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)
00683 {
00684
00685 Keyword_Parameter *keyword_node;
00686 int k=0;
00687
00688
00689 keyword_node= create_hdpf_keyword_nodes( ptr_hk_config_node, number_of_lines );
00690
00691 for(k=0; keyword_lines[k][0] != '\0';
00692 k++,keyword_node=keyword_node->next)
00693 {
00694 sscanf(keyword_lines[k]," %*s %s %s %d %d %d %s %c %*s",
00695 keyword_node->keyword_name,
00696 keyword_node->telemetry_mnemonic_name,
00697 &(keyword_node->start_byte),
00698 &(keyword_node->start_bit_number),
00699 &(keyword_node->bit_length),
00700 keyword_node->type,
00701 &keyword_node->conv_type);
00702 strcat(keyword_node->telemetry_mnemonic_name,"\0");
00703 strcat(keyword_node->keyword_name,"\0");
00704 keyword_node->dsc_ptr = (DSC_Conversion *)NULL;
00705 keyword_node->alg_ptr = (ALG_Conversion *)NULL;
00706 }
00707 return HK_SUCCESSFUL;
00708 }
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 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)
00719 {
00720
00721 DSC_Conversion *dsc_node;
00722 int i=0;
00723 char tlm_name[HK_MAX_TLM_NAME];
00724 Keyword_Parameter *kw;
00725
00726
00727
00728
00729
00730
00731 for ( kw= ptr_hk_config_node->keywords ; kw; kw=kw->next)
00732 {
00733
00734 if ( kw->conv_type == 'D')
00735 {
00736 kw->dsc_ptr=(DSC_Conversion*)NULL;
00737
00738 for (i=0; i < number_of_lines; i++)
00739 {
00740 sscanf ( dsc_lines[i], "%*s %s %*d %*d %*d %*d %*d %*d", tlm_name);
00741 strcat( tlm_name, "");
00742 strcat( tlm_name, "\0");
00743 if( !strcmp( kw->telemetry_mnemonic_name, tlm_name))
00744 {
00745
00746 dsc_node = create_hdpf_dsc_nodes( kw);
00747
00748 sscanf(dsc_lines[i]," %*s %*s %d %d %s %*s",
00749 &(dsc_node->low_range), &(dsc_node->high_range),
00750 dsc_node->dsc_value);
00751 dsc_node->next = NULL;
00752 }
00753 }
00754 }
00755 }
00756 return 0;
00757 }
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 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)
00770 {
00771
00772 ALG_Conversion *alg_node;
00773 int i, k;
00774 char tlm_name[HK_MAX_TLM_NAME];
00775 Keyword_Parameter *kw;
00776
00777
00778
00779
00780
00781
00782 for ( kw= ptr_hk_config_node->keywords ; kw; kw=kw->next)
00783 {
00784
00785 if ( kw->conv_type == 'A')
00786 {
00787
00788 for (i=0; i < number_of_lines; i++)
00789 {
00790
00791 sscanf ( alg_lines[i], "%*s %s %*d %*d %*d %*d %*d %*d %*d", tlm_name);
00792 strcat( tlm_name, "");
00793 if( !strncmp( kw->telemetry_mnemonic_name, tlm_name, sizeof(tlm_name)))
00794 {
00795
00796 kw->alg_ptr = (ALG_Conversion*)malloc (sizeof (ALG_Conversion));
00797 alg_node= kw->alg_ptr;
00798
00799
00800 k=0;
00801 sscanf(alg_lines[i]," %*s %*s %d %lf %lf %lf %lf %lf %lf %*s",
00802 &(alg_node->number_of_coeffs), &(alg_node->coeff[k++]),
00803 &(alg_node->coeff[k++]), &(alg_node->coeff[k++]),
00804 &(alg_node->coeff[k++]), &(alg_node->coeff[k++]), &(alg_node->coeff[k]) );
00805 if(alg_node->number_of_coeffs != 6 && alg_node->number_of_coeffs != 5)
00806 {
00807 printkerr("WARNING: Receive data value for number of coefficients that were not expected values "
00808 "which are <5 or 6>. If value larger then 6 then will exceed array allowed size. "
00809 "Number of coefficients got was:<%d> \n",alg_node->number_of_coeffs);
00810 }
00811 break;
00812 }
00813 }
00814 }
00815 }
00816 return HK_SUCCESSFUL;
00817 }
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 Keyword_Parameter* create_hdpf_keyword_nodes(HK_Config_Files *ptr_hk_config,
00829 int number_of_lines)
00830 {
00831
00832 Keyword_Parameter *p;
00833 int k;
00834
00835
00836 p = ptr_hk_config->keywords = NULL;
00837
00838 for( k=0; k<number_of_lines; k++)
00839 {
00840 if(ptr_hk_config->keywords == NULL)
00841 {
00842
00843 p = ptr_hk_config->keywords = malloc( sizeof(Keyword_Parameter) );
00844 }
00845 else
00846 {
00847
00848 p->next = malloc(sizeof(Keyword_Parameter ));
00849 p = p->next;
00850 }
00851 p->next = NULL;
00852 }
00853 return (ptr_hk_config->keywords);
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864 DSC_Conversion* create_hdpf_dsc_nodes(Keyword_Parameter *ptr_hk_keyword)
00865 {
00866
00867 DSC_Conversion *p;
00868
00869
00870 p = ptr_hk_keyword->dsc_ptr ;
00871
00872 if ( p == NULL)
00873 {
00874
00875 p = (DSC_Conversion *) malloc(sizeof(DSC_Conversion));
00876 ptr_hk_keyword->dsc_ptr= p;
00877 }
00878 else
00879 {
00880 while ( p->next != (DSC_Conversion *)(NULL))
00881 {
00882 p= p->next;
00883 }
00884
00885 p->next = (DSC_Conversion *) malloc (sizeof(DSC_Conversion));
00886 p=p->next;
00887 }
00888 p->next= NULL;
00889 return(p);
00890 }
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901 HK_Config_Files* check_packet_version_number( HK_Config_Files *ptr_to_configs,
00902 char *version_number )
00903 {
00904 while(ptr_to_configs != NULL )
00905 {
00906 #ifdef DEBUG_LOAD_HK_CONFIG_FILE
00907 printkerr("DEBUG:Message at %s, line %d: Packet Version Number looking for:<%s>\n", __FILE__, __LINE__,version_number);
00908 printkerr("DEBUG:Message at %s, line %d: Packet Version Number found in config structure:<%s>\n", __FILE__, __LINE__,ptr_to_configs->parameter_version_number);
00909 #endif
00910 if(!strcmp(ptr_to_configs->parameter_version_number, version_number))
00911 {
00912 break;
00913 }
00914 ptr_to_configs = ptr_to_configs->next;
00915 }
00916 return ptr_to_configs;
00917 }
00918
00919
00920
00921
00922
00923
00924
00925 HK_Config_Files* check_file_version_number( HK_Config_Files *ptr_to_configs,
00926 char *version_number )
00927 {
00928 while(ptr_to_configs != NULL )
00929 {
00930 if(!strcmp(ptr_to_configs->file_version_number, version_number))
00931 break;
00932 ptr_to_configs = ptr_to_configs->next;
00933 }
00934 return ptr_to_configs;
00935 }
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945 int check_free_configs_flag(void)
00946 {
00947
00948 int status;
00949 FILE *file_ptr;
00950 char *directory ;
00951 char *filename;
00952 char directory_filename[MAX_FILE_NAME];
00953
00954
00955 directory = getenv("HK_CONFIG_DIRECTORY");
00956 filename= getenv("HK_FREE_FLAG_FILE");
00957 if(filename == NULL)
00958 filename = "HK_FREE_CONFIG_FLAG_FILE";
00959 if(directory == NULL)
00960 directory = "../../tables/hk_config_file";
00961 sprintf(directory_filename, "%s/%s", directory, filename);
00962
00963 file_ptr = fopen(directory_filename, "r");
00964 if (file_ptr == NULL)
00965 {
00966 status =0;
00967 }
00968 else
00969 {
00970 status = 1;
00971 fclose(file_ptr);
00972 }
00973 return status;
00974 }
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 void deallocate_apid_ptr_hk_config_nodes(void)
00990 {
00991 extern APID_Pointer_HK_Configs *global_apid_configs;
00992 APID_Pointer_HK_Configs *tmp_apid_ptr_hk_configs;
00993 APID_Pointer_HK_Configs *prev_apid_ptr_hk_configs;
00994 HK_Config_Files *tmp_ptr_hk_configs;
00995 HK_Config_Files *prev_ptr_hk_configs;
00996 Keyword_Parameter *tmp_keyword_node;
00997 Keyword_Parameter *prev_keyword_node;
00998 DSC_Conversion *tmp_dsc_node;
00999 DSC_Conversion *prev_dsc_node;
01000 ALG_Conversion *tmp_alg_node;
01001
01002
01003 if (!( check_free_configs_flag()))
01004 {
01005
01006 return;
01007 }
01008
01009
01010 tmp_apid_ptr_hk_configs=global_apid_configs;
01011
01012
01013 for(prev_apid_ptr_hk_configs=tmp_apid_ptr_hk_configs;
01014 tmp_apid_ptr_hk_configs;
01015 prev_apid_ptr_hk_configs = tmp_apid_ptr_hk_configs )
01016 {
01017 for(prev_ptr_hk_configs=tmp_ptr_hk_configs=tmp_apid_ptr_hk_configs->ptr_hk_configs;
01018 tmp_ptr_hk_configs;
01019 prev_ptr_hk_configs =tmp_ptr_hk_configs)
01020 {
01021 for(prev_keyword_node=tmp_keyword_node=
01022 tmp_ptr_hk_configs->keywords;
01023 tmp_keyword_node;
01024 prev_keyword_node =tmp_keyword_node)
01025 {
01026
01027 for(prev_dsc_node=tmp_dsc_node=tmp_keyword_node->dsc_ptr;
01028 tmp_dsc_node; prev_dsc_node = tmp_dsc_node)
01029 {
01030 tmp_dsc_node= tmp_dsc_node->next;
01031 free( prev_dsc_node);
01032 }
01033
01034 tmp_alg_node=tmp_keyword_node->alg_ptr;
01035 if (tmp_keyword_node)
01036 {
01037 free( tmp_alg_node );
01038 }
01039 tmp_keyword_node=tmp_keyword_node->next;
01040 free(prev_keyword_node);
01041 }
01042 tmp_ptr_hk_configs =tmp_ptr_hk_configs->next;
01043 free(prev_ptr_hk_configs);
01044 }
01045 tmp_apid_ptr_hk_configs = tmp_apid_ptr_hk_configs->next ;
01046 free(prev_apid_ptr_hk_configs);
01047 }
01048
01049 global_apid_configs=NULL;
01050
01051 }
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061 GTCIDS_Version_Number * read_gtcids_hk_file()
01062 {
01063
01064 char *hk_gtcids_directory ;
01065 char *hk_gtcids_filename;
01066 char hk_gtcids_directory_filename[MAX_FILE_NAME];
01067 FILE *file_ptr;
01068 char line[MAXLINE_IN_FILE];
01069 GTCIDS_Version_Number *top_ptr_gtcids_vn;
01070 GTCIDS_Version_Number *ptr_gtcids_vn;
01071
01072
01073 hk_gtcids_directory = getenv("HK_CONFIG_DIRECTORY");
01074 hk_gtcids_filename= getenv("HK_GTCIDS_FILE");
01075 if(hk_gtcids_filename == NULL)
01076 hk_gtcids_filename = "gtcids.txt";
01077 if(hk_gtcids_directory == NULL)
01078 hk_gtcids_directory = "../../tables/hk_config_file";
01079 sprintf(hk_gtcids_directory_filename, "%s/%s", hk_gtcids_directory,
01080 hk_gtcids_filename);
01081
01082 file_ptr = fopen(hk_gtcids_directory_filename, "r");
01083 if(!file_ptr)
01084 {
01085 printkerr("ERROR:Couldn't open Ground To Code IDS file %s.\n",hk_gtcids_directory_filename);
01086 printkerr("Set the enviroment variables HK_CONFIG_DIRECTORY"
01087 " to point to config directory and HK_GTCIDS_FILE"
01088 " environment variable to point to the correct file name\n");
01089 return NULL;
01090 }
01091 top_ptr_gtcids_vn = NULL;
01092 while( fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL )
01093 {
01094 if(line[0] == '#')
01095 continue;
01096 else
01097 {
01098 if (top_ptr_gtcids_vn == NULL)
01099 {
01100 top_ptr_gtcids_vn = ptr_gtcids_vn = malloc(sizeof(GTCIDS_Version_Number));
01101 ptr_gtcids_vn->next = (GTCIDS_Version_Number*)NULL;
01102 }
01103 else
01104 {
01105 ptr_gtcids_vn->next = malloc(sizeof(GTCIDS_Version_Number));
01106 ptr_gtcids_vn = ptr_gtcids_vn->next;
01107 ptr_gtcids_vn->next = (GTCIDS_Version_Number*)NULL;
01108 }
01109 ptr_gtcids_vn->next= NULL;
01110
01111
01112
01113
01114
01115 sscanf( line,
01116 "%s %s |%*s | %s | %s | %s | %*s | %s | %*s",
01117 ptr_gtcids_vn->change_date,
01118 ptr_gtcids_vn->change_time,
01119 ptr_gtcids_vn->ker_id_version_number,
01120 ptr_gtcids_vn->hmi_id_version_number,
01121 ptr_gtcids_vn->aia_id_version_number,
01122 ptr_gtcids_vn->file_version_number);
01123 }
01124 }
01125 fclose(file_ptr);
01126
01127 global_gtcids_vn = top_ptr_gtcids_vn;
01128 return(top_ptr_gtcids_vn);
01129 }
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142 void load_gtcids_data( GTCIDS_Version_Number* top_ptr_gtcids_data,
01143 APID_Pointer_HK_Configs *top_apid_ptr_hk_configs)
01144 {
01145
01146 GTCIDS_Version_Number* tmp_ptr_gtcids_data;
01147 APID_Pointer_HK_Configs *tmp_apid_ptr_hk_configs;
01148 HK_Config_Files *tmp_ptr_hk_configs;
01149
01150
01151 tmp_ptr_gtcids_data= top_ptr_gtcids_data;
01152 tmp_apid_ptr_hk_configs= top_apid_ptr_hk_configs;
01153
01154
01155 for(tmp_apid_ptr_hk_configs = top_apid_ptr_hk_configs;
01156 tmp_apid_ptr_hk_configs ;
01157 tmp_apid_ptr_hk_configs= tmp_apid_ptr_hk_configs->next)
01158 {
01159 for( tmp_ptr_hk_configs = tmp_apid_ptr_hk_configs->ptr_hk_configs;
01160 tmp_ptr_hk_configs ;
01161 tmp_ptr_hk_configs= tmp_ptr_hk_configs->next)
01162 {
01163 for (tmp_ptr_gtcids_data=top_ptr_gtcids_data;tmp_ptr_gtcids_data ;
01164 tmp_ptr_gtcids_data=tmp_ptr_gtcids_data->next)
01165 {
01166 if( !strcmp(tmp_ptr_gtcids_data->file_version_number,
01167 tmp_ptr_hk_configs->file_version_number))
01168 {
01169 if(!strcmp(tmp_ptr_hk_configs->packet_id_type, HMI_ID_TYPE))
01170 {
01171 strcpy(tmp_ptr_hk_configs->parameter_version_number,
01172 tmp_ptr_gtcids_data->hmi_id_version_number);
01173 }
01174 else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, AIA_ID_TYPE))
01175 {
01176 strcpy(tmp_ptr_hk_configs->parameter_version_number,
01177 tmp_ptr_gtcids_data->aia_id_version_number);
01178 }
01179 else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, AIAKER_ID_TYPE))
01180 {
01181 strcpy(tmp_ptr_hk_configs->parameter_version_number,
01182 tmp_ptr_gtcids_data->ker_id_version_number);
01183 }
01184 else if(!strcmp(tmp_ptr_hk_configs->packet_id_type, HMIKER_ID_TYPE))
01185 {
01186 strcpy(tmp_ptr_hk_configs->parameter_version_number,
01187 tmp_ptr_gtcids_data->ker_id_version_number);
01188 }
01189 else
01190 {
01191 strcpy(tmp_ptr_hk_configs->parameter_version_number,
01192 tmp_ptr_gtcids_data->hmi_id_version_number);
01193 }
01194 break;
01195 }
01196 }
01197 }
01198 }
01199 }
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209 void deallocate_GTCIDS_Version_Number(void)
01210 {
01211
01212 GTCIDS_Version_Number *p,*tmp;
01213
01214
01215 p = global_gtcids_vn;
01216
01217 while(p)
01218 {
01219 tmp = p->next;
01220 free(p);
01221 p = tmp;
01222 }
01223 }
01224
01225
01226
01227
01228
01229
01230 void deallocate_SHCIDS_Version_Number(void)
01231 {
01232
01233 SHCIDS_Version_Number *p,*tmp;
01234
01235
01236 p = global_shcids_vn;
01237
01238 while(p)
01239 {
01240 tmp = p->next;
01241 free(p);
01242 p = tmp;
01243 }
01244 }
01245
01246
01247
01248
01249
01250
01251
01252
01253 void deallocate_apid_hkpfd_files_nodes(APID_HKPFD_Files *ptr)
01254 {
01255
01256 APID_HKPFD_Files *tmp;
01257
01258 while(ptr)
01259 {
01260 tmp = ptr->next;
01261 free(ptr);
01262 ptr = tmp;
01263 }
01264 return;
01265 }
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276 HK_Config_Files* reread_all_files(APID_Pointer_HK_Configs *apid_ptr_configs,
01277 char version_number[MAX_CHAR_VERSION_NUMBER], char pkt_date[MAX_SIZE_PKT_DATE])
01278 {
01279
01280 APID_HKPFD_Files *hkpfd_files;
01281 APID_HKPFD_Files *top_hkpfd_files;
01282 APID_Pointer_HK_Configs *p, *prev_p;
01283 GTCIDS_Version_Number *ptr_gtcids_data;
01284 SHCIDS_Version_Number *ptr_shcids_data;
01285 char file_version_number[50];
01286 char *ptr_fvn;
01287 int apid;
01288 int found_flag;
01289
01290
01291 ptr_fvn=file_version_number;
01292
01293
01294 apid= apid_ptr_configs->apid;
01295
01296
01297
01298 deallocate_GTCIDS_Version_Number();
01299 deallocate_SHCIDS_Version_Number();
01300 read_gtcids_hk_file();
01301 read_shcids_hk_file();
01302 ptr_gtcids_data = global_gtcids_vn;
01303 ptr_shcids_data = global_shcids_vn;
01304
01305 if(check_for_sdo_apid(apid))
01306 {
01307 ptr_fvn=find_fvn_from_shcids(ptr_shcids_data, pkt_date, apid);
01308 #ifdef DEBUG_LOAD_HK_CONFIG_FILE
01309 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);
01310 #endif
01311 }
01312 else
01313 {
01314
01315 ptr_fvn=find_file_version_number(ptr_gtcids_data, version_number, apid);
01316 #ifdef DEBUG_LOAD_HK_CONFIG_FILE
01317 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);
01318 #endif
01319 }
01320
01321
01322 if ((top_hkpfd_files = read_all_hk_config_files(apid,ptr_fvn,version_number)) == NULL)
01323 return (HK_Config_Files*)NULL;
01324
01325 for(hkpfd_files=top_hkpfd_files; hkpfd_files;
01326 hkpfd_files=hkpfd_files->next)
01327 {
01328 found_flag=0;
01329 for(p=global_apid_configs; p ; p=p->next)
01330 {
01331
01332 if (!strcmp(p->apid_name, hkpfd_files->apid_name))
01333 {
01334 found_flag=1;
01335 break;
01336 }
01337 prev_p=p;
01338 }
01339 if (!found_flag)
01340 {
01341
01342 prev_p->next = (APID_Pointer_HK_Configs *) malloc (sizeof (APID_Pointer_HK_Configs));
01343 prev_p->next->next= NULL;
01344 prev_p->next->ptr_hk_configs= (HK_Config_Files*) NULL;
01345
01346 strcpy(prev_p->next->apid_name, hkpfd_files->apid_name);
01347 }
01348 }
01349
01350 for(p=global_apid_configs; p ; p=p->next)
01351 {
01352 load_config_data(top_hkpfd_files, p);
01353 }
01354
01355 if (!check_for_sdo_apid(apid))
01356 {
01357
01358 p=global_apid_configs;
01359 load_gtcids_data(ptr_gtcids_data, p);
01360 }
01361
01362
01363 hkpfd_files=top_hkpfd_files;
01364 deallocate_apid_hkpfd_files_nodes(hkpfd_files) ;
01365
01366
01367 p = global_apid_configs;
01368 while (p)
01369 {
01370 if( p->apid == apid )
01371 {
01372 return p->ptr_hk_configs;
01373 }
01374 p = p->next;
01375 }
01376
01377 return (HK_Config_Files*)NULL;
01378 }
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388 char * find_file_version_number(GTCIDS_Version_Number *top, char p_version_number[MAX_CHAR_VERSION_NUMBER],int aid)
01389 {
01390
01391 GTCIDS_Version_Number *tmp_ptr;
01392
01393 for(tmp_ptr=top;tmp_ptr;tmp_ptr=tmp_ptr->next)
01394 {
01395
01396 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)
01397 {
01398 if( !strcmp(tmp_ptr->ker_id_version_number, p_version_number))
01399 {
01400 return tmp_ptr->file_version_number;
01401 }
01402 }
01403 else if ((aid >= HK_HSB_HMI_LRANGE && aid <= HK_HSB_HMI_HRANGE ) || (aid >= HK_LR_HMI_LRANGE && aid <= HK_LR_HMI_HRANGE))
01404 {
01405 if( !strcmp(tmp_ptr->hmi_id_version_number, p_version_number))
01406 {
01407 return tmp_ptr->file_version_number;
01408 }
01409 }
01410 else if ((aid >= HK_HSB_AIA_LRANGE && aid <= HK_HSB_AIA_HRANGE ) || (aid >= HK_LR_AIA_LRANGE && aid <= HK_LR_AIA_HRANGE))
01411 {
01412 if( !strcmp(tmp_ptr->aia_id_version_number, p_version_number))
01413 {
01414 return tmp_ptr->file_version_number;
01415 }
01416 }
01417 }
01418 return ("");
01419 }
01420
01421
01422
01423
01424
01425
01426
01427 SHCIDS_Version_Number * read_shcids_hk_file()
01428 {
01429
01430 char *hk_shcids_directory ;
01431 char *hk_shcids_filename;
01432 char hk_shcids_directory_filename[MAX_FILE_NAME];
01433 FILE *file_ptr;
01434 char line[MAXLINE_IN_FILE];
01435 SHCIDS_Version_Number *top_ptr_shcids_vn;
01436 SHCIDS_Version_Number *ptr_shcids_vn;
01437 char new_str[9];
01438
01439
01440 hk_shcids_directory = getenv("HK_SHCIDS_DIRECTORY");
01441 hk_shcids_filename= getenv("HK_SHCIDS_FILE");
01442 if(hk_shcids_filename == NULL)
01443 hk_shcids_filename = "shcids.txt";
01444 if(hk_shcids_directory == NULL)
01445 hk_shcids_directory = "/home/production/cvs/TBL_JSOC/lev0/hk_config_file/sdo_hk";
01446 sprintf(hk_shcids_directory_filename, "%s/%s", hk_shcids_directory,
01447 hk_shcids_filename);
01448
01449
01450 file_ptr = fopen(hk_shcids_directory_filename, "r");
01451 if(!file_ptr)
01452 {
01453 printkerr("ERROR:Couldn't open SDO HK Code IDS file %s.\n",hk_shcids_directory_filename);
01454 printkerr("Set the enviroment variables HK_SHCIDS_DIRECTORY"
01455 " to point to config directory and HK_SHCIDS_FILE"
01456 " environment variable to point to the correct file name\n");
01457 return NULL;
01458 }
01459 top_ptr_shcids_vn = NULL;
01460 while( fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL )
01461 {
01462 if(line[0] == '#')
01463 continue;
01464 else
01465 {
01466 if (top_ptr_shcids_vn == NULL)
01467 {
01468 top_ptr_shcids_vn = ptr_shcids_vn = malloc(sizeof(SHCIDS_Version_Number));
01469 ptr_shcids_vn->next = (SHCIDS_Version_Number*)NULL;
01470 }
01471 else
01472 {
01473 ptr_shcids_vn->next = malloc(sizeof(SHCIDS_Version_Number));
01474 ptr_shcids_vn = ptr_shcids_vn->next;
01475 ptr_shcids_vn->next = (SHCIDS_Version_Number*)NULL;
01476 }
01477 ptr_shcids_vn->next= NULL;
01478
01479
01480
01481 sscanf( line,
01482 "%s %s |%d |%s | %*s",
01483 ptr_shcids_vn->change_date,
01484 ptr_shcids_vn->change_time,
01485 &ptr_shcids_vn->apid,
01486 ptr_shcids_vn->file_version_number);
01487
01488
01489 for(int i=0; i < 9; new_str[i++]='\0');
01490 strncpy(new_str,ptr_shcids_vn->change_date,4);
01491 strncat(new_str,&ptr_shcids_vn->change_date[5],2);
01492 strncat(new_str,&ptr_shcids_vn->change_date[8],2);
01493 sscanf(new_str,"%d",&ptr_shcids_vn->date);
01494 }
01495 }
01496 fclose(file_ptr);
01497 global_shcids_vn = top_ptr_shcids_vn;
01498 return(top_ptr_shcids_vn);
01499 }
01500
01501
01502
01503
01504
01505
01506
01507 char * find_fvn_from_shcids(SHCIDS_Version_Number *top, char p_date[MAX_SIZE_PKT_DATE], int apid)
01508 {
01509
01510 SHCIDS_Version_Number *tmp_ptr;
01511 char new_str[9];
01512 char *saved_fvn;
01513 char saved_fvn_str[50];
01514 int current_date;
01515 int pkt_date;
01516 int saved_date;
01517 int saved_flg=0;
01518 saved_fvn=saved_fvn_str;
01519
01520
01521 for(int i=0; i < 9; new_str[i++]='\0');
01522 strncpy(new_str,p_date,4);
01523 strncat(new_str,&p_date[5],2);
01524 strncat(new_str,&p_date[8],2);
01525 sscanf(new_str,"%d",&pkt_date);
01526
01527
01528 for(tmp_ptr=top;tmp_ptr;tmp_ptr=tmp_ptr->next)
01529 {
01530 if(pkt_date >= tmp_ptr->date && tmp_ptr->apid == apid)
01531 {
01532 if(saved_flg)
01533 {
01534 current_date=tmp_ptr->date;
01535 if(current_date >= saved_date)
01536 {
01537
01538 saved_date=current_date;
01539 saved_fvn=tmp_ptr->file_version_number;
01540 }
01541 }
01542 else
01543 {
01544
01545 saved_date=tmp_ptr->date;
01546 saved_fvn=tmp_ptr->file_version_number;
01547 saved_flg=1;
01548 }
01549 }
01550 }
01551 if(saved_flg)
01552 {
01553 return ((char*)saved_fvn);
01554 }
01555 else
01556 {
01557
01558 strcpy(saved_fvn,"BAD PKT DATE");
01559 printkerr("ERROR at %s, line %d: Could not find date in shcids.txt file "
01560 "to look up file version to reference for config files. "
01561 "Problem Packet Date used was:<%s>. Probably bad data for timecodes\n",
01562 __FILE__,__LINE__,new_str);
01563 return ((char*)saved_fvn);
01564 }
01565 }
01566
01567
01568
01569
01570
01571 int check_for_sdo_apid(int apid)
01572 {
01573 if ((apid >= 96) && (apid <= 399))
01574 {
01575 return (1);
01576 }
01577 else
01578 {
01579 return (0);
01580 }
01581
01582 }
01583