Skip to content
Open
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
176 changes: 176 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
cmake_minimum_required(VERSION 2.8)
project(openpixelprotocol)

# We use a newer version of FindGLUT that findws windows DLLs
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if (WIN32)
set(GLUT_DIR "" CACHE PATH "Path to the directory where the GLUT binaries can be found, glut32.lib, glut32.dll, glut.h" )
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(LINUX 1)
endif()

option(WITH_DUMMY_CLIENT "Compile the Dummy client" ON)
option(WITH_DUMMY_SERVER "Compile the Dummy server" ON)
option(WITH_GL_SERVER "GL Server (Requires GLUT)" ON)

if (LINUX)
option(WITH_TCL_SERVER "Compile TCL server" ON)
option(WITH_APA102_SERVER "Compile APA102 server" ON)
option(WITH_WS2801_SERVER "Compile WS2801 server" ON)
option(WITH_LPD8806_SERVER "Compile LPD8806 server" ON)
endif()

# Set some nicer output dirs.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

if (MSVC)
add_definitions("/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /nologo")
set(CMAKE_EXE_LINKER_FLAGS "/SAFESEH:NO")
endif()

if (APPLE)
set(CMAKE_C_FLAGS "-Wdeprecated-declarations")
endif()

if (WITH_DUMMY_CLIENT)
set(DUMMY_CLIENT_SRCS
${PROJECT_SOURCE_DIR}/src/dummy_client.c
${PROJECT_SOURCE_DIR}/src/opc_client.c)

set(DUMMY_CLIENT_HDRS
${PROJECT_SOURCE_DIR}/src/types.h
${PROJECT_SOURCE_DIR}/src/opc.h
${PROJECT_SOURCE_DIR}/src/compat.h)

source_group("Headers" FILES ${DUMMY_CLIENT_HDRS})
source_group("Sources" FILES ${DUMMY_CLIENT_SRCS})

add_executable(dummy_client ${DUMMY_CLIENT_SRCS} ${DUMMY_CLIENT_HDRS})

if (WIN32)
target_link_libraries(dummy_client ws2_32.lib)
endif()
endif()

if (WITH_DUMMY_SERVER)
set(DUMMY_SERVER_SRCS
${PROJECT_SOURCE_DIR}/src/dummy_server.c
${PROJECT_SOURCE_DIR}/src/opc_server.c)

set(DUMMY_SERVER_HDRS
${PROJECT_SOURCE_DIR}/src/types.h
${PROJECT_SOURCE_DIR}/src/opc.h)

source_group("Headers" FILES ${DUMMY_SERVER_HDRS})
source_group("Sources" FILES ${DUMMY_SERVER_SRCS})

add_executable(dummy_server ${DUMMY_SERVER_SRCS} ${DUMMY_SERVER_HDRS})

if (WIN32)
target_link_libraries(dummy_server ws2_32.lib)
endif()
endif()

if (WITH_GL_SERVER)
set(GL_SERVER_SRCS
${PROJECT_SOURCE_DIR}/src/gl_server.c
${PROJECT_SOURCE_DIR}/src/opc_server.c
${PROJECT_SOURCE_DIR}/src/cJSON.c)

set(GL_SERVER_HDRS
${PROJECT_SOURCE_DIR}/src/cJSON.h
${PROJECT_SOURCE_DIR}/src/types.h
${PROJECT_SOURCE_DIR}/src/opc.h
${PROJECT_SOURCE_DIR}/src/win32/getopt.h
${PROJECT_SOURCE_DIR}/src/compat.h)

source_group("Headers" FILES ${GL_SERVER_HDRS})
source_group("Sources" FILES ${GL_SERVER_SRCS})

if (WIN32 AND GLUT_DIR)
set(GLUT_FOUND ON)
set(GLUT_INCLUDE_DIRS "${GLUT_DIR}")
set(GLUT_LIBRARIES "${GLUT_DIR}/glut32.lib")
set(GLUT_RUNTIME_LIBRARY_DIRS "${GLUT_DIR}")
set(GLUT_RUNTIME_LIBRARY "${GLUT_DIR}/glut32.dll")
else()
find_package(GLUT)

