encore

Répétitions espacées dans le terminal
git clone git://git.asteride.xyz/~ldp/encore.git
Journaux | Fichiers | Références

sm2.c (798B)


      1 #include <stdint.h>
      2 #include <time.h>
      3 
      4 #include <stdio.h>
      5 
      6 #include "paquet.h"
      7 #include "sm2.h"
      8 
      9 #define FMIN 1.3
     10 
     11 static uint8_t sm2_fac(int, int);
     12 
     13 void
     14 sm2(struct fiche *f, unsigned int qual, unsigned int pins, unsigned int pipi, unsigned int pnpi, uint64_t date) {
     15 	uint32_t     intrv;
     16 	uint64_t     mtn;
     17 
     18 	f->fac = sm2_fac(f->fac, qual);
     19 
     20 	if (qual >= 4)
     21 		f->nsucc++;
     22 	else
     23 		f->nsucc = 0;
     24 
     25 	if (f->nsucc <= 1)
     26 		intrv = pipi;
     27 	else if (f->nsucc == pins)
     28 		intrv = pnpi;
     29 	else
     30 		intrv  = (f->prch - f->dern) * (f->fac / 100.0 + FMIN) + 1;
     31 
     32 	mtn = (uint64_t) time(NULL) >> 8;
     33 
     34 	f->dern = mtn - date;
     35 	f->prch = f->dern + intrv;
     36 }
     37 
     38 static uint8_t
     39 sm2_fac(int fac, int qual)
     40 {
     41 	fac = fac - 80 + 28 * qual - 2 * qual * qual;
     42 
     43 	if (fac > 255)
     44 		fac = 255;
     45 	if (fac < 0)
     46 		fac = 0;
     47 
     48 	return fac;
     49 }