decoding DCF49


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)?



String Data="ZDc70d1c0803080901e204f4";
int Omzetten(int a, int b) {
  char d[3]={Data.charAt(a),Data.charAt(b),0};
  return strtol(d,NULL,16);

clearly no error checking!

Thanks, Horace!

FYI: there is a checksum of the 'telegram' in the last 4 positions. In positions 18-19 bit7 indicates wether time is correct or not.

Further reading on
about the module itself:


one problem with using strtol() it can increase code size significantly and is overkill
an alternative (with some error checking) would be

// character should represent hex digit 0-9 a-f A-F
// return integer value else 0 for error, e.g. f is 15 decimal
int hex(char ch)
  if(ch >='0' && ch<='9')
     return ch-'0';
  if(toupper(ch) >='A' && toupper(ch)<='F')
     return toupper(ch)-'A'+10;
  // error!
  Serial.println(" error not hex digit");
  return 0;

String Data="ZDc70d1c0803080901e204f4";
int Omzetten(int a, int b) {
  return hex(Data.charAt(a))*16 + hex(Data.charAt(b));