This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652R7: Issue in using Log_printf function for values of variable inside a structure

Part Number: CC2652R7

Hello, 

I am working with the "simple_central" code and under the "SimpleCentral_processAppMsg" function I want to log the following values of detected devices - device address and their RSSI values.

I have added following piece of code inside the " case SC_EVT_ADV_REPORT:" of  "SimpleCentral_processAppMsg" function 

 Log_printf(LogModule_App1, Log_INFO, "RSSI = %d Address = %s ",pAdvRpt->rssi,Util_convertBdAddr2Str(pAdvRpt->addr));

The code builds without error but the values logged are random

I have tried using Log_Buf as well but similar thing is happening with that as well.

Thanks,

Garvit

  • Hi Garvit,

    Thank you for reaching out.

    With "%s", Log_printf can only prints constant strings. I would then suggest to print the Bluetooth address byte-byte (instead of all at once).

    Notes:

    - it looks like the value printed for RSSI is correct. 4294967258 = 0xFFFF FFDA corresponding to -38

    - the value printed for the address may be the address of the variable in RAM (536890212 = 0x20004B64)

    I hope this will help,

    Best regards,

  • Hello Clement,

    Thanks for pointing out the right way to interpret the results.

    Is there a way we can modify the number of arguments allowed to be logged in single log_printf statement ? 

    The issue is in logging the address byte by byte - If I want to log the address in a single log_printf statement I need 6 arguments to be logged but there are only 4 arguments space in ROV. 

    The code I used for logging is - 

     Log_printf(LogModule_App1, Log_INFO, "RSSI = %d Address = %d %d %d %d %d %d",pAdvRpt->rssi,pAdvRpt->addr[0],pAdvRpt->addr[1],pAdvRpt->addr[2],pAdvRpt->addr[3],pAdvRpt->addr[4],pAdvRpt->addr[5]);

    Also, please let me know if this is the best way to log this information or should I be using some other approach like using the BLE_LOG_INT functions ?

    Output - 

    Thanks,

    Garvit

  • Hi Garvit,

    In this case, I would recommend using the Log_buf function. The code below should do the trick:

    Fullscreen
    1
    Log_buf(LogModule_App1, Log_INFO, "Address: ", pAdvRpt->addr, 6);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    [EDITED]

    Let me know your results.

    Regards,

  • Hello Clement,

    There seems to be some error in -  Log_buf(LogModule_App1, Log_INFO, pAdvRpt->addr, 6);

    Error - Too too few arguments provided to function-like macro invocation

    syntax -  Log_buf(LogModule_App1, Log_INFO, "The contents of bufferToLog are: ",pAdvRpt->rssi, 6);

    This syntax was not able to load data to arguments

    produced following results - 

    I tried using - Log_buf(LogModule_App1, Log_INFO, "The contents of bufferToLog are: ",pAdvRpt->rssi[1], 6);

    to see if this changes the argument to non zero value but this also produced error.

    Thanks,

    Garvit

  • Hi Garvit,

    Sorry I forgot one argument - I have updated my previous message with a fix.

    I tried using - Log_buf(LogModule_App1, Log_INFO, "The contents of bufferToLog are: ",pAdvRpt->rssi[1], 6);

    If I may, it looks like you pass a value (not a pointer) as 4th argument. I would rather suggest: Log_buf(LogModule_App1, Log_INFO, "The contents of bufferToLog are: ",&(pAdvRpt->rssi[1]), 6);

    Can you try this for me?

    Regards,

  • Hello Clement,

    Thanks a lot, It worked. I still have some doubt though, If I make use of %x in Log_printf, the message is printed in hex format although the arguments are stored in unsigned integer format as shown in image below -

    1) Is there a way to print -94 in front of RSSI in message box ?

    2) Also, Is there a way we can display the address in hex format under the message tab in Log_buf ?

    I do understand that since we are passing an address here so directly writing %x won't work.

    The output for the syntax - Log_buf(LogModule_App1, Log_INFO, "The address of device is : ",&(pAdvRpt->addr), 6);

    The output format I am looking for in message is - "The address of device is: 0x5B4C01450AE3"

    Thanks,

    Garvit

  • Hi Garvit,

    Great to see your progress.

    I have run your results by my colleagues in the R&D team. I am afraid the current version of the Log driver will not get you much better display. We will work to improve this and make it more user friendly in future releases.

    In the mean time, you can consider slightly modifying the Log driver so you can modify the way the in Log_printf function displays the messages. I could not run proper testing so far (I do not have the right boards with me), but modifying the function rsprintf the file <SDK>\source\ti\log\LogSinkBuf.rov.js you can modify the way the parameters "%d" are interpreted.
    For example, you could create the parameter "%i" so the passed argument will be interpreted as a signed integer. To do so, add the following code in the switch within rsprintf:

    Fullscreen
    1
    2
    3
    4
    5
    case 'i': val = parseInt(args[i]);
    if(temp & 0x80000000)
    {
    val = val - 0x100000000;
    }; break;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Then, you should call Log_printf as following: Log_printf(LogModule_App1, Log_INFO, "RSSI = %i",pAdvRpt->rssi);

    Let me know your results and I'll try to help for a way to display the BLE address in a better way as well.

    Kind regards,

  • Hello Clement,

    I have added the code as you suggested and removed the older log project from workspace and reloaded it to CCS.

    The results using %i are not coming as expected. Do I need to do some other changes as well ?

    Output - 

    Thanks,

    Garvit

  • Hi Garvit,

    I have asked for some internal inputs that I haven't received yet.

    Please give me a bit more time (mid-week next week to come back to you).

    Thank you for your comprehension.

    Best regards,

  • Hi Garvit,

    The issue is likely due to forgetting to update the value of the regex variable at the beginning of the rsprintf function.

    Here is the code I use:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    function rsprintf(fmt, args)
    {
    var regex = /%([scdifx%])/g; // This line should be updated when adding new "cases"
    var i = -1;
    function reparg(match, p)
    {
    if (match == '%%') return ('%');
    if (args[++i] === undefined) return (undefined);
    var val;
    switch (p) {
    case 's':
    val = String(Program.ofReader.findString(args[i]));
    break;
    case 'c':
    val = String.fromCharCode(args[i]);
    break;
    case 'd':
    val = parseInt(args[i]);
    break;
    case 'i':
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Note: To see the changes from LogSinkrBuf.rov.js to apply, you only have to close and reopen the ROV window. You don't even have to close your debugging session.

    I hope this will help,

    Best regards,

  • Hi again,

    I have a suggestion for you to display a Bluetooth LE address.

    Here is the embedded code:

    Fullscreen
    1
    2
    3
    4
    5
    // Addr: 11-22-33-44-55-66 displayed as 0x665544332211
    static int B_adr_low = 0x55669999;
    static int B_adr_high = 0x11223344;
    Log_printf(LogModule_App1, Log_DEBUG, "BLE Addr: %A%B", B_adr_low, B_adr_high);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    And here is the code I use in rsprintf (in LogSinkrBuf.rov.js):

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    function rsprintf(fmt, args)
    {
    var regex = /%([scdifxAB%])/g;
    var i = -1;
    function reparg(match, p)
    {
    if (match == '%%') return ('%');
    if (args[++i] === undefined) return (undefined);
    var val;
    switch (p) {
    case 's':
    val = String(Program.ofReader.findString(args[i]));
    break;
    case 'c':
    val = String.fromCharCode(args[i]);
    break;
    case 'd':
    val = parseInt(args[i]);
    break;
    case 'i':
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Note: The solution I have suggested will not work properly for the addresses starting with "0x00" (the two zeroes will not be displayed).

    As you can see, the display is pretty configurable!

    Please let me know your thoughts!

    Best regards,

  • Hi Clement,

    Thanks for the help. The code does function as expected now. 0x00 won't be a problem as the devices I want to detect as of now are assigned a static address starting from CA, CB and so on.

    Thanks,

    Garvit