Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INDI Build on Windows #1922

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,76 @@ endif(INDI_BUILD_WEBSOCKET)
#
# ##################################################################################################
if(INDI_BUILD_DRIVERS)
if(WIN32 OR ANDROID)
if(ANDROID)
message(WARNING "INDI drivers are only supported under Linux, BSD, MacOS, and Cygwin while current system is " ${CMAKE_SYSTEM_NAME})
else(WIN32 OR ANDROID)
elseif(WIN32)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
find_package(CFITSIO REQUIRED)
find_package(Nova REQUIRED)
find_package(USB1 REQUIRED)
find_package(CURL REQUIRED)
find_package(GSL REQUIRED)
find_package(JPEG REQUIRED)
find_library(M_LIB m)

if(CMAKE_VERSION VERSION_LESS 3.12.0)
set(CURL ${CURL_LIBRARIES})
else()
set(CURL CURL::libcurl)
endif()

include_directories(${CFITSIO_INCLUDE_DIR})
include_directories(${NOVA_INCLUDE_DIR})
include_directories(${USB1_INCLUDE_DIRS})
include_directories(${GSL_INCLUDE_DIRS})
include_directories(${JPEG_INCLUDE_DIR})
include_directories(${ZLIB_INCLUDE_DIR})
include_directories(libs/indibase)
include_directories(libs/indibase/timer)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-usb.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-usb.h)

add_subdirectory(libs/eventloop)
add_subdirectory(libs/dsp)
add_subdirectory(libs/fpack)
add_subdirectory(libs/hid)

# #################################################
# ########## INDI Driver Library ##################
# #################################################
add_subdirectory(libs/indibase)

# #################################################
# ########## INDI Alignment Subsystem #############
# #################################################
# add_subdirectory(libs/alignment)

# #################################################
# ########## INDI Drivers #########################
# #################################################
# add_subdirectory(drivers)
install(FILES drivers.xml ${CMAKE_CURRENT_SOURCE_DIR}/drivers/focuser/indi_tcfs_sk.xml DESTINATION ${DATA_INSTALL_DIR})

# ####################################
# ########### INDI TOOLS #############
# ####################################
add_subdirectory(tools)

# ####################################
# ########### EXamples ###############
# ####################################
if(INDI_BUILD_CLIENT)
# add_subdirectory(examples)
else()
message(WARNING "Skipping build of examples since INDI POSIX client is not built")
endif()

# ################################################################################
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libindi.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libindi.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libindi.pc DESTINATION ${PKGCONFIG_INSTALL_PREFIX})

else()
# 1. Dependencies
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)
Expand Down Expand Up @@ -362,7 +429,7 @@ if(INDI_BUILD_DRIVERS)
else()
message(STATUS "GTEST not found, not building tests")
endif(GTEST_FOUND AND BUILD_TESTING)
endif(WIN32 OR ANDROID)
endif(ANDROID)
endif(INDI_BUILD_DRIVERS)

# ##################################################################################################
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ sudo apt-get install -y \
libtheora-dev
```

On Windows

Download https://github.com/msys2/msys2-installer/releases/download/2023-07-18/msys2-x86_64-20230718.exe

```
pacman -Syu # Update all of the packages
pacman -S mingw-w64-x86_64-toolchain # Install g++ toolchain
pacman -S mingw-w64-x86_64-cmake # Install Cmake
pacman -S mingw-w64-x86_64-zlib
pacman -S mingw-w64-x86_64-cfitsio
pacman -S mingw-w64-x86_64-libnova
pacman -S mingw-w64-x86_64-libusb
pacman -S mingw-w64-x86_64-fftw
pacman -S mingw-w64-x86_64-libxisf
pacman -S mingw-w64-x86_64-rtl-sdr

