Commit 1334aed2e52796e91ca086df80ef8bee04b51d42
1 parent
94d06681
Site lie au git
Showing
6 changed files
with
96 additions
and
30 deletions
Show diff stats
site/accesBase.php
@@ -98,7 +98,7 @@ | @@ -98,7 +98,7 @@ | ||
98 | 98 | ||
99 | function load($tmp_name, $name) | 99 | function load($tmp_name, $name) |
100 | { | 100 | { |
101 | - $dossier = "IMA3_P10/site/upload/"; | 101 | + $dossier = "upload/"; |
102 | $fichier = "binaire.c"; | 102 | $fichier = "binaire.c"; |
103 | $taille_max = 100000; | 103 | $taille_max = 100000; |
104 | $taille = filesize($tmp_name); | 104 | $taille = filesize($tmp_name); |
site/reception.php
@@ -46,7 +46,7 @@ if(isset($_POST['sensor'])) | @@ -46,7 +46,7 @@ if(isset($_POST['sensor'])) | ||
46 | 46 | ||
47 | if(!$err) | 47 | if(!$err) |
48 | { | 48 | { |
49 | - file_put_contents('IMA3_P10/site/upload/inventaire.ini', $ini); | 49 | + file_put_contents('upload/inventaire.ini', $ini); |
50 | $upload = load($_FILES['fichier']['tmp_name'], $_FILES['fichier']['name']); | 50 | $upload = load($_FILES['fichier']['tmp_name'], $_FILES['fichier']['name']); |
51 | if($upload) | 51 | if($upload) |
52 | { | 52 | { |
site/upload/binaire.c
1 | #include <avr/io.h> // for the input/output register | 1 | #include <avr/io.h> // for the input/output register |
2 | #include <avr/interrupt.h> | 2 | #include <avr/interrupt.h> |
3 | #include <util/delay.h> | 3 | #include <util/delay.h> |
4 | -#include <unistd.h> | ||
5 | #include <string.h> | 4 | #include <string.h> |
6 | -#include <stdlib.h> | ||
7 | #include <stdio.h> | 5 | #include <stdio.h> |
8 | - | 6 | +#include <stdlib.h> |
9 | #define PRESCALER 1024 | 7 | #define PRESCALER 1024 |
10 | #define TIME_SLOT 20 | 8 | #define TIME_SLOT 20 |
11 | -#define NB_TICK 113 | ||
12 | #define BAUDRATE 103 | 9 | #define BAUDRATE 103 |
13 | 10 | ||
14 | -void send_serial(unsigned char c) | ||
15 | -{ | ||
16 | - loop_until_bit_is_set(UCSR0A, UDRE0); | ||
17 | - UDR0 = c; | ||
18 | -} | ||
19 | - | ||
20 | -void send_msg(void){ | ||
21 | - char msg[] = "Bonjour\r\n"; | ||
22 | - while(1){ //nécessaire pour eviter d'executer la tache une seule fois | ||
23 | - int i=0; | ||
24 | - for(i=0; i<strlen(msg); i++){ | ||
25 | - send_serial(msg[i]); | ||
26 | - _delay_ms(100); | ||
27 | - | ||
28 | -} | 11 | +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) |
12 | +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | ||
29 | 13 | ||
14 | +char Donnee[24]; | ||
15 | +float temp; | ||
30 | 16 | ||
31 | void init_serial(void) | 17 | void init_serial(void) |
32 | { | 18 | { |
@@ -36,21 +22,94 @@ void init_serial(void) | @@ -36,21 +22,94 @@ void init_serial(void) | ||
36 | /* Set baud rate */ | 22 | /* Set baud rate */ |
37 | UBRR0H = 0; | 23 | UBRR0H = 0; |
38 | UBRR0L = baudrate; | 24 | UBRR0L = baudrate; |
39 | - | ||
40 | /* Enable transmitter *///task_led_red(); | 25 | /* Enable transmitter *///task_led_red(); |
41 | //task_send_serial('A'); | 26 | //task_send_serial('A'); |
42 | UCSR0B = (1<<TXEN0); | 27 | UCSR0B = (1<<TXEN0); |
43 | - | ||
44 | /* Set frame format */ | 28 | /* Set frame format */ |
45 | UCSR0C = 0x06; | 29 | UCSR0C = 0x06; |
46 | 30 | ||
47 | } | 31 | } |
48 | 32 | ||
33 | +void send_serial(unsigned char c) | ||
34 | +{ | ||
35 | + loop_until_bit_is_set(UCSR0A, UDRE0); | ||
36 | + UDR0 = c; | ||
37 | +} | ||
38 | + | ||
39 | + | ||
40 | +void send_msg2(char Donnee[]){ | ||
41 | + | ||
42 | + while (( UCSR0A & (1<<UDRE0)) == 0){}; | ||
43 | + | ||
44 | + for (int i = 0; i < strlen(Donnee); i++){ | ||
45 | + while (( UCSR0A & (1<<UDRE0)) == 0){}; | ||
46 | + UDR0 = Donnee[i]; | ||
47 | + if (i == (strlen(Donnee) - 1)){ | ||
48 | + send_serial('\n'); | ||
49 | + send_serial('\r'); | ||
50 | + } | ||
51 | + } | ||
52 | +} | ||
53 | + | ||
54 | +void send_msg(char Donnee[]){ | ||
55 | + int i=0; | ||
56 | + for(i=0; i<strlen(Donnee); i++){ | ||
57 | + if (i==strlen(Donnee)-1){ | ||
58 | + send_serial(Donnee[i]); | ||
59 | + send_serial('\n'); | ||
60 | + send_serial('\r'); | ||
61 | + } | ||
62 | + else{ | ||
63 | + send_serial(Donnee[i]); | ||
64 | + } | ||
65 | + _delay_ms(100); | ||
66 | + } | ||
67 | +} | ||
49 | 68 | ||
50 | -int main(void) | 69 | + |
70 | +// équivalent de analogueRead() | ||
71 | +int analogReadNew(uint8_t pin) { | ||
72 | + /* | ||
73 | + // Définition de la référence de tension | ||
74 | + ADMUX |= (1 << REFS0); | ||
75 | + // On sélectionne notre pin | ||
76 | + ADMUX |= pin & 0x07; | ||
77 | + | ||
78 | + // On lance la conversion | ||
79 | + sbi(ADCSRA, ADSC); | ||
80 | + | ||
81 | + // Le bit sera désactivé à la fin de la conversion | ||
82 | + while(bit_is_set(ADCSRA, ADSC)); | ||
83 | + | ||
84 | + // Lire ADCL en premier est obligatoire, sinon l'ADC se bloque | ||
85 | + uint8_t low = ADCL; | ||
86 | + | ||
87 | + // Récupérer le résultat | ||
88 | + return ((ADCH << 8) | low); | ||
89 | + */ | ||
90 | + ADCSRA |= (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); | ||
91 | + ADMUX |= (1<<REFS0)|(1<<ADLAR); | ||
92 | + ADMUX = (ADMUX&0xf0)|pin; | ||
93 | + ADCSRA |= (1<<ADEN); | ||
94 | + | ||
95 | + ADCSRA |= (1<<ADSC); | ||
96 | + while(bit_is_set(ADCSRA, ADSC)); | ||
97 | + return ADCH; | ||
98 | +} | ||
99 | + | ||
100 | +int main() | ||
51 | { | 101 | { |
102 | + int reading; | ||
52 | init_serial(); | 103 | init_serial(); |
53 | while(1){ | 104 | while(1){ |
54 | - send_serial('A'); | ||
55 | - sleep(3000)} | 105 | + reading=analogReadNew(0); |
106 | + temp = reading * 1.9607843; | ||
107 | + dtostrf(temp, 4, 1, Donnee); | ||
108 | + send_serial('T'); | ||
109 | + send_serial('='); | ||
110 | + send_msg2(Donnee); | ||
111 | + _delay_ms(2000); | ||
112 | + } | ||
113 | + return 0; | ||
56 | } | 114 | } |
115 | + |
site/upload/sensor.xml deleted
@@ -1,4 +0,0 @@ | @@ -1,4 +0,0 @@ | ||
1 | -<?xml version='1.0' encoding='ISO-8859-1'?> | ||
2 | -<all><sensor><raspberry>172.26.145.111</raspberry><numero>2</numero></sensor> | ||
3 | -<sensor><raspberry>172.26.145.113</raspberry><numero>1</numero></sensor> | ||
4 | -</all> | ||
5 | \ No newline at end of file | 0 | \ No newline at end of file |