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

Have one interface per state machine #184

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
126 changes: 65 additions & 61 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,73 @@ project(RocketCode2020 C CXX)
cmake_host_system_information(RESULT _memfree QUERY AVAILABLE_PHYSICAL_MEMORY)
set_property(GLOBAL PROPERTY JOB_POOLS four_jobs=4)
if (_memfree LESS 1000)
set(CMAKE_JOB_POOL_COMPILE four_jobs)
endif()
set(CMAKE_JOB_POOL_COMPILE four_jobs)
endif ()

add_subdirectory(./libraries)

if (DEFINED ENV{DESKTOP_COMPAT} OR DESKTOP_COMPAT)
add_compile_definitions(DESKTOP_COMPAT=$ENV{DESKTOP_COMPAT})
endif ()

if (DEFINED ENV{HOTFIRE_TEST} OR HOTFIRE_TEST)
add_compile_definitions(HOTFIRE_TEST=$ENV{HOTFIRE_TEST})
endif()
add_compile_definitions(HOTFIRE_TEST=$ENV{HOTFIRE_TEST})
endif ()

if (DEFINED ENV{USE_LOGGER} OR USE_LOGGER)
add_compile_definitions(USE_LOGGER=$ENV{USE_LOGGER})
endif()
add_compile_definitions(USE_LOGGER=$ENV{USE_LOGGER})
endif ()

if (DEFINED ENV{USE_SOCKET_CLIENT} OR USE_SOCKET_CLIENT)
add_compile_definitions(USE_SOCKET_CLIENT=$ENV{USE_SOCKET_CLIENT})
endif()
add_compile_definitions(USE_SOCKET_CLIENT=$ENV{USE_SOCKET_CLIENT})
endif ()

if (DEFINED ENV{USE_INPUT} OR USE_INPUT)
add_compile_definitions(USE_INPUT=$ENV{USE_INPUT})
endif()
add_compile_definitions(USE_INPUT=$ENV{USE_INPUT})
endif ()

if (DEFINED ENV{SKIP_INIT} OR SKIP_INIT)
add_compile_definitions(SKIP_INIT=$ENV{SKIP_INIT})
endif()
add_compile_definitions(SKIP_INIT=$ENV{SKIP_INIT})
endif ()

if (DEFINED ENV{TESTING} OR TESTING)
add_compile_definitions(TESTING=$ENV{TESTING})
endif()
add_compile_definitions(TESTING=$ENV{TESTING})
endif ()

# Sensors

if (DEFINED ENV{USE_SBG} OR USE_SBG)
add_compile_definitions(USE_SBG=$ENV{USE_SBG})
endif()
add_compile_definitions(USE_SBG=$ENV{USE_SBG})
endif ()

if (DEFINED ENV{USE_RADIO} OR USE_RADIO)
add_compile_definitions(USE_RADIO=$ENV{USE_RADIO})
endif()
add_compile_definitions(USE_RADIO=$ENV{USE_RADIO})
endif ()

if (DEFINED ENV{USE_WIRING_Pi} OR USE_WIRING_Pi)
add_compile_definitions(USE_WIRING_Pi=$ENV{USE_WIRING_Pi})
endif()
add_compile_definitions(USE_WIRING_Pi=$ENV{USE_WIRING_Pi})
endif ()

if (DEFINED ENV{USE_GPIO} OR USE_GPIO)
add_compile_definitions(USE_GPIO=$ENV{USE_GPIO})
endif()
add_compile_definitions(USE_GPIO=$ENV{USE_GPIO})
endif ()

if (DEFINED ENV{USE_ARDUINO_PROXY} OR USE_ARDUINO_PROXY)
add_compile_definitions(USE_ARDUINO_PROXY=$ENV{USE_ARDUINO_PROXY})
endif()
add_compile_definitions(USE_ARDUINO_PROXY=$ENV{USE_ARDUINO_PROXY})
endif ()

# ---------------
# Main executable
# ---------------
find_package (Threads)
find_package(Threads)

