Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/20/03 15:03
Read: times


 
#46122 - bitfields
I'm decoding pocsag protocol for pagers.
the data comes in 32 bit batches, and is split into
1 bit address / message codeword
21 bits address
9 bits parity check
1 bit CRC
i done the following test softwre where 32 bits get stored in frameSync
typedef struct
{  
    unsigned char bit1       :  1; // see msb or lsb
    unsigned long bits2To21  : 21; // 19 bits for address or data 
    unsigned int  bits22To31 :  9; // 9 parity check bits
    unsigned char bit32      :  1; // even parity bit
} pagerMsg;

typedef union
{
    pagerMsg pagerData;
    unsigned long int frSync;
} pocSag;

void main()
{
    unsigned char aD, CRC;
    unsigned long address;
    unsigned int parity;
    pocSag data;
    data.frameSync = 0xffffffff;

    aD      = data.pagerData.bit1;
    address = data.pagerData.bits2To19;
    parity  = data.pagerData.bits22To31;
    CRC     = data.pagerData.bit32;
    while(1);

}

Looks like the bit fields only work on char, does this mean I have to split my 19 bits into char + char + char : 3 ruining my neat code?
any other neat suggestions for extracting 19 bits from stream without ugly >> and & ?
Regards
Mahmood

List of 15 messages in thread
TopicAuthorDate
bitfields            01/01/70 00:00      
   RE: bitfields            01/01/70 00:00      
   RE: bitfields            01/01/70 00:00      
      RE: bitfields            01/01/70 00:00      
         RTFM!            01/01/70 00:00      
   RE: bitfields            01/01/70 00:00      
      RE: bitfields            01/01/70 00:00      
      RE: bitfields            01/01/70 00:00      
         RE: bitfields            01/01/70 00:00      
            RE: bitfields            01/01/70 00:00      
               RE: bitfields            01/01/70 00:00      
                  RE: bitfields            01/01/70 00:00      
   See the Keil site.            01/01/70 00:00      
      RE: See the Keil site.            01/01/70 00:00      
         RE: See the Keil site.            01/01/70 00:00      

Back to Subject List