Files
picomap/firmware/include/net.h

35 lines
964 B
C
Raw Normal View History

#pragma once
#include <expected>
#include <functional>
#include <span>
#include "eth.h"
#include "ipv4.h"
#include "span_writer.h"
#include "msgpack.h"
#include "callback_list.h"
struct net_state {
eth::mac_addr mac;
ipv4::ip4_addr ip;
};
using net_handler = std::function<void(std::span<const uint8_t> payload,
std::function<void(std::span<const uint8_t>)> send)>;
using net_frame_callback = std::function<bool(std::span<const uint8_t> frame)>;
struct frame_callback_entry {
net_frame_callback fn;
};
using frame_cb_list = callback_list<frame_callback_entry, 16>;
using frame_cb_handle = frame_cb_list::node*;
bool net_init();
const net_state& net_get_state();
void net_set_handler(net_handler handler);
frame_cb_handle net_add_frame_callback(net_frame_callback cb);
void net_remove_frame_callback(frame_cb_handle h);
void net_poll(std::span<uint8_t> tx);
void net_send_raw(std::span<const uint8_t> data);