需要以哪种算法来解决此问题的帮助

时间:2019-10-04 13:18:03

标签: c embedded software-design firmware simplicity-studio

我正在研究SUB-GHZ频率范围,以便通过无线电板进行发送和接收。

enter image description here

如果我选择Flash Channel-1作为输入,请从上表中将其映射到Rail Channel 16。

如果我选择Flash Channel 20,它将自动将我映射到Rail Channel 1。

有人可以在这里帮助我,例如一些示例代码吗?

使用的语言为C。

1 个答案:

答案 0 :(得分:0)

由于RAIL通道和Flash通道之间似乎没有关系,因此您将需要一个可以按RAIL通道索引的表。

您已经更新了问题,这也要求进行反向查找。可以使用辅助表将Flash映射到RAID,然后(如果需要)在Raid表中查找诸如频率和单词之类的详细信息:

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];
}

注意:由于RAIL和Flash通道号均从1开始,但C索引来自0..n-1,因此将在每个表中添加第一个条目,以便可以使用通道号来索引数组。

编辑

鉴于我们在评论中的讨论,以下是简化的解决方案:

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];
}

因此x的每个条目RAIL2Flash_table都有一个与索引RAIL对应的x频道号。因此,RAIL通道1在数组条目1中,并且具有Flash通道号20,以此类推。其他表也一样。