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

📄 processnzctd.cpp

📁 这是一个变电站的监控程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	Event.month = (BYTE)CurTime.wMonth;
	Event.year = CurTime.wYear;

	Event.Recms = CurTime.wMilliseconds % 100;
	Event.Rechundms = CurTime.wMilliseconds/100;
	Event.Recseconds = (BYTE)CurTime.wSecond;
	Event.Recminute = (BYTE)CurTime.wMinute;
	Event.Rechour = (BYTE)CurTime.wHour;
	Event.Recday = (BYTE)CurTime.wDay;

	Event.rtuno = RtuNo;
	Event.yxno = RecBuf[9] + (RecBuf[10] & 0xf)*256;
	Event.cause = 1;
	Event.type = 1;
	Event.state = (RecBuf[10] & 0x80) ? 1 : 0;
	NonceInfoWord += 6;
	SOEInfo[0] = RecBuf[9];
	SOEInfo[1] = RecBuf[10];
	SOEInfo[2] = RecBuf[1];
	SOEInfo[3] = RecBuf[2];
	SOEInfo[4] = RecBuf[3];
	CurEventP = Events.EventBuf + Events.EventNum;
	memcpy(CurEventP,&Event,sizeof(FERTEVENT));
	if(++Events.EventNum>=MAX_EVENT_NUM)
		Events.EventNum=0;
}

void NZ_CDTZF(int ChNo)
{
	int RtuNo = Channels[ChNo].ChRtuNo[0];
	if(CDTZF_Receive(ChNo))
	{
		Rtus[RtuNo].bWorking = TRUE;
		Channels[ChNo].bWorking = true;
	}
	CDTZF_Send(ChNo);
}

bool NZ_CDTZF_Receive(int ChNo)
{
	int InLen = MoxaBufIqueue(ChNo);
	int RtuNo = Channels[ChNo].ChRtuNo [0];
	if (InLen<6) return false;
	Rtus[RtuNo].RecFrameSum += 1;
	MoxaBufRead(ChNo,&Rtus[RtuNo].RecBuf[0],6);
	Rtus[RtuNo].RecBufPtr=6;
	Rtus[RtuNo].RecLen=6;
	Rtus[RtuNo].bReceiveCanDisp = TRUE;	
	return true;
}

