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
+32 -6
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.
@@ -172,7 +172,7 @@ func power(setting string) error {
return nil
}
// Unconfirmed message repeats times.
// Unconfirmed message repeats times.
func rept(setting string) error {
cmd := "REPT"
writeCommandOutput(cmd, setting)
@@ -180,9 +180,9 @@ func rept(setting string) error {
return nil
}
// Confirmed message retry times. Valid range 0~254,
// Confirmed message retry times. Valid range 0~254,
// if retry times is less than 2, only one message will
// be sent. Random delay 3 - 10s between each retry
// be sent. Random delay 3 - 10s between each retry
// (band duty cycle limitation has the priority)
func retry(setting string) error {
cmd := "RETRY"
@@ -329,12 +329,38 @@ func log(setting string) error {
return nil
}
func crlf() {
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"))
}
func writeCommandOutput(cmd, data string) {
uart.Write([]byte("+"+cmd+": "))
uart.Write([]byte("+" + cmd + ": "))
uart.Write([]byte(data))
crlf()
}
+6 -6
View File
@@ -15,12 +15,12 @@ import (
// change these to test a different UART or pins if available
var (
uart = machine.Serial
tx = machine.UART_TX_PIN
rx = machine.UART_RX_PIN
uart = machine.Serial
tx = machine.UART_TX_PIN
rx = machine.UART_RX_PIN
input = make([]byte, 0, 64)
radio LoraRadio
radio LoraRadio
defaultTimeout uint32 = 1000
)
@@ -55,11 +55,11 @@ func main() {
}
}
func fail(msg string) {
func fail(msg string) {
for {
uart.Write([]byte(msg))
crlf()
time.Sleep(time.Minute)
}
}
}
+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 {
+11 -7
View File
@@ -4,7 +4,7 @@ package main
// do simulator setup here
func setupLora() (LoraRadio, error) {
return &SimLoraRadio{}, nil
return &SimLoraRadio{}, nil
}
type SimLoraRadio struct {
@@ -21,13 +21,17 @@ func (sr *SimLoraRadio) LoraRx(timeoutMs uint32) ([]uint8, error) {
return nil, nil
}
func (sr *SimLoraRadio) SetLoraFrequency(freq uint32) {}
func (sr *SimLoraRadio) SetLoraIqMode(mode uint8) {}
func (sr *SimLoraRadio) SetLoraCodingRate(cr uint8) {}
func (sr *SimLoraRadio) SetLoraBandwidth(bw uint8) {}
func (sr *SimLoraRadio) SetLoraCrc(enable bool) {}
func (sr *SimLoraRadio) SetLoraFrequency(freq uint32) {}
func (sr *SimLoraRadio) SetLoraIqMode(mode uint8) {}
func (sr *SimLoraRadio) SetLoraCodingRate(cr uint8) {}
func (sr *SimLoraRadio) SetLoraBandwidth(bw uint8) {}
func (sr *SimLoraRadio) SetLoraCrc(enable bool) {}
func (sr *SimLoraRadio) SetLoraSpreadingFactor(sf uint8) {}
func firmwareVersion() string {
return "Simulator "+currentVersion()
return "Simulator " + currentVersion()
}
func lorarx() ([]byte, error) {
return nil, nil
}
+5 -1
View File
@@ -52,7 +52,7 @@ func setupLora() (LoraRadio, error) {
loraRadio.LoraConfig(loraConf)
return loraRadio, nil
return loraRadio, nil
}
// radioIntHandler will take care of radio interrupts
@@ -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)
}
+16 -9
View File
@@ -11,15 +11,19 @@ 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:
rstPin = machine.D11
csPin = machine.D10
dio0Pin = machine.D6
dio1Pin = machine.D9
spi = machine.SPI0
rstPin = machine.D11
csPin = machine.D10
dio0Pin = machine.D6
dio1Pin = machine.D9
spi = machine.SPI0
loraRadio *sx127x.Device
)
@@ -64,15 +68,18 @@ func setupLora() (LoraRadio, error) {
loraRadio.LoraConfig(loraConf)
return loraRadio, nil
return loraRadio, nil
}
func dioIrqHandler(machine.Pin) {
loraRadio.HandleInterrupt()
}
func firmwareVersion() string {
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)
}
+1 -1
View File
@@ -4,4 +4,4 @@ const VERSION = "0.0.1"
func currentVersion() string {
return VERSION
}
}