diff --git a/cmd/load/main.go b/cmd/load/main.go index 759cda7..84765da 100644 --- a/cmd/load/main.go +++ b/cmd/load/main.go @@ -82,6 +82,9 @@ func run(buildDir string) error { if err != nil { fmt.Fprintf(os.Stderr, "warning: Info request failed: %v\n", err) } else { + fmt.Printf("Board ID: %02X%02X%02X%02X%02X%02X%02X%02X\n", + info.BoardID[0], info.BoardID[1], info.BoardID[2], info.BoardID[3], + info.BoardID[4], info.BoardID[5], info.BoardID[6], info.BoardID[7]) 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]) diff --git a/include/protocol.h b/include/protocol.h index 961ac35..3611a26 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -5,10 +5,21 @@ #include #include -struct ResponsePICOBOOT { +struct Envelope { + static constexpr int8_t ext_id = 0; + uint32_t message_id; + uint32_t checksum; + std::vector payload; + auto as_tuple() const { return std::tie(message_id, checksum, payload); } + auto as_tuple() { return std::tie(message_id, checksum, payload); } +}; + +struct DeviceError { static constexpr int8_t ext_id = 1; - auto as_tuple() const { return std::tie(); } - auto as_tuple() { return std::tie(); } + uint32_t code; + std::string message; + auto as_tuple() const { return std::tie(code, message); } + auto as_tuple() { return std::tie(code, message); } }; struct RequestPICOBOOT { @@ -17,6 +28,12 @@ struct RequestPICOBOOT { auto as_tuple() { return std::tie(); } }; +struct ResponsePICOBOOT { + static constexpr int8_t ext_id = 3; + auto as_tuple() const { 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(); } @@ -25,24 +42,8 @@ struct RequestInfo { struct ResponseInfo { static constexpr int8_t ext_id = 5; + std::array board_id; 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; - std::string message; - auto as_tuple() const { return std::tie(code, message); } - auto as_tuple() { return std::tie(code, message); } -}; - -struct Envelope { - static constexpr int8_t ext_id = 0; - uint32_t message_id; - uint32_t checksum; - std::vector payload; - auto as_tuple() const { return std::tie(message_id, checksum, payload); } - auto as_tuple() { return std::tie(message_id, checksum, payload); } + auto as_tuple() const { return std::tie(board_id, mac); } + auto as_tuple() { return std::tie(board_id, mac); } }; diff --git a/lib/client/types.go b/lib/client/types.go index c3cb7fe..dd790b7 100644 --- a/lib/client/types.go +++ b/lib/client/types.go @@ -2,12 +2,13 @@ package client import "github.com/theater/picomap/lib/msgpack" -type ResponsePICOBOOT struct{} type RequestPICOBOOT struct{} +type ResponsePICOBOOT struct{} type RequestInfo struct{} type ResponseInfo struct { - MAC [6]byte + BoardID [8]byte + MAC [6]byte } type DeviceError struct { @@ -27,9 +28,9 @@ type Envelope struct { func init() { msgpack.RegisterExt(0, (*Envelope)(nil)) - msgpack.RegisterExt(1, (*ResponsePICOBOOT)(nil)) + msgpack.RegisterExt(1, (*DeviceError)(nil)) msgpack.RegisterExt(2, (*RequestPICOBOOT)(nil)) - msgpack.RegisterExt(3, (*DeviceError)(nil)) + msgpack.RegisterExt(3, (*ResponsePICOBOOT)(nil)) msgpack.RegisterExt(4, (*RequestInfo)(nil)) msgpack.RegisterExt(5, (*ResponseInfo)(nil)) } diff --git a/picomap.cpp b/picomap.cpp index 979262f..5068f08 100644 --- a/picomap.cpp +++ b/picomap.cpp @@ -1,6 +1,7 @@ #include #include "pico/stdlib.h" #include "pico/bootrom.h" +#include "pico/unique_id.h" #include "device.h" extern "C" { @@ -25,6 +26,7 @@ static bool w6300_init() { int main() { stdio_init_all(); + stdio_set_translate_crlf(&stdio_usb, false); if (!w6300_init()) { printf("W6300 init failed\n"); @@ -54,6 +56,9 @@ int main() { break; case RequestInfo::ext_id: { ResponseInfo info; + pico_unique_board_id_t uid; + pico_get_unique_board_id(&uid); + std::copy(uid.id, uid.id + 8, info.board_id.begin()); getSHAR(info.mac.data()); send_bytes(encode_response(msg->message_id, info)); break;