55 0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178,
56 0x2c38bc, 0x161c5e, 0x0b0e2f, 0xfa7d13, 0x82c48d, 0xbe9842, 0x5f4c21, 0xd05c14,
57 0x682e0a, 0x341705, 0xe5f186, 0x72f8c3, 0xc68665, 0x9cb936, 0x4e5c9b, 0xd8d449,
58 0x939020, 0x49c810, 0x24e408, 0x127204, 0x093902, 0x049c81, 0xfdb444, 0x7eda22,
59 0x3f6d11, 0xe04c8c, 0x702646, 0x381323, 0xe3f395, 0x8e03ce, 0x4701e7, 0xdc7af7,
60 0x91c77f, 0xb719bb, 0xa476d9, 0xadc168, 0x56e0b4, 0x2b705a, 0x15b82d, 0xf52612,
61 0x7a9309, 0xc2b380, 0x6159c0, 0x30ace0, 0x185670, 0x0c2b38, 0x06159c, 0x030ace,
62 0x018567, 0xff38b7, 0x80665f, 0xbfc92b, 0xa01e91, 0xaff54c, 0x57faa6, 0x2bfd53,
63 0xea04ad, 0x8af852, 0x457c29, 0xdd4410, 0x6ea208, 0x375104, 0x1ba882, 0x0dd441,
64 0xf91024, 0x7c8812, 0x3e4409, 0xe0d800, 0x706c00, 0x383600, 0x1c1b00, 0x0e0d80,
65 0x0706c0, 0x038360, 0x01c1b0, 0x00e0d8, 0x00706c, 0x003836, 0x001c1b, 0xfff409,
66 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
67 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
68 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
74 int offset = (bits == 112) ? 0 : (112-56);
75 uint8_t theByte = *msg;
81 for(j = 0; j < bits; j++) {
86 if (theByte & 0x80) {crc ^= *pCRCTable;}
88 theByte = theByte << 1;
91 rem = (msg[0] << 16) | (msg[1] << 8) | msg[2];
92 return ((crc ^ rem) & 0x00FFFFFF);
215 (MODES_LONG_MSG_BITS+MODES_LONG_MSG_BITS*(MODES_LONG_MSG_BITS-1)/2)
244 int bytepos0 = (i >> 3);
245 int mask0 = 1 << (7 - (i & 7));
246 msg[bytepos0] ^= mask0;
254 if (
Modes.nfix_crc > 1) {
256 int bytepos1 = (j >> 3);
257 int mask1 = 1 << (7 - (j & 7));
258 msg[bytepos1] ^= mask1;
269 msg[bytepos1] ^= mask1;
272 msg[bytepos0] ^= mask0;
307 int bitpos, offset, res, i;
308 memset(&ei, 0,
sizeof(
struct errorinfo));
317 if (maxfix < pei->bits) {
323 for (i = 0; i < pei->
bits; i++) {
324 bitpos = pei->
pos[i] - offset;
325 if ((bitpos < 0) || (bitpos >= bits)) {
331 for (i = res = 0; i < pei->
bits; i++) {
332 bitpos = pei->
pos[i] - offset;
333 msg[bitpos >> 3] ^= (1 << (7 - (bitpos & 7)));
335 fixedbits[res++] = bitpos;
358 int div = magnitude / 256 / 4;
359 int rem = magnitude / 256 % 4;
366 printf(
"[%.3d] |%-66s 0x%04X\n", index, buf, magnitude);
368 printf(
"[%.2d] |%-66s 0x%04X\n", index, buf, magnitude);
383 uint32_t padding = 5;
384 uint32_t start = (offset < padding) ? 0 : offset-padding;
388 for (j = start; j <= end; j++) {
399 uint16_t *
m, uint32_t offset,
int fixable,
char *bitpos)
402 int start = offset - padding;
408 if ((fp = fopen(
"frames.js",
"a")) == NULL) {
409 fprintf(stderr,
"Error opening frames.js: %s\n", strerror(errno));
413 fprintf(fp,
"frames.push({\"descr\": \"%s\", \"mag\": [", descr);
414 for (j = start; j <= end; j++) {
415 fprintf(fp,
"%d", j < 0 ? 0 : m[j]);
416 if (j != end) fprintf(fp,
",");
418 fprintf(fp,
"], \"fix1\": %d, \"fix2\": %d, \"bits\": %d, \"hex\": \"",
421 fprintf(fp,
"\\x%02x",msg[j]);
422 fprintf(fp,
"\"});\n");
442 int msgtype = msg[0] >> 3;
458 printf(
"\n--- %s\n ", descr);
460 printf(
"%02x",msg[j]);
463 printf(
" (DF %d, Fixable: %d)\n", msgtype, fixable);
601 a = ((a >> 16) ^ a) * 0x45d9f3b;
602 a = ((a >> 16) ^ a) * 0x45d9f3b;
615 Modes.icao_cache[h*2] = addr;
616 Modes.icao_cache[h*2+1] = (uint32_t) time(NULL);
627 uint32_t
a =
Modes.icao_cache[h*2];
628 uint32_t t =
Modes.icao_cache[h*2+1];
629 uint64_t tn = time(NULL);
651 if (ID13Field & 0x1000) {hexGillham |= 0x0010;}
652 if (ID13Field & 0x0800) {hexGillham |= 0x1000;}
653 if (ID13Field & 0x0400) {hexGillham |= 0x0020;}
654 if (ID13Field & 0x0200) {hexGillham |= 0x2000;}
655 if (ID13Field & 0x0100) {hexGillham |= 0x0040;}
656 if (ID13Field & 0x0080) {hexGillham |= 0x4000;}
658 if (ID13Field & 0x0020) {hexGillham |= 0x0100;}
659 if (ID13Field & 0x0010) {hexGillham |= 0x0001;}
660 if (ID13Field & 0x0008) {hexGillham |= 0x0200;}
661 if (ID13Field & 0x0004) {hexGillham |= 0x0002;}
662 if (ID13Field & 0x0002) {hexGillham |= 0x0400;}
663 if (ID13Field & 0x0001) {hexGillham |= 0x0004;}
674 int m_bit = AC13Field & 0x0040;
675 int q_bit = AC13Field & 0x0010;
681 int n = ((AC13Field & 0x1F80) >> 2) |
682 ((AC13Field & 0x0020) >> 1) |
683 (AC13Field & 0x000F);
685 return ((n * 25) - 1000);
689 if (n < -12) {n = 0;}
705 int q_bit = AC12Field & 0x10;
710 int n = ((AC12Field & 0x0FE0) >> 1) |
711 (AC12Field & 0x000F);
713 return ((n * 25) - 1000);
716 int n = ((AC12Field & 0x0FC0) << 1) |
717 (AC12Field & 0x003F);
719 if (n < -12) {n = 0;}
735 if (movement > 123) gspeed = 199;
736 else if (movement > 108) gspeed = ((movement - 108) * 5) + 100;
737 else if (movement > 93) gspeed = ((movement - 93) * 2) + 70;
738 else if (movement > 38) gspeed = ((movement - 38) ) + 15;
739 else if (movement > 12) gspeed = ((movement - 11) >> 1) + 2;
740 else if (movement > 8) gspeed = ((movement - 6) >> 2) + 1;
750 "Level 1 (Survillance Only)",
751 "Level 2 (DF0,4,5,11)",
752 "Level 3 (DF0,4,5,11,20,21)",
753 "Level 4 (DF0,4,5,11,20,21,24)",
754 "Level 2+3+4 (DF0,4,5,11,20,21,24,code7 - is on ground)",
755 "Level 2+3+4 (DF0,4,5,11,20,21,24,code7 - is airborne)",
756 "Level 2+3+4 (DF0,4,5,11,20,21,24,code7)",
762 "ADS-B ES/NT device with ICAO 24-bit address",
763 "ADS-B ES/NT device with other address",
765 "Coarse format TIS-B",
766 "TIS-B managment message",
767 "TIS-B relay of ADS-B message with other address",
768 "ADS-B rebroadcast using DF-17 message format",
775 "Normal, On the ground",
777 "ALERT, On the ground",
778 "ALERT & Special Position Identification. Airborne or Ground",
779 "Special Position Identification. Airborne or Ground",
780 "Value 6 is not assigned",
781 "Value 7 is not assigned"
787 char *mename =
"Unknown";
789 if (metype >= 1 && metype <= 4)
790 mename =
"Aircraft Identification and Category";
791 else if (metype >= 5 && metype <= 8)
792 mename =
"Surface Position";
793 else if (metype >= 9 && metype <= 18)
794 mename =
"Airborne Position (Baro Altitude)";
795 else if (metype == 19 && mesub >=1 && mesub <= 4)
796 mename =
"Airborne Velocity";
797 else if (metype >= 20 && metype <= 22)
798 mename =
"Airborne Position (GNSS Height)";
799 else if (metype == 23 && mesub == 0)
800 mename =
"Test Message";
801 else if (metype == 24 && mesub == 1)
802 mename =
"Surface System Status";
803 else if (metype == 28 && mesub == 1)
804 mename =
"Extended Squitter Aircraft Status (Emergency)";
805 else if (metype == 28 && mesub == 2)
806 mename =
"Extended Squitter Aircraft Status (1090ES TCAS RA)";
807 else if (metype == 29 && (mesub == 0 || mesub == 1))
808 mename =
"Target State and Status Message";
809 else if (metype == 31 && (mesub == 0 || mesub == 1))
810 mename =
"Aircraft Operational Status Message";
820 char *ais_charset =
"?ABCDEFGHIJKLMNOPQRSTUVWXYZ????? ???????????????0123456789??????";
847 uint32_t ulAddr = (msg[1] << 16) | (msg[2] << 8) | (msg[3]);
858 mm->
addr = (msg[1] << 16) | (msg[2] << 8) | (msg[3]);
859 mm->
ca = (msg[0] & 0x07);
864 }
else if (mm->
crc < 80) {
871 }
else if (mm->
msgtype == 17) {
872 mm->
addr = (msg[1] << 16) | (msg[2] << 8) | (msg[3]);
873 mm->
ca = (msg[0] & 0x07);
880 }
else if (mm->
msgtype == 18) {
881 mm->
addr = (msg[1] << 16) | (msg[2] << 8) | (msg[3]);
882 mm->
ca = (msg[0] & 0x07);
908 }
else if (mm->
ca == 5) {
915 int ID13Field = ((msg[2] << 8) | msg[3]) & 0x1FFF;
925 int AC13Field = ((msg[2] << 8) | msg[3]) & 0x1FFF;
946 || ((mm->
msgtype == 18) && ((mm->
ca == 0) || (mm->
ca == 1) || (mm->
ca == 6)) )) {
947 int metype = mm->
metype = msg[4] >> 3;
948 int mesub = mm->
mesub = msg[4] & 7;
952 if (metype >= 1 && metype <= 4) {
956 chars = (msg[5] << 16) | (msg[6] << 8) | (msg[7]);
957 mm->
flight[3] = ais_charset[chars & 0x3F]; chars = chars >> 6;
958 mm->
flight[2] = ais_charset[chars & 0x3F]; chars = chars >> 6;
959 mm->
flight[1] = ais_charset[chars & 0x3F]; chars = chars >> 6;
960 mm->
flight[0] = ais_charset[chars & 0x3F];
962 chars = (msg[8] << 16) | (msg[9] << 8) | (msg[10]);
963 mm->
flight[7] = ais_charset[chars & 0x3F]; chars = chars >> 6;
964 mm->
flight[6] = ais_charset[chars & 0x3F]; chars = chars >> 6;
965 mm->
flight[5] = ais_charset[chars & 0x3F]; chars = chars >> 6;
966 mm->
flight[4] = ais_charset[chars & 0x3F];
970 }
else if (metype >= 5 && metype <= 18) {
971 mm->
raw_latitude = ((msg[6] & 3) << 15) | (msg[7] << 7) | (msg[8] >> 1);
972 mm->
raw_longitude = ((msg[8] & 1) << 16) | (msg[9] << 8) | (msg[10]);
976 int AC12Field = ((msg[5] << 4) | (msg[6] >> 4)) & 0x0FFF;
983 int movement = ((msg[4] << 4) | (msg[5] >> 4)) & 0x007F;
985 if ((movement) && (movement < 125)) {
992 mm->
heading = ((((msg[5] << 4) | (msg[6] >> 4)) & 0x007F) * 45) >> 4;
996 }
else if (metype == 19) {
1001 if ( (mesub >= 1) && (mesub <= 4) ) {
1002 int vert_rate = ((msg[8] & 0x07) << 6) | (msg[9] >> 2);
1006 {vert_rate = 0 - vert_rate;}
1012 if ((mesub == 1) || (mesub == 2)) {
1013 int ew_raw = ((msg[5] & 0x03) << 8) | msg[6];
1014 int ew_vel = ew_raw - 1;
1015 int ns_raw = ((msg[7] & 0x7F) << 3) | (msg[8] >> 5);
1016 int ns_vel = ns_raw - 1;
1019 ns_vel = ns_vel << 2;
1020 ew_vel = ew_vel << 2;
1026 {ew_vel = 0 - ew_vel;}
1033 {ns_vel = 0 - ns_vel;}
1037 if (ew_raw && ns_raw) {
1040 mm->
velocity = (int)
sqrt((ns_vel * ns_vel) + (ew_vel * ew_vel));
1043 mm->
heading = (int) (atan2(ew_vel, ns_vel) * 180.0 / M_PI);
1049 }
else if (mesub == 3 || mesub == 4) {
1050 int airspeed = ((msg[7] & 0x7f) << 3) | (msg[8] >> 5);
1055 {airspeed = airspeed << 2;}
1059 if (msg[5] & 0x04) {
1061 mm->
heading = ((((msg[5] & 0x03) << 8) | msg[6]) * 45) >> 7;
1070 if (msg[4] == 0x20) {
1074 chars = (msg[5] << 16) | (msg[6] << 8) | (msg[7]);
1075 mm->
flight[3] = ais_charset[chars & 0x3F]; chars = chars >> 6;
1076 mm->
flight[2] = ais_charset[chars & 0x3F]; chars = chars >> 6;
1077 mm->
flight[1] = ais_charset[chars & 0x3F]; chars = chars >> 6;
1078 mm->
flight[0] = ais_charset[chars & 0x3F];
1080 chars = (msg[8] << 16) | (msg[9] << 8) | (msg[10]);
1081 mm->
flight[7] = ais_charset[chars & 0x3F]; chars = chars >> 6;
1082 mm->
flight[6] = ais_charset[chars & 0x3F]; chars = chars >> 6;
1083 mm->
flight[5] = ais_charset[chars & 0x3F]; chars = chars >> 6;
1084 mm->
flight[4] = ais_charset[chars & 0x3F];
1099 unsigned char * pTimeStamp;
1102 if (
Modes.onlyaddr) {
1103 printf(
"%06x\n", mm->
addr);
1113 if (
Modes.print_timestamp) {
1114 printf(
"%llu ",
mstime());
1121 for (j=5; j>=0;j--) {
1122 printf(
"%02X",pTimeStamp[j]);
1127 for (j = 0; j < mm->
msgbits/8; j++) printf(
"%02x", mm->
msg[j]);
1136 printf(
"CRC: %06x (%s)\n", (
int)mm->
crc, mm->
crcok ?
"ok" :
"wrong");
1142 printf(
"DF 0: Short Air-Air Surveillance.\n");
1143 printf(
" VS : %s\n", (mm->
msg[0] & 0x04) ?
"Ground" :
"Airborne");
1144 printf(
" CC : %d\n", ((mm->
msg[0] & 0x02) >> 1));
1145 printf(
" SL : %d\n", ((mm->
msg[1] & 0xE0) >> 5));
1146 printf(
" Altitude : %d %s\n", mm->
altitude,
1148 printf(
" ICAO Address : %06x\n", mm->
addr);
1151 printf(
"DF %d: %s, Altitude Reply.\n", mm->
msgtype,
1152 (mm->
msgtype == 4) ?
"Surveillance" :
"Comm-B");
1153 printf(
" Flight Status : %s\n",
fs_str[mm->
fs]);
1154 printf(
" DR : %d\n", ((mm->
msg[1] >> 3) & 0x1F));
1155 printf(
" UM : %d\n", (((mm->
msg[1] & 7) << 3) | (mm->
msg[2] >> 5)));
1156 printf(
" Altitude : %d %s\n", mm->
altitude,
1158 printf(
" ICAO Address : %06x\n", mm->
addr);
1161 printf(
" Comm-B BDS : %x\n", mm->
msg[4]);
1164 if ( mm->
msg[4] == 0x20) {
1165 printf(
" BDS 2,0 Aircraft Identification : %s\n", mm->
flight);
1186 printf(
"DF %d: %s, Identity Reply.\n", mm->
msgtype,
1187 (mm->
msgtype == 5) ?
"Surveillance" :
"Comm-B");
1188 printf(
" Flight Status : %s\n",
fs_str[mm->
fs]);
1189 printf(
" DR : %d\n", ((mm->
msg[1] >> 3) & 0x1F));
1190 printf(
" UM : %d\n", (((mm->
msg[1] & 7) << 3) | (mm->
msg[2] >> 5)));
1191 printf(
" Squawk : %x\n", mm->
modeA);
1192 printf(
" ICAO Address : %06x\n", mm->
addr);
1195 printf(
" Comm-B BDS : %x\n", mm->
msg[4]);
1198 if ( mm->
msg[4] == 0x20) {
1199 printf(
" BDS 2,0 Aircraft Identification : %s\n", mm->
flight);
1219 }
else if (mm->
msgtype == 11) {
1220 printf(
"DF 11: All Call Reply.\n");
1221 printf(
" Capability : %d (%s)\n", mm->
ca,
ca_str[mm->
ca]);
1222 printf(
" ICAO Address: %06x\n", mm->
addr);
1224 {printf(
" IID : SI-%02d\n", mm->
iid-16);}
1226 {printf(
" IID : II-%02d\n", mm->
iid);}
1228 }
else if (mm->
msgtype == 16) {
1229 printf(
"DF 16: Long Air to Air ACAS\n");
1230 printf(
" VS : %s\n", (mm->
msg[0] & 0x04) ?
"Ground" :
"Airborne");
1231 printf(
" CC : %d\n", ((mm->
msg[0] & 0x02) >> 1));
1232 printf(
" SL : %d\n", ((mm->
msg[1] & 0xE0) >> 5));
1233 printf(
" Altitude : %d %s\n", mm->
altitude,
1235 printf(
" ICAO Address : %06x\n", mm->
addr);
1237 }
else if (mm->
msgtype == 17) {
1238 printf(
"DF 17: ADS-B message.\n");
1239 printf(
" Capability : %d (%s)\n", mm->
ca,
ca_str[mm->
ca]);
1240 printf(
" ICAO Address : %06x\n", mm->
addr);
1241 printf(
" Extended Squitter Type: %d\n", mm->
metype);
1242 printf(
" Extended Squitter Sub : %d\n", mm->
mesub);
1247 printf(
" Aircraft Type : %c%d\n", (
'A' + 4 - mm->
metype), mm->
mesub);
1248 printf(
" Identification : %s\n", mm->
flight);
1253 printf(
" F flag : %s\n", (mm->
msg[6] & 0x04) ?
"odd" :
"even");
1254 printf(
" T flag : %s\n", (mm->
msg[6] & 0x08) ?
"UTC" :
"non-UTC");
1255 printf(
" Altitude : %d feet\n", mm->
altitude);
1257 printf(
" Latitude : %f\n", mm->
fLat);
1258 printf(
" Longitude: %f\n", mm->
fLon);
1260 printf(
" Latitude : %d (not decoded)\n", mm->
raw_latitude);
1261 printf(
" Longitude: %d (not decoded)\n", mm->
raw_longitude);
1264 }
else if (mm->
metype == 19) {
1271 printf(
" Vertical rate src : %d\n", ((mm->
msg[8] >> 4) & 1));
1272 printf(
" Vertical rate : %d\n", mm->
vert_rate);
1274 }
else if (mm->
mesub == 3 || mm->
mesub == 4) {
1276 printf(
" Heading : %d\n", mm->
heading);
1278 printf(
" Airspeed : %d\n", mm->
velocity);
1280 printf(
" Vertical rate src : %d\n", ((mm->
msg[8] >> 4) & 1));
1281 printf(
" Vertical rate : %d\n", mm->
vert_rate);
1284 printf(
" Unrecognized ME subtype: %d subtype: %d\n", mm->
metype, mm->
mesub);
1290 printf(
" Unrecognized ME type: %d subtype: %d\n", mm->
metype, mm->
mesub);
1293 }
else if (mm->
msgtype == 18) {
1294 printf(
"DF 18: Extended Squitter.\n");
1295 printf(
" Control Field : %d (%s)\n", mm->
ca,
cf_str[mm->
ca]);
1296 if ((mm->
ca == 0) || (mm->
ca == 1) || (mm->
ca == 6)) {
1298 printf(
" Other Address : %06x\n", mm->
addr);
1300 printf(
" ICAO Address : %06x\n", mm->
addr);
1302 printf(
" Extended Squitter Type: %d\n", mm->
metype);
1303 printf(
" Extended Squitter Sub : %d\n", mm->
mesub);
1308 printf(
" Aircraft Type : %c%d\n", (
'A' + 4 - mm->
metype), mm->
mesub);
1309 printf(
" Identification : %s\n", mm->
flight);
1314 printf(
" F flag : %s\n", (mm->
msg[6] & 0x04) ?
"odd" :
"even");
1315 printf(
" T flag : %s\n", (mm->
msg[6] & 0x08) ?
"UTC" :
"non-UTC");
1316 printf(
" Altitude : %d feet\n", mm->
altitude);
1318 printf(
" Latitude : %f\n", mm->
fLat);
1319 printf(
" Longitude: %f\n", mm->
fLon);
1321 printf(
" Latitude : %d (not decoded)\n", mm->
raw_latitude);
1322 printf(
" Longitude: %d (not decoded)\n", mm->
raw_longitude);
1325 }
else if (mm->
metype == 19) {
1332 printf(
" Vertical rate src : %d\n", ((mm->
msg[8] >> 4) & 1));
1333 printf(
" Vertical rate : %d\n", mm->
vert_rate);
1335 }
else if (mm->
mesub == 3 || mm->
mesub == 4) {
1337 printf(
" Heading : %d\n", mm->
heading);
1339 printf(
" Airspeed : %d\n", mm->
velocity);
1341 printf(
" Vertical rate src : %d\n", ((mm->
msg[8] >> 4) & 1));
1342 printf(
" Vertical rate : %d\n", mm->
vert_rate);
1345 printf(
" Unrecognized ME subtype: %d subtype: %d\n", mm->
metype, mm->
mesub);
1351 printf(
" Unrecognized ME type: %d subtype: %d\n", mm->
metype, mm->
mesub);
1355 }
else if (mm->
msgtype == 19) {
1356 printf(
"DF 19: Military Extended Squitter.\n");
1358 }
else if (mm->
msgtype == 22) {
1359 printf(
"DF 22: Military Use.\n");
1361 }
else if (mm->
msgtype == 24) {
1362 printf(
"DF 24: Comm D Extended Length Message.\n");
1364 }
else if (mm->
msgtype == 32) {
1365 printf(
"SSR : Mode A/C Reply.\n");
1366 if (mm->
fs & 0x0080) {
1367 printf(
" Mode A : %04x IDENT\n", mm->
modeA);
1369 printf(
" Mode A : %04x\n", mm->
modeA);
1371 {printf(
" Mode C : %d feet\n", mm->
altitude);}
1375 printf(
"DF %d: Unknown DF Format.\n", mm->
msgtype);
1388 uint16_t *
p =
Modes.data;
1396 *m++ =
Modes.maglut[*p++];
1410 if (pPreamble[ 3] > pPreamble[2]/3)
return 1;
1411 if (pPreamble[10] > pPreamble[9]/3)
return 1;
1412 if (pPreamble[ 6] > pPreamble[7]/3)
return -1;
1413 if (pPreamble[-1] > pPreamble[1]/3)
return -1;
1452 if (pPayload[0] > pPayload[1]) {
1453 pPayload[2] = (pPayload[2] * 5) / 4;
1455 pPayload[2] = (pPayload[2] * 4) / 5;
1471 int use_correction = 0;
1473 memset(&mm, 0,
sizeof(mm));
1498 for (j = 0; j < mlen; j++) {
1499 int high, i, errors, errors56, errorsTy;
1500 uint16_t *pPreamble, *pPayload, *pPtr;
1501 uint8_t theByte, theErrs;
1502 int msglen, scanlen, sigStrength;
1514 if (!use_correction)
1532 Modes.stat_ModeAC++;
1540 if (!(pPreamble[0] > pPreamble[1] &&
1541 pPreamble[1] < pPreamble[2] &&
1542 pPreamble[2] > pPreamble[3] &&
1543 pPreamble[3] < pPreamble[0] &&
1544 pPreamble[4] < pPreamble[0] &&
1545 pPreamble[5] < pPreamble[0] &&
1546 pPreamble[6] < pPreamble[0] &&
1547 pPreamble[7] > pPreamble[8] &&
1548 pPreamble[8] < pPreamble[9] &&
1549 pPreamble[9] > pPreamble[6]))
1553 dumpRawMessage(
"Unexpected ratio among first 10 samples", msg, m, j);
1561 high = (pPreamble[0] + pPreamble[2] + pPreamble[7] + pPreamble[9]) / 6;
1562 if (pPreamble[4] >= high ||
1563 pPreamble[5] >= high)
1567 dumpRawMessage(
"Too high level in samples between 3 and 6", msg, m, j);
1574 if (pPreamble[11] >= high ||
1575 pPreamble[12] >= high ||
1576 pPreamble[13] >= high ||
1577 pPreamble[14] >= high)
1581 dumpRawMessage(
"Too high level in samples between 10 and 15", msg, m, j);
1584 Modes.stat_valid_preamble++;
1591 memcpy(aux, pPayload,
sizeof(aux));
1593 Modes.stat_out_of_phase++;
1603 theErrs = 0; errorsTy = 0;
1604 errors = 0; errors56 = 0;
1608 sigStrength = (pPreamble[0]-pPreamble[1])
1609 + (pPreamble[2]-pPreamble[3])
1610 + (pPreamble[7]-pPreamble[6])
1611 + (pPreamble[9]-pPreamble[8]);
1614 for (i = 0; i < scanlen; i++) {
1615 uint32_t
a = *pPtr++;
1616 uint32_t
b = *pPtr++;
1619 {theByte |= 1;
if (i < 56) {sigStrength += (a-
b);}}
1621 {
if (i < 56) {sigStrength += (b-
a);}}
1627 {errorsTy = errors56 = ++errors; theErrs |= 1; }
1629 {errorsTy = errors56 = ++errors; theErrs |= 1; theByte |= 1;}
1632 {*pMsg++ = theByte;}
1639 theByte = theByte << 1;
1641 {theErrs = theErrs << 1;}
1649 }
else if ((errorsTy == 1) && (theErrs == 0x80)) {
1658 msg[0] ^= theErrs; errorsTy = 0;
1660 Modes.stat_DF_Len_Corrected++;
1676 if (msglen > i) {msglen = i;}
1677 else if (msglen < i) {msglen = 0;}
1684 if ((msglen) && (errorsTy == 1) && (theErrs & 0x78)) {
1687 int thisDF = ((theByte = msg[0]) >> 3) & 0x1f;
1688 uint32_t validDFbits = 0x017F0831;
1689 uint32_t thisDFbit = (1 << thisDF);
1690 if (0 == (validDFbits & thisDFbit)) {
1694 thisDF = (theByte >> 3) & 0x1f;
1695 thisDFbit = (1 << thisDF);
1697 if (validDFbits & thisDFbit) {
1700 Modes.stat_DF_Type_Corrected++;
1708 sigStrength = (sigStrength + 29) / 60;
1719 sigStrength = (sigStrength + 0x7F) >> 8;
1720 mm.
signalLevel = ((sigStrength < 255) ? sigStrength : 255);
1730 if (use_correction) {
1732 case 0: {
Modes.stat_ph_demodulated0++;
break;}
1733 case 1: {
Modes.stat_ph_demodulated1++;
break;}
1734 case 2: {
Modes.stat_ph_demodulated2++;
break;}
1735 default:{
Modes.stat_ph_demodulated3++;
break;}
1739 case 0: {
Modes.stat_demodulated0++;
break;}
1740 case 1: {
Modes.stat_demodulated1++;
break;}
1741 case 2: {
Modes.stat_demodulated2++;
break;}
1742 default:{
Modes.stat_demodulated3++;
break;}
1747 if (use_correction) {
1749 else {
Modes.stat_ph_badcrc++;}
1752 else {
Modes.stat_badcrc++;}
1755 }
else if (use_correction) {
1756 Modes.stat_ph_badcrc++;
1757 Modes.stat_ph_fixed++;
1764 Modes.stat_badcrc++;
1775 if (use_correction) {
1797 printf(
"The following message has %d demod errors\n", errors);
1804 use_correction = 1; j--;
1813 Modes.net_output_raw_rate_count++;
1814 if (
Modes.net_output_raw_rate_count >
Modes.net_output_raw_rate)
1816 if (
Modes.rawOutUsed) {
1818 Modes.rawOutUsed = 0;
1820 if (
Modes.beastOutUsed) {
1822 Modes.beastOutUsed = 0;
1824 Modes.net_output_raw_rate_count = 0;
1860 if (res < 0) res +=
b;
1869 if (lat < 0) lat = -lat;
1870 if (lat < 10.47047130)
return 59;
1871 if (lat < 14.82817437)
return 58;
1872 if (lat < 18.18626357)
return 57;
1873 if (lat < 21.02939493)
return 56;
1874 if (lat < 23.54504487)
return 55;
1875 if (lat < 25.82924707)
return 54;
1876 if (lat < 27.93898710)
return 53;
1877 if (lat < 29.91135686)
return 52;
1878 if (lat < 31.77209708)
return 51;
1879 if (lat < 33.53993436)
return 50;
1880 if (lat < 35.22899598)
return 49;
1881 if (lat < 36.85025108)
return 48;
1882 if (lat < 38.41241892)
return 47;
1883 if (lat < 39.92256684)
return 46;
1884 if (lat < 41.38651832)
return 45;
1885 if (lat < 42.80914012)
return 44;
1886 if (lat < 44.19454951)
return 43;
1887 if (lat < 45.54626723)
return 42;
1888 if (lat < 46.86733252)
return 41;
1889 if (lat < 48.16039128)
return 40;
1890 if (lat < 49.42776439)
return 39;
1891 if (lat < 50.67150166)
return 38;
1892 if (lat < 51.89342469)
return 37;
1893 if (lat < 53.09516153)
return 36;
1894 if (lat < 54.27817472)
return 35;
1895 if (lat < 55.44378444)
return 34;
1896 if (lat < 56.59318756)
return 33;
1897 if (lat < 57.72747354)
return 32;
1898 if (lat < 58.84763776)
return 31;
1899 if (lat < 59.95459277)
return 30;
1900 if (lat < 61.04917774)
return 29;
1901 if (lat < 62.13216659)
return 28;
1902 if (lat < 63.20427479)
return 27;
1903 if (lat < 64.26616523)
return 26;
1904 if (lat < 65.31845310)
return 25;
1905 if (lat < 66.36171008)
return 24;
1906 if (lat < 67.39646774)
return 23;
1907 if (lat < 68.42322022)
return 22;
1908 if (lat < 69.44242631)
return 21;
1909 if (lat < 70.45451075)
return 20;
1910 if (lat < 71.45986473)
return 19;
1911 if (lat < 72.45884545)
return 18;
1912 if (lat < 73.45177442)
return 17;
1913 if (lat < 74.43893416)
return 16;
1914 if (lat < 75.42056257)
return 15;
1915 if (lat < 76.39684391)
return 14;
1916 if (lat < 77.36789461)
return 13;
1917 if (lat < 78.33374083)
return 12;
1918 if (lat < 79.29428225)
return 11;
1919 if (lat < 80.24923213)
return 10;
1920 if (lat < 81.19801349)
return 9;
1921 if (lat < 82.13956981)
return 8;
1922 if (lat < 83.07199445)
return 7;
1923 if (lat < 83.99173563)
return 6;
1924 if (lat < 84.89166191)
return 5;
1925 if (lat < 85.75541621)
return 4;
1926 if (lat < 86.53536998)
return 3;
1927 if (lat < 87.00000000)
return 2;
1942 return (surface ? 90.0 : 360.0) /
cprNFunction(lat, fflag);
1957 double AirDlat0 = (surface ? 90.0 : 360.0) / 60.0;
1958 double AirDlat1 = (surface ? 90.0 : 360.0) / 59.0;
1965 int j = (int) floor(((59*lat0 - 60*lat1) / 131072) + 0.5);
1966 double rlat0 = AirDlat0 * (
cprModFunction(j,60) + lat0 / 131072);
1967 double rlat1 = AirDlat1 * (
cprModFunction(j,59) + lat1 / 131072);
1973 rlat0 += floor(
Modes.fUserLat / 90.0) * 90.0;
1974 rlat1 += floor(
Modes.fUserLat / 90.0) * 90.0;
1976 if (rlat0 >= 270) rlat0 -= 360;
1977 if (rlat1 >= 270) rlat1 -= 360;
1999 a->
lon += floor(
Modes.fUserLon / 90.0) * 90.0;
2000 }
else if (a->
lon > 180) {
2034 latr =
Modes.fUserLat;
2035 lonr =
Modes.fUserLon;
2041 AirDlat = (surface ? 90.0 : 360.0) / 59.0;
2045 AirDlat = (surface ? 90.0 : 360.0) / 60.0;
2051 j = (int) (floor(latr/AirDlat) +
2052 trunc(0.5 +
cprModFunction((
int)latr, (
int)AirDlat)/AirDlat - lat/131072));
2053 rlat = AirDlat * (j + lat/131072);
2054 if (rlat >= 270) rlat -= 360;
2057 if (fabs(rlat - a->
lat) > (AirDlat/2)) {
2064 m = (int) (floor(lonr/AirDlon) +
2065 trunc(0.5 +
cprModFunction((
int)lonr, (
int)AirDlon)/AirDlon - lon/131072));
2066 rlon = AirDlon * (m + lon/131072);
2067 if (rlon > 180) rlon -= 360;
2070 if (fabs(rlon - a->
lon) > (AirDlon/2)) {
int ModeAToModeC(unsigned int ModeA)
#define MODES_ACFLAGS_NSEWSPD_VALID
#define MODES_ACFLAGS_EWSPEED_VALID
int detectModeA(uint16_t *m, struct modesMessage *mm)
void decodeModesMessage(struct modesMessage *mm, unsigned char *msg)
int decodeMovementField(int movement)
void detectModeS(uint16_t *m, uint32_t mlen)
#define MODES_ACFLAGS_ALTITUDE_VALID
#define MODES_PREAMBLE_US
uint32_t modes_checksum_table[112]
void dumpMagnitudeVector(uint16_t *m, uint32_t offset)
void modesQueueOutput(struct modesMessage *mm)
struct errorinfo bitErrorTable[((14 *8)+(14 *8)*((14 *8)-1)/2)]
void addRecentlySeenICAOAddr(uint32_t addr)
void dumpMagnitudeBar(int index, int magnitude)
#define MODES_ICAO_CACHE_LEN
#define MODES_DEBUG_GOODCRC
#define MODES_ACFLAGS_FS_VALID
#define MODES_PREAMBLE_SIZE
#define MODES_MSG_ENCODER_ERRS
void decodeModeAMessage(struct modesMessage *mm, int ModeA)
int detectOutOfPhase(uint16_t *pPreamble)
void modesInitErrorInfo()
#define MODES_ACFLAGS_AOG
char * getMEDescription(int metype, int mesub)
void applyPhaseCorrection(uint16_t *pPayload)
#define MODES_MSG_SQUELCH_LEVEL
unsigned char signalLevel
#define MODES_PREAMBLE_SAMPLES
uint32_t modesChecksum(unsigned char *msg, int bits)
int fixBitErrors(unsigned char *msg, int bits, int maxfix, char *fixedbits)
#define MODES_LONG_MSG_BYTES
#define MODES_ACFLAGS_SPEED_VALID
#define MODES_UNIT_METERS
#define MODES_ACFLAGS_SQUAWK_VALID
int decodeAC13Field(int AC13Field, int *unit)
#define MODES_DEBUG_NOPREAMBLE_LEVEL
void decodeCPR(struct aircraft *a, int fflag, int surface)
#define MODES_ACFLAGS_HEADING_VALID
#define MODES_LONG_MSG_SAMPLES
struct aircraft * interactiveReceiveData(struct modesMessage *mm)
void displayModesMessage(struct modesMessage *mm)
void useModesMessage(struct modesMessage *mm)
void dumpRawMessageJS(char *descr, unsigned char *msg, uint16_t *m, uint32_t offset, int fixable, char *bitpos)
#define MODES_MAX_BITERRORS
#define MODES_ACFLAGS_LATLON_VALID
void modesSendAllClients(int service, void *msg, int len)
void dumpRawMessage(char *descr, unsigned char *msg, uint16_t *m, uint32_t offset)
uint32_t ICAOCacheHashAddress(uint32_t a)
#define MODES_DEBUG_DEMOD
#define MODES_DEBUG_DEMODERR
int cprModFunction(int a, int b)
#define MODES_DEBUG_NOPREAMBLE
int cprNLFunction(double lat)
int decodeCPRrelative(struct aircraft *a, int fflag, int surface)
#define MODEAC_MSG_SAMPLES
#define MODES_ASYNC_BUF_SAMPLES
#define MODES_ICAO_CACHE_TTL
#define MODES_ACFLAGS_LLODD_VALID
#define MODES_ACFLAGS_VERTRATE_VALID
void computeMagnitudeVector()
#define MODES_SHORT_MSG_SAMPLES
#define MODES_USER_LATLON_VALID
#define MODES_ACFLAGS_AOG_VALID
#define MODES_LONG_MSG_SIZE
int modesMessageLenByType(int type)
int decodeAC12Field(int AC12Field, int *unit)
int cprNFunction(double lat, int fflag)
#define MODES_LONG_MSG_BITS
#define MODES_DEBUG_BADCRC
#define MODES_ACFLAGS_CALLSIGN_VALID
int decodeID13Field(int ID13Field)
#define MODES_ACFLAGS_LATLON_REL_OK
int cmpErrorInfo(const void *p0, const void *p1)
int ICAOAddressWasRecentlySeen(uint32_t addr)
#define MODES_SHORT_MSG_BYTES
double cprDlonFunction(double lat, int fflag, int surface)
#define MODES_ACFLAGS_LLEVEN_VALID
#define MODES_SHORT_MSG_BITS
#define MODES_ACFLAGS_NSSPEED_VALID