Changeset 2273 in ntrip


Ignore:
Timestamp:
Jan 21, 2010, 10:00:49 AM (15 years ago)
Author:
stoecker
Message:

fixed serial access problem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ntripserver/ntripserver.c

    r1883 r2273  
     1#define WINDOWSVERSION
    12/*
    2  * $Id: ntripserver.c,v 1.48 2009/04/27 09:47:59 stoecker Exp $
     3 * $Id: ntripserver.c,v 1.49 2009/09/07 13:26:36 stoecker Exp $
    34 *
    45 * Copyright (c) 2003...2007
     
    3738
    3839/* CVS revision and version */
    39 static char revisionstr[] = "$Revision: 1.48 $";
    40 static char datestr[]     = "$Date: 2009/04/27 09:47:59 $";
     40static char revisionstr[] = "$Revision: 1.49 $";
     41static char datestr[]     = "$Date: 2009/09/07 13:26:36 $";
    4142
    4243#include <ctype.h>
     
    111112
    112113static int ttybaud             = 19200;
     114#ifndef WINDOWSVERSION
    113115static const char *ttyport     = "/dev/gps";
     116#else
     117static const char *ttyport     = "COM1";
     118#endif
    114119static const char *filepath    = "/dev/stdin";
    115120static enum MODE inputmode     = INFILE;
     
    171176*
    172177*/
    173 
    174178int main(int argc, char **argv)
    175179{
     
    18431847static HANDLE openserial(const char * tty, int baud)
    18441848{
    1845   DCB dcb;
    1846   COMMTIMEOUTS cmt;
    18471849  char compath[15] = "";
    18481850
    18491851  snprintf(compath, sizeof(compath), "\\\\.\\%s", tty);
    1850 /*** opening the serial port ***/
    1851   gps_serial = CreateFile(compath, GENERIC_READ | GENERIC_WRITE, 0, 0,
    1852     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    1853   if(gps_serial == INVALID_HANDLE_VALUE)
     1852  if((gps_serial = CreateFile(compath, GENERIC_WRITE|GENERIC_READ
     1853  , 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
    18541854  {
    18551855    fprintf(stderr, "ERROR: opening serial connection\n");
    18561856    return (INVALID_HANDLE_VALUE);
    18571857  }
    1858 /*** configuring the serial port ***/
    1859   FillMemory(&dcb, sizeof(dcb), 0);
    1860   dcb.DCBlength = sizeof(dcb);
    1861   if(!GetCommState(gps_serial, &dcb))
     1858
     1859  DCB dcb;
     1860  memset(&dcb, 0, sizeof(dcb));
     1861  char str[100];
     1862  snprintf(str,sizeof(str),
     1863  "baud=%d parity=N data=8 stop=1 xon=off octs=off rts=off",
     1864  baud);
     1865
     1866  COMMTIMEOUTS ct = {1000, 1, 0, 0, 0};
     1867
     1868  if(!BuildCommDCB(str, &dcb))
    18621869  {
    18631870    fprintf(stderr, "ERROR: get serial attributes\n");
    18641871    return (INVALID_HANDLE_VALUE);
    18651872  }
    1866   switch (baud)
    1867   {
    1868   case 110:
    1869     baud = CBR_110;
    1870     break;
    1871   case 300:
    1872     baud = CBR_300;
    1873     break;
    1874   case 600:
    1875     baud = CBR_600;
    1876     break;
    1877   case 1200:
    1878     baud = CBR_1200;
    1879     break;
    1880   case 2400:
    1881     baud = CBR_2400;
    1882     break;
    1883   case 4800:
    1884     baud = CBR_4800;
    1885     break;
    1886   case 9600:
    1887     baud = CBR_9600;
    1888     break;
    1889   case 14400:
    1890     baud = CBR_14400;
    1891     break;
    1892   case 19200:
    1893     baud = CBR_19200;
    1894     break;
    1895   case 38400:
    1896     baud = CBR_38400;
    1897     break;
    1898   case 56000:
    1899     baud = CBR_56000;
    1900     break;
    1901   case 57600:
    1902     baud = CBR_57600;
    1903     break;
    1904   case 115200:
    1905     baud = CBR_115200;
    1906     break;
    1907   case 128000:
    1908     baud = CBR_128000;
    1909     break;
    1910   case 256000:
    1911     baud = CBR_256000;
    1912     break;
    1913   default:
    1914     fprintf(stderr, "WARNING: Baud settings not useful, using 19200\n");
    1915     baud = CBR_19200;
    1916     break;
    1917   }
    1918   dcb.BaudRate = baud;
    1919   dcb.ByteSize = 8;
    1920   dcb.StopBits = ONESTOPBIT;
    1921   dcb.Parity   = NOPARITY;
    1922   if(!GetCommState(gps_serial, &dcb))
    1923   {
    1924     fprintf(stderr, "ERROR: get serial attributes\n");
     1873  else if(!SetCommState(gps_serial, &dcb))
     1874  {
     1875    fprintf(stderr, "ERROR: set serial attributes\n");
    19251876    return (INVALID_HANDLE_VALUE);
    19261877  }
    1927   FillMemory(&cmt, sizeof(cmt), 0);
    1928   cmt.ReadIntervalTimeout = 1000;
    1929   cmt.ReadTotalTimeoutMultiplier = 1;
    1930   cmt.ReadTotalTimeoutConstant = 0;
    1931   if(!SetCommTimeouts(gps_serial, &cmt))
     1878  else if(!SetCommTimeouts(gps_serial, &ct))
    19321879  {
    19331880    fprintf(stderr, "ERROR: set serial timeouts\n");
    19341881    return (INVALID_HANDLE_VALUE);
    19351882  }
     1883
    19361884  return (gps_serial);
    1937 } /* openserial */
     1885}
    19381886#endif
    19391887
     
    19851933  fprintf(stderr, "       mandatory\n\n");
    19861934  fprintf(stderr, "       <InputMode> = 1 (Serial Port):\n");
    1987   fprintf(stderr, "       -i <Device>       Serial input device, default: /dev/gps, mandatory if\n");
     1935  fprintf(stderr, "       -i <Device>       Serial input device, default: %s, mandatory if\n", ttyport);
    19881936  fprintf(stderr, "                         <InputMode>=1\n");
    19891937  fprintf(stderr, "       -b <BaudRate>     Serial input baud rate, default: 19200 bps, mandatory\n");
     
    20021950  fprintf(stderr, "       <InputMode> = 3 (File):\n");
    20031951  fprintf(stderr, "       -s <File>         File name to simulate stream by reading data from (log)\n");
    2004   fprintf(stderr, "                         file, default is /dev/stdin, mandatory for <InputMode> = 3\n\n");
     1952  fprintf(stderr, "                         file, default is %s, mandatory for <InputMode> = 3\n\n", filepath);
    20051953  fprintf(stderr, "       <InputMode> = 4 (SISNeT Data Server):\n");
    20061954  fprintf(stderr, "       -H <SisnetHost>   SISNeT Data Server name or address,\n");
Note: See TracChangeset for help on using the changeset viewer.