// PageRackInfo.cpp : implementation file // #include "stdafx.h" #include "mgrnve.h" #include "ConnectionManager.h" #include "PageRackInfo.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define QUERY_INFO_INTERVAL 1000 #define MAX_ITEM_COUNT 4 ///////////////////////////////////////////////////////////////////////////// // CPageRackInfo dialog CPageRackInfo::CPageRackInfo(CWnd* pParent, CMgrNVE* pMgrCM, CConnectionManager *pConnMgr) : CParamDlg(CPageRackInfo::IDD, pParent, pMgrCM, pConnMgr) { //{{AFX_DATA_INIT(CPageRackInfo) //}}AFX_DATA_INIT } void CPageRackInfo::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPageRackInfo) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPageRackInfo, CDialog) //{{AFX_MSG_MAP(CPageRackInfo) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPageRackInfo message handlers BOOL CPageRackInfo::SaveSetting() { return TRUE; } BOOL CPageRackInfo::ResetSetting() { return TRUE; } BOOL CPageRackInfo::UpdateSetting() { return TRUE; } BOOL CPageRackInfo::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_pCod5Api = m_pConnection->GetCod5Api(); m_pMsgMgr = m_pMgrNVE->GetMsgManager(); m_pGlobalSettings = m_pConnection->GetGlobalSettings(); m_ThreadRackInfo.StartThread(ThreadRackInfoStub, this, NULL, NULL); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } DWORD WINAPI CPageRackInfo::ThreadRackInfoStub(LPVOID lpParameter) { THREAD_PARAM_SET *pParam = (THREAD_PARAM_SET*)lpParameter; return static_cast(pParam->pParam2)->ThreadRackInfo(lpParameter); } DWORD WINAPI CPageRackInfo::ThreadRackInfo(LPVOID lpParameter) { ULONG uInterval = 0; while (1) { ULONG uRs = WaitForSingleObject(m_ThreadRackInfo.GetKillHandle(), uInterval); if (uRs == WAIT_OBJECT_0) { break; } if (!m_pCod5Api->Cod5QueryInfo(CMN5_QIC_GET_HWINFO_STR, 0, m_pGlobalSettings->InformationString)) { m_pMsgMgr->PushErrorCodeF("Cod5QueryInfo failed"); m_pMsgMgr->Show(TRUE); break; } ParseRackInfo(); uInterval = QUERY_INFO_INTERVAL; } return 0; } void CPageRackInfo::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_ThreadRackInfo.StopThread(100); } BOOL CPageRackInfo::ParseRackInfo() { char szName[NVE_MAX_STR_LENGTH]; char szValue[NVE_MAX_STR_LENGTH]; char *pszFields = strstr(m_pGlobalSettings->InformationString, "BPuPver"); ULONG uLen; ULONG uNumOfTemp = 0, uNumOfVol = 0, uNumOfFan = 0, uNumOfItem = 0; while (1) { szValue[0] = '\0'; if (sscanf(pszFields, "%[^=]=%[^,]", szName, szValue) != 2) { break; } uLen = strlen(szValue); if (strcmp(szName, "BPuPver") == 0) { SetDlgItemText(IDC_EDIT_UP_ID, szValue); } else if (strcmp(szName, "RackID") == 0) { SetDlgItemText(IDC_EDIT_RACK_ID, szValue); } else if (strcmp(szName, "SlotID") == 0) { SetDlgItemText(IDC_EDIT_SLOT_ID, szValue); } else if (strcmp(szName, "AccessCount") == 0) { SetDlgItemText(IDC_EDIT_ACCESS_COUNT, szValue); } else if (strncmp(szName, "Temp", strlen("Temp")) == 0) { ULONG uIndex = szName[strlen("Temp")]-'0'; CStatic *pStatic = (CStatic*)GetDlgItem(IDC_STATIC_ID0+uIndex); if (pStatic) { pStatic->ShowWindow(TRUE); } CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT_TEMP0+uIndex); if (pEdit) { pEdit->ShowWindow(TRUE); } strcat(szValue, "[C]"); SetDlgItemText(IDC_EDIT_TEMP0+uIndex, szValue); uNumOfTemp = uIndex+1; if (uNumOfItem < uNumOfTemp) { uNumOfItem = uNumOfTemp; } } else if (strncmp(szName, "PWVoltage", strlen("PWVoltage")) == 0) { ULONG uIndex = szName[strlen("PWVoltage")]-'0'; CStatic *pStatic = (CStatic*)GetDlgItem(IDC_STATIC_ID0+uIndex); if (pStatic) { pStatic->ShowWindow(TRUE); } CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT_PW_VOL0+uIndex); if (pEdit) { pEdit->ShowWindow(TRUE); } strcat(szValue, "[V]"); SetDlgItemText(IDC_EDIT_PW_VOL0+uIndex, szValue); uNumOfVol = uIndex+1; if (uNumOfItem < uNumOfVol) { uNumOfItem = uNumOfVol; } } else if (strncmp(szName, "Fan", strlen("Fan")) == 0) { ULONG uIndex = szName[strlen("Fan")]-'0'; CStatic *pStatic = (CStatic*)GetDlgItem(IDC_STATIC_ID0+uIndex); if (pStatic) { pStatic->ShowWindow(TRUE); } CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT_FAN0+uIndex); if (pEdit) { pEdit->ShowWindow(TRUE); } ULONG uOn = atoi(szValue); if (uOn == 1) { SetDlgItemText(IDC_EDIT_FAN0+uIndex, "Inactive"); } else { SetDlgItemText(IDC_EDIT_FAN0+uIndex, "Active"); } uNumOfFan = uIndex+1; if (uNumOfItem < uNumOfFan) { uNumOfItem = uNumOfFan; } } pszFields += strlen(szName) + 2 /*="*/ + uLen + 1 /*"*/; while (*pszFields == ',' || *pszFields == ' ') { ++pszFields; } if (*pszFields == '\0') { break; } } ULONG i; for (i=uNumOfTemp; iShowWindow(FALSE); } } for (i=uNumOfVol; iShowWindow(FALSE); } } for (i=uNumOfFan; iShowWindow(FALSE); } } for (i=uNumOfItem; iShowWindow(FALSE); } } return TRUE; }