Ejemplo n.º 1
0
serialFrame createSerialFrame(char type, int32_t data1, int32_t data2, int32_t data3, int32_t data4, int32_t rss1, int32_t rss2, int32_t rss3, int32_t rss4){
	// creation of the frame
	serialFrame f;
	// initializing the fields
	f.seqNum = currentSerialSeqNum;
	f.type = type;
	f.data[0]= data1;
	f.data[1]= data2;
	f.data[2]= data3;
	f.data[3]= data4;
	f.rss[0]= rss1;
	f.rss[1]= rss2;
	f.rss[2]= rss3;
	f.rss[3]= rss4;
	// converting the frame into a char * for CRC generation purpose
	char tab[CONVERTED_SERIAL_FRAME_SIZE-2];
	serialFrameToChar(f,tab);
	// CRC generation
	f.crc = createCRC(tab, CONVERTED_SERIAL_FRAME_SIZE-2);
	// sequence number management
	if(currentSerialSeqNum<MAX_SERIAL_SEQ_NUM)
		currentSerialSeqNum++;
	else
		currentSerialSeqNum = 0;
		
	return f;
}
Ejemplo n.º 2
0
uint8_t retrieveReadFrame(uint8_t * read, serialFrame * uf){
	// converting back the uint8_t form of the frame in its classic form
	*uf = serialFrameFromUint(read);
	// generating the CRC for this converted form
	char tab[CONVERTED_SERIAL_FRAME_SIZE-2];
	serialFrameToChar(*uf,tab);
	uint16_t crcRead = createCRC(tab, CONVERTED_SERIAL_FRAME_SIZE-2);
	// comparing this generated CRC to the one contained in the frame to check integrity of the whole frame
	if(crcRead==uf->crc)
		return 0;
	else
		return 1;
}
Ejemplo n.º 3
0
Response::Response(bitset<1*BYTE> type, bitset<4*BYTE> ID, boost::dynamic_bitset<> message)
    :type(type), ID(ID), message(message), datasize(message.size()/8)
{
    CRC = bitset<2*BYTE>(createCRC());
}