49 int main(
int argc,
char *argv[]) {
55 char *usage =
"Usage: %1$s [-v] [-q] [-x] datfile\n"
56 "\t-v\tIncrease verbosity\n"
57 "\t-q\tDecrease verbosity\n"
58 "\t-x\tInput file is in HXV format\n"
64 while ((go = getopt(argc, argv,
"vqx")) != -1) {
73 inputType = DW_TYPE_HXV;
76 log_error(&state,
"Unknown option `-%c'", optopt);
82 if (argc - optind != 1) {
88 fprintf(stderr, usage, argv[0]);
93 log_error(&state,
"File type must be specified");
97 char *inFileName = strdup(argv[optind]);
98 FILE *inFile = fopen(inFileName,
"rb");
100 log_error(&state,
"Unable to open input file");
101 if (inFileName) { free(inFileName); }
105 bool processing =
true;
108 size_t hw = fread(buf,
sizeof(
char),
BUFSIZE, inFile);
109 uint16_t cycdata[20] = {0};
110 uint8_t cycCount = 0;
112 bool sdset[16] = {0};
113 uint16_t sysdata[16] = {0};
115 while (processing || hw > 25) {
116 if (processing && (hw <
BUFSIZE)) {
117 ssize_t ret = fread(&(buf[hw]),
sizeof(
char),
BUFSIZE - hw, inFile);
118 if (ret < 1 || feof(inFile)) {
133 "[cyc] Signal: %d, Displacements - N: %+.2f\tW: %+.2f\tV: %+.2f\n",
139 bool syncFound =
false;
140 for (
int i = 0; i < cycCount; ++i) {
141 if (cycdata[i] == 0x7FFF) {
145 for (
int j = 0; j < cycCount && (j + i) < 20; ++j) {
146 cycdata[j] = cycdata[j + i];
148 cycCount = cycCount - i;
156 memset(cycdata, 0, 20 *
sizeof(cycdata[0]));
160 if (cycCount < 16) {
break; }
165 "Failed to extract spectrum data\n");
169 fprintf(stdout,
"[spe] System data word %d\n",
172 "[spe] #\tBin\tFreq\tDir.\tSpread\tM2\tN2\tRPSD\tK\n");
173 for (
int n = 0; n < 4; ++n) {
175 "[spe] %1d\t%02d\t%.3f\t%.2f\t%.2f\t%.3f\t%.3f\t%.3f\t%.3f\n",
179 ds.
rpsd[n], ds.
K[n]);
181 fprintf(stdout,
"\n");
185 for (
int i = 0; i < 16; ++i) {
198 fprintf(stderr,
"Failed to extract system data\n");
200 fprintf(stdout,
"[sys] Transmission number %d\n", dsys.
number);
201 fprintf(stdout,
"[sys] GPS position %s\n", dsys.
GPSfix ?
"OK" :
"old or invalid");
202 fprintf(stdout,
"[sys] RMS Height: %.3f, Fz: %.3f\n", dsys.
Hrms, dsys.
fzero);
203 fprintf(stdout,
"[sys] Ref. Temp: %.1f'C, Water Temp: %.1f'C\n", dsys.
refTemp, dsys.
waterTemp);
204 fprintf(stdout,
"[sys] Expected operational time remaining: %d weeks\n", dsys.
opTime);
205 fprintf(stdout,
"[sys] Accelerometer offsets: X: %.3f, Y: %.3f, Z: %.3f\n", dsys.
a_x_off, dsys.
a_y_off, dsys.
a_z_off);
220 "[sys] Position: %.6f%c %.6f%c, Orientation: %.3f, Inclination: %.3f\n",
221 latm * dsys.
lat, latc,
222 lonm * dsys.
lon, lonc,
224 fprintf(stdout,
"\n");
228 memset(&sysdata, 0, 16 *
sizeof(uint16_t));
229 memset(&sdset, 0, 16 *
sizeof(
bool));
232 cycdata[0] = cycdata[18];
233 cycdata[1] = cycdata[19];
234 memset(&(cycdata[2]), 0, 18 *
sizeof(uint16_t));
243 memmove(buf, &(buf[end]), hw - end);
int main(int argc, char *argv[])
#define BUFSIZE
Allocated buffer size.
int16_t dw_hxv_vertical(const dw_hxv *in)
Extract vertical displacement component from HXV input line.
int16_t dw_hxv_west(const dw_hxv *in)
Extract west displacement component from HXV input line.
bool dw_spectrum_from_array(const uint16_t *arr, dw_spectrum *out)
Populate dw_spectrum from array of cyclic data words.
int16_t dw_hxv_north(const dw_hxv *in)
Extract north displacement component from HXV input line.
dw_types
DW Data format types.
uint16_t dw_hxv_cycdat(const dw_hxv *in)
Extract cyclic data word from HXV input line.
bool dw_string_hxv(const char *in, size_t *end, dw_hxv *out)
Read a line of HXV data from string and convert.
bool dw_system_from_array(const uint16_t *arr, dw_system *out)
Extract system data from array of cyclic data words.
@ DW_TYPE_UNKNOWN
Default - type not known.
void destroy_program_state(program_state *s)
Cleanly destroy program state.
void log_error(const program_state *s, const char *format,...)
Output formatted error message.
Internal representation of a Datawell HXV message.
uint8_t status
Error count. 0 or 1 OK, 2+ error.
Internal representation of HXV spectral messages.
uint8_t frequencyBin[4]
Index for each line of spectral data.
float frequency[4]
Frequency represented by each line.
float m2[4]
M2 Fourier coefficient for each line.
uint16_t sysword
12 bits of system data
float rpsd[4]
Relative power spectral density for each line.
float K[4]
Check factor for each line.
uint8_t sysseq
System data sequence number.
float spread[4]
Wave spread for each line.
float direction[4]
Direction for each line.
float n2[4]
N2 Fourier coefficient for each line.
Internal representation of HXV system messages.
float a_z_off
Vertical accelerometer offset.
float fzero
Zero crossing frequency.
float Hrms
RMS Wave height.
bool GPSfix
Valid GPS fix available.
float waterTemp
Water Temperature.
float orient
Buoy orientation.
float a_x_off
X-axis accelerometer offset.
float refTemp
Reference Temperature.
int number
Sequence number.
float incl
Buoy inclination.
float a_y_off
Y-axis accelerometer offset.
int opTime
Weeks of battery life remaining.
Program state and logging information.
int verbose
Current log verbosity (console output)
#define GIT_VERSION_STRING
Git version description.