JoToSystems / LoraPacketForwarder

Modified LoraPacket Forwarder to correct rejection on Transmit Power mismatch
3 stars 1 forks source link

Source Code #2

Open lorencosantos opened 4 years ago

lorencosantos commented 4 years ago

Hi! Can you provide de source code modification please? I need to compile this to armv7ahf-neon to run on a Toradex Colibri VF61

descartes commented 4 years ago

Me too - plus I can't install this on client machines without knowing how the code has changed!

lorencosantos commented 4 years ago

in the section "/ check TX parameter before trying to queue packet /

        if (jit_result == JIT_ERROR_OK) {
            for (i=0; i<txlut.size; i++) {
                if (txlut.lut[i].rf_power == txpkt.rf_power)
                {
                    /* this RF power is supported, we can continue */
                    txpkt.rf_power = txlut.lut[i].rf_power;
                    MSG("INFO: == used txlut index:%d\n", i);
                    break;
                }
                else if (txlut.lut[i].rf_power > txpkt.rf_power) {
                    if (0 != i)
                    {
                        MSG("INFO: >= used txlut index:%d. __1\n", i - 1);
                        MSG("WARNING: network-server wants to use powe = %d, and actually uses powd = %d\n", txpkt.rf_power, txlut.lut[i - 1].rf_power);
                        txpkt.rf_power = txlut.lut[i - 1].rf_power;
                    }
                    else
                    {
                        MSG("INFO: >= used txlut index:%d. __2\n", i);
                        MSG("WARNING: network-server wants to use powe = %d, and actually uses powd = %d\n", txpkt.rf_power, txlut.lut[0].rf_power);
                        txpkt.rf_power = txlut.lut[0].rf_power;
                    }
                    break;
                }
            }
            if (i == txlut.size) {
                /* Exceeding maximum power, use maximum power */
                MSG("WARNING: power for TX - %d exceeding maximum power - , use maximum power - %d\n", txpkt.rf_power, txlut.lut[txlut.size - 1].rf_power, txlut.lut[txlut.size - 1].rf_power);
                txpkt.rf_power = txlut.lut[txlut.size - 1].rf_power;
                MSG("INFO: >= used txlut index:%d. __3\n", txlut.size - 1);
            }
        }
tonysmith55 commented 4 years ago

The compiled Packet Forwarder is built from two separate packages, one being the Packet Forwarder and the second the Lora HAL which control the radio module. Both modules include a check on Tx power which means one is redundant. The Lora HAL works correctly, if the Tx Power does not exactly match an entry in the TxLut table, it selects the next lowest power. The Packet Forwarder when it performed its check rejects the packet if there was not a 100% match between Tx Power and a Tx_lut table entry. Since there is duplication I simply bypassed the check in the Packet Forwarder and allowed the Lora HAL to perform the check and select the next lowest power. While about it i found there was no check to ensure the Tx_lut entries are in ascending order of magnitude. I've added a test at startup otherwise the Lora HAL would not work correctly. Hope this clarifies the change I should also explain, the Tx Power sent to the radio is calculated to be the powe parameter sent from the Lora Server - Antenna Gain. This means if antenna gain is no longer zero but set to be say 5dBi then there is a good chance the resultant Tx Power would not find a match in the Tx_lut table

tonysmith55 commented 4 years ago

Similar description of the problem and solution can be found at https://www.thethingsnetwork.org/forum/t/error-packet-rejected-unsupported-rf-power-for-tx-24/34833/14 Also of interest, the problem does not existing in the SX1302 UDP packet forwarder. Similar to my solution, it has one test and selects the next lowest power.