Convert String (5-byte HEX) received via Serial to uint64 for nRF24L01+ address?

Hi there!

I hope this is sufficient to describe my problem, if not let me know ;).
I´m sending, amongst other data, a 5-byte (hex) string (e.g. "B3B3B3B3B3") via serial to an Arduino.
This string shall be used to change the TX address of a nRF24L01+ module attached to the Arduino.
The RF24 library requires a uint64 value, but I´m not able to convert it.

How would you guys convert the 5-byte string to a uint64 value?
There is no function which can convert a string directly to an unsigned 64-bit value and I can´t figure out any other way to solve this at the moment. I´ve also read about a "strtoull" C-function but it is not included in avr stdlib library and seems to be a dead end.

Thanks for your help!

Some background information...
Why do I need to change the TX address?
This string (unique address) is obtained from a database in the background before sending data to the Arduino.
The database is used to manage configuration data of multiple remote devices (other Arduinos with a nRF24 module).
With this database and the ability to switch the TX address it shall be possible to send data to specific devices with the benefits of nRF24 functions, such as auto acknowledgement to check whether the device actually received something.
The remote devices shall be used for wireless home automation sensors and switches together with OpenHAB.

From the example that comes with the RF24 library...

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

or in your case

const uint64_t pipe = 0xb3b3b3b3b3LL);

Yeah, I know how to assign addresses using the lines you quoted from the library.
That´s not the problem...
I´m receiving the TX address via serial from a computer and
want to change the TX address before transmitting data also received from the computer via serial.
The address is not hard coded in the arduino, but can change depending on what remote device the computer wants to send data to. As several remote devices shall be used, including all addresses in the arduino code is not feasible.

The data received via serial is the TX address and the payload to transmit both in string format. The payload can easily be converted from string to byte (actually int but in a byte array). The address however is a problem as it has to be converted from string to uint64.
Would it make sense to slice the string and convert it piece by piece to an int and assemble the data to the desired format?

The RF24 library requires a uint64 value

The RF24 library is silly and inefficient, probably. Unless it is actually doing 64bit math, something like char[5] would be a lot better on AVR-like processors (avr-gcc is known to produce particularly bad code for 64bit manipulation)

However, something like the following should work ok:

char hexCharToBin(char c) {
  if (isdigit(c)) {  // 0 - 9
    return c - '0';
  } else if (isxdigit(c)) { // A-F, a-f
    return (c & 0xF) + 9;
  }
  return -1;
}

unsigned long long hexStrToULL(char * string)
{
   unsigned long long x =0;
   char c;
   do {
     c =hexCharToBin(*string++);
     if (c < 0)
       break;
     x = (x << 4) | c;
  } while (1);
  return x;
}

Hi!
Thanks for the code snippet, I´ll try it after I get some sleep! XD

I think there's a c ++ function you can use

Strtoll
http://www.cplusplus.com/reference/cstdlib/strtoll/

globalize0815:
Yeah, I know how to assign addresses using the lines you quoted from the library.
That´s not the problem...
I´m receiving the TX address via serial from a computer and
want to change the TX address before transmitting data also received from the computer via serial.
The address is not hard coded in the arduino, but can change depending on what remote device the computer wants to send data to. As several remote devices shall be used, including all addresses in the arduino code is not feasible.

The data received via serial is the TX address and the payload to transmit both in string format. The payload can easily be converted from string to byte (actually int but in a byte array). The address however is a problem as it has to be converted from string to uint64.
Would it make sense to slice the string and convert it piece by piece to an int and assemble the data to the desired format?

I wouldn't convert piece by piece as an int, but as a byte... (Remember on Arduinos an int is two bytes.) Though I suppose you may want to read from the source string as an int to get both ASCII values into one variable to then convert down to an byte (high byte converts to high nybble, low byte converts to low nybble)...

Another method might be to have your address variable as a union of the uint64_t and a byte[] array. This would eliminate the tedium of shifting a 64 bit value on an 8 bit processor... Convert each byte from the two received ASCII characters to a byte hex value and then put it in the appropriate byte[] array index. Then read the completed uint64_t value. Just be careful to watch your byte order (both in order of conversion and in location of storage). You need to think about whether you want to store the value in byte[] indexes 0-4, 4-0, 7-3, or 3-7.

Hi again!
The solution posted by westfw works!!!!
I can now switch the TX address on the fly depending on which device data has to be sent to!

Thanks for the code!