📄 ykclass.cpp
字号:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// File name: DMU_YK.CPP
// This file define the functions of base module YK
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "ykclass.h"
void CYk::ykinit()
{
int i;
ykoper.ykcmdint=YKINONE;
ykoper.preseterr=YKPNONE;
ykoper.ykstate=YKSNONE;
ykoper.ykcheckresult=YKRNONE;
ykoper.ykfrom=YKFNONE;
ykoper.ykexeman=YKMNONE;
pdis.state=PNONE;
for(i=0;i<10;i++)
ykret.ykretflag[i]=FALSE;
}//void CYk::ykinit()
void CYk::ykdistinguish()
{
if (ykoper.ykcmdint==YKINONE || ykoper.ykstate!=YKSNONE) return;
// valid check
if ((ykoper.ykcmdint!=YKICLOSE && ykoper.ykcmdint!=YKITRIP)
|| datasource.total_yk<=0 || ykoper.ykobj>255 || ykoper.ykobj<0) {
ykoper.ykcmdint=YKINONE;
ykoper.preseterr=YKPERROR;
return;
}
if (datasource.board_yk>0 && ykoper.ykobj<datasource.board_yk) {
ykoper.ykexeman=YKMC3A;
pdis.state=PPRESET;
} // judge this yk operation in board
if (datasource.protect_yk>0 && ykoper.ykobj>=datasource.board_yk
&& ykoper.ykobj < (datasource.board_yk+datasource.protect_yk)) {
ykoper.ykexeman=YKMCOM;
pdis.state=PCOMPRE;
} // judge this yk operation in lfp
ykoper.ykstate=YKSPRESET;
ykoper.ykcmdint=YKINONE;
}
void CYk::ykc3apreset()
{
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
&&(pdis.state==PPRESET))
{
int boardno;
int yknoinboard;
int operation;
int ykboardaddr[8]={YKB1,YKB2,YKB3,YKB4,YKB5,YKB6,YKB7,YKB8};
boardno=ykoper.ykobj/16;
yknoinboard=ykoper.ykobj-boardno*16;
if(ykoper.ykcmd==YKCCLOSE)
operation=C3AHJ;
else
operation=C3ATJ; //+1//
outportb(hardwareset[C3724].address+5,ykboardaddr[boardno]+yknoinboard);//Give address of XJ(01--16)
outportb(hardwareset[C3724].address+6,operation);//Give one of the operations(HJ,TJ,ZJ)
// After send a command must wait a while and the readback and check
// so I make delay(4); but because delay will make CPU waiting so I use TIMER_INT
pdis.state=PFORRD;
ykoper.timer=0;
ykoper.timerlimit=1;
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
}//void CYk::ykc3apreset()
void CYk::ykc3aforread()
{
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
&&(pdis.state==PFORRD)&&(ykoper.timer>ykoper.timerlimit))
{
int operation;
int byteaddr;
if(ykoper.ykcmd==YKCCLOSE)
operation=C3AHJ;
else
operation=C3ATJ;
if((ykoper.ykobj-ykoper.ykobj/16*16)<=0x07)
byteaddr=YK07CODE;
else
byteaddr=YK8FCODE;
outportb(hardwareset[C3724].address+6,operation&byteaddr); //for readback
//Give address of 74LS240's: one of the operation,0J-7J,8J-15J
//for(i=0;i<150;i++);
//After send a command must wait a while and the readback and check
//before I make delay(1); but because delay will make CPU waiting // so I use TIMER_INT
pdis.state=PRDBACK;
ykoper.timer=0;
ykoper.timerlimit=1;
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
}//void CYk::ykc3aforread()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CYk::ykc3areadback()
{
//Wait some time I can use for(150) or delay(1)
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
&&(pdis.state==PRDBACK)&&(ykoper.timer>ykoper.timerlimit))
{
int operation;
int byteaddr;
int x;
if(ykoper.ykcmd==YKCCLOSE)
operation=C3AHJ;
else
operation=C3ATJ;
x=inportb(hardwareset[C3724].address+4);//+0x02); //Readback and test operation
pdis.readobj=x;
byteaddr=YKSTATECODE;
outportb(hardwareset[C3724].address+6,operation&byteaddr);
//Give address of 74LS240's :one of the operation,0J-7J,8J-15J
//for(i=0;i<150;i++);
//After send a command must wait a while and the readback and check
//so I make delay(1); but because delay will make CPU waiting so I use TIMER_INT
pdis.state=PCHECK;
ykoper.timer=0;
ykoper.timerlimit=1;
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
}//void CYk::ykc3areadback()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CYk::ykc3acheck()
{
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
&&(pdis.state==PCHECK)&&(ykoper.timer>ykoper.timerlimit))
{
int i;
int readoper;
int test=0x01;
int yknoinbyte;
//Wait some time I can use for(150) or delay(1)
readoper=inportb(hardwareset[C3724].address+4)&0x07;
yknoinbyte=ykoper.ykobj-ykoper.ykobj/16*16;
if(yknoinbyte>0x07)
yknoinbyte-=0x08;
test<<=yknoinbyte;
test=~test;
test&=0xff;
if(((ykoper.ykcmd==YKCCLOSE)&&(readoper!=0x05))
||((ykoper.ykcmd==YKCTRIP)&&(readoper!=0x06))||(pdis.readobj^test))
{
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
ykoper.timer=0;
ykoper.timerlimit=0;
if(ykoper.ykfrom==YKFWIN)
{
ykoper.ykcheckresult=YKRERROR;
ykop.checkresult=YKRERROR;
}//if(ykoper.ykfrom==YKFWIN)
else//else
{
ykoper.ykcheckresult=YKRNONE;
ykop.checkresult=YKRNONE;
}//else
pdis.state=PNONE;
ykret.ykretobj=ykoper.ykobj;
ykret.ykretcmd=0xff;
if(ykoper.ykfrom<=YKFP8)
if(port_set[ykoper.ykfrom].protocol==NEW_BB_CDT)
ykret.ykretflag[ykoper.ykfrom]=TRUE;
}//if(((ykoper.ykcmd==YKCCLOSE)&&(readoper!=0x05))
else//else1
{
ykoper.ykstate=YKSEXEC;
ykoper.timer=0;
ykoper.timerlimit=datasource.yk_escape_time * 18;
ykoper.ykcheckresult=YKROK;
ykop.checkresult=YKROK;
pdis.state=PC3AEXEC;
ykret.ykretobj=ykoper.ykobj;
ykret.ykretcmd=ykoper.ykcmd;
if(ykoper.ykfrom<=YKFP8)
if(port_set[ykoper.ykfrom].protocol==NEW_BB_CDT)
ykret.ykretflag[ykoper.ykfrom]=TRUE;
}//else1
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSPRESET)
}//void CYk::ykc3acheck()
void CYk::ykc3aexec()
{
int operation;
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
&&(pdis.state==PC3AEXEC)&&(ykoper.timer<ykoper.timerlimit)
&&(ykoper.ykcmdint==YKIEXEC))//EXEC WAIT AND ESC
{
ykoper.ykcmdint=YKINONE;
ykoper.ykstate=YKSESC;
ykoper.timer=0;
if(ykoper.ykcmd==YKCCLOSE)
ykoper.timerlimit=yk_time[ykoper.ykobj][0];
else
ykoper.timerlimit=yk_time[ykoper.ykobj][1];
ykoper.timerlimit*=1000;
ykoper.timerlimit/=55;
pdis.state=PC3AESC;
if(ykoper.ykcmd==YKCCLOSE)
operation=C3AHJ;
else
operation=C3ATJ;
operation|=C3AZJ;
outportb(hardwareset[C3724].address+6,operation);//Give one of the operations(HJ,TJ,ZJ)
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
&&(pdis.state==PC3AEXEC)&&(ykoper.timer<ykoper.timerlimit)
&&(ykoper.ykcmdint==YKIESC)) //MUST ESC
{
ykoper.ykcmdint=YKINONE;
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
ykoper.timer=0;
ykoper.timerlimit=0;
pdis.state=PNONE;
outportb(hardwareset[C3724].address+5,0x00);//Give all the 244 disabled and make (HJ TJ ZJ)=0
outportb(hardwareset[C3724].address+6,0x8f);//Give address of XJ(01--16)
//put the address on board8 so you can use the address board8 as the YK board
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
&&(pdis.state==PC3AEXEC)&&(ykoper.timer>ykoper.timerlimit)
&&(ykoper.ykcmdint==YKINONE))
{
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
ykoper.timer=0;
ykoper.timerlimit=0;
pdis.state=PNONE;
//ykoper.ykcheckresult=YKRTOUT;
ykoper.ykcmdint=YKINONE;
ykoper.ykcheckresult=YKRNONE;
ykop.checkresult=YKRTOUT;
outportb(hardwareset[C3724].address+5,0x00);//Give all the 244 disabled and make (HJ TJ ZJ)=0
outportb(hardwareset[C3724].address+6,0x8f);//Give address of XJ(01--16)
//put the address on board8 so you can use the address board8 as the YK board
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
}//void CYk::ykc3aexec()
void CYk::ykc3aesc()
{
if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSESC)
&&(pdis.state==PC3AESC)&&(ykoper.timer>ykoper.timerlimit)
&&(ykoper.ykcmdint==YKINONE))//after exec esc
{
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
ykoper.timer=0;
ykoper.timerlimit=0;
pdis.state=PNONE;
outportb(hardwareset[C3724].address+5,0x00);//Give all the 244 disabled and make (HJ TJ ZJ)=0
outportb(hardwareset[C3724].address+6,0x8f);//Give address of XJ(01--16)
}//if((ykoper.ykexeman==YKMC3A)&&(ykoper.ykstate==YKSEXEC)
}//void CYk::ykc3aesc()
void CYk::comykpreset()
{
if (ykoper.ykexeman == YKMCOM && pdis.state == PCOMPRE
&& ykoper.ykstate == YKSPRESET) {
pdis.state = PCOMCHECK;
ykoper.timer = 0;
ykoper.timerlimit = 30; // about 1.7s
comyk_info.yk_order = ykoper.ykobj;
if (comyk_info.yk_order >=64 ) return;
comyk_info.portno = comyk_tbl[comyk_info.yk_order][0];
comyk_info.devadd = comyk_tbl[comyk_info.yk_order][1];
comyk_info.interno = comyk_tbl[comyk_info.yk_order][2];
if (ykoper.ykcmd == YKCCLOSE) comyk_info.yk_cmd = 0xcc;
else comyk_info.yk_cmd = 0x33;
comyk_info.Y_PRESET = TRUE;
}
}
void CYk::comykcheck()
{
if (ykoper.ykexeman == YKMCOM && pdis.state == PCOMCHECK
&& ykoper.ykstate == YKSPRESET && ykoper.timer > ykoper.timerlimit) {
if (comyk_info.Y_CHECK == TRUE) {
ykoper.ykstate=YKSEXEC;
ykoper.timer=0;
ykoper.timerlimit = datasource.yk_escape_time * 18;
ykoper.ykcheckresult=YKROK;
ykop.checkresult=YKROK;
pdis.state=PCOMEXEC;
ykret.ykretobj=ykoper.ykobj;
ykret.ykretcmd=ykoper.ykcmd;
comyk_info.Y_CHECK=FALSE;
if (ykoper.ykfrom<=YKFP8)
if (port_set[ykoper.ykfrom].protocol==NEW_BB_CDT)
ykret.ykretflag[ykoper.ykfrom]=TRUE;
}
else {
port1.yk_flag=FALSE;
port2.yk_flag=FALSE;
port3.yk_flag=FALSE;
port4.yk_flag=FALSE;
port5.yk_flag=FALSE;
port6.yk_flag=FALSE;
port7.yk_flag=FALSE;
port8.yk_flag=FALSE;
comyk_info.Y_CHKERR = TRUE;
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
pdis.state=PNONE;
ykoper.timer=0;
ykoper.timerlimit=0;
if (ykoper.ykfrom==YKFWIN) {
ykoper.ykcheckresult=YKRERROR;
ykop.checkresult=YKRERROR;
}//if(ykoper.ykfrom==YKFWIN)
else {
ykoper.ykcheckresult=YKRNONE;
ykop.checkresult=YKRNONE;
}//else
ykret.ykretobj=ykoper.ykobj;
ykret.ykretcmd=0xff;
if (ykoper.ykfrom<=YKFP8)
if (port_set[ykoper.ykfrom].protocol==NEW_BB_CDT)
ykret.ykretflag[ykoper.ykfrom]=TRUE;
}
}
}
void CYk::comykexec()
{
if (ykoper.ykexeman == YKMCOM && ykoper.ykstate == YKSEXEC
&& pdis.state == PCOMEXEC && ykoper.timer < ykoper.timerlimit
&& ykoper.ykcmdint == YKIEXEC) { // EXECUTE
ykoper.ykcmdint=YKINONE;
ykoper.timer=0;
ykoper.timerlimit=0;
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
pdis.state=PNONE;
if (ykoper.ykcmd==YKCCLOSE) comyk_info.yk_cmd=0xcc;
else comyk_info.yk_cmd=0x33;
comyk_info.Y_EXEC=TRUE;
}
if (ykoper.ykexeman == YKMCOM && ykoper.ykstate == YKSEXEC
&& pdis.state == PCOMEXEC && ykoper.timer < ykoper.timerlimit
&& ykoper.ykcmdint == YKIESC) { // ESC
ykoper.ykcmdint=YKINONE;
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
ykoper.timer=0;
ykoper.timerlimit=0;
pdis.state=PNONE;
comyk_info.Y_ESC=TRUE;
}
if (ykoper.ykexeman == YKMCOM && ykoper.ykstate == YKSEXEC
&& pdis.state == PCOMEXEC && ykoper.timer > ykoper.timerlimit
&& ykoper.ykcmdint == YKINONE) { // TIMEOUT
ykoper.ykcmdint=YKINONE;
ykoper.ykexeman=YKMNONE;
ykoper.ykstate=YKSNONE;
pdis.state=PNONE;
ykoper.timer = ykoper.timerlimit = 0;
ykoper.ykcheckresult=YKRNONE;
ykop.checkresult=YKRTOUT;
comyk_info.Y_ESC=TRUE;
}
}
void CYk::doyk()
{
ykdistinguish();
/* ykc3apreset();
ykc3aforread();
ykc3areadback();
ykc3acheck();
ykc3aexec();
ykc3aesc();*/
comykpreset();
comykcheck();
comykexec();
}
//////////////////////////////////////////////////////////////////////////////////////
//The end of ykclass.cpp
//////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -