Karthik Agarwal

Karthik Agarwal

  • NA
  • 748
  • 263.9k

How to write code based on the typedef?

Oct 28 2011 8:09 AM
typedef unsigned char  UINT8;
typedef unsigned long  UINT32;
typedef UINT32 uint32_t;
typedef UINT8  uint8_t;


void new_interface(UINT16 text_id, void * dynamic_data_vp)
{
  UINT8 i;
  UINT8 index;
  void  * text_ptr_p  = &l_language_Text_data_VPA[text_id];
  UINT8 * text_format = &text_ptr_p[0];
  UINT8 count  = text_format[0]; //count holds the number of data formats embedded
  UINT8 no_of_bits  = count * 2; //holds number of bits required to represent data formats
  UINT8 no_of_bytes  = no_of_bits/8; //holds number of bytes converted from number of bits
  if((no_of_bits % 8) != 0)
  {
    no_of_bytes++;
  }

  index = 0;
  for(i = 0; i < no_of_bytes; i++)
  {
    UINT8 extracted_bits; //holds extracted embedded bits(i.e 2 bits) based on the encoding
    void * fl_text_data_vp[1]; /* array size should be some max value */
    UINT8 format    = text_format[i + 1]; //gets embedded byte one after the other
    fl_text_data_vp[0]  = (void *)dynamic_data_vp; //gets dynamic data one byte after other

    /**************
    SID  - 0x00(00)
    SS  - 0x01(01)
    DNV  - 0x02(10)
    DS  - 0x03(11)
    ***************/

    /* extract the format included */
    /* 1111 1111 are the eight bits available the format may be
    0011 1010 so extract two bits and store it
    */

    index = index + 1; //index of the embedded U8A array
    extracted_bits  = format & 0x03;
    if(index <= count) //validating number of bits and the bits decoded
    {
      decode_bit_format(extracted_bits, text_ptr_p[index], comma_delimited_sid); //to decode extracted data to string
    }

    index = index + 1;
    extracted_bits  = format & 0x0C;
    extracted_bits  = extracted_bits >> 2;
    if(index <= count)
    {
      decode_bit_format(extracted_bits, text_ptr_p[index]);
    }

    index = index + 1;
    extracted_bits  = format & 0x30;
    extracted_bits  = extracted_bits >> 4;
    if(index <= count)
    {
      decode_bit_format(extracted_bits, text_ptr_p[index]);
    }

    index = index + 1;extracted_bits = format & 0xC0;
    extracted_bits  = extracted_bits >> 6;
    if(index <= count)
    {
      decode_bit_format(extracted_bits, text_ptr_p[index]);
    }
  }
}

void decode_bit_format(UINT8 bit_format, UINT8 bit_format_ref)
{
  UINT8 Size;
  /* common block which should tell what need to be done based on the format */
  /* parameter shall be bit info */
  if((bit_format == 0x00) && (bit_format_ref != 0))
  {
    /*Get the string from the given SID ID */
    UINT32 SID_Index = bit_format_ref;
    Size = HmStrLngTable1[SID_index];
    UINT8 SID_String[Size + 1];
    for(UINT8 j = 0; j < (Size + 1); j++)
    {
      SID_String[j] = HmStrLngTable1[SID_index + j + 1];
    }
  }
  else if(bit_format == 0x01)
  {
    /* Static string that needs to displayed */
    Size = bit_format_ref;
  }
  else if(bit_format == 0x02)
  {
    /* Dynamic numeric value sent by application */
    Size = bit_format_ref;
    UINT8 DNV_Decimal = Size & 0xF0;
    DNV_Decimal = DNV_Decimal >> 4;
    UINT8 DNV_Floating = Size & 0x0F;
  }
  else
  {
    /* Dynamic string sent by application */
    Size = bit_format_ref;
  }
}

Now what i want to know is
1. can UINT8 store strings if so how many characters it can store?
2. How to count how many number of characters an UINT8 variable has?
3. How to concatenate two strings?
4. How to concatenate binary data?
5. Also tell me what does these lines mean
        void * fl_text_data_vp[1];
        fl_text_data_vp[0]    = (void *)dynamic_data_vp;

Note: All these code is written in .c file so please post your answers keeping this in mind.

Answers (44)