CompBuffer_F32

You are here:
Estimated reading time: 1 min
Go back to the VM operations list

Prototype

CompBuffer_F32 (r1, r2)

Description

Compare the values of two float stored in the buffer.

Return
return buffer[r1]>buffer[r2]?1 : (buffer[r1] == buffer[r2]?0 : -1 )

Code Example

The following code example uses the CompBuffer_F32 function.

The SMK900.evi file used for this example can be downloaded at the bottom of this page.
/* Example Code
* CompBuffer_F32
* tools Converter: https://www.h-schmidt.net/FloatConverter/IEEE754.html
*
* get buffer indexes r1 and r2
* set buffer in memory
* if params used 
* 	compare buffer[r1] to buffer[r2]
* 	return result of compare (0xFF if "<", 0x00 if "=" or 0x01 if ">") on 8 bits
* else
*	compare buffer[r1] to buffer[r2], buffer[r1] to buffer[r1] and buffer[r2] to buffer[r1]
*	return results of 3 compares on 3*8 bits
*
* example VMExecuteCmd:
* cmd: 															   |r1       |r2       |buffer
*		0xfb 0x0e 0x00 0x0c 0x00 0x0e [0x?? 0x?? 0x?? = macAdress] 0x00 0x00 0x01 0x00 0x00 0x00 0x90 0xbf 0x00 0x00 0x28 0x41
* rsp: 	0xfb 0x08 0x00 0x2d 0x00 0xe1 0x1e 0xff
*/

#include "SMK900.evi"

#define SENSORCODE 0x01

function exec_aircmd(){
	local rxLen;
	local useParams;
	local idx1,idx2;
	local i;
	local result1,result2,result3;

	rxLen=GetAirBuf(0, 0, 20);
	
	if(rxLen>=13){ // 1 byte for paketID + 12 bytes of payload (4 bytes for buffer indexes and minimum 8 bytes for buffer)
		useParams=true;
		idx1=GetBuffer_16(1);
		idx2=GetBuffer_16(3);
		for(i=5;i<rxLen;i++){
			SetBuffer(i-5,GetBuffer_S8(i),1);
		}
	}else{
		useParams=false;
		idx1=0;
		idx2=4;
		//-1.125 -> 1011 1111 1001 0000 0000 0000 0000 0000
		SetBuffer_16(0,0x0000);
		SetBuffer_16(2,0xbf90);
		
		//10.5 -> 0100 0001 0010 1000 0000 0000 0000 0000
		SetBuffer_16(4,0x0000);
		SetBuffer_16(6,0x4128);
	}
	
	result1 = CompBuffer_F32(idx1,idx2);

	if(useParams){
		SetBuffer(0,result1,1);
		Send(1);	
	}else{
		result2 = CompBuffer_F32(idx1,idx1);
		result3 = CompBuffer_F32(idx2,idx1);
		SetBuffer(0,result1,1);
		SetBuffer(1,result2,1);
		SetBuffer(2,result3,1);
		Send(3);	
	}	
}

function main() 
{
	local execType;
	
	execType = GetExecType();
	if(execType==MESHEXECTYPE_AIRCMD_bm){
		exec_aircmd();
	}
}

Go back to the VM operations list

Attachments

Was this article helpful?
Dislike 0
Views: 81
Go to Top