annotate Small_CPU/Src/uart.c @ 795:d4083ac09b5d

Moved DiveO2 sensor specific funtionality into separated file: Having the protocol functions of all sensors within one file made the code hard to ready and created aa risk of interference between the protocols. In furture every (new) sensor should be maintained in its own source file. The ols UART.c does only contain the function which are used by all UART protocols (common functions).
author Ideenmodellierer
date Mon, 31 Jul 2023 19:50:36 +0200
parents bb37d4f3e50e
children e9eba334b942
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file uart.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 27-March-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief button control
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ##### How to use #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 #include "uart.h"
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
23 #include "uartProtocol_O2.h"
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
24 #include "externalInterface.h"
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
25 #include "data_exchange.h"
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
26 #include <string.h> /* memset */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
30
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
31
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
32 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
33 #define CHUNKS_PER_BUFFER (5u)
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
34
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
35 UART_HandleTypeDef huart1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
36
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
37 DMA_HandleTypeDef hdma_usart1_rx;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
39 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
40 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
41 static uint8_t rxReadIndex; /* Index at which new data is stared */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
42 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
43 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
44
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
45 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
46 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
48
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
49
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
50 static uartCO2Status_t ComStatus_CO2 = UART_CO2_INIT;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
51
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
52 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
53 float LED_ZeroOffset = 0.0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
54 float pCO2 = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
57
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
58
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
59 //huart.Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), new_baudrate);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
60
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
61 void MX_USART1_UART_Init(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
63 /* regular init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
64
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
65 huart1.Instance = USART1;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
66
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
67 if(externalInterface_GetUARTProtocol() == 0x04)
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
68 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
69 huart1.Init.BaudRate = 19200;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
70 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
71 else
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
72 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
73 huart1.Init.BaudRate = 9600;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
74 ComStatus_CO2 = UART_CO2_INIT;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
75 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
76 huart1.Init.WordLength = UART_WORDLENGTH_8B;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
77 huart1.Init.StopBits = UART_STOPBITS_1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
78 huart1.Init.Parity = UART_PARITY_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
79 huart1.Init.Mode = UART_MODE_TX_RX;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
80 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
81 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
82
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
83 HAL_UART_Init(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
84
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
85 MX_USART1_DMA_Init();
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
86
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
87 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer));
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
88 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
89 lastCmdIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
90 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
91 dmaActive = 0;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
92
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
93 CO2Connected = 0;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
94 SentinelConnected = 0;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
95
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
96 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
98 void MX_USART1_UART_DeInit(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
99 {
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
100 HAL_DMA_Abort(&hdma_usart1_rx);
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
101 HAL_DMA_DeInit(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
102 HAL_UART_DeInit(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
103 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
104
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
105 void MX_USART1_DMA_Init()
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
106 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
107 /* DMA controller clock enable */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
108 __DMA2_CLK_ENABLE();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
109
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
110 /* Peripheral DMA init*/
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
111 hdma_usart1_rx.Instance = DMA2_Stream5;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
112 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
113 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
114 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
115 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
116 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
117 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
118 hdma_usart1_rx.Init.Mode = DMA_NORMAL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
119 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
120 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
121 HAL_DMA_Init(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
122
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
123 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
124
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
125 /* DMA interrupt init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
126 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
127 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
130 void UART_MUX_SelectAddress(uint8_t muxAddress)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
131 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
132 uint8_t indexstr[4];
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
133
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
134 if(muxAddress <= MAX_MUX_CHANNEL)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
135 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
136 indexstr[0] = '~';
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
137 indexstr[1] = muxAddress;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
138 indexstr[2] = 0x0D;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
139 indexstr[3] = 0x0A;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
140
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
141 HAL_UART_Transmit(&huart1,indexstr,4,10);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
142 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
143 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
144
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
145
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
146 void UART_SendCmdString(uint8_t *cmdString)
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
147 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
148 uint8_t cmdLength = strlen((char*)cmdString);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
149
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
150 if(cmdLength < 20) /* A longer string is an indication for a missing 0 termination */
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
151 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
152 if(dmaActive == 0)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
153 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
154 UART_StartDMA_Receiption();
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
155 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
156 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
157 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
158 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
159
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
160 void DigitalCO2_SendCmd(uint8_t CO2Cmd, uint8_t *cmdString, uint16_t *cmdLength)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
161 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
162 switch (CO2Cmd)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
163 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
164 case CO2CMD_MODE_POLL: *cmdLength = snprintf((char*)cmdString, 10, "K 2\r\n");
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
165 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
166 case CO2CMD_MODE_STREAM: *cmdLength = snprintf((char*)cmdString, 10, "K 1\r\n");
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
167 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
168 case CO2CMD_CALIBRATE: *cmdLength = snprintf((char*)cmdString, 10, "G\r\n");
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
169 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
170 case CO2CMD_GETDATA: *cmdLength = snprintf((char*)cmdString, 10, "Q\r\n");
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
171 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
172 case CO2CMD_GETSCALE: *cmdLength = snprintf((char*)cmdString, 10, ".\r\n");
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
173 break;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
174 default: *cmdLength = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
175 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
176 }
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
177 if(cmdLength != 0)
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
178 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
179 HAL_UART_Transmit(&huart1,cmdString,*cmdLength,10);
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
180 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
181 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
182
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
183 void StringToInt(char *pstr, uint32_t *puInt32)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
184 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
185 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
186 uint32_t result = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
187 while((pstr[index] >= '0') && (pstr[index] <= '9'))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
188 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
189 result *=10;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
190 result += pstr[index] - '0';
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
191 index++;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
192 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
193 *puInt32 = result;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
194 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
195
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
196 void StringToUInt64(char *pstr, uint64_t *puint64)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
197 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
198 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
199 uint64_t result = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
200 while((pstr[index] >= '0') && (pstr[index] <= '9'))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
201 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
202 result *=10;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
203 result += pstr[index] - '0';
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
204 index++;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
205 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
206 *puint64 = result;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
207 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
208 void ConvertByteToHexString(uint8_t byte, char* str)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
209 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
210 uint8_t worker = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
211 uint8_t digit = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
212 uint8_t digitCnt = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
214 worker = byte;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
215 while((worker!=0) && (digitCnt != 255))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
216 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
217 digit = worker % 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
218 if( digit < 10)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
219 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
220 digit += '0';
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
221 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
222 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
223 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
224 digit += 'A' - 10;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
225 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
226 str[digitCnt--]= digit;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
227 worker = worker / 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
228 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
229 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
230
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
231 void UART_StartDMA_Receiption()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
232 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
233 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
234 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
235 dmaActive = 1;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
236 }
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
237 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
238
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
239 #ifdef ENABLE_CO2_SUPPORT
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
240 void UART_HandleCO2Data(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
242 uint8_t localRX = rxReadIndex;
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
243 static uint8_t dataType = 0;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
244 static uint32_t dataValue = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
245 static receiveState_t rxState = RX_Ready;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
246 static uint32_t lastReceiveTick = 0;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
247 static uint32_t lastTransmitTick = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
248 static uint8_t cmdString[10];
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
249 static uint16_t cmdLength = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
250
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
251 uint32_t Tick = HAL_GetTick();
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
252
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
253 uint8_t *pmap = externalInterface_GetSensorMapPointer(0);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
254
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
255 if(ComStatus_CO2 == UART_CO2_INIT)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
256 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
257 UART_StartDMA_Receiption();
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
258 ComStatus_CO2 = UART_CO2_SETUP;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
259 }
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
260
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
261 if(ComStatus_CO2 == UART_CO2_SETUP)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
262 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
263 if(time_elapsed_ms(lastTransmitTick,Tick) > 200)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
264 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
265 if(externalInterface_GetCO2Scale() == 0.0)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
266 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
267 DigitalCO2_SendCmd(CO2CMD_GETDATA, cmdString, &cmdLength);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
268 lastTransmitTick = Tick;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
269 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
270 else
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
271 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
272 ComStatus_CO2 = UART_CO2_OPERATING;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
273 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
274 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
275 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
276 else
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
277 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
278 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* sensor is working in polling mode if mux is connected to avoid interference with other sensors */
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
279 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
280 if(time_elapsed_ms(lastTransmitTick,Tick) > 2000) /* poll every two seconds */
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
281 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
282 lastTransmitTick = Tick;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
283 if(cmdLength == 0) /* poll data */
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
284 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
285 DigitalCO2_SendCmd(CO2CMD_GETDATA, cmdString, &cmdLength);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
286 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
287 else /* resend last command */
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
288 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
289 HAL_UART_Transmit(&huart1,cmdString,strlen((char*)cmdString),10);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
290 cmdLength = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
291 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
292 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
293 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
294 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
295 while((rxBuffer[localRX]!=BUFFER_NODATA))
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
296 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
297 lastReceiveTick = Tick;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
298 if(rxState == RX_Ready) /* identify data content */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
299 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
300 switch(rxBuffer[localRX])
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
301 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
302 case 'l':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
303 case 'D':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
304 case 'Z':
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
305 case '.':
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
306 dataType = rxBuffer[localRX];
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
307 rxState = RX_Data0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
308 dataValue = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
309 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
310
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
311 default: /* unknown or corrupted => ignore */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
312 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
313 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
314 }
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
315 else if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
316 {
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
317 if((rxState >= RX_Data0) && (rxState <= RX_Data4))
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
318 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
319 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0');
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
320 rxState++;
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
321 if(rxState == RX_Data5)
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
322 {
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
323 rxState = RX_DataComplete;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
324 CO2Connected = 1;
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
325 }
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
326 }
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
327 else /* protocol error data has max 5 digits */
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
328 {
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
329 rxState = RX_Ready;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
330 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
331 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
332 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
333 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
334 if(rxState == RX_DataComplete)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
335 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
336 if(externalInterface_GetCO2State() == 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
337 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
338 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
339 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
340 switch(dataType)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
341 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
342 case 'D': externalInterface_SetCO2SignalStrength(dataValue);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
343 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
344 case 'l': LED_ZeroOffset = dataValue;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
345 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
346 case 'Z': externalInterface_SetCO2Value(dataValue);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
347 break;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
348 case '.': externalInterface_SetCO2Scale(dataValue);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
349 break;
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
350 default: rxState = RX_Ready;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
351 break;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
352 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
353 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
354 if(rxState != RX_Data0) /* reset state machine because message in wrong format */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
355 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
356 rxState = RX_Ready;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
357 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
358 }
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
359 rxBuffer[localRX] = BUFFER_NODATA;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
360 localRX++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
361 rxReadIndex++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
362 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
363 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
364 localRX = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
365 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
366 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
367 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
368
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
369 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
370 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
371 externalInterface_SetCO2State(0);
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
372 CO2Connected = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
373 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
374
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
375 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
376 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
377 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
378 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
380 #endif
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
381
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
382 #ifdef ENABLE_SENTINEL_MODE
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
383 void UART_HandleSentinelData(void)
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
384 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
385 uint8_t localRX = rxReadIndex;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
386 static uint8_t dataType = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
387 static uint32_t dataValue[3];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
388 static uint8_t dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
389 static receiveState_t rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
390 static uint32_t lastReceiveTick = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
391 static uint8_t lastAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
392 static uint8_t curAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
393 static uint8_t checksum = 0;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
394 static char checksum_str[]="00";
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
395
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
396 while((rxBuffer[localRX]!=0))
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
397 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
398 lastReceiveTick = HAL_GetTick();
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
399
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
400 switch(rxState)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
401 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
402 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
403 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
404 rxState = RX_DetectStart;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
405 curAlive = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
406 checksum = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
407 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
408 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
409
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
410 case RX_DetectStart: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
411 if(rxBuffer[localRX] == '1')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
412 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
413 rxState = RX_SelectData;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
414 dataType = 0xFF;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
415
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
416 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
417 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
418 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
419 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
420 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
421 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
422
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
423 case RX_SelectData: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
424 switch(rxBuffer[localRX])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
425 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
426 case 'T': dataType = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
427 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
428 case '0': if(dataType != 0xff)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
429 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
430 rxState = RX_Data0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
431 dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
432 dataValue[0] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
433
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
434 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
435 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
436 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
437 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
438 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
439 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
440 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
441 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
442 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
443
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
444 case RX_Data0:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
445 case RX_Data1:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
446 case RX_Data2:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
447 case RX_Data4:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
448 case RX_Data5:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
449 case RX_Data6:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
450 case RX_Data8:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
451 case RX_Data9:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
452 case RX_Data10: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
453 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
454 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
455 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0');
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
456 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
457 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
458 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
459 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
460 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
461 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
462 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
463
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
464 case RX_Data3:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
465 case RX_Data7: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
466 if(rxBuffer[localRX] == '0')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
467 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
468 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
469 dataValueIdx++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
470 dataValue[dataValueIdx] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
471 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
472 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
473 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
474 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
475 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
476 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
477 case RX_Data11: rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
478 ConvertByteToHexString(checksum,checksum_str);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
479 if(rxBuffer[localRX] == checksum_str[0])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
480 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
481 rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
482 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
483 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
484 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
485 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
486 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
487
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
488 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
489
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
490 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
491 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
492 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
493 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
494 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0));
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
495 SentinelConnected = 1;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
496 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
497 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
498 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
499
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
500
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
501 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
502 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
503
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
504 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
505 localRX++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
506 rxReadIndex++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
507 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
508 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
509 localRX = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
510 rxReadIndex = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
511 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
512 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
513
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
514 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
515 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
516 if(curAlive == lastAlive)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
517 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
518 setExternalInterfaceChannel(0,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
519 setExternalInterfaceChannel(1,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
520 setExternalInterfaceChannel(2,0.0);
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
521 SentinelConnected = 0;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
522 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
523 lastAlive = curAlive;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
524 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
525
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
526 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
527 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
528 UART_StartDMA_Receiption();
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
529 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
530 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
531 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
533
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
534 uint8_t UART_isCO2Connected()
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
535 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
536 return CO2Connected;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
537 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
538 uint8_t UART_isSentinelConnected()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
539 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
540 return SentinelConnected;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
541 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
542
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
543 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
545 if(huart == &huart1)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
546 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
547 dmaActive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
548 rxWriteIndex+=CHUNK_SIZE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
549 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
550 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
551 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
552 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
553 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
554 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
555 if(externalInterface_GetUARTProtocol() != 0)
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
556 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
557 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
558 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
559 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
560 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
563 void UART_ReadData(uint8_t sensorType)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
564 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
565 uint8_t localRX = rxReadIndex;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
567 while((rxBuffer[localRX]!=BUFFER_NODATA))
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
568 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
569 switch (sensorType)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
570 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
571 case SENSOR_MUX:
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
572 case SENSOR_DIGO2: uartO2_ProcessData(rxBuffer[localRX]);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
573 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
574 // case SENSOR_CO2: uartCO2_Control();
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
575 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
576 default:
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
577 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
578 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
579
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
580 rxBuffer[localRX] = BUFFER_NODATA;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
581 localRX++;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
582 rxReadIndex++;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
583 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
584 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
585 localRX = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
586 rxReadIndex = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
587 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
588 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
589 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
590
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
591 void UART_FlushRxBuffer(void)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
592 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
593 while(rxBuffer[rxReadIndex] != BUFFER_NODATA)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
594 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
595 rxBuffer[rxReadIndex] = BUFFER_NODATA;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
596 rxReadIndex++;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
597 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
598 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
599 rxReadIndex = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
600 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
601 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
602
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
603 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
604
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/