1 | #include <manip.h>
|
---|
2 | /*#include <stdio.h>
|
---|
3 | #include <malloc.h>
|
---|
4 | #include <stdlib.h>
|
---|
5 | #define utilitaires_de_block_archeops
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "choix_acquisition.h"
|
---|
9 | #include "archeops.h"
|
---|
10 | #include "bit_block.h"
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 | unsigned long buffer;
|
---|
15 | int llgg,somme,type_du_block,numero;
|
---|
16 | int deb; /*deb vaut zero si aucun debut n'a encore ete trouve*/
|
---|
17 | int compteur;
|
---|
18 | int cpt_cherche_debut;
|
---|
19 | def_long_block
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | int lit_bit(block_type_modele *pbk)
|
---|
24 |
|
---|
25 | {
|
---|
26 | int i,m,bit;
|
---|
27 | // unsigned char bit; /*c'est le bit lu*/
|
---|
28 |
|
---|
29 | bit=un_bit();
|
---|
30 | switch(bit)
|
---|
31 | {
|
---|
32 | case bit_vide : return(lit_bit_vide);
|
---|
33 | case bit_un : buffer=(buffer>>1)|0x80000000; break;
|
---|
34 | case bit_zero : buffer=0x7fffffff & (buffer>>1); break;
|
---|
35 | default : ecrit_erreur_bit(erreur_bit_erreur);
|
---|
36 | buffer=buffer>>1;
|
---|
37 | break;
|
---|
38 | }
|
---|
39 |
|
---|
40 | compteur++;
|
---|
41 | i=compteur%32;
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 | switch(deb)
|
---|
46 | {
|
---|
47 | case(1) :
|
---|
48 |
|
---|
49 | /*signifie qu'un debut a ete trouve precedemment*/
|
---|
50 |
|
---|
51 | if(i==31)
|
---|
52 | {
|
---|
53 | /*lecture du code 1*/
|
---|
54 | pbk->code1=buffer;
|
---|
55 | deb=2;
|
---|
56 | }
|
---|
57 | break;
|
---|
58 |
|
---|
59 | case(2) :
|
---|
60 |
|
---|
61 | /*lecture du code 2*/
|
---|
62 |
|
---|
63 | if(i==31)
|
---|
64 | {
|
---|
65 |
|
---|
66 | pbk->code2=buffer;
|
---|
67 | // type_du_block=((buffer>>24)&0xff);
|
---|
68 | // numero=(buffer&0xffffff);
|
---|
69 | deb=3;
|
---|
70 |
|
---|
71 | /*Quelques tests avant de continuer*/
|
---|
72 | llgg=longueur_block(pbk);
|
---|
73 | somme=somme_block(pbk);
|
---|
74 | type_du_block=type_block(pbk);
|
---|
75 | numero=numero_block(pbk);
|
---|
76 |
|
---|
77 | if((type_du_block<0) || (type_du_block>nb_type_blocks))
|
---|
78 | {
|
---|
79 | ecrit_erreur_bit(erreur_type);
|
---|
80 | deb=0; /*on va rechercher un nouveau debut*/
|
---|
81 | }
|
---|
82 |
|
---|
83 | if(llgg!=long_block[type_du_block])
|
---|
84 | {
|
---|
85 | ecrit_erreur_bit(erreur_longueur);
|
---|
86 | deb=0; /*on va rechercher un nouveau debut*/
|
---|
87 | }
|
---|
88 | // if(deb) ecrit_erreur_bit(bloc_correct);
|
---|
89 | }
|
---|
90 | break;
|
---|
91 |
|
---|
92 | case(3) :
|
---|
93 |
|
---|
94 | if(i==31)
|
---|
95 | {
|
---|
96 | m=(compteur+1)/32-4;
|
---|
97 | if( (m>(taille_maxi_block_archeops)/4) ou (m<0) )
|
---|
98 | {
|
---|
99 | ecrit_erreur_bit(erreur_longueur);
|
---|
100 | deb=0;
|
---|
101 | }
|
---|
102 | else
|
---|
103 | {
|
---|
104 | pbk->mot[m]=buffer;
|
---|
105 |
|
---|
106 | if(m==llgg/4-4) /*en principe, c'est le mot fin*/
|
---|
107 | {
|
---|
108 | if(pbk->mot[m] == fin_block_mesure)
|
---|
109 | {
|
---|
110 | if(calcul_somme_block(pbk,llgg)!=somme)
|
---|
111 | {
|
---|
112 | ecrit_erreur_bit(erreur_somme);
|
---|
113 |
|
---|
114 | /*on continue quand meme*/
|
---|
115 | }
|
---|
116 | // else ecrit_erreur_bit(bloc_correct);
|
---|
117 |
|
---|
118 | deb=0;
|
---|
119 |
|
---|
120 | return(lit_bit_un_block);
|
---|
121 |
|
---|
122 | }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | ecrit_erreur_bit(erreur_fin);
|
---|
126 |
|
---|
127 | /*ecrire ici une nouvelle recherche de debut dans pbk*/
|
---|
128 | deb=0;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | break;
|
---|
136 |
|
---|
137 |
|
---|
138 | default :
|
---|
139 |
|
---|
140 |
|
---|
141 | if(buffer==debut_block_mesure)
|
---|
142 | {
|
---|
143 | deb=1;
|
---|
144 | compteur=31;
|
---|
145 | pbk->debut=buffer;
|
---|
146 | }
|
---|
147 | else
|
---|
148 | {
|
---|
149 | if( (cpt_cherche_debut++<0) ou (cpt_cherche_debut>10000) )
|
---|
150 | {
|
---|
151 | cpt_cherche_debut=0;
|
---|
152 | // ecrit_erreur_bit(cherche_debut);
|
---|
153 | }
|
---|
154 | }
|
---|
155 | break;
|
---|
156 |
|
---|
157 |
|
---|
158 | }
|
---|
159 |
|
---|
160 | return(lit_bit_OK);
|
---|
161 |
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|