cembeddedsoftware-designfirmwaresimplicity-studio

need a help in what algorithmic way to approach this problem


I am working on SUB-GHZ frequency range for transmitting and receiving through a radio board.

enter image description here

from the table above if I select Flash Channel- 1 as input, it should map me to the Rail Channel 16.

If I select Flash Channel 20, it should automatically map me to Rail Channel 1.

Can anyone help me here on how to approach it, like some sample coding?

Language used is C.


Solution

  • As there seems no relation between the RAIL channel and the Flash channel, you will need a table that you can index by RAIL channel.

    You have updated your question woth the requirement for the reverse lookup too. This could be done using a secondary table to map flash to raid, then (if needed) lookup the details such as frequency and word in the Raid table:

    struct {
        int Flash;
        double freq;
        DWORD ChannelID;
        //...
    } myTable[] = {     // table indexed by RAIL channel number
        {0, 0.0, 0},
        {20, 340.04, 0x0CCC0CCC},
        {25, 340.40, 0x07C707C7}
        //...
    };
    int getFlashFromRAIL(int RAIL)
    {
        return myTable[RAIL].Flash;
    }
    
    // table of RAIL channel numbers, indexed by Flash channel number
    int myTableInv[] = { 0, 16, 18 /*...*/ };
    
    double getFreqFromFlash(int Flash) // return frequency for Flash channel number
    {
        return myTable[myTableInv[Flash]].freq;
    }
    int getRAILFromFlash(int Flash) // return RAIL channel number for Flash channel number
    {
        return myTableInv[Flash];
    }
    

    Note: As both RAIL and Flash channel numbers start at 1, but C indexes are from 0..n-1, a first entry in each table is added so the channel numbers can be used to index the arrays.

    EDIT

    Given our discussion in the comments, the following is the simplified solution:

    int RAIL2Flash_table[] = {0, 20, 25, 19 /*...*/};
    int Flash2RAIL_table[] = {0, 16, 18, 20 /*...*/};
    
    int RAIL2Flash(int RAIL)
    {
        return RAIL2Flash_table[RAIL];
    }
    int Flash2RAIL(int Flash)
    {
        return Flash2RAIL_table[Flash];
    }
    

    So each entry x of the RAIL2Flash_table has a RAIL channel number corresponding to the index x. So RAIL channel 1 is in the array entry 1 and has Flash channel number 20, etceter. The same for the other table.