examples: lora atcmd minimal rx and tx

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-01-07 13:10:44 +01:00
parent f098853465
commit 8cfe5ebc4a
8 changed files with 76 additions and 30 deletions
+28 -2
View File
@@ -11,7 +11,7 @@ func quicktest() {
// Check firmware version. // Check firmware version.
func version() { func version() {
writeCommandOutput("VER", currentVersion()+" "+firmwareVersion()) writeCommandOutput("VER", currentVersion()+" ("+firmwareVersion()+")")
} }
// Use to check the ID of the LoRaWAN module, or change the ID. // Use to check the ID of the LoRaWAN module, or change the ID.
@@ -329,12 +329,38 @@ func log(setting string) error {
return nil return nil
} }
func recv(setting string) error {
cmd := "RECV"
data, err := lorarx()
if err != nil {
writeCommandOutput(cmd, "ERROR "+err.Error())
return err
}
writeCommandOutput(cmd, string(data))
return nil
}
func recvhex(setting string) error {
cmd := "RECVHEX"
data, err := lorarx()
if err != nil {
writeCommandOutput(cmd, "ERROR "+err.Error())
return err
}
writeCommandOutput(cmd, string(data))
return nil
}
func crlf() { func crlf() {
uart.Write([]byte("\r\n")) uart.Write([]byte("\r\n"))
} }
func writeCommandOutput(cmd, data string) { func writeCommandOutput(cmd, data string) {
uart.Write([]byte("+"+cmd+": ")) uart.Write([]byte("+" + cmd + ": "))
uart.Write([]byte(data)) uart.Write([]byte(data))
crlf() crlf()
} }
+4
View File
@@ -99,6 +99,10 @@ func parseCommand(cmd, args string) error {
test(args) test(args)
case "LOG": case "LOG":
log(args) log(args)
case "RECV":
recv(args)
case "RECVHEX":
recvhex(args)
default: default:
return errInvalidCommand return errInvalidCommand
} }
+1
View File
@@ -6,6 +6,7 @@ import (
var ( var (
errRadioNotFound = errors.New("radio not found") errRadioNotFound = errors.New("radio not found")
errRxTimeout = errors.New("radio RX timeout")
) )
type LoraRadio interface { type LoraRadio interface {
+5 -1
View File
@@ -29,5 +29,9 @@ func (sr *SimLoraRadio) SetLoraCrc(enable bool) {}
func (sr *SimLoraRadio) SetLoraSpreadingFactor(sf uint8) {} func (sr *SimLoraRadio) SetLoraSpreadingFactor(sf uint8) {}
func firmwareVersion() string { func firmwareVersion() string {
return "Simulator "+currentVersion() return "Simulator " + currentVersion()
}
func lorarx() ([]byte, error) {
return nil, nil
} }
+4
View File
@@ -63,3 +63,7 @@ func radioIntHandler(intr interrupt.Interrupt) {
func firmwareVersion() string { func firmwareVersion() string {
return "sx126x" return "sx126x"
} }
func lorarx() ([]byte, error) {
return loraRadio.LoraRx(LORA_DEFAULT_RXTIMEOUT_MS)
}
+10 -3
View File
@@ -11,7 +11,11 @@ import (
"tinygo.org/x/drivers/sx127x" "tinygo.org/x/drivers/sx127x"
) )
const FREQ = 868100000 const (
FREQ = 868100000
LORA_DEFAULT_RXTIMEOUT_MS = 1000
LORA_DEFAULT_TXTIMEOUT_MS = 5000
)
var ( var (
// We assume LoRa Featherwing module is connected to PyBadge: // We assume LoRa Featherwing module is connected to PyBadge:
@@ -67,12 +71,15 @@ func setupLora() (LoraRadio, error) {
return loraRadio, nil return loraRadio, nil
} }
func dioIrqHandler(machine.Pin) { func dioIrqHandler(machine.Pin) {
loraRadio.HandleInterrupt() loraRadio.HandleInterrupt()
} }
func firmwareVersion() string { func firmwareVersion() string {
v := loraRadio.GetVersion() v := loraRadio.GetVersion()
return "sx127x v"+strconv.Itoa(int(v)) return "sx127x v" + strconv.Itoa(int(v))
}
func lorarx() ([]byte, error) {
return loraRadio.LoraRx(LORA_DEFAULT_RXTIMEOUT_MS)
} }