void NetworkCommunication::HearBeat() { heartBeatCounter++; if ((heartBeatCounter * heartBeatTimeInterval) > (1000*triggerTimeOut) && scanRunning == 0 && scanTriggered == 1) { scanTriggered=0; timerHeartBeat->stop(); qDebug() << "NetworkCommunication::HearBeat(): TimeOut, the scan did not initialize!"; } else if ((heartBeatCounter * heartBeatTimeInterval) > (1000*scanTimeOut) && scanRunning == 1 && scanTriggered == 1) { scanTriggered=0; EndScan(); timerHeartBeat->stop(); qDebug() << "NetworkCommunication::HearBeat(): TimeOut, the scan did not end!"; } else if (telegramTrigger != NULL && telegramHandler != NULL) { //qDebug() << "Beat number" << heartBeatCounter << " & scanRunning = " << scanRunning << " & scanTriggered = " << scanTriggered << " Time number: " << heartBeatCounter * heartBeatTimeInterval << " of limit " << 1000*triggerTimeOut; u_int8_t beat; telegramTrigger->ReadData(0,beat); telegramTrigger->SetData(0,!beat); //bool bit0; //telegramTrigger->ReadData(0,bit0); //bool bit1; //telegramTrigger->ReadData(1,bit1); //qDebug() << "CobID: " << telegramTrigger->readCobId() << " Port: " << telegramTrigger->readPort() << " Bit 0 :" << bit0 << " Bit 1 :" << bit1 << " variables: " << telegramTrigger->dataVariables.length(); telegramHandler->BroadcastTelegram(telegramTrigger); } else { EndScan(); timerHeartBeat->stop(); qDebug() << "NetworkCommunication::HearBeat(): Error in sequency"; } }
void NetworkCommunication::StatusReceived() { //qDebug() << "Status received!"; if(telegramStatus != NULL){ u_int8_t statusBool; telegramStatus->ReadData(variableIndexTriggerReceived,statusBool); if(scanTriggered==1 && scanRunning==0 && statusBool ==1) { qDebug() << "Start"; InitializeScan(); } else if (scanTriggered==1 && scanRunning==1 && statusBool ==0) { qDebug() << "Non violant END"; EndScan(); } } }
//--------------------------------------------------------------------------- // ParseCommandLine // // This routine parses the command line given. If the command line is valid, // then it is assumed that the user's intention is to execute the test given // and then exit -- without using the UI for anything. Else, we display the // usage message box (if the cmdline wasn't valid), and return. // // RETURNS: NULL if cmdline was valid (script run made, or attempted), // or if command line was invalid and usage was given, // OR pointer to script to load if /RUN not present given. // // NOTE: If no script was given, this function returns a ptr // to a null string. //--------------------------------------------------------------------------- HANDLE *ParseCommandLine (LPSTR cmdline) { CHAR *tok, *scr; INT doit = 0, scriptfound = 0; static HANDLE hScr[9] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; #ifdef DEBUG fDiags = 0; #endif // We always return at least one file name, so allocate it now //----------------------------------------------------------------------- listflag = 0; if (!(hScr[0] = LocalAlloc (LHND, 128))) { MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM); return (NULL); } scr = LocalLock (hScr[0]); // Return now if no cmdline args given //----------------------------------------------------------------------- scr[0] = 0; tok = GetCmdToken(cmdline); if (!tok) return (hScr); do { // Check here for the /T (testmode) switch and get its parameter //------------------------------------------------------------------- if (!_stricmp (tok, "/T") || !_stricmp (tok, "-T")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (tmbuf, tok); } // Here we check for /C (command) switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/C") || !_stricmp (tok, "-C")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } lstrcpy (cmdbuf, tok); } // /NOE (no error dialog) //------------------------------------------------------------------- else if (!_stricmp (tok, "/NOE") || !_stricmp (tok, "-NOE")) { NOERRDLG = 1; } // /A (filename) switch (produce assembly listing/diagnostics) //------------------------------------------------------------------- else if (!_stricmp (tok, "/A") || !_stricmp (tok, "-A")) { tok = GetCmdToken (cmdline); if (!tok) { Usage(); return (NULL); } SetAssemblyListFile (tok); } // /RUN switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/RUN") || !_stricmp (tok, "-RUN")) { doit = 1; } #ifdef DEBUG else if (!_stricmp (tok, "/DIAG") || !_stricmp (tok, "-DIAG")) { fDiags = 1; } #endif // /D (define) switch //------------------------------------------------------------------- else if (!_stricmp (tok, "/D") || !_stricmp (tok, "-D")) { tok = GetCmdToken(cmdline); if (!tok) { Usage(); return (NULL); } if (SymCount == 16) { MPError (NULL, MB_OK | MB_ICONSTOP, IDS_MANYSYMBOLS); return (NULL); } _fstrncpy (DefSym[SymCount], tok, MAXSYMLEN); DefSym[SymCount++][MAXSYMLEN] = 0; } // If this was nothing above, we assume it's a script name //------------------------------------------------------------------- else if (scriptfound < 8) { if (!hScr[scriptfound]) { if (!(hScr[scriptfound] = LocalAlloc (LHND, 128))) { MPError (NULL, MB_OK | MB_ICONEXCLAMATION, IDS_OUTOFMEM); return (NULL); } scr = LocalLock (hScr[scriptfound]); } lstrcpy (scr, tok); LocalUnlock (hScr[scriptfound]); scriptfound += 1; } // Must have given too many script names //------------------------------------------------------------------- else { Usage (); return (NULL); } } while (tok = GetCmdToken(cmdline)); // No error dialog gets nullified if we're running the environment //----------------------------------------------------------------------- if (NOERRDLG && (!doit)) NOERRDLG = 0; // Return a pointer to the scripts given if no /RUN switch given //----------------------------------------------------------------------- if (!doit) return (hScr); // Give an error if no script name found, or more than one //----------------------------------------------------------------------- if (scriptfound != 1) { Usage (); return (NULL); } // Okay, we got a valid cmdline and we need to run. Send the script to // the parsing engine. // // NEW: Create a simple window which stays minimized and behind every // NEW: other window. The window text for this will contain the name // NEW: of the script running. //----------------------------------------------------------------------- EnsureExt (scr, 80); AnsiUpper (scr); Command = cmdbuf; TestMode = tmbuf; // KLUDGE: Call peekmessage to yield once... { MSG msg; CHAR buf[256], fmt[40]; PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE); // Change the window text of the viewport for this guy... //----------------------------------------------------------------------- if (LoadString (hInst, IDS_VPRUNTITLE, fmt, sizeof(fmt))) { wsprintf (buf, fmt, (LPSTR)scr); SetWindowText (hwndViewPort, buf); } } // Here's where we create the dummy window //----------------------------------------------------------------------- hwndDummy = CreateWindow (szRBRun, (LPSTR)scr, WS_OVERLAPPED|WS_SYSMENU, 0, 0, 0, 0, NULL, NULL, hInst, NULL); SetWindowPos (hwndDummy, (HWND)1, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); ShowWindow (hwndDummy, SW_SHOWMINNOACTIVE); // Okay, here we go. //----------------------------------------------------------------------- if (InitParser ()) { // HACKHACK: ntbldrus (kenhia) - on x86, complains about uninit var // 41 lines below (in final else WITHIN this if block) HCURSOR hOld = 0; // Initialize the scanner //------------------------------------------------------------------- if (BeginScan (scr, CBLoaderImmediate, SymCount, DefPtrs)) { #ifdef DEBUG if (fDiags) OpenDiagFile (scr); #endif hOld = SetCursor (LoadCursor (NULL, IDC_WAIT)); if (!PcodeCompile()) { if (PcodeFixup(0)) { SetCursor (hOld); PcodeExecute(PE_RUN, NULL); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (ExitVal); } else { SetCursor (hOld); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } } else { SetCursor (hOld); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } EndScan (); } else { SetCursor (hOld); AbortParser(); MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTREAD, (LPSTR)scr); DestroyWindow (hwndDummy); DestroyWindow (hwndViewPort); exit (1); } } else MPError (NULL, MB_OK | MB_ICONSTOP, IDS_CANTINIT); DestroyWindow (hwndViewPort); DestroyWindow (hwndDummy); exit (1); }