summaryrefslogtreecommitdiff
path: root/i/serialplot/serialplot_RdMch.c
blob: 52fa54320997d41846736d16be9472377fa895b1 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "serialplot_RdMch.h"

void 
read_line ( int tab[8],  enum R_stat * etat_c, 
		const enum R_stat max, const char * chaine)
{
	char valeur[8], convert[8] = "0x";
	int resultat;
	strcpy(valeur,chaine);
	valeur[0] = valeur[2];
	valeur[1] = valeur[3];
	valeur[2] = valeur[5];
	valeur[3] = valeur[6];
	valeur[4] = '\0';
	strcat(convert,valeur);
	resultat =  (strtod( convert, NULL)); 
	/* convertie le  le nombre n�gatif sur le bon nb de bit 
	 * si n�cessaire
	 */
	if ( resultat & 0x8000) resultat |= 0xffff8000 ;
	switch (*etat_c)
	{
		case E1 : tab[0] = resultat; 
			  if (*etat_c != max) *etat_c = E2; else *etat_c = EPRINT;
			  break;
		case E2 : tab[1] = resultat;
			  if(*etat_c != max) *etat_c = E3; else *etat_c = EPRINT;
			  break;
		case E3 : tab[2] = resultat;
			  if (*etat_c != max) *etat_c = E4; else *etat_c = EPRINT;
			  break;
		case E4 : tab[3] = resultat;
			  if (*etat_c != max) *etat_c = E5; else *etat_c = EPRINT;
			  break;
		case E5 : tab[4] = resultat;
			  if (*etat_c != max) *etat_c = E6; else *etat_c = EPRINT;
			  break;
		case E6 : tab[5] = resultat;
			  if (*etat_c != max) *etat_c = E7; else *etat_c = EPRINT;
			  break;
		case E7 : tab[6] = resultat;
			  if (*etat_c != max) *etat_c = E8; else *etat_c = EPRINT;
			  break;
		case E8 : tab[7] = resultat;
			  *etat_c =EPRINT; break;
		default : printf("Ah le connard\n"); break; // make gcc happy
	}
}

int conv_Rd_type( const enum R_stat etat)
{
	
	switch (etat)
	{
		case E1 : return 1;
		case E2 : return 2;
		case E3 : return 3;
		case E4 : return 4;
		case E5 : return 5;
		case E6 : return 6;
		case E7 : return 7;
		case E8 : return 8;
		default : return 0;
	}
}

enum R_stat
read_std_param(char *cvalue)
{
	//TODO verifier la longeur de la chaine < 3
	int result = atoi(cvalue);
	int calcul = 0;
	if( (result > 0) && (result < 256) )
	{
		int test =1;
		while (test < 256)
		{
			if (result & test) calcul ++;
			test <<= 1;
		}
		switch (calcul)
		{
			case 1 : return E1;break;
			case 2 : return E2;break;
			case 3 : return E3;break;
			case 4 : return E4;break;
			case 5 : return E5;break;
			case 6 : return E6;break;
			case 7 : return E7;break;
			case 8 : return E8;break;
			default : return EPRINT;
		}
	}
	else
		return EPRINT; // mauvais interval
}