avec dfu

Fork of Utils by POTLESS

Committer:
POTLESS_2
Date:
Tue Mar 06 10:31:52 2018 +0000
Revision:
12:9dd7c462a2c0
Parent:
11:a41267cffa61
Child:
13:ff0f36a6d800
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
POTLESS_2 0:794c15bd30b0 1 #include "mbed.h"
POTLESS_2 0:794c15bd30b0 2 #include "Utils.h"
POTLESS_2 0:794c15bd30b0 3
POTLESS_2 9:fa2818db80cf 4 //SDBlockDevice bd(Flash_MOSI, Flash_MISO, Flash_SCK, Flash_CS);
POTLESS_2 9:fa2818db80cf 5 SPIFBlockDevice bd(Flash_MOSI, Flash_MISO, Flash_SCK, Flash_CS);
POTLESS_2 11:a41267cffa61 6
POTLESS_2 2:5af7a1fb1903 7 FATFileSystem Root("Root");
POTLESS_2 0:794c15bd30b0 8
POTLESS_2 3:01677db45b2a 9 int Exist_Val = 0;
POTLESS_2 3:01677db45b2a 10
POTLESS_2 11:a41267cffa61 11 //Init des PIN i2c pour l'eeprom
POTLESS_2 11:a41267cffa61 12 I2C I2C_EEPROM(SDA_PIN, SCL_PIN);
POTLESS_2 11:a41267cffa61 13
POTLESS_2 0:794c15bd30b0 14 void return_error(int ret_val)
POTLESS_2 0:794c15bd30b0 15 {
POTLESS_2 4:872676dd87a4 16 Exist_Val = 0;
POTLESS_2 6:8bae97034114 17 if (ret_val) {
POTLESS_2 12:9dd7c462a2c0 18 DEEP_DEBUG(" Problème Flash = %d\r\n", ret_val);
POTLESS_2 3:01677db45b2a 19 Exist_Val = 0;
POTLESS_2 6:8bae97034114 20 } else {
POTLESS_2 12:9dd7c462a2c0 21 DEEP_DEBUG(" Flash -> OK.\r\n");
POTLESS_2 3:01677db45b2a 22 Exist_Val = 1;
POTLESS_2 6:8bae97034114 23 }
POTLESS_2 6:8bae97034114 24 wait_ms(100);
POTLESS_2 0:794c15bd30b0 25 }
POTLESS_2 0:794c15bd30b0 26
POTLESS_2 0:794c15bd30b0 27 void errno_error(void* ret_val)
POTLESS_2 0:794c15bd30b0 28 {
POTLESS_2 4:872676dd87a4 29 Exist_Val = 0;
POTLESS_2 6:8bae97034114 30 if (ret_val == NULL) {
POTLESS_2 12:9dd7c462a2c0 31 DEEP_DEBUG(" Problème Flash = %d \r\n", errno);
POTLESS_2 3:01677db45b2a 32 Exist_Val = 0;
POTLESS_2 6:8bae97034114 33 } else {
POTLESS_2 12:9dd7c462a2c0 34 DEEP_DEBUG(" Flash -> OK.\r\n");
POTLESS_2 3:01677db45b2a 35 Exist_Val = 1;
POTLESS_2 6:8bae97034114 36 }
POTLESS_2 6:8bae97034114 37 wait_ms(100);
POTLESS_2 0:794c15bd30b0 38 }
POTLESS_2 0:794c15bd30b0 39
POTLESS_2 8:23fd400c4edd 40 void UTILS::Flash_Infos()
POTLESS_2 8:23fd400c4edd 41 {
POTLESS_2 8:23fd400c4edd 42 printf("\r\n");
POTLESS_2 8:23fd400c4edd 43 printf("Flash size : %llu Mb\r\n", bd.size() / 1048576);
POTLESS_2 8:23fd400c4edd 44 printf("Flash read size : %llu\r\n", bd.get_read_size());
POTLESS_2 8:23fd400c4edd 45 printf("Flash program size : %llu\r\n", bd.get_program_size());
POTLESS_2 8:23fd400c4edd 46 printf("Flash erase size : %llu\r\n", bd.get_erase_size());
POTLESS_2 8:23fd400c4edd 47 }
POTLESS_2 8:23fd400c4edd 48
POTLESS_2 11:a41267cffa61 49 void UTILS::Get_File_Size(char* File_Name)
POTLESS_2 11:a41267cffa61 50 {
POTLESS_2 11:a41267cffa61 51
POTLESS_2 8:23fd400c4edd 52 char filename[20];
POTLESS_2 8:23fd400c4edd 53 sprintf(filename, "/Root/%s", File_Name);
POTLESS_2 8:23fd400c4edd 54
POTLESS_2 8:23fd400c4edd 55 FILE* fd = fopen(filename, "r");
POTLESS_2 11:a41267cffa61 56 errno_error(fd);
POTLESS_2 11:a41267cffa61 57
POTLESS_2 8:23fd400c4edd 58 fseek(fd, 0, SEEK_END);
POTLESS_2 8:23fd400c4edd 59 int size = ftell(fd);
POTLESS_2 8:23fd400c4edd 60 fseek(fd, 0, SEEK_SET);
POTLESS_2 11:a41267cffa61 61
POTLESS_2 8:23fd400c4edd 62 fclose(fd);
POTLESS_2 11:a41267cffa61 63
POTLESS_2 8:23fd400c4edd 64 printf("\r\n");
POTLESS_2 8:23fd400c4edd 65 printf(" Taille du fichier %s = %d Kb\r\n", filename, size / 1024);
POTLESS_2 8:23fd400c4edd 66 }
POTLESS_2 8:23fd400c4edd 67
POTLESS_2 0:794c15bd30b0 68 void UTILS::Store_A_Val(float Val_To_Store, char* File_Name)
POTLESS_2 0:794c15bd30b0 69 {
POTLESS_2 0:794c15bd30b0 70
POTLESS_2 0:794c15bd30b0 71 char filename[20];
POTLESS_2 2:5af7a1fb1903 72 sprintf(filename, "/Root/%s.txt", File_Name);
POTLESS_2 0:794c15bd30b0 73
POTLESS_2 0:794c15bd30b0 74 FILE* fd = fopen(filename, "w");
POTLESS_2 0:794c15bd30b0 75 errno_error(fd);
POTLESS_2 0:794c15bd30b0 76 fprintf(fd, "%f\r\n", Val_To_Store);
POTLESS_2 0:794c15bd30b0 77 fclose(fd);
POTLESS_2 0:794c15bd30b0 78
POTLESS_2 12:9dd7c462a2c0 79 DEEP_DEBUG(" \r\n %s sauvegardée = %f\r\n", filename, Val_To_Store);
POTLESS_2 0:794c15bd30b0 80
POTLESS_2 0:794c15bd30b0 81 }
POTLESS_2 0:794c15bd30b0 82
POTLESS_2 0:794c15bd30b0 83 float UTILS::Read_A_Val(char* File_Name)
POTLESS_2 0:794c15bd30b0 84 {
POTLESS_2 0:794c15bd30b0 85 char buffer[10] = {0};
POTLESS_2 0:794c15bd30b0 86 char c = {0};
POTLESS_2 0:794c15bd30b0 87 char *token;
POTLESS_2 0:794c15bd30b0 88 int i = 0;
POTLESS_2 0:794c15bd30b0 89
POTLESS_2 0:794c15bd30b0 90 char filename[20];
POTLESS_2 2:5af7a1fb1903 91 sprintf(filename, "/Root/%s.txt", File_Name);
POTLESS_2 0:794c15bd30b0 92
POTLESS_2 12:9dd7c462a2c0 93 DEEP_DEBUG(" \n Récupération de %s...\r\n", filename);
POTLESS_2 0:794c15bd30b0 94
POTLESS_2 0:794c15bd30b0 95 FILE* fd = fopen(filename, "r");
POTLESS_2 0:794c15bd30b0 96 errno_error(fd);
POTLESS_2 6:8bae97034114 97
POTLESS_2 0:794c15bd30b0 98 while ((c != '\n') && (i < 10)) {
POTLESS_2 0:794c15bd30b0 99 c = fgetc(fd);
POTLESS_2 0:794c15bd30b0 100 buffer[i] = c;
POTLESS_2 0:794c15bd30b0 101 i++;
POTLESS_2 0:794c15bd30b0 102 }
POTLESS_2 0:794c15bd30b0 103
POTLESS_2 0:794c15bd30b0 104 token = strtok(buffer, "\n");
POTLESS_2 0:794c15bd30b0 105
POTLESS_2 0:794c15bd30b0 106 float val = atof(token);
POTLESS_2 0:794c15bd30b0 107
POTLESS_2 12:9dd7c462a2c0 108 DEEP_DEBUG(" Valeur Récupérée = %f\r\n", val);
POTLESS_2 0:794c15bd30b0 109
POTLESS_2 0:794c15bd30b0 110 fclose(fd);
POTLESS_2 0:794c15bd30b0 111
POTLESS_2 0:794c15bd30b0 112 return val;
POTLESS_2 0:794c15bd30b0 113 }
POTLESS_2 0:794c15bd30b0 114
POTLESS_2 0:794c15bd30b0 115
POTLESS_2 6:8bae97034114 116 void UTILS::Write_Flash_File(char* To_Store, char* File_Name)
POTLESS_2 0:794c15bd30b0 117 {
POTLESS_2 2:5af7a1fb1903 118 char filename[50];
POTLESS_2 2:5af7a1fb1903 119 sprintf(filename, "/Root/%s", (string)File_Name);
POTLESS_2 6:8bae97034114 120
POTLESS_2 0:794c15bd30b0 121 FILE* fd = fopen(filename, "a");
POTLESS_2 6:8bae97034114 122
POTLESS_2 0:794c15bd30b0 123 errno_error(fd);
POTLESS_2 0:794c15bd30b0 124 fprintf(fd, "%s\r\n", To_Store);
POTLESS_2 0:794c15bd30b0 125 fclose(fd);
POTLESS_2 0:794c15bd30b0 126
POTLESS_2 12:9dd7c462a2c0 127 DEEP_DEBUG(" Enregistrement de %s OK\r\n\r\n", filename);
POTLESS_2 0:794c15bd30b0 128 }
POTLESS_2 0:794c15bd30b0 129
POTLESS_2 6:8bae97034114 130 /*
POTLESS_2 6:8bae97034114 131 void UTILS::Read_Flash_File(char* File_Name)
POTLESS_2 0:794c15bd30b0 132 {
POTLESS_2 0:794c15bd30b0 133 char filename[20];
POTLESS_2 2:5af7a1fb1903 134 sprintf(filename, "/Root/%s", File_Name);
POTLESS_2 6:8bae97034114 135
POTLESS_2 0:794c15bd30b0 136 FILE* fd = fopen(filename, "r");
POTLESS_2 0:794c15bd30b0 137 errno_error(fd);
POTLESS_2 0:794c15bd30b0 138
POTLESS_2 6:8bae97034114 139 //printf(" Contenu du fichier :\r\n\r\n");
POTLESS_2 6:8bae97034114 140 char buff[100] = {0};
POTLESS_2 11:a41267cffa61 141
POTLESS_2 11:a41267cffa61 142 while (!feof(fd)) {
POTLESS_2 0:794c15bd30b0 143 int size = fread(&buff[0], 1, 15, fd);
POTLESS_2 11:a41267cffa61 144 fwrite(&buff[0], 1, size, stdout);
POTLESS_2 0:794c15bd30b0 145 }
POTLESS_2 6:8bae97034114 146 //printf("\r\n Fin du fichier.\r\n");
POTLESS_2 0:794c15bd30b0 147 fclose(fd);
POTLESS_2 11:a41267cffa61 148
POTLESS_2 6:8bae97034114 149 }
POTLESS_2 6:8bae97034114 150 */
POTLESS_2 6:8bae97034114 151
POTLESS_2 6:8bae97034114 152 void UTILS::Read_Flash_File(char* File_Name)
POTLESS_2 6:8bae97034114 153 {
POTLESS_2 6:8bae97034114 154 char filename[20];
POTLESS_2 6:8bae97034114 155 sprintf(filename, "/Root/%s", File_Name);
POTLESS_2 6:8bae97034114 156
POTLESS_2 6:8bae97034114 157 FILE* fd = fopen(filename, "r");
POTLESS_2 11:a41267cffa61 158 errno_error(fd);
POTLESS_2 6:8bae97034114 159 char s1[100];
POTLESS_2 8:23fd400c4edd 160 printf("\r\n");
POTLESS_2 6:8bae97034114 161 printf(" Contenu du fichier :\r\n\r\n");
POTLESS_2 6:8bae97034114 162 while (!feof(fd)) {
POTLESS_2 6:8bae97034114 163 memset(s1, 0, sizeof(s1));
POTLESS_2 6:8bae97034114 164 fgets(s1, sizeof(s1), fd);
POTLESS_2 6:8bae97034114 165 printf("%s", s1);
POTLESS_2 6:8bae97034114 166 fflush(stdout);
POTLESS_2 6:8bae97034114 167 }
POTLESS_2 11:a41267cffa61 168 fclose(fd);
POTLESS_2 11:a41267cffa61 169 printf("\r\n Fin du fichier.\r\n");
POTLESS_2 0:794c15bd30b0 170 }
POTLESS_2 0:794c15bd30b0 171
POTLESS_2 5:0f3b6e6677ef 172 bool UTILS::File_Exist(string File_Name)
POTLESS_2 3:01677db45b2a 173 {
POTLESS_2 3:01677db45b2a 174 char filename[20];
POTLESS_2 3:01677db45b2a 175 sprintf(filename, "/Root/%s.txt", File_Name);
POTLESS_2 6:8bae97034114 176
POTLESS_2 3:01677db45b2a 177 FILE* fd = fopen(filename, "r");
POTLESS_2 3:01677db45b2a 178 errno_error(fd);
POTLESS_2 6:8bae97034114 179
POTLESS_2 6:8bae97034114 180 if (Exist_Val == 0) {
POTLESS_2 10:21f3ff5d6a3d 181 DEBUG(" Le fichier %s n'existe pas....\r\n", filename);
POTLESS_2 4:872676dd87a4 182 fclose(fd);
POTLESS_2 3:01677db45b2a 183 return false;
POTLESS_2 5:0f3b6e6677ef 184 }
POTLESS_2 6:8bae97034114 185
POTLESS_2 6:8bae97034114 186 if (Exist_Val == 1) {
POTLESS_2 3:01677db45b2a 187 fclose(fd);
POTLESS_2 3:01677db45b2a 188 return true;
POTLESS_2 6:8bae97034114 189 }
POTLESS_2 3:01677db45b2a 190 }
POTLESS_2 3:01677db45b2a 191
POTLESS_2 6:8bae97034114 192 void UTILS::Delete_Flash_File(char* File_Name)
POTLESS_2 0:794c15bd30b0 193 {
POTLESS_2 0:794c15bd30b0 194 char filename[20];
POTLESS_2 6:8bae97034114 195 sprintf(filename, "%s", File_Name);
POTLESS_2 0:794c15bd30b0 196 int error = 0;
POTLESS_2 2:5af7a1fb1903 197 error = Root.remove(filename);
POTLESS_2 0:794c15bd30b0 198 return_error(error);
POTLESS_2 0:794c15bd30b0 199
POTLESS_2 12:9dd7c462a2c0 200 DEBUG(" Fichier %s effacé.\r\n", filename);
POTLESS_2 0:794c15bd30b0 201 }
POTLESS_2 0:794c15bd30b0 202
POTLESS_2 6:8bae97034114 203 void UTILS::Clean_Flash()
POTLESS_2 6:8bae97034114 204 {
POTLESS_2 12:9dd7c462a2c0 205 DEBUG(" Nettoyage de la Flash.\r\n");
POTLESS_2 12:9dd7c462a2c0 206 //float Saved_O2 = UTILS::Read_A_Val("Calibration_O2");
POTLESS_2 6:8bae97034114 207 int Saved_Motor = (int)UTILS::Read_A_Val("Servo_Poumon");
POTLESS_2 11:a41267cffa61 208 int ARNSRS_ID = (int)UTILS::Read_A_Val("ARNSRS_ID");
POTLESS_2 6:8bae97034114 209 UTILS::UnMount_Flash();
POTLESS_2 6:8bae97034114 210 UTILS::Format_Flash();
POTLESS_2 6:8bae97034114 211 UTILS::Mount_Flash();
POTLESS_2 12:9dd7c462a2c0 212 //UTILS::Store_A_Val(Saved_O2, "Calibration_O2");
POTLESS_2 6:8bae97034114 213 UTILS::Store_A_Val(Saved_Motor, "Servo_Poumon");
POTLESS_2 11:a41267cffa61 214 UTILS::Store_A_Val(ARNSRS_ID, "ARNSRS_ID");
POTLESS_2 12:9dd7c462a2c0 215 DEBUG(" Flash nettoyée.\r\n");
POTLESS_2 12:9dd7c462a2c0 216 DEBUG(" Redémmarage code.\r\n");
POTLESS_2 11:a41267cffa61 217 NVIC_SystemReset();
POTLESS_2 6:8bae97034114 218 }
POTLESS_2 6:8bae97034114 219
POTLESS_2 6:8bae97034114 220 void UTILS::Rename_Flash_File(char* Old_File_Name, char* New_File_Name)
POTLESS_2 0:794c15bd30b0 221 {
POTLESS_2 0:794c15bd30b0 222 char Oldfilename[20];
POTLESS_2 2:5af7a1fb1903 223 sprintf(Oldfilename, "/Root/%s", Old_File_Name);
POTLESS_2 0:794c15bd30b0 224 char Newfilename[20];
POTLESS_2 2:5af7a1fb1903 225 sprintf(Newfilename, "/Root/%s", New_File_Name);
POTLESS_2 0:794c15bd30b0 226
POTLESS_2 0:794c15bd30b0 227 int error = 0;
POTLESS_2 2:5af7a1fb1903 228 error = Root.rename(Oldfilename, Newfilename);
POTLESS_2 0:794c15bd30b0 229 return_error(error);
POTLESS_2 0:794c15bd30b0 230
POTLESS_2 12:9dd7c462a2c0 231 DEBUG(" Fichier %s renommé en %s.\r\n", Oldfilename, Newfilename);
POTLESS_2 0:794c15bd30b0 232 }
POTLESS_2 0:794c15bd30b0 233
POTLESS_2 6:8bae97034114 234 void UTILS::Mount_Flash()
POTLESS_2 0:794c15bd30b0 235 {
POTLESS_2 6:8bae97034114 236 //Montage Flash
POTLESS_2 10:21f3ff5d6a3d 237 DEBUG(" Montage Flash \"/Root\". \r\n\r\n");
POTLESS_2 0:794c15bd30b0 238 int error = 0;
POTLESS_2 2:5af7a1fb1903 239 error = Root.mount(&bd);
POTLESS_2 0:794c15bd30b0 240 return_error(error);
POTLESS_2 1:a937433a95c8 241 if (error > 0) {
POTLESS_2 0:794c15bd30b0 242 //On re format s'il n'y a as de file system...normalement une seul fois...
POTLESS_2 10:21f3ff5d6a3d 243 DEBUG("Pas de File system, on format... ");
POTLESS_2 6:8bae97034114 244 Format_Flash();
POTLESS_2 0:794c15bd30b0 245 }
POTLESS_2 0:794c15bd30b0 246 }
POTLESS_2 0:794c15bd30b0 247
POTLESS_2 6:8bae97034114 248 void UTILS::UnMount_Flash()
POTLESS_2 0:794c15bd30b0 249 {
POTLESS_2 6:8bae97034114 250 //De Montage Flash
POTLESS_2 10:21f3ff5d6a3d 251 DEBUG(" Demontage Flash \"/Root\". \r\n\r\n");
POTLESS_2 0:794c15bd30b0 252 int error = 0;
POTLESS_2 2:5af7a1fb1903 253 error = Root.unmount();
POTLESS_2 0:794c15bd30b0 254 return_error(error);
POTLESS_2 0:794c15bd30b0 255 }
POTLESS_2 0:794c15bd30b0 256
POTLESS_2 6:8bae97034114 257 void UTILS::Format_Flash()
POTLESS_2 0:794c15bd30b0 258 {
POTLESS_2 6:8bae97034114 259 //Formatage Flash
POTLESS_2 10:21f3ff5d6a3d 260 DEBUG(" Formatage Flash\r\n\r\n");
POTLESS_2 0:794c15bd30b0 261 int error = 0;
POTLESS_2 4:872676dd87a4 262 error = FATFileSystem::format(&bd);
POTLESS_2 2:5af7a1fb1903 263 return_error(error);
POTLESS_2 2:5af7a1fb1903 264 }
POTLESS_2 2:5af7a1fb1903 265
POTLESS_2 6:8bae97034114 266 void UTILS::Dir_Flash(char* Dir_Name)
POTLESS_2 2:5af7a1fb1903 267 {
POTLESS_2 2:5af7a1fb1903 268 int error = 0;
POTLESS_2 3:01677db45b2a 269 int nb = 0;
POTLESS_2 12:9dd7c462a2c0 270 DEEP_DEBUG("\r\n Ouverture du répertoire %s\r\n", Dir_Name);
POTLESS_2 2:5af7a1fb1903 271 char Dirname[20];
POTLESS_2 2:5af7a1fb1903 272 sprintf(Dirname, "/Root/%s", Dir_Name);
POTLESS_2 6:8bae97034114 273
POTLESS_2 2:5af7a1fb1903 274 DIR* dir = opendir(Dirname);
POTLESS_2 2:5af7a1fb1903 275
POTLESS_2 2:5af7a1fb1903 276 struct dirent* de;
POTLESS_2 12:9dd7c462a2c0 277 DEBUG(" Fichiers du répertoire :\r\n\r\n");
POTLESS_2 6:8bae97034114 278 while((de = readdir(dir)) != NULL) {
POTLESS_2 6:8bae97034114 279 printf(" %s\r\n", &(de->d_name)[0]);
POTLESS_2 6:8bae97034114 280 fflush(stdout);
POTLESS_2 6:8bae97034114 281 nb++;
POTLESS_2 6:8bae97034114 282 }
POTLESS_2 10:21f3ff5d6a3d 283 DEBUG("\r\n Nombre de fichiers = %d\r\n", nb);
POTLESS_2 12:9dd7c462a2c0 284 DEEP_DEBUG(" Fermeture du répertoire.\r\n");
POTLESS_2 6:8bae97034114 285 error = closedir(dir);
POTLESS_2 0:794c15bd30b0 286 return_error(error);
POTLESS_2 0:794c15bd30b0 287 }
POTLESS_2 0:794c15bd30b0 288
POTLESS_2 3:01677db45b2a 289 int UTILS::File_Index()
POTLESS_2 3:01677db45b2a 290 {
POTLESS_2 3:01677db45b2a 291 int error = 0;
POTLESS_2 3:01677db45b2a 292 int nb = 0;
POTLESS_2 6:8bae97034114 293
POTLESS_2 3:01677db45b2a 294 DIR* dir = opendir("/Root/");
POTLESS_2 3:01677db45b2a 295 struct dirent* de;
POTLESS_2 6:8bae97034114 296 while((de = readdir(dir)) != NULL) {
POTLESS_2 6:8bae97034114 297 nb++;
POTLESS_2 3:01677db45b2a 298 }
POTLESS_2 3:01677db45b2a 299 error = closedir(dir);
POTLESS_2 3:01677db45b2a 300 return_error(error);
POTLESS_2 6:8bae97034114 301
POTLESS_2 3:01677db45b2a 302 return nb - 2;
POTLESS_2 3:01677db45b2a 303 }
POTLESS_2 3:01677db45b2a 304
POTLESS_2 0:794c15bd30b0 305 //Remapping d'une valeur dans une autre échelle
POTLESS_2 0:794c15bd30b0 306 float UTILS::Remap(float x, float in_min, float in_max, float out_min, float out_max)
POTLESS_2 0:794c15bd30b0 307 {
POTLESS_2 0:794c15bd30b0 308 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
POTLESS_2 0:794c15bd30b0 309 }
POTLESS_2 0:794c15bd30b0 310
POTLESS_2 0:794c15bd30b0 311 //Contraint une valeur entre deux limites
POTLESS_2 0:794c15bd30b0 312 float UTILS::constrain(float x, float a, float b)
POTLESS_2 0:794c15bd30b0 313 {
POTLESS_2 0:794c15bd30b0 314 if(x < a) {
POTLESS_2 0:794c15bd30b0 315 return a;
POTLESS_2 0:794c15bd30b0 316 } else if(b < x) {
POTLESS_2 0:794c15bd30b0 317 return b;
POTLESS_2 0:794c15bd30b0 318 } else
POTLESS_2 0:794c15bd30b0 319 return x;
POTLESS_2 6:8bae97034114 320 }
POTLESS_2 6:8bae97034114 321
POTLESS_2 6:8bae97034114 322 void UTILS::Help()
POTLESS_2 6:8bae97034114 323 {
POTLESS_2 6:8bae97034114 324 printf("\r\n");
POTLESS_2 8:23fd400c4edd 325 printf(" COMMANDES GENERALES\r\n\r\n");
POTLESS_2 8:23fd400c4edd 326 printf(" help = liste des commandes.\r\n");
POTLESS_2 8:23fd400c4edd 327 printf(" start = démmarage des sorties moniteur.\r\n");
POTLESS_2 8:23fd400c4edd 328 printf(" stop = arrêt des sorties moniteur.\r\n");
POTLESS_2 6:8bae97034114 329 printf(" time X = met la RTC à l'heure, X en UNIX TIME.\n\r");
POTLESS_2 12:9dd7c462a2c0 330 printf(" ARNSRS_ID X = entrée de l'identifiant de l'appareil X.\r\n");
POTLESS_2 8:23fd400c4edd 331 printf(" sleep = mise en veille.\n\r");
POTLESS_2 8:23fd400c4edd 332 printf(" reset = reset de la carte.\n\r\n\r");
POTLESS_2 8:23fd400c4edd 333 printf(" COMMANDES MEMOIRE\r\n\r\n");
POTLESS_2 8:23fd400c4edd 334 printf(" rec = démarrage / arrêt enregistrement.\r\n");
POTLESS_2 8:23fd400c4edd 335 printf(" flash_i = informations sur la flash.\r\n");
POTLESS_2 8:23fd400c4edd 336 printf(" clean = nettoyage flash, suppression des fichiers LOG.\r\n");
POTLESS_2 8:23fd400c4edd 337 printf(" dir = liste des fichiers de la flash.\r\n");
POTLESS_2 8:23fd400c4edd 338 printf(" del X = effacer le fichier LOG_X.\n\r");
POTLESS_2 8:23fd400c4edd 339 printf(" get X = récupérer le contenu du fichier LOG_X.\n\r");
POTLESS_2 8:23fd400c4edd 340 printf(" file_s X = récupérer la taille du fichier LOG_X.\n\r\n\r");
POTLESS_2 8:23fd400c4edd 341 //printf(" file_i X = récupérer les informations sur le fichier LOG_X.\n\r\n\r");
POTLESS_2 11:a41267cffa61 342 printf(" COMMANDES MOTEURS\r\n\r\n");
POTLESS_2 8:23fd400c4edd 343 printf(" c_pou X = changement consigne volet poumon à X.\n\r");
POTLESS_2 8:23fd400c4edd 344 printf(" c_fui X = changement consigne volet fuite à X.\n\r");
POTLESS_2 8:23fd400c4edd 345 printf(" calib_p = calibration à 0 du volet poumon.\n\r");
POTLESS_2 11:a41267cffa61 346 printf(" calib_f = calibration à 0 du volet fuite.\n\r");
POTLESS_2 12:9dd7c462a2c0 347 printf(" secu = mise des volets en mode sécu.\n\r");
POTLESS_2 12:9dd7c462a2c0 348 printf(" check_F = sortie des valeurs 0 moteurs et ARNSRS_ID enregistrées.\n\r\n\r");
POTLESS_2 11:a41267cffa61 349 printf(" COMMANDES CAPTEURS\r\n\r\n");
POTLESS_2 11:a41267cffa61 350 printf(" Head_ID X = Numérote le numéro X d'identification de la sensor Head dans l'eeprom.\n\r");
POTLESS_2 11:a41267cffa61 351 printf(" O2_1_ID X = Numérote le numéro X d'identification de la cellule O2 1 dans l'eeprom.\n\r");
POTLESS_2 11:a41267cffa61 352 printf(" O2_2_ID X = Numérote le numéro X d'identification de la cellule O2 2 dans l'eeprom.\n\r");
POTLESS_2 11:a41267cffa61 353 printf(" CO2_ID X = Numérote le numéro X d'identification du capteur CO2 dans l'eeprom.\n\r");
POTLESS_2 12:9dd7c462a2c0 354 printf(" check_E = sortie des valeurs de calibration enregistrées dans l'eeprom.\n\r\n\r");
POTLESS_2 12:9dd7c462a2c0 355 printf(" calib_O2 X = calibration des cellules O2 dans l'air avec X itérations.\n\r\n\r");
POTLESS_2 12:9dd7c462a2c0 356
POTLESS_2 8:23fd400c4edd 357 printf(" Les commandes pour le Mini-r sont à entrer conformément à la doc. Les plus utilisée :\n\r");
POTLESS_2 8:23fd400c4edd 358 printf(" G = calibration du capteur CO2 dans l'air.\n\r");
POTLESS_2 11:a41267cffa61 359 printf(" K 0 = arrêt du capteur CO2.\n\r");
POTLESS_2 8:23fd400c4edd 360 printf(" K 1 = capteur CO2 mode streaming.\n\r");
POTLESS_2 8:23fd400c4edd 361 printf(" K 2 = capteur CO2 mode spooling.\n\r");
POTLESS_2 11:a41267cffa61 362 printf(" A X = digi filter X. X égal à 32, 64, 128...\n\r");
POTLESS_2 6:8bae97034114 363 printf("\r\n\r\n");
POTLESS_2 6:8bae97034114 364 fflush(stdout);
POTLESS_2 11:a41267cffa61 365 }
POTLESS_2 11:a41267cffa61 366
POTLESS_2 11:a41267cffa61 367 void UTILS::clean_line_EEPROM(unsigned int eeaddress, int address)
POTLESS_2 11:a41267cffa61 368 {
POTLESS_2 12:9dd7c462a2c0 369 DEEP_DEBUG(" Effacage de la ligne à l'adresse %d de l'eeprom.\r\n", eeaddress);
POTLESS_2 11:a41267cffa61 370
POTLESS_2 11:a41267cffa61 371 int size = 64;
POTLESS_2 11:a41267cffa61 372 char deleteData[] = {" "};
POTLESS_2 11:a41267cffa61 373
POTLESS_2 11:a41267cffa61 374 char i2cBuffer[size + 2];
POTLESS_2 11:a41267cffa61 375 i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
POTLESS_2 11:a41267cffa61 376 i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
POTLESS_2 11:a41267cffa61 377
POTLESS_2 11:a41267cffa61 378 for (int i = 0; i < size; i++) {
POTLESS_2 11:a41267cffa61 379 i2cBuffer[i + 2] = deleteData[i];
POTLESS_2 11:a41267cffa61 380 }
POTLESS_2 11:a41267cffa61 381
POTLESS_2 11:a41267cffa61 382 int result = I2C_EEPROM.write(address, i2cBuffer, size + 2, false);
POTLESS_2 11:a41267cffa61 383 wait_ms(6);
POTLESS_2 11:a41267cffa61 384
POTLESS_2 12:9dd7c462a2c0 385 DEEP_DEBUG(" Ligne à l'adresse %d de l'eeprom effacée.\r\n", eeaddress);
POTLESS_2 11:a41267cffa61 386 }
POTLESS_2 11:a41267cffa61 387
POTLESS_2 11:a41267cffa61 388 //Max 63 bit en écriture
POTLESS_2 11:a41267cffa61 389 void UTILS::write_EEPROM(char *data, unsigned int eeaddress, int address)
POTLESS_2 11:a41267cffa61 390 {
POTLESS_2 11:a41267cffa61 391 //Nettoyage de la ligne ou on va stocker la nouvelle data
POTLESS_2 11:a41267cffa61 392 clean_line_EEPROM(eeaddress);
POTLESS_2 11:a41267cffa61 393
POTLESS_2 11:a41267cffa61 394 // On calcul de la taille de la chaine a enregistrer
POTLESS_2 11:a41267cffa61 395 char size = 0;
POTLESS_2 11:a41267cffa61 396 do {
POTLESS_2 11:a41267cffa61 397 size++;
POTLESS_2 11:a41267cffa61 398 } while (data[size]);
POTLESS_2 11:a41267cffa61 399
POTLESS_2 11:a41267cffa61 400 char i2cBuffer[size + 2];
POTLESS_2 11:a41267cffa61 401 i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
POTLESS_2 11:a41267cffa61 402 i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
POTLESS_2 11:a41267cffa61 403
POTLESS_2 11:a41267cffa61 404 for (int i = 0; i < size; i++) {
POTLESS_2 11:a41267cffa61 405 i2cBuffer[i + 2] = data[i];
POTLESS_2 11:a41267cffa61 406 }
POTLESS_2 11:a41267cffa61 407
POTLESS_2 11:a41267cffa61 408 int res = I2C_EEPROM.write(address, i2cBuffer, size + 2, false);
POTLESS_2 11:a41267cffa61 409
POTLESS_2 11:a41267cffa61 410 wait_ms(6);
POTLESS_2 11:a41267cffa61 411
POTLESS_2 12:9dd7c462a2c0 412 DEEP_DEBUG(" Chaine écrite à l'adresse %d de l'eeprom : %s\r\n", eeaddress , data);
POTLESS_2 11:a41267cffa61 413 }
POTLESS_2 11:a41267cffa61 414
POTLESS_2 12:9dd7c462a2c0 415 char* UTILS::read_EEPROM(unsigned int eeaddress , int address)
POTLESS_2 12:9dd7c462a2c0 416 {
POTLESS_2 12:9dd7c462a2c0 417 //On lit toute la ligne
POTLESS_2 12:9dd7c462a2c0 418 int size = 17;
POTLESS_2 12:9dd7c462a2c0 419 static char data[17];
POTLESS_2 12:9dd7c462a2c0 420
POTLESS_2 12:9dd7c462a2c0 421 char i2cBuffer[2];
POTLESS_2 12:9dd7c462a2c0 422 i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
POTLESS_2 12:9dd7c462a2c0 423 i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
POTLESS_2 12:9dd7c462a2c0 424
POTLESS_2 12:9dd7c462a2c0 425 // Reset eeprom pointer address
POTLESS_2 12:9dd7c462a2c0 426 int result = I2C_EEPROM.write(address, i2cBuffer, 2, false);
POTLESS_2 12:9dd7c462a2c0 427 wait_ms(6);
POTLESS_2 12:9dd7c462a2c0 428
POTLESS_2 12:9dd7c462a2c0 429 // Read eeprom
POTLESS_2 12:9dd7c462a2c0 430 I2C_EEPROM.read(address, data, size);
POTLESS_2 12:9dd7c462a2c0 431 wait_ms(6);
POTLESS_2 12:9dd7c462a2c0 432
POTLESS_2 12:9dd7c462a2c0 433 DEEP_DEBUG(" Char lu à l'adresse %d de l'eeprom : %s\r\n", eeaddress, &data);
POTLESS_2 12:9dd7c462a2c0 434
POTLESS_2 12:9dd7c462a2c0 435 return data;
POTLESS_2 12:9dd7c462a2c0 436 }
POTLESS_2 12:9dd7c462a2c0 437
POTLESS_2 12:9dd7c462a2c0 438 void UTILS::read_C_EEPROM(char *data, unsigned int eeaddress ,int address)
POTLESS_2 12:9dd7c462a2c0 439 {
POTLESS_2 12:9dd7c462a2c0 440 //On lit toute la ligne
POTLESS_2 12:9dd7c462a2c0 441 int size = 64;
POTLESS_2 12:9dd7c462a2c0 442
POTLESS_2 12:9dd7c462a2c0 443 char i2cBuffer[2];
POTLESS_2 12:9dd7c462a2c0 444 i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
POTLESS_2 12:9dd7c462a2c0 445 i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
POTLESS_2 12:9dd7c462a2c0 446
POTLESS_2 12:9dd7c462a2c0 447 // Reset eeprom pointer address
POTLESS_2 12:9dd7c462a2c0 448 int result = I2C_EEPROM.write(address, i2cBuffer, 2, false);
POTLESS_2 12:9dd7c462a2c0 449 wait_ms(6);
POTLESS_2 12:9dd7c462a2c0 450
POTLESS_2 12:9dd7c462a2c0 451 // Read eeprom
POTLESS_2 12:9dd7c462a2c0 452 I2C_EEPROM.read(address, data, size);
POTLESS_2 12:9dd7c462a2c0 453 wait_ms(6);
POTLESS_2 12:9dd7c462a2c0 454
POTLESS_2 12:9dd7c462a2c0 455 DEEP_DEBUG(" Char lu à l'adresse %d de l'eeprom : %s\r\n", eeaddress, data);
POTLESS_2 12:9dd7c462a2c0 456 }
POTLESS_2 11:a41267cffa61 457
POTLESS_2 11:a41267cffa61 458 float UTILS::read_F_EEPROM(unsigned int eeaddress ,int address)
POTLESS_2 11:a41267cffa61 459 {
POTLESS_2 11:a41267cffa61 460 //On lit toute la ligne
POTLESS_2 11:a41267cffa61 461 int size = 64;
POTLESS_2 11:a41267cffa61 462 char data[64];
POTLESS_2 11:a41267cffa61 463
POTLESS_2 11:a41267cffa61 464 char i2cBuffer[2];
POTLESS_2 11:a41267cffa61 465 i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
POTLESS_2 11:a41267cffa61 466 i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
POTLESS_2 11:a41267cffa61 467
POTLESS_2 11:a41267cffa61 468 int result = I2C_EEPROM.write(address, i2cBuffer, 2, false);
POTLESS_2 11:a41267cffa61 469 wait_ms(6);
POTLESS_2 11:a41267cffa61 470
POTLESS_2 11:a41267cffa61 471 I2C_EEPROM.read(address, data, size);
POTLESS_2 11:a41267cffa61 472 wait_ms(6);
POTLESS_2 11:a41267cffa61 473
POTLESS_2 11:a41267cffa61 474 float result_F = atof(data);
POTLESS_2 12:9dd7c462a2c0 475 DEEP_DEBUG(" Float lu à l'adresse %d de l'eeprom : %f\r\n", eeaddress, result_F);
POTLESS_2 11:a41267cffa61 476 return result_F;
POTLESS_2 11:a41267cffa61 477 }
POTLESS_2 11:a41267cffa61 478
POTLESS_2 11:a41267cffa61 479
POTLESS_2 11:a41267cffa61 480 int UTILS::read_I_EEPROM(unsigned int eeaddress ,int address)
POTLESS_2 11:a41267cffa61 481 {
POTLESS_2 11:a41267cffa61 482 //On lit toute la ligne
POTLESS_2 11:a41267cffa61 483 int size = 64;
POTLESS_2 11:a41267cffa61 484 char data[64];
POTLESS_2 11:a41267cffa61 485
POTLESS_2 11:a41267cffa61 486 char i2cBuffer[2];
POTLESS_2 11:a41267cffa61 487 i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
POTLESS_2 11:a41267cffa61 488 i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
POTLESS_2 11:a41267cffa61 489
POTLESS_2 11:a41267cffa61 490 int result = I2C_EEPROM.write(address, i2cBuffer, 2, false);
POTLESS_2 11:a41267cffa61 491 wait_ms(6);
POTLESS_2 11:a41267cffa61 492
POTLESS_2 11:a41267cffa61 493 I2C_EEPROM.read(address, data, size);
POTLESS_2 11:a41267cffa61 494 wait_ms(6);
POTLESS_2 11:a41267cffa61 495
POTLESS_2 11:a41267cffa61 496 int result_I = atoi(data);
POTLESS_2 12:9dd7c462a2c0 497 DEEP_DEBUG(" Int lu à l'adresse %d l'eeprom : %d\r\n", eeaddress, result_I);
POTLESS_2 11:a41267cffa61 498 return result_I;
POTLESS_2 11:a41267cffa61 499 }
POTLESS_2 11:a41267cffa61 500
POTLESS_2 11:a41267cffa61 501 void UTILS::clean_EEPROM(int address)
POTLESS_2 11:a41267cffa61 502 {
POTLESS_2 11:a41267cffa61 503 DEBUG(" Nettoyage total de l'Eeprom (64 colonnes, 4096 lignes).\r\n");
POTLESS_2 11:a41267cffa61 504 int i;
POTLESS_2 11:a41267cffa61 505 int pointer;
POTLESS_2 11:a41267cffa61 506 char deleteData[] = {" "};
POTLESS_2 11:a41267cffa61 507 for (i = 0; i < 4096; i++) {
POTLESS_2 11:a41267cffa61 508 pointer = 64 * i;
POTLESS_2 11:a41267cffa61 509 clean_line_EEPROM(pointer, address);
POTLESS_2 11:a41267cffa61 510 }
POTLESS_2 11:a41267cffa61 511 DEBUG("Eeprom néttoyée.\r\n");
POTLESS_2 11:a41267cffa61 512 }