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