void ConfigWindow::on_tsSetTimePB_clicked() { HANDLE comport; if (opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if(setTSTime(&comport)) { ErrorMsgBox(QString("Could not set TrueSense time")); opi_closeucd_com(&comport); return; } QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Set TrueSense Time").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); opi_closeucd_com(&comport); }
void ConfigWindow::on_ucEraseEventsPB_clicked() { HANDLE comport; if (opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if (opiucd_evcaperase(&comport)) { ErrorMsgBox(QString("Could not erase captured events")); opi_closeucd_com(&comport); return; } QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Erased Events").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); opi_closeucd_com(&comport); }
static LRESULT MainWnd_OnInstall(HWND hwnd) { DWORD fontExists; /* First, we have to find out if the font still exists. */ fontExists = GetFileAttributes((LPCSTR)g_fileName); if (fontExists != 0xFFFFFFFF) /* If the file does not exist */ { ErrorMsgBox(0, IDS_ERROR_NOFONT, g_fileName); return -1; } //CopyFile(g_fileName, NULL, TRUE); MessageBox(hwnd, TEXT("This function is unimplemented"), TEXT("Unimplemented"), MB_OK); return 0; }
//! @brief parses the command line bool UpdaterApp::OnCmdLineParsed(wxCmdLineParser& parser) { if ( parser.Found(_T("help")) ) return false; // not a syntax error, but program should stop if user asked for command line usage m_paramcount = parser.GetParamCount(); if (m_paramcount == 2) { m_source_dir = parser.GetParam(0); m_destination_dir = parser.GetParam(1); return true; } if (m_paramcount == 5) { if (!parser.GetParam(0).ToLong(&m_pid)) { ErrorMsgBox(_T("Invalid pid %s") + parser.GetParam(0)); return false; } m_springlobby_exe = parser.GetParam(1); m_updater_exe = parser.GetParam(2); m_source_dir = parser.GetParam(3); m_destination_dir = parser.GetParam(4); return true; } return false; }
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int argc; WCHAR** argv; WCHAR szFileName[MAX_PATH] = L""; DWORD dwSize; HWND hMainWnd; MSG msg; WNDCLASSEXW wincl; LPCWSTR fileName; switch (GetUserDefaultUILanguage()) { case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT): SetProcessDefaultLayout(LAYOUT_RTL); break; default: break; } g_hInstance = hThisInstance; /* Get unicode command line */ argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argc < 2) { OPENFILENAMEW fontOpen; WCHAR filter[MAX_PATH], dialogTitle[MAX_PATH]; LoadStringW(NULL, IDS_OPEN, dialogTitle, MAX_PATH); LoadStringW(NULL, IDS_FILTER_LIST, filter, MAX_PATH); /* Clears out any values of fontOpen before we use it */ ZeroMemory(&fontOpen, sizeof(fontOpen)); /* Sets up the open dialog box */ fontOpen.lStructSize = sizeof(fontOpen); fontOpen.hwndOwner = NULL; fontOpen.lpstrFilter = filter; fontOpen.lpstrFile = szFileName; fontOpen.lpstrTitle = dialogTitle; fontOpen.nMaxFile = MAX_PATH; fontOpen.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; fontOpen.lpstrDefExt = L"ttf"; /* Opens up the Open File dialog box in order to chose a font file. */ if(GetOpenFileNameW(&fontOpen)) { fileName = fontOpen.lpstrFile; g_fileName = fileName; } else { /* If the user decides to close out of the open dialog effectively exiting the program altogether */ return 0; } } else { /* Try to add the font resource from command line */ fileName = argv[1]; g_fileName = fileName; } if (!AddFontResourceW(fileName)) { ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName); return -1; } /* Get the font name */ dwSize = sizeof(g_ExtLogFontW.elfFullName); if (!GetFontResourceInfoW(fileName, &dwSize, g_ExtLogFontW.elfFullName, 1)) { ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName); return -1; } dwSize = sizeof(LOGFONTW); if (!GetFontResourceInfoW(fileName, &dwSize, &g_ExtLogFontW.elfLogFont, 2)) { ErrorMsgBox(0, IDS_ERROR_NOFONT, fileName); return -1; } if (!Display_InitClass(hThisInstance)) { ErrorMsgBox(0, IDS_ERROR_NOCLASS); return -1; } /* The main window class */ wincl.cbSize = sizeof (WNDCLASSEXW); wincl.style = CS_DBLCLKS; wincl.lpfnWndProc = MainWndProc; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hInstance = hThisInstance; wincl.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT)); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND; wincl.lpszMenuName = NULL; wincl.lpszClassName = g_szFontViewClassName; wincl.hIconSm = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TT)); /* Register the window class, and if it fails quit the program */ if (!RegisterClassExW (&wincl)) { ErrorMsgBox(0, IDS_ERROR_NOCLASS); return 0; } /* The class is registered, let's create the main window */ hMainWnd = CreateWindowExW( 0, /* Extended possibilites for variation */ g_szFontViewClassName, /* Classname */ g_ExtLogFontW.elfFullName,/* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); ShowWindow(hMainWnd, nCmdShow); /* Main message loop */ while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } RemoveFontResourceW(argv[1]); return (int)msg.wParam; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupUi(this); Finished_Init = false; AllowInit = false; PreBuf_timer = new QTimer; Update_timer= new QTimer; Ping_timer= new QTimer; Spectrum_timer = new QTimer; BufferStatusUpdate_timer= new QTimer; singleClickTimer=new QTimer; m_msgbox = NULL; isPlaying=false; syncLost=false; currentRadio=NULL; currentTrack=""; dConnectionProgress=NULL; dDelConfirm=NULL; dShowHistory=NULL; netManager=NULL; currentRadioURL=-1; streamsErrLoop=false; pSpec=NULL; mMoving=false; savedVolume=0.5; isMuted=false; treeSelectionChanged=false; isRecording=false; newVersionAnimation=NULL; recButtonAnimation=NULL; isRootOperation=false; #ifdef VISUALS isVisResized=false; isVisRendering=false; visWin=new VisWinCL(this); bigVis=false; bigVisRunning=false; #endif initBitRate(); initOggQualityMap(); qDebug()<<"Cheking BASS version"; if (HIWORD(BASS_GetVersion())!=BASSVERSION) { qDebug()<<"An incorrect version of BASS.DLL was loaded"; QMessageBox::warning(this,QString("warning"),QString("An incorrect version of BASS.DLL was loaded")); } BASS_SetConfigPtr(BASS_CONFIG_NET_AGENT, (void*) _T(PLAYER_HTTPAGENT)); #ifdef Q_OS_WIN if (BASS_PluginLoad("bass_aac.dll",0)==0) { qDebug()<<"Unable to load bass_aac.ddl BassError="<<BASS_ErrorGetCode(); } #elif Q_OS_LINUX if (BASS_PluginLoad("bass_aac.so",0)==0) { qDebug()<<"Unable to load bass_aac.ddl BassError="<<BASS_ErrorGetCode(); } #endif QSettings tSettings(AppPath+CONFIG_FILENAME,QSettings::IniFormat); tSettings.setIniCodec("ISO 8859-1"); Proxy=tSettings.value("proxy","").toString(); ProxyPort=tSettings.value("proxyport","").toString(); ProxyUser=tSettings.value("proxyuser","").toString(); ProxyPass=tSettings.value("proxypass","").toString(); visualPlugin=tSettings.value("visual",VIS_WIN_PLUG).toString(); qDebug()<<"visualPlugin="<<visualPlugin; recPath=tSettings.value("recpath","").toString(); recPath=recPath.replace("\\","\\\\"); #ifdef Q_OS_WIN if (recPath!="" && recPath.at(recPath.length()-1)!='\\') recPath=recPath+"\\"; #else if (recPath!="" && recPath.at(recPath.length()-1)!='/') recPath=recPath+"/"; #endif if (recPath=="") { #ifdef Q_OS_WIN recPath=QDir::toNativeSeparators(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).at(0)+"/"); #endif #ifdef Q_OS_MAC recPath=AppPath.fromLatin1(argv[0]); recPath+="/"; #endif } qDebug()<<"Recording path ="<<recPath; if (Proxy!="") { qDebug()<<"Proxy="<<Proxy; QString tBassProxyStr=ProxyUser; if (ProxyPass!="") tBassProxyStr+=":"+ProxyPass; if (ProxyUser!="") tBassProxyStr+="@"; tBassProxyStr+=Proxy+":"+ProxyPort; qDebug()<<"BASSProxy="<<tBassProxyStr; qDebug()<<"BASSProxy="<<tBassProxyStr.toLatin1().data(); //strcpy(proxyStrChar,Proxy.toLatin1().data()); BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,tBassProxyStr.toLatin1().data()); //BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY,&proxyStrChar); } else { BASS_SetConfigPtr(BASS_CONFIG_NET_PROXY, NULL); } //if( !InitVersion() ) ErrorMsgBox(_T("\n Error Setting up Version strings \n")); if( !InitBassErrorMap() ) ErrorMsgBox(_T("\n Error setting up Error Msgs \n")); if (!BASS_Init(-1,44100,0,NULL,NULL)) { ErrorMsgBox(_T("\nUnable to initialize BASS library\n"), 86, false); exit(86); } savedVolume=BASS_GetVolume(); slVolume->setValue(savedVolume*slVolume->maximum()); #ifdef Q_OS_WIN // allocate ACM format buffer, using suggested buffer size acmformlen = BASS_Encode_GetACMFormat(0,NULL,0,NULL,0); acmform = (WAVEFORMATEX*)malloc(acmformlen); memset(acmform,0,acmformlen); acmduncil = (WAVEFORMATEX*)malloc(acmformlen); memset(acmduncil, 0, acmformlen); // #endif connect(radioTree,SIGNAL(AddStationSig(QModelIndex,RadioCL*)),this,SLOT(AddStation(QModelIndex,RadioCL*))); connect(radioTree, SIGNAL(treeSelectionChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(radioTreeSelectionChanges(const QModelIndex &, const QModelIndex &))); qDebug()<<"Connecting timers signals "; connect(PreBuf_timer, SIGNAL(timeout()), this, SLOT(prebufTimeout())); connect(Update_timer, SIGNAL(timeout()), this, SLOT(updateTimeout())); connect(Ping_timer, SIGNAL(timeout()),this, SLOT(pingRadio())); connect(Spectrum_timer, SIGNAL(timeout()), this, SLOT(specTimeout())); connect(BufferStatusUpdate_timer, SIGNAL(timeout()),this, SLOT(updateBufferStatus())); connect(singleClickTimer, SIGNAL(timeout()),this, SLOT(singleClickTimeout())); qDebug()<<"Connecting mgh signals"; connect( &mgh, SIGNAL(SendUpdTrackInfo(QString)), this, SLOT(on_UpdTrackInfo(QString)) ); connect( &mgh, SIGNAL(SendUpdRadioInfo(QString,QString,QString,QString)), this, SLOT(on_UpdRadioInfo(QString,QString,QString,QString))); connect( &mgh, SIGNAL(SendSyncLost()), this, SLOT(on_SyncLost()) ); connect( &mgh, SIGNAL(SendPlaybackStarts()), this, SLOT(on_PlaybackStarts()) ); connect( &mgh, SIGNAL(SendClickRecord()), this, SLOT(on_ClickRecord()) ); qDebug()<<"Creating actions"; createActions(); qDebug()<<"Creating tray icon"; createTrayIcon(); qDebug()<<"Setting tray icon"; setIcon(PLAYER_STATUS_INACTIVE); trayIcon->setVisible(true); trayIcon->show(); setWindowTitle(QString(PLAYER_NAME)+" v"+RADIOLA_VERSION); qDebug()<<"Initializing spectrum image"; specbuf = NULL; specmode = DEFAULT_SPEC_MODE; // spectrum mode specpos = 0; // spectrum mode (and marker pos for 2nd mode) pSpec = new QImage(SPECWIDTH, SPECHEIGHT, QImage::Format_Indexed8); // setup palette pSpec->setColor(0, qRgb(0,0,0)); for(int a=1; a < 128; a++) { pSpec->setColor(a, qRgb(2*a, 256-2*a, 0)); } for(int a=0; a < 32; a++) { pSpec->setColor(128+a, qRgb(0, 0, 8*a)); pSpec->setColor(128+32+a, qRgb(8*a, 0, 255)); pSpec->setColor(128+64+a, qRgb(255, 8*a, 8*(31-a))); //pSpec->setColor(128+64+a, qRgb(8*(31-a), 8*a, 8*a)); pSpec->setColor(128+96+a, qRgb(255, 255, 8*a)); //pSpec->setColor(128+96+a, qRgb(255, 255, 8*a)); } pSpec->setColor(254, qRgb(112, 112, 255)); pSpec->setColor(253, qRgb(255, 128, 128)); pSpec->setColor(255, qRgb(212,208,200)); // background color // create the bitmap specbuf = (BYTE*)pSpec->bits(); pSpec->fill(255); specButton->setSpec(pSpec); readSettings(); qDebug()<<"Connecting tray signals "; connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); setupRadioTree(); historyFile.setFileName(GetHistoryDir()); if (!historyFile.open(QIODevice::ReadWrite | QIODevice::Append)) { qDebug()<<"Unable to open history file for write"<<historyFile.fileName(); return; } StopPlayback(); QIcon icon = QIcon(MAINWIN_ICON); setWindowIcon(icon); new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_S), this, SLOT(showSettings())); new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_E), this, SLOT(showRecPath())); new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(showHelp())); new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_H), this, SLOT(showHistory())); #ifdef Q_OS_WIN new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_V), this, SLOT(showVisualization())); #endif new QShortcut(QKeySequence(Qt::Key_Space), this, SLOT(on_pbPlay_clicked())); new QShortcut(QKeySequence(Qt::Key_MediaPlay), this, SLOT(on_pbPlay_clicked())); new QShortcut(QKeySequence(Qt::Key_Delete), this, SLOT(removeRow())); new QShortcut(QKeySequence(Qt::Key_Insert), this, SLOT(insertStation())); new QShortcut(QKeySequence(Qt::Key_Plus), this, SLOT(insertSubfolder())); QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect(); effect->setBlurRadius(1); //Adjust accordingly effect->setOffset(3,3); //Adjust accordingly setShadow(bnShowHistory); setShadow(pbPlay); setShadow(pbRecord); setShadow(pbQuit); recButtonAnimation=new QMovie(":/images/rec_animation.gif"); connect(recButtonAnimation,SIGNAL(frameChanged(int)),this,SLOT(setRecButtonIcon(int))); singleClickTimer->setInterval(QApplication::doubleClickInterval()); singleClickTimer->setSingleShot(true); CheckNewVersion(); netManager = new QNetworkAccessManager(this); if (Proxy!="") { netManager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy,Proxy,ProxyPort.toInt(),ProxyUser,ProxyPass)); } connect(netManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(pingReply(QNetworkReply*))); }
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmd, int nCmd) { STARTUPINFO sProcStartupInfo; PROCESS_INFORMATION sProcInformation; DWORD dwNewProcessAffinity; int argc, i, rv = 1; char **argv, *szProcCmdLine, *szLastErrorMsg; LPCTSTR lpProcWorkingDir = NULL; argv = CommandLineToArgvA(GetCommandLine(),&argc,&szProcCmdLine); if(argc < 2) { ErrorMsgBox("Usage : [-a affinity] [-d working_dir] -- <cmdline>", "Improper parameters"); goto beach; } for(i=1; i<argc; ++i) { if(strcmp(argv[i],"-a") == 0) { ++i; if(i >= argc) { ErrorMsgBox("No data after -a.","Improper parameters"); goto beach; } else if(sscanf_s(argv[i],"%8x",&dwNewProcessAffinity) != 1) { ErrorMsgBox("Improper affinity specification", "Improper parameters"); goto beach; } } else if(strcmp(argv[i],"-d") == 0) { ++i; if(i >= argc) { ErrorMsgBox("No data after -d.","Improper parameters"); goto beach; } else lpProcWorkingDir = argv[i]; } } /* prepare the STARTUPINFO structure. in our case, it is desired to hide * the window of the launched process. */ ZeroMemory(&sProcStartupInfo, sizeof(sProcStartupInfo)); sProcStartupInfo.cb = sizeof(sProcStartupInfo); sProcStartupInfo.dwFlags = STARTF_USESHOWWINDOW; sProcStartupInfo.wShowWindow = SW_HIDE; ZeroMemory(&sProcInformation, sizeof(sProcInformation)); /* create the process by specifying its commandline. the process is created * as a suspended one. it is later resumed with ResumeThread() after setting * its affinity. therefore, the process will not start its execution until * the desired affinity is set. */ if(CreateProcess(NULL, szProcCmdLine, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, lpProcWorkingDir, &sProcStartupInfo, &sProcInformation) == 0) { szLastErrorMsg = win_strerror("CreateProcess()"); ErrorMsgBox(szLastErrorMsg, "WinAPI call failed"); HeapFree(GetProcessHeap(),0,szLastErrorMsg); return 1; } /* set the affinity mask for the process. */ if(SetProcessAffinityMask(sProcInformation.hProcess, dwNewProcessAffinity) == 0) { szLastErrorMsg = win_strerror("SetProcessAffinityMask()"); ErrorMsgBox(szLastErrorMsg, "WinAPI call failed"); HeapFree(GetProcessHeap(),0,szLastErrorMsg); if(TerminateProcess(sProcInformation.hProcess, 255) == 0) { szLastErrorMsg = win_strerror("TerminateProcess()"); ErrorMsgBox(szLastErrorMsg, "WinAPI call failed"); HeapFree(GetProcessHeap(),0,szLastErrorMsg); } goto beach2; } /* and resume (actually, start) its execution. */ if(ResumeThread(sProcInformation.hThread) == -1) { szLastErrorMsg = win_strerror("ResumeThread()"); ErrorMsgBox(szLastErrorMsg, "WinAPI call failed"); HeapFree(GetProcessHeap(),0,szLastErrorMsg); if(TerminateProcess(sProcInformation.hProcess, 255) == 0) { szLastErrorMsg = win_strerror("TerminateProcess()"); ErrorMsgBox(szLastErrorMsg, "WinAPI call failed"); HeapFree(GetProcessHeap(),0,szLastErrorMsg); } goto beach2; } /* process launched successfully. */ rv = 0; beach2: /* close handles to the created process and its main thread, and exit. */ CloseHandle(sProcInformation.hProcess); CloseHandle(sProcInformation.hThread); beach: HeapFree(GetProcessHeap(),0,argv); return rv; }
STDMETHODIMP HttpRequest::put_Url(BSTR newVal) { ATLASSERT(newVal); if(IsValidURL(NULL,newVal,0)!=S_OK){ ErrorMsgBox(0,_T("请求地址不合法!")); return S_OK; } DWORD dwSize=STRLEN_4K; if (!InternetCanonicalizeUrl(newVal,m_szUrl,&dwSize,ICU_BROWSER_MODE)){ ErrorMsgBox(GetLastError(),_T("请求地址不合法或者长度太大:%s")); ZeroMemory(m_szUrl,sizeof(m_szUrl)); return S_OK; } ZeroMemory(m_szUrl,sizeof(m_szUrl)); _tcsncpy_s(m_szUrl,newVal,_tcslen(newVal)); ZeroMemory(m_szUrlProtocol,sizeof(m_szUrlProtocol)); ZeroMemory(m_szUrlHost,sizeof(m_szUrlHost)); ZeroMemory(m_szUrlFile,sizeof(m_szUrlFile)); m_usUrlPort=DEFAULT_HTTP_PORT; m_blUrlIsSSL=VARIANT_FALSE; if (!m_szUrl || _tcslen(m_szUrl)==0) return S_OK; //»ñÈ¡urlÐÒ鲿·Ö for(size_t i=0;i<sizeof(m_szUrl);i++){ if (m_szUrl[i]==_T(':') || i>=sizeof(m_szUrlProtocol)) break; m_szUrlProtocol[i]=m_szUrl[i]; } //ÊÇ·ñsslºÍsslĬÈÏ¶Ë¿Ú if (_tcsicmp(m_szUrlProtocol,_T("https"))==0) { m_blUrlIsSSL=VARIANT_TRUE; if (m_usUrlPort==DEFAULT_HTTP_PORT) m_usUrlPort=DEFAULT_HTTPS_PORT; } //»ñÈ¡url¶Ë¿Ú²¿·Ö TCHAR* szPos1=_tcschr(m_szUrl+_tcslen(m_szUrlProtocol)+1,_T(':')); TCHAR* szPos2=_tcschr(m_szUrl+_tcslen(m_szUrlProtocol)+3,_T('/')); if (szPos1 && szPos2){ TCHAR szPort[STRLEN_SMALL]={0}; _tcsncpy_s(szPort,szPos1+1,szPos2-szPos1-1); TCHAR *stop; m_usUrlPort=(USHORT)_tcstoul(szPort,&stop,0); } //»ñÈ¡urlÖ÷»ú²¿·Ö int idx=0; for(size_t i=_tcslen(m_szUrlProtocol)+3;i<sizeof(m_szUrl);i++){ if (m_szUrl[i]==_T(':') || m_szUrl[i]==_T('/')) break; m_szUrlHost[idx++]=m_szUrl[i]; } //»ñÈ¡urlÎļþ²¿·Ö TCHAR* szPos3=_tcschr(m_szUrl+_tcslen(m_szUrlProtocol)+3,_T('/')); if(szPos3) _tcscpy_s(this->m_szUrlFile,szPos3); else this->m_szUrlFile[0]=_T('/'); return S_OK; }
STDMETHODIMP HttpRequest::Send(IHttpResponse** pVal) { HRESULT hr=S_OK; ATLASSERT(pVal); (*pVal)=NULL; if(!this->m_szUrl || _tcslen(this->m_szUrl)==0) { InfoMsgBox(_T("请先指定请求的目标URL地址!")); return hr; } //显示进度 rcContext.hOpen=this->m_hOpen; rcContext.dwPostFileLength=0; rcContext.dwPostedLength=0; rcContext.dwContentLength=0; rcContext.dwReceivedLength=0; if (this->m_blShowRequestProgress){ ZeroMemory(rcContext.szMemo,sizeof(rcContext.szMemo));//STRLEN_DEFAULT); _tcscpy_s(rcContext.szMemo,_T("请稍候,正在准备连接...")); rcContext.hThread=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)ProgressDialog,0,0,&(rcContext.dwThreadID)); } //请求方法 TCHAR szUrl[STRLEN_4K]={0}; _tcscpy_s(szUrl,m_szUrl); TCHAR szMethod[STRLEN_SMALL]=_T("POST"); if(this->m_szMethod && _tcslen(this->m_szMethod)>0){ ZeroMemory(szMethod,sizeof(szMethod)); _tcscpy_s(szMethod,m_szMethod); } //±äÁ¿¶¨Òå DWORD dwError=0; DWORD dwFlags=0; HINTERNET hConnect=0; //Internet»á»° HINTERNET hRequest=0; //InternetÁ¬½Ó INTERNET_PORT dwPort; BOOL postFileFlag=FALSE; //ÊÇ·ñÓÐÓÐЧµÄÌá½»Îļþ¡£ HANDLE hPostFile=0; DWORD dwPostFileSize=0; BOOL sendRequestSucceeded=TRUE; //·¢ËÍÇëÇóÊÇ·ñ³É¹¦ DWORD dwSize=0; DWORD dwStatusCode=0; //httpÇëÇóÏìÓ¦´úÂë DWORD dwContentLength=0; //httpÇëÇóÏìÓ¦ÄÚÈݳ¤¶È DWORD dwErrorCode=0; //httpÇëÇóÏìÓ¦´íÎóÂë TCHAR szContentType[STRLEN_DEFAULT]={0}; //httpÇëÇóÏìÓ¦ÄÚÈÝÀàÐÍ CComBSTR szResText(L""); //httpÇëÇóÏìÓ¦·µ»Ø½á¹ûÎı¾ TCHAR* szHeader=NULL; //httpÇëÇóÏìӦͷÐÅÏ¢ BOOL getHeanderSucceeded=TRUE; //»ñÈ¡httpÇëÇóÏìӦͷÐÅÏ¢ÊÇ·ñ³É¹¦ char readBuffer[STRLEN_1K]={0}; //ÿ´Î¶ÁÈ¡µÄÏìÓ¦ÄÚÈÝ DWORD dwCalcLength=0; //ͨ¹ýÄÚÈݼÆËã³öÀ´µÄContentLength BOOL responseFileFlag=FALSE; //ÊÇ·ñÓÐÓÐЧµÄÏìÓ¦ÄÚÈݱ¾µØ±£´æÎļþ HANDLE hResponseFile=0; //ÇëÇóÏìÓ¦ÄÚÈݱ£´æµ½±¾µØÎļþµÄÎļþ¾ä±ú int requestCount=1; //ÇëÇó´ÎÊý TCHAR szAccept[] = _T("*/*"); LPTSTR AcceptTypes[2]={0}; AcceptTypes[0]=szAccept; AcceptTypes[1]=NULL; CComPtr<IHttpResponse> response; //ÇëÇóÏìÓ¦¶ÔÏó //Á¬½Ó dwPort=this->m_usUrlPort; //¶Ë¿ÚºÅ dwFlags= INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD |INTERNET_FLAG_KEEP_CONNECTION; if (this->m_blUrlIsSSL) dwFlags |= INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_CN_INVALID | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID; //´ò¿ªÁ¬½Ó if ( !(hConnect = InternetConnect(this->m_hOpen,this->m_szUrlHost , dwPort, _T(""), _T(""), INTERNET_SERVICE_HTTP, 0, (DWORD)&rcContext))){ dwError=GetLastError(); ErrorMsgBox(dwError,_T("Internet连接错误:%s")); goto clean; } reconnect: //´ò¿ªÇëÇó if ( !(hRequest = HttpOpenRequest(hConnect,this->m_szMethod,this->m_szUrlFile, _T("HTTP/1.1"), _T(""),(LPCTSTR*)AcceptTypes, dwFlags ,(DWORD)&rcContext))){ dwError=GetLastError(); ErrorMsgBox(dwError,_T("Internet打开请求错误:%s")); goto clean; } //ÓÐÖ¸¶¨Ìá½»Îļþ if (this->m_szPostFile && _tcslen(this->m_szPostFile)) { postFileFlag=PathFileExists(this->m_szPostFile); } //Èç¹ûÓÐÌá½»µÄÎļþ if(postFileFlag) { if ((hPostFile = CreateFile(this->m_szPostFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,(HANDLE)NULL)) == (HANDLE)(-1)) { dwError=GetLastError(); ErrorMsgBox(dwError,_T("提交的文件不存在或者无法打开:%s")); goto clean; } dwPostFileSize=GetFileSize(hPostFile,NULL); rcContext.dwPostFileLength=dwPostFileSize; TCHAR szPostFileSize[STRLEN_SMALL]={0}; _stprintf_s(szPostFileSize,_T("%d"),dwPostFileSize); this->AddHeader(T2BSTR(_T("Content-Length")),T2BSTR(szPostFileSize)); } //ÉèÖÃÇëÇóÍ· if (this->m_szHeader && _tcslen(this->m_szHeader)) { if (!HttpAddRequestHeaders(hRequest,this->m_szHeader,-1L,HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD)){ dwError=GetLastError(); ErrorMsgBox(dwError,_T("设置请求头错误:%s")); goto clean; } } /* InternetSetOption(FhRequest, INTERNET_OPTION_CLIENT_CERT_CONTEXT, (LPVOID)pdDesiredCert, sizeof(CERT_CONTEXT)); INTERNET_FLAG_KEEP_CONNECTION£¬INTERNET_FLAG_EXISTING_CONNECT */ //´¦Àí¶îÍâÉèÖ㨺öÂÔһЩ´íÎó£© dwFlags=0; dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTP|SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTPS|SECURITY_FLAG_IGNORE_CERT_DATE_INVALID|SECURITY_FLAG_IGNORE_CERT_CN_INVALID; if (!InternetSetOption (hRequest, INTERNET_OPTION_SECURITY_FLAGS,&dwFlags,sizeof(dwFlags))){ dwError=GetLastError(); ErrorMsgBox(dwError,_T("设置请求选项错误:%s")); goto clean; } //·¢ËÍÇëÇó again: if(postFileFlag){ //ÓÐÌá½»ÎļþÄÚÈÝ INTERNET_BUFFERS BufferIn = {0}; DWORD dwBytesWritten; BYTE bts[STRLEN_1K]={0}; DWORD dwBtsRead=0; DWORD dwTotalBytes=0; BufferIn.dwStructSize = sizeof(INTERNET_BUFFERS); BufferIn.Next=NULL; BufferIn.dwBufferTotal=dwPostFileSize; sendRequestSucceeded=HttpSendRequestEx(hRequest, &BufferIn, NULL, HSR_INITIATE,(DWORD)&rcContext); while(ReadFile(hPostFile, bts, STRLEN_1K, &dwBtsRead, NULL) && dwBtsRead>0 && dwTotalBytes<=dwPostFileSize){ if (!InternetWriteFile(hRequest, bts,dwBtsRead, &dwBytesWritten)) { dwError=GetLastError(); ErrorMsgBox(dwError,_T("发送文件内容错误:%s")); goto clean; } dwTotalBytes+=dwBtsRead; rcContext.dwPostedLength=dwTotalBytes; } if(!HttpEndRequest(hRequest, NULL, 0, 0)) { dwError=GetLastError(); ErrorMsgBox(dwError,_T("关闭HTTP连接时错误:%s")); goto clean; } }//if end else{ //ûÓÐÌá½»ÎļþÄÚÈÝ sendRequestSucceeded=HttpSendRequest(hRequest, NULL, 0, NULL, 0); } //else end //²é¿´ÊÇ·ñÇëÇó·¢Ëͳɹ¦ if (!sendRequestSucceeded){ dwError=GetLastError(); switch(dwError){ case ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED: if(InternetErrorDlg(GetDesktopWindow(),hRequest,ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED,FLAGS_ERROR_UI_FILTER_FOR_ERRORS|FLAGS_ERROR_UI_FLAGS_GENERATE_DATA|FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,NULL)!=ERROR_SUCCESS) { requestCount++; if (requestCount>2) { InfoMsgBox(_T("已经尝试发送请求操作2次仍无法成功,请联系系统管理员!")); goto clean; } //Èç¹ûÑ»·ÇëÇó´ÎÊý¶àÓÚÁ½´Î£¬ÄÇô²»ÔÙÑ»· else goto again; } break; case ERROR_SUCCESS: break; default: ErrorMsgBox(dwError,_T("发送请求错误:%s")); goto clean; }//switch end }//if end //È¡ÏìӦ״̬ÏûÏ¢ dwSize= sizeof(DWORD); if (!HttpQueryInfo(hRequest,HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwSize, NULL)) { dwError=GetLastError(); ErrorMsgBox(dwError,_T("获取响应代码错误:%s")); goto clean; } switch(dwStatusCode){ case HTTP_STATUS_DENIED: //ÐèÒªµÇ¼ case HTTP_STATUS_PROXY_AUTH_REQ: InfoMsgBox(_T("请求的地址需要登录,请您先登录后再发送请求!")); goto clean; case HTTP_STATUS_REDIRECT: //Öض¨Ïò case HTTP_STATUS_MOVED: { TCHAR szRedirect[4096]={0}; DWORD dwRedirect=sizeof(szRedirect); if (!HttpQueryInfo(hRequest,HTTP_QUERY_LOCATION,(LPVOID)szRedirect,&dwRedirect,NULL)){ dwError=GetLastError(); ErrorMsgBox(hr,_T("获取重定向地址错误:%s")); goto clean; } this->put_Url(szRedirect); //ÏȹرÕÁ¬½ÓºÍÇëÇó£¬È»ºóÖØÐÂÁ¬½Ó if (!InternetCloseHandle(hRequest)) { dwError=GetLastError(); ErrorMsgBox(dwError,_T("关闭HTTP请求错误:%s")); goto clean; } //if (!InternetCloseHandle(hConnect)) //{ // dwError=GetLastError(); // ErrorMsgBox(dwError,_T("关闭HTTP连接错误:%s")); // goto clean; //} //MessageBox(0,szRedirect,_T("重定向"),0); goto reconnect; } case HTTP_STATUS_OK: default: break; } //¹¹ÔìÇëÇóÏìÓ¦¡£ response.p=NULL; hr=response.CoCreateInstance(_T("YRExchange.HttpResponse")); if (FAILED(hr)) { ErrorMsgBox(hr,_T("创建HttpResponse错误:%s")); goto clean; } response->put_StatusCode(dwStatusCode); response->put_ErrorCode(dwError); //ÏìÓ¦ÄÚÈÝ´óС dwSize=sizeof(dwContentLength); if (HttpQueryInfo(hRequest,HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER ,&dwContentLength,&dwSize,NULL)){ //dwError=GetLastError(); //ErrorMsgBox(dwError,_T("获取请求响应内容长度错误:%s")); //goto clean; if (dwContentLength>0) { response->put_ContentLength(dwContentLength); rcContext.dwContentLength=dwContentLength; } } //ÏìÓ¦ÄÚÈÝÀàÐÍ dwSize=sizeof(szContentType); if (HttpQueryInfo(hRequest,HTTP_QUERY_CONTENT_TYPE ,(LPVOID)szContentType,&dwSize,NULL)){ //dwError=GetLastError(); //ErrorMsgBox(dwError,_T("获取请求响应内容类型错误:%s")); //goto clean; if (_tcslen(szContentType)>0) response->put_ContentType(T2BSTR(szContentType)); } //ËùÓÐÏìӦͷÐÅÏ¢ szHeader=new TCHAR[STRLEN_8K]; dwSize=STRLEN_8K*sizeof(TCHAR); getheader: getHeanderSucceeded=HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF ,(LPVOID)szHeader,&dwSize,NULL); if(!getHeanderSucceeded){ dwError=GetLastError(); if (dwError==ERROR_INSUFFICIENT_BUFFER){ TCHAR szXX[100]={0}; _stprintf_s(szXX,_T("dwError=%d,dwSize=%d"),dwError,dwSize); InfoMsgBox(szXX); SAFE_FREE_STRING_PTR(szHeader); szHeader=new TCHAR[dwSize+2]; dwSize+=2; dwSize=dwSize*sizeof(TCHAR); goto getheader; } else if (dwError!=ERROR_SUCCESS){ ErrorMsgBox(dwError,_T("获取请求响应头信息错误:%s")); goto clean; } } if(szHeader) response->put_Header(T2BSTR(szHeader)); //ÏìÓ¦ÄÚÈÝ´¦Àí if (this->m_blSaveResponseToFile && this->m_szResponseFile && _tcslen(this->m_szResponseFile)>0 && dwStatusCode != 201){ //°ÑÏìÓ¦ÄÚÈݱ£´æµ½Îļþ //´´½¨Îļþ hResponseFile = CreateFile(this->m_szResponseFile,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if (hResponseFile == INVALID_HANDLE_VALUE) { dwError=GetLastError(); ErrorMsgBox(dwError,_T("打开响应内容本地保存文件错误:%s")); goto clean; } responseFileFlag=TRUE; } do{ ZeroMemory(readBuffer,STRLEN_1K); dwSize=0; if (!InternetReadFile(hRequest,(LPVOID)readBuffer,sizeof(readBuffer),&dwSize)){ dwError=GetLastError(); ErrorMsgBox(dwError,_T("读取请求响应内容错误:%s")); goto clean; } if (dwSize!=0){ dwCalcLength+=dwSize; if (responseFileFlag){ //дÎļþ DWORD dwWritten=0; if (!WriteFile(hResponseFile,readBuffer,dwSize,&dwWritten,NULL)){ dwError=GetLastError(); ErrorMsgBox(dwError,_T("写入响应内容本地保存文件错误:%s")); goto clean; } } else{ //×·¼Óµ½ÏàÓ¦Îı¾ char buffer[STRLEN_1K+2]={0}; strncpy_s(buffer,readBuffer,dwSize); if (szResText) szResText.Append(buffer); } if (dwCalcLength==dwContentLength) break; rcContext.dwReceivedLength=dwCalcLength; }//if end }while(dwSize!=0); //°ÑÏìÓ¦ÄÚÈݱ£´æµ½ÏìÓ¦Îı¾ if (!responseFileFlag){ response->put_ContentText(szResText.Detach()); }// //×ÊÔ´»ØÊÕ clean: //¹Ø±ÕÎļþ if(hPostFile) CloseHandle(hPostFile); if(hResponseFile) { FlushFileBuffers(hResponseFile); CloseHandle(hResponseFile); } //»ØÊÕhttpÁ¬½ÓºÍÇëÇó¾ä±ú if (hRequest) InternetCloseHandle(hRequest); if (hConnect) InternetCloseHandle(hConnect); //¹Ø±Õ״̬¿ò //if (this->m_blShowRequestProgress) WaitForMultipleObjects(1,&rcContext.hThread,TRUE,INFINITE); if (this->m_blShowRequestProgress) EndDialog(rcContext.hProgressWnd,0); SAFE_FREE_STRING_PTR(szHeader); response.CopyTo(pVal); return S_OK; }
void ConfigWindow::on_tsSetZBPB_clicked() { HANDLE comport; int zbChan; if (opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } switch(ui->tsZBValCB->currentIndex()) { case 0: zbChan = 11; break; case 1: zbChan = 12; break; case 2: zbChan = 13; break; case 3: zbChan = 14; break; case 4: zbChan = 15; break; case 5: zbChan = 16; break; case 6: zbChan = 17; break; case 7: zbChan = 18; break; case 8: zbChan = 19; break; case 9: zbChan = 20; break; case 10: zbChan = 21; break; case 11: zbChan = 22; break; case 12: zbChan = 23; break; case 13: zbChan = 24; break; case 14: zbChan = 25; break; case 15: zbChan = 26; break; } if (opiucd_settszbchan(&comport, zbChan)) { ErrorMsgBox(QString("Could not set TrueSense ZigBee Channel")); opi_closeucd_com(&comport); return; } QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Set TrueSense ZigBee Channel").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); opi_closeucd_com(&comport); }
void ConfigWindow::on_tsStatusPB_clicked() { HANDLE comport; OPIPKT_t opipkt; qint64 moddsn, modrtc, modrtcSet, modRefEpochMSecs; qint32 modfwv; qint16 modpdn, modzbChan, modRFMode, modRFTxPwr, modMMWrite, modRFTxTimeout; QString tempstr; if (opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if(opiucd_tsstatus(&comport, &opipkt)) { ErrorMsgBox(QString("Could not get TrueSense status")); opi_closeucd_com(&comport); return; } moddsn = ((qint64) opipkt.payload[1] << 32) + ((qint64)opipkt.payload[2] << 24) + (opipkt.payload[3] << 16) + (opipkt.payload[4] << 8) + opipkt.payload[5]; modrtc = ((qint64) opipkt.payload[1+DSNLEN] << 32) + ((qint64) opipkt.payload[1+DSNLEN+1] << 24) + (opipkt.payload[1+DSNLEN+2] << 16) + (opipkt.payload[1+DSNLEN+3] << 8) + opipkt.payload[1+DSNLEN+4]; modrtcSet = modrtc >> 39; if (modrtcSet) modRefEpochMSecs = (modrtc - (((qint64) 1) << 39))*64*1000/32768; else modRefEpochMSecs = modrtc*64*1000/32768; // Conversion to QDateTime, ref date & time for all sensors is 2012/sep/28 08:00:00.000 QDateTime modDT = QDateTime::fromString("20120928080000000","yyyyMMddhhmmsszzz").addMSecs(modRefEpochMSecs); modfwv = (opipkt.payload[1+DSNLEN+5] << 8) + opipkt.payload[1+DSNLEN+5+1]; modpdn = opipkt.payload[1+DSNLEN+5+FWVLEN]; modzbChan = opipkt.payload[1+DSNLEN+5+FWVLEN+1]; modRFMode = opipkt.payload[1+DSNLEN+5+FWVLEN+2]; modRFTxPwr = opipkt.payload[1+DSNLEN+5+FWVLEN+3]; modMMWrite = opipkt.payload[1+DSNLEN+5+FWVLEN+4]; modRFTxTimeout = opipkt.payload[1+DSNLEN+5+FWVLEN+5]; ui->msgPTE->appendPlainText(QString(">> TrueSense Status")); ui->msgPTE->appendPlainText(QString("Paired Device Number: %1 Firmware Version: %2 Time: %3 ZigBee Channel: %4").arg(modpdn).arg(modfwv).arg(modDT.toString("yyyyMMdd hhmmss")).arg(modzbChan)); ui->tsPDNValLE->setText(QString("%1").arg(modpdn)); ui->tsZBValCB->setCurrentIndex(modzbChan-11); if(modRFMode == 0) { tempstr.append("RF Always Off"); ui->tsRFModeValCB->setCurrentIndex(0); ui->tsRFTOValCB->setCurrentIndex(modRFTxTimeout); } else if(modRFMode == 1) { tempstr.append("RF Always On"); ui->tsRFModeValCB->setCurrentIndex(1); ui->tsRFTOValCB->setCurrentIndex(modRFTxTimeout); } else if(modRFMode == 2) { if(opiucd_settsrfmode(&comport, 3)) { ErrorMsgBox(QString("Failed to set RF Mode to On with Double Tap and Timeout enabled")); opi_closeucd_com(&comport); return; } if(modRFTxTimeout == 0) tempstr.append("RF On with double tap enabled"); else if(modRFTxTimeout == 1) tempstr.append("RF On with double tap enabled and timeout of 30 min"); else if(modRFTxTimeout == 2) tempstr.append("RF On with double tap enabled and timeout of 1 hour"); ui->tsRFModeValCB->setCurrentIndex(2); ui->tsRFTOValCB->setCurrentIndex(modRFTxTimeout); } else if(modRFMode == 3) { if(modRFTxTimeout == 0) tempstr.append("RF On with double tap enabled"); else if(modRFTxTimeout == 1) tempstr.append("RF On with double tap enabled and timeout of 30 min"); else if(modRFTxTimeout == 2) tempstr.append("RF On with double tap enabled and timeout of 1 hour"); ui->tsRFModeValCB->setCurrentIndex(2); ui->tsRFTOValCB->setCurrentIndex(modRFTxTimeout); } ui->msgPTE->appendPlainText(tempstr); if(modMMWrite) { ui->msgPTE->appendPlainText("Memory Module Write Enabled"); } else { ui->msgPTE->appendPlainText("Memory Module Write Disabled"); } QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Got TrueSense Status").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); opi_closeucd_com(&comport); }
void ConfigWindow::on_ucStatusPB_clicked() { HANDLE comport; OPIPKT_t opipkt; qint64 ucdsn, ucCurrTS, ucRefEpochMSecs; qint32 ucfwv; qint16 ucMode, pdnList[PDNLISTLEN], uczbChan, ucusdStatus, ucChgStat; qint32 i, pdnCt; QString tempstr; if (opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if(opiucd_status(&comport, &opipkt)) { ErrorMsgBox(QString("Could not get UC status")); opi_closeucd_com(&comport); return; } ucdsn = ((qint64) opipkt.payload[0] << 32) + ((qint64) opipkt.payload[1] << 24) + ((qint64) opipkt.payload[2] << 16) + ((qint64) opipkt.payload[3] << 8) + ((qint64) opipkt.payload[4]); ucCurrTS = ((qint64) opipkt.payload[5] << 40) + ((qint64) opipkt.payload[6] << 32) + ((qint64) opipkt.payload[7] << 24) + ((qint64) opipkt.payload[8] << 16) + ((qint64) opipkt.payload[9] << 8) + ((qint64) opipkt.payload[10]); ucRefEpochMSecs = ucCurrTS*1000/UCRTCFREQ; // Conversion to QDateTime, ref date & time for all sensors is 2012/sep/28 08:00:00.000 QDateTime ucDT = QDateTime::fromString("20120928080000000","yyyyMMddhhmmsszzz").addMSecs(ucRefEpochMSecs); ucfwv = (opipkt.payload[DSNLEN+TSLEN+6] << 8) + opipkt.payload[DSNLEN+TSLEN+6+1]; ucMode = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN]; for (i = 0; i < PDNLISTLEN; i++) pdnList[i] = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+i]; uczbChan = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN]; ucusdStatus = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN+1]; ucChgStat = opipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN+2]; if(ucusdStatus & 0x04) ui->ucModOnOffCB->setCurrentIndex(0); else ui->ucModOnOffCB->setCurrentIndex(1); ui->msgPTE->appendPlainText(QString(">> UC Status")); ui->msgPTE->appendPlainText(QString("Device ShortID: %1 Firmware Version: %2 Time: %3 ZigBee Channel: %4").arg(QChar(opipkt.payload[4]%26 + 65)).arg(ucfwv).arg(ucDT.toString("yyyyMMdd hhmmss")).arg(uczbChan)); if(ucusdStatus & 0x04) ui->msgPTE->appendPlainText("uSD sensor on"); else ui->msgPTE->appendPlainText("uSD sensor off"); if((ucusdStatus & 0x03) == 0) ui->msgPTE->appendPlainText("uSD Slot: Nothing"); else if((ucusdStatus & 0x03) == 1) ui->msgPTE->appendPlainText("uSD Slot: TS only"); else if((ucusdStatus & 0x03) == 2) ui->msgPTE->appendPlainText("uSD Slot: MM only"); else if((ucusdStatus & 0x03) == 3) ui->msgPTE->appendPlainText("uSD Slot: TS & MM"); if(ucChgStat & 0x30) ui->msgPTE->appendPlainText("Controller is in On Mode"); else ui->msgPTE->appendPlainText("Controller is in Off Mode"); if(ucusdStatus & 0x10) ui->msgPTE->appendPlainText("USD SPI is on"); else ui->msgPTE->appendPlainText("USD SPI is off"); pdnCt = 0; for(i = 0; i < PDNLISTLEN; i++) { if(pdnList[i] != 0xFF) { tempstr.append(QString("Slot %1-#%2, ").arg(i+1).arg(pdnList[i])); pdnCt++; } } if(!pdnCt) tempstr = QString("No paired devices"); else tempstr.prepend(QString("%1 Associated PDNs: ").arg(pdnCt)); ui->msgPTE->appendPlainText(tempstr); // update the current ZigBee Channel ui->ucZBValCB->setCurrentIndex(uczbChan-11); QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Unified Controller Status").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); opi_closeucd_com(&comport); }
void ConfigWindow::on_ucWLMeasurePB_clicked() { HANDLE comport; OPIPKT_t ucOpipkt; qint32 result[16]; QString resTopLine, resBotLine; int i, uczbChan; QProgressDialog progQPD("Measuring ZigBee Channels", QString(), 0, 15); progQPD.setWindowModality(Qt::WindowModal); progQPD.setMinimumDuration(100); if(opi_openucd_com(&comport)) { ErrorMsgBox(QString("No UC attached (COM1-COM50)")); opi_closeucd_com(&comport); return; } if(opiucd_status(&comport, &ucOpipkt)) { ErrorMsgBox(QString("Couldn't get UC status")); opi_closeucd_com(&comport); return; } // save current channel uczbChan = ucOpipkt.payload[DSNLEN+TSLEN+6+FWVLEN+1+PDNLISTLEN]; ui->msgPTE->appendPlainText(QString("Original ZigBee Channel: %1").arg(uczbChan)); ui->msgPTE->appendPlainText("Measuring all zigbee channels, please wait"); qApp->processEvents(); // Go through each valid channel and get maximum out of 100 tries for(i = 0; i < 16; i++) { if (opiucd_setzbchan(&comport, i+11)) { ErrorMsgBox(QString("Could not set UC ZigBee Channel")); opi_closeucd_com(&comport); return; } result[i] = maxWLMeasure100(&comport); progQPD.setValue(i); qApp->processEvents(); } resTopLine.append("ZigBee Channel: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26"); resBotLine.append("Maximum ED : "); for(i = 0; i < 16; i++) resBotLine.append(QString("%1 ").arg(result[i],2,10,QChar('0'))); ui->msgPTE->appendPlainText(resTopLine); ui->msgPTE->appendPlainText(resBotLine); // set original zb channel if (opiucd_setzbchan(&comport, uczbChan)) { ErrorMsgBox(QString("Could not set original UC ZigBee Channel")); opi_closeucd_com(&comport); return; } opi_closeucd_com(&comport); QDateTime currDT = QDateTime::currentDateTime(); ui->msgPTE->appendPlainText(QString("<< %1 >> Wireless Measurements done").arg(currDT.toString("yyyy.MM.dd hh:mm:ss"))); ui->msgPTE->appendPlainText(QString(" ")); ui->msgPTE->ensureCursorVisible(); }
bool MoveDirWithFilebackupRename(wxString from, wxString to, bool backup, bool silent) { // first make sure that the source dir exists if (!wxDir::Exists(from)) { ErrorMsgBox(from + _T(" does not exist. Can not copy directory."), silent); return false; } if (from == to) { ErrorMsgBox(_T("Cannot copy: source == destination: ") + from, silent); return false; } if (from.empty() || to.empty()) { ErrorMsgBox(_T("Cannot copy empty directory"), silent); return false; } SafeMkdir(to); wxString sep = wxFileName::GetPathSeparator(); wxDir dir(from); wxString filename; if (!dir.GetFirst(&filename)) { return false; } // append a slash if there is not one (for easier parsing) // because who knows what people will pass to the function. if (!to.EndsWith(sep)) { to += sep; } // for both dirs if (!from.EndsWith(sep)) { from += sep; } do { const wxString srcfile = from + filename; const wxString dstfile = to + filename; if (wxDirExists(srcfile)) { //check if srcfile is a directory MoveDirWithFilebackupRename(srcfile, dstfile, false, silent); //no backup in subdirs } else { //if files exists move it to backup, this way we can use this func on windows to replace 'active' files if (backup && wxFileExists(dstfile)) { const wxString backupfile = dstfile + _T(".old"); if (!MoveFile(dstfile, backupfile)) { ErrorMsgBox(wxString::Format(_T("could not rename %s to %s. copydir aborted"), dstfile.c_str(), backupfile.c_str()), silent); return false; } } //do the actual copy if (!wxCopyFile(srcfile, dstfile, true)) { ErrorMsgBox(wxString::Format(_T("could not copy %s to %s, copydir aborted"), srcfile, dstfile), silent); return false; } } } while (dir.GetNext(&filename)); return true; }
//--------------------------------------------------------------------------- BOOL ServoGetStat(byte addr, JRKerrSendCmd *jrsendcmd) { int numbytes, numrcvd; int i, bytecount; byte cksum; byte inbuf[20]; SERVOMOD *p; char msgstr[80]; p = (SERVOMOD *)(jrsendcmd->mod[addr].p); //cast the data pointer to the right type //Find number of bytes to read: numbytes = 2; //start with stat & cksum if ( (jrsendcmd->mod[addr].statusitems) & SEND_POS ) numbytes +=4; if ( (jrsendcmd->mod[addr].statusitems) & SEND_AD ) numbytes +=1; if ( (jrsendcmd->mod[addr].statusitems) & SEND_VEL ) numbytes +=2; if ( (jrsendcmd->mod[addr].statusitems) & SEND_AUX ) numbytes +=1; if ( (jrsendcmd->mod[addr].statusitems) & SEND_HOME ) numbytes +=4; if ( (jrsendcmd->mod[addr].statusitems) & SEND_ID ) numbytes +=2; if ( (jrsendcmd->mod[addr].statusitems) & SEND_PERROR ) numbytes +=2; if ( (jrsendcmd->mod[addr].statusitems) & SEND_NPOINTS ) numbytes +=1; numrcvd = SioGetChars(jrsendcmd->ComPort, (char *)inbuf, numbytes); //Verify enough data was read if (numrcvd != numbytes) { /* sprintf(msgstr,"ServoGetStat (%d) failed to read chars",addr); ErrorMsgBox(msgstr); */ printf("ServoGetStat (%d) failed to read chars",addr); return false; } //Verify checksum: cksum = 0; for (i=0; i<numbytes-1; i++) cksum = (byte)(cksum + inbuf[i]); if (cksum != inbuf[numbytes-1]) { sprintf(msgstr,"ServoGetStat(%d): checksum error",addr); ErrorMsgBox(msgstr); return false; } //Verify command was received intact before updating status data jrsendcmd->mod[addr].stat = inbuf[0]; if (jrsendcmd->mod[addr].stat & CKSUM_ERROR) { ErrorMsgBox("Command checksum error!"); return false; } //Finally, fill in status data bytecount = 1; if ( (jrsendcmd->mod[addr].statusitems) & SEND_POS ) { p->pos = *( (long *)(inbuf + bytecount) ); bytecount +=4; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_AD ) { p->ad = inbuf[bytecount]; bytecount +=1; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_VEL ) { p->vel = *( (short int *)(inbuf + bytecount) ); bytecount +=2; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_AUX ) { p->aux = inbuf[bytecount]; bytecount +=1; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_HOME ) { p->home = *( (unsigned long *)(inbuf + bytecount) ); bytecount +=4; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_ID ) { jrsendcmd->mod[addr].modtype = inbuf[bytecount]; jrsendcmd->mod[addr].modver = inbuf[bytecount+1]; bytecount +=2; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_PERROR ) { p->perror = *( (short int *)(inbuf + bytecount) ); bytecount +=2; } if ( (jrsendcmd->mod[addr].statusitems) & SEND_NPOINTS ) { p->npoints = inbuf[bytecount]; //bytecount +=1; } return TRUE; }