|
@@ -19,6 +19,9 @@ require "sx126x_reg"
|
|
|
local SX126x = json.encode(sx126x_reg.SX126x_t)
|
|
local SX126x = json.encode(sx126x_reg.SX126x_t)
|
|
|
local SX126xCopy,result,errinfo = json.decode(SX126x)
|
|
local SX126xCopy,result,errinfo = json.decode(SX126x)
|
|
|
SX126x = nil
|
|
SX126x = nil
|
|
|
|
|
+local ImageCalibrated = false
|
|
|
|
|
+
|
|
|
|
|
+local FREQ_STEP = 0.95367431640625
|
|
|
|
|
|
|
|
local RadioPublicNetwork_t = {
|
|
local RadioPublicNetwork_t = {
|
|
|
Previous = false,
|
|
Previous = false,
|
|
@@ -291,8 +294,43 @@ function RadioSetTxConfig(modem,power,fdev,bandwidth,datarate,coderate,preambleL
|
|
|
SX126xSetTxParams(power,sx126x_reg.RadioRampTimes_t.RADIO_RAMP_40_US)
|
|
SX126xSetTxParams(power,sx126x_reg.RadioRampTimes_t.RADIO_RAMP_40_US)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
+function SX126xCalibrateImage(freq)
|
|
|
|
|
+ local calFreq = {}
|
|
|
|
|
+
|
|
|
|
|
+ if freq > 900000000 then
|
|
|
|
|
+ calFreq = {"E1", "E9"}
|
|
|
|
|
+ elseif freq > 850000000 then
|
|
|
|
|
+ calFreq = {"D7", "D8"}
|
|
|
|
|
+ elseif freq > 770000000 then
|
|
|
|
|
+ calFreq = {"C1", "C5"}
|
|
|
|
|
+ elseif freq > 460000000 then
|
|
|
|
|
+ calFreq = {"75", "81"}
|
|
|
|
|
+ elseif freq > 425000000 then
|
|
|
|
|
+ calFreq = {"6B", "6F"}
|
|
|
|
|
+ elseif freq >= 210000000 then
|
|
|
|
|
+ calFreq = {"37", "41"}
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_CALIBRATEIMAGE, calFreq)
|
|
|
|
|
+end
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
function SX126xSetRfFrequency(frequency)
|
|
function SX126xSetRfFrequency(frequency)
|
|
|
- SX126xWriteCommand( sx126x_reg.RadioCommands.RADIO_SET_RFFREQUENCY, {frequency});
|
|
|
|
|
|
|
+
|
|
|
|
|
+ local buf = {}
|
|
|
|
|
+ local freq = 0
|
|
|
|
|
+
|
|
|
|
|
+ if ImageCalibrated == false then
|
|
|
|
|
+ SX126xCalibrateImage(frequency)
|
|
|
|
|
+ ImageCalibrated = true
|
|
|
|
|
+ end
|
|
|
|
|
+ -- local FREQ_STEP = 0.95367431640625
|
|
|
|
|
+
|
|
|
|
|
+ freq = frequency / FREQ_STEP
|
|
|
|
|
+
|
|
|
|
|
+ log.info("freq", freq)
|
|
|
|
|
+ log.info("freq", string.format("%02X", freq))
|
|
|
|
|
+ SX126xWriteCommand( sx126x_reg.RadioCommands.RADIO_SET_RFFREQUENCY, {string.format("%02X", freq)});
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function RadioSetChannel(frequency)
|
|
function RadioSetChannel(frequency)
|
|
@@ -351,7 +389,7 @@ function SX126xInit()
|
|
|
RadioSetTxConfig(sx126x_reg.RadioModems_t.MODEM_LORA,"16",0,1,7,"01","0c","00","01","00","00","00",3000)
|
|
RadioSetTxConfig(sx126x_reg.RadioModems_t.MODEM_LORA,"16",0,1,7,"01","0c","00","01","00","00","00",3000)
|
|
|
|
|
|
|
|
log.info("RadioSetTxConfig",string.format("%02X", 433000000))
|
|
log.info("RadioSetTxConfig",string.format("%02X", 433000000))
|
|
|
- RadioSetChannel(string.format("%02X", 433000000))
|
|
|
|
|
|
|
+ RadioSetChannel(433000000)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
sys.taskInit(function ()
|
|
sys.taskInit(function ()
|
|
@@ -378,10 +416,14 @@ sys.taskInit(function ()
|
|
|
-- log.info("计算结果0741寄存器", SX126xReadRegister("0741"))
|
|
-- log.info("计算结果0741寄存器", SX126xReadRegister("0741"))
|
|
|
-- SX126xWriteCommand("1d",{"07400000"})
|
|
-- SX126xWriteCommand("1d",{"07400000"})
|
|
|
|
|
|
|
|
- sys.wait(20)
|
|
|
|
|
|
|
+ -- sys.wait(20)
|
|
|
log.info("计算结果")
|
|
log.info("计算结果")
|
|
|
- RadioSend("A9","01","00")
|
|
|
|
|
- SX126xReadCommand(sx126x_reg.RadioCommands.RADIO_GET_STATUS,1)
|
|
|
|
|
|
|
+ -- SX126xSetStandby(sx126x_reg.RadioStandbyModes_t.STDBY_RC)
|
|
|
|
|
+ -- SX126xReadCommand(sx126x_reg.RadioCommands.RADIO_GET_STATUS,1)
|
|
|
|
|
+ -- sys.wait(20)
|
|
|
|
|
+ RadioSend("A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5","1e","00")
|
|
|
|
|
+ -- sys.wait(20)
|
|
|
|
|
+ -- SX126xReadCommand(sx126x_reg.RadioCommands.RADIO_GET_STATUS,1)
|
|
|
-- SX126xWakeup()
|
|
-- SX126xWakeup()
|
|
|
sys.wait(1000)
|
|
sys.wait(1000)
|
|
|
end
|
|
end
|