⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message.cpp

📁 1553B板卡的源代码,只有购买板卡才能得到的好资料
💻 CPP
字号:
#include "Message.h"

STRUCT_MSG_VECTOR g_MsgsVec;
STRUCT_MSG_VECTOR g_TempMsgsVec;
STRUCT_MSG g_TempMsg;
STRUCT_FRM_CONF g_FrameConf;
SFRAME_STRUCT g_Frame;
STRUCT_BC_RECV_MSG g_RMsg;

STRUCT_RT_MSG g_TempRTMsgs;
STRUCT_RT_MSG g_RTMsgs;
RT_TX_MODE_STRUCT g_RTTxMode;
RT_STATUS_WORD_STRUCT g_RTStatusWord[RT_ADDR_MAX];
RMSG_STRUCT g_RTRxMsg;
RMSG_STRUCT g_RTTxMsg;

RMSG_STRUCT g_MTMsg;


BYTE msgChangeType = 0;
INT modifyid=-1;

int MsgClear(LPSTRUCT_MSG_VECTOR pVec)
{
	int i=0, j=0;

	pVec->num = 0;
	for (i=0; i<MSG_MAX; i++)
	{
		memset(pVec->msgAry[i].msgname, 0, MSGNAME_MAX);
		pVec->msgAry[i].msg.ChannelSelect = 1; // default to channel A
		pVec->msgAry[i].msg.InterMSGGapTime = 0;
		pVec->msgAry[i].msg.MSGFormat = 0; // default to BC-RT
		pVec->msgAry[i].msg.RetryEnable = FALSE;
		pVec->msgAry[i].blocklen = 0;

		for (j = 0; j < MSGBLOCKSIZE; j++)
		{
			pVec->msgAry[i].msg.MSGBlock[j] = 0;
		}
	}
	return 0;
}

int MsgAdd(LPSTRUCT_MSG_VECTOR pVec, LPSTRUCT_MSG pMsg, UCHAR isForced)
{
	int i=0, j=0, k=0;
	int rt=0;
	int idx=0;
	BOOL isExist=FALSE;
	char sdest[MSGNAME_MAX];
	char ssour[MSGNAME_MAX];


	if(pMsg->msgname == NULL || strlen(pMsg->msgname) <= 0)
		return -3;

	idx = pVec->num;

	//	Check Queue
	//
	memset(ssour, 0, sizeof(ssour));
	strcpy(ssour, pMsg->msgname);

	k=0;
	for (i = 0; i < idx; i++)
	{
		memset(sdest, 0, sizeof(sdest));
		strcpy(sdest, pVec->msgAry[i].msgname);

		if (strcmp(ssour, sdest)==0)
		{
			i = idx;
			isExist = TRUE;
		}
		k++;
	}
	k--;

	if (isExist)
	{ // need modify
		if (isForced == 0)
		{
			return -2; // needn't modify, do nothing ! same Message Error
		}
		else
		{
			idx = k; // modify, count no change
			rt = idx;
		}
	}
	else
	{ // for add
		if (pVec->num >= MSG_MAX) // check Message Count
		{
			return 0; // ! Message Overflow Error
		}
		(pVec->num)++; // add message, count++
		rt = pVec->num;
	}

	memset(pVec->msgAry[idx].msgname, 0, MSGNAME_MAX); // message name
	strcpy(pVec->msgAry[idx].msgname, pMsg->msgname);

	pVec->msgAry[idx].msg.ChannelSelect = pMsg->msg.ChannelSelect;
	pVec->msgAry[idx].msg.InterMSGGapTime = pMsg->msg.InterMSGGapTime;
	pVec->msgAry[idx].msg.MSGFormat = pMsg->msg.MSGFormat;
	pVec->msgAry[idx].msg.RetryEnable = pMsg->msg.RetryEnable;
	pVec->msgAry[idx].blocklen = pMsg->blocklen;

	for (i = 0; i < MSGBLOCKSIZE; i++) // block data
	{
		pVec->msgAry[idx].msg.MSGBlock[i] = pMsg->msg.MSGBlock[i];
	}

	return rt;
}

