Data conversion

Post questions and issues with Concept2 PM3 SDK
Post Reply
AlinaRU
Paddler
Posts: 5
Joined: January 24th, 2018, 11:17 am

Data conversion

Post by AlinaRU » May 18th, 2018, 4:59 am

Hello, I'm trying to deal with one program. It displays the PM data on the computer screen.
Explain please what exactly happens in this cycle
Thank you in advance

Code: Select all

if (_rsp_data[currentbyte] == CSAFE_PM_GET_WORKDISTANCE)
	{
		currentbyte++;
		datalength = _rsp_data[currentbyte];
		currentbyte++;
		
		uint distanceTemp = (_rsp_data[currentbyte] + (_rsp_data[currentbyte + 1] << 8) + (_rsp_data[currentbyte + 2] << 16) + (_rsp_data[currentbyte + 3] << 24)) / 10;
		//uint fractionTemp = _rsp_data[currentbyte + 4];
		
		_strokeData.workDistance = distanceTemp;
		
		currentbyte += datalength;
	}

Allan Olesen
1k Poster
Posts: 122
Joined: April 27th, 2018, 6:40 am

Re: Data conversion

Post by Allan Olesen » May 18th, 2018, 2:42 pm

It looks like a piece of code which traverses through a datastream, byte by byte, and digs out the parameters in that stream. Apparently, it works like this:

It first meets a byte telling it that the next parameter is a workdistance.
The next byte tells how many bytes are used to store the parameter.
The next 4 bytes store the workdistance as a 32 bit integer, apparently in tenths of a meter, so the work distance is calculated like this :
Work distance = (Byte1 + Byte2 * 2^8 + Byte3 * 2^16 + Byte4 * 2^24)/10
It then advances in the datastream by the number of bytes used to store the parameter.
From then, I guess it will look for the next parameter description byte.

AlinaRU
Paddler
Posts: 5
Joined: January 24th, 2018, 11:17 am

Re: Data conversion

Post by AlinaRU » May 18th, 2018, 4:50 pm

Thank you very much for your answer!

Post Reply