gc9n
April 23, 2016, 8:11pm
1
Hello i have a
char sms_text[250];
wich contains a HEX value like this
006C00610074003A00330037002E003900350037003100390020006C006F006E0067003A00320033002E00370035003000370030002000730070006500650064003A00300
i want to convert it to this and store it in a string Variable..
lat:37.9899 long:23.74470 speed:0
system
April 23, 2016, 8:19pm
2
330037002E00390035003700310039
3 7 . 9 5 7 1 9
320033002E00370035003000370030
2 3 . 7 5 0 7 0
6C00610074
L a t
gc9n
April 23, 2016, 8:24pm
3
yes i know , but what i mean is how can i do it programmatically?
system
April 23, 2016, 8:28pm
4
If a byte is an ASCII digit, subtract '0' (aka 0x30)
If it's a decimal point (aka full-stop or period) leave it alone.
If it's an alphabetic character, leave it.
Your text has 137 single characters, each group of 4 denotes a resultcharacter, ups, it should be divisible.
There is one superfluous character I think.
char orgMsg[] = "006C00610074003A0033"
"0037002E003900350037"
"003100390020006C006F"
"006E0067003A00320033"
"002E0037003500300037"
"00300020007300700065"
"00650064003A00300";
char resMsg[126];
byte omsgLen = sizeof(orgMsg) - 1;
void setup() {
Serial.begin(115200);
byte offs = 0;
for (offs = 0; offs + 3 < omsgLen; offs += 4) {
resMsg[offs / 4] = getByteAt(orgMsg, offs);
}
resMsg[offs / 4] = 0;
Serial.print(F("res = '"));
Serial.print(resMsg);
Serial.println(F("'"));
}
byte getHexVal(char cx) {
if (cx <= '0') {
return 0;
}
if (cx <= '9') {
return cx - '0';
}
if (cx >= 'A' && cx <= 'F') {
return cx - 'A' + 10;
}
return 0;
}
char getByteAt(char* from, byte offset) {
return getHexVal(from[offset + 2]) * 16 + getHexVal(from[offset + 3]);
}
void loop() {}
res = 'lat:37.95719 long:23.75070 speed:0'
gc9n
April 23, 2016, 9:09pm
7
Thank you very very much , i think this will help a lot of people,
working like a charm
gc9n:
Hello i have a
char sms_text[250];
From some device outside of your control, or did you create the string in the first place?
gc9n
April 23, 2016, 9:38pm
9
from a gps tracker it sends me in PDU not in text