avec dfu
Fork of Utils by
Utils.cpp@9:fa2818db80cf, 2018-02-23 (annotated)
- Committer:
- POTLESS_2
- Date:
- Fri Feb 23 19:05:27 2018 +0000
- Revision:
- 9:fa2818db80cf
- Parent:
- 8:23fd400c4edd
- Child:
- 10:21f3ff5d6a3d
modifs
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:23fd400c4edd | 6 | |
POTLESS_2 | 8:23fd400c4edd | 7 | |
POTLESS_2 | 2:5af7a1fb1903 | 8 | FATFileSystem Root("Root"); |
POTLESS_2 | 0:794c15bd30b0 | 9 | |
POTLESS_2 | 3:01677db45b2a | 10 | int Exist_Val = 0; |
POTLESS_2 | 3:01677db45b2a | 11 | |
POTLESS_2 | 0:794c15bd30b0 | 12 | void return_error(int ret_val) |
POTLESS_2 | 0:794c15bd30b0 | 13 | { |
POTLESS_2 | 4:872676dd87a4 | 14 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 15 | if (ret_val) { |
POTLESS_2 | 6:8bae97034114 | 16 | DEBUG_U(" Problème Flash = %d\r\n", ret_val); |
POTLESS_2 | 3:01677db45b2a | 17 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 18 | } else { |
POTLESS_2 | 6:8bae97034114 | 19 | DEBUG_U(" Flash -> OK.\r\n"); |
POTLESS_2 | 3:01677db45b2a | 20 | Exist_Val = 1; |
POTLESS_2 | 6:8bae97034114 | 21 | } |
POTLESS_2 | 6:8bae97034114 | 22 | wait_ms(100); |
POTLESS_2 | 0:794c15bd30b0 | 23 | } |
POTLESS_2 | 0:794c15bd30b0 | 24 | |
POTLESS_2 | 0:794c15bd30b0 | 25 | void errno_error(void* ret_val) |
POTLESS_2 | 0:794c15bd30b0 | 26 | { |
POTLESS_2 | 4:872676dd87a4 | 27 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 28 | if (ret_val == NULL) { |
POTLESS_2 | 6:8bae97034114 | 29 | DEBUG_U(" Problème Flash = %d \r\n", errno); |
POTLESS_2 | 3:01677db45b2a | 30 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 31 | } else { |
POTLESS_2 | 6:8bae97034114 | 32 | DEBUG_U(" Flash -> OK.\r\n"); |
POTLESS_2 | 3:01677db45b2a | 33 | Exist_Val = 1; |
POTLESS_2 | 6:8bae97034114 | 34 | } |
POTLESS_2 | 6:8bae97034114 | 35 | wait_ms(100); |
POTLESS_2 | 0:794c15bd30b0 | 36 | } |
POTLESS_2 | 0:794c15bd30b0 | 37 | |
POTLESS_2 | 8:23fd400c4edd | 38 | void UTILS::Flash_Infos() |
POTLESS_2 | 8:23fd400c4edd | 39 | { |
POTLESS_2 | 8:23fd400c4edd | 40 | printf("\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 41 | printf("Flash size : %llu Mb\r\n", bd.size() / 1048576); |
POTLESS_2 | 8:23fd400c4edd | 42 | printf("Flash read size : %llu\r\n", bd.get_read_size()); |
POTLESS_2 | 8:23fd400c4edd | 43 | printf("Flash program size : %llu\r\n", bd.get_program_size()); |
POTLESS_2 | 8:23fd400c4edd | 44 | printf("Flash erase size : %llu\r\n", bd.get_erase_size()); |
POTLESS_2 | 8:23fd400c4edd | 45 | } |
POTLESS_2 | 8:23fd400c4edd | 46 | |
POTLESS_2 | 8:23fd400c4edd | 47 | void UTILS::Get_File_Size(char* File_Name) { |
POTLESS_2 | 8:23fd400c4edd | 48 | |
POTLESS_2 | 8:23fd400c4edd | 49 | char filename[20]; |
POTLESS_2 | 8:23fd400c4edd | 50 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 8:23fd400c4edd | 51 | |
POTLESS_2 | 8:23fd400c4edd | 52 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 8:23fd400c4edd | 53 | errno_error(fd); |
POTLESS_2 | 8:23fd400c4edd | 54 | |
POTLESS_2 | 8:23fd400c4edd | 55 | fseek(fd, 0, SEEK_END); |
POTLESS_2 | 8:23fd400c4edd | 56 | int size = ftell(fd); |
POTLESS_2 | 8:23fd400c4edd | 57 | fseek(fd, 0, SEEK_SET); |
POTLESS_2 | 8:23fd400c4edd | 58 | |
POTLESS_2 | 8:23fd400c4edd | 59 | fclose(fd); |
POTLESS_2 | 8:23fd400c4edd | 60 | |
POTLESS_2 | 8:23fd400c4edd | 61 | printf("\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 62 | printf(" Taille du fichier %s = %d Kb\r\n", filename, size / 1024); |
POTLESS_2 | 8:23fd400c4edd | 63 | } |
POTLESS_2 | 8:23fd400c4edd | 64 | |
POTLESS_2 | 8:23fd400c4edd | 65 | /* |
POTLESS_2 | 8:23fd400c4edd | 66 | void UTILS::Get_File_Infos(char* File_Name) { |
POTLESS_2 | 8:23fd400c4edd | 67 | |
POTLESS_2 | 8:23fd400c4edd | 68 | char filename[20]; |
POTLESS_2 | 8:23fd400c4edd | 69 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 8:23fd400c4edd | 70 | |
POTLESS_2 | 8:23fd400c4edd | 71 | struct stat fileStat; |
POTLESS_2 | 8:23fd400c4edd | 72 | stat(filename, &fileStat); |
POTLESS_2 | 8:23fd400c4edd | 73 | |
POTLESS_2 | 8:23fd400c4edd | 74 | printf("Informations sur %s\r\n\r\n",filename); |
POTLESS_2 | 8:23fd400c4edd | 75 | printf(" Taille du fichier : %d bytes\r\n",&fileStat.st_size); |
POTLESS_2 | 8:23fd400c4edd | 76 | printf(" Heure dernier accès : %s\r\n",ctime(&fileStat.st_atime)); |
POTLESS_2 | 8:23fd400c4edd | 77 | printf(" Heure dernière modification : %s\r\n",ctime(&fileStat.st_mtime)); |
POTLESS_2 | 8:23fd400c4edd | 78 | printf(" Heure dernier changement : %s\r\n",ctime(&fileStat.st_ctime)); |
POTLESS_2 | 8:23fd400c4edd | 79 | |
POTLESS_2 | 8:23fd400c4edd | 80 | |
POTLESS_2 | 8:23fd400c4edd | 81 | struct stat stat_buf; |
POTLESS_2 | 8:23fd400c4edd | 82 | |
POTLESS_2 | 8:23fd400c4edd | 83 | stat(filename, &stat_buf); |
POTLESS_2 | 8:23fd400c4edd | 84 | |
POTLESS_2 | 8:23fd400c4edd | 85 | |
POTLESS_2 | 8:23fd400c4edd | 86 | stat_buf.st_size; |
POTLESS_2 | 8:23fd400c4edd | 87 | stat_buf.st_dev; |
POTLESS_2 | 8:23fd400c4edd | 88 | stat_buf.st_ino; |
POTLESS_2 | 8:23fd400c4edd | 89 | stat_buf.st_mode; |
POTLESS_2 | 8:23fd400c4edd | 90 | stat_buf.st_nlink; |
POTLESS_2 | 8:23fd400c4edd | 91 | stat_buf.st_uid; |
POTLESS_2 | 8:23fd400c4edd | 92 | stat_buf.st_gid; |
POTLESS_2 | 8:23fd400c4edd | 93 | stat_buf.st_rdev; |
POTLESS_2 | 8:23fd400c4edd | 94 | stat_buf.st_size; |
POTLESS_2 | 8:23fd400c4edd | 95 | stat_buf.st_blksize; |
POTLESS_2 | 8:23fd400c4edd | 96 | stat_buf.st_blocks; |
POTLESS_2 | 8:23fd400c4edd | 97 | stat_buf.st_atime; |
POTLESS_2 | 8:23fd400c4edd | 98 | stat_buf.st_mtime; |
POTLESS_2 | 8:23fd400c4edd | 99 | stat_buf.st_ctime; |
POTLESS_2 | 8:23fd400c4edd | 100 | |
POTLESS_2 | 8:23fd400c4edd | 101 | printf(" Taille du fichier : %d bytes\r\n",&stat_buf.st_size); |
POTLESS_2 | 8:23fd400c4edd | 102 | printf(" Heure dernier accès : %s\r\n",ctime(&stat_buf.st_atime)); |
POTLESS_2 | 8:23fd400c4edd | 103 | printf(" Heure dernière modification : %s\r\n",ctime(&stat_buf.st_mtime)); |
POTLESS_2 | 8:23fd400c4edd | 104 | printf(" Heure dernier changement : %s\r\n",ctime(&stat_buf.st_ctime)); |
POTLESS_2 | 8:23fd400c4edd | 105 | |
POTLESS_2 | 8:23fd400c4edd | 106 | } |
POTLESS_2 | 8:23fd400c4edd | 107 | |
POTLESS_2 | 8:23fd400c4edd | 108 | void UTILS::Get_File_Infos_bis(char* File_Name) { |
POTLESS_2 | 8:23fd400c4edd | 109 | |
POTLESS_2 | 8:23fd400c4edd | 110 | char filename[20]; |
POTLESS_2 | 8:23fd400c4edd | 111 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 8:23fd400c4edd | 112 | |
POTLESS_2 | 8:23fd400c4edd | 113 | struct stat fileStat; |
POTLESS_2 | 8:23fd400c4edd | 114 | |
POTLESS_2 | 8:23fd400c4edd | 115 | stat(filename, &fileStat); |
POTLESS_2 | 8:23fd400c4edd | 116 | |
POTLESS_2 | 8:23fd400c4edd | 117 | printf("Information for %s\n",filename); |
POTLESS_2 | 8:23fd400c4edd | 118 | printf("---------------------------\n"); |
POTLESS_2 | 8:23fd400c4edd | 119 | printf("File Size: \t\t%d bytes\n",fileStat.st_size); |
POTLESS_2 | 8:23fd400c4edd | 120 | printf("Number of Links: \t%d\n",fileStat.st_nlink); |
POTLESS_2 | 8:23fd400c4edd | 121 | printf("File inode: \t\t%d\n",fileStat.st_ino); |
POTLESS_2 | 8:23fd400c4edd | 122 | |
POTLESS_2 | 8:23fd400c4edd | 123 | printf("File Permissions: \t"); |
POTLESS_2 | 8:23fd400c4edd | 124 | printf( (fileStat.st_mode & S_IRUSR) ? "r" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 125 | printf( (fileStat.st_mode & S_IWUSR) ? "w" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 126 | printf( (fileStat.st_mode & S_IXUSR) ? "x" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 127 | printf( (fileStat.st_mode & S_IRGRP) ? "r" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 128 | printf( (fileStat.st_mode & S_IWGRP) ? "w" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 129 | printf( (fileStat.st_mode & S_IXGRP) ? "x" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 130 | printf( (fileStat.st_mode & S_IROTH) ? "r" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 131 | printf( (fileStat.st_mode & S_IWOTH) ? "w" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 132 | printf( (fileStat.st_mode & S_IXOTH) ? "x" : "-"); |
POTLESS_2 | 8:23fd400c4edd | 133 | printf("\n\n"); |
POTLESS_2 | 8:23fd400c4edd | 134 | |
POTLESS_2 | 8:23fd400c4edd | 135 | } |
POTLESS_2 | 8:23fd400c4edd | 136 | */ |
POTLESS_2 | 8:23fd400c4edd | 137 | |
POTLESS_2 | 0:794c15bd30b0 | 138 | void UTILS::Store_A_Val(float Val_To_Store, char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 139 | { |
POTLESS_2 | 0:794c15bd30b0 | 140 | |
POTLESS_2 | 0:794c15bd30b0 | 141 | char filename[20]; |
POTLESS_2 | 2:5af7a1fb1903 | 142 | sprintf(filename, "/Root/%s.txt", File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 143 | |
POTLESS_2 | 0:794c15bd30b0 | 144 | FILE* fd = fopen(filename, "w"); |
POTLESS_2 | 0:794c15bd30b0 | 145 | errno_error(fd); |
POTLESS_2 | 0:794c15bd30b0 | 146 | fprintf(fd, "%f\r\n", Val_To_Store); |
POTLESS_2 | 0:794c15bd30b0 | 147 | fclose(fd); |
POTLESS_2 | 0:794c15bd30b0 | 148 | |
POTLESS_2 | 6:8bae97034114 | 149 | DEBUG_U(" \r\n %s sauvegardée = %f\r\n", filename, Val_To_Store); |
POTLESS_2 | 0:794c15bd30b0 | 150 | |
POTLESS_2 | 0:794c15bd30b0 | 151 | } |
POTLESS_2 | 0:794c15bd30b0 | 152 | |
POTLESS_2 | 0:794c15bd30b0 | 153 | float UTILS::Read_A_Val(char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 154 | { |
POTLESS_2 | 0:794c15bd30b0 | 155 | char buffer[10] = {0}; |
POTLESS_2 | 0:794c15bd30b0 | 156 | char c = {0}; |
POTLESS_2 | 0:794c15bd30b0 | 157 | char *token; |
POTLESS_2 | 0:794c15bd30b0 | 158 | int i = 0; |
POTLESS_2 | 0:794c15bd30b0 | 159 | |
POTLESS_2 | 0:794c15bd30b0 | 160 | char filename[20]; |
POTLESS_2 | 2:5af7a1fb1903 | 161 | sprintf(filename, "/Root/%s.txt", File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 162 | |
POTLESS_2 | 6:8bae97034114 | 163 | DEBUG_U(" \n Récupération de %s...\r\n", filename); |
POTLESS_2 | 0:794c15bd30b0 | 164 | |
POTLESS_2 | 0:794c15bd30b0 | 165 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 0:794c15bd30b0 | 166 | errno_error(fd); |
POTLESS_2 | 6:8bae97034114 | 167 | |
POTLESS_2 | 0:794c15bd30b0 | 168 | while ((c != '\n') && (i < 10)) { |
POTLESS_2 | 0:794c15bd30b0 | 169 | c = fgetc(fd); |
POTLESS_2 | 0:794c15bd30b0 | 170 | buffer[i] = c; |
POTLESS_2 | 0:794c15bd30b0 | 171 | i++; |
POTLESS_2 | 0:794c15bd30b0 | 172 | } |
POTLESS_2 | 0:794c15bd30b0 | 173 | |
POTLESS_2 | 0:794c15bd30b0 | 174 | token = strtok(buffer, "\n"); |
POTLESS_2 | 0:794c15bd30b0 | 175 | |
POTLESS_2 | 0:794c15bd30b0 | 176 | float val = atof(token); |
POTLESS_2 | 0:794c15bd30b0 | 177 | |
POTLESS_2 | 6:8bae97034114 | 178 | DEBUG_U(" Valeur Récupérée = %f\r\n", val); |
POTLESS_2 | 0:794c15bd30b0 | 179 | |
POTLESS_2 | 0:794c15bd30b0 | 180 | fclose(fd); |
POTLESS_2 | 0:794c15bd30b0 | 181 | |
POTLESS_2 | 0:794c15bd30b0 | 182 | return val; |
POTLESS_2 | 0:794c15bd30b0 | 183 | } |
POTLESS_2 | 0:794c15bd30b0 | 184 | |
POTLESS_2 | 0:794c15bd30b0 | 185 | |
POTLESS_2 | 6:8bae97034114 | 186 | void UTILS::Write_Flash_File(char* To_Store, char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 187 | { |
POTLESS_2 | 2:5af7a1fb1903 | 188 | char filename[50]; |
POTLESS_2 | 2:5af7a1fb1903 | 189 | sprintf(filename, "/Root/%s", (string)File_Name); |
POTLESS_2 | 6:8bae97034114 | 190 | |
POTLESS_2 | 0:794c15bd30b0 | 191 | FILE* fd = fopen(filename, "a"); |
POTLESS_2 | 6:8bae97034114 | 192 | |
POTLESS_2 | 0:794c15bd30b0 | 193 | errno_error(fd); |
POTLESS_2 | 0:794c15bd30b0 | 194 | fprintf(fd, "%s\r\n", To_Store); |
POTLESS_2 | 0:794c15bd30b0 | 195 | fclose(fd); |
POTLESS_2 | 0:794c15bd30b0 | 196 | |
POTLESS_2 | 6:8bae97034114 | 197 | DEBUG_U(" Enregistrement de %s OK\r\n\r\n", filename); |
POTLESS_2 | 0:794c15bd30b0 | 198 | } |
POTLESS_2 | 0:794c15bd30b0 | 199 | |
POTLESS_2 | 6:8bae97034114 | 200 | /* |
POTLESS_2 | 6:8bae97034114 | 201 | void UTILS::Read_Flash_File(char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 202 | { |
POTLESS_2 | 0:794c15bd30b0 | 203 | char filename[20]; |
POTLESS_2 | 2:5af7a1fb1903 | 204 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 6:8bae97034114 | 205 | |
POTLESS_2 | 0:794c15bd30b0 | 206 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 0:794c15bd30b0 | 207 | errno_error(fd); |
POTLESS_2 | 0:794c15bd30b0 | 208 | |
POTLESS_2 | 6:8bae97034114 | 209 | //printf(" Contenu du fichier :\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 210 | char buff[100] = {0}; |
POTLESS_2 | 6:8bae97034114 | 211 | |
POTLESS_2 | 6:8bae97034114 | 212 | while (!feof(fd)) { |
POTLESS_2 | 0:794c15bd30b0 | 213 | int size = fread(&buff[0], 1, 15, fd); |
POTLESS_2 | 6:8bae97034114 | 214 | fwrite(&buff[0], 1, size, stdout); |
POTLESS_2 | 0:794c15bd30b0 | 215 | } |
POTLESS_2 | 6:8bae97034114 | 216 | //printf("\r\n Fin du fichier.\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 217 | fclose(fd); |
POTLESS_2 | 6:8bae97034114 | 218 | |
POTLESS_2 | 6:8bae97034114 | 219 | } |
POTLESS_2 | 6:8bae97034114 | 220 | */ |
POTLESS_2 | 6:8bae97034114 | 221 | |
POTLESS_2 | 6:8bae97034114 | 222 | void UTILS::Read_Flash_File(char* File_Name) |
POTLESS_2 | 6:8bae97034114 | 223 | { |
POTLESS_2 | 6:8bae97034114 | 224 | char filename[20]; |
POTLESS_2 | 6:8bae97034114 | 225 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 6:8bae97034114 | 226 | |
POTLESS_2 | 6:8bae97034114 | 227 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 6:8bae97034114 | 228 | errno_error(fd); |
POTLESS_2 | 6:8bae97034114 | 229 | char s1[100]; |
POTLESS_2 | 8:23fd400c4edd | 230 | printf("\r\n"); |
POTLESS_2 | 6:8bae97034114 | 231 | printf(" Contenu du fichier :\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 232 | while (!feof(fd)) { |
POTLESS_2 | 6:8bae97034114 | 233 | memset(s1, 0, sizeof(s1)); |
POTLESS_2 | 6:8bae97034114 | 234 | fgets(s1, sizeof(s1), fd); |
POTLESS_2 | 6:8bae97034114 | 235 | printf("%s", s1); |
POTLESS_2 | 6:8bae97034114 | 236 | fflush(stdout); |
POTLESS_2 | 6:8bae97034114 | 237 | } |
POTLESS_2 | 6:8bae97034114 | 238 | fclose(fd); |
POTLESS_2 | 6:8bae97034114 | 239 | printf("\r\n Fin du fichier.\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 240 | } |
POTLESS_2 | 0:794c15bd30b0 | 241 | |
POTLESS_2 | 5:0f3b6e6677ef | 242 | bool UTILS::File_Exist(string File_Name) |
POTLESS_2 | 3:01677db45b2a | 243 | { |
POTLESS_2 | 3:01677db45b2a | 244 | char filename[20]; |
POTLESS_2 | 3:01677db45b2a | 245 | sprintf(filename, "/Root/%s.txt", File_Name); |
POTLESS_2 | 6:8bae97034114 | 246 | |
POTLESS_2 | 3:01677db45b2a | 247 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 3:01677db45b2a | 248 | errno_error(fd); |
POTLESS_2 | 6:8bae97034114 | 249 | |
POTLESS_2 | 6:8bae97034114 | 250 | if (Exist_Val == 0) { |
POTLESS_2 | 6:8bae97034114 | 251 | DEBUG_U(" Le fichier %s n'existe pas....\r\n", filename); |
POTLESS_2 | 4:872676dd87a4 | 252 | fclose(fd); |
POTLESS_2 | 3:01677db45b2a | 253 | return false; |
POTLESS_2 | 5:0f3b6e6677ef | 254 | } |
POTLESS_2 | 6:8bae97034114 | 255 | |
POTLESS_2 | 6:8bae97034114 | 256 | if (Exist_Val == 1) { |
POTLESS_2 | 3:01677db45b2a | 257 | fclose(fd); |
POTLESS_2 | 3:01677db45b2a | 258 | return true; |
POTLESS_2 | 6:8bae97034114 | 259 | } |
POTLESS_2 | 3:01677db45b2a | 260 | } |
POTLESS_2 | 3:01677db45b2a | 261 | |
POTLESS_2 | 6:8bae97034114 | 262 | void UTILS::Delete_Flash_File(char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 263 | { |
POTLESS_2 | 0:794c15bd30b0 | 264 | char filename[20]; |
POTLESS_2 | 6:8bae97034114 | 265 | sprintf(filename, "%s", File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 266 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 267 | error = Root.remove(filename); |
POTLESS_2 | 0:794c15bd30b0 | 268 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 269 | |
POTLESS_2 | 6:8bae97034114 | 270 | DEBUG_U("Fichier %s effacé.\r\n", filename); |
POTLESS_2 | 0:794c15bd30b0 | 271 | } |
POTLESS_2 | 0:794c15bd30b0 | 272 | |
POTLESS_2 | 6:8bae97034114 | 273 | void UTILS::Clean_Flash() |
POTLESS_2 | 6:8bae97034114 | 274 | { |
POTLESS_2 | 6:8bae97034114 | 275 | DEBUG_U("Nettoyage de la Flash.\r\n"); |
POTLESS_2 | 6:8bae97034114 | 276 | float Saved_O2 = UTILS::Read_A_Val("Calibration_O2"); |
POTLESS_2 | 6:8bae97034114 | 277 | int Saved_Motor = (int)UTILS::Read_A_Val("Servo_Poumon"); |
POTLESS_2 | 6:8bae97034114 | 278 | UTILS::UnMount_Flash(); |
POTLESS_2 | 6:8bae97034114 | 279 | UTILS::Format_Flash(); |
POTLESS_2 | 6:8bae97034114 | 280 | UTILS::Mount_Flash(); |
POTLESS_2 | 6:8bae97034114 | 281 | UTILS::Store_A_Val(Saved_O2, "Calibration_O2"); |
POTLESS_2 | 6:8bae97034114 | 282 | UTILS::Store_A_Val(Saved_Motor, "Servo_Poumon"); |
POTLESS_2 | 6:8bae97034114 | 283 | DEBUG_U("Flash nettoyée.\r\n"); |
POTLESS_2 | 6:8bae97034114 | 284 | DEBUG_U("Redémmarage code.\r\n"); |
POTLESS_2 | 6:8bae97034114 | 285 | NVIC_SystemReset(); |
POTLESS_2 | 6:8bae97034114 | 286 | } |
POTLESS_2 | 6:8bae97034114 | 287 | |
POTLESS_2 | 6:8bae97034114 | 288 | void UTILS::Rename_Flash_File(char* Old_File_Name, char* New_File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 289 | { |
POTLESS_2 | 0:794c15bd30b0 | 290 | char Oldfilename[20]; |
POTLESS_2 | 2:5af7a1fb1903 | 291 | sprintf(Oldfilename, "/Root/%s", Old_File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 292 | char Newfilename[20]; |
POTLESS_2 | 2:5af7a1fb1903 | 293 | sprintf(Newfilename, "/Root/%s", New_File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 294 | |
POTLESS_2 | 0:794c15bd30b0 | 295 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 296 | error = Root.rename(Oldfilename, Newfilename); |
POTLESS_2 | 0:794c15bd30b0 | 297 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 298 | |
POTLESS_2 | 6:8bae97034114 | 299 | DEBUG_U("Fichier %s renommé en %s.\r\n", Oldfilename, Newfilename); |
POTLESS_2 | 0:794c15bd30b0 | 300 | } |
POTLESS_2 | 0:794c15bd30b0 | 301 | |
POTLESS_2 | 6:8bae97034114 | 302 | void UTILS::Mount_Flash() |
POTLESS_2 | 0:794c15bd30b0 | 303 | { |
POTLESS_2 | 6:8bae97034114 | 304 | //Montage Flash |
POTLESS_2 | 6:8bae97034114 | 305 | DEBUG_U(" Montage Flash \"/Root\". \r\n\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 306 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 307 | error = Root.mount(&bd); |
POTLESS_2 | 0:794c15bd30b0 | 308 | return_error(error); |
POTLESS_2 | 1:a937433a95c8 | 309 | if (error > 0) { |
POTLESS_2 | 0:794c15bd30b0 | 310 | //On re format s'il n'y a as de file system...normalement une seul fois... |
POTLESS_2 | 6:8bae97034114 | 311 | DEBUG_U("Pas de File system, on format... "); |
POTLESS_2 | 6:8bae97034114 | 312 | Format_Flash(); |
POTLESS_2 | 0:794c15bd30b0 | 313 | } |
POTLESS_2 | 0:794c15bd30b0 | 314 | } |
POTLESS_2 | 0:794c15bd30b0 | 315 | |
POTLESS_2 | 6:8bae97034114 | 316 | void UTILS::UnMount_Flash() |
POTLESS_2 | 0:794c15bd30b0 | 317 | { |
POTLESS_2 | 6:8bae97034114 | 318 | //De Montage Flash |
POTLESS_2 | 6:8bae97034114 | 319 | DEBUG_U(" Demontage Flash \"/Root\". \r\n\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 320 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 321 | error = Root.unmount(); |
POTLESS_2 | 0:794c15bd30b0 | 322 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 323 | } |
POTLESS_2 | 0:794c15bd30b0 | 324 | |
POTLESS_2 | 6:8bae97034114 | 325 | void UTILS::Format_Flash() |
POTLESS_2 | 0:794c15bd30b0 | 326 | { |
POTLESS_2 | 6:8bae97034114 | 327 | //Formatage Flash |
POTLESS_2 | 6:8bae97034114 | 328 | DEBUG_U(" Formatage Flash\r\n\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 329 | int error = 0; |
POTLESS_2 | 4:872676dd87a4 | 330 | error = FATFileSystem::format(&bd); |
POTLESS_2 | 2:5af7a1fb1903 | 331 | return_error(error); |
POTLESS_2 | 2:5af7a1fb1903 | 332 | } |
POTLESS_2 | 2:5af7a1fb1903 | 333 | |
POTLESS_2 | 6:8bae97034114 | 334 | void UTILS::Dir_Flash(char* Dir_Name) |
POTLESS_2 | 2:5af7a1fb1903 | 335 | { |
POTLESS_2 | 2:5af7a1fb1903 | 336 | int error = 0; |
POTLESS_2 | 3:01677db45b2a | 337 | int nb = 0; |
POTLESS_2 | 6:8bae97034114 | 338 | DEBUG_U("\r\n Ouverture du répertoire %s\r\n", Dir_Name); |
POTLESS_2 | 2:5af7a1fb1903 | 339 | char Dirname[20]; |
POTLESS_2 | 2:5af7a1fb1903 | 340 | sprintf(Dirname, "/Root/%s", Dir_Name); |
POTLESS_2 | 6:8bae97034114 | 341 | |
POTLESS_2 | 2:5af7a1fb1903 | 342 | DIR* dir = opendir(Dirname); |
POTLESS_2 | 2:5af7a1fb1903 | 343 | |
POTLESS_2 | 2:5af7a1fb1903 | 344 | struct dirent* de; |
POTLESS_2 | 6:8bae97034114 | 345 | DEBUG_U(" Fichier du répertoire :\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 346 | while((de = readdir(dir)) != NULL) { |
POTLESS_2 | 6:8bae97034114 | 347 | printf(" %s\r\n", &(de->d_name)[0]); |
POTLESS_2 | 6:8bae97034114 | 348 | fflush(stdout); |
POTLESS_2 | 6:8bae97034114 | 349 | nb++; |
POTLESS_2 | 6:8bae97034114 | 350 | } |
POTLESS_2 | 6:8bae97034114 | 351 | DEBUG_U("\r\n Nombre de fichiers = %d\r\n", nb); |
POTLESS_2 | 6:8bae97034114 | 352 | DEBUG_U(" Fermeture du répertoire.\r\n"); |
POTLESS_2 | 6:8bae97034114 | 353 | error = closedir(dir); |
POTLESS_2 | 0:794c15bd30b0 | 354 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 355 | } |
POTLESS_2 | 0:794c15bd30b0 | 356 | |
POTLESS_2 | 3:01677db45b2a | 357 | int UTILS::File_Index() |
POTLESS_2 | 3:01677db45b2a | 358 | { |
POTLESS_2 | 3:01677db45b2a | 359 | int error = 0; |
POTLESS_2 | 3:01677db45b2a | 360 | int nb = 0; |
POTLESS_2 | 6:8bae97034114 | 361 | |
POTLESS_2 | 3:01677db45b2a | 362 | DIR* dir = opendir("/Root/"); |
POTLESS_2 | 3:01677db45b2a | 363 | struct dirent* de; |
POTLESS_2 | 6:8bae97034114 | 364 | while((de = readdir(dir)) != NULL) { |
POTLESS_2 | 6:8bae97034114 | 365 | nb++; |
POTLESS_2 | 3:01677db45b2a | 366 | } |
POTLESS_2 | 3:01677db45b2a | 367 | error = closedir(dir); |
POTLESS_2 | 3:01677db45b2a | 368 | return_error(error); |
POTLESS_2 | 6:8bae97034114 | 369 | |
POTLESS_2 | 3:01677db45b2a | 370 | return nb - 2; |
POTLESS_2 | 3:01677db45b2a | 371 | } |
POTLESS_2 | 3:01677db45b2a | 372 | |
POTLESS_2 | 0:794c15bd30b0 | 373 | //Remapping d'une valeur dans une autre échelle |
POTLESS_2 | 0:794c15bd30b0 | 374 | float UTILS::Remap(float x, float in_min, float in_max, float out_min, float out_max) |
POTLESS_2 | 0:794c15bd30b0 | 375 | { |
POTLESS_2 | 0:794c15bd30b0 | 376 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
POTLESS_2 | 0:794c15bd30b0 | 377 | } |
POTLESS_2 | 0:794c15bd30b0 | 378 | |
POTLESS_2 | 0:794c15bd30b0 | 379 | //Contraint une valeur entre deux limites |
POTLESS_2 | 0:794c15bd30b0 | 380 | float UTILS::constrain(float x, float a, float b) |
POTLESS_2 | 0:794c15bd30b0 | 381 | { |
POTLESS_2 | 0:794c15bd30b0 | 382 | if(x < a) { |
POTLESS_2 | 0:794c15bd30b0 | 383 | return a; |
POTLESS_2 | 0:794c15bd30b0 | 384 | } else if(b < x) { |
POTLESS_2 | 0:794c15bd30b0 | 385 | return b; |
POTLESS_2 | 0:794c15bd30b0 | 386 | } else |
POTLESS_2 | 0:794c15bd30b0 | 387 | return x; |
POTLESS_2 | 6:8bae97034114 | 388 | } |
POTLESS_2 | 6:8bae97034114 | 389 | |
POTLESS_2 | 6:8bae97034114 | 390 | void UTILS::Help() |
POTLESS_2 | 6:8bae97034114 | 391 | { |
POTLESS_2 | 6:8bae97034114 | 392 | printf("\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 393 | printf(" COMMANDES GENERALES\r\n\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 394 | printf(" help = liste des commandes.\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 395 | printf(" start = démmarage des sorties moniteur.\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 396 | printf(" stop = arrêt des sorties moniteur.\r\n"); |
POTLESS_2 | 6:8bae97034114 | 397 | printf(" time X = met la RTC à l'heure, X en UNIX TIME.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 398 | printf(" sleep = mise en veille.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 399 | printf(" reset = reset de la carte.\n\r\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 400 | printf(" COMMANDES MEMOIRE\r\n\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 401 | printf(" rec = démarrage / arrêt enregistrement.\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 402 | printf(" flash_i = informations sur la flash.\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 403 | printf(" clean = nettoyage flash, suppression des fichiers LOG.\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 404 | printf(" dir = liste des fichiers de la flash.\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 405 | printf(" del X = effacer le fichier LOG_X.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 406 | printf(" get X = récupérer le contenu du fichier LOG_X.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 407 | printf(" file_s X = récupérer la taille du fichier LOG_X.\n\r\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 408 | //printf(" file_i X = récupérer les informations sur le fichier LOG_X.\n\r\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 409 | printf(" COMMANDES MOTEURS\r\n\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 410 | printf(" c_pou X = changement consigne volet poumon à X.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 411 | printf(" c_fui X = changement consigne volet fuite à X.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 412 | printf(" calib_p = calibration à 0 du volet poumon.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 413 | printf(" calib_f = calibration à 0 du volet fuite.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 414 | printf(" secu = mise des volets en mode sécu.\n\r\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 415 | printf(" COMMANDES CAPTEURS\r\n\r\n"); |
POTLESS_2 | 8:23fd400c4edd | 416 | printf(" calib_O2 X = calibration des cellules O2 dans l'air avec X itérations.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 417 | printf(" check = sortie des valeurs de calibrations enregistrées.\n\r\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 418 | printf(" Les commandes pour le Mini-r sont à entrer conformément à la doc. Les plus utilisée :\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 419 | printf(" G = calibration du capteur CO2 dans l'air.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 420 | printf(" K 0 = arrêt du capteur CO2.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 421 | printf(" K 1 = capteur CO2 mode streaming.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 422 | printf(" K 2 = capteur CO2 mode spooling.\n\r"); |
POTLESS_2 | 8:23fd400c4edd | 423 | printf(" A X = digi filter X. X égal à 32, 64, 128...\n\r"); |
POTLESS_2 | 6:8bae97034114 | 424 | printf("\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 425 | fflush(stdout); |
POTLESS_2 | 0:794c15bd30b0 | 426 | } |