52 int i, len, startpos, retval = 1;
61 unsigned int const matchcount = 3;
62 regmatch_t matches[matchcount];
65 if ( regexec(&fapint_regex_header, packet->
header, matchcount, (regmatch_t*)&matches, 0) == 0 )
68 tmp = malloc(matches[1].rm_eo+1);
70 memcpy(tmp, packet->
header, matches[1].rm_eo);
71 tmp[matches[1].rm_eo] = 0;
89 len = matches[2].rm_eo - matches[2].rm_so;
91 if ( !rest )
return 0;
92 memcpy(rest, packet->
header + matches[2].rm_so, len);
103 if ( rest ) free(rest);
114 for ( i = 0; i < strlen(rest); ++i )
119 if ( rest[i] ==
',' )
129 memcpy(tmp, rest+startpos, len);
135 else if ( i+1 == strlen(rest) )
138 len = i+1 - startpos;
145 memcpy(tmp, rest+startpos, len);
166 if ( !current_elem->
next )
171 current_elem = current_elem->
next;
173 current_elem->
next = NULL;
174 current_elem->
text = tmp;
181 if ( tmp ) free(tmp);
221 packet->
path = calloc(path_len,
sizeof(
char*));
227 for ( i = 0; i < path_len; ++i ) packet->
path[i] = NULL;
229 current_elem = path->
next;
230 while ( current_elem != NULL )
233 if ( regexec(&fapint_regex_digicall, current_elem->
text, matchcount, (regmatch_t*)&matches, 0) == 0 )
239 memset(buf_10b, 0, 10);
240 memcpy(buf_10b, current_elem->
text, matches[1].rm_eo);
255 len = strlen(current_elem->
text);
256 packet->
path[i] = malloc(len+1);
257 if ( !packet->
path[i] )
262 strcpy(packet->
path[i], current_elem->
text);
265 if ( !seenq && current_elem->
text[0] ==
'q' ) seenq = 1;
268 else if ( seenq && regexec(&fapint_regex_digicallv6, current_elem->
text, 0, NULL, 0) == 0 )
271 len = strlen(current_elem->
text);
272 packet->
path[i] = malloc(len+1);
273 if ( !packet->
path[i] )
278 strcpy(packet->
path[i], current_elem->
text);
289 current_elem = current_elem->
next;
295 for ( len = 0; len <= i; ++len ) { free(packet->
path[len]); }
313 int len, error, i, lon;
315 char *rest, *tmp_str;
316 char dstcall[7], latitude[7], buf_6b[6], longitude[6];
317 double speed, course_speed, course_speed_tmp, course;
320 unsigned int const matchcount = 3;
321 regmatch_t matches[matchcount];
324 if ( input_len < 8 || packet->dst_callsign == NULL )
332 memset(dstcall, 0, 7);
333 for ( i = 0; i < strlen(packet->
dst_callsign) && i < 6; ++i )
338 if ( strlen(dstcall) != 6 )
346 if ( regexec(&fapint_regex_mice_dstcall, dstcall, 0, NULL, 0) != 0 )
360 if ( input[0] < 0x26 || (
unsigned char)input[0] > 0x7f ) error = 1;
361 if ( input[1] < 0x26 || input[1] > 0x61 ) error = 1;
362 if ( input[2] < 0x1c || (
unsigned char)input[2] > 0x7f ) error = 1;
363 if ( input[3] < 0x1c || (
unsigned char)input[3] > 0x7f ) error = 1;
364 if ( input[4] < 0x1c || input[4] > 0x7d ) error = 1;
365 if ( input[5] < 0x1c || (
unsigned char)input[5] > 0x7f ) error = 1;
366 if ( input[6] != 0x7d && (input[6] < 0x21 || input[6] > 0x7b) ) error = 1;
367 if ( error || regexec(&fapint_regex_mice_body, input+7, 0, NULL, 0) != 0 )
396 *packet->
format = fapPOS_MICE;
402 memset(latitude, 0, 7);
403 for ( i = 0; i < 6; ++i )
405 if ( dstcall[i] >=
'A' && dstcall[i] <=
'J' )
408 latitude[i] = dstcall[i] - 17;
410 else if ( dstcall[i] >=
'P' && dstcall[i] <=
'Y' )
413 latitude[i] = dstcall[i] - 32;
415 else if ( dstcall[i] ==
'K' || dstcall[i] ==
'L' || dstcall[i] ==
'Z' )
422 latitude[i] = dstcall[i];
429 if ( regexec(&fapint_regex_mice_amb, latitude, matchcount, (regmatch_t*)&matches, 0) != 0 )
435 *packet->
pos_ambiguity = matches[2].rm_eo - matches[2].rm_so;
454 tmp_str = strchr(latitude,
'_');
460 if ( (tmp_str = strchr(latitude,
'_')) != NULL )
467 while ( (tmp_str = strchr(latitude,
'_')) != NULL )
473 buf_6b[0] = latitude[0]; buf_6b[1] = latitude[1];
475 packet->
latitude = malloc(
sizeof(
double));
480 buf_6b[0] = latitude[2]; buf_6b[1] = latitude[3];
482 buf_6b[3] = latitude[4]; buf_6b[4] = latitude[5];
484 *packet->
latitude += atof(buf_6b)/60;
487 if ( dstcall[3] <= 0x4c )
495 for ( i = 0; i < 3; ++i )
497 if ( (dstcall[i] >=
'0' && dstcall[i] <=
'9') || dstcall[i] ==
'L' )
501 else if ( dstcall[i] >=
'P' && dstcall[i] <=
'Z' )
505 else if ( dstcall[i] >=
'A' && dstcall[i] <=
'K' )
515 if ( dstcall[4] >= 0x50 )
519 if ( lon >= 180 && lon <= 189 )
523 else if ( lon >= 190 && lon <= 199 )
527 packet->
longitude = malloc(
sizeof(
double));
532 memset(longitude, 0, 6);
538 sprintf(longitude,
"%02d.%02d", lon, input[2] - 28);
550 tmp_str[0] = longitude[0]; tmp_str[1] =
'5'; tmp_str[2] = 0;
557 memset(buf_6b, 0, 6);
558 buf_6b[0] = longitude[0];
559 buf_6b[1] = longitude[1];
568 *packet->
longitude += atof(longitude)/60;
572 *packet->
longitude += atof(longitude)/60;
582 if ( dstcall[5] >= 0x50 )
588 speed = (input[3] - 28) * 10;
589 course_speed = input[4] - 28;
590 course_speed_tmp = floor(course_speed / 10);
591 speed += course_speed_tmp;
592 course_speed -= course_speed_tmp * 10;
593 course = 100 * course_speed;
594 course += input[5] - 28;
607 packet->
speed = malloc(
sizeof(
double));
608 if ( !packet->
speed )
return 0;
612 packet->
course = malloc(
sizeof(
unsigned int));
613 if ( !packet->
course )
return 0;
621 if ( (len = input_len - 8) > 0 )
624 memcpy(rest, input+8, len);
685 for ( i = 0; i+3 < len; ++i )
688 if ( rest[i] >= 0x21 && rest[i] <= 0x7b )
691 if ( (rest[i+1] >= 0x21 && rest[i+1] <= 0x7b) &&
692 (rest[i+2] >= 0x21 && rest[i+2] <= 0x7b) &&
696 packet->
altitude = malloc(
sizeof(
double));
702 *packet->
altitude = ( (rest[i] - 33) * pow(91,2) +
703 (rest[i+1] - 33) * 91 +
704 (rest[i+2] - 33) ) - 10000;
722 for ( i = len-1; i >= 0 ; --i )
724 if ( i + 4 < len && rest[i] ==
'!' &&
725 0x21 <= rest[i+1] && rest[i+1] <= 0x7b &&
726 0x20 <= rest[i+2] && rest[i+2] <= 0x7b &&
727 0x20 <= rest[i+3] && rest[i+3] <= 0x7b &&
730 memcpy(dao, rest+i+1, 3);
759 unsigned int first, second, third;
761 struct tm now_struct, fwd_struct, back_struct, tmp_struct;
762 time_t thismonth, nextmonth, prevmonth, result;
763 const time_t now = time(NULL);
765 unsigned int const matchcount = 5;
766 regmatch_t matches[matchcount];
768 gmtime_r(&now, &now_struct);
775 if ( regexec(&fapint_regex_timestamp, input, matchcount, (regmatch_t*)&matches, 0) == 0 )
779 memcpy(buf_3b, input+matches[1].rm_so, 2);
780 first = atoi(buf_3b);
781 memcpy(buf_3b, input+matches[2].rm_so, 2);
782 second = atoi(buf_3b);
783 memcpy(buf_3b, input+matches[3].rm_so, 2);
784 third = atoi(buf_3b);
787 type = input[matches[4].rm_so];
798 if ( first > 23 || second > 59 || third > 59 )
804 memcpy((
struct tm*)&tmp_struct, &now_struct,
sizeof(
struct tm));
805 tmp_struct.tm_sec = third;
806 tmp_struct.tm_min = second;
807 tmp_struct.tm_hour = first;
808 result = timegm((
struct tm*)&tmp_struct);
812 if ( now + 3900 < result )
818 else if ( now - 82500 > result )
824 else if ( type ==
'z' || type ==
'/' )
827 if ( first < 1 || first > 31 || second > 23 || third > 59 )
838 memcpy((
struct tm*)&tmp_struct, &now_struct,
sizeof(
struct tm));
839 tmp_struct.tm_mday = first;
840 tmp_struct.tm_hour = second;
841 tmp_struct.tm_min = third;
842 tmp_struct.tm_sec = 0;
843 thismonth = timegm((
struct tm*)&tmp_struct);
846 memcpy((
struct tm*)&tmp_struct, &now_struct,
sizeof(
struct tm));
847 tmp_struct.tm_mon += 1;
848 tmp_struct.tm_mday = first;
849 tmp_struct.tm_hour = second;
850 tmp_struct.tm_min = third;
851 tmp_struct.tm_sec = 0;
852 nextmonth = timegm((
struct tm*)&tmp_struct);
855 memcpy((
struct tm*)&tmp_struct, &now_struct,
sizeof(
struct tm));
856 if ( tmp_struct.tm_mon == 0 )
858 tmp_struct.tm_mon = 11;
859 tmp_struct.tm_year -= 1;
863 tmp_struct.tm_mon -= 1;
865 tmp_struct.tm_mday = first;
866 tmp_struct.tm_hour = second-1;
867 tmp_struct.tm_min = third;
868 tmp_struct.tm_sec = 0;
869 prevmonth = timegm((
struct tm*)&tmp_struct);
873 if ( nextmonth - now < 43400 )
877 else if ( thismonth - now < 43400 )
902 char symboltable, symbolcode;
904 char c1, s1, comptype;
908 if ( strlen(input) < 13 )
915 (input[0] >=
'A' && input[0] <=
'Z') ||
916 (input[0] >=
'a' && input[0] <=
'j') ||
925 for ( i = 1; i <= 8; ++i )
927 if ( input[i] < 0x21 || input[i] > 0x7b )
934 if ( input[9] != 0x7d && (input[9] < 0x21 || input[9] > 0x7b) )
940 for ( i = 10; i <= 12; ++i )
942 if ( input[i] < 0x20 || input[i] > 0x7b )
956 *packet->
format = fapPOS_COMPRESSED;
959 symboltable = input[0];
960 symbolcode = input[9];
963 for ( i = 0; i < 4; ++i )
965 lat[i] = input[i+1] - 33;
966 lon[i] = input[i+5] - 33;
972 comptype = input[12] - 33;
975 if ( symboltable >=
'a' && symboltable <=
'j' )
986 packet->
latitude = malloc(
sizeof(
double));
988 *packet->
latitude = 90 - ( (lat[0] * pow(91,3) + lat[1] * pow(91,2) + lat[2] * 91 + lat[3]) / 380926);
989 packet->
longitude = malloc(
sizeof(
double));
991 *packet->
longitude = -180 + ( (lon[0] * pow(91,3) + lon[1] * pow(91,2) + lon[2] * 91 + lon[3]) / 190463);
1003 if ( (comptype & 0x20) == 0x20 )
1016 if ( c1 == -1 || s1 == -1 )
1020 else if ( (comptype & 0x18) == 0x10 )
1024 packet->
altitude = malloc(
sizeof(
double));
1027 *packet->
altitude = pow(1.002, cs) * 0.3048;
1029 else if ( c1 >= 0 && c1 <= 89 )
1031 packet->
course = malloc(
sizeof(
unsigned int));
1032 if ( !packet->
course )
return 0;
1041 *packet->
course = c1 * 4;
1044 packet->
speed = malloc(
sizeof(
double));
1045 if ( !packet->
speed )
return 0;
1048 else if ( c1 == 90 )
1051 packet->
radio_range = malloc(
sizeof(
unsigned int));
1065 char lat_deg[3], lat_min[6], lon_deg[4], lon_min[6], tmp_5b[5];
1068 unsigned int const matchcount = 9;
1069 regmatch_t matches[matchcount];
1073 if ( strlen(input) < 19 )
1086 *packet->
format = fapPOS_UNCOMPRESSED;
1089 if ( regexec(&fapint_regex_normalpos, input, matchcount, (regmatch_t*)&matches, 0) != 0 )
1095 if ( input[18] != 0x7d && (input[18] < 0x21 || input[18] > 0x7b) )
1103 sind = toupper(input[matches[3].rm_so]);
1104 wind = toupper(input[matches[7].rm_so]);
1111 memset(lat_deg, 0, 3);
1112 memcpy(lat_deg, input+matches[1].rm_so, 2);
1113 memset(lat_min, 0, 6);
1114 memcpy(lat_min, input+matches[2].rm_so, 5);
1115 memset(lon_deg, 0, 4);
1116 memcpy(lon_deg, input+matches[5].rm_so, 3);
1117 memset(lon_min, 0, 6);
1118 memcpy(lon_min, input+matches[6].rm_so, 5);
1137 if ( sind ==
'S' ) is_south = 1;
1138 if ( wind ==
'W' ) is_west = 1;
1141 lat = atoi(lat_deg);
1142 lon = atoi(lon_deg);
1143 if ( lat > 89 || lon > 179 )
1155 tmp_5b[0] = lat_min[0];
1156 tmp_5b[1] = lat_min[1];
1157 tmp_5b[2] = lat_min[3];
1158 tmp_5b[3] = lat_min[4];
1162 if ( regexec(&fapint_regex_normalamb, tmp_5b, matchcount, (regmatch_t*)&matches, 0) != 0 )
1168 *packet->
pos_ambiguity = matches[2].rm_eo - matches[2].rm_so;
1171 packet->
latitude = malloc(
sizeof(
double));
1172 packet->
longitude = malloc(
sizeof(
double));
1178 if ( strchr(lon_min,
' ') != NULL )
1186 *packet->
latitude = lat + atof(lat_min)/60;
1187 *packet->
longitude = lon + atof(lon_min)/60;
1198 *packet->
latitude = lat + atof(lat_min)/60;
1199 *packet->
longitude = lon + atof(lon_min)/60;
1204 memset(lat_min+2, 0, 4);
1206 memset(lon_min+2, 0, 4);
1207 *packet->
latitude = lat + atof(lat_min)/60;
1208 *packet->
longitude = lon + atof(lon_min)/60;
1238 char course[4], speed[4], range[5], altitude[7], dao[3];
1240 char* tmp_str, *rest = NULL;
1241 unsigned int rest_len = 0, tmp_us;
1243 unsigned int const matchcount = 2;
1244 regmatch_t matches[matchcount];
1249 if ( input_len >= 7 )
1252 if ( regexec(&fapint_regex_comment, input, 0, NULL, 0) == 0 )
1257 memcpy(course, input, 3);
1259 packet->
course = malloc(
sizeof(
unsigned int));
1260 if ( !packet->
course )
return;
1262 if ( isdigit(course[0]) && isdigit(course[1]) && isdigit(course[2]) )
1264 tmp_s = atoi(course);
1265 if ( tmp_s >= 1 && tmp_s <= 360 )
1274 if ( !packet->
speed )
1277 memcpy(speed, input+4, 3);
1279 if ( isdigit(speed[0]) && isdigit(speed[1]) && isdigit(speed[2]) )
1281 tmp_s = atoi(&speed[0]);
1282 packet->
speed = malloc(
sizeof(
double));
1283 if ( !packet->
speed )
return;
1292 else if ( regexec(&fapint_regex_phgr, input, 0, NULL, 0) == 0 &&
1293 input[4] >= 0x30 && input[4] <= 0x7e )
1296 packet->
phg = malloc(6);
1297 if ( !packet->
phg )
return;
1298 memcpy(packet->
phg, input+3, 5);
1305 else if ( regexec(&fapint_regex_phg, input, 0, NULL, 0) == 0 &&
1306 input[4] >= 0x30 && input[4] <= 0x7e )
1309 packet->
phg = malloc(5);
1310 if ( !packet->
phg )
return;
1311 memcpy(packet->
phg, input+3, 4);
1318 else if ( regexec(&fapint_regex_rng, input, 0, NULL, 0) == 0 )
1321 memcpy(range, input+3, 4);
1323 tmp_s = atoi(range);
1324 packet->
radio_range = malloc(
sizeof(
unsigned int));
1333 rest = malloc(input_len+1);
1334 if ( !rest )
return;
1335 memcpy(rest, input, input_len);
1336 rest_len = input_len;
1340 else if ( input_len > 0 )
1342 rest = malloc(input_len+1);
1343 if ( !rest )
return;
1344 memcpy(rest, input, input_len);
1345 rest_len = input_len;
1353 if ( regexec(&fapint_regex_altitude, rest, matchcount, (regmatch_t*)&matches, 0) == 0 )
1358 memcpy(altitude, rest+matches[1].rm_so, 6);
1360 tmp_s = atoi(altitude);
1361 packet->
altitude = malloc(
sizeof(
double));
1366 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-3, matches[1].rm_eo, &tmp_us);
1379 for ( i = rest_len-1; i >= 0 ; --i )
1381 if ( i + 4 < rest_len && rest[i] ==
'!' &&
1382 0x21 <= rest[i+1] && rest[i+1] <= 0x7b &&
1383 0x20 <= rest[i+2] && rest[i+2] <= 0x7b &&
1384 0x20 <= rest[i+3] && rest[i+3] <= 0x7b &&
1387 memcpy(dao, rest+i+1, 3);
1415 unsigned int rest_len;
1416 int i, len, retval = 1;
1418 char* checksum_area;
1419 char checksum_given_str[3];
1420 long int checksum_given;
1421 long int checksum_calculated = 0;
1424 char** nmea_fields = NULL;
1425 unsigned int nmea_field_count;
1429 unsigned int year, month, day, hours, mins, secs;
1430 struct tm timestamp;
1432 unsigned int const matchcount = 5;
1433 regmatch_t matches[matchcount];
1436 for ( i = input_len-1; i >= 0; ++i )
1438 if ( !isspace(input[i]) )
1447 rest = malloc(rest_len+1);
1448 if ( !rest )
return 0;
1449 memcpy(rest, input, rest_len);
1458 if ( regexec(&fapint_regex_nmea_chksum, rest, matchcount, (regmatch_t*)&matches, 0) == 0 )
1460 len = matches[1].rm_eo - matches[1].rm_so;
1461 checksum_area = malloc(len+1);
1462 if ( !checksum_area )
1467 memcpy(checksum_area, rest+matches[1].rm_so, len);
1468 checksum_area[len] = 0;
1470 checksum_given_str[0] = rest[matches[2].rm_so];
1471 checksum_given_str[1] = rest[matches[2].rm_so+1];
1472 checksum_given_str[2] = 0;
1473 checksum_given = strtol(checksum_given_str, NULL, 16);
1475 for ( i = 0; i < strlen(checksum_area); ++i )
1477 checksum_calculated ^= checksum_area[i];
1479 free(checksum_area);
1481 if ( checksum_given != checksum_calculated )
1499 rest =
fapint_remove_part(rest, rest_len, matches[2].rm_so-1, matches[2].rm_eo, &rest_len);
1503 printf(
"no checksum in (%s)", rest);
1513 *packet->
format = fapPOS_NMEA;
1523 tmp_str = strtok(rest,
",");
1524 nmea_field_count = 0;
1525 while ( tmp_str != NULL )
1528 if ( !nmea_field_list )
1531 if ( !nmea_field_list )
return 0;
1532 current_elem = nmea_field_list;
1537 if ( !current_elem->next )
1542 current_elem = current_elem->next;
1544 current_elem->next = NULL;
1547 current_elem->text = malloc(strlen(tmp_str)+1);
1548 if ( !current_elem->text )
1553 strcpy(current_elem->text, tmp_str);
1557 tmp_str = strtok(NULL,
",");
1569 if ( !nmea_field_count )
1578 nmea_fields = calloc(nmea_field_count,
sizeof(
char*));
1584 for ( i = 0; i < nmea_field_count; ++i ) nmea_fields[i] = NULL;
1585 current_elem = nmea_field_list;
1587 while ( current_elem != NULL )
1589 nmea_fields[i] = malloc(strlen(current_elem->text)+1);
1590 if ( !nmea_fields[i] )
1595 strcpy(nmea_fields[i], current_elem->text);
1596 current_elem = current_elem->next;
1614 if ( strcmp(nmea_fields[0],
"GPRMC") == 0 )
1617 if ( nmea_field_count < 10 )
1626 if ( strcmp(nmea_fields[2],
"A" ) != 0 )
1635 if ( regexec(&fapint_regex_nmea_time, nmea_fields[1], matchcount, (regmatch_t*)&matches, 0) == 0 )
1638 memcpy(buf_3b, nmea_fields[1]+matches[1].rm_so, 2);
1639 hours = atoi(buf_3b);
1640 memcpy(buf_3b, nmea_fields[1]+matches[2].rm_so, 2);
1641 mins = atoi(buf_3b);
1642 memcpy(buf_3b, nmea_fields[1]+matches[3].rm_so, 2);
1643 secs = atoi(buf_3b);
1645 if ( hours > 23 || mins > 59 || secs > 59 )
1662 if ( regexec(&fapint_regex_nmea_date, nmea_fields[9], matchcount, (regmatch_t*)&matches, 0) == 0 )
1665 memcpy(buf_3b, nmea_fields[9]+matches[1].rm_so, 2);
1667 memcpy(buf_3b, nmea_fields[9]+matches[2].rm_so, 2);
1668 month = atoi(buf_3b);
1669 memcpy(buf_3b, nmea_fields[9]+matches[3].rm_so, 2);
1670 year = atoi(buf_3b);
1700 if ( year >= 2038 || year < 1970 )
1709 timestamp.tm_sec = secs;
1710 timestamp.tm_min = mins;
1711 timestamp.tm_hour = hours;
1712 timestamp.tm_mday = day;
1713 timestamp.tm_mon = month-1;
1714 timestamp.tm_year = year-1900;
1715 timestamp.tm_isdst = 0;
1716 packet->
timestamp = malloc(
sizeof(time_t));
1722 *packet->
timestamp = (time_t)mktime(×tamp) - (time_t)timezone;
1726 if ( regexec(&fapint_regex_nmea_specou, nmea_fields[7], matchcount, (regmatch_t*)&matches, 0) == 0 )
1728 len = matches[1].rm_eo - matches[1].rm_so;
1729 tmp_str = malloc(len+1);
1735 memcpy(tmp_str, nmea_fields[7]+matches[1].rm_so, len);
1738 packet->
speed = malloc(
sizeof(
double));
1739 if ( !packet->
speed )
1745 free(tmp_str); tmp_str = NULL;
1749 if ( regexec(&fapint_regex_nmea_specou, nmea_fields[8], matchcount, (regmatch_t*)&matches, 0) == 0 )
1751 len = matches[1].rm_eo - matches[1].rm_so;
1752 tmp_str = malloc(len+1);
1758 memcpy(tmp_str, nmea_fields[8]+matches[1].rm_so, len);
1761 packet->
course = malloc(
sizeof(
unsigned int));
1767 *packet->
course = atof(tmp_str) + 0.5;
1768 free(tmp_str); tmp_str = NULL;
1771 if ( *packet->
course == 0 )
1775 else if ( *packet->
course > 360 )
1796 else if ( strcmp(nmea_fields[0],
"GPGGA") == 0 )
1799 if ( nmea_field_count < 11 )
1808 if ( regexec(&fapint_regex_nmea_fix, nmea_fields[6], matchcount, (regmatch_t*)&matches, 0) == 0 )
1810 len = matches[1].rm_eo - matches[1].rm_so;
1811 tmp_str = malloc(len+1);
1817 memcpy(tmp_str, nmea_fields[8]+matches[1].rm_so, len);
1819 if ( atoi(tmp_str) < 1 )
1827 free(tmp_str); tmp_str = NULL;
1840 if ( strlen(nmea_fields[1]) < 6 )
1847 tmp_str = malloc(8);
1853 memcpy(tmp_str, nmea_fields[1], 6);
1856 packet->
timestamp = malloc(
sizeof(time_t));
1863 free(tmp_str); tmp_str = NULL;
1885 if ( strcmp(nmea_fields[0],
"M") == 0 &&
1886 regexec(&fapint_regex_nmea_altitude, nmea_fields[9], matchcount, (regmatch_t*)&matches, 0) == 0 )
1888 len = matches[1].rm_eo - matches[1].rm_so;
1889 tmp_str = malloc(len+1);
1895 memcpy(tmp_str, nmea_fields[8]+matches[1].rm_so, len);
1897 packet->
altitude = malloc(
sizeof(
double));
1904 free(tmp_str); tmp_str = NULL;
1910 else if ( strcmp(nmea_fields[0],
"GPGLL") == 0 )
1913 if ( nmea_field_count < 5 )
1936 if ( nmea_field_count >= 6 && strlen(nmea_fields[5]) >= 6 )
1938 tmp_str = malloc(8);
1944 memcpy(tmp_str, nmea_fields[5], 6);
1947 packet->
timestamp = malloc(
sizeof(time_t));
1954 free(tmp_str); tmp_str = NULL;
1965 if ( nmea_field_count >= 7 )
1967 if ( strcmp(nmea_fields[0],
"GPGLL") == 0 )
1989 for ( i = 0; i < nmea_field_count; ++i )
1991 free(nmea_fields[i]);
1993 if ( tmp_str ) free(tmp_str);
1994 if ( nmea_fields ) free(nmea_fields);
2006 if ( strlen(input) < 31 )
2014 for ( i = 1; i < 10; ++i )
2016 if ( input[i] < 0x20 || input[i] > 0x7e )
2029 if ( input[i] ==
'*' )
2031 packet->
alive = malloc(
sizeof(
int));
2032 if ( !packet->
alive )
return 0;
2035 else if ( input[i] ==
'_' )
2037 packet->
alive = malloc(
sizeof(
int));
2038 if ( !packet->
alive )
return 0;
2049 packet->
timestamp = malloc(
sizeof(time_t));
2061 if ( input[i] ==
'/' || input[i] ==
'\\' ||
2062 (input[i] >=
'A' && input[i] <=
'Z') ||
2063 (input[i] >=
'a' && input[i] <=
'j')
2073 else if ( isdigit(input[i]) )
2108 if ( input_len < 18 )
2116 if ( input[0] !=
')' )
2123 for ( i = 1; i <= 9; ++i )
2125 if ( input[i] == 0x20 ||
2126 (input[i] >= 0x22 && input[i] <= 0x5e) ||
2127 (input[i] >= 0x60 && input[i] <= 0x7e) )
2136 if ( input[i] ==
'!' )
2138 packet->
alive = malloc(
sizeof(
int));
2139 if ( !packet->
alive )
return 0;
2142 else if ( input[i] ==
'_' )
2144 packet->
alive = malloc(
sizeof(
int));
2145 if ( !packet->
alive )
return 0;
2163 if ( input[i] ==
'/' || input[i] ==
'\\' ||
2164 (input[i] >=
'A' && input[i] <=
'Z') ||
2165 (input[i] >=
'a' && input[i] <=
'j')
2175 else if ( isdigit(input[i]) )
2205 short skipping_spaces = 1;
2207 unsigned int const matchcount = 3;
2208 regmatch_t matches[matchcount];
2212 if ( input_len < 12 )
2220 if ( regexec(&fapint_regex_mes_dst, input, matchcount, (regmatch_t*)&matches, 0) == 0 )
2223 len = matches[1].rm_eo - matches[1].rm_so;
2224 for ( i = matches[1].rm_eo-1; i > 0; --i )
2226 if ( input[i] ==
' ' )
2239 memcpy(packet->
destination, input+matches[1].rm_so, len);
2251 for ( i = 11; i < input_len; ++i )
2253 if ( (input[i] >= 0x20 && input[i] <= 0x7e) || ((
unsigned char)input[i] >= 0x80 && (
unsigned char)input[i] <= 0xfe) )
2270 packet->
message = malloc(len+1);
2271 if ( !packet->
message )
return 0;
2272 memcpy(packet->
message, input+11, len);
2276 if ( regexec(&fapint_regex_mes_ack, packet->
message, matchcount, (regmatch_t*)&matches, 0) == 0 )
2278 len = matches[1].rm_eo - matches[1].rm_so;
2286 if ( regexec(&fapint_regex_mes_nack, packet->
message, matchcount, (regmatch_t*)&matches, 0) == 0 )
2288 len = matches[1].rm_eo - matches[1].rm_so;
2297 for ( i = strlen(packet->
message)-1; i >= 0 ; i-- )
2299 if ( skipping_spaces && !isspace(packet->
message[i]) )
2302 skipping_spaces = 0;
2304 else if ( skipping_spaces )
2310 if ( !(isalnum(packet->
message[i]) || packet->
message[i] ==
'{') )
2323 if ( packet->
message[i] ==
'{' )
2327 packet->
message = malloc(i+1);
2333 memcpy(packet->
message, tmp, i);
2355 ( strstr(packet->
message,
"BITS.") != NULL ||
2356 strstr(packet->
message,
"PARM.") != NULL ||
2357 strstr(packet->
message,
"UNIT.") != NULL ||
2358 strstr(packet->
message,
"EQNS.") != NULL
2362 if ( packet->
type == NULL )
2365 if ( !packet->
type )
return 0;
2367 *packet->
type = fapTELEMETRY_MESSAGE;
2379 char* tmp_str, *sepa;
2380 int cap_len, cap_startpos, i, retval = 1;
2381 unsigned int foo, saved, sepa_pos;
2385 for ( i = 0; i < input_len; ++i )
2390 if ( input[i] ==
',' )
2393 cap_len = i - cap_startpos;
2394 tmp_str = malloc(cap_len+1);
2400 memcpy(tmp_str, input+cap_startpos, cap_len);
2401 tmp_str[cap_len] = 0;
2404 cap_startpos = i + 1;
2406 else if ( i+1 == input_len )
2409 cap_len = i+1 - cap_startpos;
2410 tmp_str = malloc(cap_len+1);
2416 memcpy(tmp_str, input+cap_startpos, cap_len);
2417 tmp_str[cap_len] = 0;
2432 current_elem = caps;
2437 if ( !current_elem->
next )
2442 current_elem = current_elem->
next;
2444 current_elem->
next = NULL;
2445 current_elem->
text = tmp_str;
2457 if ( cap_count == 0 )
2463 packet->
capabilities = calloc(cap_count*2,
sizeof(
char*));
2469 for ( i = 0; i < cap_count; ++i ) packet->
capabilities[i] = NULL;
2472 current_elem = caps;
2473 while ( current_elem != NULL )
2477 if ( (sepa = strchr(current_elem->
text,
'=')) != NULL )
2479 sepa_pos = sepa - current_elem->
text - 1;
2481 if ( sepa_pos < input_len )
2503 current_elem = current_elem->
next;
2515 short has_timestamp = 0;
2519 if ( input_len > 6 )
2522 for ( i = 0; i < 6; ++i )
2524 if ( !isdigit(input[i]) )
2530 if ( input[6] !=
'z' )
2537 if ( has_timestamp )
2539 packet->
timestamp = malloc(
sizeof(time_t));
2552 packet->
status = malloc(input_len);
2553 if ( !packet->
status )
return 0;
2554 memcpy(packet->
status, input, input_len);
2565 char wind_dir[4], wind_speed[4], *wind_gust = NULL, *temp = NULL;
2567 int len, retval = 1;
2568 char* rest = NULL, *tmp_str;
2569 unsigned int rest_len, tmp_us;
2571 unsigned int const matchcount = 5;
2572 regmatch_t matches[matchcount];
2575 if ( !packet || !input || !input_len )
2581 memset(wind_dir, 0, 4);
2582 memset(wind_speed, 0, 4);
2585 if ( regexec(&fapint_regex_wx1, input, matchcount, (regmatch_t*)&matches, 0) == 0 )
2587 memcpy(wind_dir, input+matches[1].rm_so, 3);
2590 memcpy(wind_speed, input+matches[2].rm_so, 3);
2593 len = matches[3].rm_eo - matches[3].rm_so;
2594 wind_gust = malloc(len+1);
2595 if ( !wind_gust )
return 0;
2596 memcpy(wind_gust, input+matches[3].rm_so, len);
2599 len = matches[4].rm_eo - matches[4].rm_so;
2600 temp = malloc(len+1);
2606 memcpy(temp, input+matches[4].rm_so, len);
2611 else if ( regexec(&fapint_regex_wx2, input, 5, matches, 0) == 0 )
2613 memcpy(wind_dir, input+matches[1].rm_so, 3);
2616 memcpy(wind_speed, input+matches[2].rm_so, 3);
2619 len = matches[3].rm_eo - matches[3].rm_so;
2620 wind_gust = malloc(len+1);
2621 if ( !wind_gust )
return 0;
2622 memcpy(wind_gust, input+matches[3].rm_so, len);
2625 len = matches[4].rm_eo - matches[4].rm_so;
2626 temp = malloc(len+1);
2632 memcpy(temp, input+matches[4].rm_so, len);
2637 else if ( regexec(&fapint_regex_wx3, input, 4, matches, 0) == 0 )
2639 memcpy(wind_dir, input+matches[1].rm_so, 3);
2642 memcpy(wind_speed, input+matches[2].rm_so, 3);
2645 len = matches[3].rm_eo - matches[3].rm_so;
2646 wind_gust = malloc(len+1);
2647 if ( !wind_gust )
return 0;
2648 memcpy(wind_gust, input+matches[3].rm_so, len);
2653 else if ( regexec(&fapint_regex_wx4, input, 4, matches, 0) == 0 )
2655 memcpy(wind_dir, input+matches[1].rm_so, 3);
2658 memcpy(wind_speed, input+matches[2].rm_so, 3);
2661 len = matches[3].rm_eo - matches[3].rm_so;
2662 wind_gust = malloc(len+1);
2663 if ( !wind_gust )
return 0;
2664 memcpy(wind_gust, input+matches[3].rm_so, len);
2669 else if ( regexec(&fapint_regex_wx5, input, 3, matches, 0) == 0 )
2671 len = matches[1].rm_eo - matches[1].rm_so;
2672 wind_gust = malloc(len+1);
2673 if ( !wind_gust )
return 0;
2674 memcpy(wind_gust, input+matches[1].rm_so, len);
2677 len = matches[2].rm_eo - matches[2].rm_so;
2678 temp = malloc(len+1);
2684 memcpy(temp, input+matches[2].rm_so, len);
2694 if ( temp == NULL && rest_len > 0 && regexec(&fapint_regex_wx5, rest, matchcount, (regmatch_t*)&matches, 0) == 0 )
2696 len = matches[1].rm_eo - matches[1].rm_so;
2697 temp = malloc(len+1);
2700 if ( wind_gust ) free(wind_gust);
2704 memcpy(temp, rest+matches[1].rm_so, len);
2707 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2717 if ( wind_gust ) free(wind_gust);
2718 if ( temp ) free(temp);
2719 if ( rest ) free(rest);
2787 if ( rest_len > 0 && regexec(&fapint_regex_wx_r1, rest, matchcount, (regmatch_t*)&matches, 0) == 0 )
2789 len = matches[1].rm_eo - matches[1].rm_so;
2790 memset(buf_5b, 0, 6);
2791 memcpy(buf_5b, rest+matches[1].rm_so, len);
2800 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2805 if ( rest_len > 0 && regexec(&fapint_regex_wx_r24, rest, 2, matches, 0) == 0 )
2807 len = matches[1].rm_eo - matches[1].rm_so;
2808 memset(buf_5b, 0, 4);
2809 memcpy(buf_5b, rest+matches[1].rm_so, len);
2818 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2823 if ( rest_len > 0 && regexec(&fapint_regex_wx_rami, rest, 2, matches, 0) == 0 )
2825 len = matches[1].rm_eo - matches[1].rm_so;
2826 memset(buf_5b, 0, 4);
2827 memcpy(buf_5b, rest+matches[1].rm_so, len);
2836 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2849 if ( rest_len > 0 && regexec(&fapint_regex_wx_humi, rest, 2, matches, 0) == 0 )
2851 len = matches[1].rm_eo - matches[1].rm_so;
2852 memset(buf_5b, 0, 6);
2853 memcpy(buf_5b, rest+matches[1].rm_so, len);
2854 if ( (tmp_us = atoi(buf_5b)) <= 100 )
2862 if ( tmp_us == 0 ) tmp_us = 100;
2866 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2873 if ( rest_len > 0 && regexec(&fapint_regex_wx_pres, rest, 2, matches, 0) == 0 )
2875 len = matches[1].rm_eo - matches[1].rm_so;
2876 memset(buf_5b, 0, 6);
2877 memcpy(buf_5b, rest+matches[1].rm_so, len);
2886 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2893 if ( rest_len > 0 && regexec(&fapint_regex_wx_lumi, rest, 3, matches, 0) == 0 )
2895 len = matches[2].rm_eo - matches[2].rm_so;
2896 memset(buf_5b, 0, 6);
2897 memcpy(buf_5b, rest+matches[2].rm_so, len);
2905 if ( input[matches[1].rm_so] ==
'l' )
2910 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so, matches[2].rm_eo, &tmp_us);
2917 if ( rest_len > 0 && regexec(&fapint_regex_wx_what, rest, 2, matches, 0) == 0 )
2919 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2926 if ( rest_len > 0 && regexec(&fapint_regex_wx_snow, rest, 2, matches, 0) == 0 )
2928 len = matches[1].rm_eo - matches[1].rm_so;
2929 if ( len > 5 ) len = 5;
2930 memset(buf_5b, 0, 6);
2931 memcpy(buf_5b, rest+matches[1].rm_so, len);
2940 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2947 if ( rest_len > 0 && regexec(&fapint_regex_wx_rrc, rest, 2, matches, 0) == 0 )
2949 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so-1, matches[1].rm_eo, &tmp_us);
2956 if ( rest_len > 0 && regexec(&fapint_regex_wx_any, rest, 2, matches, 0) == 0 )
2958 tmp_str =
fapint_remove_part(rest, rest_len, matches[1].rm_so, matches[1].rm_eo, &tmp_us);
2967 if ( rest_len > 0 && regexec(&fapint_regex_wx_soft, rest, 0, NULL, 0) == 0 )
2972 else if ( rest_len > 0 && packet->
comment == NULL )
2989 unsigned int matchcount = 13;
2990 regmatch_t matches[matchcount];
2996 if ( !packet || !input )
3000 if ( regexec(&fapint_regex_telemetry, input, matchcount, (regmatch_t*)&matches, 0) == 0 )
3008 len1 = matches[1].rm_eo - matches[1].rm_so;
3009 tmp_str = malloc(len1+1);
3010 if ( !tmp_str )
return 0;
3011 memcpy(tmp_str, input+matches[1].rm_so, len1);
3019 len1 = matches[2].rm_eo - matches[2].rm_so;
3020 len2 = matches[3].rm_eo - matches[3].rm_so;
3021 tmp_str = malloc(len1+len2+1);
3022 if ( !tmp_str )
return 0;
3023 memcpy(tmp_str, input+matches[2].rm_so, len1);
3024 memcpy(tmp_str+len1, input+matches[3].rm_so, len2);
3025 tmp_str[len1+len2] = 0;
3032 len1 = matches[4].rm_eo - matches[4].rm_so;
3033 len2 = matches[5].rm_eo - matches[5].rm_so;
3034 tmp_str = malloc(len1+len2+1);
3035 if ( !tmp_str )
return 0;
3036 memcpy(tmp_str, input+matches[4].rm_so, len1);
3037 memcpy(tmp_str+len1, input+matches[5].rm_so, len2);
3038 tmp_str[len1+len2] = 0;
3045 len1 = matches[6].rm_eo - matches[6].rm_so;
3046 len2 = matches[7].rm_eo - matches[7].rm_so;
3047 tmp_str = malloc(len1+len2+1);
3048 if ( !tmp_str )
return 0;
3049 memcpy(tmp_str, input+matches[6].rm_so, len1);
3050 memcpy(tmp_str+len1, input+matches[7].rm_so, len2);
3051 tmp_str[len1+len2] = 0;
3058 len1 = matches[8].rm_eo - matches[8].rm_so;
3059 len2 = matches[9].rm_eo - matches[9].rm_so;
3060 tmp_str = malloc(len1+len2+1);
3061 if ( !tmp_str )
return 0;
3062 memcpy(tmp_str, input+matches[8].rm_so, len1);
3063 memcpy(tmp_str+len1, input+matches[9].rm_so, len2);
3064 tmp_str[len1+len2] = 0;
3071 len1 = matches[10].rm_eo - matches[10].rm_so;
3072 len2 = matches[11].rm_eo - matches[11].rm_so;
3073 tmp_str = malloc(len1+len2+1);
3074 if ( !tmp_str )
return 0;
3075 memcpy(tmp_str, input+matches[10].rm_so, len1);
3076 memcpy(tmp_str+len1, input+matches[11].rm_so, len2);
3077 tmp_str[len1+len2] = 0;
3084 len1 = matches[12].rm_eo - matches[12].rm_so;
3085 memcpy(packet->
telemetry->
bits, input+matches[12].rm_so, len1);
3102 unsigned int part_count;
3106 unsigned int matchcount = 2;
3107 regmatch_t matches[matchcount];
3112 current_elem = NULL;
3115 while ( regexec(&fapint_regex_peet_splitter, input+i, matchcount, matches, 0) == 0 )
3125 current_elem = parts;
3130 if ( !current_elem->
next )
3135 current_elem = current_elem->
next;
3137 current_elem->
next = NULL;
3138 if ( input[i+matches[1].rm_so] !=
'-' )
3140 current_elem->
text = malloc(5);
3141 memcpy(current_elem->
text, input+i+matches[1].rm_so, 4);
3142 current_elem->
text[4] = 0;
3146 current_elem->
text = NULL;
3152 if ( i >= strlen(input) )
break;
3154 if ( !retval || !part_count )
3172 current_elem = parts;
3175 if ( current_elem->
text )
3185 current_elem = current_elem->
next;
3190 if ( current_elem->
text )
3200 current_elem = current_elem->
next;
3210 if ( current_elem->
text )
3220 current_elem = current_elem->
next;
3230 if ( current_elem->
text )
3240 current_elem = current_elem->
next;
3250 if ( current_elem->
text )
3260 current_elem = current_elem->
next;
3270 if ( current_elem->
text )
3280 current_elem = current_elem->
next;
3290 if ( current_elem->
text )
3300 current_elem = current_elem->
next;
3310 if ( current_elem->
text )
3320 current_elem = current_elem->
next;
3330 current_elem = current_elem->
next;
3340 current_elem = current_elem->
next;
3350 if ( current_elem->
text )
3354 current_elem = current_elem->
next;
3357 if ( current_elem && current_elem->
text )
3361 current_elem = current_elem->
next;
3375 unsigned int part_count;
3380 unsigned int matchcount = 2;
3381 regmatch_t matches[matchcount];
3386 current_elem = NULL;
3389 while ( regexec(&fapint_regex_peet_splitter, input+i, matchcount, matches, 0) == 0 )
3394 if ( !parts )
return 0;
3395 current_elem = parts;
3400 if ( !current_elem->
next )
3405 current_elem = current_elem->
next;
3407 current_elem->
next = NULL;
3408 if ( input[i+matches[1].rm_so] !=
'-' )
3410 current_elem->
text = malloc(5);
3411 if ( !current_elem->
text )
3416 memcpy(current_elem->
text, input+i+matches[1].rm_so, 4);
3417 current_elem->
text[4] = 0;
3421 current_elem->
text = NULL;
3427 if ( i >= strlen(input) )
break;
3429 if ( !retval || !part_count )
3447 current_elem = parts;
3450 if ( current_elem->
text )
3460 current_elem = current_elem->
next;
3465 if ( current_elem->
text )
3475 current_elem = current_elem->
next;
3485 if ( current_elem->
text )
3493 temp = strtol(current_elem->
text, NULL, 16);
3496 current_elem = current_elem->
next;
3506 if ( current_elem->
text )
3516 current_elem = current_elem->
next;
3526 if ( current_elem->
text )
3536 current_elem = current_elem->
next;
3546 current_elem = current_elem->
next;
3556 current_elem = current_elem->
next;
3566 current_elem = current_elem->
next;
3576 if ( current_elem->
text )
3586 current_elem = current_elem->
next;
3596 current_elem = current_elem->
next;
3606 current_elem = current_elem->
next;
3616 if ( current_elem->
text )
3620 current_elem = current_elem->
next;
3630 if ( current_elem->
text )
3640 current_elem = current_elem->
next;
3658 double lon_off = 0.0, lat_off = 0.0;
3661 if (
'A' <= input[0] && input[0] <=
'Z' && isdigit(input[1]) && isdigit(input[2]) )
3671 lat_off = (input[1]-48.0) * 0.001 / 60.0;
3672 lon_off = (input[2]-48.0) * 0.001 / 60.0;
3674 else if (
'a' <= input[0] && input[0] <=
'z' &&
3675 0x21 <= input[1] && input[1] <= 0x7b &&
3676 0x21 <= input[2] && input[2] <= 0x7b )
3687 lat_off = (input[1]-33.0)/91.0 * 0.01 / 60.0;
3688 lon_off = (input[2]-33.0)/91.0 * 0.01 / 60.0;
3690 else if ( 0x21 <= input[0] && input[0] <= 0x7b &&
3691 input[1] ==
' ' && input[2] ==
' ' )
3694 if (
'a' <= input[0] && input[0] <=
'z' )
3740 unsigned int matchcount = 3;
3741 regmatch_t matches[matchcount];
3747 if ( !input )
return NULL;
3749 if ( regexec(&fapint_regex_kiss_callsign, input, matchcount, (regmatch_t*)&matches, 0) == 0 )
3752 len = matches[2].rm_eo - matches[2].rm_so;
3755 tmp_str = malloc(len+1);
3756 if ( !tmp_str )
return NULL;
3757 memcpy(tmp_str, input+matches[2].rm_so, len);
3759 if ( atoi(tmp_str) < -15 )
3768 len += matches[1].rm_eo - matches[1].rm_so;
3769 tmp_str = malloc(len+1);
3770 if ( !tmp_str )
return NULL;
3771 memcpy(tmp_str, input+matches[1].rm_so, matches[1].rm_eo - matches[1].rm_so);
3772 memcpy(tmp_str+matches[1].rm_eo, input+matches[2].rm_so, matches[2].rm_eo - matches[2].rm_so);
3790 if ( !result )
return NULL;
3794 result->
type = NULL;
3800 result->
body = NULL;
3804 result->
path = NULL;
3816 result->
speed = NULL;
3831 result->
alive = NULL;