示例#1
0
int test_ais_24A( void )
{
    ais_state state;
    aismsg_24  message;
    unsigned int  result;
    /* 24A !AIVDM,1,1,,A,H52IRsP518Tj0l59D0000000000,2*45 */
    char s[] = "H52IRsP518Tj0l59D0000000000";

    /* Clear out the structure first */
    memset( &message, 0, sizeof( aismsg_24 ));

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_24( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_24A() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 24 )
    {
        fprintf( stderr, "test_ais_24A() failed: msgid\n");
        return 0;
    }

    if( message.flags != 1 )
    {
        fprintf( stderr, "test_ais_24A() failed: flags\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_24A() failed: repeat\n");
        return 0;
    }

    if( message.userid != 338060014 )
    {
        fprintf( stderr, "test_ais_24A() failed: userid\n");
        return 0;
    }

    if( message.part_number != 0 )
    {
        fprintf( stderr, "test_ais_24A() failed: part_number\n");
        return 0;
    }

    if( strcmp( message.name, "APRIL MARU@@@@@@@@@@")  != 0 )
    {
        fprintf( stderr, "test_ais_24A() failed: name\n");
        return 0;
    }

    fprintf( stderr, "test_ais_24A() passed\n");
    return 1;
}
示例#2
0
int test_ais_9( void )
{
    ais_state state;
    aismsg_9  message;
    unsigned int  result;
    /* !AIVDM,1,1,,B,900048wwTcJb0mpF16IobRP2086Q,0*48 */
    char s[] = "900048wwTcJb0mpF16IobRP2086Q";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_9( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 9 )
    {
        fprintf( stderr, "test_ais_9() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: repeat\n");
        return 0;
    }

    if( message.userid != 1059 )
    {
        fprintf( stderr, "test_ais_9() failed: userid\n");
        return 0;
    }

    if( message.altitude != 4094 )
    {
        fprintf( stderr, "test_ais_9() failed: altitude\n");
        return 0;
    }

    if( message.sog != 299 )
    {
        fprintf( stderr, "test_ais_9() failed: sog\n");
        return 0;
    }

    if( message.pos_acc != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: pos_acc\n");
        return 0;
    }

    if( message.longitude != -44824900 )
    {
        fprintf( stderr, "test_ais_9() failed: longitude\n");
        return 0;
    }

    if( message.latitude != 23086695 )
    {
        fprintf( stderr, "test_ais_9() failed: latitude\n");
        return 0;
    }

    if( message.cog != 1962 )
    {
        fprintf( stderr, "test_ais_9() failed: cog\n");
        return 0;
    }

    if( message.utc_sec != 10 )
    {
        fprintf( stderr, "test_ais_9() failed: utc_sec\n");
        return 0;
    }

    if( message.regional != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: regional\n");
        return 0;
    }

    if( message.dte != 1 )
    {
        fprintf( stderr, "test_ais_9() failed: dte\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: spare\n");
        return 0;
    }

    if( message.assigned != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: assigned\n");
        return 0;
    }

    if( message.raim != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: raim\n");
        return 0;
    }

    if( message.comm_state != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: comm_state\n");
        return 0;
    }

    if( message.comm_state != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: comm_state\n");
        return 0;
    }

    if( message.sotdma.sync_state != 0 )
    {
        fprintf( stderr, "test_ais_9() failed: sotdma.sync_state\n");
        return 0;
    }

    if( message.sotdma.slot_timeout != 2 )
    {
        fprintf( stderr, "test_ais_9() failed: sotdma.slot_timeout\n");
        return 0;
    }

    if( message.sotdma.sub_message != 417 )
    {
        fprintf( stderr, "test_ais_9() failed: sotdma.sub_message\n");
        return 0;
    }

    fprintf( stderr, "test_ais_9() passed\n");
    return 1;
}
示例#3
0
int test_ais_7( void )
{
    ais_state state;
    aismsg_7  message;
    unsigned int  result;
    /* !AIVDM,1,1,,A,703Owpi9lmaQ,0*3B */
    char s[] = "703Owpi9lmaQ";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_7( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_7() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 7 )
    {
        fprintf( stderr, "test_ais_7() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_7() failed: repeat\n");
        return 0;
    }

    if( message.userid != 3669987 )
    {
        fprintf( stderr, "test_ais_7() failed: userid\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_7() failed: spare\n");
        return 0;
    }

    if( message.destid_1 != 309647000 )
    {
        fprintf( stderr, "test_ais_7() failed: destid_1\n");
        return 0;
    }

    if( message.sequence_1 != 1 )
    {
        fprintf( stderr, "test_ais_7() failed: sequence_1\n");
        return 0;
    }

    if( message.num_acks != 1 )
    {
        fprintf( stderr, "test_ais_7() failed: num_acks\n");
        return 0;
    }

    fprintf( stderr, "test_ais_7() passed\n");
    return 1;
}
示例#4
0
int test_ais_5( void )
{

    ais_state state;
    aismsg_5  message;
    unsigned int  result;
    /* !AIVDM,2,1,9,A,55Mf@6P00001MUS;7GQL4hh61L4hh6222222220t41H,0*49 
       !AIVDM,2,2,9,A,==40HtI4i@E531H1QDTVH51DSCS0,2*16 */
    char s[] = "55Mf@6P00001MUS;7GQL4hh61L4hh6222222220t41H==40HtI4i@E531H1QDTVH51DSCS0";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_5( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_4() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 5 )
    {
        fprintf( stderr, "test_ais_5() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: repeat\n");
        return 0;
    }

    if( message.userid != 366710810 )
    {
        fprintf( stderr, "test_ais_5() failed: userid\n");
        return 0;
    }

    if( message.version != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: version\n");
        return 0;
    }

    if( message.imo != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: imo\n");
        return 0;
    }

    if( strcmp(message.callsign, "WYX2158") != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: callsign\n");
        return 0;
    }

    if( strcmp( message.name, "WALLA WALLA         ")  != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: name\n");
        return 0;
    }

    if( message.ship_type != 60 )
    {
        fprintf( stderr, "test_ais_5() failed: ship_type\n");
        return 0;
    }

    if( message.dim_bow != 32 )
    {
        fprintf( stderr, "test_ais_5() failed: dim_bow\n");
        return 0;
    }

    if( message.dim_stern != 88 )
    {
        fprintf( stderr, "test_ais_5() failed: dim_stern\n");
        return 0;
    }

    if( message.dim_port != 13 )
    {
        fprintf( stderr, "test_ais_5() failed: dim_port\n");
        return 0;
    }

    if( message.dim_starboard != 13 )
    {
        fprintf( stderr, "test_ais_5() failed: dim_starboard\n");
        return 0;
    }

    if( message.pos_type != 1 )
    {
        fprintf( stderr, "test_ais_5() failed: pos_type\n");
        return 0;
    }

    if( message.eta != 1596 )
    {
        fprintf( stderr, "test_ais_5() failed: eta\n");
        return 0;
    }

    if( message.draught != 100 )
    {
        fprintf( stderr, "test_ais_5() failed: draught\n");
        return 0;
    }

    if( strcmp(message.dest, "SEATTLE FERRY TERMNL") != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: dest\n");
        return 0;
    }

    if( message.dte != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: dte\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_5() failed: spare\n");
        return 0;
    }

    fprintf( stderr, "test_ais_5() passed\n");
    return 1;
}
示例#5
0
int test_ais_4( void )
{
    ais_state state;
    aismsg_4  message;
    unsigned int  result;
    /* !AIVDM,1,1,,A,403OwpiuIKl:Ro=sbvK=CG700<3b,0*5E */
    char s[] = "403OwpiuIKl:Ro=sbvK=CG700<3b";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_4( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_4() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 4 )
    {
        fprintf( stderr, "test_ais_4() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_4() failed: repeat\n");
        return 0;
    }

    if( message.userid != 3669987 )
    {
        fprintf( stderr, "test_ais_4() failed: userid\n");
        return 0;
    }

    if( message.utc_year != 2006 )
    {
        fprintf( stderr, "test_ais_4() failed: utc_year\n");
        return 0;
    }

    if( message.utc_month != 5 )
    {
        fprintf( stderr, "test_ais_4() failed: utc_month\n");
        return 0;
    }

    if( message.utc_day != 23 )
    {
        fprintf( stderr, "test_ais_4() failed: utc_day\n");
        return 0;
    }

    if( message.utc_hour != 20 )
    {
        fprintf( stderr, "test_ais_4() failed: utc_hour\n");
        return 0;
    }

    if( message.utc_minute != 10 )
    {
        fprintf( stderr, "test_ais_4() failed: utc_minute\n");
        return 0;
    }

    if( message.utc_second != 34)
    {
        fprintf( stderr, "test_ais_4() failed: utc_second\n");
        return 0;
    }

    if( message.pos_acc != 1 )
    {
        fprintf( stderr, "test_ais_4() failed: pos_acc\n");
        return 0;
    }

    if( message.longitude != -73671329 )
    {
        fprintf( stderr, "test_ais_4() failed: longitude\n");
        return 0;
    }

    if( message.latitude != 28529500 )
    {
        fprintf( stderr, "test_ais_4() failed: utc_latitude\n");
        return 0;
    }

    if( message.pos_type != 7 )
    {
        fprintf( stderr, "test_ais_4() failed: pos_type\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_4() failed: spare\n");
        return 0;
    }

    if( message.raim != 0 )
    {
        fprintf( stderr, "test_ais_4() failed: raim\n");
        return 0;
    }

    if( message.sync_state != 0 )
    {
        fprintf( stderr, "test_ais_4() failed: sync_state\n");
        return 0;
    }

    if( message.slot_timeout != 3 )
    {
        fprintf( stderr, "test_ais_4() failed: slot_timeout\n");
        return 0;
    }

    if( message.sub_message != 234 )
    {
        fprintf( stderr, "test_ais_4() failed: sub_message\n");
        return 0;
    }

    fprintf( stderr, "test_ais_4() passed\n");
    return 1;

}
示例#6
0
int test_ais_3( void )
{
    ais_state state;
    aismsg_3  message;
    unsigned int  result;
    /* !AIVDM,1,1,,B,35Mk33gOkSG?bLtK?;B2dRO`00`A,0*30 */
    char s[] = "35Mk33gOkSG?bLtK?;B2dRO`00`A";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_3( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 3 )
    {
        fprintf( stderr, "test_ais_3() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: repeat\n");
        return 0;
    }

    if( message.userid != 366789390 )
    {
        fprintf( stderr, "test_ais_3() failed: userid/MMSI\n");
        return 0;
    }

    if( message.nav_status != 15 )
    {
        fprintf( stderr, "test_ais_3() failed: nav_status\n");
        return 0;
    }

    if( message.rot != 127 )
    {
        fprintf( stderr, "test_ais_3() failed: rot\n");
        return 0;
    }

    if( message.sog != 227 )
    {
        fprintf( stderr, "test_ais_3() failed: sog\n");
        return 0;
    }

    if( message.longitude != -73444450 )
    {
        fprintf( stderr, "test_ais_3() failed: longitude\n");
        return 0;
    }

    if( message.latitude != 28560200 )
    {
        fprintf( stderr, "test_ais_3() failed: latitude\n");
        return 0;
    }

    if( message.cog != 690 )
    {
        fprintf( stderr, "test_ais_3() failed: cog\n");
        return 0;
    }

    if( message.true_heading != 79 )
    {
        fprintf( stderr, "test_ais_3() failed: true_heading\n");
        return 0;
    }

    if( message.utc_sec != 52 )
    {
        fprintf( stderr, "test_ais_3() failed: utc_sec\n");
        return 0;
    }

    if( message.regional != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: regional\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: spare\n");
        return 0;
    }

    if( message.raim != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: raim\n");
        return 0;
    }

    if( message.sync_state != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: sync_state\n");
        return 0;
    }

    if( message.slot_increment != 161 )
    {
        fprintf( stderr, "test_ais_3() failed: slot_increment\n");
        return 0;
    }

    if( message.num_slots != 0 )
    {
        fprintf( stderr, "test_ais_3() failed: num_slots\n");
        return 0;
    }

    if( message.keep != 1 )
    {
        fprintf( stderr, "test_ais_3() failed: keep\n");
        return 0;
    }

    fprintf( stderr, "test_ais_3() passed\n");
    return 1;
}
示例#7
0
int test_ais_1( void )
{
    ais_state state;
    aismsg_1  message;
    unsigned int  result;
    /* !AIVDM,1,1,,B,19NS7Sp02wo?HETKA2K6mUM20<L=,0*27 */
    char s[] = "19NS7Sp02wo?HETKA2K6mUM20<L=";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_1( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 1 )
    {
        fprintf( stderr, "test_ais_1() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: repeat\n");
        return 0;
    }

    if( message.userid != 636012431 )
    {
        fprintf( stderr, "test_ais_1() failed: userid/MMSI\n");
        return 0;
    }

    if( message.nav_status != 8 )
    {
        fprintf( stderr, "test_ais_1() failed: nav_status\n");
        return 0;
    }

    if( message.rot != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: rot\n");
        return 0;
    }

    if( message.sog != 191 )
    {
        fprintf( stderr, "test_ais_1() failed: sog\n");
        return 0;
    }

    if( message.longitude != -73481550 )
    {
        fprintf( stderr, "test_ais_1() failed: longitude\n");
        return 0;
    }

    if( message.latitude !=  28590700 )
    {
        fprintf( stderr, "test_ais_1() failed: latitude\n");
        return 0;
    }

    if( message.cog != 1750 )
    {
        fprintf( stderr, "test_ais_1() failed: cog\n");
        return 0;
    }

    if( message.true_heading != 174 )
    {
        fprintf( stderr, "test_ais_1() failed: true_heading\n");
        return 0;
    }

    if( message.utc_sec != 33 )
    {
        fprintf( stderr, "test_ais_1() failed: utc_sec\n");
        return 0;
    }

    if( message.regional != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: regional\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: spare\n");
        return 0;
    }

    if( message.raim != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: raim\n");
        return 0;
    }

    if( message.sync_state != 0 )
    {
        fprintf( stderr, "test_ais_1() failed: sync_state\n");
        return 0;
    }

    if( message.slot_timeout != 3 )
    {
        fprintf( stderr, "test_ais_1() failed: slot_timeout\n");
        return 0;
    }

    if( message.sub_message != 1805 )
    {
        fprintf( stderr, "test_ais_1() failed: sub_message\n");
        return 0;
    }

    fprintf( stderr, "test_ais_1() passed\n");
    return 1;

}
示例#8
0
int test_ais_24B( void )
{
    ais_state state;
    aismsg_24  message;
    unsigned int  result;
    /* 24B !AIVDM,1,1,,A,H52IRsTU000000000000000@5120,0*76 */
    char s[] = "H52IRsTU000000000000000@5120";

    /* Clear out the structure first */
    memset( &message, 0, sizeof( aismsg_24 ));

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_24( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_24B() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 24 )
    {
        fprintf( stderr, "test_ais_24B() failed: msgid\n");
        return 0;
    }

    if( message.flags != 2 )
    {
        fprintf( stderr, "test_ais_24B() failed: flags\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_24B() failed: repeat\n");
        return 0;
    }

    if( message.userid != 338060014 )
    {
        fprintf( stderr, "test_ais_24B() failed: userid\n");
        return 0;
    }

    if( message.part_number != 1 )
    {
        fprintf( stderr, "test_ais_24B() failed: part_number\n");
        return 0;
    }

	if( message.ship_type != 37 )
	{
	    fprintf( stderr, "test_ais_24B() failed: ship_type\n");
	    return 0;
	}

	if( strcmp( message.vendor_id, "@@@@@@@")  != 0 )
	{
	    fprintf( stderr, "test_ais_24B() failed: vendor_id\n");
	    return 0;
	}

	if( strcmp( message.callsign, "@@@@@@@")  != 0 )
	{
	    fprintf( stderr, "test_ais_24B() failed: callsign\n");
	    return 0;
	}

	if( message.dim_bow != 2 )
	{
	    fprintf( stderr, "test_ais_24B() failed: dim_bow\n");
	    return 0;
	}

	if( message.dim_stern != 5 )
	{
	    fprintf( stderr, "test_ais_24B() failed: dim_stern\n");
	    return 0;
	}

	if( message.dim_port != 1 )
	{
	    fprintf( stderr, "test_ais_24B() failed: dim_port\n");
	    return 0;
	}

	if( message.dim_starboard != 2 )
	{
	    fprintf( stderr, "test_ais_24B() failed: dim_starboard\n");
	    return 0;
	}

	if( message.spare != 0 )
	{
	    fprintf( stderr, "test_ais_24B() failed: spare\n");
	    return 0;
	}

    fprintf( stderr, "test_ais_24B() passed\n");
    return 1;
}
示例#9
0
int test_ais_20( void )
{
    ais_state state;
    aismsg_20  message;
    unsigned int  result;
    /* !AIVDM,1,1,,A,D03OwphiIN>4,0*25 */
    char s[] = "D03OwphiIN>4";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_20( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 20 )
    {
        fprintf( stderr, "test_ais_20() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: repeat\n");
        return 0;
    }

    if( message.userid != 3669987 )
    {
        fprintf( stderr, "test_ais_20() failed: userid\n");
        return 0;
    }

    if( message.spare1 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: spare1\n");
        return 0;
    }

    if( message.offset1 != 790 )
    {
        fprintf( stderr, "test_ais_20() failed: offset1\n");
        return 0;
    }

    if( message.slots1 != 5 )
    {
        fprintf( stderr, "test_ais_20() failed: slots1\n");
        return 0;
    }

    if( message.timeout1 != 7 )
    {
        fprintf( stderr, "test_ais_20() failed: timeout1\n");
        return 0;
    }

    if( message.increment1 != 225 )
    {
        fprintf( stderr, "test_ais_20() failed: increment1\n");
        return 0;
    }

    if( message.offset2 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: offset2\n");
        return 0;
    }

    if( message.slots2 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: slots2\n");
        return 0;
    }

    if( message.timeout2 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: timeout2\n");
        return 0;
    }

    if( message.increment2 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: increment2\n");
        return 0;
    }

    if( message.offset3 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: offset3\n");
        return 0;
    }

    if( message.slots3 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: slots3\n");
        return 0;
    }

    if( message.timeout3 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: timeout3\n");
        return 0;
    }

    if( message.increment3 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: increment3\n");
        return 0;
    }

    if( message.offset4 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: offset4\n");
        return 0;
    }

    if( message.slots4 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: slots4\n");
        return 0;
    }

    if( message.timeout4 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: timeout4\n");
        return 0;
    }

    if( message.increment4 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: increment4\n");
        return 0;
    }

    if( message.spare2 != 0 )
    {
        fprintf( stderr, "test_ais_20() failed: spare2\n");
        return 0;
    }

    fprintf( stderr, "test_ais_20() passed\n");
    return 1;
}
示例#10
0
int test_ais_18( void )
{
    ais_state state;
    aismsg_18  message;
    unsigned int  result;
    /* !AIVDM,1,1,,A,B52IRsP005=abWRnlQP03w`UkP06,0*2A */
    char s[] = "B52IRsP005=abWRnlQP03w`UkP06";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_18( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 18 )
    {
        fprintf( stderr, "test_ais_18() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: repeat\n");
        return 0;
    }

    if( message.userid != 338060014 )
    {
        fprintf( stderr, "test_ais_18() failed: userid\n");
        return 0;
    }

    if( message.regional1 != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: regional1\n");
        return 0;
    }

    if( message.sog != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: sog\n");
        return 0;
    }

    if( message.pos_acc != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: pos_acc\n");
        return 0;
    }

    if( message.longitude != -93506225 )
    {
        fprintf( stderr, "test_ais_18() failed: longitude\n");
        return 0;
    }

    if( message.latitude != 11981336 )
    {
        fprintf( stderr, "test_ais_18() failed: latitude\n");
        return 0;
    }

    if( message.cog != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: cog\n");
        return 0;
    }

    if( message.true_heading != 511 )
    {
        fprintf( stderr, "test_ais_18() failed: true_heading\n");
        return 0;
    }

    if( message.utc_sec != 17 )
    {
        fprintf( stderr, "test_ais_18() failed: utc_sec\n");
        return 0;
    }

    if( message.regional2 != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: regional2\n");
        return 0;
    }

    if( message.unit_flag != 1 )
    {
        fprintf( stderr, "test_ais_18() failed: unit_flag\n");
        return 0;
    }

    if( message.display_flag != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: display_flag\n");
        return 0;
    }

    if( message.dsc_flag != 1 )
    {
        fprintf( stderr, "test_ais_18() failed: dsc_flag\n");
        return 0;
    }

    if( message.band_flag != 1 )
    {
        fprintf( stderr, "test_ais_18() failed: band_flag\n");
        return 0;
    }

    if( message.msg22_flag != 1 )
    {
        fprintf( stderr, "test_ais_18() failed: msg22_flag\n");
        return 0;
    }

    if( message.mode_flag != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: mode_flag\n");
        return 0;
    }

    if( message.raim != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: raim\n");
        return 0;
    }

    if( message.comm_state != 1 )
    {
        fprintf( stderr, "test_ais_18() failed: comm_state\n");
        return 0;
    }

    if( message.itdma.sync_state != 3 )
    {
        fprintf( stderr, "test_ais_18() failed: itdma.sync_state\n");
        return 0;
    }

    if( message.itdma.slot_inc != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: itdma.slot_inc\n");
        return 0;
    }

    if( message.itdma.num_slots != 3 )
    {
        fprintf( stderr, "test_ais_18() failed: itdma.num_slots\n");
        return 0;
    }

    if( message.itdma.keep_flag != 0 )
    {
        fprintf( stderr, "test_ais_18() failed: itdma.keep_flag\n");
        return 0;
    }

    fprintf( stderr, "test_ais_18() passed\n");
    return 1;

}
示例#11
0
int test_ais_15( void )
{
    ais_state state;
    aismsg_15  message;
    unsigned int  result;
    /* !AIVDM,1,1,,A,?03OwpiGPmD0000,2*07
       Note that this is an invlid interrogation, it does not specify a
       message number or an offset. But it did come from a base station so I
       believe that it is not noise.
    */
    char s[] = "?03OwpiGPmD0000";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_15( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 15 )
    {
        fprintf( stderr, "test_ais_15() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: repeat\n");
        return 0;
    }

    if( message.userid != 3669987 )
    {
        fprintf( stderr, "test_ais_15() failed: userid\n");
        return 0;
    }

    if( message.spare1 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: spare1\n");
        return 0;
    }

    if( message.destid1 != 367056192 )
    {
        fprintf( stderr, "test_ais_15() failed: destid1\n");
        return 0;
    }

    if( message.msgid1_1 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: msgid1_1\n");
        return 0;
    }

    if( message.offset1_1 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: offset1_1\n");
        return 0;
    }

    if( message.spare2 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: spare2\n");
        return 0;
    }

    if( message.msgid1_2 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: msgid1_2\n");
        return 0;
    }

    if( message.offset1_2 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: offset1_2\n");
        return 0;
    }

    if( message.spare3 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: spare3\n");
        return 0;
    }

    if( message.destid2 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: destid2\n");
        return 0;
    }

    if( message.msgid2_1 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: msgid2_1\n");
        return 0;
    }

    if( message.offset2_1 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: offset2_1\n");
        return 0;
    }

    if( message.spare4 != 0 )
    {
        fprintf( stderr, "test_ais_15() failed: spare4\n");
        return 0;
    }

    fprintf( stderr, "test_ais_15() passed\n");
    return 1;
}
示例#12
0
int test_ais_12( void )
{
    ais_state state;
    aismsg_12  message;
    unsigned int  result;
    /* !AIVDM,1,1,,A,<03Owph00002QG51D85BP1<5BDQP,0*7D */
    char s[] = "<03Owph00002QG51D85BP1<5BDQP";

    init_6bit( &state.six_state );
    strcpy( state.six_state.bits, s );
    state.msgid = (char) get_6bit( &state.six_state, 6 );
    if( (result = parse_ais_12( &state, &message )) != 0 )
    {
        fprintf( stderr, "test_ais_12() failed: error %d\n", result);
        return 0;
    }

    /* Check the results */
    if( message.msgid != 12 )
    {
        fprintf( stderr, "test_ais_12() failed: msgid\n");
        return 0;
    }

    if( message.repeat != 0 )
    {
        fprintf( stderr, "test_ais_12() failed: repeat\n");
        return 0;
    }

    if( message.userid != 3669987 )
    {
        fprintf( stderr, "test_ais_12() failed: userid\n");
        return 0;
    }

    if( message.sequence != 0 )
    {
        fprintf( stderr, "test_ais_12() failed: sequence\n");
        return 0;
    }

    if( message.destination != 0 )
    {
        fprintf( stderr, "test_ais_12() failed: destination\n");
        return 0;
    }

    if( message.retransmit != 1 )
    {
        fprintf( stderr, "test_ais_12() failed: retransmit\n");
        return 0;
    }

    if( message.spare != 0 )
    {
        fprintf( stderr, "test_ais_12() failed: spare\n");
        return 0;
    }

    if( strcmp( message.message, "!WEATHER ALERT! ")  != 0 )
    {
        fprintf( stderr, "test_ais_12() failed: message\n");
        return 0;
    }

    fprintf( stderr, "test_ais_12() passed\n");
    return 1;
}
示例#13
0
文件: main.c 项目: Ridaamin/aisparser
int main( int argc, char *argv[] )
{
    ais_state     ais;
    unsigned int  i;

    /* AIS message structures */
    aismsg_1  msg_1;
    aismsg_2  msg_2;
    aismsg_3  msg_3;
    aismsg_4  msg_4;
    aismsg_5  msg_5;
    aismsg_12 msg_12;
	aismsg_18 msg_18;
	aismsg_24 msg_24;

    char *test_msgs[] = { "19NS7Sp02wo?HETKA2K6mUM20<L=",
                          "35Mk33gOkSG?bLtK?;B2dRO`00`",
                          "403OwpiuIKl:Ro=sbvK=CG700<3b",
                          "55Mf@6P00001MUS;7GQL4hh61L4hh6222222220t41H==40HtI4i@E531H1QDTVH51DSCS0",
                          "703Owpi9lmaQ",
                          "<03Owph00002QG51D85BP1<5BDQP",
                          "=03Owpi;Eo7`",
                          "?03OwpiGPmD0000",
                          "D03OwphiIN>4",
                          "B52IRsP005=abWRnlQP03w`UkP06",
                          "H52IRsP518Tj0l59D0000000000",
                          "H52IRsTU000000000000000@5120"


    };

    #define NUM_DEMO_MSGS 9
    char *demo_msgs[] = { "!AIVDM,1,1,,B,15MqvC0Oh9G?qinK?VlPhA480@2n,0*1F,123,14",
                          "!AIVDM,1,1,,B,15Mf@6P001G?v68K??4SejL<00Sl,0*71",
                          "!AIVDM,1,1,,B,15Mn4kPP01G?qNvK>:grkOv<0<11,0*55",
                          "!AIVDM,1,1,,B,15O1Pv0022o?GeNKB3f7QV2>00SP,0*26",
                          "!AIVDM,1,1,,B,15MqvC0Oh:G?qj0K?Vp@di4B0@5>,0*44",
                          "!AIVDM,1,1,,B,15Mts3?P@;G8RB@JLbgamrBF0H6B,0*16",
                          "$BSVDM,1,1,,B,15MqvC0Oh:G?qj0K?Vp@di4B0@5>,0*5D",
                          "!AIVDM,1,1,,B,15Mts3?P@;G8RB@JLbgamrBF0H6B,0*16,142,aass,12311",
                          "!AIVDM,1,1,,A,34a=CB1001JwAEhHra0qk4wF2000,0*5B"
    };

    
    if (test_ahextobin() != 1)
    {
        exit(-1);
    }
    if (test_nmea_next_field() != 1)
    {
        exit(-1);
    }
    if (test_nmea_uint() != 1)
    {
        exit(-1);
    }
    if (test_nmea_copy_field() != 1)
    {
        exit(-1);
    }
    if (test_find_nmea_start() != 1)
    {
        exit(-1);
    }
    if (test_nmea_checksum() != 1)
    {
        exit(-1);
    }
    if (test_check_nmea_checksum() != 1)
    {
        exit(-1);
    }

    if (test_binfrom6bit() != 1)
    {
        exit(-1);
    }
    if (test_init_6bit() != 1)
    {
        exit(-1);
    }
    if (test_get_6bit() != 1)
    {
        exit(-1);
    }
    if (test_ais2ascii() != 1)
    {
        exit(-1);
    }
    if (test_conv_pos() != 1)
    {
        exit(-1);
    }
    if (test_pos2ddd() != 1)
    {
        exit(-1);
    }    
    if (test_pos2dmm() != 1)
    {
        exit(-1);
    }    
    if (test_assemble_vdm() != 1)
    {
        exit(-1);
    }
    if( test_ais_1() != 1 )
    {
        exit(-1);
    }
    if( test_ais_3() != 1 )
    {
        exit(-1);
    }
    if( test_ais_4() != 1 )
    {
        exit(-1);
    }
    if( test_ais_5() != 1 )
    {
        exit(-1);
    }
    if( test_ais_7() != 1 )
    {
        exit(-1);
    }
    if( test_ais_9() != 1 )
    {
        exit(-1);
    }
    if( test_ais_12() != 1 )
    {
        exit(-1);
    }
    if( test_ais_13() != 1 )
    {
        exit(-1);
    }
    if( test_ais_15() != 1 )
    {
        exit(-1);
    }
    if( test_ais_18() != 1 )
    {
        exit(-1);
    }
    if( test_ais_20() != 1 )
    {
        exit(-1);
    }
    if( test_ais_24A() != 1 )
    {
        exit(-1);
    }
    if( test_ais_24B() != 1 )
    {
        exit(-1);
    }

    printf("Testing test_msgs\n");
    
    /* Clear out the structures */
    memset( &ais, 0, sizeof( ais_state ) );

    for (i=0; i<12; i++)
    {
        init_6bit( &ais.six_state );
        strcpy( ais.six_state.bits, test_msgs[i] );
        ais.msgid = (unsigned char) get_6bit( &ais.six_state, 6 );
    
        /* Process the AIS message */
        printf( "Message %d\n", ais.msgid );
                
        /* process message with appropriate parser */
        switch( ais.msgid ) {
            case 1:
                if( parse_ais_1( &ais, &msg_1 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI : %09ld\n", msg_1.userid );
                    printf( "Lat  : %ld\n", msg_1.latitude  );
                    printf( "Long : %ld\n", msg_1.longitude  );
                }
                break;
                        
            case 2:
                if( parse_ais_2( &ais, &msg_2 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI : %09ld\n", msg_2.userid );
                    printf( "Lat  : %ld\n", msg_1.latitude  );
                    printf( "Long : %ld\n", msg_1.longitude  );
                }
                break;
                        
            case 3:
                if( parse_ais_3( &ais, &msg_3 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI : %09ld\n", msg_3.userid );
                    printf( "Lat  : %ld\n", msg_1.latitude  );
                    printf( "Long : %ld\n", msg_1.longitude  );
                }
                break;
                        
            case 4:
                if( parse_ais_4( &ais, &msg_4 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI : %09ld\n", msg_4.userid );
                    printf( "Lat  : %ld\n", msg_1.latitude  );
                    printf( "Long : %ld\n", msg_1.longitude  );
                }
                break;
                        
            case 5:
                if( parse_ais_5( &ais, &msg_5 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI        : %09ld\n", msg_5.userid );
                    printf( "Callsign    : %s\n", msg_5.callsign );
                    printf( "Name        : %s\n", msg_5.name );
                    printf( "Destination : %s\n", msg_5.dest );
                }
                break;
                
            case 12:
                if (parse_ais_12(&ais, &msg_12) == 0)
                {
                    /* Do something with the resu;ts */
                    printf( "MMSI        : %09ld\n", msg_12.userid );
                    printf( "Message     : %s\n", msg_12.message );
                }
                break;

            case 18:
                if( parse_ais_18( &ais, &msg_18 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI : %09ld\n", msg_18.userid );
                    printf( "Lat  : %ld\n", msg_18.latitude  );
                    printf( "Long : %ld\n", msg_18.longitude  );
                } 
                break;

            case 24:
                if( parse_ais_24( &ais, &msg_24 ) == 0 )
                {
                    /* Do something with results */
                    printf( "MMSI     : %09ld\n", msg_24.userid );
					if (msg_24.flags & 1)
					{
						printf("Name : %s\n", msg_24.name );
					}
					if (msg_24.flags & 2)
					{
						printf("Callsign : %s\n", msg_24.callsign );
					}
                } 
                break;


        }
    }

    /* St. Lawrence msg8 testing */
	test_seaway();

    printf("Testing demo_msgs\n");
    
    /* Clear out the structures */
    memset( &ais, 0, sizeof( ais_state ) );

    for (i=0; i<NUM_DEMO_MSGS; i++)
    {
        if( assemble_vdm( &ais, demo_msgs[i] ) != 0 )
            continue;

        ais.msgid = (unsigned char) get_6bit( &ais.six_state, 6 );
    
        /* Process the AIS message */
        printf( "%d of %d: %s\n", i+1, NUM_DEMO_MSGS, demo_msgs[i]);
        printf( "msgid       : %d\n", ais.msgid );

        /* process message with appropriate parser */
        switch( ais.msgid ) {
            case 1:
                if( parse_ais_1( &ais, &msg_1 ) == 0 )
                {
                    printf("repeat      : %d\n", msg_1.repeat );
                    printf("userid      : %ld\n", msg_1.userid );
                    printf("nav_status  : %d\n", msg_1.nav_status );
                    printf("rot         : %d\n", msg_1.rot ); 
                    printf("sog         : %d\n", msg_1.sog );
                    printf("pos_acc     : %d\n", msg_1.pos_acc );
                    printf("longitude   : %ld\n", msg_1.longitude );
                    printf("latitude    : %ld\n", msg_1.latitude );
                    printf("cog         : %d\n", msg_1.cog );
                    printf("true        : %d\n", msg_1.true );
                    printf("utc_sec     : %d\n", msg_1.utc_sec );
                    printf("regional    : %d\n", msg_1.regional );
                    printf("spare       : %d\n", msg_1.spare );
                    printf("raim        : %d\n", msg_1.raim );
                    printf("sync_state  : %d\n", msg_1.sync_state );
                    printf("slot_timeout: %d\n", msg_1.slot_timeout );
                    printf("sub_message : %d\n", msg_1.sub_message );
                }
            break;
            case 3:
                if( parse_ais_3( &ais, &msg_3 ) == 0 )
                {
                    printf("repeat      : %d\n", msg_3.repeat );
                    printf("userid      : %ld\n", msg_3.userid );
                    printf("nav_status  : %d\n", msg_3.nav_status );
                    printf("rot         : %d\n", msg_3.rot ); 
                    printf("sog         : %d\n", msg_3.sog );
                    printf("pos_acc     : %d\n", msg_3.pos_acc );
                    printf("longitude   : %ld\n", msg_3.longitude );
                    printf("latitude    : %ld\n", msg_3.latitude );
                    printf("cog         : %d\n", msg_3.cog );
                    printf("true        : %d\n", msg_3.true );
                    printf("utc_sec     : %d\n", msg_3.utc_sec );
                    printf("regional    : %d\n", msg_3.regional );
                    printf("spare       : %d\n", msg_3.spare );
                    printf("raim        : %d\n", msg_3.raim );
                    printf("sync_state  : %d\n", msg_3.sync_state );
                    printf("slot_inc    : %d\n", msg_3.slot_increment );
                    printf("num_slots   : %d\n", msg_3.num_slots );
                    printf("keep        : %d\n", msg_3.keep);
                }


            break;
        }