Test
Dependencies: mbed-dev-OS5_10_4
Diff: Main/main.cpp
- Revision:
- 0:014fad4dfb9d
diff -r 000000000000 -r 014fad4dfb9d Main/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main/main.cpp Fri Aug 07 07:24:21 2020 +0000 @@ -0,0 +1,322 @@ +/*------------------------------------------------------------------------------- +Programm Name: Main.C +Version: 1.0 +Sprache: C++ +Compiler: mbed +Autor: PS +Copyright: PS + + +Funktion: Main Funktionen +04.08.2016: Projekt: EcmComFrdm +-------------------------------------------------------------------------------*/ +#include "Headers.h" + +// #define Ad0IsRdyDown() (LPC_GPIO0->FIOCLR & 0x000800000) +// #define Ad1IsRdyDown() (LPC_GPIO0->FIOCLR & 0x001000000) + +//const char* MyIp = "192.168.2.99"; +//const char* HostIp = "192.168.2.8"; +//const char* MySub = "255.255.255.0"; +//const char* MyGw = "0.0.0.0"; + + + +/*------------------------------------------------------------------------------- +Main Funktion. +-------------------------------------------------------------------------------*/ +int main() +{ + + InitMain(); + ConnectIrq(); + g_fDisableDataRead = false; +// Ad7739Start(0, 0,1); +// MVars.m_fMessDlgOpened = true; + MVars.nAktMittelAfter = 500; + while (true) + { + CheckAnalogIn(); + + if(nMyTimer > 0) // Scanner Verarbeitung + { + CheckTimerHandlingAndScanner(); + } +/* + if(g_nChn1Counter > 1000) + { + printf("%c#DG#Channel 1 Counter: %ld %c\n", STX, g_nChn1Counter, ETX); + g_nChn1Counter = 0; + } + else if(g_nChn2Counter > 1000) + { + printf("%c#DG#Channel 2 Counter: %ld %c\n", STX, g_nChn2Counter, ETX); + g_nChn2Counter = 0; + } +*/ + if(HostIf.nInTel > 0) + CheckCommInterface(); + + CheckEcmWinConnect(); + +#ifdef TOUCH_DISPLAY + CheckEvent(); // TFT Event +#endif +#ifdef DO_AUTO_START + if(g_fDoAutostart == true) + g_fDoAutostart = CheckAutoStart(); // kommt false zurueck, dann wird der Aufruf beendet +#endif + CheckZustand(); // Zustand der Messung + } + +} +/*------------------------------------------------------------------------------- + Funktion CheckCommInterface prüft ob ueber die Kommunikationsschnittstelle + eine Anforderung kommt. +-------------------------------------------------------------------------------*/ +int CheckCommInterface() +{ + if(TransferSioTel() == true) + { +// ChangeLedColor(); +// printf("%c#DG#HostIf.strTelAwBuf: %s%c\r\n",STX, HostIf.strTelAwBuf, ETX); + CheckTel(); + } + return(true); +} +/*------------------------------------------------------------------------------- + Funktion CheckEcmWinConnect: Bearbeitet alle Methoden die mit der Messung ueber + EcmWin zu tun haben. +-------------------------------------------------------------------------------*/ +int CheckEcmWinConnect() +{ + if(!MVars.m_fMessDlgOpened) + { + g_nChn2Counter++; + if(g_nChn2Counter > 50000) + { +// printf("%c#DG#Channel 2 Counter: %ld %c\n", STX, g_nChn2Counter, ETX); + ChangeLedColor(); + g_nChn2Counter = 0; + } + } + + if(MVars.m_fMessDlgOpened) + { +// ReadAllAdChannels(); + if(MVars.nMittelTimer >= MVars.nAktMittelAfter) + { + CheckDaAd(); + MVars.nMittelTimer -= MVars.nAktMittelAfter; + ChangeLedColor(); + } + CheckZustand(); + } +#ifdef DO_AUTO_START + else if(m_fAutoStart == true) // ist in der Autostart Funktion + { + if(MVars.nMittelTimer >= MVars.nAktMittelAfter) // nAktMittelAfter muss ueber die Sequenz neu gestzt werden + { + if(CheckDaAd() == false) + { + DisableAutoMode(); + } + MVars.nMittelTimer -= MVars.nAktMittelAfter; + ChangeLedColor(); + } + if (g_nTftTimer >= 1000) + { + RequestDateTime(); + g_nTftTimer = 0; + if(m_fAutoStart == true) + DoStatusLed = !DoStatusLed; + } + } +#endif + else + { + if (g_nTftTimer >= 1000) + { +// RequestDateTime(); + g_nTftTimer = 0; + } + } + return(true); +} + +/*------------------------------------------------------------------------------- + DoReInit: Initialisieren des AD Wandlers +-------------------------------------------------------------------------------*/ +int DoReInit() +{ + uint8_t Status0, Status1; +// DigitalOut Test(PTC16); +#ifdef TFT_DEBUG + printf("DOR_C: %08X DIR_C: %08X DDR_C:%08X \r\n", GPIOC->PDOR, GPIOC->PDIR, GPIOC->PDDR); // PTC 16 auf Output schalten +#endif + +// GPIOC->PDDR |= 0x00010000; // PTC 16 auf Output schalten + + MVars.fAdReInit = false; + MVars.m_nSendValues = 1; // fängt an, in Grundstellung zu senden + g_fRdy0 = false; g_fRdy1 = false; + +// ConnectIrq(); + g_fDisableDataRead = false; + Ad7739Start(0, 0,1); // 0=Kanal mit dem begonnen wird, Wandler 0, Mode +// Ad7739CommonStart(0, 1); + + nMyTimer = 0; + g_nAdSetPos = 0; g_nAdGetPos = 0; + g_nAdCount = 0; + MVars.m_nSendValues = 1; // fängt an, in Grundstellung zu senden + ZustandsTimer = 0; + + return(true); +} +/*------------------------------------------------------------------------------- + Funktion CheckZustand prüft alle eingehenden Telegramme auf Inhalt und Befehl +-------------------------------------------------------------------------------*/ +int CheckZustand() +{ + + if(MVars.fAdReInit == true) + { + MVars.fAdReInit = false; + DoReInit(); + } + + if(MVars.m_nSendValues == 0) // nichts senden + { + nMyTimer = 0; + ZustandsTimer = 0; + return(0); + } + +// MVars.dbAdSum[0] += (long double)AdcHs1.read_u16(); +// MVars.dbAdSum[1] += (long double)AdcHs2.read_u16(); +// MVars.nMwMittelCount++; +#ifdef TFT_DEBUG +// printf("AdResult_0: %f \n",MVars.dbAdSum[0]); +#endif +// g_nAdGetPos++; g_nAdGetPos &= 0x3FF; + + +// AdVal->AdRingBuf[0][g_nAdSetPos] = AdcHs1.read_u16(); +// AdVal->AdRingBuf[1][g_nAdSetPos] = AdcHs2.read_u16(); +// g_nAdSetPos++; g_nAdSetPos &= 0x03FF; +// g_nAdCount++; + + +// CheckDaAd(); + + if(ZustandsTimer >= 100) // die Zustände werden dadurch alle 100ms überprüft + { + MVars.nSecCounter[0] += 100; + IrComp.n100msCounter++; + ZustandsTimer -= 100; + + if(MVars.m_nSendValues == 1) // senden in Grundstellung + { + CheckGrundZustand(); + } + else if(MVars.m_nSendValues == 2) // senden während Messung + { + CheckRunZustand(); + } + } + + return(0); +} + +/*------------------------------------------------------------------------------- + CheckGrundZustand: +-------------------------------------------------------------------------------*/ +int CheckGrundZustand() +{ + MVars.m_fDisableStopTel = false; + return(true); +} +/*------------------------------------------------------------------------------- + CheckRunZustand: +-------------------------------------------------------------------------------*/ +int CheckRunZustand() +{ + + switch(MVars.nMessZustand[0]) + { + case -1: + break; + case 0: + break; + case 1: + break; + case 2: + MVars.nSecCounter[0] = 0; + break; + case 3: + break; + case 4: + break; + case 5: + if(MPara.RpDauerNach[0] > 0) + { + if(MVars.nSecCounter[0] >= 1000) + { + MVars.nSecCounter[0] -= 1000; + MPara.RpDauerNach[0]--; + } + } + else + { + MVars.m_fDoFinishMeasurement = true; + MVars.m_fDisableStopTel = true; + } + break; + case 6: // schickt nur kontinuierlich die Werte + break; + default: + break; + + } + if(MVars.m_fDoFinishMeasurement == true) // wird von Stopkommando aus EcmTel gesetzt + { + MVars.m_fDoFinishMeasurement = false; + MVars.m_fFinishMeasurement = true; + MVars.m_fScan = false; +#ifdef SIO_DEBUG + printf("MessZustand: %d \n",MVars.nMessZustand[0]); + printf("SwOCP:%d\n",MVars.SwitchChn[0]); +#endif + + } + return(true); +} +/*------------------------------------------------------------------------------- +ChangeConversionTime: Im Fall dass die Wandlungszeit geändert werden muss +-------------------------------------------------------------------------------*/ +void ChangeConversionTime() +{ + MVars.fChangeCt = false; + SetAdConversionTime(); +// wait(0.2); +// led1 = !led1; +} +/*------------------------------------------------------------------------------- +SendMessungStart: Startet die Messung +-------------------------------------------------------------------------------*/ +int SendMessungStart() +{ + sprintf(HostIf.strTempBuf,"%c#MG#%c", STX, ETX); + SendTelToHost(false, false, false); + return(0); +} +/*------------------------------------------------------------------------------- +SendMessungStop: Stoppt die Messung +-------------------------------------------------------------------------------*/ +int SendMessungStop() +{ + sprintf(HostIf.strTempBuf,"%c#MS#%c", STX, ETX); + SendTelToHost(false, false, false); + return(0); +}