Add RequestInfo/ResponseInfo with MAC address

This commit is contained in:
Ian Gulliver
2026-04-04 15:00:16 +09:00
parent 46af5becfe
commit d2b9a2e2aa
6 changed files with 67 additions and 0 deletions

View File

@@ -65,6 +65,29 @@ func run(buildDir string) error {
fmt.Println("Rebooting...") fmt.Println("Rebooting...")
_ = picotool.Reboot() _ = 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.") fmt.Println("Done.")
return nil return nil
} }

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <array>
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
#include <expected> #include <expected>
@@ -366,6 +367,9 @@ public:
pack_result pack(const std::vector<uint8_t> &v) { return pack_bin(v); } pack_result pack(const std::vector<uint8_t> &v) { return pack_bin(v); }
template <size_t N>
pack_result pack(const std::array<uint8_t, N> &v) { return pack_bin(v); }
template <typename... Ts> template <typename... Ts>
pack_result pack(const std::tuple<Ts...> &t) { pack_result pack(const std::tuple<Ts...> &t) {
auto r = pack_array(sizeof...(Ts)); auto r = pack_array(sizeof...(Ts));
@@ -725,6 +729,15 @@ inline result<parser> unpack(const parser &p, std::string &out) {
return p.next(); return p.next();
} }
template <size_t N>
result<parser> unpack(const parser &p, std::array<uint8_t, N> &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<parser> unpack(const parser &p, std::vector<uint8_t> &out) { inline result<parser> unpack(const parser &p, std::vector<uint8_t> &out) {
auto v = p.get_binary_view(); auto v = p.get_binary_view();
if (!v) return std::unexpected(v.error()); if (!v) return std::unexpected(v.error());

View File

@@ -1,4 +1,5 @@
#pragma once #pragma once
#include <array>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <tuple> #include <tuple>
@@ -16,6 +17,19 @@ struct RequestPICOBOOT {
auto as_tuple() { return std::tie(); } 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<uint8_t, 6> mac;
auto as_tuple() const { return std::tie(mac); }
auto as_tuple() { return std::tie(mac); }
};
struct DeviceError { struct DeviceError {
static constexpr int8_t ext_id = 3; static constexpr int8_t ext_id = 3;
uint32_t code; uint32_t code;

View File

@@ -90,3 +90,7 @@ func (c *Client) PICOBOOT() error {
_, err := roundTrip[ResponsePICOBOOT](c, &RequestPICOBOOT{}) _, err := roundTrip[ResponsePICOBOOT](c, &RequestPICOBOOT{})
return err return err
} }
func (c *Client) Info() (*ResponseInfo, error) {
return roundTrip[ResponseInfo](c, &RequestInfo{})
}

View File

@@ -5,6 +5,11 @@ import "github.com/theater/picomap/lib/msgpack"
type ResponsePICOBOOT struct{} type ResponsePICOBOOT struct{}
type RequestPICOBOOT struct{} type RequestPICOBOOT struct{}
type RequestInfo struct{}
type ResponseInfo struct {
MAC [6]byte
}
type DeviceError struct { type DeviceError struct {
Code uint32 Code uint32
Message string Message string
@@ -25,4 +30,6 @@ func init() {
msgpack.RegisterExt(1, (*ResponsePICOBOOT)(nil)) msgpack.RegisterExt(1, (*ResponsePICOBOOT)(nil))
msgpack.RegisterExt(2, (*RequestPICOBOOT)(nil)) msgpack.RegisterExt(2, (*RequestPICOBOOT)(nil))
msgpack.RegisterExt(3, (*DeviceError)(nil)) msgpack.RegisterExt(3, (*DeviceError)(nil))
msgpack.RegisterExt(4, (*RequestInfo)(nil))
msgpack.RegisterExt(5, (*ResponseInfo)(nil))
} }

View File

@@ -52,6 +52,12 @@ int main() {
sleep_ms(100); sleep_ms(100);
reset_usb_boot(0, 1); reset_usb_boot(0, 1);
break; break;
case RequestInfo::ext_id: {
ResponseInfo info;
getSHAR(info.mac.data());
send_bytes(encode_response(msg->message_id, info));
break;
}
} }
} }
} }