Support for win32

This commit is contained in:
Eswar Prakash 2023-02-28 16:21:56 +00:00
parent c33738a320
commit cea68f2fdf
13 changed files with 190 additions and 41 deletions

2
.gitignore vendored
View File

@ -10,6 +10,8 @@ x_pigpiod_if
x_pigpiod_if2
__pycache__
build
cmake-build-debug
cmake-build-release
dist
*.egg-info

8
.idea/.gitignore vendored Normal file
View File

@ -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

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml Normal file
View File

@ -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>

2
.idea/pigpio.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

21
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -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
}

10
.vscode/settings.json vendored Normal file
View File

@ -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"
}
}

View File

@ -19,26 +19,52 @@ add_library(pigpiod_if pigpiod_if.c command.c)
# libpigpiod_if2.(so|a)
add_library(pigpiod_if2 pigpiod_if2.c command.c)
if (WIN32)
target_link_libraries(pigpiod_if2 ws2_32)
endif()
# x_pigpio
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
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
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
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
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
add_executable(pig2vcd pig2vcd.c command.c)

View File

@ -16,24 +16,26 @@ find_path (RT_INCLUDE_DIR NAMES time.h
PATH_SUFFIXES
)
find_library(RT_LIBRARIES NAMES rt
PATHS
/usr
/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}
if (!WIN32)
find_library(RT_LIBRARIES NAMES rt
PATHS
/usr
/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}
)
endif()
endif()

View File

@ -35,17 +35,34 @@ For more information, please refer to <http://unlicense.org/>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <netdb.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.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 <netinet/tcp.h>
#include <sys/select.h>
#include <arpa/inet.h>
#endif
#include "pigpio.h"
#include "command.h"
@ -245,6 +262,15 @@ static int pigpioOpenSocket(const char *addrStr, const char *portStr)
hints.ai_socktype = SOCK_STREAM;
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);
if (err) return pigif_bad_getaddrinfo;

View File

@ -32,6 +32,7 @@ For more information, please refer to <http://unlicense.org/>
#define PIGPIOD_IF2_VERSION 17
/*TEXT
pigpiod_if2 is a C library for the Raspberry which allows control
@ -4376,6 +4377,10 @@ typedef enum
pigif_callback_not_found = -2010,
pigif_unconnected_pi = -2011,
pigif_too_many_pis = -2012,
#if WIN32
pigif_socket_startup = -2013
#endif
} pigifError_t;
/*DEF_E*/

57
pigs.c
View File

@ -35,10 +35,27 @@ This version is for pigpio version 69+
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/socket.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 <arpa/inet.h>
#include <sys/socket.h>
#endif
#include "pigpio.h"
#include "command.h"
@ -107,25 +124,33 @@ static int initOpts(int argc, char *argv[])
return args;
}
static int openSocket(void)
{
int sock, err;
struct addrinfo hints, *res, *rp;
const char *addrStr, *portStr;
static int openSocket(void) {
int sock, err;
struct addrinfo hints, *res, *rp;
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_socktype = SOCK_STREAM;
hints.ai_flags |= AI_CANONNAME;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
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);
@ -389,6 +414,10 @@ int main(int argc , char *argv[])
if (sock >= 0) close(sock);
#if WIN32
WSACleanup();
#endif
return status;
}