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

View File

@@ -71,7 +71,7 @@ if (NOT BUILDING_PIP)
find_library(PTHREAD_LIBRARY pthread) find_library(PTHREAD_LIBRARY pthread)
find_library(UTIL_LIBRARY util) find_library(UTIL_LIBRARY util)
set(_PIP_ADD_LIBS_ ${PTHREAD_LIBRARY} ${UTIL_LIBRARY}) 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) find_library(RT_LIBRARY rt)
list(APPEND _PIP_ADD_LIBS_ ${RT_LIBRARY}) list(APPEND _PIP_ADD_LIBS_ ${RT_LIBRARY})
endif() 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) set(COMPONENT_PRIV_REQUIRES pthread lwip freertos vfs spi_flash libsodium)
register_component() register_component()
set(PIP_FREERTOS ON) set(PIP_FREERTOS ON)
set(PIP_MICRO ON)
set(LIB OFF) set(LIB OFF)
set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES}) set(INCLUDE_DIRS ${IDF_INCLUDE_DIRECTORIES})
list(APPEND INCLUDE_DIRS $ENV{IDF_PATH}/components/newlib/platform_include) 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 # endif
# else # 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) { if (PRIVATE->hProc == 0) {
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString()); piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
return false; return false;
@@ -178,9 +178,6 @@ PISystemTime uint64toST(uint64_t v) {
void PISystemMonitor::run() { void PISystemMonitor::run() {
cur_tm.clear(); cur_tm.clear();
tbid.clear(); tbid.clear();
ProcessStats tstat;
tstat.ID = pID_;
#ifndef PIP_NO_THREADS
__PIThreadCollection * pitc = __PIThreadCollection::instance(); __PIThreadCollection * pitc = __PIThreadCollection::instance();
pitc->lock(); pitc->lock();
PIVector<PIThread *> tv = pitc->threads(); PIVector<PIThread *> tv = pitc->threads();
@@ -188,14 +185,16 @@ void PISystemMonitor::run() {
if (t->isPIObject()) tbid[t->tid()] = t->name(); if (t->isPIObject()) tbid[t->tid()] = t->name();
pitc->unlock(); pitc->unlock();
// piCout << tbid.keys().toType<uint>(); // piCout << tbid.keys().toType<uint>();
# ifdef FREERTOS ProcessStats tstat;
tstat.ID = pID_;
#ifdef MICRO_PIP
for (auto * t: tv) for (auto * t: tv)
if (t->isPIObject()) gatherThread(t->tid()); if (t->isPIObject()) gatherThread(t->tid());
# else // FREERTOS #else
# ifndef WINDOWS # ifndef WINDOWS
double delay_ms = delay_.toMilliseconds(); double delay_ms = delay_.toMilliseconds();
tbid[pID_] = "main"; tbid[pID_] = "main";
# ifdef MAC_OS # ifdef MAC_OS
rusage_info_current ru; rusage_info_current ru;
proc_pid_rusage(pID_, RUSAGE_INFO_CURRENT, (rusage_info_t *)&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]); // 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; tstat.cpu_load_user = 100.f * (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
cycle = 0; cycle = 0;
// piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms; // piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
# else // MAC_OS # else
PRIVATE->file.seekToBegin(); PRIVATE->file.seekToBegin();
PIString str = PIString::fromAscii(PRIVATE->file.readAll()); PIString str = PIString::fromAscii(PRIVATE->file.readAll());
int si = str.find('(') + 1, fi = 0, cc = 1; 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; if (i.flags[PIFile::FileInfo::Dot] || i.flags[PIFile::FileInfo::DotDot]) continue;
gatherThread(i.name().toInt()); gatherThread(i.name().toInt());
} }
# endif // MAC_OS # endif
# else // WINDOWS # else
if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) { if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) {
tstat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize; tstat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize;
} }
@@ -316,9 +315,8 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 0.f; tstat.cpu_load_user = 0.f;
} }
PRIVATE->tm.reset(); PRIVATE->tm.reset();
# endif // WINDOWS # endif
# endif // FREERTOS #endif
#endif // PIP_NO_THREADS
tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f); 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); 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 #ifdef MICRO_PIP
ts.name = tbid.value(id, "<PIThread>"); ts.name = tbid.value(id, "<PIThread>");
#else #else
ts.name = tbid.value(id, "<non-PIThread>"); ts.name = tbid.value(id, "<non-PIThread>");
# ifndef WINDOWS # ifndef WINDOWS
PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat"); PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat");
// piCout << f.path(); // piCout << f.path();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -19,7 +19,6 @@
#include "piintrospection_threads_p.h" #include "piintrospection_threads_p.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
PIIntrospectionThreads::ThreadInfo::ThreadInfo() { PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
id = delay = 0; id = delay = 0;
@@ -79,5 +78,3 @@ void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) {
ThreadInfo & ti(threads[t]); ThreadInfo & ti(threads[t]);
ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING 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 #ifndef PIINTROSPECTION_THREADS_P_H
#define 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 "pimap.h"
#include "pithread.h" #include "pithread.h"
@@ -72,5 +68,4 @@ BINARY_STREAM_READ(PIIntrospectionThreads::ThreadInfo) {
return s; return s;
} }
#endif // #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#endif // PIINTROSPECTION_THREADS_P_H #endif // PIINTROSPECTION_THREADS_P_H

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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