Просмотр исходного кода

add:lora添加rateOptimize配置参数

Dozingfiretruck 2 лет назад
Родитель
Сommit
ccdcc5540f

+ 14 - 4
components/lora/luat_lib_lora.c

@@ -307,7 +307,7 @@ static int luat_lora_set_txconfig(lua_State *L){
     if(strcmp("llcc68",lora_ic)== 0||strcmp("LLCC68",lora_ic)== 0||strcmp("sx1268",lora_ic)== 0||strcmp("SX1268",lora_ic)== 0){
         uint8_t mode = 1,power = 0,fdev = 0,bandwidth = 0,datarate = 9,coderate = 4,preambleLen = 8,freqHopOn = 0,hopPeriod = 0;
         uint32_t timeout = 0;
-        bool fixLen = false,crcOn = true,iqInverted = false;
+        bool fixLen = false,crcOn = true,iqInverted = false,rateOptimize = false;
 
         if (lua_istable(L, 2)) {
             lua_pushstring(L, "mode");
@@ -376,11 +376,16 @@ static int luat_lora_set_txconfig(lua_State *L){
                 timeout = luaL_optinteger(L, -1,3000);
             }
             lua_pop(L, 1);
+            lua_pushstring(L, "rateOptimize");
+            if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
+                rateOptimize = lua_toboolean(L, -1);
+            }
+            lua_pop(L, 1);
         }
         Radio.SetTxConfig( mode, power, fdev, bandwidth,
                             datarate, coderate,
                             preambleLen, fixLen,
-                            crcOn, freqHopOn, hopPeriod, iqInverted, timeout );
+                            crcOn, freqHopOn, hopPeriod, iqInverted, timeout ,rateOptimize);
     }
     else {
         LLOGE("no such ic %s", lora_ic);
@@ -419,7 +424,7 @@ static int luat_lora_set_rxconfig(lua_State *L){
     if(strcmp("llcc68",lora_ic)== 0||strcmp("LLCC68",lora_ic)== 0||strcmp("sx1268",lora_ic)== 0||strcmp("SX1268",lora_ic)== 0){
         uint8_t mode = 1,bandwidth = 0,datarate = 9,coderate = 4,bandwidthAfc = 0,preambleLen = 8,symbTimeout = 0,payloadLen = 0,freqHopOn = 0,hopPeriod = 0;
         uint32_t frequency = 433000000,timeout = 0;
-        bool fixLen = false,crcOn = true,iqInverted = false,rxContinuous = false;
+        bool fixLen = false,crcOn = true,iqInverted = false,rxContinuous = false,rateOptimize = false;
 
         if (lua_istable(L, 2)) {
             lua_pushstring(L, "mode");
@@ -492,12 +497,17 @@ static int luat_lora_set_rxconfig(lua_State *L){
                 rxContinuous = lua_toboolean(L, -1);
             }
             lua_pop(L, 1);
+            lua_pushstring(L, "rateOptimize");
+            if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
+                rateOptimize = lua_toboolean(L, -1);
+            }
+            lua_pop(L, 1);
         }
 
         Radio.SetRxConfig( mode, bandwidth, datarate,
                             coderate, bandwidthAfc, preambleLen,
                             symbTimeout, fixLen,
-                            payloadLen, crcOn, freqHopOn, hopPeriod, iqInverted, rxContinuous );
+                            payloadLen, crcOn, freqHopOn, hopPeriod, iqInverted, rxContinuous ,rateOptimize);
     }
     else {
         LLOGE("no such ic %s", lora_ic);

+ 27 - 19
components/lora/sx126x/radio.c

@@ -124,7 +124,7 @@ void RadioSetRxConfig( RadioModems_t modem, uint32_t bandwidth,
                           uint16_t symbTimeout, bool fixLen,
                           uint8_t payloadLen,
                           bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
-                          bool iqInverted, bool rxContinuous );
+                          bool iqInverted, bool rxContinuous ,bool LowDatarateOptimize);
 
 /*!
  * \brief Sets the transmission parameters
@@ -165,7 +165,7 @@ void RadioSetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
                           uint32_t bandwidth, uint32_t datarate,
                           uint8_t coderate, uint16_t preambleLen,
                           bool fixLen, bool crcOn, bool FreqHopOn,
-                          uint8_t HopPeriod, bool iqInverted, uint32_t timeout );
+                          uint8_t HopPeriod, bool iqInverted, uint32_t timeout ,bool LowDatarateOptimize);
 
 /*!
  * \brief Checks if the given RF frequency is supported by the hardware
@@ -614,7 +614,7 @@ void RadioSetRxConfig( RadioModems_t modem, uint32_t bandwidth,
                          uint16_t symbTimeout, bool fixLen,
                          uint8_t payloadLen,
                          bool crcOn, bool freqHopOn, uint8_t hopPeriod,
-                         bool iqInverted, bool rxContinuous )
+                         bool iqInverted, bool rxContinuous ,bool LowDatarateOptimize)
 {
 
     RxContinuous = rxContinuous;
@@ -673,16 +673,20 @@ void RadioSetRxConfig( RadioModems_t modem, uint32_t bandwidth,
             SX126x.ModulationParams.Params.LoRa.Bandwidth = Bandwidths[bandwidth];
             SX126x.ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t )coderate;
 
-            if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
-            ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
-            {
+            if (LowDatarateOptimize){
                 SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
+            }else{
+                if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+                ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
+                {
+                    SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
+                }
+                else
+                {
+                    SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+                }
             }
-            else
-            {
-                SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
-            }
-
+            
             SX126x.PacketParams.PacketType = PACKET_TYPE_LORA;
 
             if( ( SX126x.ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF5 ) ||
@@ -723,7 +727,7 @@ void RadioSetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
                         uint32_t bandwidth, uint32_t datarate,
                         uint8_t coderate, uint16_t preambleLen,
                         bool fixLen, bool crcOn, bool freqHopOn,
-                        uint8_t hopPeriod, bool iqInverted, uint32_t timeout )
+                        uint8_t hopPeriod, bool iqInverted, uint32_t timeout ,bool LowDatarateOptimize)
 {
 
     switch( modem )
@@ -767,14 +771,18 @@ void RadioSetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
             SX126x.ModulationParams.Params.LoRa.Bandwidth =  Bandwidths[bandwidth];
             SX126x.ModulationParams.Params.LoRa.CodingRate= ( RadioLoRaCodingRates_t )coderate;
 
-            if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
-            ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
-            {
+            if (LowDatarateOptimize){
                 SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
-            }
-            else
-            {
-                SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+            }else{
+                if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+                ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
+                {
+                    SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
+                }
+                else
+                {
+                    SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+                }
             }
 
             SX126x.PacketParams.PacketType = PACKET_TYPE_LORA;

+ 2 - 2
components/lora/sx126x/radio.h

@@ -191,7 +191,7 @@ struct Radio_s
                               uint16_t symbTimeout, bool fixLen,
                               uint8_t payloadLen,
                               bool crcOn, bool freqHopOn, uint8_t hopPeriod,
-                              bool iqInverted, bool rxContinuous );
+                              bool iqInverted, bool rxContinuous ,bool LowDatarateOptimize);
     /*!
      * \brief Sets the transmission parameters
      *
@@ -231,7 +231,7 @@ struct Radio_s
                               uint32_t bandwidth, uint32_t datarate,
                               uint8_t coderate, uint16_t preambleLen,
                               bool fixLen, bool crcOn, bool freqHopOn,
-                              uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
+                              uint8_t hopPeriod, bool iqInverted, uint32_t timeout ,bool LowDatarateOptimize);
     /*!
      * \brief Checks if the given RF frequency is supported by the hardware
      *

+ 14 - 4
components/lora2/luat_lib_lora.c

@@ -268,7 +268,7 @@ lora_device:set_txconfig(
 static int luat_lora_set_txconfig(lua_State *L){
     uint8_t mode = 1,power = 0,fdev = 0,bandwidth = 0,datarate = 9,coderate = 4,preambleLen = 8,freqHopOn = 0,hopPeriod = 0;
     uint32_t timeout = 0;
-    bool fixLen = false,crcOn = true,iqInverted = false;
+    bool fixLen = false,crcOn = true,iqInverted = false,rateOptimize = false;
     lora_device_t  * lora_device = get_lora_device(L);
 
     if (lua_istable(L, 2)) {
@@ -338,12 +338,17 @@ static int luat_lora_set_txconfig(lua_State *L){
             timeout = luaL_optinteger(L, -1,3000);
         }
         lua_pop(L, 1);
+        lua_pushstring(L, "rateOptimize");
+        if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
+            rateOptimize = lua_toboolean(L, -1);
+        }
+        lua_pop(L, 1);
     }
     
     Radio2.SetTxConfig( lora_device,mode, power, fdev, bandwidth,
                         datarate, coderate,
                         preambleLen, fixLen,
-                        crcOn, freqHopOn, hopPeriod, iqInverted, timeout );
+                        crcOn, freqHopOn, hopPeriod, iqInverted, timeout ,rateOptimize);
 
     return 0;
 }
@@ -375,7 +380,7 @@ lora_device:set_rxconfig(
 static int luat_lora_set_rxconfig(lua_State *L){
     uint8_t mode = 1,bandwidth = 0,datarate = 9,coderate = 4,bandwidthAfc = 0,preambleLen = 8,symbTimeout = 0,payloadLen = 0,freqHopOn = 0,hopPeriod = 0;
     uint32_t frequency = 433000000,timeout = 0;
-    bool fixLen = false,crcOn = true,iqInverted = false,rxContinuous = false;
+    bool fixLen = false,crcOn = true,iqInverted = false,rxContinuous = false,rateOptimize = false;
     lora_device_t  * lora_device = get_lora_device(L);
     if (lua_istable(L, 2)) {
         lua_pushstring(L, "mode");
@@ -448,12 +453,17 @@ static int luat_lora_set_rxconfig(lua_State *L){
             rxContinuous = lua_toboolean(L, -1);
         }
         lua_pop(L, 1);
+        lua_pushstring(L, "rateOptimize");
+        if (LUA_TBOOLEAN == lua_gettable(L, 2)) {
+            rateOptimize = lua_toboolean(L, -1);
+        }
+        lua_pop(L, 1);
     }
 
     Radio2.SetRxConfig( lora_device,mode, bandwidth, datarate,
                         coderate, bandwidthAfc, preambleLen,
                         symbTimeout, fixLen,
-                        payloadLen, crcOn, freqHopOn, hopPeriod, iqInverted, rxContinuous );
+                        payloadLen, crcOn, freqHopOn, hopPeriod, iqInverted, rxContinuous ,rateOptimize);
 
     return 0;
 }

+ 26 - 18
components/lora2/sx126x/radio.c

@@ -124,7 +124,7 @@ static void RadioSetRxConfig( lora_device_t* lora_device,RadioModems_t modem, ui
                           uint16_t symbTimeout, bool fixLen,
                           uint8_t payloadLen,
                           bool crcOn, bool FreqHopOn, uint8_t HopPeriod,
-                          bool iqInverted, bool rxContinuous );
+                          bool iqInverted, bool rxContinuous ,bool LowDatarateOptimize);
 
 /*!
  * \brief Sets the transmission parameters
@@ -165,7 +165,7 @@ static void RadioSetTxConfig( lora_device_t* lora_device,RadioModems_t modem, in
                           uint32_t bandwidth, uint32_t datarate,
                           uint8_t coderate, uint16_t preambleLen,
                           bool fixLen, bool crcOn, bool FreqHopOn,
-                          uint8_t HopPeriod, bool iqInverted, uint32_t timeout );
+                          uint8_t HopPeriod, bool iqInverted, uint32_t timeout ,bool LowDatarateOptimize);
 
 /*!
  * \brief Checks if the given RF frequency is supported by the hardware
@@ -600,7 +600,7 @@ static void RadioSetRxConfig( lora_device_t* lora_device,RadioModems_t modem, ui
                          uint16_t symbTimeout, bool fixLen,
                          uint8_t payloadLen,
                          bool crcOn, bool freqHopOn, uint8_t hopPeriod,
-                         bool iqInverted, bool rxContinuous )
+                         bool iqInverted, bool rxContinuous ,bool LowDatarateOptimize)
 {
 
     lora_device->RxContinuous = rxContinuous;
@@ -659,14 +659,18 @@ static void RadioSetRxConfig( lora_device_t* lora_device,RadioModems_t modem, ui
             lora_device->SX126x.ModulationParams.Params.LoRa.Bandwidth = Bandwidths[bandwidth];
             lora_device->SX126x.ModulationParams.Params.LoRa.CodingRate = ( RadioLoRaCodingRates_t )coderate;
 
-            if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
-            ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
-            {
+            if (LowDatarateOptimize){
                 lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
-            }
-            else
-            {
-                lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+            }else{
+                if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+                ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
+                {
+                    lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
+                }
+                else
+                {
+                    lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+                }
             }
 
             lora_device->SX126x.PacketParams.PacketType = PACKET_TYPE_LORA;
@@ -709,7 +713,7 @@ static void RadioSetTxConfig( lora_device_t* lora_device,RadioModems_t modem, in
                         uint32_t bandwidth, uint32_t datarate,
                         uint8_t coderate, uint16_t preambleLen,
                         bool fixLen, bool crcOn, bool freqHopOn,
-                        uint8_t hopPeriod, bool iqInverted, uint32_t timeout )
+                        uint8_t hopPeriod, bool iqInverted, uint32_t timeout ,bool LowDatarateOptimize)
 {
 
     switch( modem )
@@ -753,14 +757,18 @@ static void RadioSetTxConfig( lora_device_t* lora_device,RadioModems_t modem, in
             lora_device->SX126x.ModulationParams.Params.LoRa.Bandwidth =  Bandwidths[bandwidth];
             lora_device->SX126x.ModulationParams.Params.LoRa.CodingRate= ( RadioLoRaCodingRates_t )coderate;
 
-            if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
-            ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
-            {
+            if (LowDatarateOptimize){
                 lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
-            }
-            else
-            {
-                lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+            }else{
+                if( ( ( bandwidth == 0 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
+                ( ( bandwidth == 1 ) && ( datarate == 12 ) ) )
+                {
+                    lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x01;
+                }
+                else
+                {
+                    lora_device->SX126x.ModulationParams.Params.LoRa.LowDatarateOptimize = 0x00;
+                }
             }
 
             lora_device->SX126x.PacketParams.PacketType = PACKET_TYPE_LORA;

+ 2 - 2
components/lora2/sx126x/radio.h

@@ -194,7 +194,7 @@ struct Radio_s
                               uint16_t symbTimeout, bool fixLen,
                               uint8_t payloadLen,
                               bool crcOn, bool freqHopOn, uint8_t hopPeriod,
-                              bool iqInverted, bool rxContinuous );
+                              bool iqInverted, bool rxContinuous ,bool LowDatarateOptimize);
     /*!
      * \brief Sets the transmission parameters
      *
@@ -234,7 +234,7 @@ struct Radio_s
                               uint32_t bandwidth, uint32_t datarate,
                               uint8_t coderate, uint16_t preambleLen,
                               bool fixLen, bool crcOn, bool freqHopOn,
-                              uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
+                              uint8_t hopPeriod, bool iqInverted, uint32_t timeout ,bool LowDatarateOptimize);
     /*!
      * \brief Checks if the given RF frequency is supported by the hardware
      *