Changeset 834 in ntrip
- Timestamp:
- Apr 15, 2008, 3:27:49 PM (17 years ago)
- Location:
- trunk/ntripclient
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripclient/makefile
r611 r834 1 # $Id: makefile,v 1. 5 2007/12/12 09:45:23 stoeckerExp $1 # $Id: makefile,v 1.6 2007/12/14 14:52:16 stuerze Exp $ 2 2 # probably works not with all compilers. Thought this should be easy 3 3 # fixable. There is nothing special at this source. … … 11 11 endif 12 12 13 ntripclient: ntripclient.c 14 $(CC) $(OPTS) $?-o $@ $(LIBS)13 ntripclient: ntripclient.c serial.c 14 $(CC) $(OPTS) ntripclient.c -o $@ $(LIBS) 15 15 16 16 clean: -
trunk/ntripclient/ntripclient.c
r772 r834 1 1 /* 2 Easy exampleNTRIP client for POSIX.3 $Id: ntripclient.c,v 1.4 1 2008/04/04 13:02:06 stuerzeExp $4 Copyright (C) 2003-200 5 by Dirk Stoecker <soft@dstoecker.de>5 2 NTRIP client for POSIX. 3 $Id: ntripclient.c,v 1.42 2008/04/07 11:49:13 stoecker Exp $ 4 Copyright (C) 2003-2008 by Dirk Stöcker <soft@dstoecker.de> 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by … … 27 27 #include <string.h> 28 28 #include <time.h> 29 30 #include "serial.c" 29 31 30 32 #ifdef WINDOWSVERSION … … 57 59 58 60 /* CVS revision and version */ 59 static char revisionstr[] = "$Revision: 1.4 1$";60 static char datestr[] = "$Date: 2008/04/0 4 13:02:06$";61 static char revisionstr[] = "$Revision: 1.42 $"; 62 static char datestr[] = "$Date: 2008/04/07 11:49:13 $"; 61 63 62 64 enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, END }; … … 77 79 int udpport; 78 80 int initudp; 81 enum SerialBaud baud; 82 enum SerialDatabits databits; 83 enum SerialStopbits stopbits; 84 enum SerialParity parity; 85 enum SerialProtocol protocol; 86 const char *serdevice; 79 87 }; 80 88 … … 98 106 { "nmea", required_argument, 0, 'n'}, 99 107 { "mode", required_argument, 0, 'M'}, 108 { "serdevice", required_argument, 0, 'D'}, 109 { "baud", required_argument, 0, 'B'}, 110 { "stopbits", required_argument, 0, 'T'}, 111 { "protocol", required_argument, 0, 'C'}, 112 { "parity", required_argument, 0, 'Y'}, 113 { "databits", required_argument, 0, 'A'}, 100 114 { "help", no_argument, 0, 'h'}, 101 115 {0,0,0,0}}; 102 116 #endif 103 #define ARGOPT "-d:m:bhp:r:s:u:n:S:R:M:IP: "117 #define ARGOPT "-d:m:bhp:r:s:u:n:S:R:M:IP:D:B:T:C:Y:A:" 104 118 105 119 int stop = 0; … … 183 197 *Buffer++ = h[*url & 0x0f]; 184 198 url++; 185 } 199 } 186 200 } 187 201 } … … 300 314 args->initudp = 0; 301 315 args->udpport = 0; 316 args->protocol = SPAPROTOCOL_NONE; 317 args->parity = SPAPARITY_NONE; 318 args->stopbits = SPASTOPBITS_1; 319 args->databits = SPADATABITS_8; 320 args->baud = SPABAUD_9600; 321 args->serdevice = 0; 302 322 help = 0; 303 323 … … 320 340 args->data = optarg; 321 341 break; 342 case 'B': 343 { 344 int i = strtol(optarg, 0, 10); 345 346 switch(i) 347 { 348 case 50: args->baud = SPABAUD_50; break; 349 case 110: args->baud = SPABAUD_110; break; 350 case 300: args->baud = SPABAUD_300; break; 351 case 600: args->baud = SPABAUD_600; break; 352 case 1200: args->baud = SPABAUD_1200; break; 353 case 2400: args->baud = SPABAUD_2400; break; 354 case 4800: args->baud = SPABAUD_4800; break; 355 case 9600: args->baud = SPABAUD_9600; break; 356 case 19200: args->baud = SPABAUD_19200; break; 357 case 38400: args->baud = SPABAUD_38400; break; 358 case 57600: args->baud = SPABAUD_57600; break; 359 case 115200: args->baud = SPABAUD_115200; break; 360 default: 361 fprintf(stderr, "Baudrate '%s' unknown\n", optarg); 362 res = 0; 363 break; 364 } 365 } 366 break; 367 case 'T': 368 if(!strcmp(optarg, "1")) args->stopbits = SPASTOPBITS_1; 369 else if(!strcmp(optarg, "2")) args->stopbits = SPASTOPBITS_2; 370 else 371 { 372 fprintf(stderr, "Stopbits '%s' unknown\n", optarg); 373 res = 0; 374 } 375 break; 376 case 'A': 377 if(!strcmp(optarg, "5")) args->databits = SPADATABITS_5; 378 else if(!strcmp(optarg, "6")) args->databits = SPADATABITS_6; 379 else if(!strcmp(optarg, "7")) args->databits = SPADATABITS_7; 380 else if(!strcmp(optarg, "8")) args->databits = SPADATABITS_8; 381 else 382 { 383 fprintf(stderr, "Databits '%s' unknown\n", optarg); 384 res = 0; 385 } 386 break; 387 case 'C': 388 { 389 int i = 0; 390 args->protocol = SerialGetProtocol(optarg, &i); 391 if(i) 392 { 393 fprintf(stderr, "Protocol '%s' unknown\n", optarg); 394 res = 0; 395 } 396 } 397 break; 398 case 'Y': 399 { 400 int i = 0; 401 args->parity = SerialGetParity(optarg, &i); 402 if(i) 403 { 404 fprintf(stderr, "Parity '%s' unknown\n", optarg); 405 res = 0; 406 } 407 } 408 break; 409 case 'D': args->serdevice = optarg; break; 322 410 case 'I': args->initudp = 1; break; 323 411 case 'P': args->udpport = strtol(optarg, 0, 10); break; … … 383 471 " -n " LONG_OPT("--nmea ") "NMEA string for sending to server\n" 384 472 " -b " LONG_OPT("--bitrate ") "output bitrate\n" 473 " -I " LONG_OPT("--initudp ") "send initial UDP packet for firewall handling\n" 474 " -P " LONG_OPT("--udpport ") "set the local UDP port\n" 385 475 " -S " LONG_OPT("--proxyhost ") "proxy name or address\n" 386 476 " -R " LONG_OPT("--proxyport ") "proxy port, optional (default 2101)\n" 477 " -D " LONG_OPT("--serdevice ") "serial device for output\n" 478 " -B " LONG_OPT("--baud ") "baudrate for serial device\n" 479 " -T " LONG_OPT("--stopbits ") "stopbits for serial device\n" 480 " -C " LONG_OPT("--protocol ") "protocol for serial device\n" 481 " -Y " LONG_OPT("--parity ") "parity for serial device\n" 482 " -A " LONG_OPT("--databits ") "databits for serial device\n" 387 483 " -M " LONG_OPT("--mode ") "mode for data request\n" 388 484 " Valid modes are:\n" … … 469 565 if(getargs(argc, argv, &args)) 470 566 { 567 struct serial sx; 568 char nmeabuffer[200] = "$GPGGA,"; /* our start string */ 569 size_t nmeabufpos = 0; 570 size_t nmeastarpos = 0; 471 571 int sleeptime = 0; 572 if(args.serdevice) 573 { 574 const char *e = SerialInit(&sx, args.serdevice, args.baud, 575 args.stopbits, args.protocol, args.parity, args.databits, 1); 576 if(e) 577 { 578 fprintf(stderr, "%s\n", e); 579 return 20; 580 } 581 } 472 582 do 473 583 { … … 546 656 their_addr.sin_family = AF_INET; 547 657 their_addr.sin_addr = *((struct in_addr *)he->h_addr); 548 658 549 659 if(args.data && *args.data != '%' && args.mode == RTSP) 550 660 { … … 630 740 { 631 741 if(numbytes >= 17 && !strncmp(buf, "RTSP/1.0 200 OK\r\n", 17)) 632 742 { 633 743 int serverport = 0, session = 0; 634 744 const char *portcheck = "server_port="; … … 696 806 rtpbuffer[6] = 0; 697 807 rtpbuffer[7] = 0; 698 rtpbuffer[8] = 0; 699 rtpbuffer[9] = 0; 700 rtpbuffer[10] = 0; 701 rtpbuffer[11] = 0; 808 /* sequence and timestamp are empty */ 809 rtpbuffer[8] = (session>>24)&0xFF; 810 rtpbuffer[9] = (session>>16)&0xFF; 811 rtpbuffer[10] = (session>>8)&0xFF; 812 rtpbuffer[11] = (session)&0xFF; 702 813 /* fill structure with caster address information for UDP */ 703 814 memset(&casterRTP, 0, sizeof(casterRTP)); … … 926 1037 if(i < numbytes-l) 927 1038 chunkymode = 1; 928 1039 } 929 1040 else if(!strstr(buf, "ICY 200 OK")) 930 1041 { … … 976 1087 i = numbytes-pos; 977 1088 if(i > chunksize) i = chunksize; 978 fwrite(buf+pos, (size_t)i, 1, stdout); 1089 if(args.serdevice) 1090 { 1091 int ofs = 0; 1092 while(i > ofs && !stop) 1093 { 1094 int j = SerialWrite(&sx, buf+pos+ofs, i-ofs); 1095 if(j < 0) 1096 { 1097 fprintf(stderr, "Could not access serial device\n"); 1098 stop = 1; 1099 } 1100 else 1101 ofs += j; 1102 } 1103 } 1104 else 1105 fwrite(buf+pos, (size_t)i, 1, stdout); 979 1106 totalbytes += i; 980 1107 chunksize -= i; … … 997 1124 { 998 1125 totalbytes += numbytes; 999 fwrite(buf, (size_t)numbytes, 1, stdout); 1126 if(args.serdevice) 1127 { 1128 int ofs = 0; 1129 while(numbytes > ofs && !stop) 1130 { 1131 int i = SerialWrite(&sx, buf+ofs, numbytes-ofs); 1132 if(i < 0) 1133 { 1134 fprintf(stderr, "Could not access serial device\n"); 1135 stop = 1; 1136 } 1137 else 1138 ofs += i; 1139 } 1140 } 1141 else 1142 fwrite(buf, (size_t)numbytes, 1, stdout); 1000 1143 } 1001 1144 fflush(stdout); … … 1005 1148 starttime = time(0); 1006 1149 lastout = starttime; 1150 } 1151 if(args.serdevice && !stop) 1152 { 1153 int doloop = 1; 1154 while(doloop && !stop) 1155 { 1156 int i = SerialRead(&sx, buf, 200); 1157 if(i < 0) 1158 { 1159 fprintf(stderr, "Could not access serial device\n"); 1160 stop = 1; 1161 } 1162 else 1163 { 1164 int j = 0; 1165 if(i < 200) doloop = 0; 1166 fwrite(buf, i, 1, stdout); 1167 while(j < i) 1168 { 1169 if(nmeabufpos < 6) 1170 { 1171 if(nmeabuffer[nmeabufpos] != buf[j]) 1172 { 1173 if(nmeabufpos) nmeabufpos = 0; 1174 else ++j; 1175 } 1176 else 1177 { 1178 nmeastarpos = 0; 1179 ++j; ++nmeabufpos; 1180 } 1181 } 1182 else if((nmeastarpos && nmeabufpos == nmeastarpos + 3) 1183 || buf[j] == '\r' || buf[j] == '\n') 1184 { 1185 doloop = 0; 1186 nmeabuffer[nmeabufpos++] = '\r'; 1187 nmeabuffer[nmeabufpos++] = '\n'; 1188 if(send(sockfd, nmeabuffer, nmeabufpos, 0) 1189 != (int)nmeabufpos) 1190 { 1191 fprintf(stderr, "Could not send NMEA\n"); 1192 stop = 1; 1193 } 1194 nmeabufpos = 0; 1195 } 1196 else if(nmeabufpos > sizeof(nmeabuffer)-10 || 1197 buf[j] == '$') 1198 nmeabufpos = 0; 1199 else 1200 { 1201 if(buf[j] == '*') nmeastarpos = nmeabufpos; 1202 nmeabuffer[nmeabufpos++] = buf[j++]; 1203 } 1204 } 1205 } 1206 } 1007 1207 } 1008 1208 if(args.bitrate) … … 1033 1233 } 1034 1234 } while(args.data && *args.data != '%' && !stop); 1235 if(args.serdevice) 1236 { 1237 SerialFree(&sx); 1238 } 1035 1239 } 1036 1240 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.