Commit 1ce35c238b289d7e2805138f9cb3291f6c3d5b04

Authored by omahieux
1 parent 1c8cfea4

Ajout code raspberry et arduinoMega

Showing 3 changed files with 384 additions and 0 deletions   Show diff stats
automatique.c 0 → 100644
... ... @@ -0,0 +1,157 @@
  1 +/*-------------------------------------------------------------------------------
  2 +--------------------------PROJET BALLON ATMOSPHERIQUE ---------------------------
  3 +----------------------Baptiste GRILLERE - Olivier MAHIEUX------------------------
  4 +--------------------------------------IMA4---------------------------------------
  5 +---------------------------------------------------------------------------------
  6 +--------------------------------PROGRAMME AUTOMATIQUE----------------------------
  7 +---------------------------------------------------------------------------------*/
  8 +
  9 +#include<stdlib.h>
  10 +#include<stdio.h>
  11 +#include<unistd.h>
  12 +#include<fcntl.h>
  13 +#include<termios.h>
  14 +#include<string.h>
  15 +#include<sys/types.h>
  16 +#include<sys/ioctl.h>
  17 +#include<linux/serial.h>
  18 +
  19 + //INITIALISATIONS
  20 +
  21 + //Variables pour le traitement de données GPS
  22 + char data_gps[1024];
  23 + char trame[69], header[64], time[64], lat[64], longi[64],alt[64], nord[64], est[64];
  24 + char metres[64] = "metres";
  25 + int retoursscanf = 0; //sert à déterminer si on lit une trame GPS complète
  26 +
  27 + //Variables pour la detection de la chute du ballon
  28 + int alt_int_tmp = 50;
  29 + int alt_int;
  30 + int diff=0;
  31 +
  32 + //Descripteurs de fichier pour gestion des ports USB
  33 + int portGPS;
  34 + int portCAPTEUR;
  35 + int portLORA;
  36 + FILE* fp;
  37 +
  38 + char pression[64]; //donnée de pression en hPa
  39 + char hp[16] = "hPa";
  40 + //Le mode initial est "en ascension"
  41 + int mode = 0;
  42 +
  43 +
  44 +
  45 +
  46 +int init_serial(char*device,int speed){
  47 + struct termios new;
  48 + struct termios saveterm;
  49 + int fd = open(device,O_NOCTTY|O_RDWR|O_NONBLOCK);
  50 + if(fd<0){perror(device); exit(-1);}
  51 + tcgetattr(fd,&saveterm); /* save current port settings */
  52 + bzero(&new,sizeof(new));
  53 + new.c_cflag=CLOCAL|CREAD|speed|CS8;
  54 + new.c_iflag=0;
  55 + new.c_oflag=0;
  56 +new.c_lflag=0; /* set input mode (non-canonical, no echo,...) */
  57 + new.c_cc[VTIME]=0; /* inter-character timer unused */
  58 + new.c_cc[VMIN]=1; /* blocking read until 1 char received */
  59 + tcflush(fd, TCIFLUSH);
  60 + tcsetattr(fd,TCSANOW,&new);
  61 + return fd;
  62 + }
  63 +
  64 +
  65 +void init_PORT(){
  66 +
  67 + portGPS = init_serial("/dev/ttyUSB0",B9600);
  68 + portLORA = init_serial("/dev/ttyACM0",B9600);
  69 + portCAPTEUR = init_serial("/dev/ttyACM1",B9600);
  70 + fp=fdopen(portGPS,"r");
  71 +
  72 +}
  73 +
  74 +
  75 +
  76 +//Fonction stockant dans data_GPS les données provenant du GPS
  77 +void lecture_GPS(){
  78 +
  79 + printf("lecture GPS....\n");
  80 +
  81 + while( (retoursscanf != 7) && ( memcmp(header,"$GPGGA",6) != 0) )
  82 + {
  83 + //Acquisition trame GPS
  84 + fgets(data_gps,sizeof(data_gps),fp);
  85 +
  86 + //traitement de la trame
  87 + retoursscanf = sscanf(data_gps,"%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%*[^,],%*[^,],%*[^,],%[^,],%*[^,],%*[^,],%*[^,],%*[^,],%*s", header, time, lat, nord, longi, est, alt);
  88 + //printf("retour: %d\n",retoursscanf);
  89 + printf("header: %s\n",header);
  90 + }
  91 + printf("heure : %s\n", time);
  92 + printf("header : %s\n", header);
  93 + printf("latitude : %s\n", lat);
  94 + printf("longitude : %s\n", longi);
  95 + printf("altitude : %s\n", alt);
  96 +
  97 + alt_int = atoi(alt);
  98 +
  99 + //Envoi au sol des données traitées
  100 + if(mode == 0)
  101 + write(portLORA,&time,sizeof(time));
  102 + if(mode == 0 || mode == 1){
  103 + write(portLORA,&lat,sizeof(lat));
  104 + write(portLORA,&nord,sizeof(nord));
  105 + }
  106 + if(mode == 0 || mode == 1){
  107 + write(portLORA,&longi,sizeof(longi));
  108 + write(portLORA,&est,sizeof(est));
  109 + }
  110 + if(mode==0 || mode==1){
  111 + write(portLORA,&alt,sizeof(alt));
  112 + write(portLORA,&metres,sizeof(metres));
  113 + }
  114 +}
  115 +
  116 +void lecture_capteur(){
  117 + read(portCAPTEUR,&pression,sizeof(pression));
  118 + printf("pression = %s\n",pression);
  119 + write(portLORA,&pression,sizeof(pression));
  120 + write(portLORA,&hp,sizeof(hp));
  121 + sleep(1);
  122 +
  123 +}
  124 +
  125 +//MODE AUTOMATIQUE
  126 +int main(void) {
  127 +
  128 + init_PORT();
  129 +
  130 + while(1) {
  131 + //MODE ASCENSION
  132 + while(mode == 0){
  133 + printf("Mode ascension actif\n");
  134 + lecture_capteur();
  135 + alt_int_tmp = alt_int;
  136 + lecture_GPS();
  137 + diff = abs(alt_int - alt_int_tmp);
  138 + printf("diff: %d\n", diff);
  139 + printf("mode: %d\n",mode);
  140 +
  141 + if(200 <= diff)
  142 + mode = 1;
  143 + sleep(10);
  144 + }
  145 +
  146 + //MODE CHUTE
  147 + while(mode == 1){
  148 + printf("Mode CHUTE\n");
  149 + lecture_GPS();
  150 + sleep(1);
  151 + }
  152 +
  153 + }
  154 +
  155 + return 0;
  156 +}
  157 +
