Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@31:73be27ad5d69, 2022-06-22 (annotated)
- Committer:
- snec_student
- Date:
- Wed Jun 22 09:23:22 2022 +0000
- Revision:
- 31:73be27ad5d69
- Parent:
- 30:2457f9928392
fonctionne en boucle avec WX200 et pyranometre
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan | 0:7dec7e9ac085 | 1 | #include "mbed.h" |
snec_student | 28:6f0009bce093 | 2 | /**************************************************************/ |
snec_student | 28:6f0009bce093 | 3 | /* Déclaration des Sous fonctions */ |
snec_student | 28:6f0009bce093 | 4 | /**************************************************************/ |
snec_student | 31:73be27ad5d69 | 5 | // initialisations Leds |
snec_student | 31:73be27ad5d69 | 6 | DigitalOut Led_rouge(LED1,1); |
snec_student | 31:73be27ad5d69 | 7 | DigitalOut Led_verte(LED2,1); |
snec_student | 31:73be27ad5d69 | 8 | DigitalOut Led_bleue(LED3,1); |
snec_student | 31:73be27ad5d69 | 9 | // Initialisation WX200 |
snec_student | 28:6f0009bce093 | 10 | void ISR_read(); // lecture liaison serie |
snec_student | 28:6f0009bce093 | 11 | uint8_t gencrc2(uint8_t *data); // calcul crc NMEA |
snec_student | 30:2457f9928392 | 12 | void lire_luminosite(); |
snec_student | 30:2457f9928392 | 13 | void lire_WX200(); |
snec_student | 28:6f0009bce093 | 14 | DigitalOut myled(PTB22); |
snec_student | 29:fbc5f53d8d0f | 15 | DigitalOut CMD_200WX(PTA1,0); |
snec_student | 29:fbc5f53d8d0f | 16 | // initialisation de la liaison serie vers le capteur WX200 |
snec_student | 28:6f0009bce093 | 17 | static UnbufferedSerial capt(PTC4,PTC3,4800); |
snec_student | 28:6f0009bce093 | 18 | char c; |
snec_student | 28:6f0009bce093 | 19 | char Rx_buffer[100]; |
snec_student | 28:6f0009bce093 | 20 | char trame[100]; |
snec_student | 28:6f0009bce093 | 21 | char trame_cpy[100]; |
snec_student | 28:6f0009bce093 | 22 | volatile bool flag_ISR_read=0; |
snec_student | 28:6f0009bce093 | 23 | volatile int index=0; |
snec_student | 29:fbc5f53d8d0f | 24 | // variables associees au capteur WX200 |
snec_student | 29:fbc5f53d8d0f | 25 | static char type[20]; // type de la trame (GPGGA, RMC...) |
snec_student | 29:fbc5f53d8d0f | 26 | const char * separators = ","; // separateurs pour une trame NMEA |
snec_student | 29:fbc5f53d8d0f | 27 | char i; |
snec_student | 29:fbc5f53d8d0f | 28 | size_t len; |
snec_student | 29:fbc5f53d8d0f | 29 | uint8_t val_crc; // valeur du crc calcule a la reception de la trame |
snec_student | 29:fbc5f53d8d0f | 30 | // variables associees a une trame de type GPGGA |
snec_student | 29:fbc5f53d8d0f | 31 | bool flag_GPGGA=0; |
snec_student | 29:fbc5f53d8d0f | 32 | static char horaire[20]; // heure UTC (champ 1) |
snec_student | 29:fbc5f53d8d0f | 33 | static char lattitude[20]; // Lattitude (champ 2) |
snec_student | 29:fbc5f53d8d0f | 34 | static char hemisphere[2]; // Hemisphere (N/S) (champ 3) |
snec_student | 29:fbc5f53d8d0f | 35 | static char longitude[20]; // Longitude (champ 4) |
snec_student | 29:fbc5f53d8d0f | 36 | static char dir[2]; // direction (E/W) (champ 5) |
snec_student | 29:fbc5f53d8d0f | 37 | static char quality[2]; // GPS quality indicator (0 a 8) (champ 6) |
snec_student | 29:fbc5f53d8d0f | 38 | static char nb_satellites[10]; // Number of satellites in use, 0-12 (champ 7) |
snec_student | 29:fbc5f53d8d0f | 39 | static char HDOP[10]; // Horizontal dilution of precision (HDOP) (champ 8) |
snec_student | 29:fbc5f53d8d0f | 40 | static char altitude[10]; // Altitude relative to mean-sea-level (geoid), meters (to the nearest whole meter) (champ 9) |
snec_student | 29:fbc5f53d8d0f | 41 | static char M[2]; // M (champ 10) |
snec_student | 29:fbc5f53d8d0f | 42 | static char altitude_cor[10]; // Geoidal separation, meters (to the nearest whole meter). (champ 11) |
snec_student | 29:fbc5f53d8d0f | 43 | int n_sat; // nombre de satellites |
snec_student | 29:fbc5f53d8d0f | 44 | |
snec_student | 29:fbc5f53d8d0f | 45 | // variables associees a une trame de type WIMDA |
snec_student | 29:fbc5f53d8d0f | 46 | bool flag_WIMDA=0; |
snec_student | 29:fbc5f53d8d0f | 47 | static char pres_inch[20]; // Barometric pressure, inches of mercury, to the nearest 0.01 inch (champ 1) |
snec_student | 29:fbc5f53d8d0f | 48 | static char I[2]; // inches of mercury (champ 2) |
snec_student | 29:fbc5f53d8d0f | 49 | static char pres_bar[20]; // Barometric pressure, bars, to the nearest .001 bar(champ 3) |
snec_student | 29:fbc5f53d8d0f | 50 | static char B[2]; // B = bars (champ 4) |
snec_student | 29:fbc5f53d8d0f | 51 | static char air_temp[10]; // Air temperature, degrees C, to the nearest 0.1 degree C (champ 5) |
snec_student | 29:fbc5f53d8d0f | 52 | static char C1[2]; // C = degrees C (champ 6) |
snec_student | 29:fbc5f53d8d0f | 53 | static char wat_temp[10]; // Water temperature, degrees C (champ 7) blank with WX200 |
snec_student | 29:fbc5f53d8d0f | 54 | static char C2[2]; // C = degrees C (champ 8) |
snec_student | 30:2457f9928392 | 55 | static char rel_hum[10]; // Relative humidity, percent, to the nearest 0.1 percent (champ 9) |
snec_student | 29:fbc5f53d8d0f | 56 | static char abs_hum[10]; // Absolute humidity, percent (champ 10) blank with WX200 |
snec_student | 29:fbc5f53d8d0f | 57 | static char dew_point[10]; // Dew point, degrees C, to the nearest 0.1 degree C (champ 11) blank with WX200 |
snec_student | 29:fbc5f53d8d0f | 58 | static char C3[2]; // C = degrees C (champ 12) |
snec_student | 30:2457f9928392 | 59 | static char Wind_dir_T[10]; // Wind direction, degrees True, to the nearest 0.1 degree (champ 13) |
snec_student | 29:fbc5f53d8d0f | 60 | static char T[2]; // T = True (champ 14) |
snec_student | 30:2457f9928392 | 61 | static char Wind_dir_M[10]; // Wind direction, degrees Magnetic, to the nearest 0.1 degree (champ 15) |
snec_student | 29:fbc5f53d8d0f | 62 | static char M2[2]; // M = magnetic (champ 16) |
snec_student | 30:2457f9928392 | 63 | static char Wind_speed_knots[10]; // Wind speed, knots, to the nearest 0.1 knot (champ 17) |
snec_student | 29:fbc5f53d8d0f | 64 | static char N[2]; // N = knots (champ 18) |
snec_student | 30:2457f9928392 | 65 | static char Wind_speed_ms[10]; // Wind speed, meters per second, to the nearest 0.1 m/s (champ 19) |
snec_student | 29:fbc5f53d8d0f | 66 | static char M3[2]; // M = meters per second(champ 20) |
snec_student | 29:fbc5f53d8d0f | 67 | // variables associees a une trame de type GPRMC |
snec_student | 28:6f0009bce093 | 68 | static char vitesse[20]; |
snec_student | 28:6f0009bce093 | 69 | static char cap[20]; |
snec_student | 28:6f0009bce093 | 70 | static char date[20]; |
snec_student | 28:6f0009bce093 | 71 | static char magn[20]; |
snec_student | 28:6f0009bce093 | 72 | static char crc[10]; |
snec_student | 29:fbc5f53d8d0f | 73 | |
snec_student | 29:fbc5f53d8d0f | 74 | |
snec_student | 29:fbc5f53d8d0f | 75 | |
snec_student | 29:fbc5f53d8d0f | 76 | static char alerte[3]; |
snec_student | 29:fbc5f53d8d0f | 77 | |
snec_student | 29:fbc5f53d8d0f | 78 | |
dan | 0:7dec7e9ac085 | 79 | |
snec_student | 28:6f0009bce093 | 80 | int main() |
snec_student | 28:6f0009bce093 | 81 | { |
snec_student | 31:73be27ad5d69 | 82 | printf("lancement programme\n"); |
snec_student | 31:73be27ad5d69 | 83 | |
snec_student | 31:73be27ad5d69 | 84 | while(true) { |
snec_student | 31:73be27ad5d69 | 85 | // lecture luminosite |
snec_student | 31:73be27ad5d69 | 86 | printf ("mesure luminosite \n"); |
snec_student | 31:73be27ad5d69 | 87 | lire_luminosite(); |
snec_student | 31:73be27ad5d69 | 88 | printf ("lecture WX200 \n"); |
snec_student | 31:73be27ad5d69 | 89 | lire_WX200(); |
snec_student | 31:73be27ad5d69 | 90 | printf ("attente 5s.... \n"); |
snec_student | 31:73be27ad5d69 | 91 | thread_sleep_for (5000); |
snec_student | 30:2457f9928392 | 92 | } |
snec_student | 30:2457f9928392 | 93 | } // fin programme |
snec_student | 30:2457f9928392 | 94 | |
snec_student | 30:2457f9928392 | 95 | |
snec_student | 30:2457f9928392 | 96 | |
snec_student | 30:2457f9928392 | 97 | /******* Sous fonctions ***************/ |
snec_student | 30:2457f9928392 | 98 | void ISR_read() // lecture liaison serie |
snec_student | 30:2457f9928392 | 99 | { |
snec_student | 30:2457f9928392 | 100 | char carac; |
snec_student | 30:2457f9928392 | 101 | capt.read(&carac, 1); |
snec_student | 30:2457f9928392 | 102 | if (index==100 || carac=='$') index=0; |
snec_student | 30:2457f9928392 | 103 | Rx_buffer[index]=carac; |
snec_student | 30:2457f9928392 | 104 | index++; |
snec_student | 30:2457f9928392 | 105 | if (carac==0x0a) { |
snec_student | 30:2457f9928392 | 106 | Rx_buffer[index]=0; |
snec_student | 30:2457f9928392 | 107 | for (char i=0; i<index+1; i++) trame[i] = Rx_buffer[i]; |
snec_student | 30:2457f9928392 | 108 | index=0; |
snec_student | 30:2457f9928392 | 109 | flag_ISR_read=1; |
snec_student | 30:2457f9928392 | 110 | } |
snec_student | 30:2457f9928392 | 111 | } |
snec_student | 30:2457f9928392 | 112 | |
snec_student | 30:2457f9928392 | 113 | /************** Lecture Pyranometre ************************/ |
snec_student | 30:2457f9928392 | 114 | void lire_luminosite() |
snec_student | 30:2457f9928392 | 115 | { |
snec_student | 30:2457f9928392 | 116 | DigitalOut Cmd_Pyr(PTA2); |
snec_student | 30:2457f9928392 | 117 | AnalogIn ain0(A0); |
snec_student | 30:2457f9928392 | 118 | Cmd_Pyr=1; // on alimente le pyranometre! |
snec_student | 31:73be27ad5d69 | 119 | printf("Alimentation du pyranometre, mesures dans 5s... \n"); |
snec_student | 31:73be27ad5d69 | 120 | thread_sleep_for (5000); // on laisse 5 s pour la mesure |
snec_student | 30:2457f9928392 | 121 | const float Vcc=3.3; |
snec_student | 30:2457f9928392 | 122 | float tension= Vcc*ain0.read(); |
snec_student | 30:2457f9928392 | 123 | int lum_Wm=tension*1000+(-400); |
snec_student | 30:2457f9928392 | 124 | float lum_lux=lum_Wm*683; |
snec_student | 30:2457f9928392 | 125 | //pc.printf("ain0 : %1.3f V \n\n",ain0.read()); |
snec_student | 30:2457f9928392 | 126 | //pc.printf("mesure : %1.3f V \n\n",tension); |
snec_student | 30:2457f9928392 | 127 | printf("luminosite : %d W/m^2 \n\n",lum_Wm); |
snec_student | 30:2457f9928392 | 128 | //pc.printf("luminosite : %1.0f lux \n\n",lum_lux); |
snec_student | 30:2457f9928392 | 129 | printf ("coupure du pyranometre \n"); |
snec_student | 30:2457f9928392 | 130 | Cmd_Pyr=0; // on coupe le pyranometre! |
snec_student | 30:2457f9928392 | 131 | } |
snec_student | 30:2457f9928392 | 132 | |
snec_student | 30:2457f9928392 | 133 | |
snec_student | 30:2457f9928392 | 134 | /************** Lecture Station WX200 ************************/ |
snec_student | 30:2457f9928392 | 135 | void lire_WX200() |
snec_student | 30:2457f9928392 | 136 | { |
snec_student | 31:73be27ad5d69 | 137 | // autorise departs en interruption liaison serie |
snec_student | 28:6f0009bce093 | 138 | capt.attach(&ISR_read,SerialBase::RxIrq); |
snec_student | 29:fbc5f53d8d0f | 139 | // attente 3 secondes puis alimentation du capteur |
snec_student | 30:2457f9928392 | 140 | thread_sleep_for (500); |
snec_student | 31:73be27ad5d69 | 141 | printf("lecture station meteo WX200 dans 5 s\n"); |
snec_student | 30:2457f9928392 | 142 | printf("Lecture trame GPGGA \n"); |
snec_student | 31:73be27ad5d69 | 143 | thread_sleep_for (5000); // on laisse 5 s de mesures |
snec_student | 29:fbc5f53d8d0f | 144 | CMD_200WX=1; |
snec_student | 30:2457f9928392 | 145 | while(flag_GPGGA==0) { // afaire en boucle tant que l'on a pas recu les infos |
snec_student | 29:fbc5f53d8d0f | 146 | // si une trame est recue |
snec_student | 28:6f0009bce093 | 147 | if (flag_ISR_read==1) { |
snec_student | 30:2457f9928392 | 148 | flag_ISR_read=0; |
snec_student | 28:6f0009bce093 | 149 | //printf("%s",trame); // ligne de test gps |
snec_student | 29:fbc5f53d8d0f | 150 | char* token = strtok(trame,"*"); //on met dans trame_cpy la trame sans crc |
snec_student | 28:6f0009bce093 | 151 | strcpy(trame_cpy,token); |
snec_student | 29:fbc5f53d8d0f | 152 | token = strtok(NULL,"*"); // on copie la valeur du crc recu dans crc |
snec_student | 28:6f0009bce093 | 153 | strcpy(crc,token); |
snec_student | 29:fbc5f53d8d0f | 154 | // on calcule la valeur du crc dans la trame recue |
snec_student | 29:fbc5f53d8d0f | 155 | val_crc=gencrc2((uint8_t *)trame_cpy); |
snec_student | 28:6f0009bce093 | 156 | uint8_t val_crc2; |
snec_student | 28:6f0009bce093 | 157 | sscanf(crc,"%x",&val_crc2); |
snec_student | 29:fbc5f53d8d0f | 158 | // on teste la validite du crc recu |
snec_student | 28:6f0009bce093 | 159 | if (val_crc!=val_crc2) { |
snec_student | 30:2457f9928392 | 160 | // printf ("crc error\n"); |
snec_student | 28:6f0009bce093 | 161 | } else { |
snec_student | 29:fbc5f53d8d0f | 162 | // traitement de la trame en cas de crc correct |
snec_student | 30:2457f9928392 | 163 | // printf ("crc OK\n"); |
snec_student | 29:fbc5f53d8d0f | 164 | //printf("trame :%s \n",trame_cpy); |
snec_student | 29:fbc5f53d8d0f | 165 | char* token = strtok((char*)trame_cpy,separators); |
snec_student | 29:fbc5f53d8d0f | 166 | strcpy(type,token); |
snec_student | 29:fbc5f53d8d0f | 167 | if ((strcmp(type,"$GPGGA")==0)&&(flag_GPGGA==0)) { // traitement d'une trame GPGGA |
snec_student | 30:2457f9928392 | 168 | printf("trame GPGGA : %s \n",trame); |
snec_student | 29:fbc5f53d8d0f | 169 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 170 | if (strcmp(token,"")!=0) strcpy(horaire,token); |
snec_student | 29:fbc5f53d8d0f | 171 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 172 | strcpy(lattitude,token); |
snec_student | 29:fbc5f53d8d0f | 173 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 174 | strcpy(hemisphere,token); |
snec_student | 29:fbc5f53d8d0f | 175 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 176 | strcpy(longitude,token); |
snec_student | 29:fbc5f53d8d0f | 177 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 178 | strcpy(dir,token); |
snec_student | 29:fbc5f53d8d0f | 179 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 180 | strcpy(quality,token); |
snec_student | 29:fbc5f53d8d0f | 181 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 182 | strcpy(nb_satellites,token); |
snec_student | 29:fbc5f53d8d0f | 183 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 184 | strcpy(HDOP,token); |
snec_student | 29:fbc5f53d8d0f | 185 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 186 | strcpy(altitude,token); |
snec_student | 29:fbc5f53d8d0f | 187 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 188 | strcpy(M,token); |
snec_student | 29:fbc5f53d8d0f | 189 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 190 | strcpy(altitude_cor,token); |
snec_student | 29:fbc5f53d8d0f | 191 | token = strtok(NULL,separators); |
snec_student | 29:fbc5f53d8d0f | 192 | token = strtok(NULL,separators); |
snec_student | 30:2457f9928392 | 193 | if (strcmp(nb_satellites,"")!=0) { |
snec_student | 30:2457f9928392 | 194 | n_sat=atoi(nb_satellites); // calcul du nombre de satellites |
snec_student | 30:2457f9928392 | 195 | } |
snec_student | 30:2457f9928392 | 196 | if (n_sat>3) { |
snec_student | 30:2457f9928392 | 197 | flag_GPGGA=1; // on signale la fin d'une lecture correcte GPGGA |
snec_student | 30:2457f9928392 | 198 | printf("GPGGA OK\n"); |
snec_student | 30:2457f9928392 | 199 | } |
snec_student | 29:fbc5f53d8d0f | 200 | } // fin if GPGGA |
snec_student | 30:2457f9928392 | 201 | } // fin else (traitement trame correcte) |
snec_student | 30:2457f9928392 | 202 | }//fin if read enable |
snec_student | 30:2457f9928392 | 203 | } // fin while flags ==0 |
snec_student | 30:2457f9928392 | 204 | while(flag_WIMDA==0) { // afaire en boucle tant que l'on a pas recu les infos |
snec_student | 30:2457f9928392 | 205 | // si une trame est recue |
snec_student | 31:73be27ad5d69 | 206 | printf("Lecture trame WIMDA \n"); |
snec_student | 30:2457f9928392 | 207 | if (flag_ISR_read==1) { |
snec_student | 30:2457f9928392 | 208 | flag_ISR_read=0; |
snec_student | 30:2457f9928392 | 209 | //printf("%s",trame); // ligne de test gps |
snec_student | 30:2457f9928392 | 210 | char* token = strtok(trame,"*"); //on met dans trame_cpy la trame sans crc |
snec_student | 30:2457f9928392 | 211 | strcpy(trame_cpy,token); |
snec_student | 30:2457f9928392 | 212 | token = strtok(NULL,"*"); // on copie la valeur du crc recu dans crc |
snec_student | 30:2457f9928392 | 213 | strcpy(crc,token); |
snec_student | 30:2457f9928392 | 214 | // on calcule la valeur du crc dans la trame recue |
snec_student | 30:2457f9928392 | 215 | val_crc=gencrc2((uint8_t *)trame_cpy); |
snec_student | 30:2457f9928392 | 216 | uint8_t val_crc2; |
snec_student | 30:2457f9928392 | 217 | sscanf(crc,"%x",&val_crc2); |
snec_student | 30:2457f9928392 | 218 | // on teste la validite du crc recu |
snec_student | 30:2457f9928392 | 219 | if (val_crc!=val_crc2) { |
snec_student | 30:2457f9928392 | 220 | // printf ("crc error\n"); |
snec_student | 30:2457f9928392 | 221 | } else { |
snec_student | 30:2457f9928392 | 222 | // traitement de la trame en cas de crc correct |
snec_student | 30:2457f9928392 | 223 | //printf ("crc OK\n"); |
snec_student | 30:2457f9928392 | 224 | //printf("trame :%s \n",trame_cpy); |
snec_student | 30:2457f9928392 | 225 | char* token = strtok((char*)trame_cpy,separators); |
snec_student | 30:2457f9928392 | 226 | strcpy(type,token); |
snec_student | 30:2457f9928392 | 227 | if ((strcmp(type,"$WIMDA")==0)&&(flag_WIMDA==0)) { // traitement d'une trame WIMDA |
snec_student | 29:fbc5f53d8d0f | 228 | //capt.detach(); |
snec_student | 30:2457f9928392 | 229 | printf("trame WIMDA : %s \n",trame); |
snec_student | 29:fbc5f53d8d0f | 230 | token = strtok(NULL,separators); // champ1 |
snec_student | 29:fbc5f53d8d0f | 231 | if (strcmp(token,"")!=0)strcpy(pres_inch,token); |
snec_student | 29:fbc5f53d8d0f | 232 | token = strtok(NULL,separators); // champ2 |
snec_student | 29:fbc5f53d8d0f | 233 | if (strcmp(token,"")!=0) strcpy(I,token); |
snec_student | 29:fbc5f53d8d0f | 234 | token = strtok(NULL,separators); // champ3 |
snec_student | 29:fbc5f53d8d0f | 235 | if (strcmp(token,"")!=0)strcpy(pres_bar,token); |
snec_student | 29:fbc5f53d8d0f | 236 | token = strtok(NULL,separators); // champ4 |
snec_student | 29:fbc5f53d8d0f | 237 | if (strcmp(token,"")!=0)strcpy(B,token); |
snec_student | 29:fbc5f53d8d0f | 238 | token = strtok(NULL,separators); // champ5 |
snec_student | 29:fbc5f53d8d0f | 239 | if (strcmp(token,"")!=0)strcpy(air_temp,token); |
snec_student | 29:fbc5f53d8d0f | 240 | token = strtok(NULL,separators); // champ6 |
snec_student | 29:fbc5f53d8d0f | 241 | strcpy(C1,token); |
snec_student | 30:2457f9928392 | 242 | /* token = strtok(NULL,separators); // champ7 |
snec_student | 30:2457f9928392 | 243 | if (strcmp(token,"")!=0)strcpy(wat_temp,token); |
snec_student | 30:2457f9928392 | 244 | token = strtok(NULL,separators); // champ8 |
snec_student | 30:2457f9928392 | 245 | if (strcmp(token,"")!=0)strcpy(C2,token); |
snec_student | 30:2457f9928392 | 246 | token = strtok(NULL,separators); // champ9 |
snec_student | 30:2457f9928392 | 247 | if (strcmp(token,"")!=0)strcpy(rel_hum,token); |
snec_student | 30:2457f9928392 | 248 | token = strtok(NULL,separators); // champ10 |
snec_student | 30:2457f9928392 | 249 | if (strcmp(token,"")!=0)strcpy(abs_hum,token); |
snec_student | 30:2457f9928392 | 250 | token = strtok(NULL,separators); // champ11 |
snec_student | 30:2457f9928392 | 251 | if (strcmp(token,"")!=0)strcpy(dew_point,token); |
snec_student | 30:2457f9928392 | 252 | token = strtok(NULL,separators); // champ12 |
snec_student | 30:2457f9928392 | 253 | if (strcmp(token,"")!=0)strcpy(C3,token);*/ |
snec_student | 29:fbc5f53d8d0f | 254 | token = strtok(NULL,separators); // champ13 |
snec_student | 30:2457f9928392 | 255 | if (strcmp(token,"")!=0)strcpy(Wind_dir_T,token); |
snec_student | 29:fbc5f53d8d0f | 256 | token = strtok(NULL,separators); // champ14 |
snec_student | 29:fbc5f53d8d0f | 257 | if (strcmp(token,"")!=0)strcpy(T,token); |
snec_student | 29:fbc5f53d8d0f | 258 | token = strtok(NULL,separators); // champ15 |
snec_student | 29:fbc5f53d8d0f | 259 | if (strcmp(token,"")!=0)strcpy(Wind_dir_M,token); |
snec_student | 29:fbc5f53d8d0f | 260 | token = strtok(NULL,separators); // champ16 |
snec_student | 29:fbc5f53d8d0f | 261 | if (strcmp(token,"")!=0)strcpy(M2,token); |
snec_student | 29:fbc5f53d8d0f | 262 | token = strtok(NULL,separators); // champ17 |
snec_student | 30:2457f9928392 | 263 | if (strcmp(token,"")!=0)strcpy(Wind_speed_knots,token); |
snec_student | 29:fbc5f53d8d0f | 264 | token = strtok(NULL,separators); // champ18 |
snec_student | 29:fbc5f53d8d0f | 265 | if (strcmp(token,"")!=0)strcpy(N,token); |
snec_student | 29:fbc5f53d8d0f | 266 | token = strtok(NULL,separators); // champ19 |
snec_student | 30:2457f9928392 | 267 | if (strcmp(token,"")!=0)strcpy(Wind_speed_ms,token); |
snec_student | 29:fbc5f53d8d0f | 268 | token = strtok(NULL,separators); // champ20 |
snec_student | 30:2457f9928392 | 269 | if (strcmp(token,"")!=0)strcpy(M3,token); |
snec_student | 29:fbc5f53d8d0f | 270 | if (strcmp(air_temp,"")!=0) flag_WIMDA=1; // on signale la fin d'une lecture correcte WIMDA |
snec_student | 30:2457f9928392 | 271 | } // fin if WIMDA |
snec_student | 30:2457f9928392 | 272 | |
snec_student | 29:fbc5f53d8d0f | 273 | } // fin else (traitement trame correcte) |
snec_student | 29:fbc5f53d8d0f | 274 | }//fin if read enable |
snec_student | 29:fbc5f53d8d0f | 275 | } // fin while flags ==0 |
snec_student | 30:2457f9928392 | 276 | // fin mesures station meteo |
snec_student | 31:73be27ad5d69 | 277 | |
snec_student | 30:2457f9928392 | 278 | printf("fin d'alimentation station meteo WX200 \n"); |
snec_student | 30:2457f9928392 | 279 | CMD_200WX=0; |
snec_student | 30:2457f9928392 | 280 | // On affiche les informations GPGGA |
snec_student | 30:2457f9928392 | 281 | printf("horaire UTC :%s \n", horaire); // heure UTC (champ 1) |
snec_student | 30:2457f9928392 | 282 | printf("lattitude :%s \n",lattitude); // Lattitude (champ 2) |
snec_student | 30:2457f9928392 | 283 | printf("hemisphere :%s \n",hemisphere); // Hemisphere (N/S) (champ 3) |
snec_student | 30:2457f9928392 | 284 | printf("longitude:%s \n",longitude); // Longitude (champ 4) |
snec_student | 30:2457f9928392 | 285 | printf("dir:%s \n",dir); // direction (E/W) (champ 5) |
snec_student | 30:2457f9928392 | 286 | printf("quality:%s \n",quality); // GPS quality indicator (0 a 8) (champ 6) |
snec_student | 30:2457f9928392 | 287 | printf("nb_satellites:%s \n",nb_satellites); // Number of satellites in use, 0-12 (champ 7) |
snec_student | 30:2457f9928392 | 288 | printf("HDOP:%s \n",HDOP); // Horizontal dilution of precision (HDOP) (champ 8) |
snec_student | 30:2457f9928392 | 289 | printf("altitude:%s \n",altitude); // Altitude relative to mean-sea-level (geoid), meters (to the nearest whole meter) (champ 9) |
snec_student | 30:2457f9928392 | 290 | printf("unit :%s \n",M); |
snec_student | 30:2457f9928392 | 291 | printf("altitude_cor:%s \n",altitude_cor); // Geoidal separation, meters (to the nearest whole meter). (champ 10) |
snec_student | 30:2457f9928392 | 292 | // On affiche les informations WIMDA |
snec_student | 30:2457f9928392 | 293 | printf("Barometric Pressure :%s %s \n", pres_inch,I); // pression inch + unite (champs 1 et 2) |
snec_student | 30:2457f9928392 | 294 | printf("Barometric Pressure :%s %s \n", pres_bar,B); // pression bars + unite (champs 3 et 4) |
snec_student | 30:2457f9928392 | 295 | printf("Air Temperature:%s %s\n", air_temp,C1); // temperature de l'air + unite (champs 5 et 6) |
snec_student | 30:2457f9928392 | 296 | //printf("Water Temperature:%s %s\n", wat_temp,C2); // temperature de l'air + unite (champs 7 et 8) |
snec_student | 30:2457f9928392 | 297 | //printf("Relative humidity :%s \n", rel_hum); // humidite relative (champs 9) |
snec_student | 30:2457f9928392 | 298 | //printf("Absolute humidity :%s \n", abs_hum); // humidite relative (champs 10) |
snec_student | 30:2457f9928392 | 299 | //printf("Dew Point :%s %s\n", dew_point,C3); // point de rosee + unite (champs 11 et 12) |
snec_student | 30:2457f9928392 | 300 | printf("Wind direction :%s %s\n", Wind_dir_T,T); // direction du vent en degres vrais + unite (champs 13 et 14) |
snec_student | 30:2457f9928392 | 301 | printf("Wind direction magne :%s %s\n", Wind_dir_M,M2); // direction du vent en degres vrais + unite (champs 15 et 16) |
snec_student | 30:2457f9928392 | 302 | printf("Wind speed :%s %s\n", Wind_speed_knots,N); // vitesse du vent en noeuds + unite (champs 17 et 18) |
snec_student | 30:2457f9928392 | 303 | printf("Wind speed :%s %s\n", Wind_speed_ms,M3); // vitesse du vent en m/s + unite (champs 17 et 18) |
snec_student | 31:73be27ad5d69 | 304 | |
snec_student | 31:73be27ad5d69 | 305 | } |
snec_student | 28:6f0009bce093 | 306 | |
snec_student | 28:6f0009bce093 | 307 | |
snec_student | 30:2457f9928392 | 308 | |
snec_student | 30:2457f9928392 | 309 | /************** Calcul CRC ************************/ |
snec_student | 30:2457f9928392 | 310 | uint8_t gencrc2(uint8_t *data) // calcul crc NMEA |
snec_student | 30:2457f9928392 | 311 | { |
snec_student | 30:2457f9928392 | 312 | uint8_t crc; |
snec_student | 30:2457f9928392 | 313 | crc=data[1]; |
snec_student | 30:2457f9928392 | 314 | char i=2; |
snec_student | 30:2457f9928392 | 315 | while (data[i]!=0) { |
snec_student | 30:2457f9928392 | 316 | crc = crc^data[i]; |
snec_student | 30:2457f9928392 | 317 | i++; |
snec_student | 28:6f0009bce093 | 318 | } |
snec_student | 30:2457f9928392 | 319 | return crc; |
snec_student | 30:2457f9928392 | 320 | } |