SOP 001-Programmation » Historique » Version 81
Patrice Nadeau, 2022-11-13 10:56
| 1 | 17 | Patrice Nadeau | # SOP 001-Programmation |
|---|---|---|---|
| 2 | 1 | Patrice Nadeau | |
| 3 | Mes standards autant au niveau du style que de la documentation. |
||
| 4 | |||
| 5 | 11 | Patrice Nadeau | La plate-forme (logiciel et matériel) est documenté dans le [[SOP_002-Environnement_informatique]]. |
| 6 | 1 | Patrice Nadeau | |
| 7 | |||
| 8 | --- |
||
| 9 | |||
| 10 | {{toc}} |
||
| 11 | |||
| 12 | 17 | Patrice Nadeau | ## Diagrammes |
| 13 | 1 | Patrice Nadeau | |
| 14 | Les représentations des différents processus d’un programme ou d’un circuit. |
||
| 15 | |||
| 16 | Les diagrammes DOIVENT être faits avec le logiciel Dia. |
||
| 17 | Ils PEUVENT être exportés en d’autre format. |
||
| 18 | |||
| 19 | 17 | Patrice Nadeau | ### LibreOffice Draw |
| 20 | 14 | Patrice Nadeau | |
| 21 | Icônes : |
||
| 22 | 17 | Patrice Nadeau | |
| 23 | 15 | Patrice Nadeau | * Cisco : http://www.cisco.com/web/about/ac50/ac47/3015_jpeg.zip |
| 24 | 16 | Patrice Nadeau | * http://www.vrt.com.au/downloads/vrt-network-equipment ou http://extensions.libreoffice.org/extension-center/vrt-network-equipment/ |
| 25 | 14 | Patrice Nadeau | |
| 26 | 17 | Patrice Nadeau | ## Système de gestion de version |
| 27 | 1 | Patrice Nadeau | |
| 28 | 42 | Patrice Nadeau | Le logiciel [Git](http://www.git-scm.com/) DOIT être utilisé. |
| 29 | 1 | Patrice Nadeau | |
| 30 | 42 | Patrice Nadeau | La version DOIT être en format: *majeur*.*mineur*.*revision*. |
| 31 | Les nombres *majeur*, *mineur* NE DOIVENT PAS contenir de zéro non significatif et DEVRAIT se limiter à deux chiffres. |
||
| 32 | 1 | Patrice Nadeau | |
| 33 | Ex. |
||
| 34 | > Version 1.2.06 |
||
| 35 | |||
| 36 | 42 | Patrice Nadeau | Les modifications DOIVENT se faire avec **git commit**, de la manière suivante : |
| 37 | 17 | Patrice Nadeau | |
| 38 | 1 | Patrice Nadeau | * nom du fichier modifié, |
| 39 | * 1 espace, |
||
| 40 | * nom de l’item modifié entre parenthèses, |
||
| 41 | * un deux- points (<notextile>:</notextile>) sans espace avec l’item précédent, |
||
| 42 | * 1 espace, |
||
| 43 | * le texte du changement en anglais, commençant par une majuscule, au présent, |
||
| 44 | * un point (.) |
||
| 45 | |||
| 46 | Ex. : |
||
| 47 | > Modification ajouté manuellement |
||
| 48 | 40 | Patrice Nadeau | |
| 49 | |||
| 50 | git commit -m "usart.c (usart_Init): Add a new variable ctr." |
||
| 51 | |||
| 52 | 1 | Patrice Nadeau | > Modification par un éditeur texte |
| 53 | |||
| 54 | 40 | Patrice Nadeau | git commit |
| 55 | |||
| 56 | 17 | Patrice Nadeau | Si les commit sont fait sans l’option **-m**, chaque fichier DOIT être séparé par une ligne vide. |
| 57 | 1 | Patrice Nadeau | |
| 58 | 17 | Patrice Nadeau | ## Code source |
| 59 | 1 | Patrice Nadeau | |
| 60 | Les différents type de langage et de script décrit dans ce SOP. |
||
| 61 | |||
| 62 | 17 | Patrice Nadeau | ### Généralités |
| 63 | 1 | Patrice Nadeau | |
| 64 | 17 | Patrice Nadeau | #### Langue |
| 65 | 1 | Patrice Nadeau | |
| 66 | La langue (macros, variables, fonctions, commentaires, etc...) DOIT être l’anglais. |
||
| 67 | |||
| 68 | 17 | Patrice Nadeau | #### Commentaires |
| 69 | 1 | Patrice Nadeau | |
| 70 | Les commentaires DOIVENT être : |
||
| 71 | 17 | Patrice Nadeau | |
| 72 | 1 | Patrice Nadeau | * sur la ligne précédent l’item à documenter |
| 73 | * en minuscules et commencer par une majuscule |
||
| 74 | |||
| 75 | 17 | Patrice Nadeau | |
| 76 | 1 | Patrice Nadeau | #### Nombre magique |
| 77 | 17 | Patrice Nadeau | |
| 78 | 40 | Patrice Nadeau | L’utilisation de [nombre magique](:http://en.wikipedia.org/wiki/Magic_number_%28programming%29#Unnamed_numerical_constants) ne DOIT PAS être utilisé directement dans le code. |
| 79 | 1 | Patrice Nadeau | Il DOIVENT être définis dans une macro ou une variable globale. |
| 80 | |||
| 81 | 17 | Patrice Nadeau | ## C |
| 82 | 1 | Patrice Nadeau | |
| 83 | Le langage C, version C99 (ISO/IEC 9899:1999) utilisé avec le compilateur GCC. |
||
| 84 | |||
| 85 | 17 | Patrice Nadeau | ### Commentaires |
| 86 | 1 | Patrice Nadeau | |
| 87 | Les commentaires ne devant pas être inclus dans une documentation, DOIVENT être de style « C » : |
||
| 88 | |||
| 89 | 65 | Patrice Nadeau | ``` c |
| 90 | /* Une seule ligne... */ |
||
| 91 | 1 | Patrice Nadeau | |
| 92 | 65 | Patrice Nadeau | ... |
| 93 | 17 | Patrice Nadeau | |
| 94 | 65 | Patrice Nadeau | /* |
| 95 | * Sur |
||
| 96 | * plusieurs |
||
| 97 | * lignes |
||
| 98 | */ |
||
| 99 | ``` |
||
| 100 | 1 | Patrice Nadeau | |
| 101 | 17 | Patrice Nadeau | ### Doxygen |
| 102 | 1 | Patrice Nadeau | |
| 103 | 17 | Patrice Nadeau | Chaque item DOIT être documentés de manière à générer une documentation avec le logiciel [Doxygen](http://www.stack.nl/~dimitri/doxygen/index.html). |
| 104 | 1 | Patrice Nadeau | |
| 105 | Seulement les items définis dans les fichiers d’en-tête sont documentés par défaut. |
||
| 106 | Un commentaire Doxygen commence par *<notextile> /** </notextile>* , le compilateur le comprenant comme un commentaire ordinaire. |
||
| 107 | |||
| 108 | Les règles typographiques du [[SOP_000-Documentation]] s’appliquent : |
||
| 109 | 17 | Patrice Nadeau | |
| 110 | 44 | Patrice Nadeau | * Gras (**@b**) : Items devant être inscrit tel quel. |
| 111 | * Italique & emphase (**@e**) : Items à remplacer par un choix ou nécessitant une attention particulière. |
||
| 112 | 1 | Patrice Nadeau | |
| 113 | Les items DOIVENT être inscrit dans cet ordre : |
||
| 114 | 6 | Patrice Nadeau | |
| 115 | 55 | Patrice Nadeau | ``` c |
| 116 | /** |
||
| 117 | * @brief Short description |
||
| 118 | * @param[in,out] var Description. @n Possible values : |
||
| 119 | * − @b value1 |
||
| 120 | * − @b value2 |
||
| 121 | * @return |
||
| 122 | * @retval @b value Description |
||
| 123 | 1 | Patrice Nadeau | * @par Example : |
| 124 | 55 | Patrice Nadeau | * Example Title |
| 125 | 76 | Patrice Nadeau | * @code |
| 126 | 55 | Patrice Nadeau | * ... |
| 127 | * @endcode |
||
| 128 | * @pre Requirements |
||
| 129 | * @post Changes after the call to this function |
||
| 130 | * @see See also ... |
||
| 131 | * @note |
||
| 132 | * @warning |
||
| 133 | * @bug |
||
| 134 | * @todo |
||
| 135 | */ |
||
| 136 | ``` |
||
| 137 | 1 | Patrice Nadeau | |
| 138 | 45 | Patrice Nadeau | Des **@todo**, **@warning** et **@bug** supplémentaires PEUVENT être ajoutés dans le code. |
| 139 | L’item **@brief** DOIT toujours exister. |
||
| 140 | 1 | Patrice Nadeau | |
| 141 | 17 | Patrice Nadeau | ### Code |
| 142 | 1 | Patrice Nadeau | |
| 143 | 77 | Patrice Nadeau | Le code est dans le style K&R |
| 144 | 17 | Patrice Nadeau | |
| 145 | 1 | Patrice Nadeau | * Le « tab » DOIT être équivalent à 4 espaces. |
| 146 | * Le « backslah » DOIT être utilisé pour les lignes de plus de 80 caractères. |
||
| 147 | * Une instruction par ligne. |
||
| 148 | 46 | Patrice Nadeau | * Un espace avant et après un opérateur sauf pour les opérateurs « [unary](http://en.wikipedia.org/wiki/Unary_operation). |
| 149 | 25 | Patrice Nadeau | |
| 150 | 56 | Patrice Nadeau | ``` c |
| 151 | int fonction (void) |
||
| 152 | { |
||
| 153 | int x; |
||
| 154 | /* the comment goes here, before the loop */ |
||
| 155 | if (var != 1) { |
||
| 156 | x = x + 1; |
||
| 157 | y++; |
||
| 158 | printf("This is a long\ |
||
| 159 | line that should be splitted"); |
||
| 160 | } else { |
||
| 161 | /** @warning this is a Doxygen warning */ |
||
| 162 | x--; |
||
| 163 | } |
||
| 164 | return(0); |
||
| 165 | } |
||
| 166 | ``` |
||
| 167 | 17 | Patrice Nadeau | |
| 168 | 1 | Patrice Nadeau | #### Fichier entête |
| 169 | 17 | Patrice Nadeau | |
| 170 | 1 | Patrice Nadeau | Avertissement |
| 171 | 46 | Patrice Nadeau | >Le gabarit **template.h** DOIT être utilisé. |
| 172 | 1 | Patrice Nadeau | |
| 173 | 25 | Patrice Nadeau | Les fichiers « header » DOIVENT contenir les déclarations des fonctions, macros et la partie « mainpage » de Doxygen. |
| 174 | 1 | Patrice Nadeau | |
| 175 | Le nom du fichier DOIT être composé de la manière suivante : |
||
| 176 | |||
| 177 | 17 | Patrice Nadeau | * en minuscule |
| 178 | 1 | Patrice Nadeau | * 8 caractères maximum |
| 179 | 47 | Patrice Nadeau | * l’extension DOIT être **.h** |
| 180 | 1 | Patrice Nadeau | |
| 181 | Une définition macro DOIT être faite pour éviter de ré-inclure le fichier. |
||
| 182 | La macro DOIT être dans le format *_fichier_h* |
||
| 183 | |||
| 184 | 25 | Patrice Nadeau | ``` c |
| 185 | 77 | Patrice Nadeau | |
| 186 | 57 | Patrice Nadeau | #ifndef _usart_h |
| 187 | #define _usart_h |
||
| 188 | ... |
||
| 189 | 58 | Patrice Nadeau | |
| 190 | 57 | Patrice Nadeau | #endif /*_usart.h*/ |
| 191 | ``` |
||
| 192 | 25 | Patrice Nadeau | |
| 193 | 1 | Patrice Nadeau | #### Fichier source |
| 194 | 17 | Patrice Nadeau | |
| 195 | 1 | Patrice Nadeau | Le nom du fichier DOIT être composé de la manière suivante : |
| 196 | 25 | Patrice Nadeau | |
| 197 | 1 | Patrice Nadeau | * en minuscule |
| 198 | * 8 caractères maximum |
||
| 199 | 60 | Patrice Nadeau | * l’extension DOIT être **.c** |
| 200 | 1 | Patrice Nadeau | |
| 201 | 17 | Patrice Nadeau | #### Librairies |
| 202 | 1 | Patrice Nadeau | |
| 203 | Fichiers comprenant plusieurs déclarations et définitions reliés entre eux. |
||
| 204 | |||
| 205 | * Le nom DOIT respecter les standards ([[SOP_001-Programmation#Fichiers-Entêtes|1]] & [[SOP_001-Programmation#Fichiers-Sources|2]]) et être significatifs. |
||
| 206 | * Un fichier d’entête DOIT toujours exister. |
||
| 207 | * Les items sont précédés du nom de la librairie (minuscule) et séparés par un « underscore » (_). |
||
| 208 | |||
| 209 | L’utilisation de macros DOIT être utilisé au lieu de constates globales. |
||
| 210 | Il NE DEVRAIT PAS exister de de variables globales. |
||
| 211 | |||
| 212 | #### Déclarations locales |
||
| 213 | 17 | Patrice Nadeau | |
| 214 | 1 | Patrice Nadeau | Une déclaration n’ayant qu’une visibilité locale DOIT être précédé d’un « underscore » (_) et être de classe *static*. |
| 215 | |||
| 216 | 59 | Patrice Nadeau | ``` c |
| 217 | 58 | Patrice Nadeau | /** |
| 218 | * @brief Local function |
||
| 219 | **/ |
||
| 220 | static void _LocalFunc(void) |
||
| 221 | { |
||
| 222 | ... |
||
| 223 | return; |
||
| 224 | } |
||
| 225 | 1 | Patrice Nadeau | ``` |
| 226 | |||
| 227 | 17 | Patrice Nadeau | #### Items désuets |
| 228 | 1 | Patrice Nadeau | |
| 229 | Les déclarations ne devant plus être utilisés, DOIVENT générer un message lors de la compilation (*-Wall*) si un appel est effectué. |
||
| 230 | 48 | Patrice Nadeau | |
| 231 | 1 | Patrice Nadeau | L’attribut **__attribute\_\_((deprecated))** DOIT être ajouté à la déclaration. |
| 232 | La documentation DOIT indiquer les substituts à utiliser. |
||
| 233 | 25 | Patrice Nadeau | |
| 234 | 65 | Patrice Nadeau | ``` c |
| 235 | 58 | Patrice Nadeau | /** |
| 236 | * @brief OldFunction |
||
| 237 | * @detail will generate a warning if used |
||
| 238 | * @see @b NewFunction |
||
| 239 | */ |
||
| 240 | int OldFunction(void) __attribute__((deprecated)); |
||
| 241 | ``` |
||
| 242 | 1 | Patrice Nadeau | |
| 243 | #### Constantes |
||
| 244 | |||
| 245 | 29 | Patrice Nadeau | La déclaration DOIT inclure aussi la définition. |
| 246 | 1 | Patrice Nadeau | |
| 247 | 29 | Patrice Nadeau | Utilisé au lieu d’une macro quand le type ou la visibilité de la variable doit être définis. |
| 248 | 26 | Patrice Nadeau | |
| 249 | * En majuscule |
||
| 250 | * Séparé par un «underscore» (_) si contient plusieurs mots |
||
| 251 | * De classe _static_ ou _extern_ selon le besoin |
||
| 252 | 1 | Patrice Nadeau | |
| 253 | 26 | Patrice Nadeau | Ex. : |
| 254 | |||
| 255 | 65 | Patrice Nadeau | ``` c |
| 256 | 58 | Patrice Nadeau | /** |
| 257 | * @name List of constants |
||
| 258 | * @{ |
||
| 259 | */ |
||
| 260 | 26 | Patrice Nadeau | |
| 261 | 58 | Patrice Nadeau | /** |
| 262 | * @brief Local const |
||
| 263 | */ |
||
| 264 | static int _PI = 3.15; |
||
| 265 | /** |
||
| 266 | * @brief The initialization string of the project |
||
| 267 | */ |
||
| 268 | static const char INIT_STR[6] = {'P', 'O', 'W', 'E', 'R'}; |
||
| 269 | /** |
||
| 270 | * @brief Global const in the random library |
||
| 271 | */ |
||
| 272 | extern int random_MAX = 25; |
||
| 273 | 30 | Patrice Nadeau | |
| 274 | 58 | Patrice Nadeau | /** |
| 275 | * @} |
||
| 276 | */ |
||
| 277 | ``` |
||
| 278 | 1 | Patrice Nadeau | |
| 279 | 30 | Patrice Nadeau | #### Typedef |
| 280 | |||
| 281 | Format : |
||
| 282 | |||
| 283 | 66 | Patrice Nadeau | * En minuscule, suivie de **_t** |
| 284 | 31 | Patrice Nadeau | |
| 285 | Définition de typedef |
||
| 286 | |||
| 287 | 65 | Patrice Nadeau | ``` c |
| 288 | 31 | Patrice Nadeau | /** Unsigned integer 8 bits */ |
| 289 | typedef unsigned int new_t |
||
| 290 | /** Type of structure in the ds1305 library */ |
||
| 291 | typedef struct { |
||
| 292 | /** @brief last two digits : ≥ 00, ≤ 99 */ |
||
| 293 | uint8_t year; |
||
| 294 | /** @brief 01 - 12 */ |
||
| 295 | uint8_t month; |
||
| 296 | /** @brief 01 - 31 */ |
||
| 297 | 30 | Patrice Nadeau | uint8_t date; |
| 298 | 1 | Patrice Nadeau | /** @brief 1 - 7 */ |
| 299 | uint8_t day; |
||
| 300 | /** @brief 00 - 23 */ |
||
| 301 | uint8_t hours; |
||
| 302 | 49 | Patrice Nadeau | /** @brief 00 - 59 */ |
| 303 | uint8_t minutes; |
||
| 304 | 1 | Patrice Nadeau | /** @brief 00 - 59 */ |
| 305 | uint8_t seconds; |
||
| 306 | } ds1305_time_t; |
||
| 307 | 65 | Patrice Nadeau | ``` |
| 308 | 1 | Patrice Nadeau | |
| 309 | #### Variables |
||
| 310 | 40 | Patrice Nadeau | |
| 311 | Format : |
||
| 312 | |||
| 313 | * En minuscule. |
||
| 314 | 1 | Patrice Nadeau | * Séparé par un « underscore » (_) si contient plusieurs mots. |
| 315 | 40 | Patrice Nadeau | |
| 316 | 1 | Patrice Nadeau | Définition de variables |
| 317 | |||
| 318 | 65 | Patrice Nadeau | ``` c |
| 319 | 1 | Patrice Nadeau | /** @brief Local variable */ |
| 320 | int _ctr; |
||
| 321 | /** @brief Global variable from the random librairy */ |
||
| 322 | int random_ctr; |
||
| 323 | 65 | Patrice Nadeau | ``` |
| 324 | 40 | Patrice Nadeau | |
| 325 | #### Structures |
||
| 326 | |||
| 327 | Format |
||
| 328 | * En minuscule, séparé par des «underscores» si nécessaire. |
||
| 329 | |||
| 330 | Définition de structures |
||
| 331 | |||
| 332 | 65 | Patrice Nadeau | ``` c |
| 333 | 71 | Patrice Nadeau | /** |
| 334 | * @brief Structure for a local menu |
||
| 335 | * @see MenuSelect |
||
| 336 | */ |
||
| 337 | struct menu { |
||
| 338 | /** @brief Character used for the item */ |
||
| 339 | char choice; |
||
| 340 | /** @brief Description of the item */ |
||
| 341 | char *item; |
||
| 342 | }; |
||
| 343 | 65 | Patrice Nadeau | ``` |
| 344 | 5 | Patrice Nadeau | |
| 345 | 1 | Patrice Nadeau | #### Fonctions |
| 346 | |||
| 347 | Le nom est formé d’une lettre majuscule pour chacune des premières lettres des mots. |
||
| 348 | |||
| 349 | Le nom DOIT être dans un deux formats suivants : |
||
| 350 | |||
| 351 | * ActionItemAttribut, où _Action_ signifie : |
||
| 352 | 78 | Patrice Nadeau | * *Get* : Lis un registre |
| 353 | * *Read*, *Write* : Lis ou écris dans un fichier |
||
| 354 | * *Set* : Écris une valeur prédéfini dans un registre |
||
| 355 | * *Init* : Fonction d’initialisation |
||
| 356 | 1 | Patrice Nadeau | * isItemEtat |
| 357 | 78 | Patrice Nadeau | * *is* : Verifie si _Item_ est dans l’état _Etat_ |
| 358 | 32 | Patrice Nadeau | |
| 359 | Exception |
||
| 360 | 50 | Patrice Nadeau | > Les fonctions définies dans une librairie de bas niveau pour du matériel (« driver »). Dans ce cas, le nom définis dans le « datasheet » aura préséance. Ex. ReadRegister. |
| 361 | 32 | Patrice Nadeau | |
| 362 | 1 | Patrice Nadeau | Une fonction DEVRAIT retourner une valeur. |
| 363 | |||
| 364 | 32 | Patrice Nadeau | Dans le cas d'un « oui/non », la valeur DOIT être : |
| 365 | |||
| 366 | 1 | Patrice Nadeau | * Succès : **0** |
| 367 | 32 | Patrice Nadeau | * Erreur : **1** |
| 368 | 1 | Patrice Nadeau | |
| 369 | 32 | Patrice Nadeau | > L'utilisation d'un type booléen (*true* & *false*) est permise avec la librairie **\<stbool.h\>** (C99). |
| 370 | |||
| 371 | Dans le cas d'une fonction retournant un pointeur : |
||
| 372 | |||
| 373 | * Erreur : **NULL** |
||
| 374 | * Autre valeur : adresse du pointeur |
||
| 375 | |||
| 376 | Définition de fonctions |
||
| 377 | |||
| 378 | 63 | Patrice Nadeau | ``` c |
| 379 | /** |
||
| 380 | * @brief Check if a timer is set |
||
| 381 | * @param[in] nb Timer number. @n Possible values : |
||
| 382 | * − @b TIMER_1 |
||
| 383 | * − @b TIMER_2 |
||
| 384 | * @return |
||
| 385 | * @retval true Timer @e nb is set |
||
| 386 | * @retval false Timer @e nb is NOT set |
||
| 387 | * @par Example : |
||
| 388 | * Check if the timer is set |
||
| 389 | * @code{.c} |
||
| 390 | * ... |
||
| 391 | * result = isTimerSet(); |
||
| 392 | * ... |
||
| 393 | * @endcode |
||
| 394 | * @pre TimerInit |
||
| 395 | **/ |
||
| 396 | |||
| 397 | static bool isTimerSet(uint8_t nb); |
||
| 398 | /** |
||
| 399 | * @brief Set the led to green |
||
| 400 | **/ |
||
| 401 | SetLedColor(GREEN); |
||
| 402 | /** |
||
| 403 | * @brief Set register of the chip XYZ |
||
| 404 | * |
||
| 405 | * The name does not follow the standards but does match the datatsheet |
||
| 406 | * This is a local function not meant to be called outside this librairy |
||
| 407 | **/ |
||
| 408 | static void _WriteReg(void); |
||
| 409 | ``` |
||
| 410 | |||
| 411 | 1 | Patrice Nadeau | ### Macros |
| 412 | |||
| 413 | Les directives du préprocesseur C. |
||
| 414 | |||
| 415 | 23 | Patrice Nadeau | * Utilisé dans le code source et les fichiers entête. |
| 416 | * DOIT toujours commencer à la colonne 0. |
||
| 417 | |||
| 418 | 1 | Patrice Nadeau | #### #include |
| 419 | 40 | Patrice Nadeau | |
| 420 | 1 | Patrice Nadeau | Pour inclure d’autres fichier comme les fichiers entête. |
| 421 | 40 | Patrice Nadeau | >N’est pas documenté dans Doxygen. |
| 422 | 24 | Patrice Nadeau | |
| 423 | 1 | Patrice Nadeau | #### ifdef / ifndef |
| 424 | 70 | Patrice Nadeau | |
| 425 | 52 | Patrice Nadeau | Surtout utiliser pour des options de compilation sur différentes plateforme. |
| 426 | 67 | Patrice Nadeau | > N’est pas documenté dans Doxygen. |
| 427 | 1 | Patrice Nadeau | |
| 428 | ``` c |
||
| 429 | 64 | Patrice Nadeau | #ifndef usart_AVR |
| 430 | 1 | Patrice Nadeau | |
| 431 | 64 | Patrice Nadeau | #error "usart.h is not supported on this AVR !" |
| 432 | 34 | Patrice Nadeau | |
| 433 | 64 | Patrice Nadeau | #endif |
| 434 | ``` |
||
| 435 | 33 | Patrice Nadeau | |
| 436 | 37 | Patrice Nadeau | #### #error |
| 437 | 1 | Patrice Nadeau | |
| 438 | Affiche une erreur et arrête la compilation |
||
| 439 | >N’est pas documenté dans Doxygen. |
||
| 440 | |||
| 441 | ``` c |
||
| 442 | |||
| 443 | 62 | Patrice Nadeau | #ifndef __test__ |
| 444 | 1 | Patrice Nadeau | |
| 445 | 62 | Patrice Nadeau | #error "Error !" |
| 446 | 1 | Patrice Nadeau | |
| 447 | #endif |
||
| 448 | 65 | Patrice Nadeau | ``` |
| 449 | 38 | Patrice Nadeau | |
| 450 | 53 | Patrice Nadeau | #### #warning |
| 451 | 17 | Patrice Nadeau | |
| 452 | 1 | Patrice Nadeau | Affiche une erreur mais n’arrête la compilation |
| 453 | 53 | Patrice Nadeau | >N’est pas documenté dans Doxygen. |
| 454 | |||
| 455 | 65 | Patrice Nadeau | ``` c |
| 456 | 69 | Patrice Nadeau | #ifndef __test__ |
| 457 | 39 | Patrice Nadeau | |
| 458 | 69 | Patrice Nadeau | #warning "Warning !" |
| 459 | 39 | Patrice Nadeau | |
| 460 | 69 | Patrice Nadeau | #endif |
| 461 | 65 | Patrice Nadeau | ``` |
| 462 | 39 | Patrice Nadeau | |
| 463 | #### #define |
||
| 464 | 1 | Patrice Nadeau | |
| 465 | Définis une valeur au moment de la compilation. |
||
| 466 | |||
| 467 | 39 | Patrice Nadeau | * Format |
| 468 | * En majuscule. |
||
| 469 | * Séparé par un «underscore» si contient plusieurs mots. |
||
| 470 | * Doxygen |
||
| 471 | * @brief |
||
| 472 | * @name pour les listes de macros (regroupement dans la documentation) |
||
| 473 | |||
| 474 | 40 | Patrice Nadeau | Définition de macros |
| 475 | |||
| 476 | 65 | Patrice Nadeau | ``` c |
| 477 | 69 | Patrice Nadeau | /** |
| 478 | * @name Mathematical macros listed together |
||
| 479 | * @{ |
||
| 480 | */ |
||
| 481 | /** @brief Value for PI */ |
||
| 482 | 1 | Patrice Nadeau | |
| 483 | 69 | Patrice Nadeau | #define _PI 3.14 |
| 484 | /** @brief Another number */ |
||
| 485 | #define _MAGIC_NUMBER 42 |
||
| 486 | /** |
||
| 487 | * @} |
||
| 488 | */ |
||
| 489 | /** @brief Even parity */ |
||
| 490 | 1 | Patrice Nadeau | |
| 491 | 69 | Patrice Nadeau | #define usart_PARITY_EVEN 'e' |
| 492 | 65 | Patrice Nadeau | ``` |
| 493 | 1 | Patrice Nadeau | |
| 494 | ### Atmel AVR |
||
| 495 | |||
| 496 | 22 | Patrice Nadeau | Particularités pour les micro-contrôleurs AVR d’Atmel. |
| 497 | 1 | Patrice Nadeau | |
| 498 | 22 | Patrice Nadeau | * Progmem : Pour mettre une fonction en Flash au lieu de SRAM. |
| 499 | 72 | Patrice Nadeau | * Le nom de la fonction est suivie de **_P** |
| 500 | 22 | Patrice Nadeau | * main : Ne revient jamais à un niveau supérieur. |
| 501 | 72 | Patrice Nadeau | * Définir la fonction main avec l’attribut **noreturn** |
| 502 | * La boucle sans fin la plus optimisé est le **for (;;)** |
||
| 503 | * Atomic : Opérations ne devant pas être interrompus |
||
| 504 | 22 | Patrice Nadeau | |
| 505 | 1 | Patrice Nadeau | Particularités pour AVR |
| 506 | 22 | Patrice Nadeau | |
| 507 | 75 | Patrice Nadeau | ```c |
| 508 | 72 | Patrice Nadeau | /** |
| 509 | * @brief Progmem function |
||
| 510 | * @return An unsigned 8 bits integer |
||
| 511 | */ |
||
| 512 | uint_8t PrintString_P() |
||
| 513 | 21 | Patrice Nadeau | |
| 514 | 72 | Patrice Nadeau | /* main function */ |
| 515 | void main(void) __atribute__((noreturn)) |
||
| 516 | { |
||
| 517 | ... |
||
| 518 | /* never return */ |
||
| 519 | for (;;) { |
||
| 520 | 40 | Patrice Nadeau | } |
| 521 | 72 | Patrice Nadeau | } |
| 522 | 40 | Patrice Nadeau | |
| 523 | 72 | Patrice Nadeau | /* atomic operations */ |
| 524 | 18 | Patrice Nadeau | |
| 525 | 72 | Patrice Nadeau | #ifndef S_SPLINT_S |
| 526 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { |
||
| 527 | /* |
||
| 528 | * operations that must not be interupted |
||
| 529 | * like loading a 16 bit register with a 8 bit register |
||
| 530 | */ |
||
| 531 | } |
||
| 532 | #endif |
||
| 533 | 1 | Patrice Nadeau | ``` |
| 534 | |||
| 535 | ### Distribution |
||
| 536 | |||
| 537 | 72 | Patrice Nadeau | Les fichiers suivants DOIVENT être inclus dans une distribution en format **tar.gz** : |
| 538 | 1 | Patrice Nadeau | |
| 539 | * ChangeLog |
||
| 540 | * README |
||
| 541 | * Files.lst |
||
| 542 | * Makefile |
||
| 543 | * Makefile.mk |
||
| 544 | 18 | Patrice Nadeau | * LICENSE.txt |
| 545 | * *.c |
||
| 546 | 1 | Patrice Nadeau | * *.h |
| 547 | * projet.pdf (généré par Doxygen) |
||
| 548 | |||
| 549 | Avec mon makefile : |
||
| 550 | |||
| 551 | 72 | Patrice Nadeau | ```bash |
| 552 | make dist |
||
| 553 | ``` |
||
| 554 | 18 | Patrice Nadeau | |
| 555 | 1 | Patrice Nadeau | ### Modifications |
| 556 | 18 | Patrice Nadeau | |
| 557 | 1 | Patrice Nadeau | Un changement à un fichier (source ou en-tête), doit se refléter dans _Git_. |
| 558 | |||
| 559 | Chaque changement est fait avec : |
||
| 560 | |||
| 561 | 72 | Patrice Nadeau | ```bash |
| 562 | git add nom_fichier |
||
| 563 | git commit |
||
| 564 | ``` |
||
| 565 | 1 | Patrice Nadeau | |
| 566 | 18 | Patrice Nadeau | La ligne DOIT |
| 567 | |||
| 568 | * être au temps présent |
||
| 569 | * être en anglais |
||
| 570 | * se termine par un point |
||
| 571 | 17 | Patrice Nadeau | * être dans le format suivant : |
| 572 | 1 | Patrice Nadeau | > La partie _section_ est facultative |
| 573 | |||
| 574 | |||
| 575 | fichier1 (fonction) <section>: |
||
| 576 | 18 | Patrice Nadeau | Ajoute une description au temps présent. |
| 577 | 1 | Patrice Nadeau | Décrire les bogues réglés si il y en avaient. |
| 578 | 18 | Patrice Nadeau | |
| 579 | 1 | Patrice Nadeau | ### Changelog |
| 580 | |||
| 581 | 17 | Patrice Nadeau | La somme de toutes les modification doivent apparaitre dans un fichier « changelog ». |
| 582 | 18 | Patrice Nadeau | > Le standard seras celui GNU : http://www.gnu.org/prep/standards/html_node/Change-Logs.html#Change-Logs |
| 583 | 1 | Patrice Nadeau | |
| 584 | Ce fichier doit s'appeler **ChangeLog** et DOIT être généré à partir de _Git_ (les doubles espaces ne sont pas une erreur de frappe : |
||
| 585 | |||
| 586 | 72 | Patrice Nadeau | ```bash |
| 587 | 1 | Patrice Nadeau | git log --no-merges --format="%ad %an <%aE> %n * %B" --date=short > ChangeLog |
| 588 | 72 | Patrice Nadeau | ``` |
| 589 | 1 | Patrice Nadeau | |
| 590 | 17 | Patrice Nadeau | ### Validation du code |
| 591 | 1 | Patrice Nadeau | |
| 592 | 17 | Patrice Nadeau | Le logiciel _splint_ est utilisé. |
| 593 | 1 | Patrice Nadeau | |
| 594 | * Un « typecast » DOIT être utilisé lorsque détecté. |
||
| 595 | * L’utilisation du typecast *void* DOIT être utilisé lorsque qu’une fonction retourne un résultat non utilisé. |
||
| 596 | |||
| 597 | 18 | Patrice Nadeau | ## Makefile |
| 598 | |||
| 599 | 1 | Patrice Nadeau | ## Nagios |
| 600 | |||
| 601 | ### Plugins |
||
| 602 | |||
| 603 | https://nagios-plugins.org/doc/guidelines.html |
||
| 604 | |||
| 605 | 18 | Patrice Nadeau | Un message d'une ligne (< 80 caractères) DOIT être retourné via _STDOUT_ dans le format |
| 606 | > *SERVICE STATUS:* texte |
||
| 607 | 1 | Patrice Nadeau | |
| 608 | Les codes de retour sont les suivants : |
||
| 609 | |||
| 610 | |_. Valeur |_. Service Status |_. Description | |
||
| 611 | | 0 | OK | Le service fonctionne | |
||
| 612 | | 1 | Warning | Le service fonctionne, problème avec le seuil de la valeur _Warning_ | |
||
| 613 | | 2 | Critical | Le service ne fonctionne pas ou problème avec le seuil de la valeur _Critical_ | |
||
| 614 | | 3 | Unknow | Arguments non valides ou erreur interne (fork, tcp socket)| |
||
| 615 | |||
| 616 | 18 | Patrice Nadeau | Les arguments suivants DOIVENT être fournis : |
| 617 | 1 | Patrice Nadeau | |
| 618 | 17 | Patrice Nadeau | * *-H* (*--hostname*) : |
| 619 | 1 | Patrice Nadeau | * *-w* (*--warning*) : |
| 620 | * *-c* (*--critical*) : |
||
| 621 | * *-V* (*--version*) : |
||
| 622 | * *-h* (*--help*) : |
||
| 623 | |||
| 624 | L'argument _--help_ DOIT aussi appeler l'argument _--version_. |
||
| 625 | |||
| 626 | 18 | Patrice Nadeau | En _C_, les fonctions suivantes DOIT être utilisées : |
| 627 | 1 | Patrice Nadeau | |
| 628 | 18 | Patrice Nadeau | * _print_revision_ (utils.c) |
| 629 | 1 | Patrice Nadeau | * _print_help_ |
| 630 | * _getopt_long_ (getopt.h) |
||
| 631 | 18 | Patrice Nadeau | |
| 632 | 1 | Patrice Nadeau | ## Script |
| 633 | 40 | Patrice Nadeau | |
| 634 | ### Bash |
||
| 635 | |||
| 636 | ``` bash |
||
| 637 | 69 | Patrice Nadeau | |
| 638 | 61 | Patrice Nadeau | #/bin/bash |
| 639 | 1 | Patrice Nadeau | |
| 640 | 61 | Patrice Nadeau | function print_revision { |
| 641 | } |
||
| 642 | 17 | Patrice Nadeau | |
| 643 | 61 | Patrice Nadeau | function print_help { |
| 644 | print_revision |
||
| 645 | } |
||
| 646 | ``` |
||
| 647 | 1 | Patrice Nadeau | |
| 648 | 17 | Patrice Nadeau | ### Perl |
| 649 | 1 | Patrice Nadeau | |
| 650 | 19 | Patrice Nadeau | ## Vim |
| 651 | 1 | Patrice Nadeau | |
| 652 | * Entête (en commentaires) |
||
| 653 | * Titre |
||
| 654 | * Last Change: |
||
| 655 | * Maintainer: |
||
| 656 | 20 | Patrice Nadeau | * License: This file is placed in the public domain. |
| 657 | 19 | Patrice Nadeau | * Autre mots reconnus |
| 658 | 1 | Patrice Nadeau | * BUG: (Error:) |
| 659 | * TODO: |
||
| 660 | * Note: |
||
| 661 | * FIXME |
||
| 662 | |||
| 663 | ## Références |
||
| 664 | |||
| 665 | Références ayant servis à ce document. |
||
| 666 | |||
| 667 | [ChangeLog](http://www.gnu.org/prep/standards/html_node/Change-Logs.html#Change-Logs) |
||
| 668 | [GNU deprecated attribute](http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Type-Attributes.html) |