Hi
with my limited knowledge of programming, I am struggling to find a way to decode the output of the HKW FUM2 module.
The module answers to commands via serial and yields time, date and some info in one long string e.g. ZDc70d1c0803080901e204f4, where the characters at e.g. position 8 and 9 represent the hour. In this case: 8.
I wrote a little function to retrieve the numbers from the characters. Sorry I'm writing some Dutch: cijfer meaning number, Omzetten meaning Convert. IncomingData is the string returned by the module; int a and int b represent the positions in the string, 08 in this example. The two bytes are hexadecimal, hence 10 o'clock would show as 0a.
With this function I get the integer value of a 2-character string:
int Omzetten(int a, int b) {
int cijferA = int(IncomingData.charAt(a));
int cijferB = int(IncomingData.charAt(b));
if (cijferA > 47 && cijferA < 58) cijferA -= 48;
if (cijferA > 96 && cijferA < 103) cijferA -= 87;
if (cijferB > 47 && cijferB < 58) cijferB -= 48;
if (cijferB > 96 && cijferB < 103) cijferB -= 87;
return cijferA * 16 + cijferB;
}
Is there a better/shorter way? Or did I really invent something (LOL)?
Thanks!!
Jan