Skip to content
This repository
tree: be45545373
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 53 lines (43 sloc) 1.441 kb
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
#include "ais.h"

#include <iostream>
#include <bitset>
//#include <string>
#include <cassert>
//#include <vector>
//using namespace std;

Ais7_13::Ais7_13(const char *nmea_payload) {
    init();

    assert (nmea_payload);
    const size_t num_bits = strlen(nmea_payload) * 6;
    //cout << "num_bits: " << num_bits << endl;

    if (! ((40+32*1)==num_bits or (40+32*2)==num_bits or (40+32*3)==num_bits or (40+32*4)==num_bits) ){
        status = AIS_ERR_BAD_BIT_COUNT;
        return;
    }

    std::bitset<168> bs;
    status = aivdm_to_bits(bs, nmea_payload);
    if (had_error()) return;

    message_id = ubits(bs, 0, 6);
    if (message_id != 7 and message_id != 13) {
        status = AIS_ERR_WRONG_MSG_TYPE;
        return;
    }
    repeat_indicator = ubits(bs,6,2);
    mmsi = ubits(bs,8,30);
    spare = ubits(bs,38,2);

    const size_t num_acks = (num_bits - 40) / 32;
    for (size_t i=0; i < num_acks; i++) {
        dest_mmsi.push_back(ubits(bs,40+i*32,30));
        seq_num.push_back(ubits(bs,40+i*32+30,2));
    }
}

void
Ais7_13::print() {
    std::cout << message_id << ( (7==message_id)?" ABM Ack":" safety ack" ) << "\n"
              << "\tmmsi: " << mmsi << " repeat: " << repeat_indicator << "\n";
    std::cout << "\tspare: " << spare << "\n";
    for (size_t i=0; i < dest_mmsi.size(); i++) {
        std::cout << "\tack: " << dest_mmsi[i] << " seq: " << seq_num[i] << "\n";
    }

    std::cout << std::endl;
}
Something went wrong with that request. Please try again.