diff --git a/FlippR-Driver/CMakeLists.txt b/FlippR-Driver/CMakeLists.txt index b6697f2..eb8d8f3 100644 --- a/FlippR-Driver/CMakeLists.txt +++ b/FlippR-Driver/CMakeLists.txt @@ -12,9 +12,10 @@ set(DEFAULT_BUILD_TYPE DEBUG) set(CMAKE_CXX_STANDARD 14) -# Boost configuration -set(BOOST_COMPONENTS program_options thread timer chrono) - +IF(NOT_PI) + add_definitions(-DNOT_PI) + message("Compiling not for Pi") +ENDIF() project(FlippR-Driver) @@ -69,10 +70,13 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/${LIB_DIR}) ######################### BOOST ######################### +# Boost configuration +set(BOOST_COMPONENTS program_options thread timer chrono) find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) if(Boost_FOUND) # Include and link with boost target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS}) + LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) target_link_libraries(${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES}) message ("Boost found and linked.") else() @@ -85,9 +89,9 @@ if(NOT wiringPi_LIB) message(WARNING "Could not find wiringPi library, used testing wiring pi lib instead.") add_definitions(-DNO_WIRING_PI) else() - message (STATUS "Found wiring pi.") + message(STATUS "Found wiring pi.") + target_link_libraries(${PROJECT_NAME} PUBLIC ${wiringPi_LIB}) endif() -target_link_libraries(${PROJECT_NAME} PUBLIC ${wiringPi_LIB}) find_library(crypt_LIB crypt) if(NOT crypt_LIB) diff --git a/FlippR-Driver/contrib/json_example/output/Lamp_Config.json b/FlippR-Driver/contrib/json_example/output/Lamp_Config.json index d978a8c..ff6b418 100644 --- a/FlippR-Driver/contrib/json_example/output/Lamp_Config.json +++ b/FlippR-Driver/contrib/json_example/output/Lamp_Config.json @@ -3,8 +3,8 @@ [ { "name" : "extender_1", - "i2c_address" : 33, - "pin_base" : 82 + "i2c_address" : 32, + "pin_base" : 97 } ], "lamps" : diff --git a/FlippR-Driver/contrib/json_example/output/Sound_Config.json b/FlippR-Driver/contrib/json_example/output/Sound_Config.json index 67b236c..14765f7 100644 --- a/FlippR-Driver/contrib/json_example/output/Sound_Config.json +++ b/FlippR-Driver/contrib/json_example/output/Sound_Config.json @@ -4,7 +4,7 @@ [ { "name" : "extender_0", - "i2c_address" : 33, + "i2c_address" : 34, "pin_base" : 81 } ], @@ -17,332 +17,332 @@ [ { "id" : 0, - "address" : "22", - "description" : "Sound 1", + "address" : 22, + "name" : "Sound 1", "extender" : "extender_0" }, { "id" : 1, - "address" : "23", - "description" : "Sound 2", + "address" : 23, + "name" : "Sound 2", "extender" : "extender_0" }, { "id" : 2, - "address" : "24", - "description" : "Sound 3", + "address" : 24, + "name" : "Sound 3", "extender" : "extender_0" }, { "id" : 3, - "address" : "25", - "description" : "Sound 4", + "address" : 25, + "name" : "Sound 4", "extender" : "extender_0" }, { "id" : 4, - "address" : "26", - "description" : "Sound 5", + "address" : 26, + "name" : "Sound 5", "extender" : "extender_0" }, { "id" : 5, - "address" : "27", - "description" : "Sound 6", + "address" : 27, + "name" : "Sound 6", "extender" : "extender_0" }, { "id" : 6, - "address" : "28", - "description" : "Sound 7", + "address" : 28, + "name" : "Sound 7", "extender" : "extender_0" }, { "id" : 7, - "address" : "29", - "description" : "Sound 8", + "address" : 29, + "name" : "Sound 8", "extender" : "extender_0" }, { "id" : 8, - "address" : "30", - "description" : "Sound 9", + "address" : 30, + "name" : "Sound 9", "extender" : "extender_0" }, { "id" : 9, - "address" : "31", - "description" : "Sound 10", + "address" : 31, + "name" : "Sound 10", "extender" : "extender_0" }, { "id" : 10, - "address" : "32", - "description" : "Sound 11", + "address" : 32, + "name" : "Sound 11", "extender" : "extender_0" }, { "id" : 11, - "address" : "33", - "description" : "Sound 12", + "address" : 33, + "name" : "Sound 12", "extender" : "extender_0" }, { "id" : 12, - "address" : "34", - "description" : "Sound 13", + "address" : 34, + "name" : "Sound 13", "extender" : "extender_0" }, { "id" : 13, - "address" : "35", - "description" : "Sound 14", + "address" : 35, + "name" : "Sound 14", "extender" : "extender_0" }, { "id" : 14, - "address" : "36", - "description" : "Sound 15", + "address" : 36, + "name" : "Sound 15", "extender" : "extender_0" }, { "id" : 15, - "address" : "37", - "description" : "Sound 16", + "address" : 37, + "name" : "Sound 16", "extender" : "extender_0" }, { "id" : 16, - "address" : "38", - "description" : "Sound 17", + "address" : 38, + "name" : "Sound 17", "extender" : "extender_0" }, { "id" : 17, - "address" : "39", - "description" : "Sound 18", + "address" : 39, + "name" : "Sound 18", "extender" : "extender_0" }, { "id" : 18, - "address" : "40", - "description" : "Sound 19", + "address" : 40, + "name" : "Sound 19", "extender" : "extender_0" }, { "id" : 19, - "address" : "41", - "description" : "Sound 20", + "address" : 41, + "name" : "Sound 20", "extender" : "extender_0" }, { "id" : 20, - "address" : "42", - "description" : "Sound 21", + "address" : 42, + "name" : "Sound 21", "extender" : "extender_0" }, { "id" : 21, - "address" : "43", - "description" : "Sound 22", + "address" : 43, + "name" : "Sound 22", "extender" : "extender_0" }, { "id" : 22, - "address" : "44", - "description" : "Sound 23", + "address" : 44, + "name" : "Sound 23", "extender" : "extender_0" }, { "id" : 23, - "address" : "45", - "description" : "Sound 24", + "address" : 45, + "name" : "Sound 24", "extender" : "extender_0" }, { "id" : 24, - "address" : "46", - "description" : "Sound 25", + "address" : 46, + "name" : "Sound 25", "extender" : "extender_0" }, { "id" : 25, - "address" : "47", - "description" : "Sound 26", + "address" : 47, + "name" : "Sound 26", "extender" : "extender_0" }, { "id" : 26, - "address" : "48", - "description" : "Sound 27", + "address" : 48, + "name" : "Sound 27", "extender" : "extender_0" }, { "id" : 27, - "address" : "49", - "description" : "Sound 28", + "address" : 49, + "name" : "Sound 28", "extender" : "extender_0" }, { "id" : 28, - "address" : "50", - "description" : "Speech 1: \"You're good! But I'm still the Champ!\"", + "address" : 50, + "name" : "Speech 1: \"You're good! But I'm still the Champ!\"", "extender" : "extender_0" }, { "id" : 29, - "address" : "51", - "description" : "Speech 2: \"Twenty\"", + "address" : 51, + "name" : "Speech 2: \"Twenty\"", "extender" : "extender_0" }, { "id" : 30, - "address" : "52", - "description" : "Speech 3: \"Seconds\"", + "address" : 52, + "name" : "Speech 3: \"Seconds\"", "extender" : "extender_0" }, { "id" : 31, - "address" : "53", - "description" : "Speech 4: \"Five, Four, Three, Two, One.\"", + "address" : 53, + "name" : "Speech 4: \"Five, Four, Three, Two, One.\"", "extender" : "extender_0" }, { "id" : 32, - "address" : "54", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 54, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 33, - "address" : "55", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 55, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 34, - "address" : "56", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 56, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 35, - "address" : "57", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 57, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 36, - "address" : "58", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 58, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 37, - "address" : "59", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 59, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 38, - "address" : "60", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 60, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 39, - "address" : "61", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 61, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 40, - "address" : "62", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 62, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 41, - "address" : "63", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 63, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 42, - "address" : "64", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 64, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 43, - "address" : "65", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 65, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 44, - "address" : "66", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 66, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 45, - "address" : "67", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 67, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 46, - "address" : "68", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 68, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 47, - "address" : "69", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 69, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 48, - "address" : "70", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 70, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 49, - "address" : "71", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 71, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 50, - "address" : "72", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 72, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 51, - "address" : "73", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 73, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 52, - "address" : "74", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 74, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 53, - "address" : "75", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 75, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" }, { "id" : 54, - "address" : "76", - "description" : "speech 1: \"you're good! but i'm still the champ!\"", + "address" : 76, + "name" : "speech 1: \"you're good! but i'm still the champ!\"", "extender" : "extender_0" } ] diff --git a/FlippR-Driver/networking/FlippRServer.cpp b/FlippR-Driver/networking/FlippRServer.cpp index 8ba7583..59d9dbd 100644 --- a/FlippR-Driver/networking/FlippRServer.cpp +++ b/FlippR-Driver/networking/FlippRServer.cpp @@ -257,8 +257,8 @@ void FlippRServer::handle_help(const std::string& name, const std::string& value std::string FlippRServer::get_runtime_dir() { - std::string runtime_dir = std::getenv("XDG_RUNTIME_DIR"); - if(runtime_dir == "") + char* runtime_dir = std::getenv("XDG_RUNTIME_DIR"); + if(&runtime_dir == nullptr) { runtime_dir = DEFAULT_RUNTIME_DIR; } diff --git a/FlippR-Driver/networking/FlippRServer.h b/FlippR-Driver/networking/FlippRServer.h index a34706f..fbc3641 100644 --- a/FlippR-Driver/networking/FlippRServer.h +++ b/FlippR-Driver/networking/FlippRServer.h @@ -41,8 +41,8 @@ private: Poco::Net::TCPServer* build_input_server(); private: - const std::string DEFAULT_RUNTIME_DIR = "/tmp/flippR_driver-runtime/"; - const std::string SOCKET_NAME = "S.flippR_driver"; + const char * DEFAULT_RUNTIME_DIR = "/tmp/flippR_driver-runtime/"; + const char * SOCKET_NAME = "S.flippR_driver"; const std::vector REQUIRED_CONFIG_KEYS = {"display-config", "input-config", "lamp-config", "matrix-config", "solenoid-config", "sound-config"}; int input_port; diff --git a/FlippR-Driver/src/PinController.cpp b/FlippR-Driver/src/PinController.cpp index 3314860..6a748ea 100644 --- a/FlippR-Driver/src/PinController.cpp +++ b/FlippR-Driver/src/PinController.cpp @@ -8,7 +8,6 @@ #include "PinController.h" #include "utility/config.h" - #ifndef NO_WIRING_PI #include #include diff --git a/FlippR-Driver/src/output/OutputDriverFactory.cpp b/FlippR-Driver/src/output/OutputDriverFactory.cpp index 4444d05..4e3866b 100644 --- a/FlippR-Driver/src/output/OutputDriverFactory.cpp +++ b/FlippR-Driver/src/output/OutputDriverFactory.cpp @@ -53,6 +53,7 @@ std::shared_ptr get_OutputDriver(std::istream& solenoid_config, std::map> create_solenoids(std::istream & solenoid_config, std::shared_ptr &pin_controller) { + solenoid_config.clear(); json solenoid_config_json; solenoid_config >> solenoid_config_json; @@ -74,6 +75,7 @@ std::map> create_solenoids(std::is std::shared_ptr create_solenoid(nlohmann::json &solenoid_json, nlohmann::json &port_extenders, std::shared_ptr &pin_controller, std::chrono::milliseconds deactivation_time) { + solenoid_json; std::string config_file_name = "solenoid_config.json"; uint8_t pin_base = get_pin_base(solenoid_json, port_extenders, config_file_name); @@ -81,16 +83,18 @@ std::shared_ptr create_solenoid(nlohmann::json &solenoi auto name = get_value("name", solenoid_json, config_file_name); auto address = get_value("address", solenoid_json, config_file_name); - if(solenoid_json.find("deactivation_time_milliseconds") != solenoid_json.end()) - { - deactivation_time = std::chrono::milliseconds(get_value("deactivation_time_milliseconds", solenoid_json, config_file_name)); - } + if(solenoid_json.find("deactivation_time_milliseconds") != solenoid_json.end()) + { + deactivation_time = std::chrono::milliseconds(get_value("deactivation_time_milliseconds", solenoid_json, config_file_name)); + } return std::make_shared(pin_controller, address, pin_base, name, deactivation_time); } std::map> create_flippers(std::istream &solenoid_config, std::shared_ptr &pin_controller) { + solenoid_config.clear(); + solenoid_config.seekg(0, std::ios::beg); json solenoid_config_json; solenoid_config >> solenoid_config_json; @@ -121,6 +125,8 @@ std::shared_ptr create_flipper(nlohmann::json &flipper_j std::map> create_lamps(std::istream &lamp_config, std::shared_ptr &pin_controller) { + lamp_config.clear(); + lamp_config.seekg(0, std::ios::beg); json lamp_config_json; lamp_config >> lamp_config_json; @@ -152,6 +158,8 @@ std::shared_ptr create_lamp(json &lamp_json, json & port_ex std::map> create_sounds(std::istream &sound_config, std::shared_ptr &pin_controller) { + sound_config.clear(); + sound_config.seekg(0, std::ios::beg); json sound_config_json; sound_config >> sound_config_json; @@ -161,13 +169,13 @@ std::map> create_sounds(std::istream std::chrono::milliseconds deactivation_time{ get_value("deactivation_time_milliseconds", sound_config_json, "solenoid_config.json") }; - json solenoids_json = get_element("sounds", sound_config_json, "sound_config.json"); + json sounds_json = get_element("sounds", sound_config_json, "sound_config.json"); std::map> sounds; - for(auto &solenoid_json : solenoids_json) + for(auto &sound_json : sounds_json) { - auto solenoid = create_sound(solenoid_json, port_extenders, pin_controller, deactivation_time); - sounds.emplace(solenoid->get_name(), solenoid); + auto sound = create_sound(sound_json, port_extenders, pin_controller, deactivation_time); + sounds.emplace(sound->get_name(), sound); } return sounds; } @@ -186,6 +194,8 @@ std::shared_ptr create_sound(json &sound_json, json &port_ uint8_t get_sound_fire_address(std::istream &sound_config) { + sound_config.clear(); + sound_config.seekg(0, std::ios::beg); json sound_config_json; sound_config >> sound_config_json; @@ -200,6 +210,8 @@ uint8_t get_sound_fire_address(std::istream &sound_config) std::map parse_pins_display_board(std::istream &display_config) { + display_config.clear(); + display_config.seekg(0, std::ios::beg); std::string config_file = "display_config.json"; json display_config_json; @@ -233,7 +245,8 @@ std::map parse_pins_display_board(std::istream &display_co std::vector> create_displays(std::istream &display_config) { - + display_config.clear(); + display_config.seekg(0, std::ios::beg); json display_config_json; display_config >> display_config_json; @@ -279,7 +292,6 @@ std::map> map_displays(const std::vecto void initialize_port_extenders(json &port_extenders, PinController * pin_controller, const std::string & file_name) { - for (auto & extender_json : port_extenders) { auto i2c_address = get_value("i2c_address", extender_json, file_name); @@ -334,7 +346,7 @@ type get_value(const std::string & name, json & object, const std::string & file } catch(json::exception &e) { - CLOG(ERROR, OUTPUT_LOGGER) << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what(); + /*CLOG(ERROR, OUTPUT_LOGGER)*/ std::cerr << "File " << file_name << " seems to be corrupted at " << name << ": " << e.what(); exit(EXIT_FAILURE); } return element;