Mercurial > public > ostc4
annotate Discovery/Src/cv_heartbeat.c @ 1033:5f66e44d69f0 Puls_Integration
Added functionality needed for subscription of standard Bluetooth pulse service notifications
| author | Ideenmodellierer |
|---|---|
| date | Sat, 02 Aug 2025 22:42:51 +0200 |
| parents | 33b91584d827 |
| children | 195bfbdf961d |
| 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 | |
| 27 #include "cv_heartbeat.h" | |
| 28 #include "tMenuEdit.h" | |
| 29 | |
| 30 #include "gfx_fonts.h" | |
| 31 #include "tHome.h" | |
| 32 #include "ostc.h" | |
| 33 #include "tComm.h" | |
| 34 #include "tInfoLogger.h" | |
| 35 | |
| 36 static sensorHeartbeat_State_t heartbeatState = SENSOR_HB_OFFLINE; | |
| 37 | |
| 38 static uint8_t OnAction_Heartbeat(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action); | |
| 39 static uint32_t startDetection_ms; | |
| 40 | |
| 41 #define MAX_BT_DEVICE 10 /* max number of device which may be handled */ | |
| 42 static btDdeviceData_t btDeviceList[MAX_BT_DEVICE]; | |
| 43 static btDeviceService_t curDeviceService[10]; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
44 static btDeviceCharacteristic_t curDevCharacteristic[10]; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
45 static btDeviceDescriptor_t curDevDescriptor; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
46 |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
47 |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
48 static uint8_t curCharacteristicIndex = 0; |
| 1032 | 49 static uint8_t curServiceIndex = 0; |
| 50 static uint8_t curBtIndex = 0; | |
| 51 static uint8_t connHandle = ' '; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
52 static uint8_t evaluateDevIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
53 static uint8_t evaluateSrvIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
54 static uint8_t evaluateCharIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
55 static uint8_t evaluateDescIndex = 0xFF; |
| 1032 | 56 |
| 57 static indicatior_t checkIndicators(uint8_t* pdata) | |
| 58 { | |
| 59 indicatior_t ret = NO_INDICATOR; | |
| 60 | |
| 61 if(strcmp((char*)pdata,"+UBTD:") == 0) | |
| 62 { | |
| 63 ret = DEVICE_INDICATOR; | |
| 64 } | |
| 65 else if(strcmp((char*)pdata,"+UUBTACLC:") == 0) | |
| 66 { | |
| 67 ret = CONNECTION_INDICATOR; | |
| 68 } | |
| 69 else if(strcmp((char*)pdata,"+UBTGDP:") == 0) | |
| 70 { | |
| 71 ret = SERVICE_INDICATOR; | |
| 72 } | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
73 else if(strcmp((char*)pdata,"+UBTGDCS:") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
74 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
75 ret = CHARACTERISTIC_INDICATOR; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
76 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
77 else if(strcmp((char*)pdata,"+UBTGDCD:") == 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
78 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
79 ret = DESCRIPTOR_INDICATOR; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
80 } |
| 1032 | 81 |
| 82 return ret; | |
| 83 } | |
| 84 | |
| 85 static void handleOK() | |
| 86 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
87 uint8_t index = 0; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
88 |
| 1032 | 89 switch(heartbeatState) |
| 90 { | |
| 91 case SENSOR_HB_ENABLE_BLE: heartbeatState = SENSOR_HB_CHECK_CONFIG; | |
| 92 break; | |
| 93 case SENSOR_HB_CHECK_CONFIG: heartbeatState = SENSOR_HB_DISCOVER; | |
| 94 break; | |
| 95 case SENSOR_HB_RESTART: heartbeatState = SENSOR_HB_OFFLINE; | |
| 96 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
97 case SENSOR_HB_DISCOVER: if(curBtIndex > 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
98 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
99 heartbeatState = SENSOR_HB_CONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
100 evaluateDevIndex = 0; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
101 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
102 else |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
103 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
104 heartbeatState = SENSOR_HB_OFFLINE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
105 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
106 |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
107 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
108 case SENSOR_HB_SERVICES: evaluateSrvIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
109 if(curServiceIndex != 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
110 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
111 for(index = 0; index <= curServiceIndex; index++) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
112 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
113 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
|
114 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
115 heartbeatState = SENSOR_HB_CHARACTERISTIC; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
116 evaluateSrvIndex = index; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
117 curCharacteristicIndex = 0; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
118 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
119 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
120 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
121 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
122 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
|
123 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
124 heartbeatState = SENSOR_HB_DISCONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
125 } |
| 1032 | 126 break; |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
127 case SENSOR_HB_CHARACTERISTIC: evaluateCharIndex = 0xFF; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
128 if(curCharacteristicIndex != 0) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
129 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
130 for(index = 0; index < curCharacteristicIndex; index++) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
131 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
132 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
|
133 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
134 heartbeatState = SENSOR_HB_DESCRIPTOR; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
135 evaluateCharIndex = index; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
136 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
137 } |
|
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 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
140 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
|
141 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
142 heartbeatState = SENSOR_HB_DISCONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
143 } |
| 1032 | 144 break; |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
145 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
|
146 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
147 heartbeatState = SENSOR_HB_SUBSCRIBE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
148 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
149 else |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
150 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
151 heartbeatState = SENSOR_HB_DISCONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
152 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
153 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
154 case SENSOR_HB_DISCONNECT: evaluateDevIndex++; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
155 connHandle= ' '; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
156 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
|
157 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
158 heartbeatState = SENSOR_HB_CONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
159 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
160 else |
|
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_OFFLINE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
163 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
164 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
165 case SENSOR_HB_CONNECT: /* handled in data rx section */ |
| 1032 | 166 default: |
| 167 break; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 static void handleERROR() | |
| 172 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
173 switch(heartbeatState) |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
174 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
175 case SENSOR_HB_DISCONNECT: evaluateDevIndex++; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
176 connHandle= ' '; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
177 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
|
178 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
179 heartbeatState = SENSOR_HB_CONNECT; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
180 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
181 else |
|
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 heartbeatState = SENSOR_HB_OFFLINE; |
|
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 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
186 default: |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
187 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
188 } |
| 1032 | 189 } |
| 190 | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
191 uint8_t cv_heartbeat_HandleData() |
| 1032 | 192 { |
| 193 static uint8_t firstDevice = 1; | |
| 194 static uint8_t curLine[MAX_CHAR_PER_LINE]; /* holds complete line and is used for logging */ | |
| 195 static uint8_t curLineIndex = 0; | |
| 196 static uint8_t parameter[40]; /* content of the parameter in read state */ | |
| 197 static uint8_t writeIndex = 0; | |
| 198 static uint8_t complete = 0; | |
| 199 | |
| 200 static readDataType_t readType = BT_READ_NOTHING; | |
| 201 | |
| 202 char text[40]; | |
| 203 uint8_t data = 0; | |
| 204 data = UART_getChar(); | |
| 205 | |
| 206 while((data != 0) && (complete == 0)) | |
| 207 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
208 if(curLineIndex == MAX_CHAR_PER_LINE - 1) /* avoid overflow */ |
| 1032 | 209 { |
| 210 InfoLogger_writeLine(curLine,curLineIndex,0); | |
| 211 memset(curLine,0,sizeof(curLine)); | |
| 212 curLineIndex = 0; | |
| 213 } | |
| 214 if((data == '\r') || (data == '\n')) | |
| 215 { | |
| 216 if(curLineIndex > 0) | |
| 217 { | |
| 218 InfoLogger_writeLine(curLine,curLineIndex,0); | |
| 219 if(strcmp((char*)curLine,"OK") == 0) | |
| 220 { | |
| 221 handleOK(); | |
| 222 } | |
| 223 else | |
| 224 { | |
| 225 if(strcmp((char*)curLine,"ERROR") == 0) | |
| 226 { | |
| 227 handleERROR(); | |
| 228 } | |
| 229 } | |
| 230 } | |
| 231 switch(readType) | |
| 232 { | |
| 233 case BT_READ_DEVICE_NAME: if(writeIndex < BLUEMOD_NAME_SIZE) | |
| 234 { | |
| 235 memcpy (btDeviceList[curBtIndex].name, parameter, writeIndex); | |
| 236 } | |
| 237 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
238 case BT_READ_SERV_UUID: if((writeIndex < 50) && (curServiceIndex < 10)) |
| 1032 | 239 { |
| 240 memcpy(curDeviceService[curServiceIndex].uuid, parameter, writeIndex); | |
| 241 } | |
| 242 curServiceIndex++; | |
| 243 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
244 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
|
245 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
246 memcpy(curDevCharacteristic[curCharacteristicIndex].uuid, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
247 curCharacteristicIndex++; |
|
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 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
250 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
|
251 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
252 memcpy(curDevDescriptor.uuid, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
253 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
254 break; |
| 1032 | 255 default: |
| 256 break; | |
| 257 } | |
| 258 curLineIndex = 0; | |
| 259 writeIndex = 0; | |
| 260 memset(curLine,0,sizeof(curLine)); | |
| 261 readType = BT_READ_NOTHING; | |
| 262 } | |
| 263 else | |
| 264 { | |
| 265 if(curLineIndex < MAX_CHAR_PER_LINE) curLine[curLineIndex++] = data; | |
| 266 | |
| 267 if(data == ':') | |
| 268 { | |
| 269 switch(checkIndicators(curLine)) | |
| 270 { | |
| 271 case DEVICE_INDICATOR: readType = BT_READ_DEVICE_ADDR; | |
| 272 break; | |
| 273 case CONNECTION_INDICATOR: readType = BT_READ_CON_DETAILS; | |
| 274 break; | |
| 275 case SERVICE_INDICATOR: readType = BT_READ_SERV_HANDLE; | |
| 276 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
277 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
|
278 // snprintf(text,40,"Found Char"); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
279 // InfoLogger_writeLine((uint8_t*)text,strlen(text),0); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
280 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
281 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
|
282 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
283 |
| 1032 | 284 default: |
| 285 break; | |
| 286 } | |
| 287 writeIndex = 0; | |
| 288 memset(parameter,0,sizeof(parameter)); | |
| 289 } | |
| 290 else | |
| 291 { | |
| 292 if(data == ',') /* parameter end */ | |
| 293 { | |
| 294 switch(readType) | |
| 295 { | |
| 296 case BT_READ_DEVICE_ADDR: if(writeIndex < BLUEMOD_ADDR_SIZE-1) | |
| 297 { | |
| 298 if(firstDevice) | |
| 299 { | |
| 300 firstDevice = 0; | |
| 301 } | |
| 302 else | |
| 303 { | |
| 304 curBtIndex++; | |
| 305 } | |
| 306 parameter[writeIndex-1] = 0; /*remove 'p' from address */ | |
| 307 strcpy((char*)btDeviceList[curBtIndex].address, (char*)parameter); | |
| 308 } | |
| 309 readType = BT_READ_DEVICE_RSSI; | |
| 310 break; | |
| 311 case BT_READ_DEVICE_RSSI: if(writeIndex < BLUEMOD_RSSI_SIZE-1) | |
| 312 { | |
| 313 strcpy((char*)btDeviceList[curBtIndex].rssi, (char*)parameter); | |
| 314 } | |
| 315 readType = BT_READ_DEVICE_NAME; | |
| 316 break; | |
| 317 case BT_READ_DEVICE_NAME: if(writeIndex < BLUEMOD_NAME_SIZE-1) | |
| 318 { | |
| 319 memcpy(btDeviceList[curBtIndex].name, parameter, writeIndex); | |
| 320 } | |
| 321 readType = BT_READ_NOTHING; | |
| 322 break; | |
| 323 case BT_READ_CON_DETAILS: connHandle = parameter[0]; | |
| 324 heartbeatState = SENSOR_HB_SERVICES; | |
| 325 readType = BT_READ_NOTHING; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
326 curServiceIndex = 0; |
| 1032 | 327 break; |
| 328 case BT_READ_SERV_HANDLE: curDeviceService[curServiceIndex].handle = parameter[0]; | |
| 329 readType = BT_READ_SERV_START; | |
| 330 break; | |
| 331 case BT_READ_SERV_START: if(writeIndex < 6) | |
| 332 { | |
| 333 memcpy(curDeviceService[curServiceIndex].start, parameter, writeIndex); | |
| 334 } | |
| 335 readType = BT_READ_SERV_END; | |
| 336 break; | |
| 337 case BT_READ_SERV_END: if(writeIndex < 6) | |
| 338 { | |
| 339 memcpy(curDeviceService[curServiceIndex].end, parameter, writeIndex); | |
| 340 } | |
| 341 readType = BT_READ_SERV_UUID; | |
| 342 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
343 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
|
344 readType = BT_READ_CHAR_ATTRIBUTE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
345 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
346 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
|
347 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
348 memcpy(curDevCharacteristic[curCharacteristicIndex].attrHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
349 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
350 readType = BT_READ_CHAR_PROPERTY; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
351 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
352 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
|
353 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
354 memcpy(curDevCharacteristic[curCharacteristicIndex].properties, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
355 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
356 readType = BT_READ_CHAR_VALUEHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
357 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
358 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
|
359 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
360 memcpy(curDevCharacteristic[curCharacteristicIndex].valueHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
361 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
362 readType = BT_READ_CHAR_UUID; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
363 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
364 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
|
365 readType = BT_READ_DESC_CHARHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
366 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
367 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
|
368 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
369 memcpy(curDevDescriptor.charHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
370 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
371 readType = BT_READ_DESC_DESCHANDLE; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
372 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
373 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
|
374 { |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
375 memcpy(curDevDescriptor.descHandle, parameter, writeIndex); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
376 } |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
377 readType = BT_READ_DESC_UUID; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
378 break; |
| 1032 | 379 default: readType = BT_READ_NOTHING; |
| 380 break; | |
| 381 } | |
| 382 writeIndex = 0; | |
| 383 memset(parameter,0 , sizeof(parameter)); | |
| 384 } | |
| 385 else | |
| 386 { | |
| 387 // if(readType != BT_READ_NOTHING) | |
| 388 { | |
| 389 parameter[writeIndex++] = data; | |
| 390 } | |
| 391 } | |
| 392 } | |
| 393 } | |
| 394 data = UART_getChar(); | |
| 395 } | |
| 396 return complete; | |
| 397 } | |
| 398 | |
| 399 sensorHeartbeat_State_t cv_heartbeat_getState() | |
| 400 { | |
| 401 return heartbeatState; | |
| 402 } | |
| 403 | |
| 404 void openEdit_Heartbeat(void) | |
| 405 { | |
| 406 SSettings *settings = settingsGetPointer(); | |
| 407 | |
| 408 char text[32]; | |
| 409 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Pulse); | |
| 410 write_topline(text); | |
| 411 | |
| 412 set_globalState(StMOption_Heartbeat); | |
| 413 resetMenuEdit(CLUT_MenuPageCvOption); | |
| 414 | |
| 415 snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_SensorDetect); | |
| 416 write_field_button(StMOption_Heartbeat, 30, 299, ME_Y_LINE1, &FontT48, text); | |
| 417 | |
| 418 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 419 | |
| 420 setEvent(StMOption_Heartbeat, (uint32_t)OnAction_Heartbeat); | |
| 421 } | |
| 422 | |
| 423 static uint8_t OnAction_Heartbeat(uint32_t editId, uint8_t blockNumber, uint8_t digitNumber, uint8_t digitContent, uint8_t action) | |
| 424 { | |
| 425 switch(heartbeatState) | |
| 426 { | |
| 427 case SENSOR_HB_OFFLINE: | |
| 428 HAL_UART_AbortReceive_IT(&UartHandle); | |
| 429 MX_UART_BT_Init_DMA(); | |
| 430 UART_StartDMARx(); | |
| 431 heartbeatState = SENSOR_HB_ENABLE_BLE; | |
| 432 startDetection_ms = HAL_GetTick(); | |
| 433 curBtIndex = 0; | |
| 434 memset(btDeviceList, 0, sizeof(btDeviceList)); | |
| 435 break; | |
| 436 | |
| 437 default: | |
| 438 break; | |
| 439 } | |
| 440 return UNSPECIFIC_RETURN; | |
| 441 } | |
| 442 | |
| 443 void cv_heartbeat_Control(void) | |
| 444 { | |
| 445 static uint8_t action = 0; | |
| 446 static uint8_t retry = 0; | |
| 447 static uint8_t lastState = 0; | |
| 448 char cmd[50]; | |
| 449 | |
| 450 cmd[0] = 0; | |
| 451 | |
| 452 if(action == 3) | |
| 453 { | |
| 454 action = 0; | |
| 455 switch(heartbeatState) | |
| 456 { | |
| 457 case SENSOR_HB_ENABLE_BLE: HAL_Delay(1000); | |
| 458 snprintf(cmd, sizeof(cmd), "+++" ); //"AT+UBTD=2,1,5000\r\n" | |
| 459 InfoLogger_writeLine((uint8_t*)cmd,3,1); | |
| 460 HAL_UART_Transmit(&UartHandle, (uint8_t*)cmd, 3, 5000); | |
| 461 HAL_Delay(1000); | |
| 462 cmd[0] = 0; | |
| 463 break; | |
| 464 case SENSOR_HB_CHECK_CONFIG: snprintf(cmd, sizeof(cmd), "AT+UBTCFG=2\r\n" ); // AT+UBTLE? | |
| 465 | |
| 466 #if 0 | |
| 467 if(settingsGetPointer()->dive_mode == DIVEMODE_OC) | |
| 468 { | |
| 469 snprintf(cmd, sizeof(cmd), "AT+UBTLE=2\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 470 } | |
| 471 else | |
| 472 { | |
| 473 snprintf(cmd, sizeof(cmd), "AT+UBTLE=3\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 474 } | |
| 475 #endif | |
| 476 break; | |
| 477 case SENSOR_HB_DISCOVER: if(lastState != SENSOR_HB_DISCOVER) | |
| 478 { | |
| 479 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
|
480 curBtIndex = 0; |
| 1032 | 481 } |
| 482 | |
| 483 //snprintf(cmd, sizeof(cmd), "AT&W\r\n" ); // AT+UBTD=2,1\r\n "AT+UBTD=2,1,5000\r\n" | |
| 484 break; | |
| 485 #if 0 | |
| 486 case SENSOR_HB_RESTART: snprintf(cmd, sizeof(cmd), "AT+UBTD=2,1\r\n" ); //+UBTLE=1 //"AT+UBTD=2,1,5000\r\n" | |
| 487 | |
| 488 // snprintf(cmd, sizeof(cmd), "AT+CPWROFF\r\n" ); // AT+UBTD=2,1\r\n "AT+UBTD=2,1,5000\r\n" | |
| 489 break; | |
| 490 #endif | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
491 case SENSOR_HB_CONNECT: if(evaluateDevIndex < curBtIndex) |
| 1032 | 492 { |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
493 snprintf(cmd, sizeof(cmd), "AT+UBTACLC=%s\r\n",btDeviceList[evaluateDevIndex].address); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
494 // evaluateDevIndex = devicesIndex; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
495 // devicesIndex++; |
| 1032 | 496 } |
| 497 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
498 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
|
499 break; |
| 1032 | 500 case SENSOR_HB_SERVICES: if((connHandle >= '0') && (connHandle <= '9') && (lastState != SENSOR_HB_SERVICES)) |
| 501 { | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
502 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
|
503 memset(curDeviceService, 0, sizeof(curDeviceService)); |
| 1032 | 504 } |
| 505 break; | |
|
1033
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
506 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
|
507 ,curDeviceService[evaluateSrvIndex].end); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
508 memset(curDevCharacteristic, 0, sizeof(curDevCharacteristic)); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
509 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
510 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
|
511 ,curDeviceService[evaluateSrvIndex].end); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
512 //memset(curDevDescriptor, 0, sizeof(curDevCharacteristic)); |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
513 break; |
|
5f66e44d69f0
Added functionality needed for subscription of standard Bluetooth pulse service notifications
Ideenmodellierer
parents:
1032
diff
changeset
|
514 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
|
515 break; |
| 1032 | 516 default: |
| 517 break; | |
| 518 } | |
| 519 if(cmd[0] != 0) | |
| 520 { | |
| 521 { | |
| 522 InfoLogger_writeLine((uint8_t*)cmd,strlen(cmd),1); | |
| 523 HAL_UART_Transmit(&UartHandle, (uint8_t*)cmd, strlen(cmd), 5000); | |
| 524 retry++; | |
| 525 if(retry == 3) | |
| 526 { | |
| 527 heartbeatState = SENSOR_HB_OFFLINE; | |
| 528 } | |
| 529 } | |
| 530 } | |
| 531 if(lastState != heartbeatState) | |
| 532 { | |
| 533 lastState = heartbeatState; | |
| 534 retry = 0; | |
| 535 } | |
| 536 } | |
| 537 else | |
| 538 { | |
| 539 action++; | |
| 540 } | |
| 541 } | |
| 542 void refresh_Heartbeat(void) | |
| 543 { | |
| 544 char text[32]; | |
| 545 uint8_t index = 0; | |
| 546 | |
| 547 snprintf(text, 32, "\001%c%c", TXT_2BYTE, TXT2BYTE_Pulse); | |
| 548 write_topline(text); | |
| 549 | |
| 550 switch(heartbeatState) | |
| 551 { | |
| 552 case SENSOR_HB_OFFLINE: | |
| 553 default: snprintf(text, 32, "%c%c", TXT_2BYTE, TXT2BYTE_SensorDetect); | |
| 554 write_label_var(30, 299, ME_Y_LINE1, &FontT48, text); | |
| 555 | |
| 556 if(curBtIndex > 0) | |
| 557 { | |
| 558 while((index < curBtIndex) && (index < 3)) | |
| 559 { | |
| 560 snprintf(text, 40, "%s", btDeviceList[index].address); | |
| 561 write_label_var( 30, 300, ME_Y_LINE3 + (index * ME_Y_LINE_STEP), &FontT48, text); | |
| 562 index++; | |
| 563 } | |
| 564 } | |
| 565 break; | |
| 566 case SENSOR_HB_ENABLE_BLE: snprintf(text, 32, "Activate BLE"); | |
| 567 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 568 break; | |
| 569 case SENSOR_HB_DISCOVER: | |
| 570 snprintf(text, 32, "Searching"); | |
| 571 write_label_var( 30, 300, ME_Y_LINE1, &FontT48, text); | |
| 572 | |
| 573 if(curBtIndex > 0) | |
| 574 { | |
| 575 while((index < curBtIndex) && (index < 4)) | |
| 576 { | |
| 577 snprintf(text, 40, "%s", btDeviceList[index].address); | |
| 578 write_label_var( 30, 300, ME_Y_LINE2 + (index * ME_Y_LINE_STEP), &FontT48, text); | |
| 579 index++; | |
| 580 } | |
| 581 } | |
| 582 break; | |
| 583 } | |
| 584 | |
| 585 write_buttonTextline(TXT2BYTE_ButtonMinus, TXT2BYTE_ButtonEnter, TXT2BYTE_ButtonPlus); | |
| 586 } | |
| 587 |
