예제 #1
0
파일: simpleio.c 프로젝트: antdvid/FronTier
EXPORT	size_t	read_binary_real_array(
	double         *a,
	size_t        len,
	const IO_TYPE *io_type)
{
	size_t nread = 0;
	FILE *file = io_type->file;
	size_t  i;

	if (io_type->read_float_size == io_type->cpu_float_size)
	{
	    nread = fread((void *) a,sizeof(double),len,file);
	    if (io_type->reverse_endian)
	        for (i = 0; i < nread; ++i)
		    byte_reverse(a[i]);
	}
	else if (io_type->read_float_size > io_type->cpu_float_size)
	{
	    double tmp;
	    for (i = 0; i < len; ++i)
	    {
	    	if (fread((void *) &tmp,sizeof(double),1,file))
		{
		    ++nread;
		    if (io_type->reverse_endian)
		        byte_reverse(tmp);
	    	    a[i] = tmp;
	        }
	    }
	}
	else
	{
	    TRUEfloat tmp;
	    for (i = 0; i < len; ++i)
	    {
	    	if (fread((void *) &tmp,sizeof(TRUEfloat),1,file))
		{
		    ++nread;
		    if (io_type->reverse_endian)
		        byte_reverse(tmp);
	    	    a[i] = tmp;
	        }
	    }
	}
	return nread;
}		/*end read_binary_real_array*/
예제 #2
0
void LCD_wr_data(unsigned char datas)
{
	LCDCS;
	CLR_WR;
	SET_LCD_A0;;          //write display datas
	PORTA = byte_reverse(datas);
	SET_WR;
	CLR_LCD_A0;
	NONECS;
}
예제 #3
0
//volatile unsigned char temp;
void LCD_wr_command(unsigned char command)
{
	LCDCS;
	CLR_LCD_A0;          //write command
	CLR_WR;
	PORTA = byte_reverse(command);
	SET_WR;
	SET_LCD_A0;
	NONECS;
}
예제 #4
0
파일: simpleio.c 프로젝트: antdvid/FronTier
EXPORT	size_t	read_binary_uint64_t_array(
	uint64_t      *a,
	size_t        len,
	const IO_TYPE *io_type)
{
	FILE   *file = io_type->file;
	size_t i;
	size_t nread = 0;

	nread = fread((void *) a,sizeof(uint64_t),len,file);
	if (io_type->reverse_endian)
	    for (i = 0; i < nread; ++i)
		byte_reverse(a[i]);
	return nread;
}		/*end read_binary_uint_array*/
예제 #5
0
///read 1 byte data from LCD
unsigned char LCD_rd_data(void)
{
	unsigned char temp;
	
	SET_WR;
	DDRA=0;
	LCDCS;
	SET_LCD_A0;
	CLR_RD;
	temp = byte_reverse(PORTA);
	SET_RD;
	CLR_WR;
	CLR_LCD_A0;
	NONECS;
	DDRA=0xff;
	return temp;
}
예제 #6
0
/**
 * \brief      This is the implementation of the 15.4 MAC Reset Request
 *             primitive.
 * \param      setDefaultPIB True if the default PIB values should be set.
 * \return     Integer denoting success or failure.
 * \retval 0   Failure.
 * \retval 1   Success.
 *
 *             Sets all PIB values to default.
 */
