diff --git a/cmd/load/main.go b/cmd/load/main.go index f0b7274..759cda7 100644 --- a/cmd/load/main.go +++ b/cmd/load/main.go @@ -65,6 +65,29 @@ func run(buildDir string) error { fmt.Println("Rebooting...") _ = picotool.Reboot() + time.Sleep(3 * time.Second) + + dev, err = picoserial.FindDevice() + if err != nil { + return err + } + if dev != "" { + t, err := picoserial.Open(dev) + if err != nil { + return err + } + c := client.New(t, 2*time.Second) + info, err := c.Info() + c.Close() + if err != nil { + fmt.Fprintf(os.Stderr, "warning: Info request failed: %v\n", err) + } else { + fmt.Printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", + info.MAC[0], info.MAC[1], info.MAC[2], + info.MAC[3], info.MAC[4], info.MAC[5]) + } + } + fmt.Println("Done.") return nil } diff --git a/include/msgpackpp.h b/include/msgpackpp.h index 78fa97f..6acafc1 100644 --- a/include/msgpackpp.h +++ b/include/msgpackpp.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include #include @@ -366,6 +367,9 @@ public: pack_result pack(const std::vector &v) { return pack_bin(v); } + template + pack_result pack(const std::array &v) { return pack_bin(v); } + template pack_result pack(const std::tuple &t) { auto r = pack_array(sizeof...(Ts)); @@ -725,6 +729,15 @@ inline result unpack(const parser &p, std::string &out) { return p.next(); } +template +result unpack(const parser &p, std::array &out) { + auto v = p.get_binary_view(); + if (!v) return std::unexpected(v.error()); + if (v->size() != N) return std::unexpected(error_code::type_error); + std::copy(v->begin(), v->end(), out.begin()); + return p.next(); +} + inline result unpack(const parser &p, std::vector &out) { auto v = p.get_binary_view(); if (!v) return std::unexpected(v.error()); diff --git a/include/protocol.h b/include/protocol.h index e9629ce..961ac35 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -16,6 +17,19 @@ struct RequestPICOBOOT { auto as_tuple() { return std::tie(); } }; +struct RequestInfo { + static constexpr int8_t ext_id = 4; + auto as_tuple() const { return std::tie(); } + auto as_tuple() { return std::tie(); } +}; + +struct ResponseInfo { + static constexpr int8_t ext_id = 5; + std::array mac; + auto as_tuple() const { return std::tie(mac); } + auto as_tuple() { return std::tie(mac); } +}; + struct DeviceError { static constexpr int8_t ext_id = 3; uint32_t code; diff --git a/lib/client/client.go b/lib/client/client.go index 1ae4291..d31d7da 100644 --- a/lib/client/client.go +++ b/lib/client/client.go @@ -90,3 +90,7 @@ func (c *Client) PICOBOOT() error { _, err := roundTrip[ResponsePICOBOOT](c, &RequestPICOBOOT{}) return err } + +func (c *Client) Info() (*ResponseInfo, error) { + return roundTrip[ResponseInfo](c, &RequestInfo{}) +} diff --git a/lib/client/types.go b/lib/client/types.go index e48ff7d..c3cb7fe 100644 --- a/lib/client/types.go +++ b/lib/client/types.go @@ -5,6 +5,11 @@ import "github.com/theater/picomap/lib/msgpack" type ResponsePICOBOOT struct{} type RequestPICOBOOT struct{} +type RequestInfo struct{} +type ResponseInfo struct { + MAC [6]byte +} + type DeviceError struct { Code uint32 Message string @@ -25,4 +30,6 @@ func init() { msgpack.RegisterExt(1, (*ResponsePICOBOOT)(nil)) msgpack.RegisterExt(2, (*RequestPICOBOOT)(nil)) msgpack.RegisterExt(3, (*DeviceError)(nil)) + msgpack.RegisterExt(4, (*RequestInfo)(nil)) + msgpack.RegisterExt(5, (*ResponseInfo)(nil)) } diff --git a/picomap.cpp b/picomap.cpp index 7da9345..979262f 100644 --- a/picomap.cpp +++ b/picomap.cpp @@ -52,6 +52,12 @@ int main() { sleep_ms(100); reset_usb_boot(0, 1); break; + case RequestInfo::ext_id: { + ResponseInfo info; + getSHAR(info.mac.data()); + send_bytes(encode_response(msg->message_id, info)); + break; + } } } }