yaffs Working on timothy_tests and have updated yaffs_importer.py
[yaffs2.git] / direct / timothy_tests / message_buffer.c
1 #include "message_buffer.h"
2
3
4 void add_to_buffer(buffer *p_Buffer, char *message,char message_level){
5         unsigned int x=0;
6         /*move the head up one. the head always points at the last written data*/
7         p_Buffer->head++;
8
9 //      printf("p_Buffer->tail=%d\n",p_Buffer->tail);
10 //      printf("p_Buffer->head=%d\n",p_Buffer->head);
11         if (p_Buffer->head >=BUFFER_SIZE-1) {
12 //              printf("buffer overflow\n");
13                 p_Buffer->head -= (BUFFER_SIZE-1);      /*wrap the head around the buffer*/
14 //              printf("new p_Buffer->head=%d\n",p_Buffer->head);
15         }       
16         /*if the buffer is full then delete last entry by moving the tail*/
17         if (p_Buffer->head==p_Buffer->tail){
18 //              printf("moving buffer tail from %d to ",p_Buffer->tail);
19                 p_Buffer->tail++;
20                 if (p_Buffer->tail >=BUFFER_SIZE) p_Buffer->tail -= BUFFER_SIZE;/*wrap the tail around the buffer*/
21 //              printf("%d\n",p_Buffer->tail);
22
23         }
24
25
26
27
28         
29         
30
31         p_Buffer->message_level[p_Buffer->head]=message_level; /*copy the message level*/
32         x=p_Buffer->head;
33
34
35         
36         strcpy(p_Buffer->message[p_Buffer->head],message); /*copy the message*/
37 //      printf("copied %s into p_Buffer->message[p_Buffer->head]: %s\n",message,p_Buffer->message[p_Buffer->head]);
38 //      printf("extra %s\n",p_Buffer->message[p_Buffer->head]);
39
40         if (p_Buffer->message_level[p_Buffer->head]<=DEBUG_LEVEL){
41 //              printf("printing buffer 1\n");
42                 /* the print buffer sfunction is not working this is just a quick fix*/          
43 //              print_buffer(p_Buffer,1); /*if the debug level is higher enough then print the new message*/
44                 printf("%s\n",p_Buffer->message[p_Buffer->head]);
45         }
46 }
47 void print_buffer(buffer *p_Buffer, int number_of_messages_to_print){   
48         int x=0;
49         int i=0;
50         printf("print buffer\n");
51         printf("buffer head:%d\n",p_Buffer->head);
52         printf("buffer tail:%d\n",p_Buffer->tail);
53
54         if (number_of_messages_to_print==PRINT_ALL) number_of_messages_to_print=BUFFER_SIZE;
55 //      printf("number_of_messages_to_print=%d\n",number_of_messages_to_print);
56         for (i=0,x=0; (x>=p_Buffer->tail) && (i<number_of_messages_to_print); i++, x--){
57 //              printf("printing buffer\n");
58 //              printf("x:%d\n",x);
59                 if (x<0) x = BUFFER_SIZE-1;             /*wrap x around buffer*/
60                 printf("%s\n",p_Buffer->message[p_Buffer->head]);
61                 printf("printed buffer\n");
62         }
63
64 }
65