Changeset 653 in ntrip for trunk/ntripserver
- Timestamp:
- Jan 4, 2008, 4:23:06 PM (17 years ago)
- Location:
- trunk/ntripserver
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripserver/README
r548 r653 84 84 - make debug (for debugging purposes). 85 85 86 The exacutable will show up as ntripserver. 87 86 To compile the source code on a Windows system where a mingw gcc 87 compiler is available, you may like to run the following command: 88 89 - gcc -Wall -W -O3 -DWINDOWSVERSION ntripserver.c -DNDEBUG 90 -o ntripserver -lwsock32, or 91 - mingw32-make, or 92 - mingw32-make debug 93 94 The exacutable will show up as ntripserver on Linux 95 or ntripserver.exe on a Windows system. 88 96 89 97 Usage -
trunk/ntripserver/makefile
r489 r653 1 1 #!/usr/bin/make 2 # $Id: makefile,v 1.6 2007/08/30 07:45:59 stoecker Exp $ 2 # $Id: makefile,v 1.7 2007/08/30 14:57:34 stuerze Exp $ 3 4 ifdef windir 5 CC = gcc 6 OPTS = -Wall -W -O3 -DWINDOWSVERSION 7 LIBS = -lwsock32 8 else 9 OPTS = -Wall -W -O3 10 endif 3 11 4 12 ntripserver: ntripserver.c 5 $(CC) -Wall -W -O3 $? -DNDEBUG -o $@13 $(CC) $(OPTS) $? -DNDEBUG -o $@ $(LIBS) 6 14 7 15 debug: ntripserver.c 8 $(CC) -Wall -W -O3 $? -o ntripserver16 $(CC) $(OPTS) $? -o ntripserver $(LIBS) 9 17 10 18 clean: -
trunk/ntripserver/ntripserver.c
r598 r653 1 1 /* 2 * $Id: ntripserver.c,v 1.3 5 2007/08/30 16:40:51stoecker Exp $2 * $Id: ntripserver.c,v 1.36 2007/12/14 07:23:44 stoecker Exp $ 3 3 * 4 4 * Copyright (c) 2003...2007 … … 37 37 38 38 /* CVS revision and version */ 39 static char revisionstr[] = "$Revision: 1.3 5$";40 static char datestr[] = "$Date: 2007/ 08/30 16:40:51$";39 static char revisionstr[] = "$Revision: 1.36 $"; 40 static char datestr[] = "$Date: 2007/12/14 07:23:44 $"; 41 41 42 42 #include <ctype.h> … … 44 44 #include <fcntl.h> 45 45 #include <getopt.h> 46 #include <netdb.h>47 #include <signal.h>48 46 #include <stdio.h> 49 47 #include <stdlib.h> 50 48 #include <string.h> 49 #include <sys/time.h> 50 #include <sys/types.h> 51 #include <time.h> 52 #include <signal.h> 51 53 #include <unistd.h> 52 #include <arpa/inet.h> 53 #include <netinet/in.h> 54 #include <sys/socket.h> 55 #include <sys/termios.h> 56 #include <sys/types.h> 57 #include <sys/time.h> 54 55 #ifdef WINDOWSVERSION 56 #include <winsock2.h> 57 #include <io.h> 58 #include <sys/stat.h> 59 #include <windows.h> 60 typedef SOCKET sockettype; 61 typedef u_long in_addr_t; 62 typedef size_t socklen_t; 63 typedef u_short uint16_t; 64 #else 65 typedef int sockettype; 66 #include <arpa/inet.h> 67 #include <sys/socket.h> 68 #include <netinet/in.h> 69 #include <netdb.h> 70 #include <sys/termios.h> 71 #define closesocket(sock) close(sock) 72 #define INVALID_HANDLE_VALUE -1 73 #define INVALID_SOCKET -1 74 #endif 58 75 59 76 #ifndef COMPILEDATE 60 77 #define COMPILEDATE " built " __DATE__ 61 78 #endif 79 80 #define ALARMTIME (2*60) 62 81 63 82 #ifndef MSG_DONTWAIT … … 85 104 #define NTRIP_PORT 2101 86 105 87 /* default sisnet source */88 106 #define SISNET_SERVER "131.176.49.142" 89 107 #define SISNET_PORT 7777 90 91 #define ALARMTIME 6092 108 93 109 #define RTP_VERSION 2 … … 99 115 static enum MODE inputmode = INFILE; 100 116 static int sisnet = 31; 101 static int gpsfd = -1; 102 static int socket_tcp = -1; 103 static int socket_udp = -1; 117 static int gps_file = -1; 118 static sockettype gps_socket = INVALID_SOCKET; 119 static sockettype socket_tcp = INVALID_SOCKET; 120 static sockettype socket_udp = INVALID_SOCKET; 121 #ifndef WINDOWSVERSION 122 static int gps_serial = INVALID_HANDLE_VALUE; 123 static int sigpipe_received = 0; 124 #else 125 HANDLE gps_serial = INVALID_HANDLE_VALUE; 126 #endif 127 static int sigalarm_received = 0; 104 128 static int sigint_received = 0; 105 static int sigalarm_received = 0;106 static int sigpipe_received = 0;107 129 static int reconnect_sec = 1; 108 130 109 131 110 132 /* Forward references */ 111 static int openserial(const char * tty, int blocksz, int baud); 112 static void send_receive_loop(int sock, int fd, int outmode, 133 static void send_receive_loop(sockettype sock, int outmode, 113 134 struct sockaddr * pcasterRTP, socklen_t length); 114 135 static void usage(int, char *); 115 136 static int encode(char *buf, int size, const char *user, const char *pwd); 116 static int send_to_caster(char *input, intsocket, int input_size);137 static int send_to_caster(char *input, sockettype socket, int input_size); 117 138 static void close_session(const char *caster_addr, const char *mountpoint, 118 139 int cseq, int session, char *rtsp_ext, int fallback); 119 140 static int reconnect(int rec_sec, int rec_sec_max); 120 121 /* Signal Handling */122 141 static void handle_sigint(int sig); 142 static void setup_signal_handler(int sig, void (*handler)(int)); 143 #ifndef WINDOWSVERSION 144 static int openserial(const char * tty, int blocksz, int baud); 145 static void handle_sigpipe(int sig); 123 146 static void handle_alarm(int sig); 124 static void handle_sigpipe(int sig); 125 static void setup_signal_handler(int sig, void (*handler)(int)); 147 #else 148 static HANDLE openserial(const char * tty, int baud); 149 #endif 150 126 151 127 152 /* … … 230 255 } 231 256 257 /* setup signal handler for CTRL+C */ 258 setup_signal_handler(SIGINT, handle_sigint); 259 #ifndef WINDOWSVERSION 260 /* setup signal handler for boken pipe */ 261 setup_signal_handler(SIGPIPE, handle_sigpipe); 232 262 /* setup signal handler for timeout */ 233 263 setup_signal_handler(SIGALRM, handle_alarm); 234 264 alarm(ALARMTIME); 235 236 /* setup signal handler for CTRL+C */ 237 setup_signal_handler(SIGINT, handle_sigint); 265 #else 266 /* winsock initialization */ 267 WSADATA wsaData; 268 if (WSAStartup(MAKEWORD(1,1), &wsaData)) 269 { 270 fprintf(stderr, "Could not init network access.\n"); 271 return 20; 272 } 273 #endif 238 274 239 /* setup signal handler for boken pipe */240 setup_signal_handler(SIGPIPE, handle_sigpipe);241 242 275 /* get and check program arguments */ 243 276 if(argc <= 1) … … 497 530 { 498 531 int input_init = 1; 532 if(sigint_received) break; 499 533 /*** InputMode handling ***/ 500 534 switch(inputmode) … … 502 536 case INFILE: 503 537 { 504 if((gps fd= open(filepath, O_RDONLY)) < 0)538 if((gps_file = open(filepath, O_RDONLY)) < 0) 505 539 { 506 540 perror("ERROR: opening input file"); 507 541 exit(1); 508 542 } 543 #ifndef WINDOWSVERSION 509 544 /* set blocking inputmode in case it was not set 510 545 (seems to be sometimes for fifo's) */ 511 fcntl(gpsfd, F_SETFL, 0); 546 fcntl(gps_file, F_SETFL, 0); 547 #endif 512 548 printf("file input: file = %s\n", filepath); 513 549 } … … 515 551 case SERIAL: /* open serial port */ 516 552 { 517 gpsfd = openserial(ttyport, 1, ttybaud); 518 if(gpsfd < 0) 519 { 520 exit(1); 521 } 553 #ifndef WINDOWSVERSION 554 gps_serial = openserial(ttyport, 1, ttybaud); 555 #else 556 gps_serial = openserial(ttyport, ttybaud); 557 #endif 558 if(gps_serial == INVALID_HANDLE_VALUE) exit(1); 522 559 printf("serial input: device = %s, speed = %d\n", ttyport, ttybaud); 523 560 } … … 547 584 } 548 585 549 if((gps fd= socket(AF_INET, inputmode == UDPSOCKET550 ? SOCK_DGRAM : SOCK_STREAM, 0)) < 0)586 if((gps_socket = socket(AF_INET, inputmode == UDPSOCKET 587 ? SOCK_DGRAM : SOCK_STREAM, 0)) == INVALID_SOCKET) 551 588 { 552 589 fprintf(stderr, … … 571 608 if(bindmode) 572 609 { 573 if(bind(gps fd, (struct sockaddr *) &caster, sizeof(caster)) < 0)610 if(bind(gps_socket, (struct sockaddr *) &caster, sizeof(caster)) < 0) 574 611 { 575 612 fprintf(stderr, "ERROR: can't bind input to port %d\n", inport); … … 579 616 } 580 617 } /* connect to input-caster or proxy server*/ 581 else if(connect(gps fd, (struct sockaddr *)&caster, sizeof(caster)) < 0)618 else if(connect(gps_socket, (struct sockaddr *)&caster, sizeof(caster)) < 0) 582 619 { 583 620 fprintf(stderr, "WARNING: can't connect input to %s at port %d\n", … … 592 629 593 630 /* set socket buffer size */ 594 setsockopt(gps fd, SOL_SOCKET, SO_SNDBUF, (const char *) &size,631 setsockopt(gps_socket, SOL_SOCKET, SO_SNDBUF, (const char *) &size, 595 632 sizeof(const char *)); 596 633 if(stream_user && stream_password) … … 634 671 "\r\n", get_extension, stream_name, AGENTSTRING, revisionstr); 635 672 } 636 if((send(gps fd, szSendBuffer, (size_t)nBufferBytes, 0))673 if((send(gps_socket, szSendBuffer, (size_t)nBufferBytes, 0)) 637 674 != nBufferBytes) 638 675 { … … 644 681 /* check Source caster's response */ 645 682 while(!init && nBufferBytes < (int)sizeof(szSendBuffer) 646 && (nBufferBytes += recv(gps fd, szSendBuffer,683 && (nBufferBytes += recv(gps_socket, szSendBuffer, 647 684 sizeof(szSendBuffer)-nBufferBytes, 0)) > 0) 648 685 { … … 683 720 while((i = fread(buffer, 1, sizeof(buffer), fh)) > 0) 684 721 { 685 if((send(gps fd, buffer, (size_t)i, 0)) != i)722 if((send(gps_socket, buffer, (size_t)i, 0)) != i) 686 723 { 687 724 perror("WARNING: sending init file"); … … 715 752 i = snprintf(buffer, sizeof(buffer), sisnet >= 30 ? "AUTH,%s,%s\r\n" 716 753 : "AUTH,%s,%s", sisnetuser, sisnetpassword); 717 if((send(gps fd, buffer, (size_t)i, 0)) != i)754 if((send(gps_socket, buffer, (size_t)i, 0)) != i) 718 755 { 719 756 perror("WARNING: sending authentication for SISNeT data server"); … … 722 759 } 723 760 i = sisnet >= 30 ? 7 : 5; 724 if((j = recv(gps fd, buffer, i, 0)) != i && strncmp("*AUTH", buffer, 5))761 if((j = recv(gps_socket, buffer, i, 0)) != i && strncmp("*AUTH", buffer, 5)) 725 762 { 726 763 fprintf(stderr, "WARNING: SISNeT connect failed:"); … … 738 775 if(sisnet >= 31) 739 776 { 740 if((send(gps fd, "START\r\n", 7, 0)) != i)777 if((send(gps_socket, "START\r\n", 7, 0)) != i) 741 778 { 742 779 perror("WARNING: sending Sisnet start command"); … … 760 797 { 761 798 fprintf(stderr, "Sending user ID for receiver...\n"); 762 nBufferBytes = re ad(gpsfd, szSendBuffer, BUFSZ);799 nBufferBytes = recv(gps_socket, szSendBuffer, BUFSZ, 0); 763 800 strcpy(szSendBuffer, recvrid); 764 801 strcat(szSendBuffer,"\r\n"); 765 if(send(gps fd,szSendBuffer, strlen(szSendBuffer), MSG_DONTWAIT) < 0)802 if(send(gps_socket,szSendBuffer, strlen(szSendBuffer), MSG_DONTWAIT) < 0) 766 803 { 767 804 perror("WARNING: sending user ID for receiver"); … … 781 818 { 782 819 fprintf(stderr, "Sending user password for receiver...\n"); 783 nBufferBytes = re ad(gpsfd, szSendBuffer, BUFSZ);820 nBufferBytes = recv(gps_socket, szSendBuffer, BUFSZ, 0); 784 821 strcpy(szSendBuffer, recvrpwd); 785 822 strcat(szSendBuffer,"\r\n"); 786 if(send(gps fd, szSendBuffer, strlen(szSendBuffer), MSG_DONTWAIT) < 0)823 if(send(gps_socket, szSendBuffer, strlen(szSendBuffer), MSG_DONTWAIT) < 0) 787 824 { 788 825 perror("WARNING: sending user password for receiver"); … … 803 840 while((input_init) && (output_init)) 804 841 { 805 if((sigint_received) || (sigalarm_received) || (sigpipe_received)) break; 806 842 #ifndef WINDOWSVERSION 843 if((sigalarm_received) || (sigint_received) || (sigpipe_received)) break; 844 #else 845 if((sigalarm_received) || (sigint_received)) break; 846 #endif 807 847 if(!(he = gethostbyname(outhost))) 808 848 { … … 814 854 815 855 /* create socket */ 816 if((socket_tcp = socket(AF_INET, SOCK_STREAM, 0)) < 0)856 if((socket_tcp = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) 817 857 { 818 858 perror("ERROR: tcp socket"); … … 884 924 } 885 925 #endif 886 send_receive_loop(socket_tcp, gpsfd, outputmode, NULL, 0); 926 send_receive_loop(socket_tcp, outputmode, NULL, 0); 927 input_init = output_init = 0; 887 928 break; 888 929 case HTTP: /*** Ntrip-Version 2.0 HTTP/1.1 ***/ … … 952 993 } 953 994 #endif 954 send_receive_loop(socket_tcp, gpsfd, outputmode, NULL, 0); 995 send_receive_loop(socket_tcp, outputmode, NULL, 0); 996 input_init = output_init = 0; 955 997 break; 956 998 case RTSP: /*** Ntrip-Version 2.0 RTSP / RTP ***/ 957 if((socket_udp = socket(AF_INET, SOCK_DGRAM,0)) < 0)999 if((socket_udp = socket(AF_INET, SOCK_DGRAM,0)) == INVALID_SOCKET) 958 1000 { 959 1001 perror("ERROR: udp socket"); … … 1087 1129 || (nBufferBytes < 0)) 1088 1130 { 1089 fprintf(stderr, "ERROR: Destination caster request to long\n");1131 fprintf(stderr, "ERROR: Destination caster request to long\n"); 1090 1132 reconnect_sec_max = 0; 1091 1133 output_init = 0; … … 1094 1136 if(!send_to_caster(szSendBuffer, socket_tcp, nBufferBytes)) 1095 1137 { 1096 1097 break;1138 output_init = 0; 1139 break; 1098 1140 } 1099 1141 } … … 1119 1161 cseq = 2; 1120 1162 len = (socklen_t)sizeof(casterRTP); 1121 send_receive_loop(socket_udp, gpsfd,outputmode, (struct sockaddr *)&casterRTP,1163 send_receive_loop(socket_udp, outputmode, (struct sockaddr *)&casterRTP, 1122 1164 (socklen_t)len); 1123 1165 break; … … 1125 1167 else{break;} 1126 1168 } 1169 input_init = output_init = 0; 1127 1170 break; 1128 1171 } 1129 1172 } 1130 1173 close_session(casterouthost, mountpoint, cseq, session, rtsp_extension, 0); 1131 if((!sigint_received) && (reconnect_sec_max)) 1132 { 1133 reconnect_sec = reconnect(reconnect_sec, reconnect_sec_max); 1134 } 1174 if((reconnect_sec_max) && (!sigint_received)) 1175 reconnect_sec = reconnect(reconnect_sec, reconnect_sec_max); 1135 1176 else inputmode = LAST; 1136 1177 } … … 1138 1179 } 1139 1180 1140 static void send_receive_loop( int sock, int fd, int outmode, struct sockaddr* pcasterRTP,1181 static void send_receive_loop(sockettype sock, int outmode, struct sockaddr* pcasterRTP, 1141 1182 socklen_t length) 1142 1183 { 1143 int nodata = 0;1144 char buffer[BUFSZ] = { 0 };1145 char sisnetbackbuffer[200];1146 char szSendBuffer[BUFSZ] = "";1147 int nBufferBytes = 0;1184 int nodata = 0; 1185 char buffer[BUFSZ] = { 0 }; 1186 char sisnetbackbuffer[200]; 1187 char szSendBuffer[BUFSZ] = ""; 1188 int nBufferBytes = 0; 1148 1189 1149 1190 /* RTSP / RTP Mode */ 1150 int isfirstpacket = 1;1151 struct timeval now;1152 struct timeval last = {0,0};1191 int isfirstpacket = 1; 1192 struct timeval now; 1193 struct timeval last = {0,0}; 1153 1194 long int sendtimediff; 1154 int rtpseq = 0;1155 int rtpssrc = 0;1156 int rtptime = 0;1195 int rtpseq = 0; 1196 int rtpssrc = 0; 1197 int rtptime = 0; 1157 1198 1158 1199 /* data transmission */ 1159 1200 fprintf(stderr,"transfering data ...\n"); 1160 int send_recv_success = 0; 1201 int send_recv_success = 0; 1202 #ifdef WINDOWSVERSION 1203 time_t nodata_begin = 0, nodata_current = 0; 1204 #endif 1161 1205 while(1) 1162 1206 { 1163 1207 if(send_recv_success < 3) send_recv_success++; 1164 if(!nodata) alarm(ALARMTIME); 1165 else nodata = 0; 1166 1208 if(!nodata) 1209 { 1210 #ifndef WINDOWSVERSION 1211 alarm(ALARMTIME); 1212 #else 1213 time(&nodata_begin); 1214 #endif 1215 } 1216 else 1217 { 1218 nodata = 0; 1219 #ifdef WINDOWSVERSION 1220 time(&nodata_current); 1221 if(difftime(nodata_current, nodata_begin) >= ALARMTIME) 1222 { 1223 sigalarm_received = 1; 1224 fprintf(stderr, "ERROR: more than %d seconds no activity\n", ALARMTIME); 1225 } 1226 #endif 1227 } 1167 1228 /* signal handling*/ 1168 if((sigint_received) || (sigpipe_received) || (sigalarm_received)) break; 1169 1229 #ifdef WINDOWSVERSION 1230 if((sigalarm_received) || (sigint_received)) break; 1231 #else 1232 if((sigalarm_received) || (sigint_received) || (sigpipe_received)) break; 1233 #endif 1170 1234 if(!nBufferBytes) 1171 1235 { … … 1179 1243 memcpy(sisnetbackbuffer, buffer, sizeof(sisnetbackbuffer)); 1180 1244 i = (sisnet >= 30 ? 5 : 3); 1181 if((send(gps fd, "MSG\r\n", i, 0)) != i)1245 if((send(gps_socket, "MSG\r\n", i, 0)) != i) 1182 1246 { 1183 1247 perror("WARNING: sending SISNeT data request failed"); … … 1186 1250 } 1187 1251 /*** receiving data ****/ 1188 nBufferBytes = read(fd, buffer, sizeof(buffer)); 1252 if(inputmode == INFILE) 1253 nBufferBytes = read(gps_file, buffer, sizeof(buffer)); 1254 else if(inputmode == SERIAL) 1255 { 1256 #ifndef WINDOWSVERSION 1257 nBufferBytes = read(gps_serial, buffer, sizeof(buffer)); 1258 #else 1259 DWORD nRead = 0; 1260 if(!ReadFile(gps_serial, buffer, sizeof(buffer), &nRead, NULL)) 1261 { 1262 fprintf(stderr,"ERROR: reading serial input failed\n"); 1263 return; 1264 } 1265 nBufferBytes = (int)nRead; 1266 #endif 1267 } 1268 else 1269 nBufferBytes = recv(gps_socket, buffer, sizeof(buffer), 0); 1189 1270 if(!nBufferBytes) 1190 1271 { 1191 printf("WARNING: no data received from input\n"); 1272 fprintf(stderr, "WARNING: no data received from input\n"); 1273 nodata = 1; 1274 #ifndef WINDOWSVERSION 1192 1275 sleep(3); 1193 nodata = 1; 1276 #else 1277 Sleep(3*1000); 1278 #endif 1194 1279 continue; 1195 1280 } … … 1340 1425 * tty : pointer to : A zero-terminated string containing the device 1341 1426 * unsigned char name of the appropriate serial port. 1342 * blocksz : integer : Block size for port I/O 1427 * blocksz : integer : Block size for port I/O (ifndef WINDOWSVERSION) 1343 1428 * baud : integer : Baud rate for port I/O 1344 1429 * 1345 1430 * Return Value: 1346 1431 * The function returns a file descriptor for the opened port if successful. 1347 * The function returns -1 in the event of an error.1432 * The function returns -1 / INVALID_HANDLE_VALUE in the event of an error. 1348 1433 * 1349 1434 * Remarks: 1350 1435 * 1351 1436 ********************************************************************/ 1352 1437 #ifndef WINDOWSVERSION 1353 1438 static int openserial(const char * tty, int blocksz, int baud) 1354 1439 { 1355 int fd;1356 1440 struct termios termios; 1357 1441 1358 fd = open(tty, O_RDWR | O_NONBLOCK | O_EXLOCK); 1359 if(fd < 0) 1442 /*** opening the serial port ***/ 1443 gps_serial = open(tty, O_RDWR | O_NONBLOCK | O_EXLOCK); 1444 if(gps_serial < 0) 1360 1445 { 1361 1446 perror("ERROR: opening serial connection"); 1362 1447 return (-1); 1363 1448 } 1364 if(tcgetattr(fd, &termios) < 0) 1449 1450 /*** configuring the serial port ***/ 1451 if(tcgetattr(gps_serial, &termios) < 0) 1365 1452 { 1366 1453 perror("ERROR: get serial attributes"); … … 1381 1468 #if (B4800 != 4800) 1382 1469 /* Not every system has speed settings equal to absolute speed value. */ 1383 1384 1470 switch (baud) 1385 1471 { … … 1437 1523 return (-1); 1438 1524 } 1439 if(tcsetattr( fd, TCSANOW, &termios) < 0)1525 if(tcsetattr(gps_serial, TCSANOW, &termios) < 0) 1440 1526 { 1441 1527 perror("ERROR: setting serial attributes"); 1442 1528 return (-1); 1443 1529 } 1444 if(fcntl( fd, F_SETFL, 0) == -1)1530 if(fcntl(gps_serial, F_SETFL, 0) == -1) 1445 1531 { 1446 1532 perror("WARNING: setting blocking inputmode failed"); 1447 1533 } 1448 return (fd); 1534 return (gps_serial); 1535 } 1536 #else 1537 static HANDLE openserial(const char * tty, int baud) 1538 { 1539 DCB dcb; 1540 COMMTIMEOUTS cmt; 1541 1542 /*** opening the serial port ***/ 1543 gps_serial = CreateFile(tty, GENERIC_READ | GENERIC_WRITE, 0, 0, 1544 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 1545 if(gps_serial == INVALID_HANDLE_VALUE) 1546 { 1547 fprintf(stderr, "ERROR: opening serial connection\n"); 1548 return (INVALID_HANDLE_VALUE); 1549 } 1550 /*** configuring the serial port ***/ 1551 FillMemory(&dcb, sizeof(dcb), 0); 1552 dcb.DCBlength = sizeof(dcb); 1553 if(!GetCommState(gps_serial, &dcb)) 1554 { 1555 fprintf(stderr, "ERROR: get serial attributes\n"); 1556 return (INVALID_HANDLE_VALUE); 1557 } 1558 switch (baud) 1559 { 1560 case 110: 1561 baud = CBR_110; 1562 break; 1563 case 300: 1564 baud = CBR_300; 1565 break; 1566 case 600: 1567 baud = CBR_600; 1568 break; 1569 case 1200: 1570 baud = CBR_1200; 1571 break; 1572 case 2400: 1573 baud = CBR_2400; 1574 break; 1575 case 4800: 1576 baud = CBR_4800; 1577 break; 1578 case 9600: 1579 baud = CBR_9600; 1580 break; 1581 case 14400: 1582 baud = CBR_14400; 1583 break; 1584 case 19200: 1585 baud = CBR_19200; 1586 break; 1587 case 38400: 1588 baud = CBR_38400; 1589 break; 1590 case 56000: 1591 baud = CBR_56000; 1592 break; 1593 case 57600: 1594 baud = CBR_57600; 1595 break; 1596 case 115200: 1597 baud = CBR_115200; 1598 break; 1599 case 128000: 1600 baud = CBR_128000; 1601 break; 1602 case 256000: 1603 baud = CBR_256000; 1604 break; 1605 default: 1606 fprintf(stderr, "WARNING: Baud settings not useful, using 19200\n"); 1607 baud = CBR_19200; 1608 break; 1609 } 1610 dcb.BaudRate = baud; 1611 dcb.ByteSize = 8; 1612 dcb.StopBits = ONESTOPBIT; 1613 dcb.Parity = NOPARITY; 1614 if(!GetCommState(gps_serial, &dcb)) 1615 { 1616 fprintf(stderr, "ERROR: get serial attributes\n"); 1617 return (INVALID_HANDLE_VALUE); 1618 } 1619 FillMemory(&cmt, sizeof(cmt), 0); 1620 cmt.ReadIntervalTimeout = 1000; 1621 cmt.ReadTotalTimeoutMultiplier = 1; 1622 cmt.ReadTotalTimeoutConstant = 0; 1623 if(!SetCommTimeouts(gps_serial, &cmt)) 1624 { 1625 fprintf(stderr, "ERROR: set serial timeouts\n"); 1626 return (INVALID_HANDLE_VALUE); 1627 } 1628 return (gps_serial); 1449 1629 } /* openserial */ 1630 #endif 1450 1631 1451 1632 /******************************************************************** … … 1463 1644 * 1464 1645 *********************************************************************/ 1465 static1466 1646 #ifdef __GNUC__ 1467 1647 __attribute__ ((noreturn)) … … 1570 1750 } 1571 1751 1752 #ifndef WINDOWSVERSION 1572 1753 #ifdef __GNUC__ 1573 1754 static void handle_alarm(int sig __attribute__((__unused__))) … … 1585 1766 static void handle_sigpipe(int sig) 1586 1767 #endif /* __GNUC__ */ 1587 {sigpipe_received = 1;} 1768 { 1769 sigpipe_received = 1; 1770 } 1771 #endif /* WINDOWSVERSION */ 1588 1772 1589 1773 static void setup_signal_handler(int sig, void (*handler)(int)) … … 1602 1786 return; 1603 1787 } /* setupsignal_handler */ 1788 1604 1789 1605 1790 /******************************************************************** … … 1660 1845 * send message to caster * 1661 1846 *********************************************************************/ 1662 static int send_to_caster(char *input, intsocket, int input_size)1847 static int send_to_caster(char *input, sockettype socket, int input_size) 1663 1848 { 1664 1849 int send_error = 1; … … 1688 1873 rec_sec *= 2; 1689 1874 if (rec_sec > rec_sec_max) rec_sec = rec_sec_max; 1875 #ifndef WINDOWSVERSION 1690 1876 sleep(rec_sec); 1877 sigpipe_received = 0; 1878 #else 1879 Sleep(rec_sec*1000); 1880 #endif 1691 1881 sigalarm_received = 0; 1692 sigpipe_received = 0;1693 1882 return rec_sec; 1694 1883 } /* reconnect */ … … 1704 1893 char send_buf[BUFSZ]; 1705 1894 1706 if((gpsfd != -1) && (!fallback)) 1707 { 1708 if(close(gpsfd) == -1) 1709 { 1710 perror("ERROR: close input device "); 1711 exit(0); 1712 } 1713 else 1714 { 1715 gpsfd = -1; 1895 if(!fallback) 1896 { 1897 if((gps_socket != INVALID_SOCKET) && 1898 ((inputmode == TCPSOCKET) || (inputmode == UDPSOCKET) || 1899 (inputmode == CASTER) || (inputmode == SISNET))) 1900 { 1901 if(closesocket(gps_socket) == -1) 1902 { 1903 perror("ERROR: close input device "); 1904 exit(0); 1905 } 1906 else 1907 { 1908 gps_socket = -1; 1716 1909 #ifndef NDEBUG 1717 fprintf(stderr, "close input device: successful\n"); 1718 #endif 1719 } 1720 } 1721 1722 if(socket_udp != -1) 1910 fprintf(stderr, "close input device: successful\n"); 1911 #endif 1912 } 1913 } 1914 else if((gps_serial != INVALID_HANDLE_VALUE) && (inputmode == SERIAL)) 1915 { 1916 #ifndef WINDOWSVERSION 1917 if(close(gps_serial) == INVALID_HANDLE_VALUE) 1918 { 1919 perror("ERROR: close input device "); 1920 exit(0); 1921 } 1922 #else 1923 if(!CloseHandle(gps_serial)) 1924 { 1925 fprintf(stderr, "ERROR: close input device "); 1926 exit(0); 1927 } 1928 #endif 1929 else 1930 { 1931 gps_serial = INVALID_HANDLE_VALUE; 1932 #ifndef NDEBUG 1933 fprintf(stderr, "close input device: successful\n"); 1934 #endif 1935 } 1936 } 1937 else if((gps_file != -1) && (inputmode == INFILE)) 1938 { 1939 if(close(gps_file) == -1) 1940 { 1941 perror("ERROR: close input device "); 1942 exit(0); 1943 } 1944 else 1945 { 1946 gps_file = -1; 1947 #ifndef NDEBUG 1948 fprintf(stderr, "close input device: successful\n"); 1949 #endif 1950 } 1951 } 1952 } 1953 1954 if(socket_udp != INVALID_SOCKET) 1723 1955 { 1724 1956 if(cseq == 2) … … 1742 1974 #endif 1743 1975 } 1744 if(close (socket_udp)==-1)1976 if(closesocket(socket_udp)==-1) 1745 1977 { 1746 1978 perror("ERROR: close udp socket"); … … 1756 1988 } 1757 1989 1758 if(socket_tcp != -1)1759 { 1760 if(close (socket_tcp) == -1)1990 if(socket_tcp != INVALID_SOCKET) 1991 { 1992 if(closesocket(socket_tcp) == -1) 1761 1993 { 1762 1994 perror("ERROR: close tcp socket");
Note:
See TracChangeset
for help on using the changeset viewer.