if (NOT GLUT_FOUND)
if (WIN32)
message(FATAL_ERROR "Set cmake -DGLUT_DIR=<path>. Run 'cmake -LH .' for details")
else()
message(FATAL_ERROR "GLUT is required, please install it")
endif()
endif()
endif()

add_executable(glserver ${GL_SERVER_SRCS} ${GL_SERVER_HDRS})
target_link_libraries(glserver ${GLUT_LIBRARIES})
message("GLUT Include dir: ${GLUT_INCLUDE_DIRS}")
include_directories("${GLUT_INCLUDE_DIRS}")

if (WIN32)
target_link_libraries(glserver ws2_32.lib)

# Copy GLUT DLL to binary dir.
add_custom_command(TARGET glserver POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${GLUT_RUNTIME_LIBRARY}
$<TARGET_FILE_DIR:glserver>)
endif()

if (LINUX)
target_link_libraries(glserver m)
endif()
endif()

if (LINUX)
set(SERVER_LIST "")

set(SERVER_COMMON_SRCS
"${PROJECT_SOURCE_DIR}/src/opc_server.c"
"${PROJECT_SOURCE_DIR}/src/spi.c"
"${PROJECT_SOURCE_DIR}/src/cli.c")

set(SERVER_COMMON_HDRS
"${PROJECT_SOURCE_DIR}/src/spi.h"
"${PROJECT_SOURCE_DIR}/src/opc.h"
"${PROJECT_SOURCE_DIR}/src/types.h"
"${PROJECT_SOURCE_DIR}/src/cli.h"
)

source_group("Headers" FILES ${SERVER_COMMON_HDRS})

if (WITH_TCL_SERVER)
list(APPEND SERVER_LIST "tcl_server")
endif()

if (WITH_APA102_SERVER)
list(APPEND SERVER_LIST "apa102_server")
endif()

if (WITH_WS2801_SERVER)
list(APPEND SERVER_LIST "ws2801_server")
endif()

if (WITH_LPD8806_SERVER)
list(APPEND SERVER_LIST "lpd8806_server")
endif()

foreach (SERVER ${SERVER_LIST})
set(SRCS
"${PROJECT_SOURCE_DIR}/src/${SERVER}.c"
${SERVER_COMMON_SRCS})

source_group("Sources" FILES ${SRCS})

add_executable(${SERVER} ${SRCS} ${HDRS})
target_link_libraries(${SERVER} m)
endforeach()
endif()
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ repository includes these programs:
To build these programs, run "make" and then look in the bin/ directory.


Quickstart (simulator)
----------------------
Quickstart (simulator on Linux/OSX)
-----------------------------------

**Step 1.** If you're using Linux, first get the dependencies you need
(Mac users skip to step 2):
(**OSX users skip to step 2**):

apt-get install mesa-common-dev freeglut3-dev

Expand All @@ -50,6 +50,38 @@ Quickstart (simulator)
python/raver_plaid.py


Quickstart (simulator on Windows)
---------------------------------

Install CMake: https://cmake.org/
Install Visual Studio: https://www.visualstudio.com/

NOTE! Assuming use of **git bash** below, but normal **cmd.exe** works as well.

