int roce_add_gid(struct ib_device *ib_dev, u8 port,
		 union ib_gid *gid, struct ib_gid_attr *attr)
{
	struct ib_roce_gid_cache *cache;
	int ix;
	int ret = 0;
	struct net_device *idev;

	if (!ib_dev->cache.roce_gid_cache)
		return -ENOSYS;

	cache = ib_dev->cache.roce_gid_cache[port - start_port(ib_dev)];

	if (!cache || !cache->active)
		return -ENOSYS;

	if (!memcmp(gid, &zgid, sizeof(*gid)))
		return -EINVAL;

	if (ib_dev->get_netdev) {
		rcu_read_lock();
		idev = ib_dev->get_netdev(ib_dev, port);
		if (idev && attr->ndev != idev)
			/* Adding default GIDs in not permitted */
			if (rdma_is_default_gid(idev, gid,
			    roce_v1_noncompat_gid ? true : false)) {
				rcu_read_unlock();
				return -EPERM;
			}
		rcu_read_unlock();
	}

	mutex_lock(&cache->lock);

	ix = find_gid(cache, gid, attr, GID_ATTR_FIND_MASK_GID_TYPE |
		      GID_ATTR_FIND_MASK_NETDEV);
	if (ix >= 0)
		goto out_unlock;

	ix = find_gid(cache, &zgid, NULL, 0);
	if (ix < 0) {
		ret = -ENOSPC;
		goto out_unlock;
	}

	write_gid(ib_dev, port, cache, ix, gid, attr);

out_unlock:
	mutex_unlock(&cache->lock);
	return ret;
}
示例#2
0
int ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
		     union ib_gid *gid, struct ib_gid_attr *attr)
{
	struct ib_gid_table **ports_table = ib_dev->cache.gid_cache;
	struct ib_gid_table *table;
	int ix;
	int ret = 0;
	struct net_device *idev;

	table = ports_table[port - rdma_start_port(ib_dev)];

	if (!memcmp(gid, &zgid, sizeof(*gid)))
		return -EINVAL;

	if (ib_dev->get_netdev) {
		idev = ib_dev->get_netdev(ib_dev, port);
		if (idev && attr->ndev != idev) {
			union ib_gid default_gid;

			/* Adding default GIDs in not permitted */
			make_default_gid(idev, &default_gid);
			if (!memcmp(gid, &default_gid, sizeof(*gid))) {
				dev_put(idev);
				return -EPERM;
			}
		}
		if (idev)
			dev_put(idev);
	}

	mutex_lock(&table->lock);

	ix = find_gid(table, gid, attr, false, GID_ATTR_FIND_MASK_GID |
		      GID_ATTR_FIND_MASK_NETDEV);
	if (ix >= 0)
		goto out_unlock;

	ix = find_gid(table, &zgid, NULL, false, GID_ATTR_FIND_MASK_GID |
		      GID_ATTR_FIND_MASK_DEFAULT);
	if (ix < 0) {
		ret = -ENOSPC;
		goto out_unlock;
	}

	add_gid(ib_dev, port, table, ix, gid, attr, false);

out_unlock:
	mutex_unlock(&table->lock);
	return ret;
}
示例#3
0
/**
 * rdma_find_gid - Returns SGID attributes if the matching GID is found.
 * @device: The device to query.
 * @gid: The GID value to search for.
 * @gid_type: The GID type to search for.
 * @ndev: In RoCE, the net device of the device. NULL means ignore.
 *
 * rdma_find_gid() searches for the specified GID value in the software cache.
 *
 * Returns GID attributes if a valid GID is found or returns ERR_PTR for the
 * error. The caller must invoke rdma_put_gid_attr() to release the reference.
 *
 */
const struct ib_gid_attr *rdma_find_gid(struct ib_device *device,
					const union ib_gid *gid,
					enum ib_gid_type gid_type,
					struct net_device *ndev)
{
	unsigned long mask = GID_ATTR_FIND_MASK_GID |
			     GID_ATTR_FIND_MASK_GID_TYPE;
	struct ib_gid_attr gid_attr_val = {.ndev = ndev, .gid_type = gid_type};
	u8 p;

