Ahmed_PFE_Embarq_300415
Dependencies: C12832 LM75B mbed
Fork of Ahmed_Embarq_Prog by
Ah_main.cpp@1:197b9fed6092, 2015-04-30 (annotated)
- Committer:
- pfe
- Date:
- Thu Apr 30 12:24:33 2015 +0000
- Revision:
- 1:197b9fed6092
- Parent:
- 0:05a20e3e3179
Ahmed_PFE_Embarq_300415
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pfe | 0:05a20e3e3179 | 1 | #include "mbed.h" |
pfe | 0:05a20e3e3179 | 2 | #include "C12832.h" |
pfe | 0:05a20e3e3179 | 3 | #include "MSCFileSystem.h" |
pfe | 0:05a20e3e3179 | 4 | //----------------------- |
pfe | 0:05a20e3e3179 | 5 | #include "Define.h" |
pfe | 1:197b9fed6092 | 6 | #include "Dec_GPS.h" |
pfe | 0:05a20e3e3179 | 7 | //----------------------- |
pfe | 1:197b9fed6092 | 8 | MSCFileSystem fsLog("USB"); // Enregsetement des doonées "Flash Disque USB" |
pfe | 1:197b9fed6092 | 9 | FILE *Fs_Log; |
pfe | 1:197b9fed6092 | 10 | I2C _I2C(p28,p27); // I2C SCL,SDA |
pfe | 1:197b9fed6092 | 11 | Serial _ComGPS(NC, p14); // TX non connecté, pin14 RX. |
pfe | 1:197b9fed6092 | 12 | Serial _ComXbee(p9,p10); // Serial tx(p9),rx(10) |
pfe | 1:197b9fed6092 | 13 | #define pRST_Xbee p30 // pin RST Xbee |
pfe | 1:197b9fed6092 | 14 | Ticker _Ticker1ms; |
pfe | 1:197b9fed6092 | 15 | Timer _Timer1; // Timer pour mesurer le temps |
pfe | 0:05a20e3e3179 | 16 | |
pfe | 1:197b9fed6092 | 17 | DigitalIn boutonStart(p13); // Joystique Left : Boutton pour pouvoir controler le debut de l'enregistrement |
pfe | 1:197b9fed6092 | 18 | DigitalIn boutonEnd(p16); // Joystique Right : Boutton pour pouvoir controler la fin de l'enregistrement |
pfe | 1:197b9fed6092 | 19 | |
pfe | 1:197b9fed6092 | 20 | DigitalOut RSTXbee (p30); |
pfe | 1:197b9fed6092 | 21 | DigitalOut LedGPS (LED1); |
pfe | 1:197b9fed6092 | 22 | DigitalOut LedLog (LED2); |
pfe | 1:197b9fed6092 | 23 | DigitalOut LedXbee (LED3); |
pfe | 1:197b9fed6092 | 24 | DigitalOut LedError(LED4); |
pfe | 0:05a20e3e3179 | 25 | //----------------------- |
pfe | 1:197b9fed6092 | 26 | StructGPS GPS,OldGPS; |
pfe | 0:05a20e3e3179 | 27 | unsigned long TimeBtpress=0,TIMER_10ms; |
pfe | 1:197b9fed6092 | 28 | unsigned long FileIndex0,FileIndex; |
pfe | 0:05a20e3e3179 | 29 | char Txt[16],Txt_Log[100],Txt_Tx2GSC[100],DataLogFileName[32]; |
pfe | 0:05a20e3e3179 | 30 | //----------------------------------- Reception des données GPS 10Hz |
pfe | 1:197b9fed6092 | 31 | |
pfe | 1:197b9fed6092 | 32 | void AutoMat_GPS() |
pfe | 1:197b9fed6092 | 33 | { |
pfe | 1:197b9fed6092 | 34 | static unsigned char i=0,j=0,GPSDataType=0,ET_AutoMat_GPS=ET_01; |
pfe | 1:197b9fed6092 | 35 | static char gps_mess; |
pfe | 1:197b9fed6092 | 36 | while(_ComGPS.readable()) { |
pfe | 1:197b9fed6092 | 37 | gps_mess=_ComGPS.getc(); |
pfe | 1:197b9fed6092 | 38 | |
pfe | 1:197b9fed6092 | 39 | switch(ET_AutoMat_GPS) { |
pfe | 1:197b9fed6092 | 40 | case ET_01: |
pfe | 1:197b9fed6092 | 41 | if(gps_mess==prompt$GP[i]) { |
pfe | 1:197b9fed6092 | 42 | i++; |
pfe | 1:197b9fed6092 | 43 | if(i==3) { |
pfe | 1:197b9fed6092 | 44 | i=0; |
pfe | 1:197b9fed6092 | 45 | j=0; |
pfe | 1:197b9fed6092 | 46 | ET_AutoMat_GPS=ET_02; |
pfe | 1:197b9fed6092 | 47 | } |
pfe | 1:197b9fed6092 | 48 | } else i=0; |
pfe | 1:197b9fed6092 | 49 | break; |
pfe | 1:197b9fed6092 | 50 | case ET_02: |
pfe | 1:197b9fed6092 | 51 | if(gps_mess==promptGGA[i]) { |
pfe | 1:197b9fed6092 | 52 | i++; |
pfe | 1:197b9fed6092 | 53 | if(i==3) { |
pfe | 1:197b9fed6092 | 54 | i=0; |
pfe | 1:197b9fed6092 | 55 | j=0; |
pfe | 1:197b9fed6092 | 56 | ET_AutoMat_GPS = ET_03; |
pfe | 1:197b9fed6092 | 57 | GPSDataType = GGA; |
pfe | 1:197b9fed6092 | 58 | } |
pfe | 1:197b9fed6092 | 59 | break; |
pfe | 1:197b9fed6092 | 60 | } else i=0; |
pfe | 1:197b9fed6092 | 61 | |
pfe | 1:197b9fed6092 | 62 | if(gps_mess==promptRMC[j]) { |
pfe | 1:197b9fed6092 | 63 | j++; |
pfe | 1:197b9fed6092 | 64 | if(j==3) { |
pfe | 1:197b9fed6092 | 65 | j=0; |
pfe | 1:197b9fed6092 | 66 | ET_AutoMat_GPS=ET_03; |
pfe | 1:197b9fed6092 | 67 | GPSDataType=RMC; |
pfe | 1:197b9fed6092 | 68 | } |
pfe | 1:197b9fed6092 | 69 | break; |
pfe | 1:197b9fed6092 | 70 | } else j=0; |
pfe | 1:197b9fed6092 | 71 | |
pfe | 1:197b9fed6092 | 72 | ET_AutoMat_GPS=ET_01; |
pfe | 1:197b9fed6092 | 73 | break; |
pfe | 1:197b9fed6092 | 74 | |
pfe | 1:197b9fed6092 | 75 | case ET_03: |
pfe | 1:197b9fed6092 | 76 | _MsgGPSRx[i]=gps_mess; |
pfe | 1:197b9fed6092 | 77 | i++; |
pfe | 1:197b9fed6092 | 78 | if((i<NData_GPS_Max)&&(gps_mess!=0x0D))break; |
pfe | 1:197b9fed6092 | 79 | |
pfe | 1:197b9fed6092 | 80 | switch(GPSDataType) { |
pfe | 1:197b9fed6092 | 81 | |
pfe | 1:197b9fed6092 | 82 | case GGA: |
pfe | 1:197b9fed6092 | 83 | DecodageGPGGA(MsgGPSRx,i-1,&OldGPS);// l'appel de la fonction de decodage du message GPGGA |
pfe | 1:197b9fed6092 | 84 | if (OldGPS.GGA_Valid == 0x01) { |
pfe | 1:197b9fed6092 | 85 | OldGPS.GGA_Valid = 0x00; |
pfe | 1:197b9fed6092 | 86 | LedGPS = !LedGPS; |
pfe | 1:197b9fed6092 | 87 | } |
pfe | 0:05a20e3e3179 | 88 | break; |
pfe | 1:197b9fed6092 | 89 | case RMC: //DecodageGPRMC(i-1);// l'appel de la fonction de decodage du message GPGGA //DecodageGPRMC(i-1); |
pfe | 1:197b9fed6092 | 90 | break; |
pfe | 1:197b9fed6092 | 91 | default: |
pfe | 0:05a20e3e3179 | 92 | break; |
pfe | 1:197b9fed6092 | 93 | } |
pfe | 1:197b9fed6092 | 94 | ET_AutoMat_GPS=ET_01; |
pfe | 1:197b9fed6092 | 95 | GPSDataType = NULL; |
pfe | 1:197b9fed6092 | 96 | default : |
pfe | 1:197b9fed6092 | 97 | break; |
pfe | 0:05a20e3e3179 | 98 | } |
pfe | 1:197b9fed6092 | 99 | } |
pfe | 1:197b9fed6092 | 100 | } |
pfe | 0:05a20e3e3179 | 101 | //----------------------------------- Transmission données au sol 10 packet/s |
pfe | 1:197b9fed6092 | 102 | void AutoMat_Xbee_Tx() |
pfe | 1:197b9fed6092 | 103 | { |
pfe | 1:197b9fed6092 | 104 | static char LIndex=0; |
pfe | 1:197b9fed6092 | 105 | switch (ET_AutoMat_Xbee_Tx) { |
pfe | 1:197b9fed6092 | 106 | case ET_01: |
pfe | 1:197b9fed6092 | 107 | LIndex++; |
pfe | 1:197b9fed6092 | 108 | ET_AutoMat_Xbee_Tx = ET_00; |
pfe | 1:197b9fed6092 | 109 | if(LIndex>=5) ET_AutoMat_Xbee_Tx = ET_02; |
pfe | 1:197b9fed6092 | 110 | break; |
pfe | 1:197b9fed6092 | 111 | case ET_02: |
pfe | 1:197b9fed6092 | 112 | LIndex = 0; |
pfe | 1:197b9fed6092 | 113 | LedXbee = !LedXbee; |
pfe | 1:197b9fed6092 | 114 | sprintf(Txt_Tx2GSC,"$TIME:%lu\r\n",OldTIMER_10ms); |
pfe | 1:197b9fed6092 | 115 | _ComXbee.printf("%s",Txt_Tx2GSC); |
pfe | 1:197b9fed6092 | 116 | ET_AutoMat_Xbee_Tx = ET_03; |
pfe | 1:197b9fed6092 | 117 | break; |
pfe | 1:197b9fed6092 | 118 | case ET_03 : |
pfe | 1:197b9fed6092 | 119 | sprintf(Txt_Tx2GSC,"!!!UTC:%2u%2u%2u,***\r\n",GPS.hh,GPS.mm,GPS.ss); |
pfe | 1:197b9fed6092 | 120 | _ComXbee.printf("%s",Txt_Tx2GSC); |
pfe | 1:197b9fed6092 | 121 | ET_AutoMat_Xbee_Tx = ET_04; |
pfe | 1:197b9fed6092 | 122 | break; |
pfe | 1:197b9fed6092 | 123 | case ET_04 : |
pfe | 1:197b9fed6092 | 124 | //delay 10ms |
pfe | 1:197b9fed6092 | 125 | ET_AutoMat_Xbee_Tx = ET_05; |
pfe | 1:197b9fed6092 | 126 | break; |
pfe | 1:197b9fed6092 | 127 | case ET_05 : |
pfe | 1:197b9fed6092 | 128 | sprintf(Txt_Tx2GSC,"!!!LAT:%ld,LON:%ld,***\r\n",GPS.LatDeg,GPS.LonDeg); |
pfe | 1:197b9fed6092 | 129 | _ComXbee.printf("%s",Txt_Tx2GSC); |
pfe | 1:197b9fed6092 | 130 | ET_AutoMat_Xbee_Tx = ET_06; |
pfe | 1:197b9fed6092 | 131 | break; |
pfe | 1:197b9fed6092 | 132 | case ET_06 : |
pfe | 1:197b9fed6092 | 133 | //delay 10ms |
pfe | 1:197b9fed6092 | 134 | ET_AutoMat_Xbee_Tx = ET_07; |
pfe | 1:197b9fed6092 | 135 | break; |
pfe | 1:197b9fed6092 | 136 | case ET_07 : |
pfe | 1:197b9fed6092 | 137 | sprintf(Txt_Tx2GSC,"!!!PCH:%.2f,RLL:%.2f,CRS:%.2f,SPD:%.2f,ALT:%.2f,***\r\n",HK_PCH,HK_RLL,HK_CRS,HK_SPD,HK_ALT); |
pfe | 1:197b9fed6092 | 138 | _ComXbee.printf("%s",Txt_Tx2GSC); |
pfe | 1:197b9fed6092 | 139 | ET_AutoMat_Xbee_Tx = ET_08; |
pfe | 1:197b9fed6092 | 140 | break; |
pfe | 1:197b9fed6092 | 141 | case ET_08 : |
pfe | 1:197b9fed6092 | 142 | ET_AutoMat_Xbee_Tx = ET_00; |
pfe | 1:197b9fed6092 | 143 | break; |
pfe | 1:197b9fed6092 | 144 | default: |
pfe | 1:197b9fed6092 | 145 | ET_AutoMat_Xbee_Tx=ET_00; |
pfe | 1:197b9fed6092 | 146 | break; |
pfe | 1:197b9fed6092 | 147 | } |
pfe | 0:05a20e3e3179 | 148 | } |
pfe | 0:05a20e3e3179 | 149 | //----------------------------------- LogData 100Hz, LogGPS 10Hz |
pfe | 1:197b9fed6092 | 150 | #ifdef EN_AutoMat_DataLog |
pfe | 1:197b9fed6092 | 151 | void AutoMat_DataLog() |
pfe | 1:197b9fed6092 | 152 | { |
pfe | 1:197b9fed6092 | 153 | static char ET_Sub_AutoMat = ET_00; |
pfe | 1:197b9fed6092 | 154 | switch (ET_AutoMat_DataLog) { |
pfe | 1:197b9fed6092 | 155 | |
pfe | 1:197b9fed6092 | 156 | case ET_01: |
pfe | 1:197b9fed6092 | 157 | LedLog=!LedLog; |
pfe | 1:197b9fed6092 | 158 | //-------------- |
pfe | 1:197b9fed6092 | 159 | // au max 100us (0.1ms) |
pfe | 1:197b9fed6092 | 160 | sprintf(Txt_Log,"%lu;GPS;%1u;%2u:%2u:%2u;%10ld;%10ld;%ld;",TIMER_10ms,GPS.Qual,GPS.hh,GPS.mm,GPS.ss,GPS.LatDeg,GPS.LonDeg,GPS.HMSL); |
pfe | 1:197b9fed6092 | 161 | // au max 5000 us (5ms) |
pfe | 1:197b9fed6092 | 162 | fprintf(Fs_Log,Txt_Log); |
pfe | 1:197b9fed6092 | 163 | // 100us |
pfe | 1:197b9fed6092 | 164 | sprintf(Txt_Log,"P;%5d;%5d;%5d;%5d\r\n",CRS,ALT,SPD,TEM); |
pfe | 1:197b9fed6092 | 165 | // au max 5 ms |
pfe | 1:197b9fed6092 | 166 | fprintf(Fs_Log,Txt_Log); |
pfe | 1:197b9fed6092 | 167 | //------------------ |
pfe | 1:197b9fed6092 | 168 | ET_Sub_AutoMat = ET_01; |
pfe | 1:197b9fed6092 | 169 | ET_AutoMat_DataLog = ET_02; |
pfe | 1:197b9fed6092 | 170 | break; |
pfe | 1:197b9fed6092 | 171 | case ET_02: |
pfe | 1:197b9fed6092 | 172 | // au max 100us (0.1ms) |
pfe | 1:197b9fed6092 | 173 | sprintf(Txt_Log,"%lu;;;;;;;",TIMER_10ms); |
pfe | 1:197b9fed6092 | 174 | // au max 5000 us (5ms) |
pfe | 1:197b9fed6092 | 175 | fprintf(Fs_Log,Txt_Log); |
pfe | 1:197b9fed6092 | 176 | // au max 100us (0.1ms) |
pfe | 1:197b9fed6092 | 177 | sprintf(Txt_Log,"P;%5d;%5d;%5d;%5d\r\n",CRS,ALT,SPD,TEM); |
pfe | 1:197b9fed6092 | 178 | // au max 5000 us (5ms) |
pfe | 1:197b9fed6092 | 179 | fprintf(Fs_Log,Txt_Log); |
pfe | 1:197b9fed6092 | 180 | ET_Sub_AutoMat++; |
pfe | 1:197b9fed6092 | 181 | if(ET_Sub_AutoMat>=ET_10) ET_AutoMat_DataLog = ET_00; |
pfe | 1:197b9fed6092 | 182 | break; |
pfe | 1:197b9fed6092 | 183 | |
pfe | 1:197b9fed6092 | 184 | default: break ; |
pfe | 0:05a20e3e3179 | 185 | } |
pfe | 1:197b9fed6092 | 186 | } |
pfe | 1:197b9fed6092 | 187 | #endif |
pfe | 1:197b9fed6092 | 188 | //------------------------------------------ Sansors |
pfe | 1:197b9fed6092 | 189 | void AutoMat_ALT_EAGLE_V4() |
pfe | 1:197b9fed6092 | 190 | { |
pfe | 1:197b9fed6092 | 191 | static char L_i2c_Data[2],LIndex,Lerror; |
pfe | 1:197b9fed6092 | 192 | switch (ET_AutoMat_ALT) { |
pfe | 1:197b9fed6092 | 193 | case ET_01 : |
pfe | 1:197b9fed6092 | 194 | L_i2c_Data[0] = 0x07; // Send "register number" command to sensor |
pfe | 1:197b9fed6092 | 195 | Lerror = _I2C.write(Add_Sensor_ALT_EG4, L_i2c_Data, 1,true); // Send command string |
pfe | 1:197b9fed6092 | 196 | if (Lerror==0) ET_AutoMat_ALT = ET_02; |
pfe | 1:197b9fed6092 | 197 | LIndex = 1; |
pfe | 1:197b9fed6092 | 198 | break; |
pfe | 1:197b9fed6092 | 199 | |
pfe | 0:05a20e3e3179 | 200 | case ET_02 : |
pfe | 1:197b9fed6092 | 201 | LIndex++; |
pfe | 1:197b9fed6092 | 202 | if(LIndex>=Wait_Time1_ms) ET_AutoMat_ALT = ET_03; |
pfe | 1:197b9fed6092 | 203 | break; |
pfe | 1:197b9fed6092 | 204 | |
pfe | 1:197b9fed6092 | 205 | case ET_03 : |
pfe | 1:197b9fed6092 | 206 | Lerror = _I2C.read(Add_Sensor_ALT_EG4, L_i2c_Data, 2, true); |
pfe | 1:197b9fed6092 | 207 | if (Lerror==0) { |
pfe | 1:197b9fed6092 | 208 | ALT = *((unsigned short*)L_i2c_Data)&0xffff; //altitude en décimètre |
pfe | 1:197b9fed6092 | 209 | ALT = ALT-3000; |
pfe | 1:197b9fed6092 | 210 | } |
pfe | 1:197b9fed6092 | 211 | ET_AutoMat_ALT = ET_01; |
pfe | 1:197b9fed6092 | 212 | break; |
pfe | 1:197b9fed6092 | 213 | default : break; |
pfe | 0:05a20e3e3179 | 214 | } |
pfe | 1:197b9fed6092 | 215 | } |
pfe | 1:197b9fed6092 | 216 | |
pfe | 1:197b9fed6092 | 217 | void AutoMat_TAS_EAGLE_V4() |
pfe | 1:197b9fed6092 | 218 | { |
pfe | 1:197b9fed6092 | 219 | static char L_i2c_Data[2],LIndex,Lerror; |
pfe | 1:197b9fed6092 | 220 | unsigned short SPD_short; |
pfe | 1:197b9fed6092 | 221 | float SPD_float; |
pfe | 1:197b9fed6092 | 222 | switch (ET_AutoMat_TAS) { |
pfe | 1:197b9fed6092 | 223 | case ET_01 : |
pfe | 1:197b9fed6092 | 224 | L_i2c_Data[0] = 0x07; // Send "register number" command to sensor |
pfe | 1:197b9fed6092 | 225 | Lerror = _I2C.write(Add_Sensor_TAS_EG4, L_i2c_Data, 1,true); // Send command string |
pfe | 1:197b9fed6092 | 226 | if (Lerror==0) ET_AutoMat_TAS = ET_02; |
pfe | 1:197b9fed6092 | 227 | LIndex = 1; |
pfe | 1:197b9fed6092 | 228 | break; |
pfe | 1:197b9fed6092 | 229 | |
pfe | 1:197b9fed6092 | 230 | case ET_02 : |
pfe | 1:197b9fed6092 | 231 | LIndex++; |
pfe | 1:197b9fed6092 | 232 | if(LIndex>=Wait_Time1_ms) ET_AutoMat_TAS = ET_03; |
pfe | 1:197b9fed6092 | 233 | break; |
pfe | 1:197b9fed6092 | 234 | |
pfe | 1:197b9fed6092 | 235 | case ET_03 : |
pfe | 1:197b9fed6092 | 236 | Lerror = _I2C.read(Add_Sensor_TAS_EG4, L_i2c_Data, 2, true); |
pfe | 1:197b9fed6092 | 237 | if (Lerror==0) { |
pfe | 1:197b9fed6092 | 238 | SPD_short = *((unsigned short*)L_i2c_Data)&0xffff; |
pfe | 1:197b9fed6092 | 239 | SPD_float = 10*sqrt((float)(SPD_short-Offset_SPD)*5.87755102); |
pfe | 1:197b9fed6092 | 240 | SPD = 10*SPD_float; // mph*10 |
pfe | 1:197b9fed6092 | 241 | } |
pfe | 1:197b9fed6092 | 242 | ET_AutoMat_TAS = ET_01; |
pfe | 1:197b9fed6092 | 243 | break; |
pfe | 1:197b9fed6092 | 244 | default : |
pfe | 1:197b9fed6092 | 245 | break; |
pfe | 1:197b9fed6092 | 246 | } |
pfe | 1:197b9fed6092 | 247 | } |
pfe | 1:197b9fed6092 | 248 | void AutoMat_CAP_HMC() |
pfe | 1:197b9fed6092 | 249 | { |
pfe | 1:197b9fed6092 | 250 | static char L_i2c_Data[2],LIndex,Lerror; |
pfe | 0:05a20e3e3179 | 251 | switch (ET_AutoMat_CAP) { |
pfe | 1:197b9fed6092 | 252 | case ET_01 : |
pfe | 1:197b9fed6092 | 253 | L_i2c_Data[0] = 0x07; // Send "register number" command to sensor |
pfe | 1:197b9fed6092 | 254 | Lerror = _I2C.write(Add_Sensor_CAP_HMC, L_i2c_Data, 1,true); // Send command string |
pfe | 1:197b9fed6092 | 255 | if (Lerror==0) ET_AutoMat_CAP = ET_02; |
pfe | 1:197b9fed6092 | 256 | LIndex = 1; |
pfe | 1:197b9fed6092 | 257 | break; |
pfe | 1:197b9fed6092 | 258 | |
pfe | 0:05a20e3e3179 | 259 | case ET_02 : |
pfe | 1:197b9fed6092 | 260 | LIndex++; |
pfe | 1:197b9fed6092 | 261 | if(LIndex>=Wait_Time1_ms) ET_AutoMat_CAP = ET_03; |
pfe | 1:197b9fed6092 | 262 | break; |
pfe | 1:197b9fed6092 | 263 | |
pfe | 1:197b9fed6092 | 264 | case ET_03 : |
pfe | 1:197b9fed6092 | 265 | Lerror = _I2C.read(Add_Sensor_CAP_HMC , L_i2c_Data, 2, true); |
pfe | 1:197b9fed6092 | 266 | if (Lerror==0) { |
pfe | 1:197b9fed6092 | 267 | CRS = *((unsigned short*)L_i2c_Data)&0xffff; //Cap en deg*10 |
pfe | 1:197b9fed6092 | 268 | } |
pfe | 1:197b9fed6092 | 269 | ET_AutoMat_CAP = ET_01; |
pfe | 1:197b9fed6092 | 270 | break; |
pfe | 1:197b9fed6092 | 271 | default : |
pfe | 1:197b9fed6092 | 272 | break; |
pfe | 0:05a20e3e3179 | 273 | } |
pfe | 0:05a20e3e3179 | 274 | } |
pfe | 0:05a20e3e3179 | 275 | |
pfe | 1:197b9fed6092 | 276 | void AutoMat_TEM_LM75B() |
pfe | 1:197b9fed6092 | 277 | { |
pfe | 1:197b9fed6092 | 278 | static char L_i2c_Data[2],LIndex,Lerror; |
pfe | 1:197b9fed6092 | 279 | switch (ET_AutoMat_TEM) { |
pfe | 1:197b9fed6092 | 280 | case ET_01 : |
pfe | 1:197b9fed6092 | 281 | L_i2c_Data[0] = 0x07; // Send "register number" command to sensor |
pfe | 1:197b9fed6092 | 282 | Lerror = _I2C.write(Add_Sensor_TEM_LM75B, L_i2c_Data, 1,true); // Send command string |
pfe | 1:197b9fed6092 | 283 | if (Lerror==0) ET_AutoMat_TEM = ET_02; |
pfe | 1:197b9fed6092 | 284 | LIndex = 1; |
pfe | 1:197b9fed6092 | 285 | break; |
pfe | 1:197b9fed6092 | 286 | |
pfe | 1:197b9fed6092 | 287 | case ET_02 : |
pfe | 1:197b9fed6092 | 288 | LIndex++; |
pfe | 1:197b9fed6092 | 289 | if(LIndex>=Wait_Time1_ms) ET_AutoMat_TEM = ET_03; |
pfe | 1:197b9fed6092 | 290 | break; |
pfe | 1:197b9fed6092 | 291 | |
pfe | 1:197b9fed6092 | 292 | case ET_03 : |
pfe | 1:197b9fed6092 | 293 | Lerror = _I2C.read(Add_Sensor_TEM_LM75B, L_i2c_Data, 2, true); |
pfe | 1:197b9fed6092 | 294 | if (Lerror==0) { |
pfe | 1:197b9fed6092 | 295 | // CRS = *((unsigned short*)L_i2c_Data)&0xffff; //Cap en deg*10 |
pfe | 1:197b9fed6092 | 296 | } |
pfe | 1:197b9fed6092 | 297 | ET_AutoMat_TEM = ET_01; |
pfe | 1:197b9fed6092 | 298 | break; |
pfe | 1:197b9fed6092 | 299 | default : |
pfe | 1:197b9fed6092 | 300 | break; |
pfe | 1:197b9fed6092 | 301 | } |
pfe | 1:197b9fed6092 | 302 | } |
pfe | 1:197b9fed6092 | 303 | //----------------- LCD ------------ |
pfe | 1:197b9fed6092 | 304 | void AutoMat_LCD_Ext() |
pfe | 1:197b9fed6092 | 305 | { |
pfe | 1:197b9fed6092 | 306 | static char Lerror; |
pfe | 1:197b9fed6092 | 307 | switch (ET_AutoMat_LCD) { |
pfe | 1:197b9fed6092 | 308 | case ET_01 : |
pfe | 1:197b9fed6092 | 309 | Lerror = _I2C.write(Add_LCD_Ext, NULL, 0,true); |
pfe | 1:197b9fed6092 | 310 | if (Lerror==0) ET_AutoMat_LCD = ET_02; |
pfe | 1:197b9fed6092 | 311 | break; |
pfe | 1:197b9fed6092 | 312 | case ET_02 : |
pfe | 1:197b9fed6092 | 313 | // Code ici |
pfe | 1:197b9fed6092 | 314 | ET_AutoMat_LCD = ET_01; |
pfe | 1:197b9fed6092 | 315 | break; |
pfe | 1:197b9fed6092 | 316 | default : |
pfe | 1:197b9fed6092 | 317 | break; |
pfe | 1:197b9fed6092 | 318 | } |
pfe | 1:197b9fed6092 | 319 | } |
pfe | 1:197b9fed6092 | 320 | //--------------------------------- |
pfe | 1:197b9fed6092 | 321 | |
pfe | 1:197b9fed6092 | 322 | void Sansors_Init() |
pfe | 1:197b9fed6092 | 323 | { |
pfe | 1:197b9fed6092 | 324 | char L_i2c_Data[3]; |
pfe | 1:197b9fed6092 | 325 | //------------ init Compass HMC //Continuous mode, periodic set/reset, 20Hz measurement rate. |
pfe | 1:197b9fed6092 | 326 | L_i2c_Data[0] = HMC6352_CONTINUOUS; |
pfe | 1:197b9fed6092 | 327 | L_i2c_Data[1] = 0x01; |
pfe | 1:197b9fed6092 | 328 | L_i2c_Data[2] = 20; |
pfe | 1:197b9fed6092 | 329 | _I2C.write(Add_Sensor_CAP_HMC,L_i2c_Data,3); // Send command |
pfe | 1:197b9fed6092 | 330 | //---------------------------- |
pfe | 1:197b9fed6092 | 331 | wait_ms(1); //attendre 1mS |
pfe | 1:197b9fed6092 | 332 | //------------- Get Offset TAS |
pfe | 1:197b9fed6092 | 333 | L_i2c_Data[0] = 0x01; // Send "read data" command to sensor |
pfe | 1:197b9fed6092 | 334 | _I2C.write(Add_Sensor_TAS_EG4,L_i2c_Data,1); // Send command string |
pfe | 1:197b9fed6092 | 335 | wait_ms(1); //attendre 400µS avant de relancer |
pfe | 1:197b9fed6092 | 336 | _I2C.read(Add_Sensor_TAS_EG4,L_i2c_Data, 2); |
pfe | 1:197b9fed6092 | 337 | Offset_SPD = *((unsigned short*)L_i2c_Data)&0xffff; // Altitude en décimètre |
pfe | 1:197b9fed6092 | 338 | } |
pfe | 1:197b9fed6092 | 339 | |
pfe | 1:197b9fed6092 | 340 | void Irq01ms() |
pfe | 1:197b9fed6092 | 341 | { |
pfe | 1:197b9fed6092 | 342 | static unsigned char LFlag_Timer=0, LTIMER001ms=0,LTIMER010ms=0; |
pfe | 1:197b9fed6092 | 343 | LTIMER001ms++; |
pfe | 1:197b9fed6092 | 344 | LFlag_Timer = 1; |
pfe | 1:197b9fed6092 | 345 | //----------------------------- |
pfe | 1:197b9fed6092 | 346 | if(LTIMER001ms >= 10) { |
pfe | 1:197b9fed6092 | 347 | //----------------- |
pfe | 1:197b9fed6092 | 348 | LTIMER001ms = 0; |
pfe | 1:197b9fed6092 | 349 | LFlag_Timer = 3; |
pfe | 1:197b9fed6092 | 350 | LTIMER010ms = LTIMER010ms+1; |
pfe | 1:197b9fed6092 | 351 | //----------------- |
pfe | 1:197b9fed6092 | 352 | if(LTIMER010ms >= 10) { |
pfe | 1:197b9fed6092 | 353 | LTIMER010ms = 0; |
pfe | 1:197b9fed6092 | 354 | LFlag_Timer = 7; |
pfe | 1:197b9fed6092 | 355 | } |
pfe | 1:197b9fed6092 | 356 | //----------------- |
pfe | 1:197b9fed6092 | 357 | TIMER_10ms = TIMER_10ms+1; |
pfe | 1:197b9fed6092 | 358 | } |
pfe | 1:197b9fed6092 | 359 | AutoMat_ALT_EAGLE_V4(); |
pfe | 1:197b9fed6092 | 360 | AutoMat_TAS_EAGLE_V4(); |
pfe | 1:197b9fed6092 | 361 | AutoMat_CAP_HMC(); |
pfe | 1:197b9fed6092 | 362 | AutoMat_TEM_LM75B();// temperateur LM75B |
pfe | 0:05a20e3e3179 | 363 | |
pfe | 1:197b9fed6092 | 364 | if (Flag_Timer != 0xFF) Flag_Timer = LFlag_Timer; |
pfe | 1:197b9fed6092 | 365 | //----------------------------- |
pfe | 1:197b9fed6092 | 366 | } |
pfe | 1:197b9fed6092 | 367 | |
pfe | 1:197b9fed6092 | 368 | int main() |
pfe | 1:197b9fed6092 | 369 | { |
pfe | 1:197b9fed6092 | 370 | |
pfe | 1:197b9fed6092 | 371 | CRS = 0; |
pfe | 1:197b9fed6092 | 372 | SPD = 0; |
pfe | 1:197b9fed6092 | 373 | ALT = 0; |
pfe | 1:197b9fed6092 | 374 | LedError = 0; |
pfe | 1:197b9fed6092 | 375 | //-------------------- |
pfe | 1:197b9fed6092 | 376 | _I2C.frequency(100000); |
pfe | 1:197b9fed6092 | 377 | _ComGPS.baud(38400); //GPS V4 EAGLE |
pfe | 1:197b9fed6092 | 378 | _ComGPS.attach(&AutoMat_GPS,Serial::RxIrq); // defini une interruption chaque foix que le recepteur GPS envoi un charactere |
pfe | 1:197b9fed6092 | 379 | _ComXbee.baud(38400); |
pfe | 1:197b9fed6092 | 380 | RSTXbee=0; |
pfe | 1:197b9fed6092 | 381 | wait(0.5); |
pfe | 1:197b9fed6092 | 382 | RSTXbee=1; |
pfe | 1:197b9fed6092 | 383 | Sansors_Init(); |
pfe | 1:197b9fed6092 | 384 | //-------------------- |
pfe | 1:197b9fed6092 | 385 | //-------------- File Creat RGPSLogX.csv and DataLogX.csv X=FileIndex |
pfe | 1:197b9fed6092 | 386 | #ifdef EN_AutoMat_DataLog |
pfe | 1:197b9fed6092 | 387 | FileIndex = 0; |
pfe | 1:197b9fed6092 | 388 | Started: |
pfe | 1:197b9fed6092 | 389 | FileIndex++; |
pfe | 1:197b9fed6092 | 390 | |
pfe | 1:197b9fed6092 | 391 | //-------------------- |
pfe | 1:197b9fed6092 | 392 | sprintf(DataLogFileName,"/USB/DataLog%4lu.csv",FileIndex); |
pfe | 1:197b9fed6092 | 393 | Fs_Log = fopen(DataLogFileName, "r");//ajouter un nouveau fichier et écraser l'ancien |
pfe | 1:197b9fed6092 | 394 | if (Fs_Log!=NULL) goto Started; |
pfe | 1:197b9fed6092 | 395 | |
pfe | 1:197b9fed6092 | 396 | Fs_Log = fopen(DataLogFileName, "w");//ajouter un nouveau fichier et écraser l'ancien |
pfe | 1:197b9fed6092 | 397 | //-------------------- Verification de la creations des fichers |
pfe | 1:197b9fed6092 | 398 | if(Fs_Log==NULL) goto LabError; |
pfe | 1:197b9fed6092 | 399 | fprintf(Fs_Log,"LogData\r\n"); |
pfe | 1:197b9fed6092 | 400 | fprintf(Fs_Log,"TIMER;GPS;Qual;Heur;LatD;LongD;HMSL;"); |
pfe | 1:197b9fed6092 | 401 | fprintf(Fs_Log,"PDV;CRS;ALT;SPD;TEM\r\n"); |
pfe | 1:197b9fed6092 | 402 | #endif |
pfe | 1:197b9fed6092 | 403 | //-------------------- |
pfe | 1:197b9fed6092 | 404 | // Active les Automat |
pfe | 1:197b9fed6092 | 405 | ET_AutoMat_ALT = ET_01; |
pfe | 1:197b9fed6092 | 406 | ET_AutoMat_TAS = ET_01; |
pfe | 1:197b9fed6092 | 407 | ET_AutoMat_CAP = ET_01; |
pfe | 1:197b9fed6092 | 408 | ET_AutoMat_TEM = ET_01; |
pfe | 1:197b9fed6092 | 409 | ET_AutoMat_LCD = ET_01; |
pfe | 1:197b9fed6092 | 410 | _Ticker1ms.attach_us(&Irq01ms,Irq_Time_us); |
pfe | 1:197b9fed6092 | 411 | // la variable un nom de 1ms mais on fait ca sur 5ms ce n'est pas cohérent !!!!!!! |
pfe | 1:197b9fed6092 | 412 | // Samir |
pfe | 1:197b9fed6092 | 413 | //-------------------- |
pfe | 1:197b9fed6092 | 414 | CRS = 9991;// initialisation |
pfe | 1:197b9fed6092 | 415 | ALT = 9992;// initialisation |
pfe | 1:197b9fed6092 | 416 | SPD = 9993;// initialisation |
pfe | 1:197b9fed6092 | 417 | TEM = 9994;// initialisation |
pfe | 1:197b9fed6092 | 418 | Flag_Timer = 0; |
pfe | 1:197b9fed6092 | 419 | //------------------- |
pfe | 1:197b9fed6092 | 420 | TimeBtpress=0; |
pfe | 1:197b9fed6092 | 421 | while(TimeBtpress<100) { // Boutton pour pouvoir controler le debut de l'enregistrement |
pfe | 0:05a20e3e3179 | 422 | if(boutonStart == 1)TimeBtpress++; |
pfe | 1:197b9fed6092 | 423 | else TimeBtpress=0; |
pfe | 1:197b9fed6092 | 424 | wait_ms(10); |
pfe | 1:197b9fed6092 | 425 | } |
pfe | 1:197b9fed6092 | 426 | //------------------- |
pfe | 1:197b9fed6092 | 427 | TimeBtpress=0; |
pfe | 1:197b9fed6092 | 428 | while(TimeBtpress<0xFFFF) { |
pfe | 1:197b9fed6092 | 429 | |
pfe | 1:197b9fed6092 | 430 | switch (Flag_Timer) { |
pfe | 0:05a20e3e3179 | 431 | |
pfe | 1:197b9fed6092 | 432 | case 0x01:// 05 ms |
pfe | 1:197b9fed6092 | 433 | Flag_Timer = 0; |
pfe | 1:197b9fed6092 | 434 | // Boutton pour pouvoir controler la fin de l'enregistrement |
pfe | 1:197b9fed6092 | 435 | if(boutonEnd == 1)TimeBtpress++; |
pfe | 1:197b9fed6092 | 436 | else TimeBtpress=0; |
pfe | 1:197b9fed6092 | 437 | //------------------ |
pfe | 1:197b9fed6092 | 438 | break; |
pfe | 1:197b9fed6092 | 439 | case 0x03:// 10 ms |
pfe | 1:197b9fed6092 | 440 | Flag_Timer = 0xFF; |
pfe | 1:197b9fed6092 | 441 | #ifdef EN_AutoMat_DataLog |
pfe | 1:197b9fed6092 | 442 | AutoMat_DataLog(); |
pfe | 1:197b9fed6092 | 443 | #endif |
pfe | 1:197b9fed6092 | 444 | AutoMat_Xbee_Tx(); |
pfe | 0:05a20e3e3179 | 445 | Flag_Timer = 0; |
pfe | 0:05a20e3e3179 | 446 | break; |
pfe | 1:197b9fed6092 | 447 | case 0x07:// 100 ms |
pfe | 1:197b9fed6092 | 448 | Flag_Timer = 0xFF; |
pfe | 1:197b9fed6092 | 449 | |
pfe | 1:197b9fed6092 | 450 | GPS = OldGPS; |
pfe | 1:197b9fed6092 | 451 | OldTIMER_10ms = TIMER_10ms; |
pfe | 1:197b9fed6092 | 452 | OldALT = ALT; |
pfe | 1:197b9fed6092 | 453 | OldSPD = SPD; |
pfe | 1:197b9fed6092 | 454 | OldCRS = CRS; |
pfe | 1:197b9fed6092 | 455 | OldTEM = TEM; |
pfe | 1:197b9fed6092 | 456 | |
pfe | 1:197b9fed6092 | 457 | HK_ALT = OldALT/10.0; |
pfe | 1:197b9fed6092 | 458 | HK_SPD = OldSPD/10.0; |
pfe | 1:197b9fed6092 | 459 | HK_CRS = OldCRS/10.0; |
pfe | 0:05a20e3e3179 | 460 | |
pfe | 1:197b9fed6092 | 461 | ET_AutoMat_Xbee_Tx = ET_01; |
pfe | 1:197b9fed6092 | 462 | ET_AutoMat_DataLog = ET_01; |
pfe | 0:05a20e3e3179 | 463 | |
pfe | 1:197b9fed6092 | 464 | //------------------ vérification si le Bt de fin est press pendent un Dt=100 ms |
pfe | 1:197b9fed6092 | 465 | if(TimeBtpress>100) { |
pfe | 1:197b9fed6092 | 466 | TimeBtpress = 0xFFFF; |
pfe | 1:197b9fed6092 | 467 | ET_AutoMat_Xbee_Tx = ET_00; |
pfe | 1:197b9fed6092 | 468 | ET_AutoMat_DataLog = ET_00; |
pfe | 1:197b9fed6092 | 469 | } |
pfe | 1:197b9fed6092 | 470 | //------------------ |
pfe | 1:197b9fed6092 | 471 | #ifdef EN_AutoMat_DataLog |
pfe | 0:05a20e3e3179 | 472 | AutoMat_DataLog(); |
pfe | 1:197b9fed6092 | 473 | #endif |
pfe | 1:197b9fed6092 | 474 | AutoMat_Xbee_Tx(); |
pfe | 1:197b9fed6092 | 475 | |
pfe | 0:05a20e3e3179 | 476 | Flag_Timer = 0x00; |
pfe | 0:05a20e3e3179 | 477 | break; |
pfe | 1:197b9fed6092 | 478 | |
pfe | 1:197b9fed6092 | 479 | default: |
pfe | 1:197b9fed6092 | 480 | break; |
pfe | 1:197b9fed6092 | 481 | }// fin switch |
pfe | 1:197b9fed6092 | 482 | }// fin while |
pfe | 1:197b9fed6092 | 483 | _Ticker1ms.detach(); // ticker detach |
pfe | 1:197b9fed6092 | 484 | _ComGPS.attach(NULL,Serial::RxIrq); // detach Com GPS |
pfe | 1:197b9fed6092 | 485 | LedXbee = 0; |
pfe | 1:197b9fed6092 | 486 | LedGPS = 0; |
pfe | 1:197b9fed6092 | 487 | #ifdef EN_AutoMat_DataLog |
pfe | 1:197b9fed6092 | 488 | LedLog = 1; |
pfe | 1:197b9fed6092 | 489 | fprintf(Fs_Log,"END\r\n"); |
pfe | 1:197b9fed6092 | 490 | fclose(Fs_Log); |
pfe | 1:197b9fed6092 | 491 | wait(1); |
pfe | 1:197b9fed6092 | 492 | LedLog = 0; |
pfe | 1:197b9fed6092 | 493 | #endif |
pfe | 1:197b9fed6092 | 494 | while(1) { |
pfe | 0:05a20e3e3179 | 495 | LedError=!LedError; |
pfe | 0:05a20e3e3179 | 496 | wait(0.5); |
pfe | 1:197b9fed6092 | 497 | } |
pfe | 0:05a20e3e3179 | 498 | //---------------- |
pfe | 1:197b9fed6092 | 499 | #ifdef EN_AutoMat_DataLog |
pfe | 1:197b9fed6092 | 500 | LabError: |
pfe | 0:05a20e3e3179 | 501 | LedError=1; |
pfe | 1:197b9fed6092 | 502 | #endif |
pfe | 0:05a20e3e3179 | 503 | //---------------- |
pfe | 0:05a20e3e3179 | 504 | |
pfe | 0:05a20e3e3179 | 505 | } |