**Step 1.** Download and unpack GLUT in a known path (For example `c:\glut\`):

https://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
Or google for "glut windows" if above URL is out of date. You want `glut32.lib`, `glut32.dll` and `glut.h`.

**Step 2.** Generate the CMake project, specify the **full absolute path** to the directory were you unpacked GLUT:

mkdir build
cd build
cmake -DGLUT_DIR=c:/glut/ .. # NOTE that you should use / not \ for the paths!

**Step 3.** Open the Visual Studio Solution and build:

start openpixelcontrol.sln

**Step 4.** After compiling you can run it in the terminal window (assuming default build type Debug):

bin/Debug/gl_server.exe -l ../layout/freespace.json

**Step 6.** In another terminal window, send colors to the simulator:

python/raver_plaid.py


Quickstart (Beaglebone)
-----------------------

Expand Down
132 changes: 132 additions & 0 deletions cmake/FindGLUT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# - try to find glut library and include files
# GLUT_INCLUDE_DIRS, where to find GL/glut.h, etc.
# GLUT_LIBRARIES, the libraries to link against
# GLUT_FOUND, If false, do not try to use GLUT.
# GLUT_RUNTIME_LIBRARY_DIRS, path to DLL on Windows for runtime use.
# GLUT_RUNTIME_LIBRARY, dll on Windows, for installation purposes
#
# Also defined, but not for general use are:
# GLUT_INCLUDE_DIR, where to find GL/glut.h, etc.
# GLUT_glut_LIBRARY = the full path to the glut library.

#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
# Copyright 2009-2010 Iowa State University
# (Author: Ryan Pavlik <abiryan@ryand.net> )
#
# Distributed under the OSI-approved BSD License (the "License");
# see below.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

if(GLUT_FIND_QUIETLY)
find_package(OpenGL QUIET)
else()
find_package(OpenGL)
endif()

if(OPENGL_FOUND)
get_filename_component(_ogl_libdir ${OPENGL_gl_LIBRARY} PATH)
find_path(GLUT_INCLUDE_DIR
NAMES
GL/glut.h
GLUT/glut.h
glut.h
PATHS
${_ogl_libdir}/../include
${GLUT_ROOT_PATH}
${GLUT_ROOT_PATH}/include
/usr/include/GL
/usr/openwin/share/include
/usr/openwin/include
/opt/graphics/OpenGL/include
/opt/graphics/OpenGL/contrib/libglut)

find_library(GLUT_glut_LIBRARY
NAMES
glut
glut32
GLUT
freeglut
PATHS
${_ogl_libdir}
${GLUT_ROOT_PATH}
${GLUT_ROOT_PATH}/Release
/usr/openwin/lib)

endif()

# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLUT
DEFAULT_MSG
GLUT_glut_LIBRARY
GLUT_INCLUDE_DIR
OPENGL_FOUND)

if(GLUT_FOUND)
set(GLUT_LIBRARIES ${GLUT_glut_LIBRARY} ${OPENGL_LIBRARIES})
set(GLUT_INCLUDE_DIRS ${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})

if(WIN32)
get_filename_component(_basename "${GLUT_glut_LIBRARY}" NAME_WE)
get_filename_component(_libpath "${GLUT_glut_LIBRARY}" PATH)
find_path(GLUT_RUNTIME_LIBRARY
NAMES
${_basename}.dll
glut.dll
glut32.dll
freeglut.dll
HINTS
${_libpath}
${_libpath}/../bin)
if(GLUT_RUNTIME_LIBRARY)
get_filename_component(GLUT_RUNTIME_LIBRARY_DIRS
"${GLUT_RUNTIME_LIBRARY}"
PATH)
else()
set(GLUT_RUNTIME_LIBRARY_DIRS)
endif()
endif()

#The following deprecated settings are for backwards compatibility with CMake1.4
set(GLUT_LIBRARY ${GLUT_LIBRARIES})
set(GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR})
endif()

mark_as_advanced(GLUT_INCLUDE_DIR
GLUT_glut_LIBRARY
GLUT_RUNTIME_LIBRARY)
29 changes: 29 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright 2016 Ka-Ping Yee

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. */

#ifndef __COMPAT_H__
#define __COMPAT_H__

#ifdef _WIN32
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
#define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)

#include <BaseTsd.h>
typedef SSIZE_T ssize_t;

typedef SOCKET sock_t;
#else
typedef int sock_t;
#define SOCKET_ERROR 0xFFFFFFFF
#define INVALID_SOCKET 0xFFFFFFFF
#endif

#endif // __COMPAT_H__
Loading