OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
process_a_packet.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "PGS_IO_L0.h"
3 #include "PGS_IO.h"
4 #include "PGS_SMF.h"
5 #include "PGS_MODIS_35005.h"
6 #include "PH_pkt_hdr.h"
7 
8 static PGSt_SMF_status next_return;
9 static PH_PACKET_HEADER_t next_packet_header;
10 static PGSt_IO_L0_Packet next_pkt[PD_PKT_BUF_MAX];
11 static uint16 next_packet_cont[
14 static PGSt_PC_Logical next_packet_full = FALSE;
15 
16 
17 PGSt_SMF_status process_a_packet (
18  PGSt_IO_L0_VirtualDataSet *L0_file,
19  PGSt_IO_L0_Packet *pkt,
20  PH_PACKET_HEADER_t *packet_header,
21  uint16 *packet_cont
22 )
23 
24 /*
25 !C************************************************************************
26 
27 !Description: This function is a driver that calls all the functions
28  necessary to validate a packet and unpack its contents.
29 
30 !Input Parameters:
31  None
32 
33 !Output Parameters:
34  PH_PACKET_HEADER_t *packet_header ** L0 data packet header **
35  uint16 *packet_cont ** Unpacked data packet **
36 
37 !Input/Output Parameters:
38  PGSt_IO_L0_VirtualDataSet *L0_file ** L0 virtual data set **
39 
40 Return Values:
41  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
42  MODIS_W_NO_MORE_PACKETS (PGS_MODIS_35005.h)
43  MODIS_F_PKT_PROCESS_FAILED (PGS_MODIS-35005.h)
44  MODIS_E_INV_VERSION (PGS_MODIS_35005.h)
45  MODIS_E_INV_TYPE (PGS_MODIS_35005.h)
46  MODIS_E_INV_SEC_HDR_FLAG (PGS_MODIS_35005.h)
47  MODIS_E_INV_APID (PGS_MODIS_35005.h)
48  MODIS_E_INV_APID_TEST (PGS_MODIS_35005.h)
49  MODIS_E_INV_PKT_SEQ_FLAG (PGS_MODIS_35005.h)
50  MODIS_E_FAILED_TIMECODE_CONV (PGS_MODIS_35005.h)
51  MODIS_E_INV_QL_FLAG (PGS_MODIS_35005.h)
52  MODIS_E_INV_PKT_TYPE (PGS_MODIS_35005.h)
53  MODIS_E_EARTH_FR_CNT_EXC_LIM (PGS_MODIS_35005.h)
54  MODIS_E_CAL_FR_CNT_EXC_LIM (PGS_MODIS_35005.h)
55  MODIS_E_CHECKSUM_NOT_VALID (PGS_MODIS_35005.h)
56 
57 Externally Defined:
58  PGSt_SMF_status (PGS_SMF.h)
59  PGSt_IO_L0_Packet (PGS_IO.h)
60  PGSt_IO_L0_VirtualDataSet (PGS_IO.h)
61  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
62 
63 Called By:
64  process_a_scan
65  process_next_packet
66 
67 Routines Called:
68  read_a_packet
69  unpack_packet_header
70  unpack_packet_contents
71  check_checksum
72 
73 !Revision History:
74 $Log: process_a_packet.c,v $
75 Revision 5.1 2005/10/21 21:38:52 kuyper
76 No longer has return value indicating an invalid packet length.
77 
78 Revision 4.1 2003/05/09 19:44:57 kuyper
79 Corrected process_a_packet() to copy over the packet and it's contents.
80 Change process_next_packet() to update an externally provided pointer, rather
81  than copying the data it points at.
82 
83 James Kuyper Jr. (kuyper@saicmodis.com)
84 
85 Revision 4.0 2002/11/13 15:43:23 vlin
86 Updated according to process_next_packet.pdl revision 3.2
87 
88 Revision 1.5 2001/11/20 17:01:41 seaton
89 Bit Flip Bug Fixes.
90 
91 Revision 1.4 2001/04/13 18:09:20 seaton
92 Changed raw_mir_enc to type uint16 and fixed numerous prologs.
93 
94 Revision 1.3 2000/10/03 15:27:01 seaton
95 Split Scan fix
96 
97 Revision 2.2 2000/06/30
98 John Seaton GSC (seaton@ltpmail.gsfc.nasa.gov)
99 Code to fix split scan bug. DDTS MODx101733
100 
101 !Team-unique Header:
102  This software is developed by the MODIS Science Data Support Team
103  for the National Aeronautics and Space Administration,
104  Goddard Space Flight Center, under contract NAS5-32373.
105 
106 References and Credits: None
107 
108 Design Notes:
109  The details for the packet data locations were taken from Santa Barbara
110  Remote Sensing (SBRS) Contract Data Requirement List (CDRL)305, MODIS
111  Engineering Telemetry Description, Tables T30-5A, T30-5B, T30-5C,
112  T30-5D, and T30-5E.
113 !END*************************************************************************
114 */
115 {
116  PGSt_SMF_status returnStatus; /* SMF-style message returned by function */
117 
118  if (next_packet_full)
119  {
120  memcpy(pkt, next_pkt, sizeof(next_pkt));
121  *packet_header = next_packet_header;
122  memcpy(packet_cont, next_packet_cont, sizeof(next_packet_cont));
123  next_packet_full = FALSE;
124  return next_return;
125  }
126 
127  if( (returnStatus = read_a_packet (L0_file, pkt)) == MODIS_S_SUCCESS &&
128  (returnStatus = unpack_packet_header (pkt, packet_header))
129  == MODIS_S_SUCCESS )
130  {
131  unpack_packet_contents (pkt, packet_header, packet_cont);
132  returnStatus = check_checksum (*packet_header, packet_cont);
133  }
134 
135  return returnStatus;
136 }
137 
138 /*===========================================================================*/
139 
140 PGSt_SMF_status process_next_packet(
141  PGSt_IO_L0_VirtualDataSet *L0_file,
142  PH_PACKET_HEADER_t **packet_header
143 )
144 
145 /*****************************************************************************
146 !C
147 
148 !Description: 'Peeks' at next packet available in the L0_file while
149  leaving it in line to be read by process_a_packet.
150 
151 !Input Parameters:
152  PGSt_IO_L0_VirtualDataSet L0_file L0 virtual data set
153 
154 !Output Parameters:
155  PH_PACKET_HEADER_t packet_header L0 data packet header
156 
157 Return Values:
158  MODIS_E_CAL_FR_CNT_EXC_LIM
159  MODIS_E_CHECKSUM_NOT_VALID
160  MODIS_E_EARTH_FR_CNT_EXC_LIM
161  MODIS_E_FAILED_TIMECODE_CONV
162  MODIS_E_INV_APID
163  MODIS_E_INV_APID_TEST
164  MODIS_E_INV_PKT_SEQ_FLAG
165  MODIS_E_INV_PKT_TYPE
166  MODIS_E_INV_QL_FLAG
167  MODIS_E_INV_SEC_HDR_FLAG
168  MODIS_E_INV_TYPE
169  MODIS_F_PKT_PROCESS_FAILED
170  MODIS_E_INV_VERSION
171  MODIS_S_SUCCESS
172  MODIS_W_CANT_PKT_PEEK
173  MODIS_W_NO_MORE_PACKETS
174 
175 Externally Defined:
176  MODIS_E_CAL_FR_CNT_EXC_LIM (PGS_MODIS_35005.h)
177  MODIS_E_CHECKSUM_NOT_VALID (PGS_MODIS_35005.h)
178  MODIS_E_EARTH_FR_CNT_EXC_LIM (PGS_MODIS_35005.h)
179  MODIS_E_FAILED_TIMECODE_CONV (PGS_MODIS_35005.h)
180  MODIS_E_INV_APID (PGS_MODIS_35005.h)
181  MODIS_E_INV_APID_TEST (PGS_MODIS_35005.h)
182  MODIS_E_INV_PKT_SEQ_FLAG (PGS_MODIS_35005.h)
183  MODIS_E_INV_PKT_TYPE (PGS_MODIS_35005.h)
184  MODIS_E_INV_QL_FLAG (PGS_MODIS_35005.h)
185  MODIS_E_INV_SEC_HDR_FLAG (PGS_MODIS_35005.h)
186  MODIS_E_INV_TYPE (PGS_MODIS_35005.h)
187  MODIS_E_INV_VERSION (PGS_MODIS_35005.h)
188  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
189  MODIS_F_PKT_PROCESS_FAILED (PGS_MODIS_35005.h)
190  MODIS_W_CANT_PKT_PEEK (PGS_MODIS_35005.h)
191  MODIS_W_NO_MORE_PACKETS (PGS_MODIS_35005.h)
192  PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT (PD_pkt_data.h)
193  PGSt_IO_L0_Packet (PGS_IO.h)
194  PGSt_IO_L0_VirtualDataSet (PGS_IO.h)
195  PGSt_PC_Logical (PGS_PC.h)
196  PGSt_SMF_status (PGS_SMF.h)
197  PH_PACKET_HEADER_t (PH_pkt_hdr.h)
198  PH_NUM_12BIT_WORDS_IN_HEADER (PH_pkt_hder.h)
199  TRUE (hdf.h)
200  uint8 (hdfi.h)
201 
202  File scope variables shared only with process_a_packet:
203  PGSt_SMF_status next_return
204  PGSt_IO_L0_Packet next_pkt[PD_PKT_BUF_MAX]
205  PH_PACKET_HEADER_t next_packet_header
206  uint16 next_packet_cont[PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT
207  + PH_NUM_12BIT_WORDS_IN_HEADER + 1]
208  PGSt_PC_Logical next_packet_full initialized to FALSE
209 
210 Called By:
211  packet_of_scan
212 
213 Routines Called:
214  process_a_packet
215 
216 !Revision History:
217  Please see prologue in "process_a_packet()"
218 
219 !Team-unique Header:
220 
221  This software is developed by the MODIS Science Data Support Team
222  for the National Aeronautics and Space Administration,
223  Goddard Space Flight Center, under contract NAS5-32373.
224 
225 References and Credits: None
226 
227 Design Notes:
228  Issue: Globals modified by subroutines of process_a_packet
229  (like incrementing global packet counters) could cause
230  unintended side-effects from calling this routine.
231 
232 !END
233 ******************************************************************************/
234 
235 {
236  if (next_packet_full)
237  return MODIS_E_CANT_PKT_PEEK;
238  else
239  {
240  next_return = process_a_packet(L0_file, next_pkt, &next_packet_header,
241  next_packet_cont);
242  *packet_header = &next_packet_header;
243  next_packet_full = TRUE;
244 
245  return next_return;
246  }
247 }
#define PD_NUM_ELMTS_IN_DATA_FIELD_DAY_PKT
Definition: PD_pkt_data.h:79
PGSt_SMF_status read_a_packet(PGSt_IO_L0_VirtualDataSet *L0_file, PGSt_IO_L0_Packet *pkt)
Definition: read_a_packet.c:9
void unpack_packet_contents(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *pkt_header, uint16 *pkt_contents)
#define FALSE
Definition: rice.h:164
PGSt_SMF_status unpack_packet_header(PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header)
#define TRUE
Definition: rice.h:165
#define MODIS_E_CANT_PKT_PEEK
PGSt_SMF_status process_next_packet(PGSt_IO_L0_VirtualDataSet *L0_file, PH_PACKET_HEADER_t **packet_header)
PGSt_SMF_status process_a_packet(PGSt_IO_L0_VirtualDataSet *L0_file, PGSt_IO_L0_Packet *pkt, PH_PACKET_HEADER_t *packet_header, uint16 *packet_cont)
#define PH_NUM_12BIT_WORDS_IN_HEADER
Definition: PH_pkt_hdr.h:78
PGSt_SMF_status check_checksum(PH_PACKET_HEADER_t pkt_header, uint16 *pkt_contents)
Definition: check_checksum.c:9
#define MODIS_S_SUCCESS
#define PD_PKT_BUF_MAX
Definition: PD_pkt_data.h:69