SELKIELogger  1.0.0
UBXMessagesFromFile.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <errno.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25 
26 #include "SELKIELoggerGPS.h"
27 
47 int main(int argc, char *argv[]) {
48  //LCOV_EXCL_START
49  if (argc < 2) {
50  fprintf(stderr, "Usage: %s <file>\n", argv[0]);
51  return -2;
52  }
53 
54  errno = 0;
55  FILE *testFile = fopen(argv[1], "r");
56  if ((testFile == NULL) || errno) {
57  fprintf(stderr, "Unable to open test file %s\n", argv[1]);
58  perror("open");
59  return -2;
60  }
61  //LCOV_EXCL_STOP
62 
63  int count = 0;
64  int exit = 0;
65  while (!(feof(testFile) || exit == 1)) {
66  ubx_message tmp;
67  if (ubx_readMessage(fileno(testFile), &tmp)) {
68  // Successfully read message
69  count++;
70  } else {
71  switch (tmp.sync1) {
72  //LCOV_EXCL_START
73  case 0xAA:
74  fclose(testFile);
75  return -2;
76  break;
77  case 0xEE:
78  fclose(testFile);
79  return -1;
80  break;
81  //LCOV_EXCL_STOP
82  case 0xFD:
83  exit = 1;
84  break;
85  case 0xFF:
86  default:
87  break;
88  }
89  }
90  }
91  fprintf(stdout, "%d messages read\n", count);
92  fclose(testFile);
93  return 0;
94 }
int main(int argc, char *argv[])
bool ubx_readMessage(int handle, ubx_message *out)
Static wrapper around ubx_readMessage_buf()
Definition: GPSSerial.c:125
Internal representation of a UBX message.
Definition: GPSTypes.h:80
uint8_t sync1
Should always be 0xB5.
Definition: GPSTypes.h:81