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