refactor: migrate MICRO_PIP to fine-grained feature flags
Replace monolithic MICRO_PIP/PIP_MICRO with granular flags: Feature flags (CMake options + platform auto-detection): - PIP_NO_FILESYSTEM, PIP_NO_THREADS, PIP_NO_SOCKET - PIP_NO_PROCESS, PIP_NO_DYNLIB, PIP_NO_FFT, PIP_NO_SERIAL Embedded optimization flag: - PIP_EMBEDDED (auto-set for Pico SDK and FreeRTOS) Controls buffer sizes, time stubs, terminal fallback, init stubs Platform blocks in CMakeLists.txt: - Pico SDK: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL; conditionally disables THREADS (no FreeRTOS) and SOCKET (no LWIP) - FreeRTOS: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL; conditionally disables SOCKET (no LWIP) - Android: auto-disables PROCESS, DYNLIB, FFT Updated 96 files across libs/, utils/, tests/, and CMakeLists.txt. Builds verified for Linux (547 tests pass) and Pico SDK (100%). Removed all MICRO_PIP and PIP_MICRO references (0 remaining).
This commit is contained in:
@@ -27,7 +27,12 @@
|
||||
const uint PIBaseTransfer::signature = 0x54424950;
|
||||
|
||||
|
||||
PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
|
||||
PIBaseTransfer::PIBaseTransfer()
|
||||
: crc(standardCRC_16())
|
||||
#ifndef PIP_NO_THREADS
|
||||
, diag(false)
|
||||
#endif
|
||||
{
|
||||
header.sig = signature;
|
||||
crc_enabled = true;
|
||||
header.session_id = 0;
|
||||
@@ -39,12 +44,14 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
|
||||
send_queue = 0;
|
||||
send_up = 0;
|
||||
timeout_ = 10.;
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.setDisconnectTimeout(PISystemTime::fromSeconds(timeout_ / 10.));
|
||||
diag.setName("PIBaseTransfer");
|
||||
diag.start(20_Hz);
|
||||
#endif
|
||||
packets_count = 10;
|
||||
#ifdef MICRO_PIP
|
||||
setPacketSize(512);
|
||||
#ifdef PIP_EMBEDDED
|
||||
setPacketSize(1024);
|
||||
#else
|
||||
setPacketSize(4096);
|
||||
#endif
|
||||
@@ -53,7 +60,9 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
|
||||
|
||||
|
||||
PIBaseTransfer::~PIBaseTransfer() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.stopAndWait();
|
||||
#endif
|
||||
break_ = true;
|
||||
}
|
||||
|
||||
@@ -85,14 +94,18 @@ void PIBaseTransfer::setPause(bool pause_) {
|
||||
|
||||
void PIBaseTransfer::setTimeout(double sec) {
|
||||
timeout_ = sec;
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.setDisconnectTimeout(PISystemTime::fromSeconds(sec));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIBaseTransfer::received(PIByteArray data) {
|
||||
packet_header_size = sizeof(PacketHeader) + customHeader().size();
|
||||
if (data.size() < sizeof(PacketHeader)) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.received(data.size(), false);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
PacketHeader h;
|
||||
@@ -100,10 +113,14 @@ void PIBaseTransfer::received(PIByteArray data) {
|
||||
PacketType pt = (PacketType)h.type;
|
||||
if (!h.check_sig()) {
|
||||
piCoutObj << "invalid packet signature"_tr("PIBaseTransfer");
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.received(data.size(), false);
|
||||
#endif
|
||||
return;
|
||||
} else
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.received(data.size(), true);
|
||||
#endif
|
||||
// piCoutObj << "receive" << h.session_id << h.type << h.id;
|
||||
switch (pt) {
|
||||
case pt_Unknown: break;
|
||||
@@ -244,7 +261,9 @@ void PIBaseTransfer::received(PIByteArray data) {
|
||||
replies.resize(sr.packets + 1);
|
||||
replies.fill(pt_Unknown);
|
||||
pm_string.resize(replies.size(), '-');
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.reset();
|
||||
#endif
|
||||
// piCoutObj << "receiveStarted()";
|
||||
is_receiving = true;
|
||||
break_ = false;
|
||||
@@ -291,7 +310,9 @@ bool PIBaseTransfer::send_process() {
|
||||
mutex_session.lock();
|
||||
packet_header_size = sizeof(PacketHeader) + customHeader().size();
|
||||
break_ = false;
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.reset();
|
||||
#endif
|
||||
sendStarted();
|
||||
is_sending = true;
|
||||
int session_size = session.size();
|
||||
@@ -339,7 +360,9 @@ bool PIBaseTransfer::send_process() {
|
||||
}
|
||||
stm.reset();
|
||||
ba = build_packet(i);
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.sended(ba.size_s());
|
||||
#endif
|
||||
sendRequest(ba);
|
||||
pm_string[i + 1] = '+';
|
||||
mutex_send.lock();
|
||||
@@ -392,7 +415,9 @@ bool PIBaseTransfer::send_process() {
|
||||
continue;
|
||||
}
|
||||
ba = build_packet(chk - 1);
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.sended(ba.size_s());
|
||||
#endif
|
||||
sendRequest(ba);
|
||||
pm_string[chk] = '+';
|
||||
mutex_send.lock();
|
||||
@@ -497,7 +522,9 @@ void PIBaseTransfer::sendReply(PacketType reply) {
|
||||
header.type = reply;
|
||||
PIByteArray ba;
|
||||
ba << header;
|
||||
#ifndef PIP_NO_THREADS
|
||||
if (is_sending || is_receiving) diag.sended(ba.size_s());
|
||||
#endif
|
||||
sendRequest(ba);
|
||||
}
|
||||
|
||||
@@ -516,7 +543,9 @@ bool PIBaseTransfer::getStartRequest() {
|
||||
state_string = "send request";
|
||||
PITimeMeasurer tm;
|
||||
while (tm.elapsed_s() < timeout_) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
diag.sended(ba.size_s());
|
||||
#endif
|
||||
sendRequest(ba);
|
||||
if (break_) return false;
|
||||
// piCoutObj << replies[0];
|
||||
|
||||
@@ -159,12 +159,14 @@ public:
|
||||
//! \~russian Возвращает число байтов, уже обработанных в текущей сессии.
|
||||
llong bytesCur() const { return bytes_cur; }
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
//! \~english Get diagnostics object
|
||||
//! \~russian Получить объект диагностики
|
||||
//! \~\return
|
||||
//! \~english Diagnostic object reference
|
||||
//! \~russian Ссылка на объект диагностики
|
||||
const PIDiagnostics & diagnostic() { return diag; }
|
||||
#endif
|
||||
|
||||
//! \~english Returns the packet signature constant used by the protocol.
|
||||
//! \~russian Возвращает константу сигнатуры пакета, используемую протоколом.
|
||||
@@ -344,7 +346,9 @@ private:
|
||||
CRC_16 crc;
|
||||
int send_queue;
|
||||
int send_up;
|
||||
#ifndef PIP_NO_THREADS
|
||||
PIDiagnostics diag;
|
||||
#endif
|
||||
PIMutex mutex_session;
|
||||
PIMutex mutex_send;
|
||||
PIMutex mutex_header;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
//! \~\brief
|
||||
//! \~english Multi-channel sender and receiver over multicast, broadcast and loopback endpoints.
|
||||
//! \~russian Многоканальный отправитель и приемник через multicast-, broadcast- и loopback-конечные точки.
|
||||
#ifndef PIP_NO_SOCKET
|
||||
class PIP_IO_UTILS_EXPORT PIBroadcast
|
||||
: public PIThread
|
||||
, public PIEthUtilBase {
|
||||
@@ -182,5 +183,6 @@ private:
|
||||
int lo_pcnt;
|
||||
bool _started, _send_only, _reinit;
|
||||
};
|
||||
#endif // PIP_NO_SOCKET
|
||||
|
||||
#endif // PIBROADCAST_H
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#include "piiostream.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pitime.h"
|
||||
#include "pitranslator.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
# include "pitranslator.h"
|
||||
|
||||
/** \class PIConnection
|
||||
* \brief Complex Input/Output point
|
||||
@@ -1294,3 +1296,5 @@ __DevicePoolContainer__::__DevicePoolContainer__() {
|
||||
inited_ = true;
|
||||
__device_pool__ = new PIConnection::DevicePool();
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -379,6 +379,7 @@ public:
|
||||
bool isEmpty() const { return device_modes.isEmpty(); }
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
//! \~english Returns diagnostics object for device or filter "full_path_name".
|
||||
//! \~russian Возвращает объект диагностики для устройства или фильтра "full_path_name".
|
||||
PIDiagnostics * diagnostic(const PIString & full_path_name) const;
|
||||
@@ -386,6 +387,7 @@ public:
|
||||
//! \~english Returns diagnostics object associated with device or filter "dev".
|
||||
//! \~russian Возвращает объект диагностики, связанный с устройством или фильтром "dev".
|
||||
PIDiagnostics * diagnostic(const PIIODevice * dev) const { return diags_.value(const_cast<PIIODevice *>(dev), 0); }
|
||||
#endif
|
||||
|
||||
//! \~english Writes "data" to device resolved by full path "full_path".
|
||||
//! \~russian Записывает "data" в устройство, найденное по полному пути "full_path".
|
||||
@@ -415,6 +417,7 @@ public:
|
||||
//! \~russian Возвращает, работает ли общий пул устройств в режиме имитации.
|
||||
static bool isFakeMode();
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
class PIP_EXPORT DevicePool: public PIThread {
|
||||
PIOBJECT_SUBCLASS(DevicePool, PIThread);
|
||||
friend void __DevicePool_threadReadDP(void * ddp);
|
||||
@@ -456,6 +459,7 @@ public:
|
||||
PIMap<PIString, DeviceData *> devices;
|
||||
bool fake;
|
||||
};
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
|
||||
//! \events
|
||||
@@ -471,10 +475,12 @@ public:
|
||||
//! \~russian Генерируется, когда фильтр "from" выдает пакет.
|
||||
EVENT2(packetReceivedEvent, const PIString &, from, const PIByteArray &, data);
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
//! \fn void qualityChanged(const PIIODevice * device, PIDiagnostics::Quality new_quality, PIDiagnostics::Quality old_quality)
|
||||
//! \~english Emitted when diagnostics quality of "device" changes.
|
||||
//! \~russian Генерируется при изменении качества диагностики устройства "device".
|
||||
EVENT3(qualityChanged, const PIIODevice *, dev, PIDiagnostics::Quality, new_quality, PIDiagnostics::Quality, old_quality);
|
||||
#endif
|
||||
|
||||
//! \}
|
||||
|
||||
@@ -496,7 +502,9 @@ private:
|
||||
void rawReceived(PIIODevice * dev, const PIString & from, const PIByteArray & data);
|
||||
void unboundExtractor(PIPacketExtractor * pe);
|
||||
EVENT_HANDLER2(void, packetExtractorReceived, const uchar *, data, int, size);
|
||||
#ifndef PIP_NO_THREADS
|
||||
EVENT_HANDLER2(void, diagQualityChanged, PIDiagnostics::Quality, new_quality, PIDiagnostics::Quality, old_quality);
|
||||
#endif
|
||||
|
||||
PIString devPath(const PIIODevice * d) const;
|
||||
PIString devFPath(const PIIODevice * d) const;
|
||||
@@ -509,6 +517,7 @@ private:
|
||||
PIVector<PIIODevice *> devices;
|
||||
};
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
class PIP_EXPORT Sender: public PITimer {
|
||||
PIOBJECT_SUBCLASS(Sender, PIObject);
|
||||
|
||||
@@ -521,18 +530,24 @@ private:
|
||||
PISystemTime int_;
|
||||
void tick(int) override;
|
||||
};
|
||||
#endif
|
||||
|
||||
PIMap<PIString, Extractor *> extractors;
|
||||
#ifndef PIP_NO_THREADS
|
||||
PIMap<PIString, Sender *> senders;
|
||||
#endif
|
||||
PIMap<PIString, PIIODevice *> device_names;
|
||||
PIMap<PIIODevice *, PIIODevice::DeviceMode> device_modes;
|
||||
PIMap<PIIODevice *, PIVector<PIPacketExtractor *>> bounded_extractors;
|
||||
PIMap<PIIODevice *, PIVector<PIIODevice *>> channels_;
|
||||
#ifndef PIP_NO_THREADS
|
||||
PIMap<PIIODevice *, PIDiagnostics *> diags_;
|
||||
#endif
|
||||
|
||||
static PIVector<PIConnection *> _connections;
|
||||
};
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
void __DevicePool_threadReadDP(void * ddp);
|
||||
|
||||
extern PIP_EXPORT PIConnection::DevicePool * __device_pool__;
|
||||
@@ -544,6 +559,7 @@ public:
|
||||
};
|
||||
|
||||
static __DevicePoolContainer__ __device_pool_container__;
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
|
||||
#endif // PICONNECTION_H
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
|
||||
#include "pidiagnostics.h"
|
||||
|
||||
#include "piliterals_time.h"
|
||||
#include "pitranslator.h"
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
# include "piliterals_time.h"
|
||||
# include "pitranslator.h"
|
||||
|
||||
|
||||
/** \class PIDiagnostics
|
||||
@@ -250,3 +252,5 @@ void PIDiagnostics::changeDisconnectTimeout(PISystemTime disct) {
|
||||
// piCoutObj << hist_size << disconn_ << interval();
|
||||
mutex_state.unlock();
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "pitimer.h"
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
//! \~\ingroup IO-Utils
|
||||
//! \brief
|
||||
//! \~english Connection diagnostics for packet frequency, throughput and receive quality
|
||||
@@ -56,7 +57,7 @@ public:
|
||||
enum Quality {
|
||||
Unknown = 1 /** \~english No receive history yet \~russian История приема еще отсутствует */,
|
||||
Failure = 2 /** \~english No correct packets in the recent window \~russian В недавнем окне нет корректных пакетов */,
|
||||
Bad = 3 /** \~english Correct packets are at most 20 percent \~russian Корректных пакетов не более 20 процентов */,
|
||||
Bad = 3 /** \~english Correct packets are at most 20 percent \~russian Корректных пакетов не более 20 процентов */,
|
||||
Average =
|
||||
4 /** \~english Correct packets are above 20 and up to 80 percent \~russian Корректных пакетов больше 20 и до 80 процентов */
|
||||
,
|
||||
@@ -235,5 +236,6 @@ inline bool operator!=(const PIDiagnostics::Entry & f, const PIDiagnostics::Entr
|
||||
inline bool operator<(const PIDiagnostics::Entry & f, const PIDiagnostics::Entry & s) {
|
||||
return f.bytes_ok < s.bytes_ok;
|
||||
}
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
#endif // PIDIAGNOSTICS_H
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#ifndef PIETHUTILBASE_H
|
||||
#define PIETHUTILBASE_H
|
||||
#ifndef PIP_NO_SOCKET
|
||||
|
||||
#include "pibytearray.h"
|
||||
#include "pip_io_utils_export.h"
|
||||
@@ -96,4 +97,5 @@ private:
|
||||
bool _crypt;
|
||||
};
|
||||
|
||||
#endif // PIP_NO_SOCKET
|
||||
#endif // PIETHUTILBASE_H
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "pifiletransfer.h"
|
||||
|
||||
#ifndef PIP_NO_FILESYSTEM
|
||||
const char PIFileTransfer::sign[] = {'P', 'F', 'T'};
|
||||
|
||||
PIFileTransfer::PIFileTransfer() {
|
||||
@@ -339,3 +340,5 @@ void PIFileTransfer::send_finished(bool ok) {
|
||||
work_file.close();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PIP_NO_FILESYSTEM
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
#include "pibasetransfer.h"
|
||||
#include "pidir.h"
|
||||
|
||||
#define __PIFILETRANSFER_VERSION 2
|
||||
#ifndef PIP_NO_FILESYSTEM
|
||||
# define __PIFILETRANSFER_VERSION 2
|
||||
|
||||
|
||||
//! \~\ingroup IO-Utils
|
||||
@@ -70,7 +71,7 @@ public:
|
||||
PIString dest_path;
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
# pragma pack(push, 1)
|
||||
|
||||
//! \~english Custom packet header used by the file-transfer protocol.
|
||||
//! \~russian Пользовательский заголовок пакета, используемый протоколом передачи файлов.
|
||||
@@ -104,7 +105,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
};
|
||||
#pragma pack(pop)
|
||||
# pragma pack(pop)
|
||||
|
||||
|
||||
//! \~english Sends one file-system entry identified by "file".
|
||||
@@ -262,4 +263,6 @@ inline PICout operator<<(PICout s, const PIFileTransfer::PFTFileInfo & v) {
|
||||
s.restoreControls();
|
||||
return s;
|
||||
}
|
||||
#endif // PIP_NO_FILESYSTEM
|
||||
|
||||
#endif // PIFILETRANSFER_H
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#ifndef pipackedtcp_H
|
||||
#define pipackedtcp_H
|
||||
#ifndef PIP_NO_SOCKET
|
||||
|
||||
#include "piiodevice.h"
|
||||
#include "pinetworkaddress.h"
|
||||
@@ -122,4 +123,6 @@ private:
|
||||
|
||||
REGISTER_DEVICE(PIPackedTCP)
|
||||
|
||||
#endif // PIP_NO_SOCKET
|
||||
|
||||
#endif
|
||||
|
||||
@@ -98,8 +98,8 @@ void PIPacketExtractor::construct() {
|
||||
func_payload = nullptr;
|
||||
setPayloadSize(0);
|
||||
setTimeout(100_ms);
|
||||
#ifdef MICRO_PIP
|
||||
setThreadedReadBufferSize(512);
|
||||
#ifdef PIP_EMBEDDED
|
||||
setThreadedReadBufferSize(16_KiB);
|
||||
#else
|
||||
setThreadedReadBufferSize(64_KiB);
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#ifndef PISTREAMPACKER_H
|
||||
#define PISTREAMPACKER_H
|
||||
#ifndef PIP_NO_SOCKET
|
||||
|
||||
#include "piethutilbase.h"
|
||||
#include "piobject.h"
|
||||
@@ -200,4 +201,5 @@ private:
|
||||
mutable PIMutex prog_s_mutex, prog_r_mutex;
|
||||
};
|
||||
|
||||
#endif // PIP_NO_SOCKET
|
||||
#endif // PISTREAMPACKER_H
|
||||
|
||||
Reference in New Issue
Block a user