From 1adba473e6917b227e1b0a1118148101dca202e7 Mon Sep 17 00:00:00 2001 From: Manuel Traut Date: Mon, 31 Mar 2014 16:53:55 +0200 Subject: add quellcode Signed-off-by: Manuel Traut --- quellcode/versuch2/CPXEventConsumer | Bin 0 -> 226538 bytes quellcode/versuch2/CPXEventConsumer_i.cpp | 44 ++++++ quellcode/versuch2/CPXEventConsumer_i.h | 17 +++ quellcode/versuch2/CPXEventSupplier | Bin 0 -> 204981 bytes quellcode/versuch2/CPXEventSupplier_i.cpp | 14 ++ quellcode/versuch2/CPXEventSupplier_i.h | 19 +++ quellcode/versuch2/ESConsumer.cpp | 94 +++++++++++++ quellcode/versuch2/ESSupplier.cpp | 106 ++++++++++++++ quellcode/versuch2/GNUmakefile.RTEvent_Consumer | 177 ++++++++++++++++++++++++ quellcode/versuch2/GNUmakefile.RTEvent_Supplier | 177 ++++++++++++++++++++++++ quellcode/versuch2/RTEvent.mpc | 22 +++ quellcode/versuch2/buildNcopy | 2 + quellcode/versuch2/cpx.cpp | 85 ++++++++++++ quellcode/versuch2/cpx.h | 73 ++++++++++ quellcode/versuch2/error.txt | 13 ++ 15 files changed, 843 insertions(+) create mode 100755 quellcode/versuch2/CPXEventConsumer create mode 100755 quellcode/versuch2/CPXEventConsumer_i.cpp create mode 100755 quellcode/versuch2/CPXEventConsumer_i.h create mode 100755 quellcode/versuch2/CPXEventSupplier create mode 100755 quellcode/versuch2/CPXEventSupplier_i.cpp create mode 100755 quellcode/versuch2/CPXEventSupplier_i.h create mode 100755 quellcode/versuch2/ESConsumer.cpp create mode 100755 quellcode/versuch2/ESSupplier.cpp create mode 100755 quellcode/versuch2/GNUmakefile.RTEvent_Consumer create mode 100755 quellcode/versuch2/GNUmakefile.RTEvent_Supplier create mode 100755 quellcode/versuch2/RTEvent.mpc create mode 100755 quellcode/versuch2/buildNcopy create mode 100755 quellcode/versuch2/cpx.cpp create mode 100755 quellcode/versuch2/cpx.h create mode 100755 quellcode/versuch2/error.txt (limited to 'quellcode/versuch2') diff --git a/quellcode/versuch2/CPXEventConsumer b/quellcode/versuch2/CPXEventConsumer new file mode 100755 index 0000000..f1de2b4 Binary files /dev/null and b/quellcode/versuch2/CPXEventConsumer differ diff --git a/quellcode/versuch2/CPXEventConsumer_i.cpp b/quellcode/versuch2/CPXEventConsumer_i.cpp new file mode 100755 index 0000000..3cd3f18 --- /dev/null +++ b/quellcode/versuch2/CPXEventConsumer_i.cpp @@ -0,0 +1,44 @@ +#include "CPXEventConsumer_i.h" + +#include +#include + +#include +#include + +#include + +#include "cpx.h" + +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +CPX cpx; + +CPXEventConsumer_i::CPXEventConsumer_i(CORBA::ORB_ptr orb/*, int event_limit*/) : orb_(CORBA::ORB::_duplicate(orb))/* , event_limit_(event_limit)*/ { + //nothing +} + +void CPXEventConsumer_i::push(const RtecEventComm::EventSet& events) throw (CORBA::SystemException) { + // loop through events + int value; + for(u_int i = 0; i < events.length(); ++i){ + if(events[i].header.type == MY_EVENT_TYPE){ + // std::cout<<"my event\n"; + events[i].data.any_value >>= value; + cpx.set(1, value); + } else { + // std::cout<<"your event\n"; + cpx.set(1, value-2); + } + } +// if(--event_limit_ <= 0) orb_->shutdown(0); +} + +void CPXEventConsumer_i::disconnect_push_consumer() throw (CORBA::SystemException){ + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/quellcode/versuch2/CPXEventConsumer_i.h b/quellcode/versuch2/CPXEventConsumer_i.h new file mode 100755 index 0000000..7eacdea --- /dev/null +++ b/quellcode/versuch2/CPXEventConsumer_i.h @@ -0,0 +1,17 @@ +#ifndef CPXEVENTCONSUMER_H +#define CPXEVENTCONSUMER_H + +#include +#include + +class CPXEventConsumer_i : public virtual POA_RtecEventComm::PushConsumer +{ +public: + CPXEventConsumer_i(CORBA::ORB_ptr orb/*, int event_limit*/); + virtual void push(const RtecEventComm::EventSet& events) throw(CORBA::SystemException); + virtual void disconnect_push_consumer() throw(CORBA::SystemException); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/quellcode/versuch2/CPXEventSupplier b/quellcode/versuch2/CPXEventSupplier new file mode 100755 index 0000000..a97332d Binary files /dev/null and b/quellcode/versuch2/CPXEventSupplier differ diff --git a/quellcode/versuch2/CPXEventSupplier_i.cpp b/quellcode/versuch2/CPXEventSupplier_i.cpp new file mode 100755 index 0000000..4ceef8e --- /dev/null +++ b/quellcode/versuch2/CPXEventSupplier_i.cpp @@ -0,0 +1,14 @@ +#include "CPXEventSupplier_i.h" +#include + +CPXEventSupplier_i::CPXEventSupplier_i(CORBA::ORB_ptr orb) : orb_(CORBA::ORB::_duplicate(orb)){ + //nothing +} + +void CPXEventSupplier_i::disconnect_push_supplier() throw(CORBA::SystemException){ + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/quellcode/versuch2/CPXEventSupplier_i.h b/quellcode/versuch2/CPXEventSupplier_i.h new file mode 100755 index 0000000..c116ea0 --- /dev/null +++ b/quellcode/versuch2/CPXEventSupplier_i.h @@ -0,0 +1,19 @@ +#ifndef _CPXEventSupplier_i_h_ +#define _CPXEventSupplier_i_h_ + +#include // for POA_CosEventComm::PushSupplier + +class CPXEventSupplier_i : public virtual POA_RtecEventComm::PushSupplier +{ + public: + // Constructor + CPXEventSupplier_i(CORBA::ORB_ptr orb); + + virtual void disconnect_push_supplier() + throw(CORBA::SystemException); + + private: + CORBA::ORB_var orb_; +}; + +#endif // _CPXEventSupplier_i_h_ diff --git a/quellcode/versuch2/ESConsumer.cpp b/quellcode/versuch2/ESConsumer.cpp new file mode 100755 index 0000000..6cc7515 --- /dev/null +++ b/quellcode/versuch2/ESConsumer.cpp @@ -0,0 +1,94 @@ +#include "CPXEventConsumer_i.h" + +#include +#include +#include +#include +#include + +const int EVENT_LIMIT = 1000; + +int main (int argc, char* argv[]) +{ + + + struct sched_param schedparam; + schedparam.sched_priority = 99; + if (sched_setscheduler(0, SCHED_FIFO, &schedparam) != 0) { + fprintf(stderr, "%s: PID %d: sched_setscheduler() failed errno = %d\n", __FUNCTION__, getpid(), errno); + } + + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str("EventService"); + + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cout << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "CPXEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; + + // Obtain a reference to the consumer administration object. + RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); + + // Obtain a reference to the push supplier proxy. + RtecEventChannelAdmin::ProxyPushSupplier_var supplier = + admin->obtain_push_supplier(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an CPXEventConsumer_i servant. + CPXEventConsumer_i servant(orb.in()/*, EVENT_LIMIT*/); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushConsumer_var consumer = + RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect as a consumer. + ACE_ConsumerQOS_Factory qos; + qos.start_disjunction_group (1); + qos.insert_type (ACE_ES_EVENT_ANY, 0); + supplier->connect_push_consumer (consumer.in (), qos.get_ConsumerQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "CPXEventConsumerMain.cpp: Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + supplier->disconnect_push_supplier(); + supplier = RtecEventChannelAdmin::ProxyPushSupplier::_nil(); + admin = RtecEventChannelAdmin::ConsumerAdmin::_nil(); + + orb->destroy(); + + return 0; + } + catch (CORBA::Exception& ex) + { + std::cout << "Caught CORBA::Exception" << std::endl << ex << std::endl; + } + + return 1; +} + diff --git a/quellcode/versuch2/ESSupplier.cpp b/quellcode/versuch2/ESSupplier.cpp new file mode 100755 index 0000000..3099bac --- /dev/null +++ b/quellcode/versuch2/ESSupplier.cpp @@ -0,0 +1,106 @@ + + +#include +#include +#include +#include +#include + +#include + +#include +#include "cpx.h" + +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +CPX cpx; + +RtecEventChannelAdmin::ProxyPushConsumer_var consumer; + +#include "CPXEventSupplier_i.h" + +void sigproc(int signo){ + + signal(SIGRTMIN+29, sigproc); + int eventData = cpx.get(1); + + // Eventset initialisieren + RtecEventComm::EventSet events(1); + events.length(1); + + events[0].header.source = MY_SOURCE_ID; + events[0].header.type = MY_EVENT_TYPE; + + events[0].data.any_value <<= eventData; + consumer->push(events); + + /* + if(eventData>0) events[0].data.any_value <<= 1; + else events[0].data.any_value <<= 255; + + consumer->push(events); + + if(rand() < 1626276121){ + events[0].header.source = MY_SOURCE_ID; + events[0].header.type = MY_EVENT_TYPE+1; + if(eventData>0) events[0].data.any_value <<= 2; + else events[0].data.any_value <<= 255; + consumer->push(events); + } + */ + +} + +int main(int argc, char* argv[]){ + + struct sched_param schedparam; + schedparam.sched_priority = 99; + if (sched_setscheduler(0, SCHED_FIFO, &schedparam) != 0) { + fprintf(stderr, "%s: PID %d: sched_setscheduler() failed errno = %d\n", __FUNCTION__, getpid(), errno); + } + + signal(SIGRTMIN+29, sigproc); + + try{ + // initialize ORB + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "ClientORB"); + std::cout<<"ORB ok"<resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var namingContext = CosNaming::NamingContextExt::_narrow(namingObject.in()); + std::cout<<"NamingService ok"<resolve_str("EventService"); + RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(esObj.in()); + if(CORBA::is_nil(ec.in())){ + std::cout<<"couldn't connect to EventService\n"; + return 1; + } + RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); + consumer = admin->obtain_push_consumer(); + + // Instantiate and register servant + CPXEventSupplier_i servant(orb.in()); + + CORBA::Object_var poaObj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObj.in()); + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var supplierObj = poa->id_to_reference(oid.in()); + RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplierObj.in()); + + ACE_SupplierQOS_Factory qos; + qos.insert(MY_SOURCE_ID, MY_EVENT_TYPE, 0 /*rt_info structure*/, 1 /*number of calls*/); + + // connect as supplier + consumer->connect_push_supplier(supplier.in(), qos.get_SupplierQOS()); + + while(true) pause(); + + }catch(CORBA::Exception &any){ + // std::cout<<"Exception occured: "< + +#include +#include +#include +#include + +#define CPX_Input "/dev/iio2" +#define CPX_Input_1 "/dev/iio2_in" +#define CPX_Output_1 "/dev/iio2_out" + +#define PORT1_OUT 0x2c00 +#define PORT2_OUT 0x3c00 +#define PORT3_OUT 0x4c00 + +#define PORT1_IN 0x5c00 +#define PORT2_IN 0x6c00 +#define PORT3_IN 0x7c00 + +# ifndef PROT_READ +# define PROT_READ 0x01 +# endif +# ifndef PROT_WRITE +# define PROT_WRITE 0x02 +# endif +# ifndef MAP_SHARED +# define MAP_SHARED 0x01 +# endif +# ifndef MAP_PRIVATE +# define MAP_PRIVATE 0x02 +# endif + +// ioctl (file descriptor, CPX_DIO_IOCTL_SET_SIGNAL, irq_send_signal_param*) +// enable sending signal on interrupt +// cpx_dio_set_signal_param.signal = signal to be sent to process +#define CPX_DIO_IOCTL_BASE 0xCD + +typedef struct{ + int signal; /* IN parameter: LINUX signal to be sent */ + int pid; /* IN parameter: process id where signal should be sent to */ +}cpx_dio_set_signal_param; + +#define CPX_DIO_IOCTL_ADD_SIG _IOW(CPX_DIO_IOCTL_BASE, 3, cpx_dio_set_signal_param) +#define CPX_DIO_IOCTL_DEL_SIG _IOW(CPX_DIO_IOCTL_BASE, 4, cpx_dio_set_signal_param) + +class CPX{ + public: + CPX(); + void set(short port, short value); + short get(short port); + private: + int init(); + unsigned char *mapped_in; + unsigned char *mapped_out; + volatile u_char *DOUT; + volatile u_char *DIN; + cpx_dio_set_signal_param param; +}; + +#endif diff --git a/quellcode/versuch2/error.txt b/quellcode/versuch2/error.txt new file mode 100755 index 0000000..ff7c749 --- /dev/null +++ b/quellcode/versuch2/error.txt @@ -0,0 +1,13 @@ +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl: In member function 'bool ACE_OutputCDR::write_float(float)': +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl:237: warning: dereferencing type-punned pointer will break strict-aliasing rules +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl: In member function 'bool ACE_InputCDR::skip_double()': +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl:974: warning: dereferencing type-punned pointer will break strict-aliasing rules +ESSupplier.cpp: At global scope: +ESSupplier.cpp:21: warning: unused parameter 'signo' +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl: In member function 'bool ACE_OutputCDR::write_float(float)': +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl:237: warning: dereferencing type-punned pointer will break strict-aliasing rules +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl: In member function 'bool ACE_InputCDR::skip_double()': +/home/trautma/projects/ACE+TAO/trunk/ACE_wrappers/ace/CDR_Stream.inl:974: warning: dereferencing type-punned pointer will break strict-aliasing rules +CPXEventSupplier_i.cpp: In member function 'virtual void CPXEventSupplier_i::disconnect_push_supplier()': +CPXEventSupplier_i.cpp:9: error: 'orb' was not declared in this scope +make: *** [.obj/CPXEventSupplier_i.o] Fehler 1 -- cgit v1.2.3