1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include <time.h>
#include <stdio.h>
#include <string.h>
char *notif_msg[] = {
" Perte du secteur",
" Le groupe n'a pas démarré",
" Le groupe a démarré",
" Le secteur est rétabli",
" Secteur absent, groupe non opérationnel",
" Le groupe n'est pas opérationnel",
" Nombre d'echecs max atteint; nouvel essai dans delai REESSAI"
};
enum notif_reason {POWER_LOST, NOT_STARTED, STARTED, POWER_BACK, NOT_READY, MAX_TRIED_REACHED};
#define MAX_NOTIF 10
struct notif {
int reason;
int hh, mm, ss;
} notif[MAX_NOTIF];
int nbr_notif=0;
void SendNotif(char *msg) {
puts(msg);
}
void CreateNotifToSend() {
if(nbr_notif) {
char notif_to_send[nbr_notif * 80], *s=notif_to_send;
for(int i=0; i<nbr_notif; i++) {
sprintf(s, "%02d:%02d:%02d %s; ", notif[i].hh, notif[i].mm, notif[i].ss, notif_msg[notif[i].reason]);
s+=strlen(s);
}
nbr_notif=0;
SendNotif(notif_to_send);
}
}
int main(void) {
notif[0].reason=POWER_LOST;
notif[0].hh=12;
notif[0].mm=8;
notif[0].ss=52;
notif[1].reason=NOT_STARTED;
notif[1].hh=13;
notif[1].mm=1;
notif[1].ss=24;
notif[2].reason=POWER_BACK;
notif[2].hh=15;
notif[2].mm=28;
notif[2].ss=4;
nbr_notif=3;
CreateNotifToSend();
} |
Partager