Esempio n. 1
0
int app_rtsp_server_set_global_info(rtsp_server_config *config, rtsp_server_config *newconfig)
{
	if(g_rtsp_shandle == NULL) {
		PRINTF("\n");
		return -1;
	}

	rtsp_ginfo_print(config);
	int need_save = 0;
	mid_mutex_lock(g_rtsp_shandle->mutex);
	rtsp_server_config *old = &(g_rtsp_shandle->rtsp_config);

	/*rtsp listen port*/
	if((config->s_port != old->s_port) && (config->s_port >= 81 && config->s_port <= 65535)) {
		old->s_port = config->s_port;
		need_save = 1;
	}

	/*rtsp active time 10-900000*/
	if(config->active != old->active) {
		if(config->active >= 10 && config->active <= 900000) {
			old->active = config->active;
			need_save  = 1;
			//set rtsp lib the active
			rtsp_set_keepactive_time(g_rtsp_shandle->rtsp_config.active);

		}
	}

	//mtu 228--1500
	if(config->s_mtu != old->s_mtu) {
		if(config->s_mtu >= 228 && config->s_mtu <= 1500) {
			old->s_mtu = config->s_mtu ;
			need_save = 1;
		}
	}

	if(config->mult_flag == 0 || config->mult_flag == 1) {
		if(config->mult_flag != old->mult_flag) {
			//multicast
			if(config->mult_flag == 1) {
				old->mult_flag = config->mult_flag;
				strcpy(old->mult_ip, config->mult_ip);
				old->mult_port = config->mult_port;
				need_save = 1;


			} else {
				old->mult_flag = config->mult_flag;
				need_save = 1;

			}
		} else if((config->mult_flag == old->mult_flag) && (config->mult_flag == 1)) {
			if(strcmp(old->mult_ip, config->mult_ip) != 0 || old->mult_port != config->mult_port) {
				strcpy(old->mult_ip, config->mult_ip);
				old->mult_port = config->mult_port;
				need_save = 1;


			}
		}
	}


	//save flash
	if(need_save == 1) {
		app_rtsp_global_config_fwrite(old);
	}

	mid_mutex_unlock(g_rtsp_shandle->mutex);
	return 0;
}
Esempio n. 2
0
File: livetv.c Progetto: Bladed/xbmc
/*
 * cmyth_livetv_chain_seek(cmyth_recorder_t file, long long offset, int whence)
 * 
 * Scope: PUBLIC
 *
 * Description
 *
 * Seek to a new position in the file based on the value of whence:
 *	SEEK_SET
 *		The offset is set to offset bytes.
 *	SEEK_CUR
 *		The offset is set to the current position plus offset bytes.
 *	SEEK_END
 *		The offset is set to the size of the file minus offset bytes.
 *
 * Return Value:
 *
 * Sucess: 0
 *
 * Failure: an int containing -errno
 */