if (DEFINED ENV{SERVO_CONTROL} OR SERVO_CONTROL)
file(GLOB_RECURSE MAIN_CONFIG_SRC ${PROJECT_SOURCE_DIR}/projects/ServoControl/*.cpp)
file(GLOB_RECURSE MAIN_CONFIG_SRC ${PROJECT_SOURCE_DIR}/projects/ServoControl/*.cpp)
elseif (DEFINED ENV{HOTFIRE_TEST} OR HOTFIRE_TEST)
file(GLOB_RECURSE MAIN_CONFIG_SRC ${PROJECT_SOURCE_DIR}/projects/HotFire/*.cpp)
else()
file(GLOB_RECURSE MAIN_CONFIG_SRC ${PROJECT_SOURCE_DIR}/projects/OctoberSky1/*.cpp)
endif()
file(GLOB_RECURSE MAIN_CONFIG_SRC ${PROJECT_SOURCE_DIR}/projects/HotFire/*.cpp)
else ()
file(GLOB_RECURSE MAIN_CONFIG_SRC ${PROJECT_SOURCE_DIR}/projects/OctoberSky1/*.cpp)
endif ()

file(GLOB_RECURSE SRC_MAIN ${PROJECT_SOURCE_DIR}/src/*.cpp)

Expand All @@ -78,43 +82,43 @@ target_include_directories(MainLoopLib PUBLIC ./src/)
target_precompile_headers(MainLoopLib PUBLIC ${PROJECT_SOURCE_DIR}/src/common/pch.h)

if (DEFINED ENV{SERVO_CONTROL} OR SERVO_CONTROL)
target_include_directories(MainLoopLib PUBLIC
./projects/ServoControl/
)
target_include_directories(MainLoopLib PUBLIC
./projects/HotFire/
)
target_include_directories(MainLoopLib PUBLIC
./projects/ServoControl/
)
target_include_directories(MainLoopLib PUBLIC
./projects/HotFire/
)
elseif (DEFINED ENV{HOTFIRE_TEST} OR HOTFIRE_TEST)
target_include_directories(MainLoopLib PUBLIC
./projects/HotFire/
)
else()
target_include_directories(MainLoopLib PUBLIC
./projects/OctoberSky1/
)
endif()
target_include_directories(MainLoopLib PUBLIC
./projects/HotFire/
)
else ()
target_include_directories(MainLoopLib PUBLIC
./projects/OctoberSky1/
)
endif ()

target_link_libraries(MainLoopLib sbgECom)
add_dependencies(MainLoopLib sbgECom)

target_link_libraries(MainLoopLib WiringPi)
add_dependencies(MainLoopLib WiringPi)

if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")

target_include_directories(MainLoopLib PUBLIC "$ENV{BOOST_DIRECTORY}")
target_link_directories(MainLoopLib PUBLIC "$ENV{BOOST_DIRECTORY}/stage/lib")
target_link_libraries(MainLoopLib boost_filesystem boost_system)
target_include_directories(MainLoopLib PUBLIC "$ENV{LIBI2C_DIRECTORY}/include")
target_link_directories(MainLoopLib PUBLIC "$ENV{LIBI2C_DIRECTORY}/lib")
else()
target_link_libraries(MainLoopLib systemd)
find_package(Boost 1.65.1 COMPONENTS system filesystem REQUIRED)
target_include_directories(MainLoopLib PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(MainLoopLib ${Boost_LIBRARIES})
endif()
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")

target_include_directories(MainLoopLib PUBLIC "$ENV{BOOST_DIRECTORY}")
target_link_directories(MainLoopLib PUBLIC "$ENV{BOOST_DIRECTORY}/stage/lib")
target_link_libraries(MainLoopLib boost_filesystem boost_system)

target_include_directories(MainLoopLib PUBLIC "$ENV{LIBI2C_DIRECTORY}/include")
target_link_directories(MainLoopLib PUBLIC "$ENV{LIBI2C_DIRECTORY}/lib")

else ()
target_link_libraries(MainLoopLib systemd)
find_package(Boost 1.65.1 COMPONENTS system filesystem REQUIRED)
target_include_directories(MainLoopLib PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(MainLoopLib ${Boost_LIBRARIES})
endif ()

target_link_libraries(MainLoopLib i2c)

Expand All @@ -124,9 +128,9 @@ target_link_libraries(MainLoopLib protobufDef)

target_link_libraries(MainLoopLib cobs-c)

target_link_libraries (MainLoopLib ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(MainLoopLib ${CMAKE_THREAD_LIBS_INIT})

target_link_libraries (MainLoopLib i2c)
target_link_libraries(MainLoopLib i2c)
add_executable(MainLoop ./src/init/MainLoop.cpp)
target_link_libraries(MainLoop MainLoopLib)

Expand Down
9 changes: 9 additions & 0 deletions projects/HotFire/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// clang-format off

#define STATEMACHINE HotFireStateMachine
#define INTERFACE HotFireInterface

#ifndef USE_SBG
#define USE_SBG 0
Expand Down Expand Up @@ -57,4 +58,12 @@
#define USE_SENSOR_MAX_31865 1
#endif

// TODO: Remove this when USE_WIRING_Pi is eventually removed
#if DESKTOP_COMPAT == 1
#ifdef USE_WIRING_Pi
#undef USE_WIRING_Pi
#endif
#define USE_WIRING_Pi 0
#endif

// clang-format on
1 change: 1 addition & 0 deletions projects/OctoberSky1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// clang-format off

#define STATEMACHINE OctoberSkyStateMachine
#define INTERFACE OctoberSkyInterface

#ifndef TESTING
#define TESTING 0
Expand Down
4 changes: 0 additions & 4 deletions src/IO/ArduinoProxy.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "ArduinoProxy.h"

#if USE_ARDUINO_PROXY == 1

#include "IO/ArduinoEncoder.h"
#include <spdlog/spdlog.h>
#include <sys/poll.h>
Expand Down Expand Up @@ -173,5 +171,3 @@ int ArduinoProxy::getServoState(int pin)
return state.first;
}
}

#endif
4 changes: 0 additions & 4 deletions src/IO/ArduinoProxy.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once
#include "config.h"

#if USE_ARDUINO_PROXY == 1

#include "IO.h"
#include <ArduinoComm.pb.h>
#include <wiringSerial.h>
Expand Down Expand Up @@ -39,5 +37,3 @@ class ArduinoProxy : IO

void handleArduinoMessage(const RocketryProto::ArduinoOut &arduinoOut);
};

#endif
3 changes: 0 additions & 3 deletions src/IO/Input.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#if USE_INPUT == 1

#include "EventQueue.h"
#include "IO.h"
Expand All @@ -23,5 +22,3 @@ class Input : IO

static bool isNumber(const std::string &s);
};

#endif
Loading