# Install Libev
# Download sources from http://dist.schmorp.de/libev/Attic/
pacman -S autoconf
pacman -S automake
pacman -S libtool
pacman -S make
sh autogen.sh
./configure
make
make -j4
make install
```

## XISF Support

To enable [XISF format](https://pixinsight.com/xisf/) support in INDI, you need to build or install [libxisf](https://gitea.nouspiro.space/nou/libXISF) package.
Expand Down
16 changes: 12 additions & 4 deletions indiserver/indiserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include <poll.h>
#include <unistd.h>

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/time.h>
Expand All @@ -88,10 +91,12 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/un.h>
#include <netdb.h>
#include <poll.h>
#ifdef MSG_ERRQUEUE
#include <linux/errqueue.h>
#include <linux/errqueue.h>
#endif
#endif

#include <ev++.h>
Expand Down Expand Up @@ -1091,7 +1096,9 @@ static void usage(void)
exit(2);
}

#ifdef _WIN32
/* turn off SIGPIPE on bad write so we can handle it inline */
#else
static void noSIGPIPE()
{
struct sigaction sa;
Expand All @@ -1100,6 +1107,7 @@ static void noSIGPIPE()
sigemptyset(&sa.sa_mask);
(void)sigaction(SIGPIPE, &sa, NULL);
}
#endif

/* start the given local INDI driver process.
* exit if trouble.
Expand Down
2 changes: 1 addition & 1 deletion libs/alignment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if(NOT WIN32)
SET_TARGET_PROPERTIES(AlignmentClient PROPERTIES COMPILE_FLAGS "-fPIC")
endif(NOT WIN32)

target_link_libraries(AlignmentClient indidevice indiclient)
target_link_libraries(AlignmentClient indiclient indidriver indidevice)

set_target_properties(AlignmentClient PROPERTIES OUTPUT_NAME indiAlignmentClient)
install(TARGETS AlignmentClient ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand Down
10 changes: 8 additions & 2 deletions libs/eventloop/eventloop.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if 0
/*
INDI
Copyright (C) 2003 Elwood C. Downey

Expand All @@ -16,7 +16,7 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#endif
*/

/* suite of functions to implement an event driven program.
*
Expand All @@ -40,6 +40,12 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdint.h>
#if _WIN32
#include <winsock2.h>
#else
#include <sys/select.h>
#endif

#include "eventloop.h"

Expand Down
3 changes: 3 additions & 0 deletions libs/hid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ endif()

add_executable(indi_hid_test hidtest.cpp)
target_link_libraries(indi_hid_test hid ${USB1_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${LIBS})
if(WIN32)
target_link_libraries(indi_hid_test setupapi)
endif()
install(TARGETS indi_hid_test RUNTIME DESTINATION bin)
6 changes: 5 additions & 1 deletion libs/indibase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if(LibXISF_FOUND)
endif()

# Add OggTheora, StreamManager, v4l2
if(UNIX)
if(UNIX OR WIN32)
find_package(OggTheora)

if(OGGTHEORA_FOUND)
Expand Down Expand Up @@ -219,6 +219,10 @@ set_property(TARGET ${PROJECT_NAME}_OBJECT PROPERTY POSITION_INDEPENDENT_CODE 1)

target_compile_definitions(${PROJECT_NAME}_OBJECT PRIVATE "-DHAVE_LIBNOVA")

if(WIN32)
target_link_libraries(${PROJECT_NAME}_OBJECT setupapi wsock32 ws2_32 shlwapi iphlpapi)
endif()

target_sources(${PROJECT_NAME}_OBJECT
PUBLIC
${${PROJECT_NAME}_HEADERS}
Expand Down
90 changes: 64 additions & 26 deletions libs/indibase/connectionplugins/connectionserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include <regex>
#include <random>

#ifdef _WIN32
#include <windows.h>
#endif

namespace Connection
{
extern const char *CONNECTION_TAB;
Expand Down Expand Up @@ -439,38 +443,72 @@ bool Serial::Refresh(bool silent)

// 0 Serial Only, 1 By USB-ID, 2 Bluetooth
auto searchPath = [&](std::string prefix, uint8_t searchType)
{
struct dirent **namelist;
std::vector<std::string> detectedDevices;
int devCount = 0;
if (searchType == SERIAL_DEV)
devCount = scandir(prefix.c_str(), &namelist, serial_dev_file_select, alphasort);
else if (searchType == USB_ID_DEV)
devCount = scandir(prefix.c_str(), &namelist, usb_dev_file_select, alphasort);
else
devCount = scandir(prefix.c_str(), &namelist, bluetooth_dev_file_select, alphasort);
if (devCount > 0)
{
while (devCount--)
struct dirent **namelist;
std::vector<std::string> detectedDevices;

#ifdef _WIN32
WIN32_FIND_DATAA fileInfo;
HANDLE hFind = INVALID_HANDLE_VALUE;
std::string searchPattern;

if (searchType == SERIAL_DEV)
searchPattern = prefix + "*";
else if (searchType == USB_ID_DEV)
searchPattern = prefix + "usb*";
else
searchPattern = prefix + "bluetooth*";

hFind = FindFirstFileA(searchPattern.c_str(), &fileInfo);
if (hFind != INVALID_HANDLE_VALUE)
{
if (detectedDevices.size() < 10)
do
{
std::string s(namelist[devCount]->d_name);
s.erase(s.find_last_not_of(" \n\r\t") + 1);
detectedDevices.push_back(prefix + s);
}
else
if (detectedDevices.size() < 10)
{
std::string deviceName(fileInfo.cFileName);
detectedDevices.push_back(prefix + deviceName);
}
else
{
LOGF_DEBUG("Ignoring devices over %d : %s", detectedDevices.size(),
fileInfo.cFileName);
}
} while (FindNextFileA(hFind, &fileInfo) != 0);

FindClose(hFind);
}

#else
int devCount = 0;
if (searchType == SERIAL_DEV)
devCount = scandir(prefix.c_str(), &namelist, serial_dev_file_select, alphasort);
else if (searchType == USB_ID_DEV)
devCount = scandir(prefix.c_str(), &namelist, usb_dev_file_select, alphasort);
else
devCount = scandir(prefix.c_str(), &namelist, bluetooth_dev_file_select, alphasort);
if (devCount > 0)
{
while (devCount--)
{
LOGF_DEBUG("Ignoring devices over %d : %s", detectedDevices.size(),
namelist[devCount]->d_name);
if (detectedDevices.size() < 10)
{
std::string s(namelist[devCount]->d_name);
s.erase(s.find_last_not_of(" \n\r\t") + 1);
detectedDevices.push_back(prefix + s);
}
else
{
LOGF_DEBUG("Ignoring devices over %d : %s", detectedDevices.size(),
namelist[devCount]->d_name);
}
free(namelist[devCount]);
}
free(namelist[devCount]);
free(namelist);
}
free(namelist);
}

return detectedDevices;
};
#endif
return detectedDevices;
};

#ifdef __linux__
// Search for serial, usb, and bluetooth devices.
Expand Down
24 changes: 22 additions & 2 deletions libs/indibase/connectionplugins/connectiontcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
#include "indistandardproperty.h"

#include <cerrno>
#ifdef _WIN32

#else
#include <netdb.h>
#endif
#include <cstring>
#include <unistd.h>
#include <regex>
Expand Down Expand Up @@ -190,10 +194,26 @@ bool TCP::establishConnection(const std::string &hostname, const std::string &po
return false;
}

// Set the socket receiving and sending timeouts
#ifdef _WIN32
if (setsockopt(m_SockFD, SOL_SOCKET, SO_RCVTIMEO, (const char*)&ts, sizeof(struct timeval)) < 0)
{
LOG_ERROR("Failed to set receive timeout.");
close(m_SockFD);
m_SockFD = -1;
return false;
}

if (setsockopt(m_SockFD, SOL_SOCKET, SO_SNDTIMEO, (const char*)&ts, sizeof(struct timeval)) < 0)
{
LOG_ERROR("Failed to set send timeout.");
close(m_SockFD);
m_SockFD = -1;
return false;
}
#else
setsockopt(m_SockFD, SOL_SOCKET, SO_RCVTIMEO, &ts, sizeof(struct timeval));
setsockopt(m_SockFD, SOL_SOCKET, SO_SNDTIMEO, &ts, sizeof(struct timeval));

#endif
// Connect to the device
if (::connect(m_SockFD, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
Expand Down
Loading
Loading