From 0b8d64773e772b9ec2eff1aca4458b0df91accfc Mon Sep 17 00:00:00 2001 From: grouille Date: Fri, 31 May 2019 11:49:57 +0200 Subject: [PATCH] Ajout des scripts Raspberry --- blink.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ load.sh | 7 +++++++ script.sh | 8 ++++++++ 3 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 blink.c create mode 100644 load.sh create mode 100644 script.sh diff --git a/blink.c b/blink.c new file mode 100644 index 0000000..c601f16 --- /dev/null +++ b/blink.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include + +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; +} diff --git a/load.sh b/load.sh new file mode 100644 index 0000000..d7e130d --- /dev/null +++ b/load.sh @@ -0,0 +1,7 @@ +wget -N -P ./ http://houplin.studserv.deule.net/~grouille/PROJET/upload/binaire.c +wget -N -P ./ http://houplin.studserv.deule.net/~grouille/PROJET/upload/sensor.xml +wget -N -P ./ http://houplin.studserv.deule.net/~grouille/PROJET/upload/demande.txt +gcc -o binaire binaire.c -lwiringPi +./blink +./binaire + diff --git a/script.sh b/script.sh new file mode 100644 index 0000000..25284f6 --- /dev/null +++ b/script.sh @@ -0,0 +1,8 @@ +#!/bin/sh +while true +do + ./load.sh + sleep 15 +done + + -- libgit2 0.21.2