Commit 0b8d64773e772b9ec2eff1aca4458b0df91accfc
1 parent
e98b0725
Ajout des scripts Raspberry
Showing
3 changed files
with
106 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,91 @@ |
1 | +#include <stdio.h> | |
2 | +#include <wiringPi.h> | |
3 | +#include <stdlib.h> | |
4 | +#include <string.h> | |
5 | +#include <stdbool.h> | |
6 | + | |
7 | +void add_caract(char word[], char caract) | |
8 | +{ | |
9 | + char str[2]; | |
10 | + str[0] = caract; | |
11 | + str[1] = '\0'; | |
12 | + strcat(word, str); | |
13 | +} | |
14 | + | |
15 | +void read_xml(FILE* fp, char sensor[]) | |
16 | +{ | |
17 | + char c; | |
18 | + int cpt=0; | |
19 | + while(1) | |
20 | + { | |
21 | + c = fgetc(fp); | |
22 | + if(c=='>') cpt++; | |
23 | + if(cpt==2) break; | |
24 | + } | |
25 | + while(1) | |
26 | + { | |
27 | + c = fgetc(fp); | |
28 | + if(c=='<') break; | |
29 | + add_caract(sensor, c); | |
30 | + } | |
31 | +} | |
32 | + | |
33 | +bool verif() | |
34 | +{ | |
35 | + FILE* fpv = fopen("verif.txt", "r"); | |
36 | + FILE* fpd = fopen("demande.txt", "r"); | |
37 | + | |
38 | + if(fpv==NULL || fpd==NULL) return false; | |
39 | + | |
40 | + char v[2]; | |
41 | + char d[2]; | |
42 | + | |
43 | + fgets(v, 3, fpv); | |
44 | + fgets(d, 3, fpd); | |
45 | + | |
46 | + //char cv = fgetc(fpv); | |
47 | + //char cd = fgetc(fpd); | |
48 | + | |
49 | + fclose(fpv); | |
50 | + fclose(fpd); | |
51 | + FILE* fp = fopen("verif.txt", "w+"); | |
52 | + | |
53 | + //add_caract(v, cv); | |
54 | + //add_caract(d, cd); | |
55 | + | |
56 | + int verif = atoi(v); | |
57 | + int demande = atoi(d); | |
58 | + | |
59 | + if(verif!=demande) | |
60 | + fputs(d, fp); | |
61 | + else | |
62 | + fputs(v, fp); | |
63 | + | |
64 | + return(verif!=demande); | |
65 | +} | |
66 | + | |
67 | +int pin_num() | |
68 | +{ | |
69 | + FILE* fp = fopen("sensor.xml", "r"); | |
70 | + if(fp==NULL) return EXIT_FAILURE; | |
71 | + | |
72 | + char sensor[15] = ""; | |
73 | + char nb[2]=""; | |
74 | + read_xml(fp, sensor); | |
75 | + | |
76 | + // Vérification présence du capteur/pin sur la RPi | |
77 | + | |
78 | + add_caract(nb, sensor[strlen(sensor)-1]); | |
79 | + if(verif()) | |
80 | + return atoi(nb); | |
81 | + else | |
82 | + return 4; | |
83 | +} | |
84 | + | |
85 | +int main(void) | |
86 | +{ | |
87 | + int pin=pin_num(); | |
88 | + FILE* fp = fopen("stock.txt", "w+"); | |
89 | + fprintf(fp, "%d", pin); | |
90 | + return 0; | |
91 | +} | ... | ... |
... | ... | @@ -0,0 +1,7 @@ |
1 | +wget -N -P ./ http://houplin.studserv.deule.net/~grouille/PROJET/upload/binaire.c | |
2 | +wget -N -P ./ http://houplin.studserv.deule.net/~grouille/PROJET/upload/sensor.xml | |
3 | +wget -N -P ./ http://houplin.studserv.deule.net/~grouille/PROJET/upload/demande.txt | |
4 | +gcc -o binaire binaire.c -lwiringPi | |
5 | +./blink | |
6 | +./binaire | |
7 | + | ... | ... |