This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading Raw Adv Packet

Hello,

How can i put out the received Adv Data on the UART? Currently I get for every advertise packet the BLE_GAP_EVT_ADV_REPORT in my ble_stack_handler. Then i wanted to print out the data on my VirtualPort with  printf((char*)p_gap_evt->params.adv_report.data.p_data). But i get nothing useful. How can i print out the raw 31 Byte received advertising packet? Do i need a for-loop to print out every byte? 

PS: Using nRF52840 DK

Parents
  • Surely, this is a pure 'C' question - nothing specifically to do with Nordic?

    How can i print out the raw 31 Byte received advertising packet? Do i need a for-loop to print out every byte? 

    Of course - if you need to print 31 individual values, the obvious way to do that will be in a loop.

  • Thank you for your Answer but p_gap_evt->params.adv_report.data.p_data isnt a Array. Its a uint8_t* type. So im little bit confused. Also watched about the value in the debugger and i get something like "0x2000355c". This istn even close 31 Bytes. And my p_gap_evt->params.adv_report.data.len has the Value "0x001f", which is in dec 31

  • But arrays & pointers are almost the same thing in 'C'

    http://c-faq.com/aryptr/

    The index operator [] can be applied to a pointer:

    uint8_t* my_pointer;
    
    my_pointer = &some_data;    // set the pointer to point to something
    
    printf( "1st byte (offset 0) is %d", my_pointer[0] );
    printf( "2nd byte (offset 1) is %d", my_pointer[1] );
    printf( "3rd byte (offset 2) is %d", my_pointer[2] );
      :
      :
    printf( "nth byte (offset n-1) is %d", my_pointer[n-1] );
      
    

    which is equivalent to:

    uint8_t* my_pointer;
    
    my_pointer = &some_data;    // set the pointer to point to something
    
    printf( "1st byte (offset 0) is %d", *my_pointer   );
    printf( "2nd byte (offset 1) is %d", *my_pointer+1 );
    printf( "3rd byte (offset 2) is %d", *my_pointer+2 );
      :
      :
    printf( "nth byte (offset n-1) is %d", *my_pointer+(n-1) );
      
    

    Or:

    uint8_t* my_pointer;
    
    my_pointer = &some_data;    // set the pointer to point to something
    
    printf( "1st byte (offset 0) is %d", *my_pointer++ );
    printf( "2nd byte (offset 1) is %d", *my_pointer++ );
    printf( "3rd byte (offset 2) is %d", *my_pointer++ );
      :
      :

    Again, this is all standard 'C' - nothing specific to Nordic.

  • I am ashamed. Thank you very much. Im able to print out the 31 Bytes. Im so happy :)

Reply Children
Related