	if (ndev)
		mask |= GID_ATTR_FIND_MASK_NETDEV;

	for (p = 0; p < device->phys_port_cnt; p++) {
		struct ib_gid_table *table;
		unsigned long flags;
		int index;

		table = device->cache.ports[p].gid;
		read_lock_irqsave(&table->rwlock, flags);
		index = find_gid(table, gid, &gid_attr_val, false, mask, NULL);
		if (index >= 0) {
			const struct ib_gid_attr *attr;

			get_gid_entry(table->data_vec[index]);
			attr = &table->data_vec[index]->attr;
			read_unlock_irqrestore(&table->rwlock, flags);
			return attr;
		}
		read_unlock_irqrestore(&table->rwlock, flags);
	}

	return ERR_PTR(-ENOENT);
}
示例#4
0
/**
 * rdma_find_gid_by_port - Returns the GID entry attributes when it finds
 * a valid GID entry for given search parameters. It searches for the specified
 * GID value in the local software cache.
 * @device: The device to query.
 * @gid: The GID value to search for.
 * @gid_type: The GID type to search for.
 * @port_num: The port number of the device where the GID value should be
 *   searched.
 * @ndev: In RoCE, the net device of the device. NULL means ignore.
 *
 * Returns sgid attributes if the GID is found with valid reference or
 * returns ERR_PTR for the error.
 * The caller must invoke rdma_put_gid_attr() to release the reference.
 */
const struct ib_gid_attr *
rdma_find_gid_by_port(struct ib_device *ib_dev,
		      const union ib_gid *gid,
		      enum ib_gid_type gid_type,
		      u8 port, struct net_device *ndev)
{
	int local_index;
	struct ib_gid_table *table;
	unsigned long mask = GID_ATTR_FIND_MASK_GID |
			     GID_ATTR_FIND_MASK_GID_TYPE;
	struct ib_gid_attr val = {.ndev = ndev, .gid_type = gid_type};
	const struct ib_gid_attr *attr;
	unsigned long flags;

	if (!rdma_is_port_valid(ib_dev, port))
		return ERR_PTR(-ENOENT);

	table = rdma_gid_table(ib_dev, port);

	if (ndev)
		mask |= GID_ATTR_FIND_MASK_NETDEV;

	read_lock_irqsave(&table->rwlock, flags);
	local_index = find_gid(table, gid, &val, false, mask, NULL);
	if (local_index >= 0) {
		get_gid_entry(table->data_vec[local_index]);
		attr = &table->data_vec[local_index]->attr;
		read_unlock_irqrestore(&table->rwlock, flags);
		return attr;
	}

	read_unlock_irqrestore(&table->rwlock, flags);
	return ERR_PTR(-ENOENT);
}
示例#5
0
static int
_ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
		  union ib_gid *gid, struct ib_gid_attr *attr,
		  unsigned long mask, bool default_gid)
{
	struct ib_gid_table *table;
	int ret = 0;
	int ix;

	table = rdma_gid_table(ib_dev, port);

	mutex_lock(&table->lock);

	ix = find_gid(table, gid, attr, default_gid, mask, NULL);
	if (ix < 0) {
		ret = -EINVAL;
		goto out_unlock;
	}

	del_gid(ib_dev, port, table, ix);
	dispatch_gid_change_event(ib_dev, port);

out_unlock:
	mutex_unlock(&table->lock);
	if (ret)
		pr_debug("%s: can't delete gid %pI6 error=%d\n",
			 __func__, gid->raw, ret);
	return ret;
}
示例#6
0
int ib_find_cached_gid_by_port(struct ib_device *ib_dev,
			       const union ib_gid *gid,
			       u8 port, struct net_device *ndev,
			       u16 *index)
{
	int local_index;
	struct ib_gid_table **ports_table = ib_dev->cache.gid_cache;
	struct ib_gid_table *table;
	unsigned long mask = GID_ATTR_FIND_MASK_GID;
	struct ib_gid_attr val = {.ndev = ndev};

	if (port < rdma_start_port(ib_dev) ||
	    port > rdma_end_port(ib_dev))
		return -ENOENT;

	table = ports_table[port - rdma_start_port(ib_dev)];

	if (ndev)
		mask |= GID_ATTR_FIND_MASK_NETDEV;

	local_index = find_gid(table, gid, &val, false, mask);
	if (local_index >= 0) {
		if (index)
			*index = local_index;
		return 0;
	}

	return -ENOENT;
}
示例#7
0
static int _ib_cache_gid_table_find(struct ib_device *ib_dev,
				    const union ib_gid *gid,
				    const struct ib_gid_attr *val,
				    unsigned long mask,
				    u8 *port, u16 *index)
{
	struct ib_gid_table **ports_table = ib_dev->cache.gid_cache;
	struct ib_gid_table *table;
	u8 p;
	int local_index;

	for (p = 0; p < ib_dev->phys_port_cnt; p++) {
		table = ports_table[p];
		local_index = find_gid(table, gid, val, false, mask);
		if (local_index >= 0) {
			if (index)
				*index = local_index;
			if (port)
				*port = p + rdma_start_port(ib_dev);
			return 0;
		}
	}

	return -ENOENT;
}
int roce_gid_cache_find_gid_by_port(struct ib_device *ib_dev, union ib_gid *gid,
				    enum ib_gid_type gid_type, u8 port,
				    struct net *net, int if_index, u16 *index)
{
	int local_index;
	struct ib_roce_gid_cache *cache;
	unsigned long mask = GID_ATTR_FIND_MASK_GID_TYPE;
	struct ib_gid_attr val = {.gid_type = gid_type};