INT MsgDel(LPSTRUCT_MSG_VECTOR pVec, USHORT msgid)
{

	int i=0, j=0, k=0;
	int idx=msgid;
	int len=0;


	len = pVec->num;

	if (len==0)
	{
		return -2; // ! message length error
	}

	if (idx > len)
	{
		return -3; // ! idx > len
	}


	//	delete message
	//
	memset(pVec->msgAry[idx].msgname, 0, MSGNAME_MAX); // message name
	pVec->msgAry[idx].msg.ChannelSelect = 1;
	pVec->msgAry[idx].msg.InterMSGGapTime = 0;
	pVec->msgAry[idx].msg.MSGFormat = 0;
	pVec->msgAry[idx].msg.RetryEnable = 0;
	pVec->msgAry[idx].blocklen = 0;

	for (i = 0; i < MSGBLOCKSIZE; i++) // block data
	{
		pVec->msgAry[idx].msg.MSGBlock[i] = 0;
	}

	//	configure queue
	//
	if (idx != (MSG_MAX-1))
	{
		for (i = idx; i < len; i++)
		{
			// message name
			for (j = 0; j < MSGNAME_MAX; j++)
			{
				pVec->msgAry[i].msgname[j] = pVec->msgAry[i+1].msgname[j];
			}

			pVec->msgAry[i].msg.ChannelSelect = pVec->msgAry[i+1].msg.ChannelSelect;
			pVec->msgAry[i].msg.InterMSGGapTime = pVec->msgAry[i+1].msg.InterMSGGapTime;
			pVec->msgAry[i].msg.MSGFormat = pVec->msgAry[i+1].msg.MSGFormat;
			pVec->msgAry[i].msg.RetryEnable = pVec->msgAry[i+1].msg.RetryEnable;

			pVec->msgAry[i].blocklen = pVec->msgAry[i+1].blocklen;

			for (j = 0; j < MSGBLOCKSIZE; j++) // block data
			{
				pVec->msgAry[i].msg.MSGBlock[j] = pVec->msgAry[i+1].msg.MSGBlock[j];
			}
		}
	}
	(pVec->num)--;
	return pVec->num;
}

int Msg_isExist(LPSTRUCT_MSG_VECTOR pVec, const char *mname)
{
	int len=0;
	int i=0;
	int idx=0;
	BOOL isExist=FALSE;

	if ((mname==NULL) || (strlen(mname)<=0))
	{
		return -3; // ! message name is Error
	}

	//	find message by Name
	//
	len = pVec->num;
	idx = 0;
	for (i=0; i<len; i++)
	{
		if (strcmp(mname, pVec->msgAry[i].msgname) == 0)
		{
			i = len;
			isExist = TRUE;
		}
		else
		{
			idx++;
		}
	}
	if (!isExist)
	{
		return -1; // ! message is not Exist
	}
	return idx;
}



//
//	get RT address from command word
//
unsigned short OwnRTAddr(unsigned short cw)
{
	unsigned short rt;

	rt = (cw>>11)&0x001f;

	return rt;
}

//
//	get T/R from command word
//
unsigned short OwnTR(unsigned short cw)
{
	unsigned short rt;

	rt = (cw>>10)&0x0001;

	return rt;
}

//
//	get Sub Address from command word
//
unsigned short OwnSubAddr(unsigned short cw)
{
	unsigned short rt;

	rt = (cw>>5)&0x001f;

	return rt;
}

//
//	get Word Count from command word
//
unsigned short OwnWordCount(unsigned short cw)
{
	unsigned short rt;

	rt = cw&0x001f;

	return rt;
}

//
//	get Mode Code from command word
//
unsigned short OwnModeCode(unsigned short cw)
{
	unsigned short rt;

	rt = cw&0x001f;

	return rt;
}


//
//	set RT address from command word
//
unsigned short SetRTAddr(unsigned short cw, unsigned short val)
{
	unsigned short rt=cw&0x07ff;
	unsigned short us=val&0x001f;

	us = us<<11;

	rt = rt|us;

	return rt;
}

//
//	set T/R from command word
//
unsigned short SetTR(unsigned short cw, unsigned short val)
{
	unsigned short rt=cw&0xfbff;

	if (val!=0)
	{
		rt = rt|0x0400;
	}

	return rt;
}

//
//	set Sub Address from command word
//
unsigned short SetSubAddr(unsigned short cw, unsigned short val)
{
	unsigned short rt=cw&0xfc1f;
	unsigned short us=val&0x001f;

	us = us<<5;

	rt = rt|us;

	return rt;
}

//
//	set Word Count from command word
//
unsigned short SetWordCount(unsigned short cw, unsigned short val)
{
	unsigned short rt=cw&0xffe0;
	unsigned short us=val&0x001f;

	rt = rt|us;

	return rt;
}

//
//	set Mode Code from command word
//
unsigned short SetModeCode(unsigned short cw, unsigned short val)
{
	unsigned short rt=cw&0xffe0;
	unsigned short us=val&0x001f;

	rt = rt|us;

	return rt;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -