mirror of https://github.com/joan2937/pigpio
Support for win32
This commit is contained in:
parent
c33738a320
commit
cea68f2fdf
|
@ -10,6 +10,8 @@ x_pigpiod_if
|
||||||
x_pigpiod_if2
|
x_pigpiod_if2
|
||||||
__pycache__
|
__pycache__
|
||||||
build
|
build
|
||||||
|
cmake-build-debug
|
||||||
|
cmake-build-release
|
||||||
dist
|
dist
|
||||||
*.egg-info
|
*.egg-info
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/pigpio.iml" filepath="$PROJECT_DIR$/.idea/pigpio.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Win32",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"defines": [
|
||||||
|
"_DEBUG",
|
||||||
|
"UNICODE",
|
||||||
|
"_UNICODE"
|
||||||
|
],
|
||||||
|
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
|
||||||
|
"cStandard": "c17",
|
||||||
|
"cppStandard": "gnu++14",
|
||||||
|
"intelliSenseMode": "${default}",
|
||||||
|
"configurationProvider": "ms-vscode.cmake-tools"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"makefile.makePath": "mingw32-make",
|
||||||
|
"cmake.cmakePath": "cmake",
|
||||||
|
"files.associations": {
|
||||||
|
"stdlib.h": "c",
|
||||||
|
"types.h": "c",
|
||||||
|
"unistd.h": "c",
|
||||||
|
"pigpiod_if2.h": "c"
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,26 +19,52 @@ add_library(pigpiod_if pigpiod_if.c command.c)
|
||||||
|
|
||||||
# libpigpiod_if2.(so|a)
|
# libpigpiod_if2.(so|a)
|
||||||
add_library(pigpiod_if2 pigpiod_if2.c command.c)
|
add_library(pigpiod_if2 pigpiod_if2.c command.c)
|
||||||
|
if (WIN32)
|
||||||
|
target_link_libraries(pigpiod_if2 ws2_32)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# x_pigpio
|
# x_pigpio
|
||||||
add_executable(x_pigpio x_pigpio.c)
|
add_executable(x_pigpio x_pigpio.c)
|
||||||
target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads)
|
if (!WIN32)
|
||||||
|
target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads)
|
||||||
|
else()
|
||||||
|
target_link_libraries(x_pigpio pigpio Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
# x_pigpiod_if
|
# x_pigpiod_if
|
||||||
add_executable(x_pigpiod_if x_pigpiod_if.c)
|
add_executable(x_pigpiod_if x_pigpiod_if.c)
|
||||||
target_link_libraries(x_pigpiod_if pigpiod_if RT::RT Threads::Threads)
|
if (WIN32)
|
||||||
|
target_link_libraries(x_pigpiod_if pigpiod_if Threads::Threads)
|
||||||
|
else()
|
||||||
|
target_link_libraries(x_pigpiod_if pigpiod_if RT::RT Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# x_pigpiod_if2
|
# x_pigpiod_if2
|
||||||
add_executable(x_pigpiod_if2 x_pigpiod_if2.c)
|
add_executable(x_pigpiod_if2 x_pigpiod_if2.c)
|
||||||
target_link_libraries(x_pigpiod_if2 pigpiod_if2 RT::RT Threads::Threads)
|
if (WIN32)
|
||||||
|
target_link_libraries(x_pigpiod_if2 pigpiod_if2 Threads::Threads)
|
||||||
|
else()
|
||||||
|
target_link_libraries(x_pigpiod_if2 pigpiod_if2 RT::RT Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
# pigpiod
|
# pigpiod
|
||||||
add_executable(pigpiod pigpiod.c)
|
add_executable(pigpiod pigpiod.c)
|
||||||
target_link_libraries(pigpiod pigpio RT::RT Threads::Threads)
|
if (WIN32)
|
||||||
|
target_link_libraries(pigpiod pigpio Threads::Threads)
|
||||||
|
else()
|
||||||
|
target_link_libraries(pigpiod pigpio RT::RT Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
# pigs
|
# pigs
|
||||||
add_executable(pigs pigs.c command.c)
|
add_executable(pigs pigs.c command.c)
|
||||||
target_link_libraries(pigs Threads::Threads)
|
if (WIN32)
|
||||||
|
target_link_libraries(pigs Threads::Threads ws2_32)
|
||||||
|
else()
|
||||||
|
target_link_libraries(pigs Threads::Threads)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# pig2vcd
|
# pig2vcd
|
||||||
add_executable(pig2vcd pig2vcd.c command.c)
|
add_executable(pig2vcd pig2vcd.c command.c)
|
||||||
|
|
|
@ -16,24 +16,26 @@ find_path (RT_INCLUDE_DIR NAMES time.h
|
||||||
PATH_SUFFIXES
|
PATH_SUFFIXES
|
||||||
)
|
)
|
||||||
|
|
||||||
find_library(RT_LIBRARIES NAMES rt
|
if (!WIN32)
|
||||||
PATHS
|
find_library(RT_LIBRARIES NAMES rt
|
||||||
/usr
|
PATHS
|
||||||
/usr/local
|
/usr
|
||||||
/opt
|
/usr/local
|
||||||
)
|
/opt
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
|
|
||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(rt DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR)
|
|
||||||
|
|
||||||
mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES)
|
|
||||||
|
|
||||||
if (NOT TARGET RT::RT)
|
|
||||||
add_library(RT::RT INTERFACE IMPORTED)
|
|
||||||
|
|
||||||
set_target_properties(RT::RT PROPERTIES
|
|
||||||
INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR}
|
|
||||||
INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(RT DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR)
|
||||||
|
|
||||||
|
mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES)
|
||||||
|
|
||||||
|
if (NOT TARGET RT::RT)
|
||||||
|
add_library(RT::RT INTERFACE IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(RT::RT PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR}
|
||||||
|
INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
|
@ -35,17 +35,34 @@ For more information, please refer to <http://unlicense.org/>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <netdb.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
#include <winsock.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <ws2def.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
#define MSG_WAITALL 0x8
|
||||||
|
|
||||||
|
#undef WINVER
|
||||||
|
#undef _WIN32_WINNT
|
||||||
|
|
||||||
|
#define WINVER 0x0A00
|
||||||
|
#define _WIN32_WINNT 0x0A00
|
||||||
|
|
||||||
|
#else
|
||||||
|
#include <netdb.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "pigpio.h"
|
#include "pigpio.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
@ -245,6 +262,15 @@ static int pigpioOpenSocket(const char *addrStr, const char *portStr)
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_flags |= AI_CANONNAME;
|
hints.ai_flags |= AI_CANONNAME;
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
WORD wsVersionRequested = MAKEWORD(2, 2);
|
||||||
|
WSADATA wsaData;
|
||||||
|
|
||||||
|
err = WSAStartup(wsVersionRequested, &wsaData);
|
||||||
|
if (err) return pigif_socket_startup;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
err = getaddrinfo (addrStr, portStr, &hints, &res);
|
err = getaddrinfo (addrStr, portStr, &hints, &res);
|
||||||
|
|
||||||
if (err) return pigif_bad_getaddrinfo;
|
if (err) return pigif_bad_getaddrinfo;
|
||||||
|
|
|
@ -32,6 +32,7 @@ For more information, please refer to <http://unlicense.org/>
|
||||||
|
|
||||||
#define PIGPIOD_IF2_VERSION 17
|
#define PIGPIOD_IF2_VERSION 17
|
||||||
|
|
||||||
|
|
||||||
/*TEXT
|
/*TEXT
|
||||||
|
|
||||||
pigpiod_if2 is a C library for the Raspberry which allows control
|
pigpiod_if2 is a C library for the Raspberry which allows control
|
||||||
|
@ -4376,6 +4377,10 @@ typedef enum
|
||||||
pigif_callback_not_found = -2010,
|
pigif_callback_not_found = -2010,
|
||||||
pigif_unconnected_pi = -2011,
|
pigif_unconnected_pi = -2011,
|
||||||
pigif_too_many_pis = -2012,
|
pigif_too_many_pis = -2012,
|
||||||
|
#if WIN32
|
||||||
|
pigif_socket_startup = -2013
|
||||||
|
#endif
|
||||||
|
|
||||||
} pigifError_t;
|
} pigifError_t;
|
||||||
|
|
||||||
/*DEF_E*/
|
/*DEF_E*/
|
||||||
|
|
57
pigs.c
57
pigs.c
|
@ -35,10 +35,27 @@ This version is for pigpio version 69+
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
#include <winsock.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <ws2def.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
|
#define MSG_WAITALL 0x8
|
||||||
|
|
||||||
|
#undef WINVER
|
||||||
|
#undef _WIN32_WINNT
|
||||||
|
|
||||||
|
#define WINVER 0x0A00
|
||||||
|
#define _WIN32_WINNT 0x0A00
|
||||||
|
|
||||||
|
#else
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "pigpio.h"
|
#include "pigpio.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
@ -107,25 +124,33 @@ static int initOpts(int argc, char *argv[])
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int openSocket(void)
|
static int openSocket(void) {
|
||||||
{
|
int sock, err;
|
||||||
int sock, err;
|
struct addrinfo hints, *res, *rp;
|
||||||
struct addrinfo hints, *res, *rp;
|
const char *addrStr, *portStr;
|
||||||
const char *addrStr, *portStr;
|
|
||||||
|
|
||||||
portStr = getenv(PI_ENVPORT);
|
portStr = getenv(PI_ENVPORT);
|
||||||
|
|
||||||
if (!portStr) portStr = PI_DEFAULT_SOCKET_PORT_STR;
|
if (!portStr) portStr = PI_DEFAULT_SOCKET_PORT_STR;
|
||||||
|
|
||||||
addrStr = getenv(PI_ENVADDR);
|
addrStr = getenv(PI_ENVADDR);
|
||||||
|
|
||||||
if (!addrStr) addrStr = PI_DEFAULT_SOCKET_ADDR_STR;
|
if (!addrStr) addrStr = PI_DEFAULT_SOCKET_ADDR_STR;
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
|
||||||
hints.ai_family = PF_UNSPEC;
|
hints.ai_family = PF_UNSPEC;
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
hints.ai_flags |= AI_CANONNAME;
|
hints.ai_flags |= AI_CANONNAME;
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
WORD wsVersionRequested = MAKEWORD(2, 2);
|
||||||
|
WSADATA wsaData;
|
||||||
|
|
||||||
|
err = WSAStartup(wsVersionRequested, &wsaData);
|
||||||
|
if (err) return SOCKET_OPEN_FAILED;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
err = getaddrinfo(addrStr, portStr, &hints, &res);
|
err = getaddrinfo(addrStr, portStr, &hints, &res);
|
||||||
|
|
||||||
|
@ -389,6 +414,10 @@ int main(int argc , char *argv[])
|
||||||
|
|
||||||
if (sock >= 0) close(sock);
|
if (sock >= 0) close(sock);
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue