소스 검색

未修改完

xuxinyi 4 달 전
부모
커밋
ffc5338aa5
4개의 변경된 파일250개의 추가작업 그리고 2개의 파일을 삭제
  1. 31 0
      .vscode/launch.json
  2. 67 2
      drv_periph/sx126x_driver.lua
  3. 150 0
      drv_periph/sx126x_reg.lua
  4. 2 0
      main.lua

+ 31 - 0
.vscode/launch.json

@@ -0,0 +1,31 @@
+{
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "lua",
+            "request": "launch",
+            "tag": "normal",
+            "name": "LuaPanda",
+            "description": "通用模式,通常调试项目请选择此模式 | launchVer:3.2.0",
+            "cwd": "${workspaceFolder}",
+            "luaFileExtension": "",
+            "connectionPort": 8818,
+            "stopOnEntry": true,
+            "useCHook": true,
+            "autoPathMode": true
+        },
+        {
+            "type": "lua",
+            "request": "launch",
+            "tag": "independent_file",
+            "name": "LuaPanda-IndependentFile",
+            "description": "独立文件调试模式,使用前请参考文档",
+            "luaPath": "",
+            "packagePath": [],
+            "luaFileExtension": "",
+            "connectionPort": 8820,
+            "stopOnEntry": true,
+            "useCHook": true
+        }
+    ]
+}

+ 67 - 2
drv_periph/sx126x_driver.lua

@@ -16,6 +16,8 @@ require"pins"
 require "Drv_spi"
 require "sx126x_reg"
 
+local SX126x = sx126x_reg.SX126x_t
+
 SX126xResetGPIO = pins.setup(pio.P0_13,0)
 OperatingMode = sx126x_reg.RadioStandbyModes_t.STDBY_RC
 
@@ -135,8 +137,20 @@ function SX126xSetDioIrqParams(timeout, freq, rfChain, power, preambleLen)
     SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_SET_TX,buf)
 end
 
-function RadioStandby()
+function SX126xSetStopRxTimerOnPreambleDetect(enable)
+    SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_SET_STOPRXTIMERONPREAMBLE,{enable})
+end
+
+function SX126xSetLoRaSymbNumTimeout(SymbNum)
+    SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_SET_LORASYMBTIMEOUT,{SymbNum})
+end
+
+function RadioSetTxConfig(modem,power,fdev,bandwidth,datarate,coderate,preambleLen,fixLen,crcOn,freqHopOn,hopPeriod,iqInverted,timeout)
+    SX126xSetStopRxTimerOnPreambleDetect(false)
+    SX126xSetLoRaSymbNumTimeout(0)
+    -- local test = sx126x_reg.SX126x_t
 
+    -- test.ModulationParams_t.RadioPacketTypes_t = sx126x_reg.RadioPacketTypes_t;
 end
 
 -- 初始化SX126x
@@ -208,11 +222,17 @@ end
 --测试案例:测试初始化
 sys.taskInit(function ()
     sys.wait(3000)
-    SX126xInit()
+    -- SX126xInit()
     sys.wait(3000)
+
+    SX126x.ModulationParams.PacketType = sx126x_reg.PACKET_TYPE_LORA;
+
+    log.info("计算结果", SX126x.)
+
     log.info("计算结果", "测试1")
 end)
 
+
 -- --测试案例:拼接buffer
 -- sys.taskInit(function ()
 --     sys.wait(3000)
@@ -221,3 +241,48 @@ end)
 --     log.info("计算结果", "测试1")
 -- end)
 
