Exemple #1
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);
    }
}
Exemple #2
0
int test_pos2ddd( void )
{
    long latitude;
    long longitude;
    double lat_dd;
    double long_ddd;
 
 
    /* North East quadrant (+,+)
       Trondheim, Norway  63.416277, 10.412227
     */
    latitude = 38049766;
    longitude = 6247336;
    pos2ddd( latitude, longitude, &lat_dd, &long_ddd );
    if ((lat_dd!=63.416276666666668) || (long_ddd!= 10.412226666666667))
    {
        fprintf( stderr, "test_pos2ddd() 1: failed\n");
        return 0;
    }

    /* North West quadrant (+,-)
       Lexington Green, USA  42.471021, -71.353514
     */
    latitude = 25482612;
    longitude = -42812108;
    pos2ddd( latitude, longitude, &lat_dd, &long_ddd );
    if ((lat_dd!=42.471020000000003) || (long_ddd!=-71.353513333333339))
    {
        fprintf( stderr, "test_pos2ddd() 2: failed\n");
        return 0;
    }
    
    /* South East quadrant (-,+)
       Tasmania  -42.000951, 146.594319
     */
    latitude = -25200570;
    longitude = 87956591;
    pos2ddd( latitude, longitude, &lat_dd, &long_ddd );
    if ((lat_dd!=-42.000950000000003) || (long_ddd!=146.59431833333332))
    {
        fprintf( stderr, "test_pos2ddd() 3: failed\n");
        return 0;
    }
    
    /* South West quadrant (-,-)
       Bolivia  -17.668295, -62.777665
     */
    latitude = -10600977;
    longitude = -37666599;
    pos2ddd( latitude, longitude, &lat_dd, &long_ddd );
    if ((lat_dd!=-17.668295000000001) || (long_ddd!=-62.777664999999999))
    {
        fprintf( stderr, "test_pos2ddd() 4: failed\n");
        return 0;
    }
    
    /* Center */
    latitude = 0;
    longitude = 0;
    pos2ddd( latitude, longitude, &lat_dd, &long_ddd );
    if ((lat_dd!=0) || (long_ddd!=0))
    {
        fprintf( stderr, "test_pos2ddd() 5: failed\n");
        return 0;
    }

    fprintf( stderr, "test_pos2ddd() Passed\n");
    return 1;
}
Exemple #3
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;
}