1 Commits

Author SHA1 Message Date
34bc322b9b version 5.5.3
force using '.' instead of ',' in PIString::fromNumber()
2025-10-22 15:24:10 +03:00
19 changed files with 490 additions and 546 deletions

View File

@@ -6,7 +6,7 @@ endif()
project(PIP)
set(PIP_MAJOR 5)
set(PIP_MINOR 5)
set(PIP_REVISION 2)
set(PIP_REVISION 3)
set(PIP_SUFFIX )
set(PIP_COMPANY SHS)
set(PIP_DOMAIN org.SHS)
@@ -221,17 +221,10 @@ if (TESTS)
add_subdirectory(tests)
endif()
if(PIP_MICRO)
add_definitions(-DMICRO_PIP)
set(ICU OFF)
set(LOCAL ON)
endif()
if(PIP_FREERTOS)
add_definitions(-DPIP_FREERTOS)
endif()
if(DEFINED PICO_BOARD)
add_definitions(-DPICO_SDK)
message(STATUS "Building PIP for Pi Pico SDK ${PICO_SDK_VERSION_STRING}")
set(ICU OFF)
set(LOCAL ON)
endif()
# Check Bessel functions
@@ -336,7 +329,7 @@ if ((NOT DEFINED SHSTKPROJECT) AND (DEFINED ANDROID_PLATFORM))
#message("${ANDROID_NDK}/sysroot/usr/include")
endif()
if(NOT PIP_MICRO)
if(NOT PIP_FREERTOS)
if(WIN32)
if(${C_COMPILER} STREQUAL "cl.exe")
else()
@@ -357,7 +350,7 @@ if(NOT PIP_MICRO)
endif()
endif()
set(PIP_LIBS)
if(PIP_MICRO)
if(PIP_FREERTOS)
set(PIP_LIBS ${LIBS_MAIN})
else()
foreach(LIB_ ${LIBS_MAIN})
@@ -371,11 +364,11 @@ if(WIN32)
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
if(DEFINED ENV{QNX_HOST} OR PIP_FREERTOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-32")
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
if(DEFINED ENV{QNX_HOST} OR PIP_MICRO)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-32")
endif()
set(PCRE2_BUILD_PCRE2_8 OFF)
set(PCRE2_BUILD_PCRE2_16 ON )
@@ -413,7 +406,7 @@ endif()
if (NOT CROSSTOOLS)
if (NOT PIP_MICRO)
if (NOT PIP_FREERTOS)
if (PIP_BUILD_CONSOLE)
pip_module(console "" "PIP console support" "" "" "")
@@ -631,7 +624,7 @@ string(REPLACE ";" "," PIP_EXPORTS_STR "${PIP_EXPORTS}")
target_compile_definitions(pip PRIVATE "PICODE_DEFINES=\"${PIP_EXPORTS_STR}\"")
if(NOT PIP_MICRO)
if(NOT PIP_FREERTOS)
# Auxiliary
if (NOT CROSSTOOLS)
@@ -708,7 +701,7 @@ if(NOT LOCAL)
install(TARGETS ${PIP_MODULES} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
endif()
else()
if(NOT PIP_MICRO)
if(NOT PIP_FREERTOS)
if(WIN32)
install(TARGETS ${PIP_MODULES} RUNTIME DESTINATION bin)
install(TARGETS ${PIP_MODULES} ARCHIVE DESTINATION lib)
@@ -736,7 +729,7 @@ endif()
#
# Build Documentation
#
if ((NOT PIP_MICRO) AND (NOT CROSSTOOLS))
if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS))
include(PIPDocumentation)
find_package(Doxygen)
if(DOXYGEN_FOUND)
@@ -805,7 +798,7 @@ message(" Type : ${CMAKE_BUILD_TYPE}")
if (NOT LOCAL)
message(" Install: \"${CMAKE_INSTALL_PREFIX}\"")
else()
if(NOT PIP_MICRO)
if(NOT PIP_FREERTOS)
message(" Install: local \"bin\", \"lib\" and \"include\"")
endif()
endif()
@@ -838,7 +831,7 @@ message(" Utilites:")
foreach(_util ${PIP_UTILS_LIST})
message(" * ${_util}")
endforeach()
if(NOT PIP_MICRO)
if(NOT PIP_FREERTOS)
message("")
message(" Using libraries:")
foreach(LIB_ ${LIBS_STATUS})

View File

@@ -71,7 +71,7 @@ if (NOT BUILDING_PIP)
find_library(PTHREAD_LIBRARY pthread)
find_library(UTIL_LIBRARY util)
set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY})
if((NOT DEFINED ENV{QNX_HOST}) AND (NOT APPLE) AND (NOT PIP_MICRO))
if((NOT DEFINED ENV{QNX_HOST}) AND (NOT APPLE) AND (NOT PIP_FREERTOS))
find_library(RT_LIBRARY rt)
list(APPEND _PIP_ADD_LIBS_ ${RT_LIBRARY})
endif()

View File

@@ -17,7 +17,6 @@ list(APPEND COMPONENT_ADD_INCLUDEDIRS "../libs/main/thread")
set(COMPONENT_PRIV_REQUIRES pthread lwip freertos vfs spi_flash libsodium)
register_component()
set(PIP_FREERTOS ON)
set(PIP_MICRO ON)
set(LIB OFF)
set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES})
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/newlib/platform_include)

View File