+-- [I]-[修改前数据]
+-- [I]-[源数据] {"KEY6":[1,2,3],"KEY3":"VALUE3","KEY4":"VALUE4","KEY2":"VALUE2","KEY1":"VALUE1","KEY5":{"KEY5_2":"VALU5_2","KEY5_1":"VALU5_1"}}
+-- [I]-[源数据复制] {"KEY6":[1,2,3],"KEY3":"VALUE3","KEY4":"VALUE4","KEY2":"VALUE2","KEY1":"VALUE1","KEY5":{"KEY5_2":"VALU5_2","KEY5_1":"VALU5_1"}}
+-- [I]-[修改后数据]
+-- [I]-[源数据] {"KEY6":[1,2,3],"KEY3":"VALUE3","KEY4":"VALUE4","KEY2":"VALUE2","KEY1":"VALUE1_1","KEY5":{"KEY5_2":"VALU5_2","KEY5_1":"VALU5_1"}}
+-- [I]-[源数据复制] {"KEY6":[1,2,3],"KEY3":"VALUE3","KEY4":"VALUE4","KEY2":"VALUE2","KEY1":"VALUE1_1","KEY5":{"KEY5_2":"VALU5_2","KEY5_1":"VALU5_1"}}
+-- [I]-[计算结果] 测试1
+-- sys.taskInit(function ()
+--     sys.wait(3000)
+--     -- SX126xInit()
+--     sys.wait(3000)
+
+--     local Person = {
+--         name = "openLuat",
+--         age = 18,
+--         sex = "male",
+--         hobby = {"reading","programming"},
+--     }
+
+--     local torigin =
+--     {
+--         KEY1 = "VALUE1",
+--         KEY2 = "VALUE2",
+--         KEY3 = "VALUE3",
+--         KEY4 = "VALUE4",
+--         KEY5 = {KEY5_1="VALU5_1",KEY5_2="VALU5_2"},
+--         KEY6 = {1,2,3},
+--     }
+--     local torigin_gson = torigin
+--     log.info("修改前数据")   
+--     log.info("源数据",json.encode(torigin))   
+--     log.info("源数据复制",json.encode(torigin_gson))   
+--     log.info("修改后数据")   
+--     torigin_gson.KEY1 = "VALUE1_1"
+--     log.info("源数据",json.encode(torigin))   
+--     log.info("源数据复制",json.encode(torigin_gson))   
+    
+
+
+
+
+
+
+--     log.info("计算结果", "测试1")
+-- end)

+ 150 - 0
drv_periph/sx126x_reg.lua

@@ -37,6 +37,156 @@ RadioRampTimes_t = {
     RADIO_RAMP_3400_US = "07"
 }
 
