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