Mercurial > public > ostc4
annotate Discovery/Src/cv_heartbeat.c @ 1034:195bfbdf961d Puls_Integration
Pulse measurement integration:
Added function to parse standart GATT pulse service. Added compile switch to remove code from non dev builds.
| author | Ideenmodellierer |
|---|---|
| date | Thu, 07 Aug 2025 20:18:52 +0200 |
| parents | 5f66e44d69f0 |
| children | 5b913cdaa9dc |
| rev | line source |
|---|---|
| 1032 | 1 /////////////////////////////////////////////////////////////////////////////// |
| 2 /// -*- coding: UTF-8 -*- | |
| 3 /// | |
| 4 /// \file Discovery/Src/cv_heartbeat.c | |
| 5 /// \brief providing functionality to connect OSTC to a Polar HC10 heartbeat sensor | |
| 6 /// \author heinrichs weikamp gmbh | |
| 7 /// \date 03-July-2025 | |
| 8 /// | |
| 9 /// $Id$ | |
| 10 /////////////////////////////////////////////////////////////////////////////// | |
| 11 /// \par Copyright (c) 2014-2025 Heinrichs Weikamp gmbh | |
| 12 /// | |
| 13 /// This program is free software: you can redistribute it and/or modify | |
| 14 /// it under the terms of the GNU General Public License as published by | |
| 15 /// the Free Software Foundation, either version 3 of the License, or | |
| 16 /// (at your option) any later version. | |
| 17 /// | |
| 18 /// This program is distributed in the hope that it will be useful, | |
| 19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 /// GNU General Public License for more details. | |
| 22 /// | |
| 23 /// You should have received a copy of the GNU General Public License | |
| 24 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 25 ////////////////////////////////////////////////////////////////////////////// | |
| 26 | |
| 1034 | 27 #include "configuration.h" |
| 28 | |
| 29 #ifdef ENABLE_PULSE_SENSOR_BT | |
| 1032 | 30 #include "cv_heartbeat.h" |
| 31 #include "tMenuEdit.h" | |
| 32 | |
| 33 #include "gfx_fonts.h" | |
| 34 #include "tHome.h" | |
| 35 #include "ostc.h" | |
| 36 #include "tComm.h" | |
| 37 #include "tInfoLogger.h" | |
| 1034 | 38 #include "stdlib.h" |
| 1032 | 39 |
| 40 static sensorHeartbeat_State_t heartbeatState = SENSOR_HB_OFFLINE; | |
| 41 | |
| 42 static uint8_t OnAction_Heartbeat(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 43 static uint32_t startDetection_ms; | |
| 44 | |
| 45 #define MAX_BT_DEVICE 10 /* max number of device which may be handled */ | |
| 46 static btDdeviceData_t btDeviceList[MAX_BT_DEVICE]; | |
| 47 static btDeviceService_t curDeviceService[10]; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
48 static btDeviceCharacteristic_t curDevCharacteristic[10]; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
49 static btDeviceDescriptor_t curDevDescriptor; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
50 |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
51 |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
52 static uint8_t curCharacteristicIndex = 0; |
| 1032 | 53 static uint8_t curServiceIndex = 0; |
| 54 static uint8_t curBtIndex = 0; | |
| 55 static uint8_t connHandle = ' '; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
56 static uint8_t evaluateDevIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
57 static uint8_t evaluateSrvIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
58 static uint8_t evaluateCharIndex = 0xFF; |
| 1034 | 59 |
| 60 static void parsePulseMeasurement(uint8_t* pData, uint8_t length) | |
| 61 { | |
| 62 uint8_t rawData[10]; | |
| 63 char text[40]; | |
| 64 char* enptr; | |
| 65 uint8_t flags = 0; | |
| 66 uint16_t rr = 0; | |
| 67 uint8_t index = 0; | |
| 68 uint8_t* pRaw = (uint8_t*)&rawData; | |
| 69 char tmpStr[3]; | |
| 70 | |
| 71 tmpStr[2] = 0; | |
| 72 | |
| 73 HRMeasurement_t pulseData; | |
| 74 | |
| 75 for(index = 0; index < length; index +=2) | |
| 76 { | |
| 77 memcpy(tmpStr,&pData[index],2); | |
| 78 rawData[index / 2] = strtol(tmpStr, &enptr,16); | |
| 79 } | |
| 80 flags = pRaw[0]; | |
| 81 index = 1; | |
| 82 /* 0: Heart Rate Format bit (0 = UINT8, 1 = UINT16) */ | |
| 83 if (flags & 0x01) | |
| 84 { | |
| 85 pulseData.heart_rate = pRaw[index] | (pRaw[index + 1] << 8); | |
| 86 index += 2; | |
| 87 } else | |
| 88 { | |
| 89 pulseData.heart_rate = pRaw[index]; | |
| 90 index += 1; | |
| 91 } | |
| 92 | |
| 93 /* 3: Energy Expended Status */ | |
| 94 if (flags & 0x08) | |
| 95 { | |
| 96 pulseData.energy_expended = pRaw[index] | (pRaw[index + 1] << 8); | |
| 97 index += 2; | |
| 98 } else | |
| 99 { | |
| 100 pulseData.energy_expended = 0; | |
| 101 } | |
| 102 /* 4: RR-Interval bit */ | |
| 103 pulseData.rr_count = 0; | |
| 104 if (flags & 0x10) | |
| 105 { | |
| 106 while (index + 1 < 4 && pulseData.rr_count < 10) | |
| 107 { | |
| 108 rr = pRaw[index] | (pRaw[index + 1] << 8); | |
| 109 pulseData.rr_intervals[pulseData.rr_count++] = rr; | |
| 110 index += 2; | |
| 111 } | |
| 112 } | |
| 113 // snprintf(text,40,"Pulse: %d",pulseData.heart_rate); | |
| 114 // InfoLogger_writeLine((uint8_t*)text,strlen(text),0); | |
| 115 } | |
| 1032 | 116 |
| 117 static indicatior_t checkIndicators(uint8_t* pdata) | |
| 118 { | |
| 119 indicatior_t ret = NO_INDICATOR; | |
| 120 | |
| 121 if(strcmp((char*)pdata,"+UBTD:") == 0) | |
| 122 { | |
| 123 ret = DEVICE_INDICATOR; | |
| 124 } | |
| 125 else if(strcmp((char*)pdata,"+UUBTACLC:") == 0) | |
| 126 { | |
| 127 ret = CONNECTION_INDICATOR; | |
| 128 } | |
| 129 else if(strcmp((char*)pdata,"+UBTGDP:") == 0) | |
| 130 { | |
| 131 ret = SERVICE_INDICATOR; | |
| 132 } | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
133 else if(strcmp((char*)pdata,"+UBTGDCS:") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
134 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
135 ret = CHARACTERISTIC_INDICATOR; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
136 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
137 else if(strcmp((char*)pdata,"+UBTGDCD:") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
138 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
139 ret = DESCRIPTOR_INDICATOR; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
140 } |
| 1034 | 141 else if(strcmp((char*)pdata,"+UUBTGN:") == 0) |
| 142 { | |
| 143 ret = PULSE_INDICATOR; | |
| 144 } | |
| 1032 | 145 return ret; |
| 146 } | |
| 147 | |
| 148 static void handleOK() | |
| 149 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
150 uint8_t index = 0; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
151 |
| 1032 | 152 switch(heartbeatState) |
| 153 { | |
| 154 case SENSOR_HB_ENABLE_BLE: heartbeatState = SENSOR_HB_CHECK_CONFIG; | |
| 155 break; | |
| 156 case SENSOR_HB_CHECK_CONFIG: heartbeatState = SENSOR_HB_DISCOVER; | |
| 157 break; | |
| 158 case SENSOR_HB_RESTART: heartbeatState = SENSOR_HB_OFFLINE; | |
| 159 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
160 case SENSOR_HB_DISCOVER: if(curBtIndex > 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
161 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
162 heartbeatState = SENSOR_HB_CONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
163 evaluateDevIndex = 0; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
164 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
165 else |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
166 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
167 heartbeatState = SENSOR_HB_OFFLINE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
168 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
169 |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
170 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
171 case SENSOR_HB_SERVICES: evaluateSrvIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
172 if(curServiceIndex != 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
173 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
174 for(index = 0; index <= curServiceIndex; index++) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
175 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
176 if(strcmp((char*)curDeviceService[index].uuid,"180D") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
177 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
178 heartbeatState = SENSOR_HB_CHARACTERISTIC; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
179 evaluateSrvIndex = index; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
180 curCharacteristicIndex = 0; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
181 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
182 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
183 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
184 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
185 if(evaluateSrvIndex == 0xFF) /* device does not provide heartbeat data => disconnect */ |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
186 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
187 heartbeatState = SENSOR_HB_DISCONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
188 } |
| 1032 | 189 break; |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
190 case SENSOR_HB_CHARACTERISTIC: evaluateCharIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
191 if(curCharacteristicIndex != 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
192 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
193 for(index = 0; index < curCharacteristicIndex; index++) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
194 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
195 if(strcmp((char*)curDevCharacteristic[index].uuid,"2A37") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
196 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
197 heartbeatState = SENSOR_HB_DESCRIPTOR; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
198 evaluateCharIndex = index; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
199 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
200 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
201 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
202 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
203 if(evaluateCharIndex == 0xFF) /* device does not provide heartbeat data => disconnect */ |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
204 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
205 heartbeatState = SENSOR_HB_DISCONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
206 } |
| 1032 | 207 break; |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
208 case SENSOR_HB_DESCRIPTOR: if(strcmp((char*)curDevDescriptor.uuid,"2902") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
209 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
210 heartbeatState = SENSOR_HB_SUBSCRIBE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
211 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
212 else |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
213 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
214 heartbeatState = SENSOR_HB_DISCONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
215 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
216 break; |
| 1034 | 217 |
| 218 case SENSOR_HB_SUBSCRIBE: heartbeatState = SENSOR_HB_CONNECTED; | |
| 219 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
220 case SENSOR_HB_DISCONNECT: evaluateDevIndex++; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
221 connHandle= ' '; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
222 if(evaluateDevIndex < curBtIndex) /* more devices to be evaluated? */ |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
223 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
224 heartbeatState = SENSOR_HB_CONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
225 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
226 else |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
227 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
228 heartbeatState = SENSOR_HB_OFFLINE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
229 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
230 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
231 case SENSOR_HB_CONNECT: /* handled in data rx section */ |
| 1032 | 232 default: |
| 233 break; | |
| 234 } | |
| 235 } | |
| 236 | |
| 237 static void handleERROR() | |
| 238 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
239 switch(heartbeatState) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
240 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
241 case SENSOR_HB_DISCONNECT: evaluateDevIndex++; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
242 connHandle= ' '; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
243 if(evaluateDevIndex < curBtIndex) /* more devices to be evaluated? */ |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
244 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
245 heartbeatState = SENSOR_HB_CONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
246 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
247 else |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
248 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
249 heartbeatState = SENSOR_HB_OFFLINE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
250 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
251 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
252 default: |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
253 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
254 } |
| 1032 | 255 } |
| 256 | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
257 uint8_t cv_heartbeat_HandleData() |
| 1032 | 258 { |
| 259 static uint8_t firstDevice = 1; | |
| 260 static uint8_t curLine[MAX_CHAR_PER_LINE]; /* holds complete line and is used for logging */ | |
| 261 static uint8_t curLineIndex = 0; | |
| 262 static uint8_t parameter[40]; /* content of the parameter in read state */ | |
| 263 static uint8_t writeIndex = 0; | |
| 264 static uint8_t complete = 0; | |
| 265 | |
| 266 static readDataType_t readType = BT_READ_NOTHING; | |
| 267 | |
| 268 char text[40]; | |
| 269 uint8_t data = 0; | |
| 270 data = UART_getChar(); | |
| 271 | |
| 272 while((data != 0) && (complete == 0)) | |
| 273 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
274 if(curLineIndex == MAX_CHAR_PER_LINE - 1) /* avoid overflow */ |
| 1032 | 275 { |
| 276 InfoLogger_writeLine(curLine,curLineIndex,0); | |
| 277 memset(curLine,0,sizeof(curLine)); | |
| 278 curLineIndex = 0; | |
| 279 } | |
| 280 if((data == '\r') || (data == '\n')) | |
| 281 { | |
| 282 if(curLineIndex > 0) | |
| 283 { | |
| 284 InfoLogger_writeLine(curLine,curLineIndex,0); | |
| 285 if(strcmp((char*)curLine,"OK") == 0) | |
| 286 { | |
| 287 handleOK(); | |
| 288 } | |
| 289 else | |
| 290 { | |
| 291 if(strcmp((char*)curLine,"ERROR") == 0) | |
| 292 { | |
| 293 handleERROR(); | |
| 294 } | |
| 295 } | |
| 296 } | |
| 297 switch(readType) | |
| 298 { | |
| 299 case BT_READ_DEVICE_NAME: if(writeIndex < BLUEMOD_NAME_SIZE) | |
| 300 { | |
| 301 memcpy (btDeviceList[curBtIndex].name, parameter, writeIndex); | |
| 302 } | |
| 303 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
304 case BT_READ_SERV_UUID: if((writeIndex < 50) && (curServiceIndex < 10)) |
| 1032 | 305 { |
| 306 memcpy(curDeviceService[curServiceIndex].uuid, parameter, writeIndex); | |
| 307 } | |
| 308 curServiceIndex++; | |
| 309 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
310 case BT_READ_CHAR_UUID: if(writeIndex < 50) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
311 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
312 memcpy(curDevCharacteristic[curCharacteristicIndex].uuid, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
313 curCharacteristicIndex++; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
314 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
315 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
316 case BT_READ_DESC_UUID: if(writeIndex < 50) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
317 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
318 memcpy(curDevDescriptor.uuid, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
319 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
320 break; |
| 1034 | 321 case BT_READ_PULSE_DATA: if(writeIndex < 50) |
| 322 { | |
| 323 parsePulseMeasurement(parameter, writeIndex); | |
| 324 } | |
| 325 break; | |
| 1032 | 326 default: |
| 327 break; | |
| 328 } | |
| 329 curLineIndex = 0; | |
| 330 writeIndex = 0; | |
| 331 memset(curLine,0,sizeof(curLine)); | |
| 332 readType = BT_READ_NOTHING; | |
| 333 } | |
| 334 else | |
| 335 { | |
| 336 if(curLineIndex < MAX_CHAR_PER_LINE) curLine[curLineIndex++] = data; | |
| 337 | |
| 338 if(data == ':') | |
| 339 { | |
| 340 switch(checkIndicators(curLine)) | |
| 341 { | |
| 342 case DEVICE_INDICATOR: readType = BT_READ_DEVICE_ADDR; | |
| 343 break; | |
| 344 case CONNECTION_INDICATOR: readType = BT_READ_CON_DETAILS; | |
| 345 break; | |
| 346 case SERVICE_INDICATOR: readType = BT_READ_SERV_HANDLE; | |
| 347 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
348 case CHARACTERISTIC_INDICATOR: readType = BT_READ_CHAR_CONHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
349 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
350 case DESCRIPTOR_INDICATOR: readType = BT_READ_DESC_CONHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
351 break; |
| 1034 | 352 case PULSE_INDICATOR: readType = BT_READ_PULSE_CONHANDLE; |
| 353 break; | |
| 1032 | 354 default: |
| 355 break; | |
| 356 } | |
| 357 writeIndex = 0; | |
| 358 memset(parameter,0,sizeof(parameter)); | |
| 359 } | |
| 360 else | |
| 361 { | |
| 362 if(data == ',') /* parameter end */ | |
| 363 { | |
| 364 switch(readType) | |
| 365 { | |
| 366 case BT_READ_DEVICE_ADDR: if(writeIndex < BLUEMOD_ADDR_SIZE-1) | |
| 367 { | |
| 368 if(firstDevice) | |
| 369 { | |
| 370 firstDevice = 0; | |
| 371 } | |
| 372 else | |
| 373 { | |
| 374 curBtIndex++; | |
| 375 } | |
| 376 parameter[writeIndex-1] = 0; /*remove 'p' from address */ | |
| 377 strcpy((char*)btDeviceList[curBtIndex].address, (char*)parameter); | |
| 378 } | |
| 379 readType = BT_READ_DEVICE_RSSI; | |
| 380 break; | |
| 381 case BT_READ_DEVICE_RSSI: if(writeIndex < BLUEMOD_RSSI_SIZE-1) | |
| 382 { | |
| 383 strcpy((char*)btDeviceList[curBtIndex].rssi, (char*)parameter); | |
| 384 } | |
| 385 readType = BT_READ_DEVICE_NAME; | |
| 386 break; | |
| 387 case BT_READ_DEVICE_NAME: if(writeIndex < BLUEMOD_NAME_SIZE-1) | |
| 388 { | |
| 389 memcpy(btDeviceList[curBtIndex].name, parameter, writeIndex); | |
| 390 } | |
| 391 readType = BT_READ_NOTHING; | |
| 392 break; | |
| 393 case BT_READ_CON_DETAILS: connHandle = parameter[0]; | |
| 394 heartbeatState = SENSOR_HB_SERVICES; | |
| 395 readType = BT_READ_NOTHING; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
396 curServiceIndex = 0; |
| 1032 | 397 break; |
| 398 case BT_READ_SERV_HANDLE: curDeviceService[curServiceIndex].handle = parameter[0]; | |
| 399 readType = BT_READ_SERV_START; | |
| 400 break; | |
| 401 case BT_READ_SERV_START: if(writeIndex < 6) | |
| 402 { | |
| 403 memcpy(curDeviceService[curServiceIndex].start, parameter, writeIndex); | |
| 404 } | |
| 405 readType = BT_READ_SERV_END; | |
| 406 break; | |
| 407 case BT_READ_SERV_END: if(writeIndex < 6) | |
| 408 { | |
| 409 memcpy(curDeviceService[curServiceIndex].end, parameter, writeIndex); | |
| 410 } | |
| 411 readType = BT_READ_SERV_UUID; | |
| 412 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
413 case BT_READ_CHAR_CONHANDLE: curDevCharacteristic[curCharacteristicIndex].conHandle = parameter[0]; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
414 readType = BT_READ_CHAR_ATTRIBUTE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
415 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
416 case BT_READ_CHAR_ATTRIBUTE: if(writeIndex < 10) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
417 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
418 memcpy(curDevCharacteristic[curCharacteristicIndex].attrHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
419 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
420 readType = BT_READ_CHAR_PROPERTY; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
421 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
422 case BT_READ_CHAR_PROPERTY: if(writeIndex < 10) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
423 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
424 memcpy(curDevCharacteristic[curCharacteristicIndex].properties, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
425 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
426 readType = BT_READ_CHAR_VALUEHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
427 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
428 case BT_READ_CHAR_VALUEHANDLE: if(writeIndex < 10) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
429 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
430 memcpy(curDevCharacteristic[curCharacteristicIndex].valueHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
431 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
432 readType = BT_READ_CHAR_UUID; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
433 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
434 case BT_READ_DESC_CONHANDLE: curDevDescriptor.conHandle = parameter[0]; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
435 readType = BT_READ_DESC_CHARHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
436 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
437 case BT_READ_DESC_CHARHANDLE: if(writeIndex < 10) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
438 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
439 memcpy(curDevDescriptor.charHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
440 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
441 readType = BT_READ_DESC_DESCHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
442 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
443 case BT_READ_DESC_DESCHANDLE: if(writeIndex < 10) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
444 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
445 memcpy(curDevDescriptor.descHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
446 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
447 readType = BT_READ_DESC_UUID; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
448 break; |
| 1034 | 449 case BT_READ_PULSE_CONHANDLE: curDevDescriptor.conHandle = parameter[0]; |
| 450 readType = BT_READ_PULSE_VALUEHANDLE; | |
| 451 break; | |
| 452 case BT_READ_PULSE_VALUEHANDLE: if(writeIndex < 10) | |
| 453 { | |
| 454 // if(strcmp((char*)curDevCharacteristic[evaluateCharIndex].valueHandle,(char*) parameter) == 0) | |
| 455 { | |
| 456 readType = BT_READ_PULSE_DATA; | |
| 457 } | |
| 458 #if 0 | |
| 459 else | |
| 460 { | |
| 461 readType = BT_READ_NOTHING; | |
| 462 } | |
| 463 #endif | |
| 464 } | |
| 465 break; | |
| 1032 | 466 default: readType = BT_READ_NOTHING; |
| 467 break; | |
| 468 } | |
| 469 writeIndex = 0; | |
| 470 memset(parameter,0 , sizeof(parameter)); | |
| 471 } | |
| 472 else | |
| 473 { | |
| 1034 | 474 if(readType != BT_READ_NOTHING) |
| 1032 | 475 { |
| 476 parameter[writeIndex++] = data; | |
| 477 } | |
| 478 } | |
| 479 } | |
| 480 } | |
| 481 data = UART_getChar(); | |
| 482 } | |
| 483 return complete; | |
| 484 } | |
| 485 | |
| 486 sensorHeartbeat_State_t cv_heartbeat_getState() | |
| 487 { | |
| 488 return heartbeatState; | |
| 489 } | |
| 490 | |
| 491 void openEdit_Heartbeat(void) | |
| 492 { | |
| 493 SSettings *settings = settingsGetPointer(); | |
| 494 | |
| 495 char text[32]; | |
| 496 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Pulse); | |
| 497 write_topline(text); | |
| 498 | |
| 499 set_globalState(StMOption_Heartbeat); | |
| 500 resetMenuEdit(CLUT_MenuPageCvOption); | |
| 501 | |
| 502 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_SensorDetect); | |
| 503 write_field_button(StMOption_Heartbeat, 30, 299, ME_Y_LINE1, &FontT48, text); | |
| 504 | |
| 505 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 506 | |
| 507 setEvent(StMOption_Heartbeat, (uint32_t)OnAction_Heartbeat); | |
| 508 } | |
| 509 | |
| 510 static uint8_t OnAction_Heartbeat(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 511 { | |
| 512 switch(heartbeatState) | |
| 513 { | |
| 514 case SENSOR_HB_OFFLINE: | |
| 515 HAL_UART_AbortReceive_IT(&UartHandle); | |
| 516 MX_UART_BT_Init_DMA(); | |
| 517 UART_StartDMARx(); | |
| 518 heartbeatState = SENSOR_HB_ENABLE_BLE; | |
| 519 startDetection_ms = HAL_GetTick(); | |
| 520 curBtIndex = 0; | |
| 521 memset(btDeviceList, 0, sizeof(btDeviceList)); | |
| 522 break; | |
| 523 | |
| 524 default: | |
| 525 break; | |
| 526 } | |
| 527 return UNSPECIFIC_RETURN; | |
| 528 } | |
| 529 | |
| 530 void cv_heartbeat_Control(void) | |
| 531 { | |
| 532 static uint8_t action = 0; | |
| 533 static uint8_t retry = 0; | |
| 534 static uint8_t lastState = 0; | |
| 535 char cmd[50]; | |
| 536 | |
| 537 cmd[0] = 0; | |
| 538 | |
| 539 if(action == 3) | |
| 540 { | |
| 541 action = 0; | |
| 542 switch(heartbeatState) | |
| 543 { | |
| 544 case SENSOR_HB_ENABLE_BLE: HAL_Delay(1000); | |
| 545 snprintf(cmd, sizeof(cmd), "+++" ); //"AT+UBTD=2,1,5000\r\n" | |
| 546 InfoLogger_writeLine((uint8_t*)cmd,3,1); | |
| 547 HAL_UART_Transmit(&UartHandle, (uint8_t*)cmd, 3, 5000); | |
| 548 HAL_Delay(1000); | |
| 549 cmd[0] = 0; | |
| 550 break; | |
| 551 case SENSOR_HB_CHECK_CONFIG: snprintf(cmd, sizeof(cmd), "AT+UBTCFG=2\r\n" ); // AT+UBTLE? | |
| 552 | |
| 553 #if 0 | |
| 554 if(settingsGetPointer()->dive_mode == DIVEMODE_OC) | |
| 555 { | |
| 556 snprintf(cmd, sizeof(cmd), "AT+UBTLE=2\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 557 } | |
| 558 else | |
| 559 { | |
| 560 snprintf(cmd, sizeof(cmd), "AT+UBTLE=3\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 561 } | |
| 562 #endif | |
| 563 break; | |
| 564 case SENSOR_HB_DISCOVER: if(lastState != SENSOR_HB_DISCOVER) | |
| 565 { | |
| 566 snprintf(cmd, sizeof(cmd), "AT+UBTD=2,1\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
567 curBtIndex = 0; |
| 1032 | 568 } |
| 569 | |
| 570 //snprintf(cmd, sizeof(cmd), "AT&W\r\n" ); // AT+UBTD=2,1\r\n "AT+UBTD=2,1,5000\r\n" | |
| 571 break; | |
| 572 #if 0 | |
| 573 case SENSOR_HB_RESTART: snprintf(cmd, sizeof(cmd), "AT+UBTD=2,1\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 574 | |
| 575 // snprintf(cmd, sizeof(cmd), "AT+CPWROFF\r\n" ); // AT+UBTD=2,1\r\n "AT+UBTD=2,1,5000\r\n" | |
| 576 break; | |
| 577 #endif | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
578 case SENSOR_HB_CONNECT: if(evaluateDevIndex < curBtIndex) |
| 1032 | 579 { |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
580 snprintf(cmd, sizeof(cmd), "AT+UBTACLC=%s\r\n",btDeviceList[evaluateDevIndex].address); |
| 1032 | 581 } |
| 582 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
583 case SENSOR_HB_DISCONNECT: snprintf(cmd, sizeof(cmd), "AT+UBTACLD=%c\r\n",connHandle); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
584 break; |
| 1032 | 585 case SENSOR_HB_SERVICES: if((connHandle >= '0') && (connHandle <= '9') && (lastState != SENSOR_HB_SERVICES)) |
| 586 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
587 snprintf(cmd, sizeof(cmd), "AT+UBTGDP=%c\r\n",connHandle); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
588 memset(curDeviceService, 0, sizeof(curDeviceService)); |
| 1032 | 589 } |
| 590 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
591 case SENSOR_HB_CHARACTERISTIC: snprintf(cmd, sizeof(cmd), "AT+UBTGDCS=%c,%s,%s\r\n",connHandle,curDeviceService[evaluateSrvIndex].start |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
592 ,curDeviceService[evaluateSrvIndex].end); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
593 memset(curDevCharacteristic, 0, sizeof(curDevCharacteristic)); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
594 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
595 case SENSOR_HB_DESCRIPTOR: snprintf(cmd, sizeof(cmd), "AT+UBTGDCD=%c,%s,%s\r\n",connHandle,curDevCharacteristic[evaluateCharIndex].valueHandle |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
596 ,curDeviceService[evaluateSrvIndex].end); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
597 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
598 case SENSOR_HB_SUBSCRIBE: snprintf(cmd, sizeof(cmd), "AT+UBTGWC=%c,%s,1\r\n",connHandle,curDevDescriptor.descHandle); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
599 break; |
| 1032 | 600 default: |
| 601 break; | |
| 602 } | |
| 603 if(cmd[0] != 0) | |
| 604 { | |
| 605 { | |
| 606 InfoLogger_writeLine((uint8_t*)cmd,strlen(cmd),1); | |
| 607 HAL_UART_Transmit(&UartHandle, (uint8_t*)cmd, strlen(cmd), 5000); | |
| 608 retry++; | |
| 609 if(retry == 3) | |
| 610 { | |
| 611 heartbeatState = SENSOR_HB_OFFLINE; | |
| 612 } | |
| 613 } | |
| 614 } | |
| 615 if(lastState != heartbeatState) | |
| 616 { | |
| 617 lastState = heartbeatState; | |
| 618 retry = 0; | |
| 619 } | |
| 620 } | |
| 621 else | |
| 622 { | |
| 623 action++; | |
| 624 } | |
| 625 } | |
| 626 void refresh_Heartbeat(void) | |
| 627 { | |
| 628 char text[32]; | |
| 629 uint8_t index = 0; | |
| 630 | |
| 631 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Pulse); | |
| 632 write_topline(text); | |
| 633 | |
| 634 switch(heartbeatState) | |
| 635 { | |
| 636 case SENSOR_HB_OFFLINE: | |
| 637 default: snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_SensorDetect); | |
| 638 write_label_var(30, 299, ME_Y_LINE1, &FontT48, text); | |
| 639 | |
| 640 if(curBtIndex > 0) | |
| 641 { | |
| 642 while((index < curBtIndex) && (index < 3)) | |
| 643 { | |
| 644 snprintf(text, 40, "%s", btDeviceList[index].address); | |
| 645 write_label_var( 30, 300, ME_Y_LINE3 + (index * ME_Y_LINE_STEP), &FontT48, text); | |
| 646 index++; | |
| 647 } | |
| 648 } | |
| 649 break; | |
| 650 case SENSOR_HB_ENABLE_BLE: snprintf(text, 32, "Activate BLE"); | |
| 651 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 652 break; | |
| 653 case SENSOR_HB_DISCOVER: | |
| 654 snprintf(text, 32, "Searching"); | |
| 655 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 656 | |
| 657 if(curBtIndex > 0) | |
| 658 { | |
| 659 while((index < curBtIndex) && (index < 4)) | |
| 660 { | |
| 661 snprintf(text, 40, "%s", btDeviceList[index].address); | |
| 662 write_label_var( 30, 300, ME_Y_LINE2 + (index * ME_Y_LINE_STEP), &FontT48, text); | |
| 663 index++; | |
| 664 } | |
| 665 } | |
| 666 break; | |
| 667 } | |
| 668 | |
| 669 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 670 } | |
| 1034 | 671 #endif |
