-
Notifications
You must be signed in to change notification settings - Fork 2
/
jsfmesgtype.c
202 lines (179 loc) · 3.68 KB
/
jsfmesgtype.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*************************************
*
*
* jsfmesgtype
*
* List the ET jsf file message types and number of occurances
* Reflects jsf format 0004824_REV_1.18
*
* Tom O'Brien
* USGS
* Woods Hole, MA
*
* September 11, 2017
*
*
*************************************/
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "jsf2.h"
int
main (int argc, char *argv[])
{ /* START MAIN */
int in_fd; /* file descriptor */
int JSFmsgSize;
int inbytes;
int msg;
int Sonar = 0;
int Sidescan = 0;
int Pitch = 0;
int NMEA = 0;
int Press = 0;
int Analog = 0;
int Doppler = 0;
int Situation = 0;
int SitII = 0;
int SAS = 0;
int S_info = 0;
int Cable = 0;
off_t offset; /* offset for seeking starting record */
off_t where;
unsigned char *JSFmsg;
JSFmsgSize = 16;
char *progname;
progname = argv[0];
if ((argc - optind) < 1)
usage ();
/*
* open the input jsf file
*/
if ((in_fd = open (argv[optind], O_RDONLY)) == -1)
{
fprintf (stderr, "%s: cannot open %s\n", argv[optind], progname);
perror ("open");
err_exit ();
}
/*
* Get some memory for JSF header
*/
JSFmsg =
(unsigned char *) calloc ((size_t) JSFmsgSize, sizeof (unsigned char));
if (JSFmsg == 0)
fprintf (stdout, "Error callocing\n");
while (1)
{
inbytes = read (in_fd, JSFmsg, (size_t) JSFmsgSize);
if (inbytes == ZERO)
{
fprintf (stdout, "End of File reached in input file\n");
if (Sonar)
fprintf (stdout, "Sonar = %d ", Sonar);
if (Sidescan)
fprintf (stdout, " Sidescan = %d ", Sidescan);
if (Pitch)
fprintf (stdout, " Pitch = %d ", Pitch);
if (NMEA)
fprintf (stdout, " NMEA = %d ", NMEA);
if (Press)
fprintf (stdout, " Pressure = %d ", Press);
if (Analog)
fprintf (stdout, " Analog = %d ", Analog);
if (Doppler)
fprintf (stdout, " Doppler = %d ", Doppler);
if (Situation)
fprintf (stdout, " Situation = %d ", Situation);
if (SAS)
fprintf (stdout, " SAS = %d ", SAS);
if (S_info)
fprintf (stdout, " S_info = %d ", S_info);
if (Cable)
fprintf (stdout, " Cable = %d ", Cable);
if (SitII)
fprintf (stdout, " DII Situation = %d ", SitII);
fprintf (stdout, "\n");
exit (EXIT_SUCCESS);
} // End if
if (inbytes != (int) JSFmsgSize)
{
fprintf (stderr, "%s: error reading JSF message header\n",
progname);
perror ("read");
err_exit ();
}
if (get_short (JSFmsg, 0) != 0x1601)
{
fprintf (stdout, "Invalid file format\n");
err_exit ();
}
msg = (int) get_short (JSFmsg, 4);
switch (msg)
{
case 80:
Sonar++;
break;
case 82:
Sidescan++;
break;
case 2020:
Pitch++;
break;
case 2002:
NMEA++;
break;
case 2060:
Press++;
break;
case 2040:
Analog++;
break;
case 2080:
Doppler++;
break;
case 2091:
Situation++;
break;
case 86:
SAS++;
break;
case 182:
S_info++;
break;
case 2100:
Cable++;
break;
case 9002:
SitII++;
break;
case '?':
err_exit ();
break;
} // End switch
/*
* Skip to next JSF Headeer
*/
offset = (off_t) get_int (JSFmsg, 12);
where = lseek (in_fd, offset, SEEK_CUR);
} // End while()
} // End Main()
void
err_exit (void)
{
fprintf (stdout, "An error occured \n");
exit (EXIT_FAILURE);
}
void
usage (void)
{
fprintf (stdout,
"jsfmesgtype ... Lists Edgetech JSF message types within a file\n");
fprintf (stdout, "Usage: jsfmesgtype full path to input file name\n");
exit (EXIT_FAILURE);
}