223 |
kapl |
1 |
#include ".\main.h" |
|
|
2 |
|
240 |
kaklik |
3 |
#include <stdio.h> |
|
|
4 |
#include <string.h> |
|
|
5 |
#include <stdlib.h> |
223 |
kapl |
6 |
|
240 |
kaklik |
7 |
#define DELKA 40 |
246 |
kaklik |
8 |
#define VYKON 100 |
223 |
kapl |
9 |
|
240 |
kaklik |
10 |
char odp[DELKA]; |
239 |
kaklik |
11 |
|
240 |
kaklik |
12 |
int1 check_new_sms() |
|
|
13 |
{ |
246 |
kaklik |
14 |
fprintf(MOBIL,"AT+CMGL=0\r"); //vycti prijate SMS (0=nove;1=vsechny) |
238 |
kaklik |
15 |
while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi |
|
|
16 |
odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi |
|
|
17 |
odp[1]=fgetc(MOBIL); |
|
|
18 |
while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku |
|
|
19 |
|
240 |
kaklik |
20 |
if(odp[0] == 'O' && odp[1] == 'K') return 1; |
|
|
21 |
else return 0; |
|
|
22 |
} |
238 |
kaklik |
23 |
|
240 |
kaklik |
24 |
read_sms() |
|
|
25 |
{ |
|
|
26 |
int pom,pom2,pom3,odkl,odkl2,maskovadlo; |
238 |
kaklik |
27 |
for(pom=0;pom<54;pom++) //preskoc nedulezite informace |
223 |
kapl |
28 |
{ |
238 |
kaklik |
29 |
fgetc(MOBIL); |
239 |
kaklik |
30 |
} |
|
|
31 |
|
223 |
kapl |
32 |
//gets(odp); //uloz zakodovany text SMS |
239 |
kaklik |
33 |
|
238 |
kaklik |
34 |
odp[0]=fgetc(MOBIL); |
|
|
35 |
odp[1]=fgetc(MOBIL); |
|
|
36 |
odp[2]=fgetc(MOBIL); |
|
|
37 |
odp[3]=fgetc(MOBIL); |
|
|
38 |
odp[4]=fgetc(MOBIL); |
|
|
39 |
odp[5]=fgetc(MOBIL); |
|
|
40 |
odp[6]=fgetc(MOBIL); |
|
|
41 |
odp[7]=fgetc(MOBIL); |
|
|
42 |
|
223 |
kapl |
43 |
/*lcd_gotoxy(1,1); |
|
|
44 |
printf(lcd_putc,"\f%s\n",odp);*/ |
239 |
kaklik |
45 |
|
|
|
46 |
if(odp[0]==0) odp[1]='0'; // Prevod z ASCII do BIN |
223 |
kapl |
47 |
odp[0]=odp[0] - '0'; |
|
|
48 |
odp[1]=odp[1] - '0'; |
|
|
49 |
if(odp[0]>9) odp[0]=odp[0]-7; |
|
|
50 |
if(odp[1]>9) odp[1]=odp[1]-7; |
|
|
51 |
odp[0]=odp[0] << 4; |
|
|
52 |
odp[0] |= odp[1]; |
239 |
kaklik |
53 |
|
223 |
kapl |
54 |
if(odp[2]==0) odp[3]='0'; |
|
|
55 |
odp[2]=odp[2] - '0'; |
|
|
56 |
odp[3]=odp[3] - '0'; |
|
|
57 |
if(odp[2]>9) odp[2]=odp[2]-7; |
|
|
58 |
if(odp[3]>9) odp[3]=odp[3]-7; |
|
|
59 |
odp[2]=odp[2] << 4; |
|
|
60 |
odp[2] |= odp[3]; |
239 |
kaklik |
61 |
|
223 |
kapl |
62 |
if(odp[4]==0) odp[5]='0'; |
|
|
63 |
odp[4]=odp[4] - '0'; |
|
|
64 |
odp[5]=odp[5] - '0'; |
|
|
65 |
if(odp[4]>9) odp[4]=odp[4]-7; |
|
|
66 |
if(odp[5]>9) odp[5]=odp[5]-7; |
|
|
67 |
odp[4]=odp[4] << 4; |
|
|
68 |
odp[4] |= odp[5]; |
239 |
kaklik |
69 |
|
223 |
kapl |
70 |
if(odp[6]==0) odp[7]='0'; |
|
|
71 |
odp[6]=odp[6] - '0'; |
|
|
72 |
odp[7]=odp[7] - '0'; |
|
|
73 |
if(odp[6]>9) odp[6]=odp[6]-7; |
|
|
74 |
if(odp[7]>9) odp[7]=odp[7]-7; |
|
|
75 |
odp[6]=odp[6] << 4; |
|
|
76 |
odp[6] |= odp[7]; |
|
|
77 |
|
|
|
78 |
odp[1]=odp[2]; |
|
|
79 |
odp[2]=odp[4]; |
|
|
80 |
odp[3]=odp[6]; |
239 |
kaklik |
81 |
odp[4]=odp[5]=odp[6]=0; |
|
|
82 |
|
|
|
83 |
/*lcd_gotoxy(1,2); |
223 |
kapl |
84 |
printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2]odp[3]); */ |
239 |
kaklik |
85 |
|
223 |
kapl |
86 |
pom3=0; |
239 |
kaklik |
87 |
for (pom = 0; pom < 4;pom++) |
223 |
kapl |
88 |
{ |
|
|
89 |
maskovadlo = maskovadlo >> 1; //rotace promene urcene pro maskovani |
|
|
90 |
maskovadlo = maskovadlo | 0x80; |
|
|
91 |
odkl = odp[pom] & maskovadlo; //odlozeni "prenosu" do odkl pomoci maskovadla |
|
|
92 |
odp[pom] = odp[pom] << pom3; //rotace znaku |
|
|
93 |
for (pom2 = 0; pom2 < (8-pom3);pom2++) //rotace odkl2 |
|
|
94 |
{ |
|
|
95 |
odkl2 = odkl2 >> 1; |
239 |
kaklik |
96 |
odkl2 = odkl2 & 127; |
223 |
kapl |
97 |
} |
|
|
98 |
odp[pom] = odp[pom] | odkl2; //pridani odkl2 ke znaku |
|
|
99 |
odp[pom] = odp[pom] & 127; //smazani nejvysiho bitu |
|
|
100 |
odkl2 = odkl; //ulozeni odlk na dalsi pruchod |
|
|
101 |
pom3++; //inkrementace citace rotace |
|
|
102 |
if (pom3 == 8) //kazdy 8my znak |
|
|
103 |
{ |
|
|
104 |
pom3 = 0; //smaz citac |
|
|
105 |
odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu" |
|
|
106 |
maskovadlo = 0; //smaz maskovadlo |
|
|
107 |
} |
|
|
108 |
} |
239 |
kaklik |
109 |
odp[pom]='\0'; |
240 |
kaklik |
110 |
} |
239 |
kaklik |
111 |
|
240 |
kaklik |
112 |
void read_time() |
|
|
113 |
{ |
|
|
114 |
unsigned int8 n; |
238 |
kaklik |
115 |
|
239 |
kaklik |
116 |
|
240 |
kaklik |
117 |
fprintf(MOBIL,"AT+CCLK?\r"); |
|
|
118 |
while(fgetc(MOBIL)!='"'); |
|
|
119 |
for(n=0;n<12;n++) //preskoc nedulezite informace |
|
|
120 |
{ |
|
|
121 |
fgetc(MOBIL); |
|
|
122 |
} |
|
|
123 |
odp[0]=fgetc(MOBIL); |
|
|
124 |
odp[1]=fgetc(MOBIL); |
|
|
125 |
odp[2]=0; |
|
|
126 |
} |
239 |
kaklik |
127 |
|
240 |
kaklik |
128 |
void del_sms() |
|
|
129 |
{ |
|
|
130 |
fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku |
|
|
131 |
} |
239 |
kaklik |
132 |
|
240 |
kaklik |
133 |
void main() |
|
|
134 |
{ |
|
|
135 |
setup_adc_ports(NO_ANALOGS); |
|
|
136 |
setup_adc(ADC_OFF); |
|
|
137 |
setup_spi(SPI_SS_DISABLED); |
|
|
138 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
139 |
setup_timer_1(T1_DISABLED); |
|
|
140 |
setup_timer_2(T2_DIV_BY_4,255,1); |
|
|
141 |
setup_ccp1(CCP_PWM); |
|
|
142 |
setup_ccp2(CCP_PWM); |
|
|
143 |
setup_comparator(NC_NC_NC_NC); |
|
|
144 |
setup_vref(FALSE); |
|
|
145 |
setup_wdt(WDT_2304MS); |
239 |
kaklik |
146 |
|
240 |
kaklik |
147 |
set_pwm1_duty(0); |
|
|
148 |
set_pwm2_duty(0); |
239 |
kaklik |
149 |
|
240 |
kaklik |
150 |
while(TRUE) |
|
|
151 |
{ |
246 |
kaklik |
152 |
unsigned int8 n; |
240 |
kaklik |
153 |
char *ptr; |
|
|
154 |
int time; |
238 |
kaklik |
155 |
|
240 |
kaklik |
156 |
output_low(PIN_A4) ; |
|
|
157 |
delay_ms(150); |
|
|
158 |
output_high(PIN_A4); |
|
|
159 |
delay_ms(150); |
|
|
160 |
output_low(PIN_A4) ; |
|
|
161 |
delay_ms(150); |
|
|
162 |
output_high(PIN_A4); |
|
|
163 |
delay_ms(150); |
238 |
kaklik |
164 |
|
|
|
165 |
|
245 |
kaklik |
166 |
if(check_new_sms()) // Je odpoved "OK"? |
240 |
kaklik |
167 |
{ |
|
|
168 |
// printf(lcd_putc,"736 655 250"); |
247 |
kaklik |
169 |
delay_ms(1000); |
240 |
kaklik |
170 |
} |
|
|
171 |
else |
|
|
172 |
{ |
|
|
173 |
read_sms(); |
|
|
174 |
|
246 |
kaklik |
175 |
if (toupper(odp[0]) == 'A') |
240 |
kaklik |
176 |
{ |
246 |
kaklik |
177 |
set_pwm1_duty(VYKON); |
|
|
178 |
set_pwm2_duty(VYKON); |
|
|
179 |
Delay_ms(10000); |
|
|
180 |
fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)" |
|
|
181 |
Delay_ms(2000); |
|
|
182 |
fprintf(VRTULE,"JACK[BARmk"); // "JACK BAR :)" |
|
|
183 |
Delay_ms(5000); |
|
|
184 |
set_pwm1_duty(0); |
|
|
185 |
set_pwm2_duty(0); |
|
|
186 |
del_sms(); |
|
|
187 |
break; |
|
|
188 |
} |
240 |
kaklik |
189 |
|
246 |
kaklik |
190 |
if (toupper(odp[0]) == 'B') |
245 |
kaklik |
191 |
{ |
246 |
kaklik |
192 |
set_pwm1_duty(VYKON); |
|
|
193 |
set_pwm2_duty(VYKON); |
245 |
kaklik |
194 |
Delay_ms(10000); |
246 |
kaklik |
195 |
for(n=0;n<=1;n++) |
|
|
196 |
{ |
|
|
197 |
fprintf(VRTULE,"[ERROR[d[["); // " ERROR 3 " |
|
|
198 |
Delay_ms(2000); |
|
|
199 |
fprintf(VRTULE,"[OVERFLOW["); // " OVERFLOW " |
|
|
200 |
Delay_ms(2000); |
|
|
201 |
} |
|
|
202 |
Delay_ms(5000); |
|
|
203 |
set_pwm1_duty(0); |
|
|
204 |
set_pwm2_duty(0); |
|
|
205 |
del_sms(); |
|
|
206 |
break; |
|
|
207 |
} |
|
|
208 |
|
|
|
209 |
if (toupper(odp[0]) == 'C') |
|
|
210 |
{ |
|
|
211 |
set_pwm1_duty(VYKON); |
|
|
212 |
set_pwm2_duty(VYKON); |
|
|
213 |
Delay_ms(10000); |
|
|
214 |
for(n=0;n<=1;n++) |
|
|
215 |
{ |
|
|
216 |
fprintf(VRTULE,"[ERROR[e[["); // " ERROR 4 " |
|
|
217 |
Delay_ms(2000); |
|
|
218 |
fprintf(VRTULE,"[OPAKUJTE["); // " OPAKUJTE " |
|
|
219 |
Delay_ms(2000); |
|
|
220 |
fprintf(VRTULE,"[[VOLBU[[["); // " VOLBU " |
|
|
221 |
Delay_ms(2000); |
|
|
222 |
} |
|
|
223 |
Delay_ms(3000); |
|
|
224 |
set_pwm1_duty(0); |
|
|
225 |
set_pwm2_duty(0); |
|
|
226 |
del_sms(); |
|
|
227 |
break; |
|
|
228 |
} |
|
|
229 |
|
|
|
230 |
if (toupper(odp[0]) == 'D') |
|
|
231 |
{ |
|
|
232 |
set_pwm1_duty(VYKON); |
|
|
233 |
set_pwm2_duty(VYKON); |
|
|
234 |
Delay_ms(10000); |
|
|
235 |
fprintf(VRTULE,"[[PEACE[[["); // " PEACE " |
245 |
kaklik |
236 |
Delay_ms(2000); |
246 |
kaklik |
237 |
fprintf(VRTULE,"[[PEACE[[["); |
|
|
238 |
Delay_ms(3000); |
|
|
239 |
set_pwm1_duty(0); |
|
|
240 |
set_pwm2_duty(0); |
|
|
241 |
del_sms(); |
|
|
242 |
break; |
|
|
243 |
} |
|
|
244 |
|
|
|
245 |
if (toupper(odp[0]) == 'E') |
|
|
246 |
{ |
|
|
247 |
set_pwm1_duty(VYKON); |
|
|
248 |
set_pwm2_duty(VYKON); |
|
|
249 |
Delay_ms(10000); |
|
|
250 |
for(n=0;n<=1;n++) |
|
|
251 |
{ |
|
|
252 |
fprintf(VRTULE,"[[[MORE[[["); // " MORE " |
|
|
253 |
Delay_ms(2000); |
|
|
254 |
fprintf(VRTULE,"[[ZE[JO[[["); // " ZE JO " |
|
|
255 |
Delay_ms(2000); |
|
|
256 |
} |
245 |
kaklik |
257 |
Delay_ms(5000); |
|
|
258 |
set_pwm1_duty(0); |
|
|
259 |
set_pwm2_duty(0); |
246 |
kaklik |
260 |
del_sms(); |
|
|
261 |
break; |
|
|
262 |
} |
239 |
kaklik |
263 |
|
246 |
kaklik |
264 |
if (toupper(odp[0]) == 'F') |
245 |
kaklik |
265 |
{ |
246 |
kaklik |
266 |
set_pwm1_duty(VYKON); |
|
|
267 |
set_pwm2_duty(VYKON); |
245 |
kaklik |
268 |
Delay_ms(10000); |
246 |
kaklik |
269 |
for(n=0;n<=1;n++) |
|
|
270 |
{ |
|
|
271 |
fprintf(VRTULE,"[ROZBITY[["); // " ROZBITY " |
|
|
272 |
Delay_ms(2000); |
|
|
273 |
fprintf(VRTULE,"[[BUDIK[[["); // " BUDIK " |
|
|
274 |
Delay_ms(2000); |
|
|
275 |
} |
|
|
276 |
Delay_ms(5000); |
|
|
277 |
set_pwm1_duty(0); |
|
|
278 |
set_pwm2_duty(0); |
|
|
279 |
del_sms(); |
|
|
280 |
break; |
|
|
281 |
} |
|
|
282 |
|
|
|
283 |
if (toupper(odp[0]) == 'G') |
|
|
284 |
{ |
|
|
285 |
set_pwm1_duty(VYKON); |
|
|
286 |
set_pwm2_duty(VYKON); |
|
|
287 |
Delay_ms(10000); |
|
|
288 |
for(n=0;n<=1;n++) |
|
|
289 |
{ |
|
|
290 |
fprintf(VRTULE,"[ZAPOJIT[["); // " ZAPOJIT " |
|
|
291 |
Delay_ms(2000); |
|
|
292 |
fprintf(VRTULE,"[ZASUVKU[["); // " ZASUVKU " |
|
|
293 |
Delay_ms(2000); |
|
|
294 |
} |
|
|
295 |
Delay_ms(5000); |
|
|
296 |
set_pwm1_duty(0); |
|
|
297 |
set_pwm2_duty(0); |
|
|
298 |
del_sms(); |
|
|
299 |
break; |
|
|
300 |
} |
247 |
kaklik |
301 |
|
246 |
kaklik |
302 |
if (toupper(odp[0]) == 'H') |
|
|
303 |
{ |
|
|
304 |
set_pwm1_duty(VYKON); |
|
|
305 |
set_pwm2_duty(VYKON); |
|
|
306 |
Delay_ms(10000); |
|
|
307 |
for(n=0;n<=1;n++) |
|
|
308 |
{ |
|
|
309 |
fprintf(VRTULE,"[[MARTIN[["); // " MARTIN " |
|
|
310 |
Delay_ms(2000); |
|
|
311 |
fprintf(VRTULE,"[[SVEJDA[["); // " SVEJDA " |
|
|
312 |
Delay_ms(2000); |
|
|
313 |
fprintf(VRTULE,"[[TOMAS[[["); // " TOMAS " |
|
|
314 |
Delay_ms(2000); |
|
|
315 |
fprintf(VRTULE,"[[[KAPL[[["); // "KAPL" |
|
|
316 |
Delay_ms(2000); |
|
|
317 |
fprintf(VRTULE,"[[JAKUB[[["); // " JAKUB " |
|
|
318 |
Delay_ms(2000); |
|
|
319 |
fprintf(VRTULE,"[[KAKONA[["); // "KAKONA" |
|
|
320 |
Delay_ms(2000); |
|
|
321 |
} |
|
|
322 |
Delay_ms(3000); |
|
|
323 |
set_pwm1_duty(0); |
|
|
324 |
set_pwm2_duty(0); |
|
|
325 |
del_sms(); |
|
|
326 |
break; |
|
|
327 |
} |
|
|
328 |
|
|
|
329 |
if (toupper(odp[0]) == 'I') |
|
|
330 |
{ |
|
|
331 |
set_pwm1_duty(VYKON); |
|
|
332 |
set_pwm2_duty(VYKON); |
|
|
333 |
Delay_ms(10000); |
|
|
334 |
for(n=0;n<=1;n++) |
|
|
335 |
{ |
|
|
336 |
fprintf(VRTULE,"ODPOVED[NA"); // "ODPOVED NA" |
|
|
337 |
Delay_ms(2000); |
|
|
338 |
fprintf(VRTULE,"[[VASI[[[["); // " VASI " |
|
|
339 |
Delay_ms(2000); |
|
|
340 |
fprintf(VRTULE,"[[OTAZKU[["); // " OTAZKU " |
|
|
341 |
Delay_ms(2000); |
|
|
342 |
fprintf(VRTULE,"[[[[JE[[[["); // "JE" |
|
|
343 |
Delay_ms(2000); |
|
|
344 |
fprintf(VRTULE,"[[[[ec[[[["); // " 42 " |
|
|
345 |
Delay_ms(2000); |
|
|
346 |
} |
|
|
347 |
Delay_ms(3000); |
|
|
348 |
set_pwm1_duty(0); |
|
|
349 |
set_pwm2_duty(0); |
|
|
350 |
del_sms(); |
|
|
351 |
break; |
|
|
352 |
} |
|
|
353 |
else |
|
|
354 |
{ |
|
|
355 |
set_pwm1_duty(VYKON); |
|
|
356 |
set_pwm2_duty(VYKON); |
|
|
357 |
Delay_ms(10000); |
|
|
358 |
fprintf(VRTULE,"[[NEUMIS[["); // "NEUMIS" |
245 |
kaklik |
359 |
Delay_ms(2000); |
246 |
kaklik |
360 |
fprintf(VRTULE,"[[[PSAT[[["); // " PSAT " |
245 |
kaklik |
361 |
Delay_ms(2000); |
246 |
kaklik |
362 |
fprintf(VRTULE,"[[TRUBKO[["); // " TRUBKO " |
245 |
kaklik |
363 |
Delay_ms(3000); |
|
|
364 |
set_pwm1_duty(0); |
|
|
365 |
set_pwm2_duty(0); |
246 |
kaklik |
366 |
del_sms(); |
247 |
kaklik |
367 |
} |
240 |
kaklik |
368 |
} |
245 |
kaklik |
369 |
read_time(); |
240 |
kaklik |
370 |
time=strtoul(odp,&ptr,10); |
246 |
kaklik |
371 |
if((time >= 30 && time <= 32) || (time >= 0 && time <= 2) || (time >= 45 && time <= 47) || (time >= 15 && time <= 17)) |
238 |
kaklik |
372 |
{ |
246 |
kaklik |
373 |
set_pwm1_duty(VYKON); |
|
|
374 |
set_pwm2_duty(VYKON); |
240 |
kaklik |
375 |
} |
|
|
376 |
else |
|
|
377 |
{ |
|
|
378 |
set_pwm1_duty(0); |
|
|
379 |
set_pwm2_duty(0); |
245 |
kaklik |
380 |
} |
223 |
kapl |
381 |
|
238 |
kaklik |
382 |
delay_ms(1000); |
223 |
kapl |
383 |
} |
|
|
384 |
} |