-2

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.

Clifford
  • 88,407
  • 13
  • 85
  • 165
john
  • 1
  • 3
  • 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. – Paul Ogilvie Oct 04 '19 at 13:20
  • No there is a connection, here the frequency is sorted with a spacing of .360. when a user selects channel 1 , instead of giving the frequency in the sorted order , it maps to the channel 20, which will be channel 1 in user side , but in back end it is channel 20 – john Oct 04 '19 at 13:21
  • I have edited it to make it more clear – john Oct 04 '19 at 13:30
  • But....is there a relation from the RAIL channel to the Flash channel? As per your question> Anyway, take a look at my solution. – Paul Ogilvie Oct 04 '19 at 13:30
  • hi paul, very helpful one ,if i want only the flash and radio channel to be mapped, how to do that? – john Oct 04 '19 at 13:58
  • Just delete the fields not needed from `myTable`. With the examples in my solution you can map RAIL ont Flash and vice versa. – Paul Ogilvie Oct 04 '19 at 14:01
  • If you give me clear function names, I can show you, e,g. the `getFlashFromRAIL` and `getRAILFromFlash` function names. – Paul Ogilvie Oct 04 '19 at 14:04
  • getrailfromflash() is the function, from the user side, if i select 1 as input , it should map me to the 16th in rail channel. – john Oct 04 '19 at 14:19
  • if I select 5 as input, it should map me to 22 in railchannel – john Oct 04 '19 at 14:20
  • That would be function `getRAILFromFlash` as (I assume) your input "5" is a Flash channel number. – Paul Ogilvie Oct 04 '19 at 14:27
  • I am sorry for this naive doubt - inside the struct You have called mytable[], but in getrailfrom function(), it is throwing up error like it is not identified – john Oct 04 '19 at 14:37
  • My error (too quick posting the code). Should have been `return myTableInv[Flash];` Updated the solution. – Paul Ogilvie Oct 04 '19 at 14:45
  • thank you for your patience, its still throwing up error when i do the following struct { int flash }mytable[] ={20,25,18....29} }; – john Oct 04 '19 at 14:56
  • Because it is a table of `struct`s, you must enclose each entry in curly braces. So for what you want it is sufficient to have `int mytable[] ={0, 20, 25...};` AND you must add a first entry of zero! (See note at end of my solution.) – Paul Ogilvie Oct 04 '19 at 15:07
  • Does it work now as you want? – Paul Ogilvie Oct 04 '19 at 15:25
  • I created two arrays for both the channel, mapped it using for loop for(int i=1;i<=32;i++) { if(table[i] ==flashvalue) { return mytable[j]} what do you think? – john Oct 04 '19 at 15:29
  • is there any effective approach? – john Oct 04 '19 at 15:32
  • That is a search. But I gave you a lookup. If you look for the `RAILvalue` using the `flashvalue`, then just do `return mytable[flashvalue];` I will post an update to my solution to show you. – Paul Ogilvie Oct 04 '19 at 15:33

1 Answers1

0

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.

Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41