17 #include <satcat5/cfgbus_interrupt.h>
18 #include <satcat5/ethernet.h>
20 #include <satcat5/ip_stack.h>
28 #if SATCAT5_CBOR_ENABLE
29 #include <qcbor/qcbor_decode.h>
34 #define SATCAT5_MAKE_STRING(x) (std::string(x, x + sizeof(x)))
39 #define SATCAT5_TEST_START \
40 CHECK(satcat5::irq::pre_test_reset()); \
41 CHECK(satcat5::log::pre_test_reset()); \
42 CHECK(satcat5::poll::pre_test_reset()); \
43 CHECK(satcat5::test::pre_test_reset()); \
44 satcat5::log::ToConsole log;
49 bool pre_test_reset();
62 std::string sim_filename(
const char* pre,
const char* ext);
67 unsigned nbytes,
const u8* data);
69 const std::string& dat);
77 unsigned nbytes,
const u8* data);
79 const std::string& ref);
81 const std::string& ref);
102 #if SATCAT5_CBOR_ENABLE
103 QCBORItem
get(
const char* key)
const;
104 QCBORItem
get(u32 key)
const;
120 unsigned count()
const {
return m_count;}
143 : m_arp(iface->arp()) {m_arp->
add(
this);}
165 : m_icmp(iface->icmp()) {m_icmp->
add(
this);}
210 u32
raw()
override {
return m_timer.
raw() << 8; }
245 void clear_dev(
unsigned devaddr, u32 val = 0);
251 u32
m_regs[satcat5::cfg::MAX_TOTAL_REGS];
283 inline unsigned len()
const {
return m_len;}
289 const unsigned m_len;
ConfigBus core definitions.
Memory-mapped local ConfigBus.
Event-handler for individual ConfigBus interrupts.
Callback interface for responding to ARP and ICMP events.
Implemention of "net::Dispatch" for Ethernet frames.
Protocol handler for Ethernet-to-IPv4 ARP queries and replies.
void add(satcat5::eth::ArpListener *evt)
Register an event-listener.
void remove(satcat5::eth::ArpListener *evt)
Unregister an event-listener.
Accept incoming Ethernet packets by EtherType.
Ephemeral Readable interface for a simple array.
Event-handler interface for newly received data.
Limited read of next N bytes.
PacketBuffer with heap allocation (in packet mode).
bool write_finalize() override
Mark end of frame and release temporary working data.
void write_abort() override
If possible, abort the current partially-written packet.
Abstract API for reading byte-streams and packets.
void read_notify()
Attempt notification by calling m_callback->data_rcvd().
Abstract API for writing byte-streams and packets.
Protocol handler and dispatch unit for Internet Protocol v4 (IPv4).
Callback API for handling "ping" reponses.
Protocol handler for the Internet Control Message Protocol (ICMP).
void remove(satcat5::ip::PingListener *cb)
Add/remove callback handlers for Ping responses.
void add(satcat5::ip::PingListener *cb)
Add/remove callback handlers for Ping responses.
Defines a generic API for sending data to a specific destination, such as a MAC address,...
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
An "Always" object is polled whenever service() is called.
An "OnDemand" object is polled only on request.
Timer objects are polled after a fixed delay or at a regular interval.
PTP callback accepts each complete measurement from the Source.
Callback(satcat5::ptp::Source *source)
If a source pointer is provided, call add_callback.
A source for ptp::Measurement events, usually a ptp::Client.
A simple CBOR decoder for use in unit tests.
QCBORItem get(const char *key) const
Attempt to fetch top-level QCBOR item for the given key.
CborParser(satcat5::io::Readable *src, bool verbose=false)
Copy received message to local buffer.
Count calls to poll_always().
void poll_always() override
Child class MUST override this method.
Count calls to arp_event().
void arp_event(const satcat5::eth::MacAddr &mac, const satcat5::ip::Addr &ip) override
Callback for any announced MAC/IP address pair.
void gateway_change(const satcat5::ip::Addr &dstaddr, const satcat5::ip::Addr &gateway) override
Callback for changes to gateway configuration.
Base object for counting specific callback or event types.
void count_reset()
Reset the counter to zero.
CountHelper()
Constructor is only accessible to the child object.
unsigned count() const
Returns the current counter value.
Count calls to poll_demand().
void poll_demand() override
Deferred event handler, called after request().
Count calls to ping_event().
void ping_event(const satcat5::ip::Addr &from, u32 elapsed_usec)
Callback method when a ping response is received.
Count calls to ptp_ready().
void ptp_ready(const satcat5::ptp::Measurement &data) override
The child class MUST override this method.
Count calls to timer_event().
void timer_event() override
Child class MUST override this method.
Dummy implementation of net::Address that writes data to a buffer.
void close() override
Close any open connections and revert to idle.
satcat5::net::Dispatch * iface() const override
Fetch a pointer to the underlying interface.
satcat5::io::Writeable * open_write(unsigned len) override
Open a new frame to the designated address and type.
bool ready() const
Is this address object ready for use? Child MUST override this method.
satcat5::io::PacketBufferHeap m_rx
Received-data buffer is directly accessible.
Accelerated version of PosixTimer is 256x real-time.
u32 raw() override
Read current time in arbitrary "ticks".
Count calls to data_rcvd().
void data_rcvd(satcat5::io::Readable *src)
The data_rcvd() callback is polled whenever data is available.
Log any received Ethernet traffic of the designated type.
LogProtocol(satcat5::eth::Dispatch *dispatch, const satcat5::eth::MacType ðertype)
Attach this object to an Ethernet interface and set filter.
void frame_rcvd(satcat5::io::LimitedRead &src) override
Dispatch calls frame_rcvd(...) for each incoming frame with with a matching net::Type value.
Mockup for a memory-mapped ConfigBus.
void clear_all(u32 val=0)
Clear all registers for all devices.
u32 m_regs[satcat5::cfg::MAX_TOTAL_REGS]
Simulated register-map for up to 256 devices.
void clear_dev(unsigned devaddr, u32 val=0)
Clear all registers for the specified device-ID.
void irq_event()
Make event-handler accessible (normally private)
MockConfigBusMmap()
Create this mock interface.
Mockup for a ConfigBus interrupt register.
void irq_event() override
Interrupt service routine.
void fire()
Trigger a virtual interrupt.
MockInterrupt(satcat5::cfg::ConfigBus *cfg)
No associated register, assumes interrupt has fired.
Readable source for a pseudorandom block of data.
const u8 * raw() const
Raw access to the underlying buffer.
RandomSource(unsigned len)
Generate a pseudorandom block of data.
satcat5::io::Readable * read()
Prepare to read or re-read data from start of block.
unsigned len() const
Length of the internal block.
void notify()
Issue the read_notify / data_rcvd callback.
Measure various statistics of a discrete-time series.
double m_max
Running maximum.
double rms() const
Root-mean-square.
double var() const
Variance.
Statistics()
Create an empty dataset.
double std() const
Standard deviation.
void add(double x)
Add a new data point.
double min() const
Minimum over all inputs.
double msq() const
Mean-square.
double m_sumsq
Sum of squares.
double max() const
Maximum over all inputs.
double m_sum
Sum of inputs.
unsigned m_count
Number of data points.
double m_min
Running minimum.
double mean() const
Mean of all data points.
Timekeeper object for granular simulation of elapsed time.
void sim_step()
Step forward one millisecond.
void sim_wait(unsigned dly_msec)
Step forward N milliseconds.
u32 raw() override
Read current time in arbitrary "ticks".
Helper object for heap allocation.
u8 *const m_buffptr
Pointer to the underlying buffer.
Timer object using ctime::clock().
u32 raw() override
Read current time in arbitrary "ticks".
The TimeRef API provides access to a monotonic time-counter.
Diagnostic logging to UART and/or Ethernet ports.
Core event-processing loop for SatCat5 software.
Miscellaneous POSIX wrappers (e.g., heap allocation, log to console...)
Define the API for generating ptp::Measurement events.
Platform-agnostic API for interrupt management.
An Ethernet MAC address (with serializable interface).
EtherType field (uint16) is used a protocol-ID [1536..65535].
IPv4 address is a 32-bit unsigned integer.
Timestamps and metadata for a two-way time-transfer handshake.
TimeRef and TimeVal define the API for monotonic timers.