soypat / cyw43439

Driver for the Wifi+bluetooth integrated circuit on the pico.
MIT License
109 stars 6 forks source link

Use external TCP stack #24

Closed soypat closed 9 months ago

soypat commented 9 months ago

Switching from developing https://github.com/soypat/cyw43439/pull/20 as an internal TCP stack to an externally imported TCP stack.

The External TCP stack is https://github.com/soypat/seqs

soypat commented 9 months ago

@scottfeldman Alright gonna go ahead and merge this since it's quite a noisy handful. Not much has changed, just moved files around mostly.

The DHCP and TCP examples are working on my end. To test I'm using the following program. You'll need ot modify the IP below to match the one assigned by DHCP.

# To flash program. This will also attach yourself to the USB output.
$ tinygo flash -target=pico -opt=1 -stack-size=8kb -size=short -monitor  ./examples/tcpserver/
// Modify IP below to match the one assigned by DHCP!
package main

import (
    "fmt"
    "net"
    "net/netip"
    "time"
)

func main() {
    const server = "192.168.1.120:1234" // Edit this to match your DHCP
    raddr := netip.MustParseAddrPort(server)
    conn, err := net.DialTCP("tcp", nil, net.TCPAddrFromAddrPort(raddr))
    if err != nil {
        panic(err)
    }
    // wait a second for SYN/ACK stuff.
    time.Sleep(time.Second)
    dd := make([]byte, 1024)
    go func() {
        for {
            time.Sleep(time.Second)
            n, err := conn.Read(dd)
            if err != nil {
                fmt.Println("rerr", err.Error())
            }
            if n > 0 {
                fmt.Printf("read %q\n", string(dd[:n]))
            }
        }
    }()
    for {
        _, err = conn.Write([]byte("hello"))
        if err != nil {
            fmt.Println("werr", err.Error())
        }
        time.Sleep(time.Second)
    }
}