|
|
@@ -78,7 +78,7 @@ function gpio4IntFnc(msg)
|
|
|
log.info("testGpioSingle.gpio4IntFnc",msg,getGpio4Fnc())
|
|
|
--上升沿中断
|
|
|
if msg==cpu.INT_GPIO_POSEDGE then
|
|
|
- sys.publish("LORA_CALL_BACK")
|
|
|
+ -- sys.publish("LORA_CALL_BACK")
|
|
|
-- log.info("我是中断")
|
|
|
--下降沿中断
|
|
|
else
|
|
|
@@ -413,15 +413,43 @@ function SX126xWriteBuffer(offset, buffer,size)
|
|
|
-- log.info("SX126xWriteBuffer",offset,buffer,size)
|
|
|
local sentdata = offset .. buffer
|
|
|
Drv_spi.drv_spi_read_write_byte(sx126x_reg.RadioCommands.RADIO_WRITE_BUFFER,0)
|
|
|
- Drv_spi.drv_spi_read_write_byte(sentdata,10)
|
|
|
+ Drv_spi.drv_spi_read_write_byte(sentdata,size)
|
|
|
|
|
|
end
|
|
|
|
|
|
-function SX126xSetPayload (payload,size)
|
|
|
- -- log.info("SX126xSetPayload",payload,size)
|
|
|
- SX126xWriteBuffer( "00", payload, size );
|
|
|
+function SX126xSetPayload(payload,size)
|
|
|
+ -- 每个缓冲区的大小:10字节 = 20个十六进制字符
|
|
|
+ local bytesPerBuffer = 10
|
|
|
+ local charsPerBuffer = bytesPerBuffer * 2 -- 20个字符
|
|
|
+
|
|
|
+ -- 起始地址(十六进制)
|
|
|
+ local address = 0x00
|
|
|
+ local totalLength = #payload
|
|
|
+
|
|
|
+ local readBuf = ""
|
|
|
+
|
|
|
+ -- 循环分割 payload 并写入
|
|
|
+ for i = 1, totalLength, charsPerBuffer do
|
|
|
+ -- 提取当前段的十六进制字符串(最多20个字符)
|
|
|
+ local segment = string.sub(payload, i, i + charsPerBuffer - 1)
|
|
|
+ -- 计算当前段的实际字节数(字符数 / 2)
|
|
|
+ local segmentBytes = #segment / 2
|
|
|
+
|
|
|
+ -- 将地址转换为两位十六进制字符串(带前导零)
|
|
|
+ local addrHex = string.format("%02X", address)
|
|
|
+
|
|
|
+ -- 调用写入缓冲区函数
|
|
|
+ SX126xWriteBuffer(addrHex, segment, segmentBytes)
|
|
|
+ readBuf = SX126xReadBuffer(addrHex,segmentBytes)
|
|
|
+ local hexStr = stringToHex(readBuf)
|
|
|
+ -- 地址递增(每次增加10字节)
|
|
|
+ address = address + bytesPerBuffer
|
|
|
+ log.info("SX126xWriteBuffer", "写入地址:", address,segment)
|
|
|
+ log.info("SX126xWriteBuffer", "读出地址:", address,hexStr)
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
+
|
|
|
function SX126xSetTx(timeout)
|
|
|
SX126xWriteCommand( sx126x_reg.RadioCommands.RADIO_SET_TX, {timeout});
|
|
|
end
|
|
|
@@ -468,9 +496,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
|
|
|
|
|
|
@@ -546,13 +574,14 @@ function SX126xReadBuffer(offset,size)
|
|
|
command = command .. "00"
|
|
|
end
|
|
|
local ret = Drv_spi.drv_spi_read_write_byte(command,size)
|
|
|
- log.info("SX126xReadBuffer",ret)
|
|
|
+ -- log.info("SX126xReadBuffer",ret)
|
|
|
-- 测试示例
|
|
|
-- local hex_str = "617368696E696E67" -- "ashining"的十六进制表示
|
|
|
local original_str = hex_to_string(ret)
|
|
|
|
|
|
-- print("转换后的字符串: " .. original_str) -- 输出: ashining
|
|
|
- log.info("原始字符串: " .. original_str)
|
|
|
+ -- log.info("原始字符串: " .. original_str)
|
|
|
+ return original_str
|
|
|
end
|
|
|
|
|
|
|
|
|
@@ -578,8 +607,8 @@ sys.subscribe("LORA_CALL_BACK", function()
|
|
|
-- end
|
|
|
log.info("payloadLength",num1)
|
|
|
--测试读取数据。
|
|
|
- SX126xReadBuffer("00",8)
|
|
|
- SX126xReadBuffer("09",8)
|
|
|
+ SX126xReadBuffer("00",num1)
|
|
|
+ -- SX126xReadBuffer("09",8)
|
|
|
end)
|
|
|
|
|
|
-- sys.taskInit(function ()
|
|
|
@@ -608,3 +637,5 @@ end)
|
|
|
-- spi.close(spi.SPI_1)
|
|
|
-- end)
|
|
|
|
|
|
+
|
|
|
+
|