static long long
cmyth_livetv_chain_seek(cmyth_recorder_t rec, long long offset, int whence)
{
	long long ret;
	cmyth_file_t fp;
	int cur, ct;

	if (rec == NULL)
		return -EINVAL;

	ct  = rec->rec_livetv_chain->chain_ct;

	if (whence == SEEK_END) {

		offset -= rec->rec_livetv_file->file_req;
		for (cur = rec->rec_livetv_chain->chain_current; cur < ct; cur++) {
			offset += rec->rec_livetv_chain->chain_files[cur]->file_length;
		}

		cur = rec->rec_livetv_chain->chain_current;
		fp  = rec->rec_livetv_chain->chain_files[cur];
		whence = SEEK_CUR;
	}

	if (whence == SEEK_SET) {

		for (cur = 0; cur < ct; cur++) {
    			fp = rec->rec_livetv_chain->chain_files[cur];
			if (offset < (long long)fp->file_length)
				break;
			offset -= fp->file_length;
		}
	}

	if (whence == SEEK_CUR) {

	if (offset == 0) {
		cur     = rec->rec_livetv_chain->chain_current;
		offset += rec->rec_livetv_chain->chain_files[cur]->file_req;
		for (; cur > 0; cur--) {
			offset += rec->rec_livetv_chain->chain_files[cur-1]->file_length;
		}
		return offset;
	}
  else
  {
    cur = rec->rec_livetv_chain->chain_current;
		fp  = rec->rec_livetv_chain->chain_files[cur];
  }

	offset += fp->file_req;

	while (offset > (long long)fp->file_length) {
		cur++;
		offset -= fp->file_length;
		if(cur == ct)
			return -1;
		fp = rec->rec_livetv_chain->chain_files[cur];
	}

	while (offset < 0) {
		cur--;
		if(cur < 0)
			return -1;
		fp = rec->rec_livetv_chain->chain_files[cur];
		offset += fp->file_length;
	}

	offset -= fp->file_req;
  }

	pthread_mutex_lock(&mutex);

	ret = cmyth_file_seek_unlocked(fp, offset, whence);

	PRINTF("** SSDEBUG: new pos %lld after seek command\n", ret);

	cur -= rec->rec_livetv_chain->chain_current;
	if (ret >= 0 && cur) {
		cmyth_livetv_chain_switch(rec, cur);
	}

	pthread_mutex_unlock(&mutex);

	return ret;
}
Esempio n. 3
0
void printInt16(char* ptr) {
	PRINTF("%d", *((uint16_t*)ptr));
}
Esempio n. 4
0
/*---------------------------------------------------------------------------*/
static void
update_rtmetric(struct collect_conn *tc)
{
  struct neighbor *n;

  /* We should only update the rtmetric if we are not the sink. */
  if(tc->rtmetric != SINK) {

    /* Find the neighbor with the lowest rtmetric. */
    n = neighbor_best();

    /* If n is NULL, we have no best neighbor. */
    if(n == NULL) {

      /* If we have don't have any neighbors, we set our rtmetric to
	 the maximum value to indicate that we do not have a route. */
      
      if(tc->rtmetric != RTMETRIC_MAX) {
	PRINTF("%d.%d: didn't find a best neighbor, setting rtmetric to max\n",
	       rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
      }
      tc->rtmetric = RTMETRIC_MAX;
      announcement_set_value(&tc->announcement, tc->rtmetric);
    } else {

      /* We set our rtmetric to the rtmetric of our best neighbor plus
	 the expected transmissions to reach that neighbor. */
      if(n->rtmetric + neighbor_etx(n) != tc->rtmetric) {
	uint16_t old_rtmetric = tc->rtmetric;
	
	tc->rtmetric = n->rtmetric + neighbor_etx(n);

#if !COLLECT_ANNOUNCEMENTS
	neighbor_discovery_start(&tc->neighbor_discovery_conn, tc->rtmetric);
#else
	announcement_set_value(&tc->announcement, tc->rtmetric);
#endif /* !COLLECT_ANNOUNCEMENTS */

	PRINTF("%d.%d: new rtmetric %d\n",
	       rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	       tc->rtmetric);
	
	/* We got a new, working, route we send any queued packets we may have. */
	if(old_rtmetric == RTMETRIC_MAX) {
	  send_queued_packet();
	}
      }
    }
  }

  /*  DEBUG_PRINTF("%d: new rtmetric %d\n", node_id, rtmetric);*/
#if CONTIKI_TARGET_NETSIM
  {
    char buf[8];
    if(tc->rtmetric == RTMETRIC_MAX) {
      strcpy(buf, " ");
    } else {
      sprintf(buf, "%.1f", (float)tc->rtmetric / NEIGHBOR_ETX_SCALE);
    }
    ether_set_text(buf);
  }
#endif
}
Esempio n. 5
0
void configure_request(xcb_generic_event_t *evt)
{
	xcb_configure_request_event_t *e = (xcb_configure_request_event_t *) evt;

	PRINTF("configure request %X\n", e->window);

	coordinates_t loc;
	bool is_managed = locate_window(e->window, &loc);
	client_t *c = (is_managed ? loc.node->client : NULL);
	int w = 0, h = 0;

	if (is_managed && !is_floating(c)) {
		if (e->value_mask & XCB_CONFIG_WINDOW_X)
			c->floating_rectangle.x = e->x;
		if (e->value_mask & XCB_CONFIG_WINDOW_Y)
			c->floating_rectangle.y = e->y;
		if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH)
			w = e->width;
		if (e->value_mask & XCB_CONFIG_WINDOW_HEIGHT)
			h = e->height;

		if (w != 0) {
			restrain_floating_width(c, &w);
			c->floating_rectangle.width = w;
		}

		if (h != 0) {
			restrain_floating_height(c, &h);
			c->floating_rectangle.height = h;
		}

		xcb_configure_notify_event_t evt;
		xcb_rectangle_t rect;
		xcb_window_t win = c->window;
		unsigned int bw = c->border_width;

		if (c->fullscreen)
			rect = loc.monitor->rectangle;
		else
			rect = c->tiled_rectangle;

		evt.response_type = XCB_CONFIGURE_NOTIFY;
		evt.event = win;
		evt.window = win;
		evt.above_sibling = XCB_NONE;
		evt.x = rect.x;
		evt.y = rect.y;
		evt.width = rect.width;
		evt.height = rect.height;
		evt.border_width = bw;
		evt.override_redirect = false;

		xcb_send_event(dpy, false, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (const char *) &evt);

		if (c->pseudo_tiled)
			arrange(loc.monitor, loc.desktop);
	} else {
		uint16_t mask = 0;
		uint32_t values[7];
		unsigned short i = 0;

		if (e->value_mask & XCB_CONFIG_WINDOW_X) {
			mask |= XCB_CONFIG_WINDOW_X;
			values[i++] = e->x;
			if (is_managed)
				c->floating_rectangle.x = e->x;
		}

		if (e->value_mask & XCB_CONFIG_WINDOW_Y) {
			mask |= XCB_CONFIG_WINDOW_Y;
			values[i++] = e->y;
			if (is_managed)
				c->floating_rectangle.y = e->y;
		}

		if (e->value_mask & XCB_CONFIG_WINDOW_WIDTH) {
			mask |= XCB_CONFIG_WINDOW_WIDTH;
			w = e->width;
			if (is_managed) {
				restrain_floating_width(c, &w);
				c->floating_rectangle.width = w;
			}
			values[i++] = w;
		}

		if (e->value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
			mask |= XCB_CONFIG_WINDOW_HEIGHT;
			h = e->height;
			if (is_managed) {
				restrain_floating_height(c, &h);
				c->floating_rectangle.height = h;
			}
			values[i++] = h;
		}

		if (!is_managed && e->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) {
			mask |= XCB_CONFIG_WINDOW_BORDER_WIDTH;
			values[i++] = e->border_width;
		}

		if (e->value_mask & XCB_CONFIG_WINDOW_SIBLING) {
			mask |= XCB_CONFIG_WINDOW_SIBLING;
			values[i++] = e->sibling;
		}

		if (e->value_mask & XCB_CONFIG_WINDOW_STACK_MODE) {
			mask |= XCB_CONFIG_WINDOW_STACK_MODE;
			values[i++] = e->stack_mode;
		}

		xcb_configure_window(dpy, e->window, mask, values);
	}

	if (is_managed)
		translate_client(monitor_from_client(c), loc.monitor, c);
}
Esempio n. 6
0
/*---------------------------------------------------------------------------*/
static void
handle_data(struct rudolph1mh_conn *c, struct rudolph1mh_datapacket *p)
{
  //Only called if partner is correct of NULL
  PRINTF("Handle P: %d:%d - %d\n",
         c->partner.u8[0], c->partner.u8[1], p->h.chunk);
  if(p->h.chunk == 0) { //New stream
    PRINTF("%d.%d: rudolph1mh new v_id %d, chunk %d\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
        p->h.s_id, p->h.chunk);
    c->s_id = p->h.s_id;
    c->highest_chunk = c->chunk = 0;
    if(p->h.chunk != 0) {
      send_nack(c);
    }
    else {
       if(!c->cb->write_chunk){
         printf("No write-callback\n");
         return;
       }
      c->cb->write_chunk(c, 0, RUDOLPH1MH_FLAG_NEWFILE, p->data, 0);
      write_data(c, 0, p->data, p->datalen);
      c->chunk = 1; /* Next chunk is 1. */
      //ctimer_set(&c->t, send_interval * 30, send_next_packet, c);
    }
    /*    }*/
  }
  else if(p->h.s_id == c->s_id) {

    PRINTF("%d.%d: got chunk %d (%d) highest heard %d\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
        p->h.chunk, c->chunk, c->highest_chunk);

    if(p->h.chunk == c->chunk) {
      PRINTF("%d.%d: received chunk %d\n",
          rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
          p->h.chunk);
      write_data(c, p->h.chunk, p->data, p->datalen);
      if(c->highest_chunk < c->chunk) {
        c->highest_chunk = c->chunk;
      }
      c->chunk++;
    }
    else if(p->h.chunk > c->chunk) {
      PRINTF("%d.%d: received chunk %d > %d, sending NACK\n",
          rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
          p->h.chunk, c->chunk);
      send_nack(c);
      c->highest_chunk = p->h.chunk;
    }
    else if(p->h.chunk < c->chunk) {
      /* Ignore packets with a lower chunk number */
    }

    /* If we have heard a higher chunk number, we send a NACK so that
     we get a repair for the next packet. */

    if(c->highest_chunk > p->h.chunk) {
      send_nack(c);
    }
  }
  else { /* p->h.s_id < c->current.h.s_id */
    PRINTF("%d.%d: Recieved s_id %i expected %i\n",
              rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
              p->h.s_id, c->s_id);
    /* Ignore packets with old s_id */
  }

}
Esempio n. 7
0
/*---------------------------------------------------------------------------*/
static void
timeout_mesh(struct mesh_conn *mesh)
{
  PRINTF("%d.%d: dropped ipolite\n",
      rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
}
Esempio n. 8
0
static int app_rtsp_config_fread(RTSP_Output_Server_Handle *handle)
{
	char 			temp[512] = {0};
	int 			ret  = -1 ;
	int 	value = 0;
	char 			config_file[256] = {0};

	strcpy(config_file, RTSP_SERVER_CONFIG_INI);

	ret = app_ini_read_int(config_file, "rtsp", "used", &value);

	if(ret == -1 || value == NOTUSED) {
		PRINTF("warning ,the rtsp is not used\n");
		return -1;
	}

	handle->s_used = value;

	if(app_ini_read_int(config_file, "rtsp", "status", &value) != -1) {
		handle->config.status = value;
	}

	if(app_ini_read_int(config_file, "rtsp", "type", &value) != -1) {
		if(value == TYPE_RTSP) {
			handle->config.type = value;
		} else {
			handle->config.type = TYPE_RTSP;
		}
	}

	if(app_ini_read_string(config_file, "rtsp", "main_ip", temp, sizeof(temp)) != -1) {
		strcpy(handle->config.main_ip, temp);
	}

	if(app_ini_read_int(config_file, "rtsp", "video_port", &value) != -1) {
		handle->config.video_port = value;
	}

	if(app_ini_read_int(config_file, "rtsp", "audio_port", &value) != -1) {
		handle->config.audio_port = value;
	}

	if(app_ini_read_int(config_file, "rtsp", "mtu", &value) != -1) {
		if(value > 228 || value < 1500) {
			handle->config.mtu = value;
		} else {
			handle->config.mtu = 1500;
		}
	}

	if(app_ini_read_int(config_file, "rtsp", "ttl", &value) != -1) {
		handle->config.ttl = value;
	}

	if(app_ini_read_int(config_file, "rtsp", "tos", &value) != -1) {
		handle->config.tos = value;
	}

	//	if(app_ini_read_int(config_file, "rtsp", "active", &value) != -1) {
	//		handle->config.active = value;
	//	}

	if(app_ini_read_int(config_file, "rtsp", "tc", &value) != -1) {
		handle->config.tc_flag = value;
	}

	if(app_ini_read_int(config_file, "rtsp", "tc_rate", &value) != -1) {
		handle->config.tc_rate = value;
	}

	//check config

	//set config


	return 0;
}
Esempio n. 9
0
/*---------------------------------------------------------------------------*/
static int
send_packet(void)
{
  rtimer_clock_t t0;
  rtimer_clock_t t;
  rtimer_clock_t encounter_time = 0;
  int strobes;
  int ret;
#if 0
  struct xmac_hdr *hdr;
#endif
  uint8_t got_strobe_ack = 0;
  uint8_t got_ack = 0;
  uint8_t strobe[MAX_STROBE_SIZE];
  int strobe_len, len;
  int is_broadcast = 0;
/*int is_reliable; */
  struct encounter *e;
  struct queuebuf *packet;
  int is_already_streaming = 0;
  uint8_t collisions;

  /* Create the X-MAC header for the data packet. */
  packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
  if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
    is_broadcast = 1;
    PRINTDEBUG("xmac: send broadcast\n");
  } else {
#if UIP_CONF_IPV6
    PRINTDEBUG("xmac: send unicast to %02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[2],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[3],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[4],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[5],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[6],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[7]);
#else
    PRINTDEBUG("xmac: send unicast to %u.%u\n",
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
           packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
#endif /* UIP_CONF_IPV6 */
  }
/*  is_reliable = packetbuf_attr(PACKETBUF_ATTR_RELIABLE) ||
    packetbuf_attr(PACKETBUF_ATTR_ERELIABLE); */

  packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);
  len = NETSTACK_FRAMER.create();
  strobe_len = len + sizeof(struct xmac_hdr);
  if(len < 0 || strobe_len > (int)sizeof(strobe)) {
    /* Failed to send */
   PRINTF("xmac: send failed, too large header\n");
    return MAC_TX_ERR_FATAL;
  }
  memcpy(strobe, packetbuf_hdrptr(), len);
  strobe[len] = DISPATCH; /* dispatch */
  strobe[len + 1] = TYPE_STROBE; /* type */

  packetbuf_compact();
  packet = queuebuf_new_from_packetbuf();
  if(packet == NULL) {
    /* No buffer available */
    PRINTF("xmac: send failed, no queue buffer available (of %u)\n",
           QUEUEBUF_CONF_NUM);
    return MAC_TX_ERR;
  }

#if WITH_STREAMING
  if(is_streaming == 1 &&
     (rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
		   &is_streaming_to) ||
      rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
		   &is_streaming_to_too))) {
    is_already_streaming = 1;
  }
  if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
     PACKETBUF_ATTR_PACKET_TYPE_STREAM) {
    is_streaming = 1;
    if(rimeaddr_cmp(&is_streaming_to, &rimeaddr_null)) {
      rimeaddr_copy(&is_streaming_to, packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
    } else if(!rimeaddr_cmp(&is_streaming_to, packetbuf_addr(PACKETBUF_ADDR_RECEIVER))) {
      rimeaddr_copy(&is_streaming_to_too, packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
    }
    stream_until = RTIMER_NOW() + DEFAULT_STREAM_TIME;
  }
#endif /* WITH_STREAMING */

  off();

#if WITH_ENCOUNTER_OPTIMIZATION
  /* We go through the list of encounters to find if we have recorded
     an encounter with this particular neighbor. If so, we can compute
     the time for the next expected encounter and setup a ctimer to
     switch on the radio just before the encounter. */
  for(e = list_head(encounter_list); e != NULL; e = list_item_next(e)) {
    const rimeaddr_t *neighbor = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);

    if(rimeaddr_cmp(neighbor, &e->neighbor)) {
      rtimer_clock_t wait, now, expected;

      /* We expect encounters to happen every DEFAULT_PERIOD time
	 units. The next expected encounter is at time e->time +
	 DEFAULT_PERIOD. To compute a relative offset, we subtract
	 with clock_time(). Because we are only interested in turning
	 on the radio within the DEFAULT_PERIOD period, we compute the
	 waiting time with modulo DEFAULT_PERIOD. */

      now = RTIMER_NOW();
      wait = ((rtimer_clock_t)(e->time - now)) % (DEFAULT_PERIOD);
      if(wait < 2 * DEFAULT_ON_TIME) {
        wait = DEFAULT_PERIOD;
      }
      expected = now + wait - 2 * DEFAULT_ON_TIME;

#if WITH_ACK_OPTIMIZATION
      /* Wait until the receiver is expected to be awake */
      if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) !=
	 PACKETBUF_ATTR_PACKET_TYPE_ACK &&
	 is_streaming == 0) {
	/* Do not wait if we are sending an ACK, because then the
	   receiver will already be awake. */
	while(RTIMER_CLOCK_LT(RTIMER_NOW(), expected));
      }
#else /* WITH_ACK_OPTIMIZATION */
      /* Wait until the receiver is expected to be awake */
      while(RTIMER_CLOCK_LT(RTIMER_NOW(), expected));
#endif /* WITH_ACK_OPTIMIZATION */
    }
  }
