2021-11-11 03:46 AM
I am receiving data from UART in uint8_t array.
I want to convert array to string to work on it:
if (Received Data=="Reset") { resetFunc(); }
if (Received Data.substring(0,8)=="ABCDASD")
{
Do something
}
if (Received Data.substring(4,8)=="ABC1234")
{
int Number=1234; // convert substring to int
char Data ="ABC"; // convert substring to char
}
2021-11-11 05:06 AM
You cannot compare strings in C.
You can cast (uint8_t*) to (char*) ans use strcmp thereafter.
hth
KnarfB
2021-11-11 05:25 AM
if (strcmp((const char *) Received Data, "Reset") == 0) {
resetFunc();
}
if (strncmp((const char *) Received Data, "ABCDASD", 7) == 0) {
Do something
}
if (strncmp((const char *) &Received Data[4], "ABC1234", 4) == 0) {
...
}
2021-11-11 06:27 AM
This is more a C language issue, and not STM32 specific
You can construct/re-construct a string a character at a time.
You might need to synchronize and discard characters if you receive from a serial port.
To use string functions you need to insure the data is NUL terminated.
Review C libraries and documentation. Review materials on parsing input.
For numeric conversion there are functions like atoi() and atod(), also sscanf()
2021-11-11 12:15 PM
Thanks for all.
2021-11-11 12:15 PM
It worked
Very thanks