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:
15:a8c19ad9c11d
update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
POTLESS_2 0:794c15bd30b0 1 #ifndef CHANGEME_H_
POTLESS_2 0:794c15bd30b0 2 #define CHANGEME_H_
POTLESS_2 0:794c15bd30b0 3
POTLESS_2 0:794c15bd30b0 4 #include "mbed.h"
POTLESS_2 0:794c15bd30b0 5 #include <string>
POTLESS_2 0:794c15bd30b0 6
POTLESS_2 0:794c15bd30b0 7 #include "FATFileSystem.h"
POTLESS_2 9:fa2818db80cf 8 //#include "SDBlockDevice.h"
POTLESS_2 9:fa2818db80cf 9 #include "SPIFBlockDevice.h"
POTLESS_2 8:23fd400c4edd 10
POTLESS_2 0:794c15bd30b0 11 #include <stdio.h>
POTLESS_2 0:794c15bd30b0 12 #include <errno.h>
POTLESS_2 0:794c15bd30b0 13
POTLESS_2 6:8bae97034114 14 //PIN OUT Flash
POTLESS_2 6:8bae97034114 15 #define Flash_MOSI PA_7
POTLESS_2 6:8bae97034114 16 #define Flash_MISO PA_6
POTLESS_2 6:8bae97034114 17 #define Flash_SCK PA_5
POTLESS_2 6:8bae97034114 18 #define Flash_CS PB_6
POTLESS_2 6:8bae97034114 19
POTLESS_2 11:a41267cffa61 20 //Pin de l'eeprom I2C
POTLESS_2 11:a41267cffa61 21 #define SCL_PIN PB_8
POTLESS_2 11:a41267cffa61 22 #define SDA_PIN PB_9
POTLESS_2 11:a41267cffa61 23
POTLESS_2 11:a41267cffa61 24 //Adresse i2C de l'eeprom
POTLESS_2 11:a41267cffa61 25 #define EEPROM_ADDRESS 0xA0
POTLESS_2 11:a41267cffa61 26
POTLESS_2 11:a41267cffa61 27 #define DEBUG_MODE 1
POTLESS_2 6:8bae97034114 28
POTLESS_2 10:21f3ff5d6a3d 29 #if DEBUG_MODE
POTLESS_2 10:21f3ff5d6a3d 30 #define DEBUG(...) { printf(__VA_ARGS__); fflush(stdout);}
POTLESS_2 6:8bae97034114 31 #else
POTLESS_2 10:21f3ff5d6a3d 32 #define DEBUG(...)
POTLESS_2 6:8bae97034114 33 #endif
POTLESS_2 0:794c15bd30b0 34
POTLESS_2 12:9dd7c462a2c0 35 #define DEEP_DEBUG_MODE 0
POTLESS_2 12:9dd7c462a2c0 36
POTLESS_2 12:9dd7c462a2c0 37 #if DEEP_DEBUG_MODE
POTLESS_2 12:9dd7c462a2c0 38 #define DEEP_DEBUG(...) { printf(__VA_ARGS__); fflush(stdout);}
POTLESS_2 12:9dd7c462a2c0 39 #else
POTLESS_2 12:9dd7c462a2c0 40 #define DEEP_DEBUG(...)
POTLESS_2 12:9dd7c462a2c0 41 #endif
POTLESS_2 12:9dd7c462a2c0 42
POTLESS_2 0:794c15bd30b0 43 /** Utils class.
POTLESS_2 0:794c15bd30b0 44 * Rassemblant des fonctions annexes pour le fonctionnement de l'ARNSRS.
POTLESS_2 0:794c15bd30b0 45 *
POTLESS_2 0:794c15bd30b0 46 * A besoin des libs suivantes :
POTLESS_2 0:794c15bd30b0 47 *
POTLESS_2 0:794c15bd30b0 48 * - FATFileSystem
POTLESS_2 0:794c15bd30b0 49 *
POTLESS_2 6:8bae97034114 50 * - SPIFBlockDevice
POTLESS_2 0:794c15bd30b0 51 *
POTLESS_2 0:794c15bd30b0 52 *
POTLESS_2 0:794c15bd30b0 53 * Constantes de l'application :
POTLESS_2 0:794c15bd30b0 54 *
POTLESS_2 6:8bae97034114 55 * Pin out Flash :
POTLESS_2 6:8bae97034114 56 *
POTLESS_2 6:8bae97034114 57 * - Flash_MOSI PA_7
POTLESS_2 6:8bae97034114 58 *
POTLESS_2 6:8bae97034114 59 * - Flash_MISO PA_6
POTLESS_2 6:8bae97034114 60 *
POTLESS_2 6:8bae97034114 61 * - Flash_SCK PA_5
POTLESS_2 6:8bae97034114 62 *
POTLESS_2 6:8bae97034114 63 * - Flash_CS PB_6
POTLESS_2 6:8bae97034114 64 *
POTLESS_2 6:8bae97034114 65 * Liste des erreurs possibles sur les fonctions Flash :
POTLESS_2 0:794c15bd30b0 66 *
POTLESS_2 6:8bae97034114 67 *
POTLESS_2 6:8bae97034114 68 * (0) no error
POTLESS_2 11:a41267cffa61 69 *
POTLESS_2 6:8bae97034114 70 * (1) A hard error occurred in the low level disk I/O layer
POTLESS_2 6:8bae97034114 71 *
POTLESS_2 11:a41267cffa61 72 * (2) Assertion failed
POTLESS_2 6:8bae97034114 73 *
POTLESS_2 11:a41267cffa61 74 * (3) The physical drive cannot work
POTLESS_2 6:8bae97034114 75 *
POTLESS_2 6:8bae97034114 76 * (4) Could not find the file
POTLESS_2 6:8bae97034114 77 *
POTLESS_2 6:8bae97034114 78 * (5) Could not find the path
POTLESS_2 0:794c15bd30b0 79 *
POTLESS_2 6:8bae97034114 80 * (6) The path name format is invalid
POTLESS_2 6:8bae97034114 81 *
POTLESS_2 6:8bae97034114 82 * (7) Access denied due to prohibited access or directory full, Permission denied
POTLESS_2 6:8bae97034114 83 *
POTLESS_2 6:8bae97034114 84 * (8) Access denied due to prohibited access, File exists
POTLESS_2 6:8bae97034114 85 *
POTLESS_2 11:a41267cffa61 86 * (9) The file/directory object is invalid, Bad address
POTLESS_2 6:8bae97034114 87 *
POTLESS_2 6:8bae97034114 88 * (10) The physical drive is write protected
POTLESS_2 6:8bae97034114 89 *
POTLESS_2 6:8bae97034114 90 * (11) The logical drive number is invalid
POTLESS_2 6:8bae97034114 91 *
POTLESS_2 6:8bae97034114 92 * (12) The volume has no work area, No such device or address
POTLESS_2 0:794c15bd30b0 93 *
POTLESS_2 6:8bae97034114 94 * (13) There is no valid FAT volume, No such file or directory
POTLESS_2 6:8bae97034114 95 *
POTLESS_2 6:8bae97034114 96 * (14) The f_mkfs() aborted due to any parameter error
POTLESS_2 6:8bae97034114 97 *
POTLESS_2 6:8bae97034114 98 * (15) Could not get a grant to access the volume within defined period, Bad file number
POTLESS_2 0:794c15bd30b0 99 *
POTLESS_2 6:8bae97034114 100 * (16) The operation is rejected according to the file sharing policy, Permission denied
POTLESS_2 6:8bae97034114 101 *
POTLESS_2 6:8bae97034114 102 * (17) LFN working buffer could not be allocated, Not enough space
POTLESS_2 0:794c15bd30b0 103 *
POTLESS_2 6:8bae97034114 104 * (18) Number of open files > _FS_LOCK, Too many open files in system
POTLESS_2 6:8bae97034114 105 *
POTLESS_2 11:a41267cffa61 106 * (19) Given parameter is invalid, Exec format error
POTLESS_2 0:794c15bd30b0 107 */
POTLESS_2 0:794c15bd30b0 108
POTLESS_2 0:794c15bd30b0 109 class UTILS
POTLESS_2 0:794c15bd30b0 110 {
POTLESS_2 0:794c15bd30b0 111
POTLESS_2 0:794c15bd30b0 112 public:
POTLESS_2 0:794c15bd30b0 113
POTLESS_2 0:794c15bd30b0 114 /**Remapper une valeur dans une autre échelle.
POTLESS_2 0:794c15bd30b0 115 * @param float Valeur à remapper
POTLESS_2 0:794c15bd30b0 116 * @param float Minimum de l'échelle de la valeur
POTLESS_2 0:794c15bd30b0 117 * @param float Maximum de l'échelle de la valeur
POTLESS_2 0:794c15bd30b0 118 * @param float Minimum de la nouvelle échelle
POTLESS_2 0:794c15bd30b0 119 * @param float Maximum de de la nouvelle échelle
POTLESS_2 0:794c15bd30b0 120 */
POTLESS_2 0:794c15bd30b0 121 static float Remap(float x, float in_min, float in_max, float out_min, float out_max);
POTLESS_2 0:794c15bd30b0 122
POTLESS_2 0:794c15bd30b0 123 /**Contraint une valeur entre deux limites.
POTLESS_2 0:794c15bd30b0 124 * @param float Valeur à contraindre
POTLESS_2 0:794c15bd30b0 125 * @param float Minimum de la valeur
POTLESS_2 0:794c15bd30b0 126 * @param float Maximum de la valeur
POTLESS_2 0:794c15bd30b0 127 */
POTLESS_2 0:794c15bd30b0 128 static float constrain(float x, float a, float b);
POTLESS_2 0:794c15bd30b0 129
POTLESS_2 8:23fd400c4edd 130 /**Fonction d'affichage des infos de la Flash.
POTLESS_2 8:23fd400c4edd 131 */
POTLESS_2 8:23fd400c4edd 132 static void Flash_Infos();
POTLESS_2 11:a41267cffa61 133
POTLESS_2 6:8bae97034114 134 /**Fonction de stockage valeur sur la Flash.
POTLESS_2 0:794c15bd30b0 135 * @param float Val_To_Store, la valeur à stocker
POTLESS_2 0:794c15bd30b0 136 * @param char* Nom du fichier ou stocker cette valeur
POTLESS_2 0:794c15bd30b0 137 */
POTLESS_2 0:794c15bd30b0 138 static void Store_A_Val(float Val_To_Store, char* File_Name);
POTLESS_2 0:794c15bd30b0 139
POTLESS_2 6:8bae97034114 140 /**Fonction de récupération d'une valeur stockée sur la Flash.
POTLESS_2 0:794c15bd30b0 141 * @param char* Nom du fichier ou stocker cette valeur
POTLESS_2 0:794c15bd30b0 142 * @returns
POTLESS_2 0:794c15bd30b0 143 * valeur de calibration des capteurs O2
POTLESS_2 0:794c15bd30b0 144 */
POTLESS_2 0:794c15bd30b0 145 static float Read_A_Val(char* File_Name);
POTLESS_2 0:794c15bd30b0 146
POTLESS_2 6:8bae97034114 147 /**Fonction d'enregistrement d'une chaine de charatères sur la Flash.
POTLESS_2 0:794c15bd30b0 148 * @param char* To_Store, chaine de charactères
POTLESS_2 0:794c15bd30b0 149 * @param char* Nom du fichier, s'il existe il est ouvert, sinon il est créé
POTLESS_2 0:794c15bd30b0 150 */
POTLESS_2 6:8bae97034114 151 static void Write_Flash_File(char* To_Store, char* File_Name);
POTLESS_2 0:794c15bd30b0 152
POTLESS_2 6:8bae97034114 153 /**Fonction de lecture d'un fichier sur la Flash.
POTLESS_2 0:794c15bd30b0 154 * @param char* Nom du fichier
POTLESS_2 0:794c15bd30b0 155 */
POTLESS_2 6:8bae97034114 156 static void Read_Flash_File(char* File_Name);
POTLESS_2 11:a41267cffa61 157
POTLESS_2 8:23fd400c4edd 158 /**Fonction de renvoie de la taille d'un fichier.
POTLESS_2 8:23fd400c4edd 159 * @param char* Nom du fichier
POTLESS_2 8:23fd400c4edd 160 */
POTLESS_2 8:23fd400c4edd 161 static void Get_File_Size(char* File_Name);
POTLESS_2 11:a41267cffa61 162
POTLESS_2 6:8bae97034114 163 /**Fonction d'éffaçage d'un fichier sur la Flash.
POTLESS_2 8:23fd400c4edd 164 * @param char* Nom du fichier à effacer
POTLESS_2 0:794c15bd30b0 165 */
POTLESS_2 6:8bae97034114 166 static void Delete_Flash_File(char* File_Name);
POTLESS_2 0:794c15bd30b0 167
POTLESS_2 6:8bae97034114 168 /**Fonction nettoyage de la Flash.
POTLESS_2 6:8bae97034114 169 */
POTLESS_2 6:8bae97034114 170 static void Clean_Flash();
POTLESS_2 11:a41267cffa61 171
POTLESS_2 6:8bae97034114 172 /**Fonction d'éffaçage d'un fichier sur la Flash.
POTLESS_2 0:794c15bd30b0 173 * @param char* Nom du fichier à effacer
POTLESS_2 0:794c15bd30b0 174 * @param char* Nouveau Nom du fichier
POTLESS_2 0:794c15bd30b0 175 */
POTLESS_2 6:8bae97034114 176 static void Rename_Flash_File(char* Old_File_Name, char* New_File_Name);
POTLESS_2 0:794c15bd30b0 177
POTLESS_2 6:8bae97034114 178 /**Fonction montage de la Flash.
POTLESS_2 0:794c15bd30b0 179 */
POTLESS_2 6:8bae97034114 180 static void Mount_Flash();
POTLESS_2 0:794c15bd30b0 181
POTLESS_2 6:8bae97034114 182 /**Fonction demontage de la Flash.
POTLESS_2 0:794c15bd30b0 183 */
POTLESS_2 6:8bae97034114 184 static void UnMount_Flash();
POTLESS_2 0:794c15bd30b0 185
POTLESS_2 6:8bae97034114 186 /**Fonction formatage de la Flash.
POTLESS_2 0:794c15bd30b0 187 */
POTLESS_2 6:8bae97034114 188 static void Format_Flash();
POTLESS_2 11:a41267cffa61 189
POTLESS_2 2:5af7a1fb1903 190 /**Fonction DIR.
POTLESS_2 2:5af7a1fb1903 191 * @param char* Nom du répertoire
POTLESS_2 2:5af7a1fb1903 192 */
POTLESS_2 6:8bae97034114 193 static void Dir_Flash(char* Dir_Name = "");
POTLESS_2 11:a41267cffa61 194
POTLESS_2 3:01677db45b2a 195 /**Fonction de numérotage des fichiers log.
POTLESS_2 3:01677db45b2a 196 * @returns
POTLESS_2 3:01677db45b2a 197 * Index du nouveau fichier log
POTLESS_2 3:01677db45b2a 198 */
POTLESS_2 3:01677db45b2a 199 static int File_Index();
POTLESS_2 11:a41267cffa61 200
POTLESS_2 3:01677db45b2a 201 /**Fonction de test si un fichier existe.
POTLESS_2 3:01677db45b2a 202 * @param char* Nom du fichier
POTLESS_2 3:01677db45b2a 203 * @returns
POTLESS_2 3:01677db45b2a 204 * true si le fichier existe, false s'il n'existe pas
POTLESS_2 3:01677db45b2a 205 */
POTLESS_2 5:0f3b6e6677ef 206 static bool File_Exist(string File_Name);
POTLESS_2 11:a41267cffa61 207
POTLESS_2 6:8bae97034114 208 /**Fonction d'affichage du menu d'aide.
POTLESS_2 6:8bae97034114 209 */
POTLESS_2 6:8bae97034114 210 static void Help();
POTLESS_2 3:01677db45b2a 211
POTLESS_2 11:a41267cffa61 212 /**Fonction d'écriture sur l'eeprom.
POTLESS_2 11:a41267cffa61 213 * @param char data à stocker
POTLESS_2 11:a41267cffa61 214 * @param int eeadress de stockage de la data dans l'eeprom
POTLESS_2 11:a41267cffa61 215 * @param int adress adresse I2C de l'eeprom
POTLESS_2 11:a41267cffa61 216 */
POTLESS_2 11:a41267cffa61 217 static void write_EEPROM(char *data, unsigned int eeaddress, int address = EEPROM_ADDRESS);
POTLESS_2 11:a41267cffa61 218
POTLESS_2 11:a41267cffa61 219 /**Fonction de lecture d'un int dans l'eeprom.
POTLESS_2 11:a41267cffa61 220 * @param int eeadress de stockage de la data dans l'eeprom
POTLESS_2 11:a41267cffa61 221 * @param int adress adresse I2C de l'eeprom
POTLESS_2 11:a41267cffa61 222 * @returns
POTLESS_2 11:a41267cffa61 223 * valeur int stockée à cette adresse
POTLESS_2 11:a41267cffa61 224 */
POTLESS_2 11:a41267cffa61 225 static int read_I_EEPROM(unsigned int eeaddress, int address = EEPROM_ADDRESS);
POTLESS_2 11:a41267cffa61 226
POTLESS_2 11:a41267cffa61 227 /**Fonction de lecture d'un float dans l'eeprom.
POTLESS_2 11:a41267cffa61 228 * @param int eeadress de stockage de la data dans l'eeprom
POTLESS_2 11:a41267cffa61 229 * @param int adress adresse I2C de l'eeprom
POTLESS_2 11:a41267cffa61 230 * @returns
POTLESS_2 11:a41267cffa61 231 * valeur float stockée à cette adresse
POTLESS_2 11:a41267cffa61 232 */
POTLESS_2 11:a41267cffa61 233 static float read_F_EEPROM(unsigned int eeaddress, int address = EEPROM_ADDRESS);
POTLESS_2 11:a41267cffa61 234
POTLESS_2 12:9dd7c462a2c0 235 /**Fonction de lecture d'un char dans l'eeprom.
POTLESS_2 12:9dd7c462a2c0 236 * @param char data ou vaêtre stocké le résultat
POTLESS_2 12:9dd7c462a2c0 237 * @param int eeadress de stockage de la data dans l'eeprom
POTLESS_2 12:9dd7c462a2c0 238 * @param int adress adresse I2C de l'eeprom
POTLESS_2 12:9dd7c462a2c0 239 * @returns
POTLESS_2 12:9dd7c462a2c0 240 * char stockée à cette adresse
POTLESS_2 12:9dd7c462a2c0 241 */
POTLESS_2 12:9dd7c462a2c0 242 static void read_C_EEPROM(char *data, unsigned int eeaddress , int address = EEPROM_ADDRESS);
POTLESS_2 12:9dd7c462a2c0 243
POTLESS_2 12:9dd7c462a2c0 244 /**Fonction de lecture d'un char dans l'eeprom.
POTLESS_2 12:9dd7c462a2c0 245 * @param int eeadress de stockage de la data dans l'eeprom
POTLESS_2 12:9dd7c462a2c0 246 * @param int adress adresse I2C de l'eeprom
POTLESS_2 12:9dd7c462a2c0 247 * @returns
POTLESS_2 12:9dd7c462a2c0 248 * char stockée à cette adresse
POTLESS_2 12:9dd7c462a2c0 249 */
POTLESS_2 12:9dd7c462a2c0 250 static char* read_EEPROM(unsigned int eeaddress , int address = EEPROM_ADDRESS);
POTLESS_2 12:9dd7c462a2c0 251
POTLESS_2 11:a41267cffa61 252 /**Fonction de nettoyage d'une ligne de l'eeprom.
POTLESS_2 11:a41267cffa61 253 * @param int eeadress de la ligne a effacer
POTLESS_2 11:a41267cffa61 254 * @param int adress adresse I2C de l'eeprom
POTLESS_2 11:a41267cffa61 255 */
POTLESS_2 11:a41267cffa61 256 static void clean_line_EEPROM(unsigned int eeaddress, int address = EEPROM_ADDRESS);
POTLESS_2 11:a41267cffa61 257
POTLESS_2 11:a41267cffa61 258 /**Fonction de nettoyage l'eeprom.
POTLESS_2 11:a41267cffa61 259 * @param int adress adresse I2C de l'eeprom
POTLESS_2 11:a41267cffa61 260 */
POTLESS_2 11:a41267cffa61 261 static void clean_EEPROM(int address = EEPROM_ADDRESS);
POTLESS_2 11:a41267cffa61 262
POTLESS_2 0:794c15bd30b0 263 private:
POTLESS_2 0:794c15bd30b0 264 //Rien...
POTLESS_2 0:794c15bd30b0 265 };
POTLESS_2 0:794c15bd30b0 266 #endif