#endif /* WITH_ENCOUNTER_OPTIMIZATION */

  /* By setting we_are_sending to one, we ensure that the rtimer
     powercycle interrupt do not interfere with us sending the packet. */
  we_are_sending = 1;
  
  t0 = RTIMER_NOW();
  strobes = 0;

  LEDS_ON(LEDS_BLUE);

  /* Send a train of strobes until the receiver answers with an ACK. */

  /* Turn on the radio to listen for the strobe ACK. */
  //  on();
  collisions = 0;
  if(!is_already_streaming) {
    watchdog_stop();
    got_strobe_ack = 0;
    t = RTIMER_NOW();
    for(strobes = 0, collisions = 0;
	got_strobe_ack == 0 && collisions == 0 &&
	  RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + xmac_config.strobe_time);
	strobes++) {

      while(got_strobe_ack == 0 &&
	    RTIMER_CLOCK_LT(RTIMER_NOW(), t + xmac_config.strobe_wait_time)) {
#if 0
	rtimer_clock_t now = RTIMER_NOW();

	/* See if we got an ACK */
	packetbuf_clear();
	len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
	if(len > 0) {
	  packetbuf_set_datalen(len);
	  if(NETSTACK_FRAMER.parse() >= 0) {
	    hdr = packetbuf_dataptr();
	    if(hdr->dispatch == DISPATCH && hdr->type == TYPE_STROBE_ACK) {
	      if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
			      &rimeaddr_node_addr)) {
		/* We got an ACK from the receiver, so we can immediately send
		   the packet. */
		got_strobe_ack = 1;
		encounter_time = now;
	      } else {
		PRINTDEBUG("xmac: strobe ack for someone else\n");
	      }
	    } else /*if(hdr->dispatch == DISPATCH && hdr->type == TYPE_STROBE)*/ {
	      PRINTDEBUG("xmac: strobe from someone else\n");
	      collisions++;
	    }
	  } else {
	    PRINTF("xmac: send failed to parse %u\n", len);
	  }
	}
#endif /* 0 */
      }
      
      t = RTIMER_NOW();
            /* Send the strobe packet. */
      if(got_strobe_ack == 0 && collisions == 0) {

	if(is_broadcast) {
#if WITH_STROBE_BROADCAST
	  ret = NETSTACK_RADIO.send(strobe, strobe_len);
#else
	  /* restore the packet to send */
	  queuebuf_to_packetbuf(packet);
	  ret = NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
#endif
          off();
	} else {
#if 0
	  rtimer_clock_t wt;
#endif
          on();
	  ret = NETSTACK_RADIO.send(strobe, strobe_len);
#if 0
	  /* Turn off the radio for a while to let the other side
	     respond. We don't need to keep our radio on when we know
	     that the other side needs some time to produce a reply. */
	  off();
	  wt = RTIMER_NOW();
	  while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + WAIT_TIME_BEFORE_STROBE_ACK));
#endif /* 0 */
#if RDC_CONF_HARDWARE_ACK
          if(ret == RADIO_TX_OK) {
            got_strobe_ack = 1;
          } else {
            off();
          }
#else
          if(detect_ack()) {
            got_strobe_ack = 1;
          } else {
            off();
          }
#endif /* RDC_CONF_HARDWARE_ACK */

        }
      }
    }
  }

#if WITH_ACK_OPTIMIZATION
  /* If we have received the strobe ACK, and we are sending a packet
     that will need an upper layer ACK (as signified by the
     PACKETBUF_ATTR_RELIABLE packet attribute), we keep the radio on. */
  if(got_strobe_ack && (packetbuf_attr(PACKETBUF_ATTR_RELIABLE) ||
			packetbuf_attr(PACKETBUF_ATTR_ERELIABLE) ||
			packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
			PACKETBUF_ATTR_PACKET_TYPE_STREAM)) {
    on(); /* Wait for ACK packet */
    waiting_for_packet = 1;
  } else {
    off();
  }