@@ -113,7 +113,7 @@ bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
}
# endif
# else
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
if (PRIVATE->hProc == 0) {
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
return false;
@@ -178,9 +178,6 @@ PISystemTime uint64toST(uint64_t v) {
void PISystemMonitor::run() {
cur_tm.clear();
tbid.clear();
ProcessStats tstat;
tstat.ID = pID_;
#ifndef PIP_NO_THREADS
__PIThreadCollection * pitc = __PIThreadCollection::instance();
pitc->lock();
PIVector<PIThread *> tv = pitc->threads();
@@ -188,14 +185,16 @@ void PISystemMonitor::run() {
if (t->isPIObject()) tbid[t->tid()] = t->name();
pitc->unlock();
// piCout << tbid.keys().toType<uint>();
# ifdef FREERTOS
ProcessStats tstat;
tstat.ID = pID_;
#ifdef MICRO_PIP
for (auto * t: tv)
if (t->isPIObject()) gatherThread(t->tid());
# else // FREERTOS
# ifndef WINDOWS
#else
# ifndef WINDOWS
double delay_ms = delay_.toMilliseconds();
tbid[pID_] = "main";
# ifdef MAC_OS
# ifdef MAC_OS
rusage_info_current ru;
proc_pid_rusage(pID_, RUSAGE_INFO_CURRENT, (rusage_info_t *)&ru);
// piCout << PISystemTime(((uint*)&(ru.ri_user_time))[1], ((uint*)&(ru.ri_user_time))[0]);
@@ -211,7 +210,7 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 100.f * (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
cycle = 0;
// piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
# else // MAC_OS
# else
PRIVATE->file.seekToBegin();
PIString str = PIString::fromAscii(PRIVATE->file.readAll());
int si = str.find('(') + 1, fi = 0, cc = 1;
@@ -265,8 +264,8 @@ void PISystemMonitor::run() {
if (i.flags[PIFile::FileInfo::Dot] || i.flags[PIFile::FileInfo::DotDot]) continue;
gatherThread(i.name().toInt());
}
# endif // MAC_OS
# else // WINDOWS
# endif
# else
if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) {
tstat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize;
}
@@ -316,9 +315,8 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 0.f;
}
PRIVATE->tm.reset();
# endif // WINDOWS
# endif // FREERTOS
#endif // PIP_NO_THREADS
# endif
#endif
tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f);
tstat.cpu_load_user = piClampf(tstat.cpu_load_user, 0.f, 100.f);
@@ -354,7 +352,7 @@ void PISystemMonitor::gatherThread(llong id) {
#ifdef MICRO_PIP
ts.name = tbid.value(id, "<PIThread>");
#else
ts.name = tbid.value(id, "<non-PIThread>");
ts.name = tbid.value(id, "<non-PIThread>");
# ifndef WINDOWS
PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat");
// piCout << f.path();

View File

@@ -18,11 +18,9 @@
*/
#include "pikbdlistener.h"
#ifndef MICRO_PIP
# include "piincludes_p.h"
# include "piliterals.h"
# include "piwaitevent_p.h"
#include "piincludes_p.h"
#include "piliterals.h"
#include "piwaitevent_p.h"
// clang-format off
#ifndef WINDOWS
# include <termios.h>
@@ -51,7 +49,7 @@ bool PIKbdListener::exiting;
PIKbdListener * PIKbdListener::_object = 0;
# ifndef WINDOWS
#ifndef WINDOWS
// unix
const PIKbdListener::EscSeq PIKbdListener::esc_seq[] = {
{"OA", PIKbdListener::UpArrow, 0, 0, 1},
@@ -132,22 +130,22 @@ void setupTerminal(bool on) {
printf(on ? "h" : "l");
fflush(0);
}
# endif
#endif
PRIVATE_DEFINITION_START(PIKbdListener)
# ifdef WINDOWS
#ifdef WINDOWS
void *hIn, *hOut;
DWORD smode, tmode;
CONSOLE_SCREEN_BUFFER_INFO sbi;
# else
#else
struct termios sterm, tterm;
# endif
# ifdef WINDOWS
#endif
#ifdef WINDOWS
DWORD
# else
#else
int
# endif
#endif
ret;
PIWaitEvent event;
PRIVATE_DEFINITION_END(PIKbdListener)
@@ -156,13 +154,13 @@ PRIVATE_DEFINITION_END(PIKbdListener)
PIKbdListener::PIKbdListener(KBFunc slot, void * _d, bool startNow): PIThread() {
setName("keyboard_listener"_a);
_object = this;
# ifdef WINDOWS
#ifdef WINDOWS
PRIVATE->hIn = GetStdHandle(STD_INPUT_HANDLE);
PRIVATE->hOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(PRIVATE->hIn, &PRIVATE->smode);
# else
#else
tcgetattr(0, &PRIVATE->sterm);
# endif
#endif
ret_func = slot;
kbddata_ = _d;
dbl_interval = 400;
@@ -180,10 +178,10 @@ PIKbdListener::~PIKbdListener() {
void PIKbdListener::begin() {
# ifdef WINDOWS
#ifdef WINDOWS
GetConsoleMode(PRIVATE->hIn, &PRIVATE->tmode);
SetConsoleMode(PRIVATE->hIn, ENABLE_PROCESSED_INPUT | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS);
# else
#else
struct termios term;
tcgetattr(0, &term);
term.c_lflag &= ~(ECHO | ICANON);
@@ -191,11 +189,11 @@ void PIKbdListener::begin() {
PRIVATE->tterm = term;
tcsetattr(0, TCSANOW, &term);
setupTerminal(true);
# endif
#endif
}
# ifdef WINDOWS
#ifdef WINDOWS
PIKbdListener::KeyModifiers getModifiers(DWORD v, bool * shift = 0) {
PIKbdListener::KeyModifiers ret;
bool ctrl = v & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED);
@@ -216,7 +214,7 @@ PIKbdListener::MouseButtons getButtons(DWORD v) {
if (v & FROM_LEFT_2ND_BUTTON_PRESSED) ret |= PIKbdListener::MouseMiddle;
return ret;
}
# endif
#endif
void PIKbdListener::readKeyboard() {
@@ -224,7 +222,7 @@ void PIKbdListener::readKeyboard() {
ke.modifiers = 0;
char rc[8];
piZeroMemory(rc, 8);
# ifdef WINDOWS
#ifdef WINDOWS
INPUT_RECORD ir;
ReadConsoleInput(PRIVATE->hIn, &ir, 1, &(PRIVATE->ret));
switch (ir.EventType) {
@@ -408,7 +406,7 @@ void PIKbdListener::readKeyboard() {
} break;
default: piMSleep(10); return;
}
# else
#else
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
if (!PRIVATE->event.wait(0)) return;
PRIVATE->ret = read(0, rc, 8);
@@ -535,7 +533,7 @@ void PIKbdListener::readKeyboard() {
cout << endl;*/
}
if (ke.key == 0 && PRIVATE->ret > 1) ke.key = PIChar::fromSystem(rc).unicode16Code();
# endif
#endif
if ((rc[0] == '\n' || rc[0] == '\r') && PRIVATE->ret == 1) ke.key = Return;
if (exit_enabled && ke.key == exit_key) {
PIKbdListener::exiting = true;
@@ -562,32 +560,30 @@ bool PIKbdListener::stopAndWait(PISystemTime timeout) {
void PIKbdListener::end() {
// cout << "list end" << endl;
# ifdef WINDOWS
#ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->smode);
# else
#else
tcsetattr(0, TCSANOW, &PRIVATE->sterm);
setupTerminal(false);
# endif
#endif
}
void PIKbdListener::setActive(bool yes) {
is_active = yes;
if (is_active) {
# ifdef WINDOWS
#ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->tmode);
# else
#else
tcsetattr(0, TCSANOW, &PRIVATE->tterm);
setupTerminal(true);
# endif
#endif
} else {
# ifdef WINDOWS
#ifdef WINDOWS
SetConsoleMode(PRIVATE->hIn, PRIVATE->smode);
# else
#else
tcsetattr(0, TCSANOW, &PRIVATE->sterm);
setupTerminal(false);
# endif
#endif
}
}
#endif // MICRO_PIP

View File

@@ -26,19 +26,15 @@
#ifndef PIKBDLISTENER_H
#define PIKBDLISTENER_H
#include "pibase.h"
#include "pithread.h"
#include "pitime.h"
#ifndef MICRO_PIP
# include "pithread.h"
# include "pitime.h"
# define WAIT_FOR_EXIT \
while (!PIKbdListener::exiting) \
piMSleep(PIP_MIN_MSLEEP * 5); \
if (PIKbdListener::instance()) { \
if (!PIKbdListener::instance()->stopAndWait(PISystemTime::fromSeconds(1))) PIKbdListener::instance()->terminate(); \
}
#define WAIT_FOR_EXIT \
while (!PIKbdListener::exiting) \
piMSleep(PIP_MIN_MSLEEP * 5); \
if (PIKbdListener::instance()) { \
if (!PIKbdListener::instance()->stopAndWait(PISystemTime::fromSeconds(1))) PIKbdListener::instance()->terminate(); \
}
class PIP_EXPORT PIKbdListener: public PIThread {
@@ -235,7 +231,7 @@ private:
void run() override { readKeyboard(); }
void end() override;
# ifndef WINDOWS
#ifndef WINDOWS
struct PIP_EXPORT EscSeq {
const char * seq;
int key;
@@ -255,7 +251,7 @@ private:
};
static const EscSeq esc_seq[];
# endif
#endif
PRIVATE_DECLARATION(PIP_EXPORT)
KBFunc ret_func;
@@ -309,5 +305,4 @@ REGISTER_PIVARIANTSIMPLE(PIKbdListener::KeyEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::MouseEvent)
REGISTER_PIVARIANTSIMPLE(PIKbdListener::WheelEvent)
#endif // MICRO_PIP
#endif // PIKBDLISTENER_H

View File

@@ -18,19 +18,18 @@
*/
#include "piwaitevent_p.h"
#ifndef MICRO_PIP
# ifdef WINDOWS
#ifdef WINDOWS
// # ifdef _WIN32_WINNT
// # undef _WIN32_WINNT
// # define _WIN32_WINNT 0x0600
// # endif
# include <synchapi.h>
# else
# include <errno.h>
# include <fcntl.h>
# include <sys/ioctl.h>
# endif
# include "pistring.h"
# include <synchapi.h>
#else
# include <errno.h>
# include <fcntl.h>
# include <sys/ioctl.h>
#endif
#include "pistring.h"
PIWaitEvent::~PIWaitEvent() {
@@ -40,12 +39,12 @@ PIWaitEvent::~PIWaitEvent() {
void PIWaitEvent::create() {
destroy();
# ifdef WINDOWS
#ifdef WINDOWS
event = CreateEventA(NULL, TRUE, FALSE, NULL);
if (!event) {
piCout << "Error with CreateEventA:" << errorString();
}
# else
#else
for (int i = 0; i < 3; ++i)
piZeroMemory(fds[i]);
if (::pipe(pipe_fd) < 0) {
@@ -54,34 +53,34 @@ void PIWaitEvent::create() {
fcntl(pipe_fd[ReadEnd], F_SETFL, O_NONBLOCK);
fcntl(pipe_fd[WriteEnd], F_SETFL, O_NONBLOCK);
}
# endif
#endif
}
void PIWaitEvent::destroy() {
# ifdef WINDOWS
#ifdef WINDOWS
if (event) {
CloseHandle(event);
event = NULL;
}
# else
#else
for (int i = 0; i < 2; ++i) {
if (pipe_fd[i] != 0) {
::close(pipe_fd[i]);
pipe_fd[i] = 0;
}
}
# endif
#endif
}
bool PIWaitEvent::wait(int fd, CheckRole role) {
if (!isCreate()) return false;
# ifdef WINDOWS
#ifdef WINDOWS
DWORD ret = WaitForSingleObjectEx(event, INFINITE, TRUE);
ResetEvent(event);
if (ret == WAIT_IO_COMPLETION || ret == WAIT_FAILED) return false;
# else
#else
if (fd == -1) return false;
int nfds = piMaxi(pipe_fd[ReadEnd], fd) + 1;
int fd_index = role;
@@ -98,18 +97,18 @@ bool PIWaitEvent::wait(int fd, CheckRole role) {
if (sr == EBADF || sr == EINTR) return false;
if (FD_ISSET(fd, &(fds[CheckExeption]))) return true;
return FD_ISSET(fd, &(fds[fd_index]));
# endif
#endif
return true;
}
bool PIWaitEvent::sleep(int us) {
if (!isCreate()) return false;
# ifdef WINDOWS
#ifdef WINDOWS
DWORD ret = WaitForSingleObjectEx(event, us / 1000, TRUE);
ResetEvent(event);
return ret == WAIT_TIMEOUT;
# else
#else
int nfds = pipe_fd[ReadEnd] + 1;
FD_ZERO(&(fds[CheckRead]));
FD_SET(pipe_fd[ReadEnd], &(fds[CheckRead]));
@@ -121,36 +120,34 @@ bool PIWaitEvent::sleep(int us) {
while (::read(pipe_fd[ReadEnd], &buf, sizeof(buf)) > 0)
;
return ret == 0;
# endif
#endif
}
void PIWaitEvent::interrupt() {
if (!isCreate()) return;
# ifdef WINDOWS
#ifdef WINDOWS
SetEvent(event);
# else
#else
auto _r = ::write(pipe_fd[WriteEnd], "", 1);
NO_UNUSED(_r);
# endif
#endif
}
bool PIWaitEvent::isCreate() const {
# ifdef WINDOWS
#ifdef WINDOWS
return event;
# else
#else
return pipe_fd[ReadEnd] != 0;
# endif
#endif
}
void * PIWaitEvent::getEvent() const {
# ifdef WINDOWS
#ifdef WINDOWS
return event;
# else
#else
return nullptr;
# endif
#endif
}
#endif // MICRO_PIP

View File

@@ -20,9 +20,7 @@
#ifndef PIWAITEVENT_P_H
#define PIWAITEVENT_P_H
#ifndef MICRO_PIP
# include "pibase.h"
#include "pibase.h"
// clang-format off
#ifdef WINDOWS
# include <stdarg.h>
@@ -54,18 +52,17 @@ public:
void * getEvent() const; // WINDOWS only
private:
# ifdef WINDOWS
#ifdef WINDOWS
void * event = nullptr;
# else
#else
int pipe_fd[2] = {0, 0};
fd_set fds[3];
enum {
ReadEnd = 0,
WriteEnd = 1
};
# endif
#endif
};
#endif // MICRO_PIP
#endif // PIWAITEVENT_P_H

View File

@@ -19,12 +19,10 @@
#include "piintrospection_server_p.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
# include "pichunkstream.h"
# include "piinit.h"
# include "piobject.h"
# include "pisysteminfo.h"
#include "pichunkstream.h"
#include "piinit.h"
#include "piobject.h"
#include "pisysteminfo.h"
const uint PIIntrospection::sign = 0x0F1C2B3A;
@@ -113,9 +111,9 @@ PIByteArray PIIntrospection::packContainers() {
PIByteArray ret;
PIVector<PIIntrospectionContainers::TypeInfo> data;
PIIntrospectionContainers * p = 0;
# ifdef PIP_INTROSPECTION
#ifdef PIP_INTROSPECTION
p = PIINTROSPECTION_CONTAINERS->p;
# endif
#endif
if (p) {
data = p->getInfo();
}
@@ -133,9 +131,9 @@ void PIIntrospection::unpackContainers(PIByteArray & ba, PIVector<PIIntrospectio
PIByteArray PIIntrospection::packThreads() {
PIByteArray ret;
PIIntrospectionThreads * p = 0;
# ifdef PIP_INTROSPECTION
#ifdef PIP_INTROSPECTION
p = PIINTROSPECTION_THREADS->p;
# endif
#endif
if (p) {
p->mutex.lock();
PIMap<PIThread *, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
@@ -172,5 +170,3 @@ void PIIntrospection::unpackObjects(PIByteArray & ba, PIVector<PIIntrospection::
objects.clear();
ba >> objects;
}
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)

View File

@@ -27,7 +27,6 @@
#include "piintrospection_threads_p.h"
#include "pisystemmonitor.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIP_EXPORT PIIntrospection {
public:
@@ -169,5 +168,4 @@ BINARY_STREAM_READ(PIIntrospection::ObjectInfo) {
return s;
}
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#endif // PIINTROSPECTION_SERVER_P_H

View File

@@ -19,7 +19,6 @@
#include "piintrospection_threads_p.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
id = delay = 0;
@@ -79,5 +78,3 @@ void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) {
ThreadInfo & ti(threads[t]);
ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING
}
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)

View File

@@ -20,10 +20,6 @@
#ifndef PIINTROSPECTION_THREADS_P_H
#define PIINTROSPECTION_THREADS_P_H
#include "pibase.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "pimap.h"
#include "pithread.h"
@@ -72,5 +68,4 @@ BINARY_STREAM_READ(PIIntrospectionThreads::ThreadInfo) {
return s;
}
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#endif // PIINTROSPECTION_THREADS_P_H

View File

@@ -20,7 +20,7 @@
#include "pipropertystorage.h"
#include "piwaitevent_p.h"
#if !defined(WINDOWS) && !defined(MAC_OS) && !defined(PIP_NO_SOCKET)
#if !defined(WINDOWS) && !defined(MAC_OS) && !defined(MICRO_PIP)
# define PIP_CAN
#endif
#ifdef PIP_CAN
@@ -39,29 +39,25 @@
REGISTER_DEVICE(PICAN)
#ifdef PIP_CAN
PRIVATE_DEFINITION_START(PICAN)
PIWaitEvent event;
PRIVATE_DEFINITION_END(PICAN)
#endif
PICAN::PICAN(const PIString & path, PIIODevice::DeviceMode mode): PIIODevice(path, mode) {
setThreadedReadBufferSize(256);
setPath(path);
#ifdef PIP_CAN
can_id = 0;
sock = 0;
PRIVATE->event.create();
#endif
}
PICAN::~PICAN() {
stopAndWait();
close();
#ifdef PIP_CAN
PRIVATE->event.destroy();
#endif
}
@@ -168,9 +164,7 @@ int PICAN::readedCANID() const {
void PICAN::interrupt() {
#ifdef PIP_CAN
PRIVATE->event.interrupt();
#endif
}

View File

@@ -18,65 +18,64 @@
*/
#include "piethernet.h"
#ifndef PIP_NO_SOCKET
# include "piconfig.h"
# include "piconstchars.h"
# include "piincludes_p.h"
# include "piliterals.h"
# include "pipropertystorage.h"
# include "pisysteminfo.h"
# include "pitranslator.h"
# ifdef QNX
# include <arpa/inet.h>
# include <fcntl.h>
# include <hw/nicinfo.h>
# include <ifaddrs.h>
# include <net/if.h>
# include <net/if_dl.h>
# include <netdb.h>
#include "piconfig.h"
#include "piconstchars.h"
#include "piincludes_p.h"
#include "piliterals.h"
#include "pipropertystorage.h"
#include "pisysteminfo.h"
#include "pitranslator.h"
// clang-format off
#ifdef QNX
# include <arpa/inet.h>
# include <fcntl.h>
# include <hw/nicinfo.h>
# include <ifaddrs.h>
# include <net/if.h>
# include <net/if_dl.h>
# include <netdb.h>
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <sys/time.h>
# include <sys/types.h>
# ifdef BLACKBERRY
# include <netinet/in.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <sys/time.h>
# include <sys/types.h>
# ifdef BLACKBERRY
# include <netinet/in.h>
# else
# include <sys/dcmd_io-net.h>
# endif
# define ip_mreqn ip_mreq
# define imr_address imr_interface
# else
# ifdef WINDOWS
# include <io.h>
# include <iphlpapi.h>
# include <psapi.h>
# include <winsock2.h>
# include <ws2tcpip.h>
# define ip_mreqn ip_mreq
# define imr_address imr_interface
# else
# include <arpa/inet.h>
# include <fcntl.h>
# include <net/if.h>
# include <netdb.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# if !defined(ANDROID) && !defined(LWIP)
# include <ifaddrs.h>
# endif
# ifdef LWIP
# include <lwip/sockets.h>
# endif
# endif
# include <sys/dcmd_io-net.h>
# endif
# include "piwaitevent_p.h"
# define ip_mreqn ip_mreq
# define imr_address imr_interface
#else
# ifdef WINDOWS
# include <io.h>
# include <winsock2.h>
# include <iphlpapi.h>
# include <psapi.h>
# include <ws2tcpip.h>
# define ip_mreqn ip_mreq
# define imr_address imr_interface
# else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <sys/socket.h>
# include <netdb.h>
# include <net/if.h>
# if !defined(ANDROID) && !defined(LWIP)
# include <ifaddrs.h>
# endif
# ifdef LWIP
# include <lwip/sockets.h>
# endif
# endif
#endif
// clang-format on
#include "piwaitevent_p.h"
# include <errno.h>
#include <errno.h>
/** \class PIEthernet piethernet.h
@@ -101,11 +100,11 @@
*
* */
# ifndef WINDOWS
#ifndef WINDOWS
PIString getSockAddr(sockaddr * s) {
return s == 0 ? PIString() : PIStringAscii(inet_ntoa(((sockaddr_in *)s)->sin_addr));
}
# endif
#endif
REGISTER_DEVICE(PIEthernet)
@@ -197,11 +196,11 @@ void PIEthernet::construct() {
setMulticastTTL(1);
server_thread_.setData(this);
server_thread_.setName("_S.tcpserver"_a);
# ifdef LWIP
#ifdef MICRO_PIP
setThreadedReadBufferSize(512);
# else
#else
setThreadedReadBufferSize(64_KiB);
# endif
#endif
// setPriority(piHigh);
}
@@ -305,9 +304,9 @@ bool PIEthernet::openDevice() {
PRIVATE->addr_.sin_addr.s_addr = INADDR_ANY;
else
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
# ifdef QNX
#ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
# endif
#endif
// piCout << "bind to" << (params[PIEthernet::Broadcast] ? "255.255.255.255" : ip_) << ":" << port_ << " ...";
int tries = 0;
while ((bind(sock, (sockaddr *)&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 2)) {
@@ -380,14 +379,14 @@ void PIEthernet::applyBuffers() {
void PIEthernet::applyTimeout(int fd, int opt, PISystemTime tm) {
if (fd == 0) return;
// piCoutObj << "setReadIsBlocking" << yes;
# ifdef WINDOWS
// piCoutObj << "setReadIsBlocking" << yes;
#ifdef WINDOWS
DWORD _tm = tm.toMilliseconds();
# else
#else
timeval _tm;
_tm.tv_sec = tm.seconds;
_tm.tv_usec = tm.nanoseconds / 1000;
# endif
#endif
ethSetsockopt(fd, SOL_SOCKET, opt, &_tm, sizeof(_tm));
}
@@ -412,30 +411,30 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
return true;
}
addr_r.set(path());
# ifndef LWIP
#ifndef LWIP
struct ip_mreqn mreq;
# else
#else
struct ip_mreq mreq;
# endif
#endif
piZeroMemory(mreq);
# ifdef LINUX
#ifdef LINUX
// mreq.imr_address.s_addr = INADDR_ANY;
/*PIEthernet::InterfaceList il = interfaces();
const PIEthernet::Interface * ci = il.getByAddress(addr_r.ipString());
if (ci != 0) mreq.imr_ifindex = ci->index;*/
# endif
#endif
if (params[PIEthernet::Broadcast])
# ifndef LWIP
#ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY;
# else
#else
mreq.imr_interface.s_addr = INADDR_ANY;
# endif
#endif
else
# ifndef LWIP
#ifndef LWIP
mreq.imr_address.s_addr = addr_r.ip();
# else
#else
mreq.imr_interface.s_addr = addr_r.ip();
# endif
#endif
// piCout << "join group" << group << "ip" << ip_ << "with index" << mreq.imr_ifindex << "socket" << sock;
mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii());
@@ -458,24 +457,24 @@ bool PIEthernet::leaveMulticastGroup(const PIString & group) {
return false;
}
addr_r.set(path());
# ifndef LWIP
#ifndef LWIP
struct ip_mreqn mreq;
# else
#else
struct ip_mreq mreq;
# endif
#endif
piZeroMemory(mreq);
if (params[PIEthernet::Broadcast])
# ifndef LWIP
#ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY;
# else
#else
mreq.imr_interface.s_addr = INADDR_ANY;
# endif
#endif
else
# ifndef LWIP
#ifndef LWIP
mreq.imr_address.s_addr = addr_r.ip();
# else
#else
mreq.imr_interface.s_addr = addr_r.ip();
# endif
#endif
mreq.imr_multiaddr.s_addr = inet_addr(group.dataAscii());
if (ethSetsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)) == -1) {
piCoutObj << "Can`t leave multicast group" << group << "," << ethErrorString();
@@ -499,9 +498,9 @@ bool PIEthernet::connect(bool threaded) {
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET;
# ifdef QNX
#ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
# endif
#endif
connecting_ = true;
connected_ = connectTCP();
connecting_ = false;
@@ -536,9 +535,9 @@ bool PIEthernet::listen(bool threaded) {
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET;
# ifdef QNX
#ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
# endif
#endif
opened_ = false;
int tries = 0;
while ((bind(sock, (sockaddr *)&PRIVATE->addr_, sizeof(PRIVATE->addr_)) == -1) && (tries < 2)) {
@@ -662,9 +661,9 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET;
# ifdef QNX
#ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
# endif
#endif
// piCoutObj << "connect to " << path() << "...";
connected_ = connectTCP();
// piCoutObj << "connect to " << path() << connected_;
@@ -679,7 +678,7 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
}
if (!connected_) return -1;
errorClear();
# ifdef WINDOWS
#ifdef WINDOWS
{
long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE);
switch (wr) {
@@ -695,34 +694,34 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
default: break;
}
}
# else
#else
if (PRIVATE->event.wait(sock)) {
errorClear();
rs = ethRecv(sock, read_to, max_size);
}
# endif
#endif
// piCoutObj << "readed" << rs;
if (rs <= 0) {
lerr = ethErrorCore();
// piCoutObj << "readed" << rs << "error" << lerr;
// async normal returns
# ifdef WINDOWS
#ifdef WINDOWS
if (lerr == WSAEWOULDBLOCK) {
# else
#else
if (lerr == EWOULDBLOCK || lerr == EAGAIN || lerr == EINTR) {
# endif
#endif
// piCoutObj << "Ignore would_block" << lerr;
return -1;
}
// if no disconnect on timeout
if (!params[DisonnectOnTimeout]) {
# ifdef WINDOWS
#ifdef WINDOWS
if (lerr == WSAETIMEDOUT) {
# else
#else
if (lerr == ETIMEDOUT) {
# endif
#endif
// piCoutObj << "Ignore read timeout";
return -1;
}
@@ -746,7 +745,7 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
case UDP: {
piZeroMemory(PRIVATE->raddr_);
// piCoutObj << "read from" << path() << "...";
# ifdef WINDOWS
#ifdef WINDOWS
long wr = waitForEvent(PRIVATE->event, FD_READ | FD_CLOSE);
switch (wr) {
case FD_READ:
@@ -759,9 +758,9 @@ ssize_t PIEthernet::readDevice(void * read_to, ssize_t max_size) {
break;
default: break;
}
# else
#else
rs = ethRecvfrom(sock, read_to, max_size, 0, (sockaddr *)&PRIVATE->raddr_);
# endif
#endif
// piCoutObj << "read from" << path() << rs << "bytes";
if (rs > 0) {
addr_lr.set(uint(PRIVATE->raddr_.sin_addr.s_addr), ntohs(PRIVATE->raddr_.sin_port));
@@ -794,11 +793,11 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
return ethSendto(sock_s,
data,
max_size,
# ifndef WINDOWS
#ifndef WINDOWS
isOptionSet(BlockingWrite) ? 0 : MSG_DONTWAIT
# else
#else
0
# endif
#endif
,
(sockaddr *)&PRIVATE->saddr_,
sizeof(PRIVATE->saddr_));
@@ -810,9 +809,9 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
PRIVATE->addr_.sin_port = htons(addr_r.port());
PRIVATE->addr_.sin_addr.s_addr = addr_r.ip();
PRIVATE->addr_.sin_family = AF_INET;
# ifdef QNX
#ifdef QNX
PRIVATE->addr_.sin_len = sizeof(PRIVATE->addr_);
# endif
#endif
// piCoutObj << "connect to " << ip << ":" << port_;
connected_ = connectTCP();
if (!connected_) piCoutObj << "Can`t connect to" << addr_r << "," << ethErrorString();
@@ -848,11 +847,11 @@ ssize_t PIEthernet::writeDevice(const void * data, ssize_t max_size) {
int sr = ::send(sock, remain_data, remain_size, 0);
if (sr < 0) {
int err = ethErrorCore();
# ifdef WINDOWS
#ifdef WINDOWS
if (err == WSAEWOULDBLOCK) {
# else
#else
if (err == EAGAIN || err == EWOULDBLOCK) {
# endif
#endif
piMinSleep();
// piCoutObj << "wait for write";
continue;
@@ -911,30 +910,30 @@ void PIEthernet::server_func(void * eth) {
}
sockaddr_in client_addr;
socklen_t slen = sizeof(client_addr);
# ifdef WINDOWS
#ifdef WINDOWS
long wr = ce->waitForEvent(ce->PRIVATEWB->event, FD_ACCEPT | FD_CLOSE);
if (wr != FD_ACCEPT) {
piMSleep(10);
return;
}
# else
#else
if (!ce->PRIVATEWB->event.wait(ce->sock)) {
piMSleep(10);
return;
}
# endif
#endif
// piCout << "server" << "accept ...";
int s = accept(ce->sock, (sockaddr *)&client_addr, &slen);
// piCout << "server" << "accept done" << ethErrorString();
if (s == -1) {
int lerr = ethErrorCore();
# ifdef WINDOWS
#ifdef WINDOWS
if (lerr == WSAETIMEDOUT) {
# elif defined(ANDROID)
#elif defined(ANDROID)
if ((lerr == EAGAIN || lerr == EINTR)) {
# else
#else
if (lerr == EAGAIN) {
# endif
#endif
piMSleep(10);
return;
}
@@ -970,7 +969,7 @@ void PIEthernet::setType(Type t, bool reopen) {
bool PIEthernet::connectTCP() {
::connect(sock, (sockaddr *)&(PRIVATE->addr_), sizeof(PRIVATE->addr_));
// piCout << errorString();
# ifdef WINDOWS
#ifdef WINDOWS
long wr = waitForEvent(PRIVATE->event, FD_CONNECT | FD_CLOSE);
switch (wr) {
case FD_CONNECT:
@@ -978,7 +977,7 @@ bool PIEthernet::connectTCP() {
return ethIsWriteable(sock);
default: break;
}
# else
#else
if (PRIVATE->event.wait(sock, PIWaitEvent::CheckWrite)) {
if (ethIsWriteable(sock))
return true;
@@ -987,12 +986,12 @@ bool PIEthernet::connectTCP() {
init();
}
}
# endif
#endif
return false;
}
# ifdef WINDOWS
#ifdef WINDOWS
long PIEthernet::waitForEvent(PIWaitEvent & event, long mask) {
if (!event.isCreate() || sock < 0) return 0;
if (WSAEventSelect(sock, event.getEvent(), mask) == SOCKET_ERROR) {
@@ -1009,7 +1008,7 @@ long PIEthernet::waitForEvent(PIWaitEvent & event, long mask) {
}
return 0;
}
# endif
#endif
bool PIEthernet::configureDevice(const void * e_main, const void * e_parent) {
@@ -1119,7 +1118,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
Interface ci;
ci.index = -1;
ci.mtu = 1500;
# ifdef WINDOWS
#ifdef WINDOWS
int ret = 0;
ulong ulOutBufLen = sizeof(IP_ADAPTER_INFO);
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
@@ -1170,10 +1169,10 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
}
}
if (pAdapterInfo) HeapFree(GetProcessHeap(), 0, pAdapterInfo);
#else
# ifdef MICRO_PIP
# else
# ifdef LWIP
# else
# ifdef ANDROID
# ifdef ANDROID
struct ifconf ifc;
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
ifc.ifc_len = 256;
@@ -1201,7 +1200,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
il << ci;
}
delete ifc.ifc_buf;
# else
# else
struct ifaddrs *ret, *cif = 0;
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
if (getifaddrs(&ret) == 0) {
@@ -1219,8 +1218,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ci.address = getSockAddr(cif->ifa_addr);
ci.netmask = getSockAddr(cif->ifa_netmask);
ci.mac.clear();
# ifdef QNX
# ifndef BLACKBERRY
# ifdef QNX
# ifndef BLACKBERRY
int fd = ::open((PIString("/dev/io-net/") + ci.name).dataAscii(), O_RDONLY);
if (fd != 0) {
nic_config_t nic;
@@ -1228,9 +1227,9 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
::close(fd);
ci.mac = macFromBytes(PIByteArray(nic.permanent_address, 6));
}
# endif
# else
# ifdef MAC_OS
# endif
# else
# ifdef MAC_OS
PIString req = PISystemInfo::instance()->ifconfigPath + " " + ci.name + " | grep ether";
FILE * fp = popen(req.dataAscii(), "r");
if (fp != 0) {
@@ -1241,7 +1240,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
}
pclose(fp);
}
# else
# else
if (s != -1) {
struct ifreq ir;
memset(&ir, 0, sizeof(ir));
@@ -1253,8 +1252,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
ci.mtu = ir.ifr_mtu;
}
}
# endif
# endif
# endif
ci.flags = 0;
if (cif->ifa_flags & IFF_UP) ci.flags |= PIEthernet::ifActive;
if (cif->ifa_flags & IFF_RUNNING) ci.flags |= PIEthernet::ifRunning;
@@ -1275,18 +1274,18 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
piCout << "[PIEthernet]"
<< "Can`t get interfaces: %1"_tr("PIEthernet").arg(errorString());
if (s != -1) ::close(s);
# endif
# endif
# endif
#endif
return il;
}
PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) {
# if defined(WINDOWS) || defined(LWIP)
#if defined(WINDOWS) || defined(MICRO_PIP)
piCout << "[PIEthernet] Not implemented, use \"PIEthernet::allAddresses\" or \"PIEthernet::interfaces\" instead";
return PINetworkAddress();
# else
#else
struct ifreq ifr;
piZeroMemory(ifr);
strcpy(ifr.ifr_name, interface_.dataAscii());
@@ -1295,7 +1294,7 @@ PINetworkAddress PIEthernet::interfaceAddress(const PIString & interface_) {
::close(s);
struct sockaddr_in * sa = (struct sockaddr_in *)&ifr.ifr_addr;
return PINetworkAddress(uint(sa->sin_addr.s_addr));
# endif
#endif
}
@@ -1318,16 +1317,16 @@ PIVector<PINetworkAddress> PIEthernet::allAddresses() {
// System wrap
int PIEthernet::ethErrorCore() {
# ifdef WINDOWS
#ifdef WINDOWS
return WSAGetLastError();
# else
#else
return errno;
# endif
#endif
}
PIString PIEthernet::ethErrorString() {
# ifdef WINDOWS
#ifdef WINDOWS
char * msg = nullptr;
int err = WSAGetLastError();
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
@@ -1344,18 +1343,18 @@ PIString PIEthernet::ethErrorString() {
} else
ret += '?';
return ret;
# else
#else
return errorString();
# endif
#endif
}
int PIEthernet::ethRecv(int sock, void * buf, int size, int flags) {
if (sock < 0) return -1;
return recv(sock,
# ifdef WINDOWS
#ifdef WINDOWS
(char *)
# endif
#endif
buf,
size,
flags);
@@ -1364,29 +1363,29 @@ int PIEthernet::ethRecv(int sock, void * buf, int size, int flags) {
int PIEthernet::ethRecvfrom(int sock, void * buf, int size, int flags, sockaddr * addr) {
if (sock < 0) return -1;
# ifdef QNX
#ifdef QNX
return recv(sock, buf, size, flags);
# else
#else
socklen_t len = sizeof(sockaddr);
return recvfrom(sock,
# ifdef WINDOWS
# ifdef WINDOWS
(char *)
# endif
# endif
buf,
size,
flags,
addr,
&len);
# endif
#endif
}
int PIEthernet::ethSendto(int sock, const void * buf, int size, int flags, sockaddr * addr, int addr_len) {
if (sock < 0) return -1;
return sendto(sock,
# ifdef WINDOWS
#ifdef WINDOWS
(const char *)
# endif
#endif
buf,
size,
flags,
@@ -1400,26 +1399,26 @@ void PIEthernet::ethClosesocket(int sock, bool shutdown) {
if (sock < 0) return;
if (shutdown)
::shutdown(sock,
# ifdef WINDOWS
#ifdef WINDOWS
SD_BOTH);
closesocket(sock);
# else
#else
SHUT_RDWR);
::close(sock);
# endif
#endif
}
int PIEthernet::ethSetsockopt(int sock, int level, int optname, const void * optval, int optlen) {
if (sock < 0) return -1;
auto ret = setsockopt(sock,
level,
optname,
# ifdef WINDOWS
(char *)
# endif
optval,
optlen);
level,
optname,
#ifdef WINDOWS
(char *)
#endif
optval,
optlen);
if (ret != 0) piCout << "setsockopt error:" << ethErrorString();
return ret;
}
@@ -1427,11 +1426,11 @@ int PIEthernet::ethSetsockopt(int sock, int level, int optname, const void * opt
int PIEthernet::ethSetsockoptInt(int sock, int level, int optname, int value) {
if (sock < 0) return -1;
# ifdef WINDOWS
#ifdef WINDOWS
DWORD
# else
#else
int
# endif
#endif
so = value;
return ethSetsockopt(sock, level, optname, &so, sizeof(so));
}
@@ -1439,11 +1438,11 @@ int PIEthernet::ethSetsockoptInt(int sock, int level, int optname, int value) {
int PIEthernet::ethSetsockoptBool(int sock, int level, int optname, bool value) {
if (sock < 0) return -1;
# ifdef WINDOWS
#ifdef WINDOWS
BOOL
# else
#else
int
# endif
#endif
so = (value ? 1 : 0);
return ethSetsockopt(sock, level, optname, &so, sizeof(so));
}
@@ -1451,12 +1450,12 @@ int PIEthernet::ethSetsockoptBool(int sock, int level, int optname, bool value)
void PIEthernet::ethNonblocking(int sock) {
if (sock < 0) return;
# ifdef WINDOWS
#ifdef WINDOWS
u_long mode = 1;
ioctlsocket(sock, FIONBIO, &mode);
# else
#else
fcntl(sock, F_SETFL, O_NONBLOCK);
# endif
#endif
}
@@ -1472,7 +1471,7 @@ bool PIEthernet::ethIsWriteable(int sock) {
timeout.tv_sec = timeout.tv_usec = 0;
::select(fds, nullptr, &fd_test, nullptr, &timeout);
return FD_ISSET(sock, &fd_test);*/
# ifdef WINDOWS
#ifdef WINDOWS
fd_set fd_test;
FD_ZERO(&fd_test);
FD_SET(sock, &fd_test);
@@ -1480,12 +1479,10 @@ bool PIEthernet::ethIsWriteable(int sock) {
timeout.tv_sec = timeout.tv_usec = 0;
::select(0, nullptr, &fd_test, nullptr, &timeout);
return FD_ISSET(sock, &fd_test);
# else
#else
int ret = 0;
socklen_t len = sizeof(ret);
getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&ret, &len);
return ret == 0;
# endif
#endif
}
#endif // PIP_NO_SOCKET

View File

@@ -26,17 +26,14 @@
#ifndef PIETHERNET_H
#define PIETHERNET_H
#include "piiodevice.h"
#include "pinetworkaddress.h"
#ifndef PIP_NO_SOCKET
# ifdef ANDROID
#ifdef ANDROID
struct
# else
#else
class
# endif
#endif
sockaddr;
class PIP_EXPORT PIEthernet: public PIIODevice {
@@ -442,7 +439,7 @@ public:
//! \}
//! \ioparams
//! \{
# ifdef DOXYGEN
#ifdef DOXYGEN
//! \brief read ip, default ""
string ip;
@@ -463,7 +460,7 @@ public:
//! \brief time-to-live for multicast, default 1
int multicastTTL;
# endif
#endif
//! \}
protected:
@@ -512,9 +509,9 @@ private:
static void server_func(void * eth);
void setType(Type t, bool reopen = true);
bool connectTCP();
# ifdef WINDOWS
#ifdef WINDOWS
long waitForEvent(PIWaitEvent & event, long mask);
# endif
#endif
static int ethErrorCore();
static PIString ethErrorString();
@@ -539,5 +536,4 @@ inline bool operator!=(const PIEthernet::Interface & v0, const PIEthernet::Inter
return (v0.name != v1.name || v0.address != v1.address || v0.netmask != v1.netmask);
}
#endif // PIP_NO_SOCKET
#endif // PIETHERNET_H

View File

@@ -45,7 +45,7 @@
# include <utime.h>
#endif
#define S_IFHDN 0x40
#if defined(QNX) || defined(ANDROID) || defined(MICRO_PIP)
#if defined(QNX) || defined(ANDROID) || defined(FREERTOS)
# define _fopen_call_ fopen
# define _fseek_call_ fseek
# define _ftell_call_ ftell

View File

@@ -19,37 +19,38 @@
#include "piserial.h"
#ifndef MICRO_PIP
#include "piconfig.h"
#include "pidir.h"
#include "piincludes_p.h"
#include "pipropertystorage.h"
#include "pitime.h"
#include "pitranslator.h"
#include "piwaitevent_p.h"
# include "piconfig.h"
# include "pidir.h"
# include "piincludes_p.h"
# include "pipropertystorage.h"
# include "pitime.h"
# include "pitranslator.h"
# include "piwaitevent_p.h"
#include <errno.h>
# include <errno.h>
# if defined(PISERIAL_NO_PINS) || defined(WINDOWS)
# define TIOCM_LE 1
# define TIOCM_DTR 4
# define TIOCM_RTS 7
# define TIOCM_CTS 8
# define TIOCM_ST 3
# define TIOCM_SR 2
# define TIOCM_CAR 1
# define TIOCM_RNG 9
# define TIOCM_DSR 6
#if defined(MICRO_PIP)
# define PISERIAL_NO_PINS
#endif
#if defined(PISERIAL_NO_PINS) || defined(WINDOWS)
# define TIOCM_LE 1
# define TIOCM_DTR 4
# define TIOCM_RTS 7
# define TIOCM_CTS 8
# define TIOCM_ST 3
# define TIOCM_SR 2
# define TIOCM_CAR 1
# define TIOCM_RNG 9
# define TIOCM_DSR 6
#endif
#ifdef WINDOWS
# ifndef INITGUID
# define INITGUID
# include <guiddef.h>
# undef INITGUID
# else
# include <guiddef.h>
# endif
# ifdef WINDOWS
# ifndef INITGUID
# define INITGUID
# include <guiddef.h>
# undef INITGUID
# else
# include <guiddef.h>
# endif
// clang-format off
# include <ntddmodm.h>
# include <winreg.h>
@@ -58,89 +59,89 @@
# include <cfgmgr32.h>
# include <setupapi.h>
// clang-format on
# define B50 50
# define B75 75
# define B110 110
# define B300 300
# define B600 600
# define B1200 1200
# define B2400 2400
# define B4800 4800
# define B9600 9600
# define B14400 14400
# define B19200 19200
# define B38400 38400
# define B57600 57600
# define B115200 115200
# define B230400 230400
# define B460800 460800
# define B500000 500000
# define B576000 576000
# define B921600 921600
# define B1000000 1000000
# define B1152000 1152000
# define B1500000 1500000
# define B2000000 2000000
# define B2500000 2500000
# define B3000000 3000000
# define B3500000 3500000
# define B4000000 4000000
# else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <termios.h>
# ifndef B50
# define B50 0000001
# endif
# ifndef B75
# define B75 0000002
# endif
# ifndef B230400
# define B230400 0010003
# endif
# ifndef B460800
# define B460800 0010004
# endif
# ifndef B500000
# define B500000 0010005
# endif
# ifndef B576000
# define B576000 0010006
# endif
# ifndef B921600
# define B921600 0010007
# endif
# ifndef B1000000
# define B1000000 0010010
# endif
# ifndef B1152000
# define B1152000 0010011
# endif
# ifndef B1500000
# define B1500000 0010012
# endif
# ifndef B2000000
# define B2000000 0010013
# endif
# ifndef B2500000
# define B2500000 0010014
# endif
# ifndef B3000000
# define B3000000 0010015
# endif
# ifndef B3500000
# define B3500000 0010016
# endif
# ifndef B4000000
# define B4000000 0010017
# endif
# define B50 50
# define B75 75
# define B110 110
# define B300 300
# define B600 600
# define B1200 1200
# define B2400 2400
# define B4800 4800
# define B9600 9600
# define B14400 14400
# define B19200 19200
# define B38400 38400
# define B57600 57600
# define B115200 115200
# define B230400 230400
# define B460800 460800
# define B500000 500000
# define B576000 576000
# define B921600 921600
# define B1000000 1000000
# define B1152000 1152000
# define B1500000 1500000
# define B2000000 2000000
# define B2500000 2500000
# define B3000000 3000000
# define B3500000 3500000
# define B4000000 4000000
#else
# include <fcntl.h>
# include <sys/ioctl.h>
# include <termios.h>
# ifndef B50
# define B50 0000001
# endif
# ifndef CRTSCTS
# define CRTSCTS 020000000000
# ifndef B75
# define B75 0000002
# endif
# ifdef LINUX
# include <linux/serial.h>
# ifndef B230400
# define B230400 0010003
# endif
# ifndef B460800
# define B460800 0010004
# endif
# ifndef B500000
# define B500000 0010005
# endif
# ifndef B576000
# define B576000 0010006
# endif
# ifndef B921600
# define B921600 0010007
# endif
# ifndef B1000000
# define B1000000 0010010
# endif
# ifndef B1152000
# define B1152000 0010011
# endif
# ifndef B1500000
# define B1500000 0010012
# endif
# ifndef B2000000
# define B2000000 0010013
# endif
# ifndef B2500000
# define B2500000 0010014
# endif
# ifndef B3000000
# define B3000000 0010015
# endif
# ifndef B3500000
# define B3500000 0010016
# endif
# ifndef B4000000
# define B4000000 0010017
# endif
#endif
#ifndef CRTSCTS
# define CRTSCTS 020000000000
#endif
#ifdef LINUX
# include <linux/serial.h>
#endif
//! \class PISerial piserial.h
@@ -176,16 +177,16 @@ REGISTER_DEVICE(PISerial)
PRIVATE_DEFINITION_START(PISerial)
PIWaitEvent event;
# ifdef WINDOWS
#ifdef WINDOWS
PIWaitEvent event_write;
DCB desc, sdesc;
HANDLE hCom = nullptr;
DWORD readed = 0, mask = 0;
OVERLAPPED overlap, overlap_write;
# else
#else
termios desc, sdesc;
uint readed = 0;
# endif
#endif
PRIVATE_DEFINITION_END(PISerial)
@@ -213,9 +214,9 @@ PISerial::~PISerial() {
stopAndWait();
close();
PRIVATE->event.destroy();
# ifdef WINDOWS
#ifdef WINDOWS
PRIVATE->event_write.destroy();
# endif
#endif
}
@@ -346,7 +347,7 @@ bool PISerial::setBreak(bool enabled) {
piCoutObj << "sendBreak error: \"" << path() << "\" is not opened!";
return false;
}
# ifdef WINDOWS
#ifdef WINDOWS
if (enabled) {
if (!SetCommBreak(PRIVATE->hCom)) {
piCoutObj << "setBreak error: " << errorString();
@@ -362,14 +363,14 @@ bool PISerial::setBreak(bool enabled) {
return true;
}
}
# else
#else
if (ioctl(fd, enabled ? TIOCSBRK : TIOCCBRK) < 0) {
piCoutObj << "setBreak error: " << errorString();
return false;
} else {
return true;
}
# endif
#endif
return false;
}
@@ -379,8 +380,8 @@ bool PISerial::setBit(int bit, bool on, const PIString & bname) {
piCoutObj << "setBit" << bname << " error: \"" << path() << "\" is not opened!";
return false;
}
# ifndef PISERIAL_NO_PINS
# ifdef WINDOWS
#ifndef PISERIAL_NO_PINS
# ifdef WINDOWS
static int bit_map_on[] = {0, 0, 0, 0, SETDTR, 0, 0, SETRTS, 0, 0, 0};
static int bit_map_off[] = {0, 0, 0, 0, CLRDTR, 0, 0, CLRRTS, 0, 0, 0};
int action = (on ? bit_map_on : bit_map_off)[bit];
@@ -391,14 +392,14 @@ bool PISerial::setBit(int bit, bool on, const PIString & bname) {
}
return true;
}
# else
# else
if (ioctl(fd, on ? TIOCMBIS : TIOCMBIC, &bit) < 0) {
piCoutObj << "setBit" << bname << " error: " << errorString();
return false;
}
return true;
# endif
# endif
#endif
piCoutObj << "setBit" << bname << " doesn`t implemented, sorry :-(";
return false;
}
@@ -409,23 +410,23 @@ bool PISerial::isBit(int bit, const PIString & bname) const {
piCoutObj << "isBit" << bname << " error: \"" << path() << "\" is not opened!";
return false;
}
# ifndef PISERIAL_NO_PINS
# ifdef WINDOWS
# else
#ifndef PISERIAL_NO_PINS
# ifdef WINDOWS
# else
int ret = 0;
if (ioctl(fd, TIOCMGET, &ret) < 0) piCoutObj << "isBit" << bname << " error: " << errorString();
return ret & bit;
# endif
# endif
#endif
piCoutObj << "isBit" << bname << " doesn`t implemented, sorry :-(";
return false;
}
void PISerial::flush() {
# ifndef WINDOWS
#ifndef WINDOWS
if (fd != -1) tcflush(fd, TCIOFLUSH);
# endif
#endif
}
@@ -440,9 +441,9 @@ int PISerial::convertSpeed(PISerial::Speed speed) {
case S2400: return B2400;
case S4800: return B4800;
case S9600: return B9600;
# ifdef WINDOWS
#ifdef WINDOWS
case S14400: return B14400;
# endif
#endif
case S19200: return B19200;
case S38400: return B38400;
case S57600: return B57600;
@@ -462,13 +463,13 @@ int PISerial::convertSpeed(PISerial::Speed speed) {
case S4000000: return B4000000;
default: break;
}
# ifdef WINDOWS
#ifdef WINDOWS
piCoutObj << "Warning: Custom speed %1"_tr("PISerial").arg((int)speed);
return (int)speed;
# else
#else
piCoutObj << "Warning: Unknown speed %1, using 115200"_tr("PISerial").arg((int)speed);
return B115200;
# endif
#endif
}
@@ -671,9 +672,9 @@ bool PISerial::send(const void * data, int size) {
void PISerial::interrupt() {
// piCoutObj << "interrupt";
PRIVATE->event.interrupt();
# ifdef WINDOWS
#ifdef WINDOWS
PRIVATE->event_write.interrupt();
# endif
#endif
}
@@ -695,7 +696,7 @@ bool PISerial::openDevice() {
}
}
if (p.isEmpty()) return false;
# ifdef WINDOWS
#ifdef WINDOWS
DWORD ds = 0, sm = 0;
if (isReadable()) {
ds |= GENERIC_READ;
@@ -713,7 +714,7 @@ bool PISerial::openDevice() {
return false;
}
fd = 0;
# else
#else
int om = 0;
switch (mode()) {
case PIIODevice::ReadOnly: om = O_RDONLY; break;
@@ -728,12 +729,12 @@ bool PISerial::openDevice() {
tcgetattr(fd, &PRIVATE->desc);
PRIVATE->sdesc = PRIVATE->desc;
// piCoutObj << "Initialized " << p;
# endif
#endif
applySettings();
PRIVATE->event.create();
# ifdef WINDOWS
#ifdef WINDOWS
PRIVATE->event_write.create();
# endif
#endif
return true;
}
@@ -744,28 +745,28 @@ bool PISerial::closeDevice() {
stopThreadedRead();
}
if (fd != -1) {
# ifdef WINDOWS
#ifdef WINDOWS
SetCommState(PRIVATE->hCom, &PRIVATE->sdesc);
SetCommMask(PRIVATE->hCom, PRIVATE->mask);
// piCoutObj << "close" <<
CloseHandle(PRIVATE->hCom);
PRIVATE->hCom = 0;
# else
#else
tcsetattr(fd, TCSANOW, &PRIVATE->sdesc);
::close(fd);
# endif
#endif
fd = -1;
}
PRIVATE->event.destroy();
# ifdef WINDOWS
#ifdef WINDOWS
PRIVATE->event_write.destroy();
# endif
#endif
return true;
}
void PISerial::applySettings() {
# ifdef WINDOWS
#ifdef WINDOWS
if (fd == -1) return;
setTimeouts();
GetCommMask(PRIVATE->hCom, &PRIVATE->mask);
@@ -791,7 +792,7 @@ void PISerial::applySettings() {
piCoutObj << "Unable to set comm state for \"%1\""_tr("PISerial").arg(path());
return;
}
# else
#else
if (fd == -1) return;
tcgetattr(fd, &PRIVATE->desc);
PRIVATE->desc.c_oflag = PRIVATE->desc.c_lflag = PRIVATE->desc.c_cflag = 0;
@@ -825,12 +826,12 @@ void PISerial::applySettings() {
piCoutObj << "Can`t set attributes for \"%1\""_tr("PISerial").arg(path());
return;
}
# endif
#endif
}
void PISerial::setTimeouts() {
# ifdef WINDOWS
#ifdef WINDOWS
COMMTIMEOUTS times;
if (isOptionSet(BlockingRead)) {
times.ReadIntervalTimeout = MAXDWORD;
@@ -844,9 +845,9 @@ void PISerial::setTimeouts() {
times.WriteTotalTimeoutConstant = isOptionSet(BlockingWrite) ? 0 : 1;
times.WriteTotalTimeoutMultiplier = 0;
if (SetCommTimeouts(PRIVATE->hCom, &times) == -1) piCoutObj << "Unable to set timeouts for \"" << path() << "\"";
# else
#else
fcntl(fd, F_SETFL, isOptionSet(BlockingRead) ? 0 : O_NONBLOCK);
# endif
#endif
}
@@ -865,7 +866,7 @@ void PISerial::setTimeouts() {
//!
//! \~\sa \a readData(), \a readString()
ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
# ifdef WINDOWS
#ifdef WINDOWS
if (!canRead()) return -1;
if (sending) return -1;
// piCoutObj << "read ..." << PRIVATE->hCom << max_size;
@@ -895,7 +896,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
return -1;
// piCoutObj << "read" << (PRIVATE->readed) << errorString();
return PRIVATE->readed;
# else
#else
if (!canRead()) return -1;
if (isOptionSet(PIIODevice::BlockingRead)) {
if (!PRIVATE->event.wait(fd)) return -1;
@@ -910,7 +911,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
}
}
return ret;
# endif
#endif
}
@@ -919,7 +920,7 @@ ssize_t PISerial::writeDevice(const void * data, ssize_t max_size) {
// piCoutObj << "Can`t write to uninitialized COM";
return -1;
}
# ifdef WINDOWS
#ifdef WINDOWS
DWORD wrote(0);
// piCoutObj << "send ..." << max_size;// << ": " << PIString((char*)data, max_size);
sending = true;
@@ -931,11 +932,11 @@ ssize_t PISerial::writeDevice(const void * data, ssize_t max_size) {
}
sending = false;
// piCoutObj << "send ok" << wrote;// << " bytes in " << path();
# else
#else
ssize_t wrote;
wrote = ::write(fd, data, max_size);
if (isOptionSet(BlockingWrite)) tcdrain(fd);
# endif
#endif
return (ssize_t)wrote;
// piCoutObj << "Error while sending";
}
@@ -1060,9 +1061,9 @@ void PISerial::configureFromVariantDevice(const PIPropertyStorage & d) {
PIVector<int> PISerial::availableSpeeds() {
PIVector<int> spds;
spds << 50 << 75 << 110 << 300 << 600 << 1200 << 2400 << 4800 << 9600 <<
# ifdef WINDOWS
#ifdef WINDOWS
14400 <<
# endif
#endif
19200 << 38400 << 57600 << 115200 << 230400 << 460800 << 500000 << 576000 << 921600 << 1000000 << 1152000 << 1500000 << 2000000
<< 2500000 << 3000000 << 3500000 << 4000000;
return spds;
@@ -1078,7 +1079,7 @@ PIStringList PISerial::availableDevices(bool test) {
}
# ifdef WINDOWS
#ifdef WINDOWS
PIString devicePortName(HDEVINFO deviceInfoSet, PSP_DEVINFO_DATA deviceInfoData) {
PIString ret;
const HKEY key = SetupDiOpenDevRegKey(deviceInfoSet, deviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
@@ -1146,13 +1147,13 @@ bool parseID(PIString str, PISerial::DeviceInfo & di) {
if (i > 0) di.pID = str.mid(i + 4, 4).toInt(16);
return (di.vID > 0) && (di.pID > 0);
}
# endif
#endif
PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
PIVector<DeviceInfo> ret;
DeviceInfo di;
# ifdef WINDOWS
#ifdef WINDOWS
static const GUID guids[] = {GUID_DEVINTERFACE_MODEM, GUID_DEVINTERFACE_COMPORT};
static const int guids_cnt = sizeof(guids) / sizeof(GUID);
for (int i = 0; i < guids_cnt; ++i) {
@@ -1181,12 +1182,12 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
}
SetupDiDestroyDeviceInfoList(dis);
}
# else
# ifndef ANDROID
#else
# ifndef ANDROID
PIStringList prefixes;
# ifdef QNX
# ifdef QNX
prefixes << "ser";
# else
# else
prefixes << "ttyS"
<< "ttyO"
<< "ttyUSB"
@@ -1197,14 +1198,14 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
<< "ttyAMA"
<< "rfcomm"
<< "ircomm";
# ifdef FREE_BSD
# ifdef FREE_BSD
prefixes << "cu";
# endif
# ifdef MAC_OS
# endif
# ifdef MAC_OS
prefixes.clear();
prefixes << "cu."
<< "tty.";
# endif
# endif
PIFile file_prefixes("/proc/tty/drivers", PIIODevice::ReadOnly);
if (file_prefixes.open()) {
PIString fc = PIString::fromAscii(file_prefixes.readAll()), line, cpref;
@@ -1225,18 +1226,18 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
}
prefixes.removeDuplicates();
}
# endif
# endif
PIDir dir("/dev");
PIVector<PIFile::FileInfo> de = dir.entries();
# ifdef LINUX
# ifdef LINUX
char linkbuf[1024];
# endif
# endif
for (const auto & e: de) { // TODO changes in FileInfo
for (const auto & p: prefixes) {
if (e.name().startsWith(p)) {
di = DeviceInfo();
di.path = e.path;
# ifdef LINUX
di = DeviceInfo();
di.path = e.path;
# ifdef LINUX
ssize_t lsz = readlink(("/sys/class/tty/" + e.name()).dataAscii(), linkbuf, 1024);
if (lsz > 0) {
PIString fpath = "/sys/class/tty/" + PIString(linkbuf, lsz) + "/";
@@ -1252,16 +1253,16 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
if (di.pID > 0) break;
}
}
# endif
# endif
ret << di;
}
}
}
# endif
# endif
#endif
if (test) {
for (int i = 0; i < ret.size_s(); ++i) {
# ifdef WINDOWS
#ifdef WINDOWS
void * hComm = CreateFileA(ret[i].path.dataAscii(),
GENERIC_READ,
FILE_SHARE_READ,
@@ -1270,31 +1271,31 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
0);
if (hComm == INVALID_HANDLE_VALUE) {
# else
#else
int fd = ::open(ret[i].path.dataAscii(), O_NOCTTY | O_RDONLY);
if (fd == -1) {
# endif
#endif
ret.remove(i);
--i;
continue;
}
bool rok = true;
# ifndef WINDOWS
#ifndef WINDOWS
int void_ = 0;
fcntl(fd, F_SETFL, O_NONBLOCK);
if (::read(fd, &void_, 1) == -1) rok = errno != EIO;
# endif
#endif
if (!rok) {
ret.remove(i);
--i;
continue;
}
# ifdef WINDOWS
#ifdef WINDOWS
CloseHandle(hComm);
# else
#else
::close(fd);
# endif
#endif
}
}
return ret;
@@ -1308,14 +1309,12 @@ void PISerial::optionsChanged() {
void PISerial::threadedReadBufferSizeChanged() {
if (!isOpened()) return;
# if defined(LINUX)
#if defined(LINUX)
serial_struct ss;
ioctl(fd, TIOCGSERIAL, &ss);
// piCoutObj << "b" << ss.xmit_fifo_size;
ss.xmit_fifo_size = piMaxi(threadedReadBufferSize(), 4096);
ioctl(fd, TIOCSSERIAL, &ss);
// piCoutObj << "a" << ss.xmit_fifo_size;
# endif
#endif
}
#endif // MICRO_PIP

View File

@@ -51,14 +51,8 @@
#ifdef PIP_FREERTOS
# define FREERTOS
#endif
#ifdef MICRO_PIP
# ifndef FREERTOS
# define PIP_NO_THREADS
# endif
# ifndef LWIP
# define PIP_NO_SOCKET
# endif
# define PISERIAL_NO_PINS
#if defined(FREERTOS) || defined(PLATFORMIO)
# define MICRO_PIP
#endif
#ifndef WINDOWS
# ifndef QNX

View File

@@ -206,7 +206,10 @@ PIString PIString::dtos(const double num, char format, int precision) {
if (wr > 4) wr = 4;
f[2 + wr] = format;
f[3 + wr] = 0;
pisprintf(f, num);
char ch[256];
piZeroMemory(ch, 256);
snprintf(ch, 256, f, num);
return PIStringAscii(ch).replaceAll(',', '.');
}
#undef pisprintf