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