#endif /* WITH_ACK_OPTIMIZATION */

  /* restore the packet to send */
  queuebuf_to_packetbuf(packet);
  queuebuf_free(packet);

  /* Send the data packet. */
  if((is_broadcast || got_strobe_ack || is_streaming) && collisions == 0) {
    ret = NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());

    if(!is_broadcast) {
#if RDC_CONF_HARDWARE_ACK
      if(ret == RADIO_TX_OK) {
        got_ack = 1;
      }
#else
      if(detect_ack()) {
        got_ack = 1;
      }
#endif /* RDC_CONF_HARDWARE_ACK */
    }
  }
  off();

#if WITH_ENCOUNTER_OPTIMIZATION
  if(got_strobe_ack && !is_streaming) {
    register_encounter(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), encounter_time);
  }
#endif /* WITH_ENCOUNTER_OPTIMIZATION */
  watchdog_start();

  PRINTF("xmac: send (strobes=%u,len=%u,%s), done\n", strobes,
	 packetbuf_totlen(), got_strobe_ack ? "ack" : "no ack");

#if XMAC_CONF_COMPOWER
  /* Accumulate the power consumption for the packet transmission. */
  compower_accumulate(&current_packet);

  /* Convert the accumulated power consumption for the transmitted
     packet to packet attributes so that the higher levels can keep
     track of the amount of energy spent on transmitting the
     packet. */
  compower_attrconv(&current_packet);

  /* Clear the accumulated power consumption so that it is ready for
     the next packet. */
  compower_clear(&current_packet);