... ...
manuel.c 0 → 100644
... ... @@ -0,0 +1,195 @@
  1 +/*-------------------------------------------------------------------------------
  2 + --------------------------PROJET BALLON ATMOSPHERIQUE ---------------------------
  3 + ----------------------Baptiste GRILLERE - Olivier MAHIEUX------------------------
  4 + --------------------------------------IMA4---------------------------------------
  5 + ---------------------------------------------------------------------------------
  6 + --------------------------------PROGRAMME MANUEL---------------------------------
  7 + ---------------------------------------------------------------------------------*/
  8 +
  9 +#include<stdlib.h>
  10 +#include<stdio.h>
  11 +#include<unistd.h>
  12 +#include<fcntl.h>
  13 +#include<termios.h>
  14 +#include<string.h>
  15 +#include<sys/types.h>
  16 +#include<sys/ioctl.h>
  17 +#include<linux/serial.h>
  18 +
  19 +//INITIALISATIONS
  20 +char chaine[25] = "ici raspberry, over\n";
  21 +char reception[200]; //reception lora
  22 +//chaines servant à la comparaison avec la reception LORA
  23 +char veille[10] = "veille\n";
  24 +char demande_gps[4] = "GPS";
  25 +char demande_char[5] ="char";
  26 +char demande_veille[7] ="veille";
  27 +char demande_altitude[4] = "alt";
  28 +char demande_longitude[5] = "long";
  29 +char demande_latitude[4] = "lat";
  30 +char demande_time[5] = "time";
  31 +char press[9] = "pression";
  32 +
  33 +
  34 +
  35 +char data_gps[1024]; //buffer dans la fonction lecture_GPS()
  36 +char trame[69], header[64], time[64], lat[64], longi[64],alt[64], nord[64], est[64];
  37 +char metres[64] = "metres";
  38 +int retoursscanf = 0;
  39 +int portGPS;
  40 +int portCAPTEUR;
  41 +int portLORA;
  42 +FILE* fp; //utilisation pour le traitement sémantique des données GPS
  43 +char pression[64]; //buffer pour la lecture du capteur
  44 +
  45 +int init_serial(char*device,int speed){
  46 + struct termios new;
  47 + struct termios saveterm;
  48 + int fd = open(device,O_NOCTTY|O_RDWR|O_NONBLOCK);
  49 + if(fd<0){perror(device); exit(-1);}
  50 + tcgetattr(fd,&saveterm); /* save current port settings */
  51 + bzero(&new,sizeof(new));
  52 + new.c_cflag=CLOCAL|CREAD|speed|CS8;
  53 + new.c_iflag=0;
  54 + new.c_oflag=0;
  55 + new.c_lflag=0; /* set input mode (non-canonical, no echo,...) */
  56 + new.c_cc[VMIN]=1; /* blocking read until 1 char received */
  57 + tcflush(fd, TCIFLUSH);
  58 + tcsetattr(fd,TCSANOW,&new);
  59 + return fd;
  60 +}
  61 +
  62 +
  63 +void init_PORT(){
  64 +
  65 + portGPS = init_serial("/dev/ttyUSB0",B9600);
  66 + portLORA = init_serial("/dev/ttyACM1",B9600);
  67 + portCAPTEUR = init_serial("/dev/ttyACM0",B9600);
  68 + fp=fdopen(portGPS,"r");
  69 +
  70 +}
  71 +
  72 +//Le mode initial est "en veille"
  73 +int mode = 0;
  74 +
  75 +
  76 +//Verification et changement éventuel de mode
  77 +void check_mode(){
  78 + if(memcmp(reception,demande_veille,sizeof(demande_veille)-1)==0)
  79 + mode = 0;
  80 + if(memcmp(reception,demande_char,sizeof(demande_char)-1)==0)
  81 + mode = 1;
  82 + if(memcmp(reception,demande_gps,sizeof(demande_gps)-1)==0)
  83 + mode = 2;
  84 + if(memcmp(reception,demande_altitude,sizeof(demande_altitude)-1)==0)
  85 + mode = 3;
  86 + if(memcmp(reception,demande_longitude,sizeof(demande_longitude)-1)==0)
  87 + mode = 4;
  88 + if(memcmp(reception,demande_latitude,sizeof(demande_latitude)-1)==0)
  89 + mode = 5;
  90 + if(memcmp(reception,demande_time,sizeof(demande_time)-1)==0)
  91 + mode = 6;
  92 + if(memcmp(reception,press,sizeof(press)-1)==0)
  93 + mode = 7;
  94 +}
  95 +
  96 +//Fonction lisant ce que le module LORA receptionne
  97 +void lecture_LORA(){
  98 + if ( read(portLORA,reception,sizeof(reception)) != -1){
  99 + printf("reception lora: %s\n",reception);
  100 + }
  101 + check_mode();
  102 +
  103 +}
  104 +
  105 +//Fonction stockant dans data_GPS les données provenant du GPS
  106 +void lecture_GPS(){
  107 + printf("lecture GPS....\n");
  108 +
  109 + while(retoursscanf != 7 || (memcmp(header,"$GPGGA",7) != 0)) //Acquisition d'une trame complète et débutant par $GPGGA
  110 + {
  111 + //Acquisition trame GPS
  112 + fgets(data_gps,sizeof(data_gps),fp);
  113 + //traitement de la trame
  114 + retoursscanf = sscanf(data_gps,"%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%*[^,],%*[^,],%*[^,],%[^,],%*[^,],%*[^,],%*[^,],%*[^,],%*s", header, time, lat, nord, longi, est, alt);
  115 + printf("header: %s\n",header);
  116 + }
  117 + printf("heure : %s\n", time);
  118 + printf("header : %s\n", header);
  119 + printf("latitude : %s\n", lat);
  120 + printf("longitude : %s\n", longi);
  121 + printf("altitude : %s\n", alt);
  122 +
  123 + //Envoi au sol des données traitées
  124 + if(mode == 6)
  125 + write(portLORA,&time,sizeof(time));
  126 + if(mode == 5){
  127 + write(portLORA,&lat,sizeof(lat));
  128 + write(portLORA,&nord,sizeof(nord));
  129 + }
  130 + if(mode == 4) {
  131 + write(portLORA,&longi,sizeof(longi));
  132 + write(portLORA,&est,sizeof(est));
  133 + }
  134 + if(mode == 3){
  135 + write(portLORA,&alt,sizeof(alt));
  136 + write(portLORA,&metres,sizeof(metres));
  137 + }
  138 + if(mode==2){
  139 + write(portLORA,&time,sizeof(time));
  140 + write(portLORA,&lat,sizeof(lat));
  141 + write(portLORA,&nord,sizeof(nord));
  142 + write(portLORA,&longi,sizeof(longi));
  143 + write(portLORA,&est,sizeof(est));
  144 + write(portLORA,&alt,sizeof(alt));
  145 + write(portLORA,&metres,sizeof(metres));
  146 + }
  147 + }
  148 +
  149 + void lecture_capteur(){
  150 + printf("Mode envoi valeur pression\n"); //valeur en hPa
  151 + read(portCAPTEUR,&pression,sizeof(pression));
  152 + printf("pression = %s\n",pression);
  153 + write(portLORA,&pression,sizeof(pression));
  154 + sleep(1);
  155 + }
  156 +
  157 + int main(void) {
  158 +
  159 + init_PORT();
  160 +
  161 + lecture_LORA();
  162 + while(1) {
  163 + //MODE VEILLE
  164 + while(mode==0){
  165 + printf("Mode veille actif\n");
  166 + write(portLORA,&veille,sizeof(veille));
  167 + lecture_LORA(); //ecoute de la station au sol
  168 + sleep(2);
  169 + }
  170 +
  171 + //MODE ENVOI DE CHAINE
  172 + while(mode==1){
  173 + //EMISSION
  174 + printf("Mode envoi de chaine\n");
  175 + write(portLORA,&chaine,sizeof(chaine));
  176 + }
  177 +
  178 + //MODE GPS
  179 + while(2 <= mode && mode <= 6){
  180 + printf("Mode GPS\n");
  181 + lecture_GPS();
  182 + lecture_LORA();
  183 + sleep(10);
  184 + }
  185 +
  186 + //MODE CAPTEUR DE PRESSION
  187 + while(mode == 7){
  188 + lecture_capteur();
  189 + lecture_LORA();
  190 + sleep(2);
  191 + }
  192 + }
  193 +
  194 + return 0;
  195 + }
... ...
pression_analog.ino 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +
  2 +int analogPin = 0; //entrée analogique du capteur
  3 +int val = 0; // variable dans laquelle la donnée brute du capteur est stockée
  4 +float pression; //variable qui contient la valeur de la pression en hPa
  5 +
  6 +
  7 +void setup()
  8 +
  9 +{
  10 +
  11 + Serial.begin(9600); // setup serial à 9 600 bauds
  12 +
  13 +}
  14 +
  15 +
  16 +
  17 +void loop()
  18 +
  19 +{
  20 +
  21 + val = analogRead(analogPin); // lecture du port analogique
  22 +
  23 + // conversion en hPa
  24 + pression = val -0,5;
  25 + pression = pression /2;
  26 + pression = pression * 15;
  27 +
  28 + // envoi de la donnée vers le port série
  29 + Serial.println(pression);
  30 + delay(20000);
  31 +}
  32 +
... ...