// COSDlg.cpp : implementation file // #include "stdafx.h" #include "COS.h" #include "COSDlg.h" #include "afxdialogex.h" #include "AIOWDM.h" //#include "ACCES32.h" #include "TIRQThread.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // Need to run ACCES32 sample and set address 140B to 00 to enable IRQ // then you can run a dio sample to generate IRQ's // CAboutDlg dialog used for App About class CAboutDlg : public CDialogEx { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // CCOSDlg dialog CCOSDlg::CCOSDlg(CWnd* pParent /*=NULL*/) : CDialogEx(CCOSDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCOSDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CCOSDlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_CBN_SELCHANGE(IDC_COMBO_CARD, &CCOSDlg::OnCbnSelchangeComboCard) ON_BN_CLICKED(IDC_BTN_GENERIC, &CCOSDlg::OnBnClickedBtnGeneric) ON_BN_CLICKED(IDC_BTN_COS, &CCOSDlg::OnBnClickedBtnCos) ON_BN_CLICKED(IDC_BTN_ABORT, &CCOSDlg::OnBnClickedBtnAbort) ON_BN_CLICKED(IDCANCEL, &CCOSDlg::OnBnClickedCancel) END_MESSAGE_MAP() // CCOSDlg message handlers BOOL CCOSDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here if (InPortB(0x61) == 0xAA55) { MessageBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", "Warning", MB_OK); } // Setting CardData to 0 as needed int count,I; for(count = 0; count < 10; count++) { CardData[count].Base = 0; CardData[count].PPIs = 0; CardData[count].IRQCount = 0; CardData[count].WDGPets = 0; CardData[count].IsWDG = FALSE; for(I = 0; I < 4; I++) { CardData[count].LastCOSData[I].A = 0; CardData[count].LastCOSData[I].B = 0; CardData[count].LastCOSData[I].C = 0; } } // Beginning Init for program signed int NumCards, CardNum; unsigned long DeviceID, Base; unsigned long NameSize; UCHAR Name[256]; char BaseHex[256]; CButton GenIRQButton; CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); pCBox->ResetContent(); NumCards = GetNumCards(); ThereCanBeOnlyOne = FALSE; if (NumCards == 0) { UpdateButtonUI(); GetDlgItem(IDC_EDIT_LOGMEMO)->SetWindowText(_T("No cards found. The cards may not be installed, or they may be installed using a driver other than AIOWDM.sys.")); } else { for (CardNum = 0; CardNum != NumCards; CardNum++) { CardData[CardNum].IsWDG = FALSE; NameSize = 256; QueryCardInfo(CardNum, &DeviceID, &Base, &NameSize, Name); sprintf( BaseHex, "%s [%4x]",Name, Base); pCBox->AddString(BaseHex); CardData[CardNum].Base = Base; switch (DeviceID) { case 0x0E50: //PCI-DIO-24S CardData[CardNum].PPIs = 1; break; case 0x0E56: //PCI-DIO-24DCS CardData[CardNum].PPIs = 1; break; case 0x0E60: //PCI-DIO-48S CardData[CardNum].PPIs = 2; break; case 0x22C0: case 0x25C0: case 0x2FC0: case 0x2FC1: //PCI-WDG-CSM, P104-WDG-E, P104-WDG-CSM, and P104-WDG-CSMA CardData[CardNum].IsWDG = TRUE; WDGInit(CardNum); break; } if (CardData[CardNum].PPIs != 0) { CardData[CardNum].Log = ("AIOWDM provides generic IRQ-handling functions for all cards " "and special IRQ-handling functions for COS cards like this one. \r\n\r\n" "Click 'Detect Generic IRQs' to handle IRQs generically for the card selected above, " "or 'Detect COS IRQs' to handle IRQs for the card selected above by updating COS data. \r\n\r\n"); } else { if (CardData[CardNum].IsWDG) { CardData[CardNum].Log = ("AIOWDM provides generic IRQ-handling functions for all cards " "and special functions for watchdog cards like this one.\r\n\r\n" "Click 'Detect Generic IRQs' to handle IRQs generically for the card selected above, " "or 'Handle Watchdog IRQ' to handle the next IRQ for the card selected above with the selected action.\r\n\r\n" "You can also click 'Test Watchdog Timing' to set the watchdog timer, pet it a few times, then let it time out, " "'Read Temp' to read the temperature(if installed)," "'Read Status' to read the card''s status byte," "or 'Reboot' to quickly reboot your computer.\r\n\r\n"); } else { CardData[CardNum].Log = ("AIOWDM provides generic IRQ-handling functions for all cards. \r\n\r\n" "Click 'Detect Generic IRQs' to handle IRQs for the card selected above.\r\n\r\n"); } } }// end for //CButton* pCSoft = (CButton*)GetDlgItem(IDC_S_RESTART); //pCSoft->SetCheck(1); pCBox->SetCurSel(0); OnCbnSelchangeComboCard(); }// end else return TRUE; // return TRUE unless you set the focus to a control } void CCOSDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CCOSDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CCOSDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CCOSDlg::OnCbnSelchangeComboCard() { // TODO: Add your control notification handler code here unsigned long I; char CosHolder[25]; CString FinalHolder; CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); CEdit* pCEdit = (CEdit*)GetDlgItem(IDC_EDIT_LOGMEMO); int CardNum = pCBox->GetCurSel(); GetDlgItem(IDC_EDIT_LOGMEMO)->SetWindowText(CardData[CardNum].Log); pCEdit->SetSel(0, -1, FALSE); //Generic IRQs if (CardData[CardNum].IRQCount == 0) { GetDlgItem(IDC_STATIC_GENIRQ)->SetWindowText(""); } else { char Holder[25]; sprintf(Holder, "%d IRQ(s) detected",CardData[CardNum].IRQCount); GetDlgItem(IDC_STATIC_MSG)->SetWindowText(Holder); } //COS IRQs if (CardData[CardNum].PPIs != 0) { sprintf(CosHolder, " "); for (I = 0; I < CardData[CardNum].PPIs; I++) { sprintf(CosHolder, " %2x %2x %2x",CardData[CardNum].LastCOSData[I].A, CardData[CardNum].LastCOSData[I].B, CardData[CardNum].LastCOSData[I].C); FinalHolder = FinalHolder + CosHolder; OutPortB(CardData[CardNum].Base+11,0x00); } FinalHolder.MakeUpper(); GetDlgItem(IDC_STATIC_COSIRQ)->SetWindowText(FinalHolder); GetDlgItem(IDC_BTN_COS)->EnableWindow(TRUE); } else { UpdateCOSUI(); } } void CCOSDlg::AddLine(int CardNum, CString Line) { CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); CardData[CardNum].Log = (CardData[CardNum].Log + Line + "\r\n\r\n"); if (CardNum == pCBox->GetCurSel()) OnCbnSelchangeComboCard(); } void CCOSDlg::ReceiveCOSData(int CardNum, TCOSData COSData[]) { unsigned long I; CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); for (I = 0; I < CardData[CardNum].PPIs; I++) { CardData[CardNum].LastCOSData[I].A = COSData[I].A; CardData[CardNum].LastCOSData[I].B = COSData[I].B; CardData[CardNum].LastCOSData[I].C = COSData[I].C; } if (CardNum == pCBox->GetCurSel()) OnCbnSelchangeComboCard(); } void CCOSDlg::ReceiveGenIRQ(int CardNum) { CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); CardData[CardNum].IRQCount++; if (CardNum == pCBox->GetCurSel()) OnCbnSelchangeComboCard(); } void CCOSDlg::UpdateButtonUI() { GetDlgItem(IDC_BTN_GENERIC)->EnableWindow(FALSE); GetDlgItem(IDC_BTN_ABORT)->EnableWindow(FALSE); } void CCOSDlg::UpdateCOSUI() { GetDlgItem(IDC_BTN_COS)->EnableWindow(FALSE); GetDlgItem(IDC_STATIC_COSIRQ)->SetWindowText(""); } void CCOSDlg::OnBnClickedBtnGeneric() { CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); int CardNum = pCBox->GetCurSel(); if (ThereCanBeOnlyOne == FALSE) { Thrd = (TIRQThread*)AfxBeginThread(RUNTIME_CLASS(TIRQThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); Thrd->SetOwner(this); Thrd->COSPPIs = 0; Thrd->CardNum = CardNum; Thrd->ResumeThread(); AddLine(CardNum, "Detecting generic IRQs; generate IRQs to see this sample count them. Press 'Abort IRQ Detect' to cancel when done."); ThereCanBeOnlyOne = TRUE; } } void CCOSDlg::OnBnClickedBtnCos() { CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); int CardNum = pCBox->GetCurSel(); if (!ThereCanBeOnlyOne) { Thrd = (TIRQThread*)AfxBeginThread(RUNTIME_CLASS(TIRQThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); Thrd->SetOwner(this); Thrd->COSPPIs = CardData[CardNum].PPIs; Thrd->CardNum = CardNum; Thrd->ResumeThread(); AddLine(CardNum, "Detecting COS IRQs; change the input data to see the COS data update. Press 'Abort IRQ Detect' to cancel when done."); ThereCanBeOnlyOne = TRUE; } } void CCOSDlg::OnBnClickedBtnAbort() { CComboBox* pCBox = (CComboBox*)GetDlgItem(IDC_COMBO_CARD); int CardNum = pCBox->GetCurSel(); if (AbortRequest(CardNum) != 0 ) { AddLine(CardNum, "Aborting IRQ detection..."); ThereCanBeOnlyOne = FALSE; } else AddLine(CardNum, "No IRQ request to abort."); // Dont break in here if debugging may cause exception } void CCOSDlg::OnBnClickedCancel() { int CardNum; /* Abort all pending IRQ requests. If we don't do this before exiting, later when an IRQ comes in or somebody else calls AbortRequest the pending IRQ request will attempt to unlock a thread that no longer exists, which is bad. (We can AbortRequest for a card with no pending requests, it'll just tell us that, and it's easier than remembering which cards have pending requests.) */ for (CardNum = 0; CardNum < GetNumCards(); CardNum++) AbortRequest(CardNum); CDialogEx::OnCancel(); }