📄 dianpen.cpp
字号:
// DIANPEN.cpp - main module for VxD DIANPEN
#define DEVICE_MAIN
#include "dianpen.h"
#include "enginevxd.h"
Declare_Virtual_Device(DIANPEN)
#undef DEVICE_MAIN
DianpenVM::DianpenVM(VMHANDLE hVM) : VVirtualMachine(hVM) {}
DianpenThread::DianpenThread(THREADHANDLE hThread) : VThread(hThread) {}
//全局事件变量
HANDLE g_eventSampleEnd, g_eventSampleStart; //采样结束事件
HANDLE g_hEndSample, g_hStartSample;
int g_nAC1050;
int MY_IRQ;//===中断号
//unsigned int SamplePoints;//采样点数
//int * m_pBuf;//ad结果数组之指针
int g_nSampleRearNum;//实际采样点数
bool begin;
BOOL DianpenDevice::OnSysDynamicDeviceInit()
{
dprintf("init");
//g_eventSampleStart=NULL;
//g_hStartSample = NULL;
g_hEndSample= NULL;
g_nSampleRearNum=0;
g_nAC1050=0x210;
MY_IRQ=10;
begin=false;
/* m_pMyIRQ=new MyCylinderInt();
if(m_pMyIRQ && m_pMyIRQ->hook()) //Virtual the INT sucessfully
{
m_pMyIRQ->Enable(); //Enable the Cylinder Interrupt
m_pMyIRQ->physicalUnmask();
dprintf("Load VXD sucessfully");
return TRUE; //Init the VXD sucessfully
}
else
{
dprintf("Load the VXD failure");
return FALSE;
}
*/
return TRUE;
}
BOOL DianpenDevice::OnSysDynamicDeviceExit()
{
m_pMyIRQ->Enable(FALSE);
delete m_pMyIRQ;
dprintf("Unload the VXD");
return TRUE;
}
DWORD DianpenDevice::OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams)
{
DWORD rc,nSize;
int i;
switch(pDIOCParams->dioc_IOCtlCode)
{ //dioc_IOCtlCode--Win32程序调用VxD的服务标识
case DIOC_OPEN: //Create the VXD 装载VxD
dprintf("DIOC_OPEN");
rc=DEVIOCTL_NOERROR;//装载成功标志
break;
case DIOC_CLOSEHANDLE: //Close the VXD 卸载VxD
/* m_pMyIRQ->Enable(FALSE);
delete m_pMyIRQ;*/
dprintf("DIOC_CLOSEHANDLE");
rc=DEVIOCTL_NOERROR;
break;
case DIOC_INIT_IRQ:
dprintf("传送地址和中断号到vxd");
DataStruct *idata;
idata = new DataStruct;
idata = (DataStruct *)pDIOCParams->dioc_InBuf;
g_nAC1050 = idata->nAC1050;
MY_IRQ=idata->my_irq;
// SamplePoints=idata->samplePointsI;
dprintf("地址%d中断号%d",g_nAC1050,MY_IRQ);
m_pMyIRQ=new MyCylinderInt();
if(m_pMyIRQ && m_pMyIRQ->hook()) //Virtual the INT sucessfully
{
m_pMyIRQ->Enable(); //Enable the Cylinder Interrupt
m_pMyIRQ->physicalUnmask();
dprintf("虚拟化中断号%d成功!",MY_IRQ);
return TRUE; //Init the VXD sucessfully
}
else
{
dprintf("虚拟化中断号%d失败!",MY_IRQ);
}
delete idata;
rc=DEVIOCTL_NOERROR;
break;
//传递事件到VXD中
case DIOC_WRITE_EVENT:
dprintf("向vxd传递事件");
EventStruct *event_str;
event_str=new EventStruct;
//case input buffer to structure
event_str=(EventStruct *)pDIOCParams->dioc_InBuf; //Win32程序向VxD的输入缓冲,含有ring3给ring0的数据
//new event handle from Windows Application (Ring3)
g_hStartSample=event_str->hSampleStart;
g_hEndSample=event_str->hSampleEnd;
//_outp(0x22e, 0xf);
rc=DEVIOCTL_NOERROR;
break;
case DIOC_TEST_BEGIN:
dprintf("begin");
_outp(g_nAC1050 + 0x06,0);
_outp(g_nAC1050 + 0x05,0);
begin=true;
//_outp(0x22e, 0);//启动AD转换
break;
case DIOC_READ_DATA:
DataStruct_Dianpen *data;
data=new DataStruct_Dianpen;
data->nSampleRearNum=g_nSampleRearNum;//实际采样点数
/* for(i=0;i<g_nSampleRearNum;i++)
data->p_buf[i]=m_pBuf[i];//ad结果数组之指针*/
nSize=pDIOCParams->dioc_cbOutBuf;//VxD向Win32程序的输出缓冲大小
if(nSize>=sizeof(DataStruct_Dianpen))
{
memcpy(pDIOCParams->dioc_OutBuf,data,sizeof(DataStruct_Dianpen));
//dioc_OutBuf -- VxD向Win32程序的输出缓冲
*(pDIOCParams->dioc_bytesret)=sizeof(DataStruct_Dianpen);
//dioc_bytesret--VxD实际写入输出缓冲的字节数
nSize=sizeof(DataStruct_Dianpen);
pDIOCParams->dioc_bytesret=&nSize;
rc=DEVIOCTL_NOERROR;
}
else//数据缓冲区大小不够
rc=DEVIOCTL_NOERROR;
delete data;
break;
default://无效指令处理
rc=ERROR_INVALID_PARAMETER;
break;
}
return rc;
}
VOID DianpenDevice::PM_API_Entry(VMHANDLE hVM, CLIENT_STRUCT* pRegs)
{
}
VOID MyCylinderInt::Enable(BOOL flag)
{
}
MyCylinderInt::MyCylinderInt():VHardwareInt(MY_IRQ,0,0,0)
{
}
MyCylinderInt::~MyCylinderInt()
{
}
VOID MyCylinderInt::OnHardwareInt(VMHANDLE hVM)
{
dprintf(" Heney Int 9 comming !");
if(begin)
{
// _outp(g_nAC1050 + 0x06,0); //复位AC1050卡( 停止采样 )
// _outp(g_nAC1050+0x0f,0x02);
// g_nSampleRearNum=_inp(g_nAC1050+0x0c) & 0x00ff; //read low byte
// g_nSampleRearNum+=(_inp(g_nAC1050+0x0c) & 0x00ff) * 256;
/* for(int i=0;i<g_nSampleRearNum;i++)
{
m_pBuf[i] = _inpw(g_nAC1050);
}
*/
VWIN32_SetWin32Event(g_hEndSample);
begin=false;
dprintf("---SampleEnd!");
}
sendPhysicalEOI();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -