annotate Discovery/Src/bonexConnect.c @ 84:e6abbef57475 kittz

Remove unusable code!!! prepare data for SPI in ONLY 1 IRQ!!!!
author Dmitry Romanov <kitt@bk.ru>
date Wed, 21 Nov 2018 10:25:15 +0300
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @copyright heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @file bonexConnect.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 29-Sept-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @version 0.2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @since 01-Okt-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief connect to bluetooth LTE of BonexInfoSystem
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * @bug
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * @warning
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 BLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 first of all:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 AT+LEROLE=1 // set BLE role of the device to Central
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 it is invisible and does not accept incoming BLE connections
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 then:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 AT+LESCAN
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 AT+LENAME=<bdaddr> request remote device name over BLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 ATD <brad>,TIO Initiate Bluetooth Link (for outgoing connections)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 #include "bonexConnect.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 #ifndef BONEXBLUETOOTH
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 void bonexControl(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 void bC_setConnectRequest(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 uint8_t bC_getStatus(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 return BC_DISCONNECTED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 uint8_t bC_getName(char *name)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 *name = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 uint8_t bC_getData(float *watt, float *temperature, uint16_t *drehzahl, uint8_t *residualcapacity)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 *watt = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 *temperature = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 *drehzahl = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 *residualcapacity = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 return BC_DISCONNECTED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 #else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #include "settings.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 #include "ostc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 #include "string.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 #include "data_central.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 union tempFloat16{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 uint16_t u16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 uint8_t u8[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 } temp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 void bC_connect(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 uint8_t bC_connect_sub_Search(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 uint8_t bC_connect_sub_Connect(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 void bC_call(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 void bC_evaluateData(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 /* Private variables with external access ------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 uint8_t status = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 uint8_t searchrequest = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 char nameOfScooter[20];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 uint8_t dataBuffer[9];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 uint8_t StartListeningToUARTscooter = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 float scooterWattstunden = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 float scooterTemperature = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 uint8_t scooterRestkapazitaet = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 uint16_t scooterDrehzahl = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 uint8_t bC_evaluateData(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 for
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 pStateReal->lifeData.wireless_data[i].data[j]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 uint8_t bC_getData(float *watt, float *temperature, uint16_t *drehzahl, uint8_t *residualcapacity)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 if(watt)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 *watt = scooterWattstunden;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 if(temperature)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 *temperature = scooterTemperature;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 if(drehzahl)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 *drehzahl = scooterDrehzahl;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 if(residualcapacity)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 *residualcapacity = scooterRestkapazitaet;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 uint8_t bC_getStatus(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 void bC_setConnectRequest(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 searchrequest = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 uint8_t bC_getName(char *name)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 if(status != BC_CONNECTED)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 *name = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 strncpy(name,nameOfScooter,20);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 name[19] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 return strlen(name);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 void bonexControl(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 static uint32_t time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 if(settingsGetPointer()->scooterControl == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 status = BC_DISCONNECTED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 if(settingsGetPointer()->bluetoothActive == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 status = BC_DISCONNECTED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 if(searchrequest)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 searchrequest = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 // maybe we have to disconnect first?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 bC_connect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 StartListeningToUARTscooter = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 if(status != BC_CONNECTED)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 time = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 if(UartReady == SET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 UartReady = RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 StartListeningToUARTscooter = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 bC_evaluateData();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 if(time_elapsed_ms(time, HAL_GetTick()) < 1000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 // test
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 const char request[4] = {0xA3, 5, 0, 0xA6};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 HAL_UART_Transmit(&UartHandle, (uint8_t*)request, 4, 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 time = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 if((UartReady == RESET) && StartListeningToUARTscooter)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 bC_call();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 time = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 void BONEX_to_16bit(uint16_t *dataOutUint16, int16_t *dataOutInt16, uint8_t *dataIn)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 union tempU16{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 int16_t i16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 uint16_t u16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 uint8_t u8[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 } temp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 temp.u8[0] = dataIn[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 temp.u8[1] = dataIn[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 if(dataOutUint16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 *dataOutUint16 = temp.u16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 if(dataOutInt16)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 *dataOutInt16 = temp.i16;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 void bC_evaluateData(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 uint8_t crc = dataBuffer[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 for(int i=1;i<=8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 crc ^= dataBuffer[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 if(crc != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 uint16_t watt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 int16_t temperatureL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 BONEX_to_16bit(&watt,0, &dataBuffer[1]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 BONEX_to_16bit(0,&temperatureL, &dataBuffer[4]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 BONEX_to_16bit(&scooterDrehzahl,0, &dataBuffer[6]);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 // scooterWattstunden = ((float)(dataBuffer[3]))/100;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 // scooterWattstunden += watt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 scooterWattstunden = watt; // neu ohne milliWattSekunden hw 160113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 scooterRestkapazitaet = dataBuffer[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 scooterTemperature = ((float)(temperatureL))/10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 aTxBuffer[0] = uartSendNext; // 0 UINT8_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 BONEX_16to8(&aTxBuffer[1],&WattStunden); // 1+2 LSB first UINT16_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 alt: aTxBuffer[3] = (uint8_t)(milliWattSekunden/36000);// 3 UINT8_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 neu: aTxBuffer[3] = (uint8_t)(RestKapazitaet); // 3 UINT8_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 BONEX_16to8(&aTxBuffer[4],&TemperaturLStufe); // 4+5 LSB first INT16_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 BONEX_16to8(&aTxBuffer[6],&DrehzahlNeu); // 6+7 LSB first UINT16_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 crc UINT8_T
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 void bC_call(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 const char request[4] = {0xA3, 1, 0, 0xA2};
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 uint8_t answer = BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 answer = HAL_UART_Transmit(&UartHandle, (uint8_t*)request, 4, 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 if(answer != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 StartListeningToUARTscooter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 answer = HAL_UART_Receive_IT(&UartHandle, dataBuffer, 9);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 void bC_connect(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 status = BC_SEARCHING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 uint8_t answer = BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 answer = BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 if(settingsGetPointer()->scooterDeviceAddress[0] == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 answer = bC_connect_sub_Search();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 if(answer == BONEX_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 answer = bC_connect_sub_Connect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 if(answer == BONEX_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 status = BC_CONNECTED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 status = BC_DISCONNECTED;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 uint8_t bC_connect_sub_Search(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 uint8_t answer = BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 char buffer[256];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 uint8_t bufferPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 uint8_t length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 uint32_t time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 char *startOfBONEXString;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 char *startOfRemoteDeviceAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 uint8_t okayNotSend;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 strncpy(buffer,"AT+BINQ\r",256);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 length = strlen(buffer);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 answer = HAL_UART_Transmit(&UartHandle, (uint8_t*)buffer, length, 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 time = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 bufferPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 okayNotSend = 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 while((time_elapsed_ms(time, HAL_GetTick()) < 20000) && (bufferPtr < 255) && (okayNotSend))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&buffer[bufferPtr], 1, 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 if(answer == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 switch(okayNotSend)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 case 1:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 if(buffer[bufferPtr] == '\n')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 okayNotSend = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 case 2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 if(buffer[bufferPtr] == '\r')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 okayNotSend = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 case 3:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 if(buffer[bufferPtr] == 'K')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 okayNotSend = 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 case 4:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 if(buffer[bufferPtr] == 'O')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 okayNotSend = 3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 case 5:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 if(buffer[bufferPtr] == '\n')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 okayNotSend = 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 case 6:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 if(buffer[bufferPtr] == '\r')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 okayNotSend = 5;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 okayNotSend = 6;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 bufferPtr++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 buffer[bufferPtr] = 0; // just for safety of search routines
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 length = bufferPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 if(length < 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 return BONEX_NOTFOUND;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 startOfBONEXString = strstr(buffer,"BONEX");
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 if(!startOfBONEXString)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 return BONEX_NOTFOUND;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 // copy to scooterDeviceAddress
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 startOfRemoteDeviceAddress = startOfBONEXString - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 while(startOfRemoteDeviceAddress >= buffer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 if(*startOfRemoteDeviceAddress == '\r')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 startOfRemoteDeviceAddress--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 startOfBONEXString = 0; // for strrchr
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 startOfRemoteDeviceAddress = strrchr(buffer, '\r');
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 // first in list?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 if(!startOfRemoteDeviceAddress)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 startOfRemoteDeviceAddress = buffer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 startOfRemoteDeviceAddress += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 if(*startOfRemoteDeviceAddress == '\n')
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 startOfRemoteDeviceAddress += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 strncpy(settingsGetPointer()->scooterDeviceAddress, startOfRemoteDeviceAddress, 12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 for(int i=0;i<19;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 if((startOfBONEXString[i] == 0) || (startOfBONEXString[i] == '\r'))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 settingsGetPointer()->scooterDeviceName[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 settingsGetPointer()->scooterDeviceName[i] = startOfBONEXString[i];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 return BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 uint8_t bC_connect_sub_Connect(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 uint8_t answer = BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 char buffer2[256];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 uint8_t bufferPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 uint8_t length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 uint32_t time;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 strncpy(buffer2,"ATD ",256);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 length = strlen(buffer2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 strncpy(&buffer2[length], settingsGetPointer()->scooterDeviceAddress, 12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 length += 12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 buffer2[length++] = '\r';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 buffer2[length++] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 answer = HAL_UART_Transmit(&UartHandle, (uint8_t*)buffer2, length, 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 time = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 bufferPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 while((time_elapsed_ms(time, HAL_GetTick()) < 5000) && (bufferPtr < 255))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&buffer2[bufferPtr], 1, 1000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 if(answer == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 bufferPtr++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 if(bufferPtr < 7)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 return BONEX_NOTFOUND;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 if(strstr(buffer2,"CONNECT"))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 strncpy(nameOfScooter, settingsGetPointer()->scooterDeviceName, 19);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 nameOfScooter[19] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 return BONEX_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 return BONEX_NOCONNECT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 #endif // BONEXBLUETOOTH
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/