	if (!ib_dev->cache.roce_gid_cache || port < start_port(ib_dev) ||
	    port >= (start_port(ib_dev) + ib_dev->phys_port_cnt))
		return -ENOENT;

	cache = ib_dev->cache.roce_gid_cache[port - start_port(ib_dev)];
	if (!cache || !cache->active)
		return -ENOENT;

	mask |= get_netdev_from_ifindex(net, if_index, &val);

	local_index = find_gid(cache, gid, &val, mask);
	if (local_index >= 0) {
		if (index)
			*index = local_index;
		return 0;
	}

	return -ENOENT;
}
static int _roce_gid_cache_find_gid(struct ib_device *ib_dev, union ib_gid *gid,
				    const struct ib_gid_attr *val,
				    unsigned long mask,
				    u8 *port, u16 *index)
{
	struct ib_roce_gid_cache *cache;
	u8 p;
	int local_index;

	if (!ib_dev->cache.roce_gid_cache)
		return -ENOENT;

	for (p = 0; p < ib_dev->phys_port_cnt; p++) {
		if (rdma_port_get_link_layer(ib_dev, p + start_port(ib_dev)) !=
		    IB_LINK_LAYER_ETHERNET)
			continue;
		cache = ib_dev->cache.roce_gid_cache[p];
		if (!cache || !cache->active)
			continue;
		local_index = find_gid(cache, gid, val, mask);
		if (local_index >= 0) {
			if (index)
				*index = local_index;
			if (port)
				*port = p + start_port(ib_dev);
			return 0;
		}
	}

	return -ENOENT;
}
int roce_del_gid(struct ib_device *ib_dev, u8 port,
		 union ib_gid *gid, struct ib_gid_attr *attr)
{
	struct ib_roce_gid_cache *cache;
	int ix;

	if (!ib_dev->cache.roce_gid_cache)
		return 0;

	cache  = ib_dev->cache.roce_gid_cache[port - start_port(ib_dev)];

	if (!cache || !cache->active)
		return -ENOSYS;

	if (attr->ndev) {
		/* Deleting default GIDs in not permitted */
		if (rdma_is_default_gid(attr->ndev, gid,
		    roce_v1_noncompat_gid ? true : false))
			return -EPERM;
	}

