SatCat5
net_aeroftp.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // AeroCube File Transfer Protocol (AeroFTP) transmitter
6 
7 #pragma once
8 
9 #include <satcat5/eth_header.h>
10 #include <satcat5/net_address.h>
11 #include <satcat5/net_protocol.h>
12 #include <satcat5/polling.h>
13 #include <satcat5/udp_core.h>
14 
15 namespace satcat5 {
16  namespace net {
43  public:
45  inline bool busy() const {return m_file_pos < m_file_len;}
47  inline bool done() const {return m_file_pos >= m_file_len;}
48 
54  bool send(u32 file_id,
56  satcat5::io::Readable* aux = 0);
57 
59  void close();
60 
62  void throttle(unsigned msec_per_pkt);
63 
64  protected:
67  explicit AeroFtpClient(satcat5::net::Address* dst);
68 
69  void end_of_file();
70  void skip_ahead();
71  void timer_event() override;
72 
73  // Internal state.
74  satcat5::net::Address* const m_dst;
77  u32 m_file_id;
78  u32 m_file_len;
79  u32 m_file_pos;
81  unsigned m_throttle;
82  };
83  }
84 
85  namespace eth {
87  constexpr satcat5::eth::MacType ETYPE_AEROFTP = {0x4346};
88 
90  class AeroFtpClient final
93  {
94  public:
97 
99  inline void connect(
100  const satcat5::eth::MacAddr& addr,
101  const satcat5::eth::MacType& type = satcat5::eth::ETYPE_AEROFTP)
102  { m_addr.connect(addr, type); }
103 
105  inline bool ready() const
106  { return m_addr.ready(); }
107  };
108  }
109 
110  namespace udp {
112  constexpr satcat5::udp::Port PORT_AEROFTP = {0x4346};
113 
118  class AeroFtpClient final
121  {
122  public:
124  explicit AeroFtpClient(satcat5::udp::Dispatch* udp);
125 
127  inline void connect(
128  const satcat5::udp::Addr& addr,
129  const satcat5::udp::Port& port = satcat5::udp::PORT_AEROFTP)
130  { m_addr.connect(addr, port, 0); }
131 
133  inline bool ready() const
134  { return m_addr.ready(); }
135  };
136  }
137 }
Inheritable container for a eth::Address.
Definition: eth_address.h:60
bool ready() const override
Is this address object ready for use? Child MUST override this method.
Definition: eth_address.cc:43
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Connect to the designated address.
Definition: eth_address.cc:19
Implement AeroFTP protocol over Ethernet.
Definition: net_aeroftp.h:93
AeroFtpClient(satcat5::eth::Dispatch *eth)
Constructor links to the Ethernet interface.
Definition: net_aeroftp.cc:13
bool ready() const
Is the connection ready to transmit?
Definition: net_aeroftp.h:105
void connect(const satcat5::eth::MacAddr &addr, const satcat5::eth::MacType &type=satcat5::eth::ETYPE_AEROFTP)
Set the destination address before calling send().
Definition: net_aeroftp.h:99
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Defines a generic API for sending data to a specific destination, such as a MAC address,...
Definition: net_address.h:30
AeroCube File Transfer Protocol (AeroFTP) transmitter.
Definition: net_aeroftp.h:42
u32 m_file_len
Length (bytes)
Definition: net_aeroftp.h:78
bool done() const
Is the current transfer completed?
Definition: net_aeroftp.h:47
u32 m_file_pos
Current read index (bytes)
Definition: net_aeroftp.h:79
satcat5::io::Readable * m_src
Source for file data.
Definition: net_aeroftp.h:75
bool send(u32 file_id, satcat5::io::Readable *src, satcat5::io::Readable *aux=0)
Begin transmission of the designated file.
Definition: net_aeroftp.cc:73
void timer_event() override
Callback for timer events.
Definition: net_aeroftp.cc:117
void skip_ahead()
Skip to next requested block.
Definition: net_aeroftp.cc:102
void throttle(unsigned msec_per_pkt)
Set throttle (one packet every N msec).
Definition: net_aeroftp.cc:111
satcat5::io::Readable * m_aux
Source for retransmit control.
Definition: net_aeroftp.h:76
AeroFtpClient(satcat5::net::Address *dst)
Constructor is only available to child classes.
Definition: net_aeroftp.cc:42
void close()
Close connection and abort transfer in progress.
Definition: net_aeroftp.cc:55
void end_of_file()
End-of-file cleanup.
Definition: net_aeroftp.cc:61
unsigned m_throttle
Delay per packet (msec)
Definition: net_aeroftp.h:81
u32 m_file_id
ID for this file.
Definition: net_aeroftp.h:77
u32 m_bytes_sent
Count transmission length.
Definition: net_aeroftp.h:80
bool busy() const
Is there already a transfer in progress?
Definition: net_aeroftp.h:45
Timer objects are polled after a fixed delay or at a regular interval.
Definition: polling.h:213
Inheritable container for a udp::Address.
Definition: udp_core.h:149
bool ready() const override
Is this address object ready for use? Child MUST override this method.
Definition: udp_core.h:103
void connect(const satcat5::udp::Addr &dstaddr, const satcat5::eth::MacAddr &dstmac, const satcat5::udp::Port &dstport, const satcat5::udp::Port &srcport=satcat5::udp::PORT_NONE, const satcat5::eth::VlanTag &vtag=satcat5::eth::VTAG_NONE)
Manual address resolution (user supplies IP + MAC).
Definition: udp_core.cc:30
Implement AeroFTP protocol over UDP.
Definition: net_aeroftp.h:121
AeroFtpClient(satcat5::udp::Dispatch *udp)
Constructor links to the UDP stack.
Definition: net_aeroftp.cc:20
bool ready() const
Is the connection ready to transmit?
Definition: net_aeroftp.h:133
void connect(const satcat5::udp::Addr &addr, const satcat5::udp::Port &port=satcat5::udp::PORT_AEROFTP)
Set the destination address before calling send().
Definition: net_aeroftp.h:127
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
Type definitions for Ethernet frames and protocol handlers.
Generic network Address API.
Generic network Protocol API.
Core event-processing loop for SatCat5 software.
An Ethernet MAC address (with serializable interface).
Definition: eth_header.h:29
EtherType field (uint16) is used a protocol-ID [1536..65535].
Definition: eth_header.h:96
IPv4 address is a 32-bit unsigned integer.
Definition: ip_core.h:15
UDP and TCP ports are both 16-bit unsigned integers.
Definition: ip_core.h:119