cleanup printing
This commit is contained in:
@@ -104,9 +104,7 @@ func main() {
|
||||
// txDone.Store(false)
|
||||
// println("cleaning up prior to transmit...")
|
||||
// radio.ClearIrqStatus(sx126x.IRQ_ALL_MASK)
|
||||
// checkStatus(radio, "ClearIrqStatus")
|
||||
// radio.SetStandby(sx126x.STANDBY_RC)
|
||||
// checkStatus(radio, "SetStandby")
|
||||
// println("waiting 1s before transmitting...")
|
||||
// time.Sleep(1000 * time.Millisecond)
|
||||
// led.Set(true)
|
||||
@@ -141,55 +139,22 @@ func SetupLora(radio *sx126x.Device, config lora.Config) {
|
||||
chipMode, _ := radio.GetStatus()
|
||||
if chipMode != sx126x.CHIP_MODE_STBY_RC {
|
||||
radio.SetStandby(sx126x.STANDBY_RC)
|
||||
checkStatus(radio, "SetStandby")
|
||||
}
|
||||
radio.ClearDeviceErrors()
|
||||
// Clear errors, disable radio interrupts for the moment
|
||||
radio.SetPacketType(sx126x.PACKET_TYPE_LORA)
|
||||
checkStatus(radio, "SetPacketType")
|
||||
radio.SetRfFrequency(config.Freq)
|
||||
checkStatus(radio, "SetRfFrequency")
|
||||
radio.SetModulationParamsLoRa(spreadingFactor(config.Sf), bandwidth(config.Bw), codingRate(config.Cr), config.Ldr)
|
||||
checkStatus(radio, "SetModulationParamsLoRa")
|
||||
radio.SetPaConfig(0x04, 0x07, sx126x.DEVICE_SEL_SX1262)
|
||||
checkStatus(radio, "SetPaConfig")
|
||||
radio.SetTxParams(config.LoraTxPowerDBm, sx126x.RADIO_RAMP_200U)
|
||||
checkStatus(radio, "SetTxParams")
|
||||
var syncWord [2]uint8
|
||||
syncWord[0] = uint8(config.SyncWord >> 8)
|
||||
syncWord[1] = uint8(config.SyncWord & 0x00FF)
|
||||
|
||||
radio.WriteRegister(sx126x.REG_LORA_SYNC_WORD_MSB, syncWord[:])
|
||||
checkStatus(radio, "WriteRegister")
|
||||
radio.SetRxTxFallbackMode(sx126x.FALLBACK_MODE_STDBY_RC)
|
||||
checkStatus(radio, "SetRxTxFallbackMode")
|
||||
radio.SetDIO2AsRfSwitchCtrl(true)
|
||||
checkStatus(radio, "SetDIO2AsRfSwitchCtrl")
|
||||
radio.SetDIO3AsTCXOCtrl(sx126x.TCXO_VOLTAGE_1_6V, 5000)
|
||||
checkStatus(radio, "SetDIO3AsTCXOCtrl")
|
||||
}
|
||||
|
||||
func printRegister(radio *sx126x.Device, address uint16) {
|
||||
data := radio.ReadRegister(address)
|
||||
println("register:", address, "data:", data)
|
||||
}
|
||||
|
||||
func checkStatus(radio *sx126x.Device, prefix string) {
|
||||
chipMode, commandStatus := radio.GetStatus()
|
||||
if commandStatus == sx126x.COMMAND_STATUS_COMMAND_PROCESSING_ERROR || commandStatus == sx126x.COMMAND_STATUS_COMMAND_TIMEOUT || commandStatus == sx126x.COMMAND_STATUS_FAILURE_TO_EXECUTE_COMMAND {
|
||||
println(prefix, "->", "command failed with status:", commandStatus)
|
||||
}
|
||||
if chipMode != sx126x.CHIP_MODE_STBY_RC && chipMode != sx126x.CHIP_MODE_STBY_XOSC {
|
||||
println(prefix, "->", "exited standby:", chipMode)
|
||||
}
|
||||
}
|
||||
|
||||
func checkDeviceErrors(radio *sx126x.Device, prefix string) {
|
||||
err := radio.GetDeviceErrors()
|
||||
if err == 0 {
|
||||
return
|
||||
}
|
||||
println(prefix, "->", "error:", err)
|
||||
}
|
||||
|
||||
func Tx(radio *sx126x.Device, loraConfig lora.Config, data []byte) error {
|
||||
|
||||
Reference in New Issue
Block a user