OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
unpack_packet_header.c
Go to the documentation of this file.
1 #include "PGS_IO.h"
2 #include "PGS_SMF.h"
3 #include "PGS_MODIS_35005.h"
4 #include "PH_pkt_hdr.h"
5 #include "L1A_prototype.h"
6 #include "packet_stats.h"
7 
8 
9 PGSt_SMF_status unpack_packet_header ( PGSt_IO_L0_Packet *pkt,
10  PH_PACKET_HEADER_t *packet_header )
11 
12 /*
13 !C********************************************************************************
14 
15 !Description: This function calls other routines to extract and validate
16  the packet's primary, secondary, and MODIS header.
17 
18 !Input Parameters:
19  PGSt_IO_L0_Packet *pkt ** The MODIS packet **
20 
21 !Output Parameters:
22  PH_PACKET_HEADER_t *packet_header ** Unpacked primary, secondary
23  and MODIS header **
24 
25 Return Values:
26  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
27  MODIS_E_INV_VERSION (PGS_MODIS_35005.h)
28  MODIS_E_INV_TYPE (PGS_MODIS_35005.h)
29  MODIS_E_INV_SEC_HDR_FLAG (PGS_MODIS_35005.h)
30  MODIS_E_INV_APID (PGS_MODIS_35005.h)
31  MODIS_E_INV_APID_TEST (PGS_MODIS_35005.h)
32  MODIS_E_INV_PKT_SEQ_FLAG (PGS_MODIS_35005.h)
33  MODIS_E_INV_PKTLEN (PGS_MODIS_35005.h)
34  MODIS_E_FAILED_TIMECODE_CONV (PGS_MODIS_35005.h)
35  MODIS_E_INV_QL_FLAG (PGS_MODIS_35005.h)
36  MODIS_E_INV_PKT_TYPE (PGS_MODIS_35005.h)
37  MODIS_E_EARTH_FR_CNT_EXC_LIM (PGS_MODIS_35005.h)
38  MODIS_E_CAL_FR_CNT_EXC_LIM (PGS_MODIS_35005.h)
39 
40 Externally Defined:
41  PGSt_IO_L0_Packet (PGS_IO.h)
42  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
43  PH_PRI_LONG_PKT_LENGTH (PH_pkt_hdr.h)
44  PH_PRI_PKT_LENGTH_BYTE_OFFSET (PH_pkt_hdr.h)
45  PH_PRI_SHORT_PKT_LENGTH (PH_pkt_hdr.h)
46  PH_SEC_PKT_TYPE_DAY_GROUP (PH_pkt_hdr.h)
47  PH_SEC_PKT_TYPE_ENG1_GROUP (PH_pkt_hdr.h)
48  PH_SEC_PKT_TYPE_ENG2_GROUP (PH_pkt_hdr.h)
49  PH_SEC_PKT_TYPE_NIGHT_GROUP (PH_pkt_hdr.h)
50 
51 Called By:
52  load_eng_data
53  process_a_packet
54 
55 Routines Called:
56  unpack_primary_header
57  unpack_secondary_header
58  unpack_MODIS_header
59 
60 !Revision History:
61  $Log: unpack_packet_header.c,v $
62  Revision 6.1 2010/08/25 19:10:41 kuyper
63  Changed to return MODIS_E_L1A for any failure detected in subroutines.
64  Changed from correcting packet lengths to be consistent with the packet type,
65  to marking the packet as invalid when they are inconsistent.
66  Added two other intra-packet consistency tests.
67  Added collection of packet filtering statistics.
68 
69  Revision 5.1 2005/10/21 16:12:15 kuyper
70  Changed to correct invalid packet lengths based upon the packet type.
71 
72  Revision 4.2 2002/12/03 20:47:54 vlin
73  Updated after code walk through.
74 
75  Revision 4.1 2002/10/16 16:10:21 vlin
76  call memcmp before calling memset.
77 
78  Revision 2.0 1997/07/15 16:07
79  Tom Johnson/SAIC/GSC (johnson@ltpmail.gsfc.nasa.gov)
80  Completely overhauled for Version 2
81 
82  Revision 1.0 1997/06/18 16:40 EDT
83  Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
84  Baseline from Version 1.
85 
86 !Team-unique Header:
87 
88  This software is developed by the MODIS Science Data Support Team
89  for the National Aeronautics and Space Administration,
90  Goddard Space Flight Center, under contract NAS5-32373.
91 
92 Design Notes:
93  The details for the packet header data locations were taken
94  from Hughes Santa Barbara Remote Sensing (SBRS) Contract Data
95  Requirements List (CDRL) 305, MODIS Engineering Telemetry
96  Description, Figures 3-7 and 30-8.
97 
98 
99 !END
100 *************************************************************************/
101 
102 {
103  int i;
104  PGSt_SMF_status returnStatus = MODIS_S_SUCCESS, tempStatus;
105  char *routine = "unpack_packet_header";
106  char msg[256];
107 
108  packet_header->fpa_aem_config[0] = -1;
109  memset(packet_header->fpa_aem_config+1, -1,
110  sizeof(packet_header->fpa_aem_config[0]));
111 
112  if (memcmp(packet_header->fpa_aem_config, packet_header->fpa_aem_config+1,
113  sizeof(packet_header->fpa_aem_config[0])) ) { /* memset didn't work */
115  packet_header->fpa_aem_config[i] = -1;
116  }
117  else
118  memset(packet_header->fpa_aem_config+2, -1,
119  sizeof(packet_header->fpa_aem_config));
120 
121  packet_header->version = -1;
122  packet_header->type = -1;
123  packet_header->sec_hdr_flag = -1;
124  packet_header->apid = -1;
125  packet_header->sequence_flag = -1;
126  packet_header->pkt_seq_cnt = -1;
127  packet_header->pkt_length = -1;
128  packet_header->pkt_TAI_time = -1.0;
129  packet_header->QL_flag = -1;
130  packet_header->pkt_type = -1;
131  packet_header->scan_cnt = -1;
132  packet_header->mirror_side = -1;
133  packet_header->source_ID_type_flag = -1;
134  packet_header->earth_frame_cnt = -1;
135  packet_header->cal_type = -1;
136  packet_header->cal_mode = -1;
137  packet_header->cal_frame_cnt = -1;
138  packet_header->sci_state = -1;
139  packet_header->sci_abnorm = -1;
140  memset(packet_header->pkt_time_code, '\0',
141  sizeof(packet_header->pkt_time_code));
142 
143  stats.packets++;
144  tempStatus = unpack_primary_header(pkt, packet_header);
145  if (tempStatus != MODIS_S_SUCCESS)
146  {
147  switch(tempStatus)
148  {
149  case MODIS_E_INV_VERSION: stats.version++; break;
150  case MODIS_E_INV_TYPE: stats.type++; break;
152  case MODIS_E_INV_APID: /*FALLTHROUGH*/
153  case MODIS_E_INV_APID_TEST: stats.apid++; break;
154  case MODIS_E_INV_PKT_SEQ_FLAG: stats.seq_flag++; break;
155  default:
156  log_fmt_msg(MODIS_E_L1A, routine,
157  "unpack_primary_header() returned %ld", (long)tempStatus);
158  }
159 
160  returnStatus = MODIS_E_L1A;
161  }
162 
163  tempStatus = unpack_secondary_header(pkt, packet_header);
164  if (tempStatus != MODIS_S_SUCCESS)
165  {
166  switch(tempStatus)
167  {
169  case MODIS_E_INV_QL_FLAG: stats.quick_look++; break;
170  case MODIS_E_INV_PKT_TYPE: stats.pkt_type++; break;
171  default:
172  log_fmt_msg(MODIS_E_L1A, routine,
173  "unpack_secondary_header() returned %ld", (long)tempStatus);
174  }
175  returnStatus = MODIS_E_L1A;
176  }
177 
178  if (returnStatus == MODIS_S_SUCCESS)
179  {
180  if(packet_header->pkt_length !=
181  (packet_header->pkt_type == PH_SEC_PKT_TYPE_NIGHT_GROUP
183  {
184 
185  sprintf(msg, "packet length value: %d Valid Values: long packet %d "
186  "short packet %d", packet_header->pkt_length,
189 
190  stats.length_type++;
191  returnStatus = MODIS_W_INV_PKTLEN;
192  }
193  else if(
195  != (packet_header->pkt_type == PH_SEC_PKT_TYPE_NIGHT_GROUP))
196  {
197  stats.seq_type++;
198  returnStatus = MODIS_E_INV_PKT_SEQ_FLAG;
199  }
200  }
201 
202  tempStatus = unpack_MODIS_header(pkt, packet_header);
203  if (tempStatus != MODIS_S_SUCCESS)
204  {
205  stats.frame_count++; /* Only failure mode is excess frame count. */
206  returnStatus = MODIS_E_L1A;
207  }
208 
209  if(returnStatus == MODIS_S_SUCCESS &&
211  && packet_header->pkt_type != PH_SEC_PKT_TYPE_DAY_GROUP)
212  {
213  stats.type_flag++;
214  returnStatus = MODIS_E_INV_SECTOR;
215  }
216 
217  return returnStatus;
218 }
219 
unsigned long length_type
Definition: packet_stats.h:58
#define PH_PRI_SHORT_PKT_LENGTH
Definition: PH_pkt_hdr.h:141
unsigned long version
Definition: packet_stats.h:47
#define MODIS_E_INV_PKT_SEQ_FLAG
unsigned long frame_count
Definition: packet_stats.h:60
#define MODIS_E_INV_SEC_HDR_FLAG
#define MODIS_E_FAILED_TIMECODE_CONV
PGSt_scTime pkt_time_code[8]
Definition: PH_pkt_hdr.h:250
#define MODIS_E_INV_TYPE
unsigned long quick_look
Definition: packet_stats.h:53
unsigned long time_tag
Definition: packet_stats.h:52
int8 fpa_aem_config[PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS]
Definition: PH_pkt_hdr.h:261
struct packet_stats stats
PGSt_SMF_status unpack_MODIS_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define MODIS_E_INV_APID_TEST
PGSt_SMF_status unpack_secondary_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
unsigned long type
Definition: packet_stats.h:48
unsigned long packets
Definition: packet_stats.h:45
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
PGSt_SMF_status unpack_packet_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define PH_SEC_PKT_TYPE_NIGHT_GROUP
Definition: PH_pkt_hdr.h:162
#define PH_MOD_SOURCE_ID_TYPE_FLAG_EARTH
Definition: PH_pkt_hdr.h:188
unsigned long apid
Definition: packet_stats.h:51
#define MODIS_E_INV_VERSION
PGSt_double pkt_TAI_time
Definition: PH_pkt_hdr.h:251
unsigned long sec_hdr_flag
Definition: packet_stats.h:50
#define PH_PRI_SEQUENCE_ONLY_PKT_IN_GROUP
Definition: PH_pkt_hdr.h:129
#define PH_SEC_PKT_TYPE_DAY_GROUP
Definition: PH_pkt_hdr.h:161
#define MODIS_E_INV_QL_FLAG
PGSt_SMF_status unpack_primary_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define MODIS_E_L1A
unsigned long seq_flag
Definition: packet_stats.h:49
#define MODIS_S_SUCCESS
#define MODIS_W_INV_PKTLEN
#define PH_MOD_FPA_AEM_CONFIG_NUM_ELEMENTS
Definition: PH_pkt_hdr.h:221
#define PH_PRI_LONG_PKT_LENGTH
Definition: PH_pkt_hdr.h:140
unsigned long type_flag
Definition: packet_stats.h:59
string msg
Definition: mapgen.py:227
#define MODIS_E_INV_PKT_TYPE
int i
Definition: decode_rs.h:71
unsigned long seq_type
Definition: packet_stats.h:57
unsigned long pkt_type
Definition: packet_stats.h:54
#define MODIS_E_INV_APID
#define MODIS_E_INV_SECTOR