|
|
@@ -76,7 +76,7 @@ pio.pin.setdebounce(0xffffffff)
|
|
|
|
|
|
|
|
|
function gpio4IntFnc(msg)
|
|
|
- log.info("testGpioSingle.gpio4IntFnc",msg,getGpio4Fnc())
|
|
|
+ -- log.info("testGpioSingle.gpio4IntFnc",msg,getGpio4Fnc())
|
|
|
--上升沿中断
|
|
|
if msg==cpu.INT_GPIO_POSEDGE then
|
|
|
sys.publish("LORA_CALL_BACK")
|
|
|
@@ -103,7 +103,7 @@ end
|
|
|
|
|
|
function gsonLoginfo(data)
|
|
|
local jsondata = json.encode(data)
|
|
|
- log.info("SX126xSetModulationParams.encode",jsondata)
|
|
|
+ -- log.info("SX126xSetModulationParams.encode",jsondata)
|
|
|
end
|
|
|
|
|
|
-- 初始化SPI
|
|
|
@@ -123,7 +123,7 @@ end
|
|
|
function SX126xWakeup()
|
|
|
local command = sx126x_reg.RadioCommands.RADIO_GET_STATUS .. "00"
|
|
|
local ret = Drv_spi.drv_spi_read_write_byte(command,1)
|
|
|
- log.info("SX126xWakeup",ret)
|
|
|
+ -- log.info("SX126xWakeup",ret)
|
|
|
end
|
|
|
|
|
|
--命令写入 完成
|
|
|
@@ -149,7 +149,7 @@ function SX126xReadCommand(command,size)
|
|
|
|
|
|
local ret = Drv_spi.drv_spi_read_write_byte(command,size)
|
|
|
-- Drv_spi.drv_spi_read_write_byte(command,0)
|
|
|
- log.info("SX126xReadCommand",ret)
|
|
|
+ -- log.info("SX126xReadCommand",ret)
|
|
|
return ret
|
|
|
end
|
|
|
-- -----------------------------------------------SPI基础读写---------------------------------------------------
|
|
|
@@ -187,7 +187,7 @@ function SX126xWriteRegisters(address,buffer)
|
|
|
end
|
|
|
|
|
|
local test = address .. bufferTotal
|
|
|
- log.info("SX126xWriteRegisters",bufferTotal)
|
|
|
+ -- log.info("SX126xWriteRegisters",bufferTotal)
|
|
|
Drv_spi.drv_spi_read_write_byte(test,0);
|
|
|
end
|
|
|
|
|
|
@@ -220,7 +220,7 @@ end
|
|
|
function SX126xSetPaConfig(paDutyCycle,hpMax,deviceSel,paLut)
|
|
|
local buf = {paDutyCycle,hpMax,deviceSel,paLut}
|
|
|
SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_SET_PACONFIG,buf)
|
|
|
- log.info("SX126xSetPaConfig",sx126x_reg.RadioCommands.RADIO_SET_PACONFIG)
|
|
|
+ -- log.info("SX126xSetPaConfig",sx126x_reg.RadioCommands.RADIO_SET_PACONFIG)
|
|
|
end
|
|
|
|
|
|
function SX126xSetTxParams(power, rampTime)
|
|
|
@@ -282,7 +282,7 @@ function SX126xSetDioIrqParams(irqMask, dio1Mask, dio2Mask, dio3Mask)
|
|
|
end
|
|
|
|
|
|
-- 6. 打印日志(验证格式是否正确)
|
|
|
- log.info("SX126xSetDioIrqParams", table.concat(buf_hex, " "))
|
|
|
+ -- log.info("SX126xSetDioIrqParams", table.concat(buf_hex, " "))
|
|
|
|
|
|
-- 7. 发送命令(写入8字节配置)
|
|
|
SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_CFG_DIOIRQ, buf_hex)
|
|
|
@@ -304,7 +304,7 @@ end
|
|
|
function SX126xSetPacketType(packetType)
|
|
|
PacketType = packetType;
|
|
|
SX126xWriteCommand( sx126x_reg.RadioCommands.RADIO_SET_PACKETTYPE,{PacketType})
|
|
|
- log.info("PacketType:",PacketType,sx126x_reg.RadioCommands.RADIO_SET_PACKETTYPE)
|
|
|
+ -- log.info("PacketType:",PacketType,sx126x_reg.RadioCommands.RADIO_SET_PACKETTYPE)
|
|
|
end
|
|
|
|
|
|
-- 原驱动好像并没有启用,不晓得这个是什么功能
|
|
|
@@ -343,7 +343,7 @@ function SX126xSetModulationParams(modulationParams)
|
|
|
modulationParams.Params.LoRa.LowDatarateOptimize
|
|
|
}
|
|
|
local jsondata = json.encode(buf)
|
|
|
- log.info("SX126xSetModulationParams.encode",jsondata)
|
|
|
+ -- log.info("SX126xSetModulationParams.encode",jsondata)
|
|
|
SX126xWriteCommand( sx126x_reg.RadioCommands.RADIO_SET_MODULATIONPARAMS,buf);
|
|
|
end
|
|
|
|
|
|
@@ -446,8 +446,8 @@ function SX126xSetRfFrequency(frequency)
|
|
|
|
|
|
freq = frequency / FREQ_STEP
|
|
|
|
|
|
- log.info("freq", freq)
|
|
|
- log.info("freq", string.format("%02X", freq))
|
|
|
+ -- log.info("freq", freq)
|
|
|
+ -- log.info("freq", string.format("%02X", freq))
|
|
|
SX126xWriteCommand( sx126x_reg.RadioCommands.RADIO_SET_RFFREQUENCY, {string.format("%02X", freq)});
|
|
|
end
|
|
|
|
|
|
@@ -482,7 +482,7 @@ end
|
|
|
function RadioSend(buffer,size,time_out)
|
|
|
-- setTransmitMode()
|
|
|
-- SX126xSetDioIrqParams( sx126x_reg.RadioIrqMasks_t.IRQ_TX_DONE + sx126x_reg.RadioIrqMasks_t.IRQ_RX_TX_TIMEOUT, sx126x_reg.RadioIrqMasks_t.IRQ_TX_DONE + sx126x_reg.RadioIrqMasks_t.IRQ_RX_TX_TIMEOUT, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_NONE, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_NONE )--SX126xSetDioIrqParams( sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_ALL, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_ALL, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_NONE, sx126x_reg.RadioIrqMasks_t.IRQ_RADIO_NONE )
|
|
|
- log.info("RadioSend",buffer,size,time_out)
|
|
|
+ -- log.info("RadioSend",buffer,size,time_out)
|
|
|
local tx_irq_mask = bit.bor(
|
|
|
sx126x_reg.RadioIrqMasks_t.IRQ_TX_DONE,
|
|
|
sx126x_reg.RadioIrqMasks_t.IRQ_RX_TX_TIMEOUT
|
|
|
@@ -527,9 +527,9 @@ function sentString(strData)
|
|
|
RadioSend(hexStr,string.format("%02X", #hexStr/2),"00")
|
|
|
-- local original = "Hello, Lua!\n"
|
|
|
-- local hexStr = stringToHex(original)
|
|
|
- log.info("test:",hexStr) -- 输出: 48656c6c6f2c204c756121
|
|
|
- log.info("testlen:",#hexStr)
|
|
|
- log.info("testlen2:",string.format("%02X", #hexStr/2))
|
|
|
+ -- log.info("test:",hexStr) -- 输出: 48656c6c6f2c204c756121
|
|
|
+ -- log.info("testlen:",#hexStr)
|
|
|
+ -- log.info("testlen2:",string.format("%02X", #hexStr/2))
|
|
|
-- RadioSend(hexStr,string.format("%02X", #hexStr/2),"00")
|
|
|
end
|
|
|
|
|
|
@@ -669,8 +669,8 @@ local function SX126xGetIrqStatus()
|
|
|
-- 正确的字节序:高字节在前,低字节在后
|
|
|
local irq = bit.lshift(msb, 8) + lsb
|
|
|
|
|
|
- log.info("IRQ原始数据", ret, "LSB:", string.format("0x%02X", lsb), "MSB:", string.format("0x%02X", msb))
|
|
|
- log.info("IRQ解析结果", string.format("0x%04X", irq))
|
|
|
+ -- log.info("IRQ原始数据", ret, "LSB:", string.format("0x%02X", lsb), "MSB:", string.format("0x%02X", msb))
|
|
|
+ -- log.info("IRQ解析结果", string.format("0x%04X", irq))
|
|
|
|
|
|
return irq
|
|
|
end
|
|
|
@@ -678,7 +678,7 @@ end
|
|
|
|
|
|
|
|
|
sys.subscribe("LORA_CALL_BACK", function()
|
|
|
- log.info("LORA_CALL_BACK")
|
|
|
+ -- log.info("LORA_CALL_BACK")
|
|
|
-- -- 先读 IRQ 状态
|
|
|
local irq = SX126xGetIrqStatus()
|
|
|
if irq == 0 then
|
|
|
@@ -690,55 +690,55 @@ sys.subscribe("LORA_CALL_BACK", function()
|
|
|
RadioRx()
|
|
|
|
|
|
|
|
|
- local tx_gpio_level = pio.pin.getval(pio.P0_27)
|
|
|
- local rx_gpio_level = pio.pin.getval(pio.P0_28)
|
|
|
- log.info("TXENGPIO 电平", tx_gpio_level)
|
|
|
- log.info("RXENGPIO 电平", rx_gpio_level)
|
|
|
+ -- local tx_gpio_level = pio.pin.getval(pio.P0_27)
|
|
|
+ -- log.info("TXENGPIO 电平", tx_gpio_level)
|
|
|
+ -- local rx_gpio_level = pio.pin.getval(pio.P0_28)
|
|
|
+ -- log.info("RXENGPIO 电平", rx_gpio_level)
|
|
|
-- if tx_gpio_level == 0 and rx_gpio_level == 1 then
|
|
|
-- return
|
|
|
-- end
|
|
|
|
|
|
- log.info("IRQ原始HEX", ret) -- 记得在 GetIrqStatus 里打印
|
|
|
- log.info("IRQ解析结果", string.format("0x%04X", irq))
|
|
|
+ -- log.info("IRQ原始HEX", ret) -- 记得在 GetIrqStatus 里打印
|
|
|
+ -- log.info("IRQ解析结果", string.format("0x%04X", irq))
|
|
|
if irq == 0xAC then
|
|
|
return
|
|
|
end
|
|
|
--日志显示还是有点区别的。如果是oxAC就是把自己读出来了 如果是0xA4就是正常的接收
|
|
|
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_TX_DONE) ~= 0 then
|
|
|
- log.info("发送完成")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_RX_DONE) ~= 0 then
|
|
|
- log.info("接收完成")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_RX_TX_TIMEOUT) ~= 0 then
|
|
|
- log.info("接收超时")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_CRC_ERROR) ~= 0 then
|
|
|
- log.info("接收CRC错误")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_CAD_DONE) ~= 0 then
|
|
|
- log.info("CAD完成")
|
|
|
- end
|
|
|
- if bit.band(irq,sx126x_reg.RadioIrqMasks_t.IRQ_HEADER_VALID) ~= 0 then
|
|
|
- log.info("头部有效")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_HEADER_ERROR) ~= 0 then
|
|
|
- log.info("头部错误")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_SYNCWORD_VALID) ~= 0 then
|
|
|
- log.info("同步字有效")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_PREAMBLE_DETECTED) ~= 0 then
|
|
|
- log.info("前导码检测到")
|
|
|
- end
|
|
|
- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_CAD_ACTIVITY_DETECTED) ~= 0 then
|
|
|
- log.info("CAD活动检测到")
|
|
|
- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_TX_DONE) ~= 0 then
|
|
|
+ -- log.info("发送完成")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_RX_DONE) ~= 0 then
|
|
|
+ -- log.info("接收完成")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_RX_TX_TIMEOUT) ~= 0 then
|
|
|
+ -- log.info("接收超时")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_CRC_ERROR) ~= 0 then
|
|
|
+ -- log.info("接收CRC错误")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_CAD_DONE) ~= 0 then
|
|
|
+ -- log.info("CAD完成")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq,sx126x_reg.RadioIrqMasks_t.IRQ_HEADER_VALID) ~= 0 then
|
|
|
+ -- log.info("头部有效")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_HEADER_ERROR) ~= 0 then
|
|
|
+ -- log.info("头部错误")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_SYNCWORD_VALID) ~= 0 then
|
|
|
+ -- log.info("同步字有效")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_PREAMBLE_DETECTED) ~= 0 then
|
|
|
+ -- log.info("前导码检测到")
|
|
|
+ -- end
|
|
|
+ -- if bit.band(irq, sx126x_reg.RadioIrqMasks_t.IRQ_CAD_ACTIVITY_DETECTED) ~= 0 then
|
|
|
+ -- log.info("CAD活动检测到")
|
|
|
+ -- end
|
|
|
|
|
|
|
|
|
local ret = SX126xReadCommand(sx126x_reg.RadioCommands.RADIO_GET_RXBUFFERSTATUS, 3)
|
|
|
- log.info("LORA_CALL_BACK", ret)
|
|
|
+ -- log.info("LORA_CALL_BACK", ret)
|
|
|
|
|
|
local payloadLength = ret:sub(3, 4)
|
|
|
local num1 = tonumber(payloadLength, 16)
|