?? ccd_commcenter.c
字號(hào):
if(FILE_PATHLEN == commVar.fStep) {
if(readcount < sizeof(UInt32)) {
//包體尚未接收到最小數(shù)據(jù)長(zhǎng)度
continue;
}
//計(jì)算包體的CRC16
commVar.pcb->cCRC = Add_CRC16(commVar.pcb->cCRC, commVar.szStoreBuffer+commVar.nPotS, sizeof(UInt32));
//讀取路徑長(zhǎng)度
commVar.fcb.PathLen = CommCenter_ntohl( CommCenter_strtol(commVar.szStoreBuffer + commVar.nPotS) );
if(commVar.fcb.PathLen <= 0 || commVar.fcb.PathLen >= MAXPATH_LEN) {//文件路徑長(zhǎng)度字段錯(cuò)誤
//文件錯(cuò)誤報(bào)告, 處理
CommCenter_ErrorDealEvent(&commVar, 0x00000006, 0x00000006);
continue;
}
#ifdef debug_modul
sprintf((char *)szOutPutBuff, (char *)"==== COM4: %d %d %d\n", commVar.fcb.PathLen, commVar.nPotS, commVar.nPotE);
EOS_Write(commVar.deBugfp, szOutPutBuff, StrLen(szOutPutBuff));
#endif
//更新其它數(shù)據(jù)
commVar.fStep = FILE_PATH;
commVar.nPotS+= sizeof(UInt32);
readcount -= sizeof(UInt32);
//繼續(xù)處理緩沖區(qū)
} //end 取文件路徑長(zhǎng)度
//3. 取文件路徑
if(FILE_PATH == commVar.fStep) {
if(readcount < commVar.fcb.PathLen) {
//包體尚未接收到完整文件路徑信息
continue;
}
//計(jì)算包體的CRC16
commVar.pcb->cCRC = Add_CRC16(commVar.pcb->cCRC, commVar.szStoreBuffer+commVar.nPotS, commVar.fcb.PathLen);
//更新文件路徑
StrNCopy(commVar.fcb.Path, commVar.szStoreBuffer + commVar.nPotS, commVar.fcb.PathLen);
#ifdef debug_modul
sprintf((char *)szOutPutBuff, (char *)"==== PATH: %s %d %d\n", commVar.fcb.Path, commVar.nPotS, commVar.nPotE);
EOS_Write(commVar.deBugfp, szOutPutBuff, StrLen(szOutPutBuff));
#endif
//創(chuàng)建可能的目標(biāo)目錄(假定前3個(gè)是盤符, 如C:\)
MdWithFile(commVar.fcb.Path, commVar.fcb.Path + StrLen((Char *)"C:\\"));
//打開或創(chuàng)建目標(biāo)文件
if(0 <=commVar.hFile) EOS_Close(commVar.hFile);
commVar.hFile = EOS_Open(commVar.fcb.Path, PO_CREAT|PO_TRUNC|PO_BINARY|PO_WRONLY, PS_IWRITE);
if(0 > commVar.hFile) {
//打開或創(chuàng)建目標(biāo)文件失敗
CommCenter_ErrorDealEvent(&commVar, 0x00000005, 0x00000007);
continue;
}
//更新其它數(shù)據(jù)
commVar.fStep = FILE_LENTH;
commVar.nPotS+= commVar.fcb.PathLen;
readcount -= commVar.fcb.PathLen;
//繼續(xù)處理緩沖區(qū)
} //end 取文件路徑
//4. 取文件長(zhǎng)度
if(FILE_LENTH == commVar.fStep) {
if(readcount < sizeof(UInt32)) {
//包體尚未接收到完整文件路徑信息
continue;
}
//計(jì)算至文件內(nèi)容的CRC16
commVar.pcb->cCRC = Add_CRC16(commVar.pcb->cCRC, commVar.szStoreBuffer+commVar.nPotS, sizeof(UInt32));
//更新文件長(zhǎng)度
commVar.fcb.len = CommCenter_ntohl( CommCenter_strtol(commVar.szStoreBuffer + commVar.nPotS) );
if(0 >= commVar.fcb.len) {//文件長(zhǎng)度字段錯(cuò)誤
//文件錯(cuò)誤報(bào)告,處理
CommCenter_ErrorDealEvent(&commVar, 0x00000006, 0x00000008);
continue;
}
#ifdef debug_modul
sprintf((char *)szOutPutBuff, (char *)"==== COM6: %d %d %d\n", commVar.fcb.len, commVar.nPotS, commVar.nPotE);
EOS_Write(commVar.deBugfp, szOutPutBuff, StrLen(szOutPutBuff));
#endif
//更新相關(guān)數(shù)據(jù)
commVar.fStep = FILE_DATA;
commVar.nPotS+= sizeof(UInt32);
commVar.fcb.WriteLen = 0;
readcount -= sizeof(UInt32);
//繼續(xù)處理緩沖區(qū)
} //end 取文件長(zhǎng)度
//5. 取文件數(shù)據(jù)
if(CommCenter_FILEDATA == commVar.nStep) {
if(readcount <= 0) {
//包體尚未接收到最小數(shù)據(jù)長(zhǎng)度
continue;
}
if(commVar.fcb.WriteLen < commVar.fcb.len) {
tmpWcount = min(readcount, commVar.fcb.len - commVar.fcb.WriteLen);
//計(jì)算當(dāng)前所讀數(shù)據(jù)的CRC16
commVar.pcb->cCRC = Add_CRC16(commVar.pcb->cCRC, commVar.szStoreBuffer+commVar.nPotS, tmpWcount);
if(tmpWcount != EOS_Write(commVar.hFile, commVar.szStoreBuffer+commVar.nPotS, tmpWcount)) {
//文件寫入失敗
CommCenter_ErrorDealEvent(&commVar, 0x00000006, 0x00000009);
continue;
}
readcount -= tmpWcount;
commVar.fcb.WriteLen += tmpWcount; //保存當(dāng)前所讀數(shù)據(jù)到文件
//向父進(jìn)程發(fā)送消息,要求顯示“文件下載進(jìn)度”
CommCenterThread_Inform(AppRequest_GetFatherPid(), WinGetWindowHwndId(g__winP), CommCenter_FILEDATA, commVar.fcb.nId, commVar.fcb.WriteLen, commVar.fcb.len);
//匯報(bào)已經(jīng)正確接收并處理完報(bào)文
CommCenter_ErrorDealEvent(&commVar, 0x00000000, sizeof(CommCenter_PACKETHEADType)+sizeof(UInt32)+sizeof(UInt32)+commVar.fcb.PathLen+sizeof(UInt32)+commVar.fcb.WriteLen);
}
//在此, 可以認(rèn)為已經(jīng)處理完所讀的數(shù)據(jù), 更新相關(guān)數(shù)據(jù)
commVar.nPotS = sizeof(CommCenter_PACKETHEADType);
commVar.nPotE = sizeof(CommCenter_PACKETHEADType);
if(commVar.fcb.WriteLen >= commVar.fcb.len) { //寫完一個(gè)文件
if(0 <= commVar.hFile) {
EOS_Close(commVar.hFile);
commVar.hFile = -1;
}
//校驗(yàn)報(bào)文的CRC16
if(FALSE == IsValid_CRC16(commVar.pcb->cCRC, commVar.CRC) ) {
//文件傳輸出錯(cuò)
CommCenter_ErrorDealEvent(&commVar, 0x00000003, 0x0000000A);
continue;
}
//匯報(bào)已經(jīng)正確寫入文件
CommCenter_ErrorDealEvent(&commVar, 0x00000000, sizeof(CommCenter_PACKETHEADType)+sizeof(UInt32)+sizeof(UInt32)+commVar.fcb.PathLen+sizeof(UInt32)+commVar.fcb.WriteLen);
//更新數(shù)據(jù)
commVar.nStat = CommCenter_PACKETHEAD;
commVar.fStep = FILE_INDEX;
commVar.nPotS = 0;
commVar.nPotE = 0;
if(commVar.fcb.nId >= commVar.FiletotleCount) {
MemSet(&commVar.fcb, 0, sizeof(CommCenter_FILEINDEXType));
commVar.nStep = CommCenter_FILEWAIT;
commVar.FiletotleCount = 0;
//向父進(jìn)程發(fā)送消息,要求顯示“文件傳輸完畢,進(jìn)入文件傳輸?shù)却隣顟B(tài)”
CommCenterThread_Inform(AppRequest_GetFatherPid(), WinGetWindowHwndId(g__winP), CommCenter_FILEWAIT, 0, 0, 0);
}
} //end if(commVar.fcb.WriteLen >= commVar.fcb.len)
} //end 取文件數(shù)據(jù)
} //end 發(fā)送文件
} //end 接收?qǐng)?bào)體
} // end while(FALSE == bExitThread)
if(0 <= commVar.comId) {
Close(commVar.comId);
commVar.comId = -1;
}
if(0 <= commVar.hFile) {
EOS_Close(commVar.hFile);
commVar.hFile = -1;
}
#ifdef debug_modul
if(0 <= commVar.deBugfp) {
EOS_Write(commVar.deBugfp, (Char *)"thread end!\n", StrLen((Char *)"thread end!\n"));
EOS_Close(commVar.deBugfp);
}
#endif
return TRUE;
}
////////////////////////////////////////
// 串口下載窗體處理函數(shù)
Boolean CommCenterAppFrmProgressHandleEvent(void *globalVarPtr, WinHandle formP, EventPtr eventP)
{
//CommCenter_DEMOGVRType *pVar = (CommCenter_DEMOGVRType *)globalVarPtr;
Boolean handled = FALSE;
Char szTxt[512];
LabelType *pLab_BarHint = WinGetControlPtr(formP, Com_ID_FrmProgress_BarHint_FrmProgress);
RectangleType rtCtl;
Int32 r;
switch(eventP->eType) {
case winInitEvent:
//啟動(dòng)IO線程
g__winP = formP;
r = AppRequest_MethodExec((Char *)"Comm_IOType", (Char *)APP_NAME_CDD_COMMCENTER, (Char *)"Comm_IO", NULL, 0);
handled = TRUE;
break;
case winPaintEvent:
WinDrawWindow(formP);
handled = TRUE;
break;
case RSPCOM_MSG:
switch(eventP->sParam1){
case CommCenter_FILEWAIT://等待文件傳輸
sprintf((char *)szTxt, (char *)"正在等待文件傳輸...");
break;
case CommCenter_FILEREQ://傳輸文件請(qǐng)求
sprintf((char *)szTxt, (char *)"開始傳輸文件,共%d個(gè)", eventP->lParam3);
break;
case CommCenter_FILEDATA://傳輸文件內(nèi)容
sprintf((char *)szTxt, (char *)"目前傳輸: %d字節(jié)", eventP->lParam3);
break;
default: break;
}
//更新文件下載進(jìn)度說明
if(0 != StrLen(szTxt)) WinSetControlCaption(formP, Com_ID_FrmProgress_TxtHint_FrmProgress, szTxt, FALSE);
if(CommCenter_FILEDATA == eventP->sParam1) {
//更新文件下載進(jìn)度條
CtlGetBounds(pLab_BarHint, &rtCtl);
rtCtl.extent.X = (Int16)(162*eventP->lParam3/eventP->lParam4);
CtlSetBounds(pLab_BarHint, &rtCtl);
WinDrawControl(formP, Com_ID_FrmProgress_BarHint_FrmProgress);
if(eventP->lParam3 == eventP->lParam4) {
CtlGetBounds(pLab_BarHint, &rtCtl);
rtCtl.extent.X = 0;
CtlSetBounds(pLab_BarHint, &rtCtl);
WinDrawControl(formP, Com_ID_FrmProgress_Field1114);
}
}
handled = TRUE;
break;
case ctlSelectEvent:
if(Com_ID_FrmProgress_Close_FrmProgress == eventP->sParam1) {
g__winP = NULL;
WinCloseWindow(formP);
AppSendStopEvent();
handled = TRUE;
}
break;
}
return handled;
}
//////////////////////////////////////////////////////////////////////////
// 串口下載窗體處理函數(shù)
//
Boolean App_CCD_CommCenterAppHandleEvent(void *globalVarPtr, EventPtr eventP)
{
//CommCenter_DEMOGVRType * pVar = (CommCenter_DEMOGVRType *)globalVarPtr;
WinHandle formP;
Boolean handled = FALSE;
if (eventP->eType == frmOpenEvent)
{
formP = WinGetWindowPtrByResId(eventP->sParam1);
WinSetActiveWindow(formP);
switch (eventP->sParam1)
{
case Com_ID_FrmProgress:
WinSetEventHandlerEx (formP, CommCenterAppFrmProgressHandleEvent);
break;
default: break;
}
handled = TRUE;
}
return handled;
}
//////////////////////////////////////////////////////////////////////////
// 串口下載應(yīng)用入口
//
void CCD_CommCenterAppMain(UInt32 cmd, void *cmdPBP)
{
CommCenter_DEMOGVRType *pVar;
Int32 r;
switch(cmd)
{
case SYSTEM_START_REGISTER: // 終端操作系統(tǒng)啟動(dòng)時(shí)進(jìn)入
case SYSTEM_RESTART_REGISTER: //終端操作系統(tǒng)重新啟動(dòng)時(shí)進(jìn)入
r = AppRegister_DataTypeAdd((Char *)"Comm_IOType", NULL);
r = AppRegister_MethodAdd((Char *)"Comm_IOType", (Char *)"Comm_IO", 2, METHOD_THREAD);
break;
case 2:
CommCenter_IOThread(); //線程處理過程
break;
case 0: // 在終端操作界面點(diǎn)擊圖標(biāo)時(shí)進(jìn)入
//應(yīng)用進(jìn)行本功能的初始化工作
pVar = mcMalloc(sizeof(CommCenter_DEMOGVRType));
MemSet(pVar, 0, sizeof(CommCenter_DEMOGVRType));
//初始化并注冊(cè)GUI應(yīng)用,設(shè)置應(yīng)用消息處理函數(shù)和主窗口ID
WM_GuiAppInit(pVar, App_CCD_CommCenterAppHandleEvent, Com_ID_FrmProgress);
//缺省的事件處理循環(huán),一般來說,不要更改
AppDefaultEventLoop();
//注銷GUI應(yīng)用,釋放占用的資源
WM_GuiAppStop();
//應(yīng)用進(jìn)行本功能的資源釋放工作
mcFree(pVar);
break;
default:
break;
};
return;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -