Mercurial > public > ostc4
comparison Small_CPU/Src/uartProtocol_HUD.c @ 1077:bd8ab302ef4a Icon_Integration
Added uart support for HUD:
the protocol implementation for the HUD has been added. It may be activated by the compile switch ENABLE_HUD_SUPPORT. Because the HUD will not mapped to the three classic o2 value display slots, the sensor data structure has been increased to the max number of devices => all devices may now raise device specific data.
| author | Ideenmodellierer |
|---|---|
| date | Mon, 02 Mar 2026 17:22:25 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1076:c87753e73eb8 | 1077:bd8ab302ef4a |
|---|---|
| 1 /** | |
| 2 ****************************************************************************** | |
| 3 * @file uartProtocol_HUD.c | |
| 4 * @author heinrichs weikamp gmbh | |
| 5 * @version V0.0.1 | |
| 6 * @date 24-Feb-2026 | |
| 7 * @brief Interface functionality to external, UART based HUD | |
| 8 * | |
| 9 @verbatim | |
| 10 | |
| 11 | |
| 12 @endverbatim | |
| 13 ****************************************************************************** | |
| 14 * @attention | |
| 15 * | |
| 16 * <h2><center>© COPYRIGHT(c) 2023 heinrichs weikamp</center></h2> | |
| 17 * | |
| 18 ****************************************************************************** | |
| 19 */ | |
| 20 /* Includes ------------------------------------------------------------------*/ | |
| 21 | |
| 22 #include <string.h> | |
| 23 #include <uartProtocol_HUD.h> | |
| 24 #include "uart.h" | |
| 25 #include "externalInterface.h" | |
| 26 | |
| 27 #ifdef ENABLE_HUD_SUPPORT | |
| 28 static uint8_t HUDConnected = 0; /* Binary indicator if a sensor is connected or not */ | |
| 29 static receiveStateHUD_t rxState = HUDRX_Ready; | |
| 30 | |
| 31 | |
| 32 | |
| 33 void uartHUD_SendCmd(uint8_t HUDCmd) | |
| 34 { | |
| 35 uint8_t cmdLength = 0; | |
| 36 uint8_t cmdBuf[HUD_MAX_CMD_LENGTH]; | |
| 37 uint8_t index = 0; | |
| 38 uint16_t checkSum = 0; | |
| 39 | |
| 40 cmdBuf[0] = HUD_CMD_BYTE_START; | |
| 41 switch (HUDCmd) | |
| 42 { | |
| 43 case HUDCMD_GETINFO: cmdBuf[1] = HUD_CMD_BYTE_INFO; | |
| 44 cmdLength = 1; | |
| 45 break; | |
| 46 case HUDCMD_UPDATE: cmdBuf[1] = HUD_CMD_BYTE_UPDATE; | |
| 47 externalInterface_GetHUDSequence(&cmdBuf[3],&cmdBuf[2]); | |
| 48 cmdLength = 19; | |
| 49 break; | |
| 50 case HUDCMD_ABORTSEQ: cmdBuf[1] = HUD_CMD_BYTE_STOP; | |
| 51 cmdLength = 1; | |
| 52 break; | |
| 53 default: cmdLength = 0; | |
| 54 break; | |
| 55 } | |
| 56 if(cmdLength != 0) | |
| 57 { | |
| 58 cmdLength++; /* add Startbyte */ | |
| 59 for(index = 0; index < cmdLength; index++) | |
| 60 { | |
| 61 if(index > 2) /* hard coded number of pulses = 2 */ | |
| 62 { | |
| 63 cmdBuf[index] |= 0x10; | |
| 64 } | |
| 65 checkSum += cmdBuf[index]; | |
| 66 } | |
| 67 cmdBuf[cmdLength++] = (checkSum & 0x00FF); /* low byte */ | |
| 68 cmdBuf[cmdLength++] = (checkSum >> 8); /* high byte */ | |
| 69 UART_SendCmdRaw(cmdBuf,cmdLength); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 | |
| 74 void uartHUD_Control(void) | |
| 75 { | |
| 76 static uint8_t cmdString[20]; | |
| 77 static uint8_t cmdLength = 0; | |
| 78 static uint8_t lastComState = UART_HUD_INIT; | |
| 79 | |
| 80 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); | |
| 81 uartHUDStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); | |
| 82 | |
| 83 if(localComState == UART_HUD_ERROR) | |
| 84 { | |
| 85 localComState = lastComState; | |
| 86 } | |
| 87 | |
| 88 switch(localComState) | |
| 89 { | |
| 90 case UART_HUD_INIT: HUDConnected = 0; | |
| 91 UART_ReadData(SENSOR_HUD, 1); /* flush buffer */ | |
| 92 UART_StartDMA_Receiption(&Uart1Ctrl); | |
| 93 localComState = UART_HUD_SETUP; | |
| 94 uartHUD_SendCmd(HUDCMD_GETINFO); | |
| 95 break; | |
| 96 case UART_HUD_SETUP: uartHUD_SendCmd(HUDCMD_GETINFO); | |
| 97 rxState = HUDRX_DetectStart; | |
| 98 break; | |
| 99 case UART_HUD_UPDATE: uartHUD_SendCmd(HUDCMD_UPDATE); | |
| 100 rxState = HUDRX_Ready; | |
| 101 break; | |
| 102 case UART_HUD_ABORT: uartHUD_SendCmd(HUDCMD_ABORTSEQ); | |
| 103 rxState = HUDRX_Ready; | |
| 104 break; | |
| 105 default: if(cmdLength != 0) | |
| 106 { | |
| 107 UART_SendCmdString(cmdString); /* resend last command */ | |
| 108 cmdLength = 0; | |
| 109 } | |
| 110 break; | |
| 111 } | |
| 112 lastComState = localComState; | |
| 113 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState); | |
| 114 } | |
| 115 | |
| 116 void uartHUD_ProcessData(uint8_t data) | |
| 117 { | |
| 118 static uint8_t dataValue[HUD_INFO_DATA_LENGTH]; | |
| 119 static uint8_t dataIndex = 0; | |
| 120 static uint16_t checkSum = 0; | |
| 121 static uint16_t rxCheckSum = 0; | |
| 122 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); | |
| 123 uartHUDStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); | |
| 124 | |
| 125 if((localComState == UART_HUD_SETUP) && (rxState == HUDRX_Ready)) | |
| 126 { | |
| 127 rxState = HUDRX_DetectStart; | |
| 128 } | |
| 129 switch(rxState) | |
| 130 { | |
| 131 case HUDRX_DetectStart: if(data == 0xAA) | |
| 132 { | |
| 133 dataIndex = 0; | |
| 134 memset(dataValue,0,HUD_INFO_DATA_LENGTH); | |
| 135 dataValue[dataIndex++] = data; | |
| 136 checkSum = data; | |
| 137 rxState = HUDRX_RXData; | |
| 138 } | |
| 139 break; | |
| 140 case HUDRX_RXData: dataValue[dataIndex++] = data; | |
| 141 checkSum += data; | |
| 142 if(dataIndex == HUD_INFO_DATA_LENGTH) | |
| 143 { | |
| 144 rxState = HUDRX_CheckSum_L; | |
| 145 } | |
| 146 break; | |
| 147 case HUDRX_CheckSum_L: rxCheckSum = data; | |
| 148 rxState++; | |
| 149 break; | |
| 150 case HUDRX_CheckSum_H: rxCheckSum |= (data << 8); | |
| 151 if(checkSum == rxCheckSum) | |
| 152 { | |
| 153 HUDConnected = 1; | |
| 154 if(localComState == UART_HUD_SETUP) | |
| 155 { | |
| 156 externalInterface_SetSensorData(activeSensor + EXT_INTERFACE_MUX_OFFSET, &dataValue[1]); | |
| 157 localComState = UART_HUD_ABORT; /* reset default sequence */ | |
| 158 } | |
| 159 } | |
| 160 rxState = HUDRX_DetectStart; | |
| 161 break; | |
| 162 default: if(data == 'K') /* OK respond from HUD */ | |
| 163 { | |
| 164 localComState = UART_HUD_IDLE; | |
| 165 } | |
| 166 if(data == 'N') /* NOK respond from HUD */ | |
| 167 { | |
| 168 localComState = UART_HUD_ERROR; | |
| 169 } | |
| 170 if(data == 0xff) | |
| 171 { | |
| 172 localComState = UART_HUD_IDLE; | |
| 173 } | |
| 174 break; | |
| 175 } | |
| 176 | |
| 177 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState); | |
| 178 } | |
| 179 | |
| 180 uint8_t uartHUD_isSensorConnected() | |
| 181 { | |
| 182 return HUDConnected; | |
| 183 } | |
| 184 | |
| 185 #endif | |
| 186 |
