Skip to content

Commit

Permalink
starting on message 8s
Browse files Browse the repository at this point in the history
git-svn-id: https://cowfish.unh.edu/projects/schwehr/trunk/src/libais@13738 a19cddd1-5311-0410-bb07-9ca93daf0f0b
  • Loading branch information
schwehr committed May 20, 2010
1 parent b43687d commit 9a2558c
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -19,6 +19,8 @@ CXXFLAGS += -Werror
SRCS := ais.cpp
SRCS += ais1_2_3.cpp ais4_11.cpp ais5.cpp ais7_13.cpp
#
SRCS += ais8.cpp
#
SRCS += ais9.cpp ais10.cpp ais12.cpp
SRCS += ais14.cpp
#
Expand Down
65 changes: 65 additions & 0 deletions ais.h
Expand Up @@ -189,6 +189,71 @@ class Ais7_13 : public AisMsg {

std::ostream& operator<< (std::ostream& o, Ais7_13 const& msg);

// 366 34 - Kurt older whale message 2008-2010

// AIS Binary Broadcast message ... parent to many
class Ais8 : public AisMsg {
private:
static const int MAX_BITS = 1008;
public:
int message_id;
int repeat_indicator;
int mmsi; // source ID
int spare;
int dac; // dac+fi = app id
int fi;

std::vector<unsigned char> payload; // If dac/fi (app id is now one we know). without dac/fi

Ais8(const char *nmea_payload);
bool decode_header8(const std::bitset<MAX_BITS> &bs);
void print();
};
std::ostream& operator<< (std::ostream& o, Ais8 const& msg);

// IMO met hydro
class Ais8_1_11 : public Ais8 {
public:
float x, y;
int day;
int hour;
int minute;
int ave_wind; // kts
int wind_gust; // kts
int wind_dir;
int wind_gust_dir;
float air_temp; // C
int rel_humid;
float dew_point;
float air_pres;
int air_pres_trend;
float horz_vis; // NM
float water_level; // m
int water_level_trend;
float surf_cur_speed;
int surf_cur_dir;
float cur_speed_2; // kts
int cur_dir_2;
int cur_depth_2; // m
float cur_speed_3; // kts
int cur_dir_3;
int cur_depth_3; // m
float wave_height; // ,
int wave_period;
int wave_dir;
float swell_height;
int swell_period;
int swell_dir;
int sea_state; // beaufort scale
int precip_type;
float salinity;
int ice; // yes/no/undef/unknown
int extended_water_level; //spare; // OHMEX uses this for extra water level precision

Ais8_1_11(const char *nmea_payload);
void print();
}


class Ais9 : public AisMsg {
public:
Expand Down
59 changes: 59 additions & 0 deletions ais8.cpp
@@ -0,0 +1,59 @@
// Since 2010-05-19
// Binary Broadcast Message (BBM) - 8

#include "ais.h"

Ais8::Ais8(const char *nmea_payload) {
assert(nmea_payload);
init();
const int payload_len = strlen(nmea_payload)*6 - 46; // in bits w/o DAC/FI
std::cout << "payload_len: " << strlen(nmea_payload) << " " << strlen(nmea_payload)*6 << " " << payload_len << " " << payload_len / 8 << "\n";
if (payload_len < 0 or payload_len > 952) {
status = AIS_ERR_BAD_BIT_COUNT;
return;
}

std::bitset<MAX_BITS> bs; // FIX: shouldn't this be a max of 1192?
status = aivdm_to_bits(bs, nmea_payload);
if (had_error()) return; // checks status

if (!decode_header8(bs)) return; // side effect - sets status

// Handle all the byte aligned payload
for (int i=0; i<payload_len/8; i++) {
const int start = 56+i*8;
//std::cout << "payload: " << i << " " << start <<"\n";
payload.push_back(ubits(bs,start,8));
}
const int remainder = payload_len % 8; // FIX: need to handle spare bits!!
std::cout << "remainder: " << remainder << "\n";
if (remainder > 0) {
const int start = (payload_len/8) * 8;
//std::cout << "start: " << start <<"\n";
payload.push_back(ubits(bs, start, remainder));
}
}

bool Ais8::decode_header8(const std::bitset<MAX_BITS> &bs) {
message_id = ubits(bs, 0, 6);
if (8 != message_id) { status = AIS_ERR_WRONG_MSG_TYPE; return false; }
repeat_indicator = ubits(bs,6,2);
mmsi = ubits(bs,8,30);
spare = ubits(bs,38,2);
dac = ubits(bs,40,10);
fi = ubits(bs,50,6);
return true;
}

#include <iomanip>

void Ais8::print() {
std::cout << "AIS_broadcast_binary_message: " << message_id
<< "\t\tdac: " << dac << "\tfi:" << fi << "\n";
std::cout << "\tpayload: "; // << std::hex << std::uppercase; // << std::setfill('0') << std::setw(2) << "\n";
for (std::vector<unsigned char>::iterator i = payload.begin(); i != payload.end(); i++) {
std::cout << std::hex <<std::setfill('0') << std::setw(2)<< int(*i);
}
std::cout << std::dec << std::nouppercase << std::endl;
//std::cout << "test: " << 1 << " " << 255 << " " << std::hex << 255 << std::endl;
}
15 changes: 15 additions & 0 deletions test_libais.cpp
Expand Up @@ -56,6 +56,21 @@ int main(UNUSED int argc, UNUSED char* argv[]) {
}


//////////////////////////////////////////////////////////////////////
// 8 - BBM
//////////////////////////////////////////////////////////////////////

if (true) {
int i=0;
// 1 11 601998 !AIVDM,1,1,4,B,800TgSP0BierU=KHP200OwwwwwwwwwwwwwwPIrOwwww?wowwwgwwwwwwwt0000,4*47,b003669954,1273276903
{
Ais8 msg("800TgSP0BierU=KHP200OwwwwwwwwwwwwwwPIrOwwww?wowwwgwwwwwwwt0000"); i++;
if (!msg.had_error()) msg.print();
else std::cout<<"FAILED 8 "<< i << " "<< AIS_STATUS_STRINGS[msg.get_error()] << "\n";
std::cout << "\n";
}

}
//////////////////////////////////////////////////////////////////////
// 9 - Search and rescue
//////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 9a2558c

Please sign in to comment.