SatCat5
file_aeroftp.h
Go to the documentation of this file.
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
19 
20 #pragma once
21 
22 #include <hal_posix/file_io.h>
23 #include <satcat5/net_aeroftp.h>
24 #include <cstdio>
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 namespace satcat5 {
30  namespace net {
33  class AeroFtpFile {
34  public:
44  const char* work_folder,
45  u32 file_id, u32 file_len,
46  bool resume);
47  ~AeroFtpFile();
48 
50  void frame_rcvd(
51  u32 file_id, u32 file_len, u32 offset, u32 rxlen,
53 
56 
58  inline bool done() const { return m_pcount == 0; }
60  inline bool error() const { return m_pcount == UINT_MAX; }
61 
62  protected:
63  void cleanup(); // Close open file handles
64  void log(s8 level, const char* msg);
65 
66  const std::string m_name_data; // Filenames (see top)
67  const std::string m_name_meta;
68  const std::string m_name_part;
69  const u32 m_file_id; // Numeric File-ID
70  const u32 m_file_len; // Length of file (words)
71  const u32 m_bcount; // Total block count
72  unsigned m_pcount; // Number of pending blocks
73  FILE* m_data; // In-progress file-data
74  FILE* m_meta; // In-progress meta-data
75  u8* m_pending; // Flag each pending block
76  satcat5::io::ArrayRead m_status;
77  };
78 
81  public:
85 
87  bool done(u32 file_id) const;
88 
90  inline void resume(bool allow) {m_resume = allow;}
91 
92  protected:
99  const char* work_folder,
100  satcat5::net::Dispatch* iface,
101  const satcat5::net::Type& typ);
102  ~AeroFtpServer();
103 
105  void frame_rcvd(satcat5::io::LimitedRead& src) override;
106 
107  // Internal state.
108  const std::string m_work_folder;
109  satcat5::net::Dispatch* const m_iface;
110  bool m_resume;
111  std::map<u32, satcat5::net::AeroFtpFile*> m_files;
112  };
113  }
114 
115  // Thin wrappers for commonly used protocols:
116  namespace eth {
119  public:
121  const char* work_folder,
123  const satcat5::eth::MacType& type = satcat5::eth::ETYPE_AEROFTP);
124  };
125  }
126 
127  namespace udp {
130  public:
132  const char* work_folder,
134  const satcat5::udp::Port& port = satcat5::udp::PORT_AEROFTP);
135  };
136  }
137 }
Server for receiving file(s) using AeroFTP over Ethernet.
Definition: file_aeroftp.h:118
Implemention of "net::Dispatch" for Ethernet frames.
Definition: eth_dispatch.h:21
Ephemeral Readable interface for a simple array.
Definition: io_readable.h:206
Limited read of next N bytes.
Definition: io_readable.h:255
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Helper class representing a saving data to a particular file.
Definition: file_aeroftp.h:33
bool error() const
Has there been an unrecoverable file-transfer error?
Definition: file_aeroftp.h:60
bool done() const
Has the complete file been received successfully?
Definition: file_aeroftp.h:58
void frame_rcvd(u32 file_id, u32 file_len, u32 offset, u32 rxlen, satcat5::io::LimitedRead &data)
Handler for each received packet relating to this file.
satcat5::io::Readable * missing_blocks()
Get a stream of missing blocks for this file.
AeroFtpFile(const char *work_folder, u32 file_id, u32 file_len, bool resume)
Create a new file object.
Definition: file_aeroftp.cc:56
Server for receiving file(s) using AeroFTP.
Definition: file_aeroftp.h:80
void frame_rcvd(satcat5::io::LimitedRead &src) override
Callback for incoming packets.
satcat5::io::Readable * missing_blocks(u32 file_id)
Get a stream of missing blocks for the designated file-ID.
AeroFtpServer(const char *work_folder, satcat5::net::Dispatch *iface, const satcat5::net::Type &typ)
Constructor is only available to child classes.
void resume(bool allow)
Allow server to resume transfers in progress?
Definition: file_aeroftp.h:90
bool done(u32 file_id) const
Has the complete file been received successfully?
The "Dispatch" is a generic interface that knows how to read a designated protocol layer and sort inc...
Definition: net_dispatch.h:36
A net::Protocol is the counterpart to net::Dispatch that handles a particular data stream,...
Definition: net_protocol.h:28
Server for receiving file(s) using AeroFTP over UDP.
Definition: file_aeroftp.h:129
Dispatcher sorts incoming UDP messages by port index.
Definition: udp_dispatch.h:20
EtherType field (uint16) is used a protocol-ID [1536..65535].
Definition: eth_header.h:96
UDP and TCP ports are both 16-bit unsigned integers.
Definition: ip_core.h:119
Multipurpose filter for matching fields in network packets.
Definition: net_type.h:38