Bonjour,

Je suis bloqué sur mon programme, suite à un segmentation fault
Je m'explique :

Je voudrai faire un scan par RFID, et afficher constamment les tags
que je passe devant le capteur... Seulement, je ne veux pas afficher
deux fois le même tag, c'est pourquoi je passe par une pile, pour
ensuite l'afficher ...

En outre, je devrai avoir des identifiants de tag unique, sans
doublon, mais mon programme s'arrête sur l'affichage et provoque un
seg fault...

Si vous avez une idée ...
Je vous en remercie


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
 
#include <caenrfid.h>
 
#include <stdint.h>
 
 
/*********************\
 
 *      pile.h       *
\*********************/
typedef struct ElementListe{
 char *donnee;
 struct ElementListe *suivant;
} Element;
 
typedef struct ListeRepere{
 Element *debut;
 int taille; //c'est le nombre de cellule créées
} Pile;
 
 
/* initialisation */
void initialisation (Pile *tas);
 
/* EMPILER*/
int empiler (Pile *tas, char *donnee);
 
/* DEPILER*/
int depiler (Pile *tas);
 
/* Affichage de élément en haut de la pile (LastInFirstOut) */
#define pile_donnee(tas)  tas->debut->donnee
 
/* Affiche la pile */
void affiche (Pile *tas);
/*-------------------------------------------------------------*/
 
 
/***********************\
 
 * pile_function.h     *
\***********************/
 
void initialisation (Pile * tas){
 tas->debut = NULL;
 tas->taille = 0;
}
 
/* empiler (ajouter) un élément dans la pile */
int empiler (Pile * tas, char *donnee){
 Element *nouveau_element;
 if ((nouveau_element = (Element *) malloc (sizeof (Element))) == NULL)
   return -1;
 if ((nouveau_element->donnee = (char *) malloc (50 * sizeof (char)))
     == NULL)
   return -1;
 strcpy (nouveau_element->donnee, donnee);
 nouveau_element->suivant = tas->debut;
 tas->debut = nouveau_element;
 tas->taille++;
}
 
/* depiler (supprimer un élément de la pile */
int depiler (Pile * tas){
 Element *supp_element;
 if (tas->taille == 0)
   return -1;
 supp_element = tas->debut;
 tas->debut = tas->debut->suivant;
 free (supp_element->donnee);
 free (supp_element);
 tas->taille--;
 return 0;
}
 
/* affichage de la pile */
void affiche (Pile * tas){
 Element *courant;
 int i;
 courant = tas->debut;
 
 for(i=0;i<tas->taille;++i){
   printf("\t\t%s\n", courant->donnee);
   courant = courant->suivant;
 }
}
 
/*---------------------------------------------*/
 
 
static char nibble2hex(char c)
{
       switch (c) {
       case 0 ... 9:
               return '0' + c;
 
       case 0xa ... 0xf:
               return 'a' + (c - 10);
       }
 
       printf("got invalid data!");
       return '\0';
}
 
char *bin2hex(uint8_t *data, size_t len)
{
       char *str;
       int i;
 
       str = malloc(len * 2 + 1);
       if (!str)
               return NULL;
 
       for (i = 0; i < len; i++) {
               str[i * 2] = nibble2hex(data[i] >> 4);
               str[i * 2 + 1] = nibble2hex(data[i] & 0x0f);
       }
       str[i * 2] = '\0';
 
       return str;
}
struct tableau_tag {
       int str;
       size_t len;
       char source[CAENRFID_SOURCE_NAME_LEN];
       char readpoint[CAENRFID_READPOINT_NAME_LEN];
       enum caenrfid_protocol type;
       uint16_t rssi;
};
 
/* MAIN ! */
 
 
int main(int argc, char *argv[])
{
       int i,j,k=0;
       struct caenrfid_handle handle;
       char string[] = "Source_0";
       struct caenrfid_tag *tag;
       struct tableau_tag *tab;
       size_t size;
       char *str;
       int ret=0;
 
       Pile *tas;
 char *nom;
 if ((tas = (Pile *) malloc (sizeof (Pile))) == NULL)
   return -1;
 if ((str = (char *) malloc (50 * sizeof (char))) == NULL)
   return -1;
 initialisation (tas);
 
 
 
 
 
 
       //if (argc < 2) {
       //      fprintf(stderr, "usage: %s: <server_addr>\n", argv[0]);
       //      exit(EXIT_FAILURE);
       //}
 argv[1]="192.168.0.120";
       /* Start a new connection with the CAENRFIDD server */
       ret = caenrfid_open(CAENRFID_PORT_TCP, argv[1], &handle);
       if (ret < 0) {
               fprintf(stderr, "cannot init lib (err=%d)\n", ret);
               exit(EXIT_FAILURE);
       }
       while(1){
       /* Do the inventory */
       ret = caenrfid_inventory(&handle, string, &tag, &size);
       if (ret < 0) {
               fprintf(stderr, "cannot get data (err=%d)\n", ret);
               exit(EXIT_FAILURE);
       }
 
 
 
int i;
int entier;
int entier2;
int position;
 
       for(i = 0 ; i < size ; i++)
       {
           str = bin2hex(tag[i].id, tag[i].len);
           for(j = 0 ; j < tas->taille ; j++)
           {
 
               entier=atoi(tas->debut->donnee);
               entier2=atoi(str);
               if(entier2 == entier)
               {
                   ret=1;
                   position=j;
               }
                   tas->debut = tas->debut->suivant;
           }
 
               if(ret==0) /*Ce qui veux dire qu'il n'est pas existant */
               {
                   empiler(tas,str); /* on le rajoute a la liste*/
               }
               ret = 0;
        }
 
 
/* AFFICHAGE */
 
 
           affiche(tas);
 
 
       } // Fin du while(1)
 
 
       return 0;
}