📄 ifsusbdlg.cpp
字号:
return (HCURSOR) m_hIcon;
}
void CIfsUsbDlg::OnButtonAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CIfsUsbDlg::OnCheckLed1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led1)
m_LedStatus = m_LedStatus | 0x01;
else
m_LedStatus = m_LedStatus & 0xfe;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed2()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led2)
m_LedStatus = m_LedStatus | 0x02;
else
m_LedStatus = m_LedStatus & 0xfd;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed3()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led3)
m_LedStatus = m_LedStatus | 0x04;
else
m_LedStatus = m_LedStatus & 0xfb;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed4()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led4)
m_LedStatus = m_LedStatus | 0x08;
else
m_LedStatus = m_LedStatus & 0xf7;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed5()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led5)
m_LedStatus = m_LedStatus | 0x10;
else
m_LedStatus = m_LedStatus & 0xef;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed6()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led6)
m_LedStatus = m_LedStatus | 0x20;
else
m_LedStatus = m_LedStatus & 0xdf;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed7()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led7)
m_LedStatus = m_LedStatus | 0x40;
else
m_LedStatus = m_LedStatus & 0xbf;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::OnCheckLed8()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (!m_Led8)
m_LedStatus = m_LedStatus | 0x80;
else
m_LedStatus = m_LedStatus & 0x7f;
SendLedStatus(m_LedStatus);
UpdateData(false);
}
void CIfsUsbDlg::SendLedStatus(BYTE mLedStatus)
{
HANDLE hLed = INVALID_HANDLE_VALUE;
CHAR *poutBuf = NULL;
ULONG nBytesWrite;
hLed = open_file( LED_PIPE);
poutBuf = (PCHAR)malloc(1);
if (hLed == INVALID_HANDLE_VALUE)
MessageBox("Can not open handle,write LED status failed!","Error",MB_OK | MB_ICONWARNING);
else
{
if (poutBuf)
{
*poutBuf = mLedStatus;
WriteFile(hLed,
poutBuf,
1, //write one byte
&nBytesWrite,
NULL);
free(poutBuf);
}
else
{
MessageBox("No much memory!","Error",MB_OK | MB_ICONWARNING);
}
CloseHandle(hLed);
}
}
void CIfsUsbDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
//according to nSBCode,we will refresh one line or one page of ram list
UINT nCurrentScrollBarPosition;
UINT iRefreshLength ;
UINT iRefreshStartLine;
UINT i,j;
CString temp;
CString strTemp,strTemp2;
BOOL bSuccess;
if (nSBCode == SB_THUMBPOSITION)
{
if (m_ListTopIndex != nPos)
{
if (nPos >47) //total 0~63 lines,48~63 always in same page
{
m_ListTopIndex = 48;
}
else
{
m_ListTopIndex = nPos;
}
iRefreshLength = 128;
iRefreshStartLine = m_ListTopIndex;
}
}
else if (nSBCode == SB_PAGEDOWN)
{
if ((m_ListTopIndex+16)>47)
{
m_ListTopIndex = 48;
}
else
{
m_ListTopIndex += 16;
}
iRefreshLength = 128;
iRefreshStartLine = m_ListTopIndex;
}
else if (nSBCode == SB_PAGEUP)
{
if (m_ListTopIndex < 16)
{
m_ListTopIndex = 0;
}
else
{
m_ListTopIndex -= 16;
}
iRefreshLength = 128;
iRefreshStartLine = m_ListTopIndex;
}
else if (nSBCode == SB_LINEDOWN)
{
if ((m_ListTopIndex +16) <= 63)
{
m_ListTopIndex +=1 ;
}
iRefreshLength = 8;
iRefreshStartLine = m_ListTopIndex+15;
}
else if (nSBCode == SB_LINEUP)
{
if (m_ListTopIndex > 0)
{
m_ListTopIndex -=1 ;
}
iRefreshLength = 8;
iRefreshStartLine = m_ListTopIndex;
}
else
{
iRefreshLength = 0;
iRefreshStartLine = 0;
}
//refresh ram list content
if (iRefreshLength>0)
{
sDeviceControl.bRequest = RAM_COMMAND_READ; //read ram
sDeviceControl.wIndex = iRefreshStartLine*8; //start address
sDeviceControl.wValue = iRefreshLength; //read length
sDeviceControl.wLength = 0; //read ram is a vendor request without data stage
sDeviceControl.pBuffer = NULL; //wLength is 0,pBuffer will always NULL
bSuccess = ReadSram(&sDeviceControl,&m_SramPage[0]);
if (bSuccess)
{
for (i=0;i<(iRefreshLength/8);i++)
{
m_ListSram.GetText(iRefreshStartLine+i,temp);
strTemp2 = temp.Mid(0,6);
for (j=0;j<8;j++)
{
strTemp.Format("%X",m_SramPage[i*8+j]);
if (strTemp.GetLength() == 1)
{
strTemp = "0"+strTemp;
}
strTemp = " "+strTemp; //add a space
strTemp2 += strTemp; //get data string
}
//update List content
m_ListSram.DeleteString(iRefreshStartLine+i);
m_ListSram.InsertString(iRefreshStartLine+i,strTemp2);
}
//UpdateData(false);
}
else
{
MessageBox("Refresh RAM list failed!","Error",MB_OK | MB_ICONWARNING);
}
m_ListSram.SetTopIndex(m_ListTopIndex);
nCurrentScrollBarPosition = m_ListTopIndex;
pScrollBar->SetScrollPos(nCurrentScrollBarPosition,true);
UpdateData(false);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CIfsUsbDlg::OnDblclkListSram()
{
// TODO: Add your control notification handler code here
CSramDlg aDlg;
SHORT i;
UCHAR j;
SHORT iCurrentSel;
CString strSramLine;
CString dlgSramLine;
CString strTemp = "";
CString strTemp2 = "";
BOOL bSuccess;
i=m_ListSram.GetCurSel();
iCurrentSel = i;
m_ListSram.GetText(i,strSramLine);
//display of SRAM dialog
aDlg.m_SramDlgEdit1 = strSramLine.Mid( 7,2);
aDlg.m_SramDlgEdit2 = strSramLine.Mid(10,2);
aDlg.m_SramDlgEdit3 = strSramLine.Mid(13,2);
aDlg.m_SramDlgEdit4 = strSramLine.Mid(16,2);
aDlg.m_SramDlgEdit5 = strSramLine.Mid(19,2);
aDlg.m_SramDlgEdit6 = strSramLine.Mid(22,2);
aDlg.m_SramDlgEdit7 = strSramLine.Mid(25,2);
aDlg.m_SramDlgEdit8 = strSramLine.Mid(28,2);
aDlg.m_SramDlgAddress = "SRAM Address: "+strSramLine.Mid(0,5);
//if click OK button
if (aDlg.DoModal() == IDOK)
{
m_ListTopIndex = m_ListSram.GetTopIndex();
dlgSramLine = aDlg.m_SramDlgEdit1 +" "+ aDlg.m_SramDlgEdit2 +" "+
aDlg.m_SramDlgEdit3 +" "+ aDlg.m_SramDlgEdit4 +" "+
aDlg.m_SramDlgEdit5 +" "+ aDlg.m_SramDlgEdit6 +" "+
aDlg.m_SramDlgEdit7 +" "+ aDlg.m_SramDlgEdit8;
if (dlgSramLine != strSramLine.Mid(7,(strSramLine.GetLength()-7)))
{
//MessageBox("SRAM line content is modified!","Tips",MB_OK);
m_SramLineData[0] = EditToByte(aDlg.m_SramDlgEdit1);
m_SramLineData[1] = EditToByte(aDlg.m_SramDlgEdit2);
m_SramLineData[2] = EditToByte(aDlg.m_SramDlgEdit3);
m_SramLineData[3] = EditToByte(aDlg.m_SramDlgEdit4);
m_SramLineData[4] = EditToByte(aDlg.m_SramDlgEdit5);
m_SramLineData[5] = EditToByte(aDlg.m_SramDlgEdit6);
m_SramLineData[6] = EditToByte(aDlg.m_SramDlgEdit7);
m_SramLineData[7] = EditToByte(aDlg.m_SramDlgEdit8);
//will write sram
sDeviceControl.bRequest = RAM_COMMAND_WRITE;
//sram address wil read/write
sDeviceControl.wIndex = (((USHORT)EditToByte(strSramLine.Mid(0,2)))<<8)+\
EditToByte(strSramLine.Mid(2,2));
//data length that will read or write sram
sDeviceControl.wValue = 8;
//this vendor request has no data phase
sDeviceControl.wLength = 0;
//because no data phase,buffer is not needed
sDeviceControl.pBuffer = NULL;
//write this line data to device
bSuccess = WriteSram(&sDeviceControl,&m_SramLineData[0]);
if (bSuccess)
{
//read back content of this line and display
sDeviceControl.bRequest = RAM_COMMAND_READ;
bSuccess = ReadSram(&sDeviceControl,&m_SramLineData[0]);
if (bSuccess)
{
strTemp2 = strSramLine.Mid(0,6);
for (j=0;j<8;j++)
{
strTemp.Format("%X",m_SramLineData[j]);
if (strTemp.GetLength() == 1)
{
strTemp = "0"+strTemp;
}
strTemp = " "+strTemp; //add a space
strTemp2 += strTemp; //get data string
}
//update List content
m_ListSram.DeleteString(i);
m_ListSram.InsertString(i,strTemp2);
m_ListSram.SetCurSel(iCurrentSel);
m_ListSram.SetTopIndex(m_ListTopIndex);
UpdateData(false);
}
}
}
}
}
BYTE CIfsUsbDlg::EditToByte(CString m_sStr)
{
BYTE bDigital = 0;
UCHAR b;
if (m_sStr.GetLength() == 1)
{
b = m_sStr.GetAt(0);
if (b>=0x30 && b<=0x39) bDigital = b-0x30;
else if (b>=0x41 && b<=0x46) bDigital = b-0x37;
}
else if (m_sStr.GetLength() == 2)
{
b = m_sStr.GetAt(0);
if (b>=0x30 && b<=0x39) bDigital = b-0x30;
else if (b>=0x41 && b<=0x46) bDigital = b-0x37;
bDigital <<= 4;
b = m_sStr.GetAt(1);
if (b>=0x30 && b<=0x39) bDigital += (b-0x30);
else if (b>=0x41 && b<=0x46) bDigital += (b-0x37);
}
else
{
bDigital = 0x00;
}
return bDigital;
}
BOOL CIfsUsbDlg::ReadSram(PDEVICE_CONTROL pDeviceControl, PBYTE pBuff)
{
HANDLE hSram = INVALID_HANDLE_VALUE;
ULONG nBytesRead;
BOOL bSuccess = FALSE;
ULONG nByteNumber = pDeviceControl->wValue;
//send request: set sram read command and byte number through IO CONTROL
bSuccess = device_ctl(pDeviceControl,false);
if (!bSuccess)
{
MessageBox("Set SRAM address failed!","Error",MB_OK | MB_ICONWARNING);
return bSuccess;
}
//read sram
hSram = open_file( SRAM_PIPE_IN);
if (hSram == INVALID_HANDLE_VALUE)
MessageBox("Can not open handle,read SRAM failed!","Error",MB_OK | MB_ICONWARNING);
else
{
bSuccess = ReadFile(hSram,
pBuff,
nByteNumber,
&nBytesRead,
NULL);
if (!bSuccess)
{
reset_pipe(hSram);
MessageBox("Write SRAM failed!","Error",MB_OK | MB_ICONWARNING);
}
CloseHandle(hSram);
}
return bSuccess;
}
BOOL CIfsUsbDlg::WriteSram(PDEVICE_CONTROL pDeviceControl, PBYTE pBuff)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -