Esempio n. 1
0
int test_assemble_vdm( void )
{
    ais_state state;
    char buf[3][255] = { "!AIVDM,1,1,,B,19NS7Sp02wo?HETKA2K6mUM20<L=,0*27\r\n",
                         "!AIVDM,2,1,9,A,55Mf@6P00001MUS;7GQL4hh61L4hh6222222220t41H,0*49\r\n",
                         "!AIVDM,2,2,9,A,==40HtI4i@E531H1QDTVH51DSCS0,2*16\r\n"
                       };
    
    memset( &state, 0, sizeof(state) );

    if (assemble_vdm( &state, buf[0] ) != 0)
    {
        fprintf( stderr, "test_assemble_vdm() 1: failed\n" );
        return 0;
    }
    if (strcmp( state.six_state.bits, "19NS7Sp02wo?HETKA2K6mUM20<L=" ) != 0)
    {
        fprintf( stderr, "test_assemble_vdm() 2: failed\n" );
        return 0;
    }

    if (assemble_vdm( &state, buf[1] ) != 1)
    {
        fprintf( stderr, "test_assemble_vdm() 3: failed\n" );
        return 0;
    }

    if (assemble_vdm( &state, buf[2] ) != 0)
    {
        fprintf( stderr, "test_assemble_vdm() 4: failed\n" );
        return 0;
    }
    if (strcmp( state.six_state.bits, "55Mf@6P00001MUS;7GQL4hh61L4hh6222222220t41H==40HtI4i@E531H1QDTVH51DSCS0" ) != 0)
    {
        fprintf( stderr, "test_assemble_vdm() 5: failed\n" );
        return 0;
    }

    fprintf( stderr, "test_assemble_vdm() Passed\n");
    return 1;
}
Esempio n. 2
0
void* receptor(void* data) 
{   
    boat* barco = (boat*) data;
    char msg[256];
    ais_state ais;
    aismsg_1  msg_1; // Solo se contempla mensages de tipo 1.
    long lat,lon;
    double lat_dd, long_ddd;
    float time;
    while (1)
    {   
        time = 0;
        memset( &ais, 0, sizeof( ais_state ) );
        pthread_mutex_lock(&lock);
        if (list != NULL)
        {   
            list = remove_message(list, msg);
            pthread_mutex_unlock(&lock);
            if (assemble_vdm( &ais, msg ) == 0)
            {
                ais.msgid = (unsigned char) get_6bit( &ais.six_state, 6 );
                
                if( (ais.msgid == 1)&&(parse_ais_1( &ais, &msg_1 ) == 0) )
                {   
                    float dist = distancia(barco->cog, msg_1.cog, barco->sog, msg_1.sog, barco->latitude, barco->longitude, msg_1.latitude, msg_1.longitude);
                    lat = msg_1.latitude; lon = msg_1.longitude;
					conv_pos(&lat, &lon);
                    pos2ddd( lat, lon, &lat_dd, &long_ddd );
                    printf("*****-----*****-----*****-----*****\n");
	                printf( "MESSAGE ID: %d\t", ais.msgid );
			        printf( "USER ID   : %ld\n", msg_1.userid );
			        printf( "SOG       : %d\t", msg_1.sog );
			        printf( "COG       : %d\n", msg_1.cog );
                    printf( "POSITION  : Lat %0.6f Lon %0.6f\n", lat_dd, long_ddd );
                    printf("MDCPA :%0.6f \n", dist); 
                }else printf("ERROR!!\nmsgid:%d msg:%s \n", ais.msgid, msg);
            }
        }
        else 
        {
            pthread_mutex_unlock(&lock);
            printf("No hay mensages\n");
            sleep(1);
            time += 1;
        }
        usleep(100000); // 0.1 seg
        time += 0.1;
        boat_new_pos(barco, time);
    }
}
Esempio n. 3
0
void test_access()
{
	int i;
	ais_state state;
    aismsg_8  message;
	seaway1_3 msg1_3;
	sixbit *seaway;
	water_level_report *report;
	timetag *utc_time;
	int dac, fi, spare, msgid;
    unsigned int  result;
	char *test_messages[] = {
		"!AIVDM,2,1,2,B,8030ojA?0@=DE3@?BDPA3onQiUFttP1Wh01DE3<1EJ?>0onlkUG0e01I,0*3D",
		"!AIVDM,2,2,2,B,h00,2*7D",
		"!AIVDM,2,1,9,B,8030ojA?0@=DE3C?B5<00o`O1UA@V01vh01DE63>DB3?5oW@PU?d4P1i,0*55",
		"!AIVDM,2,2,9,B,h00,2*76",
		"!AIVDM,2,1,3,B,8030ojA?0@=DE9CD:?B9Fot`9UKQW03Gh01DE9CD6B19?oqHd5H=WP11,0*51",
		"!AIVDM,2,2,3,B,h00,2*7C"
	};


    memset( &state, 0, sizeof(state) );
	for (i=0; i<6; i++)
	{ 
		if( assemble_vdm( &state, test_messages[i] ) == 0)
		{
		    state.msgid = (char) get_6bit( &state.six_state, 6 );
			if (state.msgid != 8)
				continue;

		    if( (result = parse_ais_8( &state, &message )) != 0 )
		    {
		        fprintf( stderr, "test_ais_1() failed: error %d\n", result);
		        return;
		    }

			seaway = get_msg8_data( &message );
			dac = message.app_id >> 6;
			fi = message.app_id & 0x3F; 

			spare = (char) get_6bit( seaway, 2);
			msgid = (char) get_6bit( seaway, 6);

			printf( "AppID: 0x%04X\n", message.app_id );
			printf( "DAC  : 0x%03X (%d)\n", dac, dac );
			printf( "FI   : 0x%02X (%d)\n", fi, fi);
			printf( "Spare: 0x%02X (%d)\n", spare, spare );
			printf( "msgid: 0x%02X (%d)\n", msgid, msgid );

			if ((fi == 1) && (msgid == 3))
			{
				if ( (result = parse_seaway1_3( seaway, &msg1_3)) != 0 )
				{
					fprintf( stderr, "parse_seaway1_3 failed: %d\n", result);
				}

				int r;
				for (r=0; r<6; r++)
				{
					report = get_water_level_report( &msg1_3, r);
					utc_time = get_water_level_utc_time( report );
					
					printf("month     : %d\n", utc_time->month);
					printf("day       : %d\n", utc_time->day);
					printf("hours     : %d\n", utc_time->hours);
					printf("minutes   : %d\n", utc_time->minutes);
					printf("station   : %s\n", report->station_id);
					printf("longitude : %ld\n", report->longitude);
					printf("latitude  : %ld\n", report->latitude);
					printf("type      : %d\n", report->type);
					printf("level     : %d\n", report->level);
					printf("datum     : %d\n", report->datum);
					printf("spare     : %d\n", report->spare);
					printf("\n\n");

				}
			}
		    memset( &state, 0, sizeof(state) );
		}
	}
Esempio n. 4
0
int main( int argc, char *argv[] )
{
    ais_state     ais;
    char          buf[256];

    /* AIS message structures, only parse ones with positions */
    aismsg_1  msg_1;
    aismsg_2  msg_2;
    aismsg_3  msg_3;
    aismsg_4  msg_4;
    aismsg_9  msg_9;
    aismsg_18 msg_18;
    aismsg_19 msg_19;
    
    /* Position in DD.DDDDDD */
    double lat_dd;
    double long_ddd;
    long   userid;

    /* Clear out the structures */
    memset( &ais, 0, sizeof( ais_state ) );

    /* Output JSON structure header */
    printf("<markers>\n");
    
    /* Process incoming packets from stdin */
    while( !feof(stdin) )
    {
        if (fgets( buf, 255, stdin ) == NULL ) break;

        if (assemble_vdm( &ais, buf ) == 0)
        {
            /* Get the 6 bit message id */
            ais.msgid = (unsigned char) get_6bit( &ais.six_state, 6 );
            
            /* process message with appropriate parser */
            switch( ais.msgid ) {
                case 1:
                    if( parse_ais_1( &ais, &msg_1 ) == 0 )
                    {
                        userid = msg_1.userid;
                        pos2ddd( msg_1.latitude, msg_1.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                            
                case 2:
                    if( parse_ais_2( &ais, &msg_2 ) == 0 )
                    {
                        userid = msg_2.userid;
                        pos2ddd( msg_2.latitude, msg_2.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                            
                case 3:
                    if( parse_ais_3( &ais, &msg_3 ) == 0 )
                    {
                        userid = msg_3.userid;
                        pos2ddd( msg_3.latitude, msg_3.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                            
                case 4:
                    if( parse_ais_4( &ais, &msg_4 ) == 0 )
                    {
                        userid = msg_4.userid;
                        pos2ddd( msg_4.latitude, msg_4.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                            
                case 9:
                    if( parse_ais_9( &ais, &msg_9 ) == 0 )
                    {
                        userid = msg_9.userid;
                        pos2ddd( msg_9.latitude, msg_9.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                    
                case 18:
                    if( parse_ais_18( &ais, &msg_18 ) == 0 )
                    {
                        userid = msg_18.userid;
                        pos2ddd( msg_18.latitude, msg_18.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                    

                case 19:
                    if( parse_ais_19( &ais, &msg_19 ) == 0 )
                    {
                        userid = msg_19.userid;
                        pos2ddd( msg_19.latitude, msg_19.longitude, &lat_dd, &long_ddd );
                    }
                    break;
                    
            }  /* switch msgid */
            printf( "    <marker lat=\"%0.6f\" lng=\"%0.6f\" />\n", lat_dd, long_ddd );
        }  /* if */
    }  /* while */

    /* Output JSON footer */
    printf("</markers>\n");
    
    return 0;
}
Esempio n. 5
0
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;
        }