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

📄 yxclass.cpp

📁 基于PC104平台
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                 File name: yxclass.cpp
//  This file define the functions of base module YX
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "yxclass.h"
/////////////////////////////////////////////////////////////////////////////
BOOLEAN issoe(INT8U portno);
BOOLEAN isyxbw(INT8U portno);
void getsoe(SOE1 *prt, BYTE portno);
void getyxbw(BYTE portno);
void insertsoe(SOE1 *ptr);
void insertyxbw(yx_bw_tt *ptr);

void CYx::yxinit()
{
  int i,j;
  first_board=TRUE;

  yxsource[0].start = 0;
  yxsource[0].end = datasource.board_yx;
  yxsource[1].start = 0;
  yxsource[1].end = 0;
  yxsource[2].start = 0;
  yxsource[2].end = 0;

	for (i = 0; i < SOEBUFSIZE; i++) {
		soe_flag[i] = startsoe[i] = FALSE;
		soetim[i] = 0;
	}

	soe_ctl.start = soe_ctl.next = soe_ctl.writeptr = 0;
	soe_ctl.size = SOEBUFSIZE;

	for (i = 0; i < MAXPORTNO; i++ )
		soe_ctl.count[i] = soe_ctl.readptr[i] = 0;
															// initlize soe buffer

	yx_bw_log.start = yx_bw_log.next = yx_bw_log.writeptr = 0;
	yx_bw_log.size = YXBWBUFSIZE;

	for (i = 0; i < MAXPORTNO; i++)
		yx_bw_log.count[i] = yx_bw_log.readptr[i] = 0;
															// initlize yxbw buffer
}

// get 8bit yx from yx board through 3724
INT8U CYx::Get8Yx(BYTE address,BYTE orderno)
{
	INT8U codeconv[4] = {YX14, YX24, YX34, YX44};
	int i;

	outportb(hardwareset[C3724].address + 1, address + codeconv[orderno]); // choose

	for (i = 0; i < 320; i++);						// must wait 2us for 8255
	INT8U x= (inportb(hardwareset[C3724].address));  // read 8bit yx
	return x;
}

void CYx::boardyxget()
{

	INT8U BoardAdd[] = {YXB0, YXB1, YXB2, YXB3, YXB4, YXB5, YXB6, YXB7,
							  YXB8, YXB9, YXBA, YXBB, YXBC, YXBD, YXBE, YXBF};
	INT16U BoardNo, yxin16bit;
	INT16U c3ayxloc, i, j, k;
	INT16U boardyxno, temp, test, orderno, diff;
	INT16U read_data;
	SOE1 tempsoe;
	yx_bw_tt tempyxbw;


	boardyxno = datasource.board_yx;
	temp = boardyxno / 32;
	if (boardyxno > (temp * 32)) temp++;
	if (temp > MAXYXBOARD) return;

	// get all yx board data
	for (BoardNo = 0; BoardNo < temp; BoardNo++) {
		c3ayxloc = BoardNo * 2;
		read_data = Get8Yx(BoardAdd[BoardNo], 0);    // first 8 bit
		read_data |= Get8Yx(BoardAdd[BoardNo], 1) << 8;// second 8 bit
		c3ayx[c3ayxloc++] = read_data;

		read_data = Get8Yx(BoardAdd[BoardNo], 2);    // third 8 bit
		read_data |= Get8Yx(BoardAdd[BoardNo], 3) << 8;// forth 8 bit
		c3ayx[c3ayxloc] = read_data;
	}

	yxin16bit = boardyxno / 16 + 1;
	if (first_board == FALSE) {
		for (i = 0; i < yxin16bit; i++) {
			if (c3ayx[i] != c3ayxold[i]) {	// yx status changed ?
				test = 0x01;
				diff = c3ayx[i] ^ c3ayxold[i]; // check which bit changed
				for (k = 0; k < 16; k++) {
					if (diff & test) {

						orderno = i * 16 + k;

						if (soe_flag[orderno] == TRUE) soe_flag[orderno] = FALSE;
						else soe_flag[orderno] = TRUE;
						if (startsoe[orderno] == FALSE) {

							startsoe[orderno] = TRUE;
							if (test & c3ayx[i]) keepsoe[orderno].status = 0xaa;  			// BW: 0->1
							else keepsoe[orderno].status = 0x55;					     		   // BW: 1->0

							keepsoe[orderno].orderno = orderno;

							struct date d;
                            struct time t;
                            getdate(&d);
                            gettime(&t);
				          	keepsoe[orderno].mil_second = t.ti_hund*10;
							keepsoe[orderno].second = t.ti_sec;
							keepsoe[orderno].minute = t.ti_min;
							keepsoe[orderno].hour = t.ti_hour;
							keepsoe[orderno].day = d.da_day;
							keepsoe[orderno].month = d.da_mon;
							keepsoe[orderno].year = d.da_year;        // get time

							keepyxbw[orderno].func_code = orderno / 32 + 0xf0;
							keepyxbw[orderno].yx1 = c3ayx[orderno / 32 * 2];
							keepyxbw[orderno].yx2 = c3ayx[orderno / 32 * 2 + 1];

						}
					}
				test<<=1;
			}
		}
	}
	for (i = 0; i < yxin16bit; i++)
		c3ayxold[i] = c3ayx[i];
	}

	for (i = 0; i < boardyxno; i++) {
		if (startsoe[i] == TRUE)
			if (soetim[i] < 50) soetim[i]++;  // yx qd time
			else {             // may
				if (soe_flag[i] == TRUE) {
					soe_flag[i] = startsoe[i] = FALSE;
					soetim[i] = 0;
					tempsoe.status = keepsoe[i].status;
					tempsoe.orderno = keepsoe[i].orderno;
					for ( j = 0; j < 8; j++ )
						tempsoe.send_status[j] = 3;
					tempsoe.time.mil_second = keepsoe[i].mil_second;
					tempsoe.time.second = keepsoe[i].second;
					tempsoe.time.minute = keepsoe[i].minute;
					tempsoe.time.hour = keepsoe[i].hour;
					tempsoe.time.day = keepsoe[i].day;
					tempsoe.time.month = keepsoe[i].month;
					tempsoe.time.year = keepsoe[i].year;         // get time
					tempyxbw.func_code = keepyxbw[i].func_code;
					tempyxbw.two_yx_word[0] = keepyxbw[i].yx1;
					tempyxbw.two_yx_word[1] = keepyxbw[i].yx2;
					for (j = 0; j < 8; j++)
						tempyxbw.send_count[j] = 3;
					insertsoe(&tempsoe);
					insertyxbw(&tempyxbw);
				}
				else {
					soe_flag[i] = FALSE;
					startsoe[i] = FALSE;
					soetim[i] = 0;
				}
			}
	}

	if (first_board == TRUE) {
		for (i = 0; i < yxin16bit; i++) c3ayxold[i] = c3ayx[i];
		first_board = FALSE;
	}																		// first sample no soe and bw
}