void NZ_CDTZF_Send(int ChNo)
{//发码顺序 ABACABACABACD1AD2
	static int iCurSort = 0;//指明当前发码顺序处于哪一个位置
	int RtuNo = Channels[ChNo].ChRtuNo [0];
	BYTE *SendBuf = &Rtus[RtuNo].TXBuf [0];
	if (Rtus[RtuNo].SoePtr != Rtus[RtuNo].SoeSendPtr )//have soe event and yx change
	{//send f4
		for (int i = 0;i < 6;i++) SendBuf[i] = Rtus[RtuNo].SynWord [i + 1];
		int iCount = (Rtus[RtuNo].YxNum + 31) / 32;//信息字个数
		SendBuf[6] = 0x71;
		SendBuf[7] = 0xf4;
		SendBuf[8] = iCount;
		SendBuf[9] = 0;
		SendBuf[10] = 0;
		SendBuf[11] = CDT_CheckCRC(&SendBuf[6]);
		for (i = 0;i < iCount;i++)
		{
			SendBuf[12 + i * 6] = Rtus[RtuNo].ProtocolStamp[1] + i;
			for (int j = 0;j < 4;j++)
			{
				BYTE YxValue = 0;
				for (int k = 0;k < 8;k++)
				{
					int iDian = i * 32 + j * 8 + k;//yx dian
					YxValue |= ((Rtus[RtuNo].YxValue [iDian] & 0x1) << k);
				}
				SendBuf[12 + i * 6 + j + 1] = YxValue;
			}
			SendBuf[12 + i * 6 + 5] = CDT_CheckCRC(&SendBuf[12 + i * 6]);
		}
		Rtus[RtuNo].TXBufPtr = 12 + iCount * 6;
		Rtus[RtuNo].TXLen=Rtus[RtuNo].TXBufPtr;
		Rtus[RtuNo].bSendCanDisp=TRUE;
		MoxaBufWrite(ChNo,(char*)&Rtus[RtuNo].TXBuf[0],Rtus[RtuNo].TXBufPtr);
		Rtus[RtuNo].TXBufPtr=0;
		int iDelay = (int)((float)Rtus[RtuNo].TXLen / (Channels[ChNo].Baud / 14) * 1000);//ms
		Sleep(iDelay);
		//send soe
		int iSoeNum = Rtus[RtuNo].SoePtr - Rtus[RtuNo].SoeSendPtr ;
		int iPtr = Rtus[RtuNo].SoeSendPtr ;
		for (i = 0;i < 6;i++) SendBuf[i] = Rtus[RtuNo].SynWord [i + 1];
		SendBuf[6] = 0x71;
		SendBuf[7] = 0x26;
		SendBuf[8] = iSoeNum * 6;
		SendBuf[9] = 0;
		SendBuf[10] = 0;
		SendBuf[11] = CDT_CheckCRC(&SendBuf[6]);
		for (i = 0;i < iSoeNum;i++)
		{
			for (int j = 0;j < 3;j++)
			{
				SendBuf[12 + i * 36 + j * 12] = 0x80;
				SendBuf[12 + i * 36 + j * 12 + 1] = Rtus[RtuNo].SoeEvent [iPtr].SoeTime.wMilliseconds % 256;
				SendBuf[12 + i * 36 + j * 12 + 2] = Rtus[RtuNo].SoeEvent [iPtr].SoeTime.wMilliseconds / 256;
				SendBuf[12 + i * 36 + j * 12 + 3] = (BYTE)Rtus[RtuNo].SoeEvent [iPtr].SoeTime.wSecond;
				SendBuf[12 + i * 36 + j * 12 + 4] = (BYTE)Rtus[RtuNo].SoeEvent [iPtr].SoeTime.wMinute;
				SendBuf[12 + i * 36 + j * 12 + 5] = CDT_CheckCRC(&SendBuf[12 + i * 36 + j * 12]);
				SendBuf[12 + i * 36 + j * 12 + 6] = 0x81;
				SendBuf[12 + i * 36 + j * 12 + 7] = (BYTE)Rtus[RtuNo].SoeEvent [iPtr].SoeTime.wHour;
				SendBuf[12 + i * 36 + j * 12 + 8] = (BYTE)Rtus[RtuNo].SoeEvent [iPtr].SoeTime.wDay;
				SendBuf[12 + i * 36 + j * 12 + 9] = Rtus[RtuNo].SoeEvent [iPtr].YxNo % 256;
				SendBuf[12 + i * 36 + j * 12 + 10] = ((Rtus[RtuNo].SoeEvent [iPtr].YxNo / 256) & 0xf) 
					+ ((Rtus[RtuNo].SoeEvent [iPtr].YxState & 0x1) << 7);
				SendBuf[12 + i * 36 + j * 12 + 11] = CDT_CheckCRC(&SendBuf[12 + i * 36 + j * 12 + 6]);
			}
		}
		Rtus[RtuNo].TXBufPtr = 12 + iSoeNum * 36;
		Rtus[RtuNo].TXLen=Rtus[RtuNo].TXBufPtr;
		Rtus[RtuNo].bSendCanDisp=TRUE;
		MoxaBufWrite(ChNo,(char*)&Rtus[RtuNo].TXBuf[0],Rtus[RtuNo].TXBufPtr);
		Rtus[RtuNo].TXBufPtr=0;
		Rtus[RtuNo].SoeSendPtr = Rtus[RtuNo].SoePtr;
	}
	else//按顺序发送
	{
		switch(iCurSort)
		{
		case 0://A,first 10 yc 
		case 2:
		case 4:
		case 6:
		case 8:
		case 10:
		case 13:
			{
				for (int i = 0;i < 6;i++) SendBuf[i] = Rtus[RtuNo].SynWord [i + 1];
				int iCount = 10 / 2;//信息字个数
				if (Rtus[RtuNo].YcNum < 10)
					iCount = (Rtus[RtuNo].YcNum + 1) / 2;
				SendBuf[6] = 0x71;
				SendBuf[7] = 0x61;
				SendBuf[8] = iCount;
				SendBuf[9] = 0;
				SendBuf[10] = 0;
				SendBuf[11] = CDT_CheckCRC(&SendBuf[6]);
				for (i = 0;i < iCount;i++)
				{
					SendBuf[12 + i * 6] = Rtus[RtuNo].ProtocolStamp[0] + i;
					int YcValue = (int)(Rtus[RtuNo].YcValue [2 * i] * 10) % 2048;
					if (YcValue >= 0)
					{
						SendBuf[12 + i * 6 + 1] = (int)YcValue % 256;
						SendBuf[12 + i * 6 + 2] = (int)(YcValue / 256) & 0x7;
					}
					else
					{
						WORD YcVal = YcValue + 2048;
						SendBuf[12 + i * 6 + 1] = YcVal % 256;
						SendBuf[12 + i * 6 + 2] = ((YcVal / 256) & 0x7) | 0x8;
					}
					YcValue = (int)(Rtus[RtuNo].YcValue [2 * i + 1] * 10) % 2048;
					if (YcValue >= 0)
					{
						SendBuf[12 + i * 6 + 3] = (int)YcValue % 256;
						SendBuf[12 + i * 6 + 4] = (int)(YcValue / 256) & 0x7;
					}
					else
					{
						WORD YcVal = YcValue + 2048;
						SendBuf[12 + i * 6 + 3] = YcVal % 256;
						SendBuf[12 + i * 6 + 4] = ((YcVal / 256) & 0x7) | 0x8;
					}
					SendBuf[12 + i * 6 + 5] = CDT_CheckCRC(&SendBuf[12 + i * 6]);
				}
				Rtus[RtuNo].TXBufPtr = 12 + iCount * 6;
				Rtus[RtuNo].TXLen=Rtus[RtuNo].TXBufPtr;
				Rtus[RtuNo].bSendCanDisp=TRUE;
				MoxaBufWrite(ChNo,(char*)&Rtus[RtuNo].TXBuf[0],Rtus[RtuNo].TXBufPtr);
				Rtus[RtuNo].TXBufPtr=0;
			}
			break;
		case 1://B 20 yc
		case 5:
		case 9:
			{
				for (int i = 0;i < 6;i++) SendBuf[i] = Rtus[RtuNo].SynWord [i + 1];
				int iCount = 20 / 2;//信息字个数
				if (Rtus[RtuNo].YcNum < 30)
					iCount = (Rtus[RtuNo].YcNum - 10 + 1) / 2;
				SendBuf[6] = 0x71;
				SendBuf[7] = 0xc2;
				SendBuf[8] = iCount;
				SendBuf[9] = 0;
				SendBuf[10] = 0;
				SendBuf[11] = CDT_CheckCRC(&SendBuf[6]);
				for (i = 0;i < iCount;i++)
				{
					SendBuf[12 + i * 6] = Rtus[RtuNo].ProtocolStamp[0] + 5 + i;
					int YcValue = (int)(Rtus[RtuNo].YcValue [2 * i + 10] * 10) % 2048;
					if (YcValue >= 0)
					{
						SendBuf[12 + i * 6 + 1] = (int)YcValue % 256;
						SendBuf[12 + i * 6 + 2] = (int)(YcValue / 256) & 0x7;
					}
					else
					{
						WORD YcVal = YcValue + 2048;
						SendBuf[12 + i * 6 + 1] = YcVal % 256;
						SendBuf[12 + i * 6 + 2] = ((YcVal / 256) & 0x7) | 0x8;
					}
					YcValue = (int)(Rtus[RtuNo].YcValue [2 * i + 10 + 1] * 10) % 2048;
					if (YcValue >= 0)
					{
						SendBuf[12 + i * 6 + 3] = (int)YcValue % 256;
						SendBuf[12 + i * 6 + 4] = (int)(YcValue / 256) & 0x7;
					}
					else
					{
						WORD YcVal = YcValue + 2048;
						SendBuf[12 + i * 6 + 3] = YcVal % 256;
						SendBuf[12 + i * 6 + 4] = ((YcVal / 256) & 0x7) | 0x8;
					}
					SendBuf[12 + i * 6 + 5] = CDT_CheckCRC(&SendBuf[12 + i * 6]);
				}
				Rtus[RtuNo].TXBufPtr = 12 + iCount * 6;
				Rtus[RtuNo].TXLen=Rtus[RtuNo].TXBufPtr;
				Rtus[RtuNo].bSendCanDisp=TRUE;
				MoxaBufWrite(ChNo,(char*)&Rtus[RtuNo].TXBuf[0],Rtus[RtuNo].TXBufPtr);
				Rtus[RtuNo].TXBufPtr=0;
			}
			break;
		case 3://C
		case 7:
		case 11:
			{
				for (int i = 0;i < 6;i++) SendBuf[i] = Rtus[RtuNo].SynWord [i + 1];
				int iCount = 0;//信息字个数
				if (Rtus[RtuNo].YcNum > 30)
					iCount = (Rtus[RtuNo].YcNum - 30 + 1) / 2;
				SendBuf[6] = 0x71;
				SendBuf[7] = 0xb3;
				SendBuf[8] = iCount;
				SendBuf[9] = 0;
				SendBuf[10] = 0;
				SendBuf[11] = CDT_CheckCRC(&SendBuf[6]);
				for (i = 0;i < iCount;i++)
				{
					SendBuf[12 + i * 6] = Rtus[RtuNo].ProtocolStamp[0] + 15 + i;
					int YcValue = (int)(Rtus[RtuNo].YcValue [2 * i + 30] * 10) % 2048;
					if (YcValue >= 0)
					{
						SendBuf[12 + i * 6 + 1] = (int)YcValue % 256;
						SendBuf[12 + i * 6 + 2] = (int)YcValue & 0x7;
					}
					else
					{
						WORD YcVal = YcValue + 2048;
						SendBuf[12 + i * 6 + 1] = YcVal % 256;
						SendBuf[12 + i * 6 + 2] = ((YcVal / 256) & 0x7) | 0x8;
					}
					YcValue = (int)(Rtus[RtuNo].YcValue [2 * i + 30 + 1] * 10) % 2048;
					if (YcValue >= 0)
					{
						SendBuf[12 + i * 6 + 3] = (int)YcValue % 256;
						SendBuf[12 + i * 6 + 4] = (int)(YcValue / 256) & 0x7;
					}
					else
					{
						WORD YcVal = YcValue + 2048;
						SendBuf[12 + i * 6 + 3] = YcVal % 256;
						SendBuf[12 + i * 6 + 4] = ((YcVal / 256) & 0x7) | 0x8;
					}
					SendBuf[12 + i * 6 + 5] = CDT_CheckCRC(&SendBuf[12 + i * 6]);
				}
				Rtus[RtuNo].TXBufPtr = 12 + iCount * 6;
				Rtus[RtuNo].TXLen=Rtus[RtuNo].TXBufPtr;
				Rtus[RtuNo].bSendCanDisp=TRUE;
				MoxaBufWrite(ChNo,(char*)&Rtus[RtuNo].TXBuf[0],Rtus[RtuNo].TXBufPtr);
				Rtus[RtuNo].TXBufPtr=0;
			}
			break;
		case 12://D1
			{
				for (int i = 0;i < 6;i++) SendBuf[i] = Rtus[RtuNo].SynWord [i + 1];
				int iCount = (Rtus[RtuNo].YxNum + 31) / 32;//信息字个数
				SendBuf[6] = 0x71;
				SendBuf[7] = 0xf4;
				SendBuf[8] = iCount;
				SendBuf[9] = 0;
				SendBuf[10] = 0;
				SendBuf[11] = CDT_CheckCRC(&SendBuf[6]);
				for (i = 0;i < iCount;i++)
				{
					SendBuf[12 + i * 6] = Rtus[RtuNo].ProtocolStamp[1] + i;
					for (int j = 0;j < 4;j++)
					{
						BYTE YxValue = 0;
						for (int k = 0;k < 8;k++)
						{
							int iDian = i * 32 + j * 8 + k;//yx dian
							YxValue |= ((Rtus[RtuNo].YxValue [iDian] & 0x1) << k);
						}
						SendBuf[12 + i * 6 + j + 1] = YxValue;
					}
					SendBuf[12 + i * 6 + 5] = CDT_CheckCRC(&SendBuf[12 + i * 6]);
				}
				Rtus[RtuNo].TXBufPtr = 12 + iCount * 6;
				Rtus[RtuNo].TXLen=Rtus[RtuNo].TXBufPtr;
				Rtus[RtuNo].bSendCanDisp=TRUE;
				MoxaBufWrite(ChNo,(char*)&Rtus[RtuNo].TXBuf[0],Rtus[RtuNo].TXBufPtr);
				Rtus[RtuNo].TXBufPtr=0;
			}
			break;
		case 14://D2
			break;
		}
		if (iCurSort++ > 14) iCurSort = 0;
		int iDelay = (int)((float)Rtus[RtuNo].TXLen / (Channels[ChNo].Baud / 14) * 1000);//ms
		Sleep(iDelay);
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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