# HG changeset patch # User Ideenmodellierer # Date 1730644984 -3600 # Node ID c0553dd706084b909c54ba57b004ad41e1897344 # Parent f72613a152dd4851f2413a631b09b433fd80b73f GNSS support for external UART interface: An ubox gps module may now be connected to the external UART. Per default the functionality is disabled using the compile switch ENABLE_GNSS_SUPPORT diff -r f72613a152dd -r c0553dd70608 Small_CPU/Inc/uartProtocol_GNSS.h --- a/Small_CPU/Inc/uartProtocol_GNSS.h Sun Nov 03 15:40:55 2024 +0100 +++ b/Small_CPU/Inc/uartProtocol_GNSS.h Sun Nov 03 15:43:04 2024 +0100 @@ -33,23 +33,47 @@ typedef enum { - UART_GNSS_INIT = 0, /* Default Status for every sensor type */ - UART_GNSS_LOAD, /* Load modul configuration */ - UART_GNSS_GET_ID, /* get unique module ID */ - UART_GNSS_IDLE, /* sensor detected and no communication pending */ - UART_GNSS_ERROR, - UART_GNSS_OPERATING, /* normal operation => cyclic request of PVT data */ + UART_GNSS_INIT = 0, /* Default Status for every sensor type */ + UART_GNSS_IDLE, /* sensor detected and no communication pending */ + UART_GNSS_ERROR, /* Error message received from sensor */ + UART_GNSS_WARMUP = 10, + UART_GNSS_LOADCONF_0, + UART_GNSS_LOADCONF_1, + UART_GNSS_LOADCONF_2, + UART_GNSS_GET_PVT, } uartGnssStatus_t; typedef enum { GNSSRX_READY = 0, /* Initial state */ - GNSSRX_RECEIVING, /* Pending data receiption */ + GNSSRX_DETECT_HEADER_0, + GNSSRX_DETECT_HEADER_1, + GNSSRX_DETECT_HEADER_2, + GNSSRX_DETECT_HEADER_3, + GNSSRX_DETECT_ACK_0, + GNSSRX_DETECT_ACK_1, + GNSSRX_DETECT_ACK_2, + GNSSRX_DETECT_ACK_3, + GNSSRX_READ_NAV_DATA, + GNSSRX_READ_PVT_DATA, + GNSSRX_READ_POSLLH_DATA } receiveStateGnss_t; + typedef enum + { + GNSSCMD_LOADCONF_0 = 0, + GNSSCMD_LOADCONF_1, + GNSSCMD_LOADCONF_2, + GNSSCMD_GET_NAV_DATA, + GNSSCMD_GET_PVT_DATA, + GNSSCMD_GET_POSLLH_DATA + } gnssSensorCmd_t; + + void uartGnss_Control(void); -void uartGnss_ProcessData(void); -uint8_t uartSentinel_isSensorConnected(); +void uartGnss_ProcessData(uint8_t data); +uint8_t uartGnss_isSensorConnected(); +void uartGnss_SendCmd(uint8_t GnssCmd); #endif /* UART_PROTOCOL_GNSS_H */ diff -r f72613a152dd -r c0553dd70608 Small_CPU/Src/GNSS.c --- a/Small_CPU/Src/GNSS.c Sun Nov 03 15:40:55 2024 +0100 +++ b/Small_CPU/Src/GNSS.c Sun Nov 03 15:43:04 2024 +0100 @@ -171,6 +171,9 @@ * @param GNSS Pointer to main GNSS structure. */ void GNSS_ParsePVTData(GNSS_StateHandle *GNSS) { + + static float searchCnt = 1.0; + uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[10]; GNSS->yearBytes[0]=GNSS_Handle.uartWorkingBuffer[10]; uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[11]; @@ -226,6 +229,11 @@ iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 70]; } GNSS->headMot = iLong.iLong * 1e-5; // todo I'm not sure this good options. + + if((GNSS->fLat == 0.0) && (GNSS->fLon == 0.0)) + { + GNSS->fLat = searchCnt++; + } } /*! diff -r f72613a152dd -r c0553dd70608 Small_CPU/Src/scheduler.c --- a/Small_CPU/Src/scheduler.c Sun Nov 03 15:40:55 2024 +0100 +++ b/Small_CPU/Src/scheduler.c Sun Nov 03 15:43:04 2024 +0100 @@ -882,7 +882,9 @@ uartGnss_ProcessData(); uartGnss_Control(); #endif +#ifdef ENABLE_GNSS_SUPPORT copyGNSSdata(); +#endif Scheduler.counterAmbientLight100msec++; } @@ -1745,19 +1747,8 @@ void copyGNSSdata(void) { -#ifdef ENABLE_GNSS global.dataSendToMaster.data[0].fLat = GNSS_Handle.fLat; global.dataSendToMaster.data[0].fLon = GNSS_Handle.fLon; -#else - static float tmpLon = 0.0; - static float tmpLat= 100.0; - global.dataSendToMaster.data[0].fLat = tmpLat; - global.dataSendToMaster.data[0].fLon = tmpLon; - tmpLon += 0.15; - if(tmpLon > 360.0) tmpLon = 0.0; - tmpLat += 0.33; - if(tmpLat > 360.0) tmpLat = 0.0; -#endif } diff -r f72613a152dd -r c0553dd70608 Small_CPU/Src/uartProtocol_Co2.c --- a/Small_CPU/Src/uartProtocol_Co2.c Sun Nov 03 15:40:55 2024 +0100 +++ b/Small_CPU/Src/uartProtocol_Co2.c Sun Nov 03 15:43:04 2024 +0100 @@ -84,6 +84,7 @@ { CO2Connected = 0; externalInterface_SetCO2Scale(0.0); + UART_clearRxBuffer(); UART_StartDMA_Receiption(); localComState = UART_CO2_SETUP; } diff -r f72613a152dd -r c0553dd70608 Small_CPU/Src/uartProtocol_GNSS.c --- a/Small_CPU/Src/uartProtocol_GNSS.c Sun Nov 03 15:40:55 2024 +0100 +++ b/Small_CPU/Src/uartProtocol_GNSS.c Sun Nov 03 15:43:04 2024 +0100 @@ -24,11 +24,17 @@ #include #include "uart.h" #include "GNSS.h" +#include "configuration.h" +#include "externalInterface.h" -#ifdef ENABLE_GNSS +#if defined ENABLE_GNSS || defined ENABLE_GNSS_SUPPORT -static uartGnssStatus_t gnssOpState = UART_GNSS_INIT; static receiveStateGnss_t rxState = GNSSRX_READY; +static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ + +static uint8_t writeIndex = 0; + +static uint8_t dataToRead = 0; void ConvertByteToHexString(uint8_t byte, char* str) { @@ -53,61 +59,181 @@ } } + +void uartGnss_SendCmd(uint8_t GnssCmd) +{ + uint8_t* pData; + uint8_t txLength = 0; + + switch (GnssCmd) + { + case GNSSCMD_LOADCONF_0: pData = configUBX; + txLength = sizeof(configUBX) / sizeof(uint8_t); + break; + case GNSSCMD_LOADCONF_1: pData = setNMEA410; + txLength = sizeof(setNMEA410) / sizeof(uint8_t); + break; + case GNSSCMD_LOADCONF_2: pData = setGNSS; + txLength = sizeof(setGNSS) / sizeof(uint8_t); + break; + case GNSSCMD_GET_PVT_DATA: pData = getPVTData; + txLength = sizeof(getPVTData) / sizeof(uint8_t); + break; + case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData; + txLength = sizeof(getNavigatorData) / sizeof(uint8_t); + break; + + default: + break; + } + if(txLength != 0) + { + UART_SendCmdUbx(pData, txLength); + } +} + void uartGnss_Control(void) { - static uint32_t delayStartTick = 0; + static uint32_t warmupTick = 0; - uint32_t tick = HAL_GetTick(); + uint8_t activeSensor = externalInterface_GetActiveUartSensor(); + uartGnssStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); - switch (gnssOpState) + switch (localComState) { - case UART_GNSS_INIT: delayStartTick = tick; - gnssOpState = UART_GNSS_LOAD; + case UART_GNSS_INIT: localComState = UART_GNSS_WARMUP; + warmupTick = HAL_GetTick(); + UART_clearRxBuffer(); break; - case UART_GNSS_LOAD: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 1000) - { - GNSS_LoadConfig(&GNSS_Handle); - gnssOpState = UART_GNSS_GET_ID; - delayStartTick = tick; - } + case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000) + { + localComState = UART_GNSS_LOADCONF_0; + } break; - case UART_GNSS_GET_ID: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 250) - { - GNSS_GetUniqID(&GNSS_Handle); - gnssOpState = UART_GNSS_IDLE; - rxState = GNSSRX_RECEIVING; - delayStartTick = tick; - } + case UART_GNSS_LOADCONF_0: uartGnss_SendCmd(GNSSCMD_LOADCONF_0); + localComState = UART_GNSS_LOADCONF_1; + rxState = GNSSRX_DETECT_ACK_0; + break; + case UART_GNSS_LOADCONF_1: uartGnss_SendCmd(GNSSCMD_LOADCONF_1); + localComState = UART_GNSS_LOADCONF_2; + rxState = GNSSRX_DETECT_ACK_0; break; - case UART_GNSS_IDLE: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 1000) - { - GNSS_GetPVTData(&GNSS_Handle); - gnssOpState = UART_GNSS_OPERATING; - rxState = GNSSRX_RECEIVING; - delayStartTick = tick; - } + case UART_GNSS_LOADCONF_2: uartGnss_SendCmd(GNSSCMD_LOADCONF_2); + localComState = UART_GNSS_IDLE; + rxState = GNSSRX_DETECT_ACK_0; break; - case UART_GNSS_OPERATING: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 1000) - { - gnssOpState = UART_GNSS_IDLE; /* simple error handling => start next request */ - rxState = GNSSRX_READY; - } + case UART_GNSS_IDLE: uartGnss_SendCmd(GNSSCMD_GET_PVT_DATA); + localComState = UART_GNSS_GET_PVT; + rxState = GNSSRX_DETECT_HEADER_0; break; default: break; } + + externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState); + } -void uartGnss_ProcessData(void) +void uartGnss_ProcessData(uint8_t data) { - if(rxState == GNSSRX_RECEIVING) + uint8_t activeSensor = externalInterface_GetActiveUartSensor(); + GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; + switch(rxState) { - if(GNSS_ParseBuffer(&GNSS_Handle)) - { - gnssOpState = UART_GNSS_IDLE; - } + case GNSSRX_DETECT_ACK_0: + case GNSSRX_DETECT_HEADER_0: if(data == 0xB5) + { + writeIndex = 0; + memset(GNSS_Handle.uartWorkingBuffer,0, sizeof(GNSS_Handle.uartWorkingBuffer)); + GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; + rxState++; + } + break; + case GNSSRX_DETECT_ACK_1: + case GNSSRX_DETECT_HEADER_1: if(data == 0x62) + { + rxState++; + } + else + { + rxState = GNSSRX_DETECT_HEADER_0; + } + break; + case GNSSRX_DETECT_ACK_2: if(data == 0x05) + { + rxState++; + } + else + { + rxState = GNSSRX_DETECT_HEADER_0; + } + break; + case GNSSRX_DETECT_ACK_3: if((data == 0x01) || (data == 0x00)) + { + GnssConnected = 1; + rxState = GNSSRX_READY; + } + else + { + rxState = GNSSRX_DETECT_HEADER_0; + } + break; + case GNSSRX_DETECT_HEADER_2: if(data == 0x01) + { + rxState++; + } + else + { + rxState = GNSSRX_DETECT_HEADER_0; + } + break; + case GNSSRX_DETECT_HEADER_3: + switch(data) + { + case 0x21: rxState = GNSSRX_READ_NAV_DATA; + dataToRead = 20; + break; + case 0x07: rxState = GNSSRX_READ_PVT_DATA; + dataToRead = 92; + break; + case 0x02: rxState = GNSSRX_READ_POSLLH_DATA; + break; + default: rxState = GNSSRX_DETECT_HEADER_0; + break; + } + break; + case GNSSRX_READ_NAV_DATA: + case GNSSRX_READ_PVT_DATA: + case GNSSRX_READ_POSLLH_DATA: if(dataToRead > 0) + { + dataToRead--; + } + else + { + switch(rxState) + { + case GNSSRX_READ_NAV_DATA: GNSS_ParseNavigatorData(&GNSS_Handle); + break; + case GNSSRX_READ_PVT_DATA: GNSS_ParsePVTData(&GNSS_Handle); + break; + case GNSSRX_READ_POSLLH_DATA: GNSS_ParsePOSLLHData(&GNSS_Handle); + break; + default: rxState = GNSSRX_DETECT_HEADER_0; + break; + } + rxState = GNSSRX_DETECT_HEADER_0; + externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,UART_GNSS_IDLE); + } + break; + default: rxState = GNSSRX_READY; + break; } } +uint8_t uartGnss_isSensorConnected() +{ + return GnssConnected; +} + #endif