void insertsoe( SOE1 *ptr )
{
  int i;
  soe_ctl.soe_log[soe_ctl.writeptr] = *ptr;        // store user data
  soe_ctl.writeptr++;
  if( soe_ctl.writeptr >= soe_ctl.size ) soe_ctl.writeptr = 0;
												   // adjust writeptr
  for( i = 0 ; i < 10 ; i++ ) {
	soe_ctl.count[i]++;                            // count number
	while( soe_ctl.count[i] > soe_ctl.size ) {     // if overflow
	  soe_ctl.count[i]--;
	  soe_ctl.readptr[i]++;                        // drop lastest bw
	  if( soe_ctl.readptr[i] >= soe_ctl.size )
		soe_ctl.readptr[i] = 0;                    // adjust readptr
	}
  }
}



// judge having soe or not
BOOLEAN issoe(INT8U portno)
{
	if (soe_ctl.count[portno] == 0) {
		soe_ctl.readptr[portno] = soe_ctl.writeptr;
		return (FALSE);
	}
	else return (TRUE);
}

// get a soe from soe queue
void getsoe( SOE1 *ptr , BYTE portno )
{
  *ptr = soe_ctl.soe_log[soe_ctl.readptr[portno]]; // get user data

  soe_ctl.soe_log[soe_ctl.readptr[portno]].send_status[portno]--;
												   // send 3 times over ?
  if( soe_ctl.soe_log[soe_ctl.readptr[portno]].send_status[portno] == 0 ) {
	soe_ctl.count[portno]--;                     // increase yxbw amount
	soe_ctl.readptr[portno]++;                   // adjust readptr
	if( soe_ctl.readptr[portno] >= soe_ctl.size )
	  soe_ctl.readptr[portno] = 0;
  }
}


