Sample communication application – Beijer Electronics SCOM Protocol EN User Manual

Page 126

Advertising
background image

Sample Communication Application

126

Beijer Electronics, MAEN975

/*=====================================================================*/

/* SCOM limits. */

#define _SCOM_MSG_HDR_SIZE 7

#define _SCOM_MAX_MSG_LEN 82

#define _SCOM_MAX_DAT_LEN 74

/* SCOM attention codes. */

#define _ATTN_CMD 0x07

#define _ATTN_ACK 0x06

#define _ATTN_NAK 0x15

/* SCOM message fields. */

#define _SCOM_MSG_OFS_ATTN 0x00

#define _SCOM_MSG_OFS_ADDR 0x01

#define _SCOM_MSG_OFS_CMD0 0x02

#define _SCOM_MSG_OFS_CMD1 0x03

#define _SCOM_MSG_OFS_CMD2 0x04

#define _SCOM_MSG_OFS_LEN 0x05

#define _SCOM_MSG_OFS_ICHK 0x06

#define _SCOM_MSG_OFS_DATA 0x07

#define _ "\r\n"

/*=======================================================================

Calculates and returns the inverse header checksum of the provided SCOM

message.

*/

unsigned char

getICHKH(unsigned char *pucSCOM)

{

unsigned char uc;

unsigned char ucICHKH;

/*========*/

ucICHKH=0;

for (uc=0;uc<=5;uc++)

ucICHKH+=pucSCOM[uc];

return ~ucICHKH;

}

/*=======================================================================

Calculates and returns the inverse data checksum of the provided SCOM

message.

*/

unsigned char

getICHKD(unsigned char *pucSCOM,unsigned char ucLen)

{

unsigned char uc;

unsigned char ucICHKD;

/*========*/

ucICHKD=0;

for (uc=_SCOM_MSG_OFS_DATA;uc<_SCOM_MSG_OFS_DATA+ucLen;uc++)

ucICHKD+=pucSCOM[uc];

return ~ucICHKD;

}

Advertising