Esempio n. 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);
    }
}
Esempio n. 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);
	}
}
Esempio n. 3
0
void
nRFCMD_RegisterDump (void)
{
  uint8_t t, size, reg, buf[32];

  reg = 0;
  debug_printf ("\nnRFCMD_RegisterDump:\n");
  while (((size = nRFCMD_GetRegSize (reg)) > 0) && (reg < 0xFF))
    {
      nRFCMD_RegReadBuf (reg, buf, size);

      debug_printf ("\treg[0x%02X]:", reg);
      for (t = 0; t < size; t++)
	debug_printf (" 0x%02X", buf[t]);
      debug_printf ("\n");

      reg++;
    }
  debug_printf ("\n");
}
Esempio n. 4
0
File: nRF_API.c Progetto: CMon/dld
unsigned char nRFAPI_RX(unsigned char *buf,unsigned char count)
{
    unsigned char size,pipe;

    pipe=nRFAPI_GetPipeCurrent();
    if(pipe>=7)
        size=0;
    else
    {
        size=nRFAPI_GetPipeSizeRX(pipe);

        if(size<=count)
            nRFCMD_RegReadBuf(RD_RX_PLOAD,buf,size);
        else
        {
            nRFAPI_FlushRX();
            size=0;
        }
    }

    return size;
}
Esempio n. 5
0
uint8_t
nRFAPI_RX (uint8_t * buf, uint8_t count)
{
  uint8_t size, pipe;

  pipe = nRFAPI_GetPipeCurrent ();
  if (pipe >= 7)
    size = 0;
  else
    {
      size = nRFAPI_GetPipeSizeRX (pipe);

      if (size <= count)
	nRFCMD_RegReadBuf (RD_RX_PLOAD, buf, size);
      else
	{
	  nRFAPI_FlushRX ();
	  size = 0;
	}
    }

  return size;
}
Esempio n. 6
0
File: nRF_API.c Progetto: CMon/dld
void nRFAPI_GetTxMAC(unsigned char *addr,unsigned char addr_size)
{
    if(addr_size>=3 && addr_size<=5)
        nRFCMD_RegReadBuf(TX_ADDR,addr,addr_size);
}
Esempio n. 7
0
void
nRFAPI_GetTxMAC (uint8_t * addr, uint8_t addr_size)
{
  if (addr_size >= 3 && addr_size <= 5)
    nRFCMD_RegReadBuf (TX_ADDR, addr, addr_size);
}
Esempio n. 8
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 (;;)
    {
      /* 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);
    }
}