Passing rx from NRF.nfcRx to C code

Posted on
  • I'm trying to implement a custom ntag215 emulator with the bulk of it in C, but I'm having an issue passing the received data to my C function.

    Here's the function signature:

    // int processRx(int, int)
    int processRx(int rxLen, unsigned char *rx)
    

    I've tried this since it was the same general code that I used to point the C code to my storage array, but accessing rx[0] from the C code just reads 0

    NRF.on('NFCrx', function(rx) {
      var rxAddr = E.getAddressOf(rx);
      if (!rxAddr) throw new Error("RX not a flat string");
      var txLen = ntag.processRx(rx.length, rxAddr);
      console.log(rx);
      console.log(txLen);
    }
    

    the console logs the full expected rx array, but the C function doesn't see the expected values, I'm assuming it's something related to a data type mismatch between the javascript and c code.

  • Hi - the code looks good, but can you try E.getAddressOf(rx, true); - to require a flat string?

    My guess is it'll then error with RX not a flat string, in which case you need to add rx = E.toString(rx) at the start to make it 'flat'.

    I believe it's because rx that is passed to the function may not be flat (by default fragmented strings, which are faster to allocate, are used). For stuff like this, trace(rx) might help to give you some clues to the actual variable type.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Passing rx from NRF.nfcRx to C code

Posted by Avatar for DanTheMan827 @DanTheMan827

Actions