Esempio n. 1
0
// Provide ethernet devices with a semi-unique MAC address from the UUID
void mbed_mac_address(char *mac)
{
    uint16_t MAC[3];                        // 3 16 bits words for the MAC
    uint32_t UID[4];

    // get UID via ISP commands
    FLASHIAP_ReadUid(UID);

    // generate three CRC16's using different slices of the UUID
    MAC[0] = crcSlow((const uint8_t *)UID, 8);  // most significant half-word
    MAC[1] = crcSlow((const uint8_t *)UID, 12);
    MAC[2] = crcSlow((const uint8_t *)UID, 16); // least significant half word

    // The network stack expects an array of 6 bytes
    // so we copy, and shift and copy from the half-word array to the byte array
    mac[0] = MAC[0] >> 8;
    mac[1] = MAC[0];
    mac[2] = MAC[1] >> 8;
    mac[3] = MAC[1];
    mac[4] = MAC[2] >> 8;
    mac[5] = MAC[2];

    // We want to force bits [1:0] of the most significant byte [0]
    // to be "10"
    // http://en.wikipedia.org/wiki/MAC_address

    mac[0] |= 0x02; // force bit 1 to a "1" = "Locally Administered"
    mac[0] &= 0xFE; // force bit 0 to a "0" = Unicast

}
Esempio n. 2
0
static bool infoDecode(DeckInfo * info)
{
  uint8_t crcHeader;
  uint8_t crcTlv;

  if (info->header != DECK_INFO_HEADER_ID) {
    DEBUG_PRINT("Memory error: wrong header ID\n");
    return false;
  }

  crcHeader = crcSlow(info->raw, DECK_INFO_HEADER_SIZE);
  if(info->crc != crcHeader) {
    DEBUG_PRINT("Memory error: incorrect header CRC\n");
    return false;
  }

  if(info->raw[DECK_INFO_TLV_VERSION_POS] != DECK_INFO_TLV_VERSION) {
    DEBUG_PRINT("Memory error: incorrect TLV version\n");
    return false;
  }

  crcTlv = crcSlow(&info->raw[DECK_INFO_TLV_VERSION_POS], info->raw[DECK_INFO_TLV_LENGTH_POS]+2);
  if(crcTlv != info->raw[DECK_INFO_TLV_DATA_POS + info->raw[DECK_INFO_TLV_LENGTH_POS]]) {
    DEBUG_PRINT("Memory error: incorrect TLV CRC %x!=%x\n", (unsigned int)crcTlv,
                info->raw[DECK_INFO_TLV_DATA_POS + info->raw[DECK_INFO_TLV_LENGTH_POS]]);
    return false;
  }

  info->tlv.data = &info->raw[DECK_INFO_TLV_DATA_POS];
  info->tlv.length = info->raw[DECK_INFO_TLV_LENGTH_POS];

  return true;
}
Esempio n. 3
0
int cmd_module(int argc, char *argv[]) {
	struct module_info *header;
	
	header = (struct module_info *)pvPortMalloc(sizeof(struct module_info));
	
	if (argc < 2) {
		cmd_print("\r\ni2c exists: %d",I2CEE_exists(SLAVE_ADDRESS_MODULE1));
	} else {
		if(ustrncmp(argv[1],"write",5) == 0) {
			header->magic   = 0x3A;
			header->vendor  = 0x01;
			header->product = 0x01;
			header->version = 0x01;
			header->profile = ustrtoul(argv[2],NULL,16);
			header->modres  = ustrtoul(argv[3],NULL,16);
			header->dummy2  = 0;
			header->crc     = crcSlow((unsigned char *)header, sizeof(struct module_info)-sizeof(header->crc));
			
			I2CEE_write(SLAVE_ADDRESS_MODULE1,(unsigned char *) header, sizeof(struct module_info), 0);
			vTaskDelay(100 / portTICK_RATE_MS); // there must be a delay after write or avoid I2CEE_read()
		}
		I2CEE_read(SLAVE_ADDRESS_MODULE1, (unsigned char *) header, sizeof(struct module_info), 0);
		cmd_print("\r\ni2c module magic: %X vendor: %X product: %X version: %X profile: %X modres: %X", header->magic, header->vendor, header->product, header->version, header->profile, header->modres);


	}

	vPortFree(header);
	return(0);
}
Esempio n. 4
0
void
main(void)
{
	unsigned char  test[] = "123456789";
	printf("Size of short is %i\n", sizeof(short));
	printf("Size of int is %i\n", sizeof(int));
	printf("Size of long is %i\n", sizeof(long));

	/*
	 * Print the check value for the selected CRC algorithm.
	 */
	printf("The check value for the %s standard is 0x%X\n", CRC_NAME, CHECK_VALUE);
	
	/*
	 * Compute the CRC of the test message, slowly.
	 */
	printf("The crcSlow() of \"123456789\" is 0x%X\n", crcSlow(test, strlen(test)));
	
	/*
	 * Compute the CRC of the test message, more efficiently.
	 */
	crcInit();
	printf("The crcFast() of \"123456789\" is 0x%X\n", crcFast(test, strlen(test)));
	int testing = crcFast(test, strlen(test));
	int *helping = &testing;
	printf("Test string with crc %s%c%c%c%c\n", test, helping[0],helping[1], helping[2],helping[3]);
	
	//How to add the characters to the packet
	/*packet[1020] = helping[0];
	packet[1021] = helping[1];
	packet[1022] = helping[2];
	packet[1023] = helping[3];*/

}   /* main() */
Esempio n. 5
0
void logInit(void)
{
  int i;
  
  if(isInit)
    return;

  logs = &_log_start;
  logsLen = &_log_stop - &_log_start;
  logsCrc = crcSlow(logs, logsLen);
  
  // Big lock that protects the log datastructures
  logLock = xSemaphoreCreateMutex();

  for (i=0; i<logsLen; i++)
  {
    if(!(logs[i].type & LOG_GROUP)) 
      logsCount++;
  }
  
  //Manually free all log blocks
  for(i=0; i<LOG_MAX_BLOCKS; i++)
    logBlocks[i].id = BLOCK_ID_FREE;

  //Init data structures and set the log subsystem in a known state
  logReset();
  
  //Start the log task
  xTaskCreate(logTask, (const signed char * const)"log",
    configMINIMAL_STACK_SIZE, NULL, /*priority*/1, NULL);

  isInit = true;
}
Esempio n. 6
0
void logInit(void)
{
  int i;
  rt_thread_t log_thread;
  if(isInit)
    return;

  logs = &_log_start;
  logsLen = &_log_stop - &_log_start;
  logsCrc = crcSlow(logs, logsLen);
  
  // Big lock that protects the log datastructures
  logLock = rt_mutex_create("log_lock",RT_IPC_FLAG_FIFO);

  for (i=0; i<logsLen; i++)
  {
    if(!(logs[i].type & LOG_GROUP)) 
      logsCount++;
  }
  
  //Manually free all log blocks
  for(i=0; i<LOG_MAX_BLOCKS; i++)
    logBlocks[i].id = BLOCK_ID_FREE;

  //Init data structures and set the log subsystem in a known state
  logReset();
  
  //Start the log task
  //xTaskCreate(logTask, (const signed char * const)"log",
   // configMINIMAL_STACK_SIZE, NULL, /*priority*/1, NULL);
  log_thread = rt_thread_create("log", logTask, RT_NULL, 512, 10, 5);
  isInit = RT_TRUE;
}
Esempio n. 7
0
void paramInit(void)
{
  int i;

  if(isInit)
    return;
#if defined(__CC_ARM)
    params = (struct param_s *)&Image$$PARAM$$Base;
  paramsLen = (int)&Image$$PARAM$$Length + (int)&Image$$PARAM$$ZI$$Length;
#else
  params = &_param_start;
  paramsLen = &_param_stop - &_param_start;
#endif
  paramsCrc = crcSlow(params, paramsLen);
  
  for (i=0; i<paramsLen; i++)
  {
    if(!(params[i].type & PARAM_GROUP)) 
      paramsCount++;
  }
  
  
  //Start the param task
	xTaskCreate(paramTask, (const signed char * const)"PARAM",
				    configMINIMAL_STACK_SIZE, NULL, /*priority*/1, NULL);
  
  //TODO: Handle stored parameters!
  
  isInit = true;
}
Esempio n. 8
0
void paramInit(void)
{
  int i;

  if(isInit)
    return;

  params = &_param_start;
  paramsLen = &_param_stop - &_param_start;
  paramsCrc = crcSlow(params, paramsLen);

  for (i=0; i<paramsLen; i++)
  {
    if(!(params[i].type & PARAM_GROUP))
      paramsCount++;
  }


  //Start the param task
	xTaskCreate(paramTask, (const signed char * const)PARAM_TASK_NAME,
	            PARAM_TASK_STACKSIZE, NULL, PARAM_TASK_PRI, NULL);

  //TODO: Handle stored parameters!

  isInit = true;
}
Esempio n. 9
0
static void updateChecksum(SISControllerChecksum* csum, SISField* compressed) {
	uint8_t* compressedData = new uint8_t[compressed->HeaderDataLength()];
	uint8_t* compressedPtr = compressedData;
	compressed->CopyHeaderData(compressedPtr);
	uint16_t ccsum = crcSlow(compressedData, compressed->HeaderDataLength());
	delete [] compressedData;
	csum->iValue = ccsum;
}
Esempio n. 10
0
void paramInit(void)
{
  int i;
  const char* group = NULL;
  int groupLength = 0;

  if(isInit)
    return;

  params = &_param_start;
  paramsLen = &_param_stop - &_param_start;

  // Calculate a hash of the toc by chaining description of each elements
  // Using the CRTP packet as temporary buffer
  paramsCrc = 0;
  for (int i=0; i<paramsLen; i++)
  {
    int len = 5;
    memcpy(&p.data[0], &paramsCrc, 4);
    p.data[4] = params[i].type;
    if (params[i].type & PARAM_GROUP) {
      if (params[i].type & PARAM_START) {
        group = params[i].name;
        groupLength = strlen(group);
      }
    } else {
      // CMD_GET_ITEM_V2 result's size is: 4 + strlen(params[i].name) + groupLength + 2
      if (strlen(params[i].name) + groupLength + 2 > 26) {
        PARAM_ERROR("'%s.%s' too long\n", group, params[i].name);
        ASSERT_FAILED();
      }
    }

    if (params[i].name) {
      memcpy(&p.data[5], params[i].name, strlen(params[i].name));
      len += strlen(params[i].name);
    }
    paramsCrc = crcSlow(p.data, len);
  }

  for (i=0; i<paramsLen; i++)
  {
    if(!(params[i].type & PARAM_GROUP))
      paramsCount++;
  }


  //Start the param task
	xTaskCreate(paramTask, PARAM_TASK_NAME,
	            PARAM_TASK_STACKSIZE, NULL, PARAM_TASK_PRI, NULL);

  //TODO: Handle stored parameters!

  isInit = true;
}
void Serializer(connection *conn, char *buffer) {
	char header[MAX_HEADER_SIZE];
	char payload[MAX_PAYLOAD_SIZE];
	char header_payload[MAX_HEADER_SIZE + MAX_PAYLOAD_SIZE];
	char tailer[CRC32SIZE];

	memset(&header, 0, sizeof(header));
	memset(&payload, 0, sizeof(payload));
	memset(&header_payload, 0, sizeof(header_payload));
	memset(&tailer, 0, sizeof(tailer));

	sprintf(payload, "%s|%s|%s|", conn->clientNickName, conn->serviceName, conn->messageText);
	sprintf(header, "%s|%s|%d|", conn->protoName, conn->protoVersion, (int)strlen(payload) + 8);
	sprintf(header_payload, "%s%s", header, payload);
	sprintf(tailer, "%X", (unsigned int)crcSlow((unsigned char *)header_payload, strlen(header_payload)));
	sprintf(buffer, "%s%s%s", header, payload, tailer);
}
Esempio n. 12
0
bool CryptoTest::Run()
{
	CCrypto Crypto;

	Crypto.Initialize("Key.txt");

	TCHAR szJuhang[] = _T("juhang");

	Crypto.ProcessEncryption(szJuhang, sizeof(szJuhang));
	Crypto.ProcessDecryption(szJuhang, sizeof(szJuhang));

	///////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////
	unsigned char  test[] = "123456789";

	/*
	* Print the check value for the selected CRC algorithm.
	*/
	printf("The check value for the %s standard is 0x%X\n", CRC_NAME, CHECK_VALUE);

	/*
	* Compute the CRC of the test message, slowly.
	*/
	printf("The crcSlow() of \"123456789\" is 0x%X\n", crcSlow(test, 9));

	/*
	* Compute the CRC of the test message, more efficiently.
	*/
	crcInit();
	printf("The crcFast() of \"123456789\" is 0x%X\n", crcFast(test, 9));

	///////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////
	Cmd5Capi md5Capi;


	std::wstring out, in;
	in = L"JUHANG";

	out = md5Capi.Digest(in);

	return true;

}
Esempio n. 13
0
void
main(void)
{
	unsigned char  test[] = "123456789";


	/*
	 * Print the check value for the selected CRC algorithm.
	 */
	printf("The check value for the %s standard is 0x%X\n", CRC_NAME, CHECK_VALUE);
	
	/*
	 * Compute the CRC of the test message, slowly.
	 */
	printf("The crcSlow() of \"123456789\" is 0x%X\n", crcSlow(test, strlen(test)));
	
	/*
	 * Compute the CRC of the test message, more efficiently.
	 */
	crcInit();
	printf("The crcFast() of \"123456789\" is 0x%X\n", crcFast(test, strlen(test)));

}   /* main() */
Esempio n. 14
0
static bool expbrdIsValid(ExpbrdData *data)
{
  bool status = false;
  uint8_t crc;

  if (data->header == EXPBRD_ID)
  {
    crc = crcSlow(data, sizeof(ExpbrdData) - 1);
    if (crc == data->crc)
    {
      status = true;
    }
    else
    {
      DEBUG_PRINT("Wrong CRC:0x%X!=0x%X\n", crc, data->crc);
    }
  }
  else
  {
    DEBUG_PRINT("Wrong header id: 0x%X\n", data->header);
  }

  return status;
}
Esempio n. 15
0
int8_t vscp_sendUDPEvent( PVSCPMSG pmsg )
{
    int i;

    if ( UDPIsPutReady( vscp_udp_transmitsocket ) ) {

        pmsg->crc = crcSlow( (unsigned char *)pmsg, sizeof( vscpMsg ) - 2  );

        UDPPut( pmsg->head );

        UDPPut( ( pmsg->vscp_class >> 8 ) & 0xff );
        UDPPut( pmsg->vscp_class & 0xff );

        UDPPut( ( pmsg->vscp_type >> 8 ) & 0xff );
        UDPPut( pmsg->vscp_type & 0xff );

        for ( i=0; i<16; i++ ) {
            UDPPut( vscp_getGUID( i ) );
        }

        UDPPut( ( pmsg->sizeData >> 8 ) & 0xff );
        UDPPut( pmsg->sizeData & 0xff );

        for ( i=0; i<pmsg->sizeData; i++ ) {
            UDPPut( pmsg->data[ i ] );
        }

        UDPPut( ( pmsg->crc >> 8 ) & 0xff );
        UDPPut( pmsg->crc & 0xff );

        UDPFlush();
        return TRUE;
    }

    return FALSE;
}
Esempio n. 16
0
//реализация функции конвертирования данных структуры в строку для пересылки по сети
//аргументы:
//connection - структура данных о клиенте и параметрах соединения
//buffer - строка, в которую будет помещен результат
void Serializer(connection *connection, char *buffer) {
	char tempString[BUFFERSIZE];
	char messageLength[5];
	memset(&tempString, 0, sizeof(tempString));
	memset(&messageLength, 0, sizeof(messageLength));

	strcat(buffer, connection->protoName);
	strcat(buffer, "|");
	strcat(buffer, connection->protoVersion);
	strcat(buffer, "|");
	strcat(tempString, connection->clientNickName);
	strcat(tempString, "|");
	strcat(tempString, connection->serviceName);
	strcat(tempString, "|");
	strcat(tempString, connection->messageText);
	strcat(tempString, "|");
	sprintf(messageLength, "%d", (int)(strlen(buffer) + strlen(tempString) + 8 + 1));
	sprintf(connection->length, "%d", (int)(atoi(messageLength) + strlen(messageLength)));
	strcat(buffer, connection->length);
	strcat(buffer, "|");
	strcat(buffer, tempString);
	sprintf(connection->messageCRC32, "%X", (unsigned int)crcSlow((unsigned char *)buffer, strlen(buffer)));
	strcat(buffer, connection->messageCRC32);
}
Esempio n. 17
0
void sendCommand() {
//	while(1){
		printf("Send command: \r\n");
		printf("0 - NULL\r\n"
		   "1 - Change can speed\r\n"
		   "2 - Get can speed\r\n"
			"3 - Init can bus\r\n"
			"4 - Set can RX object\r\n"
			"5 - Get can RX object\r\n"
			"6 - Set can TX object\r\n"
			"7 - Get can TX object\r\n"
			"8 - Transmit CAN object\r\n"
			"9 - Get board temperature\r\n"
			"10 - Get board uptime\r\n"
			"11 - Set board LED\r\n"
			"12 - Get board LED\r\n"
			"13 - Init SD card\r\n"
			"14 - Open file\r\n"
			"15 - Close file\r\n"
			"16 - Write file\r\n"
			"17 - Write LCD command\r\n"
			"18 - Write LCD string\r\n");
	scanf("%d",&input);
	switch(input) {
	case NULL_COMMAND:
		printf("NULL_COMMAND\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case CHANGE_CAN_SPEED:
		printf("CHANGE_CAN_SPEED\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case GET_CAN_SPEED:
		printf("GET_CAN_SPEED\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case INIT_CAN_BUS:
		printf("INIT_CAN_BUS\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case SET_CAN_RX_OBJ:
		printf("SET_CAN_RX_OBJ\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case GET_CAN_RX_OBJ:
		printf("GET_CAN_RX_OBJ\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case SETUP_CAN_TX_OBJ:
		printf("SETUP_CAN_TX_OBJ\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case GET_CAN_TX_OBJ:
		printf("GET_CAN_TX_OBJ\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case TRANSMIT_CAN_OBJ:
		printf("TRANSMIT_CAN_OBJ\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case GET_BOARD_TEMP:
		printf("GET_BOARD_TEMP\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case GET_BOARD_UPTIME:
		printf("GET_BOARD_UPTIME\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case SET_BOARD_LED:
		printf("SET_BOARD_LED\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case GET_BOARD_LED:
		printf("GET_BOARD_LED\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case INIT_SD_CARD:
		printf("INIT_SD_CARD\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case OPEN_FILE:
		printf("OPEN_FILE\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case CLOSE_FILE:
		printf("CLOSE_FILE\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case WRITE_FILE:
		printf("WRITE_FILE\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case READ_FILE:
		printf("READ_FILE\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case WRITE_LCD_CMD:
		printf("WRITE_LCD_CMD\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	case WRITE_LCD_STRING:
		printf("WRITE_LCD_STRING\r\n");
		hdlc_frame->cmd = input;
		hdlc_frame->len = 0x00;
		break;
	default:
		printf("DEFAULT\r\n");
		return;
//	}
	}
	hdlc_frame->sflag = HDLC_SFLAG;
	hdlc_frame->eflag = HDLC_EFLAG;
	hdlc_frame->crc = crcSlow((uint8_t*)hdlc_frame,3+hdlc_frame->len);
	//written = fwrite(hdlc_frame,1,3+hdlc_frame->len,can_board);
	written = write(can_board,hdlc_frame,3+hdlc_frame->len);
	printf("Written bytes: %d\r\n",written); 

	return;
}
Esempio n. 18
0
void FILE_Processor::process_sdu( M_SDU &sdu ){
	Transport_File file;
	DEBUG("%s", "Processing PDU:\n");
	//for( int i = 0; i < sdu.length+1; i++ ){
	//	printf( "%X ", sdu.data[i] );
	//}
	uint8_t flag = sdu.seq_flag;
	//printf("\n");
	DEBUG( "\n%s","Checking sequence flag\n");
	/*
	 * Somehow putting the pdu.seq_flag directly in the switch caused a bus error on SPARC
	 */
	uint16_t sducrc;
	memcpy( &sducrc, sdu.data + sdu.length+1-2, 2 );
	DEBUG("SDU crc = 0x%X\n", sducrc );
	uint16_t calcedcrc = crcSlow( sdu.data, sdu.length+1-2 );
	DEBUG("Calced crc = 0x%X\n", calcedcrc );

	if( sducrc != calcedcrc ){
		DEBUG("%s","CRC invalid, tossing packet\n");
		return;
	}
       uint16_t apid = sdu.apid;
	
	switch( flag ){
		case SEQ_COMPLETE_FILE:{ // complete file, don't bother adding to the list just output

			      DEBUG("%s","We have a complete file\n");
			      fill_file_info( file, sdu );
			      file.tp_sdu = new unsigned char[file.length];
			      memcpy( file.tp_sdu, sdu.data+10, file.length-10 );
			      // now what? have a complete file, write to disk?
			      this->save_file( file );
			      break;
		      }		
		case SEQ_FIRST_SEGMENT:{					       					       
					       DEBUG("%s","Got first SDU of a file\n" );
						files_by_apid[apid].clear(); // clear out contents if there's an existing list, otherwise this makes a new one
						files_by_apid[apid].push_back( sdu );
					       
					       break;
				       }
		case SEQ_CONTINUATION:{
			DEBUG("%s", "Got continuing SDU of a file\n" );
			if( files_by_apid.count( apid ) == 1 ){
				files_by_apid[apid].push_back( sdu );
			}else{
				DEBUG("%s", "But we haven't started this file yet, ignoring");
			}
			
			break;
		}
		case SEQ_LAST_SEGMENT:{
			if( files_by_apid.count( apid ) == 1 ){
				files_by_apid[apid].push_back( sdu );
			}else{
				break;	
			}
			files_by_apid[apid].push_back( sdu );

			DEBUG("Got last SDU of a file, consisting of %d M_SDUs\n", files_by_apid[apid].size() );
			// build file
			try{
				list<M_SDU>::iterator _sdu = files_by_apid[apid].begin();

				//from the first header, get the base file info
				fill_file_info( file, *_sdu );
				// now build the file from all of the M_SDU packets
				file.tp_sdu = new unsigned char[file.length+1];//throw in the +1, in case of the filler portion
				memcpy(file.tp_sdu, _sdu->data+10, _sdu->length-10-2 ); // -10 this was the first M_SDU that's the transport header, -2 ignore the crc
				_sdu++;
				// note we need to check the sequence count before putting these together. we'll put zeros 
				// in for missing packets, but we need to increase the byte count.
				size_t bytes_stored = _sdu->length-10-2;
				while( _sdu != files_by_apid[apid].end() && bytes_stored < _sdu->length ){
					memcpy(file.tp_sdu+bytes_stored, _sdu->data, _sdu->length );
					bytes_stored += _sdu->length;
					_sdu++;
				}
			

				this->save_file( file );
			}catch(... ){
				printf("Failed to Create file for apid: %d", apid );
			}
			files_by_apid.erase(apid);
			break;
		 }
		 default:{
				 printf("%s:%d unknown packet type\n", __FILE__, __LINE__);
				break;
			 }

	}

	DEBUG("%s", "End process sdu\n"  );

}
Esempio n. 19
0
static bool expbrdScan(void)
{
  uint8_t i = 0;
  bool status = false;
#if 1
  if (owScan(&nBoards))
  {
    DEBUG_PRINT("Found %d memories.\n", nBoards);
  }
  else
  {
    DEBUG_PRINT("Scan [FAILED].\n");
  }


#if 0
  expbrdData[0].header = EXPBRD_ID;
  expbrdData[0].vid    = EXPBRD_VID_BITCRAZE;
  expbrdData[0].pid    = EXPBRD_PID_LEDRING;
  expbrdData[0].crc = crcSlow( (uint8_t *)&expbrdData[0], sizeof(ExpbrdData) - 1);

  status = owWrite(0, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[0]);

  if( status == true )
  {
	  DEBUG_PRINT("owWrite LED Ring OK\n");
  }
  else
  {
	  DEBUG_PRINT("owWrite LED Ring Fail\n");
  }
#endif



  for (i = 0; i < nBoards; i++)
  {
    if (owRead(i, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[i]))
    {
      if (expbrdIsValid(&expbrdData[i]))
      {
        DEBUG_PRINT("Info board %i:\n", i);
        expbrdPrintData(&expbrdData[i]);
        status = true;
      }
    }
    else
    {
      DEBUG_PRINT("Reading board nr:%d [FAILED].\n", i);
    }
  }
#endif
  /*
  nBoards = 1;
  expbrdData[0].header = EXPBRD_ID;
  expbrdData[0].vid    = EXPBRD_VID_BITCRAZE;
  expbrdData[0].pid    = EXPBRD_PID_LEDRING;
  expbrdData[0].crc = crcSlow( (uint8_t *)&expbrdData[0], sizeof(ExpbrdData) - 1);
  */

  owScan(&nBoards);

  return status;
}
Esempio n. 20
0
void main(void)
{
    char* input_data = malloc(DATA_SIZE);

    FILE* input_file; 
    input_file = fopen(INPUT_FILE, "r");

    if(input_file == NULL){
        fprintf(stderr, "Failed to open %s\n", INPUT_FILE);
        exit(1);
    }

    int i = 0;

    char buffer[BLOCK_SIZE];
    while(fgets(buffer, BLOCK_SIZE, input_file)){
        strcpy(input_data+i,buffer);
        i = i + BLOCK_SIZE - 1;
    }
    fclose(input_file);

    /*Replace the line field ascii with \0*/
    input_data[strlen(input_data) - 1] = '\0';

    struct stopwatch_t* sw = stopwatch_create();

/*--------------------------------------------------------------------------------------*/
    stopwatch_init();
    stopwatch_start(sw);

    printf("crcSlow() 0x%X  ", crcSlow(input_data, strlen(input_data)));

    stopwatch_stop(sw);   

    printf("  Time: %Lg\n", stopwatch_elapsed(sw));
/*--------------------------------------------------------------------------------------*/

    stopwatch_start(sw);

    size_t input_data_len = strlen(input_data);
    
    int input_blocks = input_data_len / BLOCK_SIZE;
    int extra_blocks = 0;
    if(input_data_len % BLOCK_SIZE != 0)
        extra_blocks = 1;

    int total_blocks = input_blocks + extra_blocks;
    int *result = malloc(total_blocks * sizeof(int));
    
    omp_set_num_threads(16);

    unsigned int ans = 0;

    char* block_data = malloc(input_blocks * (BLOCK_SIZE + 1));
    char* block_addr;

    i = 0;

    #pragma omp parallel  for default(none) shared(input_blocks, input_data, result, block_data) private (i, block_addr)  
    for(i = 0; i < input_blocks; ++i){
        block_addr = block_data + (BLOCK_SIZE + 1) * i;
        strncpy(block_addr, input_data + BLOCK_SIZE * i, BLOCK_SIZE);
        *(block_addr + BLOCK_SIZE) = '\0';
        result[i] = CrcHash(block_addr, BLOCK_SIZE);
    }
    
    int rem = input_data_len % BLOCK_SIZE;

    char* last_block_data = malloc(rem + 1);
    
    if(extra_blocks == 1){
        strncpy(last_block_data, input_data + BLOCK_SIZE * input_blocks, rem);
        *(last_block_data + rem) = '\0';
        result[input_blocks] = CrcHash(last_block_data, rem);
    }

    i=0;
    for(i = 0; i < input_blocks; ++i){
        ans = crc32_combine(ans, result[i], BLOCK_SIZE);
    }
    
    if(extra_blocks == 1)
        ans = crc32_combine(ans, result[i], rem);

    stopwatch_stop(sw);

    printf("Parallel() 0x%X   Time:  %Lg \n",ans, stopwatch_elapsed(sw)); 
/*--------------------------------------------------------------------------------------*/

    crcInit();
    stopwatch_start(sw);
    printf("crcFast() 0x%X  ", crcFast(input_data, strlen(input_data)));
    stopwatch_stop(sw);
    printf("  Time: %Lg\n", stopwatch_elapsed(sw));

    stopwatch_destroy(sw);
/*--------------------------------------------------------------------------------------*/
    stopwatch_start(sw);
    printf("crc_intel() 0x%X  ", CrcHash((const void*)input_data, strlen(input_data)));
    stopwatch_stop(sw);
    printf("  Time: %Lg\n", stopwatch_elapsed(sw));

/*--------------------------------------------------------------------------------------*/
    
    /*Cleanup*/  
    free(last_block_data);
    free(block_data);
    free(input_data);
}