#endif /* XMAC_CONF_COMPOWER */

  we_are_sending = 0;

  LEDS_OFF(LEDS_BLUE);
  if(collisions == 0) {
    if(is_broadcast == 0 && got_ack == 0) {
      return MAC_TX_NOACK;
    } else {
      return MAC_TX_OK;
    }
  } else {
    someone_is_sending++;
    return MAC_TX_COLLISION;
  }

}
Esempio n. 10
0
static int app_rtsp_global_config_fwrite(rtsp_server_config *config)
{
	if(config == NULL) {
		ERR_PRN("\n");
		return -1;
	}

	int ret = 0;
	char bak_name[512] = {0};
	char cmd[512] = {0};
	int value = 0;
	//	int used = 0;
	sprintf(bak_name, "%s.bak", RTSP_SERVER_GLOBAL_CONFIG_INI);

	value = config->s_port;
	ret = app_ini_write_int(bak_name, "rtsp_config", "s_port", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config->active;
	ret = app_ini_write_int(bak_name, "rtsp_config", "active", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}


	value = config->s_mtu;
	ret = app_ini_write_int(bak_name, "rtsp_config", "s_mtu", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config->mult_flag;
	ret = app_ini_write_int(bak_name, "rtsp_config", "mult_flag", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}


	ret = app_ini_write_string(bak_name, "rtsp_config", "mult_ip", config->mult_ip);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config->mult_port;
	ret = app_ini_write_int(bak_name, "rtsp_config", "mult_port", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	/*拷贝bak文件到ini*/
	sprintf(cmd, "cp -rf %s %s;rm -rf %s", bak_name, RTSP_SERVER_GLOBAL_CONFIG_INI, bak_name);
	system(cmd);
	PRINTF("i will run cmd:%s\n", cmd);
	return 0;

}
Esempio n. 11
0
static int app_rtsp_config_fwrite(int reset)
{
	if(g_rtsp_shandle == NULL) {
		ERR_PRN("\n");
		return -1;
	}

	//	int total = 0;
	int ret = 0;
	//int value = 0;
	//	int i = 0;
	char bak_name[512] = {0};
	//	char section[256] = {0};
	char cmd[512] = {0};
	int value = 0;
	int used = 0;
	sprintf(bak_name, "%s.bak", RTSP_SERVER_CONFIG_INI);

	stream_output_server_config config ;
	mid_mutex_lock(g_rtsp_shandle->mutex);
	config = g_rtsp_shandle->config;
	used = g_rtsp_shandle->s_used;
	mid_mutex_unlock(g_rtsp_shandle->mutex);
	/*写接口到bak文件*/

	value = config.tc_flag;
	ret = app_ini_write_int(bak_name, "rtsp", "tc", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	//	value = config.active;
	//	ret = app_ini_write_int(bak_name, "rtsp", "active", value);

	//	if(ret == -1) {
	//		ERR_PRN("\n");
	//		return -1;
	//	}

	value = config.tos;
	ret = app_ini_write_int(bak_name, "rtsp", "tos", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.ttl;
	ret = app_ini_write_int(bak_name, "rtsp", "ttl", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.mtu;
	ret = app_ini_write_int(bak_name, "rtsp", "mtu", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.audio_port;
	ret = app_ini_write_int(bak_name, "rtsp", "audio_port", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.video_port;
	ret = app_ini_write_int(bak_name, "rtsp", "video_port", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	//ip
	ret = app_ini_write_string(bak_name, "rtsp", "main_ip", config.main_ip);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.type;
	ret = app_ini_write_int(bak_name, "rtsp", "type", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.status;
	ret = app_ini_write_int(bak_name, "rtsp", "status", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = used;

	if(reset == 1) {
		value = 0;
	}

	ret = app_ini_write_int(bak_name, "rtsp", "used", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	value = config.tc_rate;
	ret = app_ini_write_int(bak_name, "rtsp", "tc_rate", value);

	if(ret == -1) {
		ERR_PRN("\n");
		return -1;
	}

	/*拷贝bak文件到ini*/
	if(ret != -1) {
		sprintf(cmd, "cp -rf %s %s;rm -rf %s", bak_name, RTSP_SERVER_CONFIG_INI, bak_name);
		system(cmd);
		PRINTF("i will run cmd:%s\n", cmd);
	}

	/*拷贝bak文件到ini*/

	return ret;
}
Esempio n. 12
0
/*==============================================================================
    Function: 	<rtsp_porting_client_add>
    Input:
    Output:
    Description:  用于rtsp线程调用,建立一个新的client
    Modify:
    Auth: 		zhangmin
    Date: 		2012.04.04
==============================================================================*/
static int rtsp_porting_client_add(char *ip, int vport, int aport, int type)
{
	if(g_rtsp_shandle == NULL) {
		PRINTF("Error\n");
		return -1;
	}

	//	int ret = -1;
	int r_num = -1;
	int free_num = -1;
	struct sockaddr_in video_addr;
	struct sockaddr_in audio_addr;
	int have_audio = 0;

	mid_mutex_lock(g_rtsp_shandle->mutex);
	r_num =  rtsp_client_find(ip, vport, aport, type, g_rtsp_shandle, &free_num);

	if(r_num >= 0) {
		PRINTF("Warnning,the client %s:%d is repeat %d client\n", ip, vport, r_num);

		if(mid_ip_is_multicast(ip) == 1) {
			g_rtsp_shandle->client[r_num].usenum ++;
			PRINTF("Debug,the %d client is multicast,the usenum=%d\n", r_num, g_rtsp_shandle->client[r_num].usenum);
			mid_mutex_unlock(g_rtsp_shandle->mutex);
			return 0;
		}
	}

	if(free_num == -1) {
		PRINTF("Warnning,there is not have free client\n");
		mid_mutex_unlock(g_rtsp_shandle->mutex);
		return -1;
	}


	memset(&video_addr, 0, sizeof(struct sockaddr_in));
	memset(&audio_addr, 0, sizeof(struct sockaddr_in));

	if(aport != 0) {
		have_audio = 1;
	}

	inet_pton(AF_INET, ip, &video_addr.sin_addr);
	video_addr.sin_port = htons(vport);
	video_addr.sin_family = AF_INET;

	if(have_audio) {
		inet_pton(AF_INET, ip, &audio_addr.sin_addr);
		audio_addr.sin_port = htons(aport);
		audio_addr.sin_family = AF_INET;
	}

	//create new client
	PRINTF("Debug,the %d client will create for the %s:%d-%d\n", free_num, ip, vport, aport);
	rtsp_client_create(&video_addr, &audio_addr, type, &(g_rtsp_shandle->client[free_num]));

	if(mid_ip_is_multicast(ip) == 1) {
		g_rtsp_shandle->client[free_num].usenum ++;
		PRINTF("Debug,the %d client is multicast,the usenum=%d\n", free_num, g_rtsp_shandle->client[free_num].usenum);
	}

	//config the client
	rtsp_client_config(&(g_rtsp_shandle->client[free_num]), &(g_rtsp_shandle->config));

	//set tc ip ,port
	mid_mutex_unlock(g_rtsp_shandle->mutex);
	return 0;
}
Esempio n. 13
0
int stream_rtsp_del_client_tc(int num)
{
	PRINTF("tc num = %d\n", num);
	tc_del_element(num);
	return 0;
}
Esempio n. 14
0
//不对状态进行操作
int app_rtsp_server_set_common_info(stream_output_server_config *in, stream_output_server_config *out)
{
	if(in == NULL || out == NULL) {
		PRINTF("Error.\n");
		return -1;
	}

	int tc_change = 0;
	int ttl_change = 0;

	if(g_rtsp_shandle == NULL) {
		PRINTF("\n");
		return -1;
	}

	mid_mutex_lock(g_rtsp_shandle->mutex);

	if(in->mtu >= 228 && in->mtu <= 1500) {
		g_rtsp_shandle->config.mtu = in->mtu;
		PRINTF("set mtu=%d\n", in->mtu);
	}

	if(in->ttl >= 1 && in->ttl <= 255) {
		g_rtsp_shandle->config.ttl = in->ttl;
		PRINTF("set ttl=%d\n", in->ttl);
		ttl_change = 2;
	}

	if(in->tos >= 0 && in->tos <= 255) {
		g_rtsp_shandle->config.tos = in->tos;
		PRINTF("set tos=%d\n", in->tos);
		ttl_change = 2;
	}

	if(in->tc_flag != g_rtsp_shandle->config.tc_flag) {
		tc_change = 1;
		g_rtsp_shandle->config.tc_flag = in->tc_flag;
		PRINTF("tc_flag change to %d\n", in->tc_flag);
	}

	if(in->tc_rate != g_rtsp_shandle->config.tc_rate) {
		tc_change = 1;
		g_rtsp_shandle->config.tc_rate = in->tc_rate;
		PRINTF("tc_rate change to %d\n", in->tc_rate);
	}

	mid_mutex_unlock(g_rtsp_shandle->mutex);

	//add code for tc by zm
	if(tc_change == 1) {
		stream_rtsp_set_all_tc();
	}

	if(ttl_change == 2) {
		stream_rtsp_set_all_config();
	}

	app_rtsp_config_fwrite(0);

	return 0;

}
Esempio n. 15
0
static void
my_closedir (void *dir)
{
  PRINTF ("my_closedir ()\n");
  free (dir);
}
Esempio n. 16
0
/*---------------------------------------------------------------------------*/
static void
input_packet(void)
{
  struct xmac_hdr *hdr;

  if(NETSTACK_FRAMER.parse() >= 0) {
    hdr = packetbuf_dataptr();

    if(hdr->dispatch != DISPATCH) {
      someone_is_sending = 0;
      if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
                                     &rimeaddr_node_addr) ||
	 rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
                      &rimeaddr_null)) {
	/* This is a regular packet that is destined to us or to the
	   broadcast address. */

	/* We have received the final packet, so we can go back to being
	   asleep. */
	off();

        /* Check for duplicate packet by comparing the sequence number
           of the incoming packet with the last few ones we saw. */
        {
          int i;
          for(i = 0; i < MAX_SEQNOS; ++i) {
            if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == received_seqnos[i].seqno &&
               rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_SENDER),
                            &received_seqnos[i].sender)) {
              /* Drop the packet. */
              return;
            }
          }
          for(i = MAX_SEQNOS - 1; i > 0; --i) {
            memcpy(&received_seqnos[i], &received_seqnos[i - 1],
                   sizeof(struct seqno));
          }
          received_seqnos[0].seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
          rimeaddr_copy(&received_seqnos[0].sender,
                        packetbuf_addr(PACKETBUF_ADDR_SENDER));
        }

#if XMAC_CONF_COMPOWER
	/* Accumulate the power consumption for the packet reception. */
	compower_accumulate(&current_packet);
	/* Convert the accumulated power consumption for the received
	   packet to packet attributes so that the higher levels can
	   keep track of the amount of energy spent on receiving the
	   packet. */
	compower_attrconv(&current_packet);

	/* Clear the accumulated power consumption so that it is ready
	   for the next packet. */
	compower_clear(&current_packet);
#endif /* XMAC_CONF_COMPOWER */

	waiting_for_packet = 0;

        PRINTDEBUG("xmac: data(%u)\n", packetbuf_datalen());
	NETSTACK_MAC.input();
        return;
      } else {
        PRINTDEBUG("xmac: data not for us\n");
      }

    } else if(hdr->type == TYPE_STROBE) {
      someone_is_sending = 2;

      if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
                      &rimeaddr_node_addr)) {
	/* This is a strobe packet for us. */

	/* If the sender address is someone else, we should
	   acknowledge the strobe and wait for the packet. By using
	   the same address as both sender and receiver, we flag the
	   message is a strobe ack. */
        waiting_for_packet = 1;
#if 0
	hdr->type = TYPE_STROBE_ACK;
	packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER,
			   packetbuf_addr(PACKETBUF_ADDR_SENDER));
	packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
	packetbuf_compact();
	if(NETSTACK_FRAMER.create() >= 0) {
	  /* We turn on the radio in anticipation of the incoming
	     packet. */
	  someone_is_sending = 1;
	  waiting_for_packet = 1;
	  on();
	  NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
	  PRINTDEBUG("xmac: send strobe ack %u\n", packetbuf_totlen());
	} else {
	  PRINTF("xmac: failed to send strobe ack\n");
	}
#endif /* 0 */
      } else if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
                             &rimeaddr_null)) {
	/* If the receiver address is null, the strobe is sent to
	   prepare for an incoming broadcast packet. If this is the
	   case, we turn on the radio and wait for the incoming
	   broadcast packet. */
	waiting_for_packet = 1;
	on();
      } else {
        PRINTDEBUG("xmac: strobe not for us\n");
      }
      
      /* We are done processing the strobe and we therefore return
	 to the caller. */
      return;
#if XMAC_CONF_ANNOUNCEMENTS
    } else if(hdr->type == TYPE_ANNOUNCEMENT) {
      packetbuf_hdrreduce(sizeof(struct xmac_hdr));
      parse_announcements(packetbuf_addr(PACKETBUF_ADDR_SENDER));
#endif /* XMAC_CONF_ANNOUNCEMENTS */
    } else if(hdr->type == TYPE_STROBE_ACK) {
      PRINTDEBUG("xmac: stray strobe ack\n");
    } else {
      PRINTF("xmac: unknown type %u (%u/%u)\n", hdr->type,
             packetbuf_datalen(), len);
    }
  } else {
    PRINTF("xmac: failed to parse (%u)\n", packetbuf_totlen());
  }
}
Esempio n. 17
0
static long int
find_file (const char *s)
{
  int level = 1;
  long int idx = 0;

  while (s[0] == '/')
    {
      if (s[1] == '\0')
	{
	  s = ".";
	  break;
	}
      ++s;
    }

  if (strcmp (s, ".") == 0)
    return 0;

  if (s[0] == '.' && s[1] == '/')
    s += 2;

  while (*s != '\0')
    {
      char *endp = strchrnul (s, '/');

      PRINTF ("looking for %.*s, level %d\n", (int) (endp - s), s, level);

      while (idx < nfiles && filesystem[idx].level >= level)
	{
	  if (filesystem[idx].level == level
	      && memcmp (s, filesystem[idx].name, endp - s) == 0
	      && filesystem[idx].name[endp - s] == '\0')
	    break;
	  ++idx;
	}

      if (idx == nfiles || filesystem[idx].level < level)
	{
	  errno = ENOENT;
	  return -1;
	}

      if (*endp == '\0')
	return idx + 1;

      if (filesystem[idx].type != DT_DIR
	  && (idx + 1 >= nfiles
	      || filesystem[idx].level >= filesystem[idx + 1].level))
	{
	  errno = ENOTDIR;
	  return -1;
	}

      ++idx;

      s = endp + 1;
      ++level;
    }

  errno = ENOENT;
  return -1;
}
Esempio n. 18
0
void process_keys(void)
{
#if CONFIG_NSK
  char ip[50]   = "";
  char mask[50] = "";
  /* netx_addr_t   addr; */
  ip4addr_t     myip = 0;
#endif

  acn_protect_t protect;
  component_t  *comp;
  int           cnt;
  int           x;
  char          cid_text[37];

#if CONFIG_SDT
  cid_t cid;
  cid_t dcid;
  sdt_member_t  *member;
#endif

  bool          WaitingForJoin = false;
  bool          WaitingForLeave = false;

  int   ch;
  bool  doexit = false;

  /* wait for ip address (in host format)*/
#if CONFIG_NSK
  while (!myip) {
    myip = ntohl(netx_getmyip(NULL));
  }
#endif

#if CONFIG_SDT
  /* make a local component */
  textToCid(cid_str1, cid);
  textToCid(dcid_str1, dcid);
  /* make our cid unique to us */
  cid[15] = (uint8_t)(myip & 0xff);
  /* create our local component */
  local_component = sdt_add_component(cid, dcid, true, accBOTH, cbAPP);

  /* fill in some required data */
  if (local_component) {
    /* local_component->callback = component_callback; */
    strcpy(local_component->uacn, myuacn);
    strcpy(local_component->fctn, myfctn);
  }
#endif
  /*  main is debug thread */
  while (!doexit) {
    ch = _getch();
    if (ch == EOF) {
      break;
    }

    if (ch) {
      if (WaitingForJoin || WaitingForLeave) {
        if (ch < '1' || ch > '9') {
          WaitingForJoin = false;
          WaitingForLeave = false;
        }
      }
    }

    switch (ch) {
      case 0:
        /* do nothing */
        break;
      case 8: _putch(8); _putch(' '); _putch(8);
        /* backspace */
        break;
      case 10: _putch(10);
        break;
      case 13: _putch(10);
        /* lf */
        break;
      case 'j': case 'J':
        PRINTF("%s","Enter component number to join: ");
        WaitingForJoin = true;
        break;
      case 'l': case 'L':
        PRINTF("%s","Enter component number to leave: ");
        WaitingForLeave = true;
        break;
#if CONFIG_SDT
      case '1': case '2': case '3':
        if (WaitingForJoin || WaitingForLeave) {
          x = ch - '0';
          protect = ACN_PORT_PROTECT();
          comp = sdt_first_component();
          cnt = 0;
          while (comp) {
            cnt++;
            if (cnt == x) {
              if (!comp->is_local) {
                if (WaitingForJoin) {
                  PRINTF("Joining %d\n",cnt);
                  sdt_join(local_component, comp);
                }
                if (WaitingForLeave) {
                  PRINTF("Leaving %d\n",cnt);
                sdt_leave(local_component, comp);

                }

              } else {
                PRINTF("Nope, %d is local!\n", cnt);
              }
            }
            comp = comp->next;
          }
          ACN_PORT_UNPROTECT(protect);
          WaitingForJoin = false;
          WaitingForLeave = false;
        } else {
          PRINTF("%s",".\n");
        }
        break;
#endif
#if CONFIG_SLP
      case 'd': case 'D':
        /*  discover */
        discover_acn(dcid_str1, discover_callback);
        break;
#endif
#if CONFIG_NSK
      case 'i': case 'I':
        /* We copy to local as ntoa can not be reused... */
        strcpy(ip, ntoa(netx_getmyip(0)));
        strcpy(mask, ntoa(netx_getmyipmask(0)));
        PRINTF("My IP: %s, mask %s\n", ip, mask);
        break;
#endif
#if CONFIG_SDT
      case 'c': case 'C':
        protect = ACN_PORT_PROTECT();
        comp = sdt_first_component();
        cnt = 0;
        while (comp) {
          cnt++;
          cidToText(comp->cid, cid_text);
          member = NULL;
          if (local_component->tx_channel) {
            member = sdt_find_member_by_component(local_component->tx_channel, comp);
          }
          PRINTF("%d, %s %s\n", cnt, cid_text, comp->is_local?"(local)":(member?"(joined)":""));
          comp = comp->next;
        }
        ACN_PORT_UNPROTECT(protect);
        break;
#endif
#if CONFIG_SLP
      case 'r': case 'R':
        discover_register(local_component);
        break;
      case 'u':case 'U':
        discover_deregister(local_component);
        break;
#endif
#if CONFIG_SDT
      case 's': case 'S':
        slp_stats();
        sdt_stats();
        break;
#endif
      case 3: case 'x': case 'X':
        /* exit test app */
        doexit = true;
        break;
      case 't': case 'T':
#if 0
        {
          rlp_txbuf_t *tx_buffer;
          uint8_t *buf_start;
          /* uint8_t *buffer; */

          netx_INADDR(&addr) = DD2NIP(193,168,1,200);
          netx_PORT(&addr) = htons(6000);

          /* IP4_ADDR(&addr.sin_addr.S_un.S_addr, 192,168,1,200); */


          /* Create packet buffer*/
          tx_buffer = rlpm_new_txbuf(DEFAULT_MTU, local_component);
          if (!tx_buffer) {
            acnlog(LOG_ERR | LOG_SDT, "sdt_tx_join : failed to get new txbuf");
           break;
          }
          buf_start = rlp_init_block(tx_buffer, NULL);
          rlp_add_pdu(tx_buffer, buf_start, 49, NULL);

          rlp_send_block(tx_buffer, local_component->tx_channel->sock, &addr);
          rlpm_release_txbuf(tx_buffer);
        }
        break;
#endif
      default:
        if (ch >= ' ' && ch <= 126) {
          _putch(ch);
        }
    }
  }

#if CONFIG_SDT
  if (local_component) {
    sdt_del_component(local_component);
  }
  if (foreign_component) {
    sdt_del_component(foreign_component);
  }
#endif
  PRINTF("%s","Shutting down...\n");
}
Esempio n. 19
0
/*---------------------------------------------------------------------------*/
static void
sent_mesh(struct mesh_conn *mesh)
{
  PRINTF("%d.%d: Sent mesh\n",
      rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
}
Esempio n. 20
0
void UserMain(void * pd) {
  int x;
  DWORD flag = 0;
  int cnt;

  InitializeStack();
  GetDHCPAddressIfNecessary();
  if (EthernetIP == 0) GetDHCPAddress();
  OSChangePrio(MAIN_PRIO);
  EnableAutoUpdate();

  #ifdef _DEBUG
    /* InitializeNetworkGDB_and_Wait(); */
    InitializeNetworkGDB();
  #endif

  /* note, this may not work in all cases.
  1) all systems might boot at the same time
  2) when they get to this point, they may not have an ip yet
  */
    /* init our acn stack */
    acn_port_protect_startup();
#if CONFIG_NSK
  srand(GetPreciseTime() + netx_getmyip(0));
  netx_init();
  netx_startup();
#endif

#if CONFIG_SLP
  slp_init();
  slp_open();
  slp_active_discovery_start();
#endif

#if CONFIG_RLP
  rlp_init();
#if CONFIG_SDT
  sdt_init(); /* indirectly calls sdtm_init(), rlp_init(), rlpm_init() */
  sdt_startup(true);
#endif

#if CONFIG_DMP
  /* dmp_startup(); */
#endif

#endif /* RLP */

  CreateTasks();

  x = OSChangePrio( DEBUG_TERM_PRIORITY );
  if (x) {
    PRINTF("%s","OUCH\n");
  }

  PRINTF("%s","Hello ACN World\n");

  ioctl( 0, IOCTL_CLR | IOCTL_RX_ECHO ); /* turn sdtin echo off */

  process_keys();

  /* shut things down - these require the threads to continue run... */
#if CONFIG_SDT
  sdt_shutdown();
#endif

#if CONFIG_SLP
  slp_close();
#endif

#if CONFIG_DMP
  /* dmp_shutdown() */
#endif

  /* shut down receive thread */
  OSFlagClear(&recv_flag, 1);
  PRINTF("%s","Waiting for task to recv to shut down..");
  cnt = 0;
  flag = 0;
  while (!flag) {
    cnt++;
    if (cnt == 80) {
      cnt = 0;
      PRINTF("%s","\n");
    }
    PRINTF("%s",".");
    flag = OSFlagState(&recv_flag);
  }

  /* shut down tick thread */
  OSFlagClear(&tick_flag, 1);
  PRINTF("%s","Waiting for task to tick to shut down..");
  cnt = 0;
  flag = 0;
  while (!flag) {
    cnt++;
    if (cnt == 80) {
      cnt = 0;
      PRINTF("%s","\n");
    }
    PRINTF("%s",".");
    flag = OSFlagState(&tick_flag);
  }

#if CONFIG_NSK
  netx_shutdown();
#endif
  acn_port_protect_shutdown();

  slp_stats();
  sdt_stats();
  PRINTF("%s","========================\n");

  PRINTF("%s","\nDone....\n");
  while (1) {
    OSTimeDly(20);
  }
}
Esempio n. 21
0
/*---------------------------------------------------------------------------*/
static void
recv_mesh(struct mesh_conn *mesh, const rimeaddr_t *from, uint8_t hops)
{
  struct rudolph1mh_conn *c = (struct rudolph1mh_conn *) ((char *) mesh
      - offsetof(struct rudolph1mh_conn, mesh));
  struct rudolph1mh_datapacket *p = packetbuf_dataptr();

  PRINTF("%d.%d: Got mesh type %d from %d.%d\n",
      rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
      p->h.type, from->u8[0], from->u8[1]);

  if(!rimeaddr_cmp(&c->partner, from)){
    if(!rimeaddr_cmp(&c->partner, &rimeaddr_null)){
      rimeaddr_t lfrom;
      PRINTF("%d.%d: Unexpected packet from %d.%d\n",
            rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
            from->u8[0], from->u8[1]);
      rimeaddr_copy(&lfrom, from);
      send_busy(c, &lfrom);
      return;
    } else {
      rimeaddr_copy(&c->partner, from);
    }
  }


  if(p->h.type == TYPE_ACK){
    if(p->h.s_id == c->s_id && p->h.chunk == c->highest_chunk){
      ctimer_stop(&c->t);
      rimeaddr_copy(&c->partner, &rimeaddr_null);
      if(c->cb->read_done){
        c->cb->read_done(c);
      }
      PRINTF("GOT ACK\n");
    } else {
      PRINTF("Unexpected ACK sid %i,%i C %i,%i\n", p->h.s_id, c->s_id, p->h.chunk, c->highest_chunk);
    }



  } else if(p->h.type == TYPE_NACK) {
    c->nacks++;
    PRINTF("%d.%d: Got NACK for %d:%d (%d:%d)\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
        p->h.s_id, p->h.chunk,
        c->s_id, c->chunk);
    if(p->h.s_id == c->s_id) {
      if(p->h.chunk < c->chunk) {
        /* Format and send a repair packet */
        PRINTF("%d.%d: sending repair for chunk %d\n",
            rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
            p->h.chunk);
        format_data(c, p->h.chunk);
        mesh_send(&c->mesh, &c->partner);
      }
    }
    else if(LT(p->h.s_id, c->s_id)) {
      format_data(c, 0);
      mesh_send(&c->mesh, &c->partner);
    }
  }
  else if(p->h.type == TYPE_DATA ) {
    /* This is a repair packet from someone else. */
    PRINTF("%d.%d: got chunk %d\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
        p->h.chunk);
    handle_data(c, p);
  } else if(p->h.type == TYPE_FIN ) {
    /* This is a repair packet from someone else. */
    PRINTF("%d.%d: got last chunk %d\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
        p->h.chunk);
    if(!rimeaddr_cmp(&c->partner, &rimeaddr_null)){
      handle_data(c, p);
    }{
      rimeaddr_copy(&c->partner, from);
    }
    send_ack(c);
    rimeaddr_copy(&c->partner, &rimeaddr_null);

  } else if(p->h.type == TYPE_BUSY){
    PRINTF("%d.%d: %d.%d is busy\n",
        rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
        from->u8[0], from->u8[1]);
    //Wait
  }
}
Esempio n. 22
0
 void init() { PRINTF("Waiting 2 seconds");}
Esempio n. 23
0
/*---------------------------------------------------------------------------*/
static void
node_packet_received(struct runicast_conn *c, const rimeaddr_t *from,
		     uint8_t seqno)
{
  struct collect_conn *tc = (struct collect_conn *)
    ((char *)c - offsetof(struct collect_conn, runicast_conn));
  int i;

  /* To protect against forwarding duplicate packets, we keep a list
     of recently forwarded packet seqnos. If the seqno of the current
     packet exists in the list, we drop the packet. */

  for(i = 0; i < NUM_RECENT_PACKETS; i++) {
    if(recent_packets[i].seqno == packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID) &&
       rimeaddr_cmp(&recent_packets[i].originator,
		    packetbuf_addr(PACKETBUF_ADDR_ESENDER))) {
      PRINTF("%d.%d: dropping duplicate packet from %d.%d with seqno %d\n",
	     rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	     recent_packets[i].originator.u8[0], recent_packets[i].originator.u8[1],
	     packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID));
      /* Drop the packet. */
      return;
    }
  }
  recent_packets[recent_packet_ptr].seqno = packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID);
  rimeaddr_copy(&recent_packets[recent_packet_ptr].originator,
		packetbuf_addr(PACKETBUF_ADDR_ESENDER));
  recent_packet_ptr = (recent_packet_ptr + 1) % NUM_RECENT_PACKETS;
  
  if(tc->rtmetric == SINK) {

    /* If we are the sink, we call the receive function. */
    
    PRINTF("%d.%d: sink received packet from %d.%d via %d.%d\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	   packetbuf_addr(PACKETBUF_ADDR_ESENDER)->u8[0],
	   packetbuf_addr(PACKETBUF_ADDR_ESENDER)->u8[1],
	   from->u8[0], from->u8[1]);

    if(tc->cb->recv != NULL) {
      tc->cb->recv(packetbuf_addr(PACKETBUF_ADDR_ESENDER),
		   packetbuf_attr(PACKETBUF_ATTR_EPACKET_ID),
		   packetbuf_attr(PACKETBUF_ATTR_HOPS));
    }
    return;
  } else if(packetbuf_attr(PACKETBUF_ATTR_TTL) > 1 &&
	    tc->rtmetric != RTMETRIC_MAX) {

    /* If we are not the sink, we forward the packet to the best
       neighbor. */
    packetbuf_set_attr(PACKETBUF_ATTR_HOPS, packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
    packetbuf_set_attr(PACKETBUF_ATTR_TTL, packetbuf_attr(PACKETBUF_ATTR_TTL) - 1);

        
    PRINTF("%d.%d: packet received from %d.%d via %d.%d, forwarding %d\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	   packetbuf_addr(PACKETBUF_ADDR_ESENDER)->u8[0],
	   packetbuf_addr(PACKETBUF_ADDR_ESENDER)->u8[1],
	   from->u8[0], from->u8[1], tc->forwarding);

    if(packetqueue_enqueue_packetbuf(&forwarding_queue, FORWARD_PACKET_LIFETIME,
				     tc)) {
      send_queued_packet();
    } else {
      PRINTF("%d.%d: packet dropped: no queue buffer available\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
    }
  }
  
  return;
}
GLOBAL Int UMF_report_vector
(
    Int n,
    const double Xx [ ],
    const double Xz [ ],
    Int prl,
    Int user,
    Int scalar
)
{
    Int n2, i ;

    if (user || prl >= 4)
    {
	PRINTF (("dense vector, n = "ID". ", n)) ;
    }

    if (user)
    {
	if (!Xx)
	{
	    PRINTF (("ERROR: vector not present\n\n")) ;
	    return (UMFPACK_ERROR_argument_missing) ;
	}
	if (n < 0)
	{
	    PRINTF (("ERROR: length of vector is < 0\n\n")) ;
	    return (UMFPACK_ERROR_n_nonpositive) ;
	}
    }

    if (user || prl >= 4)
    {
	PRINTF4 (("\n")) ;
    }

    if (prl == 4)
    {
	/* print level of 4 */
	n2 = MIN (10, n) ;
	for (i = 0 ; i < n2 ; i++)
	{
	    print_value (i, Xx, Xz, scalar) ;
	}
	if (n2 < n)
	{
	    PRINTF (("    ...\n")) ;
	    print_value (n-1, Xx, Xz, scalar) ;
	}
    }
    else if (prl > 4)
    {
	/* print level 4 or more */
	for (i = 0 ; i < n ; i++)
	{
	    print_value  (i, Xx, Xz, scalar) ;
	}
    }

    PRINTF4 (("    dense vector ")) ;
    if (user || prl >= 4)
    {
	PRINTF (("OK\n\n")) ;
    }
    return (UMFPACK_OK) ;
}
Esempio n. 25
0
PROCESS_THREAD(datetime_service_process, ev, data) {

    static struct etimer update_timer;
    static int valid_counter;

    PROCESS_BEGIN();

    timestamp = 0;
    time_valid = false;
    valid_counter = VALID_TIME;

    etimer_set(&update_timer, CLOCK_SECOND * UPDATE_INTERVALL);

    while(1) {
        PROCESS_WAIT_EVENT();

        if(ev == PROCESS_EVENT_TIMER) {
            PRINTF("Time: %d:%d:%d\t%d.%d.%d Day: %d Valid: %d\n", current_dt.hour, current_dt.minute, current_dt.second, current_dt.day, current_dt.month, current_dt.year, current_dt.weekday, time_valid);

            if(etimer_expired(&update_timer)){
                etimer_reset(&update_timer);
            }

            timestamp++; // update timestamp

            if(valid_counter < VALID_TIME) {
                valid_counter+=1;
            } else {
                time_valid = false;
            }

            current_dt.second+=1;
            if(current_dt.second > 59) {
                current_dt.second = 0;
                current_dt.minute+=1;
                if(current_dt.minute > 59) {
                    current_dt.minute = 0;
                    current_dt.hour+=1;
                    if(current_dt.hour > 23) {
                        current_dt.hour = 0;
                        current_dt.day+=1;
                        current_dt.weekday+=1;
                        if(current_dt.weekday>6) {
                            current_dt.weekday=0;
                        }
                        if( ((current_dt.month==1||current_dt.month==3||current_dt.month==5||current_dt.month==7||current_dt.month==8||current_dt.month==10||current_dt.month==12)&&current_dt.day>31) || ((current_dt.month==4||current_dt.month==6||current_dt.month==9||current_dt.month==11)&&current_dt.day>30) || (current_dt.month==2 && current_dt.day>28)) { //TODO Schaltjahre >.<
                            current_dt.day=0;
                            current_dt.month+=1;
                            if(current_dt.month>12) {
                                current_dt.month=0;
                                current_dt.year+=1;
                            }
                        }
                    }
                }
            }
        } else if(ev == dt_update_event) {
            PRINTF("Time: Got update.\n");

            current_dt = *(struct datetime*)&(((struct hxb_envelope*)data)->value.data);
            time_valid = true;
            valid_counter = 0;

            etimer_restart(&update_timer);
            free(data);
        }
    }
    PROCESS_END();
}
Esempio n. 26
0
Int KLU_sort
(
    KLU_symbolic *Symbolic,
    KLU_numeric *Numeric,
    KLU_common *Common
)
{
    Int *R, *W, *Tp, *Ti, *Lip, *Uip, *Llen, *Ulen ;
    Entry *Tx ;
    Unit **LUbx ;
    Int n, nk, nz, block, nblocks, maxblock, k1 ;
    size_t m1 ;

    if (Common == NULL)
    {
	return (FALSE) ;
    }
    Common->status = KLU_OK ;

    n = Symbolic->n ;
    R = Symbolic->R ;
    nblocks = Symbolic->nblocks ;
    maxblock = Symbolic->maxblock ;

    Lip  = Numeric->Lip ;
    Llen = Numeric->Llen ;
    Uip  = Numeric->Uip ;
    Ulen = Numeric->Ulen ;
    LUbx = (Unit **) Numeric->LUbx ;

    m1 = ((size_t) maxblock) + 1 ;

    /* allocate workspace */
    nz = MAX (Numeric->max_lnz_block, Numeric->max_unz_block) ;
    W  = KLU_malloc (maxblock, sizeof (Int), Common) ;
    Tp = KLU_malloc (m1, sizeof (Int), Common) ;
    Ti = KLU_malloc (nz, sizeof (Int), Common) ;
    Tx = KLU_malloc (nz, sizeof (Entry), Common) ;

    PRINTF (("\n======================= Start sort:\n")) ;

    if (Common->status == KLU_OK)
    {
	/* sort each block of L and U */
	for (block = 0 ; block < nblocks ; block++)
	{
	    k1 = R [block] ;
	    nk = R [block+1] - k1 ;
	    if (nk > 1)
	    {
		PRINTF (("\n-------------------block: %d nk %d\n", block, nk)) ;
		sort (nk, Lip + k1, Llen + k1, LUbx [block], Tp, Ti, Tx, W) ;
		sort (nk, Uip + k1, Ulen + k1, LUbx [block], Tp, Ti, Tx, W) ;
	    }
	}
    }

    PRINTF (("\n======================= sort done.\n")) ;

    /* free workspace */
    KLU_free (W, maxblock, sizeof (Int), Common) ;
    KLU_free (Tp, m1, sizeof (Int), Common) ;
    KLU_free (Ti, nz, sizeof (Int), Common) ;
    KLU_free (Tx, nz, sizeof (Entry), Common) ;
    return (Common->status == KLU_OK) ;
}
Esempio n. 27
0
error_t
parse_message(coap_packet_t* packet, u8_t* buf, u16_t size)
{
  u16_t processed = 0;
  u16_t i = 0;
  PRINTF("parse_message size %d-->\n",size);

  init_packet(packet);

  packet->ver = (buf[0] & COAP_HEADER_VERSION_MASK) >> COAP_HEADER_VERSION_POSITION;
  packet->type = (buf[0] & COAP_HEADER_TYPE_MASK) >> COAP_HEADER_TYPE_POSITION;
  packet->option_count = buf[0] & COAP_HEADER_OPTION_COUNT_MASK;
  packet->code = buf[1];
  packet->tid = (buf[2] << 8) + buf[3];

  processed += 4;

  if (packet->option_count) {
    u8_t option_index = 0;
    u8_t option_delta;
    u16_t option_len;
    u8_t* option_buf = buf + processed;
    packet->options = (header_option_t*)allocate_buffer(sizeof(header_option_t) * packet->option_count);

    if (!packet->options) {
      return MEMORY_ALLOC_ERR;
    }
    header_option_t* current_option = packet->options;
    header_option_t* prev_option = NULL;
    while ((option_index < packet->option_count) && (i <= (size - processed))) {
      option_delta = (option_buf[i] & COAP_HEADER_OPTION_DELTA_MASK)
          >> COAP_HEADER_OPTION_DELTA_POSITION;
      option_len = (option_buf[i] & COAP_HEADER_OPTION_SHORT_LENGTH_MASK);
      i++;
      if (option_len == 0xf) {
        option_len += option_buf[i];
        i++;
      }

      current_option->option = option_delta;
      current_option->len = option_len;
      current_option->value = option_buf + i;
      if (option_index) {
        prev_option->next = current_option;
        /*This field defines the difference between the option Type of
         * this option and the previous option (or zero for the first option)*/
        current_option->option += prev_option->option;
      }

      if (current_option->option == Option_Type_Uri_Path) {
        if (!packet->url) {
          /* Allocate space for url */
          packet->url = allocate_buffer(MAX_URI_PATH_LENGTH);
          if (!packet->url){
            return MEMORY_ALLOC_ERR;
          }
        } else {
          if (packet->url_len + 1 <= MAX_URI_PATH_LENGTH) {
            packet->url[packet->url_len++] = '/';
          } else {
            return MEMORY_ALLOC_ERR;
          }
        }
        if (packet->url_len + current_option->len <= MAX_URI_PATH_LENGTH) {
          strncpy(&packet->url[packet->url_len], (char*) current_option->value,
                  current_option->len);
          packet->url_len += current_option->len;
        } else {
          return MEMORY_ALLOC_ERR;
        }
      } else if (current_option->option == Option_Type_Uri_Query) {
        packet->query = (char*) current_option->value;
        packet->query_len = current_option->len;
      }

      i += option_len;
      option_index++;
      prev_option = current_option;
      if (option_index < packet->option_count) {
        /* There are still options to parse */
        current_option++;
      }
    }
    if (i > (size - processed)) {
      /* Out of bounds. Bad request? */
      return BAD_REQUEST_ERR;
    }
    current_option->next = NULL;
  }
Esempio n. 28
0
void mid_task_init(void)
{
	PRINTF("mid_task_init \n");
	return ;
}
Esempio n. 29
0
void printInt32(char* ptr) {
	PRINTF("%d", *((uint32_t*)ptr));
}
Esempio n. 30
0
static void rtsp_ginfo_print(rtsp_server_config *config)
{
	PRINTF("rtsp_ginfo_print: config= %p\n", config);
	PRINTF("s_port=%d,active=%d,s_mtu=%d,mult_flag=%d,ip=%s:%d\n", config->s_port, config->active, config->s_mtu, config->mult_flag, config->mult_ip, config->mult_port);
}