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.
Loading
VulpesPosted Nov 2, 2011, 3:58 PM
So, I'd try:
If I'm right, this line:
format = text_format[i + 1];
will also need changing to:
format = ((UINT8 *)text_format)[i + 1];
Mahesh ChandPosted Nov 3, 2011, 10:44 PM
Please try to keep your questions simple, clear and small. If there are multiple questions, post them as different questions.
Sam HobbsPosted Nov 3, 2011, 10:58 AM
VulpesPosted Nov 3, 2011, 10:14 AM
Karthik AgarwalPosted Nov 3, 2011, 9:14 AM
void** text_ptr_p = l_language_Text_data_VPA[text_id];
void** text_format = text_ptr_p[0];
and sending the address to another fucntion as follows:
hmi_gfx_mgr_decode_bit_format(&text_ptr_p[index]);
and receiving as
static void hmi_gfx_mgr_decode_bit_format(UINT32 * bit_format_ref)
{
//insdie the array I am assigning as follows
Size = HmStrLngTable1[*bit_format_ref];
//now what I want to do is if the Size is equal to 31 or 0x1F then it should concatenate all the other elements in the array
if(Size == 0x1F)
{
// write ur code here
}
}
HmStrLngTable1 looks like follows:
HmStrLngTable1[]
{
/*0x000C */, 0x05, 0x4D, 0x79, 0x4B, 0x65, 0x79
/*0x0012 */, 0x1F, 0x00, 0x0C
/*0x0015 */, 0x1F, 0x00, 0x0C
}
If you see the lines marked in red which starts with 0x1F if that is the case then I need to point to the location which is given by the next two bits which are 0x00 and 0x0C after combining them which becomes 0x000C and which is in green color in the very starting line of the array. Got it.
Probably * bit_format_ref
can be used to point HmStrLngTable1
If you have any doubts get back to me?
Karthik AgarwalPosted Nov 3, 2011, 1:31 AM
Sam HobbsPosted Nov 2, 2011, 2:06 PM
Another possibility would be to write code that converts the data (such as what is done by Windows to "marshal" data) to a format compatible with the other software but your program could use a better format for processing within itself.
Karthik AgarwalPosted Nov 2, 2011, 2:04 PM
UINT8 * text_format = (UINT8 *) text_ptr_p;
UINT8 count = text_format[0];
To be more explanatory
1. first line gives the address and name of the specified l_language_Text_data_VPA element
2. second line just stores the address which we got above
3. finally the third line gives which is not intended.
This means i am not getting anything other than first array element address where i want to three array elements starting from the first array which is is l_language_Text_data_VPA down to the other two arrays.
To be straight forward i would say no improvement Vulpes.
VulpesPosted Nov 2, 2011, 1:59 PM
If so, is that an improvement on the original code? If it is, it might give me a clue what to look for.
Karthik AgarwalPosted Nov 2, 2011, 1:47 PM
Karthik AgarwalPosted Nov 2, 2011, 12:41 PM
And if it comes to the thread i don't understand why i should create a new thread if you see from the start to end it's a single post where i am trying to solve one issue after the other. i posted in vc++ as i am working on vc++ but with c code. Probably if you guide me in a better i am ready to take up the challenge and can change myself and the way i post as well.
@Vulpes: You need to have an another look at the code i guess i am still not able to get the desired result. Still problem with those three lines of code. not able to get the last array data by using the code you gave. haven't worked on C in the past 6yrs hence causing poor pointer usage concept.
Sam HobbsPosted Nov 2, 2011, 12:28 PM
Your code is not good. You are using a void * to avoid the type-safety of C/C++. That is not good. Experienced C++ programmers will choke on such a dependence on void*. Good C++ programmers will refuse to work on programs like that; some of them will do it if they are allowed to totally re-design the data.
My initial impression is that what you could do is to create a base class and then create an array of the base class items and then you can create derived classes and then you can cast the derived class items to the base class to put them in the array. My guess is that you should not even be doing that, but it would be better than what you are doing now.
You are using void too much. You should not use void for data you design; it should be used only for data that you get from or give to Windows or some other software that is designed to be language-neutral. You are using arrays of void* and that is going to cause you numerous problems.
I have one more day of the project I mentioned, but in terms of helping in the forums it is not any different from someone that goes to work and is not able to access these forums while at work. The important thing is that I don't have as much time to look at this as Vulpes does but I have certainly done this type of thing using C++. I could help you to create a better design but it would really help if the specific question was independent of all the other stuff in this thread.
The thing I suggest is that you explain the data that you need to process, but not in C++ terms; please specify the data in a language-independent manner. Perhaps Vuples can help with that. So in ohter words, you can say that a TripMenuTitle_Text_Data_VPA consists of a Title, which is text, and a T_413_B and a T_613_B and an integer. But please, learn how to not use a void*.
VulpesPosted Nov 2, 2011, 12:15 PM
UINT8 * text_format = (UINT8 *)text_ptr_p;
Karthik AgarwalPosted Nov 2, 2011, 12:03 PM
But the line UINT8 * text_format = &text_ptr_p[0];
error C2036: 'void *' : unknown size
VulpesPosted Nov 2, 2011, 11:54 AM
Karthik AgarwalPosted Nov 2, 2011, 11:41 AM
I want to point to l_language_Text_data_VPA and then from that to l_TripResetLine3_Text_Data_VPA and then from that to l_TripResetLine3_Text_Format_U8A and access all the elements in all the arrays how can I do that?
above sequence is very important which needs to be followed
I tried doing it in the following way but didn't end up in correct results.
void * text_ptr_p = &l_language_Text_data_VPA[text_id];
UINT8 * text_format = &text_ptr_p[0];
UINT8 count = text_format[0];
i guess these three lines are causing problem. can you just check out these three lines leaving the other part.
VulpesPosted Nov 2, 2011, 11:30 AM
Karthik AgarwalPosted Nov 2, 2011, 11:11 AM
I have a void pointer array as follows:
void *l_language_Text_data_VPA[] = {
l_TripResetLine3_Text_Data_VPA,
l_Dummy_Text_Data_VPA,
l_TripMenuTitle_Text_Data_VPA
};
which in turn are defined as follows:
void *l_TripResetLine3_Text_Data_VPA[4] =
{
l_TripResetLine3_Text_Format_U8A,
T_411_A,
T_411_B,
0x01
};
void *l_Dummy_Text_Data_VPA[6] =
{
l_Dummy_Text_Format_U8A,
T_438_B,
T_414_C,
"abcdefghijklmnop",
T_414_A,
0x32
};
void *l_TripMenuTitle_Text_Data_VPA[4] =
{
l_TripMenuTitle_Text_Format_U8A,
T_413_B,
T_613_B,
0x11
};
which in turn as follows:
UINT8 l_TripResetLine3_Text_Format_U8A[2] = {0x03, 0x30};
UINT8 l_Dummy_Text_Format_U8A[3] = {0x05, 0x10, 0x02};
UINT8 l_TripMenuTitle_Text_Format_U8A[2] = {0x03, 0x20};
Now I have to point to all the array elements in all the array elements tell me how can I do that?
Note: this is c code which needs to compiled on vc++ (visual studio 2008)
Karthik AgarwalPosted Nov 2, 2011, 9:51 AM
Karthik AgarwalPosted Nov 2, 2011, 6:56 AM
Note: It's c code which i am trying to compile in vc++ visual studio 2008.
Karthik AgarwalPosted Nov 2, 2011, 6:52 AM
static void hmi_gfx_mgr_decode_bit_format(UINT8 bit_format,
UINT8 * bit_format_ref,
UINT8 cat_string[],
UINT8 index,
void * text_data_vp);
int main()
{
UINT8 id;
char vp = '\0';
id = 0;
hmi_gfx_mgr_new_interface(id, &vp);
return 0;
}
static void hmi_gfx_mgr_new_interface(UINT16 text_id, void * dynamic_data_vp)
{
UINT8 i;
UINT8 index = 0;
UINT8 extracted_bits;
UINT8 concat_string[32];
UINT8 array_index = 0;
UINT8 format;
char * text_ptr_p = &l_language_Text_data_VPA[text_id];
UINT8 * text_format = &text_ptr_p[0];
UINT8 count = text_format[0];
UINT8 no_of_bits = count * 2;
UINT8 no_of_bytes = (no_of_bits/8);
if((no_of_bits % 8) != 0)
{
no_of_bytes++;
}
for(i = 0; i < no_of_bytes; i++)
{
UINT8 extracted_bits; //holds extracted embedded bits(i.e 2 bits) based on the encodin
void * fl_text_data_vp;
format = text_format[i + 1];
fl_text_data_vp = (void *)dynamic_data_vp;
index = index + 1;
extracted_bits = format & 0x03;
if(index <= count)
{
hmi_gfx_mgr_decode_bit_format(extracted_bits,
((UINT8 *) &text_ptr_p),
concat_string,
array_index,
fl_text_data_vp);
}
index = index + 1;
extracted_bits = format & 0x0C;
extracted_bits = extracted_bits >> 2;
if(index <= count)
{
hmi_gfx_mgr_decode_bit_format(extracted_bits,
((UINT8 *) &text_ptr_p),
concat_string,
array_index,
fl_text_data_vp);
}
index = index + 1;
extracted_bits = format & 0x30;
extracted_bits = extracted_bits >> 4;
if(index <= count)
{
hmi_gfx_mgr_decode_bit_format(extracted_bits,
((UINT8 *) &text_ptr_p),
concat_string,
array_index,
fl_text_data_vp);
}
index = index + 1;
extracted_bits = format & 0xC0;
extracted_bits = extracted_bits >> 6;
if(index <= count)
{
hmi_gfx_mgr_decode_bit_format(extracted_bits,
((UINT8 *) &text_ptr_p),
concat_string,
array_index,
fl_text_data_vp);
}
}
concat_string[32] = '\0';
}
static void hmi_gfx_mgr_decode_bit_format(UINT8 bit_format,
UINT8 * bit_format_ref,
UINT8 cat_string[],
UINT8 index,
void * text_data_vp)
{
UINT8 Size;
UINT8 len;
UINT8 replace_char;
void * text_data;
text_data = (void *)text_data_vp;
if(bit_format == 0x00)
{
if(*bit_format_ref != 0)
{
/*Get the string from the given SID ID */
UINT32 SID_Index = *bit_format_ref;
Size = HmStrLngTable1[SID_Index];
for(len = 0; len < Size; len++)
{
if(index <= 31)
{
cat_string[index] = HmStrLngTable1[SID_Index + len + 1];
index++;
}
}
}
}
else if(bit_format == 0x01)
{
/* Static string that needs to displayed */
Size = HMI_STRLEN(*bit_format_ref, 0);
for(len = 0; len < Size; len++)
{
if(index <= 31)
{
cat_string[index] = bit_format_ref[len]; // possibly this is causing problem
index++;
}
}
}
else if(bit_format == 0x02)
{
/* Dynamic numeric value sent by application */
replace_char = '0';
Size = *bit_format_ref & 0xF0;
Size = Size >> 4;
for(len = 0; len < Size; len++)
{
if(index <= 31)
{
cat_string[index] = replace_char;
index++;
}
}
Size = *bit_format_ref & 0x0F;
if(Size > 0)
{
cat_string[index] = '.';
index++;
for(len = 0; len < Size; len++)
{
if(index <= 31)
{
cat_string[index] = replace_char;
index++;
}
}
}
}
else
{
/* Dynamic string sent by application */
replace_char = 'W';
Size = *bit_format_ref;
for(len = 0; len < Size; len++)
{
if(index <= 31)
{
cat_string[index] = replace_char;
index++;
}
}
}
}
Karthik AgarwalPosted Nov 2, 2011, 6:50 AM
void *l_language_Text_data_VPA[] = {
l_TripResetLine3_Text_Data_VPA,
l_Dummy_Text_Data_VPA,
l_TripMenuTitle_Text_Data_VPA
};
which in turn is defined as follows:
void *l_TripResetLine3_Text_Data_VPA[4] =
{
l_TripResetLine3_Text_Format_U8A,
T_411_A,
T_411_B,
0x01
};
void *l_Dummy_Text_Data_VPA[6] =
{
l_Dummy_Text_Format_U8A,
T_438_B,
T_414_C,
"abcdefghijklmnop",//when i try to access this string issue is found
T_414_A,
0x32
};
void *l_TripMenuTitle_Text_Data_VPA[4] =
{
l_TripMenuTitle_Text_Format_U8A,
T_413_B,
T_613_B,
0x11
};
which in turn follows as below:
UINT8 l_TripResetLine3_Text_Format_U8A[2] = {0x03, 0x30};
UINT8 l_Dummy_Text_Format_U8A[3] = {0x05, 0x10, 0x02};
UINT8 l_TripMenuTitle_Text_Format_U8A[2] = {0x03, 0x20};
where all the values in the format T_XXX_Y are defined as macros as follows:
#define T_411_A 0x26368
#define T_411_B 0x263AC
#define T_438_B 0x263FA
#define T_414_C 0x26470 and so on......
But the problem is Now i wrote some code as follows in my next post.
Karthik AgarwalPosted Nov 1, 2011, 1:35 AM
Sam HobbsPosted Oct 31, 2011, 1:09 PM
I have an Uncle that has had heart surgery. Today is the last day for us to move everything out of where he was living. It takes nearly an hour each way to go there. I have not had much time to do much else. I should not have taken the time to write this reply.
I hope I am able to help you more in the future.
VulpesPosted Oct 31, 2011, 10:41 AM
I find it hard to figure much out after about 10.00pm :)
Karthik AgarwalPosted Oct 31, 2011, 9:51 AM
Karthik AgarwalPosted Oct 31, 2011, 9:46 AM
Then if i am not wrong Sam Hobbs must be your senior right then how come he can't even guess those kind of things. Some things need to be interpreted if not he can ask to explain further right. How come he says can't really understand and leave it to you. May be he doesn't have much patience i guess. Anyways thanks Vulpes.
VulpesPosted Oct 31, 2011, 9:16 AM
Karthik AgarwalPosted Oct 31, 2011, 8:43 AM
Anyways i could make it from the code you posted.
Was that so difficult to understand how i described my problem?
If that's the case how come you could answer all of my posts and come up with a solution.
VulpesPosted Oct 31, 2011, 7:05 AM
Karthik AgarwalPosted Oct 31, 2011, 3:35 AM
if you have an hexadecimal value then convert the same into binary as follows:
0x32 which is 00110010 in binary
then if you see the binary data first 4 bits from the left they represent the number of X's in the before the decimal point and if represented in X's is XXX(0011)
then the next 4 bits are 0010 is 2 X's after decimal point
hence the final data XXX.XX
which should be replaced with 0's and becomes 000.00
Can you understand now?
Sam HobbsPosted Oct 31, 2011, 3:29 AM
I can not help at the moment; I will leave this for Vulpes for the moment.
Karthik AgarwalPosted Oct 31, 2011, 3:24 AM
Anyways example is as below:
if the string is like XXX.XX then i should replace the X's with 0's as 000.00 for XXX.XX that's it. But the example which i stated is only one but X's can appear in any way. So what is to be done is X's is to be decoded into hexadecimal first of all as follows:
XXX ----- decimal places will be represented by 4 bits (whatever may be the number of X's) which after converting is 0011
and XX ------- floating places will be represented by 4 bits (whatever may be the number of X's) after converting to binary is 0010
They these two has to be concatenated as first decimal places and then floating places as hence it becomes as
00110010 which after converting to hexadecimal will become 0x32 which comes as a value for us which we decode again to binary and replace it with 0's again that is the reversal of the whole process again.
In simple we just need to replace X's with 0's but what i explained is all the procedure
but in the coding point of view we just have hexadecimal value based on that we should do the whole procedure and give the final string based on that.
I will be happy to answer if there any other queries?
VulpesPosted Oct 29, 2011, 8:14 AM
With stuff like this which is difficult to explain in words, an example or two is always useful.
Sam HobbsPosted Oct 28, 2011, 4:58 PM
sprintf(buffer, "%04u.%04u", DNV_Decimal, DNV_Floating);
However it is difficult for me to understand what he is asking.
VulpesPosted Oct 28, 2011, 3:36 PM
char buffer[9];
for(int i = 0; i < 8; i++) buffer[i] = '0';
buffer[0] += (DNV_Decimal & 8) >> 3;
buffer[1] += (DNV_Decimal & 4) >> 2;
buffer[2] += (DNV_Decimal & 2) >> 1;
buffer[3] += DNV_Decimal & 1;
buffer[4] += (DNV_Floating & 8) >> 3;
buffer[5] += (DNV_Floating & 4) >> 2;
buffer[6] += (DNV_Floating & 2) >> 1;
buffer[7] += DNV_Floating & 1;
buffer[8] = '\0';
I didn't follow the second part - it sounds like you just want the string "0000.0000" ?
Sam HobbsPosted Oct 28, 2011, 2:09 PM
Your code is doing a lot of C-style stuff. I assume that is a necessity because the data is coming from somewhere else and the C++ program is getting the data in a format that is intended to be used by any language, not just C or C++.
If it were me, I would convert the data to C++ first before trying to process it. In other words, I would use std::string or std::wstring when relevant and other C++ Standard Classes such as std::vector when relevant. Alternatively, you could use a combination of managed and unmanaged code and then the unmanaged code could convert the data to .Net format and then most of the processing could use .Net.
Karthik AgarwalPosted Oct 28, 2011, 10:16 AM
It depends what you mean by binary data but, in principle, you allocate a buffer big enough to contain all the data and then copy the individual items into it.
The numbers of bits which i will be getting is maximum of 8bits from the following code:
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;
}
DNV_Decimal is of 4 bits if less than that should be padded to its left and
DNV_Floating is of 4 bits if less than that should be padded to its left
then
destination_value = DNV_Decimal + DNV_Floating; // both should be concatenated
and then they should be replaced with 0's (zero's) in the following format
DNV_Decimal number of zero's + "." + DNV_Floating number of zero's
How can i do this?
Try to respond at the earliest.
VulpesPosted Oct 28, 2011, 10:03 AM
Karthik AgarwalPosted Oct 28, 2011, 9:44 AM
Based on what you said it look like you didn't notice the below two lines in my 1st post.
Considering these UINT8 is defined as unsigned char which should make some difference i guess?
typedef unsigned char UINT8;
typedef unsigned long UINT32;
Karthik AgarwalPosted Oct 28, 2011, 9:38 AM
void * fl_text_data_vp[1];
fl_text_data_vp[0] = (void *)dynamic_data_vp;
Karthik AgarwalPosted Oct 28, 2011, 9:27 AM
0x26537 will not fit in UINT8 right? will that fit into UINT8 or should i change the data type. If i need to change what data type i should use?
VulpesPosted Oct 28, 2011, 9:14 AM
Karthik AgarwalPosted Oct 28, 2011, 8:44 AM
#define T_414_A 0x26537 // hexadecimal value.
void * text_ptr_p = &l_language_Text_data_VPA[text_id]; // related declarations
UINT8 * text_format = &text_ptr_p[0]; // related declarations
T_414_A is in "text_ptr_p" array?
But if i want get value 0x26537 how can i get it?
If i just assign as below can i get that value as it is already defined as 0x26537 already?
UINT8 value = text_ptr_p[index]; //respective location where T_414_A which i know