diff --git a/examples/lora/atcmd/README.md b/examples/lora/atcmd/README.md index f50c099..fda176c 100644 --- a/examples/lora/atcmd/README.md +++ b/examples/lora/atcmd/README.md @@ -4,7 +4,7 @@ $ tinygo monitor Connected to /dev/ttyACM0. Press Ctrl-C to exit. +AT: OK -+VER: 0.0.1 sx127x v18 ++VER: 0.0.1 (sx127x v18) ``` # Building diff --git a/examples/lora/atcmd/commands.go b/examples/lora/atcmd/commands.go index de58128..64c1ee1 100644 --- a/examples/lora/atcmd/commands.go +++ b/examples/lora/atcmd/commands.go @@ -1,6 +1,7 @@ package main import ( + "encoding/hex" "strings" ) @@ -329,6 +330,49 @@ func log(setting string) error { return nil } +func send(data string) error { + cmd := "SEND" + writeCommandOutput(cmd, "Start") + + // remove leading/trailing quotes + data = strings.Trim(data, "\"'") + + if err := radio.LoraTx([]byte(data), defaultTimeout); err != nil { + writeCommandOutput(cmd, err.Error()) + + return err + } + + writeCommandOutput(cmd, "Done") + return nil +} + +func sendhex(data string) error { + cmd := "SENDHEX" + writeCommandOutput(cmd, "Start") + + // remove leading/trailing quotes + data = strings.Trim(data, "\"'") + + // convert data from hex formatted string + data = strings.ReplaceAll(data, " ", "") + payload, err := hex.DecodeString(data) + if err != nil { + writeCommandOutput(cmd, err.Error()) + + return err + } + + if err := radio.LoraTx(payload, defaultTimeout); err != nil { + writeCommandOutput(cmd, err.Error()) + + return err + } + + writeCommandOutput(cmd, "Done") + return nil +} + func recv(setting string) error { cmd := "RECV" diff --git a/examples/lora/atcmd/parser.go b/examples/lora/atcmd/parser.go index e2d2cd7..8dc9dcf 100644 --- a/examples/lora/atcmd/parser.go +++ b/examples/lora/atcmd/parser.go @@ -103,6 +103,10 @@ func parseCommand(cmd, args string) error { recv(args) case "RECVHEX": recvhex(args) + case "SEND": + send(args) + case "SENDHEX": + sendhex(args) default: return errInvalidCommand } diff --git a/examples/lora/atcmd/sim.go b/examples/lora/atcmd/sim.go index c2c252e..f070077 100644 --- a/examples/lora/atcmd/sim.go +++ b/examples/lora/atcmd/sim.go @@ -29,7 +29,7 @@ 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) { diff --git a/examples/lora/atcmd/wl55jc.go b/examples/lora/atcmd/wl55jc.go new file mode 100644 index 0000000..8b2738a --- /dev/null +++ b/examples/lora/atcmd/wl55jc.go @@ -0,0 +1,54 @@ +//go:build nucleowl55jc + +/* + Nucleo WL55JC1 + RFSwitch + ++-----------+---------+------------+------------+ +| | FE_CTRL1 | FE_CTRL2 | FE_CTRL3 | +| | (PC4) | (PC5) | (PC3) | ++-----------+----------+-----------+------------+ +| TX_HP | LOW | HIGH | HIGH | +| TX_LP | HIGH | HIGH | HIGH | +| RX | HIGH | LOW | HIGH | ++-----------+----------+-----------+------------+ +*/ +package main + +import ( + "machine" + + "tinygo.org/x/drivers/sx126x" +) + +type CustomSwitch struct { +} + +func (s CustomSwitch) InitRFSwitch() { + machine.PC4.Configure(machine.PinConfig{Mode: machine.PinOutput}) + machine.PC5.Configure(machine.PinConfig{Mode: machine.PinOutput}) + machine.PC3.Configure(machine.PinConfig{Mode: machine.PinOutput}) +} + +func (s CustomSwitch) SetRfSwitchMode(mode int) error { + switch mode { + + case sx126x.RFSWITCH_TX_HP: + machine.PC4.Set(false) + machine.PC5.Set(true) + machine.PC3.Set(true) + + case sx126x.RFSWITCH_TX_LP: + machine.PC4.Set(true) + machine.PC5.Set(true) + machine.PC3.Set(true) + + case sx126x.RFSWITCH_RX: + machine.PC4.Set(true) + machine.PC5.Set(false) + machine.PC3.Set(true) + + } + return nil + +}