Changeset 1884 in ntrip
- Timestamp:
- Sep 11, 2009, 11:49:19 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripclient/ntripclient.c
r1847 r1884 1 1 /* 2 2 NTRIP client for POSIX. 3 $Id: ntripclient.c,v 1. 49 2009/05/06 14:52:52 stuerzeExp $3 $Id: ntripclient.c,v 1.50 2009/06/08 14:07:22 stoecker Exp $ 4 4 Copyright (C) 2003-2008 by Dirk Stöcker <soft@dstoecker.de> 5 5 … … 65 65 66 66 /* CVS revision and version */ 67 static char revisionstr[] = "$Revision: 1. 49$";68 static char datestr[] = "$Date: 2009/0 5/06 14:52:52 $";67 static char revisionstr[] = "$Revision: 1.50 $"; 68 static char datestr[] = "$Date: 2009/06/08 14:07:22 $"; 69 69 70 70 enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, UDP = 5, END }; … … 853 853 ; 854 854 } 855 if(i == numbytes-l) 855 if(i == numbytes-l) 856 856 { 857 857 fprintf(stderr, "No 'Content-Type: gnss/data' or" 858 858 " 'Content-Type: gnss/sourcetable' found\n"); 859 859 error = 1; 860 860 } 861 else 861 else 862 862 { 863 863 /* check for http response end */ … … 889 889 if(rtpbuf[i] == '\r') 890 890 { 891 contentlength += httpresponselength; 891 contentlength += httpresponselength; 892 892 do 893 893 { … … 904 904 } 905 905 else 906 { 906 { 907 907 fprintf(stderr, "Could not extract content length\n"); 908 908 stop = 1; … … 970 970 continue; 971 971 } 972 else if((rtpbuf[1] == 96) && (i>12)) 972 else if((rtpbuf[1] == 96) && (i>12)) 973 973 { 974 974 fwrite(rtpbuf+12, (size_t)i-12, 1, stdout); … … 976 976 } 977 977 sn = u; ts = v; 978 978 979 979 /* Keep Alive */ 980 980 ct = time(0); … … 1487 1487 if(!k) 1488 1488 { 1489 buf[numbytes] = 0; /* latest end mark for strstr */ 1489 1490 if( numbytes > 17 && 1490 1491 !strstr(buf, "ICY 200 OK") && /* case 'proxy & ntrip 1.0 caster' */ … … 1533 1534 stop = 1; 1534 1535 } 1535 ++k; 1536 k = 1; 1537 if(args.mode == NTRIP1) 1538 continue; /* skip old headers for NTRIP1 */ 1539 else 1540 { 1541 char *ep = strstr(buf, "\r\n\r\n"); 1542 if(!ep || ep+4 == buf+numbytes) 1543 continue; 1544 ep += 4; 1545 memmove(buf, ep, numbytes-(ep-buf)); 1546 numbytes -= (ep-buf); 1547 } 1548 } 1549 sleeptime = 0; 1550 if(chunkymode) 1551 { 1552 int cstop = 0; 1553 int pos = 0; 1554 while(!stop && !cstop && !error && pos < numbytes) 1555 { 1556 switch(chunkymode) 1557 { 1558 case 1: /* reading number starts */ 1559 chunksize = 0; 1560 ++chunkymode; /* no break */ 1561 case 2: /* during reading number */ 1562 i = buf[pos++]; 1563 if(i >= '0' && i <= '9') chunksize = chunksize*16+i-'0'; 1564 else if(i >= 'a' && i <= 'f') chunksize = chunksize*16+i-'a'+10; 1565 else if(i >= 'A' && i <= 'F') chunksize = chunksize*16+i-'A'+10; 1566 else if(i == '\r') ++chunkymode; 1567 else if(i == ';') chunkymode = 5; 1568 else cstop = 1; 1569 break; 1570 case 3: /* scanning for return */ 1571 if(buf[pos++] == '\n') chunkymode = chunksize ? 4 : 1; 1572 else cstop = 1; 1573 break; 1574 case 4: /* output data */ 1575 i = numbytes-pos; 1576 if(i > chunksize) i = chunksize; 1577 if(args.serdevice) 1578 { 1579 int ofs = 0; 1580 while(i > ofs && !cstop && !stop && !error) 1581 { 1582 int j = SerialWrite(&sx, buf+pos+ofs, i-ofs); 1583 if(j < 0) 1584 { 1585 fprintf(stderr, "Could not access serial device\n"); 1586 stop = 1; 1587 } 1588 else 1589 ofs += j; 1590 } 1591 } 1592 else 1593 fwrite(buf+pos, (size_t)i, 1, stdout); 1594 totalbytes += i; 1595 chunksize -= i; 1596 pos += i; 1597 if(!chunksize) 1598 chunkymode = 1; 1599 break; 1600 case 5: 1601 if(i == '\r') chunkymode = 3; 1602 break; 1603 } 1604 } 1605 if(cstop) 1606 { 1607 fprintf(stderr, "Error in chunky transfer encoding\n"); 1608 error = 1; 1609 } 1536 1610 } 1537 1611 else 1538 1612 { 1539 sleeptime = 0;1540 if( chunkymode)1613 totalbytes += numbytes; 1614 if(args.serdevice) 1541 1615 { 1542 int cstop = 0; 1543 int pos = 0; 1544 while(!stop && !cstop && !error && pos < numbytes) 1616 int ofs = 0; 1617 while(numbytes > ofs && !stop) 1545 1618 { 1546 switch(chunkymode) 1547 { 1548 case 1: /* reading number starts */ 1549 chunksize = 0; 1550 ++chunkymode; /* no break */ 1551 case 2: /* during reading number */ 1552 i = buf[pos++]; 1553 if(i >= '0' && i <= '9') chunksize = chunksize*16+i-'0'; 1554 else if(i >= 'a' && i <= 'f') chunksize = chunksize*16+i-'a'+10; 1555 else if(i >= 'A' && i <= 'F') chunksize = chunksize*16+i-'A'+10; 1556 else if(i == '\r') ++chunkymode; 1557 else if(i == ';') chunkymode = 5; 1558 else cstop = 1; 1559 break; 1560 case 3: /* scanning for return */ 1561 if(buf[pos++] == '\n') chunkymode = chunksize ? 4 : 1; 1562 else cstop = 1; 1563 break; 1564 case 4: /* output data */ 1565 i = numbytes-pos; 1566 if(i > chunksize) i = chunksize; 1567 if(args.serdevice) 1568 { 1569 int ofs = 0; 1570 while(i > ofs && !cstop && !stop && !error) 1571 { 1572 int j = SerialWrite(&sx, buf+pos+ofs, i-ofs); 1573 if(j < 0) 1574 { 1575 fprintf(stderr, "Could not access serial device\n"); 1576 stop = 1; 1577 } 1578 else 1579 ofs += j; 1580 } 1581 } 1582 else 1583 fwrite(buf+pos, (size_t)i, 1, stdout); 1584 totalbytes += i; 1585 chunksize -= i; 1586 pos += i; 1587 if(!chunksize) 1588 chunkymode = 1; 1589 break; 1590 case 5: 1591 if(i == '\r') chunkymode = 3; 1592 break; 1593 } 1594 } 1595 if(cstop) 1596 { 1597 fprintf(stderr, "Error in chunky transfer encoding\n"); 1598 error = 1; 1599 } 1600 } 1601 else 1602 { 1603 totalbytes += numbytes; 1604 if(args.serdevice) 1605 { 1606 int ofs = 0; 1607 while(numbytes > ofs && !stop) 1608 { 1609 int i = SerialWrite(&sx, buf+ofs, numbytes-ofs); 1610 if(i < 0) 1611 { 1612 fprintf(stderr, "Could not access serial device\n"); 1613 stop = 1; 1614 } 1615 else 1616 ofs += i; 1617 } 1618 } 1619 else 1620 fwrite(buf, (size_t)numbytes, 1, stdout); 1621 } 1622 fflush(stdout); 1623 if(totalbytes < 0) /* overflow */ 1624 { 1625 totalbytes = 0; 1626 starttime = time(0); 1627 lastout = starttime; 1628 } 1629 if(args.serdevice && !stop) 1630 { 1631 int doloop = 1; 1632 while(doloop && !stop) 1633 { 1634 int i = SerialRead(&sx, buf, 200); 1619 int i = SerialWrite(&sx, buf+ofs, numbytes-ofs); 1635 1620 if(i < 0) 1636 1621 { … … 1639 1624 } 1640 1625 else 1626 ofs += i; 1627 } 1628 } 1629 else 1630 fwrite(buf, (size_t)numbytes, 1, stdout); 1631 } 1632 fflush(stdout); 1633 if(totalbytes < 0) /* overflow */ 1634 { 1635 totalbytes = 0; 1636 starttime = time(0); 1637 lastout = starttime; 1638 } 1639 if(args.serdevice && !stop) 1640 { 1641 int doloop = 1; 1642 while(doloop && !stop) 1643 { 1644 int i = SerialRead(&sx, buf, 200); 1645 if(i < 0) 1646 { 1647 fprintf(stderr, "Could not access serial device\n"); 1648 stop = 1; 1649 } 1650 else 1651 { 1652 int j = 0; 1653 if(i < 200) doloop = 0; 1654 fwrite(buf, i, 1, stdout); 1655 if(ser) 1656 fwrite(buf, i, 1, ser); 1657 while(j < i) 1641 1658 { 1642 int j = 0; 1643 if(i < 200) doloop = 0; 1644 fwrite(buf, i, 1, stdout); 1645 if(ser) 1646 fwrite(buf, i, 1, ser); 1647 while(j < i) 1659 if(nmeabufpos < 6) 1648 1660 { 1649 if(nmeabuf pos < 6)1661 if(nmeabuffer[nmeabufpos] != buf[j]) 1650 1662 { 1651 if(nmeabuffer[nmeabufpos] != buf[j]) 1652 { 1653 if(nmeabufpos) nmeabufpos = 0; 1654 else ++j; 1655 } 1656 else 1657 { 1658 nmeastarpos = 0; 1659 ++j; ++nmeabufpos; 1660 } 1663 if(nmeabufpos) nmeabufpos = 0; 1664 else ++j; 1661 1665 } 1662 else if((nmeastarpos && nmeabufpos == nmeastarpos + 3)1663 || buf[j] == '\r' || buf[j] == '\n')1664 {1665 doloop = 0;1666 nmeabuffer[nmeabufpos++] = '\r';1667 nmeabuffer[nmeabufpos++] = '\n';1668 if(send(sockfd, nmeabuffer, nmeabufpos, 0)1669 != (int)nmeabufpos)1670 {1671 fprintf(stderr, "Could not send NMEA\n");1672 error = 1;1673 }1674 nmeabufpos = 0;1675 }1676 else if(nmeabufpos > sizeof(nmeabuffer)-10 ||1677 buf[j] == '$')1678 nmeabufpos = 0;1679 1666 else 1680 1667 { 1681 if(buf[j] == '*') nmeastarpos = nmeabufpos;1682 nmeabuffer[nmeabufpos++] = buf[j++];1668 nmeastarpos = 0; 1669 ++j; ++nmeabufpos; 1683 1670 } 1671 } 1672 else if((nmeastarpos && nmeabufpos == nmeastarpos + 3) 1673 || buf[j] == '\r' || buf[j] == '\n') 1674 { 1675 doloop = 0; 1676 nmeabuffer[nmeabufpos++] = '\r'; 1677 nmeabuffer[nmeabufpos++] = '\n'; 1678 if(send(sockfd, nmeabuffer, nmeabufpos, 0) 1679 != (int)nmeabufpos) 1680 { 1681 fprintf(stderr, "Could not send NMEA\n"); 1682 error = 1; 1683 } 1684 nmeabufpos = 0; 1685 } 1686 else if(nmeabufpos > sizeof(nmeabuffer)-10 || 1687 buf[j] == '$') 1688 nmeabufpos = 0; 1689 else 1690 { 1691 if(buf[j] == '*') nmeastarpos = nmeabufpos; 1692 nmeabuffer[nmeabufpos++] = buf[j++]; 1684 1693 } 1685 1694 } 1686 1695 } 1687 1696 } 1688 if(args.bitrate) 1697 } 1698 if(args.bitrate) 1699 { 1700 int t = time(0); 1701 if(t > lastout + 60) 1689 1702 { 1690 int t = time(0); 1691 if(t > lastout + 60) 1692 { 1693 lastout = t; 1694 fprintf(stderr, "Bitrate is %dbyte/s (%d seconds accumulated).\n", 1695 totalbytes/(t-starttime), t-starttime); 1696 } 1703 lastout = t; 1704 fprintf(stderr, "Bitrate is %dbyte/s (%d seconds accumulated).\n", 1705 totalbytes/(t-starttime), t-starttime); 1697 1706 } 1698 1707 }
Note:
See TracChangeset
for help on using the changeset viewer.