Mercurial > public > ostc4
annotate Discovery/Src/cv_heartbeat.c @ 1035:5b913cdaa9dc Puls_Integration
Degub message logger:
Added functionality to handle logger view (in case it is enabled via compile switch) like a normal t7 custom view.
| author | Ideenmodellierer |
|---|---|
| date | Sat, 09 Aug 2025 16:55:20 +0200 |
| parents | 195bfbdf961d |
| children |
| 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]; | |
| 1035 | 63 |
| 1034 | 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 uint8_t data = 0; | |
| 269 data = UART_getChar(); | |
| 270 | |
| 271 while((data != 0) && (complete == 0)) | |
| 272 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
273 if(curLineIndex == MAX_CHAR_PER_LINE - 1) /* avoid overflow */ |
| 1032 | 274 { |
| 275 InfoLogger_writeLine(curLine,curLineIndex,0); | |
| 276 memset(curLine,0,sizeof(curLine)); | |
| 277 curLineIndex = 0; | |
| 278 } | |
| 279 if((data == '\r') || (data == '\n')) | |
| 280 { | |
| 281 if(curLineIndex > 0) | |
| 282 { | |
| 283 InfoLogger_writeLine(curLine,curLineIndex,0); | |
| 284 if(strcmp((char*)curLine,"OK") == 0) | |
| 285 { | |
| 286 handleOK(); | |
| 287 } | |
| 288 else | |
| 289 { | |
| 290 if(strcmp((char*)curLine,"ERROR") == 0) | |
| 291 { | |
| 292 handleERROR(); | |
| 293 } | |
| 294 } | |
| 295 } | |
| 296 switch(readType) | |
| 297 { | |
| 298 case BT_READ_DEVICE_NAME: if(writeIndex < BLUEMOD_NAME_SIZE) | |
| 299 { | |
| 300 memcpy (btDeviceList[curBtIndex].name, parameter, writeIndex); | |
| 301 } | |
| 302 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
303 case BT_READ_SERV_UUID: if((writeIndex < 50) && (curServiceIndex < 10)) |
| 1032 | 304 { |
| 305 memcpy(curDeviceService[curServiceIndex].uuid, parameter, writeIndex); | |
| 306 } | |
| 307 curServiceIndex++; | |
| 308 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
309 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
|
310 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
311 memcpy(curDevCharacteristic[curCharacteristicIndex].uuid, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
312 curCharacteristicIndex++; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
313 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
314 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
315 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
|
316 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
317 memcpy(curDevDescriptor.uuid, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
318 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
319 break; |
| 1034 | 320 case BT_READ_PULSE_DATA: if(writeIndex < 50) |
| 321 { | |
| 322 parsePulseMeasurement(parameter, writeIndex); | |
| 323 } | |
| 324 break; | |
| 1032 | 325 default: |
| 326 break; | |
| 327 } | |
| 328 curLineIndex = 0; | |
| 329 writeIndex = 0; | |
| 330 memset(curLine,0,sizeof(curLine)); | |
| 331 readType = BT_READ_NOTHING; | |
| 332 } | |
| 333 else | |
| 334 { | |
| 335 if(curLineIndex < MAX_CHAR_PER_LINE) curLine[curLineIndex++] = data; | |
| 336 | |
| 337 if(data == ':') | |
| 338 { | |
| 339 switch(checkIndicators(curLine)) | |
| 340 { | |
| 341 case DEVICE_INDICATOR: readType = BT_READ_DEVICE_ADDR; | |
| 342 break; | |
| 343 case CONNECTION_INDICATOR: readType = BT_READ_CON_DETAILS; | |
| 344 break; | |
| 345 case SERVICE_INDICATOR: readType = BT_READ_SERV_HANDLE; | |
| 346 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
347 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
|
348 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
349 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
|
350 break; |
| 1034 | 351 case PULSE_INDICATOR: readType = BT_READ_PULSE_CONHANDLE; |
| 352 break; | |
| 1032 | 353 default: |
| 354 break; | |
| 355 } | |
| 356 writeIndex = 0; | |
| 357 memset(parameter,0,sizeof(parameter)); | |
| 358 } | |
| 359 else | |
| 360 { | |
| 361 if(data == ',') /* parameter end */ | |
| 362 { | |
| 363 switch(readType) | |
| 364 { | |
| 365 case BT_READ_DEVICE_ADDR: if(writeIndex < BLUEMOD_ADDR_SIZE-1) | |
| 366 { | |
| 367 if(firstDevice) | |
| 368 { | |
| 369 firstDevice = 0; | |
| 370 } | |
| 371 else | |
| 372 { | |
| 373 curBtIndex++; | |
| 374 } | |
| 375 parameter[writeIndex-1] = 0; /*remove 'p' from address */ | |
| 376 strcpy((char*)btDeviceList[curBtIndex].address, (char*)parameter); | |
| 377 } | |
| 378 readType = BT_READ_DEVICE_RSSI; | |
| 379 break; | |
| 380 case BT_READ_DEVICE_RSSI: if(writeIndex < BLUEMOD_RSSI_SIZE-1) | |
| 381 { | |
| 382 strcpy((char*)btDeviceList[curBtIndex].rssi, (char*)parameter); | |
| 383 } | |
| 384 readType = BT_READ_DEVICE_NAME; | |
| 385 break; | |
| 386 case BT_READ_DEVICE_NAME: if(writeIndex < BLUEMOD_NAME_SIZE-1) | |
| 387 { | |
| 388 memcpy(btDeviceList[curBtIndex].name, parameter, writeIndex); | |
| 389 } | |
| 390 readType = BT_READ_NOTHING; | |
| 391 break; | |
| 392 case BT_READ_CON_DETAILS: connHandle = parameter[0]; | |
| 393 heartbeatState = SENSOR_HB_SERVICES; | |
| 394 readType = BT_READ_NOTHING; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
395 curServiceIndex = 0; |
| 1032 | 396 break; |
| 397 case BT_READ_SERV_HANDLE: curDeviceService[curServiceIndex].handle = parameter[0]; | |
| 398 readType = BT_READ_SERV_START; | |
| 399 break; | |
| 400 case BT_READ_SERV_START: if(writeIndex < 6) | |
| 401 { | |
| 402 memcpy(curDeviceService[curServiceIndex].start, parameter, writeIndex); | |
| 403 } | |
| 404 readType = BT_READ_SERV_END; | |
| 405 break; | |
| 406 case BT_READ_SERV_END: if(writeIndex < 6) | |
| 407 { | |
| 408 memcpy(curDeviceService[curServiceIndex].end, parameter, writeIndex); | |
| 409 } | |
| 410 readType = BT_READ_SERV_UUID; | |
| 411 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
412 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
|
413 readType = BT_READ_CHAR_ATTRIBUTE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
414 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
415 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
|
416 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
417 memcpy(curDevCharacteristic[curCharacteristicIndex].attrHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
418 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
419 readType = BT_READ_CHAR_PROPERTY; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
420 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
421 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
|
422 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
423 memcpy(curDevCharacteristic[curCharacteristicIndex].properties, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
424 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
425 readType = BT_READ_CHAR_VALUEHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
426 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
427 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
|
428 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
429 memcpy(curDevCharacteristic[curCharacteristicIndex].valueHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
430 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
431 readType = BT_READ_CHAR_UUID; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
432 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
433 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
|
434 readType = BT_READ_DESC_CHARHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
435 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
436 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
|
437 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
438 memcpy(curDevDescriptor.charHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
439 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
440 readType = BT_READ_DESC_DESCHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
441 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
442 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
|
443 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
444 memcpy(curDevDescriptor.descHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
445 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
446 readType = BT_READ_DESC_UUID; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
447 break; |
| 1034 | 448 case BT_READ_PULSE_CONHANDLE: curDevDescriptor.conHandle = parameter[0]; |
| 449 readType = BT_READ_PULSE_VALUEHANDLE; | |
| 450 break; | |
| 451 case BT_READ_PULSE_VALUEHANDLE: if(writeIndex < 10) | |
| 452 { | |
| 453 // if(strcmp((char*)curDevCharacteristic[evaluateCharIndex].valueHandle,(char*) parameter) == 0) | |
| 454 { | |
| 455 readType = BT_READ_PULSE_DATA; | |
| 456 } | |
| 457 #if 0 | |
| 458 else | |
| 459 { | |
| 460 readType = BT_READ_NOTHING; | |
| 461 } | |
| 462 #endif | |
| 463 } | |
| 464 break; | |
| 1032 | 465 default: readType = BT_READ_NOTHING; |
| 466 break; | |
| 467 } | |
| 468 writeIndex = 0; | |
| 469 memset(parameter,0 , sizeof(parameter)); | |
| 470 } | |
| 471 else | |
| 472 { | |
| 1034 | 473 if(readType != BT_READ_NOTHING) |
| 1032 | 474 { |
| 475 parameter[writeIndex++] = data; | |
| 476 } | |
| 477 } | |
| 478 } | |
| 479 } | |
| 480 data = UART_getChar(); | |
| 481 } | |
| 482 return complete; | |
| 483 } | |
| 484 | |
| 485 sensorHeartbeat_State_t cv_heartbeat_getState() | |
| 486 { | |
| 487 return heartbeatState; | |
| 488 } | |
| 489 | |
| 490 void openEdit_Heartbeat(void) | |
| 491 { | |
| 492 char text[32]; | |
| 493 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Pulse); | |
| 494 write_topline(text); | |
| 495 | |
| 496 set_globalState(StMOption_Heartbeat); | |
| 497 resetMenuEdit(CLUT_MenuPageCvOption); | |
| 498 | |
| 499 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_SensorDetect); | |
| 500 write_field_button(StMOption_Heartbeat, 30, 299, ME_Y_LINE1, &FontT48, text); | |
| 501 | |
| 502 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 503 | |
| 504 setEvent(StMOption_Heartbeat, (uint32_t)OnAction_Heartbeat); | |
| 505 } | |
| 506 | |
| 507 static uint8_t OnAction_Heartbeat(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 508 { | |
| 509 switch(heartbeatState) | |
| 510 { | |
| 511 case SENSOR_HB_OFFLINE: | |
| 512 HAL_UART_AbortReceive_IT(&UartHandle); | |
| 513 MX_UART_BT_Init_DMA(); | |
| 514 UART_StartDMARx(); | |
| 515 heartbeatState = SENSOR_HB_ENABLE_BLE; | |
| 516 startDetection_ms = HAL_GetTick(); | |
| 517 curBtIndex = 0; | |
| 518 memset(btDeviceList, 0, sizeof(btDeviceList)); | |
| 519 break; | |
| 520 | |
| 521 default: | |
| 522 break; | |
| 523 } | |
| 524 return UNSPECIFIC_RETURN; | |
| 525 } | |
| 526 | |
| 527 void cv_heartbeat_Control(void) | |
| 528 { | |
| 529 static uint8_t action = 0; | |
| 530 static uint8_t retry = 0; | |
| 531 static uint8_t lastState = 0; | |
| 532 char cmd[50]; | |
| 533 | |
| 534 cmd[0] = 0; | |
| 535 | |
| 536 if(action == 3) | |
| 537 { | |
| 538 action = 0; | |
| 539 switch(heartbeatState) | |
| 540 { | |
| 541 case SENSOR_HB_ENABLE_BLE: HAL_Delay(1000); | |
| 542 snprintf(cmd, sizeof(cmd), "+++" ); //"AT+UBTD=2,1,5000\r\n" | |
| 543 InfoLogger_writeLine((uint8_t*)cmd,3,1); | |
| 544 HAL_UART_Transmit(&UartHandle, (uint8_t*)cmd, 3, 5000); | |
| 545 HAL_Delay(1000); | |
| 546 cmd[0] = 0; | |
| 547 break; | |
| 548 case SENSOR_HB_CHECK_CONFIG: snprintf(cmd, sizeof(cmd), "AT+UBTCFG=2\r\n" ); // AT+UBTLE? | |
| 549 | |
| 550 #if 0 | |
| 551 if(settingsGetPointer()->dive_mode == DIVEMODE_OC) | |
| 552 { | |
| 553 snprintf(cmd, sizeof(cmd), "AT+UBTLE=2\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 554 } | |
| 555 else | |
| 556 { | |
| 557 snprintf(cmd, sizeof(cmd), "AT+UBTLE=3\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 558 } | |
| 559 #endif | |
| 560 break; | |
| 561 case SENSOR_HB_DISCOVER: if(lastState != SENSOR_HB_DISCOVER) | |
| 562 { | |
| 563 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
|
564 curBtIndex = 0; |
| 1032 | 565 } |
| 566 | |
| 567 //snprintf(cmd, sizeof(cmd), "AT&W\r\n" ); // AT+UBTD=2,1\r\n "AT+UBTD=2,1,5000\r\n" | |
| 568 break; | |
| 569 #if 0 | |
| 570 case SENSOR_HB_RESTART: snprintf(cmd, sizeof(cmd), "AT+UBTD=2,1\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 571 | |
| 572 // snprintf(cmd, sizeof(cmd), "AT+CPWROFF\r\n" ); // AT+UBTD=2,1\r\n "AT+UBTD=2,1,5000\r\n" | |
| 573 break; | |
| 574 #endif | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
575 case SENSOR_HB_CONNECT: if(evaluateDevIndex < curBtIndex) |
| 1032 | 576 { |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
577 snprintf(cmd, sizeof(cmd), "AT+UBTACLC=%s\r\n",btDeviceList[evaluateDevIndex].address); |
| 1032 | 578 } |
| 579 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
580 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
|
581 break; |
| 1032 | 582 case SENSOR_HB_SERVICES: if((connHandle >= '0') && (connHandle <= '9') && (lastState != SENSOR_HB_SERVICES)) |
| 583 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
584 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
|
585 memset(curDeviceService, 0, sizeof(curDeviceService)); |
| 1032 | 586 } |
| 587 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
588 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
|
589 ,curDeviceService[evaluateSrvIndex].end); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
590 memset(curDevCharacteristic, 0, sizeof(curDevCharacteristic)); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
591 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
592 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
|
593 ,curDeviceService[evaluateSrvIndex].end); |
|
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_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
|
596 break; |
| 1032 | 597 default: |
| 598 break; | |
| 599 } | |
| 600 if(cmd[0] != 0) | |
| 601 { | |
| 602 { | |
| 603 InfoLogger_writeLine((uint8_t*)cmd,strlen(cmd),1); | |
| 604 HAL_UART_Transmit(&UartHandle, (uint8_t*)cmd, strlen(cmd), 5000); | |
| 605 retry++; | |
| 606 if(retry == 3) | |
| 607 { | |
| 608 heartbeatState = SENSOR_HB_OFFLINE; | |
| 609 } | |
| 610 } | |
| 611 } | |
| 612 if(lastState != heartbeatState) | |
| 613 { | |
| 614 lastState = heartbeatState; | |
| 615 retry = 0; | |
| 616 } | |
| 617 } | |
| 618 else | |
| 619 { | |
| 620 action++; | |
| 621 } | |
| 622 } | |
| 623 void refresh_Heartbeat(void) | |
| 624 { | |
| 625 char text[32]; | |
| 626 uint8_t index = 0; | |
| 627 | |
| 628 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Pulse); | |
| 629 write_topline(text); | |
| 630 | |
| 631 switch(heartbeatState) | |
| 632 { | |
| 633 case SENSOR_HB_OFFLINE: | |
| 634 default: snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_SensorDetect); | |
| 635 write_label_var(30, 299, ME_Y_LINE1, &FontT48, text); | |
| 636 | |
| 637 if(curBtIndex > 0) | |
| 638 { | |
| 639 while((index < curBtIndex) && (index < 3)) | |
| 640 { | |
| 641 snprintf(text, 40, "%s", btDeviceList[index].address); | |
| 642 write_label_var( 30, 300, ME_Y_LINE3 + (index * ME_Y_LINE_STEP), &FontT48, text); | |
| 643 index++; | |
| 644 } | |
| 645 } | |
| 646 break; | |
| 647 case SENSOR_HB_ENABLE_BLE: snprintf(text, 32, "Activate BLE"); | |
| 648 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 649 break; | |
| 650 case SENSOR_HB_DISCOVER: | |
| 651 snprintf(text, 32, "Searching"); | |
| 652 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 653 | |
| 654 if(curBtIndex > 0) | |
| 655 { | |
| 656 while((index < curBtIndex) && (index < 4)) | |
| 657 { | |
| 658 snprintf(text, 40, "%s", btDeviceList[index].address); | |
| 659 write_label_var( 30, 300, ME_Y_LINE2 + (index * ME_Y_LINE_STEP), &FontT48, text); | |
| 660 index++; | |
| 661 } | |
| 662 } | |
| 663 break; | |
| 664 } | |
| 665 | |
| 666 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 667 } | |
| 1034 | 668 #endif |
