OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
unpack_primary_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 
7 PGSt_SMF_status unpack_primary_header (PGSt_IO_L0_Packet *pkt,
8  PH_PACKET_HEADER_t *packet_header)
9 
10 /*
11 !C************************************************************************
12 
13 !Description: This function extracts the primary header information contained
14  in the MODIS packet and places each item into the appropriate
15  variable in the PH_PACKET_HEADER_t structure. It also validates each
16  item.
17 
18 !Input Parameters:
19  PGSt_IO_L0_Packet *pkt ** The MODIS packet **
20 
21 !Output Parameters:
22  PH_PACKET_HEADER_t *packet_header ** Pointer to structure that
23  contains unpacked contents
24  of the primary header, secondary
25  header, and MODIS header **
26 
27 Return Values:
28  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
29  MODIS_E_INV_VERSION (PGS_MODIS_35005.h)
30  MODIS_E_INV_TYPE (PGS_MODIS_35005.h)
31  MODIS_E_INV_SEC_HDR_FLAG (PGS_MODIS_35005.h)
32  MODIS_E_INV_APID (PGS_MODIS_35005.h)
33  MODIS_E_INV_APID_TEST (PGS_MODIS_35005.h)
34  MODIS_E_INV_PKT_SEQ_FLAG (PGS_MODIS_35005.h)
35 
36 Externally Defined:
37  PGSt_IO_L0_Packet (PGS_IO.h)
38  PGSt_SMF_status (PGS_SMF.h)
39  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
40  PH_PRI_VERSION_BYTE_OFFSET (PH_pkt_hdr.h)
41  PH_PRI_VERSION_BIT_OFFSET (PH_pkt_hdr.h)
42  PH_PRI_VERSION_NUM_BITS (PH_pkt_hdr.h)
43  PH_PRI_VERSION_VALUE (PH_pkt_hdr.h)
44  PH_PRI_TYPE_BYTE_OFFSET (PH_pkt_hdr.h)
45  PH_PRI_TYPE_BIT_OFFSET (PH_pkt_hdr.h)
46  PH_PRI_TYPE_NUM_BITS (PH_pkt_hdr.h)
47  PH_PRI_TYPE_VALUE (PH_pkt_hdr.h)
48  PH_PRI_SEC_HDR_FLAG_BYTE_OFFSET (PH_pkt_hdr.h)
49  PH_PRI_SEC_HDR_FLAG_BIT_OFFSET (PH_pkt_hdr.h)
50  PH_PRI_SEC_HDR_FLAG_NUM_BITS (PH_pkt_hdr.h)
51  PH_PRI_SEC_HDR_PRESENT (PH_pkt_hdr.h)
52  PH_PRI_APID_BYTE_OFFSET (PH_pkt_hdr.h)
53  PH_PRI_APID_BIT_OFFSET (PH_pkt_hdr.h)
54  PH_PRI_APID_NUM_BITS (PH_pkt_hdr.h)
55  PH_PRI_MIN_MODIS_APID_AM1 (PH_pkt_hdr.h)
56  PH_PRI_MAX_MODIS_APID_AM1 (PH_pkt_hdr.h)
57  PH_PRI_APID_TEST_PACKET (PH_pkt_hdr.h)
58  PH_PRI_SEQUENCE_FLAG_BYTE_OFFSET (PH_pkt_hdr.h)
59  PH_PRI_SEQUENCE_FLAG_BIT_OFFSET (PH_pkt_hdr.h)
60  PH_PRI_SEQUENCE_FLAG_NUM_BITS (PH_pkt_hdr.h)
61  PH_PRI_SEQUENCE_NOT_USED (PH_pkt_hdr.h)
62  PH_PRI_SOURCE_SEQ_CNT_BYTE_OFFSET (PH_pkt_hdr.h)
63  PH_PRI_SOURCE_SEQ_CNT_BIT_OFFSET (PH_pkt_hdr.h)
64  PH_PRI_SOURCE_SEQ_CNT_NUM_BITS (PH_pkt_hdr.h)
65  PH_PRI_PKT_LENGTH_BYTE_OFFSET (PH_pkt_hdr.h)
66  PH_PRI_PKT_LENGTH_BIT_OFFSET (PH_pkt_hdr.h)
67  PH_PRI_PKT_LENGTH_NUM_BITS (PH_pkt_hdr.h)
68 
69 Called By:
70  unpack_packet_header
71 
72 Routines Called:
73  extr_bits
74  log_fmt_msg
75 
76 !Revision History:
77  Revision 2.0 1997/07/14 12:30
78  Tom Johnson/SAIC/GSC (johnson@ltpmail.gsfc.nasa.gov)
79  Created from unpack_packet_header and validate_packet
80 
81  Revision 1.0 1997/06/18 16:40 EDT
82  Timi Adelekan/GSC (adelekan@ltpmail.gsfc.nasa.gov)
83  Baseline from Version 1.
84 
85 !Team-unique Header:
86  This software is developed by the MODIS Science
87  Data Support Team (SDST) for the National Aeronautics
88  and Space Administration (NASA), Goddard Space Flight
89  Center (GSFC), under contract NAS5-32373.
90 
91 !References and Credits:
92  None
93 
94 !Design Notes:
95  The details for the packet header data locations were taken
96  from Hughes Santa Barbara Remote Sensing (SBRS) Contract Data
97  Requirements List (CDRL) 305, MODIS Engineering Telemetry
98  Description, Figures 3-7 and 30-8.
99 
100 
101 !END************************************************************************
102 */
103 
104 
105 {
106  /***************************************************************************/
107  /* */
108  /* Declare and Initialize Local Variables */
109  /* */
110  /***************************************************************************/
111 
112  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
113  char *routine = "unpack_primary_header";
114  char msg[300];
115 
116 
117  /***************************************************************************/
118  /* */
119  /* Set returnStatus equal to MODIS_S_SUCCESS */
120  /* */
121  /* set routine to "unpack_primary_header" (done during declaration) */
122  /* */
123  /***************************************************************************/
124 
125  returnStatus = MODIS_S_SUCCESS;
126 
127 
128  /***************************************************************************/
129  /* */
130  /* CALL extr_bits to extract the version from the packet primary header */
131  /* INPUTS: PH_PRI_VERSION_BYTE_OFFSET, PH_PRI_VERSION_BIT_OFFSET, */
132  /* PH_PRI_VERSION_NUM_BITS, pkt */
133  /* OUTPUTS: None */
134  /* RETURN: PH_PACKET_HEADER_t.version */
135  /* */
136  /* IF PH_PACKET_HEADER_t.version is not equal to PH_PRI_VERSION_VALUE */
137  /* THEN */
138  /* set returnStatus equal to MODIS_E_INV_VERSION */
139  /* CALL log_fmt_msg to report that an invalid version value has been */
140  /* detected in the packet primary header */
141  /* INPUTS: returnStatus, routine, msg */
142  /* ENDIF */
143  /* */
144  /***************************************************************************/
145 
146  packet_header->version = extr_bits(pkt, PH_PRI_VERSION_BIT_OFFSET,
148 
149  if (packet_header->version != PH_PRI_VERSION_VALUE)
150  {
151  returnStatus = MODIS_E_INV_VERSION;
152  sprintf(msg, "version number from packet primary header: %d valid version number %d",
153  packet_header->version, PH_PRI_VERSION_VALUE);
155  }
156 
157 
158  /***************************************************************************/
159  /* */
160  /* CALL extr_bits to extract the type from the packet primary header */
161  /* INPUTS: PH_PRI_TYPE_BYTE_OFFSET, PH_PRI_TYPE_BIT_OFFSET, */
162  /* PH_PRI_TYPE_NUM_BITS, pkt */
163  /* OUTPUTS: None */
164  /* RETURN: PH_PACKET_HEADER_t.type */
165  /* */
166  /* IF PH_PACKET_HEADER_t.type is not equal to PH_PRI_TYPE_VALUE */
167  /* THEN */
168  /* set returnStatus equal to MODIS_E_INV_TYPE */
169  /* CALL log_fmt_msg to report that a test packet has been detected from*/
170  /* information in the type field of the packet primary header */
171  /* INPUTS: returnStatus, routine, msg */
172  /* ENDIF */
173  /* */
174  /***************************************************************************/
175 
176  packet_header->type = extr_bits(pkt, PH_PRI_TYPE_BIT_OFFSET,
178 
179  if (packet_header->type != PH_PRI_TYPE_VALUE)
180  {
181  returnStatus = MODIS_E_INV_TYPE;
182  sprintf(msg, "Type from primary header: %d Normal Type: 0 Test Packet: 1",
183  packet_header->type);
184  log_fmt_msg(MODIS_E_INV_TYPE, routine, msg);
185  }
186 
187 
188  /***************************************************************************/
189  /* */
190  /* CALL extr_bits to extract the secondary header flag from the packet */
191  /* primary header */
192  /* INPUTS: PH_PRI_SEC_HDR_FLAG_BYTE_OFFSET, */
193  /* PH_PRI_SEC_HDR_FLAG_BIT_OFFSET, */
194  /* PH_PRI_SEC_HDR_FLAG_NUM_BITS, pkt */
195  /* OUTPUTS: None */
196  /* RETURN: PH_PACKET_HEADER_t.sec_hdr_flag */
197  /* */
198  /* IF PH_PACKET_HEADER_t.sec_hdr_flag is not equal to */
199  /* PH_PRI_SEC_HDR_PRESENT */
200  /* THEN */
201  /* set returnStatus equal to MODIS_E_INV_SEC_HDR_FLAG */
202  /* CALL log_fmt_msg to report that an invalid secondary header flag */
203  /* value has been detected in the packet primary header */
204  /* INPUTS: returnStatus, routine, msg */
205  /* ENDIF */
206  /* */
207  /***************************************************************************/
208 
211 
212  if (packet_header->sec_hdr_flag != PH_PRI_SEC_HDR_PRESENT)
213  {
214  returnStatus = MODIS_E_INV_SEC_HDR_FLAG;
215  sprintf(msg, "Secondary Header Flag value: %d Normal Value: %d",
216  packet_header->sec_hdr_flag, PH_PRI_SEC_HDR_PRESENT);
218  }
219 
220 
221 
222  /***************************************************************************/
223  /* */
224  /* CALL extr_bits to extract the application process ID (APID) from the */
225  /* packet primary header */
226  /* INPUTS: pkt, PH_PRI_APID_BIT_OFFSET, PH_PRI_APID_BYTE_OFFSET, */
227  /* PH_PRI_APID_NUM_BITS */
228  /* OUTPUTS: None */
229  /* RETURN: PH_PACKET_HEADER_t.apid */
230  /* */
231  /* IF PH_PACKET_HEADER_t.apid is less than PH_PRI_MIN_MODIS_APID_AM1 OR */
232  /* greater than PH_PRI_MAX_MODIS_APID_AM1 */
233  /* THEN */
234  /* set returnStatus equal to MODIS_E_INV_APID */
235  /* CALL log_fmt_msg to report that an invalid APID value has been */
236  /* detected in the packet primary header */
237  /* INPUTS: returnStatus, routine, msg */
238  /* ELSE */
239  /* IF PH_PACKET_HEADER_t.apid is equal to PH_PRI_APID_TEST_PACKET */
240  /* THEN */
241  /* set returnStatus equal to MODIS_E_INV_APID_TEST */
242  /* set msg to "a test packet has been detected from information in */
243  /* the APID field of the packet primary header" */
244  /* CALL log_fmt_msg to report that a test packet has been detected */
245  /* from information in the APID field of the packet primary */
246  /* header */
247  /* INPUTS: returnStatus, routine, msg */
248  /* ENDIF */
249  /* ENDIF */
250  /* */
251  /***************************************************************************/
252 
253  packet_header->apid = extr_bits(pkt, PH_PRI_APID_BIT_OFFSET,
255 
256  if ((packet_header->apid < PH_PRI_MIN_MODIS_APID_AM1) ||
257  (packet_header->apid > PH_PRI_MAX_MODIS_APID_AM1))
258  {
259  returnStatus = MODIS_E_INV_APID;
260  sprintf(msg, "APID value: %d MODIS APID range 64-127", packet_header->apid);
261  log_fmt_msg(MODIS_E_INV_APID, routine, msg);
262  }
263  else
264  {
265  if (packet_header->apid == PH_PRI_APID_TEST_PACKET)
266  {
267  returnStatus = MODIS_E_INV_APID_TEST;
268  sprintf(msg, "APID Value: %d", packet_header->apid);
270  }
271  }
272 
273 
274  /***************************************************************************/
275  /* */
276  /* CALL extr_bits to extract the sequence flag from the packet primary */
277  /* header */
278  /* INPUTS: pkt, PH_PRI_SEQUENCE_FLAG_BIT_OFFSET, */
279  /* PH_PRI_SEQUENCE_FLAG_BYTE_OFFSET, */
280  /* PH_PRI_SEQUENCE_FLAG_NUM_BITS */
281  /* OUTPUTS: None */
282  /* RETURN: PH_PACKET_HEADER_t.sequence_flag */
283  /* */
284  /* IF PH_PACKET_HEADER_t.sequence_flag is equal to */
285  /* PH_PRI_SEQUENCE_NOT_USED */
286  /* THEN */
287  /* set returnStatus equal to MODIS_E_INV_SEQ_FLAG */
288  /* CALL log_fmt_msg to report that an invalid sequence flag value has */
289  /* been detected in the packet primary header */
290  /* INPUTS: returnStatus, routine, msg */
291  /* ENDIF */
292  /* */
293  /***************************************************************************/
294 
297 
298  if (packet_header->sequence_flag == PH_PRI_SEQUENCE_NOT_USED)
299  {
300  returnStatus = MODIS_E_INV_PKT_SEQ_FLAG;
301  sprintf(msg, "sequence flag value: %d", packet_header->sequence_flag);
303  }
304 
305 
306  /***************************************************************************/
307  /* */
308  /* CALL extr_bits to extract the source sequence count from the packet */
309  /* primary header */
310  /* INPUTS: pkt, PH_PRI_SOURCE_SEQ_CNT_BIT_OFFSET, */
311  /* PH_PRI_SOURCE_SEQ_CNT_BYTE_OFFSET, */
312  /* PH_PRI_SOURCE_SEQ_CNT_NUM_BITS, */
313  /* OUTPUTS: None */
314  /* RETURN: PH_PACKET_HEADER_t.pkt_seq_cnt */
315  /* */
316  /***************************************************************************/
317 
320 
321 
322 
323  /***************************************************************************/
324  /* */
325  /* CALL extr_bits to extract the packet length from the packet primary */
326  /* header */
327  /* INPUTS: pkt, PH_PRI_PKT_LENGTH_BIT_OFFSET, */
328  /* PH_PRI_PKT_LENGTH_BYTE_OFFSET, PH_PRI_PKT_LENGTH_NUM_BITS */
329  /* OUTPUTS: None */
330  /* RETURN: PH_PACKET_HEADER_t.pkt_length */
331  /* */
332  /***************************************************************************/
333 
334  packet_header->pkt_length = extr_bits(pkt, PH_PRI_PKT_LENGTH_BIT_OFFSET,
336 
337 
338  /***************************************************************************/
339  /* */
340  /* RETURN returnStatus */
341  /* */
342  /***************************************************************************/
343 
344  return (returnStatus);
345 
346 }
#define MODIS_E_INV_PKT_SEQ_FLAG
#define MODIS_E_INV_SEC_HDR_FLAG
#define PH_PRI_VERSION_BYTE_OFFSET
Definition: PH_pkt_hdr.h:102
#define PH_PRI_SEQUENCE_FLAG_BYTE_OFFSET
Definition: PH_pkt_hdr.h:124
#define PH_PRI_VERSION_BIT_OFFSET
Definition: PH_pkt_hdr.h:103
#define PH_PRI_SEC_HDR_FLAG_BIT_OFFSET
Definition: PH_pkt_hdr.h:113
#define MODIS_E_INV_TYPE
PGSt_SMF_status unpack_primary_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define PH_PRI_VERSION_NUM_BITS
Definition: PH_pkt_hdr.h:104
#define PH_PRI_SEQUENCE_FLAG_NUM_BITS
Definition: PH_pkt_hdr.h:126
#define PH_PRI_APID_TEST_PACKET
Definition: PH_pkt_hdr.h:122
#define PH_PRI_SEQUENCE_FLAG_BIT_OFFSET
Definition: PH_pkt_hdr.h:125
#define PH_PRI_PKT_LENGTH_NUM_BITS
Definition: PH_pkt_hdr.h:139
#define MODIS_E_INV_APID_TEST
#define PH_PRI_SEQUENCE_NOT_USED
Definition: PH_pkt_hdr.h:130
#define PH_PRI_TYPE_NUM_BITS
Definition: PH_pkt_hdr.h:109
#define PH_PRI_SEC_HDR_FLAG_BYTE_OFFSET
Definition: PH_pkt_hdr.h:112
#define PH_PRI_MIN_MODIS_APID_AM1
Definition: PH_pkt_hdr.h:120
#define PH_PRI_TYPE_VALUE
Definition: PH_pkt_hdr.h:110
#define PH_PRI_PKT_LENGTH_BIT_OFFSET
Definition: PH_pkt_hdr.h:138
#define PH_PRI_MAX_MODIS_APID_AM1
Definition: PH_pkt_hdr.h:121
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define PH_PRI_SOURCE_SEQ_CNT_NUM_BITS
Definition: PH_pkt_hdr.h:134
#define MODIS_E_INV_VERSION
#define PH_PRI_SOURCE_SEQ_CNT_BIT_OFFSET
Definition: PH_pkt_hdr.h:133
#define PH_PRI_APID_BYTE_OFFSET
Definition: PH_pkt_hdr.h:117
#define PH_PRI_SOURCE_SEQ_CNT_BYTE_OFFSET
Definition: PH_pkt_hdr.h:132
uint32 extr_bits(uint8 *a, int start_bit, int start_byte, int num_bits)
Definition: extr_bits.c:6
#define PH_PRI_PKT_LENGTH_BYTE_OFFSET
Definition: PH_pkt_hdr.h:137
#define PH_PRI_TYPE_BIT_OFFSET
Definition: PH_pkt_hdr.h:108
#define MODIS_S_SUCCESS
#define PH_PRI_SEC_HDR_FLAG_NUM_BITS
Definition: PH_pkt_hdr.h:114
#define PH_PRI_APID_BIT_OFFSET
Definition: PH_pkt_hdr.h:118
#define PH_PRI_TYPE_BYTE_OFFSET
Definition: PH_pkt_hdr.h:107
#define PH_PRI_APID_NUM_BITS
Definition: PH_pkt_hdr.h:119
#define PH_PRI_SEC_HDR_PRESENT
Definition: PH_pkt_hdr.h:115
string msg
Definition: mapgen.py:227
#define PH_PRI_VERSION_VALUE
Definition: PH_pkt_hdr.h:105
#define MODIS_E_INV_APID