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