Пример #1
0
/**
 * Transmit the start message to the DV service.
 *
 * @param cls the `struct GNUNET_DV_ServiceHandle *`
 * @param size number of bytes available in buf
 * @param buf where to copy the message
 * @return number of bytes written to buf
 */
static size_t
transmit_start (void *cls,
		size_t size,
		void *buf)
{
  struct GNUNET_DV_ServiceHandle *sh = cls;
  struct GNUNET_MessageHeader start_message;

  sh->th = NULL;
  if (NULL == buf)
  {
    GNUNET_break (0);
    reconnect (sh);
    return 0;
  }
  GNUNET_assert (size >= sizeof (start_message));
  start_message.size = htons (sizeof (struct GNUNET_MessageHeader));
  start_message.type = htons (GNUNET_MESSAGE_TYPE_DV_START);
  memcpy (buf, &start_message, sizeof (start_message));
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Transmitting START request, starting receive loop for %p\n",
       sh->client);
  GNUNET_CLIENT_receive (sh->client,
			 &handle_message_receipt, sh,
                         GNUNET_TIME_UNIT_FOREVER_REL);
  start_transmit (sh);
  return sizeof (start_message);
}
Пример #2
0
/**
 * Send a message via DV service.
 *
 * @param sh service handle
 * @param target intended recpient
 * @param msg message payload
 * @param cb function to invoke when done
 * @param cb_cls closure for @a cb
 * @return handle to cancel the operation
 */
struct GNUNET_DV_TransmitHandle *
GNUNET_DV_send (struct GNUNET_DV_ServiceHandle *sh,
		const struct GNUNET_PeerIdentity *target,
		const struct GNUNET_MessageHeader *msg,
		GNUNET_DV_MessageSentCallback cb,
		void *cb_cls)
{
  struct GNUNET_DV_TransmitHandle *th;
  struct GNUNET_DV_SendMessage *sm;
  struct ConnectedPeer *peer;

  if (ntohs (msg->size) + sizeof (struct GNUNET_DV_SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
  {
    GNUNET_break (0);
    return NULL;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Asked to send %u bytes of type %u to %s via %p\n",
       (unsigned int) ntohs (msg->size),
       (unsigned int) ntohs (msg->type),
       GNUNET_i2s (target),
       sh->client);
  peer = GNUNET_CONTAINER_multipeermap_get (sh->peers,
                                            target);
  if (NULL == peer)
  {
    GNUNET_break (0);
    return NULL;
  }
  th = GNUNET_malloc (sizeof (struct GNUNET_DV_TransmitHandle) +
		      sizeof (struct GNUNET_DV_SendMessage) +
		      ntohs (msg->size));
  th->sh = sh;
  th->target = peer;
  th->cb = cb;
  th->cb_cls = cb_cls;
  th->msg = (const struct GNUNET_MessageHeader *) &th[1];
  sm = (struct GNUNET_DV_SendMessage *) &th[1];
  sm->header.type = htons (GNUNET_MESSAGE_TYPE_DV_SEND);
  sm->header.size = htons (sizeof (struct GNUNET_DV_SendMessage) +
			   ntohs (msg->size));
  if (0 == sh->uid_gen)
    sh->uid_gen = 1;
  th->uid = sh->uid_gen;
  sm->uid = htonl (sh->uid_gen++);
  /* use memcpy here as 'target' may not be sufficiently aligned */
  memcpy (&sm->target, target, sizeof (struct GNUNET_PeerIdentity));
  memcpy (&sm[1], msg, ntohs (msg->size));
  GNUNET_CONTAINER_DLL_insert_tail (sh->th_head,
                                    sh->th_tail,
                                    th);
  start_transmit (sh);
  return th;
}
Пример #3
0
void rt_task4_thread_entry(void* parameter)
{
	extern void start_transmit(void);
 	extern void stop_transmit(void);
	extern uint8_t check_parameter(void);
//	extern uint8_t self_check(void);
//	extern void cpu_usage_init();
	rt_uint32_t ev;
	
	if((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0))
	{
		coil.usRegCoilBuf |= M(0);
	}
	else
	{
		coil.usRegCoilBuf &= ~M(0);
	}
	
	rt_event_init(&key_event, "key_event", RT_IPC_FLAG_FIFO );
	
	while(1)
	{
		if( rt_event_recv( &key_event, FOOT_PUPD | KEY_PUPD, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &ev ) == RT_EOK ) 
		{
			
				rt_thread_delay(6);
				if( (ev & FOOT_PUPD) && (coil.usRegCoilBuf & M(0)) &&(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0)&& \
					(check_parameter()) && (coil.usRegCoilBuf & M(7)))
				{
					start_transmit();
				}
				else
				{
					stop_transmit();
				}
				
				if(ev & KEY_PUPD)
				{
					if((GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3) == 0))
					{
						coil.usRegCoilBuf |= M(0);
					}
					else
					{
						coil.usRegCoilBuf &= ~M(0);
					}
				}
		}
		rt_event_recv( &key_event, FOOT_PUPD | KEY_PUPD, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, 2, &ev );
		
		rt_thread_delay(20);
	}
}
Пример #4
0
/**
 * Gives a message from our queue to the DV service.
 *
 * @param cls handle to the dv service (`struct GNUNET_DV_ServiceHandle`)
 * @param size how many bytes can we send
 * @param buf where to copy the message to send
 * @return how many bytes we copied to @a buf
 */
static size_t
transmit_pending (void *cls, size_t size, void *buf)
{
  struct GNUNET_DV_ServiceHandle *sh = cls;
  char *cbuf = buf;
  struct GNUNET_DV_TransmitHandle *th;
  size_t ret;
  size_t tsize;

  sh->th = NULL;
  if (NULL == buf)
  {
    reconnect (sh);
    return 0;
  }
  ret = 0;
  while ( (NULL != (th = sh->th_head)) &&
	  (size - ret >= (tsize = ntohs (th->msg->size)) ))
  {
    GNUNET_CONTAINER_DLL_remove (sh->th_head,
				 sh->th_tail,
				 th);
    memcpy (&cbuf[ret], th->msg, tsize);
    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Passing %u bytes of type %u to DV service\n",
         tsize,
         ntohs (th->msg->type));
    th->msg = NULL;
    ret += tsize;
    if (NULL != th->cb)
    {
      GNUNET_CONTAINER_DLL_insert_tail (th->target->head,
                                        th->target->tail,
                                        th);
    }
    else
    {
      GNUNET_free (th);
    }
  }
  if (NULL != sh->th_head)
    start_transmit (sh);
  return ret;
}