// insert a yxbw to yxbw queue
void insertyxbw(yx_bw_tt *ptr)
{
	int i;

	yx_bw_log.bw[yx_bw_log.writeptr].func_code = ptr->func_code;
	yx_bw_log.bw[yx_bw_log.writeptr].two_yx_word[0] = ptr->two_yx_word[0];
	yx_bw_log.bw[yx_bw_log.writeptr].two_yx_word[1] = ptr->two_yx_word[1];
	for (i = 0; i < MAXPORTNO; i++)        // store user data
		yx_bw_log.bw[yx_bw_log.writeptr].send_count[i] = 3;

	if (++yx_bw_log.writeptr >= yx_bw_log.size) yx_bw_log.writeptr = 0;
														// write pointer out of boundary
	for (i = 0; i < MAXPORTNO; i++) {
		yx_bw_log.count[i]++;                          // count number
		while (yx_bw_log.count[i] > yx_bw_log.size) {  // if buffer overflow
			yx_bw_log.count[i]--;
			yx_bw_log.readptr[i]++;								// drop latest soe
			if (yx_bw_log.readptr[i] >= yx_bw_log.size)
				yx_bw_log.readptr[i] = 0;                 // read pointer out of boundary
		}
	}
}

// judge having yxbw or not
BOOLEAN isyxbw(INT8U portno)
{
	if (yx_bw_log.count[portno] == 0) {
		yx_bw_log.readptr[portno] = yx_bw_log.writeptr;
		return (FALSE);
	}
	else return (TRUE);
}

// get a yxbw from yxbw queue
void getyxbw(yx_bw_tt *ptr, INT8U portno)
{
	int i;
	ptr->func_code = yx_bw_log.bw[yx_bw_log.readptr[portno]].func_code;
	ptr->two_yx_word[0] = yx_bw_log.bw[yx_bw_log.readptr[portno]].two_yx_word[0];
	ptr->two_yx_word[1] = yx_bw_log.bw[yx_bw_log.readptr[portno]].two_yx_word[1];
	for (i = 0; i < MAXPORTNO; i++)								// get user data
		ptr->send_count[i] = yx_bw_log.bw[yx_bw_log.readptr[portno]].send_count[i];

	yx_bw_log.bw[yx_bw_log.readptr[portno]].send_count[portno]--;
																			 // send 3 times over ?
	if (yx_bw_log.bw[yx_bw_log.readptr[portno]].send_count[portno] == 0) {
		yx_bw_log.count[portno]--;										// decrease yxbw amount
		if (++yx_bw_log.readptr[portno] >= yx_bw_log.size)
			yx_bw_log.readptr[portno] = 0;							// read pointer out of boundary
	}
}

void CYx::yxgetdeal()
{
	INT16U i;
	INT16U tempyx[MAXYXNO / 16];
	INT16U temp1, temp2, temp3;
	INT16U test1, test2, test3;

	memset(tempyx, 0, MAXYXNO / 8);

//	boardyxget();
	for (i = 0; i < datasource.board_yx; i++)	{
		temp1 = i;
		temp2 = temp1 / 16;						// yx int no
		temp3 = temp1 - temp2 * 16;			// bit no in yx int
		test1 = 0x01;
		test1 <<= temp3;							// bit no set
		test2 = ~test1;							// reverse

		temp1 = i / 16;							// prot_yx[]  int no
		temp3 = i - temp1 * 16;					// bit no
		test3 = 0x01;
		test3 <<= temp3;							// bit set

		if (c3ayx[temp1] & test3) tempyx[temp2] |= test1;
		else tempyx[temp2] &= test2;
	}

	for (i = 0; i < datasource.protect_yx; i++) {
		temp1 = i + datasource.board_yx;				// yx no in all yx
		temp2 = temp1 / 16;								// yx int no
		temp3 = temp1 - temp2 * 16;					// bit no in yx int
		test1 = 0x01;
		test1 <<= temp3;									// bit no set
		test2 = ~test1;									// reverse

		temp1 = i / 16;									// prot_yx[]  int no
		temp3 = i - temp1 * 16;							// bit no
		test3 = 0x01;
		test3 <<= temp3;									// bit set
		if (prot_yx[temp1] & test3) tempyx[temp2] |= test1;
		else tempyx[temp2] &= test2;
	}

	for (i = 0; i < datasource.zlp_yx; i++) {
		temp1 = i + datasource.board_yx+datasource.protect_yx;				// yx no in all yx
		temp2 = temp1 / 16;								// yx int no
		temp3 = temp1 - temp2 * 16;					// bit no in yx int
		test1 = 0x01;
		test1 <<= temp3;									// bit no set
		test2 = ~test1;									// reverse

		temp1 = i / 16;									// prot_yx[]  int no
		temp3 = i - temp1 * 16;	    						// bit no
		test3 = 0x01;
		test3 <<= temp3;									// bit set
		if (zlp_yx[i/16] & test3) tempyx[temp2] |= test1;
		else tempyx[temp2] &= test2;
	}

	for (i = 0; i < MAXYXNO / 16; i++) yx_info.yx_value[i] = tempyx[i];

	for (i = 0; i < MAXYXNO / 16; i++) port_yx[i] = tempyx[i];
}

⌨️ 快捷键说明

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