Changeset 1570 in ntrip
- Timestamp:
- Feb 10, 2009, 1:20:09 PM (16 years ago)
- Location:
- trunk/ntripserver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripserver/makefile
r653 r1570 1 1 #!/usr/bin/make 2 # $Id: makefile,v 1. 7 2007/08/30 14:57:34 stuerze Exp $2 # $Id: makefile,v 1.8 2008/01/04 15:22:44 stuerze Exp $ 3 3 4 4 ifdef windir 5 5 CC = gcc 6 OPTS = -Wall -W - O3 -DWINDOWSVERSION6 OPTS = -Wall -W -DWINDOWSVERSION 7 7 LIBS = -lwsock32 8 8 else 9 OPTS = -Wall -W -O39 OPTS = -Wall -W 10 10 endif 11 11 12 12 ntripserver: ntripserver.c 13 $(CC) $(OPTS) $? - DNDEBUG -o $@ $(LIBS)13 $(CC) $(OPTS) $? -O3 -DNDEBUG -o $@ $(LIBS) 14 14 15 15 debug: ntripserver.c 16 $(CC) $(OPTS) $? - o ntripserver $(LIBS)16 $(CC) $(OPTS) $? -g -o ntripserver $(LIBS) 17 17 18 18 clean: -
trunk/ntripserver/ntripserver.c
r1113 r1570 1 1 /* 2 * $Id: ntripserver.c,v 1.4 4 2008/06/06 07:34:09stuerze Exp $2 * $Id: ntripserver.c,v 1.45 2008/09/11 09:18:23 stuerze Exp $ 3 3 * 4 4 * Copyright (c) 2003...2007 … … 37 37 38 38 /* CVS revision and version */ 39 static char revisionstr[] = "$Revision: 1.4 4$";40 static char datestr[] = "$Date: 2008/0 6/06 07:34:09$";39 static char revisionstr[] = "$Revision: 1.45 $"; 40 static char datestr[] = "$Date: 2008/09/11 09:18:23 $"; 41 41 42 42 #include <ctype.h> … … 56 56 #include <winsock2.h> 57 57 #include <io.h> 58 #include <sys/stat.h> 59 #include <windows.h> 58 #include <sys/stat.h> 59 #include <windows.h> 60 60 typedef SOCKET sockettype; 61 61 typedef u_long in_addr_t; … … 90 90 CASTER = 6, LAST }; 91 91 92 enum OUTMODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, END };92 enum OUTMODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, UDP = 4, END }; 93 93 94 94 #define AGENTSTRING "NTRIP NtripServerPOSIX" … … 132 132 static const char * mountpoint = NULL; 133 133 static int udp_cseq = 1; 134 static int udp_tim, udp_seq, udp_init; 134 135 135 136 /* Forward references */ … … 150 151 #else 151 152 static HANDLE openserial(const char * tty, int baud); 152 #endif 153 #endif 153 154 154 155 … … 256 257 /* setup signal handler for CTRL+C */ 257 258 setup_signal_handler(SIGINT, handle_sigint); 258 #ifndef WINDOWSVERSION 259 #ifndef WINDOWSVERSION 259 260 /* setup signal handler for boken pipe */ 260 261 setup_signal_handler(SIGPIPE, handle_sigpipe); … … 271 272 } 272 273 #endif 273 274 274 275 /* get and check program arguments */ 275 276 if(argc <= 1) … … 397 398 else if(!strcmp(optarg,"r") || !strcmp(optarg,"rtsp")) 398 399 outputmode = RTSP; 400 else if(!strcmp(optarg,"u") || !strcmp(optarg,"udp")) 401 outputmode = UDP; 399 402 else outputmode = atoi(optarg); 400 403 if((outputmode == 0) || (outputmode >= END)) … … 535 538 case INFILE: 536 539 { 537 538 540 if((gps_file = open(filepath, O_RDONLY)) < 0) 541 { 539 542 perror("ERROR: opening input file"); 540 543 exit(1); 541 544 } 542 545 #ifndef WINDOWSVERSION 543 546 /* set blocking inputmode in case it was not set 544 547 (seems to be sometimes for fifo's) */ 545 546 #endif 547 548 fcntl(gps_file, F_SETFL, 0); 549 #endif 550 printf("file input: file = %s\n", filepath); 548 551 } 549 552 break; … … 551 554 { 552 555 #ifndef WINDOWSVERSION 553 556 gps_serial = openserial(ttyport, 1, ttybaud); 554 557 #else 555 556 #endif 557 558 559 560 561 558 gps_serial = openserial(ttyport, ttybaud); 559 #endif 560 if(gps_serial == INVALID_HANDLE_VALUE) exit(1); 561 printf("serial input: device = %s, speed = %d\n", ttyport, ttybaud); 562 563 if(initfile) 564 { 562 565 char buffer[1024]; 563 566 FILE *fh; … … 571 574 if((write(gps_serial, buffer, i)) != i) 572 575 { 573 574 575 576 perror("WARNING: sending init file"); 577 input_init = 0; 578 break; 576 579 } 577 580 #else 578 DWORD nWrite = -1; 581 DWORD nWrite = -1; 579 582 if(!WriteFile(gps_serial, buffer, sizeof(buffer), &nWrite, NULL)) 580 583 { 581 584 fprintf(stderr,"ERROR: sending init file \n"); 582 585 input_init = 0; 583 586 break; 584 587 } … … 602 605 break; 603 606 } 604 607 } 605 608 } 606 609 break; 607 610 case TCPSOCKET: case UDPSOCKET: case SISNET: case CASTER: 608 611 { 609 610 612 if(inputmode == SISNET) 613 { 611 614 if(!inhost) inhost = SISNET_SERVER; 612 615 if(!inport) inport = SISNET_PORT; 613 614 615 616 } 617 else if(inputmode == CASTER) 618 { 616 619 if(!inport) inport = NTRIP_PORT; 617 620 if(!inhost) inhost = NTRIP_CASTER; 618 619 620 621 } 622 else if((inputmode == TCPSOCKET) || (inputmode == UDPSOCKET)) 623 { 621 624 if(!inport) inport = SERV_TCP_PORT; 622 625 if(!inhost) inhost = SERV_HOST_ADDR; 623 624 625 626 626 } 627 628 if(!(he = gethostbyname(inhost))) 629 { 627 630 fprintf(stderr, "ERROR: Input host <%s> unknown\n", inhost); 628 631 usage(-2, argv[0]); 629 630 631 632 633 632 } 633 634 if((gps_socket = socket(AF_INET, inputmode == UDPSOCKET 635 ? SOCK_DGRAM : SOCK_STREAM, 0)) == INVALID_SOCKET) 636 { 634 637 fprintf(stderr, 635 638 "ERROR: can't create socket for incoming data stream\n"); 636 639 exit(1); 637 638 639 640 640 } 641 642 memset((char *) &caster, 0x00, sizeof(caster)); 643 if(!bindmode) 641 644 memcpy(&caster.sin_addr, he->h_addr, (size_t)he->h_length); 642 643 644 645 646 647 648 649 650 651 652 653 654 645 caster.sin_family = AF_INET; 646 caster.sin_port = htons(inport); 647 648 fprintf(stderr, "%s input: host = %s, port = %d, %s%s%s%s%s\n", 649 inputmode == CASTER ? "caster" : inputmode == SISNET ? "sisnet" : 650 inputmode == TCPSOCKET ? "tcp socket" : "udp socket", 651 bindmode ? "127.0.0.1" : inet_ntoa(caster.sin_addr), 652 inport, stream_name ? "stream = " : "", stream_name ? stream_name : "", 653 initfile ? ", initfile = " : "", initfile ? initfile : "", 654 bindmode ? "binding mode" : ""); 655 656 if(bindmode) 657 { 655 658 if(bind(gps_socket, (struct sockaddr *) &caster, sizeof(caster)) < 0) 656 659 { … … 660 663 break; 661 664 } 662 663 664 665 } /* connect to input-caster or proxy server*/ 666 else if(connect(gps_socket, (struct sockaddr *)&caster, sizeof(caster)) < 0) 667 { 665 668 fprintf(stderr, "WARNING: can't connect input to %s at port %d\n", 666 669 inet_ntoa(caster.sin_addr), inport); 667 670 input_init = 0; 668 671 break; 669 670 671 672 672 } 673 674 if(stream_name) /* input from Ntrip Version 1.0 caster*/ 675 { 673 676 int init = 0; 674 677 … … 702 705 reconnect_sec_max =0; 703 706 break; 704 } 707 } 705 708 szSendBuffer[nBufferBytes++] = '\r'; 706 709 szSendBuffer[nBufferBytes++] = '\n'; … … 730 733 { 731 734 if(strstr(szSendBuffer, "\r\n")) 732 { 735 { 733 736 if(!strstr(szSendBuffer, "ICY 200 OK")) 734 737 { … … 741 744 fprintf(stderr, "%c", isprint(szSendBuffer[k]) 742 745 ? szSendBuffer[k] : '.'); 743 746 } 744 747 fprintf(stderr, "\n"); 745 748 if(!strstr(szSendBuffer, "SOURCETABLE 200 OK")) … … 753 756 } 754 757 } 755 756 757 758 758 } /* end input from Ntrip Version 1.0 caster */ 759 760 if(initfile && inputmode != SISNET) 761 { 759 762 char buffer[1024]; 760 763 FILE *fh; … … 767 770 if((send(gps_socket, buffer, (size_t)i, 0)) != i) 768 771 { 769 770 771 772 perror("WARNING: sending init file"); 773 input_init = 0; 774 break; 772 775 } 773 776 } … … 788 791 break; 789 792 } 790 793 } 791 794 } 792 795 if(inputmode == SISNET) 793 796 { 794 795 796 797 797 int i, j; 798 char buffer[1024]; 799 800 i = snprintf(buffer, sizeof(buffer), sisnet >= 30 ? "AUTH,%s,%s\r\n" 798 801 : "AUTH,%s,%s", sisnetuser, sisnetpassword); 799 800 802 if((send(gps_socket, buffer, (size_t)i, 0)) != i) 803 { 801 804 perror("WARNING: sending authentication for SISNeT data server"); 802 805 input_init = 0; 803 806 break; 804 805 806 807 807 } 808 i = sisnet >= 30 ? 7 : 5; 809 if((j = recv(gps_socket, buffer, i, 0)) != i && strncmp("*AUTH", buffer, 5)) 810 { 808 811 fprintf(stderr, "WARNING: SISNeT connect failed:"); 809 812 for(i = 0; i < j; ++i) … … 817 820 input_init = 0; 818 821 break; 819 820 821 822 } 823 if(sisnet >= 31) 824 { 822 825 if((send(gps_socket, "START\r\n", 7, 0)) != i) 823 826 { … … 826 829 break; 827 830 } 828 831 } 829 832 } 830 833 /*** receiver authentication ***/ … … 832 835 || (inputmode == UDPSOCKET))) 833 836 { 834 835 837 if (strlen(recvrid) > (BUFSZ-3)) 838 { 836 839 fprintf(stderr, "ERROR: Receiver ID too long\n"); 837 840 reconnect_sec_max = 0; 838 841 input_init = 0; 839 842 break; 840 841 842 843 } 844 else 845 { 843 846 fprintf(stderr, "Sending user ID for receiver...\n"); 844 847 nBufferBytes = recv(gps_socket, szSendBuffer, BUFSZ, 0); … … 851 854 break; 852 855 } 853 854 855 856 857 fprintf(stderr, "ERROR: Receiver password too long\n"); 856 } 857 858 if (strlen(recvrpwd) > (BUFSZ-3)) 859 { 860 fprintf(stderr, "ERROR: Receiver password too long\n"); 858 861 reconnect_sec_max = 0; 859 862 input_init = 0; 860 863 break; 861 862 863 864 } 865 else 866 { 864 867 fprintf(stderr, "Sending user password for receiver...\n"); 865 868 nBufferBytes = recv(gps_socket, szSendBuffer, BUFSZ, 0); … … 872 875 break; 873 876 } 874 877 } 875 878 } 876 879 break; … … 879 882 break; 880 883 } 881 884 882 885 /* ----- main part ----- */ 883 886 int output_init = 1, fallback = 0; … … 892 895 if(!(he = gethostbyname(outhost))) 893 896 { 894 895 897 fprintf(stderr, "ERROR: Destination caster or proxy host <%s> unknown\n", 898 outhost); 896 899 close_session(casterouthost, mountpoint, session, rtsp_extension, 0); 897 900 usage(-2, argv[0]); 898 901 } 899 902 900 903 /* create socket */ 901 if((socket_tcp = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 902 { 903 perror("ERROR: tcp socket"); 904 if((socket_tcp = socket(AF_INET, (outputmode == UDP ? SOCK_DGRAM 905 : SOCK_STREAM), 0)) == INVALID_SOCKET) 906 { 907 perror("ERROR: tcp socket"); 904 908 reconnect_sec_max = 0; 905 909 break; … … 914 918 fprintf(stderr, "caster output: host = %s, port = %d, mountpoint = %s" 915 919 ", mode = %s\n\n", inet_ntoa(caster.sin_addr), outport, mountpoint, 916 outputmode == NTRIP1 ? "ntrip1" : outputmode == HTTP ? "http" : "rtsp"); 920 outputmode == NTRIP1 ? "ntrip1" : outputmode == HTTP ? "http" : 921 outputmode == UDP ? "udp" : "rtsp"); 917 922 918 923 if(connect(socket_tcp, (struct sockaddr *) &caster, sizeof(caster)) < 0) 919 924 { 920 925 fprintf(stderr, "WARNING: can't connect output to %s at port %d\n", 921 926 inet_ntoa(caster.sin_addr), outport); 922 927 break; … … 926 931 switch(outputmode) 927 932 { 928 case NTRIP1: /*** OutputMode Ntrip Version 1.0 ***/ 933 case UDP: 934 { 935 int session; 936 char rtpbuf[1526]; 937 int i=12, j; 938 939 udp_init = time(0); 940 srand(udp_init); 941 session = rand(); 942 udp_tim = rand(); 943 udp_seq = rand(); 944 945 rtpbuf[0] = (2<<6); 946 /* padding, extension, csrc are empty */ 947 rtpbuf[1] = 97; 948 /* marker is empty */ 949 rtpbuf[2] = (udp_seq>>8)&0xFF; 950 rtpbuf[3] = (udp_seq)&0xFF; 951 rtpbuf[4] = (udp_tim>>24)&0xFF; 952 rtpbuf[5] = (udp_tim>>16)&0xFF; 953 rtpbuf[6] = (udp_tim>>8)&0xFF; 954 rtpbuf[7] = (udp_tim)&0xFF; 955 /* sequence and timestamp are empty */ 956 rtpbuf[8] = (session>>24)&0xFF; 957 rtpbuf[9] = (session>>16)&0xFF; 958 rtpbuf[10] = (session>>8)&0xFF; 959 rtpbuf[11] = (session)&0xFF; 960 ++udp_seq; 961 962 j = snprintf(rtpbuf+i, sizeof(rtpbuf)-i-40, /* leave some space for login */ 963 "POST /%s HTTP/1.1\r\n" 964 "Host: %s\r\n" 965 "Ntrip-Version: Ntrip/2.0\r\n" 966 "User-Agent: %s/%s\r\n" 967 "Authorization: Basic %s%s%s\r\n" 968 "Connection: close\r\n" 969 "Transfer-Encoding: chunked\r\n\r\n", 970 mountpoint, casterouthost, AGENTSTRING, 971 revisionstr, authorization, ntrip_str ? "\r\nNtrip-STR: " : "", 972 ntrip_str); 973 i += j; 974 if(i > (int)sizeof(rtpbuf)-40 || j < 0) /* second check for old glibc */ 975 { 976 fprintf(stderr, "Requested data too long\n"); 977 reconnect_sec_max = 0; 978 output_init = 0; 979 break; 980 } 981 else 982 { 983 rtpbuf[i++] = '\r'; 984 rtpbuf[i++] = '\n'; 985 rtpbuf[i++] = '\r'; 986 rtpbuf[i++] = '\n'; 987 988 if(send(socket_tcp, rtpbuf, i, 0) != i) 989 { 990 perror("Could not send UDP packet"); 991 reconnect_sec_max = 0; 992 output_init = 0; 993 break; 994 } 995 else 996 { 997 int stop = 0; 998 int numbytes; 999 if((numbytes=recv(socket_tcp, rtpbuf, sizeof(rtpbuf)-1, 0)) > 0) 1000 { 1001 /* we don't expect message longer than 1513, so we cut the last 1002 byte for security reasons to prevent buffer overrun */ 1003 rtpbuf[numbytes] = 0; 1004 if(numbytes > 17+12 && 1005 (!strncmp(rtpbuf+12, "HTTP/1.1 200 OK\r\n", 17) || 1006 !strncmp(rtpbuf+12, "HTTP/1.0 200 OK\r\n", 17))) 1007 { 1008 const char *sessioncheck = "session: "; 1009 int l = strlen(sessioncheck)-1; 1010 int j=0; 1011 for(i = 12; j != l && i < numbytes-l; ++i) 1012 { 1013 for(j = 0; j < l && tolower(rtpbuf[i+j]) == sessioncheck[j]; ++j) 1014 ; 1015 } 1016 if(i != numbytes-l) /* found a session number */ 1017 { 1018 i+=l; 1019 session = 0; 1020 while(i < numbytes && rtpbuf[i] >= '0' && rtpbuf[i] <= '9') 1021 session = session * 10 + rtpbuf[i++]-'0'; 1022 if(rtpbuf[i] != '\r') 1023 { 1024 fprintf(stderr, "Could not extract session number\n"); 1025 stop = 1; 1026 } 1027 } 1028 } 1029 else 1030 { 1031 int k; 1032 fprintf(stderr, "Could not access mountpoint: "); 1033 for(k = 12; k < numbytes && rtpbuf[k] != '\n' && rtpbuf[k] != '\r'; ++k) 1034 { 1035 fprintf(stderr, "%c", isprint(rtpbuf[k]) ? rtpbuf[k] : '.'); 1036 } 1037 fprintf(stderr, "\n"); 1038 stop = 1; 1039 } 1040 } 1041 if(!stop) 1042 { 1043 send_receive_loop(socket_tcp, outputmode, NULL, 0, session); 1044 input_init = output_init = 0; 1045 /* send connection close always to allow nice session closing */ 1046 udp_tim += (time(0)-udp_init)*1000000/TIME_RESOLUTION; 1047 rtpbuf[0] = (2<<6); 1048 /* padding, extension, csrc are empty */ 1049 rtpbuf[1] = 98; 1050 /* marker is empty */ 1051 rtpbuf[2] = (udp_seq>>8)&0xFF; 1052 rtpbuf[3] = (udp_seq)&0xFF; 1053 rtpbuf[4] = (udp_tim>>24)&0xFF; 1054 rtpbuf[5] = (udp_tim>>16)&0xFF; 1055 rtpbuf[6] = (udp_tim>>8)&0xFF; 1056 rtpbuf[7] = (udp_tim)&0xFF; 1057 /* sequence and timestamp are empty */ 1058 rtpbuf[8] = (session>>24)&0xFF; 1059 rtpbuf[9] = (session>>16)&0xFF; 1060 rtpbuf[10] = (session>>8)&0xFF; 1061 rtpbuf[11] = (session)&0xFF; 1062 1063 send(socket_tcp, rtpbuf, 12, 0); /* cleanup */ 1064 } 1065 else 1066 { 1067 reconnect_sec_max = 600; 1068 output_init = 0; 1069 } 1070 } 1071 } 1072 } 1073 break; 1074 case NTRIP1: /*** OutputMode Ntrip Version 1.0 ***/ 929 1075 fallback = 0; 930 1076 nBufferBytes = snprintf(szSendBuffer, sizeof(szSendBuffer), … … 958 1104 fprintf(stderr, "\n"); 959 1105 if((strstr(szSendBuffer,"ERROR - Bad Password")) 960 || (strstr(szSendBuffer,"400 Bad Request"))) 1106 || (strstr(szSendBuffer,"400 Bad Request"))) 961 1107 reconnect_sec_max = 0; 962 1108 output_init = 0; … … 973 1119 input_init = output_init = 0; 974 1120 break; 975 1121 case HTTP: /*** Ntrip-Version 2.0 HTTP/1.1 ***/ 976 1122 nBufferBytes = snprintf(szSendBuffer, sizeof(szSendBuffer), 977 1123 "POST %s/%s HTTP/1.1\r\n" … … 1042 1188 input_init = output_init = 0; 1043 1189 break; 1044 1190 case RTSP: /*** Ntrip-Version 2.0 RTSP / RTP ***/ 1045 1191 if((socket_udp = socket(AF_INET, SOCK_DGRAM,0)) == INVALID_SOCKET) 1046 1192 { … … 1109 1255 for(a = szSendBuffer; *a && *a != '\n' && *a != '\r'; ++a) 1110 1256 { 1111 1257 fprintf(stderr, "%c", isprint(*a) ? *a : '.'); 1112 1258 } 1113 1259 fprintf(stderr, "\n"); … … 1115 1261 if(strncmp(szSendBuffer, "RTSP",4) != 0) 1116 1262 { 1117 1118 1263 if(strstr(szSendBuffer,"Ntrip-Version: Ntrip/2.0\r\n")) 1264 { 1119 1265 fprintf(stderr, 1120 1266 " RTSP not implemented at Destination caster <%s>%s%s%s\n\n" … … 1126 1272 fallback = 1; 1127 1273 break; 1128 1129 1130 1274 } 1275 else 1276 { 1131 1277 fprintf(stderr, 1132 1278 " Ntrip-Version 2.0 not implemented at Destination caster" … … 1142 1288 fallback = 1; 1143 1289 break; 1144 1290 } 1145 1291 } 1146 1292 else if((strstr(szSendBuffer, "RTSP/1.0 401 Unauthorized")) … … 1164 1310 token = strtok(NULL, dlim)) 1165 1311 { 1166 1312 tok_buf[i] = token; i++; 1167 1313 } 1168 1314 session = atoi(tok_buf[6]); 1169 1315 server_port = atoi(tok_buf[10]); 1170 1316 nBufferBytes = snprintf(szSendBuffer, sizeof(szSendBuffer), 1171 1172 1173 1174 1175 1176 1317 "RECORD rtsp://%s%s/%s RTSP/1.0\r\n" 1318 "CSeq: %d\r\n" 1319 "Session: %d\r\n" 1320 "\r\n", 1321 casterouthost, rtsp_extension, mountpoint, udp_cseq++, 1322 session); 1177 1323 if((nBufferBytes >= (int)sizeof(szSendBuffer)) 1178 1324 || (nBufferBytes < 0)) 1179 1325 { 1180 1326 fprintf(stderr, "ERROR: Destination caster request to long\n"); 1181 1327 reconnect_sec_max = 0; 1182 1328 output_init = 0; 1183 1329 break; 1184 1330 } 1185 1331 if(!send_to_caster(szSendBuffer, socket_tcp, nBufferBytes)) 1186 1332 { 1187 1333 output_init = 0; 1188 1334 break; 1189 1335 } 1190 1336 } 1191 1337 else if((strstr(szSendBuffer,"RTSP/1.0 200 OK\r\n")) && (strstr(szSendBuffer, 1192 "CSeq: 2\r\n"))) 1338 "CSeq: 2\r\n"))) 1193 1339 { 1194 1340 /* fill structure with caster address information for UDP */ … … 1196 1342 casterRTP.sin_family = AF_INET; 1197 1343 casterRTP.sin_port = htons(((uint16_t)server_port)); 1198 if((he = gethostbyname(outhost))== NULL) 1344 if((he = gethostbyname(outhost))== NULL) 1199 1345 { 1200 1346 fprintf(stderr, "ERROR: Destination caster unknown\n"); 1201 1347 reconnect_sec_max = 0; 1202 1348 output_init = 0; … … 1205 1351 else 1206 1352 { 1207 1208 1353 memcpy((char *)&casterRTP.sin_addr.s_addr, 1354 he->h_addr_list[0], (size_t)he->h_length); 1209 1355 } 1210 1356 len = (socklen_t)sizeof(casterRTP); 1211 send_receive_loop(socket_udp, outputmode, (struct sockaddr *)&casterRTP, 1357 send_receive_loop(socket_udp, outputmode, (struct sockaddr *)&casterRTP, 1212 1358 (socklen_t)len, session); 1213 1359 break; … … 1245 1391 time_t laststate = time(0); 1246 1392 1247 if(outmode == RTSP) 1248 { 1393 if(outmode == UDP) 1394 { 1395 rtptime = time(0); 1249 1396 #ifdef WINDOWSVERSION 1250 1397 u_long blockmode = 1; … … 1258 1405 } 1259 1406 } 1407 else if(outmode == RTSP) 1408 { 1409 #ifdef WINDOWSVERSION 1410 u_long blockmode = 1; 1411 if(ioctlsocket(socket_tcp, FIONBIO, &blockmode)) 1412 #else /* WINDOWSVERSION */ 1413 if(fcntl(socket_tcp, F_SETFL, O_NONBLOCK) < 0) 1414 #endif /* WINDOWSVERSION */ 1415 { 1416 fprintf(stderr, "Could not set nonblocking mode\n"); 1417 return; 1418 } 1419 } 1260 1420 1261 1421 /* data transmission */ 1262 1422 fprintf(stderr,"transfering data ...\n"); 1263 1423 int send_recv_success = 0; 1264 #ifdef WINDOWSVERSION 1265 time_t nodata_begin = 0, nodata_current = 0; 1424 #ifdef WINDOWSVERSION 1425 time_t nodata_begin = 0, nodata_current = 0; 1266 1426 #endif 1267 1427 while(1) 1268 1428 { 1269 if(send_recv_success < 3) send_recv_success++; 1429 if(send_recv_success < 3) send_recv_success++; 1270 1430 if(!nodata) 1271 { 1431 { 1272 1432 #ifndef WINDOWSVERSION 1273 1433 alarm(ALARMTIME); … … 1276 1436 #endif 1277 1437 } 1278 else 1279 { 1280 nodata = 0; 1281 #ifdef WINDOWSVERSION 1438 else 1439 { 1440 nodata = 0; 1441 #ifdef WINDOWSVERSION 1282 1442 time(&nodata_current); 1283 if(difftime(nodata_current, nodata_begin) >= ALARMTIME) 1443 if(difftime(nodata_current, nodata_begin) >= ALARMTIME) 1284 1444 { 1285 1445 sigalarm_received = 1; … … 1316 1476 else if(inputmode == SERIAL) 1317 1477 { 1318 #ifndef WINDOWSVERSION 1478 #ifndef WINDOWSVERSION 1319 1479 nBufferBytes = read(gps_serial, buffer, sizeof(buffer)); 1320 1480 #else 1321 DWORD nRead = 0; 1481 DWORD nRead = 0; 1322 1482 if(!ReadFile(gps_serial, buffer, sizeof(buffer), &nRead, NULL)) 1323 1483 { … … 1358 1518 } 1359 1519 } 1520 if(nBufferBytes < 0) 1521 return; 1360 1522 /** send data ***/ 1361 1523 if((nBufferBytes) && (outmode == NTRIP1)) /*** Ntrip-Version 1.0 ***/ … … 1381 1543 { 1382 1544 nBufferBytes = 0; 1545 } 1546 } 1547 else if((nBufferBytes) && (outmode == UDP)) 1548 { 1549 char rtpbuf[1592]; 1550 int i; 1551 int ct = time(0); 1552 udp_tim += (ct-udp_init)*1000000/TIME_RESOLUTION; 1553 udp_init = ct; 1554 rtpbuf[0] = (2<<6); 1555 rtpbuf[1] = 96; 1556 rtpbuf[2] = (udp_seq>>8)&0xFF; 1557 rtpbuf[3] = (udp_seq)&0xFF; 1558 rtpbuf[4] = (udp_tim>>24)&0xFF; 1559 rtpbuf[5] = (udp_tim>>16)&0xFF; 1560 rtpbuf[6] = (udp_tim>>8)&0xFF; 1561 rtpbuf[7] = (udp_tim)&0xFF; 1562 rtpbuf[8] = (rtpssrc>>24)&0xFF; 1563 rtpbuf[9] = (rtpssrc>>16)&0xFF; 1564 rtpbuf[10] = (rtpssrc>>8)&0xFF; 1565 rtpbuf[11] = (rtpssrc)&0xFF; 1566 ++udp_seq; 1567 memcpy(rtpbuf+12, buffer, nBufferBytes); 1568 if((i = send(socket_tcp, rtpbuf, (size_t)nBufferBytes+12, MSG_DONTWAIT)) 1569 != nBufferBytes+12) 1570 { 1571 if(errno != EAGAIN) 1572 { 1573 perror("WARNING: could not send data to Destination caster"); 1574 return; 1575 } 1576 } 1577 else 1578 nBufferBytes = 0; 1579 i = recv(socket_tcp, rtpbuf, sizeof(rtpbuf), 0); 1580 if(i >= 12 && (unsigned char)rtpbuf[0] == (2 << 6) && rtpbuf[1] >= 96 1581 && rtpbuf[1] <= 98 && rtpssrc == 1582 (((unsigned char)rtpbuf[8]<<24)+((unsigned char)rtpbuf[9]<<16) 1583 +((unsigned char)rtpbuf[10]<<8)+(unsigned char)rtpbuf[11])) 1584 { 1585 rtptime = time(0); 1586 } 1587 else if(time(0) > rtptime+60) 1588 { 1589 fprintf(stderr, "Timeout\n"); 1590 return; 1383 1591 } 1384 1592 } … … 1642 1850 static HANDLE openserial(const char * tty, int baud) 1643 1851 { 1644 DCB dcb; 1852 DCB dcb; 1645 1853 COMMTIMEOUTS cmt; 1646 1854 char compath[15] = ""; … … 1648 1856 snprintf(compath, sizeof(compath), "\\\\.\\%s", tty); 1649 1857 /*** opening the serial port ***/ 1650 gps_serial = CreateFile(compath, GENERIC_READ | GENERIC_WRITE, 0, 0, 1858 gps_serial = CreateFile(compath, GENERIC_READ | GENERIC_WRITE, 0, 0, 1651 1859 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 1652 1860 if(gps_serial == INVALID_HANDLE_VALUE) … … 1715 1923 break; 1716 1924 } 1717 dcb.BaudRate = baud; 1925 dcb.BaudRate = baud; 1718 1926 dcb.ByteSize = 8; 1719 1927 dcb.StopBits = ONESTOPBIT; … … 1731 1939 { 1732 1940 fprintf(stderr, "ERROR: set serial timeouts\n"); 1733 return (INVALID_HANDLE_VALUE); 1941 return (INVALID_HANDLE_VALUE); 1734 1942 } 1735 1943 return (gps_serial); … … 1826 2034 fprintf(stderr, " 2 = rtsp: NTRIP Version 2.0 Caster in RTSP/RTP mode\n"); 1827 2035 fprintf(stderr, " 3 = ntrip1: NTRIP Version 1.0 Caster\n"); 2036 fprintf(stderr, " 4 = udp: NTRIP Version 2.0 Caster in Plain UDP mode\n"); 1828 2037 fprintf(stderr, " optional\n\n"); 1829 2038 fprintf(stderr, " Defaults to NTRIP1.0, but will change to 2.0 in future versions\n"); … … 1996 2205 * close session * 1997 2206 *********************************************************************/ 1998 static void close_session(const char *caster_addr, const char *mountpoint, 2207 static void close_session(const char *caster_addr, const char *mountpoint, 1999 2208 int session, char *rtsp_ext, int fallback) 2000 2209 { … … 2004 2213 if(!fallback) 2005 2214 { 2006 if((gps_socket != INVALID_SOCKET) && 2007 ((inputmode == TCPSOCKET) || (inputmode == UDPSOCKET) || 2215 if((gps_socket != INVALID_SOCKET) && 2216 ((inputmode == TCPSOCKET) || (inputmode == UDPSOCKET) || 2008 2217 (inputmode == CASTER) || (inputmode == SISNET))) 2009 { 2218 { 2010 2219 if(closesocket(gps_socket) == -1) 2011 2220 { … … 2016 2225 { 2017 2226 gps_socket = -1; 2018 #ifndef NDEBUG 2227 #ifndef NDEBUG 2019 2228 fprintf(stderr, "close input device: successful\n"); 2020 2229 #endif … … 2039 2248 { 2040 2249 gps_serial = INVALID_HANDLE_VALUE; 2041 #ifndef NDEBUG 2250 #ifndef NDEBUG 2042 2251 fprintf(stderr, "close input device: successful\n"); 2043 2252 #endif … … 2045 2254 } 2046 2255 else if((gps_file != -1) && (inputmode == INFILE)) 2047 { 2256 { 2048 2257 if(close(gps_file) == -1) 2049 2258 { … … 2054 2263 { 2055 2264 gps_file = -1; 2056 #ifndef NDEBUG 2265 #ifndef NDEBUG 2057 2266 fprintf(stderr, "close input device: successful\n"); 2058 2267 #endif
Note:
See TracChangeset
for help on using the changeset viewer.