diff --git a/bin/config/config.cfg b/bin/config/config.cfg index 2237897..d748ed0 100644 --- a/bin/config/config.cfg +++ b/bin/config/config.cfg @@ -6,6 +6,8 @@ pluginDir = "./plugins" mappingFile = "./config/mapping.cfg" prepare3dConfigurationFile = "./config/prepare3d.cfg" pokeyConfigurationFile = "./config/pokey.cfg" +httpListenAddress = "127.0.0.1" +httpListenPort = 3000 # AWS specific configuration aws = diff --git a/bin/config/mapping.cfg b/bin/config/mapping.cfg index a4cc22f..fc4ceee 100644 --- a/bin/config/mapping.cfg +++ b/bin/config/mapping.cfg @@ -193,7 +193,8 @@ mapping=( }, { source = "G_OH_EGT", - target = "G_OH_EGT" + target = "G_OH_EGT", + sustain = 1000 }, { source = "G_OH_TEMPERATURE", @@ -201,12 +202,250 @@ mapping=( sustain = 1000 }, { - source = "I_OH_BATT_DISCHARGE", - target = "I_OH_BATT_DISCHARGE" + source = "V_OH_FLTALT", + target = "V_OH_FLTALT", + sustain = 1000 }, { - source = "V_OH_FLTALT", - target = "V_OH_FLTALT" - } + source = "B_STARTER_SOLENOID_1", + target = "B_STARTER_SOLENOID_1" + }, + { + source = "B_STARTER_SOLENOID_2", + target = "B_STARTER_SOLENOID_2" + }, + { + source = "S_OH_FUEL_PUMP_LA", + target = "S_OH_FUEL_PUMP_LA" + }, + { + source = "S_OH_FUEL_PUMP_RA", + target = "S_OH_FUEL_PUMP_RA" + }, + { + source = "S_OH_FUEL_PUMP_LF", + target = "S_OH_FUEL_PUMP_LF" + }, + { + source = "S_OH_FUEL_PUMP_RF", + target = "S_OH_FUEL_PUMP_RF" + }, + { + source = "S_OH_FUEL_PUMP_CL", + target = "S_OH_FUEL_PUMP_CL" + }, + { + source = "S_OH_FUEL_PUMP_CR", + target = "S_OH_FUEL_PUMP_CR" + }, + { + source = "S_OH_BUS_TRANSFER", + target = "S_OH_BUS_TRANSFER" + }, + { + source = "S_OH_LIGHT_RWY1", + target = "S_OH_LIGHT_RWY1" + }, + { + source = "S_OH_LIGHT_RWY2", + target = "S_OH_LIGHT_RWY2" + }, + { + source = "S_OH_YAW_DAMPER", + target = "S_OH_YAW_DAMPER" + }, + { + source = "I_OH_TEMP_PROBE", + target = "I_OH_TEMP_PROBE" + }, + { + source = "I_OH_CAPT_PITOT", + target = "I_OH_CAPT_PITOT" + }, + { + source = "I_OH_ELEV_PITOT1", + target = "I_OH_ELEV_PITOT1" + }, + { + source = "I_OH_ELEV_PITOT2", + target = "I_OH_ELEV_PITOT2" + }, + { + source = "I_OH_COWL_AI_L", + target = "I_OH_COWL_AI_L" + }, + { + source = "I_OH_COWL_VALVE_L", + target = "I_OH_COWL_VALVE_L" + }, + { + source = "I_OH_COWL_AI_R", + target = "I_OH_COWL_AI_R" + }, + { + source = "I_OH_ALPHA_VANE1", + target = "I_OH_ALPHA_VANE1" + }, + { + source = "I_OH_ENG_HYD_PUMP_R", + target = "I_OH_ENG_HYD_PUMP_R" + }, + { + source = "I_OH_ALPHA_VANE2", + target = "I_OH_ALPHA_VANE2" + }, + { + source = "I_OH_WINDOW_HEAT_OVT_SL", + target = "I_OH_WINDOW_HEAT_OVT_SL" + }, + { + source = "I_OH_WINDOW_HEAT_FL", + target = "I_OH_WINDOW_HEAT_FL" + }, + { + source = "I_OH_WINDOW_HEAT_FR", + target = "I_OH_WINDOW_HEAT_FR" + }, + { + source = "I_OH_WINDOW_HEAT_SL", + target = "I_OH_WINDOW_HEAT_SL" + }, + { + source = "I_OH_WINDOW_HEAT_SR", + target = "I_OH_WINDOW_HEAT_SR" + }, + { + source = "I_OH_WINDOW_HEAT_OVT_FR", + target = "I_OH_WINDOW_HEAT_OVT_FR" + }, + { + source = "I_OH_WINDOW_HEAT_OVT_SR", + target = "I_OH_WINDOW_HEAT_OVT_SR" + }, + { + source = "I_OH_ELEC_HYD_PUMP_OVHT_1", + target = "I_OH_ELEC_HYD_PUMP_OVHT_1" + }, + { + source = "I_OH_AUX_PITOT", + target = "I_OH_AUX_PITOT" + }, + { + source = "I_OH_CO_PITOT", + target = "I_OH_CO_PITOT" + }, + { + source = "I_OH_WAI_VALVE_L", + target = "I_OH_WAI_VALVE_L" + }, + { + source = "I_OH_BLEED_TRIP_L", + target = "I_OH_BLEED_TRIP_L" + }, + { + source = "I_OH_BLEED_TRIP_R", + target = "I_OH_BLEED_TRIP_R" + }, + { + source = "I_OH_WINGBODY_OVT_R", + target = "I_OH_WINGBODY_OVT_R" + }, + { + source = "I_OH_WINGBODY_OVT_L", + target = "I_OH_WINGBODY_OVT_L" + }, + { + source = "I_OH_PRES_MANUAL", + target = "I_OH_PRES_MANUAL" + }, + { + source = "I_OH_ELEC_HYD_PUMP_1", + target = "I_OH_ELEC_HYD_PUMP_1" + }, + { + source = "I_OH_DOOR_FWD_SERVICE", + target = "I_OH_DOOR_FWD_SERVICE" + }, + { + source = "I_OH_DOOR_LEFT_FWD_OVERWING", + target = "I_OH_DOOR_LEFT_FWD_OVERWING" + }, + { + source = "I_OH_DOOR_RIGHT_FWD_OVERWING", + target = "I_OH_DOOR_RIGHT_FWD_OVERWING" + }, + { + source = "I_OH_DOOR_EQUIP", + target = "I_OH_DOOR_EQUIP" + }, + { + source = "I_OH_DOOR_LEFT_AFT_OVERWING", + target = "I_OH_DOOR_LEFT_AFT_OVERWING" + }, + { + source = "I_OH_DOOR_FWD_ENTRY", + target = "I_OH_DOOR_FWD_ENTRY" + }, + { + source = "I_OH_DOOR_AFT_ENTRY", + target = "I_OH_DOOR_AFT_ENTRY" + }, + { + source = "I_OH_DOOR_RIGHT_AFT_OVERWING", + target = "I_OH_DOOR_RIGHT_AFT_OVERWING" + }, + { + source = "I_OH_DOOR_AFT_CARGO", + target = "I_OH_DOOR_AFT_CARGO" + }, + { + source = "I_OH_PACK_L", + target = "I_OH_PACK_L" + }, + { + source = "I_OH_PRES_AUTO_FAIL", + target = "I_OH_PRES_AUTO_FAIL" + }, + { + source = "I_OH_ENG_HYD_PUMP_1", + target = "I_OH_ENG_HYD_PUMP_1" + }, + { + source = "I_OH_PRES_OFFSCHED", + target = "I_OH_PRES_OFFSCHED" + }, + { + source = "I_OH_PACK_R", + target = "I_OH_PACK_R" + }, + { + source = "I_OH_ELEC_HYD_PUMP_2", + target = "I_OH_ELEC_HYD_PUMP_2" + }, + { + source = "I_OH_DOOR_FWD_CARGO", + target = "I_OH_DOOR_FWD_CARGO" + }, + { + source = "I_OH_PRES_ALTN", + target = "I_OH_PRES_ALTN" + }, + { + source = "B_STARTER_SOLENOID_1", + target = "B_STARTER_SOLENOID_1" + }, + { + source = "B_STARTER_SOLENOID_2", + target = "B_STARTER_SOLENOID_2" + }, + { + source = "S_OH_ENG_START_R", + target = "S_OH_ENG_START_R" + }, + { + source = "S_OH_ENG_START_L", + target = "S_OH_ENG_START_L" + } + ) \ No newline at end of file diff --git a/bin/config/pokey.cfg b/bin/config/pokey.cfg index ae412b2..d209b7e 100644 --- a/bin/config/pokey.cfg +++ b/bin/config/pokey.cfg @@ -4,19 +4,18 @@ configuration = { serialNumber = "25770", name = "DCMetering", + # pin - integer - any valid IO pin (1-55) + # name - string - name of the pin + # type - string - DIGITAL_INPUT, DIGITAL_OUTPUT + # description - string + # units - string + # default - integer - value on start pins = ( - # pin - integer - any valid IO pin (1-55) - # name - string - name of the pin - # type - string - DIGITAL_INPUT, DIGITAL_OUTPUT - # description - string - # units - string - # default - integer - value on start - ), + # pins 1-2 as encoder 1 + # pins 5-6 as encoder 2 + # pins 15-16 as encoder 3 encoders = ( - # pins 1-2 as encoder 1 - # pins 5-6 as encoder 2 - # pins 15-16 as encoder 3 { encoder = 1, name = "V_OH_FLTALT", @@ -75,6 +74,7 @@ configuration = ) }, { + # pokey_1 # Fuel Control Panel & Bus Switching Panel serialNumber = "25774", name = "pokey_1", @@ -82,13 +82,13 @@ configuration = { pin = 1, name = "I_OH_FUEL_PUMP_LA", - description = "Left AFT fuel pump indicator" + description = "Left AFT fuel pump indicator", type = "DIGITAL_OUTPUT" }, { pin = 2, name = "I_OH_FUEL_PUMP_LF", - description = "Left FWD fuel pump indicator" + description = "Left FWD fuel pump indicator", type = "DIGITAL_OUTPUT" }, { @@ -204,11 +204,22 @@ configuration = pin = 24, name = "I_OH_TRANS_OFF2", type = "DIGITAL_OUTPUT" + }, + { + # should send GRD/OFF + pin = 41, + name = "S_OH_ENG_START_L", + type = "DIGITAL_INPUT" + }, + { + pin = 44, + name = "S_OH_YAW_DAMPER", + type = "DIGITAL_INPUT" } ) }, { - # flight Control / AC/DC Meetering + # pokey_2 serialNumber = "25423", name = "pokey_2", pins = ( @@ -295,7 +306,7 @@ configuration = ) }, { - serialNumber="26733", + serialNumber="26701", name = "test PWM", pins = (), pwm= ( @@ -305,7 +316,7 @@ configuration = decription = "APU Exhaust Gas Temp", units = "degrees", leftDutyCycle = 62000, - rightDutyCycle = 22000, + rightDutyCycle = 18000, period = 500000 # hw cycles } ) diff --git a/bin/config/prepare3d.cfg b/bin/config/prepare3d.cfg index 4aa4e15..4c4ec93 100644 --- a/bin/config/prepare3d.cfg +++ b/bin/config/prepare3d.cfg @@ -1,12 +1,24 @@ configuration = ( { type="prepare3d", - ipAddress= "127.0.0.1", # ipAddress= "192.168.2.2", + ipAddress= "127.0.0.1", port = 8091, transforms = { - # S_OH_STANDBY_POWER = { On = "Auto", Off = "Bat" }, - # I_OH_BATT_DISCHARGE = { On = "On", Off = "Off" } + S_OH_STANDBY_POWER = { On = "Auto", Off = "Bat" }, + S_OH_FUEL_PUMP_LA = { On = "On", Off = "Off" }, + S_OH_FUEL_PUMP_LF = { On = "On", Off = "Off" }, + S_OH_FUEL_PUMP_RA = { On = "On", Off = "Off" }, + S_OH_FUEL_PUMP_RF = { On = "On", Off = "Off" }, + S_OH_FUEL_PUMP_CL = { On = "On", Off = "Off" }, + S_OH_FUEL_PUMP_CR = { On = "On", Off = "Off" }, + S_OH_BUS_TRANSFER = { On = "Off", Off = "Auto" }, + S_OH_LIGHT_RWY1 = { On = "On", Off = "Off"}, + S_OH_LIGHT_RWY2 = { On = "On", Off = "Off"}, + S_OH_YAW_DAMPER = { On = "On", Off = "Off"}, + S_OH_ENG_START_R = { On = "GRD", Off = "Off"}, + S_OH_ENG_START_L = { On = "GRD", Off = "Off"} + } } ) diff --git a/docs/tofix.md b/docs/tofix.md new file mode 100644 index 0000000..7b8a2c4 --- /dev/null +++ b/docs/tofix.md @@ -0,0 +1,4 @@ +Not functioning + +I_OH_WINDOW_HEAT_OVT_FL +I_OH_WAI_VALVE_R \ No newline at end of file diff --git a/premake4.lua b/premake4.lua index 48a5f43..841fea9 100644 --- a/premake4.lua +++ b/premake4.lua @@ -25,6 +25,7 @@ solution "simhub" configuration {""} defines {"__PLATFORM"} + configuration "Debug" defines { "DEBUG" } symbols "On" @@ -57,31 +58,44 @@ solution "simhub" includedirs { "src", "src/app", - "src/common", - "src/libs", - "src/libs/variant/include", - "src/libs/variant/include/mpark", - "src/libs/queue" } + "/usr/local/opt/openssl/include", + "src/common", + "src/libs", + "src/libs/variant/include", + "src/libs/variant/include/mpark", + "src/libs/queue" } + + libdirs { "/usr/local/opt/openssl/lib" } links { "zlog", - "pthread", + "pthread", + "cpprest", + "ssl", + "boost_system", + "crypto", + "boost_chrono", "config++" } targetdir ("bin") buildoptions { "--std=c++14" } - + + configuration { "macosx" } + links { "boost_thread-mt" } + configuration {} + + configuration { "macosx", "Debug" } postbuildcommands { "dsymutil bin/simhub", "gtags" } configuration {} - + configuration {"linux"} links {"dl"} configuration {""} project "simhub_tests" kind "ConsoleApp" - language "C++" + language "C++" files { "src/common/**.h", "src/common/**.cpp", "src/test/**.h", @@ -93,6 +107,8 @@ solution "simhub" excludes {"src/common/aws/**"} configuration {} + libdirs { "/usr/local/opt/openssl/lib" } + includedirs { "src/libs/googletest/include", "src/libs/googletest", "src", @@ -101,18 +117,27 @@ solution "simhub" "src/libs/variant/include", "src/libs", "src/libs/variant/include/mpark", - "src/libs/queue" } + "/usr/local/opt/openssl/include", + "src/libs/queue" } links { "dl", "zlog", - "pthread", + "pthread", + "cpprest", + "ssl", + "boost_system", + "crypto", + "boost_chrono", "config++"} targetdir ("bin") buildoptions { "--std=c++14" } + configuration { "macosx" } + links { "boost_thread-mt" } + configuration {} project "prepare3d_plugin" - kind "SharedLib" - language "C++" + kind "SharedLib" + language "C++" targetname "prepare3d" targetdir ("bin/plugins") links { 'uv', @@ -166,24 +191,22 @@ solution "simhub" targetname "pokey" targetdir ("bin/plugins") libdirs { "lib/pokey" } - links { - "PoKeys", - "usb-1.0", - "uv" - } + links { "PoKeys", + "usb-1.0", + "uv" } files { "src/libs/plugins/pokey/**.h", "src/libs/plugins/common/**.cpp", "src/libs/plugins/pokey/**.cpp" } includedirs { "src/libs/googletest/include", - "src/libs/googletest", - "src/common", - "src/libs/plugins", - "src/libs/variant/include", - "src/libs", - "src/libs/variant/include/mpark", - "lib/pokey", - "src/libs/queue" } - links { 'config++', - 'pthread'} + "src/libs/googletest", + "src/common", + "src/libs/plugins", + "src/libs/variant/include", + "src/libs", + "src/libs/variant/include/mpark", + "lib/pokey", + "src/libs/queue" } + links { "config++", + "pthread"} buildoptions { "--std=c++14" } diff --git a/src/app/main.cpp b/src/app/main.cpp index 9edb121..0a2abcb 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -80,7 +80,6 @@ int main(int argc, char *argv[]) if (simhubController->loadPokeyPlugin()) { if (simhubController->loadPrepare3dPlugin()) { - // kick off the simhub envent loop simhubController->runEventLoop([=](std::shared_ptr value) { diff --git a/src/app/simhub.cpp b/src/app/simhub.cpp index 421561c..0654a4c 100644 --- a/src/app/simhub.cpp +++ b/src/app/simhub.cpp @@ -23,6 +23,7 @@ std::shared_ptr SimHubEventController::EventControllerIns } SimHubEventController::SimHubEventController() +// : _configurationHTTPListener(U("http://127.0.0.1:3000")) { _prepare3dMethods.plugin_instance = NULL; _pokeyMethods.plugin_instance = NULL; @@ -36,11 +37,126 @@ SimHubEventController::SimHubEventController() logger.log(LOG_INFO, "Starting event controller"); } +/** + * like strtok but not evil + */ +void split(const std::string &sequence, std::string &delims, std::vector &tokens) +{ + size_t i = 0; + size_t pos = sequence.find(delims); + + if (pos == std::string::npos){ + tokens.push_back(sequence); + return; + } + + while (pos != std::string::npos) { + tokens.push_back(sequence.substr(i, pos-i)); + i = ++pos; + pos = sequence.find(delims, pos); + + if (pos == std::string::npos) { + tokens.push_back(sequence.substr(i, sequence.length())); + } + } +} + +/** + * rudimentary converter from libconfig content to JSON content + * - doesn't suppoert '#' comments outside of dictionaries (like in lists) + */ +std::string libconfigToJSON(std::string configFilename) +{ + std::ifstream file(configFilename); + + if (!file) { + return ""; + } + + size_t lineIdx = 0; + + std::string line; + std::stringstream jsonStream; + + std::string commentToken("#"); + std::string jsonAssign(":"); + + jsonStream << "{" << std::endl; + + while (std::getline(file, line)) { + lineIdx++; + + std::replace(line.begin(), line.end(), '=', ':'); + std::replace(line.begin(), line.end(), '(', '['); + std::replace(line.begin(), line.end(), ')', ']'); + std::replace(line.begin(), line.end(), ';', ','); + + std::vector tokens; + + split(line, commentToken, tokens); + + if (line.find(commentToken) != std::string::npos) { + jsonStream << "\"_line_comment_" << lineIdx << "\": \"" << tokens[tokens.size() - 1] << "\"," << std::endl; + } + else { + tokens.clear(); + split(line, jsonAssign, tokens); + + if (tokens.size() > 1) { + size_t p = tokens[0].find_first_not_of(" "); + tokens[0].insert(p, "\""); + p = tokens[0].find_last_not_of(" "); + tokens[0].insert(p + 1, "\""); + + jsonStream << tokens[0] << ":"; + for (size_t i = 1; i < tokens.size(); i++) { + jsonStream << " " << tokens[i]; + } + jsonStream << std::endl; + } + else { + jsonStream << line << std::endl; + } + } + } + + jsonStream << "}" << std::endl; + + return jsonStream.str(); +} + +/** + * serves GET requests on http://localhost/configuration - returns JSON converted + * pokey configuration content + */ +void SimHubEventController::httpGETConfigurationHandler(web::http::http_request request) +{ + std::string config_json = libconfigToJSON(_configManager->pokeyConfigurationFilename()); + request.reply(web::http::status_codes::OK, config_json); +} + +/** + * constructs cpprest HTTP listener instance and tells it to start listening on + * cofigured port + */ +void SimHubEventController::startHTTPListener(void) +{ + std::stringstream httpListenURI; + + httpListenURI << "http://" << _configManager->httpListenAddress() << ":" << _configManager->httpListenPort(); + _configurationHTTPListener = std::make_shared(httpListenURI.str()); + + // start http listener for json config read + _configurationHTTPListener->open().wait(); + _configurationHTTPListener->support(web::http::methods::GET, std::bind(&SimHubEventController::httpGETConfigurationHandler, this, std::placeholders::_1)); +} + SimHubEventController::~SimHubEventController(void) { if (_running) { terminate(); } + #if defined(_AWS_SDK) if (_awsHelper.polly()) { _awsHelper.polly()->shutdown(); @@ -57,6 +173,8 @@ SimHubEventController::~SimHubEventController(void) #if defined(_AWS_SDK) void SimHubEventController::startSustainThread(void) { + _awsHelper.polly()->say("Simulator is ready."); + std::shared_ptr sustainThread = std::make_shared([=] { _sustainThreadManager.setThreadRunning(true); while (!_sustainThreadManager.threadCanceled()) { @@ -312,8 +430,13 @@ void SimHubEventController::terminate(void) ceaseSustainThread(); #endif + // kill web configuration listener + auto listenerCloseTask = _configurationHTTPListener->close(); + listenerCloseTask.wait(); + shutdownPlugin(_prepare3dMethods); shutdownPlugin(_pokeyMethods); + _running = false; } diff --git a/src/app/simhub.h b/src/app/simhub.h index 3f4d6b1..e0f0460 100644 --- a/src/app/simhub.h +++ b/src/app/simhub.h @@ -6,6 +6,10 @@ #include #include #include +#include +#include +#include +#include #include "appsupport.h" #include "elements/attributes/attribute.h" @@ -67,6 +71,13 @@ class SimHubEventController libconfig::Config *_pokeyDeviceConfig; libconfig::Config *_prepare3dDeviceConfig; + //! implements configuration server + std::shared_ptr _configurationHTTPListener; + std::string _httpListenAddress; + size_t _httpListenPort; + virtual void httpGETConfigurationHandler(web::http::http_request request); + virtual void startHTTPListener(void); + public: virtual ~SimHubEventController(void); bool loadPrepare3dPlugin(void); @@ -119,6 +130,8 @@ template void SimHubEventController::runEventLoop(F &&eventProcessorFu startSustainThread(); #endif + startHTTPListener(); + while (!breakLoop) { try { std::shared_ptr data = _eventQueue.pop(); diff --git a/src/common/configmanager/configmanager.cpp b/src/common/configmanager/configmanager.cpp index ae9a584..b5320ab 100644 --- a/src/common/configmanager/configmanager.cpp +++ b/src/common/configmanager/configmanager.cpp @@ -170,3 +170,18 @@ std::string ConfigManager::name(void) return _configName; } + +std::string ConfigManager::httpListenAddress(void) +{ + std::string retVal(""); + config()->lookupValue("httpListenAddress", retVal); + return retVal; +} + +size_t ConfigManager::httpListenPort(void) +{ + int port = 0; + config()->lookupValue("httpListenPort", port); + return port; +} + diff --git a/src/common/configmanager/configmanager.h b/src/common/configmanager/configmanager.h index 522ff14..d66850d 100644 --- a/src/common/configmanager/configmanager.h +++ b/src/common/configmanager/configmanager.h @@ -67,6 +67,9 @@ class ConfigManager std::string loadPokeyConfiguration(void); std::string version(void); std::string name(void); + std::string httpListenAddress(void); + size_t httpListenPort(void); + std::string pokeyConfigurationFilename(void) { return _pokeyConfigurationFilename; }; std::shared_ptr mapManager(void); libconfig::Config *config() { return &_config; } }; diff --git a/src/libs/plugins/pokey/main.cpp b/src/libs/plugins/pokey/main.cpp index 14d09ad..ac586ab 100644 --- a/src/libs/plugins/pokey/main.cpp +++ b/src/libs/plugins/pokey/main.cpp @@ -248,10 +248,17 @@ bool PokeyDevicePluginStateManager::devicePWMConfiguration(libconfig::Setting *p pokeyDevice->addPWM(channel, name, description, units, leftDutyCycle, rightDutyCycle, period); _logger(LOG_INFO, " - Added PWM channel %i - %s", channel, name.c_str()); + /* + // -- uncomment to test + pokeyDevice->targetValue(name, 0.0f); - - pokeyDevice->targetValue(name, 0.5f); - pokeyDevice->targetValue(name, 1.0f); + + for (float idx = 0.0f; idx <= 1.00f; idx += 0.05f) { + pokeyDevice->targetValue(name, idx); + } + + pokeyDevice->targetValue(name, 0.0f); + */ } } } @@ -308,7 +315,11 @@ bool PokeyDevicePluginStateManager::devicePinsConfiguration(libconfig::Setting * } } else if (pinType == "DIGITAL_INPUT") { - pokeyDevice->addPin(pinName, pinNumber, pinType, 0, description); + bool invert = false; + if (iter->exists("invert")) + iter->lookupValue("invert", invert); + + pokeyDevice->addPin(pinName, pinNumber, pinType, 0, description, invert); _logger(LOG_INFO, " - [%d] Added source %s on pin %d", pinIndex, pinName.c_str(), pinNumber); } pinIndex++; diff --git a/src/libs/plugins/pokey/main.h b/src/libs/plugins/pokey/main.h index bc3d56c..ffd1cf0 100644 --- a/src/libs/plugins/pokey/main.h +++ b/src/libs/plugins/pokey/main.h @@ -34,8 +34,8 @@ class PokeyDevicePluginStateManager : public PluginStateManager bool devicePinsConfiguration(libconfig::Setting *pins, std::shared_ptr pokeyDevice); bool deviceEncodersConfiguration(libconfig::Setting *encoders, std::shared_ptr pokeyDevice); bool deviceDisplaysConfiguration(libconfig::Setting *displays, std::shared_ptr pokeyDevice); - int deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int id, std::shared_ptr pokeyDevice, std::string type); bool devicePWMConfiguration(libconfig::Setting *pwm, std::shared_ptr pokeyDevice); + int deviceDisplaysGroupsConfiguration(libconfig::Setting *displayGroups, int id, std::shared_ptr pokeyDevice, std::string type); bool addTargetToDeviceTargetList(std::string, std::shared_ptr device); std::shared_ptr targetFromDeviceTargetList(std::string); void enumerateDevices(void); diff --git a/src/libs/plugins/pokey/pokeyDevice.cpp b/src/libs/plugins/pokey/pokeyDevice.cpp index ec4b858..0de2287 100644 --- a/src/libs/plugins/pokey/pokeyDevice.cpp +++ b/src/libs/plugins/pokey/pokeyDevice.cpp @@ -7,12 +7,8 @@ using namespace std::chrono_literals; -std::mutex PokeyDevice::_BigPokeyLock; - PokeyDevice::PokeyDevice(sPoKeysNetworkDeviceSummary deviceSummary, uint8_t index) { - std::lock_guard pokeyLock(_BigPokeyLock); - _callbackArg = NULL; _enqueueCallback = NULL; @@ -64,8 +60,6 @@ void PokeyDevice::setCallbackInfo(EnqueueEventHandler enqueueCallback, void *cal void PokeyDevice::DigitalIOTimerCallback(uv_timer_t *timer, int status) { - std::lock_guard pokeyLock(_BigPokeyLock); - PokeyDevice *self = static_cast(timer->data); int encoderRetValue = PK_EncoderValuesGet(self->_pokey); @@ -145,14 +139,12 @@ void PokeyDevice::DigitalIOTimerCallback(uv_timer_t *timer, int status) } } -void PokeyDevice::addPin(std::string pinName, int pinNumber, std::string pinType, int defaultValue, std::string description) +void PokeyDevice::addPin(std::string pinName, int pinNumber, std::string pinType, int defaultValue, std::string description, bool invert) { - if (pinType == "DIGITAL_OUTPUT") { + if (pinType == "DIGITAL_OUTPUT") outputPin(pinNumber); - } - else if (pinType == "DIGITAL_INPUT") { - inputPin(pinNumber); - } + if (pinType == "DIGITAL_INPUT") + inputPin(pinNumber, invert); mapNameToPin(pinName.c_str(), pinNumber); @@ -166,11 +158,6 @@ void PokeyDevice::addPin(std::string pinName, int pinNumber, std::string pinType _pins[portNumber].description = description; } -uint32_t msToTicks(uint32_t ms) -{ - return (ms * 1000000) / 40; -} - void PokeyDevice::addPWM( uint8_t channel, std::string name, @@ -181,86 +168,9 @@ void PokeyDevice::addPWM( uint32_t period) { _pwmChannels[channel] = true; - /* - std::lock_guard pokeyLock(_BigPokeyLock); - - float ms = _pokey->info.PWMinternalFrequency / 1000; - - PK_PWMConfigurationGet(_pokey); - - // _pokey->PWM.PWMperiod = (ms * period); - _pokey->PWM.PWMperiod = 250000; - _pokey->PWM.PWMenabledChannels[channel] = true; - int ret = PK_PWMConfigurationSet(_pokey); + mapNameToPWM(name.c_str(), channel); - int left_duty = 62000; - int centre_duty = 42000; - int right_duty = 22000; - - //PK_SL_PWM_SetDuty(_pokey, channel, centre_duty); - //PK_SL_PWM_SetDuty(_pokey, channel, left_duty); - //PK_SL_PWM_SetDuty(_pokey, channel, right_duty); - int t = PK_PWMUpdate(_pokey); - - //printf(". %i\n", t); - //_pokey->PWM.PWMenabledChannels[channel] = false; - //PK_PWMConfigurationSet(_pokey); - - // // std::this_thread::sleep_for(100ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // // std::this_thread::sleep_for(100ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // // std::this_thread::sleep_for(10ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // // std::this_thread::sleep_for(10ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - std::this_thread::sleep_for(1000ms); - // PK_SL_PWM_SetDuty(_pokey, channel, left_duty); - // PK_PWMUpdate(_pokey); - // std::this_thread::sleep_for(1000ms); - - _pokey->PWM.PWMenabledChannels[channel] = true; - PK_PWMConfigurationSet(_pokey); - t = PK_SL_PWM_SetDuty(_pokey, channel, PWM_SERVO_RIGHT); - t = PK_PWMUpdate(_pokey); - std::this_thread::sleep_for(20ms); - printf(". %i\n", t); - _pokey->PWM.PWMenabledChannels[channel] = false; - PK_PWMConfigurationSet(_pokey); - - // std::this_thread::sleep_for(10ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // std::this_thread::sleep_for(10ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // std::this_thread::sleep_for(10ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - - // std::this_thread::sleep_for(10ms); - // t = PK_PWMUpdate(_pokey); - // printf(". %i\n", t); - */ - mapNameToPWM(name.c_str(), channel); _pwm[channel].name = name; _pwm[channel].description = description; _pwm[channel].units = units; @@ -352,8 +262,6 @@ bool PokeyDevice::validateEncoder(int encoderNumber) bool PokeyDevice::isEncoderCapable(int pin) { - std::lock_guard pokeyLock(_BigPokeyLock); - switch (pin) { case 1: return (bool)PK_CheckPinCapability(_pokey, 0, PK_AllPinCap_fastEncoder1A); @@ -387,8 +295,6 @@ void PokeyDevice::addEncoder( { assert(encoderNumber >= 1); - std::lock_guard pokeyLock(_BigPokeyLock); - PK_EncoderConfigurationGet(_pokey); int encoderIndex = encoderNumber - 1; @@ -450,8 +356,6 @@ void PokeyDevice::addEncoder( void PokeyDevice::addMatrixLED(int id, std::string name, std::string type) { - std::lock_guard pokeyLock(_BigPokeyLock); - PK_MatrixLEDConfigurationGet(_pokey); _matrixLED[id].name = name; _matrixLED[id].type = type; @@ -469,8 +373,6 @@ void PokeyDevice::addGroupToMatrixLED(int id, int displayId, std::string name, i void PokeyDevice::configMatrixLED(int id, int rows, int cols, int enabled) { - std::lock_guard pokeyLock(_BigPokeyLock); - _pokey->MatrixLED[id].rows = rows; _pokey->MatrixLED[id].columns = cols; _pokey->MatrixLED[id].displayEnabled = enabled; @@ -499,30 +401,22 @@ using namespace std::chrono_literals; uint32_t PokeyDevice::targetValue(std::string targetName, float value) { - //std::lock_guard pokeyLock(_BigPokeyLock); - uint8_t channel = PWMFromName(targetName); // value is percent, so calculate cycles back from left cycle count + uint32_t duty = _pwm[channel].leftDutyCycle - ((_pwm[channel].leftDutyCycle - _pwm[channel].rightDutyCycle) * value); - //_pokey->PWM.PWMenabledChannels[channel] = true; PK_SL_PWM_SetDuty(_pokey, channel, duty); PK_PWMUpdate(_pokey); - std::this_thread::sleep_for(1000ms); - //_pokey->PWM.PWMperiod = 0; - //_pokey->PWM.PWMenabledChannels[channel] = false; - //PK_PWMConfigurationSet(_pokey); + std::this_thread::sleep_for(250ms); PK_SL_PWM_SetDuty(_pokey, channel, 0); PK_PWMUpdate(_pokey); - std::this_thread::sleep_for(100ms); return 0; } uint32_t PokeyDevice::targetValue(std::string targetName, bool value) { - std::lock_guard pokeyLock(_BigPokeyLock); - uint32_t retValue = -1; uint8_t pin = pinFromName(targetName) - 1; @@ -545,8 +439,6 @@ uint32_t PokeyDevice::targetValue(std::string targetName, bool value) uint8_t PokeyDevice::displayNumber(uint8_t displayNumber, std::string targetName, int value) { - std::lock_guard pokeyLock(_BigPokeyLock); - int groupIndex = 0; for (int i = 0; i < MAX_MATRIX_LED_GROUPS; i++) { @@ -602,21 +494,24 @@ uint8_t PokeyDevice::displayNumber(uint8_t displayNumber, std::string targetName uint32_t PokeyDevice::outputPin(uint8_t pin) { - std::lock_guard pokeyLock(_BigPokeyLock); _pokey->Pins[--pin].PinFunction = PK_PinCap_digitalOutput | PK_PinCap_invertPin; return PK_PinConfigurationSet(_pokey); } -uint32_t PokeyDevice::inputPin(uint8_t pin) +uint32_t PokeyDevice::inputPin(uint8_t pin, bool invert) { - std::lock_guard pokeyLock(_BigPokeyLock); - _pokey->Pins[--pin].PinFunction = PK_PinCap_digitalInput; + int pinSetting = PK_PinCap_digitalInput; + + if (invert) { + pinSetting = pinSetting | PK_PinCap_invertPin; + } + + _pokey->Pins[--pin].PinFunction = pinSetting; return PK_PinConfigurationSet(_pokey); } int32_t PokeyDevice::name(std::string name) { - std::lock_guard pokeyLock(_BigPokeyLock); strncpy((char *)_pokey->DeviceData.DeviceName, name.c_str(), 30); return PK_DeviceNameSet(_pokey); } @@ -680,12 +575,10 @@ void PokeyDevice::mapNameToMatrixLED(std::string name, int id) bool PokeyDevice::isPinDigitalOutput(uint8_t pin) { - std::lock_guard pokeyLock(_BigPokeyLock); return (bool)PK_CheckPinCapability(_pokey, pin, PK_AllPinCap_digitalOutput); } bool PokeyDevice::isPinDigitalInput(uint8_t pin) { - std::lock_guard pokeyLock(_BigPokeyLock); return (bool)PK_CheckPinCapability(_pokey, pin, PK_AllPinCap_digitalInput); } diff --git a/src/libs/plugins/pokey/pokeyDevice.h b/src/libs/plugins/pokey/pokeyDevice.h index 11ac2a7..92e120d 100644 --- a/src/libs/plugins/pokey/pokeyDevice.h +++ b/src/libs/plugins/pokey/pokeyDevice.h @@ -15,7 +15,7 @@ #include #define DEVICE_READ_INTERVAL 100 -#define DEVICE_START_DELAY 100 +#define DEVICE_START_DELAY 1000 #define ENCODER_1 1 #define ENCODER_2 2 #define ENCODER_3 3 @@ -107,16 +107,15 @@ class PokeyDevice std::map _encoderMap; std::map _displayMap; std::map _pwmMap; - static std::mutex _BigPokeyLock; sPoKeysDevice *_pokey; void *_callbackArg; SPHANDLE _pluginInstance; device_port_t _pins[MAX_PINS]; + device_pwm_t _pwm[MAX_PWM_CHANNELS]; device_encoder_t _encoders[MAX_ENCODERS]; device_matrixLED_t _matrixLED[MAX_MATRIX_LEDS]; - device_pwm_t _pwm[MAX_PWM_CHANNELS]; uint8_t _pwmChannels[6]; uint8_t _intToDisplayRow[MAX_DIGITS]; @@ -148,8 +147,7 @@ class PokeyDevice uint32_t targetValue(std::string targetName, bool value); uint32_t targetValue(std::string targetName, int value); uint32_t targetValue(std::string targetName, float value); - - uint32_t inputPin(uint8_t pin); + uint32_t inputPin(uint8_t pin, bool invert = false); uint32_t outputPin(uint8_t pin); int32_t name(std::string name); @@ -188,7 +186,8 @@ class PokeyDevice int pinNumber, std::string pinType, int defaultValue = 0, - std::string description = "None"); + std::string description = "None", + bool invert = false); void addPWM( uint8_t pinNumber, diff --git a/src/libs/plugins/prepare3d/main.cpp b/src/libs/plugins/prepare3d/main.cpp index c6f6c1d..27b2d2a 100644 --- a/src/libs/plugins/prepare3d/main.cpp +++ b/src/libs/plugins/prepare3d/main.cpp @@ -329,7 +329,6 @@ void SimSourcePluginStateManager::processElement(char *element) else if (strncmp(type, "bool", sizeof(&type)) == 0) { el.type = CONFIG_BOOL; el.length = sizeof(uint8_t); - if (strncmp(value, "0", sizeof(el.value)) == 0) { el.value.bool_value = 0; } @@ -352,6 +351,7 @@ void SimSourcePluginStateManager::processElement(char *element) char *SimSourcePluginStateManager::getElementDataType(char identifier) { + switch (identifier) { case GAUGE_IDENTIFIER: return (char *)"float"; @@ -397,6 +397,9 @@ std::string SimSourcePluginStateManager::prosimValueString(std::shared_ptrvalue() ? 0 : 1; break; + case BOOLEAN_IDENTIFIER: + retVal = attribute->value() ? 0 : 1; + break; default: retVal = attribute->valueToString();