BOOL CSignalDefinerDlg::OnInitDialog() { CDialog::OnInitDialog(); UpdateData(FALSE); m_ctrNoOfCycles.SetCurSel(m_nSelCycle); //Get the CWnd reference to the DMGraph ActiveX control m_poDMGraphCtrl = GetDlgItem(IDC_DMGRAPHCTRL); /*Set Graph properties*/ if( m_poDMGraphCtrl->m_hWnd != NULL ) { LPUNKNOWN pUnk = m_poDMGraphCtrl->GetControlUnknown(); IDMGraphCtrl* pDMGraphCtrl = NULL; pUnk->QueryInterface(IID_IDMGraphCtrl, (void**) &pDMGraphCtrl); if ( pDMGraphCtrl ==NULL ) { return TRUE; } // Set Axis Color pDMGraphCtrl->put_AxisColor((OLE_COLOR)0xFF); // Set Plot Area Color pDMGraphCtrl->put_PlotAreaColor((OLE_COLOR)0x00); // Set Grid Color pDMGraphCtrl->put_GridColor((OLE_COLOR)0xC0C0C0); // Set Frame Style pDMGraphCtrl->put_FrameStyle((FrameStyle)1); // Set Frame Color pDMGraphCtrl->put_ControlFrameColor((OLE_COLOR)0x5500); // Set Grid Lines Count CComPtr<IDMGraphAxis> spAxisX; pDMGraphCtrl->get_Axis( HorizontalX, &spAxisX); spAxisX->put_GridNumber(10); CComPtr<IDMGraphAxis> spAxisY; pDMGraphCtrl->get_Axis( VerticalY, &spAxisY); spAxisY->put_GridNumber(5); if (NULL != pDMGraphCtrl) { pDMGraphCtrl->Release(); pDMGraphCtrl = NULL; } } vGenerateWave(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
/* Read thread function for graph display*/ DWORD WINAPI SignalDataPlotterThread(LPVOID pVoid) { CPARAM_THREADPROC* pThreadParam = (CPARAM_THREADPROC*) pVoid; if (pThreadParam == NULL) { return (DWORD)-1; } pThreadParam->m_unActionCode = CREATE_TIME_MAP; int nBufferSize = 0; for(int nBUSId = 0; nBUSId<AVAILABLE_PROTOCOLS; nBUSId++) { if(m_pomGraphWindows[nBUSId] != NULL) { int nRefreshTime = m_pomGraphWindows[nBUSId]->m_pGraphList->m_odGraphParameters.m_nRefreshRate; nBufferSize = m_pomGraphWindows[nBUSId]->m_pGraphList->m_odGraphParameters.m_nBufferSize; } } //Clear the buffer with previous contents if any. m_ouMsgInterpretBuffer.vClearMessageBuffer(); LONGLONG g_nInitTimeStamp[MAX_PROTOCOLS] = {0}; double g_dElapsdTime[MAX_PROTOCOLS] = {0}; bool bLoopON = true; //Allow the connection related activities take place prior to proceeding with loop Sleep(1000); UINT64 unPointsCnt = 0; while (bLoopON) { //Commented by Arunkumar Karri on 07/02/2012 to make the plotting realtime. //Sleep(nRefreshTime); //Introduced a 50 Millisecond delay Sleep(50); if(pThreadParam->m_unActionCode == IDLE) { bLoopON = false; } while(m_ouMsgInterpretBuffer.GetMsgCount() > 0) { INT nType = 0; INT nSize = MAX_DATA_LEN_J1939; SINTERPRETDATA_LIST sInterpretList; sInterpretList.m_unValue.m_dPhysical = 0; sInterpretList.m_unValue.m_nRawValue = 0; HRESULT hResult = m_ouMsgInterpretBuffer.ReadFromBuffer(nType, (BYTE*)&sInterpretList, nSize); //Get access to the Graph control IDMGraphCtrl* pDMGraphCtrl = m_pomGraphWindows[nType]->m_pDMGraphCtrl; if ( pDMGraphCtrl ==NULL ) { return 0; } //Get the Graph collectrion CComPtr<IDMGraphCollection> spGraphCollection; pDMGraphCtrl->get_Elements(&spGraphCollection); if(hResult == S_OK && m_pomGraphWindows[nType]!=NULL) { if(g_nInitTimeStamp[nType] == 0) { g_nInitTimeStamp[nType] = sInterpretList.m_nTimeStamp; g_dElapsdTime[nType] = CTimeManager::nCalculateCurrTimeStamp() - CTimeManager::nGetAbsoluteTime(); g_dElapsdTime[nType] /= defTIMER_RESOLUTION_FACTOR; } double dAbsTime = (double)sInterpretList.m_nTimeStamp - g_nInitTimeStamp[nType]; dAbsTime /= defTIMER_RESOLUTION_FACTOR; dAbsTime+=g_dElapsdTime[nType]; CGraphElement odTemp; CGraphList* podList = NULL; podList = m_pomGraphWindows[nType]->m_pGraphList; INT_PTR nItemCount = podList->m_omElementList.GetSize(); for( int nIndex = 0; nIndex < nItemCount; nIndex++ ) { CComPtr<IDispatch> spDispatch; CComPtr<IDMGraphElement> spGraphElement; hResult = spGraphCollection->get_Item(nIndex, &spDispatch); if ( spDispatch == NULL ) { return 0; } hResult = spDispatch.QueryInterface(&spGraphElement); odTemp = podList->m_omElementList[ nIndex ]; //if the read data is of type signal if( hResult == S_OK && odTemp.m_bEnabled == TRUE && odTemp.m_nValueType != eSTAT_PARAM && sInterpretList.unMsgID == (unsigned int)odTemp.m_nMsgID) { CString strSigName(sInterpretList.m_acSigName); if(odTemp.m_omStrElementName == strSigName) { if(sInterpretList.m_shType == odTemp.m_nValueType) { if(odTemp.m_nValueType == eRAW_VALUE) { spGraphElement->PlotXY(dAbsTime, (double)sInterpretList.m_unValue.m_nRawValue); } else { spGraphElement->PlotXY(dAbsTime, sInterpretList.m_unValue.m_dPhysical); } unPointsCnt++; } } } //If the read data from buffer is of parameter type else if( odTemp.m_bEnabled == TRUE && odTemp.m_nValueType == eSTAT_PARAM && sInterpretList.unMsgID == (unsigned int)nIndex) { double dTime = CTimeManager::nCalculateCurrTimeStamp() - CTimeManager::nGetAbsoluteTime(); dTime /= defTIMER_RESOLUTION_FACTOR; if(sInterpretList.m_unValue.m_nRawValue == -1) { spGraphElement->PlotXY(dTime, sInterpretList.m_unValue.m_dPhysical); } else { spGraphElement->PlotXY(dTime, (double)sInterpretList.m_unValue.m_nRawValue); } unPointsCnt++; } } //If the plotted points exceeds the maximum buffer limit if ( unPointsCnt > nBufferSize ) { vClearGraphElementPoints(spGraphCollection); //After clearing the Graph, sleep for 100 msec Sleep(100); unPointsCnt = 0; } } } double dAbsTime = CTimeManager::nCalculateCurrTimeStamp() - CTimeManager::nGetAbsoluteTime(); dAbsTime /= defTIMER_RESOLUTION_FACTOR; for(register int nBusID = 0; nBusID<AVAILABLE_PROTOCOLS; nBusID++) { if(m_pomGraphWindows[nBusID] == NULL) { continue; } //check if windows is already distroyed. if(!IsWindow(m_pomGraphWindows[nBusID]->m_hWnd)) { m_pomGraphWindows[nBusID]->m_pDMGraphCtrl = NULL; m_pomGraphWindows[nBusID] = NULL; continue; } if ( m_pomGraphWindows[nBusID]->m_pDMGraphCtrl == NULL ) { break; } IDMGraphCtrl* pDMGraphCtrl = m_pomGraphWindows[nBusID]->m_pDMGraphCtrl; if ( pDMGraphCtrl == NULL ) { break; } //Update X-axis Range double dXMin = 0.0, dXMax = 0.0,dYMin = 0.0, dYMax = 0.0; // Get Present X,Y Axis Values pDMGraphCtrl->GetRange(&dXMin, &dXMax,&dYMin, &dYMax); // Check the Max Range is lesser then the present time value // If the time axis is old then set the latest value if( dXMax < dAbsTime ) { double dRange = dXMax - dXMin; // Update Graph Control pDMGraphCtrl->SetRange(dAbsTime - dRange, dAbsTime, dYMin, dYMax); } } } return 0; }
/** * \brief Plots the element points available onto the Graph * \param[out] - * \param[in] pvarrX, pvarrY; Takes the element points in the form of VARIANT array * \return void * \authors Arunkumar Karri * \date 03.02.2012 Created */ void CSignalDefinerDlg::SetGraphData(VARIANT* pvarrX, VARIANT* pvarrY) { CComBSTR bsName("Signal"); IDMGraphCtrl* pDMGraphCtrl = NULL; /*CComPtr<IDMGraphCollection> spElements;*/ CComPtr<IDMGraphElement> spGraphElement; if( m_poDMGraphCtrl->m_hWnd != NULL ) { LPUNKNOWN pUnk = m_poDMGraphCtrl->GetControlUnknown(); pUnk->QueryInterface(IID_IDMGraphCtrl, (void**) &pDMGraphCtrl); if ( pDMGraphCtrl ==NULL ) { return; } } HRESULT hr = pDMGraphCtrl->get_Elements(&spElements); //Set the signal name as caption pDMGraphCtrl->put_Caption(m_strSignalName); long i, nElementCount = 0; BOOL bReplace = FALSE; hr = spElements->get_Count(&nElementCount); for(i=0; i<nElementCount; i++) { CComBSTR bsElemName; CComPtr<IDispatch> spDispatch; hr = spElements->get_Item(i, &spDispatch); hr = spDispatch.QueryInterface(&spGraphElement); spGraphElement->get_Name(&bsElemName); if(_wcsicmp(bsElemName, bsName) == 0) { spGraphElement->Plot(*pvarrX, *pvarrY); pDMGraphCtrl->AutoRange(); return; } else { spGraphElement = NULL; } } if(bReplace == FALSE || spGraphElement == NULL) { CComPtr<IDispatch> spDispatch; hr = spElements->Add(&spDispatch); spGraphElement = NULL; hr = spDispatch.QueryInterface(&spGraphElement); } hr = spGraphElement->put_Name(bsName); hr = spGraphElement->put_PointSymbol( Dots ); hr = spGraphElement->put_PointSize(2); hr = spGraphElement->Plot(*pvarrX, *pvarrY); hr = pDMGraphCtrl->AutoRange(); if (NULL != pDMGraphCtrl) { pDMGraphCtrl->Release(); pDMGraphCtrl = NULL; } SysFreeString(bsName); }