Changeset 18 in ntrip for trunk/ntripserver/NtripLinuxServer.c
- Timestamp:
- Apr 19, 2005, 1:28:17 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripserver/NtripLinuxServer.c
r16 r18 1 1 /* 2 * main.c2 * NtripServerLinux.c 3 3 * 4 4 * Copyright (c) 2003...2005 … … 41 41 */ 42 42 43 /* $Id: NtripLinuxServer.c,v 1.7 2005/02/17 09:22:23 stoecker Exp $ 44 * Changes - Version 0.7 45 * Thu Sep 22 08:10:45 2003 actina AG <http://www.actina.de> 46 * 47 * Steffen Tschirpke <St.Tschirpke@actina.de> 48 * * main.c 43 /* $Id: NtripLinuxServer.c,v 1.8 2005/03/21 13:02:47 stoecker Exp $ 44 * Changes - Version 0.7 45 * Sep 22 2003 Steffen Tschirpke <St.Tschirpke@actina.de> 49 46 * - socket support 50 47 * - command line option handling 51 48 * - error handling 52 49 * - help screen 50 * 51 * Changes - Version 0.9 52 * Feb 15 2005 Dirk Stoecker <soft@dstoecker.de> 53 * - some minor updates, fixed serial baudrate settings 54 * 55 * Changes - Version 0.10 56 * Apr 05 2005 Dirk Stoecker <soft@dstoecker.de> 57 * - some cleanup and miscellaneous fixes 58 * - replaced non-working simulate with file input (stdin) 59 * - TCP sending now somewhat more stable 60 * - cleanup of error handling 53 61 */ 54 62 55 /* Changes - Version 0.9 56 * Feb 15 2005 Dirk Stoecker <soft@dstoecker.de> 57 */ 58 63 #include <ctype.h> 64 #include <errno.h> 65 #include <fcntl.h> 66 #include <getopt.h> 67 #include <netdb.h> 59 68 #include <stdio.h> 69 #include <stdlib.h> 60 70 #include <string.h> 61 71 #include <unistd.h> 62 #include <stdlib.h> 72 #include <arpa/inet.h> 73 #include <netinet/in.h> 74 #include <sys/socket.h> 75 #include <sys/termios.h> 63 76 #include <sys/types.h> 64 #include <sys/socket.h> 65 #include <netinet/in.h> 66 #include <arpa/inet.h> 67 #include <netdb.h> 68 #include <getopt.h> 69 #include <sys/termios.h> 70 #include <fcntl.h> 71 #include "NtripServerLinux.h" 72 73 #define VERSION "NTRIP NtripServerLinux/0.9" 74 75 #define SIMULATE 0 76 #define SERIAL 1 77 #define TCPSOCKET 2 77 78 #ifndef MSG_DONTWAIT 79 #define MSG_DONTWAIT 0 /* prevent compiler errors */ 80 #endif 81 #ifndef O_EXLOCK 82 #define O_EXLOCK 0 /* prevent compiler errors */ 83 #endif 84 85 enum MODE { SERIAL = 1, TCPSOCKET = 2, INFILE = 3 }; 86 87 #define VERSION "NTRIP NtripServerLinux/0.10" 88 #define BUFSZ 1024 78 89 79 90 /* default socket source */ 80 #define SERV_HOST_ADDR "127.0.0.1"81 #define SERV_TCP_PORT 102591 #define SERV_HOST_ADDR "127.0.0.1" 92 #define SERV_TCP_PORT 1025 82 93 83 94 /* default destination */ 84 #define NTRIP_CASTER "www.euref-ip.net" 85 #define NTRIP_PORT 80 86 87 int verbose = 0; 88 int simulate = 0; 89 int tickinterval = 1; 90 int ttybaud = 19200; 91 char * ttyport = "/dev/gps"; 92 int mode = 0; 95 #define NTRIP_CASTER "www.euref-ip.net" 96 #define NTRIP_PORT 80 97 98 int ttybaud = 19200; 99 char *ttyport = "/dev/gps"; 100 char *filepath = "/dev/stdin"; 101 enum MODE mode = INFILE; 93 102 94 103 /* Forward references */ 95 int openserial 96 intsend_receive_loop(int socket, int fd);97 void usage 104 int openserial(u_char * tty, int blocksz, int ttybaud); 105 void send_receive_loop(int socket, int fd); 106 void usage(int); 98 107 99 108 /* … … 115 124 */ 116 125 117 int main (int argc, char **argv)126 int main(int argc, char **argv) 118 127 { 119 u_char * ttyin = ttyport; 120 char * logfilepath = NULL; 121 FILE * fp = NULL; 122 int c, gpsfd = -1; 123 int size = 2048; //for setting send buffer size 124 128 u_char *ttyin = ttyport; 129 int c, gpsfd = -1; 130 int size = 2048; /* for setting send buffer size */ 131 125 132 unsigned int out_port = 0; 126 133 unsigned int in_port = 0; 127 char *mountpoint = NULL; 128 char *password = NULL; 129 int sock_id; 130 char szSendBuffer[BUFSZ]; 131 int nBufferBytes; 132 int sockfd; 134 char *mountpoint = NULL; 135 char *password = ""; 136 int sock_id; 137 char szSendBuffer[BUFSZ]; 138 int nBufferBytes; 133 139 134 140 struct hostent *inhost; 135 141 struct hostent *outhost; 136 142 137 143 struct sockaddr_in in_addr; 138 144 struct sockaddr_in out_addr; … … 140 146 if(!(outhost = gethostbyname(NTRIP_CASTER))) 141 147 { 142 fprintf(stderr, " host %s unknown\n\n", NTRIP_CASTER);148 fprintf(stderr, "WARNING: host %s unknown\n", NTRIP_CASTER); 143 149 } 144 150 else … … 148 154 } 149 155 150 //get and check program arguments 151 if (argc <=1) 152 { 156 /* get and check program arguments */ 157 if(argc <= 1) 158 { 159 usage(2); 160 exit(1); 161 } 162 while((c = getopt(argc, argv, "M:i:h:b:p:s:a:m:c:H:P:")) != EOF) 163 { 164 switch (c) 165 { 166 case 'M': 167 mode = atoi(optarg); 168 if((mode == 0) || (mode > 3)) 169 { 170 fprintf(stderr, "ERROR: can't convert %s to a valid mode\n", optarg); 171 usage(-1); 172 } 173 break; 174 case 'i': /* gps serial ttyin */ 175 ttyin = optarg; 176 break; 177 case 'b': /* serial ttyin speed */ 178 ttybaud = atoi(optarg); 179 if(ttybaud <= 1) 180 { 181 fprintf(stderr, "ERROR: can't convert %s to valid serial speed\n", optarg); 182 usage(1); 183 } 184 break; 185 case 'a': /* http server IP address A.B.C.D */ 186 outhost = gethostbyname(optarg); 187 if(outhost == NULL) 188 { 189 fprintf(stderr, "ERROR: host %s unknown\n", optarg); 190 usage(-2); 191 } 192 memset((char *) &out_addr, 0x00, sizeof(out_addr)); 193 memcpy(&out_addr.sin_addr, outhost->h_addr, outhost->h_length); 194 break; 195 case 'p': /* http server port */ 196 out_port = atoi(optarg); 197 if(out_port <= 1) 198 { 199 fprintf(stderr, "ERROR: can't convert %s to a valid HTTP server port\n", 200 optarg); 201 usage(1); 202 } 203 break; 204 case 'm': /* http server mountpoint */ 205 mountpoint = optarg; 206 break; 207 case 'f': /* datastream from file */ 208 filepath = optarg; 209 break; 210 case 'c': /* password */ 211 password = optarg; 212 break; 213 case 'H': /* host */ 214 inhost = gethostbyname(optarg); 215 if(inhost == NULL) 216 { 217 fprintf(stderr, "ERROR: host %s unknown\n", optarg); 218 usage(-2); 219 } 220 memset((char *) &in_addr, 0x00, sizeof(in_addr)); 221 memcpy(&in_addr.sin_addr, inhost->h_addr, inhost->h_length); 222 break; 223 case 'P': /* port */ 224 in_port = atoi(optarg); 225 if(in_port <= 1) 226 { 227 fprintf(stderr, "ERROR: can't convert %s to a valid receiver port\n", 228 optarg); 229 usage(1); 230 } 231 break; 232 case 'h': /* help */ 233 case '?': 234 usage(0); 235 break; 236 default: 153 237 usage(2); 154 exit(1); 155 } 156 while ((c = getopt (argc, argv, "M:i:h:b:p:s:a:m:c:H:P:")) != EOF) 157 { 158 switch (c) 159 { 160 case 'M': 161 mode = atoi(optarg); 162 if ((mode == 0) || (mode > 3)) 163 { 164 fprintf (stderr, "can't convert %s to a valid mode\n\n", optarg); 165 usage(-1); 166 } 167 break; 168 case 'i': /* gps serial ttyin */ 169 ttyin = optarg; 170 break; 171 case 'b': /* serial ttyin speed */ 172 ttybaud = atoi (optarg); 173 if (ttybaud <= 1) 174 { 175 fprintf (stderr, "can't convert %s to valid ttyin speed\n\n", optarg); 176 usage(1); 177 } 178 break; 179 case 'a': /* http server IP address A.B.C.D*/ 180 outhost = gethostbyname(optarg); 181 if (outhost == NULL) 182 { 183 fprintf (stderr, "host %s unknown\n\n", optarg); 184 usage(-2); 185 } 186 memset((char *) &out_addr, 0x00, sizeof(out_addr)); 187 memcpy(&out_addr.sin_addr, outhost->h_addr, outhost->h_length); 188 break; 189 case 'p': /* http server port*/ 190 out_port = atoi(optarg); 191 if (out_port <= 1) 192 { 193 fprintf (stderr, "can't convert %s to a valid http server port\n\n", optarg); 194 usage(1); 195 } 196 break; 197 case 'm': /* http server mountpoint*/ 198 mountpoint = optarg; 199 break; 200 case 's': /* simulate datastream from file */ 201 logfilepath = optarg; 202 break; 203 case 'c': /* password */ 204 password=optarg; 205 break; 206 case 'H': /* host */ 207 inhost = gethostbyname(optarg); 208 if (inhost == NULL) 209 { 210 /* TODO Errorhandling/Debugging - Output */ 211 fprintf (stderr, "host %s unknown\n\n", optarg); 212 usage(-2); 213 } 214 memset((char *) &in_addr, 0x00, sizeof(in_addr)); 215 memcpy(&in_addr.sin_addr, inhost->h_addr, inhost->h_length); 216 break; 217 case 'P': /* port */ 218 in_port = atoi(optarg); 219 if (in_port <= 1) 220 { 221 /* TODO Errorhandling/Debugging - Output */ 222 fprintf (stderr, "can't convert %s to a valid receiver port\n\n", optarg); 223 usage(1); 224 } 225 break; 226 case 'h': /* help */ 227 case '?': 228 usage(0); 229 break; 230 default: 231 usage(2); 232 break; 233 } 234 235 if (in_port <= 0 ) 236 { 237 in_port = SERV_TCP_PORT; 238 } 239 if (out_port <= 0 ) 240 { 241 out_port = NTRIP_PORT; 242 } 243 } 244 238 break; 239 } 240 241 if(in_port <= 0) 242 { 243 in_port = SERV_TCP_PORT; 244 } 245 if(out_port <= 0) 246 { 247 out_port = NTRIP_PORT; 248 } 249 } 250 245 251 argc -= optind; 246 252 argv += optind; 247 248 if (argc > 0) 249 { 250 /* TODO Errorhandling/Debugging - Output */ 251 fprintf (stderr, "Extra args on command line.\n"); 252 for (; argc > 0; argc--) 253 { 254 fprintf (stderr, " %s", *argv++); 255 } 256 fprintf (stderr, "\n"); 257 usage (1); /* never returns */ 258 } 259 260 if ((mode ==SIMULATE) && (tickinterval <= 0)) 261 { 262 /* TODO Errorhandling/Debugging - Output */ 263 fprintf (stderr, "-t parameter must be positive in simulator mode\n"); 264 exit (1); 265 } 266 267 if (verbose >= 1) 268 fprintf (stderr, "%s\n", VERSION); 269 if (mountpoint == NULL) 270 { 271 /* TODO Errorhandling/Debugging - Output */ 272 fprintf(stderr,"missing mountpoint arguement\n"); 273 exit(1); 274 } 275 //print program arguments on screen 276 /* TODO Errorhandling/Debugging - Output */ 277 // printf("\ncaster IP :\t%s\nport :\t%d\nmountpoint :\t%s\npassword :\t%s\n\n",address,port,mountpoint,(password==NULL)?"none":"yes"); 278 if (password == NULL) 279 { 280 password="\0"; 281 } 282 253 254 if(argc > 0) 255 { 256 fprintf(stderr, "ERROR: Extra args on command line: "); 257 for(; argc > 0; argc--) 258 { 259 fprintf(stderr, " %s", *argv++); 260 } 261 fprintf(stderr, "\n"); 262 usage(1); /* never returns */ 263 } 264 265 if(mountpoint == NULL) 266 { 267 fprintf(stderr, "ERROR: Missing mountpoint argument\n"); 268 exit(1); 269 } 270 if(!password[0]) 271 { 272 fprintf(stderr, "WARNING: Missing password argument - are you really sure?\n"); 273 } 274 283 275 switch (mode) 284 { 285 case SIMULATE: 286 { 287 fp = fopen (logfilepath, "r"); 288 if (!fp) 289 { 290 /* TODO Errorhandling/Debugging - Output */ 291 perror ("fopen logfile"); 292 exit (1); 293 } 294 } 295 break; 296 case SERIAL: //open serial port 297 { 298 gpsfd = openserial (ttyin, 1, ttybaud); 299 fp = fdopen (gpsfd, "r"); 300 if (!fp) 301 { 302 /* TODO Errorhandling/Debugging - Output */ 303 perror ("fdopen gps"); 304 exit (1); 305 } 306 } 307 break; 308 case TCPSOCKET: 309 { 310 in_addr.sin_family = AF_INET; 311 in_addr.sin_port = htons(in_port); 312 313 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 314 { 315 /* TODO Errorhandling/Debugging - Output */ 316 fprintf (stderr, "can't create socket\n"); 317 exit(1); 318 } 319 320 /* TODO Errorhandling/Debugging - Output */ 321 printf("connecting input ...\n"); 322 fprintf (stderr, "socket input:\n"); 323 fprintf (stderr, "\tHost: %s\n", inet_ntoa(in_addr.sin_addr)); 324 fprintf (stderr, "\tPort: %d\n", in_port); 325 326 if (connect(sockfd, (struct sockaddr *) &in_addr, sizeof(in_addr)) < 0) 327 { 328 /* TODO Errorhandling/Debugging - Output */ 329 fprintf (stderr, "can't connect input to %s at port %d\n", inet_ntoa(in_addr.sin_addr), in_port); 330 // exit(1); 331 } 332 gpsfd = sockfd; 333 } 334 break; 335 default: 336 usage(-1); 337 break; 338 } 339 276 { 277 case INFILE: 278 { 279 gpsfd = open(filepath, O_RDONLY); 280 if(!gpsfd) 281 { 282 perror("ERROR: opening input file"); 283 exit(1); 284 } 285 /* set blocking mode in case it was not set (seems to be sometimes for fifo's) */ 286 fcntl(gpsfd, F_SETFL, 0); 287 printf("file input: file = %s\n", filepath); 288 } 289 break; 290 case SERIAL: /* open serial port */ 291 { 292 gpsfd = openserial(ttyin, 1, ttybaud); 293 if(gpsfd < 0) 294 { 295 exit(1); 296 } 297 printf("serial input: device = %s, speed = %d\n", ttyin, ttybaud); 298 } 299 break; 300 case TCPSOCKET: 301 { 302 in_addr.sin_family = AF_INET; 303 in_addr.sin_port = htons(in_port); 304 305 if((gpsfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 306 { 307 fprintf(stderr, "ERROR: can't create socket\n"); 308 exit(1); 309 } 310 311 printf("socket input: host = %s, port = %d\n", 312 inet_ntoa(in_addr.sin_addr), in_port); 313 314 if(connect(gpsfd, (struct sockaddr *) &in_addr, sizeof(in_addr)) < 0) 315 { 316 fprintf(stderr, "ERROR: can't connect input to %s at port %d\n", 317 inet_ntoa(in_addr.sin_addr), in_port); 318 exit(1); 319 } 320 } 321 break; 322 default: 323 usage(-1); 324 break; 325 } 326 340 327 out_addr.sin_family = AF_INET; 341 out_addr.sin_port = htons((u_short) (out_port));342 343 / / ----- main part -----328 out_addr.sin_port = htons((u_short) (out_port)); 329 330 /* ----- main part ----- */ 344 331 while(1) 345 { 346 //create socket 347 if ((sock_id = socket(AF_INET, SOCK_STREAM, 0)) < 0) 348 { 349 /* TODO Errorhandling/Debugging - Output */ 350 printf("ERROR : could not create socket\n"); 351 // sleep(5); 352 exit(2); 353 } 354 //connect to caster 355 printf("connecting output ...\n"); 356 fprintf (stderr, "caster output:\n"); 357 fprintf (stderr, "\tHost: %s\n", inet_ntoa(out_addr.sin_addr)); 358 fprintf (stderr, "\tPort: %d\n", out_port); 359 if (connect(sock_id, (struct sockaddr *) &out_addr, sizeof(out_addr)) < 0) 360 { 361 /* TODO Errorhandling/Debugging - Output */ 362 fprintf (stderr, "can't connect output to %s at port %d\n", inet_ntoa(out_addr.sin_addr), out_port); 363 close(sock_id); 364 // sleep(5); 365 exit(3); 366 } 367 368 /* TODO Errorhandling/Debugging - Output */ 369 printf("connection succesfull\n"); 370 //set socket buffer size 371 setsockopt(sock_id,SOL_SOCKET,SO_SNDBUF,(const char *) &size,sizeof(const char *)); 372 //send message to caster 373 szSendBuffer[0] = '\0'; 374 sprintf(szSendBuffer,"SOURCE %s /%s\r\n",password,mountpoint); 375 strcat(szSendBuffer,"Source-Agent: "); 376 strcat(szSendBuffer,VERSION); 377 strcat(szSendBuffer, "\r\n"); 378 strcat(szSendBuffer, "\r\n"); 379 strcat(szSendBuffer, "\0"); 380 nBufferBytes=strlen(szSendBuffer); 381 if ((send(sock_id, szSendBuffer, nBufferBytes, 0)) != nBufferBytes) 382 { 383 /* TODO Errorhandling/Debugging - Output */ 384 fprintf(stderr, "ERROR : could not send to caster\n"); 385 close(sock_id); 386 sleep(5); 387 exit(0); 388 } 389 //check caster's response 390 nBufferBytes=recv(sock_id,szSendBuffer,sizeof(szSendBuffer),0); 391 szSendBuffer[nBufferBytes]='\0'; 392 if(strcmp(szSendBuffer,"OK\r\n")) 393 { 394 /* TODO Errorhandling/Debugging - Output */ 395 fprintf(stderr,"caster's reply is not OK\n"); 396 close(sock_id); 397 sleep(5); 398 exit(0); 399 } 400 send_receive_loop(sock_id, gpsfd); 401 } 332 { 333 /* create socket */ 334 if((sock_id = socket(AF_INET, SOCK_STREAM, 0)) < 0) 335 { 336 fprintf(stderr, "ERROR : could not create socket\n"); 337 exit(2); 338 } 339 /* connect to caster */ 340 fprintf(stderr, "caster output: host = %s, port = %d, mountpoint = %s\n", 341 inet_ntoa(out_addr.sin_addr), out_port, mountpoint); 342 if(connect(sock_id, (struct sockaddr *) &out_addr, sizeof(out_addr)) < 0) 343 { 344 fprintf(stderr, "ERROR: can't connect output to %s at port %d\n", 345 inet_ntoa(out_addr.sin_addr), out_port); 346 close(sock_id); 347 exit(3); 348 } 349 350 /* set socket buffer size */ 351 setsockopt(sock_id, SOL_SOCKET, SO_SNDBUF, (const char *) &size, 352 sizeof(const char *)); 353 /* send message to caster */ 354 szSendBuffer[0] = '\0'; 355 sprintf(szSendBuffer, "SOURCE %s /%s\r\n", password, mountpoint); 356 strcat(szSendBuffer, "Source-Agent: "); 357 strcat(szSendBuffer, VERSION); 358 strcat(szSendBuffer, "\r\n"); 359 strcat(szSendBuffer, "\r\n"); 360 strcat(szSendBuffer, "\0"); 361 nBufferBytes = strlen(szSendBuffer); 362 if((send(sock_id, szSendBuffer, nBufferBytes, 0)) != nBufferBytes) 363 { 364 fprintf(stderr, "ERROR: could not send to caster\n"); 365 close(sock_id); 366 sleep(5); 367 exit(0); 368 } 369 /* check caster's response */ 370 nBufferBytes = recv(sock_id, szSendBuffer, sizeof(szSendBuffer), 0); 371 szSendBuffer[nBufferBytes] = '\0'; 372 if(strcmp(szSendBuffer, "OK\r\n")) 373 { 374 char *a; 375 fprintf(stderr, "ERROR: caster's reply is not OK : "); 376 for(a = szSendBuffer; *a && *a != '\n' && *a != '\r'; ++a) 377 { 378 fprintf(stderr, "%.1s", isprint(*a) ? a : "."); 379 } 380 fprintf(stderr, "\n"); 381 close(sock_id); 382 sleep(5); 383 exit(0); 384 } 385 printf("connection succesfull\n"); 386 send_receive_loop(sock_id, gpsfd); 387 } 402 388 exit(0); 403 389 } 404 390 405 intsend_receive_loop(int socket, int fd)391 void send_receive_loop(int socket, int fd) 406 392 { 407 char buffer[BUFSZ] ={0};408 int nBufferBytes =0;409 / /data transmission393 char buffer[BUFSZ] = { 0 }; 394 int nBufferBytes = 0, i; 395 /* data transmission */ 410 396 printf("transfering data ...\n"); 411 397 while(1) 412 { 413 // recieving data 398 { 399 if(!nBufferBytes) 400 { 401 /* receiving data */ 414 402 nBufferBytes = read(fd, buffer, BUFSZ); 415 if (nBufferBytes<=0) 416 { 417 /* TODO Errorhandling/Debugging - Output */ 418 printf("ERROR : no data recieved from serial port or socket\n"); 419 } 420 // send data 421 if((send(socket, buffer, nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) 422 { //MSG_DONTWAIT : send works in non-blocking mode 423 /* TODO Errorhandling/Debugging - Output */ 424 fprintf(stderr,"ERROR : could not send data\n"); 425 close(socket); 426 sleep(5); 427 exit(4); 428 } 429 } 403 if(!nBufferBytes) 404 { 405 printf("WARNING: no data received from input\n"); 406 continue; 407 } 408 else if(nBufferBytes < 0) 409 { 410 perror("ERROR: reading input failed"); 411 exit(1); 412 } 413 } 414 /* send data */ 415 if((i = send(socket, buffer, nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) 416 { 417 if(i < 0 && errno != EAGAIN) 418 { 419 perror("WARNING: could not send data - retry connection"); 420 close(socket); 421 sleep(5); 422 return; 423 } 424 else if(i) 425 { 426 memmove(buffer, buffer+i, nBufferBytes-i); 427 nBufferBytes -= i; 428 } 429 } 430 else 431 { 432 nBufferBytes = 0; 433 } 434 } 430 435 } 431 436 … … 450 455 */ 451 456 452 int openserial 457 int openserial(u_char * tty, int blocksz, int ttybaud) 453 458 { 454 int fd; 455 struct termios termios; 456 457 fd = open(tty, O_RDWR | O_NONBLOCK 458 #ifdef O_EXLOCK /* for Linux */ 459 | O_EXLOCK 460 #endif 461 ); 462 if (fd < 0) { 463 perror("open"); 459 int fd; 460 struct termios termios; 461 462 fd = open(tty, O_RDWR | O_NONBLOCK | O_EXLOCK); 463 if(fd < 0) 464 { 465 perror("ERROR: opening serial connection"); 464 466 return (-1); 465 467 } 466 if (tcgetattr(fd, &termios) < 0) {467 468 perror(" tcgetattr");468 if(tcgetattr(fd, &termios) < 0) 469 { 470 perror("ERROR: get serial attributes"); 469 471 return (-1); 470 472 } 471 473 termios.c_iflag = 0; 472 termios.c_oflag = 0; /* (ONLRET) */474 termios.c_oflag = 0; /* (ONLRET) */ 473 475 termios.c_cflag = CS8 | CLOCAL | CREAD; 474 476 termios.c_lflag = 0; 475 477 { 476 int 477 for 478 int cnt; 479 for(cnt = 0; cnt < NCCS; cnt++) 478 480 termios.c_cc[cnt] = -1; 479 481 } 480 482 termios.c_cc[VMIN] = blocksz; 481 483 termios.c_cc[VTIME] = 2; 482 484 483 485 #if (B4800 != 4800) 484 486 /* 485 487 * Not every system has speed settings equal to absolute speed value. 486 488 */ 487 489 488 490 switch (ttybaud) 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 491 { 492 case 300: 493 ttybaud = B300; 494 break; 495 case 1200: 496 ttybaud = B1200; 497 break; 498 case 2400: 499 ttybaud = B2400; 500 break; 501 case 4800: 502 ttybaud = B4800; 503 break; 504 case 9600: 505 ttybaud = B9600; 506 break; 507 case 19200: 508 ttybaud = B19200; 509 break; 510 case 38400: 511 ttybaud = B38400; 512 break; 511 513 #ifdef B57600 512 513 514 514 case 57600: 515 ttybaud = B57600; 516 break; 515 517 #endif 516 518 #ifdef B115200 517 518 519 519 case 115200: 520 ttybaud = B115200; 521 break; 520 522 #endif 521 523 #ifdef B230400 522 523 524 524 case 230400: 525 ttybaud = B230400; 526 break; 525 527 #endif 526 527 fprintf(stderr, "Baud settings not useful, using 19200\n");528 529 530 528 default: 529 fprintf(stderr, "WARNING: Baud settings not useful, using 19200\n"); 530 ttybaud = B19200; 531 break; 532 } 531 533 #endif 532 533 if (cfsetispeed(&termios, ttybaud) != 0) 534 { 535 perror("cfsetispeed"); 536 return (-1); 537 } 538 if (cfsetospeed(&termios, ttybaud) != 0) 539 { 540 perror("cfsetospeed"); 541 return (-1); 542 } 543 if (tcsetattr(fd, TCSANOW, &termios) < 0) 544 { 545 perror("tcsetattr"); 546 return (-1); 547 } 548 #if 1 /* WANT_BLOCKING_READ */ 549 if (fcntl(fd, F_SETFL, 0) == -1) 550 { 551 perror("fcntl: set nonblock"); 552 } 553 #endif 534 535 if(cfsetispeed(&termios, ttybaud) != 0) 536 { 537 perror("ERROR: setting serial speed with cfsetispeed"); 538 return (-1); 539 } 540 if(cfsetospeed(&termios, ttybaud) != 0) 541 { 542 perror("ERROR: setting serial speed with cfsetospeed"); 543 return (-1); 544 } 545 if(tcsetattr(fd, TCSANOW, &termios) < 0) 546 { 547 perror("ERROR: setting serial attributes"); 548 return (-1); 549 } 550 if(fcntl(fd, F_SETFL, 0) == -1) 551 { 552 perror("WARNING: setting blocking mode failed"); 553 } 554 554 return (fd); 555 555 } … … 570 570 */ 571 571 572 void usage 572 void usage(int rc) 573 573 { 574 fprintf (stderr, "%s: application\n",VERSION);575 fprintf (stderr, "Usage: %s [OPTIONS]\n",VERSION);576 fprintf (stderr, " Options are:\n");577 fprintf (stderr, " -a caster name or address (default: %s)\n",NTRIP_CASTER);578 fprintf 579 fprintf 580 fprintf 581 fprintf 582 fprintf 583 fprintf (stderr, " (1=serial, 2=tcpsocket, 3=simulate)\n");584 fprintf (stderr, " Mode = simulate:\n");585 fprintf 586 fprintf (stderr, " default/current setting is %s\n", (simulate ? "enabled" : "disabled"));587 fprintf 588 fprintf 589 fprintf 590 fprintf 591 fprintf 592 fprintf 593 fprintf 594 fprintf 595 fprintf 596 fprintf 597 exit 574 fprintf(stderr, "Usage: %s [OPTIONS]\n", VERSION); 575 fprintf(stderr, " Options are:\n"); 576 fprintf(stderr, " -a caster name or address (default: %s)\n", 577 NTRIP_CASTER); 578 fprintf(stderr, " -p caster port (default: %d)\n", NTRIP_PORT); 579 fprintf(stderr, " -m caster mountpoint\n"); 580 fprintf(stderr, " -c password for caster login\n"); 581 fprintf(stderr, " -h|? print this help screen\n"); 582 fprintf(stderr, " -M <mode> sets the mode\n"); 583 fprintf(stderr, " (1=serial, 2=tcpsocket, 3=file)\n"); 584 fprintf(stderr, " Mode = file:\n"); 585 fprintf(stderr, " -s file, simulate data stream by reading log file\n"); 586 fprintf(stderr, " default/current setting is %s\n", filepath); 587 fprintf(stderr, " Mode = serial:\n"); 588 fprintf(stderr, " -b baud_rate, sets serial input baud rate\n"); 589 fprintf(stderr, " default/current value is %d\n", ttybaud); 590 fprintf(stderr, " -i input_device, sets name of serial input device\n"); 591 fprintf(stderr, " default/current value is %s\n", ttyport); 592 fprintf(stderr, " (normally a symbolic link to /dev/tty\?\?)\n"); 593 fprintf(stderr, " Mode = tcpsocket:\n"); 594 fprintf(stderr, " -P receiver port (default: 1025)\n"); 595 fprintf(stderr, " -H hostname of TCP server (default: 127.0.0.1)\n"); 596 fprintf(stderr, " \n"); 597 exit(rc); 598 598 }
Note:
See TracChangeset
for help on using the changeset viewer.