From 9c23f656779e240614e21dbab9d1ec6733114971 Mon Sep 17 00:00:00 2001 From: Claudio Bisegni <Claudio.Bisegni@lnf.infn.it> Date: Mon, 10 Feb 2014 14:23:01 +0100 Subject: [PATCH] removed unused example and modificed the addOption inthe GlobalConfiguration Change-Id: I5a94f1fdde74a6843a8dc108d51de0bae79f4c5c --- CMakeLists.txt | 10 +- ChaosDataService/CMakeLists.txt | 9 +- chaos/common/CMakeLists.txt | 7 +- .../configuration/GlobalConfiguration.h | 59 +- .../channel/DirectIOVirtualClientChannel.h | 2 +- example/ChaosCLI/main.cpp | 37 +- example/ChaosDeviceDriver/CMakeLists.txt | 18 - .../project.pbxproj | 522 ---------- .../contents.xcworkspacedata | 7 - .../CommunicationChannel.cpp | 53 - .../ChaosDeviceDriver/CommunicationChannel.h | 39 - example/ChaosDeviceDriver/DriverUID.h | 52 - example/ChaosDeviceDriver/ModbusProtocol.cpp | 952 ------------------ example/ChaosDeviceDriver/ModbusProtocol.h | 203 ---- example/ChaosDeviceDriver/ProtocolDriver.cpp | 70 -- example/ChaosDeviceDriver/ProtocolDriver.h | 73 -- example/ChaosDeviceDriver/SWAlim.cpp | 124 --- example/ChaosDeviceDriver/SWAlim.h | 47 - example/ChaosDeviceDriver/TcpChannel.cpp | 124 --- example/ChaosDeviceDriver/TcpChannel.h | 100 -- example/ChaosDeviceDriver/attribute.cpp | 20 - example/ChaosDeviceDriver/attribute.h | 53 - example/ChaosDeviceDriver/basichw.cpp | 73 -- example/ChaosDeviceDriver/basichw.h | 243 ----- example/ChaosDeviceDriver/device_proxy.cpp | 46 - example/ChaosDeviceDriver/device_proxy.h | 96 -- example/ChaosDeviceDriver/main.cpp | 56 -- example/ControlUnitTest/CMakeLists.txt | 29 - .../ControlUnitTest/ControlUnitExample.cpp | 107 -- .../ControlUnitTest.xcodeproj/project.pbxproj | 451 --------- example/ControlUnitTest/DummyDriver.cpp | 70 -- example/ControlUnitTest/DummyDriver.h | 44 - example/ControlUnitTest/RTWorkerCU.cpp | 298 ------ example/ControlUnitTest/RTWorkerCU.h | 123 --- example/ControlUnitTest/SCWorkerCU.cpp | 118 --- example/ControlUnitTest/SCWorkerCU.h | 71 -- example/ControlUnitTest/SWAlim/SWAlimCU.cpp | 258 ----- example/ControlUnitTest/SWAlim/SWAlimCU.h | 111 -- example/ControlUnitTest/SWAlim/main.cpp | 62 -- example/ControlUnitTest/SinWaveCommand.cpp | 186 ---- example/ControlUnitTest/SinWaveCommand.h | 78 -- 41 files changed, 88 insertions(+), 5013 deletions(-) delete mode 100644 example/ChaosDeviceDriver/CMakeLists.txt delete mode 100644 example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.pbxproj delete mode 100644 example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 example/ChaosDeviceDriver/CommunicationChannel.cpp delete mode 100644 example/ChaosDeviceDriver/CommunicationChannel.h delete mode 100644 example/ChaosDeviceDriver/DriverUID.h delete mode 100644 example/ChaosDeviceDriver/ModbusProtocol.cpp delete mode 100644 example/ChaosDeviceDriver/ModbusProtocol.h delete mode 100644 example/ChaosDeviceDriver/ProtocolDriver.cpp delete mode 100644 example/ChaosDeviceDriver/ProtocolDriver.h delete mode 100644 example/ChaosDeviceDriver/SWAlim.cpp delete mode 100644 example/ChaosDeviceDriver/SWAlim.h delete mode 100644 example/ChaosDeviceDriver/TcpChannel.cpp delete mode 100644 example/ChaosDeviceDriver/TcpChannel.h delete mode 100644 example/ChaosDeviceDriver/attribute.cpp delete mode 100644 example/ChaosDeviceDriver/attribute.h delete mode 100644 example/ChaosDeviceDriver/basichw.cpp delete mode 100644 example/ChaosDeviceDriver/basichw.h delete mode 100644 example/ChaosDeviceDriver/device_proxy.cpp delete mode 100644 example/ChaosDeviceDriver/device_proxy.h delete mode 100644 example/ChaosDeviceDriver/main.cpp delete mode 100644 example/ControlUnitTest/CMakeLists.txt delete mode 100644 example/ControlUnitTest/ControlUnitExample.cpp delete mode 100644 example/ControlUnitTest/ControlUnitTest.xcodeproj/project.pbxproj delete mode 100644 example/ControlUnitTest/DummyDriver.cpp delete mode 100644 example/ControlUnitTest/DummyDriver.h delete mode 100644 example/ControlUnitTest/RTWorkerCU.cpp delete mode 100644 example/ControlUnitTest/RTWorkerCU.h delete mode 100644 example/ControlUnitTest/SCWorkerCU.cpp delete mode 100644 example/ControlUnitTest/SCWorkerCU.h delete mode 100644 example/ControlUnitTest/SWAlim/SWAlimCU.cpp delete mode 100644 example/ControlUnitTest/SWAlim/SWAlimCU.h delete mode 100644 example/ControlUnitTest/SWAlim/main.cpp delete mode 100644 example/ControlUnitTest/SinWaveCommand.cpp delete mode 100644 example/ControlUnitTest/SinWaveCommand.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3904860fe..413bc5e3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,8 +42,8 @@ ADD_SUBDIRECTORY(chaos/ui_toolkit bin/bin_uitoolkit) message(STATUS "Configure Chaos Node Directory Service") ADD_SUBDIRECTORY(ChaosNodeDirectory bin/bin_cnd) -message(STATUS "Configure Chaos HST Service") -ADD_SUBDIRECTORY(ChaosHSTService bin/bin_chst) +message(STATUS "Configure Chaos Data Service") +ADD_SUBDIRECTORY(ChaosDataService bin/bin_chst) message(STATUS "Configure Chaos CLI") ADD_SUBDIRECTORY(example/ChaosCLI bin/chaos_cli) @@ -51,12 +51,6 @@ ADD_SUBDIRECTORY(example/ChaosCLI bin/chaos_cli) #message(STATUS "Configure Control Unit Test examples") #ADD_SUBDIRECTORY(example/ControlUnitTest bin/bin_example_cutest) -#message(STATUS "Configure UIToolkit command line example") -#ADD_SUBDIRECTORY(example/UIToolkitCMDLineExample bin/bin_example_uicmdline_test) - -#message(STATUS "Configure UIToolkit c-wrapper command line example") -#ADD_SUBDIRECTORY(example/UIToolkitCMDLineCWrapperExample bin/bin_example_uicmdline_cwrapper_test) - #message(STATUS "Configure BenchTest simulation excutable") #ADD_SUBDIRECTORY(example/BenchTest bin/bench_test) diff --git a/ChaosDataService/CMakeLists.txt b/ChaosDataService/CMakeLists.txt index b9e0ac2c3..09bfdf412 100644 --- a/ChaosDataService/CMakeLists.txt +++ b/ChaosDataService/CMakeLists.txt @@ -1,11 +1,12 @@ SET(cnd_src main.cpp) +SET(cnd_src ${cnd_src} ChaosDataService.cpp) -ADD_EXECUTABLE(ChaosHSTService ${cnd_src}) +ADD_EXECUTABLE(ChaosDataService ${cnd_src}) IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - TARGET_LINK_LIBRARIES(ChaosHSTService pthread dl chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio) + TARGET_LINK_LIBRARIES(ChaosDataService pthread dl chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio) ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - TARGET_LINK_LIBRARIES(ChaosHSTService chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio) + TARGET_LINK_LIBRARIES(ChaosDataService chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio) ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") -INSTALL_TARGETS(/bin ChaosHSTService) \ No newline at end of file +INSTALL_TARGETS(/bin ChaosDataService) \ No newline at end of file diff --git a/chaos/common/CMakeLists.txt b/chaos/common/CMakeLists.txt index a1b2f5c90..7753c37ba 100644 --- a/chaos/common/CMakeLists.txt +++ b/chaos/common/CMakeLists.txt @@ -19,9 +19,10 @@ SET(common_lib_src ${common_lib_src} event/EventClient.cpp event/AsioImplEventC event/evt_desc/CustomEventDescriptor.cpp event/channel/EventChannel.cpp event/channel/AlertEventChannel.cpp event/channel/InstrumentEventChannel.cpp) SET(common_lib_src ${common_lib_src} direct_io/DirectIOClient.cpp direct_io/DirectIOServer.cpp - direct_io/ServerFeeder.cpp direct_io/DirectIOServerEndpoint.cpp direct_io/DirectIODispatcher.cpp - direct_io/channel/DirectIOVirtualClientChannel.cpp direct_io/channel/DirectIOVirtualServerChannel.cpp - direct_io/impl/ZMQDirectIOClient.cpp direct_io/impl/ZMQDirectIOServer.cpp) + direct_io/ServerFeeder.cpp direct_io/DirectIOServerEndpoint.cpp direct_io/DirectIODispatcher.cpp + direct_io/impl/ZMQDirectIOClient.cpp direct_io/impl/ZMQDirectIOServer.cpp direct_io/impl/ZMQBaseClass.cpp + direct_io/channel/DirectIOVirtualChannel.cpp direct_io/channel/DirectIOVirtualClientChannel.cpp direct_io/channel/DirectIOVirtualServerChannel.cpp + direct_io/channel/DirectIOCDataWrapperClientChannel.cpp direct_io/channel/DirectIOCDataWrapperServerChannel.cpp) SET(common_lib_src ${common_lib_src} io/IODataDriver.cpp io/IOMemcachedDriver.cpp io/OutputMongoDataDriver.cpp) SET(common_lib_src ${common_lib_src} message/DeviceMessageChannel.cpp message/MDSMessageChannel.cpp message/MessageChannel.cpp) SET(common_lib_src ${common_lib_src} network/NetworkBroker.cpp) diff --git a/chaos/common/configuration/GlobalConfiguration.h b/chaos/common/configuration/GlobalConfiguration.h index 992aeee44..ff314b8d4 100644 --- a/chaos/common/configuration/GlobalConfiguration.h +++ b/chaos/common/configuration/GlobalConfiguration.h @@ -122,12 +122,67 @@ x = hasOption(y); void addOption(const char* name, const po::value_semantic* s, const char* description) throw (CException); + /* + Add a custom option + */ + void addOption(const char* name, + const char* description) throw (CException); /* Add a custom option */ + template<typename T> void addOption(const char* name, - const char* description) throw (CException); - + const char* description) throw (CException) { + try{//po::value<T>(&timeout)->default_value(2000) + const po::value_semantic* s = po::value<T>(); + desc.add_options()(name, s, description); + }catch (po::error &e) { + throw CException(0, e.what(), "GlobalConfiguration::addOption"); + } + } + /* + Add a custom option + */ + template<typename T> + void addOption(const char* name, + const char* description, + T default_value) throw (CException) { + try{//po::value<T>(&timeout)->default_value(2000) + const po::value_semantic* s = po::value<T>()->default_value(default_value); + desc.add_options()(name, s, description); + }catch (po::error &e) { + throw CException(0, e.what(), "GlobalConfiguration::addOption"); + } + } + /* + Add a custom option + */ + template<typename T> + void addOption(const char* name, + const char* description, + T default_value, + T *default_variable) throw (CException) { + try{//po::value<T>(&timeout)->default_value(2000) + const po::value_semantic* s = po::value<T>(default_variable)->default_value(default_value); + desc.add_options()(name, s, description); + }catch (po::error &e) { + throw CException(0, e.what(), "GlobalConfiguration::addOption"); + } + } + /* + Add a custom option + */ + template<typename T> + void addOption(const char* name, + const char* description, + T *default_variable) throw (CException) { + try{//po::value<T>(&timeout)->default_value(2000) + const po::value_semantic* s = po::value<T>(default_variable); + desc.add_options()(name, s, description); + }catch (po::error &e) { + throw CException(0, e.what(), "GlobalConfiguration::addOption"); + } + } /* return the presence of the option name */ diff --git a/chaos/common/direct_io/channel/DirectIOVirtualClientChannel.h b/chaos/common/direct_io/channel/DirectIOVirtualClientChannel.h index 5b1c049c1..4b88ad546 100644 --- a/chaos/common/direct_io/channel/DirectIOVirtualClientChannel.h +++ b/chaos/common/direct_io/channel/DirectIOVirtualClientChannel.h @@ -29,7 +29,7 @@ namespace chaos { namespace direct_io { class DirectIOClient; class DirectIOForwarder; - class DirectIODataPack; + struct DirectIODataPack; namespace channel { diff --git a/example/ChaosCLI/main.cpp b/example/ChaosCLI/main.cpp index 2a57e3479..f5df8711e 100644 --- a/example/ChaosCLI/main.cpp +++ b/example/ChaosCLI/main.cpp @@ -93,7 +93,7 @@ int checkSubmissionRule(std::string scSubmissionRule) { } else return -1; } -int main (int argc, i34mnq szchar* argv[] ) +int main (int argc, char* argv[] ) { try { int err = 0; @@ -121,24 +121,25 @@ int main (int argc, i34mnq szchar* argv[] ) CUStateKey::ControlUnitState deviceState; //! [UIToolkit Attribute Init] - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_DEVICE_ID, po::value<string>(), "The identification string of the device"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_TIMEOUT, po::value<uint32_t>(&timeout)->default_value(2000), "Timeout rpc in milliseconds"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_STATE, po::value<int>()->default_value(0), "The state to set on the device{1=init, 2=start, 3=stop, 4=deinit, 5=set schedule time, 6=submite slow command(slcu), 7=kill current command(slcu), 8=get command state by id, 9=set input channel(rtcu)}, 10=flush history state(slcu)"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SCHEDULE_TIME, po::value<long>(), "the time in microseconds for devide schedule time"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_PRINT_STATE, po::value<bool>(&printState)->default_value(false), "Print the state of the device"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_PRINT_TYPE, po::value<bool>(&printType)->default_value(false), "Print the type of the control unit of the device"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_ALIAS, po::value<string>(&scAlias)->default_value(""), "The alias associted to the command for the slow control cu"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_EXEC_CHANNEL, po::value<uint32_t>(&scExecutionChannel)->default_value(0), "TThe alias used to execute the command [it's 1 based, 0 let choice the channel to the engine]"); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<string>(OPT_DEVICE_ID, "The identification string of the device"); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<string>(OPT_DEVICE_ID, "The identification string of the device"); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint32_t>(OPT_TIMEOUT, "Timeout rpc in milliseconds", 2000, &timeout); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<int>(OPT_STATE, "The state to set on the device{1=init, 2=start, 3=stop, 4=deinit, 5=set schedule time, 6=submite slow command(slcu), 7=kill current command(slcu), 8=get command state by id, 9=set input channel(rtcu)}, 10=flush history state(slcu)", 0); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<long>(OPT_SCHEDULE_TIME, "the time in microseconds for devide schedule time"); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<bool>(OPT_PRINT_STATE, "Print the state of the device", false, &printState); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<bool>(OPT_PRINT_TYPE, "Print the type of the control unit of the device", false, &printType); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<string>(OPT_SL_ALIAS, "The alias associted to the command for the slow control cu", "", &scAlias); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint32_t>(OPT_SL_EXEC_CHANNEL, "TThe alias used to execute the command [it's 1 based, 0 let choice the channel to the engine]", 0, &scExecutionChannel); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_SUBMISSION_RULE, po::value<string>(&scSubmissionRule)->default_value("stack"), "The rule used for submit the command for the slow control cu [normal, stack, kill]"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_PRIORITY, po::value<uint32_t>(&scSubmissionPriority)->default_value(50), "The priority used for submit the command for the slow control cu"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_COMMAND_DATA, po::value<string>(&scUserData), "The bson pack (in text format) sent to the set handler of the command for the slow"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_COMMAND_ID, po::value<uint64_t>(&scCmdID), "The command identification number(cidn)"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_COMMAND_SCHEDULE_DELAY, po::value<uint32_t>(&scSubmissionSchedulerDelay)->default_value(1000000), "The millisecond beetwen a step an the next of the scheduler[in milliseconds]"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_COMMAND_SUBMISSION_RETRY_DELAY, po::value<uint32_t>(&scSubmissionSubmissionRetryDelay)->default_value(1000), "The millisecond beetwen submission checker run"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_COMMAND_SET_FEATURES_LOCK, po::value<bool>(&scFeaturesLock), "if true will lock the feature to the command modification"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_SL_COMMAND_SET_FEATURES_SCHEDULER_WAIT, po::value<uint32_t>(&scFeaturesSchedWait), "The millisecond beetwen two step of the scheduler"); - ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_RT_ATTRIBUTE_VALUE, po::value<string>(&rtAttributeValue), "The attribute and value for the input attribute in rt control unit [attribute:value]"); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<string>(OPT_SL_SUBMISSION_RULE, "The rule used for submit the command for the slow control cu [normal, stack, kill]","stack", &scSubmissionRule); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint32_t>(OPT_SL_PRIORITY, "The priority used for submit the command for the slow control cu", 50,&scSubmissionPriority); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<string>(OPT_SL_COMMAND_DATA, "The bson pack (in text format) sent to the set handler of the command for the slow", &scUserData); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint64_t>(OPT_SL_COMMAND_ID, "The command identification number(cidn)", &scCmdID); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint32_t>(OPT_SL_COMMAND_SCHEDULE_DELAY, "The millisecond beetwen a step an the next of the scheduler[in milliseconds]", 1000000, &scSubmissionSchedulerDelay); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint32_t>(OPT_SL_COMMAND_SUBMISSION_RETRY_DELAY, "The millisecond beetwen submission checker run", 1000, &scSubmissionSubmissionRetryDelay); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<bool>(OPT_SL_COMMAND_SET_FEATURES_LOCK, "if true will lock the feature to the command modification", &scFeaturesLock); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<uint32_t>(OPT_SL_COMMAND_SET_FEATURES_SCHEDULER_WAIT, "The millisecond beetwen two step of the scheduler", &scFeaturesSchedWait); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<string>(OPT_RT_ATTRIBUTE_VALUE, "The attribute and value for the input attribute in rt control unit [attribute:value]", &rtAttributeValue); //! [UIToolkit Attribute Init] diff --git a/example/ChaosDeviceDriver/CMakeLists.txt b/example/ChaosDeviceDriver/CMakeLists.txt deleted file mode 100644 index 7e7aa941f..000000000 --- a/example/ChaosDeviceDriver/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -SET(driver_lib_src attribute.cpp basichw.cpp CommunicationChannel.cpp device_proxy.cpp ModbusProtocol.cpp ProtocolDriver.cpp SWAlim.cpp TcpChannel.cpp) - -SET(common_lib_library boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup memcached msgpack msgpack-rpc mpio) - - -ADD_LIBRARY(chaosDD SHARED ${driver_lib_src}) - -set_target_properties(chaosDD PROPERTIES VERSION 1.0.0 SOVERSION 1) - -TARGET_LINK_LIBRARIES(chaosDD ${common_lib_library}) - - -FILE(GLOB files "*.h") -INSTALL(FILES ${files} DESTINATION include/chaos/dd) - -INSTALL(TARGETS chaosDD - DESTINATION "lib" - PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) diff --git a/example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.pbxproj b/example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.pbxproj deleted file mode 100644 index 74ecfaa42..000000000 --- a/example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.pbxproj +++ /dev/null @@ -1,522 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 32943668174400A7002A2BDA /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32943667174400A7002A2BDA /* main.cpp */; }; - 3294366917440100002A2BDA /* SWAlim.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53AD03C7173013A10058E5A6 /* SWAlim.cpp */; }; - 3294366A17440106002A2BDA /* TcpChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D32A1726B7F900362426 /* TcpChannel.cpp */; }; - 3294366B17440109002A2BDA /* ModbusProtocol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53962F6D1727DA790051032A /* ModbusProtocol.cpp */; }; - 3294366C1744010D002A2BDA /* basichw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D322171EB52200362426 /* basichw.cpp */; }; - 3294366D1744010F002A2BDA /* ProtocolDriver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D326171FD54600362426 /* ProtocolDriver.cpp */; }; - 3294366E17440112002A2BDA /* device_proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D31F171EB4AD00362426 /* device_proxy.cpp */; }; - 3294366F17440115002A2BDA /* CommunicationChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D31A171EB3C900362426 /* CommunicationChannel.cpp */; }; - 3294367017440118002A2BDA /* attribute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D316171EA13B00362426 /* attribute.cpp */; }; - 5356D318171EA13B00362426 /* attribute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D316171EA13B00362426 /* attribute.cpp */; }; - 5356D319171EA13B00362426 /* attribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 5356D317171EA13B00362426 /* attribute.h */; settings = {ATTRIBUTES = (); }; }; - 5356D31C171EB3C900362426 /* CommunicationChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D31A171EB3C900362426 /* CommunicationChannel.cpp */; }; - 5356D31D171EB3C900362426 /* CommunicationChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 5356D31B171EB3C900362426 /* CommunicationChannel.h */; settings = {ATTRIBUTES = (); }; }; - 5356D320171EB4AD00362426 /* device_proxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 5356D31E171EB4AD00362426 /* device_proxy.h */; settings = {ATTRIBUTES = (); }; }; - 5356D321171EB4AD00362426 /* device_proxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D31F171EB4AD00362426 /* device_proxy.cpp */; }; - 5356D324171EB52200362426 /* basichw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D322171EB52200362426 /* basichw.cpp */; }; - 5356D325171EB52200362426 /* basichw.h in Headers */ = {isa = PBXBuildFile; fileRef = 5356D323171EB52200362426 /* basichw.h */; settings = {ATTRIBUTES = (); }; }; - 5356D328171FD54600362426 /* ProtocolDriver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D326171FD54600362426 /* ProtocolDriver.cpp */; }; - 5356D329171FD54600362426 /* ProtocolDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 5356D327171FD54600362426 /* ProtocolDriver.h */; settings = {ATTRIBUTES = (); }; }; - 5356D32C1726B7F900362426 /* TcpChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5356D32A1726B7F900362426 /* TcpChannel.cpp */; }; - 5356D32D1726B7F900362426 /* TcpChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 5356D32B1726B7F900362426 /* TcpChannel.h */; settings = {ATTRIBUTES = (); }; }; - 53962F6F1727DA790051032A /* ModbusProtocol.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53962F6D1727DA790051032A /* ModbusProtocol.cpp */; }; - 53962F701727DA790051032A /* ModbusProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 53962F6E1727DA790051032A /* ModbusProtocol.h */; settings = {ATTRIBUTES = (); }; }; - 53AD03C9173013A10058E5A6 /* SWAlim.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53AD03C7173013A10058E5A6 /* SWAlim.cpp */; }; - 53AD03CA173013A10058E5A6 /* SWAlim.h in Headers */ = {isa = PBXBuildFile; fileRef = 53AD03C8173013A10058E5A6 /* SWAlim.h */; settings = {ATTRIBUTES = (); }; }; - 53AD03CB173278270058E5A6 /* libchaosDD.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5356D30B171DAB9100362426 /* libchaosDD.dylib */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - 53AD03CC173278300058E5A6 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 5356D303171DAB9100362426 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 5356D30A171DAB9100362426; - remoteInfo = chaosDeviceDriver; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 539510E11741197500ECF627 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = ""; - dstSubfolderSpec = 16; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 53AD03BC173013420058E5A6 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = usr/share/man/man1; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 32943667174400A7002A2BDA /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; }; - 3294367117440EC2002A2BDA /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; }; - 5356D30B171DAB9100362426 /* libchaosDD.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libchaosDD.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; - 5356D316171EA13B00362426 /* attribute.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = attribute.cpp; sourceTree = "<group>"; }; - 5356D317171EA13B00362426 /* attribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = attribute.h; sourceTree = "<group>"; }; - 5356D31A171EB3C900362426 /* CommunicationChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommunicationChannel.cpp; sourceTree = "<group>"; }; - 5356D31B171EB3C900362426 /* CommunicationChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommunicationChannel.h; sourceTree = "<group>"; }; - 5356D31E171EB4AD00362426 /* device_proxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = device_proxy.h; sourceTree = "<group>"; }; - 5356D31F171EB4AD00362426 /* device_proxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = device_proxy.cpp; sourceTree = "<group>"; }; - 5356D322171EB52200362426 /* basichw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = basichw.cpp; sourceTree = "<group>"; }; - 5356D323171EB52200362426 /* basichw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = basichw.h; sourceTree = "<group>"; }; - 5356D326171FD54600362426 /* ProtocolDriver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProtocolDriver.cpp; sourceTree = "<group>"; }; - 5356D327171FD54600362426 /* ProtocolDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProtocolDriver.h; sourceTree = "<group>"; }; - 5356D32A1726B7F900362426 /* TcpChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TcpChannel.cpp; sourceTree = "<group>"; }; - 5356D32B1726B7F900362426 /* TcpChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TcpChannel.h; sourceTree = "<group>"; }; - 53962F6D1727DA790051032A /* ModbusProtocol.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModbusProtocol.cpp; sourceTree = "<group>"; }; - 53962F6E1727DA790051032A /* ModbusProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModbusProtocol.h; sourceTree = "<group>"; }; - 53962F711727DBD90051032A /* DriverUID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DriverUID.h; sourceTree = "<group>"; }; - 53AD03BE173013420058E5A6 /* testSWAlim */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testSWAlim; sourceTree = BUILT_PRODUCTS_DIR; }; - 53AD03C7173013A10058E5A6 /* SWAlim.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWAlim.cpp; sourceTree = "<group>"; }; - 53AD03C8173013A10058E5A6 /* SWAlim.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWAlim.h; sourceTree = "<group>"; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 5356D308171DAB9100362426 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 53AD03BB173013420058E5A6 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 53AD03CB173278270058E5A6 /* libchaosDD.dylib in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 5356D302171DAB9100362426 = { - isa = PBXGroup; - children = ( - 3294367117440EC2002A2BDA /* CMakeLists.txt */, - 53AD03C7173013A10058E5A6 /* SWAlim.cpp */, - 53AD03C8173013A10058E5A6 /* SWAlim.h */, - 53962F711727DBD90051032A /* DriverUID.h */, - 5356D32A1726B7F900362426 /* TcpChannel.cpp */, - 5356D32B1726B7F900362426 /* TcpChannel.h */, - 53962F6D1727DA790051032A /* ModbusProtocol.cpp */, - 53962F6E1727DA790051032A /* ModbusProtocol.h */, - 5356D322171EB52200362426 /* basichw.cpp */, - 5356D323171EB52200362426 /* basichw.h */, - 5356D31E171EB4AD00362426 /* device_proxy.h */, - 5356D326171FD54600362426 /* ProtocolDriver.cpp */, - 5356D327171FD54600362426 /* ProtocolDriver.h */, - 5356D31F171EB4AD00362426 /* device_proxy.cpp */, - 5356D31A171EB3C900362426 /* CommunicationChannel.cpp */, - 5356D31B171EB3C900362426 /* CommunicationChannel.h */, - 5356D316171EA13B00362426 /* attribute.cpp */, - 5356D317171EA13B00362426 /* attribute.h */, - 32943667174400A7002A2BDA /* main.cpp */, - 5356D30C171DAB9100362426 /* Products */, - ); - sourceTree = "<group>"; - }; - 5356D30C171DAB9100362426 /* Products */ = { - isa = PBXGroup; - children = ( - 5356D30B171DAB9100362426 /* libchaosDD.dylib */, - 53AD03BE173013420058E5A6 /* testSWAlim */, - ); - name = Products; - sourceTree = "<group>"; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 5356D309171DAB9100362426 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 5356D319171EA13B00362426 /* attribute.h in Headers */, - 5356D31D171EB3C900362426 /* CommunicationChannel.h in Headers */, - 5356D320171EB4AD00362426 /* device_proxy.h in Headers */, - 5356D325171EB52200362426 /* basichw.h in Headers */, - 5356D329171FD54600362426 /* ProtocolDriver.h in Headers */, - 5356D32D1726B7F900362426 /* TcpChannel.h in Headers */, - 53962F701727DA790051032A /* ModbusProtocol.h in Headers */, - 53AD03CA173013A10058E5A6 /* SWAlim.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 5356D30A171DAB9100362426 /* chaosDD */ = { - isa = PBXNativeTarget; - buildConfigurationList = 5356D30F171DAB9100362426 /* Build configuration list for PBXNativeTarget "chaosDD" */; - buildPhases = ( - 5356D307171DAB9100362426 /* Sources */, - 5356D308171DAB9100362426 /* Frameworks */, - 5356D309171DAB9100362426 /* Headers */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = chaosDD; - productName = chaosDeviceDriver; - productReference = 5356D30B171DAB9100362426 /* libchaosDD.dylib */; - productType = "com.apple.product-type.library.dynamic"; - }; - 53AD03BD173013420058E5A6 /* testSWAlim */ = { - isa = PBXNativeTarget; - buildConfigurationList = 53AD03C6173013420058E5A6 /* Build configuration list for PBXNativeTarget "testSWAlim" */; - buildPhases = ( - 53AD03BA173013420058E5A6 /* Sources */, - 53AD03BB173013420058E5A6 /* Frameworks */, - 53AD03BC173013420058E5A6 /* CopyFiles */, - 539510E11741197500ECF627 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - 53AD03CD173278300058E5A6 /* PBXTargetDependency */, - ); - name = testSWAlim; - productName = testSWAlim; - productReference = 53AD03BE173013420058E5A6 /* testSWAlim */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 5356D303171DAB9100362426 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0460; - ORGANIZATIONNAME = "andrea michelotti"; - }; - buildConfigurationList = 5356D306171DAB9100362426 /* Build configuration list for PBXProject "ChaosDeviceDriver" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 5356D302171DAB9100362426; - productRefGroup = 5356D30C171DAB9100362426 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 5356D30A171DAB9100362426 /* chaosDD */, - 53AD03BD173013420058E5A6 /* testSWAlim */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 5356D307171DAB9100362426 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 5356D318171EA13B00362426 /* attribute.cpp in Sources */, - 5356D31C171EB3C900362426 /* CommunicationChannel.cpp in Sources */, - 5356D321171EB4AD00362426 /* device_proxy.cpp in Sources */, - 5356D324171EB52200362426 /* basichw.cpp in Sources */, - 5356D328171FD54600362426 /* ProtocolDriver.cpp in Sources */, - 5356D32C1726B7F900362426 /* TcpChannel.cpp in Sources */, - 53962F6F1727DA790051032A /* ModbusProtocol.cpp in Sources */, - 53AD03C9173013A10058E5A6 /* SWAlim.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 53AD03BA173013420058E5A6 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 32943668174400A7002A2BDA /* main.cpp in Sources */, - 3294366917440100002A2BDA /* SWAlim.cpp in Sources */, - 3294366A17440106002A2BDA /* TcpChannel.cpp in Sources */, - 3294366B17440109002A2BDA /* ModbusProtocol.cpp in Sources */, - 3294366C1744010D002A2BDA /* basichw.cpp in Sources */, - 3294366D1744010F002A2BDA /* ProtocolDriver.cpp in Sources */, - 3294366E17440112002A2BDA /* device_proxy.cpp in Sources */, - 3294366F17440115002A2BDA /* CommunicationChannel.cpp in Sources */, - 3294367017440118002A2BDA /* attribute.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - 53AD03CD173278300058E5A6 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 5356D30A171DAB9100362426 /* chaosDD */; - targetProxy = 53AD03CC173278300058E5A6 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - 5356D30D171DAB9100362426 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvmgcc42; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - 5356D30E171DAB9100362426 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_VERSION = com.apple.compilers.llvmgcc42; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.8; - SDKROOT = macosx; - }; - name = Release; - }; - 5356D310171DAB9100362426 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - EXECUTABLE_PREFIX = lib; - GCC_VERSION = ""; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - /usr/local/include, - ); - LIBRARY_SEARCH_PATHS = ( - "$(SRCROOT)/../../DerivedData/CHAOSWorkspace/Build/Products/Debug", - "$(SRCROOT)/../../usr/local/lib", - /usr/local/lib, - ); - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - ); - PRIVATE_HEADERS_FOLDER_PATH = " -"; - PRODUCT_NAME = chaosDD; - }; - name = Debug; - }; - 5356D311171DAB9100362426 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - EXECUTABLE_PREFIX = lib; - GCC_VERSION = ""; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - /usr/local/include, - ); - LIBRARY_SEARCH_PATHS = ( - "$(SRCROOT)/../../DerivedData/CHAOSWorkspace/Build/Products/Debug", - "$(SRCROOT)/../../usr/local/lib", - /usr/local/lib, - ); - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - ); - PRIVATE_HEADERS_FOLDER_PATH = " -"; - PRODUCT_NAME = chaosDD; - }; - name = Release; - }; - 53AD03C4173013420058E5A6 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - GCC_VERSION = ""; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - /usr/local/include, - ); - LIBRARY_SEARCH_PATHS = ( - "$(SRCROOT)/../../DerivedData/CHAOSWorkspace/Build/Products/Debug", - "$(SRCROOT)/../../usr/local/lib", - /usr/local/lib, - ); - ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 53AD03C5173013420058E5A6 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - GCC_VERSION = ""; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - /usr/local/include, - ); - LIBRARY_SEARCH_PATHS = ( - "$(SRCROOT)/../../DerivedData/CHAOSWorkspace/Build/Products/Debug", - "$(SRCROOT)/../../usr/local/lib", - /usr/local/lib, - ); - ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 5356D306171DAB9100362426 /* Build configuration list for PBXProject "ChaosDeviceDriver" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5356D30D171DAB9100362426 /* Debug */, - 5356D30E171DAB9100362426 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 5356D30F171DAB9100362426 /* Build configuration list for PBXNativeTarget "chaosDD" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 5356D310171DAB9100362426 /* Debug */, - 5356D311171DAB9100362426 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 53AD03C6173013420058E5A6 /* Build configuration list for PBXNativeTarget "testSWAlim" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 53AD03C4173013420058E5A6 /* Debug */, - 53AD03C5173013420058E5A6 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 5356D303171DAB9100362426 /* Project object */; -} diff --git a/example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 92cd2c9b5..000000000 --- a/example/ChaosDeviceDriver/ChaosDeviceDriver.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<Workspace - version = "1.0"> - <FileRef - location = "self:chaosDeviceDriver.xcodeproj"> - </FileRef> -</Workspace> diff --git a/example/ChaosDeviceDriver/CommunicationChannel.cpp b/example/ChaosDeviceDriver/CommunicationChannel.cpp deleted file mode 100644 index 16dc50869..000000000 --- a/example/ChaosDeviceDriver/CommunicationChannel.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// bus.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/17/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "CommunicationChannel.h" -#include "device_proxy.h" - -namespace chaos { - CommunicationChannel::CommunicationChannel(const char*name,uint32_t uid):basichw(name,uid){ - } - - int CommunicationChannel::attach(ProtocolDriver*hw){ - if(hw){ - chaos::addHWToList(m_driver_list, hw); - device_proxy* devs=hw->getDevice(); - addHWToList<device_proxy>(m_device_list, devs); - addHWToList<ProtocolDriver>(m_driver_list, hw); - return DevError::NOERROR; - } - - return DevError::PROTOCOL_INVALID; - - } - - int CommunicationChannel::detach(ProtocolDriver*hw){ - if(hw){ - device_proxy* devs=hw->getDevice(); - if( chaos::removeHWToList(m_device_list, devs)!=0){ - DERR("error removing device\n"); - return DevError::PROTOCOL_DETACH_ERROR; - } - if( chaos::removeHWToList(m_driver_list, hw)!=0){ - DERR("error removing protocol\n"); - return DevError::PROTOCOL_DETACH_ERROR; - } - } - - return DevError::PROTOCOL_INVALID; - } - - std::vector< ProtocolDriver* >& CommunicationChannel::getDriverList(){ - return m_driver_list; - } - std::vector< device_proxy* >& CommunicationChannel::getDeviceList(){ - return m_device_list; - } - - -} diff --git a/example/ChaosDeviceDriver/CommunicationChannel.h b/example/ChaosDeviceDriver/CommunicationChannel.h deleted file mode 100644 index 5aef4121b..000000000 --- a/example/ChaosDeviceDriver/CommunicationChannel.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// bus.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/17/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__CommunicationChannel__ -#define __chaosDeviceDriver__CommunicationChannel__ - -#include <iostream> -#include "device_proxy.h" -#include "ProtocolDriver.h" -#include <vector> -#include <stdint.h> -namespace chaos { - - - class CommunicationChannel:public basichw { - - protected: - // list of drivers attached to this bus - std::vector< ProtocolDriver* > m_driver_list; - std::vector< device_proxy* > m_device_list; - - - public: - std::vector< ProtocolDriver* >& getDriverList(); - std::vector< device_proxy* >& getDeviceList(); - CommunicationChannel(){} - CommunicationChannel(const char*name,uint32_t uid=ProtocolDriverUid::NO_PROTOCOL); - int attach(ProtocolDriver*hw); - int detach(ProtocolDriver*hw); - - }; -}; - -#endif /* defined(__chaosDeviceDriver__bus__) */ diff --git a/example/ChaosDeviceDriver/DriverUID.h b/example/ChaosDeviceDriver/DriverUID.h deleted file mode 100644 index 6e6aea1dc..000000000 --- a/example/ChaosDeviceDriver/DriverUID.h +++ /dev/null @@ -1,52 +0,0 @@ -// -// DriverUID.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/24/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef chaosDeviceDriver_DriverUID_h -#define chaosDeviceDriver_DriverUID_h -#ifdef DEBUG -#include <stdio.h> -#define DPRINT(x,...) printf( "[%lu]%s: " x,time(NULL),__func__,## __VA_ARGS__) -#else -#define DPRINT(x,...) -#endif - -#define DERR(x,s...) printf("## Error in %s: " x,__func__,##s) - - -namespace chaos { - - namespace CommChannelUid { - enum { - NO_CHANNEL, - TCP_CHANNEL, - RS232_CHANNEL, - RTU_CHANNEL, - I2C_CHANNEL - }; - }; - - namespace ProtocolDriverUid { - enum { - NO_PROTOCOL, - MODBUS_TCP_PROTOCOL, - MODBUS_RTU_PROTOCOL - }; - }; - - namespace DeviceUid { - enum { - NO_DEVICE, - DEVICE_SWALIM_TCP, - DEVICE_SWALIM_RTU - }; - }; - - -}; - -#endif diff --git a/example/ChaosDeviceDriver/ModbusProtocol.cpp b/example/ChaosDeviceDriver/ModbusProtocol.cpp deleted file mode 100644 index a5efbdfe4..000000000 --- a/example/ChaosDeviceDriver/ModbusProtocol.cpp +++ /dev/null @@ -1,952 +0,0 @@ -// -// ModbusProtocol.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/24/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "ModbusProtocol.h" -#include "CommunicationChannel.h" -#define READ_COIL_STATUS 1 -#define READ_INPUT_STATUS 2 -#define READ_HOLDING_REGISTERS 3 -#define READ_INPUT_REGISTERS 4 -#define FORCE_SINGLE_COIL 5 -#define PRESET_SINGLE_REGISTER 6 -#define READ_EXCEPTION_STATUS 7 -#define FETCH_COMM_EVENT_CTR 11 -#define FETCH_COMM_EVENT_LOG 12 -#define FORCE_MULTIPLE_COILS 15 -#define PRESET_MULTIPLE_REGISTERS 16 -#define REPORT_SLAVE_ID 17 -#define READ_GENERAL_REFERENCE 20 -#define WRITE_GENERAL_REFERENCE 21 -#define MASK_WRITE_REGISTER 22 -#define READ_WRITE_REGISTERS 23 -#define READ_FIFO_QUEUE 24 - -#define MODBUS_ERR_SendTCPFrame -2 -#define MODBUS_ERR_GetRTUResponse_1 -3 -#define MODBUS_ERR_GetRTUResponse_2 -4 -#define MODBUS_ERR_GetRTUResponse_3 -5 -#define MODBUS_ERR_GetRTUResponse_4 -6 -#define MODBUS_ERR_GetRTUResponse_5 -7 -#define MODBUS_ERR_GetRTUResponse_6 -8 -#define MODBUS_ERR_GetRTUResponse_8 -9 -#define MODBUS_ERR_GetRTUResponse_9 -10 -#define MODBUS_ERR_GetRTUResponse_CRC -11 -#define MODBUS_ERR_GetTCPResponse_1 -33 -#define MODBUS_ERR_GetTCPResponse_2 -34 -#define MODBUS_ERR_GetTCPResponse_3 -35 -#define MODBUS_ERR_GetTCPResponse_4 -36 -#define MODBUS_ERR_GetTCPResponse_5 -37 -#define MODBUS_ERR_GetTCPResponse_6 -38 -#define MODBUS_ERR_GetTCPResponse_8 -39 -#define MODBUS_ERR_GetTCPResponse_9 -40 -#define MODBUS_ERR_GetTCPResponse_Resp -41 -#define MODBUS_ERR_GetTCPResponse_TO -42 -#define MODBUS_ERR_GetTCPResponse_Select -43 -#define MODBUS_ERR_GetTCPResponse_Recv -44 - -#define OK 0 -#define NOTOK (-1) - -namespace chaos { - int ModbusProtocol::transaction_id=1; - - ModbusProtocol::ModbusProtocol(CommunicationChannel*comm):ProtocolDriver("Modbus driver",ProtocolDriverUid::NO_PROTOCOL,comm){ - m_state = ModBus::MODBUS_NONE; - address = -1; - - } - ModbusProtocol::ModbusProtocol(const char* name,CommunicationChannel*comm):ProtocolDriver(name,ProtocolDriverUid::NO_PROTOCOL,comm){ - m_state = ModBus::MODBUS_NONE; - address = -1; - - } - - ModbusProtocol::ModbusProtocol(const char* name):ProtocolDriver(name){ - m_state = ModBus::MODBUS_NONE; - address = -1; - - } - - long ModbusProtocol::CalculateCRC (unsigned char *frame, short frame_length, unsigned char *crc){ - /* Table of CRC values for high-order byte */ - - static unsigned char auchCRCHi[] = { - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, - 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, - 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, - 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, - 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40 - } ; - - /* Table of CRC values for low-order byte */ - - static unsigned char auchCRCLo[] = { - 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, - 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD, - 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, - 0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, - 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4, - 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, - 0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, - 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4, - 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, - 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29, - 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, - 0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, - 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60, - 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, - 0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, - 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68, - 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, - 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5, - 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, - 0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, - 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C, - 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, - 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, - 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C, - 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, - 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 - } ; - unsigned char uchCRCHi = 0xFF ; /* high CRC byte initialized */ - unsigned char uchCRCLo = 0xFF ; /* low CRC byte initialized */ - unsigned uIndex ; /* will index into CRC lookup*/ - /* table */ - - while (frame_length--) /* pass through message buffer */ - { - uIndex = uchCRCHi ^ *frame++ ; /* calculate the CRC */ - uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ; - uchCRCLo = auchCRCLo[uIndex] ; - } - - crc[0] = uchCRCHi; - crc[1] = uchCRCLo; - - return (OK) ; - } - - - long ModbusProtocol::SendFrame (unsigned char *query, short query_length, long *error){ - - if (m_uid == ProtocolDriverUid::MODBUS_RTU_PROTOCOL) - { - return(SendRTUFrame(query, query_length, error)); - } - - if (m_uid == ProtocolDriverUid::MODBUS_TCP_PROTOCOL) - { - return(SendTCPFrame(query, query_length, error)); - } - - return(NOTOK); - } - - - long ModbusProtocol::SendRTUFrame (unsigned char *query, short query_length, long *error){ - unsigned char frame[1024], crc[2]; - int iframe, i; - - iframe=0; - - frame[iframe++] = address; - for (i=0; i<query_length; i++) - { - frame[iframe++] = query[i]; - } - CalculateCRC(frame, query_length+1, crc); - frame[iframe++] = crc[0]; - frame[iframe++] = crc[1]; - - - if (m_bus->write(m_dev,(char*)frame, iframe)!=iframe) - return(NOTOK); - - return(OK); - } - - //+===================================================================== - // Function: ModbusCore::SendTCPFrame() - // - // Description: Send a Modbus frame to a node using the TCP protocol - // - // Arg(s) In: unsigned char function - function code - // short * data - data to send - // short length - number of data words to send - // - // Arg(s) Out: none - //-===================================================================== - - long ModbusProtocol::SendTCPFrame (unsigned char *query, short query_length, long *error) - { - unsigned char frame[1024]; - long i,j; - - - // transaction id - frame[0] =(transaction_id>>8)&0xff; - frame[1] = transaction_id&0xff; - // protocol - frame[2] = 0; - frame[3] = 0; - // length - frame[4] = ((query_length+1)>>8)&0xff; - frame[5] = (query_length+1)&0xff; - - // slave id - frame[6] = 0xff; - - for (i=0,j=7; i<query_length; i++,j++){ - frame[j] = query[i]; - } - DPRINT("query len:%d, trx id =%d, function %d addr:%d num bytes %d\n",(frame[4]<<8) | frame[5],(frame[0]<<8) | frame[1] ,frame[7],(frame[8]<<8)|frame[9],(frame[10]<<8)|frame[11]); -#ifdef DEBUG - dumpRequestHeader(frame); -#endif - if(m_bus->write(m_dev, (char*)frame, query_length+7)!=query_length+7){ - *error = MODBUS_ERR_SendTCPFrame; - - return NOTOK; - } - transaction_id++; - return(OK); - } - //+===================================================================== - // Function: ModbusCore::GetResponse() - // - // Description: Get response from Modbus node via serial line (RTU/ASCII) - // or TCP/IP - // - // Arg(s) In: short * data - data to send - // short length - number of data words to send - // - // Arg(s) Out: none - //-===================================================================== - - long ModbusProtocol::GetResponse (unsigned char *response, short response_length, long *error) - { - if (m_uid == ProtocolDriverUid::MODBUS_RTU_PROTOCOL) - { - return(GetRTUResponse(response, response_length, error)); - } - - if (m_uid == ProtocolDriverUid::MODBUS_TCP_PROTOCOL) - { - return(GetTCPResponse(response, response_length, error)); - } - - return(NOTOK); - } - - - void ModbusProtocol::dumpRequestHeader(unsigned char*frame){ - unsigned trx_id=(frame[0]>>8) | frame[1]; - unsigned prot_id=(frame[2]>>8) | frame[3]; - unsigned len = (frame[4]>>8) | frame[5]; - unsigned unit_id = frame[6]; - unsigned func_code = frame[7]; - unsigned start_addr = frame[8]>>8 | frame[9]; - unsigned num_regs = frame[10]>>8 | frame[11]; - - std::cout<<"Transaction ID:"<<trx_id<<std::endl; - std::cout<<"Protocol ID:"<<prot_id<<std::endl; - std::cout<<"Len:"<<len<<std::endl; - std::cout<<"unit ID:"<<unit_id<<std::endl; - std::cout<<"function code:"<<func_code<<std::endl; - std::cout<<"start addr:"<<start_addr<<std::endl; - std::cout<<"num registers:"<<num_regs<<std::endl; - - - } - - //+===================================================================== - // Function: ModbusCore::GetRTUResponse() - // - // Description: Get response from Modbus node via serial line using the - // RTU (binary) protocol - // - // Arg(s) In: short * data - data to send - // short length - number of data words to send - // - // Arg(s) Out: none - //-===================================================================== - - long ModbusProtocol::GetRTUResponse (unsigned char *response, short response_length, long *error) - { - unsigned char frame[1024], crc[2]; - int ncharexp, i; - size_t nchar; - ncharexp = 2; - if((nchar=m_bus->read(m_dev,(char*)frame,2))!=2){ - return NOTOK; - } - - if (frame[1] & 0x80) - { - - if((nchar=m_bus->read(m_dev,(char*)frame,3))!=3){ - return NOTOK; - } - - switch (frame[0]) - { - case (1) : - *error = MODBUS_ERR_GetRTUResponse_1; - break; - - case (2) : - *error = MODBUS_ERR_GetRTUResponse_2; - break; - - case (3) : - *error = MODBUS_ERR_GetRTUResponse_3; - break; - - case (4) : - *error = MODBUS_ERR_GetRTUResponse_4; - break; - - case (5) : - *error = MODBUS_ERR_GetRTUResponse_5; - break; - - case (6) : - *error = MODBUS_ERR_GetRTUResponse_6; - break; - - case (8) : - *error = MODBUS_ERR_GetRTUResponse_8; - break; - - default : - *error = MODBUS_ERR_GetRTUResponse_9; - break; - } - return(NOTOK); - - } - - response[0] = frame[1]; - /* function code echoed correctly, read rest of response */ - - ncharexp = (response_length+1); - if((nchar=m_bus->read(m_dev,(char*)frame,ncharexp))!=ncharexp){ - return NOTOK; - } - - - CalculateCRC(frame, nchar, crc); - - DPRINT("returned %d chars, crc 0x%x\n",nchar,crc); - - if ((crc[0] != frame[nchar]) && (crc[1] != frame[nchar+1])) - { - *error = MODBUS_ERR_GetRTUResponse_CRC; - return(NOTOK); - } - - for (i=1; i<response_length; i++) - { - response[i] = frame[i+1]; - } - - return(OK); - } - - //+===================================================================== - // Function: ModbusCore::GetTCPResponse() - // - // Description: Get response from Modbus node via ethernet using the - // TCP protocol - // - // Arg(s) In: short * data - data to send - // short length - number of data words to send - // - // Arg(s) Out: none - //-===================================================================== - - long ModbusProtocol::GetTCPResponse (unsigned char *response, short response_length, long *error) - { - unsigned char frame[1024]; - long status=1, i; - DPRINT("reading response of %d bytes\n",response_length); - if(m_bus->read(m_dev,(char*)frame,7+response_length)!=7+response_length){ - status = 0; - } - - if (status == 0) - { - *error = MODBUS_ERR_GetTCPResponse_Recv; - return(NOTOK); - } - - if (frame[7] & 0x80) - { - switch (frame[8]) - { - case (1) : - *error = MODBUS_ERR_GetTCPResponse_1; - break; - - case (2) : - *error = MODBUS_ERR_GetTCPResponse_2; - break; - - case (3) : - *error = MODBUS_ERR_GetTCPResponse_3; - break; - - case (4) : - *error = MODBUS_ERR_GetTCPResponse_4; - break; - - case (5) : - *error = MODBUS_ERR_GetTCPResponse_5; - break; - - case (6) : - *error = MODBUS_ERR_GetTCPResponse_6; - break; - - case (8) : - *error = MODBUS_ERR_GetTCPResponse_8; - break; - - default : - *error = MODBUS_ERR_GetTCPResponse_9; - break; - } - return(NOTOK); - - } - - for (i=0; i<response_length+1; i++) - { - response[i] = frame[i+7]; - } - - return(OK); - } - - - //+===================================================================== - // Function: ModbusCore::SendGet() - // - // Description: Send a Modbus frame and get its answer - // - // Arg(s) In: short * data - data to send - // short length - number of data words to send - // - // Arg(s) Out: none - //-===================================================================== - - long ModbusProtocol::SendGet ( - unsigned char *query, - short query_length, - unsigned char *response, - short response_length, - long *error) - { - long status; - - { - // For the serial lne protocol, protect against - // unsynchronized writing and reading - - - status = SendFrame(query, query_length, error); - if (status != OK) { - return(NOTOK); - } - - status = GetResponse(response, response_length, error); - if (status != OK){ - return(NOTOK); - } - } - - return(OK); - } - - - //+===================================================================== - // Function: ModbusCore::GetErrorMessage() - // - // Description: Returns an error string for the given error code. - // Note: Returns a handle to a static reference so the - // returned string must not be freed. - // - // Arg(s) In: long code - Error code - // - // Arg(s) Out: none - //-===================================================================== - - char *ModbusProtocol::GetErrorMessage(long code) { - - static char ret_str[1024]; - sprintf(ret_str,"Unknown error code:%ld",code); - - switch(code) - { - case MODBUS_ERR_GetRTUResponse_1: - case MODBUS_ERR_GetRTUResponse_2: - case MODBUS_ERR_GetRTUResponse_3: - case MODBUS_ERR_GetRTUResponse_4: - case MODBUS_ERR_GetRTUResponse_5: - case MODBUS_ERR_GetRTUResponse_6: - case MODBUS_ERR_GetRTUResponse_8: - case MODBUS_ERR_GetRTUResponse_9: - strcpy(ret_str,"ModbusCore::GetRTUResponse(): "); - break; - case MODBUS_ERR_GetTCPResponse_1: - case MODBUS_ERR_GetTCPResponse_2: - case MODBUS_ERR_GetTCPResponse_3: - case MODBUS_ERR_GetTCPResponse_4: - case MODBUS_ERR_GetTCPResponse_5: - case MODBUS_ERR_GetTCPResponse_6: - case MODBUS_ERR_GetTCPResponse_8: - case MODBUS_ERR_GetTCPResponse_9: - strcpy(ret_str,"ModbusCore::GetTCPResponse(): "); - break; - } - - switch(code) - { - case MODBUS_ERR_SendTCPFrame: - strcpy(ret_str,"ModbusCore::SendTCPFrame(): failed to send frame to "); - strcat(ret_str,"node using TCP protocol "); - strcat(ret_str,"(hint: check the network cable)"); - break; - - - case MODBUS_ERR_GetTCPResponse_1: - case MODBUS_ERR_GetRTUResponse_1: - strcat(ret_str,"error getting response, "); - strcat(ret_str,"illegal function (hint: contact the programmer)!"); - break; - - case MODBUS_ERR_GetTCPResponse_2: - case MODBUS_ERR_GetRTUResponse_2: - strcat(ret_str,"error getting response, "); - strcat(ret_str,"illegal data address (hint: check the module address)"); - break; - - case MODBUS_ERR_GetTCPResponse_3: - case MODBUS_ERR_GetRTUResponse_3: - strcat(ret_str,"error getting response, "); - strcat(ret_str,"illegal data value (hint: check the module data)"); - break; - - case MODBUS_ERR_GetTCPResponse_4: - case MODBUS_ERR_GetRTUResponse_4: - strcat(ret_str,"error getting response, "); - strcat(ret_str,"slave device failure (hint:check the module hardware)"); - break; - - case MODBUS_ERR_GetTCPResponse_5: - case MODBUS_ERR_GetRTUResponse_5: - strcat(ret_str,"error getting response, "); - strcat(ret_str,"answer will take some time"); - strcat(ret_str,"(hint: poll the node to get the answer)"); - break; - - case MODBUS_ERR_GetTCPResponse_6: - case MODBUS_ERR_GetRTUResponse_6: - strcat(ret_str,"slave is busy, "); - strcat(ret_str,"cannot process request "); - strcat(ret_str,"(hint: wait and then retransmit request)"); - break; - - case MODBUS_ERR_GetTCPResponse_8: - case MODBUS_ERR_GetRTUResponse_8: - strcat(ret_str,"memory parity error while reading "); - strcat(ret_str,"extended memory (hint: check the node hardware)"); - break; - - case MODBUS_ERR_GetTCPResponse_9: - case MODBUS_ERR_GetRTUResponse_9: - strcat(ret_str,"unknown exception code "); - strcat(ret_str,"(hint: check the node hardware)"); - break; - - case MODBUS_ERR_GetRTUResponse_CRC: - strcpy(ret_str,"ModbusCore::GetRTUResponse(): failed to get response "); - strcat(ret_str,"from node, error in CRC"); - break; - - case MODBUS_ERR_GetTCPResponse_Resp: - strcpy(ret_str,"ModbusCore::GetTCPResponse(): failed to get TCP "); - strcat(ret_str,"response from node "); - break; - - case MODBUS_ERR_GetTCPResponse_TO: - strcpy(ret_str,"ModbusCore::GetTCPResponse(): failed to get TCP "); - strcat(ret_str,"response from node (timeout > "); - - break; - - case MODBUS_ERR_GetTCPResponse_Select: - strcpy(ret_str,"ModbusCore::GetTCPResponse(): failed to get TCP "); - strcat(ret_str,"response from node (select() returned not for us)"); - break; - - case MODBUS_ERR_GetTCPResponse_Recv: - strcpy(ret_str,"ModbusCore::GetTCPResponse(): failed to get TCP "); - strcat(ret_str,"response from node, unexpected close of connection "); - strcat(ret_str,"at remote end"); - break; - - } - - return ret_str; - - } - - /*******************/ - int ModbusProtocol::read_registers(int code, uint16_t add,uint16_t*buf,uint16_t len16){ - long error; - short register_address, no_registers, no_bytes; - unsigned char query[5], response[1024]; - int nb_reg_to_get; // The number of registers to be read at next call. - -#define MAX_NB_REG 120 - - //--------------------------------------- - - int index = 0; - no_registers = len16; - register_address = add; - - do // Do as many readouts as required. - { - - if(no_registers > MAX_NB_REG) // Check for limit. - nb_reg_to_get = MAX_NB_REG; - else - nb_reg_to_get = no_registers; - - DPRINT("register address %d nb_reg_to_get %d\n",register_address,nb_reg_to_get); - - query[0] = code; - query[1] = register_address >> 8; - query[2] = register_address & 0xff; - query[3] = nb_reg_to_get >> 8; - query[4] = nb_reg_to_get & 0xff; - - no_bytes = nb_reg_to_get * 2; - - if(SendGet(query,5,response,no_bytes+2,&error) != OK) - { - return nb_reg_to_get - no_registers; - } - - for (int i=0; i < nb_reg_to_get; i++, index++) // Copy received data to argout - buf[index] = (response[i*2+2] << 8) + response[i*2+3]; - - register_address += nb_reg_to_get; // Update address pointer. - no_registers -= nb_reg_to_get; // Update remaining data to be read. - } - while(no_registers > 0); // Still some registers to be read? - - return nb_reg_to_get - no_registers;; - } - /******************/ - - /*******************/ - int ModbusProtocol::write_registers(int code, uint16_t add,uint16_t*buf,uint16_t len16){ - long error; - short register_address, no_registers, no_bytes; - unsigned char query[1024], response[1024]; - int nb_reg_to_get; // The number of registers to be read at next call. - -#define MAX_NB_REG 120 - - //--------------------------------------- - - int i; - no_registers = len16; - register_address = add; - - - if(no_registers > MAX_NB_REG) // Check for limit. - nb_reg_to_get = MAX_NB_REG; - else - nb_reg_to_get = no_registers; - - DPRINT("register address %d nb_reg_to_write %d\n",register_address,nb_reg_to_get); - - query[0] = code; - query[1] = register_address >> 8; - query[2] = register_address & 0xff; - query[3] = nb_reg_to_get >> 8; - query[4] = nb_reg_to_get & 0xff; - query[5] = no_registers * 2; - no_bytes = 6; - - - for (i=0; i<no_registers; i++) - { - query[6+(i*2)] = (buf[i]) >> 8; - no_bytes++; - query[6+(i*2)+1] = (buf[i]) & 0xff; - no_bytes++; - } - - if(SendGet(query,no_bytes,response,5,&error) != OK) { - return i; - } - - - return 0; - } - /******************/ - void ModbusProtocol::force_single_coil(uint16_t argin,uint8_t val){ - } - - /** - * Command ReadCoilStatus related method - * Description: Read coil (digital I/O) status. - * - * @param argin coil address - * @param status returned status - * @returns number of elements read/write - */ - int ModbusProtocol::read_coil_status(uint16_t argin,uint8_t*status){ - return 0; - } - - /** - * Command read_input_status related method - * Description: Read discrete input status. Return one boolean per array element. - * - * @param add input address - * @param buf returning buffer - * @param len16 no. of inputs - * @returns number of elements read/write - */ - int ModbusProtocol::read_input_status(uint16_t add, uint16_t*buf,uint16_t len16){ - return read_registers(READ_INPUT_STATUS,add,buf,len16); - } - /** - * Command read_holding_register related method - * Description: Read multiple 16bits registers. - * - * @param add register address - * @param buf returning buffer - * @param len16 no. of registers - * @returns number of elements read/write - */ - int ModbusProtocol::read_holding_registers(uint16_t add, uint16_t*buf,uint16_t len16){ - - return read_registers(READ_HOLDING_REGISTERS,add,buf,len16); - } - - - /** - * Command read_input_registers related method - * Description: Read Multiple 16bits input registers. - * - * @param add register address - * @param buf returning buffer - * @param len16 no. of registers - * @returns number of elements read/write - */ - int ModbusProtocol::read_input_registers(uint16_t add, uint16_t*buf,uint16_t len16){ - return read_registers(READ_INPUT_REGISTERS,add,buf,len16); - } - - - /** - * Command preset_single_register related method - * Description: Write single 16bits register. - * - * @param add register address - * @param val value - * @returns number of elements read/write - */ - int ModbusProtocol::preset_single_register(uint16_t add, uint16_t val){ - return 0; - } - - - /** - * Command read_exception_status related method - * Description: Read exception status (usually a predefined range of 8 bits - * - * @param val returned value - * @returns number of elements read/write - */ - int ModbusProtocol::read_exception_status(uint16_t*val){ - return 0; - } - - - /** - * Command fetch_comm_event_ctr related method - * Description: Fetch communications event counter. - * - * @param status return status - * @param eventcnt return event counter - * @returns number of elements read/write - */ - int ModbusProtocol::fetch_comm_event_ctr(uint16_t*status,uint16_t*eventcnt){ - return 0; - } - - /** - * Command force_multiple_coils related method - * Description: Write multiple coils (digital I/O) state. - * @param add coil address - * @param buf returning buffer - * @param len16 no. of coils - * @returns number of elements read/write - */ - int ModbusProtocol::force_multiple_coils(uint16_t add, uint8_t*buf,uint16_t len16){ - return 0; - } - - - /** - * Command read_multiple_coils related method - * Description: Read multiple coil (digital I/O) status. - * @param add register address - * @param buf returning buffer - * @param len16 no. of coils - * @returns number of elements read/write - */ - int ModbusProtocol::read_multiple_coils(uint16_t add, uint8_t*buf,uint16_t len16){ - return 0; - } - - - /** - * Command PresetMultipleRegisters related method - * Description: Write multiple 16bits registers. - * @param add register address - * @param buf returning buffer - * @param len16 no. of coils - * @returns number of elements read/write - */ - int ModbusProtocol::preset_multiple_registers(uint16_t add, uint16_t*buf,uint16_t len16){ - return write_registers(PRESET_MULTIPLE_REGISTERS,add,buf,len16); - } - - /** - * Command mask_write_register related method - * Description: Mask write a 16bits register. - * - * @param add register address - * @param andmask AND mask - * @param ormask OR mask - * @returns number of elements read/write - */ - - int ModbusProtocol::mask_write_register(uint16_t add,uint16_t andmask,uint16_t ormask){ - return 0; - } - - /** - * Command read_write_register related method - * Description: Read and Write multiple 16bits registers. - * - * @param radd register read address - * @param rbuf return read buffer - * @param rlen16 registers to read - * @param wadd register write address - * @param wbuf write buffer - * @param wlen16 registers to write - * @returns number of elements read/write - */ - int ModbusProtocol::read_write_register(uint16_t radd, uint16_t*rbuf,uint16_t rlen16,uint16_t wadd, uint16_t*wbuf,uint16_t wlen16){ - return 0; - } - - int ModbusProtocol::init(){ - if(m_dev){ - std::string add; - if(m_dev->getAttribute("address",add)){ - address = (int)strtoul(add.c_str(),0,0); - } else { - DERR("device must specify address attribute\n"); - return DevError::PROTOCOL_ERROR; - } - } - if(m_bus){ - int ret; - if(m_bus->getUID()==CommChannelUid::RTU_CHANNEL){ - m_uid = ProtocolDriverUid::MODBUS_RTU_PROTOCOL; - } else if(m_bus->getUID()==CommChannelUid::TCP_CHANNEL){ - m_uid = ProtocolDriverUid::MODBUS_TCP_PROTOCOL; - } else { - DERR("invalid protocol : %d\n",m_bus->getUID()); - return DevError::PROTOCOL_INVALID; - } - if((ret=m_bus->init())==0) - m_state = ModBus::MODBUS_CONNECTED; - - return ret; - } - DERR("invalid communication channel"); - return DevError::BUS_INVALID; - } - - - int ModbusProtocol::deinit(){ - m_state = ModBus::MODBUS_NONE; - return m_bus->deinit(); - } - - int ModbusProtocol::reset(){ - m_state = ModBus::MODBUS_NONE; - return init(); - - } - - - size_t ModbusProtocol::read(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeo,uint32_t flags){ - size_t ret; - setDeadLine(timeo); - ret = read_input_registers(add, (uint16_t*)buf,sizeb/sizeof(uint16_t)); - setDeadLine(0); - return 0; - } - - size_t ModbusProtocol::write(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeo,uint32_t flags){ - size_t ret; - setDeadLine(timeo); - ret= preset_multiple_registers(add, (uint16_t*)buf,sizeb/sizeof(uint16_t)); - setDeadLine(0); - - return ret; - } - - - - -}; \ No newline at end of file diff --git a/example/ChaosDeviceDriver/ModbusProtocol.h b/example/ChaosDeviceDriver/ModbusProtocol.h deleted file mode 100644 index 302335eb8..000000000 --- a/example/ChaosDeviceDriver/ModbusProtocol.h +++ /dev/null @@ -1,203 +0,0 @@ -// -// ModbusProtocol.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/24/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__ModbusProtocol__ -#define __chaosDeviceDriver__ModbusProtocol__ - -#include <iostream> -#include "ProtocolDriver.h" -#include "stdint.h" -namespace chaos{ - namespace ModBus { - enum ModBusState{ - MODBUS_NONE, - MODBUS_CONNECTED - }; - }; - class ModbusProtocol:public ProtocolDriver{ - - static int transaction_id; - private: - long CalculateCRC (unsigned char *frame,short frame_length,unsigned char *crc); - long SendFrame (unsigned char *frame, short frame_length, long *error); - long SendRTUFrame (unsigned char *frame, short frame_length, long *error); - long SendTCPFrame (unsigned char *frame, short frame_length, long *error); - long GetResponse (unsigned char *frame, short frame_length, long *error); - long GetRTUResponse (unsigned char *frame, short frame_length, long *error); - long GetTCPResponse (unsigned char *frame, short frame_length, long *error); - long SendGet (unsigned char *frame,short frame_length,unsigned char *response,short response_length,long *error); - int read_registers(int code, uint16_t add,uint16_t*buf,uint16_t len16); - - int write_registers(int code, uint16_t add,uint16_t*buf,uint16_t len16); - void dumpRequestHeader(unsigned char*frame); - ModBus::ModBusState m_state; - int address; - public: - ModbusProtocol(CommunicationChannel*comm); - ModbusProtocol(const char* name,CommunicationChannel*comm); - ModbusProtocol(const char* name); - char *GetErrorMessage(long code); - - /** - Protocol driver interface - */ - - /** - * Command force_single_coil related method - * Description: Write single coil (digital I/O) state. - * - * @param argin coil address, - * @param value 0/1 - * @returns - */ - - void force_single_coil(uint16_t argin,uint8_t value); - - /** - * Command ReadCoilStatus related method - * Description: Read coil (digital I/O) status. - * - * @param argin coil address - * @param status returned status - * @returns 0 on success - */ - int read_coil_status(uint16_t argin,uint8_t*status); - - /** - * Command read_input_status related method - * Description: Read discrete input status. Return one boolean per array element. - * - * @param add input address - * @param buf returning buffer - * @param len16 no. of inputs - * @returns 0 on success - */ - int read_input_status(uint16_t add, uint16_t*buf,uint16_t len16); - - /** - * Command read_holding_register related method - * Description: Read multiple 16bits registers. - * - * @param add register address - * @param buf returning buffer - * @param len16 no. of registers - * @returns 0 on success - */ - int read_holding_registers(uint16_t add, uint16_t*buf,uint16_t len16); - - /** - * Command read_input_registers related method - * Description: Read Multiple 16bits input registers. - * - * @param add register address - * @param buf returning buffer - * @param len16 no. of registers - * @returns 0 on success - */ - int read_input_registers(uint16_t add, uint16_t*buf,uint16_t len16); - - /** - * Command preset_single_register related method - * Description: Write single 16bits register. - * - * @param add register address - * @param val value - * @returns 0 on success - */ - int preset_single_register(uint16_t add, uint16_t val); - - /** - * Command read_exception_status related method - * Description: Read exception status (usually a predefined range of 8 bits - * - * @param val returned value - * @returns 0 on success - */ - int read_exception_status(uint16_t*val); - - /** - * Command fetch_comm_event_ctr related method - * Description: Fetch communications event counter. - * - * @param status return status - * @param eventcnt return event counter - * @returns 0 on success - */ - int fetch_comm_event_ctr(uint16_t*status,uint16_t*eventcnt); - /** - * Command force_multiple_coils related method - * Description: Write multiple coils (digital I/O) state. - * @param add coil address - * @param buf returning buffer - * @param len16 no. of coils - * @returns 0 on success - */ - int force_multiple_coils(uint16_t add, uint8_t*buf,uint16_t len16); - - /** - * Command read_multiple_coils related method - * Description: Read multiple coil (digital I/O) status. - * @param add register address - * @param buf returning buffer - * @param len16 no. of coils - * @returns 0 on success - */ - int read_multiple_coils(uint16_t add, uint8_t*buf,uint16_t len16); - - /** - * Command PresetMultipleRegisters related method - * Description: Write multiple 16bits registers. - * @param add register address - * @param buf returning buffer - * @param len16 no. of coils - * @returns 0 on success - */ - int preset_multiple_registers(uint16_t add, uint16_t*buf,uint16_t len16); - - /** - * Command mask_write_register related method - * Description: Mask write a 16bits register. - * - * @param add register address - * @param andmask AND mask - * @param ormask OR mask - * @returns 0 on success - */ - - int mask_write_register(uint16_t add,uint16_t andmask,uint16_t ormask); - /** - * Command read_write_register related method - * Description: Read and Write multiple 16bits registers. - * - * @param radd register read address - * @param rbuf return read buffer - * @param rlen16 registers to read - * @param wadd register write address - * @param wbuf write buffer - * @param wlen16 registers to write - * @returns 0 on success - */ - int read_write_register(uint16_t radd, uint16_t*rbuf,uint16_t rlen16,uint16_t wadd, uint16_t*wbuf,uint16_t wlen16); - - - size_t read(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeo =0,uint32_t flags=0); - - size_t write(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeo=0,uint32_t flags=0); - - - /** - HW/SW inerithed - */ - - int init(); - int deinit(); - int reset(); - - }; -}; -#endif /* defined(__chaosDeviceDriver__ModbusProtocol__) */ diff --git a/example/ChaosDeviceDriver/ProtocolDriver.cpp b/example/ChaosDeviceDriver/ProtocolDriver.cpp deleted file mode 100644 index d306c2d68..000000000 --- a/example/ChaosDeviceDriver/ProtocolDriver.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// -// ProtocolDriver.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/18/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "ProtocolDriver.h" -#include "CommunicationChannel.h" -#include "basichw.h" -namespace chaos{ - ProtocolDriver::ProtocolDriver(const char*name,uint32_t uid,CommunicationChannel*comm):m_bus(comm),basichw(name,uid){ - } - - ProtocolDriver::ProtocolDriver(const char*name):m_bus(0),basichw(name,ProtocolDriverUid::NO_PROTOCOL){ - } - - int ProtocolDriver::attach(CommunicationChannel *hw){ - if(hw){ - m_bus = hw; - if(m_dev == NULL){ - DERR("Protocol must be attached to a device"); - return DevError::BUS_ATTACH_ERROR; - } - return hw->attach(this); - } - return DevError::BUS_ATTACH_ERROR; - } - - int ProtocolDriver::detach(CommunicationChannel *hw){ - if(hw && m_bus == hw){ - m_bus = NULL; - return hw->detach(this); - } - return DevError::BUS_DETACH_ERROR; - } - - int ProtocolDriver::attach(device_proxy *hw){ - if(hw){ - m_dev = hw; - if(m_bus) - return m_bus->attach(this); - return DevError::NOERROR; - } - return DevError::DEVICE_ATTACH_ERROR; - } - - int ProtocolDriver::detach(device_proxy *hw){ - if(hw){ - int ret ; - if(m_bus){ - ret= m_bus->detach(this); - } - m_dev = NULL; - } - return DevError::DEVICE_ATTACH_ERROR; - } - - device_proxy* ProtocolDriver::getDevice(){ - return m_dev; - } - - CommunicationChannel*ProtocolDriver::getCommunicationChannel(){ - return m_bus; - } - - - -}; diff --git a/example/ChaosDeviceDriver/ProtocolDriver.h b/example/ChaosDeviceDriver/ProtocolDriver.h deleted file mode 100644 index 07c5797f3..000000000 --- a/example/ChaosDeviceDriver/ProtocolDriver.h +++ /dev/null @@ -1,73 +0,0 @@ -// -// ProtocolDriver.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/18/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__ProtocolDriver__ -#define __chaosDeviceDriver__ProtocolDriver__ - -#include <iostream> -#include "basichw.h" -#include <vector> -namespace chaos{ - class CommunicationChannel; - class device_proxy; - - - class ProtocolDriver:public basichw { - - protected: - // one protocol driver for each bus - CommunicationChannel* m_bus; - - // device attached to this protocol driver - device_proxy* m_dev; - - public: - device_proxy* getDevice(); - CommunicationChannel*getCommunicationChannel(); - - ProtocolDriver(const char*name,uint32_t uid,CommunicationChannel*comm); - ProtocolDriver(const char*name); - - /** - attach a Communication Channel - - @param hw Protocol driver to attach - @return 0 on success - */ - int attach(CommunicationChannel* hw); - - /** - detach a Communication Channel driver from this device - - @param hw to detach - @return 0 on success - */ - int detach(CommunicationChannel* hw); - - - /** - attach a device - - @param hw device to attach - @return 0 on success - */ - int attach(device_proxy* hw); - - /** - detach a device from this device - - @param hw to detach - @return 0 on success - */ - int detach(device_proxy* hw); - - - - }; -}; -#endif /* defined(__chaosDeviceDriver__ProtocolDriver__) */ diff --git a/example/ChaosDeviceDriver/SWAlim.cpp b/example/ChaosDeviceDriver/SWAlim.cpp deleted file mode 100644 index 3a74dfaae..000000000 --- a/example/ChaosDeviceDriver/SWAlim.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// -// SWAlim.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/30/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "SWAlim.h" -#include "ModbusProtocol.h" - -namespace chaos { - -#define CMD_REGISTER 1 -#define CURRENT_WRITE_REGISTER 2 -#define CURRENT_READ_REGISTER 3 -#define VOLTAGE_READ_REGISTER 4 - - - - SWAlim::SWAlim(const char*name):device_proxy(name,""){ - //create and initialize attributes of this device - setAttribute("address",std::string("")); - setAttribute("port",std::string("")); - } - SWAlim::SWAlim(const char*name,const char* busid):device_proxy(name,busid){ - // TCP busid = <address>:port - // RTU busid = <address> - size_t found = m_busid.find(":"); - if(found != std::string::npos){ - // TCP - std::string address = m_busid.substr(0,found); - std::string port =m_busid.substr(found+1); - setAttribute("address",address); - setAttribute("port",port); - // set the type - setUID(DeviceUid::DEVICE_SWALIM_TCP); - } else { - if(!m_busid.empty()){ - setAttribute("address", m_busid); - setUID(DeviceUid::DEVICE_SWALIM_RTU); - } - } - } - int SWAlim::init(){ - std::string address,port; - if(getAttribute("address",address)==false){ - DERR ("Address not set\n"); - return DevError::DEVICE_BAD_ADDRESS; - } - if(getAttribute("port",port)==false){ - setUID(DeviceUid::DEVICE_SWALIM_RTU); - } else { - setUID(DeviceUid::DEVICE_SWALIM_TCP); - } - m_busid = address + ":" + port; - return device_proxy::init(); - } - int SWAlim::deinit(){ - return device_proxy::deinit(); - } - - - int SWAlim::command(int cmdid, int val){ - int reg=1; - uint16_t v=0; - ModbusProtocol * prt = getProtocol<ModbusProtocol>(); - - if((cmdid == SET_ON) || (cmdid == SET_OFF)|| (cmdid == START) || (cmdid==MOVE_LVL)){ - v= cmdid; - reg = 1; - } else if(cmdid == SET_CURRENT){ - reg =2 ; - v = val; - } - - return prt->preset_multiple_registers(reg, &v, 1); - - } - - int SWAlim::readCurrent(int& curr){ - ModbusProtocol * prt = getProtocol<ModbusProtocol>(); - uint16_t buf; - if(prt->read_input_registers(CURRENT_READ_REGISTER, &buf, 1)==1){ - curr = buf; - } else { - - return 0; - } - return 1; - - } - int SWAlim::readVoltage(int&volt){ - ModbusProtocol * prt = getProtocol<ModbusProtocol>(); - uint16_t buf; - if(prt->read_input_registers(VOLTAGE_READ_REGISTER, &buf, 1)==1){ - volt = buf; - } else { - DERR ("Cannot read voltage\n"); - return 0; - } - return 1; - - - } - int SWAlim::on(){ - return command(SET_ON); - - } - int SWAlim::off(){ - return command(SET_OFF); - } - int SWAlim::start(){ - return command(START); - } - int SWAlim::moveLevel(){ - return command(MOVE_LVL); - } - int SWAlim::setCurrent(int curr){ - return command(SET_CURRENT,curr); - } - - -}; diff --git a/example/ChaosDeviceDriver/SWAlim.h b/example/ChaosDeviceDriver/SWAlim.h deleted file mode 100644 index d8729fc2d..000000000 --- a/example/ChaosDeviceDriver/SWAlim.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// SWAlim.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/30/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__SWAlim__ -#define __chaosDeviceDriver__SWAlim__ - -#include <iostream> -#include "device_proxy.h" - - -namespace chaos{ - class SWAlim:public device_proxy { - enum { - SET_ON = 1, - SET_OFF = 2, - START = 4, - MOVE_LVL =8, - SET_CURRENT =9, - - - }; - - private: - int command(int cmdid, int val=0); - - public: - - SWAlim(const char*name); - SWAlim(const char*name,const char* busid); - int init(); - int deinit(); - - int readCurrent(int& curr); - int readVoltage(int&volt); - int on(); - int off(); - int start(); - int moveLevel(); - int setCurrent(int curr); - }; -}; -#endif /* defined(__chaosDeviceDriver__SWAlim__) */ diff --git a/example/ChaosDeviceDriver/TcpChannel.cpp b/example/ChaosDeviceDriver/TcpChannel.cpp deleted file mode 100644 index a840e97ae..000000000 --- a/example/ChaosDeviceDriver/TcpChannel.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// -// TcpChannel.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/23/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "TcpChannel.h" -#include "basichw.h" - - - -namespace chaos { - TcpChannel::TcpChannel(const char *name):CommunicationChannel(name,CommChannelUid::TCP_CHANNEL){ - - sock = new tcp::socket(io_service); - - } - - TcpChannel::TcpChannel():CommunicationChannel("TCP Channel",CommChannelUid::TCP_CHANNEL){ - - sock = new tcp::socket(io_service); - - - } - TcpChannel::~TcpChannel(){ - deinit(); - } - - - int TcpChannel::connectTCP(const char*host,const char* port){ - if(sock){ - try{ - tcp::resolver resolver(io_service); - tcp::resolver::query query(tcp::v4(),host, port); - tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); - boost::asio::connect(*sock, endpoint_iterator); - } catch (std::exception&e){ - DERR("error connecting to \"%s\" port %s\n",host,port); - return DevError::BUS_INIT_ERROR; - } - return DevError::NOERROR; - } - - return DevError::BUS_INVALID; - } - - int TcpChannel::init(){ - std::string address,port; - // point to point connection just one driver and device - device_proxy*dev = m_driver_list[0]->getDevice(); - if(m_driver_list.size()!=1){ - DERR("invalid number of drivers attached to a point to point: %lu\n",m_driver_list.size()); - return DevError::BUS_INIT_ERROR; - } - if(sock){ - if(dev){ - //these two attribute must be defined for target device - if(dev->getAttribute("address",address)&& dev->getAttribute("port", port)){ - return connectTCP(address.c_str(), port.c_str()); - } - DERR("no \"address\" and/or \"port\" attribute found in device :\"%s\"\n",dev->getName()); - return DevError::BUS_INIT_ERROR; - - } - DERR("no valid device specified\n"); - return DevError::BUS_INIT_ERROR; - } - - return DevError::BUS_INIT_ERROR; - } - int TcpChannel::reset(){ - if(sock){ - delete sock; - } - sock = new tcp::socket(io_service); - return init(); - } - int TcpChannel::deinit(){ - if(sock){ - delete sock; - sock = NULL; - } - return 0; - } - - size_t TcpChannel::write(char *buf, uint32_t sizeb,uint32_t flags){ - size_t ret; - try{ - ret = boost::asio::write(*sock, boost::asio::buffer(buf, sizeb)); - } catch (std::exception&e){ - std::cerr << "TcpChannel::write() Exception: " << e.what() << "\n"; - return ret; - } - return ret; - } - - size_t TcpChannel::read(char *buf, uint32_t sizeb,uint32_t flags){ - size_t ret; - try{ - ret = boost::asio::read(*sock, boost::asio::buffer(buf, sizeb)); - } catch (std::exception&e){ - std::cerr << "TcpChannel::read() Exception: " << e.what() << "\n"; - return ret; - } - return ret; - - } - - size_t TcpChannel::read(chaos::basichw *hw, uint32_t add, char *buf, uint32_t sizeb,int timeo,uint32_t flags){ - setDeadLine(timeo); - size_t ret =read(buf, sizeb,flags); - setDeadLine(0); - return ret; - } - - size_t TcpChannel::write(chaos::basichw *hw, uint32_t add, char *buf, uint32_t sizeb,int timeo,uint32_t flags){ - setDeadLine(timeo); - size_t ret =write(buf, sizeb,flags); - setDeadLine(0); - return ret; - } -} \ No newline at end of file diff --git a/example/ChaosDeviceDriver/TcpChannel.h b/example/ChaosDeviceDriver/TcpChannel.h deleted file mode 100644 index 5ba1c617f..000000000 --- a/example/ChaosDeviceDriver/TcpChannel.h +++ /dev/null @@ -1,100 +0,0 @@ -// -// TcpChannel.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/23/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__TcpChannel__ -#define __chaosDeviceDriver__TcpChannel__ - -#include <iostream> -#include "CommunicationChannel.h" - -#include <boost/asio.hpp> -using boost::asio::ip::tcp; - - -namespace chaos { - class TcpChannel:public CommunicationChannel { - - private: - tcp::socket* sock; - - protected: - /** - @return connected fd - */ - - public: - TcpChannel(const char*chan_name); - TcpChannel(); - ~TcpChannel(); - - /** - */ - int connectTCP(const char*host,const char* port); - - /** - close and reopen the connection - */ - int reset(); - /** - open and connect to target - @return 0 on success - */ - int init(); - - /** - close the connection - @return 0 on success - */ - int deinit(); - - /** - read buffer from the target hw - @param buf destination buffer - @param sizeb size in byte of the read - @param flags optional read flags - */ - - size_t read(char*buf, uint32_t sizeb,uint32_t flags=0); - - /** - write buffer to the target hw - - @param buf source buffer - @param sizeb size in byte of the read - @param flags optional write flags - */ - - size_t write(char*buf, uint32_t sizeb,uint32_t flags=0); - - /** - read buffer from the target hw - - @param basic_hw target device - @param add address inside the device - @param buf destination buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional read flags - */ - size_t read(basichw*,uint32_t add, char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0); - - /** - write buffer to the target hw - - @param basic_hw target device - @param add address inside the device - @param buf source buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional write flags - */ - size_t write(basichw*,uint32_t add, char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0); - - }; -}; -#endif /* defined(__chaosDeviceDriver__TcpChannel__) */ diff --git a/example/ChaosDeviceDriver/attribute.cpp b/example/ChaosDeviceDriver/attribute.cpp deleted file mode 100644 index f209573c3..000000000 --- a/example/ChaosDeviceDriver/attribute.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// attribute.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/17/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "attribute.h" - -namespace chaos { - namespace Attribute{ - AttributeMode basic_attribute::getMode(){ - return m_mode; - } - const char* basic_attribute::getName(){ - return m_name.c_str(); - } - }; -} \ No newline at end of file diff --git a/example/ChaosDeviceDriver/attribute.h b/example/ChaosDeviceDriver/attribute.h deleted file mode 100644 index 4c174a127..000000000 --- a/example/ChaosDeviceDriver/attribute.h +++ /dev/null @@ -1,53 +0,0 @@ -// -// attribute.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/17/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__attribute__ -#define __chaosDeviceDriver__attribute__ - -#include <iostream> -#include <map> -namespace chaos{ - namespace Attribute{ - enum AttributeMode{ - RO, - WO, - RW - }; - - - class basic_attribute { - - std::string m_name; - Attribute::AttributeMode m_mode; - - public: - basic_attribute(const char*n,AttributeMode m=Attribute::RW):m_name(n),m_mode(m){ - }; - basic_attribute(){m_mode = RW;} - Attribute::AttributeMode getMode(); - const char* getName(); - - }; - - template <typename T> - class attribute:public basic_attribute { - T value; - public: - attribute(const char*name,T val,AttributeMode m=Attribute::RW):basic_attribute(name,m),value(val){}; - T& operator=(T& v){ - return value=v; - } - operator T(){return value;} - T& getValue(){return value;} - void setValue(T& val){value = val;} - }; - - }; - }; - -#endif /* defined(__chaosDeviceDriver__attribute__) */ diff --git a/example/ChaosDeviceDriver/basichw.cpp b/example/ChaosDeviceDriver/basichw.cpp deleted file mode 100644 index be7eb9a21..000000000 --- a/example/ChaosDeviceDriver/basichw.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// -// basichw.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/17/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "basichw.h" -#include <boost/bind.hpp> -#include <stdarg.h> - -namespace chaos{ - devexcept::devexcept(basichw*dev,const char * stringa,...){ - char buffer[2048]; - va_list ap; - va_start(ap,stringa); - vsnprintf(buffer,sizeof(buffer),stringa,ap); - w = dev->getName(); - w= w + std::string(":")+ stringa; - } - devexcept::devexcept(basichw*dev,std::string s){ - w = dev->getName(); - w= w + std::string(":")+ s; - } - - basichw::basichw():deadline_(io_service){ - deadline_.expires_at(boost::posix_time::pos_infin); - } - basichw::basichw(const char*n,uint32_t i):m_name(n),m_uid(i),deadline_(io_service){ - deadline_.expires_at(boost::posix_time::pos_infin); - } - - - size_t basichw::read_reg(chaos::basichw *hw, uint32_t add, char *buf, uint32_t sizeb, int timeo, uint32_t flags){ - return 0; - } - size_t basichw::write_reg(chaos::basichw *hw, uint32_t add, char *buf, uint32_t sizeb, int timeo, uint32_t flags){ - return 0; - } - - uint32_t basichw::getUID(){return m_uid;} - void basichw::setUID(uint32_t p){m_uid=p;} - - int basichw::reset(){ - return 0; - } - const char* basichw::getName(){return m_name.c_str();} - - - size_t basichw::read(basichw*a,char*buf, uint32_t sizeb,int timeo, uint32_t flags){return read(a,0,buf,sizeb,timeo,flags);} - - size_t basichw::write(basichw*a,char*buf, uint32_t sizeb,int timeo,uint32_t flags){return write(a,0,buf,sizeb,timeo,flags);} - - - void basichw::setDeadLine(int milli){ - boost::posix_time::time_duration t; - if(milli==0){ - deadline_.expires_at(boost::posix_time::pos_infin); - return; - } - t=boost::posix_time::milliseconds(milli); - deadline_.expires_from_now(t); - deadline_.async_wait(boost::bind(&basichw::deadLineHandler,this)); - - } - void basichw::deadLineHandler(){ - deadline_.expires_at(boost::posix_time::pos_infin); - throw devexcept(this,"timeout"); - } - -}; - diff --git a/example/ChaosDeviceDriver/basichw.h b/example/ChaosDeviceDriver/basichw.h deleted file mode 100644 index 18962b850..000000000 --- a/example/ChaosDeviceDriver/basichw.h +++ /dev/null @@ -1,243 +0,0 @@ -// -// basichw.h -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/17/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__basichw__ -#define __chaosDeviceDriver__basichw__ - -#include <iostream> -#include "attribute.h" -#include <stdint.h> -#include <map> -#include <vector> -#include "DriverUID.h" -#include <boost/asio.hpp> -#include <string> - -namespace chaos{ - - - class basichw { - - - protected: - boost::asio::io_service io_service; - boost::asio::deadline_timer deadline_; - - // name of device, bus, driver - std::string m_name; - // unique vendor identifier for device, bus, driver - uint32_t m_uid; - - // list of attribute of the HW - std::map<const char* ,Attribute::basic_attribute*> m_attr; - - public: - basichw(); - basichw(const char*n,uint32_t i); - - const char* getName(); - uint32_t getUID(); - void setUID(uint32_t); - /** - Set the deadline for a given operation - @param milli set the timeout in milli seconds, 0 = no timeout(default) - */ - void setDeadLine(int milli); - virtual void deadLineHandler(); - std::vector<const char*> getAttributes(){ - std::vector<const char*> ret; - std::map<const char* ,Attribute::basic_attribute*>::iterator i; - for(i=m_attr.begin();i!=m_attr.end();i++){ - ret.push_back(i->first); - } - return ret; - } - template<typename T> - bool getAttribute(const char*name,T&def){ - std::map<const char* ,Attribute::basic_attribute*>::iterator i; - if((i=m_attr.find(name))==m_attr.end()){ - return false; - } - Attribute::attribute<T> *p = (Attribute::attribute<T> *)i->second; - def = p->getValue(); - return true; - } - - template<typename T> - bool setAttribute(const char*name,T def, Attribute::AttributeMode mode=Attribute::RW){ - std::map<const char* ,Attribute::basic_attribute*>::iterator i; - - if((i=m_attr.find(name))==m_attr.end()){ - // if not exists create - Attribute::attribute<T>* pnt= new Attribute::attribute<T>(name,def,mode); - if(pnt){ - m_attr.insert(std::pair<const char*,Attribute::basic_attribute*>(name,pnt)); - // m_attr[name]=*pnt; - DPRINT("create and set attribute attribute \"%s\"\n",name); - return true; - } - DERR("## cannot create attribute \"%s\"\n",name); - return false; - } else { - if(m_attr[name]->getMode() == Attribute::RW || m_attr[name]->getMode() == Attribute::WO){ - Attribute::attribute<T> *p =(Attribute::attribute<T> *)m_attr[name]; - *p = def; - - DPRINT("setting attribute attribute \"%s\"\n",name); - - return true; - } else { - DERR("setting attribute access violation \"%s\" cannot write such attribute\n",name); - } - } - return false; - } - - - /** - reset the device,bus,driver - @return 0 on success - */ - virtual int reset(); - /** - initialize hw - @return 0 on success - */ - virtual int init()=0; - - /** - deinitialize hw - @return 0 on success - */ - virtual int deinit()=0; - - /** - read registers - - @param basic_hw target device - @param add address inside the device - @param buf destination buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional read flags - @return the number of bytes read - */ - virtual size_t read_reg(basichw*,uint32_t add, char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0); - - /** - write registers - - @param basic_hw target device - @param add address inside the device - @param buf destination buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional read flags - @return the number of bytes read - */ - virtual size_t write_reg(basichw*,uint32_t add, char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0); - - /** - read buffer from the target hw - - @param basic_hw target device - @param add address inside the device - @param buf destination buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional read flags - @return the number of bytes read - */ - virtual size_t read(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0)=0; - - /** - write buffer to the target hw - - @param basic_hw target device - @param add address inside the device - @param buf source buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional write flags - @return the number of bytes written - */ - virtual size_t write(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0)=0; - - - /** - read stream buffer from the target hw - @param basic_hw target device - @param buf destination buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional read flags - @return the number of bytes read - */ - virtual size_t read(basichw*,char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0); - - /** - write buffer to the target hw - - @param basic_hw target device - @param buf source buffer - @param sizeb size in byte of the read - @param timeomilli timeout in milliseconds - @param flags optional write flags - @return the number of bytes written - */ - virtual size_t write(basichw*,char*buf, uint32_t sizeb,int timeomilli=0,uint32_t flags=0); - - - }; - /** - add a HW to a list - @return 0 on success - */ - template<typename T> - int addHWToList(std::vector<T*>& ref,T* hw){ - typename std::vector<T*>::iterator i; - // check if already there - for(i=ref.begin();i!=ref.end();i++){ - if(*i == hw) { - return -1; - } - } - ref.push_back(hw); - return 0; - } - - /** - remove a HW to a list - @return 0 on success - */ - template<typename T> - int removeHWToList(std::vector<T*>& ref,T* hw){ - typename std::vector<T*>::iterator i; - // check if already there - for(i=ref.begin();i!=ref.end();i++){ - if(*i == hw) { - ref.erase(i); - return 0; - } - } - return -2; - } - - class devexcept: public std::exception { - - std::string w; - public: - devexcept(basichw*,const char * stringa,...); - devexcept(basichw*,std::string s); - ~devexcept() throw(){} - const char* what() {return w.c_str();}; - - }; - -}; -#endif /* defined(__chaosDeviceDriver__basichw__) */ diff --git a/example/ChaosDeviceDriver/device_proxy.cpp b/example/ChaosDeviceDriver/device_proxy.cpp deleted file mode 100644 index 8118923b0..000000000 --- a/example/ChaosDeviceDriver/device_proxy.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// -// Device.cpp -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/16/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include "device_proxy.h" - -namespace chaos { - const char* device_proxy::getBusID(){ - return m_busid.c_str(); - } - void device_proxy::setBusID(const char*busid){ - m_busid = busid; - } -int device_proxy::attach(ProtocolDriver* hw){ - if(hw){ - m_driver = hw; - return hw->attach(this); - } - return DevError::DEVICE_ATTACH_ERROR; -} - - int device_proxy::detach(ProtocolDriver* hw){ - if(hw==m_driver){ - m_driver = NULL; - return hw->detach(this); - } - return DevError::DEVICE_DETACH_ERROR; - } - - int device_proxy::init(){ - if (m_driver) - return m_driver->init(); - return DevError::PROTOCOL_INVALID; - - } - int device_proxy::deinit(){ - if (m_driver) - return m_driver->init(); - return DevError::PROTOCOL_INVALID; - - } -} diff --git a/example/ChaosDeviceDriver/device_proxy.h b/example/ChaosDeviceDriver/device_proxy.h deleted file mode 100644 index 31fdf05f8..000000000 --- a/example/ChaosDeviceDriver/device_proxy.h +++ /dev/null @@ -1,96 +0,0 @@ -// -// device_proxy -// chaosDeviceDriver -// -// Created by andrea michelotti on 4/16/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#ifndef __chaosDeviceDriver__Device__ -#define __chaosDeviceDriver__Device__ - -#include <iostream> -#include <map> -#include <stdint.h> -#include "DriverUID.h" -#include "basichw.h" -#include "ProtocolDriver.h" -#include "CommunicationChannel.h" -#include <stdio.h> - -namespace chaos { - - namespace DevError { - enum { - NOERROR, - - PROTOCOL_ERROR, - PROTOCOL_ATTACH_ERROR, - PROTOCOL_DETACH_ERROR, - PROTOCOL_INVALID, - PROTOCOL_NOFOUND, - - BUS_ERROR, - BUS_ATTACH_ERROR, - BUS_DETACH_ERROR, - BUS_INIT_ERROR, - BUS_WRITE_ERROR, - BUS_INVALID, - - DEVICE_ERROR, - DEVICE_BAD_ADDRESS, - DEVICE_ATTACH_ERROR, - DEVICE_DETACH_ERROR, - DEVICE_INVALID - }; - }; - class device_proxy : public basichw { - - protected: - // identifier of the device inside a bus - std::string m_busid; - // attached driver - ProtocolDriver* m_driver; - - public: - device_proxy(){m_driver=NULL;} - device_proxy(const char*n,const char*_busid,uint32_t uid=DeviceUid::NO_DEVICE):basichw(n,uid),m_busid(_busid){ - - } - - device_proxy(const char*n):basichw(n,DeviceUid::NO_DEVICE){ - - } - - const char* getBusID(); - void setBusID(const char*busid); - template<typename T> - T* getProtocol(){return static_cast<T*>(m_driver);} - - /** - attach a Protocol driver - - @param hw Protocol driver to attach - @return 0 on success - */ - int attach(ProtocolDriver* hw); - - /** - detach a Protocol driver from this device - - @param hw to detach - @return 0 on success - */ - int detach(ProtocolDriver* hw); - - int init(); - int deinit(); - - size_t read(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeo=0,uint32_t flags=0){return 0;} - - size_t write(basichw*,uint32_t add,char*buf, uint32_t sizeb,int timeo=0,uint32_t flags=0){return 0;} - - }; -}; - -#endif /* defined(__chaosDeviceDriver__Device__) */ diff --git a/example/ChaosDeviceDriver/main.cpp b/example/ChaosDeviceDriver/main.cpp deleted file mode 100644 index ff4ef24b3..000000000 --- a/example/ChaosDeviceDriver/main.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// main.cpp -// testSWAlim -// -// Created by andrea michelotti on 4/30/13. -// Copyright (c) 2013 andrea michelotti. All rights reserved. -// - -#include <iostream> -//#include <curses.h> -#include "SWAlim.h" -#include "ModbusProtocol.h" -#include "TcpChannel.h" -#include <stdio.h> -using namespace chaos; - -void run(SWAlim& myalim){ - int current=0,voltage=0; - int c=0; - while(1){ - - myalim.readCurrent(current); - myalim.readVoltage(voltage); - printf("(1) on (2) off (3) start (4) lvl (5) set current, current: %8d, voltage %8d\r",current,voltage); - fflush(stdout); - //c = std::cin.get(); - //c=getch(); - if(c == '1') myalim.on(); - if(c == '2') myalim.off(); - if(c == '3') myalim.start(); - if(c == '4') myalim.moveLevel(); - if(c == '5') { - int current; - printf("\nset current to:"); - scanf("%d",¤t); - myalim.setCurrent(current); - printf("\n"); - } - } -} - -int main(int argc, const char * argv[]) { - // insert code here... - TcpChannel tcpChan("LocalTcp"); - ModbusProtocol prot("my modbus"); - SWAlim myalim("SWAlim00","localhost:8083"); - - prot.attach(&tcpChan); - myalim.attach(&prot); - if(myalim.init()==0){ - run(myalim); - } - - return 0; -} - diff --git a/example/ControlUnitTest/CMakeLists.txt b/example/ControlUnitTest/CMakeLists.txt deleted file mode 100644 index 7535df910..000000000 --- a/example/ControlUnitTest/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -option(BUILD_FORCE_32 "Set to ON to enable 32 bit compilation" OFF) - -IF( ($ENV{CHAOS32}) OR (BUILD_FORCE_32) ) - MESSAGE(STATUS "Enabling 32 bit Compilation") - set (CMAKE_C_FLAGS "-m32") - set (CMAKE_CXX_FLAGS "-m32") - set (CMAKE_LINK_FLAGS "-m32") -ENDIF() -ADD_DEFINITIONS(-g -O2 -Wall) - -SET(cutest_exe_src ControlUnitExample.cpp RTWorkerCU.cpp SCWorkerCU.cpp SinWaveCommand.cpp DummyDriver.cpp) -SET(swalim_src SWAlim/main.cpp SWAlim/SWAlimCU.cpp) - -INCLUDE_DIRECTORIES(. ${PROJECT_SOURCE_DIR}/../../usr/local/include /usr/local/include /usr/include ${PROJECT_SOURCE_DIR}/example/ChaosDeviceDriver/) -LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/../../usr/local/lib /usr/local/lib) - -ADD_EXECUTABLE(ControlUnitTest ${cutest_exe_src}) -ADD_EXECUTABLE(CUSWAlim ${swalim_src}) - -IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - TARGET_LINK_LIBRARIES(ControlUnitTest pthread chaos_cutoolkit chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio) - TARGET_LINK_LIBRARIES(CUSWAlim pthread chaos_cutoolkit chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio chaosDD) -ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - TARGET_LINK_LIBRARIES(ControlUnitTest chaos_cutoolkit chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio) - TARGET_LINK_LIBRARIES(CUSWAlim chaos_cutoolkit chaos_common boost_program_options boost_system boost_thread boost_chrono boost_regex boost_log boost_log_setup boost_atomic memcached msgpack msgpack-rpc mpio chaosDD) -ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") - -INSTALL_TARGETS(/bin ControlUnitTest) \ No newline at end of file diff --git a/example/ControlUnitTest/ControlUnitExample.cpp b/example/ControlUnitTest/ControlUnitExample.cpp deleted file mode 100644 index 659d3a08f..000000000 --- a/example/ControlUnitTest/ControlUnitExample.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ControlUnitTest.cpp - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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. - */ - -#include "RTWorkerCU.h" -#include "SCWorkerCU.h" -#include "DummyDriver.h" - -#include <chaos/common/chaos_constants.h> -#include <chaos/cu_toolkit/ChaosCUToolkit.h> - -#include <iostream> -#include <string> - -/*! \page page_example_cue ChaosCUToolkit Example - * \section page_example_cue_sec An basic usage for the ChaosCUToolkit package - * - * \subsection page_example_cue_sec_sub1 Toolkit usage - * ChaosCUToolkit has private constructor so it can be used only using singleton pattern, - * the only way to get unique isntance is; ChaosCUToolkit::getInstance(). So the first call of - * getInstance method will provide the CUToolkit and Common layer initial setup. - * \snippet example/ControlUnitTest/ControlUnitExample.cpp Custom Option - * - * Then it must be initialized, in this method can be passed the main argument - * of a c or c++ programm - * \snippet example/ControlUnitTest/ControlUnitExample.cpp CUTOOLKIT Init - * - * At this point the custom implementation af a control unit cab be added to framework - * \snippet example/ControlUnitTest/ControlUnitExample.cpp Adding the CustomControlUnit - * - * At this step the framework can be started, it will perform all needs, comunicate with - * Metadata Server and all chaos workflow will start. The start method call will block the main execution - * until the chaos workflow of this isnstance need to be online - * \snippet example/ControlUnitTest/ControlUnitExample.cpp Starting the Framework - */ -using namespace std; -using namespace chaos; -using namespace chaos::cu; - -namespace common_plugin = chaos::common::plugin; -namespace common_utility = chaos::common::utility; -namespace cu_driver_manager = chaos::cu::driver_manager; - -#define OPT_CUSTOM_DEVICE_ID_A "device_a" -#define OPT_CUSTOM_DEVICE_ID_B "device_b" - - -int main (int argc, char* argv[] ) -{ - string tmpDeviceID; - //! [Custom Option] - try { - ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_CUSTOM_DEVICE_ID_A, po::value<string>(), "Real Time wave simultaion Device A identification string"); - ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_CUSTOM_DEVICE_ID_B, po::value<string>(), "Slow Controlled wave simulation Device B identification string"); - //! [Custom Option] - - //! [Driver Registration] - MATERIALIZE_INSTANCE_AND_INSPECTOR(DummyDriver) - cu_driver_manager::DriverManager::getInstance()->registerDriver(DummyDriverInstancer, DummyDriverInspector); - //! [Driver Registration] - - ChaosCUToolkit::getInstance()->init(argc, argv); - //! [CUTOOLKIT Init] - - //! [Adding the CustomControlUnit] - if(ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_CUSTOM_DEVICE_ID_A)){ - tmpDeviceID = ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->getOption<string>(OPT_CUSTOM_DEVICE_ID_A); - ChaosCUToolkit::getInstance()->addControlUnit(new RTWorkerCU(tmpDeviceID)); - } - - if(ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_CUSTOM_DEVICE_ID_B)){ - tmpDeviceID = ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->getOption<string>(OPT_CUSTOM_DEVICE_ID_B); - ChaosCUToolkit::getInstance()->addControlUnit(new SCWorkerCU(tmpDeviceID)); - } - //! [Adding the CustomControlUnit] - - //! [Starting the Framework] - ChaosCUToolkit::getInstance()->start(); - //! [Starting the Framework] - } catch (CException& e) { - cerr<<"Exception::"<<endl; - std::cerr<< "in:"<<e.errorDomain << std::endl; - std::cerr<< "cause:"<<e.errorMessage << std::endl; - } catch (program_options::error &e){ - cerr << "Unable to parse command line: " << e.what() << endl; - } catch (...){ - cerr << "unexpected exception caught.. " << endl; - } - - return 0; -} diff --git a/example/ControlUnitTest/ControlUnitTest.xcodeproj/project.pbxproj b/example/ControlUnitTest/ControlUnitTest.xcodeproj/project.pbxproj deleted file mode 100644 index c0e2d8612..000000000 --- a/example/ControlUnitTest/ControlUnitTest.xcodeproj/project.pbxproj +++ /dev/null @@ -1,451 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 321B9F2617B24D650070D32D /* DummyDriver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 321B9F2417B24D650070D32D /* DummyDriver.cpp */; }; - 3252C9DB179330A800A17C7C /* SinWaveCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3252C9D9179330A800A17C7C /* SinWaveCommand.cpp */; }; - 32F22423179AFF3600853F62 /* SCWorkerCU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32F22421179AFF3500853F62 /* SCWorkerCU.cpp */; }; - 32F7449C14B49CFA0025638B /* ControlUnitExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32F7449914B49CFA0025638B /* ControlUnitExample.cpp */; }; - 32F7449D14B49CFA0025638B /* RTWorkerCU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32F7449A14B49CFA0025638B /* RTWorkerCU.cpp */; }; - 539510D7174116F500ECF627 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539510D6174116F500ECF627 /* main.cpp */; }; - 539510DF1741174400ECF627 /* SWAlimCU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539510DD1741174400ECF627 /* SWAlimCU.cpp */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 321B9F2417B24D650070D32D /* DummyDriver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DummyDriver.cpp; sourceTree = SOURCE_ROOT; }; - 321B9F2517B24D650070D32D /* DummyDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DummyDriver.h; sourceTree = SOURCE_ROOT; }; - 3252C9D9179330A800A17C7C /* SinWaveCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SinWaveCommand.cpp; sourceTree = SOURCE_ROOT; }; - 3252C9DA179330A800A17C7C /* SinWaveCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SinWaveCommand.h; sourceTree = SOURCE_ROOT; }; - 32BE864A15A0E3C500818C39 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = SOURCE_ROOT; }; - 32F22421179AFF3500853F62 /* SCWorkerCU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SCWorkerCU.cpp; sourceTree = SOURCE_ROOT; }; - 32F22422179AFF3500853F62 /* SCWorkerCU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCWorkerCU.h; sourceTree = SOURCE_ROOT; }; - 32F7448F14B49CCB0025638B /* ControlUnitTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ControlUnitTest; sourceTree = BUILT_PRODUCTS_DIR; }; - 32F7449914B49CFA0025638B /* ControlUnitExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = ControlUnitExample.cpp; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - 32F7449A14B49CFA0025638B /* RTWorkerCU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = RTWorkerCU.cpp; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - 32F7449B14B49CFA0025638B /* RTWorkerCU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RTWorkerCU.h; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; - 539510D4174116F500ECF627 /* CUSWAlim */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CUSWAlim; sourceTree = BUILT_PRODUCTS_DIR; }; - 539510D6174116F500ECF627 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; }; - 539510DD1741174400ECF627 /* SWAlimCU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SWAlimCU.cpp; sourceTree = "<group>"; }; - 539510DE1741174400ECF627 /* SWAlimCU.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SWAlimCU.h; sourceTree = "<group>"; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 32F7448C14B49CCB0025638B /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 539510D1174116F500ECF627 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 3260279D14B309ED00C906CE = { - isa = PBXGroup; - children = ( - 32BE864A15A0E3C500818C39 /* CMakeLists.txt */, - 326DB50714B3B7890018A8D0 /* ControlUnitTest */, - 539510D5174116F500ECF627 /* SWAlim */, - 326027B914B30A2400C906CE /* Products */, - ); - sourceTree = "<group>"; - }; - 326027B914B30A2400C906CE /* Products */ = { - isa = PBXGroup; - children = ( - 32F7448F14B49CCB0025638B /* ControlUnitTest */, - 539510D4174116F500ECF627 /* CUSWAlim */, - ); - name = Products; - sourceTree = "<group>"; - }; - 326DB50714B3B7890018A8D0 /* ControlUnitTest */ = { - isa = PBXGroup; - children = ( - 32F7449914B49CFA0025638B /* ControlUnitExample.cpp */, - 32F7449A14B49CFA0025638B /* RTWorkerCU.cpp */, - 32F7449B14B49CFA0025638B /* RTWorkerCU.h */, - 32F22421179AFF3500853F62 /* SCWorkerCU.cpp */, - 32F22422179AFF3500853F62 /* SCWorkerCU.h */, - 3252C9D9179330A800A17C7C /* SinWaveCommand.cpp */, - 3252C9DA179330A800A17C7C /* SinWaveCommand.h */, - 321B9F2417B24D650070D32D /* DummyDriver.cpp */, - 321B9F2517B24D650070D32D /* DummyDriver.h */, - ); - path = ControlUnitTest; - sourceTree = "<group>"; - }; - 539510D5174116F500ECF627 /* SWAlim */ = { - isa = PBXGroup; - children = ( - 539510DD1741174400ECF627 /* SWAlimCU.cpp */, - 539510DE1741174400ECF627 /* SWAlimCU.h */, - 539510D6174116F500ECF627 /* main.cpp */, - ); - path = SWAlim; - sourceTree = "<group>"; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 32F7448E14B49CCB0025638B /* ControlUnitTest */ = { - isa = PBXNativeTarget; - buildConfigurationList = 32F7449614B49CCC0025638B /* Build configuration list for PBXNativeTarget "ControlUnitTest" */; - buildPhases = ( - 32F7448B14B49CCB0025638B /* Sources */, - 32F7448C14B49CCB0025638B /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = ControlUnitTest; - productName = ControlUnitTest; - productReference = 32F7448F14B49CCB0025638B /* ControlUnitTest */; - productType = "com.apple.product-type.tool"; - }; - 539510D3174116F500ECF627 /* CUSWAlim */ = { - isa = PBXNativeTarget; - buildConfigurationList = 539510DA174116F500ECF627 /* Build configuration list for PBXNativeTarget "CUSWAlim" */; - buildPhases = ( - 539510D0174116F500ECF627 /* Sources */, - 539510D1174116F500ECF627 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = CUSWAlim; - productName = SWAlim; - productReference = 539510D4174116F500ECF627 /* CUSWAlim */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 3260279F14B309ED00C906CE /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0430; - ORGANIZATIONNAME = INFN; - }; - buildConfigurationList = 326027A214B309ED00C906CE /* Build configuration list for PBXProject "ControlUnitTest" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 3260279D14B309ED00C906CE; - productRefGroup = 326027B914B30A2400C906CE /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 32F7448E14B49CCB0025638B /* ControlUnitTest */, - 539510D3174116F500ECF627 /* CUSWAlim */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 32F7448B14B49CCB0025638B /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 32F7449C14B49CFA0025638B /* ControlUnitExample.cpp in Sources */, - 32F7449D14B49CFA0025638B /* RTWorkerCU.cpp in Sources */, - 3252C9DB179330A800A17C7C /* SinWaveCommand.cpp in Sources */, - 32F22423179AFF3600853F62 /* SCWorkerCU.cpp in Sources */, - 321B9F2617B24D650070D32D /* DummyDriver.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 539510D0174116F500ECF627 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 539510D7174116F500ECF627 /* main.cpp in Sources */, - 539510DF1741174400ECF627 /* SWAlimCU.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 326027A414B309ED00C906CE /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_PREPROCESSOR_DEFINITIONS = BOOST_ALL_DYN_LINK; - }; - name = Debug; - }; - 326027A514B309ED00C906CE /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_PREPROCESSOR_DEFINITIONS = BOOST_ALL_DYN_LINK; - }; - name = Release; - }; - 32F7449714B49CCC0025638B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = ""; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - /usr/local/include, - ); - MACOSX_DEPLOYMENT_TARGET = 10.8; - ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 32F7449814B49CCC0025638B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_PREPROCESSOR_DEFINITIONS = ""; - GCC_VERSION = ""; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - /usr/local/include, - ); - MACOSX_DEPLOYMENT_TARGET = 10.8; - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Release; - }; - 539510DB174116F500ECF627 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = ""; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - "$(SRCROOT)/../../example/ChaosDeviceDriver", - /usr/local/include, - ); - LIBRARY_SEARCH_PATHS = ( - "$(SRCROOT)/../../DerivedData/CHAOSWorkspace/Build/Products/Debug", - "$(SRCROOT)/../../usr/local/lib", - /usr/local/lib, - ); - MACOSX_DEPLOYMENT_TARGET = 10.8; - ONLY_ACTIVE_ARCH = YES; - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - "-lchaosDD", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx10.8; - }; - name = Debug; - }; - 539510DC174116F500ECF627 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++98"; - CLANG_CXX_LIBRARY = "libstdc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_VERSION = ""; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - ../../, - ../../usr/local/include, - "$(SRCROOT)/../../example/ChaosDeviceDriver", - /usr/local/include, - ); - LIBRARY_SEARCH_PATHS = ( - "$(SRCROOT)/../../DerivedData/CHAOSWorkspace/Build/Products/Debug", - "$(SRCROOT)/../../usr/local/lib", - /usr/local/lib, - ); - MACOSX_DEPLOYMENT_TARGET = 10.8; - OTHER_LDFLAGS = ( - "-lboost_chrono", - "-lmemcached", - "-lboost_system", - "-lboost_thread", - "-lboost_program_options", - "-lboost_regex", - "-lboost_filesystem", - "-lmpio", - "-lmsgpack", - "-lmsgpack-rpc", - "-lboost_log", - "-lboost_log_setup", - "-lchaos_cutoolkit", - "-lchaos_common", - "-lchaosDD", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx10.8; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 326027A214B309ED00C906CE /* Build configuration list for PBXProject "ControlUnitTest" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 326027A414B309ED00C906CE /* Debug */, - 326027A514B309ED00C906CE /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 32F7449614B49CCC0025638B /* Build configuration list for PBXNativeTarget "ControlUnitTest" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 32F7449714B49CCC0025638B /* Debug */, - 32F7449814B49CCC0025638B /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 539510DA174116F500ECF627 /* Build configuration list for PBXNativeTarget "CUSWAlim" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 539510DB174116F500ECF627 /* Debug */, - 539510DC174116F500ECF627 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 3260279F14B309ED00C906CE /* Project object */; -} diff --git a/example/ControlUnitTest/DummyDriver.cpp b/example/ControlUnitTest/DummyDriver.cpp deleted file mode 100644 index b3a220931..000000000 --- a/example/ControlUnitTest/DummyDriver.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * DummyDriver.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2013 INFN, National Institute of Nuclear Physics - * - * 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. - */ -#include "DummyDriver.h" - -#include <string> - -#include <chaos/cu_toolkit/driver_manager/driver/AbstractDriverPlugin.h> - -#include <boost/regex.hpp> - -namespace cu_driver = chaos::cu::driver_manager::driver; - -#define SL7DRVLAPP_ LAPP_ << "[DummyDriver] " -#define SL7DRVLDBG_ LDBG_ << "[DummyDriver] " -#define SL7DRVLERR_ LERR_ << "[DummyDriver] " - - -//! Regular expression for check server hostname and port -static const boost::regex PlcHostNameAndPort("([a-zA-Z0-9]+(.[a-zA-Z0-9]+)+):([0-9]{3,5})"); -//! Regular expression for check server ip and port -static const boost::regex PlcIpAnPort("(\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b):([0-9]{4,5})"); - - -//GET_PLUGIN_CLASS_DEFINITION -//we need only to define the driver because we don't are makeing a plugin -OPEN_CU_DRIVER_PLUGIN_CLASS_DEFINITION(DummyDriver, 1.0.0, DummyDriver) -REGISTER_CU_DRIVER_PLUGIN_CLASS_INIT_ATTRIBUTE(Sl7Drv,http_address/dnsname:port) -CLOSE_CU_DRIVER_PLUGIN_CLASS_DEFINITION - -//default constructor definition -DEFAULT_CU_DRIVER_PLUGIN_CONSTRUCTOR(DummyDriver) { - -} - -//default descrutcor -DummyDriver::~DummyDriver() { - -} - -void DummyDriver::driverInit(const char *initParameter) throw(chaos::CException) { - SL7DRVLAPP_ << "Init dummy driver"; -} - -void DummyDriver::driverDeinit() throw(chaos::CException) { - SL7DRVLAPP_ << "Deinit dummy driver"; - -} - -//! Execute a command -cu_driver::MsgManagmentResultType::MsgManagmentResult DummyDriver::execOpcode(cu_driver::DrvMsgPtr cmd) { - cu_driver::MsgManagmentResultType::MsgManagmentResult result = cu_driver::MsgManagmentResultType::MMR_EXECUTED; - return result; -} \ No newline at end of file diff --git a/example/ControlUnitTest/DummyDriver.h b/example/ControlUnitTest/DummyDriver.h deleted file mode 100644 index fefbefd42..000000000 --- a/example/ControlUnitTest/DummyDriver.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * DummyDriver.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2013 INFN, National Institute of Nuclear Physics - * - * 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 __ControlUnitTest__TestDeviceDriver__ -#define __ControlUnitTest__TestDeviceDriver__ - -#include <chaos/cu_toolkit/driver_manager/driver/AbstractDriverPlugin.h> - -namespace cu_driver = chaos::cu::driver_manager::driver; - -DEFINE_CU_DRIVER_DEFINITION_PROTOTYPE(DummyDriver) - -/* - driver definition - */ -class DummyDriver: ADD_CU_DRIVER_PLUGIN_SUPERCLASS { - - - void driverInit(const char *initParameter) throw(chaos::CException); - void driverDeinit() throw(chaos::CException); -public: - DummyDriver(); - ~DummyDriver(); - //! Execute a command - cu_driver::MsgManagmentResultType::MsgManagmentResult execOpcode(cu_driver::DrvMsgPtr cmd); -}; - -#endif /* defined(__ControlUnitTest__DummyDriver__) */ diff --git a/example/ControlUnitTest/RTWorkerCU.cpp b/example/ControlUnitTest/RTWorkerCU.cpp deleted file mode 100644 index a841e7d66..000000000 --- a/example/ControlUnitTest/RTWorkerCU.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/* - * RTWorkerCU.cpp - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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. - */ -#include <boost/thread.hpp> - -#include "RTWorkerCU.h" - -#include <chaos/common/global.h> -#include <chaos/common/chaos_constants.h> -#include <chaos/common/bson/bson.h> -#include <chaos/common/bson/util/hex.h> -#include <chaos/common/action/ActionDescriptor.h> -#include <chaos/cu_toolkit/ControlManager/handler/DSInt32Handler.h> -#include <chaos/cu_toolkit/ControlManager/handler/DSDoubleHandler.h> - -#include <cmath> -#include <stdio.h> -#include <iostream> -#include <iomanip> -#include <time.h> -#include <stdlib.h> -using namespace chaos; - -#define SIMULATED_DEVICE_ID "SIN_DEVICE" -#define DS_ELEMENT_1 "sinOutput" -#define DS_ELEMENT_2 "sinAltitude" -#define DS_ELEMENT_3 "sinPahseTime" - -#define TEST_BUFFER_DIM 100 -#define CU_DELAY_FROM_TASKS 1000000 //1Sec -#define ACTION_TWO_PARAM_NAME "actionTestTwo_paramName" - -/* - Construct a new CU with an identifier - */ -RTWorkerCU::RTWorkerCU(string &customDeviceID):rng((const uint_fast32_t) time(0) ),one_to_hundred( -100, 100 ),randInt(rng, one_to_hundred){ - _deviceID = customDeviceID; - numberOfResponse = 0; -} - -/* - Destructor a new CU with an identifier - */ -RTWorkerCU::~RTWorkerCU() { - -} - -/* - Return the default configuration - */ -void RTWorkerCU::unitDefineActionAndDataset() throw(CException) { - //cuSetup.addStringValue(CUDefinitionKey::CS_CM_CU_DESCRIPTION, "This is a beautifull CU"); - - - //set the default delay for the CU - setDefaultScheduleDelay(CU_DELAY_FROM_TASKS); - - //add managed device di - setDeviceID(_deviceID); - - - //add custom action - AbstActionDescShrPtr - actionDescription = addActionDescritionInstance<RTWorkerCU>(this, - &RTWorkerCU::actionTestOne, - "actionTestOne", - "comandTestOne this action will do some beautifull things!"); - - actionDescription = addActionDescritionInstance<RTWorkerCU>(this, - &RTWorkerCU::resetStatistic, - "resetStatistic", - "resetStatistic this action will reset all cu statistic!"); - - actionDescription = addActionDescritionInstance<RTWorkerCU>(this, - &RTWorkerCU::actionTestTwo, - "actionTestTwo", - "comandTestTwo, this action will do some beautifull things!"); - - //add param to second action - actionDescription->addParam(ACTION_TWO_PARAM_NAME, - DataType::TYPE_INT32, - "integer 32bit action param description for testing purpose"); - - - //setup the dataset - addAttributeToDataSet("sinWave", - "The sin waveform", - DataType::TYPE_BYTEARRAY, - DataType::Output, - 10000); - - addInputInt32AttributeToDataSet<RTWorkerCU>("points", - "The number of point that compose the wave", - this, - &RTWorkerCU::setWavePoint); - - addInputDoubleAttributeToDataSet<RTWorkerCU>("frequency", - "The frequency of the wave [1-10Mhz]", - this, - &RTWorkerCU::setDoubleValue); - - addInputDoubleAttributeToDataSet<RTWorkerCU>("bias", - "The bias of the wave", - this, - &RTWorkerCU::setDoubleValue); - - - addInputDoubleAttributeToDataSet<RTWorkerCU>("gain", - "The gain of the wave", - this, - &RTWorkerCU::setDoubleValue); - - addInputDoubleAttributeToDataSet<RTWorkerCU>("phase", - "The phase of the wave", - this, - &RTWorkerCU::setDoubleValue); - - addInputDoubleAttributeToDataSet<RTWorkerCU>("gain_noise", - "The gain of the noise of the wave", - this, - &RTWorkerCU::setDoubleValue); -} - -void RTWorkerCU::unitDefineDriver(std::vector<chaos::cu::driver_manager::driver::DrvRequestInfo>& neededDriver) { - -} - -/* - Initialize the Custom Contro Unit and return the configuration - */ -void RTWorkerCU::unitInit() throw(CException) { - LAPP_ << "init RTWorkerCU"; - //RTAbstractControlUnit::init(); - - initTime = steady_clock::now(); - lastExecutionTime = steady_clock::now(); - numberOfResponse = 0; - srand((unsigned)time(0)); - PI = acos((long double) -1); - messageID = 0; - sinevalue = NULL; - setWavePoint("points", 30); - freq = 1.0; - gain = 5.0; - phase = 0.0; - bias = 0.0; - gainNoise = 0.5; -} - -/* - Execute the work, this is called with a determinated delay, it must be as fast as possible - */ -void RTWorkerCU::unitStart() throw(CException) { - // RTAbstractControlUnit::start(); -} - -/* - Execute the Control Unit work - */ -void RTWorkerCU::unitRun() throw(CException) { - //get new data wrapper instance filled - //with mandatory data - CDataWrapper *acquiredData = getNewDataWrapper(); - if(!acquiredData) return; - - //put the messageID for test the lost of package - acquiredData->addInt32Value("id", ++messageID); - computeWave(acquiredData); - - //submit acquired data - pushDataSet(acquiredData); - -} - -void RTWorkerCU::computeWave(CDataWrapper *acquiredData) { - if(sinevalue == NULL) return; - double interval = (2*PI)/points; - boost::mutex::scoped_lock lock(pointChangeMutex); - for(int i=0; i<points; i++){ - sinevalue[i] = (gain*sin((interval*i)+phase)+(((double)randInt()/(double)100)*gainNoise)+bias); - } - acquiredData->addBinaryValue("sinWave", (char*)sinevalue, (int32_t)sizeof(double)*points); -} - - -/* - Execute the Control Unit work - */ -void RTWorkerCU::unitStop() throw(CException) { - LAPP_ << "stop RTWorkerCU"; - //RTAbstractControlUnit::stop(); -} - -/* - Deinit the Control Unit - */ -void RTWorkerCU::unitDeinit() throw(CException) { - LAPP_ << "deinit RTWorkerCU"; - if(sinevalue){ - free(sinevalue); - } - //RTAbstractControlUnit::deinit(); -} - -/* - */ -void RTWorkerCU::setWavePoint(const std::string& deviceID, const int32_t& newNumberOfPoints) { - boost::mutex::scoped_lock lock(pointChangeMutex); - int32_t tmpNOP = newNumberOfPoints; - if(tmpNOP < 1) tmpNOP = 0; - - if(!tmpNOP){ - if(sinevalue){ - free(sinevalue); - sinevalue = NULL; - } - }else{ - size_t byteSize = sizeof(double) * tmpNOP; - double* tmpPtr = (double*)realloc(sinevalue, byteSize); - if(tmpPtr) { - sinevalue = tmpPtr; - memset(sinevalue, 0, byteSize); - }else{ - //memory can't be enlarged so pointer ramin the same - //so all remain unchanged - tmpNOP = points; - } - } - points = tmpNOP; -} - -/* - */ -void RTWorkerCU::setDoubleValue(const std::string& deviceID, const double& dValue) { - LAPP_ << "setDoubleValue for " << deviceID << " = " << dValue; - if(!deviceID.compare("frequency")){ - freq = dValue; - } else if(!deviceID.compare("gain")){ - gain = dValue; - } else if(!deviceID.compare("phase")){ - phase = dValue; - } else if(!deviceID.compare("bias")){ - bias = dValue; - } else if(!deviceID.compare("gain_noise")){ - gainNoise = dValue; - } -} - -/* - Test Action Handler - */ -CDataWrapper* RTWorkerCU::actionTestOne(CDataWrapper *actionParam, bool& detachParam) { - CDataWrapper *result = new CDataWrapper(); - result->addStringValue("result_key", "result_key_value"); - return result; -} - -/* - Test Action Handler - */ -CDataWrapper* RTWorkerCU::resetStatistic(CDataWrapper *actionParam, bool& detachParam) { - LAPP_ << "resetStatistic in RTWorkerCU called from rpc"; - numberOfResponse = 0; - return NULL; -} - -/* - Test Action Handler - */ -CDataWrapper* RTWorkerCU::actionTestTwo(CDataWrapper *actionParam, bool& detachParam) { - LAPP_ << "resetStatistic in RTWorkerCU called from rpc"; - if(actionParam->hasKey(ACTION_TWO_PARAM_NAME)){ - int32_t sleepTime = actionParam->getInt32Value(ACTION_TWO_PARAM_NAME); - - LAPP_ << "param for actionTestTwo with value:" << sleepTime; - LAPP_ << "let this thread to waith "<< sleepTime << " usec"; - boost::this_thread::sleep(boost::posix_time::microseconds(sleepTime)); - } else { - LAPP_ << "No param received for action actionTestTwo"; - } - return NULL; -} diff --git a/example/ControlUnitTest/RTWorkerCU.h b/example/ControlUnitTest/RTWorkerCU.h deleted file mode 100644 index 657c59c03..000000000 --- a/example/ControlUnitTest/RTWorkerCU.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * RTWorkerCU.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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 ChaosFramework_RTWorkerCU_h -#define ChaosFramework_RTWorkerCU_h - -#include <string> -#include <boost/random.hpp> -#include <boost/chrono.hpp> -#include <boost/thread.hpp> -#include <chaos/common/utility/Atomic.h> -#include <chaos/cu_toolkit/ControlManager/RTAbstractControlUnit.h> - -using namespace std; -using namespace boost; -using namespace boost::posix_time; - -using namespace chaos; -using namespace chaos::common::data; - -class RTWorkerCU : public chaos::cu::RTAbstractControlUnit { - typedef boost::mt19937 RNGType; - RNGType rng; - uniform_int<> one_to_hundred; - variate_generator< RNGType, uniform_int<> > randInt; - double numberOfResponse; - high_resolution_clock::time_point initTime; - high_resolution_clock::time_point lastExecutionTime; - high_resolution_clock::time_point currentExecutionTime; - string _deviceID; - long double PI; - - int32_t points; - double *sinevalue; - double freq; - double gain; - double phase; - double bias; - double gainNoise; - - boost::mutex pointChangeMutex; - int32_t messageID; - -public: - /* - Construct a new CU with an identifier - */ - RTWorkerCU(string&); - /* - Destructor a new CU with an identifier - */ - ~RTWorkerCU(); - - inline void computeWave(CDataWrapper *acquiredData); - - inline void setDoubleValue(const std::string& deviceID, const double& dValue); - - inline void setWavePoint(const std::string& deviceID, const int32_t& newNumberOfPoints); -protected: - /* - Define the Control Unit Dataset and Actions - */ - void unitDefineActionAndDataset()throw(CException); - - void unitDefineDriver(std::vector<chaos::cu::driver_manager::driver::DrvRequestInfo>& neededDriver); - - /*(Optional) - Initialize the Control Unit and all driver, with received param from MetadataServer - */ - void unitInit() throw(CException); - /* - Execute the work, this is called with a determinated delay, it must be as fast as possible - */ - void unitStart() throw(CException); - /* - Execute the work, this is called with a determinated delay, it must be as fast as possible - */ - void unitRun() throw(CException); - - /* - The Control Unit will be stopped - */ - void unitStop() throw(CException); - - /*(Optional) - The Control Unit will be deinitialized and disposed - */ - void unitDeinit() throw(CException); - - /* - Test Action Handler - */ - CDataWrapper* actionTestOne(CDataWrapper*, bool&); - - /* - Test Action Handler - */ - CDataWrapper* actionTestTwo(CDataWrapper*, bool&); - - /* - Test Action Handler - */ - CDataWrapper* resetStatistic(CDataWrapper*, bool&); - -}; - -#endif diff --git a/example/ControlUnitTest/SCWorkerCU.cpp b/example/ControlUnitTest/SCWorkerCU.cpp deleted file mode 100644 index c9f2f5144..000000000 --- a/example/ControlUnitTest/SCWorkerCU.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// -// SCWorkerCU.cpp -// ControlUnitTest -// -// Created by Claudio Bisegni on 7/20/13. -// Copyright (c) 2013 INFN. All rights reserved. -// - -#include "SCWorkerCU.h" -#include "SinWaveCommand.h" - -using namespace chaos::common::data; - -using namespace chaos::cu::control_manager::slow_command; -using namespace chaos::cu::driver_manager::driver; - - -/* - Construct a new CU with an identifier - */ -SCWorkerCU::SCWorkerCU(string &customDeviceID) { - _deviceID = customDeviceID; -} - -SCWorkerCU::~SCWorkerCU() { - -} - -/* - Return the default configuration - */ -void SCWorkerCU::unitDefineActionAndDataset() throw(CException) { - //set the base information - RangeValueInfo rangeInfoTemp; - //cuSetup.addStringValue(CUDefinitionKey::CS_CM_CU_DESCRIPTION, "This is a beautifull CU"); - - //add managed device di - setDeviceID(_deviceID); - - //install a command - installCommand<SinWaveCommand>("sinwave_base"); - - //set it has default - // setDefaultCommand("sinwave_base"); - - //setup the dataset - addAttributeToDataSet("sinWave", - "The sin waveform", - DataType::TYPE_BYTEARRAY, - DataType::Output, - 10000); - - addAttributeToDataSet("points", - "The number of point that compose the wave", - DataType::TYPE_INT32, - DataType::Input); - rangeInfoTemp.defaultValue = "30"; - rangeInfoTemp.maxRange = ""; - rangeInfoTemp.minRange = "30"; - setAttributeRangeValueInfo("points", rangeInfoTemp); - - addAttributeToDataSet("frequency", - "The frequency of the wave [1-10Mhz]", - DataType::TYPE_DOUBLE, - DataType::Input); - - addAttributeToDataSet("bias", - "The bias of the wave", - DataType::TYPE_DOUBLE, - DataType::Input); - - addAttributeToDataSet("phase", - "The phase of the wave", - DataType::TYPE_DOUBLE, - DataType::Input); - - addAttributeToDataSet("gain", - "The gain of the wave", - DataType::TYPE_DOUBLE, - DataType::Input); - - addAttributeToDataSet("gain_noise", - "The gain of the noise of the wave", - DataType::TYPE_DOUBLE, - DataType::Input); - -} - -void SCWorkerCU::defineSharedVariable() { - bool quit = false; - addSharedVariable("quit", 1, chaos::DataType::TYPE_BOOLEAN); - setSharedVariableValue("quit", &quit, sizeof(bool)); -} - -void SCWorkerCU::unitDefineDriver(std::vector<cu_driver::DrvRequestInfo>& neededDriver) { - cu_driver::DrvRequestInfo drv1 = {"DummyDriver","1.0.0","plccalc.lnf.infn.it:102"}; - neededDriver.push_back(drv1); -} - -// Abstract method for the initialization of the control unit -void SCWorkerCU::unitInit() throw(CException) { - -} - -// Abstract method for the start of the control unit -void SCWorkerCU::unitStart() throw(CException) { - -} - -// Abstract method for the stop of the control unit -void SCWorkerCU::unitStop() throw(CException) { - -} - -// Abstract method for the deinit of the control unit -void SCWorkerCU::unitDeinit() throw(CException) { - -} \ No newline at end of file diff --git a/example/ControlUnitTest/SCWorkerCU.h b/example/ControlUnitTest/SCWorkerCU.h deleted file mode 100644 index 78803920b..000000000 --- a/example/ControlUnitTest/SCWorkerCU.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SCWorkerCU.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2013 INFN, National Institute of Nuclear Physics - * - * 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 __ControlUnitTest__SCWorkerCU__ -#define __ControlUnitTest__SCWorkerCU__ - -#include <chaos/cu_toolkit/ControlManager/SCAbstractControlUnit.h> - -using namespace std; -using namespace chaos; -using namespace boost; -using namespace boost::posix_time; - -namespace cu_driver = chaos::cu::driver_manager::driver; - -class SCWorkerCU : public chaos::cu::SCAbstractControlUnit { - string _deviceID; -protected: - /* - Define the Control Unit Dataset and Actions - */ - void unitDefineActionAndDataset()throw(CException); - void defineSharedVariable(); - void unitDefineDriver(std::vector<cu_driver::DrvRequestInfo>& neededDriver); - /*(Optional) - Initialize the Control Unit and all driver, with received param from MetadataServer - */ - void unitInit() throw(CException); - /*(Optional) - Execute the work, this is called with a determinated delay, it must be as fast as possible - */ - void unitStart() throw(CException); - /*(Optional) - The Control Unit will be stopped - */ - void unitStop() throw(CException); - /*(Optional) - The Control Unit will be deinitialized and disposed - */ - void unitDeinit() throw(CException); -public: - /* - Construct a new CU with an identifier - */ - SCWorkerCU(string&); - - /* - Base destructor - */ - ~SCWorkerCU(); -}; - - -#endif /* defined(__ControlUnitTest__SCWorkerCU__) */ diff --git a/example/ControlUnitTest/SWAlim/SWAlimCU.cpp b/example/ControlUnitTest/SWAlim/SWAlimCU.cpp deleted file mode 100644 index 6a8745c34..000000000 --- a/example/ControlUnitTest/SWAlim/SWAlimCU.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/* - * SWAlimCU.cpp - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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. - */ -#include <boost/thread.hpp> - -#include "SWAlimCU.h" -#include <chaos/common/global.h> -#include <chaos/common/chaos_constants.h> -#include <chaos/common/bson/bson.h> -#include <chaos/common/bson/util/hex.h> -#include <chaos/common/action/ActionDescriptor.h> -#include <chaos/cu_toolkit/ControlManager/handler/DSInt32Handler.h> -#include <chaos/cu_toolkit/ControlManager/handler/DSDoubleHandler.h> - -#include <cmath> -#include <stdio.h> -#include <iostream> -#include <iomanip> -#include <time.h> -#include <stdlib.h> -using namespace chaos; -using namespace chaos::common::data; - -#define SIMULATED_DEVICE_ID "SWAlim" -#define DS_ELEMENT_1 "current" -#define DS_ELEMENT_2 "voltage" - -#define TEST_BUFFER_DIM 100 -#define CU_DELAY_FROM_TASKS 1000000 //1Sec -#define ACTION_TWO_PARAM_NAME "actionTestTwo_paramName" - - - -SWAlimCU::SWAlimCU():rng((const uint_fast32_t) time(0) ),one_to_hundred( -100, 100 ),randInt(rng, one_to_hundred) { - //first we make some write - _deviceID.assign(SIMULATED_DEVICE_ID); - numberOfResponse = 0; -} - -/* - Construct a new CU with an identifier - */ -SWAlimCU::SWAlimCU(string &customDeviceID):rng((const uint_fast32_t) time(0) ),one_to_hundred( -100, 100 ),randInt(rng, one_to_hundred){ - _deviceID = customDeviceID; - numberOfResponse = 0; - tcpChan = new TcpChannel("LocalTcp"); - prot = new ModbusProtocol("modbus"); - myalim = new SWAlim(_deviceID.c_str()); - LAPP_ << "Created Channel:"<<tcpChan->getName()<<endl<<"Created Protocol:"<<prot->getName()<<endl; - -} - -/* - Destructor a new CU with an identifier - */ -SWAlimCU::~SWAlimCU() { - -} - -/* - Return the default configuration - */ -void SWAlimCU::unitDefineActionAndDataset() throw(CException) { - //set the base information - const char *devIDInChar = _deviceID.c_str(); - - - //set the default delay for the CU - setDefaultScheduleDelay(CU_DELAY_FROM_TASKS); - - //add managed device di - setDeviceID(_deviceID); - - //add custom action - AbstActionDescShrPtr - actionDescription = addActionDescritionInstance<SWAlimCU>(this, - &SWAlimCU::actionTestOne, - "actionTestOne", - "comandTestOne this action will do some beautifull things!"); - - actionDescription = addActionDescritionInstance<SWAlimCU>(this, - &SWAlimCU::resetStatistic, - "resetStatistic", - "resetStatistic this action will reset all cu statistic!"); - - actionDescription = addActionDescritionInstance<SWAlimCU>(this, - &SWAlimCU::actionTestTwo, - "actionTestTwo", - "comandTestTwo, this action will do some beautifull things!"); - - //add param to second action - actionDescription->addParam(ACTION_TWO_PARAM_NAME, - DataType::TYPE_INT32, - "integer 32bit action param description for testing purpose"); - - - //setup the dataset - /* - addAttributeToDataSet(devIDInChar, - "DeviceTCPAddress", - "SWAlim Address in the form [<ip>:<port>]", - DataType::TYPE_STRING, - DataType::Input); - */ - - addAttributeToDataSet("Current", - "SWAlim current", - DataType::TYPE_INT32, - DataType::Output); - - addAttributeToDataSet("Voltage", - "SWAlim voltage", - DataType::TYPE_INT32, - DataType::Output); - - addInputInt32AttributeToDataSet<SWAlimCU>("Setcurrent", - "Set The current", - this, - &SWAlimCU::setCurrent); - - - std::vector<const char*> alim_attr; - alim_attr = myalim->getAttributes(); - for(std::vector<const char*>::iterator i = alim_attr.begin();i!=alim_attr.end();i++){ - addAttributeToDataSet(*i, - "parameter", - DataType::TYPE_STRING, - DataType::Input); - - } - -} - -void SWAlimCU::unitDefineDriver(std::vector<chaos::cu::driver_manager::driver::DrvRequestInfo>& neededDriver) { - -} - -// from abstract class -void SWAlimCU::unitInit() throw(CException) { - LAPP_ << "init SWAlimCU"; - RangeValueInfo param; - std::vector<const char*> alim_attr; - alim_attr = myalim->getAttributes(); - for(std::vector<const char*>::iterator i = alim_attr.begin();i!= alim_attr.end();i++){ - - getAttributeRangeValueInfo(*i, param); - LAPP_<< "Parameter: "<<*i<<" val="<<param.defaultValue<<endl; - myalim->setAttribute(*i,param.defaultValue); - } - - /* myalim = new SWAlim(_deviceID.c_str(),param.defaultValue.c_str()); - if(myalim==NULL) - throw new CException(0,"cannot create SWAlim",__FUNCTION__); - */ - initTime = steady_clock::now(); - lastExecutionTime = steady_clock::now(); - numberOfResponse = 0; - messageID = 0; - prot->attach(tcpChan); - myalim->attach(prot); - if(myalim->init()!=0) - throw new CException(0,"cannot init SWAlim",__FUNCTION__); -} - -// from abstract class -void SWAlimCU::unitStart() throw(CException) { - -} - -// from abstract class -void SWAlimCU::unitRun() throw(CException) { - int current,voltage; - //get new data wrapper instance filled - //with mandatory data - CDataWrapper *acquiredData = getNewDataWrapper(); - if(!acquiredData) return; - myalim->readCurrent(current); - myalim->readVoltage(voltage); - //put the messageID for test the lost of package - acquiredData->addInt32Value("id", ++messageID); - acquiredData->addInt32Value("Current", current); - acquiredData->addInt32Value("Voltage", voltage); - //adding some interesting random data - LAPP_<<"Current:"<<current<<endl<<"Voltage:"<<voltage<<endl; - - //submit acquired data - pushDataSet(acquiredData); - -} - - -// from abstract class -void SWAlimCU::unitStop() throw(CException) { - LAPP_ << "stop SWAlimCU"; -} - -// from abstract class -void SWAlimCU::unitDeinit() throw(CException) { - LAPP_ << "deinit SWAlimCU"; - myalim->deinit(); -} - -/* - */ -void SWAlimCU::setCurrent(const std::string& deviceID, const int32_t& current) { - myalim->setCurrent(current); -} - -/* - Test Action Handler - */ -CDataWrapper* SWAlimCU::actionTestOne(CDataWrapper *actionParam, bool& detachParam) { - CDataWrapper *result = new CDataWrapper(); - result->addStringValue("result_key", "result_key_value"); - return result; -} - -/* - Test Action Handler - */ -CDataWrapper* SWAlimCU::resetStatistic(CDataWrapper *actionParam, bool& detachParam) { - LAPP_ << "resetStatistic in SWAlimCU called from rpc"; - numberOfResponse = 0; - return NULL; -} - -/* - Test Action Handler - */ -CDataWrapper* SWAlimCU::actionTestTwo(CDataWrapper *actionParam, bool& detachParam) { - LAPP_ << "resetStatistic in SWAlimCU called from rpc"; - if(actionParam->hasKey(ACTION_TWO_PARAM_NAME)){ - int32_t sleepTime = actionParam->getInt32Value(ACTION_TWO_PARAM_NAME); - - LAPP_ << "param for actionTestTwo with value:" << sleepTime; - LAPP_ << "let this thread to waith "<< sleepTime << " usec"; - boost::this_thread::sleep(boost::posix_time::microseconds(sleepTime)); - } else { - LAPP_ << "No param received for action actionTestTwo"; - } - return NULL; -} diff --git a/example/ControlUnitTest/SWAlim/SWAlimCU.h b/example/ControlUnitTest/SWAlim/SWAlimCU.h deleted file mode 100644 index f28be045b..000000000 --- a/example/ControlUnitTest/SWAlim/SWAlimCU.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * WorkerCU.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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 ChaosFramework_WorkerCU_h -#define ChaosFramework_WorkerCU_h - -#include <string> -#include <boost/random.hpp> -#include <boost/chrono.hpp> -#include <boost/thread.hpp> -#include <chaos/common/utility/Atomic.h> -#include <chaos/cu_toolkit/ControlManager/RTAbstractControlUnit.h> -#include "SWAlim.h" -#include "TcpChannel.h" -#include "ModbusProtocol.h" - - -using namespace std; -using namespace chaos; -using namespace boost; -using namespace boost::posix_time; - -namespace c_data = chaos::common::data; - -class SWAlimCU : public chaos::cu::RTAbstractControlUnit { - typedef boost::mt19937 RNGType; - RNGType rng; - uniform_int<> one_to_hundred; - variate_generator< RNGType, uniform_int<> > randInt; - double numberOfResponse; - high_resolution_clock::time_point initTime; - high_resolution_clock::time_point lastExecutionTime; - high_resolution_clock::time_point currentExecutionTime; - string _deviceID; - - TcpChannel* tcpChan; - ModbusProtocol* prot; - SWAlim* myalim; - unsigned messageID; -public: - /* - Construct a new CU with an identifier - */ - SWAlimCU(); - /* - Construct a new CU with an identifier - */ - SWAlimCU(string&); - /* - Destructor a new CU with an identifier - */ - ~SWAlimCU(); - - inline void setCurrent(const std::string& deviceID, const int32_t& current); -protected: - /* - Define the Control Unit Dataset and Actions - */ - void unitDefineActionAndDataset()throw(CException); - - void unitDefineDriver(std::vector<chaos::cu::driver_manager::driver::DrvRequestInfo>& neededDriver); - - // from abstract class - void unitInit() throw(CException); - - // from abstract class - void unitStart() throw(CException); - - // from abstract class - void unitRun() throw(CException); - - // from abstract class - void unitStop() throw(CException); - - // from abstract class - void unitDeinit() throw(CException); - - /* - Test Action Handler - */ - c_data::CDataWrapper* actionTestOne(c_data::CDataWrapper*, bool&); - - /* - Test Action Handler - */ - c_data::CDataWrapper* actionTestTwo(c_data::CDataWrapper*, bool&); - - /* - Test Action Handler - */ - c_data::CDataWrapper* resetStatistic(c_data::CDataWrapper*, bool&); - -}; - -#endif diff --git a/example/ControlUnitTest/SWAlim/main.cpp b/example/ControlUnitTest/SWAlim/main.cpp deleted file mode 100644 index 4f40ff297..000000000 --- a/example/ControlUnitTest/SWAlim/main.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// -// main.cpp -// SWAlim -// -// Created by andrea michelotti on 5/9/13. -// Copyright (c) 2013 INFN. All rights reserved. -// - -#include "SWAlimCU.h" -#include <chaos/common/chaos_constants.h> -#include <chaos/cu_toolkit/ChaosCUToolkit.h> - -#include <iostream> -#include <string> -using namespace std; -using namespace chaos; -using namespace chaos::cu; -#define OPT_CUSTOM_DEVICE_ID_A "device_a" -#define OPT_CUSTOM_DEVICE_ID_B "device_b" - -int main(int argc, char * argv[]) -{ - - string tmpDeviceID; - //! [Custom Option] - try { - ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_CUSTOM_DEVICE_ID_A, po::value<string>(), "Device A identification string"); - ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->addOption(OPT_CUSTOM_DEVICE_ID_B, po::value<string>(), "Device B identification string"); - //! [Custom Option] - - //! [CUTOOLKIT Init] - ChaosCUToolkit::getInstance()->init(argc, argv); - //! [CUTOOLKIT Init] - - //! [Adding the CustomControlUnit] - if(ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_CUSTOM_DEVICE_ID_A)){ - tmpDeviceID = ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->getOption<string>(OPT_CUSTOM_DEVICE_ID_A); - ChaosCUToolkit::getInstance()->addControlUnit(new SWAlimCU(tmpDeviceID)); - } - - if(ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_CUSTOM_DEVICE_ID_B)){ - tmpDeviceID = ChaosCUToolkit::getInstance()->getGlobalConfigurationInstance()->getOption<string>(OPT_CUSTOM_DEVICE_ID_B); - ChaosCUToolkit::getInstance()->addControlUnit(new SWAlimCU(tmpDeviceID)); - } - //! [Adding the CustomControlUnit] - - //! [Starting the Framework] - ChaosCUToolkit::getInstance()->start(); - //! [Starting the Framework] - } catch (CException& e) { - cerr<<"Exception::"<<endl; - std::cerr<< "in:"<<e.errorDomain << std::endl; - std::cerr<< "cause:"<<e.errorMessage << std::endl; - } catch (program_options::error &e){ - cerr << "Unable to parse command line: " << e.what() << endl; - } catch (...){ - cerr << "unexpected exception caught.. " << endl; - } - - return 0; -} - diff --git a/example/ControlUnitTest/SinWaveCommand.cpp b/example/ControlUnitTest/SinWaveCommand.cpp deleted file mode 100644 index c343c0ea6..000000000 --- a/example/ControlUnitTest/SinWaveCommand.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * SinWaveCommand.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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. - */ -#include "SinWaveCommand.h" -#include <boost/lexical_cast.hpp> - -#define CMDCU_ LAPP_ << "[SinWaveCommand] - " - - -using namespace chaos; - -using namespace chaos::common::data; - -using namespace chaos::cu::control_manager::slow_command; - -SinWaveCommand::SinWaveCommand():rng((const uint_fast32_t) time(0) ),one_to_hundred( -100, 100 ),randInt(rng, one_to_hundred) { - //set default scheduler delay - setFeatures(features::FeaturesFlagTypes::FF_SET_SCHEDULER_DELAY, 50); -} - -SinWaveCommand::~SinWaveCommand() { - -} - -// return the implemented handler -uint8_t SinWaveCommand::implementedHandler() { - return HandlerType::HT_Set | - HandlerType::HT_Acquisition | - HandlerType::HT_Correlation; -} - -// Start the command execution -void SinWaveCommand::setHandler(CDataWrapper *data) { - // chaos::cu::DeviceSchemaDB *deviceDB = NULL; - - srand((unsigned)time(0)); - PI = acos((long double) -1); - sinevalue = NULL; - - - pointSetting = getValueSetting((AttributeIndexType)0); - points = pointSetting->getCurrentValue<uint32_t>(); - //setWavePoint(); - *(freq = getValueSetting((AttributeIndexType)1)->getCurrentValue<double>()) = 1.0; - *(bias = getValueSetting((AttributeIndexType)2)->getCurrentValue<double>()) = 0.0; - *(phase = getValueSetting((AttributeIndexType)3)->getCurrentValue<double>()) = 0.0; - *(gain = getValueSetting((AttributeIndexType)4)->getCurrentValue<double>()) = 5.0; - *(gainNoise = getValueSetting((AttributeIndexType)5)->getCurrentValue<double>()) = 0.5; - - //custom variable - quitSharedVariable = getValueSetting((AttributeIndexType)6)->getCurrentValue<bool>(); - - lastStartTime = 0; - - //this is necessary becase if the command is installed after the first start the - //attribute is not anymore marched has "changed". so in every case at set handler - //we call the set point funciton that respect the actual value of poits pointer. - setWavePoint(); - - CMDCU_ << "SinWaveCommand::setHandler"; -} - -// Aquire the necessary data for the command -/*! - The acquire handler has the purpose to get all necessary data need the by CC handler. - \return the mask for the runnign state - */ -void SinWaveCommand::acquireHandler() { - uint64_t timeDiff = shared_stat->lastCmdStepStart - lastStartTime; - - if(timeDiff > 10000 || (*quitSharedVariable)) { - //every ten seconds ste the state until reac the killable and - //the return to exec - lastStartTime = shared_stat->lastCmdStepStart; - if(!(*quitSharedVariable)) { - switch (SlowCommand::runningState) { - case chaos::cu::control_manager::slow_command::RunningStateType::RS_Exsc: - SL_STACK_RUNNIG_STATE - CMDCU_ << "Change to SL_STACK_RUNNIG_STATE"; - break; - case chaos::cu::control_manager::slow_command::RunningStateType::RS_Stack: - SL_KILL_RUNNIG_STATE - CMDCU_ << "Change to SL_KILL_RUNNIG_STATE"; - break; - case chaos::cu::control_manager::slow_command::RunningStateType::RS_Kill: - SL_EXEC_RUNNIG_STATE - CMDCU_ << "Change to SL_EXEC_RUNNIG_STATE"; - break; - } - } else { - SL_END_RUNNIG_STATE; - } - } - - //check if some parameter has changed every 100 msec - if(timeDiff > 100) { - getChangedAttributeIndex(changedIndex); - if(changedIndex.size()) { - CMDCU_ << "We have " << changedIndex.size() << " changed attribute"; - for (int idx =0; idx < changedIndex.size(); idx++) { - ValueSetting *vSet = getValueSetting(changedIndex[idx]); - - //set change as completed - vSet->completed(); - - //the index is correlated to the creation sequence so - //the index 0 is the first input parameter "frequency" - switch (vSet->index) { - case 0://points - - // apply the modification - setWavePoint(); - break; - default:// all other parameter are managed into the function that create the sine waveform - break; - } - - } - changedIndex.clear(); - } - } - CDataWrapper *acquiredData = getNewDataWrapper(); - if(!acquiredData) return; - - //put the messageID for test the lost of package - acquiredData->addInt32Value("id", ++messageID); - computeWave(acquiredData); - - //submit acquired data - pushDataSet(acquiredData); -} - -// Correlation and commit phase -void SinWaveCommand::ccHandler() { - -} - -void SinWaveCommand::computeWave(CDataWrapper *acquiredData) { - if(sinevalue == NULL) return; - double interval = (2*PI)/(*points); - boost::mutex::scoped_lock lock(pointChangeMutex); - for(int i=0; i<(*points); i++){ - sinevalue[i] = ((*gain)*sin((interval*i)+(*phase))+(((double)randInt()/(double)100)*(*gainNoise))+(*bias)); - } - acquiredData->addBinaryValue("sinWave", (char*)sinevalue, (int32_t)sizeof(double)*(*points)); -} - -/* - */ -void SinWaveCommand::setWavePoint() { - boost::mutex::scoped_lock lock(pointChangeMutex); - uint32_t tmpNOP = *pointSetting->getCurrentValue<uint32_t>(); - if(tmpNOP < 1) tmpNOP = 0; - - if(!tmpNOP){ - if(sinevalue){ - free(sinevalue); - sinevalue = NULL; - } - }else{ - size_t byteSize = sizeof(double) * tmpNOP; - double* tmpPtr = (double*)realloc(sinevalue, byteSize); - if(tmpPtr) { - sinevalue = tmpPtr; - memset(sinevalue, 0, byteSize); - }else{ - pointSetting->completedWithError(); - } - } -} \ No newline at end of file diff --git a/example/ControlUnitTest/SinWaveCommand.h b/example/ControlUnitTest/SinWaveCommand.h deleted file mode 100644 index bdbc81002..000000000 --- a/example/ControlUnitTest/SinWaveCommand.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SinWaveCommand.h - * !CHOAS - * Created by Bisegni Claudio. - * - * Copyright 2012 INFN, National Institute of Nuclear Physics - * - * 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 __ControlUnitTest__SinWaveCommand__ -#define __ControlUnitTest__SinWaveCommand__ - -#include <boost/random.hpp> -#include <boost/thread.hpp> -#include <chaos/cu_toolkit/ControlManager/slow_command/SlowCommand.h> - -using namespace chaos; - -namespace c_data = chaos::common::data; -namespace ccc_slow_command = chaos::cu::control_manager::slow_command; - -class SinWaveCommand : public ccc_slow_command::SlowCommand { - typedef boost::mt19937 RNGType; - RNGType rng; - uniform_int<> one_to_hundred; - variate_generator< RNGType, uniform_int<> > randInt; - double *sinevalue; - uint32_t *points; - ccc_slow_command::ValueSetting *pointSetting; - double *freq; - double *gain; - double *phase; - double *bias; - double *gainNoise; - bool *quitSharedVariable; - uint64_t lastStartTime; - - long double PI; - int32_t messageID; - boost::mutex pointChangeMutex; - std::vector<ccc_slow_command::AttributeIndexType> changedIndex; - - inline void computeWave(c_data::CDataWrapper *acquiredData); - inline void setWavePoint(); -protected: - // return the implemented handler - uint8_t implementedHandler(); - - // Start the command execution - void setHandler(c_data::CDataWrapper *data); - - // Aquire the necessary data for the command - /*! - The acquire handler has the purpose to get all necessary data need the by CC handler. - \return the mask for the runnign state - */ - void acquireHandler(); - - // Correlation and commit phase - void ccHandler(); - -public: - SinWaveCommand(); - ~SinWaveCommand(); -}; - -#endif /* defined(__ControlUnitTest__SinWaveCommand__) */ -- GitLab