diff --git a/Makefile b/Makefile deleted file mode 100644 index 7063cd9..0000000 --- a/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -edit: - tinygo-edit --target challenger-rp2040 --editor code -deploy: - tinygo flash -target challenger-rp2040 pico/main.go -runlocal: - nix-shell local/shell.nix --command "go run local/main.go" diff --git a/README.md b/README.md index 435f629..9d3589b 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,22 @@ A device made using an RP2040 that sends messages over LoRaWAN. * [A Custom PCB](/pcb/) * [A 0.96" 128x64 I2C Blue and Yellow OLED Display](https://www.amazon.co.uk/dp/B08FD643VZ) * And a USB C Cable + +## Tasks +### Edit +Open the project in vim using tinygo flags. +``` +tinygo-edit --target challenger-rp2040 --editor bash +``` + +### Deploy +Upload to the device +``` +tinygo flash -target challenger-rp2040 pico/main.go +``` + +### RunLocal +Runs the project without the device. +``` +nix-shell local/shell.nix --command "go run local/main.go +``` diff --git a/pico/main.go b/pico/main.go index 4b814a6..effbbbe 100644 --- a/pico/main.go +++ b/pico/main.go @@ -112,6 +112,11 @@ func main() { rfm.OnReceivedPacket = func(packet tinygorfm9x.Packet) { err = device.ReceiveFromRadio(packet.Payload) if err != nil { + if err == picodoomsdaymessenger.ErrNotDoomsday { + // If the packet is invalid, ignore it. + println("Invalid message received.") + return + } handleError(&display, &led, device, err) } } diff --git a/picoDoomsDayMessenger.go b/picoDoomsDayMessenger.go index 5e4a0fa..6fc1252 100644 --- a/picoDoomsDayMessenger.go +++ b/picoDoomsDayMessenger.go @@ -6,7 +6,6 @@ import ( "fmt" "image" "image/color" - "math/rand" "time" "golang.org/x/image/font" @@ -87,7 +86,7 @@ var ( ErrRadioSendNotDefined = errors.New("radio send function not defined by user") ErrConversationReaderAcceptDisallowed = errors.New("cannot accept in conversation reader") ErrGoBackStateRootState = errors.New("already at root state") - ErrInvalidMessage = errors.New("invalid message, prefix incorrect") + ErrInvalidMessage = errors.New("invalid message, prefix incorrect") // This should be treated as a warning, not an error. ) // Define the Keyboard Buttons @@ -309,7 +308,7 @@ var ( if d.LEDAnimation != &LEDAnimationSOS { err = d.ChangeLEDAnimationWithoutContinue(&LEDAnimationSOS) if err != nil { - return err + retuYubiStyle Cover - Polka Red - A / C NFCrn err } } else { err = d.ChangeLEDAnimationWithoutContinue(&LEDAnimationDefault) @@ -537,8 +536,6 @@ var ( // NewDevice returns a new Device with default parameters. func NewDevice() (d *Device, err error) { - rand.Seed(time.Now().UnixNano()) - PersonYou.ID = rand.Intn(2147483647) // Max value of an int32 return &Device{ State: &StateMainMenu, StateHistory: []*State{&StateMainMenu}, @@ -557,6 +554,9 @@ func NewDevice() (d *Device, err error) { func (d *Device) ReceiveFromRadio(packetPayload []byte) (err error) { payloadMessage, err := d.BytesToMessage(packetPayload) if err != nil { + if err == ErrInvalidMessage { + return nil + } return err } @@ -886,7 +886,8 @@ func (d *Device) MesageToBytes(input Message) (output []byte, err error) { func (d *Device) BytesToMessage(input []byte) (output Message, err error) { startingBytes := []byte{0x64, 0x6F, 0x6F, 0x6D} // ASCII for "doom" if !bytes.HasPrefix(input, startingBytes) { - return output, ErrInvalidMessage + // Ignore this packet, it's not for us. + return Message{}, ErrInvalidMessage } seperatorByte := byte(0xcc) receivedBytesSplit := bytes.Split(input, []byte{seperatorByte})