Page 256 - Programming Microcontrollers in C
P. 256

Data Compression      241

                              The listing shown below is a simple Huffman-encoded routine to
                          print out to the screen several aircraft-oriented terms that might be
                          used in an on-board avionics system. The first part of the function is
                          a list of the several words or phrases.

                   #include <stdio.h>
                   /* The messages to send out */
                   static unsigned char M1[]={0x9f,0x36,0xef,0xdc,0x0a};
                   static unsigned char M2[]={0xfd,0x26,0x0e,0x7c,0xa0};
                   static unsigned char M3[]={0xc1,0xee,0xe6,0x7f,0xc6,
                                 0x3a,0x39,0x1c,0xb9,0xf2,0x80 };
                   static unsigned char M4[]={0xfc,0xf4,0xf9,0x8e,0x8e,
                                     0x47,0x2e,0x7c,0xa0};
                   static unsigned char M5[]={0x8e,0xb1,0xef,0xf0,0x61,
                                         0x40};
                   static unsigned char M6[]={0x73,0x8f,0xef,0xdf,0x75,
                                         0xda};
                   static unsigned char M7[]={0xdb,0xc2,0x80};
                   static unsigned char M8[]={0x3b,0xb7,0x93,0x66,0x18,
                                     0xed,0xe1,0x8f,0xdf,0xcc,0x66,
                                     0xb4,0xff,0xe7,0xca};
                   static unsigned char M9[]={0xf3,0x5f,0x7d,0xce,0x18,
                                     0xf7,0xf8,0x30,0xa0};
                   /* The Huffman tree */
                   const static char
                   Node[]={4, 2, ‘E’|0X80, ‘I’|0X80, 4, 2,‘A’|0X80,
                   ‘\n’|0X80, 10, 6, 4, 2,‘D’|0X80, ‘ ‘|0X80,
                   ‘N’|0X80, 2, ‘R’|0X80, ‘T’|0X80, 4, 2, ‘M’|0X80,
                   ‘S’|0X80, 4, 2, ‘G’|0X80, ‘U’|0X80, 4, 2,
                   ‘L’|0X80, ‘O’|0X80, 4, 2, ‘F’|0X80, ‘H’|0X80, 2,
                   ‘P’|0X80, 2, ‘C’|0X80, ‘V’|0X80};

                   void decode(unsigned char *M)
                   {
                       unsigned char mask = 0x80;
                       char i=0,j=0,k=0,l=0; /* j is the node pointer,
                                                       i is the byte pointer, M
                                                       is the message pointer */


                       while(k !=’\n’)
   251   252   253   254   255   256   257   258   259   260   261