diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/FlippR-Driver/CMakeLists.txt b/FlippR-Driver/CMakeLists.txt
index 3de33b2..90d042b 100644
--- a/FlippR-Driver/CMakeLists.txt
+++ b/FlippR-Driver/CMakeLists.txt
@@ -96,6 +96,9 @@ endif(BUILD_SHARED_LIB)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/include)
+# Set libraries include path
+target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/${LIB_DIR})
+
######################### BOOST #########################
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
if(Boost_FOUND)
@@ -107,9 +110,6 @@ else()
message (FATAL_ERROR "Can't find Boost.")
endif(Boost_FOUND)
-# Set libraries include path
-target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/${LIB_DIR})
-
##################### WIRING_PI ##########################
find_library(wiringPi_LIB wiringPi)
if(NOT wiringPi_LIB)
@@ -122,25 +122,32 @@ if(NOT crypt_LIB)
message(FATAL_ERROR "Could not find crypt library")
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC ${crypt_LIB})
-## EASYLOGGING
+
+##################### EASYLOGGING #########################
set(EASYLOGGING_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/${LIB_DIR}/easylogging)
add_library(Easylogging STATIC ${EASYLOGGING_INCLUDE_DIR}/easylogging++.cc)
target_include_directories(${PROJECT_NAME} PUBLIC ${EASYLOGGING_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC Easylogging)
-## CATCH
+######################## CATCH ############################
set(CATCH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/tests)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
-## THREAD
+####################### THREAD ############################
find_package(Threads REQUIRED)
if(NOT CMAKE_THREAD_LIBS_INIT)
message(FATAL_ERROR, "Could not find libthread")
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE ${Threads_LIBRARIES})
+####################### POCO ##############################
+find_package(Poco REQUIRED COMPONENTS Foundation Net JSON )
+if(NOT Poco_FOUND)
+ message(FATAL_ERROR, "Could not find libPoco")
+endif()
+target_link_libraries(${PROJECT_NAME} PUBLIC Poco::Foundation Poco::Net Poco::JSON)
if(ENABLE_TESTING)
add_subdirectory(tests)
endif(ENABLE_TESTING)
diff --git a/FlippR-Driver/cli/PrintHandler.h b/FlippR-Driver/cli/PrintHandler.h
index a19097f..36355d0 100644
--- a/FlippR-Driver/cli/PrintHandler.h
+++ b/FlippR-Driver/cli/PrintHandler.h
@@ -6,7 +6,7 @@
#define flippR_driver_PRINTHANDLER_H
#include
-#include "../src/input/implementation/EventHandler.h"
+#include "input/EventHandler.h"
#include "input/InputDriver.h"
class PrintHandler : public flippR_driver::input::EventHandler
diff --git a/FlippR-Driver/cli/main.cpp b/FlippR-Driver/cli/main.cpp
index c459a23..3cbc723 100644
--- a/FlippR-Driver/cli/main.cpp
+++ b/FlippR-Driver/cli/main.cpp
@@ -16,6 +16,8 @@
using namespace flippR_driver;
namespace po = boost::program_options;
+PrintHandler* print_handler = nullptr;
+
void __sigint_handler(int param)
{
printf("Caught SIGINT... aborting!\n");
@@ -29,17 +31,9 @@ static void show_usage(const std::string &name)
<< "-osolc= -osc=]";
}
-static void register_program_options(po::options_description &po_desc)
+static void register_program_options(po::options_description &po_desc, boost::optional &input_pin_config_file, std::string &input_matrix_config_file,
+ boost::optional &output_pin_config_file, std::string &output_display_config_file, std::string &output_lamp_config_file, std::string &output_solenoid_config_file, std::string &output_sound_config_file)
{
- boost::optional input_pin_config_file;
- std::string input_matrix_config_file;
-
- boost::optional output_pin_config_file;
- std::string output_display_config_file;
- std::string output_lamp_config_file;
- std::string output_solenoid_config_file;
- std::string output_sound_config_file;
-
po_desc.add_options()
("help", "print_help_message")
("input_pin_config,ipc", po::value>(&input_pin_config_file), "input pin config file")
@@ -83,11 +77,29 @@ int main (int argc, char *argv[])
// registering sigint
signal(SIGINT, __sigint_handler);
- // todo work with boost program options
po::options_description po_desc("Options");
- register_program_options(po_desc);
+ boost::optional input_pin_config_file;
+ std::string input_matrix_config_file;
+ boost::optional output_pin_config_file;
+ std::string output_display_config_file;
+ std::string output_lamp_config_file;
+ std::string output_solenoid_config_file;
+ std::string output_sound_config_file;
+ register_program_options(po_desc, input_pin_config_file, input_matrix_config_file, output_pin_config_file, output_display_config_file, output_lamp_config_file, output_solenoid_config_file, output_sound_config_file);
+
+ // todo parse
+
+ if(input_pin_config_file)
+ {
+ print_handler = start_print_handler(*input_pin_config_file, input_matrix_config_file);
+ }
+
+ if(output_pin_config_file)
+ {
+ start_output_driver(*output_pin_config_file, )
+ }
while(1);
return 0;
diff --git a/FlippR-Driver/contrib/json_example/output/Sound_Config.json b/FlippR-Driver/contrib/json_example/output/Sound_Config.json
index e3122ff..8b8f1ab 100644
--- a/FlippR-Driver/contrib/json_example/output/Sound_Config.json
+++ b/FlippR-Driver/contrib/json_example/output/Sound_Config.json
@@ -2,6 +2,11 @@
"deactivation_time_milliseconds" : 10,
"sounds" :
[
+ {
+ "id" : -1, //todo should be 0
+ "address" : 0,
+ "description" : "Deactivate Sound"
+ },
{
"id" : 0,
"address" : "22",
diff --git a/FlippR-Driver/contrib/json_example/output_socket_solenoid.json b/FlippR-Driver/contrib/json_example/output_socket_solenoid.json
new file mode 100644
index 0000000..bd4aa12
--- /dev/null
+++ b/FlippR-Driver/contrib/json_example/output_socket_solenoid.json
@@ -0,0 +1,10 @@
+{
+ "type" : "Solenoid",
+ "name" : "Right flap",
+ "functions" :
+ {
+ "trigger" : false
+ }
+}
+string function;
+lamp
\ No newline at end of file
diff --git a/FlippR-Driver/src/utility/InputSocketConnection.cpp b/FlippR-Driver/src/utility/InputSocketConnection.cpp
new file mode 100644
index 0000000..242b3a2
--- /dev/null
+++ b/FlippR-Driver/src/utility/InputSocketConnection.cpp
@@ -0,0 +1,5 @@
+//
+// Created by rhetenor on 3/6/19.
+//
+
+#include "InputSocketConnection.h"
diff --git a/FlippR-Driver/src/utility/InputSocketConnection.h b/FlippR-Driver/src/utility/InputSocketConnection.h
new file mode 100644
index 0000000..d9119f9
--- /dev/null
+++ b/FlippR-Driver/src/utility/InputSocketConnection.h
@@ -0,0 +1,18 @@
+//
+// Created by rhetenor on 3/6/19.
+//
+
+#ifndef FLIPPR_CODE_INPUTSOCKETCONNECTION_H
+#define FLIPPR_CODE_INPUTSOCKETCONNECTION_H
+
+
+#include
+
+class InputSocketConnection : public Poco::Net::TCPServerConnection
+{
+
+
+};
+
+
+#endif //FLIPPR_CODE_INPUTSOCKETCONNECTION_H
diff --git a/FlippR-Driver/src/utility/InputSocketHandler.h b/FlippR-Driver/src/utility/InputSocketHandler.h
index b4f3629..80098ca 100644
--- a/FlippR-Driver/src/utility/InputSocketHandler.h
+++ b/FlippR-Driver/src/utility/InputSocketHandler.h
@@ -5,26 +5,25 @@
#ifndef FLIPPR_DRIVER_INPUTSOCKETHANDLER_H
#define FLIPPR_DRIVER_INPUTSOCKETHANDLER_H
-#include "SocketHandler.h"
-
#include "input/EventHandler.h"
+#include
+
#include
namespace flippR_driver
{
namespace utility
{
-class InputSocketHandler : public SocketHandler, public input::EventHandler
+class InputSocketHandler : public input::EventHandler
{
public:
- explicit InputSocketHandler(boost::asio::io_service &service, std::string socket_file = "/var/run/user/" + std::to_string(getuid())
- + "flippR/S.flippR_input");
+ InputSocketHandler();
void handle(input::Event &event) override;
private:
- nlohmann::json serialize_event(input::Event &event);
+ std::string serialize_event(input::Event &event);
};
}
diff --git a/FlippR-Driver/src/utility/OutputRequestHandler.cpp b/FlippR-Driver/src/utility/OutputRequestHandler.cpp
new file mode 100644
index 0000000..1feefbc
--- /dev/null
+++ b/FlippR-Driver/src/utility/OutputRequestHandler.cpp
@@ -0,0 +1,168 @@
+//
+// Created by rhetenor on 3/6/19.
+//
+
+#include "OutputRequestHandler.h"
+
+#include
+#include
+namespace flippR_driver
+{
+namespace utility
+{
+using namespace Poco;
+using namespace Poco::Net;
+
+OutputRequestHandler::OutputRequestHandler(std::shared_ptr output_driver) :
+ output_driver(output_driver)
+ {}
+
+void OutputRequestHandler::handleRequest(HTTPServerRequest &request,
+ HTTPServerResponse &response)
+{
+ auto& path_segments = getPathSegments(URI(request.getPathSegments()));
+
+ std::string item_type = path_segments.at(0);
+ std::string item_name = path_segments.at(1);
+ std::string action = path_segments.at(2);
+ std::string score = "";
+
+ if(item_type == "displays")
+ {
+ score = path_segments.at(3);
+ }
+
+ response.setContentType("text/json");
+ response.setStatus(HTTPServerResponse::HTTP_OK);
+
+ try
+ {
+ parseRequest(item_type, item_name, action, score);
+ }
+ catch(NotFoundException &e)
+ {
+ response.setStatusAndReason(HTTPServerResponse::HTTP_NOT_FOUND, e.displayText());
+ }
+}
+
+void OutputRequestHandler::parseRequest(const std::string& item_type, const std::string& item_name, const std::string& action, const std::string& score)
+{
+ if(item_type == "solenoids")
+ {
+ parseSolenoid(item_name, action);
+ }
+ else if(item_type == "lamps")
+ {
+ parseLamp(item_name, action);
+ }
+ else if(item_type == "sounds")
+ {
+ parseSound(item_name, action);
+ }
+ else if(item_type == "displays")
+ {
+ parseDisplay(item_name, action, score);
+ }
+}
+
+void OutputRequestHandler::parseSolenoid(const std::string& item_name, const std::string& action)
+{
+ auto opt_solenoid = this->output_driver->get_solenoid(item_name);
+
+ if(!opt_solenoid)
+ {
+ throw new Poco::NotFoundException("No solenoid with name \"" + item_name + "\"!");
+ }
+
+ auto solenoid = opt_solenoid->get();
+
+ if(action == "trigger")
+ {
+ solenoid->trigger();
+ }
+ else
+ {
+ throw new Poco::NotFoundException("No action with name \"" + action + "\" on solenoids!");
+ }
+}
+
+void OutputRequestHandler::parseLamp(const std::string& item_name, const std::string& action)
+{
+ auto opt_lamp = this->output_driver->get_lamp(item_name);
+
+ if(!opt_lamp)
+ {
+ throw new Poco::NotFoundException("No lamp with name \"" + item_name + "\"!");
+ }
+
+ auto lamp = opt_lamp->get();
+
+ if(action == "activate")
+ {
+ lamp->activate();
+ }
+ else if(action == "deactivate")
+ {
+ lamp->deactivate();
+ }
+ else
+ {
+ throw new Poco::NotFoundException("No action with name \"" + action + "\" on lamps!");
+ }
+}
+
+void OutputRequestHandler::parseSound(const std::string& item_name, const std::string& action)
+{
+ auto opt_sound = this->output_driver->get_sound(item_name);
+
+ if(!opt_sound)
+ {
+ throw new Poco::NotFoundException("No sound with name \"" + item_name + "\"!");
+ }
+
+ auto sound = opt_sound->get();
+
+ if(action == "play")
+ {
+ sound->play();
+ }
+ else
+ {
+ throw new Poco::NotFoundException("No action with name \"" + action + "\" on sounds!");
+ }
+}
+
+void OutputRequestHandler::parseDisplay(const std::string& item_name, const std::string& action, const std::string& score)
+{
+ uint8_t display_number = std::stoi(item_name);
+ auto opt_display = this->output_driver->get_display(display_number);
+
+ if(!opt_display)
+ {
+ throw new Poco::NotFoundException("No display with number \"" + item_name + "\"!");
+ }
+
+ auto display = opt_display->get();
+
+
+ if(action == "write_score")
+ {
+ unsigned int score = std::stoi(score);
+ display->write_score(score);
+ }
+ else
+ {
+ throw new Poco::NotFoundException("No Action with name \"" + action + "\" on sounds!");
+ }
+}
+std::vector OutputRequestHandler::getPathSegements(Poco::URI uri)
+{
+ std::vector path_segments;
+ uri.getPathSegments(path_segments);
+ return path_segments;
+}
+
+
+}
+}
+
diff --git a/FlippR-Driver/src/utility/OutputRequestHandler.h b/FlippR-Driver/src/utility/OutputRequestHandler.h
new file mode 100644
index 0000000..eeaa323
--- /dev/null
+++ b/FlippR-Driver/src/utility/OutputRequestHandler.h
@@ -0,0 +1,39 @@
+//
+// Created by rhetenor on 3/6/19.
+//
+
+#ifndef FLIPPR_CODE_OUTPUTREQUESTHANDLER_H
+#define FLIPPR_CODE_OUTPUTREQUESTHANDLER_H
+
+#include
+#include
+#include