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
+27 -1
View File
@@ -11,7 +11,7 @@ func quicktest() {
// Check firmware version.
func version() {
writeCommandOutput("VER", currentVersion()+" "+firmwareVersion())
writeCommandOutput("VER", currentVersion()+" ("+firmwareVersion()+")")
}
// Use to check the ID of the LoRaWAN module, or change the ID.
@@ -329,6 +329,32 @@ func log(setting string) error {
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() {
uart.Write([]byte("\r\n"))
}
+4
View File
@@ -99,6 +99,10 @@ func parseCommand(cmd, args string) error {
test(args)
case "LOG":
log(args)
case "RECV":
recv(args)
case "RECVHEX":
recvhex(args)
default:
return errInvalidCommand
}
+1
View File
@@ -6,6 +6,7 @@ import (
var (
errRadioNotFound = errors.New("radio not found")
errRxTimeout = errors.New("radio RX timeout")
)
type LoraRadio interface {
+4
View File
@@ -31,3 +31,7 @@ func (sr *SimLoraRadio) SetLoraSpreadingFactor(sf uint8) {}
func firmwareVersion() string {
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 {
return "sx126x"
}
func lorarx() ([]byte, error) {
return loraRadio.LoraRx(LORA_DEFAULT_RXTIMEOUT_MS)
}
+9 -2
View File
@@ -11,7 +11,11 @@ import (
"tinygo.org/x/drivers/sx127x"
)
const FREQ = 868100000
const (
FREQ = 868100000
LORA_DEFAULT_RXTIMEOUT_MS = 1000
LORA_DEFAULT_TXTIMEOUT_MS = 5000
)
var (
// We assume LoRa Featherwing module is connected to PyBadge:
@@ -67,7 +71,6 @@ func setupLora() (LoraRadio, error) {
return loraRadio, nil
}
func dioIrqHandler(machine.Pin) {
loraRadio.HandleInterrupt()
}
@@ -76,3 +79,7 @@ func firmwareVersion() string {
v := loraRadio.GetVersion()
return "sx127x v" + strconv.Itoa(int(v))
}
func lorarx() ([]byte, error) {
return loraRadio.LoraRx(LORA_DEFAULT_RXTIMEOUT_MS)
}