Remove USB/serial support: network-only protocol, drop tinyusb and PICOBOOT
This commit is contained in:
+2
-53
@@ -23,14 +23,12 @@ type target struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type targetFlags struct {
|
type targetFlags struct {
|
||||||
usb string
|
|
||||||
udp string
|
udp string
|
||||||
iface string
|
iface string
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTargetFlags(fs *flag.FlagSet) *targetFlags {
|
func addTargetFlags(fs *flag.FlagSet) *targetFlags {
|
||||||
tf := &targetFlags{}
|
tf := &targetFlags{}
|
||||||
fs.StringVar(&tf.usb, "usb", "", "comma-separated USB serial devices")
|
|
||||||
fs.StringVar(&tf.udp, "udp", "", "comma-separated UDP IP addresses")
|
fs.StringVar(&tf.udp, "udp", "", "comma-separated UDP IP addresses")
|
||||||
fs.StringVar(&tf.iface, "iface", "", "network interface for multicast discovery")
|
fs.StringVar(&tf.iface, "iface", "", "network interface for multicast discovery")
|
||||||
return tf
|
return tf
|
||||||
@@ -39,17 +37,6 @@ func addTargetFlags(fs *flag.FlagSet) *targetFlags {
|
|||||||
func (tf *targetFlags) connect(timeout time.Duration) ([]target, error) {
|
func (tf *targetFlags) connect(timeout time.Duration) ([]target, error) {
|
||||||
var targets []target
|
var targets []target
|
||||||
|
|
||||||
if tf.usb != "" {
|
|
||||||
for _, dev := range strings.Split(tf.usb, ",") {
|
|
||||||
dev = strings.TrimSpace(dev)
|
|
||||||
c, err := client.NewSerial(dev, timeout)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("usb %s: %w", dev, err)
|
|
||||||
}
|
|
||||||
targets = append(targets, target{dev, c})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tf.udp != "" {
|
if tf.udp != "" {
|
||||||
for _, addr := range strings.Split(tf.udp, ",") {
|
for _, addr := range strings.Split(tf.udp, ",") {
|
||||||
addr = strings.TrimSpace(addr)
|
addr = strings.TrimSpace(addr)
|
||||||
@@ -84,21 +71,6 @@ func (tf *targetFlags) connect(timeout time.Duration) ([]target, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tf.usb == "" && tf.udp == "" && tf.iface == "" {
|
|
||||||
devs, err := client.ListSerial()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for _, dev := range devs {
|
|
||||||
c, err := client.NewSerial(dev, timeout)
|
|
||||||
if err != nil {
|
|
||||||
slog.Warn("connect error", "dev", dev, "err", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
targets = append(targets, target{dev, c})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(targets) == 0 {
|
if len(targets) == 0 {
|
||||||
return nil, fmt.Errorf("no devices found")
|
return nil, fmt.Errorf("no devices found")
|
||||||
}
|
}
|
||||||
@@ -113,7 +85,7 @@ func closeTargets(targets []target) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Fprintf(os.Stderr, "usage: picomap <command> [args...]\n\ncommands:\n info\n flash-status\n load\n log\n reboot\n picoboot\n test\n")
|
fmt.Fprintf(os.Stderr, "usage: picomap <command> [args...]\n\ncommands:\n info\n flash-status\n load\n log\n reboot\n test\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
cmd := os.Args[1]
|
cmd := os.Args[1]
|
||||||
@@ -131,12 +103,10 @@ func main() {
|
|||||||
err = cmdLog(args)
|
err = cmdLog(args)
|
||||||
case "reboot":
|
case "reboot":
|
||||||
err = cmdReboot(args)
|
err = cmdReboot(args)
|
||||||
case "picoboot":
|
|
||||||
err = cmdPICOBOOT(args)
|
|
||||||
case "test":
|
case "test":
|
||||||
err = cmdTestGroup(args)
|
err = cmdTestGroup(args)
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "usage: picomap <command> [args...]\n\ncommands:\n info\n flash-status\n load\n log\n reboot\n picoboot\n test\n")
|
fmt.Fprintf(os.Stderr, "usage: picomap <command> [args...]\n\ncommands:\n info\n flash-status\n load\n log\n reboot\n test\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -253,27 +223,6 @@ func cmdReboot(args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdPICOBOOT(args []string) error {
|
|
||||||
fs := flag.NewFlagSet("picoboot", flag.ExitOnError)
|
|
||||||
tf := addTargetFlags(fs)
|
|
||||||
fs.Parse(args)
|
|
||||||
|
|
||||||
targets, err := tf.connect(500 * time.Millisecond)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer closeTargets(targets)
|
|
||||||
|
|
||||||
for _, t := range targets {
|
|
||||||
if err := t.client.PICOBOOT(); err != nil {
|
|
||||||
slog.Error("picoboot error", "via", t.name, "err", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
slog.Info("picoboot", "via", t.name)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func boardSerial(id [8]byte) string {
|
func boardSerial(id [8]byte) string {
|
||||||
return fmt.Sprintf("%02X%02X%02X%02X%02X%02X%02X%02X",
|
return fmt.Sprintf("%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7])
|
id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7])
|
||||||
|
|||||||
@@ -18,11 +18,10 @@ set(LIB_SOURCES
|
|||||||
lib/igmp.cpp
|
lib/igmp.cpp
|
||||||
lib/ipv4.cpp
|
lib/ipv4.cpp
|
||||||
lib/net.cpp
|
lib/net.cpp
|
||||||
lib/tusb_config.cpp
|
|
||||||
w6300/w6300.cpp
|
w6300/w6300.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIB_DEPS pico_stdlib pico_sha256 tinyusb_device tinyusb_board hardware_pio hardware_spi hardware_dma hardware_clocks)
|
set(LIB_DEPS pico_stdlib pico_sha256 pico_unique_id hardware_pio hardware_spi hardware_dma hardware_clocks)
|
||||||
|
|
||||||
add_executable(picomap firmware.cpp ${LIB_SOURCES})
|
add_executable(picomap firmware.cpp ${LIB_SOURCES})
|
||||||
target_include_directories(picomap PRIVATE include w6300)
|
target_include_directories(picomap PRIVATE include w6300)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
std::string_view firmware_name = "picomap";
|
std::string_view firmware_name = "picomap";
|
||||||
|
|
||||||
static constexpr handler_entry handlers[] = {
|
static constexpr handler_entry handlers[] = {
|
||||||
{RequestPICOBOOT::ext_id, typed_handler<RequestPICOBOOT, handle_picoboot>},
|
|
||||||
{RequestInfo::ext_id, typed_handler<RequestInfo, handle_info>},
|
{RequestInfo::ext_id, typed_handler<RequestInfo, handle_info>},
|
||||||
{RequestLog::ext_id, typed_handler<RequestLog, handle_log>},
|
{RequestLog::ext_id, typed_handler<RequestLog, handle_log>},
|
||||||
{RequestFlashErase::ext_id, typed_handler<RequestFlashErase, handle_flash_erase>},
|
{RequestFlashErase::ext_id, typed_handler<RequestFlashErase, handle_flash_erase>},
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ extern std::string_view firmware_name;
|
|||||||
|
|
||||||
void handlers_init();
|
void handlers_init();
|
||||||
void handlers_start();
|
void handlers_start();
|
||||||
std::optional<ResponsePICOBOOT> handle_picoboot(const responder& resp, const RequestPICOBOOT&);
|
|
||||||
std::optional<ResponseInfo> handle_info(const responder& resp, const RequestInfo&);
|
std::optional<ResponseInfo> handle_info(const responder& resp, const RequestInfo&);
|
||||||
std::optional<ResponseLog> handle_log(const responder& resp, const RequestLog&);
|
std::optional<ResponseLog> handle_log(const responder& resp, const RequestLog&);
|
||||||
std::optional<ResponseFlashErase> handle_flash_erase(const responder& resp, const RequestFlashErase&);
|
std::optional<ResponseFlashErase> handle_flash_erase(const responder& resp, const RequestFlashErase&);
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
|
||||||
#define CFG_TUD_CDC 1
|
|
||||||
#define CFG_TUD_CDC_RX_BUFSIZE 256
|
|
||||||
#define CFG_TUD_CDC_TX_BUFSIZE 256
|
|
||||||
#define CFG_TUD_CDC_EP_BUFSIZE 64
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <cstdint>
|
|
||||||
#include <span>
|
|
||||||
#include <vector>
|
|
||||||
#include "tusb.h"
|
|
||||||
#include "ring_buffer.h"
|
|
||||||
|
|
||||||
struct usb_cdc {
|
|
||||||
ring_buffer<uint8_t, 8192> tx;
|
|
||||||
|
|
||||||
bool send(std::span<const uint8_t> data) {
|
|
||||||
if (!tx.push(data)) return false;
|
|
||||||
drain();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void send(const std::vector<uint8_t>& data) {
|
|
||||||
send(std::span<const uint8_t>{data});
|
|
||||||
}
|
|
||||||
|
|
||||||
void drain() {
|
|
||||||
while (!tx.empty()) {
|
|
||||||
uint32_t avail = tud_cdc_write_available();
|
|
||||||
if (avail == 0) break;
|
|
||||||
auto chunk = tx.read_contiguous();
|
|
||||||
if (chunk.size() > avail) chunk = chunk.first(avail);
|
|
||||||
tud_cdc_write(chunk.data(), chunk.size());
|
|
||||||
tx.consume(chunk.size());
|
|
||||||
}
|
|
||||||
tud_cdc_write_flush();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -27,18 +27,6 @@ struct DeviceError {
|
|||||||
auto as_tuple() { return std::tie(code, message); }
|
auto as_tuple() { return std::tie(code, message); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RequestPICOBOOT {
|
|
||||||
static constexpr int8_t ext_id = 2;
|
|
||||||
auto as_tuple() const { return std::tie(); }
|
|
||||||
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 {
|
struct RequestInfo {
|
||||||
static constexpr int8_t ext_id = 4;
|
static constexpr int8_t ext_id = 4;
|
||||||
auto as_tuple() const { return std::tie(); }
|
auto as_tuple() const { return std::tie(); }
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "tusb.h"
|
|
||||||
#include "wire.h"
|
#include "wire.h"
|
||||||
#include "usb_cdc.h"
|
|
||||||
#include "timer_queue.h"
|
#include "timer_queue.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "igmp.h"
|
#include "igmp.h"
|
||||||
@@ -19,7 +17,6 @@ static void igmp_reannounce() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_init() {
|
void dispatch_init() {
|
||||||
tusb_init();
|
|
||||||
net_init();
|
net_init();
|
||||||
dispatch_schedule_ms(60000, igmp_reannounce);
|
dispatch_schedule_ms(60000, igmp_reannounce);
|
||||||
dlog("dispatch_init complete");
|
dlog("dispatch_init complete");
|
||||||
@@ -41,8 +38,6 @@ bool dispatch_cancel_timer(timer_handle h) {
|
|||||||
handler_map[entry.type_id] = entry.handle;
|
handler_map[entry.type_id] = entry.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static usb_cdc usb;
|
|
||||||
static static_vector<uint8_t, 4096> usb_rx_buf;
|
|
||||||
static std::array<uint8_t, 4096> tx_buf;
|
static std::array<uint8_t, 4096> tx_buf;
|
||||||
|
|
||||||
auto dispatch_msg = [&](const DecodedMessage& msg, send_fn send) {
|
auto dispatch_msg = [&](const DecodedMessage& msg, send_fn send) {
|
||||||
@@ -65,48 +60,9 @@ bool dispatch_cancel_timer(timer_handle h) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
uint32_t save = save_and_disable_interrupts();
|
uint32_t save = save_and_disable_interrupts();
|
||||||
|
|
||||||
dlog_if_slow("tud_task", 1000, [&]{ tud_task(); });
|
|
||||||
dlog_if_slow("drain", 1000, [&]{ usb.drain(); });
|
|
||||||
dlog_if_slow("timers", 1000, [&]{ timers.run(); });
|
dlog_if_slow("timers", 1000, [&]{ timers.run(); });
|
||||||
dlog_if_slow("net_poll", 1000, [&]{ net_poll(std::span{tx_buf}); });
|
dlog_if_slow("net_poll", 1000, [&]{ net_poll(std::span{tx_buf}); });
|
||||||
|
|
||||||
while (tud_cdc_available()) {
|
|
||||||
uint8_t byte;
|
|
||||||
if (tud_cdc_read(&byte, 1) != 1) break;
|
|
||||||
|
|
||||||
usb_rx_buf.push_back(byte);
|
|
||||||
|
|
||||||
auto msg = try_decode(usb_rx_buf);
|
|
||||||
if (!msg) {
|
|
||||||
if (usb_rx_buf.full()) usb_rx_buf.clear();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch_msg(*msg, [&](encode_fn encode) {
|
|
||||||
uint8_t buf[4096];
|
|
||||||
span_writer out(buf, sizeof(buf));
|
|
||||||
auto r = encode(out);
|
|
||||||
if (!r) return;
|
|
||||||
std::span<const uint8_t> data{buf, *r};
|
|
||||||
if (data.size() <= usb.tx.free()) {
|
|
||||||
if (!usb.send(data))
|
|
||||||
dlogf("usb send failed: %zu bytes, %u free", data.size(), usb.tx.free());
|
|
||||||
} else {
|
|
||||||
dlogf("usb response too large: %zu bytes, %u free", data.size(), usb.tx.free());
|
|
||||||
uint8_t err_buf[256];
|
|
||||||
span_writer err_out(err_buf, sizeof(err_buf));
|
|
||||||
auto err = encode_response_into(err_out, msg->message_id,
|
|
||||||
[&]{
|
|
||||||
char m[48];
|
|
||||||
snprintf(m, sizeof(m), "response too large: %zu", data.size());
|
|
||||||
return DeviceError{2, m};
|
|
||||||
}());
|
|
||||||
if (err) usb.send(std::span<const uint8_t>{err_buf, *err});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
usb_rx_buf.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
__wfi();
|
__wfi();
|
||||||
restore_interrupts(save);
|
restore_interrupts(save);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ void handlers_start() {
|
|||||||
poke_watchdog();
|
poke_watchdog();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<ResponsePICOBOOT> handle_picoboot(const responder&, const RequestPICOBOOT&) {
|
|
||||||
dispatch_schedule_ms(100, []{ reset_usb_boot(0, 1); });
|
|
||||||
return ResponsePICOBOOT{};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<ResponseInfo> handle_info(const responder&, const RequestInfo&) {
|
std::optional<ResponseInfo> handle_info(const responder&, const RequestInfo&) {
|
||||||
ResponseInfo resp;
|
ResponseInfo resp;
|
||||||
pico_unique_board_id_t uid;
|
pico_unique_board_id_t uid;
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
#include <cstring>
|
|
||||||
#include "pico/unique_id.h"
|
|
||||||
#include "tusb.h"
|
|
||||||
|
|
||||||
constexpr uint16_t USB_VID = 0x2E8A;
|
|
||||||
constexpr uint16_t USB_PID = 0x000A;
|
|
||||||
|
|
||||||
static constexpr tusb_desc_device_t desc_device = {
|
|
||||||
sizeof(tusb_desc_device_t),
|
|
||||||
TUSB_DESC_DEVICE,
|
|
||||||
0x0200,
|
|
||||||
TUSB_CLASS_MISC,
|
|
||||||
MISC_SUBCLASS_COMMON,
|
|
||||||
MISC_PROTOCOL_IAD,
|
|
||||||
CFG_TUD_ENDPOINT0_SIZE,
|
|
||||||
USB_VID,
|
|
||||||
USB_PID,
|
|
||||||
0x0100,
|
|
||||||
1, 2, 3,
|
|
||||||
1,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum { ITF_NUM_CDC, ITF_NUM_CDC_DATA, ITF_NUM_TOTAL };
|
|
||||||
|
|
||||||
constexpr uint8_t EPNUM_CDC_NOTIF = 0x81;
|
|
||||||
constexpr uint8_t EPNUM_CDC_OUT = 0x02;
|
|
||||||
constexpr uint8_t EPNUM_CDC_IN = 0x82;
|
|
||||||
constexpr uint16_t CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN;
|
|
||||||
|
|
||||||
static uint8_t const desc_configuration[] = {
|
|
||||||
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
|
|
||||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 0, EPNUM_CDC_NOTIF, 8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64),
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr const char* string_desc[] = {
|
|
||||||
"\x09\x04",
|
|
||||||
"picomap",
|
|
||||||
"picomap",
|
|
||||||
nullptr,
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint16_t desc_str_buf[33];
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
uint8_t const* tud_descriptor_device_cb(void) {
|
|
||||||
return reinterpret_cast<uint8_t const*>(&desc_device);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
|
||||||
return desc_configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
|
||||||
uint8_t chr_count;
|
|
||||||
|
|
||||||
if (index == 0) {
|
|
||||||
memcpy(&desc_str_buf[1], string_desc[0], 2);
|
|
||||||
chr_count = 1;
|
|
||||||
} else if (index == 3) {
|
|
||||||
pico_unique_board_id_t uid;
|
|
||||||
pico_get_unique_board_id(&uid);
|
|
||||||
chr_count = 0;
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
desc_str_buf[1 + chr_count++] = "0123456789ABCDEF"[uid.id[i] >> 4];
|
|
||||||
desc_str_buf[1 + chr_count++] = "0123456789ABCDEF"[uid.id[i] & 0xF];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (index >= sizeof(string_desc) / sizeof(string_desc[0])) return nullptr;
|
|
||||||
const char* str = string_desc[index];
|
|
||||||
if (!str) return nullptr;
|
|
||||||
chr_count = strlen(str);
|
|
||||||
if (chr_count > 31) chr_count = 31;
|
|
||||||
for (uint8_t i = 0; i < chr_count; i++)
|
|
||||||
desc_str_buf[1 + i] = str[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
desc_str_buf[0] = static_cast<uint16_t>((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
|
|
||||||
return desc_str_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
@@ -14,7 +14,6 @@ static void led_toggle() {
|
|||||||
std::string_view firmware_name = "picomap_test";
|
std::string_view firmware_name = "picomap_test";
|
||||||
|
|
||||||
static constexpr handler_entry handlers[] = {
|
static constexpr handler_entry handlers[] = {
|
||||||
{RequestPICOBOOT::ext_id, typed_handler<RequestPICOBOOT, handle_picoboot>},
|
|
||||||
{RequestInfo::ext_id, typed_handler<RequestInfo, handle_info>},
|
{RequestInfo::ext_id, typed_handler<RequestInfo, handle_info>},
|
||||||
{RequestLog::ext_id, typed_handler<RequestLog, handle_log>},
|
{RequestLog::ext_id, typed_handler<RequestLog, handle_log>},
|
||||||
{RequestFlashErase::ext_id, typed_handler<RequestFlashErase, handle_flash_erase>},
|
{RequestFlashErase::ext_id, typed_handler<RequestFlashErase, handle_flash_erase>},
|
||||||
|
|||||||
@@ -2,9 +2,4 @@ module github.com/theater/picomap
|
|||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
require go.bug.st/serial v1.6.4
|
require golang.org/x/sys v0.19.0
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/creack/goselect v0.1.2 // indirect
|
|
||||||
golang.org/x/sys v0.19.0 // indirect
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,14 +1,2 @@
|
|||||||
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
|
|
||||||
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
go.bug.st/serial v1.6.4 h1:7FmqNPgVp3pu2Jz5PoPtbZ9jJO5gnEnZIvnI1lzve8A=
|
|
||||||
go.bug.st/serial v1.6.4/go.mod h1:nofMJxTeNVny/m6+KaafC6vJGj3miwQZ6vW4BZUGJPI=
|
|
||||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
|
|||||||
@@ -100,11 +100,6 @@ func first[T any](results []Response[T], err error) (*T, error) {
|
|||||||
return results[0].Value, nil
|
return results[0].Value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) PICOBOOT() error {
|
|
||||||
_, err := first(roundTrip[ResponsePICOBOOT](c, &RequestPICOBOOT{}))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) Info() (*ResponseInfo, error) {
|
func (c *Client) Info() (*ResponseInfo, error) {
|
||||||
return first(roundTrip[ResponseInfo](c, &RequestInfo{}))
|
return first(roundTrip[ResponseInfo](c, &RequestInfo{}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
package client
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/theater/picomap/lib/msgpack"
|
|
||||||
"go.bug.st/serial"
|
|
||||||
"go.bug.st/serial/enumerator"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ListSerial() ([]string, error) {
|
|
||||||
ports, err := enumerator.GetDetailedPortsList()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("enumerating ports: %w", err)
|
|
||||||
}
|
|
||||||
type entry struct {
|
|
||||||
name string
|
|
||||||
serial string
|
|
||||||
}
|
|
||||||
var entries []entry
|
|
||||||
for _, p := range ports {
|
|
||||||
if p.IsUSB && p.VID == "2E8A" && strings.HasPrefix(p.Name, "/dev/cu.") {
|
|
||||||
entries = append(entries, entry{p.Name, p.SerialNumber})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
slices.SortFunc(entries, func(a, b entry) int {
|
|
||||||
return strings.Compare(a.serial, b.serial)
|
|
||||||
})
|
|
||||||
var result []string
|
|
||||||
for _, e := range entries {
|
|
||||||
result = append(result, e.name)
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type serialTransport struct {
|
|
||||||
port serial.Port
|
|
||||||
portName string
|
|
||||||
dec *msgpack.Decoder
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSerial(portName string, timeout time.Duration) (*Client, error) {
|
|
||||||
port, err := serial.Open(portName, &serial.Mode{BaudRate: 115200})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("opening %s: %w", portName, err)
|
|
||||||
}
|
|
||||||
t := &serialTransport{port: port, portName: portName, dec: msgpack.NewDecoder(port)}
|
|
||||||
return &Client{transport: t, timeout: timeout}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *serialTransport) Send(data []byte) error {
|
|
||||||
_, err := t.port.Write(data)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *serialTransport) SetReadTimeout(timeout time.Duration) {
|
|
||||||
t.port.SetReadTimeout(timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *serialTransport) Recv() ([]byte, string, error) {
|
|
||||||
var raw msgpack.RawMessage
|
|
||||||
if err := t.dec.Decode(&raw); err != nil {
|
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
return []byte(raw), t.portName, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *serialTransport) Broadcast() bool { return false }
|
|
||||||
|
|
||||||
func (t *serialTransport) Close() error {
|
|
||||||
return t.port.Close()
|
|
||||||
}
|
|
||||||
@@ -2,9 +2,6 @@ package client
|
|||||||
|
|
||||||
import "github.com/theater/picomap/lib/msgpack"
|
import "github.com/theater/picomap/lib/msgpack"
|
||||||
|
|
||||||
type RequestPICOBOOT struct{}
|
|
||||||
type ResponsePICOBOOT struct{}
|
|
||||||
|
|
||||||
type RequestInfo struct{}
|
type RequestInfo struct{}
|
||||||
type BootReason uint8
|
type BootReason uint8
|
||||||
|
|
||||||
@@ -108,8 +105,6 @@ type Envelope struct {
|
|||||||
func init() {
|
func init() {
|
||||||
msgpack.RegisterExt(0, (*Envelope)(nil))
|
msgpack.RegisterExt(0, (*Envelope)(nil))
|
||||||
msgpack.RegisterExt(1, (*DeviceError)(nil))
|
msgpack.RegisterExt(1, (*DeviceError)(nil))
|
||||||
msgpack.RegisterExt(2, (*RequestPICOBOOT)(nil))
|
|
||||||
msgpack.RegisterExt(3, (*ResponsePICOBOOT)(nil))
|
|
||||||
msgpack.RegisterExt(4, (*RequestInfo)(nil))
|
msgpack.RegisterExt(4, (*RequestInfo)(nil))
|
||||||
msgpack.RegisterExt(5, (*ResponseInfo)(nil))
|
msgpack.RegisterExt(5, (*ResponseInfo)(nil))
|
||||||
msgpack.RegisterExt(6, (*RequestLog)(nil))
|
msgpack.RegisterExt(6, (*RequestLog)(nil))
|
||||||
|
|||||||
Reference in New Issue
Block a user