TimingEventSourceSCU.cpp
Go to the documentation of this file.00001
00002 #include <sstream>
00003 #include <fstream>
00004 #include <malloc.h>
00005 #include <sys/time.h>
00006
00007 #include <fesa-core-gsi/RealTime/TimingEventSourceSCU.h>
00008 #include <fesa-core-gsi/Synchronization/TimingContextSCU.h>
00009 #include <fesa-core-gsi/Synchronization/GSICycleDescriptor.h>
00010 #include <fesa-core-gsi/Exception/GSIException.h>
00011 #include <fesa-core/Core/FesaDefs.h>
00012 #include <fesa-core/Utilities/ParserElements/EventElement.h>
00013 #include <fesa-core/Utilities/ParserElements/ParserElementDefs.h>
00014
00015 namespace fesaGSI
00016 {
00017
00018 TimingEventSourceSCU::TimingEventSourceSCU() :
00019 fesa::AbstractEventSource(fesa::TIMING_EVENT_SOURCE_NAME, fesa::TimingSource)
00020 {
00021 int status;
00022
00023
00024 status = fileDescriptor_ = open(SCU_TIMING_DEVICE_NAME.c_str(), O_RDWR);
00025 if (status == -1)
00026 {
00027 throw GSIException(__FILE__, __LINE__, FESAGSIErrorWhileConnectingToSCUTiming.c_str(),SCU_TIMING_DEVICE_NAME.c_str());
00028 }
00029 }
00030
00031 TimingEventSourceSCU::~TimingEventSourceSCU()
00032 {
00033 close(fileDescriptor_);
00034 }
00035
00036 fesa::RTEvent* TimingEventSourceSCU::wait()
00037 {
00038
00039
00040
00041 while(true)
00042 {
00043 fesa::RTEvent* theEvent = 0;
00044 fesa::MultiplexingContext* context = 0;
00045 try
00046 {
00047
00048 unsigned int cnt_value_irq;
00049 int status;
00050
00051
00052 status = read(fileDescriptor_, &cnt_value_irq, sizeof(int));
00053 if (status == -1)
00054 {
00055 throw GSIException(__FILE__, __LINE__, FESAGSIErrorWhileReceivingInterrupt.c_str());
00056 }
00057
00058 long timestamp = cnt_value_irq;
00059 std::string cycleName = "AnyCycle";
00060 context = new TimingContextSCU(timestamp,cycleName);
00061 theEvent = new fesa::RTEvent("SCUTestClass::START_CYCLE#CTIM#32",context ,this);
00062
00063
00064 return theEvent;
00065 }
00066 catch (fesa::FesaException& ex)
00067 {
00068 if (context != 0)
00069 delete context;
00070 if (theEvent != 0)
00071 delete theEvent;
00072
00073
00074
00075
00076 }
00077 catch (...)
00078 {
00079 if (context != 0)
00080 delete context;
00081 if (theEvent != 0)
00082 delete theEvent;
00083
00084
00085
00086
00087 }
00088 }
00089 }
00090
00091 void TimingEventSourceSCU::connect(boost::shared_ptr<fesa::EventElement>& eventElement)
00092 {
00093 std::string concreteEventName = eventElement->getSourceTypeSpecificData(fesa::TIMING_TAG_CONCRETE_NAME);
00094
00095
00096
00097
00098
00099 size_t posSep1 = concreteEventName.find('#');
00100 size_t posSep2 = concreteEventName.rfind('#', concreteEventName.size());
00101 if (posSep1 == std::string::npos || posSep2 == std::string::npos)
00102 {
00103 throw GSIException(__FILE__, __LINE__, FESAGSIErrorWrongTimingName.c_str(), concreteEventName.c_str());
00104 }
00105
00106
00107
00108
00109 if (false)
00110 {
00111 throw GSIException(__FILE__, __LINE__, FESAGSIErrorWhileConnectingTimingEvent.c_str(),
00112 concreteEventName.c_str());
00113 }
00114
00115 return;
00116 }
00117
00118 }