void
sicslowmac_resetRequest (bool setDefaultPIB)
{
  if(setDefaultPIB){
    /* initialize all of the MAC PIB variables to their default values */
    macCoordShortAddress = 0xffff;
    macDSN = rand() % 256;
    macSrcPANId = SOURCE_PAN_ID;
    macDstPANId = DEST_PAN_ID;
    macShortAddress = 0xffff;
    /* Setup the address of this device by reading a stored address from eeprom. */
    /** \todo   This might be read from the serial eeprom onboard Raven. */
    AVR_ENTER_CRITICAL_REGION();
    eeprom_read_block ((void *)&macLongAddr, EEPROMMACADDRESS, 8);
	
	byte_reverse((uint8_t *) &macLongAddr, 8);
	
	
    AVR_LEAVE_CRITICAL_REGION();
  }
}
예제 #7
0
void CRYPTO_POLYVAL_update_blocks(struct polyval_ctx *ctx, const uint8_t *in,
                                  size_t in_len) {
  assert((in_len & 15) == 0);
  polyval_block reversed[32];

  while (in_len > 0) {
    size_t todo = in_len;
    if (todo > sizeof(reversed)) {
      todo = sizeof(reversed);
    }
    OPENSSL_memcpy(reversed, in, todo);
    in += todo;
    in_len -= todo;

    size_t blocks = todo / sizeof(polyval_block);
    for (size_t i = 0; i < blocks; i++) {
      byte_reverse(&reversed[i]);
    }

    ctx->ghash(ctx->S.u, ctx->Htable, (const uint8_t *) reversed, todo);
  }
}
예제 #8
0
/*---------------------------------------------------------------------------*/
int
sicslowmac_dataRequest(void)
{

  _delay_ms(SICSLOW_CORRECTION_DELAY);

   /* create structure to store result. */
  frame_create_params_t params;
  frame_result_t result;

  /* Save the msduHandle in a global variable. */
  msduHandle = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);

  /* Build the FCF. */
  params.fcf.frameType = DATAFRAME;
  params.fcf.securityEnabled = false;
  params.fcf.framePending = false;
  params.fcf.ackRequired = packetbuf_attr(PACKETBUF_ATTR_RELIABLE);
  params.fcf.panIdCompression = false;

  /* Insert IEEE 802.15.4 (2003) version bit. */
  params.fcf.frameVersion = IEEE802154_2003;

  /* Increment and set the data sequence number. */
  params.seq = macDSN++;

  /* Complete the addressing fields. */
  /**
     \todo For phase 1 the addresses are all long. We'll need a mechanism
     in the rime attributes to tell the mac to use long or short for phase 2.
  */
  params.fcf.srcAddrMode = LONGADDRMODE;
  params.dest_pid = ieee15_4ManagerAddress.get_dst_panid();

  /*
   *  If the output address is NULL in the Rime buf, then it is broadcast
   *  on the 802.15.4 network.
   */
  if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null) ) {
    /* Broadcast requires short address mode. */
    params.fcf.destAddrMode = SHORTADDRMODE;
    params.dest_pid = BROADCASTPANDID;
    params.dest_addr.addr16 = BROADCASTADDR;

  } else {

    /* Phase 1.5 - end nodes send to anyone? */
    memcpy(&params.dest_addr, (uint8_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER), LONG_ADDR_LEN);
	
    /* Change from sicslowpan byte arrangement to sicslowmac */
    byte_reverse((uint8_t*)&params.dest_addr.addr64, LONG_ADDR_LEN);

    /* Phase 1 - end nodes only sends to pan coordinator node. */
    /* params.dest_addr.addr64 = ieee15_4ManagerAddress.get_coord_long_addr(); */
    params.fcf.destAddrMode = LONGADDRMODE;
  }

  /* Set the source PAN ID to the global variable. */
  params.src_pid = ieee15_4ManagerAddress.get_src_panid();

  /*
   * Set up the source address using only the long address mode for
   * phase 1.
   */
  params.src_addr.addr64 = ieee15_4ManagerAddress.get_long_addr();

  /* Copy the payload data. */
  params.payload_len = packetbuf_datalen();
  params.payload =  packetbuf_dataptr();

  /* Create transmission frame. */
  frame_tx_create(&params, &result);
  
  /* Log if needed */
  LOG_FRAME(&params, &result);

  /* Retry up to this many times to send the packet if radio is busy */
  uint8_t retry_count = 3;

  while(retry_count) {

	  PRINTF("sicslowmac: sending packet of length %d to radio, result:", result.length);
	  
	    

	  /* Send data to radio. */
	  radio_status_t rv = radio_send_data(result.length, result.frame);

	  if (rv == RADIO_SUCCESS) {
	      PRINTF(" Success\n");

		  return 1; /* True says that the packet could be sent */
      }


	  if (rv != RADIO_WRONG_STATE) {
	      PRINTF(" Failed\n");
	  	  return 0;
      }

	  PRINTF(" Radio busy, retrying\n");

      /** \todo: Fix delay in sicslowmac so they do not block receiving */

       //We have blocking delay here, it is safest this way. BUT doesn't solve the
	   //problem of TX when you are RXing.. as the RX code can't execute!
	  if (retry_count == 3) {
	 	  _delay_ms(10);
	  } else if (retry_count == 2) {
	      _delay_ms(50);
	  } else if (retry_count == 1) {
	      _delay_ms(200);
	  }

	  retry_count--;
  }

  PRINTF("sicslowmac: Unable to send packet, dropped\n");
  return 0;

}
예제 #9
0
void
sicslowmac_unknownIndication(void)
{
  if (sicslowmac_snifferhook) {

	  packetbuf_clear();

	  /* Finally, get the stuff into the rime buffer.... */
	  packetbuf_copyfrom(parsed_frame->payload, parsed_frame->payload_length);
	  packetbuf_set_datalen(parsed_frame->payload_length);
	  
  #if UIP_LLADDR_LEN == 8
  	memcpy(dest_reversed, (uint8_t *)parsed_frame->dest_addr, UIP_LLADDR_LEN);
	memcpy(src_reversed, (uint8_t *)parsed_frame->src_addr, UIP_LLADDR_LEN);
  
	/* Change addresses to expected byte order */
	byte_reverse((uint8_t *)dest_reversed, UIP_LLADDR_LEN);
	byte_reverse((uint8_t *)src_reversed, UIP_LLADDR_LEN);
  
	packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
	packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);
	
  #elif UIP_CONF_USE_RUM	
	
	dest_reversed[0] = MSB(parsed_frame->dest_pid);
	dest_reversed[1] = LSB(parsed_frame->dest_pid);
	dest_reversed[2] = 0;
	dest_reversed[3] = 0;  
	dest_reversed[4] = MSB(parsed_frame->payload[0]); //FinalDestAddr
	dest_reversed[5] = LSB(parsed_frame->payload[1]);
	
	src_reversed[0] = MSB(parsed_frame->src_pid);
	src_reversed[1] = LSB(parsed_frame->src_pid);
	src_reversed[2] = 0;
	src_reversed[3] = 0;  
	src_reversed[4] = MSB(parsed_frame->payload[2]); //originAddr
	src_reversed[5] = LSB(parsed_frame->payload[3]);	

  #else
  
	dest_reversed[0] = MSB(parsed_frame->dest_pid);
	dest_reversed[1] = LSB(parsed_frame->dest_pid);
	dest_reversed[2] = 0;
	dest_reversed[3] = 0;  
	dest_reversed[4] = MSB(parsed_frame->dest_addr->addr16);
	dest_reversed[5] = LSB(parsed_frame->dest_addr->addr16);
	
	src_reversed[0] = MSB(parsed_frame->src_pid);
	src_reversed[1] = LSB(parsed_frame->src_pid);
	src_reversed[2] = 0;
	src_reversed[3] = 0;  
	src_reversed[4] = MSB(parsed_frame->src_addr->addr16);
	src_reversed[5] = LSB(parsed_frame->src_addr->addr16);

	packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, (const rimeaddr_t *)dest_reversed);
	packetbuf_set_addr(PACKETBUF_ADDR_SENDER, (const rimeaddr_t *)src_reversed);	
  
  #endif

	  PRINTF("sicslowmac: hand off frame to sniffer \n");
	  
	  sicslowmac_snifferhook(pmac_driver);
	 }
  
}
예제 #10
0
void CRYPTO_POLYVAL_finish(const struct polyval_ctx *ctx, uint8_t out[16]) {
  polyval_block S = ctx->S;
  byte_reverse(&S);
  OPENSSL_memcpy(out, &S.c, sizeof(polyval_block));
}
예제 #11
0
파일: simpleio.c 프로젝트: antdvid/FronTier
EXPORT	double	fread_float(
	const char    *label,
	const IO_TYPE *io_type)
{
	FILE	*file = io_type->file;
	double	x;
	char	s[81];
	int	c;
	char *string;
	size_t size;

	if (label != NULL)
	    (void) fgetstring(file,label);
	if ((c = getc(file)) != '\f') /*NOBINARY*/
	{
	    long current;
	    (void) ungetc(c,file);
	    current = ftell(file);
	    string = fgets(s,5,file);
	    if (strncasecmp("inf",s,3) == 0)
	    	x = HUGE_VAL;
	    else if (strncasecmp("-inf",s,4) == 0)
	    	x = -HUGE_VAL;
	    else
	    {
		(void) fseek(file,current,SEEK_SET);
	        if (fscanf(file,scan_float_fmt,&x) != 1)
		{
	    	    screen("ERROR in fread_float(), "
	    	           "can't read floating point variable\n");
	    	    clean_up(ERROR);
		}
	    }
	}
	else
	{
	    (void) getc(file);
	    if (io_type->read_float_size == io_type->cpu_float_size)
	    {
	        size = fread((void *)&x,sizeof(double),1,file);
	        if (io_type->reverse_endian)
	            byte_reverse(x);
	    }
	    else if (io_type->read_float_size > io_type->cpu_float_size)
	    {
		double tmp;
	        size = fread((void *)&tmp,sizeof(double),1,file);
	        if (io_type->reverse_endian)
	            byte_reverse(tmp);
		x = tmp;
	    }
	    else
	    {
	        TRUEfloat tmp;
	        size = fread((void *)&tmp,sizeof(TRUEfloat),1,file);
	        if (io_type->reverse_endian)
	            byte_reverse(tmp);
		x = tmp;
	    }
	}
	return x;
}		/* end fread_float*/