forked from schwehr/libais
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ais_decode_normed.cpp
68 lines (54 loc) · 1.77 KB
/
ais_decode_normed.cpp
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
#include "ais.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
//using namespace std;
#define UNUSED __attribute((__unused__))
// http://stackoverflow.com/questions/236129/c-how-to-split-a-string
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while(std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
return split(s, delim, elems);
}
//int main(UNUSED char *argc, UNUSED char* argv[]) {
int main( int argc, char* argv[]) {
build_nmea_lookup();
assert(2<=argc);
//std::string filename(argv[1]);
std::ifstream infile(argv[1]);
if (! infile.is_open() ) {
std::cerr << "Unable to open file: " << argv[1] << std::endl;
exit(1);
}
int i = 0;
std::string line;
//char line[1024];
while (!infile.eof()) {
i++;
getline(infile,line); // G++ problem with this and a string
//infile.getline(line,1024);
//if (strlen(line) < 20) {continue;}
if (line.size() < 20) {continue;}
if ('!' != line[0] || 'A' != line[1] ) {continue;}
std::string line_str(line);
std::vector<std::string> fields = split(line_str,',');
{
if (fields.size() < 7) continue;
if (fields[5].size() < 5) continue;
if (fields[5][0] != '5') continue;
Ais5 m5(fields[5].c_str());
if (m5.had_error()) continue;
std::cout << m5.mmsi << "," << m5.name << "," << m5.callsign << "," << m5.type_and_cargo << std::endl;
}
}
return 0;
}