/* ----------------------------------------------------------------------- */ int __stdcall parse_seaway1_1( sixbit *state, seaway1_1 *result ) { int length; int i; int j; if( !state ) return 1; if( !result ) return 1; length = sixbit_length(state); if( (length < 0) || (length > 1008) ) return 2; /* Clear out the structure first */ memset( result, 0, sizeof( seaway1_1 ) ); for( i=0; i<4; i++ ) { if( get_timetag( state, &result->report[i].utc_time ) ) return 3; /* Get the Callsign, convert to ASCII */ j = 0; while( j != 7 ) { result->report[i].station_id[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->report[i].station_id[j] = 0; result->report[i].longitude = (long) get_6bit( state, 25 ); result->report[i].latitude = (long) get_6bit( state, 24 ); result->report[i].speed = (int) get_6bit( state, 10 ); result->report[i].gust = (int) get_6bit( state, 10 ); result->report[i].direction = (int) get_6bit( state, 9 ); result->report[i].pressure = (int) get_6bit( state, 14 ); result->report[i].air_temp = (int) get_6bit( state, 10 ); result->report[i].dew_point = (int) get_6bit( state, 10 ); result->report[i].visibility= (unsigned char) get_6bit( state, 8 ); result->report[i].water_temp= (int) get_6bit( state, 10 ); /* Convert the position to signed value */ result->report[i].longitude *= 10; result->report[i].latitude *= 10; conv_pos( &result->report[i].latitude, &result->report[i].longitude); /* Convert the air_temp, dew_point and water_temp to a signed value */ conv_sign( 0x0200, &result->report[i].air_temp); conv_sign( 0x0200, &result->report[i].dew_point); conv_sign( 0x0200, &result->report[i].water_temp); /* Is there enough data for another? */ if( sixbit_length(state) < 192) break; } return 0; }
template <int N, bool Xinv, bool Yinv> inline unsigned int Diagonal<N, Xinv, Yinv>::encode(const Board& b, Disc d) const { unsigned int ret = 0; for (int i = 0; i < N; i++) { ret = (ret << 1) + ret; ret += b.code_at(conv_pos(N-1 - i, i), d); } return ret; }
template <bool Xinv, bool Yinv> inline unsigned int Corner3x3<Xinv, Yinv>::encode(const Board& b, Disc d) const { unsigned int ret = 0; for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { ret = ret * 3 + b.code_at(conv_pos(x, y), d); } } return ret; }
/* ----------------------------------------------------------------------- */ int __stdcall parse_seaway1_3( sixbit *state, seaway1_3 *result ) { int length; int i; int j; if( !state ) return 1; if( !result ) return 1; length = sixbit_length(state); if( (length < 0) || (length > 1008) ) return 2; /* Clear out the structure first */ memset( result, 0, sizeof( seaway1_3 ) ); for( i=0; i<6; i++ ) { if( get_timetag( state, &result->report[i].utc_time ) ) return 3; /* Get the Callsign, convert to ASCII */ j = 0; while( j != 7 ) { result->report[i].station_id[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->report[i].station_id[j] = 0; result->report[i].longitude = (long) get_6bit( state, 25 ); result->report[i].latitude = (long) get_6bit( state, 24 ); result->report[i].type = (char) get_6bit( state, 1 ); result->report[i].level = (unsigned int) get_6bit( state, 16 ); result->report[i].datum = (char) get_6bit( state, 2 ); result->report[i].spare = (int) get_6bit( state, 14 ); /* Convert the position to signed value */ result->report[i].longitude *= 10; result->report[i].latitude *= 10; conv_pos( &result->report[i].latitude, &result->report[i].longitude); /* Convert level to a signed integer */ conv_sign( 0x8000, &result->report[i].level ); /* Is there enough data for another? */ if( sixbit_length(state) < 144) break; } return 0; }
/* ----------------------------------------------------------------------- */ int __stdcall parse_pawss1_5( sixbit *state, pawss1_5 *result ) { int length; int i; int j; if( !state ) return 1; if( !result ) return 1; length = sixbit_length(state); if( (length < 0) || (length > 1008) ) return 2; /* Clear out the structure first */ memset( result, 0, sizeof( pawss1_5 ) ); for( i=0; i<6; i++ ) { if( get_timetag( state, &result->report[i].utc_time ) ) return 3; /* Get the Callsign, convert to ASCII */ j = 0; while( j != 7 ) { result->report[i].station_id[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->report[i].station_id[j] = 0; result->report[i].longitude = (long) get_6bit( state, 25 ); result->report[i].latitude = (long) get_6bit( state, 24 ); result->report[i].salinity = (int) get_6bit( state, 10 ); result->report[i].water_temp= (int) get_6bit( state, 10 ); result->report[i].spare = (unsigned int) get_6bit( state, 13 ); /* Convert the position to signed value */ result->report[i].longitude *= 10; result->report[i].latitude *= 10; conv_pos( &result->report[i].latitude, &result->report[i].longitude); /* Convert water temp to signed value */ conv_sign( 0x0200, &result->report[i].water_temp); /* Is there enough data for another? */ if( sixbit_length(state) < 144) break; } return 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); } }
/* ----------------------------------------------------------------------- */ int __stdcall parse_pawss2_3( sixbit *state, pawss2_3 *result ) { int length; int i; int j; if( !state ) return 1; if( !result ) return 1; length = sixbit_length(state); if( (length < 0) || (length > 1008) ) return 2; /* Clear out the structure first */ memset( result, 0, sizeof( pawss2_3 ) ); if( get_timetag( state, &result->utc_time ) ) return 3; /* Get the Direction, convert to ASCII */ j = 0; while( j != 16 ) { result->direction[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->direction[j] = 0; result->longitude = (long) get_6bit( state, 25 ); result->latitude = (long) get_6bit( state, 24 ); result->spare2 = (char) get_6bit( state, 3 ); /* Convert the position to signed value */ result->longitude *= 10; result->latitude *= 10; conv_pos( &result->latitude, &result->longitude); for( i=0; i<4; i++ ) { result->report[i].order = (char) get_6bit( state, 5 ); /* Get the Vessel Name, convert to ASCII */ j = 0; while( j != 15 ) { result->report[i].vessel_name[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->report[i].vessel_name[j] = 0; /* Get the Vessel Name, convert to ASCII */ j = 0; while( j != 13 ) { result->report[i].position_name[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->report[i].position_name[j] = 0; result->report[i].time_hh = (char) get_6bit( state, 5 ); result->report[i].time_mm = (char) get_6bit( state, 6 ); result->report[i].spare = (char) get_6bit( state, 6 ); /* Is there enough data for another? */ if( sixbit_length(state) < 184) break; } return 0; }
/* ----------------------------------------------------------------------- */ int __stdcall parse_seaway2_1( sixbit *state, seaway2_1 *result ) { int length; int i; int j; if( !state ) return 1; if( !result ) return 1; length = sixbit_length(state); if( (length < 0) || (length > 1008) ) return 2; /* Clear out the structure first */ memset( result, 0, sizeof( seaway2_1 ) ); if( get_timetag( state, &result->utc_time ) ) return 3; /* Get the Callsign, convert to ASCII */ j = 0; while( j != 7 ) { result->lock_id[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->lock_id[j] = 0; result->longitude = (long) get_6bit( state, 25 ); result->latitude = (long) get_6bit( state, 24 ); result->spare2 = (int) get_6bit( state, 9 ); /* Convert the position to signed value */ result->longitude *= 10; result->latitude *= 10; conv_pos( &result->latitude, &result->longitude); for( i=0; i<6; i++ ) { /* Get the Callsign, convert to ASCII */ j = 0; while( j != 15 ) { result->schedule[i].name[j] = ais2ascii( (char) get_6bit( state, 6 )); j++; } result->schedule[i].name[j] = 0; result->schedule[i].direction = (char) get_6bit( state, 1 ); if ( get_timetag( state, &result->schedule[i].eta ) ) return 4; result->schedule[i].spare = (int) get_6bit( state, 9 ); /* Is there enough data for another? */ if( sixbit_length(state) < 120) break; } return 0; }
int test_conv_pos( void ) { long latitude; long longitude; /* North East quadrant (+,+) Trondheim, Norway 63.416277, 10.412227 */ latitude = 38049766; longitude = 6247336; conv_pos( &latitude, &longitude ); if ((latitude!=38049766) || (longitude!=6247336)) { fprintf( stderr, "test_conv_pos() 1: failed\n"); return 0; } /* North West quadrant (+,-) Lexington Green, USA 42.471021, -71.353514 */ latitude = 25482612; longitude = 225623348; conv_pos( &latitude, &longitude ); if ((latitude!=25482612) || (longitude!=-42812108)) { fprintf( stderr, "test_conv_pos() 2: failed\n"); return 0; } /* South East quadrant (-,+) Tasmania -42.000951, 146.594319 */ latitude = 109017158; longitude = 87956591; conv_pos( &latitude, &longitude ); if ((latitude!=-25200570) || (longitude!=87956591)) { fprintf( stderr, "test_conv_pos() 3: failed\n"); return 0; } /* South West quadrant (-,-) Bolivia -17.668295, -62.777665 */ latitude = 123616751; longitude = 230768857; conv_pos( &latitude, &longitude ); if ((latitude!=-10600977) || (longitude!=-37666599)) { fprintf( stderr, "test_conv_pos() 4: failed\n"); return 0; } /* Center */ latitude = 0; longitude = 0; conv_pos( &latitude, &longitude ); if ((latitude!=0) || (longitude!=0)) { fprintf( stderr, "test_conv_pos() 5: failed\n"); return 0; } fprintf( stderr, "test_conv_pos() Passed\n"); return 1; }