Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf89d77981 | |||
| 4885623492 |
@@ -221,11 +221,18 @@ if (TESTS)
|
|||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PIP_FREERTOS)
|
if(PIP_MICRO)
|
||||||
add_definitions(-DPIP_FREERTOS)
|
add_definitions(-DMICRO_PIP)
|
||||||
set(ICU OFF)
|
set(ICU OFF)
|
||||||
set(LOCAL ON)
|
set(LOCAL ON)
|
||||||
endif()
|
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}")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Check Bessel functions
|
# Check Bessel functions
|
||||||
set(CMAKE_REQUIRED_INCLUDES math.h)
|
set(CMAKE_REQUIRED_INCLUDES math.h)
|
||||||
@@ -329,7 +336,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_FREERTOS)
|
if(NOT PIP_MICRO)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
if(${C_COMPILER} STREQUAL "cl.exe")
|
if(${C_COMPILER} STREQUAL "cl.exe")
|
||||||
else()
|
else()
|
||||||
@@ -350,7 +357,7 @@ if(NOT PIP_FREERTOS)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
set(PIP_LIBS)
|
set(PIP_LIBS)
|
||||||
if(PIP_FREERTOS)
|
if(PIP_MICRO)
|
||||||
set(PIP_LIBS ${LIBS_MAIN})
|
set(PIP_LIBS ${LIBS_MAIN})
|
||||||
else()
|
else()
|
||||||
foreach(LIB_ ${LIBS_MAIN})
|
foreach(LIB_ ${LIBS_MAIN})
|
||||||
@@ -364,11 +371,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 )
|
||||||
@@ -406,7 +413,7 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
if (NOT CROSSTOOLS)
|
if (NOT CROSSTOOLS)
|
||||||
if (NOT PIP_FREERTOS)
|
if (NOT PIP_MICRO)
|
||||||
|
|
||||||
if (PIP_BUILD_CONSOLE)
|
if (PIP_BUILD_CONSOLE)
|
||||||
pip_module(console "" "PIP console support" "" "" "")
|
pip_module(console "" "PIP console support" "" "" "")
|
||||||
@@ -624,7 +631,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_FREERTOS)
|
if(NOT PIP_MICRO)
|
||||||
|
|
||||||
# Auxiliary
|
# Auxiliary
|
||||||
if (NOT CROSSTOOLS)
|
if (NOT CROSSTOOLS)
|
||||||
@@ -701,7 +708,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_FREERTOS)
|
if(NOT PIP_MICRO)
|
||||||
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)
|
||||||
@@ -729,7 +736,7 @@ endif()
|
|||||||
#
|
#
|
||||||
# Build Documentation
|
# Build Documentation
|
||||||
#
|
#
|
||||||
if ((NOT PIP_FREERTOS) AND (NOT CROSSTOOLS))
|
if ((NOT PIP_MICRO) AND (NOT CROSSTOOLS))
|
||||||
include(PIPDocumentation)
|
include(PIPDocumentation)
|
||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
if(DOXYGEN_FOUND)
|
if(DOXYGEN_FOUND)
|
||||||
@@ -798,7 +805,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_FREERTOS)
|
if(NOT PIP_MICRO)
|
||||||
message(" Install: local \"bin\", \"lib\" and \"include\"")
|
message(" Install: local \"bin\", \"lib\" and \"include\"")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
@@ -831,7 +838,7 @@ message(" Utilites:")
|
|||||||
foreach(_util ${PIP_UTILS_LIST})
|
foreach(_util ${PIP_UTILS_LIST})
|
||||||
message(" * ${_util}")
|
message(" * ${_util}")
|
||||||
endforeach()
|
endforeach()
|
||||||
if(NOT PIP_FREERTOS)
|
if(NOT PIP_MICRO)
|
||||||
message("")
|
message("")
|
||||||
message(" Using libraries:")
|
message(" Using libraries:")
|
||||||
foreach(LIB_ ${LIBS_STATUS})
|
foreach(LIB_ ${LIBS_STATUS})
|
||||||
|
|||||||
@@ -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_FREERTOS))
|
if((NOT DEFINED ENV{QNX_HOST}) AND (NOT APPLE) AND (NOT PIP_MICRO))
|
||||||
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()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ 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)
|
||||||
|
|||||||
@@ -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,6 +178,9 @@ 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();
|
||||||
@@ -185,16 +188,14 @@ 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>();
|
||||||
ProcessStats tstat;
|
# ifdef FREERTOS
|
||||||
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
|
# else // FREERTOS
|
||||||
# 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]);
|
||||||
@@ -210,7 +211,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
|
# else // MAC_OS
|
||||||
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;
|
||||||
@@ -264,8 +265,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
|
# endif // MAC_OS
|
||||||
# else
|
# else // WINDOWS
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -315,8 +316,9 @@ void PISystemMonitor::run() {
|
|||||||
tstat.cpu_load_user = 0.f;
|
tstat.cpu_load_user = 0.f;
|
||||||
}
|
}
|
||||||
PRIVATE->tm.reset();
|
PRIVATE->tm.reset();
|
||||||
# endif
|
# endif // WINDOWS
|
||||||
#endif
|
# endif // FREERTOS
|
||||||
|
#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);
|
||||||
@@ -352,7 +354,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();
|
||||||
|
|||||||
@@ -18,9 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
#include "pikbdlistener.h"
|
#include "pikbdlistener.h"
|
||||||
|
|
||||||
#include "piincludes_p.h"
|
#ifndef MICRO_PIP
|
||||||
#include "piliterals.h"
|
|
||||||
#include "piwaitevent_p.h"
|
# include "piincludes_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>
|
||||||
@@ -49,7 +51,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},
|
||||||
@@ -130,22 +132,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)
|
||||||
@@ -154,13 +156,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;
|
||||||
@@ -178,10 +180,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);
|
||||||
@@ -189,11 +191,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);
|
||||||
@@ -214,7 +216,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() {
|
||||||
@@ -222,7 +224,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) {
|
||||||
@@ -406,7 +408,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);
|
||||||
@@ -533,7 +535,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;
|
||||||
@@ -560,30 +562,32 @@ 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
|
||||||
|
|||||||
@@ -26,15 +26,19 @@
|
|||||||
#ifndef PIKBDLISTENER_H
|
#ifndef PIKBDLISTENER_H
|
||||||
#define PIKBDLISTENER_H
|
#define PIKBDLISTENER_H
|
||||||
|
|
||||||
#include "pithread.h"
|
#include "pibase.h"
|
||||||
#include "pitime.h"
|
|
||||||
|
|
||||||
#define WAIT_FOR_EXIT \
|
#ifndef MICRO_PIP
|
||||||
while (!PIKbdListener::exiting) \
|
|
||||||
piMSleep(PIP_MIN_MSLEEP * 5); \
|
# include "pithread.h"
|
||||||
if (PIKbdListener::instance()) { \
|
# include "pitime.h"
|
||||||
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 {
|
||||||
@@ -231,7 +235,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;
|
||||||
@@ -251,7 +255,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;
|
||||||
@@ -305,4 +309,5 @@ 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
|
||||||
|
|||||||
@@ -18,18 +18,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "piwaitevent_p.h"
|
#include "piwaitevent_p.h"
|
||||||
#ifdef WINDOWS
|
#ifndef MICRO_PIP
|
||||||
|
# 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() {
|
||||||
@@ -39,12 +40,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) {
|
||||||
@@ -53,34 +54,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;
|
||||||
@@ -97,18 +98,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]));
|
||||||
@@ -120,34 +121,36 @@ 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
|
||||||
|
|||||||
@@ -20,7 +20,9 @@
|
|||||||
#ifndef PIWAITEVENT_P_H
|
#ifndef PIWAITEVENT_P_H
|
||||||
#define PIWAITEVENT_P_H
|
#define PIWAITEVENT_P_H
|
||||||
|
|
||||||
#include "pibase.h"
|
#ifndef MICRO_PIP
|
||||||
|
|
||||||
|
# include "pibase.h"
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
@@ -52,17 +54,18 @@ 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
|
||||||
|
|||||||
@@ -19,10 +19,12 @@
|
|||||||
|
|
||||||
#include "piintrospection_server_p.h"
|
#include "piintrospection_server_p.h"
|
||||||
|
|
||||||
#include "pichunkstream.h"
|
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
|
||||||
#include "piinit.h"
|
|
||||||
#include "piobject.h"
|
# include "pichunkstream.h"
|
||||||
#include "pisysteminfo.h"
|
# include "piinit.h"
|
||||||
|
# include "piobject.h"
|
||||||
|
# include "pisysteminfo.h"
|
||||||
|
|
||||||
|
|
||||||
const uint PIIntrospection::sign = 0x0F1C2B3A;
|
const uint PIIntrospection::sign = 0x0F1C2B3A;
|
||||||
@@ -111,9 +113,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();
|
||||||
}
|
}
|
||||||
@@ -131,9 +133,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);
|
||||||
@@ -170,3 +172,5 @@ 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)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#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:
|
||||||
@@ -168,4 +169,5 @@ 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
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#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;
|
||||||
@@ -78,3 +79,5 @@ 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)
|
||||||
|
|||||||
@@ -20,6 +20,10 @@
|
|||||||
#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"
|
||||||
|
|
||||||
@@ -68,4 +72,5 @@ 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
|
||||||
|
|||||||
@@ -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(MICRO_PIP)
|
#if !defined(WINDOWS) && !defined(MAC_OS) && !defined(PIP_NO_SOCKET)
|
||||||
# define PIP_CAN
|
# define PIP_CAN
|
||||||
#endif
|
#endif
|
||||||
#ifdef PIP_CAN
|
#ifdef PIP_CAN
|
||||||
@@ -39,25 +39,29 @@
|
|||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -164,7 +168,9 @@ int PICAN::readedCANID() const {
|
|||||||
|
|
||||||
|
|
||||||
void PICAN::interrupt() {
|
void PICAN::interrupt() {
|
||||||
|
#ifdef PIP_CAN
|
||||||
PRIVATE->event.interrupt();
|
PRIVATE->event.interrupt();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,64 +18,65 @@
|
|||||||
*/
|
*/
|
||||||
#include "piethernet.h"
|
#include "piethernet.h"
|
||||||
|
|
||||||
#include "piconfig.h"
|
#ifndef PIP_NO_SOCKET
|
||||||
#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>
|
|
||||||
# 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 <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 "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 <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
|
||||||
|
# endif
|
||||||
|
# include "piwaitevent_p.h"
|
||||||
|
|
||||||
|
# include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
/** \class PIEthernet piethernet.h
|
/** \class PIEthernet piethernet.h
|
||||||
@@ -100,11 +101,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)
|
||||||
@@ -196,11 +197,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 MICRO_PIP
|
# ifdef LWIP
|
||||||
setThreadedReadBufferSize(512);
|
setThreadedReadBufferSize(512);
|
||||||
#else
|
# else
|
||||||
setThreadedReadBufferSize(64_KiB);
|
setThreadedReadBufferSize(64_KiB);
|
||||||
#endif
|
# endif
|
||||||
// setPriority(piHigh);
|
// setPriority(piHigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,9 +305,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)) {
|
||||||
@@ -379,14 +380,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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,30 +412,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());
|
||||||
@@ -457,24 +458,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();
|
||||||
@@ -498,9 +499,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;
|
||||||
@@ -535,9 +536,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)) {
|
||||||
@@ -661,9 +662,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_;
|
||||||
@@ -678,7 +679,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) {
|
||||||
@@ -694,34 +695,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;
|
||||||
}
|
}
|
||||||
@@ -745,7 +746,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:
|
||||||
@@ -758,9 +759,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));
|
||||||
@@ -793,11 +794,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_));
|
||||||
@@ -809,9 +810,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();
|
||||||
@@ -847,11 +848,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;
|
||||||
@@ -910,30 +911,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;
|
||||||
}
|
}
|
||||||
@@ -969,7 +970,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:
|
||||||
@@ -977,7 +978,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;
|
||||||
@@ -986,12 +987,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) {
|
||||||
@@ -1008,7 +1009,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) {
|
||||||
@@ -1118,7 +1119,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));
|
||||||
@@ -1169,10 +1170,10 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pAdapterInfo) HeapFree(GetProcessHeap(), 0, pAdapterInfo);
|
if (pAdapterInfo) HeapFree(GetProcessHeap(), 0, pAdapterInfo);
|
||||||
#else
|
|
||||||
# ifdef MICRO_PIP
|
|
||||||
# else
|
# else
|
||||||
# ifdef ANDROID
|
# ifdef LWIP
|
||||||
|
# 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;
|
||||||
@@ -1200,7 +1201,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) {
|
||||||
@@ -1218,8 +1219,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;
|
||||||
@@ -1227,9 +1228,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) {
|
||||||
@@ -1240,7 +1241,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));
|
||||||
@@ -1252,8 +1253,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;
|
||||||
@@ -1274,18 +1275,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(MICRO_PIP)
|
# if defined(WINDOWS) || defined(LWIP)
|
||||||
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());
|
||||||
@@ -1294,7 +1295,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1317,16 +1318,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,
|
||||||
@@ -1343,18 +1344,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);
|
||||||
@@ -1363,29 +1364,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,
|
||||||
@@ -1399,26 +1400,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;
|
||||||
}
|
}
|
||||||
@@ -1426,11 +1427,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));
|
||||||
}
|
}
|
||||||
@@ -1438,11 +1439,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));
|
||||||
}
|
}
|
||||||
@@ -1450,12 +1451,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1471,7 +1472,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);
|
||||||
@@ -1479,10 +1480,12 @@ 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
|
||||||
|
|||||||
@@ -26,14 +26,17 @@
|
|||||||
#ifndef PIETHERNET_H
|
#ifndef PIETHERNET_H
|
||||||
#define PIETHERNET_H
|
#define PIETHERNET_H
|
||||||
|
|
||||||
|
|
||||||
#include "piiodevice.h"
|
#include "piiodevice.h"
|
||||||
#include "pinetworkaddress.h"
|
#include "pinetworkaddress.h"
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifndef PIP_NO_SOCKET
|
||||||
|
|
||||||
|
# ifdef ANDROID
|
||||||
struct
|
struct
|
||||||
#else
|
# else
|
||||||
class
|
class
|
||||||
#endif
|
# endif
|
||||||
sockaddr;
|
sockaddr;
|
||||||
|
|
||||||
class PIP_EXPORT PIEthernet: public PIIODevice {
|
class PIP_EXPORT PIEthernet: public PIIODevice {
|
||||||
@@ -439,7 +442,7 @@ public:
|
|||||||
//! \}
|
//! \}
|
||||||
//! \ioparams
|
//! \ioparams
|
||||||
//! \{
|
//! \{
|
||||||
#ifdef DOXYGEN
|
# ifdef DOXYGEN
|
||||||
//! \brief read ip, default ""
|
//! \brief read ip, default ""
|
||||||
string ip;
|
string ip;
|
||||||
|
|
||||||
@@ -460,7 +463,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:
|
||||||
@@ -509,9 +512,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();
|
||||||
@@ -536,4 +539,5 @@ 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
|
||||||
|
|||||||
@@ -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(FREERTOS)
|
#if defined(QNX) || defined(ANDROID) || defined(MICRO_PIP)
|
||||||
# define _fopen_call_ fopen
|
# define _fopen_call_ fopen
|
||||||
# define _fseek_call_ fseek
|
# define _fseek_call_ fseek
|
||||||
# define _ftell_call_ ftell
|
# define _ftell_call_ ftell
|
||||||
|
|||||||
@@ -19,38 +19,37 @@
|
|||||||
|
|
||||||
#include "piserial.h"
|
#include "piserial.h"
|
||||||
|
|
||||||
#include "piconfig.h"
|
#ifndef MICRO_PIP
|
||||||
#include "pidir.h"
|
|
||||||
#include "piincludes_p.h"
|
|
||||||
#include "pipropertystorage.h"
|
|
||||||
#include "pitime.h"
|
|
||||||
#include "pitranslator.h"
|
|
||||||
#include "piwaitevent_p.h"
|
|
||||||
|
|
||||||
#include <errno.h>
|
# include "piconfig.h"
|
||||||
|
# include "pidir.h"
|
||||||
|
# include "piincludes_p.h"
|
||||||
|
# include "pipropertystorage.h"
|
||||||
|
# include "pitime.h"
|
||||||
|
# include "pitranslator.h"
|
||||||
|
# include "piwaitevent_p.h"
|
||||||
|
|
||||||
#if defined(MICRO_PIP)
|
# include <errno.h>
|
||||||
# define PISERIAL_NO_PINS
|
|
||||||
#endif
|
# if defined(PISERIAL_NO_PINS) || defined(WINDOWS)
|
||||||
#if defined(PISERIAL_NO_PINS) || defined(WINDOWS)
|
# define TIOCM_LE 1
|
||||||
# define TIOCM_LE 1
|
# define TIOCM_DTR 4
|
||||||
# define TIOCM_DTR 4
|
# define TIOCM_RTS 7
|
||||||
# define TIOCM_RTS 7
|
# define TIOCM_CTS 8
|
||||||
# define TIOCM_CTS 8
|
# define TIOCM_ST 3
|
||||||
# define TIOCM_ST 3
|
# define TIOCM_SR 2
|
||||||
# define TIOCM_SR 2
|
# define TIOCM_CAR 1
|
||||||
# define TIOCM_CAR 1
|
# define TIOCM_RNG 9
|
||||||
# define TIOCM_RNG 9
|
# define TIOCM_DSR 6
|
||||||
# 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>
|
||||||
@@ -59,89 +58,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 B75
|
# ifndef CRTSCTS
|
||||||
# define B75 0000002
|
# define CRTSCTS 020000000000
|
||||||
# endif
|
# endif
|
||||||
# ifndef B230400
|
# ifdef LINUX
|
||||||
# define B230400 0010003
|
# include <linux/serial.h>
|
||||||
# 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
|
||||||
@@ -177,16 +176,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)
|
||||||
|
|
||||||
|
|
||||||
@@ -214,9 +213,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -347,7 +346,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();
|
||||||
@@ -363,14 +362,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,8 +379,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];
|
||||||
@@ -392,14 +391,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;
|
||||||
}
|
}
|
||||||
@@ -410,23 +409,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -441,9 +440,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;
|
||||||
@@ -463,13 +462,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -672,9 +671,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -696,7 +695,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;
|
||||||
@@ -714,7 +713,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;
|
||||||
@@ -729,12 +728,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;
|
||||||
}
|
}
|
||||||
@@ -745,28 +744,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);
|
||||||
@@ -792,7 +791,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;
|
||||||
@@ -826,12 +825,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;
|
||||||
@@ -845,9 +844,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, ×) == -1) piCoutObj << "Unable to set timeouts for \"" << path() << "\"";
|
if (SetCommTimeouts(PRIVATE->hCom, ×) == -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -866,7 +865,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;
|
||||||
@@ -896,7 +895,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;
|
||||||
@@ -911,7 +910,7 @@ ssize_t PISerial::readDevice(void * read_to, ssize_t max_size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -920,7 +919,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;
|
||||||
@@ -932,11 +931,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";
|
||||||
}
|
}
|
||||||
@@ -1061,9 +1060,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;
|
||||||
@@ -1079,7 +1078,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);
|
||||||
@@ -1147,13 +1146,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) {
|
||||||
@@ -1182,12 +1181,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"
|
||||||
@@ -1198,14 +1197,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;
|
||||||
@@ -1226,18 +1225,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) + "/";
|
||||||
@@ -1253,16 +1252,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,
|
||||||
@@ -1271,31 +1270,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;
|
||||||
@@ -1309,12 +1308,14 @@ 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
|
||||||
|
|||||||
@@ -51,8 +51,14 @@
|
|||||||
#ifdef PIP_FREERTOS
|
#ifdef PIP_FREERTOS
|
||||||
# define FREERTOS
|
# define FREERTOS
|
||||||
#endif
|
#endif
|
||||||
#if defined(FREERTOS) || defined(PLATFORMIO)
|
#ifdef MICRO_PIP
|
||||||
# define MICRO_PIP
|
# ifndef FREERTOS
|
||||||
|
# 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
|
||||||
|
|||||||
Reference in New Issue
Block a user