int prod_retrans_get_addr( int channel_type, /* SBN channel type */ PROD_RETRANS_TABLE *prod_retrans_table, /* retrans table */ PROD_RETRANS_ENTRY_INFO **in_p_retrans_entry_info, /* retrans tab info */ PROD_RETRANS_ENTRY **in_p_retrans_entry, /* retrans table entry */ int *in_retrans_table_typ) /* retrans table type */ { static char FNAME[]="prod_retrans_get_addr"; int retrans_table_typ; /* retrans table typ */ PROD_RETRANS_ENTRY *p_retrans_entry; PROD_RETRANS_ENTRY_INFO *p_retrans_entry_info; if(prod_retrans_table == (PROD_RETRANS_TABLE *)NULL) { uerror("%s null prod_retrans_table ptr so give up\n", FNAME); return(ERROR); } if((retrans_table_typ = GET_RETRANS_TABLE_TYP(channel_type)) >= 0) { p_retrans_entry_info = &prod_retrans_table->entry_info[retrans_table_typ]; p_retrans_entry = (PROD_RETRANS_ENTRY *) (((long)&p_retrans_entry_info->retrans_entry_base_offset) + p_retrans_entry_info->retrans_entry_base_offset); } else { /* have invalid table type */ *in_p_retrans_entry_info = (PROD_RETRANS_ENTRY_INFO *)NULL; *in_p_retrans_entry = (PROD_RETRANS_ENTRY *)NULL; *in_retrans_table_typ = 0; /* so ignore lookup */ uerror("%s invalid channel_typ=%d tbl[%d] ignore\n", FNAME, channel_type, retrans_table_typ); return(ERROR); } *in_p_retrans_entry_info = p_retrans_entry_info; *in_p_retrans_entry = p_retrans_entry; *in_retrans_table_typ = retrans_table_typ; if(p_retrans_entry_info->numb_entries == 0) { /* assume have no entries */ uerror("%s OK prod_retrans_table entry_info=0x%x numb_entry=%d\n", FNAME, (unsigned long)*in_p_retrans_entry_info, p_retrans_entry_info->numb_entries); return(ERROR); } return(0); } /* end prod_retrans_get_addr routine */
/* init_retrans - Routine to initialize retransmission table */ int init_retrans(PROD_RETRANS_TABLE **pp_prod_retrans_table) { static char FNAME[] = "init_retrans"; long int entry_base; /* base of entry */ long int ii,iii; /* loop counter */ int flags, rtn_val; static const char *utc_time = "UTC"; /* Pointer to prod_retrans table */ PROD_RETRANS_ENTRY *p_retrans_entry; PROD_RETRANS_ENTRY_INFO *p_retrans_entry_info; /* pointer to prod_retrans_table */ PROD_RETRANS_TABLE *pl_prod_retrans_table; pl_prod_retrans_table = *pp_prod_retrans_table; log_debug("%s Begin init retrans_table base=0x%x\n", FNAME, pl_prod_retrans_table); global_time_zone = (char *) utc_time; if (pl_prod_retrans_table != NULL){ /* IMPORTANT, special init for local prod_retrans_table */ /* Assume entries directly follow the entry info for all links */ /* and each is variable size */ /* IMPORTANT, these must be initialized in order of their index value */ /* ie, GOES_EAST(0), NMC2(1), NMC(2), NOAAPORT_OPT(3), NMC3(4), NMC1(5) */ /* note NMC2 was GOES_WEST */ /* as per RETRANS_TBL_TYP_xxxxxxx */ entry_base = (long)pl_prod_retrans_table + sizeof(PROD_RETRANS_TABLE); ii = 0; /* For now set to 0; Later can setup retrans table depending on the channel type */ pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. numb_entries = GET_RETRANS_CHANNEL_ENTRIES(sbn_type); log_debug("%s Total retrans numb_entries for channel %s of sbn_type (%d) = %d \n", FNAME, sbn_channel_name,sbn_type,pl_prod_retrans_table->entry_info[ii].numb_entries); pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. retrans_entry_base_offset = (long)entry_base - (long)(&pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. retrans_entry_base_offset); entry_base += (long) (pl_prod_retrans_table->entry_info[GET_RETRANS_TABLE_TYP(sbn_type)]. numb_entries * (sizeof(PROD_RETRANS_ENTRY))); /*ii = GET_RETRANS_TABLE_TYP(sbn_type);*/ p_prod_retrans_table->entry_info[ii].entry_bytes = sizeof(PROD_RETRANS_ENTRY); pl_prod_retrans_table->entry_info[ii].index_last = 0; pl_prod_retrans_table->entry_info[ii].run_id_last = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_rcvd = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost_seqno = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost_abort = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_lost_other = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rcvd = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rcvd_lost = 0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rcvd_notlost=0; pl_prod_retrans_table->entry_info[ii].tot_prods_retrans_rqstd = 0; pl_prod_retrans_table->entry_info[ii].len_wmo_hdr_max = MAX_WMO_ENTRY_LEN; pl_prod_retrans_table->entry_info[ii].len_wmo_hdr_abbrev_max = MAX_RETRANS_LEN_WMO_HDR_ABBREV; pl_prod_retrans_table->entry_info[ii].last_wmo_hdr[0] = '\0'; pl_prod_retrans_table->entry_info[ii].last_wmo_loghdr_info[0] = '\0'; p_retrans_entry_info = &pl_prod_retrans_table->entry_info[ii]; p_retrans_entry = (PROD_RETRANS_ENTRY *)(((long)&p_retrans_entry_info-> retrans_entry_base_offset) + (long)p_retrans_entry_info->retrans_entry_base_offset); /* Now clear each entry */ for(iii=0; iii < pl_prod_retrans_table->entry_info[ii].numb_entries; iii++) { p_retrans_entry[iii].prod_arrive_time = (long) 0; p_retrans_entry[iii].prod_seqno = (long) 0; p_retrans_entry[iii].prod_run_id = 0; p_retrans_entry[iii].prod_type = 0; p_retrans_entry[iii].prod_cat = 0; p_retrans_entry[iii].prod_code = 0; p_retrans_entry[iii].prod_sub_code = 0; p_retrans_entry[iii].prod_status = 0; p_retrans_entry[iii].prod_err_cause = 0; p_retrans_entry[iii].prod_link_id = 0; p_retrans_entry[iii].entry_flag = 0; p_retrans_entry[iii].WMO_hdr_abbrev[0] = '\0'; } /* end for each numb entries */ log_debug("%s OK init retrans_table for channel [%s] numb_entries = %d\n",FNAME, sbn_channel_name,pl_prod_retrans_table->entry_info[ii].numb_entries); } /* end if pl_prod_retrans_table != NULL */ /*Open retransmit pipe */ if((global_retransmitpipe_fd = open(DEFAULT_RETRANSMIT_PIPENAME, O_RDWR,0)) <= 0){ log_error("Fail to open %s pipe errno=%d \n",DEFAULT_RETRANSMIT_PIPENAME,errno); perror("pipe open err"); return (-1); } if((flags = fcntl(global_retransmitpipe_fd, F_GETFL)) < 0){ log_error("Fail fcntl(F_GETFL) %s pipe\n",DEFAULT_RETRANSMIT_PIPENAME); /* Continue for now */ }else{ flags |= DONT_BLOCK; if((rtn_val = fcntl(global_retransmitpipe_fd, F_SETFL, flags)) < 0){ log_error("Fail fcntl(F_SETFL) %s pipe \n",DEFAULT_RETRANSMIT_PIPENAME); } log_notice(" OK open pipe[%d] for %s\n", global_retransmitpipe_fd,DEFAULT_RETRANSMIT_PIPENAME); } log_debug("%s Exiting init retrans_table base=0x%lx\n", FNAME,(unsigned long) pl_prod_retrans_table); return(0); } /* end init_retrans */