2971 |
jichapav |
1 |
/* |
|
|
2 |
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio |
|
|
3 |
|
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
5 |
you may not use this file except in compliance with the License. |
|
|
6 |
You may obtain a copy of the License at |
|
|
7 |
|
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0 |
|
|
9 |
|
|
|
10 |
Unless required by applicable law or agreed to in writing, software |
|
|
11 |
distributed under the License is distributed on an "AS IS" BASIS, |
|
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
13 |
See the License for the specific language governing permissions and |
|
|
14 |
limitations under the License. |
|
|
15 |
*/ |
|
|
16 |
|
|
|
17 |
#include "ch.h" |
|
|
18 |
#include "hal.h" |
|
|
19 |
#include "test.h" |
|
|
20 |
#include "serial.h" |
|
|
21 |
#include "gpt.h" |
|
|
22 |
#include <string.h> |
|
|
23 |
#include "keil/GPS_dekoduj.h" |
|
|
24 |
#include <../../os/various/chprintf.h> |
|
|
25 |
#include <chstreams.h.> |
|
|
26 |
|
|
|
27 |
/*MAX delka prikazu, ktery uzivatel muze zadat*/ |
|
|
28 |
#define MAX_DELKA_PRIKAZU 10 |
|
|
29 |
|
|
|
30 |
/*Velikost GPS bufferu*/ |
|
|
31 |
#define GPS_BUFFER 500 |
|
|
32 |
#define PWM_PERIODA_NORMAL 20000 |
|
|
33 |
#define PWM_SIRKA_NORMAL PWM_PERIODA_NORMAL/2 |
|
|
34 |
|
|
|
35 |
/*Pocet opakovani pro jednotlive faze odpalu (pocet = cas[s]*8) pro kompenzaci 8xrychlejsiho casovace na desce STM32F10xRxT01A */ |
|
|
36 |
#define POCET_VENTIL (5*8) |
2972 |
jichapav |
37 |
#define POCET_LIS (1*8) |
|
|
38 |
#define POCET_ZATAVENI (2*8) |
|
|
39 |
#define POCET_STRECHA (5*8) |
2971 |
jichapav |
40 |
#define CEKANI_NA_STRECHU (10*8) |
|
|
41 |
#define CEKANI_NA_LIS (10*8) |
|
|
42 |
|
|
|
43 |
/*makra pro cteni switch sensoru*/ |
|
|
44 |
#define CTI_STRECHU palReadPad(STRECHA_SENS_PORT, STRECHA_SENS_STATE) |
|
|
45 |
#define CTI_LIS palReadPad(LIS_SENS_PORT, LIS_SENS_STATE) |
|
|
46 |
|
|
|
47 |
extern NMEA_GPGGA GPGGA_informace; |
|
|
48 |
Thread *tp_odpal = NULL; |
2972 |
jichapav |
49 |
uint8_t uvitaci_zprava[] = "\r\n\r\n* * * * * * * * * * * * * * * * * * * * * * * * * *\r\nVita vas Automaticky Vypoustec Meteobalonu 1.1\r\nZapojeni vyvodu:\r\n\tGPIOB10 - strecha\r\n\tGPIOB11 - ventil\r\n\tGPIOB12 - lis\r\n\tGPIOB13 - zataveni/odpojeni\r\nPrikazy:\r\n\t<odpal> zahajeni sekvence vypousteni\n\r\t<zrus> zruseni vypousteni\n\r\t<help> napoveda\r\n* * * * * * * * * * * * * * * * * * * * * * * * * *\r\n\r\n"; |
2971 |
jichapav |
50 |
|
|
|
51 |
//static PWMConfig pwmcfg = { |
|
|
52 |
//10000, /* 10kHz PWM clock frequency. */ |
|
|
53 |
//PWM_PERIODA_NORMAL, /* PWM period 1S (in ticks). */ |
|
|
54 |
/*NULL, |
|
|
55 |
{ |
|
|
56 |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, |
|
|
57 |
{PWM_OUTPUT_ACTIVE_HIGH, NULL}, |
|
|
58 |
{PWM_OUTPUT_DISABLED, NULL}, |
|
|
59 |
{PWM_OUTPUT_DISABLED, NULL} |
|
|
60 |
}, |
|
|
61 |
HW dependent part.*/ |
|
|
62 |
//0 |
|
|
63 |
//}; |
|
|
64 |
|
|
|
65 |
/* |
|
|
66 |
* Konfigurace USART2 |
|
|
67 |
*/ |
|
|
68 |
|
|
|
69 |
static const SerialConfig USART2_config = |
|
|
70 |
{ |
|
|
71 |
/*Speed*/ |
|
|
72 |
9600, |
|
|
73 |
/*Initialization value for the CR1 register.*/ |
|
|
74 |
0, |
|
|
75 |
/*Initialization value for the CR2 register.*/ |
|
|
76 |
USART_CR2_STOP1_BITS | USART_CR2_LINEN, |
|
|
77 |
/*Initialization value for the CR3 register.*/ |
|
|
78 |
|
|
|
79 |
}; |
|
|
80 |
|
|
|
81 |
|
|
|
82 |
/* |
|
|
83 |
* GPT2 callback. |
|
|
84 |
*/ |
|
|
85 |
static void gpt2cb(GPTDriver *gptp) |
|
|
86 |
{ |
|
|
87 |
(void)gptp; |
|
|
88 |
/* Wakes up the thread.*/ |
|
|
89 |
chSysLockFromIsr(); |
|
|
90 |
if (tp_odpal != NULL) { |
|
|
91 |
tp_odpal->p_u.rdymsg = (msg_t)50; /* Znaci, ze se vlakno probouzi kvuli preruseni od GPT*/ |
|
|
92 |
chSchReadyI(tp_odpal); |
|
|
93 |
tp_odpal = NULL; |
|
|
94 |
} |
|
|
95 |
chSysUnlockFromIsr(); |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
/* |
|
|
100 |
*Konfigurace casovace 2 |
|
|
101 |
*/ |
|
|
102 |
static const GPTConfig gpt2cfg = |
|
|
103 |
{ |
|
|
104 |
500, /*500 Hz ? (puvodne 1000Hz) f*/ |
|
|
105 |
gpt2cb /*callback fce*/ |
|
|
106 |
}; |
|
|
107 |
|
|
|
108 |
/* |
|
|
109 |
* Vlakno pro blikani diodou |
|
|
110 |
*/ |
|
|
111 |
static WORKING_AREA(waThread1, 128); |
|
|
112 |
static msg_t Thread1(void *arg) { |
|
|
113 |
(void)arg; |
|
|
114 |
chRegSetThreadName("blinker"); |
|
|
115 |
while (TRUE) { |
|
|
116 |
palClearPad(GPIOB, GPIOB_LED4); |
|
|
117 |
chThdSleepMilliseconds(500); |
|
|
118 |
palSetPad(GPIOB, GPIOB_LED4); |
|
|
119 |
chThdSleepMilliseconds(500); |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
|
|
|
123 |
/* |
|
|
124 |
* Vlakno pro ovladani odpalovaci sekvence |
|
|
125 |
*/ |
|
|
126 |
static WORKING_AREA(waThread_odpal, 128); |
|
|
127 |
static msg_t Thread_odpal(void *arg) { |
|
|
128 |
uint8_t stav = 0; // rika, ve ktere fazi je odpalovani |
|
|
129 |
uint8_t odpal_povolen = 0; |
|
|
130 |
uint8_t odpal_pomocna = 0; |
|
|
131 |
uint16_t pocet_opakovani = 1; |
|
|
132 |
uint16_t perioda_casovace = 500; // changing to 8*500 = 400 |
|
|
133 |
(void)arg; |
|
|
134 |
chRegSetThreadName("Odpal_vlakno"); |
|
|
135 |
|
|
|
136 |
while (TRUE) |
|
|
137 |
{ |
|
|
138 |
msg_t msg; |
|
|
139 |
|
|
|
140 |
/* Waiting for the IRQ to happen.*/ |
|
|
141 |
chSysLock(); |
|
|
142 |
tp_odpal = chThdSelf(); |
|
|
143 |
chSchGoSleepS(THD_STATE_SUSPENDED); |
|
|
144 |
msg = chThdSelf()->p_u.rdymsg; /* Retrieving the message, optional.*/ |
|
|
145 |
chSysUnlock(); |
|
|
146 |
|
|
|
147 |
/* Perform processing here.*/ |
|
|
148 |
if(msg == 1) |
|
|
149 |
{ |
|
|
150 |
odpal_povolen = 1; |
|
|
151 |
odpal_pomocna++; |
|
|
152 |
stav = 0; |
|
|
153 |
pocet_opakovani = 1; |
|
|
154 |
} |
|
|
155 |
else if (msg == 2) //Pokud se ma odpal zrusit v prubehu vypousteni |
|
|
156 |
{ |
|
|
157 |
/* |
|
|
158 |
* Pro jistotu se vypnou vsechny vystupy pri zruseni odpalu |
|
|
159 |
*/ |
|
|
160 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN10); |
|
|
161 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN11); |
|
|
162 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN12); |
|
|
163 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN13); |
|
|
164 |
palSetPad(IND_LEDS_PORT, LED_STRECHA); |
|
|
165 |
palSetPad(IND_LEDS_PORT, LED_LIS); |
|
|
166 |
palSetPad(IND_LEDS_PORT, LED_VENTIL); |
|
|
167 |
palSetPad(IND_LEDS_PORT, LED_ZATAVENI); |
|
|
168 |
|
|
|
169 |
if(odpal_povolen == 1) |
|
|
170 |
chprintf((BaseSequentialStream *)&SD1,"\r\nOdpal zrusen uzivatelem.\r\n"); |
|
|
171 |
else |
|
|
172 |
chprintf((BaseSequentialStream *)&SD1,"Odpal nebyl aktivovan.\r\n"); |
|
|
173 |
|
|
|
174 |
odpal_povolen = 0; |
|
|
175 |
odpal_pomocna = 0; |
|
|
176 |
stav = 0; |
|
|
177 |
pocet_opakovani = 1; |
|
|
178 |
} |
|
|
179 |
else if (msg == 50 && odpal_povolen == 1) // preruseni od GPT |
|
|
180 |
{ |
|
|
181 |
odpal_pomocna = 1; |
|
|
182 |
} |
|
|
183 |
if (odpal_povolen == 1 && odpal_pomocna <= 1) |
|
|
184 |
{ |
|
|
185 |
odpal_pomocna = 2; // aby nepretekla tato promenna |
|
|
186 |
switch (stav) |
|
|
187 |
{ |
|
|
188 |
case 0: // ukonceni tohoto stavu pouze v pripade, ze je otevrena strecha |
|
|
189 |
if (pocet_opakovani == 1) |
|
|
190 |
chprintf((BaseSequentialStream *)&SD1,"Vypousteni zahajeno!\r\n"); |
|
|
191 |
|
|
|
192 |
if (pocet_opakovani <= POCET_STRECHA) |
|
|
193 |
{ |
|
|
194 |
chprintf((BaseSequentialStream *)&SD1,"(1/4)\tOtevirani vika... Strecha: %d, Zbyva: %3d \r",CTI_STRECHU,(POCET_STRECHA-pocet_opakovani)); |
|
|
195 |
palSetPad(GPIOB, GPIOB_PIN10); |
|
|
196 |
palClearPad(IND_LEDS_PORT, LED_STRECHA); |
|
|
197 |
gptStartOneShot(&GPTD2,perioda_casovace); |
|
|
198 |
pocet_opakovani++; |
|
|
199 |
if (pocet_opakovani == (POCET_STRECHA+1)) |
|
|
200 |
{ |
|
|
201 |
chprintf((BaseSequentialStream *)&SD1,"\r\n"); |
|
|
202 |
stav++; |
|
|
203 |
pocet_opakovani = 1; |
|
|
204 |
} |
|
|
205 |
} |
|
|
206 |
break; |
|
|
207 |
case 1: |
|
|
208 |
// kontrola strechy - maximalni cas prepalovani |
|
|
209 |
gptStartOneShot(&GPTD2,perioda_casovace); |
|
|
210 |
if (CTI_STRECHU) |
|
|
211 |
{ |
|
|
212 |
chprintf((BaseSequentialStream *)&SD1,"Strecha otevrena. Pokracovani v napousteni.\r\n"); |
|
|
213 |
pocet_opakovani = 1; |
|
|
214 |
stav++; |
|
|
215 |
} |
|
|
216 |
else |
|
|
217 |
{ |
|
|
218 |
if(pocet_opakovani <= CEKANI_NA_STRECHU){ |
|
|
219 |
chprintf((BaseSequentialStream *)&SD1,"Cekani na otevreni strechy.\r"); |
|
|
220 |
pocet_opakovani++; |
|
|
221 |
} |
|
|
222 |
else { // prekroceni maximalni doby pro odpaleni strechy |
|
|
223 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN10); |
|
|
224 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN11); |
|
|
225 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN12); |
|
|
226 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN13); |
|
|
227 |
palSetPad(IND_LEDS_PORT, LED_STRECHA); |
|
|
228 |
palSetPad(IND_LEDS_PORT, LED_LIS); |
|
|
229 |
palSetPad(IND_LEDS_PORT, LED_VENTIL); |
|
|
230 |
palSetPad(IND_LEDS_PORT, LED_ZATAVENI); |
|
|
231 |
chprintf((BaseSequentialStream *)&SD1,"\r\nNelze otevrit strechu.\r\n"); |
|
|
232 |
|
|
|
233 |
odpal_povolen = 0; |
|
|
234 |
odpal_pomocna = 0; |
|
|
235 |
stav = 0; |
|
|
236 |
pocet_opakovani = 1; |
|
|
237 |
} |
|
|
238 |
} |
|
|
239 |
break; |
|
|
240 |
case 2: |
|
|
241 |
if (pocet_opakovani <= POCET_VENTIL) |
|
|
242 |
{ |
|
|
243 |
palClearPad(GPIOB, GPIOB_PIN10); |
|
|
244 |
palSetPad(IND_LEDS_PORT, LED_STRECHA); |
|
|
245 |
palSetPad(GPIOB, GPIOB_PIN11); |
|
|
246 |
palClearPad(IND_LEDS_PORT, LED_VENTIL); |
|
|
247 |
chprintf((BaseSequentialStream *)&SD1,"(2/4)\tVentil otevren -> nafukovani balonu... Strecha: %d, Zbyva: %3d\r",CTI_STRECHU,(POCET_VENTIL-pocet_opakovani)); |
|
|
248 |
gptStartOneShot(&GPTD2,perioda_casovace); |
|
|
249 |
pocet_opakovani++; |
|
|
250 |
if (pocet_opakovani == (POCET_VENTIL+1)) |
|
|
251 |
{ |
|
|
252 |
chprintf((BaseSequentialStream *)&SD1,"\r\n"); |
|
|
253 |
stav++; |
|
|
254 |
pocet_opakovani = 1; |
|
|
255 |
} |
|
|
256 |
} |
|
|
257 |
break; |
|
|
258 |
case 3: |
|
|
259 |
if (pocet_opakovani <= POCET_LIS) |
|
|
260 |
{ |
|
|
261 |
palClearPad(GPIOB, GPIOB_PIN11); |
|
|
262 |
palSetPad(IND_LEDS_PORT, LED_VENTIL); |
|
|
263 |
palSetPad(GPIOB, GPIOB_PIN12); |
|
|
264 |
palClearPad(IND_LEDS_PORT, LED_LIS); |
|
|
265 |
chprintf((BaseSequentialStream *)&SD1,"(3/4)\tPrepalovani lisu... Lis: %d, Zbyva: %3d\r",CTI_LIS,(POCET_LIS-pocet_opakovani)); |
|
|
266 |
gptStartOneShot(&GPTD2,perioda_casovace); |
|
|
267 |
pocet_opakovani++; |
|
|
268 |
if (pocet_opakovani == (POCET_LIS+1)) |
|
|
269 |
{ |
|
|
270 |
chprintf((BaseSequentialStream *)&SD1,"\r\n"); |
|
|
271 |
stav++; |
|
|
272 |
pocet_opakovani = 1; |
|
|
273 |
} |
|
|
274 |
} |
|
|
275 |
break; |
|
|
276 |
case 4: // kontrola prepaleni lisu |
|
|
277 |
gptStartOneShot(&GPTD2,perioda_casovace); |
|
|
278 |
if (CTI_LIS) |
|
|
279 |
{ |
|
|
280 |
chprintf((BaseSequentialStream *)&SD1,"Lis stlacen. Pokracovani v pretavovani.\r\n"); |
|
|
281 |
pocet_opakovani = 1; |
|
|
282 |
stav++; |
|
|
283 |
} |
|
|
284 |
else |
|
|
285 |
{ |
|
|
286 |
if(pocet_opakovani <= CEKANI_NA_LIS){ |
|
|
287 |
chprintf((BaseSequentialStream *)&SD1,"Cekani na stlaceni lisu.\r"); |
|
|
288 |
pocet_opakovani++; |
|
|
289 |
} |
|
|
290 |
else { // prekroceni maximalni doby pro slisovani |
|
|
291 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN10); |
|
|
292 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN11); |
|
|
293 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN12); |
|
|
294 |
palClearPad(NFET_OUTPUTS_PORT, GPIOB_PIN13); |
|
|
295 |
palSetPad(IND_LEDS_PORT, LED_STRECHA); |
|
|
296 |
palSetPad(IND_LEDS_PORT, LED_LIS); |
|
|
297 |
palSetPad(IND_LEDS_PORT, LED_VENTIL); |
|
|
298 |
palSetPad(IND_LEDS_PORT, LED_ZATAVENI); |
|
|
299 |
chprintf((BaseSequentialStream *)&SD1,"\r\nNelze spustit lis.\r\n"); |
|
|
300 |
|
|
|
301 |
odpal_povolen = 0; |
|
|
302 |
odpal_pomocna = 0; |
|
|
303 |
stav = 0; |
|
|
304 |
pocet_opakovani = 1; |
|
|
305 |
} |
|
|
306 |
} |
|
|
307 |
break; |
|
|
308 |
case 5: |
|
|
309 |
if (pocet_opakovani <= POCET_ZATAVENI) |
|
|
310 |
{ |
|
|
311 |
palClearPad(GPIOB, GPIOB_PIN12); |
|
|
312 |
palSetPad(IND_LEDS_PORT, LED_LIS); |
|
|
313 |
palSetPad(GPIOB, GPIOB_PIN13); |
|
|
314 |
palClearPad(IND_LEDS_PORT, LED_ZATAVENI); |
|
|
315 |
chprintf((BaseSequentialStream *)&SD1,"(4/4)\tZatavovani balonu... Lis: %d, Zbyva: %3d \r",CTI_LIS,(POCET_ZATAVENI-pocet_opakovani)); |
|
|
316 |
gptStartOneShot(&GPTD2,perioda_casovace); |
|
|
317 |
pocet_opakovani++; |
|
|
318 |
if (pocet_opakovani == (POCET_ZATAVENI+1)) |
|
|
319 |
{ |
|
|
320 |
chprintf((BaseSequentialStream *)&SD1,"\r\n"); |
|
|
321 |
stav++; |
|
|
322 |
pocet_opakovani = 1; |
|
|
323 |
} |
|
|
324 |
} |
|
|
325 |
break; |
|
|
326 |
case 6: |
|
|
327 |
palClearPad(GPIOB, GPIOB_PIN13); |
|
|
328 |
palSetPad(IND_LEDS_PORT, LED_ZATAVENI); |
|
|
329 |
chprintf((BaseSequentialStream *)&SD1,"Vypousteni ukonceno!\r\n"); |
|
|
330 |
odpal_povolen = 0; |
|
|
331 |
odpal_pomocna = 0; |
|
|
332 |
stav = 0; |
|
|
333 |
break; |
|
|
334 |
default: |
|
|
335 |
chprintf((BaseSequentialStream *)&SD1,"NIC!\r\n"); |
|
|
336 |
break; |
|
|
337 |
} |
|
|
338 |
} |
|
|
339 |
} |
|
|
340 |
} |
|
|
341 |
|
|
|
342 |
|
|
|
343 |
/* |
|
|
344 |
* Vlakno pro obsluhu GPS prijimace |
|
|
345 |
*/ |
|
|
346 |
static WORKING_AREA(waThread_GPS, 768); |
|
|
347 |
static msg_t Thread_GPS(void *arg) { |
|
|
348 |
/* |
|
|
349 |
* Nacita se jen nekolik NMEA zprav, aby se neplytvalo pameti na ulozeni kompletniho |
|
|
350 |
* setu s tím rizikem, ze se nekdy nenacte aktualni informace o poloze. |
|
|
351 |
*/ |
|
|
352 |
uint8_t inBuffer[GPS_BUFFER]; |
|
|
353 |
char *zacatek_retezce; |
|
|
354 |
char *konec_retezce; |
|
|
355 |
uint8_t pocet_znaku; |
|
|
356 |
uint8_t NMEA_zprava[100]; |
|
|
357 |
|
|
|
358 |
(void)arg; |
|
|
359 |
chRegSetThreadName("GPS_NMEA"); |
|
|
360 |
|
|
|
361 |
while (TRUE) { |
|
|
362 |
chThdSleepMilliseconds(1000); //neni potreba data vycitat rychleji |
|
|
363 |
sdRead(&SD2,inBuffer,GPS_BUFFER); |
|
|
364 |
|
|
|
365 |
/* |
|
|
366 |
*Nejprve se vycte cast NMEA dat, pote se vyhleda retezec GPGGA zpravy, ta se vyparsuje a pomoci fce |
|
|
367 |
*dekoduj_zpravu_GPS, ktera vyparsuje data o poloze a jine, a ulozi je do struktury GPGGA_informace. |
|
|
368 |
*/ |
|
|
369 |
|
|
|
370 |
if ((zacatek_retezce = strstr((char *)inBuffer,"$GPGGA")) != NULL) |
|
|
371 |
{ |
|
|
372 |
if ((konec_retezce = strstr(zacatek_retezce,"*")) != NULL) |
|
|
373 |
{ |
|
|
374 |
pocet_znaku = (konec_retezce-zacatek_retezce)/sizeof(char); |
|
|
375 |
if (pocet_znaku > 100) |
|
|
376 |
{ |
|
|
377 |
pocet_znaku = 100; |
|
|
378 |
} |
|
|
379 |
strncpy((char *)NMEA_zprava,zacatek_retezce,pocet_znaku); |
|
|
380 |
dekoduj_zpravu_GPS(&NMEA_zprava[0],pocet_znaku); |
|
|
381 |
sdWrite(&SD2,"Latitude: ",sizeof("Latitude: ")/sizeof(char)); |
|
|
382 |
sdWrite(&SD2,GPGGA_informace.Latitude,sizeof(GPGGA_informace.Latitude)/sizeof(uint8_t)); |
|
|
383 |
sdWrite(&SD2,"\r\n",2); |
|
|
384 |
sdWrite(&SD2,"Longitude: ",sizeof("Longitude: ")/sizeof(char)); |
|
|
385 |
sdWrite(&SD2,GPGGA_informace.Longitude,sizeof(GPGGA_informace.Longitude)/sizeof(uint8_t)); |
|
|
386 |
sdWrite(&SD2,"\r\n",2); |
|
|
387 |
sdWrite(&SD2,"Altitude: ",sizeof("Altitude: ")/sizeof(char)); |
|
|
388 |
sdWrite(&SD2,GPGGA_informace.Altitude,sizeof(GPGGA_informace.Altitude)/sizeof(uint8_t)); |
|
|
389 |
sdWrite(&SD2,"\r\n",2); |
|
|
390 |
sdWrite(&SD2,"Status: ",sizeof("Status: ")/sizeof(char)); |
|
|
391 |
sdWrite(&SD2,&GPGGA_informace.Status_GPS,sizeof(GPGGA_informace.Status_GPS)/sizeof(uint8_t)); |
|
|
392 |
sdWrite(&SD2,"\r\n",2); |
|
|
393 |
sdWrite(&SD2,NMEA_zprava,pocet_znaku); |
|
|
394 |
sdWrite(&SD2,"\r\n",2); |
|
|
395 |
} |
|
|
396 |
else |
|
|
397 |
{ |
|
|
398 |
sdWrite(&SD2,"\r\n",2); |
|
|
399 |
sdWrite(&SD2,"Nenalezen ukoncovaci znak NMEA zpravy *\r\n",sizeof("Nenalezen ukoncovaci znak NMEA zpravy *\r\n")/sizeof(char)); |
|
|
400 |
sdWrite(&SD2,inBuffer,GPS_BUFFER); |
|
|
401 |
} |
|
|
402 |
} |
|
|
403 |
else |
|
|
404 |
sdWrite(&SD2,"Nenalezen zacatek GPGGA zpravy\r\n",sizeof("Nenalezen zacatek GPGGA zpravy\r\n")/sizeof(char)); |
|
|
405 |
|
|
|
406 |
} |
|
|
407 |
} |
|
|
408 |
|
|
|
409 |
void dekodujPrikaz(char *prikaz) |
|
|
410 |
{ |
|
|
411 |
if(strcmp(prikaz,"odpal") == 0) |
|
|
412 |
{ |
|
|
413 |
/* Wakes up the thread.*/ |
|
|
414 |
chSysLockFromIsr(); |
|
|
415 |
if (tp_odpal != NULL) { |
|
|
416 |
tp_odpal->p_u.rdymsg = (msg_t)1; /* odpal povolen*/ |
|
|
417 |
chSchReadyI(tp_odpal); |
|
|
418 |
tp_odpal = NULL; |
|
|
419 |
} |
|
|
420 |
chSysUnlockFromIsr(); |
|
|
421 |
|
|
|
422 |
} |
|
|
423 |
else if (strcmp(prikaz,"zrus") == 0) |
|
|
424 |
{ |
|
|
425 |
/* Wakes up the thread.*/ |
|
|
426 |
chSysLockFromIsr(); |
|
|
427 |
if (tp_odpal != NULL) { |
|
|
428 |
tp_odpal->p_u.rdymsg = (msg_t)2; /* zakazano pokracovat v odpalovaci sekvenci*/ |
|
|
429 |
chSchReadyI(tp_odpal); |
|
|
430 |
tp_odpal = NULL; |
|
|
431 |
} |
|
|
432 |
chSysUnlockFromIsr(); |
|
|
433 |
} |
|
|
434 |
else if (strcmp(prikaz,"help") == 0) |
|
|
435 |
{ |
|
|
436 |
sdWrite(&SD1, uvitaci_zprava, sizeof(uvitaci_zprava)/sizeof(uint8_t)); |
|
|
437 |
} |
|
|
438 |
else |
|
|
439 |
{ |
|
|
440 |
uint8_t zp_neplatny[] = "Neplatny prikaz!\r\n\t<odpal> pro zahajeni sekvence\n\r\t<zrus> pro zruseni vypousteni\n\r"; |
|
|
441 |
sdWrite(&SD1,zp_neplatny,sizeof(zp_neplatny)/sizeof(uint8_t)); |
|
|
442 |
palTogglePad(GPIOB, GPIOB_LED3); |
|
|
443 |
} |
|
|
444 |
} |
|
|
445 |
|
|
|
446 |
/* |
|
|
447 |
* Application entry point. |
|
|
448 |
*/ |
|
|
449 |
int main(void) { |
|
|
450 |
|
|
|
451 |
uint8_t znaky[20]; |
|
|
452 |
char prikaz[MAX_DELKA_PRIKAZU + 1]; |
|
|
453 |
uint8_t pocet_znaku = 0; |
|
|
454 |
|
|
|
455 |
/* |
|
|
456 |
* System initializations. |
|
|
457 |
* - HAL initialization, this also initializes the configured device drivers |
|
|
458 |
* and performs the board-specific initializations. |
|
|
459 |
* - Kernel initialization, the main() function becomes a thread and the |
|
|
460 |
* RTOS is active. |
|
|
461 |
*/ |
|
|
462 |
halInit(); |
|
|
463 |
chSysInit(); |
|
|
464 |
|
|
|
465 |
/* |
|
|
466 |
* Activates the serial driver 1 using the driver default configuration. |
|
|
467 |
* PA9 and PA10 are routed to USART1. |
|
|
468 |
* Komunikace s uzivatelem |
|
|
469 |
*/ |
|
|
470 |
sdStart(&SD1, NULL); |
|
|
471 |
palSetPadMode(GPIOA, 9, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); //TX |
|
|
472 |
//palSetPadMode(GPIOA, 10, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); //RX |
|
|
473 |
|
|
|
474 |
/* |
|
|
475 |
* Activates the serial driver 2 using the driver default configuration. |
|
|
476 |
* PA2 and PA3 are routed to USART2. |
|
|
477 |
*GPS |
|
|
478 |
*/ |
|
|
479 |
sdStart(&SD2, &USART2_config); |
2972 |
jichapav |
480 |
palSetPadMode(GPIOA, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL); //TX |
|
|
481 |
//palSetPadMode(GPIOA, 3, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); //RX - overrides board.h PadValues |
2971 |
jichapav |
482 |
|
|
|
483 |
/* |
|
|
484 |
* LED na vyvojove desce |
|
|
485 |
*/ |
|
|
486 |
palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_OUTPUT_PUSHPULL); |
|
|
487 |
|
|
|
488 |
/* |
|
|
489 |
* Initializes the PWM driver 4, routes the TIM4 outputs to the board LEDs. |
|
|
490 |
*/ |
|
|
491 |
/*pwmStart(&PWMD4, &pwmcfg); |
|
|
492 |
palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); |
|
|
493 |
pwmEnableChannel(&PWMD4,0,PWM_SIRKA_NORMAL);*/ |
|
|
494 |
|
|
|
495 |
|
|
|
496 |
/* |
|
|
497 |
* Porty pro vypousteci sekvenci |
|
|
498 |
*/ |
|
|
499 |
palSetPadMode(GPIOB, GPIOB_PIN10, PAL_MODE_OUTPUT_PUSHPULL); |
|
|
500 |
palClearPad(GPIOB, GPIOB_PIN10); |
|
|
501 |
palSetPadMode(GPIOB, GPIOB_PIN11, PAL_MODE_OUTPUT_PUSHPULL); |
|
|
502 |
palClearPad(GPIOB, GPIOB_PIN11); |
|
|
503 |
palSetPadMode(GPIOB, GPIOB_PIN12, PAL_MODE_OUTPUT_PUSHPULL); |
|
|
504 |
palClearPad(GPIOB, GPIOB_PIN12); |
|
|
505 |
palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_OUTPUT_PUSHPULL); |
|
|
506 |
palClearPad(GPIOB, GPIOB_PIN13); |
|
|
507 |
palSetPad(IND_LEDS_PORT, LED_STRECHA); |
|
|
508 |
palSetPad(IND_LEDS_PORT, LED_LIS); |
|
|
509 |
palSetPad(IND_LEDS_PORT, LED_VENTIL); |
|
|
510 |
palSetPad(IND_LEDS_PORT, LED_ZATAVENI); |
|
|
511 |
|
|
|
512 |
/* |
|
|
513 |
* Aktivuje timer2 a timer3 prejde tak do aktivniho stavu |
|
|
514 |
*/ |
|
|
515 |
gptStart(&GPTD2,&gpt2cfg); |
|
|
516 |
|
|
|
517 |
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
|
|
518 |
/* |
|
|
519 |
* Vytvori vlakno pro prijem dat z GPS modulu |
|
|
520 |
*/ |
|
|
521 |
chThdCreateStatic(waThread_GPS, sizeof(waThread_GPS), NORMALPRIO, Thread_GPS, NULL); |
|
|
522 |
|
|
|
523 |
/* |
|
|
524 |
* Vytvori vlakno pro odpalovaci sekvenci |
|
|
525 |
*/ |
|
|
526 |
chThdCreateStatic (waThread_odpal, sizeof(waThread_odpal), NORMALPRIO, Thread_odpal, NULL); |
|
|
527 |
|
|
|
528 |
sdWrite(&SD1, uvitaci_zprava, sizeof(uvitaci_zprava)/sizeof(uint8_t)); |
|
|
529 |
/* |
|
|
530 |
* Normal main() thread activity, in this demo it does nothing except |
|
|
531 |
* sleeping in a loop and check the button state, when the button is |
|
|
532 |
* pressed the test procedure is launched with output on the serial |
|
|
533 |
* driver 1. |
|
|
534 |
*/ |
|
|
535 |
|
|
|
536 |
while (TRUE) { |
|
|
537 |
|
|
|
538 |
sdRead(&SD1,znaky,1); |
|
|
539 |
/*Kdyz uzivatel stiskne enter -> dekoduj a vykonej prikaz, nebo pokud je prikaz delsi, nez by mel byt, |
|
|
540 |
*prestane ukladat a upozorni uzivatele |
|
|
541 |
*/ |
|
|
542 |
if (znaky[0] == '\r' || pocet_znaku >= MAX_DELKA_PRIKAZU) |
|
|
543 |
{ |
|
|
544 |
pocet_znaku = 0; |
|
|
545 |
dekodujPrikaz(prikaz); |
|
|
546 |
prikaz[0] = 0; |
|
|
547 |
} |
|
|
548 |
/*Uklada prikaz*/ |
2972 |
jichapav |
549 |
else if (znaky[0] == 's') // ukonci odpalovani |
|
|
550 |
{ |
|
|
551 |
chSysLockFromIsr(); |
|
|
552 |
if (tp_odpal != NULL) { |
|
|
553 |
tp_odpal->p_u.rdymsg = (msg_t)2; /* zakazano pokracovat v odpalovaci sekvenci*/ |
|
|
554 |
chSchReadyI(tp_odpal); |
|
|
555 |
tp_odpal = NULL; |
|
|
556 |
} |
|
|
557 |
chSysUnlockFromIsr(); |
|
|
558 |
} |
2971 |
jichapav |
559 |
else |
|
|
560 |
{ |
|
|
561 |
prikaz[pocet_znaku + 1] = 0; |
|
|
562 |
prikaz[pocet_znaku++] = znaky[0]; |
|
|
563 |
} |
|
|
564 |
} |
|
|
565 |
} |