| 1 | // This file is deprecated. I plan to make a new C++ decoder based on vdm.cc |
| 2 | // and to make C++ based TAG Block and USCG metadata handlers. |
| 3 | // |
| 4 | // Do not expect this file to build or really work. |
| 5 | |
| 6 | #include "ais.h" |
| 7 | |
| 8 | #include <fstream> |
| 9 | #include <iostream> |
| 10 | #include <cstring> |
| 11 | #include <sstream> |
| 12 | #include <string> |
| 13 | |
| 14 | using std::stringstream; |
| 15 | |
| 16 | // http://stackoverflow.com/questions/236129/c-how-to-split-a-string |
| 17 | vector<string> &split(const string &s, char delim, vector<string> &elems) { |
| 18 | stringstream ss(s); |
| 19 | string item; |
| 20 | while (std::getline(ss, item, delim)) { |
| 21 | elems.push_back(item); |
| 22 | } |
| 23 | return elems; |
| 24 | } |
| 25 | |
| 26 | vector<string> split(const string &s, char delim) { |
| 27 | vector<string> elems; |
| 28 | return split(s, delim, elems); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | int main(int argc, char* argv[]) { |
| 33 | assert(2 <= argc); |
| 34 | std::ifstream infile(argv[1]); |
| 35 | if (!infile.is_open()) { |
| 36 | std::cerr << "Unable to open file: " << argv[1] << std::endl; |
| 37 | exit(1); |
| 38 | } |
| 39 | |
| 40 | int i = 0; |
| 41 | string line; |
| 42 | while (!infile.eof()) { |
| 43 | i++; |
| 44 | getline(infile, line); // G++ problem with this and a string |
| 45 | if (line.size() < 20) {continue;} |
| 46 | if ('!' != line[0] || 'A' != line[1] ) {continue;} |
| 47 | string line_str(line); |
| 48 | vector<string> fields = split(line_str, ','); |
| 49 | { |
| 50 | if (fields.size() < 7) continue; |
| 51 | if (fields[5].size() < 5) continue; |
| 52 | if (fields[5][0] != '5') continue; |
| 53 | Ais5 m5(fields[5].c_str(), 2); |
| 54 | if (m5.had_error()) continue; |
| 55 | std::cout << m5.mmsi << "," << m5.name << "," << m5.callsign << "," |
| 56 | << m5.type_and_cargo << std::endl; |
| 57 | } |
| 58 | } |
| 59 | return 0; |
| 60 | } |