[r78]: / trunk / Monarco / Monarco_FB / utility / dataTransfer / svnobj  Maximize  Restore  History

Download this file

32 lines (31 with data), 4.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(* Handles the SPI data transfer to the Monarco HAT *)
METHOD  dataTransfer : MNR.eMonarcoComStatus
VAR                 	
//init temporay buffer before filling;
// determine size of buffer
udiBufSize 						:= SIZEOF( THIS^._abyIntTxBuf );
(* Sets CRC16 checksum, for Tx byte array [24] and [25]*)
CRC 							:= THIS^.getCRC( THIS^._abyIntTxBuf );
THIS^._abyIntTxBuf[24]			:= WORD_TO_BYTE(CRC);
THIS^._abyIntTxBuf[25]			:= WORD_TO_BYTE(SHR(CRC,8));
// Send, Recv
						 pabyRxBuffer := ADR( tmpRxBuf ), 		// write result into a temporary buffer for post-analysis. Beware that the received answser is from the last question, not the current question.
						 udiLen		  := udiBufSize, 
						 uiDelayus	  := 5,
						 udispeedHz	  := 0); 
IF NOT xDone THEN 
	// Send / Recv fail
	DataTransfer := eMonarcoComStatus.ERROR;
	_iState := 1000;
ELSE
	// OK?
	IF THIS^.checkCRC(tmpRxBuf) THEN
		//CRC okay, return the recv buffer
		THIS^._abyIntRxBuf 	:= tmpRxBuf;
		DataTransfer		:= eMonarcoComStatus.SUCCES;
	ELSE
		//CRC not okay, return an empty buffer
		flush(tmpRxBuf);
		DataTransfer		:= eMonarcoComStatus.CrcFail;
	END_IF
END_IF;