	mutex_lock(&cache->lock);

	ix = find_gid(cache, gid, attr,
		      GID_ATTR_FIND_MASK_GID_TYPE |
		      GID_ATTR_FIND_MASK_NETDEV);
	if (ix < 0)
		goto out_unlock;

	write_gid(ib_dev, port, cache, ix, &zgid, &zattr);

out_unlock:
	mutex_unlock(&cache->lock);
	return 0;
}
示例#11
0
void ib_cache_gid_set_default_gid(struct ib_device *ib_dev, u8 port,
				  struct net_device *ndev,
				  enum ib_cache_gid_default_mode mode)
{
	struct ib_gid_table **ports_table = ib_dev->cache.gid_cache;
	union ib_gid gid;
	struct ib_gid_attr gid_attr;
	struct ib_gid_table *table;
	int ix;
	union ib_gid current_gid;
	struct ib_gid_attr current_gid_attr = {};

	table  = ports_table[port - rdma_start_port(ib_dev)];

	make_default_gid(ndev, &gid);
	memset(&gid_attr, 0, sizeof(gid_attr));
	gid_attr.ndev = ndev;

	mutex_lock(&table->lock);
	ix = find_gid(table, NULL, NULL, true, GID_ATTR_FIND_MASK_DEFAULT);

	/* Coudn't find default GID location */
	WARN_ON(ix < 0);

	if (!__ib_cache_gid_get(ib_dev, port, ix,
				&current_gid, &current_gid_attr) &&
	    mode == IB_CACHE_GID_DEFAULT_MODE_SET &&
	    !memcmp(&gid, &current_gid, sizeof(gid)) &&
	    !memcmp(&gid_attr, &current_gid_attr, sizeof(gid_attr)))
		goto unlock;

	if ((memcmp(&current_gid, &zgid, sizeof(current_gid)) ||
	     memcmp(&current_gid_attr, &zattr,
		    sizeof(current_gid_attr))) &&
	    del_gid(ib_dev, port, table, ix, true)) {
		pr_warn("ib_cache_gid: can't delete index %d for default gid %pI6\n",
			ix, gid.raw);
		goto unlock;
	}

	if (mode == IB_CACHE_GID_DEFAULT_MODE_SET)
		if (add_gid(ib_dev, port, table, ix, &gid, &gid_attr, true))
			pr_warn("ib_cache_gid: unable to add default gid %pI6\n",
				gid.raw);

unlock:
	if (current_gid_attr.ndev)
		dev_put(current_gid_attr.ndev);
	mutex_unlock(&table->lock);
}
示例#12
0
static int __ib_cache_gid_add(struct ib_device *ib_dev, u8 port,
			      union ib_gid *gid, struct ib_gid_attr *attr,
			      unsigned long mask, bool default_gid)
{
	struct ib_gid_table *table;
	int ret = 0;
	int empty;
	int ix;

	/* Do not allow adding zero GID in support of
	 * IB spec version 1.3 section 4.1.1 point (6) and
	 * section 12.7.10 and section 12.7.20
	 */
	if (rdma_is_zero_gid(gid))
		return -EINVAL;

	table = rdma_gid_table(ib_dev, port);

	mutex_lock(&table->lock);

	ix = find_gid(table, gid, attr, default_gid, mask, &empty);
	if (ix >= 0)
		goto out_unlock;

	if (empty < 0) {
		ret = -ENOSPC;
		goto out_unlock;
	}
	attr->device = ib_dev;
	attr->index = empty;
	attr->port_num = port;
	attr->gid = *gid;
	ret = add_modify_gid(table, attr);
	if (!ret)
		dispatch_gid_change_event(ib_dev, port);

out_unlock:
	mutex_unlock(&table->lock);
	if (ret)
		pr_warn("%s: unable to add gid %pI6 error=%d\n",
			__func__, gid->raw, ret);
	return ret;
}
示例#13
0
int ib_cache_gid_del(struct ib_device *ib_dev, u8 port,
		     union ib_gid *gid, struct ib_gid_attr *attr)
{
	struct ib_gid_table **ports_table = ib_dev->cache.gid_cache;
	struct ib_gid_table *table;
	int ix;

