|
|
@@ -57,17 +57,17 @@ end
|
|
|
-- end,1000)
|
|
|
|
|
|
|
|
|
-function gpio13IntFnc(msg)
|
|
|
- log.info("testGpioSingle.gpio24IntFnc",msg,getGpio13Fnc())
|
|
|
- --上升沿中断
|
|
|
- if msg==cpu.INT_GPIO_POSEDGE then
|
|
|
- --下降沿中断
|
|
|
- else
|
|
|
- end
|
|
|
-end
|
|
|
+-- function gpio13IntFnc(msg)
|
|
|
+-- log.info("testGpioSingle.gpio24IntFnc",msg,getGpio13Fnc())
|
|
|
+-- --上升沿中断
|
|
|
+-- if msg==cpu.INT_GPIO_POSEDGE then
|
|
|
+-- --下降沿中断
|
|
|
+-- else
|
|
|
+-- end
|
|
|
+-- end
|
|
|
pio.pin.setdebounce(0xffffffff)
|
|
|
--GPIO13配置为中断,可通过getGpio13Fnc()获取输入电平,产生中断时,自动执行gpio13IntFnc函数
|
|
|
-getGpio13Fnc = pins.setup(pio.P0_24,gpio13IntFnc)
|
|
|
+-- getGpio13Fnc = pins.setup(pio.P0_24,gpio13IntFnc)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -78,8 +78,7 @@ function gpio4IntFnc(msg)
|
|
|
log.info("testGpioSingle.gpio4IntFnc",msg,getGpio4Fnc())
|
|
|
--上升沿中断
|
|
|
if msg==cpu.INT_GPIO_POSEDGE then
|
|
|
- RadioClearIrqStatus()
|
|
|
- log.info("清除中断")
|
|
|
+ sys.publish("LORA_CALL_BACK")
|
|
|
--下降沿中断
|
|
|
else
|
|
|
end
|
|
|
@@ -141,18 +140,21 @@ function SX126xWriteCommand(command,buffer)
|
|
|
end
|
|
|
|
|
|
function SX126xReadCommand(command,size)
|
|
|
- Drv_spi.drv_spi_read_write_byte(command,0)
|
|
|
+ -- Drv_spi.drv_spi_read_write_byte(command,0)
|
|
|
for i = 1, size do
|
|
|
command = command .. "00"
|
|
|
end
|
|
|
+
|
|
|
+ local ret = Drv_spi.drv_spi_read_write_byte(command,size)
|
|
|
-- Drv_spi.drv_spi_read_write_byte(command,0)
|
|
|
- log.info("SX126xReadCommand",Drv_spi.drv_spi_read_write_byte(command,size))
|
|
|
+ log.info("SX126xReadCommand",ret)
|
|
|
+ return ret
|
|
|
end
|
|
|
-- -----------------------------------------------SPI基础读写---------------------------------------------------
|
|
|
-- 读取寄存器 完成
|
|
|
function SX126xReadRegisters(address,size)
|
|
|
Drv_spi.drv_spi_read_write_byte(sx126x_reg.RadioCommands.RADIO_READ_REGISTER,0)
|
|
|
- sys.wait(20)
|
|
|
+ -- sys.wait(20)
|
|
|
local sendData = address .. "00"
|
|
|
local receiverDataCount= size
|
|
|
|
|
|
@@ -478,10 +480,10 @@ function SX126xSetRx(timeout)
|
|
|
end
|
|
|
|
|
|
|
|
|
-function RadioRx(timeout)
|
|
|
+function RadioRx()
|
|
|
pins.setup(pio.P0_27,0)
|
|
|
pins.setup(pio.P0_28,1)
|
|
|
- sys.wait(1000)
|
|
|
+ -- sys.wait(1000)
|
|
|
SX126xSetDioIrqParams( "02", sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_ALL, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_NONE, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_NONE )
|
|
|
SX126xSetRx(0)
|
|
|
end
|
|
|
@@ -496,6 +498,77 @@ function RadioClearIrqStatus()
|
|
|
SX126xClearIrqStatus()
|
|
|
end
|
|
|
|
|
|
+-- function SX126xGetRxBufferStatus()
|
|
|
+-- local ret = SX126xReadCommand( sx126x_reg.RadioCommands.RADIO_GET_RXBUFFERSTATUS, 4 )
|
|
|
+-- log.info("LORA_CALL_BACK",ret)
|
|
|
+-- return ret
|
|
|
+-- end
|
|
|
+
|
|
|
+-- function SX126xGetPayload(buffer,size,maxSize)
|
|
|
+-- local offset = "00"
|
|
|
+-- local data = SX126xGetRxBufferStatus(size,offset) --例子:返回 "A408" A4是起始地址,08是接收到的长度
|
|
|
+
|
|
|
+-- if size > maxSize then
|
|
|
+-- return -1
|
|
|
+-- end
|
|
|
+-- SX126xReadBuffer(offset,buffer,size)
|
|
|
+-- return 0
|
|
|
+-- end
|
|
|
+
|
|
|
+-- function RadioGetBuffer()
|
|
|
+
|
|
|
+-- end
|
|
|
+
|
|
|
+-- function loraCallback()
|
|
|
+
|
|
|
+-- end
|
|
|
+
|
|
|
+function SX126xReadBuffer(offset,size)
|
|
|
+ local command = sx126x_reg.RadioCommands.RADIO_READ_BUFFER .. offset .. "00"
|
|
|
+ -- Drv_spi.drv_spi_read_write_byte(sx126x_reg.RadioCommands.RADIO_READ_BUFFER)
|
|
|
+
|
|
|
+ -- for i = 1, size do
|
|
|
+ -- command = command .. "00"
|
|
|
+ -- end
|
|
|
+ -- log.info("offset",offset)
|
|
|
+ -- log.info("SX126xReadBuffer",ret)
|
|
|
+ log.info("SX126xReadBuffer",command)
|
|
|
+ local ret = Drv_spi.drv_spi_read_write_byte(command,8)
|
|
|
+ log.info("SX126xReadBuffer",ret)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+sys.subscribe("LORA_CALL_BACK", function()
|
|
|
+ RadioClearIrqStatus()
|
|
|
+ RadioRx()
|
|
|
+ log.info("清除中断")
|
|
|
+ local ret = SX126xReadCommand( sx126x_reg.RadioCommands.RADIO_GET_RXBUFFERSTATUS, 3 )
|
|
|
+ log.info("LORA_CALL_BACK",ret)
|
|
|
+ -- 从第1个字符截取到第2个字符,得到"A4"
|
|
|
+ local rxStartBufferPointer = ret:sub(1, 2)
|
|
|
+
|
|
|
+ -- 从第3个字符截取到第4个字符,得到"08"
|
|
|
+ local payloadLength = ret:sub(3, 4)
|
|
|
+
|
|
|
+ local num1 = tonumber(payloadLength, 16) -- 第二个参数 16 表示按十六进制解析
|
|
|
+ local nmu2 = tonumber("FF", 16)
|
|
|
+
|
|
|
+ -- print(string.format("0x%02X", nmu2)) -- 输出 0x08(十六进制格式化显示)
|
|
|
+
|
|
|
+ if num1 >= nmu2 then
|
|
|
+ -- print(string.format("0x%02X", nmu1)) -- 输出 0x08(十六进制格式化显示)
|
|
|
+ return 1
|
|
|
+ end
|
|
|
+
|
|
|
+ log.info("payloadLength: "..payloadLength)
|
|
|
+ log.info("payloadLength: "..rxStartBufferPointer)
|
|
|
+ SX126xReadBuffer("01","08")
|
|
|
+
|
|
|
+ -- print(part1) -- 输出 "A4"
|
|
|
+ -- print(part2) -- 输出 "08"
|
|
|
+ -- SX126xReadRegister("0702")
|
|
|
+end)
|
|
|
+
|
|
|
-- sys.taskInit(function ()
|
|
|
-- sys.wait(5000)
|
|
|
-- SX126xInit()
|