nou vooruit, bij deze de decodering voor ais zoals ik die zelf ontworpen heb voor de multiview:
Het ware bitneuken.
Op de multiview kan je ook instellen wat het maximum ais bereik moet zijn.
/return distance between two points in thents of nmile
int calc_distance( double my_lat, double my_lon, double dest_lat, double dest_lon)
{
dest_lat = dest_lat / 10000000;
dest_lon = dest_lon / 10000000;
double dlon = deg2rad(dest_lon-my_lon);
double dlat = deg2rad(dest_lat-my_lat);
my_lat = deg2rad(my_lat);
dest_lat = deg2rad(dest_lat);
double a,d;
a = sin(dlat/2) * sin(dlat/2) + sin(dlon/2) * sin(dlon/2)* cos(my_lat) * cos(dest_lat) ;
d = 12745.6 * asin(sqrt(a));
d/= 0.1853;
return (int)d;
}
unsigned char decode_char(unsigned char c)
{
unsigned char value = c - '0';
if (value > 40)
value -= 8;
return value & 0x3f;
}
// !AIVDM,1,1,,B,177KQJ5000G?tO`K>RA1wUbN0TKH,0*5C
void decode_ais(int messptr)
{
unsigned char comma=0,ctr,ctr1;
unsigned long x;
char buf[200];
double lat,lon;
for(ctr=0;ctr<100;ctr++)
{
if (AIS.rxbuf[messptr]== ',')
comma++;
messptr++;
if(comma == 5)
break;
}
if(comma != 5)
{
usb_tx_mes(" NF ");
return; // not found
}
for(ctr=0;ctr<100;ctr++)
{
if (AIS.rxbuf[messptr] != ',')
buf[ctr]=decode_char(AIS.rxbuf[messptr++]);
else
break;
}
if((buf[0] == 1)|(buf[0] == 2)|(buf[0] == 3))
{
AIS_Boats.ais_rx_mess_type=1;
x = buf[1]&0xF;
x<<=6;
x |= buf[2];
x<<=6;
x |= buf[3];
x<<=6;
x |= buf[4];
x<<=6;
x |= buf[5];
x<<=2;
x |= (buf[6]>>4) & 0x3;//first 2
AIS_Boats.ais_rx_mmsi=x;
x= buf[6] & 0xF;//last 4
x = buf[7]; //first 6
x<<= 2;
x|= (buf[8]>>4) & 0x3; //first 2
x = buf[8] &0xf ;//last 4
x<<= 6;
x|= buf[9];
AIS_Boats.ais_rx_sog=x;
x = (buf[10]>>5) & 1; //6nd bit
x = buf[10] & 0x1f; //last bit 28
x<<=6;
x |= buf[11];
x<<=6;
x |= buf[12];
x<<=6;
x |= buf[13];
x<<=5;
x |= buf[14]>>1;//first 5
lon=x;
lon/=0.06;
AIS_Boats.ais_rx_lon=lon;
x = buf[14] & 1 ; // 27
x<<=6;
x |= buf[15] ; // 27
x<<=6;
x |= buf[16];
x<<=6;
x |= buf[17];
x<<=6;
x |= buf[18];
x<<=2;
x |= buf[19]>>4; //first 2
lat=x;
lat/=0.06;
AIS_Boats.ais_rx_lat=lat;
x= buf[19]& 0xF ; //cog 12 bits last 4
x<<=6;
x |= buf[20];
x<<=2;
x |= buf[21]>>4; //first 2
AIS_Boats.ais_rx_cog=x;
if(( AIS_Boats.mypos[0] != 0) && (lat<= 900000000))
{
AIS_Boats.ais_rx_distance = calc_distance( AIS_Boats.mypos[0], AIS_Boats.mypos[1], lat,lon);
if (AIS_Boats.ais_rx_distance < mem.set_ais_max)
{
add_ais_table_pos();
}
else
remove_ais_table_pos();
}
else
if(lat> 900000000)
remove_ais_table_pos();
}
else
if(buf[0] ==5)
{
AIS_Boats.ais_rx_mess_type=5;
x = buf[1]&0xF;
x<<=6;
x |= buf[2];
x<<=6;
x |= buf[3];
x<<=6;
x |= buf[4];
x<<=6;
x |= buf[5];
x<<=2;
x |= (buf[6]>>4) & 0x3;//first 2
AIS_Boats.ais_rx_mmsi=x;
ctr1=11;
for(ctr=0;ctr<7;ctr++)
{
x = buf[ctr1++]&3;
x<<=4;
x|= buf[ctr1]>>2;
x = ais_string[x];
if (x== '@')
{
AIS_Boats.ais_rx_callsign[ctr]=0;
break;
}
AIS_Boats.ais_rx_callsign[ctr]=x; //@ is eind
}
for(ctr=0;ctr<20;ctr++)
{
x = buf[ctr1++]&3;
x<<=4;
x|= buf[ctr1]>>2;
x = ais_string[x];
if (x== '@')
x= 0x20;
AIS_Boats.ais_rx_name[ctr]=x;
}
AIS_Boats.ais_rx_name[20]=0;
x = buf[ctr1++]&3; //last 2
x<<=6;
x|= buf[ctr1++];
AIS_Boats.ais_rx_ship_type=x; //shiptype 8 bits
add_ais_table_name_callsign();
}
else
if(buf[0] ==24)
{
AIS_Boats.ais_rx_mess_type=24;
x = buf[1]&0xF;
x<<=6;
x |= buf[2];
x<<=6;
x |= buf[3];
x<<=6;
x |= buf[4];
x<<=6;
x |= buf[5];
x<<=2;
x |= (buf[6]>>4) & 0x3;//first 2
AIS_Boats.ais_rx_mmsi=x;
if (((buf[6]>>2)&3) == 0) //partA
{
ctr1=6;
for(ctr=0;ctr<20;ctr++)
{
x = buf[ctr1++]&3;
x<<=4;
x|= buf[ctr1]>>2;
x = ais_string[x];
if (x== '@')
x= 0x20;
AIS_Boats.ais_rx_name[ctr]=x;
}
AIS_Boats.ais_rx_name[20]=0;
x = buf[ctr1++]&3; //last 2
x<<=6;
x|= buf[ctr1++];
AIS_Boats.ais_rx_ship_type=x; //shiptype 8 bits
add_ais_table_name();
}
else
if (((buf[6]>>2)&3) == 1) //partB 2 left after partnumber 50 bits overslaan voor call sign. -2 = 48 = 8 bytes
{
AIS_Boats.ais_rx_callsign[0]='-';
AIS_Boats.ais_rx_callsign[1]=0;
ctr1=15;
for(ctr=0;ctr<7;ctr++)
{
x = buf[ctr1++]&0x3F;
x = ais_string[x];
if (x== '@')
{
AIS_Boats.ais_rx_callsign[ctr]=0;
break;
}
AIS_Boats.ais_rx_callsign[ctr]=x; //@ is eind
}
add_ais_table_callsign();
}
}
else
if(buf[0] == 18)
{
AIS_Boats.ais_rx_mess_type=18;
x = buf[1]&0xF;
x<<=6;
x |= buf[2];
x<<=6;
x |= buf[3];
x<<=6;
x |= buf[4];
x<<=6;
x |= buf[5];
x<<=2;
x |= (buf[6]>>4) & 0x3; //30 bits mmsi
AIS_Boats.ais_rx_mmsi=x;
x= buf[6]; //4
x <<=4;
x |= (buf[7] >>2) & 0xf;//4
x = buf[7] &0x3;
x<<= 6;
x|= buf[8];
x<<=2 ;
x|= (buf[9]>>4) & 0x3;//first 2
AIS_Boats.ais_rx_sog= x;
x = buf[9] & 7; //last 3 28
x<<=6;
x |= buf[10];
x<<=6;
x |= buf[11];
x<<=6;
x |= buf[12];
x<<=6;
x |= buf[13];
x<<=1;
x |= ((buf[14]>>5) & 1) ;//first 1
lon=x;
lon/=0.060;
AIS_Boats.ais_rx_lon=lon;
x = buf[14] & 0x1F;//last 5 27
x<<=6;
x |= buf[15];
x<<=6;
x |= buf[16];
x<<=6;
x |= buf[17];
x<<=4;
x |= buf[18]>>2; //first 4
lat=x;
lat/=0.06;
AIS_Boats.ais_rx_lat=lat;
x= buf[18] & 0x3; //cog 12 bits
x<<=6;
x |= buf[19];
x<<=4;
x |= (buf[20]>>2); //first 4
AIS_Boats.ais_rx_cog=x;
if(( AIS_Boats.mypos[0] != 0) && (lat<= 900000000))
{
AIS_Boats.ais_rx_distance = calc_distance( AIS_Boats.mypos[0], AIS_Boats.mypos[1], lat,lon);
if (AIS_Boats.ais_rx_distance < mem.set_ais_max)
{
add_ais_table_pos();
}
else
{
remove_ais_table_pos();
}
}
else
if(lat> 900000000)
remove_ais_table_pos();
}
}