From 61deef5cdf96cbfdd6ad45be49e80d597c00ca65 Mon Sep 17 00:00:00 2001 From: QuakeGod <QuakeGod@sina.com> Date: 星期二, 24 十二月 2024 08:37:21 +0800 Subject: [PATCH] 2024-12-24 --- MTerm1/NavView.cpp | 1430 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 1,270 insertions(+), 160 deletions(-) diff --git a/MTerm1/NavView.cpp b/MTerm1/NavView.cpp index 8ff6ad9..1926e63 100644 --- a/MTerm1/NavView.cpp +++ b/MTerm1/NavView.cpp @@ -6,6 +6,7 @@ #include "NavView.h" #include "MTerm1.h" +#include "../MyLib/Functions.hpp" #define IDC_NAVTREE1 1046 class CClassViewMenuButton : public CMFCToolBarMenuButton @@ -57,6 +58,9 @@ // ON_COMMAND(ID_CLASS_DEFINITION, OnClassDefinition) // ON_COMMAND(ID_CLASS_PROPERTIES, OnClassProperties) ON_COMMAND(ID_NEW_FOLDER, OnNewFolder) + ON_COMMAND(ID_NAV_SETCOMM, OnSetComm) + ON_COMMAND(ID_NAV_CONNECT, OnConnect) + ON_COMMAND(ID_NAV_DISCONNECT, OnDisConnect) ON_WM_PAINT() ON_WM_SETFOCUS() ON_COMMAND_RANGE(ID_SORTING_GROUPBYTYPE, ID_SORTING_SORTBYACCESS, OnSort) @@ -65,6 +69,23 @@ ON_NOTIFY(NM_CLICK, IDC_NAVTREE1, OnNMClkNavTree1) ON_WM_TIMER() + ON_COMMAND(ID_MENU_NAV_SET_CONN, &CNavView::OnMenuNavSetConn) + ON_COMMAND(ID_MENU_NAV_CONNECT, &CNavView::OnMenuNavConnect) + ON_COMMAND(ID_MENU_NAV_DISCONNECT, &CNavView::OnMenuNavDisconnect) + ON_COMMAND(ID_MENU_NV_UPDATE_FIRMWARE, &CNavView::OnMenuNvUpdateFirmware) + ON_COMMAND(ID_MENU_NV_DEVICE_READ_INFO, &CNavView::OnMenuNvDeviceReadInfo) + + ON_COMMAND(ID_LED_BLINK, &CNavView::OnLedBlink) + ON_COMMAND(ID_RESET_DEVICE, &CNavView::OnResetDevice) + ON_COMMAND(ID_REMOTE_REFRESH_DATA, &CNavView::OnRemoteRefreshData) + ON_COMMAND(ID_REMOTE_BLINK, &CNavView::OnRemoteBlinkLED) + ON_COMMAND(ID_REMOTE_DEVICE_RESET, &CNavView::OnRemoteDeviceReset) + ON_COMMAND(ID_REMOTE_UPDATE_FIRMWARE, &CNavView::OnRemoteUpdateFirmware) + ON_COMMAND(ID_REMOTE_BLINK_LED_ALL, &CNavView::OnRemoteBlinkLedAll) + ON_COMMAND(ID_PORT_RESET, &CNavView::OnPortReset) + ON_COMMAND(ID_PORT_RESET_ALL_CHILD, &CNavView::OnPortResetAllChild) +// ON_COMMAND(ID_COMMTEST, &CNavView::OnCommtest) +// ON_COMMAND(ID_DEVICE_CONFIG, &CNavView::OnDeviceConfig) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// @@ -88,8 +109,8 @@ } m_NavViewTree.SetExtendedStyle(TVS_EX_DOUBLEBUFFER, TVS_EX_DOUBLEBUFFER); // 鍔犺浇鍥惧儚: - m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_SORT); - m_wndToolBar.LoadToolBar(IDR_SORT, 0, 0, TRUE /* 宸查攣瀹�*/); + m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_NAV_TOOLBAR); + m_wndToolBar.LoadToolBar(IDR_NAV_TOOLBAR, 0, 0, TRUE /* 宸查攣瀹�*/); OnChangeVisualStyle(); @@ -102,7 +123,7 @@ m_wndToolBar.SetRouteCommandsViaFrame(FALSE); CMenu menuSort; - menuSort.LoadMenu(IDR_POPUP_SORT); + menuSort.LoadMenu(IDR_POPUP_NAV); m_wndToolBar.ReplaceButton(ID_SORT_MENU, CClassViewMenuButton(menuSort.GetSubMenu(0)->GetSafeHmenu())); @@ -127,117 +148,6 @@ AdjustLayout(); } -void CNavView::FillClassView() -{ - HTREEITEM hRoot1 = m_NavViewTree.InsertItem(_T("杩炴帴1 Via COM3 230400 8-N-1 KLinkV1.00"), 0, 0); - m_NavViewTree.SetItemState(hRoot1, TVIS_BOLD, TVIS_BOLD); - HTREEITEM hItem; - HTREEITEM hClass1 = m_NavViewTree.InsertItem(_T("KL10-E16D-N1 1/1 Run, Good"), 5, 5, hRoot1); - m_NavViewTree.SetItemData(hClass1, 10); - hItem = m_NavViewTree.InsertItem(_T("璁惧淇℃伅"), 3, 3, hClass1); - m_NavViewTree.SetItemData(hItem, 11); - hItem = m_NavViewTree.InsertItem(_T("宸ヤ綔鐘舵��,绯荤粺鍙傛暟"), 3, 3, hClass1); - m_NavViewTree.SetItemData(hItem, 12); - - HTREEITEM hPort2 = m_NavViewTree.InsertItem(_T("绔彛2 485 KBus 鏈満鍦板潃(0)/5 Run "), 1, 1, hClass1); - m_NavViewTree.SetItemData(hPort2, 13); - hItem = m_NavViewTree.InsertItem(_T("1 KL10-E08D-N1 Run Good"), 5, 5, hPort2); - m_NavViewTree.SetItemData(hItem, 131); - hItem = m_NavViewTree.InsertItem(_T("2 KL10-E08D-N1 Run bad"), 5, 5, hPort2); - m_NavViewTree.SetItemData(hItem, 132); - hItem = m_NavViewTree.InsertItem(_T("3 KL10-E08D-N1 Run Good"), 5, 5, hPort2); - m_NavViewTree.SetItemData(hItem, 133); - hItem = m_NavViewTree.InsertItem(_T("4 KL10-E08D-N1 Run Good"), 5, 5, hPort2); - m_NavViewTree.SetItemData(hItem, 134); - hItem = m_NavViewTree.InsertItem(_T("5 KL10-E08D-N1 Run bad"), 5, 5, hPort2); - m_NavViewTree.SetItemData(hItem, 135); - - HTREEITEM hPort3 = m_NavViewTree.InsertItem(_T("绔彛3 WireLess "), 1, 1, hClass1); - m_NavViewTree.SetItemData(hPort3, 14); - - m_NavViewTree.SetBkColor(COLORREF(0xf0f0f0f0) ); - - m_NavViewTree.Expand(hRoot1, TVE_EXPAND); - - HTREEITEM hClass2 = m_NavViewTree.InsertItem(_T("CFakeAboutDlg"), 1, 1, hRoot1); - m_NavViewTree.SetItemData(hClass2, 20); - hItem = m_NavViewTree.InsertItem(_T("CFakeAboutDlg()"), 3, 3, hClass2); - m_NavViewTree.SetItemData(hItem, 21); - - HTREEITEM hClass3 = m_NavViewTree.InsertItem(_T("CFakeAppDoc"), 1, 1, hRoot1); - m_NavViewTree.SetItemData(hClass3, 30); - hItem = m_NavViewTree.InsertItem(_T("CFakeAppDoc()"), 4, 4, hClass3); - m_NavViewTree.SetItemData(hItem, 31); - hItem = m_NavViewTree.InsertItem(_T("~CFakeAppDoc()"), 3, 3, hClass3); - m_NavViewTree.SetItemData(hItem, 32); - hItem = m_NavViewTree.InsertItem(_T("OnNewDocument()"), 3, 3, hClass3); - m_NavViewTree.SetItemData(hItem, 33); - - HTREEITEM hClass4 = m_NavViewTree.InsertItem(_T("CFakeAppView"), 1, 1, hRoot1); - m_NavViewTree.SetItemData(hClass4, 40); - hItem = m_NavViewTree.InsertItem(_T("CFakeAppView()"), 4, 4, hClass4); - m_NavViewTree.SetItemData(hItem, 41); - hItem = m_NavViewTree.InsertItem(_T("~CFakeAppView()"), 3, 3, hClass4); - m_NavViewTree.SetItemData(hItem, 42); - hItem = m_NavViewTree.InsertItem(_T("GetDocument()"), 3, 3, hClass4); - m_NavViewTree.SetItemData(hItem, 43); - m_NavViewTree.Expand(hClass4, TVE_EXPAND); - - HTREEITEM hClass5 = m_NavViewTree.InsertItem(_T("Globals"), 2, 2, hRoot1); - m_NavViewTree.SetItemData(hClass5, 50); - hItem = m_NavViewTree.InsertItem(_T("theFakeApp"), 5, 5, hClass5); - m_NavViewTree.SetItemData(hItem, 51); - m_NavViewTree.Expand(hClass5, TVE_EXPAND); - - HTREEITEM hRoot2 = m_NavViewTree.InsertItem(_T("杩炴帴鐘舵��2"), 0, 0); - - m_NavViewTree.SetItemState(hRoot2, TVIS_BOLD, TVIS_BOLD); - - -} - -void CNavView::OnContextMenu(CWnd* pWnd, CPoint point) -{ - CTreeCtrl* pWndTree = (CTreeCtrl*)&m_NavViewTree; - ASSERT_VALID(pWndTree); - - if (pWnd != pWndTree) - { - CDockablePane::OnContextMenu(pWnd, point); - return; - } - - if (point != CPoint(-1, -1)) - { - // 閫夋嫨宸插崟鍑荤殑椤�: - CPoint ptTree = point; - pWndTree->ScreenToClient(&ptTree); - - UINT flags = 0; - HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags); - if (hTreeItem != nullptr) - { - pWndTree->SelectItem(hTreeItem); - } - } - - pWndTree->SetFocus(); - CMenu menu; - menu.LoadMenu(IDR_POPUP_SORT); - - CMenu* pSumMenu = menu.GetSubMenu(0); - - if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx))) - { - CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu; - - if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE)) - return; - - ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu); - UpdateDialogControls(this, FALSE); - } -} void CNavView::AdjustLayout() { @@ -304,52 +214,8 @@ int CNavView::DelayInit() { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. - FillClassView(); + FillDeviceView(); return 0; -} - -int CNavView::UpdateDisplay() -{ - // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. -// m_NavViewTree.DeleteAllItems(); -// FillClassView(); - CString s1; - HTREEITEM hroot1 = m_NavViewTree.GetRootItem(); - HTREEITEM hItem1 = m_NavViewTree.GetChildItem(hroot1); - nDisplayCount++; - s1.Format(_T("KL10-E16D-N1 1/1 Run, Good %d"), nDisplayCount); - m_NavViewTree.SetItemText(hItem1, s1); - return 0; -} - -void CNavView::OnUpdateSort(CCmdUI* pCmdUI) -{ - pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort); -} - -void CNavView::OnClassAddMemberFunction() -{ - AfxMessageBox(_T("娣诲姞鎴愬憳鍑芥暟...")); -} - -void CNavView::OnClassAddMemberVariable() -{ - // TODO: 鍦ㄦ澶勬坊鍔犲懡浠ゅ鐞嗙▼搴忎唬鐮� -} - -void CNavView::OnClassDefinition() -{ - // TODO: 鍦ㄦ澶勬坊鍔犲懡浠ゅ鐞嗙▼搴忎唬鐮� -} - -void CNavView::OnClassProperties() -{ - // TODO: 鍦ㄦ澶勬坊鍔犲懡浠ゅ鐞嗙▼搴忎唬鐮� -} - -void CNavView::OnNewFolder() -{ - AfxMessageBox(_T("鏂板缓鏂囦欢澶�...")); } void CNavView::OnPaint() @@ -398,9 +264,405 @@ m_NavViewTree.SetImageList(&m_NavViewImages, TVSIL_NORMAL); m_wndToolBar.CleanUpLockedImages(); - m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_SORT_24 : IDR_SORT, 0, 0, TRUE /* 閿佸畾*/); + m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_NAV_TOOLBAR_24 : IDR_NAV_TOOLBAR, 0, 0, TRUE /* 閿佸畾*/); } +void CNavView::FillDeviceView() +{ + HTREEITEM hRoot1 = m_NavViewTree.InsertItem(_T("杩炴帴1 No Connect"), 0, 0); + m_NavViewTree.SetItemState(hRoot1, TVIS_BOLD, TVIS_BOLD); + + HTREEITEM hItem; + HTREEITEM hDevice1 = m_NavViewTree.InsertItem(_T("KL10-E08D-N1 1/1"), 5, 5, hRoot1); + m_NavViewTree.SetItemData(hDevice1, MENU_DEVICE|0); + + m_NavViewTree.Expand(hRoot1, TVE_EXPAND); + +/* + hItem = m_NavViewTree.InsertItem(_T("璁惧淇℃伅"), 3, 3, hDevice1); + m_NavViewTree.SetItemData(hItem, MENU_PROPERTY|0); + hItem = m_NavViewTree.InsertItem(_T("宸ヤ綔鐘舵��,绯荤粺鍙傛暟"), 3, 3, hDevice1); + m_NavViewTree.SetItemData(hItem, MENU_PROPERTY|1); + HTREEITEM hPort1 = m_NavViewTree.InsertItem(_T("绔彛1 232 KLink 鏈満鍦板潃(1)/5 Run "), 1, 1, hDevice1); + m_NavViewTree.SetItemData(hPort1, MENU_PORT|0); + + HTREEITEM hPort2 = m_NavViewTree.InsertItem(_T("绔彛2 485 KBus 鏈満鍦板潃(0)/5 Run "), 1, 1, hDevice1); + m_NavViewTree.SetItemData(hPort2, MENU_PORT|1); + hItem = m_NavViewTree.InsertItem(_T("1 KL10-E08D-N1 Run Good"), 5, 5, hPort2); + m_NavViewTree.SetItemData(hItem, MENU_REMOTE_DEVICE|0); + HTREEITEM hPort3 = m_NavViewTree.InsertItem(_T("绔彛3 WireLess "), 1, 1, hDevice1); + m_NavViewTree.SetItemData(hPort3, MENU_PORT|2); + + m_NavViewTree.SetBkColor(COLORREF(0xf0f0f0f0)); + + HTREEITEM hDevice2 = m_NavViewTree.InsertItem(_T("KL10-E16D-N1 1/1"), 5, 5, hRoot1); + m_NavViewTree.SetItemData(hDevice2, MENU_DEVICE | 1); + + // */ +} + +void CNavView::OnContextMenu(CWnd* pWnd, CPoint point) +{ + CTreeCtrl* pWndTree = (CTreeCtrl*)&m_NavViewTree; + ASSERT_VALID(pWndTree); + + if (pWnd != pWndTree) + { + CDockablePane::OnContextMenu(pWnd, point); + return; + } + HTREEITEM hTreeItem = nullptr; + if (point != CPoint(-1, -1)) + { + // 閫夋嫨宸插崟鍑荤殑椤�: + CPoint ptTree = point; + pWndTree->ScreenToClient(&ptTree); + + UINT flags = 0; + hTreeItem = pWndTree->HitTest(ptTree, &flags); + if (hTreeItem != nullptr) + { + pWndTree->SelectItem(hTreeItem); + } + } + pWndTree->SetFocus(); + DWORD_PTR ItemData = 0; + if (hTreeItem != nullptr) { + ItemData = m_NavViewTree.GetItemData(hTreeItem); + } + + CMenu menu; + // menu.LoadMenu(IDR_POPUP_SORT); + menu.LoadMenu(IDR_POPUP_NAV); + CMenu* pSubMenu; + HTREEITEM hRoot1 = m_NavViewTree.GetRootItem(); + HTREEITEM hDevice1 = m_NavViewTree.GetNextItem(hRoot1, TVGN_CHILD); + if (hTreeItem == hRoot1) { + pSubMenu = menu.GetSubMenu(1); // 杩炴帴鑿滃崟 + } + else if (hTreeItem == hDevice1 ){ + pSubMenu = menu.GetSubMenu(2); //璁惧鑿滃崟 + } + else if (ItemData & MENU_PROPERTY){ + pSubMenu = menu.GetSubMenu(3); //灞炴�ц彍鍗� + } + else if (ItemData & MENU_PORT) { + pSubMenu = menu.GetSubMenu(4); //绔彛鑿滃崟 + } + else if (ItemData & MENU_REMOTE_DEVICE) { + pSubMenu = menu.GetSubMenu(5); //杩滅▼璁惧鑿滃崟 + } + else { + pSubMenu = menu.GetSubMenu(0); //榛樿鑿滃崟 + } + + + pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); +/* + if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx))) + { + CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu; + + if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSubMenu->m_hMenu, FALSE, TRUE)) + return; + + ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu); + UpdateDialogControls(this, FALSE); + } +*/ + menu.DestroyMenu(); + +} + +void CNavView::OnUpdateSort(CCmdUI* pCmdUI) +{ + pCmdUI->SetCheck(pCmdUI->m_nID == m_nCurrSort); +} + +void CNavView::OnClassAddMemberFunction() +{ + AfxMessageBox(_T("娣诲姞鎴愬憳鍑芥暟...")); +} + +void CNavView::OnClassAddMemberVariable() +{ + // TODO: 鍦ㄦ澶勬坊鍔犲懡浠ゅ鐞嗙▼搴忎唬鐮� +} + +void CNavView::OnClassDefinition() +{ + // TODO: 鍦ㄦ澶勬坊鍔犲懡浠ゅ鐞嗙▼搴忎唬鐮� +} + +void CNavView::OnClassProperties() +{ + // TODO: 鍦ㄦ澶勬坊鍔犲懡浠ゅ鐞嗙▼搴忎唬鐮� +} + +void CNavView::OnNewFolder() +{ + AfxMessageBox(_T("鏂板缓鏂囦欢澶�...")); +} + +int CNavView::GetDocCount() +{ + // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. +/* + + int nCount1 = 0; + + POSITION Templatepos = AfxGetApp()->m_pDocManager->GetFirstDocTemplatePosition(); + while (Templatepos != NULL) + { + CDocTemplate* pDocTemplate = AfxGetApp()->m_pDocManager->GetNextDocTemplate(Templatepos); + + POSITION pos = pDocTemplate->GetFirstDocPosition(); + while (pos != NULL) + { + CDocument * pDoc = pDocTemplate->GetNextDoc(pos); + nCount1++; + //if (pDoc->IsModified()) // 鍙繚瀛樿淇敼鐨勬枃妗� + //{ + // pDoc->DoFileSave(); + //} + } + } + return nCount1; +*/ + return 0; +} + +int CNavView::UpdateDisplay() +{ + // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. +// m_NavViewTree.DeleteAllItems(); +// FillDeviceView(); + nDisplayCount++; + + KLink1* pMyKLink1 = &theApp.MyKLink1; + CString s1; + HTREEITEM hRoot1 = m_NavViewTree.GetRootItem(); + if (theApp.MyKLink1.m_bOpened) { + s1.Format(_T("杩炴帴1 ")); + s1.AppendFormat(_T("COM%d %d %s "), pMyKLink1->MySerPort1.m_nPort, pMyKLink1->MySerPort1.m_nBaudRate, pMyKLink1->MySerPort1.m_Settings); + s1.AppendFormat(_T("S %d R %d D %d"), theApp.MyKLink1.m_nTotalSendCount,theApp.MyKLink1.m_nTotalRecvCount, nDisplayCount); +///* + if ( (nDisplayCount & 0x1f) == 0) { + bPortRegsUpdated[0] = 0; + bPortRegsUpdated[1] = 0; + bPortRegsUpdated[2] = 0; + } +// */ + } + else { + s1.Format(_T("杩炴帴1 No Connect")); + } + m_NavViewTree.SetItemText(hRoot1, s1); + HTREEITEM hDevice1 = m_NavViewTree.GetChildItem(hRoot1); + +// m_NavViewTree.DeleteItem(hDevice1); + + if (!theApp.MyKLink1.m_bOpened) { + s1.Format(_T("No Connect")); + } + else { + s1.Format(_T("Dev %04X %s Run"), m_DeviceInfo.nDeviceTypeVer,DeviceTypeToStr(m_DeviceInfo.nDeviceTypeVer)); + } + m_NavViewTree.SetItemText(hDevice1, s1); + if (!theApp.MyKLink1.m_bOpened) + { + HTREEITEM hItem11 = m_NavViewTree.GetNextItem(hDevice1, TVGN_CHILD); + s1.Format(_T("璁惧鍙傛暟")); + m_NavViewTree.SetItemText(hItem11, s1); + HTREEITEM hItem12 = m_NavViewTree.GetNextItem(hItem11, TVGN_NEXT); + m_NavViewTree.SetItemText(hItem12, _T("宸ヤ綔鐘舵��")); + + HTREEITEM hItem13 = m_NavViewTree.GetNextItem(hItem12, TVGN_NEXT); + if (hItem13 != nullptr) { + bPortRegsUpdated[0] = 0; + bPortRegsUpdated[1] = 0; + bPortRegsUpdated[2] = 0; + m_NavViewTree.DeleteItem(hItem13); + HTREEITEM hItem13 = m_NavViewTree.GetNextItem(hItem12, TVGN_NEXT); + } + + }else + { + HTREEITEM hItem11 = m_NavViewTree.GetNextItem(hDevice1, TVGN_CHILD); + if (hItem11 == nullptr) { + hItem11 = m_NavViewTree.InsertItem(_T("璁惧鍙傛暟 "), 3, 3, hDevice1); + m_NavViewTree.Expand(hDevice1, TVE_EXPAND); + } + s1.Format(_T("璁惧鍙傛暟 V%d.%02d KLink %04X KBus %04X In %d Out %d"), + m_infoblock.nProgVerMajor, m_infoblock.nProgVerMinor, m_infoblock.nKLinkVer, m_infoblock.nKBusVer, m_DeviceInfo.InBitCount, m_DeviceInfo.OutBitCount); + m_NavViewTree.SetItemText(hItem11, s1); + HTREEITEM hItem12 = m_NavViewTree.GetNextItem(hItem11, TVGN_NEXT); + if (hItem12 == nullptr) { + hItem12 = m_NavViewTree.InsertItem(_T("宸ヤ綔鐘舵�� "), 3, 3, hDevice1); + m_NavViewTree.Expand(hDevice1, TVE_EXPAND); + } + m_NavViewTree.SetItemText(hItem12, _T("宸ヤ綔鐘舵��,绯荤粺鍙傛暟,IO鐘舵�� hItem12")); + HTREEITEM hPort1 = hItem12; + USHORT nReaded = 0; + USHORT DataBuf1[256]; + for (int i = 0; i < m_DeviceInfo.nPortCount; i++) { + hPort1 = m_NavViewTree.GetNextItem(hPort1, TVGN_NEXT); + if (hPort1 == nullptr) { + hPort1 = m_NavViewTree.InsertItem(_T("绔彛1 "), 1, 1, hDevice1); + m_NavViewTree.Expand(hDevice1, TVE_EXPAND); + } + if (theApp.MyKLink1.m_bOpened && !bPortRegsUpdated[i]) { + int res1 = theApp.MyKLink1.GetPortInfo(1, i, sizeof(stPortDef), &nReaded, DataBuf1); + if (res1 == KLink1::KL_OK) { + pstPortDef thepPortReg = (pstPortDef)DataBuf1; + PortDefs[i] = *thepPortReg; + s1.Format(_T("绔彛%d (%02X)%s (%02X)%s 鑳藉姏 %04X M %d 绔欏彿 %d/%d H %d"), i + 1, + thepPortReg->nPortHardType, PortHardTypeToStr(thepPortReg->nPortHardType), thepPortReg->nPortUseType, + PortUseTypeToStr(thepPortReg->nPortUseType), thepPortReg->ability, thepPortReg->bMaster, thepPortReg->StationId, thepPortReg->nMaxStations, thepPortReg->nHealth); + m_NavViewTree.SetItemText(hPort1, s1); + m_NavViewTree.SetItemData(hPort1, MENU_PORT | i); + + bPortRegsUpdated[i] = 1; + break; + } + else { + s1.Format(_T("GetPortInfo %d = %d len %d %s"), i, res1, &nReaded,theApp.MyKLink1.m_resultStr); + DbgLog(s1); + s1.Format(_T("绔彛%d --------- ???? "), i + 1); + m_NavViewTree.SetItemText(hPort1, s1); + m_NavViewTree.SetItemData(hPort1, MENU_PORT | i); + } + } + if (bPortRegsUpdated[i] && (PortDefs[i].nPortUseType == PortUse_KBus || PortDefs[i].nPortUseType == PortUse_KRF)) { + HTREEITEM hChild1 = m_NavViewTree.GetNextItem(hPort1, TVGN_CHILD); + int nChildCount = PortDefs[i].nMaxStations; + for (int j = 1; j <= nChildCount; j++) { + if (j != 1) hChild1 = m_NavViewTree.GetNextItem(hChild1, TVGN_NEXT); + if (hChild1 == nullptr) { + s1.Format(_T("瀛愭満%d "), j); + hChild1 = m_NavViewTree.InsertItem(s1, 5, 5, hPort1); + m_NavViewTree.SetItemData(hChild1, MENU_REMOTE_DEVICE | (j)); + m_NavViewTree.Expand(hPort1, TVE_EXPAND); + } + //if (j < LastUpdateIndex) continue; + if (bPortDeviceUpdated[j]) continue; + int res2 = theApp.MyKLink1.GetPortChildInfo(1, i, j, sizeof(stDeviceInfo), &nReaded, DataBuf1); //sizeof(stDeviceInfo) + if (res2 == KLink1::KL_OK) { + s1.Format(_T("GetChildInfo %d %d = %d B\r\n"), i, j, nReaded); + for (int k = 0; k < nReaded; k++) { + s1.AppendFormat(_T("%02X "), ((unsigned char*)DataBuf1)[k]); + } + // SysLog(s1); + stDeviceInfo* ptheInfo = (stDeviceInfo*)DataBuf1; + PortDeviceInfos[j] = *ptheInfo; + s1.Format(_T("瀛�%d (%04X)%s V%d.%02d %d/%d "), + j, ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount); + m_NavViewTree.SetItemText(hChild1, s1); + m_NavViewTree.SetItemData(hChild1, MENU_REMOTE_DEVICE | (j)); + } + bPortDeviceUpdated[j] = 1; + break; + } + LastUpdateIndex[i]++; + if (LastUpdateIndex[i] > nChildCount) { LastUpdateIndex[i] = 0; } + s1.Format(_T("i %d LastUpdated %d nChildCount %d nMaxStations %d \r\n"),i, LastUpdateIndex[i],nChildCount, PortDefs[i].nMaxStations); + // SysLog(s1); + + } + ///* + if (bPortRegsUpdated[i] && PortDefs[i].nPortUseType == PortUse_KBus ) { + HTREEITEM hChild1 = m_NavViewTree.GetNextItem(hPort1, TVGN_CHILD); + int nChildCount = PortDefs[i].nMaxStations; + int j = LastUpdateIndex[i] + 1; + for (int j = 1; j <= nChildCount; j++) { + if (j != 1) hChild1 = m_NavViewTree.GetNextItem(hChild1, TVGN_NEXT); + if (hChild1 == nullptr) { + s1.Format(_T("瀛愭満%d "), j); + hChild1 = m_NavViewTree.InsertItem(s1, 5, 5, hPort1); + m_NavViewTree.Expand(hPort1, TVE_EXPAND); + } + if (j < LastUpdateIndex[i]) continue; + //if (bPortDeviceUpdated[j]) continue; + int res2 = theApp.MyKLink1.GetPortChnInfo(1, i, j, sizeof(stChnStat), &nReaded, DataBuf1); //sizeof(stDeviceInfo) + if (res2 == KLink1::KL_OK) { + s1.Format(_T("GetChnInfo %d %d = %d B\r\n"), i, j, nReaded); + for (int k = 0; k < nReaded; k++) { + s1.AppendFormat(_T("%02X "), ((unsigned char*)DataBuf1)[k]); + } + // SysLog(s1); + stDeviceInfo* ptheInfo = &PortDeviceInfos[j]; + stChnStat* ptheChnInfo = (stChnStat*)DataBuf1; + + s1.Format(_T("瀛�%d (%04X)%s V%d.%02d %d/%d 涓㈠寘鐜�(%.2f%%) 鏀跺彂(%d/%d) "), j, + ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount + , ptheChnInfo->LostPackets * 100.0 / ptheChnInfo->SendPackets, ptheChnInfo->RecvPackets, ptheChnInfo->SendPackets); + m_NavViewTree.SetItemText(hChild1, s1); + } + // bPortDeviceUpdated[j] = 1; + break; + } + } + // */ + ///* + if (bPortRegsUpdated[i] && PortDefs[i].nPortUseType == PortUse_KRF) { + HTREEITEM hChild1 = m_NavViewTree.GetNextItem(hPort1, TVGN_CHILD); + int nChildCount = PortDefs[i].nMaxStations; + int j = LastUpdateIndex[i] + 1; + for (int j = 1; j <= nChildCount; j++) { + if (j != 1) hChild1 = m_NavViewTree.GetNextItem(hChild1, TVGN_NEXT); + if (hChild1 == nullptr) { + s1.Format(_T("瀛愭満%d "), j); + hChild1 = m_NavViewTree.InsertItem(s1, 5, 5, hPort1); + m_NavViewTree.Expand(hPort1, TVE_EXPAND); + } + if (j < LastUpdateIndex[i]) continue; + //if (bPortDeviceUpdated[j]) continue; + int res2 = theApp.MyKLink1.GetPortChnInfo(1, i, j, sizeof(stKwChnStat), &nReaded, DataBuf1); //sizeof(stDeviceInfo) + if (res2 == KLink1::KL_OK) { + s1.Format(_T("GetChnInfo %d %d = %d B\r\n"), i, j, nReaded); + for (int k = 0; k < nReaded; k++) { + s1.AppendFormat(_T("%02X "), ((unsigned char*)DataBuf1)[k]); + } + // SysLog(s1); + stDeviceInfo* ptheInfo = &PortDeviceInfos[j]; + stKwChnStat* ptheChnInfo = (stKwChnStat*)DataBuf1; + + s1.Format(_T("瀛�%d (%04X)%s V%d.%02d %d/%d 涓㈠寘鐜�(%.2f%%) 鏀跺彂(%d/%d) "), j, + ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount + , ptheChnInfo->LostPackets * 100.0 / ptheChnInfo->sentCount, ptheChnInfo->recvCount, ptheChnInfo->sentCount); + m_NavViewTree.SetItemText(hChild1, s1); + } + else { + s1.Format(_T("GetChnInfo %d %d = %d B\r\n"), i, j, nReaded); + SysLog(s1); + } + // bPortDeviceUpdated[j] = 1; + break; + } + } + // */ + } + } + + + HTREEITEM hDevice2 = m_NavViewTree.GetNextItem(hDevice1, TVGN_NEXT); + m_NavViewTree.SetItemText(hDevice2, _T("hDevice2")); + + +// HTREEITEM hDevice1 = m_NavViewTree.InsertItem(s1, 5, 5, hRoot1); +// m_NavViewTree.SetItemData(hDevice1, 10); +// m_NavViewTree.SetItemText(hDevice1, s1); + + /* + AfxGetApp()->m_pDocManager->GetFirstDocTemplatePosition + CMDIFrameWnd* pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; + CMDIChildWnd* pChild = (CMDIChildWnd*)pFrame->GetActiveFrame(); + CView* pV = (CView*)pChild->GetActiveView(); + CMTerm1Doc* pDoc = (CMTerm1Doc*)(pV->GetDocument()); + */ + + return 0; +} void CNavView::OnNMClkNavTree1(NMHDR* pNMHDR, LRESULT* pResult) { LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); @@ -439,4 +701,852 @@ *pResult = 0; } +void CNavView::OnMenuNavSetConn() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + theApp.MyKLink1.SetCommParam(); +} + +void CNavView::OnSetComm() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + theApp.MyKLink1.SetCommParam(); +} + +void CNavView::OnConnect() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + unsigned short buf1[64]; + unsigned short len1; + if (!theApp.MyKLink1.m_bCommParamSet) { + theApp.MyKLink1.m_nPort = 6; + } + int res = theApp.MyKLink1.Connect(); + if (res == KLink1::KL_OK) { + Sleep(100); + theApp.MyKLink1.MySerPort1.ClearBuf(); + + int res2 = theApp.MyKLink1.GetInfo(1, &len1, buf1); + s1.Format(_T("GetInfo = %d %d \r\n"), res2, len1); + if (res2 == KLink1::KL_OK && len1 > 0) { + pKMInfoBlock pinfob = (pKMInfoBlock)buf1; + m_infoblock = *pinfob; + + for (int i = 0; i < 8; i++) { + bPortRegsUpdated[i] = 0; + } + for (int i = 0; i < 16; i++) { + bPortDeviceUpdated[i] = 0; + } + m_DeviceInfo.nDeviceTypeVer = pinfob->nDeviceTypeVer; + m_DeviceInfo.InBitCount = pinfob->nDInput; + m_DeviceInfo.OutBitCount = pinfob->nDOutput; + m_DeviceInfo.nPortCount = pinfob->nPorts; + + HTREEITEM hRoot1 = m_NavViewTree.GetRootItem(); + if (theApp.MyKLink1.m_bOpened) { + s1.Format(_T("杩炴帴1 ")); + s1.AppendFormat(_T("COM%d %d %s "), theApp.MyKLink1.MySerPort1.m_nPort, theApp.MyKLink1.MySerPort1.m_nBaudRate, theApp.MyKLink1.MySerPort1.m_Settings); + s1.AppendFormat(_T("%d %d %d \r\n"), theApp.MyKLink1.m_nTotalSendCount, theApp.MyKLink1.m_nTotalRecvCount, nDisplayCount); + } + else { + s1.Format(_T("杩炴帴1 No Connect")); + } + m_NavViewTree.SetItemText(hRoot1, s1); + HTREEITEM hDevice1 = m_NavViewTree.GetChildItem(hRoot1); + m_NavViewTree.Expand(hDevice1, TVE_EXPAND); + + for (int i = 0; i < len1 / 2; i++) { + s1.AppendFormat(_T("%04X "), buf1[i]); + } + s1 += _T("\r\n"); + + s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer); + s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer); + s1.AppendFormat(_T(" nKLinkVer %04X \t"), pinfob->nKLinkVer); + s1.AppendFormat(_T(" nKBusVer %04X \r\n"), pinfob->nKBusVer); + s1.AppendFormat(_T(" nCapacity1 %d k \t"), pinfob->nCapacity1); + s1.AppendFormat(_T(" nCapacity2 %d k\r\n"), pinfob->nCapacity2); + s1.AppendFormat(_T(" nDInput %d \t"), pinfob->nDInput); + s1.AppendFormat(_T(" nDOutput %d \r\n"), pinfob->nDOutput); + s1.AppendFormat(_T(" nAInput %d \t"), pinfob->nAInput); + s1.AppendFormat(_T(" nAOutput %d \r\n"), pinfob->nAOutput); + s1.AppendFormat(_T(" nHInput %d \t"), pinfob->nHInput); + s1.AppendFormat(_T(" nHOutput %d \r\n"), pinfob->nHOutput); + s1.AppendFormat(_T(" nExt1 %d \t"), pinfob->nExt1); + s1.AppendFormat(_T(" nExt2 %d \r\n"), pinfob->nExt2); + s1.AppendFormat(_T(" nLogSize %d \r\n"), pinfob->nLogSize); + s1.AppendFormat(_T(" nPorts %d \r\n"), pinfob->nPorts); + s1.AppendFormat(_T(" nManSize %d \r\n"), pinfob->nManSize); + s1.AppendFormat(_T(" nAbility %d \r\n"), pinfob->nAbility); + s1.AppendFormat(_T(" nSwitchBits %d \r\n"), pinfob->nSwitchBits); + } + SysLog(s1); + int len0 = sizeof(stKMSysCfg); + UCHAR nType = 0; + res2 = theApp.MyKLink1.ReadSysCfgData(1, nType, 0, len0, &len1, buf1); + s1.Format(_T("GetSysCfg %d = %d %d \r\n"), len0, res2, len1); + if (res2 == KLink1::KL_OK && len1 > 0) { + for (int i = 0; i < len1 / 2; i++) { + s1.AppendFormat(_T("%04X "), buf1[i]); + } + s1 += _T("\r\n"); + pstKMSysCfg pSysCfg = (pstKMSysCfg)buf1; + s1.AppendFormat(_T("Version %04X \r\n"), pSysCfg->Version); + s1.AppendFormat(_T("WorkMode %04X \r\n"), pSysCfg->workmode); + s1.AppendFormat(_T("SwitchFunc %04X \r\n"), pSysCfg->SwitchFunc); + s1.AppendFormat(_T("CfgBlockCount %d \r\n"), pSysCfg->nCfgBlockCount); + + for (int j = 0; j < 2; j++) { + s1.AppendFormat(_T("COM %d \r\n"), j + 1); + s1.AppendFormat(_T("WorkMode %d \r\n"), pSysCfg->PortParams[j].WorkMode); + s1.AppendFormat(_T("Station %d \r\n"), pSysCfg->PortParams[j].Station); + s1.AppendFormat(_T("BaudRate %d \r\n"), pSysCfg->PortParams[j].BaudRate*100); + s1.AppendFormat(_T("ByteSize %d Parity %d StopBit %d \r\n"), pSysCfg->PortParams[j].ByteSize, pSysCfg->PortParams[j].Parity, pSysCfg->PortParams[j].StopBits); + s1.AppendFormat(_T("EndType %d \r\n"), pSysCfg->PortParams[j].EndType); + s1.AppendFormat(_T("EofChar %d \r\n"), pSysCfg->PortParams[j].EofChar); + s1.AppendFormat(_T("SofChar %d \r\n"), pSysCfg->PortParams[j].SofChar); + s1.AppendFormat(_T("EndTime %d \r\n"), pSysCfg->PortParams[j].EndTime); + s1.AppendFormat(_T("RecvAddr %d \r\n"), pSysCfg->PortParams[j].RecvAddr); + s1.AppendFormat(_T("RecvSize %d \r\n"), pSysCfg->PortParams[j].RecvSize); + } +/* + s1.AppendFormat(_T("InputParam \r\n")); + for (int j = 0; j < 16; j++) { + s1.AppendFormat(_T("%2d Filter0 %d Filter1 %d \r\n"),j, pSysCfg->InputParams[j].Filter0, pSysCfg->InputParams[j].Filter1); + } + s1.AppendFormat(_T("OutputParam \r\n")); + for (int j = 0; j < 16; j++) { + s1.AppendFormat(_T("%2d Hold1 %d Hold2 %d \r\n"),j, pSysCfg->OutputParams[j].Hold1, pSysCfg->OutputParams[j].Hold2); + } +// */ + s1.AppendFormat(_T("OutMapping \r\n")); + for (int j = 0; j < 8; j++) { +// s1.AppendFormat(_T("%d Map %04X \r\n"),j, pSysCfg->OutMappings[j]); + s1.AppendFormat(_T("%d Map %04X type %X Addr %02X bitPos %X\r\n"),j, pSysCfg->OutMappings[j].value,pSysCfg->OutMappings[j].type,pSysCfg->OutMappings[j].byteAddr,pSysCfg->OutMappings[j].bitPos); + } + s1.AppendFormat(_T("CfgBlockCount %d\r\n"), pSysCfg->nCfgBlockCount); + for (int j = 0; j < pSysCfg->nCfgBlockCount; j++) { + // s1.AppendFormat(_T("%d Map %04X \r\n"),j, pSysCfg->OutMappings[j]); + s1.AppendFormat(_T("%d type %X Size %d \r\n"), j, pSysCfg->CfgBlockInfos[j].nBlockType, pSysCfg->CfgBlockInfos[j].nBlockSize); + } + + } + SysLog(s1); + } +} +static const uint16_t crctalbeabs[] = { + 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, + 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 +}; + +static uint16_t crc16tablefast(uint8_t* ptr, uint16_t len) +{ + uint16_t crc = 0xffff; + uint16_t i; + uint8_t ch; + + for (i = 0; i < len; i++) { + ch = *ptr++; + crc = crctalbeabs[(ch ^ crc) & 15] ^ (crc >> 4); + crc = crctalbeabs[((ch >> 4) ^ crc) & 15] ^ (crc >> 4); + } + + return crc; +} + +void CNavView::OnDisConnect() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + theApp.MyKLink1.DisConnect(); + +} + +void CNavView::OnMenuNavConnect() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + OnConnect(); +} + +void CNavView::OnMenuNavDisconnect() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + OnDisConnect(); + +} + +void CNavView::OnMenuNvDeviceReadInfo() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + s1.Format(_T("璇诲彇璁惧 淇℃伅")); + SysLog(s1); + USHORT len1; + USHORT buf1[1024]; + int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1); + pKMInfoBlock pinfob = (pKMInfoBlock)buf1; + if (r2 == 0 && len1 > 0) { + for (int i = 0; i < len1 / 2; i++) { + s1.AppendFormat(_T("%04X "), buf1[i]); + } + s1 += _T("\r\n"); + + s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer); + s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer); + } + SysLog(s1); + myLogger1.UpdateLogDisplay(); +} + +void CNavView::OnDeviceConfig() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + s1.Format(_T("璁剧疆鍙傛暟")); + SysLog(s1); + USHORT len1; + USHORT buf1[1024]; + int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1); + pKMInfoBlock pinfob = (pKMInfoBlock)buf1; + if (r2 == 0 && len1 > 0) { + for (int i = 0; i < len1 / 2; i++) { + s1.AppendFormat(_T("%04X "), buf1[i]); + } + s1 += _T("\r\n"); + + s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer); + s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer); + } + SysLog(s1); + myLogger1.UpdateLogDisplay(); + + +} + +void CNavView::OnLedBlink() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + theApp.MyKLink1.BlinkLED(1, 5); +} + +void CNavView::OnResetDevice() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int r5 = theApp.MyKLink1.ResetDevice(1, 0); + s1.Format(_T("ResetDevice = %d"), r5); + SysLog(s1); + for (int i = 0; i < 8; i++) { + bPortRegsUpdated[i] = 0; + } + for (int i = 0; i < 16; i++) { + bPortDeviceUpdated[i] = 0; + } +} +void CNavView::OnCommtest() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + + /* + CView* pView; + pView = FindView(RUNTIME_CLASS(CMTerm1CtrlView)); + if (pView != NULL) { + ((CMDIFrameWndEx*)AfxGetMainWnd())->MDIActivate(pView->GetParent()); + // pView->SetActiveWindow(); + } + else { + s1 = GetTitle(); + //AfxMessageBox(s1); + ASSERT_VALID(theApp.m_pCtrlViewTemplate); + CFrameWnd* pFrame = theApp.m_pCtrlViewTemplate->CreateNewFrame(this, NULL); + ASSERT_KINDOF(CFrameWnd, pFrame); + theApp.m_pCtrlViewTemplate->InitialUpdateFrame(pFrame, this); + } + */ + int a = 0; +#pragma omp parrelle for + for (int i = 0; i < 1000; i++) { + a += i; + } + s1.Format(_T("a = %d "), a); + DbgLog(s1); + + + + +} + +void CNavView::OnMenuNvUpdateFirmware() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + s1.Format(_T("鏇存柊璁惧 鍥轰欢")); + SysLog(s1); + USHORT len1; + USHORT buf1[1024]; + int r2 = theApp.MyKLink1.GetInfo(1, &len1, buf1); + pKMInfoBlock pinfob = (pKMInfoBlock)buf1; + if (r2 == 0 && len1 > 0) { + for (int i = 0; i < len1 / 2; i++) { + s1.AppendFormat(_T("%04X "), buf1[i]); + } + s1 += _T("\r\n"); + + s1.AppendFormat(_T(" DeviceType %04X \t "), pinfob->nDeviceTypeVer); + s1.AppendFormat(_T(" nProgVer %04X \r\n"), pinfob->nProgVer); + } + SysLog(s1); + myLogger1.UpdateLogDisplay(); + unsigned char Appbuf[131072]; + unsigned char firmwarebuf[262144]; + + int nBtldrInfoOffset = 256; + int AppOffset = 4096; + int nAppInfoOffset = 256; + + int btldrLength = 0; + int AppLength = 0; + int FirmwareSize = 0; + + bool btldrfileLoaded = false; + bool appfileLoaded = false; + bool combinefileSaved = false; + + unsigned char filebuf[65536]; + unsigned int blocksize = 64; + stNewAppInfoBlock NewAppInfo; + + + CFileDialog dialog1(true); + INT_PTR r = dialog1.DoModal(); + if (r == IDOK) + { + CString sFilePathName = dialog1.GetPathName(); + //OpenFile + CFile file1; + CFileException e; + bool r = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e); + s1.Format(_T("Open File %s = %d"), sFilePathName, r); + DbgLog(s1); + if (r) + { + int fileLen1 = (int)file1.GetLength(); + file1.Read(filebuf, fileLen1); + file1.Close(); + unsigned int nBlkType = 0; + unsigned int nBlkVer = 0; + s1.Empty(); + pAppInfoBlock pAppinfo = (pAppInfoBlock)(filebuf + nAppInfoOffset); + s1.Format(_T("鏂囦欢淇℃伅 \r\n")); +// SetDlgItemText(IDC_STATIC_APP_INFO, s1); + if (pAppinfo->Hdr.nBlkSign == 0xaa55) { + s1.Empty(); + s1.Format(_T("鏂囦欢淇℃伅 ")); + // s1.AppendFormat(_T("鍚姩鏂囦欢 %s \r\n"), sFilePathName); + + s1.AppendFormat(_T("鏂囦欢澶у皬: %d \r\n"), fileLen1); + s1.AppendFormat(_T("淇℃伅鍧椾綅缃�: 0x%04X 淇℃伅鍧楀ぇ灏�: %d \r\n"), nAppInfoOffset, pAppinfo->Hdr.nBlkSize); + s1.AppendFormat(_T("淇℃伅鍧楃被鍨�: 0x%04X "), pAppinfo->Hdr.nBlkTypeVer); + nBlkType = (pAppinfo->Hdr.nBlkTypeVer) >> 8; + nBlkVer = pAppinfo->Hdr.nBlkTypeVer & 0xff; + if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 绫诲瀷1 鐗堟湰 %d) "), nBlkVer); } + else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 绫诲瀷2 鐗堟湰 %d) "), nBlkVer); } + else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App绫诲瀷1 鐗堟湰 %d) "), nBlkVer); } + else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App绫诲瀷2 鐗堟湰 %d) "), nBlkVer); } + else { s1.AppendFormat(_T(" (鏈煡绫诲瀷) ")); } + s1.AppendFormat(_T("\r\n")); + s1.AppendFormat(_T("搴旂敤鍖虹増鏈�: 0x%04X 瀵瑰簲妯″潡绫诲瀷: 0x%04X\r\n"), pAppinfo->nAppVer, pAppinfo->nAppDevice); + s1.AppendFormat(_T("搴旂敤鍖哄ぇ灏�: 0x%04X 瀹為檯浠g爜澶у皬: 0x%04X \r\n"), pAppinfo->nAppSize, pAppinfo->nAppDataSize); + s1.AppendFormat(_T("搴旂敤鍖哄湴鍧�: 0x%08X (鍋忕Щ %d )\r\n"), pAppinfo->nAppStartAddr, pAppinfo->nAppStartAddr - 0x08000000); + s1.AppendFormat(_T("淇℃伅鏆傚瓨鍖�: 0x%08X \r\n搴旂敤鏆傚瓨鍖�: 0x%08X \r\n"), pAppinfo->nAppStartOffset, pAppinfo->nApp); +// SetDlgItemText(IDC_STATIC_APP_INFO, s1); + + if (nBlkType == 0x03 || nBlkType == 0x04) { + memmove(Appbuf, filebuf , fileLen1); + appfileLoaded = true; + AppLength = fileLen1; + } + else { + if ((nBlkType == 0x01 || nBlkType == 0x02) && fileLen1 >= AppOffset + nAppInfoOffset + sizeof(stAppInfoBlock)) + { + pAppInfoBlock pAppinfo2 = (pAppInfoBlock)(filebuf + AppOffset + nAppInfoOffset); + if ((pAppinfo2->Hdr.nBlkSign == 0xaa55) && pAppinfo2->Hdr.nBlkTypeVer == 0x0301) { + s1.Format(_T("鏂囦欢鏄痓ootloader鍜孉pp鍚堟垚鐨勬枃浠� , 鏄惁浠庝腑鎻愬彇鍥轰欢骞剁户缁�")); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf + AppOffset, fileLen1 - AppOffset); + appfileLoaded = true; + AppLength = fileLen1 - AppOffset; + } + } + else { + s1.Format(_T("鏂囦欢 涓嶆槸App鏂囦欢 , 鏄惁缁х画 ")); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf , fileLen1 ); + appfileLoaded = true; + AppLength = fileLen1; + } + } + } + else { + s1.Format(_T("鏂囦欢 涓嶆槸App鏂囦欢 , 鏄惁缁х画 ")); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf , fileLen1 ); + appfileLoaded = true; + AppLength = fileLen1; + } + } + } + // s1.Format(_T(" BootLoader鍚姩鏂囦欢 鐗堟湰 %04X 纭欢绫诲瀷 %04X 鍗犵敤绌洪棿 %04X, %d Bytes\r\n 鏄惁缁х画"), pinfob->nBtldrVer, pinfob->nBtldrDevice, pinfob->nBtldrSize, fileLen1); + } + else { + s1.Format(_T("鏂囦欢涓湭鎵惧埌淇℃伅鍧�, 鏂囦欢澶у皬 %d Bytes\r\n 鏄惁缁х画"), fileLen1); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf , fileLen1 ); + appfileLoaded = true; + AppLength = fileLen1; + } + } + + + + unsigned short crc2 = crc16tablefast(Appbuf, AppLength); + unsigned char* buf2 = Appbuf + 0x1000; ; + //s1.Format(_T("GetInfo From File = %d %d \r\n"), j, fileLen1); + + pKMInfoBlock pinfof = (pKMInfoBlock)buf2; + + + s1.Format(_T(" 鐩爣妯″潡 绫诲瀷 %04X 鐗堟湰 %d.%02d, \r\n 鍥轰欢鏂囦欢 绫诲瀷 %04X 鐗堟湰 %d.%02d, %d Bytes\r\n 鏄惁缁х画"), + pinfob->nDeviceTypeVer, pinfob->nProgVerMajor,pinfob->nProgVerMinor, + pinfof->nDeviceTypeVer, pinfof->nProgVerMajor,pinfof->nProgVerMinor, fileLen1); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + int bError = 0; + for (int i = 0; i < AppLength; i += blocksize) + { + int sendsize = AppLength - i; + if (sendsize > blocksize) { sendsize = blocksize; } + int k = 999; + int j = 0; + double time1 = GetTimemS(); + for (j = 0; j < 5 && k != 0; j++) { + k = theApp.MyKLink1.WriteFirmware(1, 0, i, sendsize, Appbuf + i); + if (k) { + double time2 = GetTimemS(); + s1.Format(_T("Wr@ %x %dB = %d re %d %.2fmS %s "), i, sendsize, k, j, time2 - time1, theApp.MyKLink1.m_resultStr); + SysLog(s1); + myLogger1.UpdateLogDisplay(); + Sleep(30); + } + } + double time2 = GetTimemS(); + s1.Format(_T("Wr@ %x %dB = %d re %d %.2fmS"), i, sendsize, k, j, time2 - time1); + SysLog(s1); + myLogger1.UpdateLogDisplay(); + if (k) { // 鍑虹幇閿欒; + bError = 1; + CString sErr; + sErr = KLink1::GetErrDescStr(k); + s1.Format(_T("涓嬭浇鍑洪敊 %d, %s"), k, sErr); + int r3 = AfxMessageBox(s1); + break; //璺冲嚭 + } + } + if (bError == 0) { + NewAppInfo.Length = AppLength; + NewAppInfo.Sign = 0x55AA; + NewAppInfo.Version = 0x109; + NewAppInfo.nCRC = crc2; + + int k = theApp.MyKLink1.WriteFirmInfo(1, 0, 0, sizeof(NewAppInfo), (UCHAR*)&NewAppInfo); + s1.Format(_T("Write InfoBlock %d bytes = %d"), sizeof(NewAppInfo), k); + SysLog(s1); + Sleep(100); + int r5 = theApp.MyKLink1.ResetDevice(1, 0); + s1.Format(_T("ResetDevice = %d"), r5); + SysLog(s1); + myLogger1.UpdateLogDisplay(); + Sleep(2000); + } + theApp.MyKLink1.DisConnect();; + Sleep(1000); + OnMenuNavConnect(); + + } + } + } +} + + +void CNavView::OnRemoteBlinkLedAll() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int n = m_NavViewTree.GetSelectedCount(); + + HTREEITEM hItem1 = nullptr; + DWORD_PTR itemData = 0; + if (n == 1) { + hItem1 = m_NavViewTree.GetSelectedItem(); + itemData = m_NavViewTree.GetItemData(hItem1); + } + s1.Format(_T("Selected Count %d Data %08X"), n, itemData); + SysLog(s1); + int nDst = 1; + int nPort = 1; + int nTime = 5; + if (itemData & MENU_PORT) { + int nChildId = 0xff; + theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqBlinkLED, nTime, 0, 0, 0); + s1.Format(_T("Remote BlinkLED Port %d Child %d Timer %d"), nPort, nChildId, nTime); + SysLog(s1); + } +} + + +void CNavView::OnPortReset() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 +} + + +void CNavView::OnPortResetAllChild() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int n = m_NavViewTree.GetSelectedCount(); + + HTREEITEM hItem1 = nullptr; + DWORD_PTR itemData = 0; + if (n == 1) { + hItem1 = m_NavViewTree.GetSelectedItem(); + itemData = m_NavViewTree.GetItemData(hItem1); + } + s1.Format(_T("Selected Count %d Data %08X"), n, itemData); + SysLog(s1); + int nDst = 1; + int nPort = 1; + int nTime = 5; + if (itemData & MENU_PORT) { + int nChildId = 0xff; + theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqReset, nTime, 0, 0, 0); + s1.Format(_T("Remote Reset Port %d Child %d Timer %d"), nPort, nChildId, nTime); + SysLog(s1); + } +} + + +void CNavView::OnRemoteRefreshData() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int n = m_NavViewTree.GetSelectedCount(); + + HTREEITEM hItem1 = nullptr; + DWORD_PTR itemData =0; + if (n == 1) { + hItem1 = m_NavViewTree.GetSelectedItem(); + itemData = m_NavViewTree.GetItemData(hItem1); + } + s1.Format(_T("Selected Count %d Data %08X"), n, itemData); + SysLog(s1); +} + + +void CNavView::OnRemoteBlinkLED() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int n = m_NavViewTree.GetSelectedCount(); + + HTREEITEM hItem1 = nullptr; + DWORD_PTR itemData = 0; + if (n == 1) { + hItem1 = m_NavViewTree.GetSelectedItem(); + itemData = m_NavViewTree.GetItemData(hItem1); + } + s1.Format(_T("Selected Count %d Data %08X"), n, itemData); + SysLog(s1); + int nDst = 1; + int nPort = 1; + int nTime = 5; + if (itemData & MENU_REMOTE_DEVICE) { + int nChildId = itemData & 0xff; + theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqBlinkLED, nTime, 0, 0, 0); + s1.Format(_T("Remote BlinkLED Port %d Child %d Timer %d"), nPort, nChildId,nTime); + SysLog(s1); + } +} + +void CNavView::OnRemoteDeviceReset() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int n = m_NavViewTree.GetSelectedCount(); + + HTREEITEM hItem1 = nullptr; + DWORD_PTR itemData = 0; + if (n == 1) { + hItem1 = m_NavViewTree.GetSelectedItem(); + itemData = m_NavViewTree.GetItemData(hItem1); + } + s1.Format(_T("Selected Count %d Data %08X"), n, itemData); + SysLog(s1); + int nDst = 1; + int nPort = 1; + int nTime = 5; + if (itemData & MENU_REMOTE_DEVICE) { + int nChildId = itemData & 0xff; + theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqReset, nTime, 0, 0, 0); + s1.Format(_T("Remote Reset Port %d Child %d Timer %d"), nPort, nChildId, nTime); + SysLog(s1); + } + +} + +void CNavView::OnRemoteUpdateFirmware() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CString s1; + int n = m_NavViewTree.GetSelectedCount(); + + HTREEITEM hItem1 = nullptr; + DWORD_PTR itemData = 0; + if (n == 1) { + hItem1 = m_NavViewTree.GetSelectedItem(); + itemData = m_NavViewTree.GetItemData(hItem1); + } + s1.Format(_T("Selected Count %d Data %08X"), n, itemData); + SysLog(s1); + int nDst = 1; + int nPort = 1; + int nChildId = 0; + if (itemData & MENU_REMOTE_DEVICE) { + nChildId = itemData & 0xff; + } + else { return; } + +// CString s1; + s1.Format(_T("鏇存柊杩滅▼璁惧 鍥轰欢")); + SysLog(s1); + USHORT len1 = 0; + USHORT buf1[1024]; + int r2 = 0; + stDeviceInfo* ptheDeviceInfo =&PortDeviceInfos[nChildId]; + int res2 = theApp.MyKLink1.GetPortChildInfo(1, nPort, nChildId , sizeof(stDeviceInfo), &len1, buf1); //sizeof(stDeviceInfo) + if (res2 == KLink1::KL_OK) { + s1.Format(_T("GetChildInfo %d %d = %d B\r\n"), nPort, nChildId , len1); +// for (int k = 0; k < len1; k++) { +// s1.AppendFormat(_T("%02X "), ((unsigned char*)buf1)[k]); +// } + SysLog(s1); + stDeviceInfo* ptheInfo = (stDeviceInfo*)buf1; +// PortDeviceInfos[nChildId] = *ptheInfo; + s1.Format(_T("瀛�%d (%04X)%s V%d.%02d %d/%d "), + nChildId, ptheInfo->DeviceType, DeviceTypeToStr(ptheInfo->DeviceType), ptheInfo->DeviceVerMajor, ptheInfo->DeviceVerMinor, ptheInfo->InBitCount, ptheInfo->OutBitCount); + SysLog(s1); + } + myLogger1.UpdateLogDisplay(); + + unsigned char Appbuf[131072]; + unsigned char firmwarebuf[262144]; + + int nBtldrInfoOffset = 256; + int AppOffset = 4096; + int nAppInfoOffset = 256; + + int btldrLength = 0; + int AppLength = 0; + int FirmwareSize = 0; + + bool btldrfileLoaded = false; + bool appfileLoaded = false; + bool combinefileSaved = false; + + unsigned char filebuf[65536]; + unsigned int blocksize = 32; + stNewAppInfoBlock NewAppInfo; + + + CFileDialog dialog1(true); + INT_PTR r = dialog1.DoModal(); + if (r != IDOK) { return; } + CString sFilePathName = dialog1.GetPathName(); + //OpenFile + CFile file1; + CFileException e; + bool r3 = file1.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e); + s1.Format(_T("Open File %s = %d"), sFilePathName, r); + DbgLog(s1); + if (!r3) { + + return; + } + int fileLen2 = (int)file1.GetLength(); + file1.Read(filebuf, fileLen2); + file1.Close(); + unsigned int nBlkType = 0; + unsigned int nBlkVer = 0; + s1.Empty(); + pAppInfoBlock pAppinfo = (pAppInfoBlock)(filebuf + nAppInfoOffset); + s1.Format(_T("鏂囦欢淇℃伅 \r\n")); + // SetDlgItemText(IDC_STATIC_APP_INFO, s1); + if (pAppinfo->Hdr.nBlkSign == 0xaa55) { + s1.Empty(); + s1.Format(_T("鏂囦欢淇℃伅 ")); + // s1.AppendFormat(_T("鍚姩鏂囦欢 %s \r\n"), sFilePathName); + + s1.AppendFormat(_T("鏂囦欢澶у皬: %d \r\n"), fileLen2); + s1.AppendFormat(_T("淇℃伅鍧椾綅缃�: 0x%04X 淇℃伅鍧楀ぇ灏�: %d \r\n"), nAppInfoOffset, pAppinfo->Hdr.nBlkSize); + s1.AppendFormat(_T("淇℃伅鍧楃被鍨�: 0x%04X "), pAppinfo->Hdr.nBlkTypeVer); + nBlkType = (pAppinfo->Hdr.nBlkTypeVer) >> 8; + nBlkVer = pAppinfo->Hdr.nBlkTypeVer & 0xff; + if (nBlkType == 0x01) { s1.AppendFormat(_T(" (BootLoader 绫诲瀷1 鐗堟湰 %d) "), nBlkVer); } + else if (nBlkType == 0x02) { s1.AppendFormat(_T(" (BootLoader 绫诲瀷2 鐗堟湰 %d) "), nBlkVer); } + else if (nBlkType == 0x03) { s1.AppendFormat(_T(" (App绫诲瀷1 鐗堟湰 %d) "), nBlkVer); } + else if (nBlkType == 0x04) { s1.AppendFormat(_T(" (App绫诲瀷2 鐗堟湰 %d) "), nBlkVer); } + else { s1.AppendFormat(_T(" (鏈煡绫诲瀷) ")); } + s1.AppendFormat(_T("\r\n")); + s1.AppendFormat(_T("搴旂敤鍖虹増鏈�: 0x%04X 瀵瑰簲妯″潡绫诲瀷: 0x%04X\r\n"), pAppinfo->nAppVer, pAppinfo->nAppDevice); + s1.AppendFormat(_T("搴旂敤鍖哄ぇ灏�: 0x%04X 瀹為檯浠g爜澶у皬: 0x%04X \r\n"), pAppinfo->nAppSize, pAppinfo->nAppDataSize); + s1.AppendFormat(_T("搴旂敤鍖哄湴鍧�: 0x%08X (鍋忕Щ %d )\r\n"), pAppinfo->nAppStartAddr, pAppinfo->nAppStartAddr - 0x08000000); + s1.AppendFormat(_T("淇℃伅鏆傚瓨鍖�: 0x%08X \r\n搴旂敤鏆傚瓨鍖�: 0x%08X \r\n"), pAppinfo->nAppStartOffset, pAppinfo->nApp); + // SetDlgItemText(IDC_STATIC_APP_INFO, s1); + + if (nBlkType == 0x03 || nBlkType == 0x04) { + memmove(Appbuf, filebuf, fileLen2); + appfileLoaded = true; + AppLength = fileLen2; + } + else { + if ((nBlkType == 0x01 || nBlkType == 0x02) && fileLen2 >= AppOffset + nAppInfoOffset + sizeof(stAppInfoBlock)) + { + pAppInfoBlock pAppinfo2 = (pAppInfoBlock)(filebuf + AppOffset + nAppInfoOffset); + if ((pAppinfo2->Hdr.nBlkSign == 0xaa55) && pAppinfo2->Hdr.nBlkTypeVer == 0x0301) { + s1.Format(_T("鏂囦欢鏄痓ootloader鍜孉pp鍚堟垚鐨勬枃浠� , 鏄惁浠庝腑鎻愬彇鍥轰欢骞剁户缁�")); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf + AppOffset, fileLen2 - AppOffset); + appfileLoaded = true; + AppLength = fileLen2 - AppOffset; + } + } + else { + s1.Format(_T("鏂囦欢 涓嶆槸App鏂囦欢 , 鏄惁缁х画 ")); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf, fileLen2); + appfileLoaded = true; + AppLength = fileLen2; + } + } + } + else { + s1.Format(_T("鏂囦欢 涓嶆槸App鏂囦欢 , 鏄惁缁х画 ")); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf, fileLen2); + appfileLoaded = true; + AppLength = fileLen2; + } + } + } + // s1.Format(_T(" BootLoader鍚姩鏂囦欢 鐗堟湰 %04X 纭欢绫诲瀷 %04X 鍗犵敤绌洪棿 %04X, %d Bytes\r\n 鏄惁缁х画"), pinfob->nBtldrVer, pinfob->nBtldrDevice, pinfob->nBtldrSize, fileLen1); + } + else { + s1.Format(_T("鏂囦欢涓湭鎵惧埌淇℃伅鍧�, 鏂囦欢澶у皬 %d Bytes\r\n 鏄惁缁х画"), fileLen2); + int r3 = AfxMessageBox(s1, MB_YESNO); + if (r3 == IDYES) { + memmove(Appbuf, filebuf, fileLen2); + appfileLoaded = true; + AppLength = fileLen2; + } + } + + + unsigned short crc2 = crc16tablefast(Appbuf, AppLength); + unsigned char* buf2 = Appbuf + 0x1000; ; + //s1.Format(_T("GetInfo From File = %d %d \r\n"), j, fileLen1); + + pKMInfoBlock pinfof = (pKMInfoBlock)buf2; + + + s1.Format(_T(" 鐩爣妯″潡 绫诲瀷 %04X 鐗堟湰 %d.%02d, \r\n 鍥轰欢鏂囦欢 绫诲瀷 %04X 鐗堟湰 %d.%02d, %d Bytes\r\n 鏄惁缁х画"), + ptheDeviceInfo->DeviceType, ptheDeviceInfo->DeviceVerMajor,ptheDeviceInfo->DeviceVerMinor, + pinfof->nDeviceTypeVer, pinfof->nProgVerMajor,pinfof->nProgVerMinor, fileLen2); + int r4 = AfxMessageBox(s1, MB_YESNO); + if (r4 != IDYES) { return; } + + { + int bError = 0; + for (int i = 0; i < AppLength; i += blocksize) + { + int sendsize = AppLength - i; + if (sendsize > blocksize) { sendsize = blocksize; } + int k = 999; + int j = 0; + double time1 = GetTimemS(); + + for (j = 0; j < 5 && k != 0; j++) { + k = theApp.MyKLink1.RunRemoteReq(nDst, nPort,nChildId, ReqUpdateFirm,0,i, sendsize, Appbuf + i); + Sleep(10); + if (k) { + double time2 = GetTimemS(); + s1.Format(_T("Wr@ %x %dB = %d re %d %.2fmS %s "), i, sendsize, k, j, time2 - time1, theApp.MyKLink1.m_resultStr); + SysLog(s1); + myLogger1.UpdateLogDisplay(); + Sleep(30); + } + } + double time2 = GetTimemS(); + s1.Format(_T("Wr@ %x %dB = %d re %d %.2fmS"), i, sendsize, k, j, time2 - time1); + SysLog(s1); + myLogger1.UpdateLogDisplay(); + if (k) { // 鍑虹幇閿欒; + bError = 1; + CString sErr; + sErr = KLink1::GetErrDescStr(k); + s1.Format(_T("涓嬭浇鍑洪敊 %d, %s"), k, sErr); + int r3 = AfxMessageBox(s1); + break; //璺冲嚭 + } + } + if (bError == 0) { + NewAppInfo.Length = AppLength; + NewAppInfo.Sign = 0x55AA; + NewAppInfo.Version = 0x109; + NewAppInfo.nCRC = crc2; + + int k = theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqUpdateFirmInfo, 0, 0,sizeof(NewAppInfo), (UCHAR*)&NewAppInfo); + s1.Format(_T("Write InfoBlock %d bytes = %d"), sizeof(NewAppInfo), k); + SysLog(s1); + Sleep(100); + int r5 = theApp.MyKLink1.RunRemoteReq(nDst, nPort, nChildId, ReqReset, 0); + s1.Format(_T("ResetRemoteDevice Port %d Child %d = %d"), nPort, nChildId, r5); + SysLog(s1); +/* + int r6 = theApp.MyKLink1.ResetDevice(nDst, 0); + s1.Format(_T("ResetDevice = %d"), r6); + SysLog(s1); + for (int i = 0; i < 8; i++) { + bPortRegsUpdated[i] = 0; + } + for (int i = 0; i < 16; i++) { + bPortDeviceUpdated[i] = 0; + } + myLogger1.UpdateLogDisplay(); +*/ + // Sleep(2000); + } + // theApp.MyKLink1.DisConnect();; + // OnMenuNavConnect(); + } +} -- Gitblit v1.9.1