📄 ezmrview.cpp
字号:
if( !CFile::GetStatus( m_strDldFile, status ) ) // just in case default
m_strDldFile = theApp.m_strPathUSBRoot + "\\Examples";
if( !CFile::GetStatus( m_strDldFile, status ) ) // just in case default
m_strDldFile = theApp.m_strPathUSBRoot;
}
CFileDialog dlgLoad(
TRUE, 0, 0,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"HexFiles (*.hex)|*.hex|AllFiles (*.*)|*.*||");
dlgLoad.m_ofn.lpstrTitle = "Anchor Download";
dlgLoad.m_ofn.lpstrInitialDir = m_strDldFile; // OK if you specify a file
if(dlgLoad.DoModal() != IDOK)
return;
m_strDldFile = dlgLoad.m_ofn.lpstrFile;
m_strLastLoadedFile = m_strDldFile;
LoadFile(m_strDldFile);
}
void CEzMrView::OnIDC_FILE_TRANS()
{
TRACE("TPM:CEzMrView::OnIDC_FILE_TRANS()\n");
int pipeNum = ((CEzMrFrame*)GetParentFrame())->m_wndTBarRes.GetDlgItemInt(IDC_RESETPIPENUM, NULL, FALSE);
PUSBD_PIPE_INFORMATION pPipe =
((PUSBD_INTERFACE_INFORMATION)theApp.m_uInterfaceInfo)->Pipes;
CString strDlgLable;
if(!(pPipe[pipeNum].EndpointAddress >> 7)) //if write
strDlgLable = "Select Output File for File Transfer (or type new name)";
else
strDlgLable = "Select Input File for File Transfer";
CFileDialog dlgLoad(
TRUE, 0, 0,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"AllFiles (*.*)|*.*||");
dlgLoad.m_ofn.lpstrTitle = strDlgLable;
dlgLoad.m_ofn.lpstrInitialDir = m_strTransFile;
if(dlgLoad.DoModal() != IDOK)
return;
m_strTransFile = dlgLoad.m_ofn.lpstrFile;
CFileStatus status;
fstream file;
char text[80];
int savePipeIdx = 0;
CString strSaveText;
if(pPipe[pipeNum].PipeType == UsbdPipeTypeBulk)
{ //set control bar values appropriately
((CEzMrFrame*)GetParentFrame())->m_wndTBarRes.GetDlgItemText(IDC_RESETPIPENUM, text, 80);
int BlkpipeNum = ((CEzMrFrame*)GetParentFrame())->m_wndTBarBlk.GetDlgItemInt(IDC_BLK_PIPE, NULL, FALSE);
savePipeIdx = ((CEzMrFrame*)GetParentFrame())->m_CBoxBlkPipe.GetCurSel();
((CEzMrFrame*)GetParentFrame())->m_EBoxBlkLen.GetWindowText(strSaveText);
if(BlkpipeNum != pipeNum)
{
int pipeIdx = ((CEzMrFrame*)GetParentFrame())->m_CBoxBlkPipe.FindString(0, text);
if(pipeIdx != CB_ERR)
((CEzMrFrame*)GetParentFrame())->m_CBoxBlkPipe.SetCurSel(pipeIdx);
else
theApp.report_error("Pipe Sel not found in Bulk Bar");
}
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeIsochronous)
{ //set control bar values appropriately
((CEzMrFrame*)GetParentFrame())->m_wndTBarRes.GetDlgItemText(IDC_RESETPIPENUM, text, 80);
int IsopipeNum = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_ISO_PIPE, NULL, FALSE);
if(IsopipeNum != pipeNum)
{
int pipeIdx = ((CEzMrFrame*)GetParentFrame())->m_CBoxIsoPipe.FindString(0, text);
if(pipeIdx != CB_ERR)
((CEzMrFrame*)GetParentFrame())->m_CBoxIsoPipe.SetCurSel(pipeIdx);
else
theApp.report_error("Pipe Sel not found in Iso Bar");
}
}
if(!(pPipe[pipeNum].EndpointAddress >> 7)) //if write
{
if( CFile::GetStatus( m_strTransFile, status ) ) // static function
file.open(m_strTransFile, ios::in|ios::binary);
if(!file)
{
TRACE("Error opening Input file: %s", m_strTransFile);
theApp.report_error("Error opening Input file.\n");
return;
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeBulk)
{
if(status.m_size > MAX_FILE_SIZE)
{
status.m_size = MAX_FILE_SIZE;
TRACE("File %s exceeds Max file size of %d bytes. File truncated.",
m_strTransFile, MAX_FILE_SIZE);
theApp.report_error("File exceeds Max packet size. File truncated.\n");
}
file.read(((CEzMrFrame*)GetParentFrame())->BlkBuf, status.m_size);
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeIsochronous)
{
if(status.m_size > MAX_ISO_SIZE)
{
status.m_size = MAX_ISO_SIZE;
TRACE("File %s exceeds Max file size of %d bytes. File truncated.",
m_strTransFile, MAX_ISO_SIZE);
theApp.report_error("File exceeds Max packet size. File truncated.\n");
}
file.read(((CEzMrFrame*)GetParentFrame())->IsoBuf, status.m_size);
}
file.close();
if(pPipe[pipeNum].PipeType == UsbdPipeTypeBulk)
{ //set control bar values appropriately
sprintf(text, "%d", status.m_size);
((CEzMrFrame*)GetParentFrame())->m_EBoxBlkLen.SetWindowText(text);
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeIsochronous)
{ //set control bar values appropriately
if(status.m_size % pPipe[pipeNum].MaximumPacketSize)
theApp.report_error("File clipped slightly to fit MaxPacketSize.");
int pktCount = status.m_size/pPipe[pipeNum].MaximumPacketSize;
int PktSize = pPipe[pipeNum].MaximumPacketSize;
int buffCount = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_ISO_BUF_CNT, NULL, FALSE);;
int frmPerBuff = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_PAK_PER, NULL, FALSE);;
if(pktCount <= 1)
{ // if there is less data in file than 1 transfer
pktCount = 1;
buffCount = 1;
frmPerBuff = 1;
}
if(pktCount < (buffCount*frmPerBuff))
{ // need to modify buff values to some minimal default
buffCount = 1;
frmPerBuff = pktCount;
}
if(pktCount % (buffCount*frmPerBuff))
{ // need to modify buff values to some minimal default
if(pktCount > (pktCount % (buffCount*frmPerBuff)))
{
pktCount -= pktCount % (buffCount*frmPerBuff); //trim it
theApp.report_error("File clipped slightly to fit buffers.");
}
}
sprintf(text, "%d", pktCount);
((CEzMrFrame*)GetParentFrame())->m_EBoxPack.SetWindowText(text);
sprintf(text, "%d", PktSize);
((CEzMrFrame*)GetParentFrame())->m_EBoxSize.SetWindowText(text);
sprintf(text, "%d", buffCount);
((CEzMrFrame*)GetParentFrame())->m_EBoxIsoBufCnt.SetWindowText(text);
sprintf(text, "%d", frmPerBuff);
((CEzMrFrame*)GetParentFrame())->m_EBoxIsoPakPer.SetWindowText(text);
}
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeBulk)
{
SendOp(OP_RW_BLK_BYT);
((CEzMrFrame*)GetParentFrame())->m_CBoxBlkPipe.SetCurSel(savePipeIdx); // restore the prior value
((CEzMrFrame*)GetParentFrame())->m_EBoxBlkLen.SetWindowText(strSaveText); // restore the prior value
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeIsochronous)
SendOp(OP_ISO_TRANSF);
if(pPipe[pipeNum].EndpointAddress >> 7) //if read
{
int length;
((CEzMrFrame*)GetParentFrame())->m_EBoxBlkLen.GetWindowText(text, 80);
sscanf(text, "%d", &length);
file.open(m_strTransFile, ios::out|ios::binary);
if(!file)
{
TRACE("Error opening Output file: %s", m_strTransFile);
theApp.report_error("Error opening Output file.\n");
return;
}
else
{
if(pPipe[pipeNum].PipeType == UsbdPipeTypeBulk)
{
file.write(((CEzMrFrame*)GetParentFrame())->BlkBuf, length);
}
if(pPipe[pipeNum].PipeType == UsbdPipeTypeIsochronous)
{
file.write(((CEzMrFrame*)GetParentFrame())->IsoBuf, length);
}
file.close();
}
}
}
void CEzMrView::OnIDC_GET_DD(){SendOp(OP_GET_DEVDES);}
void CEzMrView::OnIDC_GET_CD(){SendOp(OP_GET_CONDES);}
void CEzMrView::OnIDC_GET_PI(){SendOp(OP_GET_PIPINF);}
void CEzMrView::OnID_BBLK_LBL()
{
((CEzMrFrame*)GetParentFrame())->OnEditchangeData(); //slurp up data into buff
char text[193];
((CEzMrFrame*)GetParentFrame())->m_wndTBarBlk.GetDlgItemText(IDC_DATA_VALUE, text, 193);
CString strText = text;
if( ((CEzMrFrame*)GetParentFrame())->m_CBoxBlkData.FindString(-1, (LPTSTR)(LPCTSTR)strText) == -1)
((CEzMrFrame*)GetParentFrame())->m_CBoxBlkData.AddString(strText);
SendOp(OP_RW_BLK_BYT);
}
void CEzMrView::OnID_BVEN_LBL()
{
((CEzMrFrame*)GetParentFrame())->OnEditVenData(); //slurp up data into buff
char text[193];
((CEzMrFrame*)GetParentFrame())->m_wndTBarVen.GetDlgItemText(IDC_VENDOR_DATA, text, 193);
CString strText = text;
if( ((CEzMrFrame*)GetParentFrame())->m_CBoxVenData.FindString(-1, (LPTSTR)(LPCTSTR)strText) == -1)
((CEzMrFrame*)GetParentFrame())->m_CBoxVenData.AddString(strText);
SendOp(OP_VEND_REQST);
}
void CEzMrView::OnIDC_RESET_PIPE(){SendOp(OP_RESET_PIPE);}
void CEzMrView::OnIDC_ABORT_PIPE(){SendOp(OP_ABORT_PIPE);}
void CEzMrView::OnID_BISO_LBL()
{
int pipeSel = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_ISO_PIPE, NULL, FALSE);
int pktCount = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_ISO_PACKETS, NULL, FALSE);
int pktSize = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_ISO_SIZE, NULL, FALSE);
int buffCount = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_ISO_BUF_CNT, NULL, FALSE);
int frmPerBuff = ((CEzMrFrame*)GetParentFrame())->m_wndTBarIso.GetDlgItemInt(IDC_PAK_PER, NULL, FALSE);
int maxPktSize;
int totalSize;
totalSize = pktCount * pktSize;
PUSBD_INTERFACE_INFORMATION pInterface;
PUSBD_PIPE_INFORMATION pPipe;
pInterface = (PUSBD_INTERFACE_INFORMATION) theApp.m_uInterfaceInfo;
pPipe = pInterface->Pipes;
maxPktSize = pPipe[pipeSel].MaximumPacketSize;
if(pktSize > maxPktSize)
{
theApp.report_error("PacketSize must be less than MaxPacketSize for selected endpoint.\nPlease check value and send again\n");
return;
}
if(pktCount % (buffCount*frmPerBuff))
{
theApp.report_error("PacketCount must be evenly divisible by (BuffCount*FrmPerBuff).\nPlease check value and send again\n");
return;
}
if(totalSize > MAX_ISO_SIZE)
{
theApp.report_error("PacketCount*pktSize exceeds max transfer size of 1MB.\nPlease check values and send again\n");
return;
}
// fill the buffer with some data
WORD* wdptr = (WORD*) ((CEzMrFrame*)GetParentFrame())->IsoBuf;
int i, j;
ULONG count = 0;
for (i=0; i< (int)pktCount; i++)
for (j=0; j< (int)(pktSize / 2); j++)
{
*wdptr = (WORD)count++;
wdptr++;
}
SendOp(OP_ISO_TRANSF);
}
void CEzMrView::OnID_BCFG_LBL(){SendOp(OP_SET_INTERF);}
void CEzMrView::OnIDC_ABORT_ALL()
{
AbortPendingOps();
}
void CEzMrView::OnIDC_GET_URB_STAT()
{
TRACE("TPM:CEzMrView::OnIDC_GET_URB_STAT()\n");
SendOp(OP_GETURBSTAT);
}
void CEzMrView::OnIDC_GET_SD()
{
TRACE("TPM:CEzMrView::OP_GET_STRING()\n");
theApp.m_nStringIndex = 1;
SendOp(OP_GET_STRING);
theApp.m_nStringIndex = 2;
SendOp(OP_GET_STRING);
}
void CEzMrView::AbortPendingOps(void)
{
/*
if(m_nOpsPending)
{
TRACE("TPM:CEzMrView::AbortPendingOps()\n");
PUSBD_INTERFACE_INFORMATION pInterface;
PUSBD_PIPE_INFORMATION pPipe;
pInterface = (PUSBD_INTERFACE_INFORMATION) theApp.m_uInterfaceInfo;
pPipe = pInterface->Pipes;
for(int i=0; i < (int) pInterface->NumberOfPipes; i++)
{ // just abort all pipes for now
CString pipe_end;
pipe_end.Format("%d-%d %s", i, (pPipe[i].EndpointAddress & 0x0F),
(pPipe[i].EndpointAddress >> 7) ? "IN" : "OUT");
((CEzMrFrame*)GetParentFrame())->m_CBoxResPipe.SetCurSel(i);
theApp.m_nMaxOpsPending++; // make sure it can clear the op
//SendOp(OP_RESET_PIPE);
SendOp(OP_ABORT_PIPE);
SleepEx(2000, 0);
//theApp.m_nMaxOpsPending++; // make sure it can clear the op
//SendOp(OP_RESET_PIPE);
//SleepEx(2000, 0);
}
}
*/
}
void CEzMrView::Ezusb_DownloadIntelHex(PINTEL_HEX_RECORD pHexRecord)
{
PINTEL_HEX_RECORD ptr = pHexRecord;
unsigned char* pbuf = (unsigned char *)((CEzMrFrame*)GetParentFrame())->BlkBuf;
unsigned char* ptmp = NULL;
ptr = pHexRecord;
On_8051_HOLD();
while (ptr->Type == 0)
{ //load low mem
if((ptmp != NULL) &&
(m_dldOffset+m_DldLen == ptr->Address) &&
((m_DldLen+ptr->Length) <= MAX_EP0_XFER_SIZE) )
{ // continue a segment
memcpy(ptmp, ptr->Data, ptr->Length);
m_DldLen += ptr->Length;
ptmp += ptr->Length;
}
else
{ // start a new segment
if(ptmp != NULL)
{ // send prev segment first
SendOp(OP_ANCHOR_DLD);
if( ( m_nOpsPending ) >= theApp.m_nMaxOpsPending)
break;
}
ptmp = pbuf;
memcpy(ptmp, ptr->Data, ptr->Length);
m_DldLen = ptr->Length;
m_dldOffset = ptr->Address;
ptmp += ptr->Length;
}
ptr++;
}
if(ptmp != NULL)
{ // send final segment
SendOp(OP_ANCHOR_DLD);
}
On_8051_RUN();
}
void CEzMrView::OnIDC_RELOAD()
{
CString strSaveDld = m_strDldFile;
m_strDldFile = m_strLastLoadedFile;
LoadFile(m_strDldFile);
m_strDldFile = strSaveDld;
}
void CEzMrView::OnUpdateIDC_RELOAD(CCmdUI* pCmdUI)
{
if((m_strLastLoadedFile != "")
&& (theApp.m_nTarg != 2))
pCmdUI->Enable(1);
else
pCmdUI->Enable(0);
}
void CEzMrView::OnUpdateTargetSel(CCmdUI* pCmdUI)
{
if(theApp.m_nTarg != 2)
pCmdUI->Enable(1);
else
pCmdUI->Enable(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -