Thread: TX/RX Beacon UART

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    8

    TX/RX Beacon UART

    Hi,

    im currently working on a project where a TX sends a packet, the packet is picked up by the RX and the RX echoes back another packet. The echoed packet is picked up by the TX, and the signal strength and echoed packet is then sent through UART to a Single board computer as a string.

    As the signal strength is inconsistent, i am trying to get the average of 3 of the same packets before sending the information through the UART. I am really new to C programming and I hope yall can help!

    this is part of my code: (rssi is the signal strength)

    insert
    Code:
     /* Check the packet against what was transmitted */
            int16_t status = memcmp(returnCheck, rxPacket, checkLength);
    
    
    
    
    
    
            if(status == 0)
            {
                /* Toggle LED1, clear LED2 to indicate RX */
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED1,
                                   !PIN_getOutputValue(Board_PIN_LED1));
                PIN_setOutputValue(ledPinHandle, Board_PIN_LED2, 0);
    
    
                char buff[20];  // take a chance that 10 is always enough
                sprintf(buff,"%s %d",rxPacket,RSSIout);
                UART_write(uart, buff, strlen(buff));
    
    
    
    
            }

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    881
    You could use error detection and error connecttion algorithms if you have issues with the signal:

    Error Detection
    Error Correction
    Reed Solomon Codes
    Error Correction & International Book Codes

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,908
    So just to clarify, you want a function that returns the average value of the last 3 readings?

    That's easy enough to achieve

    I suggest that you give it a go and post what you have come up with if you have any problems

    To get you started, have a look at this tutorial

    Functions in C - Cprogramming.com

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,708
    So why did you jump forum?
    Texas Instrument CC1350 UART for RSSI si - C++ Forum

    Let's say your RSSI is an int, since you format it as one.

    So you want an average of three.
    Code:
    int rawRSSI[3];
    int numSamples = 0;
    So your first step is
    Code:
    rawRSSI[numSamples++] = receivedRSSI;   // you didn't show how this arrives.
    You then say
    Code:
    if ( numSamples == 3 ) {
        int avgRSSI = ( rawRSSI[0] + rawRSSI[1] + rawRSSI[2] ) / 3;
        char buff[20];  // take a chance that 10 is always enough
        sprintf(buff,"%s %d",rxPacket,avgRSSI);
        UART_write(uart, buff, strlen(buff));
    }
    What do you want to happen next?
    - Throw away all the samples, get three more and then output another average.
    - Throw away the oldest sample, get one more sample, and output a moving average.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    thank you all for the advice!

    Hi salem nice to hear from you again! came to this forum as it was for C.

    This is what i want to do:
    Throw away all the samples, get three more and then output another average.

    But my problem arrises as i may have multiple RX packets coming in with different RSSI values.


    Quote Originally Posted by Salem View Post
    So why did you jump forum?
    Texas Instrument CC1350 UART for RSSI si - C++ Forum

    Let's say your RSSI is an int, since you format it as one.

    So you want an average of three.
    Code:
    int rawRSSI[3];
    int numSamples = 0;
    So your first step is
    Code:
    rawRSSI[numSamples++] = receivedRSSI;   // you didn't show how this arrives.
    You then say
    Code:
    if ( numSamples == 3 ) {
        int avgRSSI = ( rawRSSI[0] + rawRSSI[1] + rawRSSI[2] ) / 3;
        char buff[20];  // take a chance that 10 is always enough
        sprintf(buff,"%s %d",rxPacket,avgRSSI);
        UART_write(uart, buff, strlen(buff));
    }
    What do you want to happen next?
    - Throw away all the samples, get three more and then output another average.
    - Throw away the oldest sample, get one more sample, and output a moving average.

  6. #6
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    Thank you all for the constructive input!

    Hi salem good to hear from you again!
    i came to this forum as it was C specific.

    I want to do this:
    Throw away all the samples, get three more and then output another average.

    But the issue i face now is that i have multiple RXs that send Multiple RX packets to the TX with different RSSI values.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,708
    Most people only worry about RSSI (Received Signal Strength Indication) when it drops below some lower threshold for some period of time.
    Received signal strength indication - Wikipedia

    Other than that, it's just a pretty up and down bar graph / line to give the user a warm fuzzy feeling.

    > I want to do this:
    > Throw away all the samples, get three more and then output another average.
    So just reset the counter back to 0 after each send.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    I am actually using the RSSI value to measure distance! and so far it has proven quite accurate!
    My objective is to send the RX packet and the distance to the RX

  9. #9
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    Hi didnt want to start a new thread and i was hoping any of yall could help!

    the code:
    Code:
    if ( numSamples == 3 ) {    int avgRSSI = ( rawRSSI[0] + rawRSSI[1] + rawRSSI[2] ) / 3;
        char buff[20];  // take a chance that 10 is always enough
        sprintf(buff,"%s %d",rxPacket,avgRSSI);
        UART_write(uart, buff, strlen(buff));
    }
    Works great but now i have an issue. I want to flush all the results out if i dont receive 3 signals within 5 seconds.
    So after 5 seconds lets say i only receive two rawRSSI, i want to flush the current two rawRSSI and restart the process

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,708
    So what sort of clocks and timers do you have on your machine?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    sorry im not to familiar with what kind of clock is on my board but i am using a Texas Instrument CC1350 launchpad

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,708
    Well it boils down to whether you have a real operating system running on the board, such as
    http://www.ti.com/tool/ti-15.4-stack-gateway-linux-sdk

    Or whether it's just a bare board and the only s/w running on it is your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    Its just a bare board running my code! my board is connected to a single board computer

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,708
    So is UART_write() some library you link with, or did you also write that yourself?

    What about PIN_setOutputValue(), is that a library or something you wrote?

    Anyway, the point is, you need to start reading your documentation or post DIRECT links to where it can be found online.
    Nobody is going to play "20 questions" with you to tease out this information from you.

    > Its just a bare board running my code!
    On the assumption you know what you're taking about, try searching for "timer interrupt" in your documentation.
    You need to
    - figure out how to enable a timer interrupt.
    - figure out how to set an interval period (5 seconds).
    - figure out how to attach the timer interrupt to some of your code. Some compilers allow you to say things like
    Code:
    void ISR(n) timerInterrupt(void) {
      // some code to execute as an Interrupt Service Routine (ISR)
      // n being the interrupt number
    }
    - figure out how to reset the interval if you get the required number of samples within the time limit.

    You also need to be aware that an ISR may be a restricted environment, so you might not be able to call UART_write() directly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  15. #15
    Registered User
    Join Date
    Mar 2019
    Posts
    8
    My apologies for the vague posts, still pretty new to the forums. But thanks for all the help so far Salem, much of my project has to be credited to you.

    http://www.ti.com/lit/ug/swcu117h/swcu117h.pdf - this is the technical manual for the board i am using. I have previously read up on the timer function (page 1188) but i have failed to implement it in my system.

    http://dev.ti.com/tirex/content/simp...26_x_x_8h.html - this is an example provided by the manufacturer of the board

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Uart communication
    By Silli in forum C Programming
    Replies: 4
    Last Post: 04-28-2016, 11:04 AM
  2. Uart psoc3
    By MacJ in forum C Programming
    Replies: 5
    Last Post: 09-26-2015, 07:34 AM
  3. capturing beacon frames on my wireless card
    By nabi in forum Networking/Device Communication
    Replies: 1
    Last Post: 12-08-2010, 04:29 PM

Tags for this Thread