I receive a SMS in UCS2 (HEX) format (Arabic) something like this "06720631062F0648064A06460648"
i break it 4 by 4, i transform to numbers with strtoul(), i change the code to utf-8 , it is OK I can display the correct message in the correct language on The serial monitor
Now I would like to find specific substrings in the message to perform specific tasks.
the received string "06720631062F0648064A06460648" is formed by the unicode code points (2 bytes) in hex representation of the word ٲردوينو, to display on the serial monitor, it is necessary to transform to utf-8. To do that, i was obliged to cast the string to numbers. But now, i dont know how to cast it back to String
void setup() {
Serial.begin(9600);
char UCS2[] = "06720631062F0648064A06460648";
uint8_t n = strlen(UCS2);
char S[5]; // 4 digits + \0
for(uint8_t i = 0; i < n ; i+=4){
strncpy(S, &UCS2[i], 4);
uint16_t CP = strtoul(S,NULL,16);
unicode2utf8(CP); //inversé [L H]
Serial.write((byte*)&CP,2); // little Endian
}
}
void loop() {
}
void unicode2utf8(uint16_t& U){
// pour points de codes 0 --> u+07FF
if(U > 127){
uint8_t UL = (U & 0x003F)| 0B10000000;
uint8_t UH = (U >> 6) | 0B11000000;
U = (UL << 8) | UH ; //inversé
}
}