예제 #1
0
static void
vnRFtaskRxTx (void *parameter)
{
    u_int32_t crc; //, t;
    u_int8_t status;
//  portTickType last_ticks = 0, jam_ticks = 0;

    if (!PtInitNRF ())
        return;

    for (;;)
    {
        status = nRFAPI_GetFifoStatus ();

        /* check for received packets */
        if ((status & FIFO_RX_FULL) || nRFCMD_WaitRx (0))
        {
            vLedSetGreen (0);

            do
            {
                /* read packet from nRF chip */
                nRFCMD_RegReadBuf (RD_RX_PLOAD, (unsigned char *) &rfpkg,
                                   sizeof (rfpkg));

                /* adjust byte order and decode */
                shuffle_tx_byteorder ((unsigned long *) &rfpkg,
                                      sizeof (rfpkg) / sizeof (long));
                xxtea_decode ((long *) &rfpkg, sizeof (rfpkg) / sizeof (long));
                shuffle_tx_byteorder ((unsigned long *) &rfpkg,
                                      sizeof (rfpkg) / sizeof (long));

                /* verify the crc checksum */
                crc =
                    crc32 ((unsigned char *) &rfpkg,
                           sizeof (rfpkg) - sizeof (rfpkg.crc));
                if ((crc == PtSwapLong (rfpkg.crc)) &&
                        (rfpkg.wmcu_id == env.e.mcu_id) &&
                        (rfpkg.cmd & RF_PKG_SENT_BY_DIMMER))
                {
                    // Sende Daten an die Zwischenschicht, um zu sehen ob was empfangen wird
                    memset(packet,0,100);
                    sprintf((portCHAR*)(packet+sizeof(struct packet_header) + 3), "Hallo ich höre!");
                    u_int8_t  length = strlen( (portCHAR*)(packet+sizeof(struct packet_header) + 3) ) + 3 + 1;
                    usb_send_buffer_zero_copy(packet, length+sizeof(struct packet_header),  NULL, NULL, portMAX_DELAY);

                    rf_rec++;
                }
            }
            while ((nRFAPI_GetFifoStatus () & FIFO_RX_EMPTY) == 0);

            vLedSetGreen (1);
        }

        vTaskDelay (5 / portTICK_RATE_MS);

        /* did I already mention the paranoid world thing? */
        nRFAPI_ClearIRQ (MASK_IRQ_FLAGS);
    }
}
예제 #2
0
static void
authentication_task (void *parameter)
{
	TBouncerEnvelope Bouncer;
	(void) parameter;
	memset (&authentication_state, 0, sizeof (authentication_state));
	authentication_state.state = AUTHENTICATION_IDLE;
	
	
	while(1) {
		if (nRFCMD_WaitRx (10)) {
			
			do {
				vLedSetRed (1);
				// read packet from nRF chip
				nRFCMD_RegReadBuf (RD_RX_PLOAD, (unsigned char *) &Bouncer, sizeof (Bouncer));
				
				process_message(&Bouncer);
				
				vLedSetRed (0);
			} while ((nRFAPI_GetFifoStatus () & FIFO_RX_EMPTY) == 0);
			
			nRFAPI_GetFifoStatus();
		}
		nRFAPI_ClearIRQ (MASK_IRQ_FLAGS);
	}
}
예제 #3
0
static void
vnRFtaskRxTx (void *parameter)
{
  u_int32_t t;
  u_int8_t status;
  portTickType last_ticks = 0, jam_ticks = 0;

  if (!PtInitNRF ())
    return;

  for (;;)
    {
//	sprintf(msg, "Senden ...\n");
      /* check if TX strength changed */
      if (nrf_powerlevel_current != nrf_powerlevel_last)
	{
	  nRFAPI_SetTxPower (nrf_powerlevel_current);
	  nrf_powerlevel_last = nrf_powerlevel_current;
	}

      status = nRFAPI_GetFifoStatus ();
      /* living in a paranoid world ;-) */
      if (status & FIFO_TX_FULL)
	nRFAPI_FlushTX ();

      /* transmit current lamp value */  // schickt regelmässig ein Packet broadcast
      if (env.e.mcu_id && ((xTaskGetTickCount () - last_ticks) > jam_ticks))
	{
	  memset (&rfpkg, 0, sizeof (rfpkg));
	  rfpkg.cmd = RF_CMD_SET_VALUES;
	  rfpkg.wmcu_id = env.e.mcu_id;
	  rfpkg.mac = 0xffff;	/* send to all MACs */

	  for (t = 0; t < RF_PAYLOAD_SIZE; t++)
	    rfpkg.payload[t] =
	      (last_lamp_val[t * 2] & 0xf) |
	      (last_lamp_val[(t * 2) + 1] << 4);

	  // random delay to avoid collisions
	  PtInternalTransmit (&rfpkg);

	  // prepare next jam transmission
	  last_ticks = xTaskGetTickCount ();
	  jam_ticks =
	    (RndNumber () % (jam_density_ms * 2)) / portTICK_RATE_MS;
	}

      vTaskDelay (5 / portTICK_RATE_MS);

      /* did I already mention the paranoid world thing? */
      nRFAPI_ClearIRQ (MASK_IRQ_FLAGS);
    }
}
예제 #4
0
파일: proto.c 프로젝트: bomma/openbeacon
static void
vnRFtaskRxTx (void *parameter)
{
  u_int32_t crc, t;
  u_int8_t status;
  portTickType last_ticks = 0, jam_ticks = 0;

  if (!PtInitNRF ())
    return;

  for (;;)
    {
      /* check if TX strength changed */
      if (nrf_powerlevel_current != nrf_powerlevel_last)
	{
	  nRFAPI_SetTxPower (nrf_powerlevel_current);
	  nrf_powerlevel_last = nrf_powerlevel_current;
	}

      status = nRFAPI_GetFifoStatus ();
      /* living in a paranoid world ;-) */
      if (status & FIFO_TX_FULL)
	nRFAPI_FlushTX ();

      /* check for received packets */
      if ((status & FIFO_RX_FULL) || nRFCMD_WaitRx (0))
	{
	  vLedSetGreen (0);

	  do
	    {
	      /* read packet from nRF chip */
	      nRFCMD_RegReadBuf (RD_RX_PLOAD, (unsigned char *) &rfpkg,
				 sizeof (rfpkg));

	      /* adjust byte order and decode */
	      shuffle_tx_byteorder ((unsigned long *) &rfpkg,
				    sizeof (rfpkg) / sizeof (long));
	      xxtea_decode ((long *) &rfpkg, sizeof (rfpkg) / sizeof (long));
	      shuffle_tx_byteorder ((unsigned long *) &rfpkg,
				    sizeof (rfpkg) / sizeof (long));

	      /* verify the crc checksum */
	      crc =
		crc32 ((unsigned char *) &rfpkg,
		       sizeof (rfpkg) - sizeof (rfpkg.crc));
	      if ((crc == PtSwapLong (rfpkg.crc)) &&
		  (rfpkg.wmcu_id == env.e.mcu_id) &&
		  (rfpkg.cmd & RF_PKG_SENT_BY_DIMMER))
		{
		  //debug_printf("dumping received packet:\n");
		  //hex_dump((unsigned char *) &rfpkg, 0, sizeof(rfpkg));
		  b_parse_rfrx_pkg (&rfpkg);
		  rf_rec++;
		}
	    }
	  while ((nRFAPI_GetFifoStatus () & FIFO_RX_EMPTY) == 0);

	  vLedSetGreen (1);
	}

      /* transmit current lamp value */
      if (env.e.mcu_id && ((xTaskGetTickCount () - last_ticks) > jam_ticks))
	{
	  memset (&rfpkg, 0, sizeof (rfpkg));
	  rfpkg.cmd = RF_CMD_SET_VALUES;
	  rfpkg.wmcu_id = env.e.mcu_id;
	  rfpkg.mac = 0xffff;	/* send to all MACs */

	  for (t = 0; t < RF_PAYLOAD_SIZE; t++)
	    rfpkg.payload[t] =
	      (last_lamp_val[t * 2] & 0xf) |
	      (last_lamp_val[(t * 2) + 1] << 4);

	  // random delay to avoid collisions
	  PtInternalTransmit (&rfpkg);

	  // prepare next jam transmission
	  last_ticks = xTaskGetTickCount ();
	  jam_ticks =
	    (RndNumber () % (jam_density_ms * 2)) / portTICK_RATE_MS;
	}

      vTaskDelay (5 / portTICK_RATE_MS);

      /* did I already mention the paranoid world thing? */
      nRFAPI_ClearIRQ (MASK_IRQ_FLAGS);
    }
}