annotate Small_CPU/Src/uart.c @ 791:92ac192e98d5

update current build for testing
author heinrichsweikamp
date Wed, 02 Aug 2023 08:41:03 +0200
parents aeb72882f30a
children bb37d4f3e50e
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"
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
23 #include "externalInterface.h"
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
24 #include "data_exchange.h"
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
25 #include <string.h> /* memset */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
29 #define BUFFER_NODATA (7u) /* The read function needs a byte which indecated that no data for processing is available.*/
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
30 /* This byte shall never appear in a normal data steam */
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)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
34 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
35 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor */
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
36 UART_HandleTypeDef huart1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
37
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
38 DMA_HandleTypeDef hdma_usart1_rx;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
40 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
41 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
42 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
43 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
44 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
45 static uint8_t digO2Connected = 0; /* Binary indicator if a sensor is connected or not */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
46 static uint8_t CO2Connected = 0; /* Binary indicator if a sensor is connected or not */
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
47 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
49 static SSensorDataDiveO2 tmpSensorDataDiveO2; /* intermediate storage for additional sensor data */
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
50
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
51 char tmpRxBuf[30];
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
52 uint8_t tmpRxIdx = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
53
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
54 static uartO2Status_t Comstatus_O2 = UART_O2_INIT;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
55 static uint8_t activeSensor = 0;
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
56 static uint8_t sensorMapping[MAX_MUX_CHANNEL]; /* The mapping is used to assign the visible sensor channel to the mux address (DiveO2) */
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
57
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
58 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
59 float LED_ZeroOffset = 0.0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
60 float pCO2 = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
63 void MX_USART1_UART_Init(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
65 /* regular init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
66
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
67 huart1.Instance = USART1;
704
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 if(externalInterface_GetUARTProtocol() == 0x04)
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 huart1.Init.BaudRate = 19200;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
72 Comstatus_O2 = UART_O2_INIT;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
73 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
74 else
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
75 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
76 huart1.Init.BaudRate = 9600;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
77 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
78 huart1.Init.WordLength = UART_WORDLENGTH_8B;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
79 huart1.Init.StopBits = UART_STOPBITS_1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
80 huart1.Init.Parity = UART_PARITY_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
81 huart1.Init.Mode = UART_MODE_TX_RX;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
82 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
83 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
84
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
85 HAL_UART_Init(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
86
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
87 MX_USART1_DMA_Init();
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
88
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
89 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer));
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
90 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
91 lastCmdIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
92 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
93 dmaActive = 0;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
94 digO2Connected = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
95 CO2Connected = 0;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
96 SentinelConnected = 0;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
97 Comstatus_O2 = UART_O2_INIT;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
98 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
100 void MX_USART1_UART_DeInit(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
101 {
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
102 HAL_DMA_Abort(&hdma_usart1_rx);
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
103 HAL_DMA_DeInit(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
104 HAL_UART_DeInit(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
105 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
106
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
107 void MX_USART1_DMA_Init()
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
108 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
109 /* DMA controller clock enable */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
110 __DMA2_CLK_ENABLE();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
111
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
112 /* Peripheral DMA init*/
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
113 hdma_usart1_rx.Instance = DMA2_Stream5;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
114 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
115 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
116 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
117 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
118 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
119 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
120 hdma_usart1_rx.Init.Mode = DMA_NORMAL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
121 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
122 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
123 HAL_DMA_Init(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
124
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
125 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
126
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
127 /* DMA interrupt init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
128 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
129 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
132
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
133 void DigitalO2_SelectSensor(uint8_t channel)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
134 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
135 uint8_t indexstr[4];
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
136 uint8_t muxAddress = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
137 indexstr[0] = '~';
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
138 indexstr[1] = '1';
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
139 indexstr[2] = 0x0D;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
140 indexstr[3] = 0x0A;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
141
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
142 /* Lookup mux address mapped to the provided channel. If no mapping is found the the MUX itself will be selected */
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
143 for(muxAddress = 0; muxAddress < MAX_MUX_CHANNEL; muxAddress++)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
144 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
145 if(sensorMapping[muxAddress] == channel)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
146 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
147 break;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
148 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
149 }
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
150 indexstr[1] = muxAddress;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
151 HAL_UART_Transmit(&huart1,indexstr,4,10);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
152 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
153
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
154 void DigitalO2_SetupCmd(uint8_t O2State, uint8_t *cmdString, uint8_t *cmdLength)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
155 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
156 switch (O2State)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
157 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
158 case UART_O2_CHECK: *cmdLength = snprintf((char*)cmdString, 10, "#LOGO");
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
159 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
160 case UART_O2_REQ_INFO: *cmdLength = snprintf((char*)cmdString, 10, "#VERS");
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
161 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
162 case UART_O2_REQ_ID: *cmdLength = snprintf((char*)cmdString, 10, "#IDNR");
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
163 break;
785
3c0b16473af4 Change support from Pyroscience -> DiveO2 sensors
heinrichsweikamp
parents: 784
diff changeset
164 case UART_O2_REQ_O2: *cmdLength = snprintf((char*)cmdString, 10, "#DOXY");
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
165 break;
785
3c0b16473af4 Change support from Pyroscience -> DiveO2 sensors
heinrichsweikamp
parents: 784
diff changeset
166 case UART_O2_REQ_RAW: *cmdLength = snprintf((char*)cmdString, 10, "#DRAW");
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
167 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
168 default: *cmdLength = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
169 break;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
170 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
171 if(*cmdLength != 0)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
172 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
173 cmdString[*cmdLength] = 0x0D;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
174 *cmdLength = *cmdLength + 1;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
175 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
176 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
177
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
178 void StringToInt(char *pstr, uint32_t *puInt32)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
179 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
180 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
181 uint32_t result = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
182 while((pstr[index] >= '0') && (pstr[index] <= '9'))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
183 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
184 result *=10;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
185 result += pstr[index] - '0';
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
186 index++;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
187 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
188 *puInt32 = result;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
189 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
190
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
191 void StringToUInt64(char *pstr, uint64_t *puint64)
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 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
194 uint64_t result = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
195 while((pstr[index] >= '0') && (pstr[index] <= '9'))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
196 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
197 result *=10;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
198 result += pstr[index] - '0';
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
199 index++;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
200 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
201 *puint64 = result;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
202 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
203 void ConvertByteToHexString(uint8_t byte, char* str)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
204 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
205 uint8_t worker = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
206 uint8_t digit = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
207 uint8_t digitCnt = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
209 worker = byte;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
210 while((worker!=0) && (digitCnt != 255))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
211 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
212 digit = worker % 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
213 if( digit < 10)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
214 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
215 digit += '0';
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
216 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
217 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
218 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
219 digit += 'A' - 10;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
220 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
221 str[digitCnt--]= digit;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
222 worker = worker / 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
223 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
224 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
225
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
226 void UART_StartDMA_Receiption()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
227 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
228 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
229 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
230 dmaActive = 1;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
231 }
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
232 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
233
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
234 #ifdef ENABLE_CO2_SUPPORT
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
235 void UART_HandleCO2Data(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
237 uint8_t localRX = rxReadIndex;
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
238 static uint8_t dataType = 0;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
239 static uint32_t dataValue = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
240 static receiveState_t rxState = RX_Ready;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
241 static uint32_t lastReceiveTick = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
242
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
243
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
244 while((rxBuffer[localRX]!=0))
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
245 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
246 lastReceiveTick = HAL_GetTick();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
247 if(rxState == RX_Ready) /* identify data content */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
248 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
249 switch(rxBuffer[localRX])
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
250 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
251 case 'l':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
252 case 'D':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
253 case 'Z':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
254 dataType = rxBuffer[localRX];
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
255 rxState = RX_Data0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
256 dataValue = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
257 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
258
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
259 default: /* unknown or corrupted => ignore */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
260 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
261 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
262 }
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
263 else if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
264 {
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
265 if((rxState >= RX_Data0) && (rxState <= RX_Data4))
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
266 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
267 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0');
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
268 rxState++;
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
269 if(rxState == RX_Data5)
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
270 {
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
271 rxState = RX_DataComplete;
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
272 CO2Connected = 1;
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
273 }
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
274 }
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
275 else /* protocol error data has max 5 digits */
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
276 {
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
277 rxState = RX_Ready;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
278 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
279 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
280 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
281 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
282 if(rxState == RX_DataComplete)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
283 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
284 if(externalInterface_GetCO2State() == 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
285 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
286 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
287 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
288 switch(dataType)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
289 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
290 case 'D': externalInterface_SetCO2SignalStrength(dataValue);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
291 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
292 case 'l': LED_ZeroOffset = dataValue;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
293 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
294 case 'Z': externalInterface_SetCO2Value(dataValue);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
295 break;
747
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
296 default: rxState = RX_Ready;
df0d43da1614 Added pressure compensation to CO2 detection:
Ideenmodellierer
parents: 742
diff changeset
297 break;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
298 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
299 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
300 if(rxState != RX_Data0) /* reset state machine because message in wrong format */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
301 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
302 rxState = RX_Ready;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
303 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
304 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
305 rxBuffer[localRX] = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
306 localRX++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
307 rxReadIndex++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
308 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
309 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
310 localRX = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
311 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
312 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
313 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
314
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
315 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
316 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
317 externalInterface_SetCO2State(0);
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
318 CO2Connected = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
319 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
320
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
321 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
322 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
323 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
324 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
326 #endif
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
327
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
328 #ifdef ENABLE_SENTINEL_MODE
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
329 void UART_HandleSentinelData(void)
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
330 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
331 uint8_t localRX = rxReadIndex;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
332 static uint8_t dataType = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
333 static uint32_t dataValue[3];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
334 static uint8_t dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
335 static receiveState_t rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
336 static uint32_t lastReceiveTick = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
337 static uint8_t lastAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
338 static uint8_t curAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
339 static uint8_t checksum = 0;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
340 static char checksum_str[]="00";
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
341
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
342 while((rxBuffer[localRX]!=0))
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
343 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
344 lastReceiveTick = HAL_GetTick();
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
345
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
346 switch(rxState)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
347 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
348 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
349 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
350 rxState = RX_DetectStart;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
351 curAlive = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
352 checksum = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
353 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
354 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
355
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
356 case RX_DetectStart: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
357 if(rxBuffer[localRX] == '1')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
358 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
359 rxState = RX_SelectData;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
360 dataType = 0xFF;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
361
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
362 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
363 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
364 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
365 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
366 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
367 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
368
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
369 case RX_SelectData: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
370 switch(rxBuffer[localRX])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
371 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
372 case 'T': dataType = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
373 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
374 case '0': if(dataType != 0xff)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
375 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
376 rxState = RX_Data0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
377 dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
378 dataValue[0] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
379
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
380 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
381 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
382 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
383 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
384 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
385 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
386 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
387 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
388 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
389
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
390 case RX_Data0:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
391 case RX_Data1:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
392 case RX_Data2:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
393 case RX_Data4:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
394 case RX_Data5:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
395 case RX_Data6:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
396 case RX_Data8:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
397 case RX_Data9:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
398 case RX_Data10: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
399 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
400 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
401 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0');
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
402 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
403 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
404 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
405 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
406 rxState = RX_Ready;
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_Data3:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
411 case RX_Data7: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
412 if(rxBuffer[localRX] == '0')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
413 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
414 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
415 dataValueIdx++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
416 dataValue[dataValueIdx] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
417 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
418 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
419 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
420 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
421 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
422 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
423 case RX_Data11: rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
424 ConvertByteToHexString(checksum,checksum_str);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
425 if(rxBuffer[localRX] == checksum_str[0])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
426 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
427 rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
428 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
429 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
430 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
431 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
432 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
433
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
434 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
435
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
436 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
437 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
438 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
439 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
440 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0));
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
441 SentinelConnected = 1;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
442 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
443 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
444 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
445
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
446
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
447 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
448 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
449
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
450 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
451 localRX++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
452 rxReadIndex++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
453 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
454 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
455 localRX = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
456 rxReadIndex = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
457 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
458 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
459
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
460 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
461 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
462 if(curAlive == lastAlive)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
463 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
464 setExternalInterfaceChannel(0,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
465 setExternalInterfaceChannel(1,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
466 setExternalInterfaceChannel(2,0.0);
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
467 SentinelConnected = 0;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
468 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
469 lastAlive = curAlive;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
470 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
471
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
472 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
473 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
474 UART_StartDMA_Receiption();
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
475 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
476 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
477 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
479
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
480
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
481 void UART_HandleDigitalO2(void)
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
482 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
483 static uint32_t lastO2ReqTick = 0;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
484 static uint8_t errorStr[] = "#ERRO";
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
485 static uartO2RxState_t rxState = O2RX_IDLE;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
486 static uint32_t lastReceiveTick = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
487 static uint8_t lastAlive = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
488 static uint8_t curAlive = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
489
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
490 static uint8_t cmdLength = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
491 static uint8_t cmdString[10];
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
492 static uint8_t cmdReadIndex = 0;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
493 static uint8_t errorReadIndex = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
494 static uint32_t tickToTX = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
495 static uint32_t delayStartTick = 0;
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
496 static uint16_t requestIntervall = 0;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
497 static uint8_t retryRequest = 1;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
498 static uint8_t lastComState = 0;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
499 static uint8_t respondErrorDetected = 0;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
500 static uint8_t switchChannel = 0;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
501
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
502 uint8_t index = 0;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
503 uint32_t tmpO2 = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
504 uint32_t tmpData = 0;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
505 uint8_t localRX = rxReadIndex;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
506 uint32_t tick = HAL_GetTick();
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
507
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
508 uint8_t *pmap = externalInterface_GetSensorMapPointer(0);
714
045ff7800501 Added customizable data area for specific sensor data:
Ideenmodellierer
parents: 704
diff changeset
509
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
510 /* The channel switch will cause the sensor to respond with an error message. */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
511 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
512 if((tickToTX) && (time_elapsed_ms(delayStartTick,tick) >= tickToTX ))
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
513 {
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
514 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
515 tickToTX = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
516 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
517 else
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
518 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
519 if(Comstatus_O2 == UART_O2_INIT)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
520 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
521 memset((char*)&rxBuffer[rxWriteIndex],(int)BUFFER_NODATA, sizeof(rxBuffer));
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
522 memset((char*) &tmpSensorDataDiveO2, 0, sizeof(tmpSensorDataDiveO2));
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
523 externalInterface_SetSensorData(0xFF,(uint8_t*)&tmpSensorDataDiveO2);
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
524
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
525 lastAlive = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
526 curAlive = 0;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
527
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
528 Comstatus_O2 = UART_O2_CHECK;
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
529 lastComState = UART_O2_IDLE;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
530 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength);
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
531
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
532 if(activeSensor < MAX_MUX_CHANNEL)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
533 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
534 externalInterface_GetSensorData(activeSensor, (uint8_t*)&tmpSensorDataDiveO2);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
535 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
536
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
537 tickToTX = COMMAND_TX_DELAY;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
538
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
539 rxState = O2RX_CONFIRM;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
540 cmdReadIndex = 0;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
541 errorReadIndex = 0;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
542 respondErrorDetected = 0;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
543 digO2Connected = 0;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
544 switchChannel = 1;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
545
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
546 requestIntervall = 0;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
547 for(index = 0; index < MAX_MUX_CHANNEL; index++)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
548 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
549 if(pmap[index] == SENSOR_DIGO2)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
550 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
551 requestIntervall++;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
552 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
553 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
554 if(requestIntervall != 0)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
555 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
556 requestIntervall = REQUEST_INT_SENSOR_MS / requestIntervall;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
557 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
558 else
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
559 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
560 requestIntervall = REQUEST_INT_SENSOR_MS;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
561 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
562 UART_StartDMA_Receiption();
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
563 lastO2ReqTick = tick + requestIntervall + 1;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
564 }
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
565 if(time_elapsed_ms(lastO2ReqTick,tick) > requestIntervall) /* repeat request or iterate to next sensor */
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
566 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
567 respondErrorDetected = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
568 lastO2ReqTick = tick;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
569 index = activeSensor;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
570 if((lastComState == Comstatus_O2) && (Comstatus_O2 != UART_O2_IDLE))
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
571 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
572 if(retryRequest)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
573 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
574 retryRequest = 0;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
575 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
576 else /* no answer even repeating the request => abort request */
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
577 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
578 if(Comstatus_O2 == UART_O2_REQ_RAW)
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
579 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
580 setExternalInterfaceChannel(activeSensor,0.0);
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
581 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
582 Comstatus_O2 = UART_O2_IDLE;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
583 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
584 }
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
585 lastComState = Comstatus_O2;
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
586 if(Comstatus_O2 == UART_O2_IDLE) /* cyclic request of o2 value */
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
587 {
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
588 retryRequest = 1;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
589 if(pmap[EXT_INTERFACE_SENSOR_CNT-1] == SENSOR_MUX) /* select next sensor if mux is connected */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
590 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
591 if(activeSensor < MAX_MUX_CHANNEL)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
592 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
593 do
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
594 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
595 index++;
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
596 if(index == MAX_MUX_CHANNEL)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
597 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
598 index = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
599 }
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
600 if((pmap[index] == SENSOR_DIGO2) && (index != activeSensor))
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
601 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
602 activeSensor = index;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
603 switchChannel = 1;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
604 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
605 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
606 } while(index != activeSensor);
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
607 externalInterface_GetSensorData(activeSensor, (uint8_t*)&tmpSensorDataDiveO2);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
608 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
609 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
610 if((activeSensor != MAX_MUX_CHANNEL) && (tmpSensorDataDiveO2.sensorId == 0))
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
611 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
612 Comstatus_O2 = UART_O2_REQ_ID;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
613 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
614 else
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
615 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
616 Comstatus_O2 = UART_O2_REQ_RAW;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
617 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
618 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
619 rxState = O2RX_CONFIRM;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
620 if(switchChannel)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
621 {
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
622 switchChannel = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
623 delayStartTick = tick;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
624 DigitalO2_SelectSensor(activeSensor);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
625 tickToTX = COMMAND_TX_DELAY;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
626 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
627 else
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
628 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
629 tickToTX = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
630 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
631 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
632 DigitalO2_SetupCmd(Comstatus_O2,cmdString,&cmdLength);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
633 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
634 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
635 while((rxBuffer[localRX] != BUFFER_NODATA))
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
636 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
637 lastReceiveTick = tick;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
638 switch(rxState)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
639 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
640 case O2RX_CONFIRM: if(rxBuffer[localRX] == '#')
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
641 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
642 cmdReadIndex = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
643 errorReadIndex = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
644 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
645 if(errorReadIndex < sizeof(errorStr)-1)
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
646 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
647 if(rxBuffer[localRX] == errorStr[errorReadIndex])
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
648 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
649 errorReadIndex++;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
650 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
651 else
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
652 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
653 errorReadIndex = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
654 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
655 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
656 else
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
657 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
658 respondErrorDetected = 1;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
659 errorReadIndex = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
660 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
661 if(rxBuffer[localRX] == cmdString[cmdReadIndex])
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
662 {
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
663 cmdReadIndex++;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
664 if(cmdReadIndex == cmdLength - 1)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
665 {
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
666 if((activeSensor == MAX_MUX_CHANNEL))
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
667 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
668 if(respondErrorDetected)
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
669 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
670 digO2Connected = 0; /* the multiplexer mirrors the incoming message and does not generate an error information => no mux connected */
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
671 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
672 else
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
673 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
674 digO2Connected = 1;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
675 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
676 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
677 else /* handle sensors which should respond with an error message after channel switch */
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
678 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
679 if(respondErrorDetected)
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
680 {
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
681 digO2Connected = 1;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
682 }
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
683 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
684 tmpRxIdx = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
685 memset((char*) tmpRxBuf, 0, sizeof(tmpRxBuf));
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
686 cmdReadIndex = 0;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
687 switch (Comstatus_O2)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
688 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
689 case UART_O2_CHECK: Comstatus_O2 = UART_O2_IDLE;
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
690 rxState = O2RX_IDLE;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
691 break;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
692 case UART_O2_REQ_ID: rxState = O2RX_GETNR;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
693 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
694 case UART_O2_REQ_INFO: rxState = O2RX_GETTYPE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
695 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
696 case UART_O2_REQ_RAW:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
697 case UART_O2_REQ_O2: rxState = O2RX_GETO2;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
698 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
699 default: Comstatus_O2 = UART_O2_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
700 rxState = O2RX_IDLE;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
701 break;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
702 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
703 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
704 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
705 else
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
706 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
707 cmdReadIndex = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
708 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
709 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
710
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
711 case O2RX_GETSTATUS:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
712 case O2RX_GETTEMP:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
713 case O2RX_GETTYPE:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
714 case O2RX_GETVERSION:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
715 case O2RX_GETCHANNEL:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
716 case O2RX_GETSUBSENSORS:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
717 case O2RX_GETO2:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
718 case O2RX_GETNR:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
719 case O2RX_GETDPHI:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
720 case O2RX_INTENSITY:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
721 case O2RX_AMBIENTLIGHT:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
722 case O2RX_PRESSURE:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
723 case O2RX_HUMIDITY:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
724 if(rxBuffer[localRX] != 0x0D)
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
725 {
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
726 if(rxBuffer[localRX] != ' ') /* the following data entities are placed within the data stream => no need to store data at the end */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
727 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
728 tmpRxBuf[tmpRxIdx++] = rxBuffer[localRX];
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
729 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
730 else
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
731 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
732 if(tmpRxIdx != 0)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
733 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
734 switch(rxState)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
735 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
736 case O2RX_GETCHANNEL: StringToInt(tmpRxBuf,&tmpData);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
737 rxState = O2RX_GETVERSION;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
738 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
739 case O2RX_GETVERSION: StringToInt(tmpRxBuf,&tmpData);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
740 rxState = O2RX_GETSUBSENSORS;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
741 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
742 case O2RX_GETTYPE: StringToInt(tmpRxBuf,&tmpData);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
743 rxState = O2RX_GETCHANNEL;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
744 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
745
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
746 case O2RX_GETO2: StringToInt(tmpRxBuf,&tmpO2);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
747 setExternalInterfaceChannel(activeSensor,(float)(tmpO2 / 10000.0));
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
748 rxState = O2RX_GETTEMP;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
749 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
750 case O2RX_GETTEMP: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.temperature);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
751 rxState = O2RX_GETSTATUS;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
752 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
753 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&tmpSensorDataDiveO2.status); /* raw data cycle */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
754 rxState = O2RX_GETDPHI;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
755 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
756 case O2RX_GETDPHI: /* ignored to save memory and most likly irrelevant for diver */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
757 rxState = O2RX_INTENSITY;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
758 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
759 case O2RX_INTENSITY: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.intensity); /* raw data cycle */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
760 rxState = O2RX_AMBIENTLIGHT;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
761 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
762 case O2RX_AMBIENTLIGHT: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.ambient); /* raw data cycle */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
763 rxState = O2RX_PRESSURE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
764 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
765 case O2RX_PRESSURE: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.pressure); /* raw data cycle */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
766 rxState = O2RX_HUMIDITY;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
767 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
768 default:
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
769 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
770 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
771 memset((char*) tmpRxBuf, 0, tmpRxIdx);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
772 tmpRxIdx = 0;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
773 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
774 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
775 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
776 else
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
777 { /* the following data items are the last of a sensor respond => store temporal data */
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
778 switch (rxState)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
779 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
780 case O2RX_GETSTATUS: StringToInt(tmpRxBuf,&tmpSensorDataDiveO2.status);
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
781 externalInterface_SetSensorData(activeSensor,(uint8_t*)&tmpSensorDataDiveO2);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
782 Comstatus_O2 = UART_O2_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
783 rxState = O2RX_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
784 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
785 case O2RX_GETSUBSENSORS: StringToInt(tmpRxBuf,&tmpData);
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
786 Comstatus_O2 = UART_O2_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
787 rxState = O2RX_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
788 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
789 case O2RX_HUMIDITY: StringToInt(tmpRxBuf,(uint32_t*)&tmpSensorDataDiveO2.humidity); /* raw data cycle */
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
790 externalInterface_SetSensorData(activeSensor,(uint8_t*)&tmpSensorDataDiveO2);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
791 Comstatus_O2 = UART_O2_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
792 rxState = O2RX_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
793 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
794 case O2RX_GETNR: StringToUInt64((char*)tmpRxBuf,&tmpSensorDataDiveO2.sensorId);
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
795 externalInterface_SetSensorData(activeSensor,(uint8_t*)&tmpSensorDataDiveO2);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
796 index = activeSensor;
784
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
797 Comstatus_O2 = UART_O2_IDLE;
95af969fe0ae Bugfixloop UART multiplexer integration:
Ideenmodellierer
parents: 781
diff changeset
798 rxState = O2RX_IDLE;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
799 break;
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
800 default: Comstatus_O2 = UART_O2_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
801 rxState = O2RX_IDLE;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
802 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
803 }
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
804 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
805 break;
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
806 default: rxState = O2RX_IDLE;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
807 break;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
808
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
809 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
810 rxBuffer[localRX] = BUFFER_NODATA;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
811 localRX++;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
812 rxReadIndex++;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
813 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
814 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
815 localRX = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
816 rxReadIndex = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
817 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
818 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
819
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
820 if((digO2Connected) && time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
821 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
822 digO2Connected = 0;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
823 if(curAlive == lastAlive)
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
824 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
825 for(index = 0; index < MAX_ADC_CHANNEL; index++)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
826 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
827 if(pmap[index] == SENSOR_DIGO2)
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
828 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
829 setExternalInterfaceChannel(index,0.0);
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
830 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
831 }
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
832 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
833 lastAlive = curAlive;
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
834 }
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
835 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
836 {
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
837 UART_StartDMA_Receiption();
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
838 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
839 }
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
840
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
841 void UART_SetDigO2_Channel(uint8_t channel)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
842 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
843 if(channel <= MAX_MUX_CHANNEL)
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
844 {
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
845 activeSensor = channel;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
846 }
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
847 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
848 void UART_MapDigO2_Channel(uint8_t channel, uint8_t muxAddress)
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
849 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
850 if(((channel < MAX_ADC_CHANNEL) || (channel == 0xff)) && (muxAddress < MAX_MUX_CHANNEL))
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
851 {
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
852 sensorMapping[muxAddress] = channel;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
853 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
854 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
855
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
856 uint8_t UART_isDigO2Connected()
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
857 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
858 return digO2Connected;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
859 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
860 uint8_t UART_isCO2Connected()
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
861 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
862 return CO2Connected;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
863 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
864 uint8_t UART_isSentinelConnected()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
865 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
866 return SentinelConnected;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
867 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
868
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
869 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
871 if(huart == &huart1)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
872 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
873 dmaActive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
874 rxWriteIndex+=CHUNK_SIZE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
875 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
876 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
877 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
878 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
879 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
880 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
881 if(externalInterface_GetUARTProtocol() != 0)
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
882 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
883 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
884 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
885 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
886 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
890
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/