+RadioPreambleDetection_t = {
+    RADIO_PREAMBLE_DETECTOR_OFF = "00",
+    RADIO_PREAMBLE_DETECTOR_08_BITS = "01",
+    RADIO_PREAMBLE_DETECTOR_16_BITS = "02",
+    RADIO_PREAMBLE_DETECTOR_24_BITS = "03",
+    RADIO_PREAMBLE_DETECTOR_32_BITS = "04"
+}
+
+RadioAddressComp_t = {
+    RADIO_ADDRESSCOMP_FILT_OFF = "00",
+    RADIO_ADDRESSCOMP_FILT_NODE = "01",
+    RADIO_ADDRESSCOMP_FILT_NODE_BROAD = "02"
+}
+RadioPacketLengthModes_t = {
+    RADIO_PACKET_FIXED_LENGTH = "00",
+    RADIO_PACKET_VARIABLE_LENGTH = "01"
+}
+
+RadioCrcTypes_t = {
+    RADIO_CRC_OFF = "01",
+    RADIO_CRC_1_BYTES = "00",
+    RADIO_CRC_2_BYTES = "02",
+    RADIO_CRC_1_BYTES_INV = "04",
+    RADIO_CRC_2_BYTES_INV = "06",
+    RADIO_CRC_2_BYTES_IBM = "F1",
+    RADIO_CRC_2_BYTES_CCIT = "F2"
+}
+
+RadioDcFree_t = {
+    RADIO_DC_FREE_OFF       = "00",
+    RADIO_DC_FREEWHITENING  = "01",
+}
+
+
+
+RadioLoRaPacketLengthsMode_t = {
+    LORA_PACKET_VARIABLE_LENGTH = "00",
+    LORA_PACKET_FIXED_LENGTH = "01",
+    LORA_PACKET_EXPLICIT  = LORA_PACKET_VARIABLE_LENGTH,
+    LORA_PACKET_IMPLICIT  = LORA_PACKET_FIXED_LENGTH,
+}
+
+RadioLoRaCrcModes_t = { 
+    LORA_CRC_ON     = "01",        -- //!< CRC activated
+    LORA_CRC_OFF    = "00",         --//!< CRC not used
+}
+
+RadioLoRaIQModes_t = {
+    LORA_IQ_NORMAL     = "00",
+    LORA_IQ_INVERTED   = "01",
+}
+
+RadioPacketTypes_t = {
+    PACKET_TYPE_GFSK  = "00",
+    PACKET_TYPE_LORA  = "01",
+    PACKET_TYPE_NONE  = "0F",
+}
+
+RadioModShapings_t = {
+    MOD_SHAPING_OFF      = "00",
+    MOD_SHAPING_G_BT_03  = "08",
+    MOD_SHAPING_G_BT_05  = "09",
+    MOD_SHAPING_G_BT_07  = "0A",
+    MOD_SHAPING_G_BT_1   = "0B",
+}
+
+RadioLoRaSpreadingFactors_t = {
+    LORA_SF5  = "05",
+    LORA_SF6  = "06",
+    LORA_SF7  = "07",
+    LORA_SF8  = "08",
+    LORA_SF9  = "09",
+    LORA_SF10 = "0A",
+    LORA_SF11 = "0B",
+    LORA_SF12 = "0C",
+}
+
+RadioLoRaCodingRates_t = {
+    LORA_CR_4_5 = "01",
+    LORA_CR_4_6 = "02",
+    LORA_CR_4_7 = "03",
+    LORA_CR_4_8 = "04",
+}
+
+PacketParams_t = { 
+    PacketType = RadioPacketTypes_t,
+    Params = {
+        Gfsk = {
+            PreambleLength = nil;   -- //!< The preamble Tx length for GFSK packet type in bit
+            PreambleMinDetect = RadioPreambleDetection_t; --//!< The preamble Rx length minimal for GFSK packet type
+            SyncWordLength = nil;    --//!< The synchronization word length for GFSK packet type
+            AddrComp = RadioAddressComp_t;          --//!< Activated SyncWord correlators
+            HeaderType = RadioPacketLengthModes_t;        --//!< If the header is explicit, it will be transmitted in the GFSK packet. If the header is implicit, it will not be transmitted
+            PayloadLength = nil;     --//!< Size of the payload in the GFSK packet
+            CrcLength = RadioCrcTypes_t;         --//!< Size of the CRC block in the GFSK packet
+            DcFree = RadioDcFree_t;
+        },
+        LoRa = {
+            PreambleLength = nil;    
+            HeaderType = RadioLoRaPacketLengthsMode_t;
+            PayloadLength = nil;     
+            CrcMode = RadioLoRaCrcModes_t;           
+            InvertIQ = RadioLoRaIQModes_t;          
+        }
+    }
+}
+
+PacketStatus_t = {
+    PacketType = RadioPacketTypes_t,
+    Params = {
+        Gfsk = {
+            RxStatus = nil,
+            RssiAvg = nil,                                --//!< The averaged RSSI
+            RssiSync = nil,                               --//!< The RSSI measured on last packet
+            FreqError = nil
+        },
+        LoRa = {
+            RssiPkt =  nil,                               -- //!< The RSSI of the last packet
+            SnrPkt = nil,                                -- //!< The SNR of the last packet
+            SignalRssiPkt = nil,
+            FreqError = nil
+        }
+    }
+}
+
+ModulationParams_t = {
+    PacketType = RadioPacketTypes_t,
+    Params = {
+        Gfsk = {
+            BitRate = nil,
+            Fdev = nil,
+            ModulationShaping =RadioModShapings_t,
+            Bandwidth = nil
+        },
+        LoRa = {
+            SpreadingFactor = RadioLoRaSpreadingFactors_t,    --//!< Spreading Factor for the LoRa modulation
+            Bandwidth = RadioLoRaBandwidths_t,                  --//!< Bandwidth for the LoRa modulation
+            CodingRate = RadioLoRaCodingRates_t,                --//!< Coding rate for the LoRa modulation
+            LowDatarateOptimize = nil; -- //!< Indicates if the modem uses the low datarate optimization
+        }
+    }
+}
+
+SX126x_t = {
+    test = "测试",
+    PacketParams = PacketParams_t,
+    PacketStatus = PacketStatus_t,
+    ModulationParams = ModulationParams_t
+}
+
 -- 定义Radio命令枚举(字符串格式,用于直接通信)
 --[[
     Represents all possible opcode understood by the radio

+ 2 - 0
main.lua

@@ -66,6 +66,8 @@ errDump.request("udp://dev_msg1.openluat.com:12425", nil, true)
 
 -- require "Drv_spi"
 require "sx126x_driver"
+
+
 --启动系统框架
 sys.init(0, 0)
 sys.run()