I'm trying to read data from a TCP stack and using the data to control external interfaces etc. The data is in u32_t so if I write for example "test" to the interface the hex value corresponds to 0x74657374. I want to convert this data to their corresponding characters so it is easier to use the data. How do I convert hexadecimal values in a u32_t to its char string?
I've tried print the data directly via the %c format specifier but then it only shows the first character of the string.
/* indicate that the packet has been received */
tcp_recved(tpcb, p->len);
// Put actual data in 32 bit unsigned integer.
tempPtr = (u32_t*)p->payload;
// Print length of the actual data.
xil_printf("Received package. Length = %d \r\n", p->len);
// Reverse the data so it corresponds to the data sent.
u32_t reversedTemp = byte_reverse_32(*tempPtr);
// Prints hex value of data
xil_printf("Data: %08x \r\n",reversedTemp);
if (reversedTemp == 0x6C656431) { /* Read "led1" */
xil_printf("Data Read: led1");
} else if (reversedTemp == 0x74657374) { /* Read "test */
xil_printf("Data Read: test");
}
So where I'm using the full hex value in the if statement I only want to use the string value. So for checking test it should be == "test" instead of == 0x74657374.