/*********************************************************************** * FUNCTION: MeasCyclicSaveValues * DESCRIPTION: Cyclicly called routine to asure all necessary * measurement data to be saved in NVRAM * PARAMETER: - * RETURN: error code * COMMENT: - Does only write into nvram if any changes made in value * - Reduces sytem load by only saving one value every 200 ms. * - init values are valid after reading initial reading * from nvram. *********************************************************************** */ ERRCODE MeasCyclicSaveValues(void) { static BOOL fInit = FALSE; /* to check for initialized static vars */ static PARAM_ID_TYPE PID = PID_NVRAM_START; static UINT16 wLastCall = 0; UINT16 wThisCall = 0; ERRCODE RValue = ERR_OK; static DIST_TYPE VehicDistCopy; static DIST_TYPE TripACopy; static DIST_TYPE TripBCopy; static DIST_TYPE FuelDistCopy; static SPEED_TYPE SpeedMaxCopy; static SPEED_TYPE SpeedAvrMCopy; static SPEED_TYPE SpeedAvrPCopy; /* first init local copies at first call */ if (fInit == FALSE) { VehicDistCopy = VehicDist; TripACopy = TripA; TripBCopy = TripB; SpeedMaxCopy = SpeedMax; SpeedAvrMCopy = SpeedAvrM; SpeedAvrPCopy = SpeedAvrP; FuelDistCopy = FuelDist; fInit = TRUE; } /* check: time to save one system parameter? */ TimerGetSys_msec(wThisCall); if (wThisCall - wLastCall > NVRAM_CYCLE) { wLastCall = wThisCall; /* update time stamp */ switch (PID) /* choice of system parameter to be saved */ { case PID_VEHIC_KM: if (VehicDistCopy.dkm != VehicDist.dkm) { RValue = ParWriteSysParam( PID, &VehicDist); VehicDistCopy = VehicDist; ODS2(DBG_MEAS,DBG_INFO,"VehicDist: %lu,%.2lu km", VehicDist.dkm/100L, VehicDist.dkm-(VehicDist.dkm/100L)*100); } break; case PID_TRIPA_KM: if (TripACopy.dkm != TripA.dkm) { RValue = ParWriteSysParam( PID, &TripA); TripACopy = TripA; ODS2(DBG_MEAS,DBG_INFO,"TripA: %lu,%.2lu km", TripA.dkm/100L, TripA.dkm-(TripA.dkm/100L)*100); } break; case PID_TRIPB_KM: if (TripBCopy.dkm != TripB.dkm) { RValue = ParWriteSysParam( PID, &TripB); TripBCopy = TripB; ODS2(DBG_MEAS,DBG_INFO,"TripB: %lu,%.2lu km", TripB.dkm/100L, TripB.dkm-(TripB.dkm/100L)*100); } break; case PID_FUEL_KM: if (FuelDistCopy.dkm != FuelDist.dkm) { RValue = ParWriteSysParam( PID, &FuelDist); FuelDistCopy = FuelDist; ODS2(DBG_MEAS,DBG_INFO,"FuelDist: %lu,%.2lu km", FuelDist.dkm/100L, FuelDist.dkm-(FuelDist.dkm/100L)*100); } break; case PID_SPEED_MAX: if (SpeedMaxCopy != SpeedMax) { RValue = ParWriteSysParam( PID, &SpeedMax); SpeedMaxCopy = SpeedMax; ODS2(DBG_MEAS,DBG_INFO,"SpeedMax: %u,%.2u km/h", SpeedMax/100, SpeedMax-(SpeedMax/100)*100); } break; case PID_SPEED_AVR_M: if (SpeedAvrMCopy != SpeedAvrM) { RValue = ParWriteSysParam( PID, &SpeedAvrM); SpeedAvrMCopy = SpeedAvrM; ODS2(DBG_MEAS,DBG_INFO,"SpeedAvrM: %u,%.2u km/h", SpeedAvrM/100, SpeedAvrM-(SpeedAvrM/100)*100); } break; case PID_SPEED_AVR_P: if (SpeedAvrPCopy != SpeedAvrP) { RValue = ParWriteSysParam( PID, &SpeedAvrP); SpeedAvrPCopy = SpeedAvrP; ODS2(DBG_MEAS,DBG_INFO,"SpeedAvrP: %u,%.2u km/h", SpeedAvrP/100, SpeedAvrP-(SpeedAvrP/100)*100); } break; default: ODS1(DBG_MEAS,DBG_ERROR,"Unknown PID: %u", PID); break; } /* next system parameter for next call */ PID++; /* inkr PID */ if (PID >= PID_NVRAM_END) PID = PID_NVRAM_START; /* start at the begining again */ } return RValue; }
int CHttpRequest::ConnectUrl(TCHAR *sUrl, TCHAR *sReturn, long *lVersion, int *Count) { ODS(_T("XFILTER.EXE: GetFromUrl Begin... \n")); if(sUrl == NULL) return XERR_INVALID_PARAMETER; CString strServerName; CString strObject; INTERNET_PORT nPort; DWORD dwServiceType; if (!AfxParseURL(sUrl, dwServiceType, strServerName, strObject, nPort) || dwServiceType != INTERNET_SERVICE_HTTP) { ODS(_T("XFILTER.EXE: Internet Invalid Url ...")); return XERR_INTERNET_URL_ERROR; } CInternetSession session(GUI_APP_CLASS_NAME); CHttpConnection *pServer = NULL; CHttpFile *pFile = NULL; int iRet = XERR_SUCCESS; m_IsConnecting = TRUE; try { pServer = session.GetHttpConnection(strServerName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject); pFile->AddRequestHeaders(szHeaders); pFile->SendRequest(); DWORD dwRet; pFile->QueryInfoStatusCode(dwRet); if (dwRet >= 400 && dwRet <= 499) { ODS(_T("XFILTER.EXE: Internet Request Error ...")); iRet = XERR_INTERNET_REQUEST_ERROR; } else if(dwRet >= 500 && dwRet <= 599) { ODS(_T("XFILTER.EXE: Internet Server Error ...")); iRet = XERR_INTERNET_SERVER_ERROR; } else if(sReturn != NULL) { pFile->ReadString(sReturn, MAX_NET_COMMAND_LENTH - 1); ODS(sReturn); CString tmpStr = sReturn; long lVer = atol(tmpStr.Left(MAX_NET_COMMAND_VERSION_LENTH)); if(lVer > *lVersion) { *lVersion = lVer; int i = 1; while (i < MAX_NET_COMMAND && pFile->ReadString((sReturn + MAX_NET_COMMAND_LENTH * i), MAX_NET_COMMAND_LENTH - 1)) { ODS(sReturn + i * MAX_NET_COMMAND_LENTH); i ++; } *Count = i; } else { *Count = 1; } } else { CString sRet; pFile->ReadString(sRet); if(sRet.GetAt(0) != '1') iRet = XERR_INTERNET_REG_ERROR; ODS2(_T("XFILTER.EXE: Internet User Register Return Value "),sRet); } pFile->Close(); pServer->Close(); } catch(CInternetException* pEx) { pEx->Delete(); iRet = XERR_INTERNET_CONNECT_ERROR; ODS(_T("XFILTER.EXE: GetFromUrl XERR_INTERNET_CONNECT_ERROR... ")); } if (pFile != NULL) delete pFile; if (pServer != NULL) delete pServer; session.Close(); m_IsConnecting = FALSE; ODS(_T("XFILTER.EXE: GetFromUrl End... ")); return iRet; }
void TimerInterrupt(void) { UINT16 wEntry_ms = 0; UINT16 wExit_ms = 0; UINT8 bActLoad = 0; UINT8 i; TOGGLE_PAD28; // get current last time TimerGetSys_msec(wEntry_ms); // !!! Re-Enable higher interrupts than this interrupt! // (for use of MilliSecCounter) INT_GLOB_ENABLE // ----------------------------------------- // increment internal system time gdwTicks++; // ----------------------------------------- // call all registered timer entry functions for( i = 0; i < gbFuncs; i++ ) { UINT16 wEntry_ms = 0; UINT16 wExit_ms = 0; EntryFunction pFn; TimerGetSys_msec(wEntry_ms); if( (pFn = gaEntryFunctions[i]) != NULL ) { (*pFn)(); // execute registered entry function } TimerGetSys_msec(wExit_ms); if ((wExit_ms - wEntry_ms) > WARN_TIMERLOAD_MS) ODS2( DBG_SYS, DBG_WARNING, "TimerEntryFct 0x%lx took %u ms!", pFn, (wExit_ms - wEntry_ms)); } // ----------------------------------------- // check for any expired message timer for( i = 0; i < gbLastTimer; i++ ) { if ( gaMessageQueueTimer[i].time == 0 ) { // try to post message with HIGH priority if ( MsgQPostMsg(gaMessageQueueTimer[i].msg, MSGQ_PRIO_HIGH) == ERR_OK ) { gbLastTimer--; gaMessageQueueTimer[i] = gaMessageQueueTimer[gbLastTimer]; } else { /* posting not successful, try again next time */ } } else { /* not expired, decrement time */ gaMessageQueueTimer[i].time--; } } // of checking timers // check last use of this isr TimerGetSys_msec(wExit_ms); // calculate processor load by this isr in percent // (should be about 10%) bActLoad = ((wExit_ms - wEntry_ms) * TICKS_PER_SECOND) / 10; // safe max load if (bActLoad > gbTimerInterruptLoad) gbTimerInterruptLoad = bActLoad; // 'out of echtzeit' warning: Load > 100% if (bActLoad >= 100) ODS1(DBG_SYS, DBG_WARNING, "TimerInterrupt overloaded! (Load: %d \x25)", bActLoad); }
/*********************************************************************** * FUNCTION: LEDSetNewState * DESCRIPTION: handles new led status of any led * PARAMETER: MESSAGE msg with all parameters * RETURN: error code * COMMENT: wOffTicks = 0 eq. 'permanent ON' * wOnTicks = 0 eq. 'permanent OFF' *********************************************************************** */ ERRCODE LEDSetNewState(MESSAGE GivenMsg) { MESSAGE NewMsg; ERRCODE RValue = ERR_OK; MESSAGE_ID MsgId; /* get parameters out of message */ LED_ENUMTYPE bLed = MSG_CHAR1(GivenMsg)&0x0f; /* lower nibble eq. led index */ LED_MODETYPE bMode = (MSG_CHAR1(GivenMsg)&0xf0) >> 4; /* higher nibble eq. led mode */; /* check parameters */ if ((bLed > LED3) || (bMode > LED_RED) ) { ODS2(DBG_SYS,DBG_ERROR,"MSG_LED_X with invalid parameter(s) (led:%d state:%d)", bLed, bMode); return ERR_PARAM_ERR; } /* analyze message: ON/OFF */ MsgId = MSG_ID(GivenMsg); /* get message id */ switch (MsgId) { case MSG_LED_SET: { /* save led timings */ rgLedTiming[bLed].wOnTicks = MSG_CHAR2(GivenMsg); rgLedTiming[bLed].wOffTicks = MSG_CHAR3(GivenMsg); /* directly switch led to advised mode (ON/OFF/GREEN/RED) */ LEDDrvSetLED(bLed, bMode); /* check led state for further messages */ if ( (bMode != LED_OFF) &&(rgLedTiming[bLed].wOffTicks > 0) ) { /* build msg to later switch OFF the red/green led */ MSG_BUILD_UINT8(NewMsg, MSG_LED_OFF, (bLed | (bMode<<4)), 0, 0); /* switch OFF after OnTime */ RValue = SetTimerMsg(NewMsg, rgLedTiming[bLed].wOnTicks); } } break; case MSG_LED_ON: { /* led has not been disabled (wOnTicks==0) inbetween? */ if (rgLedTiming[bLed].wOnTicks > 0) { /* switch on NOW! */ LEDDrvSetLED(bLed, bMode); /* permanent on? (wOffTicks==0) */ if (rgLedTiming[bLed].wOffTicks > 0) { /* build msg to later switch OFF the red/green led */ MSG_BUILD_UINT8(NewMsg, MSG_LED_OFF, (bLed | (bMode<<4)), 0, 0); /* switch OFF after OnTime */ RValue = SetTimerMsg(NewMsg, rgLedTiming[bLed].wOnTicks); } } } break; case (MSG_LED_OFF): { /* led has not been permanent enabled (wOffTicks==0) inbetween? */ if (rgLedTiming[bLed].wOffTicks > 0) { /* switch off NOW! */ LEDDrvSetLED(bLed, LED_OFF); /* permanent off? (wOnTicks==0) */ if (rgLedTiming[bLed].wOnTicks > 0) { /* build msg to later switch ON the red/green led */ MSG_BUILD_UINT8(NewMsg, MSG_LED_ON, (bLed | (bMode<<4)), 0, 0); /* switch ON after OffTime */ RValue = SetTimerMsg(NewMsg, rgLedTiming[bLed].wOffTicks); } } } break; default: break; } if (RValue != ERR_OK) ODS(DBG_SYS,DBG_ERROR,"Unable to send new MSG_LED_ON/OFF!"); return RValue; }