	table = ports_table[port - rdma_start_port(ib_dev)];

	mutex_lock(&table->lock);

	ix = find_gid(table, gid, attr, false,
		      GID_ATTR_FIND_MASK_GID	  |
		      GID_ATTR_FIND_MASK_NETDEV	  |
		      GID_ATTR_FIND_MASK_DEFAULT);
	if (ix < 0)
		goto out_unlock;

	del_gid(ib_dev, port, table, ix, false);

out_unlock:
	mutex_unlock(&table->lock);
	return 0;
}
示例#14
0
int main (int argc, char *argv[])
{
  fd_set readset;
  fd_set writeset;
  int n, sel;
  int c, errflg=0;
  struct sigaction sigact;
  sigset_t sigmask;
  char *scratch, *next_scratch;
  char nmea_buf[1024];
  char send_buf[1024];
  int  gps_buf[15];
  int  nmea_index = 0;
  int  send_len = 0;
  /* Set default options */
  outfile = stdout;
  int sAnt = 0;

  memset(gps_buf, 0, 15);
  memset(send_buf, 0, 1024);
  send_len = 0;

  /* Process options */
  while ((c = getopt(argc, argv, "Vlqvs:o:p:t:m:u:g:/:")) != EOF)
    switch (c) {
      case 'q':
	quiet=1;
	break;
      case 'v':
        verbose = 1;
        break;
      case 'l':
        linebuff = 1;
        break;
      case 'p':
        opt_ptyname = optarg;
        break;
      case 't':
        opt_ttyname = optarg;
        break;
      case 'm':
	/* mode for pty: [user,[group,]]mode */
	scratch = strdup(optarg);
	if ((next_scratch = strchr(scratch,',')) != NULL) {
	  /* Username */
	  *next_scratch = '\0';
	  next_scratch++;

	  frontend_owner = find_uid(scratch);

	  scratch = next_scratch;

	  if ((next_scratch = strchr(scratch,',')) != NULL)
	  {
	    /* Group */
	    *next_scratch = '\0';
	    next_scratch++;
	    
	    frontend_group = find_gid(scratch);

	    scratch = next_scratch;
	  }
	}
	frontend_mode = strtol(scratch,NULL,8);
	break;
      case 'u':
	switch_uid = find_uid(optarg);
	break;
      case 'g':
	switch_gid = find_gid(optarg);
	break;
      case '/':
	switch_root = strdup(optarg);
	break;
      case 's':
        settings = optarg;
        break;
      case 'o':
        outfilename=optarg;
        if ( (outfile = fopen(outfilename,"w")) == NULL)
          errorf("Couldn't open output file '%s' for write: %s\n",outfilename,strerror(errno));
        break;
      case 'V':
	puts(VERSION);
	exit(0);
      case '?':
      default:
        errflg++;
        break;
    }

  if (errflg || ((argc-optind) < 1) || ((argc-optind) > 2)) {
    usage(argv[0]);
    exit (2);
  }

  /* Process the two non-flag options */
  backend = argv[optind];
  if ((argc-optind) == 2)
    frontend = argv[optind+1];
        
  if (strcmp(frontend,"-") == 0)
    frontend = NULL;
  if (linebuff)
    setlinebuf(outfile);

  atexit (closedown);
  /* Do some initialization */
  stty_initstore();

  sendudp_open();
  /* Setup backend */
  if (setup_backend(backfd) < 0)
    errorf ("select failed. errno = %d\n", errno);

  /* Setup frontend */
  if ((setup_frontend(frontfd)) < 0)
    errorf("setup_frontend failed: %s\n",strerror(errno));

  /* Drop privileges if we've been asked to */
  if (switch_root)
  {
    if (chroot(switch_root) != 0)
      errorf("chroot(%s) failed: %s\n",switch_root,strerror(errno));
  }
  if (switch_gid != -1)
  {
    if (setgroups(1,&switch_gid) == -1)
      errorf("setgroups(1,[%d]) failed: %s\n",switch_gid, strerror(errno));
    if (setregid(switch_gid, switch_gid) == -1)
      errorf("setregid(%d,%d) failed: %s\n",switch_gid,switch_gid);
    if (getgid() != switch_gid)
      errorf("setregid succeeded, but we're the wrong gid!");
    if (getegid() != switch_gid)
      errorf("setregid succeeded, but we're the wrong effective gid!");
  }
  if (switch_uid != -1)
  {
    if (setreuid(switch_uid, switch_uid) == -1)
      errorf("setreuid(%d,%d) failed: %s\n",switch_uid,switch_uid,strerror(errno));
    if (getuid() != switch_uid)
      errorf("setreuid succeeded, but we're the wrong uid!");
    if (geteuid() != switch_uid)
      errorf("setregid succeeded, but we're the wrong effective uid!");
  }

  
  /* calc (initial) max file descriptor to use in select() */
  fdmax = max(backfd[0], frontfd[0]);

  /* Set up signal handlers and such */
  sigemptyset(&sigmask);
  memset(&sigact,0,sizeof sigact);
  sigact.sa_handler = sigdeath;
  sigact.sa_mask = sigmask;

  sigaction(SIGHUP,&sigact,NULL);
  sigaction(SIGINT,&sigact,NULL);
  sigaction(SIGQUIT,&sigact,NULL);
  sigaction(SIGPIPE,&sigact,NULL);
  sigaction(SIGTERM,&sigact,NULL);

  sigact.sa_handler = sigchld;
  sigaction(SIGCHLD,&sigact,NULL);

  pthread_t udp_recv;
  pthread_create(&udp_recv, NULL, udp_recv_gnssmode_thread, NULL);
  pthread_detach(udp_recv);

  struct tm p;
  time_t timep;
  while (!please_die_now)
  {
    do
    {
      FD_ZERO (&readset);
      FD_SET (backfd[0], &readset);
      FD_SET (frontfd[0], &readset);
      FD_ZERO (&writeset);
      FD_SET (backfd[1], &writeset);
      FD_SET (frontfd[1], &writeset);
      sel = select(fdmax + 1, &readset, &writeset, NULL, NULL);
    }
    while (sel == -1 && errno == EINTR && !please_die_now);
    if (sel == -1 && errno != EINTR)
      errorf ("select failed. errno = %d\n", errno);
    else if (please_die_now)
      break;

    if (FD_ISSET(backfd[0], &readset))
    {
      if ((n = read(backfd[0], buff, BUFF_SIZE)) == 0)
      {
	/* Serial port has closed.  This doesn't really make sense for
	 * a real serial port, but for sockets and programs, probably
	 * we should just exit.
	 */
	if (!quiet)
	  errorf("Backend device was closed.\n");
	break;
      }
      else if (n < 0)
      {
	if ( (errno != EAGAIN) && (errno != EINTR) )
	{
	  errorf("Error reading from backend device: %s\n",strerror(errno));
	}
	break;
      }
      else
      {
	/* We should handle this better.  FIX */
    	if(FD_ISSET(frontfd[1], &writeset))
        {
        if (write (frontfd[1], buff, n) != n)
	  errorf("Error writing to frontend device: %s\n",strerror(errno));
        }
       // if (!quiet)
	     //   dumpbuff(1,buff,n);
	//nmea decode
	{
		tNmea_Msg nmeamsg ;	
	 	int i=0;
		int ret = 0;
		for(i=0; i<n; i++)
		{
			if(buff[i] == '$')
				nmea_index = 0;
			nmea_buf[nmea_index] = buff[i];
			if(buff[i] == '\r')
				nmea_buf[nmea_index] = 0;
			if(buff[i] == '\n')
			{
				nmea_buf[nmea_index] = 0;
                #if 0
        			if (!quiet)
					fprintf(outfile,"%s\n",nmea_buf);
                #endif
#if 1 
				
                ret = NmeaDecode(nmea_buf,&nmeamsg);
                
                if(nmeamsg.nMsgMask == GGA_DECODE)
                {
                    memset(send_buf, 0, 1024);
                    send_len = 0;
                }

                memcpy(send_buf+send_len, nmea_buf, nmea_index);
                send_len += strlen(nmea_buf);
                send_buf[send_len] = 0x0D;
                send_len ++;
                                    
				if(nmeamsg.nMsgMask & ANT_DECODE)
				{
					sAnt = nmeamsg.nAnttenaStatus;
					//sendudp(1011,&sAnt, 4);  //gui
					sAnt |= (nmeamsg.version<<8);
				}

				if(nmeamsg.nMsgMask & RMC_DECODE)
				{
				    if (nmea_buf[3] == 'R' && nmea_buf[4] == 'M' && nmea_buf[5] == 'C' )
				    {
                        if (!quiet)
                            fprintf(outfile,"%s=len=%d\n",nmea_buf, strlen(nmea_buf));
                        sendudp(1014,nmea_buf, strlen(nmea_buf));  //busdemaon
				    }
				}
                
				if(nmeamsg.nMsgMask >= 0x8F)
				{
				   sendudp(1012, send_buf, send_len);
                   sendudp(1011,&nmeamsg.aSvInfo, 2*sizeof(tSVData));  //gui satelite display
                   if (!quiet) 
                   {
                       //fprintf(outfile,"\r\n\r\n%s---------send_len=%d\n\n",send_buf,send_len);
                       
                       fprintf(outfile,"nAnttenaStatus=%d,position=%c mode=%d fy=%f fx=%f (%d-%d-%d)(%d:%d:%f)\n",
                           sAnt,
                           nmeamsg.cFixFlag,
                           NmeaGetRxRunMode(),
                           nmeamsg.fLatInDegree,
                           nmeamsg.fLonInDegree,
                           nmeamsg.usYear,    
                           nmeamsg.ucMonth,
                           nmeamsg.ucDay,                           
                           nmeamsg.usHours,    
                           nmeamsg.usMinutes,
                           nmeamsg.fSeconds);
                   }
                   #if 1
                   localtime_r(&timep, &p);
                   p.tm_sec = (int)nmeamsg.fSeconds;
                   p.tm_min = nmeamsg.usMinutes;
                   p.tm_hour = nmeamsg.usHours+8;
                   p.tm_mday = nmeamsg.ucDay;
                   p.tm_mon = nmeamsg.ucMonth-1;
                   p.tm_year = nmeamsg.usYear + 100;
                   timep = mktime(&p);
                    if(nmeamsg.cFixFlag == 'A')
                        gps_buf[0] = 1;
                    else
                        gps_buf[0] = 0;
                    gps_buf[1] = nmeamsg.fLonInDegree*1000000;
                    gps_buf[2] = nmeamsg.fLatInDegree*1000000;
                    gps_buf[3] = (int)timep;
                    gps_buf[4] = (int)timep;
                    gps_buf[5] = nmeamsg.fHeading;
                    gps_buf[6] = nmeamsg.fGroundVel*1.85;
                    if(nmeamsg.cLatIdx == 'S')
                        gps_buf[7] = 1;
                    else
                        gps_buf[7] = 0;
                    if(nmeamsg.cLonIdx == 'W')
                        gps_buf[8] = 1;
                    else
                        gps_buf[8] = 0;
                    gps_buf[9] = nmeamsg.fAltitude;    
                    
                    gps_buf[10] = NmeaGetRxRunMode();
                    gps_buf[11] = nmeamsg.aSvInfo[1].nSvsUsed;
                    gps_buf[12] = nmeamsg.aSvInfo[0].nSvsUsed;
                    gps_buf[13] = sAnt;
#if 0
                    printf("position=%d, flon=%d, flat=%d, %d, %d, iOrientation=%d, vel=%d, s=%d, w=%d, alt=%d, mode=%d, gps=%d, bd=%d\n",
                        gps_buf[0], gps_buf[1],gps_buf[2],gps_buf[3], gps_buf[4],gps_buf[5], gps_buf[6],gps_buf[7], gps_buf[8],gps_buf[9], gps_buf[10],
                        gps_buf[11], gps_buf[12]);
#endif
                    sendudp(1013, gps_buf, 4*14);
                    sendudp(1015, gps_buf, 4*14);  //busdemaon
                    memset(gps_buf, 0 , 15);
                    #endif
                    
                    memset(send_buf, 0, 1024);
                    send_len = 0;
				}
                
#endif
			}	
			nmea_index++;
//			fprintf(outfile,"nmea_index = %d\n",nmea_index);
			if(nmea_index >= 1024)
				nmea_index = 0;
				
		}	
	}
      }
    }

    if (please_die_now)
      break;

    if (FD_ISSET(frontfd[0], &readset))
    {
      if ((n = read(frontfd[0], buff, BUFF_SIZE)) == 0)
      {
        if (listenfd)
        {
          if (close(frontfd[0]) < 0)
            errorf("Couldn't close old frontfd: %s\n",strerror(errno));
          if ((frontfd[0]=frontfd[1]=accept(listenfd,NULL,NULL)) < 0)
            errorf("Couldn't accept new socket connection: %s\n",strerror(errno));
        }
          
      }
      else if (n <= 0)
      {
	if ( (errno == EAGAIN) || (errno == EINTR) )
	{
	  /* No real error */
	}
	else
	{
	  errorf("Error reading from frontend device: %s\n",strerror(errno));
	}
      }
      else
      {
        if (write (backfd[1], buff, n) != n)
	  errorf("Error writing to backend device: %s\n",strerror(errno));
	if (!quiet)
	  dumpbuff(0,buff,n);
      }
    }

  }
  stty_orig();
  exit(0);
}
示例#15
0
int main(int argc, char *argv[])
{
	FILE *f;
	char buf[1000];
	char **gname;
	char name[500];
	int is_end = 1;
	int num_genes = 0;
	int i = 0;

	strcpy(buf, "");
	if( argc != 3 ) {
		printf("filter_protein_db_fasta fasta gff\n");
		return 1;
	}

	f = fopen(argv[2], "r");
	while(fgets(buf, 1000, f)) num_genes++;

	gname = (char **) ckalloc(sizeof(char *) * num_genes);	
	for( i = 0; i < num_genes; i++ ) {
		gname[i] = (char *) ckalloc(sizeof(char) * 500);
		strcpy(gname[i], "");
	}

	fseek(f, 0, SEEK_SET);
	i = 0;
	while( fgets(buf, 1000, f) ) {
		if( sscanf(buf, "%*s %*s %*s %*s %*s %*s %*s %*s %s", gname[i]) != 1 ) {
			printf("wrong gff line: %s\n", buf);
			return 1;
		}
		i++;
	}
	fclose(f);

	f = fopen(argv[1], "r");

	if( fgets(buf, 1000, f) ) is_end = 1;
	else is_end = 0;

	while(is_end != 0)
	{
		if(buf[0] == '>')
		{
			if( sscanf(buf+1, "%s %*s", name) != 1 ) {
				printf("bad format in %s\n", buf);
				return 1;
			}
			else {
				if( find_gid(name, gname, num_genes) != -1 ) {
					printf("%s", buf);
					if(fgets(buf, 1000, f)) is_end = 1;
					else is_end = 0;
					while((is_end != 0 ) &&  (buf[0] != '>')) {
						if( buf[0] != '>' ) printf("%s", buf);

						if( fgets(buf, 1000, f) ) is_end = 1;
						else is_end = 0;
					}
				}
				else {
					if(fgets(buf, 1000, f)) is_end = 1;
					else is_end = 0;
					while((is_end != 0 ) &&  (buf[0] != '>')) {
						if( fgets(buf, 1000, f) ) is_end = 1;
						else is_end = 0;
					}
				}
			}
		}
	}

	fclose(f);
	return 0;
}