TimingContext.cpp
Go to the documentation of this file.00001
00002 #include <climits>
00003 #include <fesa-core-gsi/Synchronization/TimingContext.h>
00004 #include <fesa-core/Synchronization/Timing.h>
00005 #include <fesa-core-gsi/Exception/GSIException.h>
00006 #include <fesa-core-gsi/Synchronization/GSICycleDescriptor.h>
00007 #include <fesa-core/Synchronization/SynchronizationLabObjectFactory.h>
00008
00009 namespace fesaGSI
00010 {
00011
00012
00013 TimingContext::TimingContext(long long cycleStamp, const std::string& cycleName) :
00014 fesa::TimingContext()
00015 {
00016 type_ = fesa::MultiplexingContext::CycleOccurrenceCtxt;
00017 forewarning_ = false;
00018 fesa::CycleSelector cycleSelector;
00019 fesa::parseCycleSelector(cycleName, cycleSelector);
00020 fesa::SynchronizationLabObjectFactory* syncFactory = fesa::SynchronizationLabObjectFactory::getInstance();
00021 fesaGSI::GSICycleDescriptor *ptd = dynamic_cast<fesaGSI::GSICycleDescriptor*> (syncFactory->getCycleDescriptor(cycleSelector.domain_, cycleSelector.criterion_));
00022 cycleStamp_ = cycleStamp;
00023 cycleName_ = cycleName;
00024 cycleId_ = ptd->getCycleSelectorId(cycleName);
00025 timingDomainId_ = ptd->getTgmMachineId();
00026 timingDomainName_ = cycleSelector.domain_;
00027 cycleTimeStamp_.Second = cycleStamp / 1000000000;
00028 cycleTimeStamp_.Nano = cycleStamp % 1000000000;
00029 cycleTimeStamp_.CTrain = 0;
00030 cycleTimeStamp_.Machine = ptd->getTgmMachineId();
00031 }
00032
00033
00034 TimingContext::TimingContext(TimLibTime& interruptTimeStamp, unsigned long payload, bool forewarning) :
00035 fesa::TimingContext(), interruptTimeStamp_(interruptTimeStamp)
00036 {
00037 type_ = fesa::MultiplexingContext::CycleOccurrenceCtxt;
00038 forewarning_ = forewarning;
00039 init(payload);
00040 }
00041
00042 void TimingContext::init(unsigned long payload)
00043 {
00044
00045 timingDomainName_ = TgmGetMachineName(interruptTimeStamp_.Machine);
00046
00047
00048 timingDomainId_ = interruptTimeStamp_.Machine;
00049
00050
00051 TimLibError err = TimLibGetTgmInfo(interruptTimeStamp_, &cycleTimeStamp_, NULL, NULL);
00052 if (err != TimLibErrorSUCCESS)
00053 {
00054 throw GSIException(__FILE__, __LINE__, FesaGSIErrorAccessingTimLib.c_str());
00055 }
00056
00057
00058 cycleStamp_ = cycleTimeStamp_.Second * (long long) 1000000000 + cycleTimeStamp_.Nano;
00059
00060
00061 unsigned long userGroupNb = TgmGetGroupNumber((TgmMachine) interruptTimeStamp_.Machine, "USER");
00062 err = TimLibGetGroupValueFromStamp(cycleTimeStamp_, userGroupNb, 0, (long unsigned int*)&cycleId_);
00063 if (err != TimLibErrorSUCCESS)
00064 {
00065 throw GSIException(__FILE__, __LINE__, FesaGSIErrorAccessingTimLib.c_str());
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 fesa::SynchronizationLabObjectFactory* syncFactory = fesa::SynchronizationLabObjectFactory::getInstance();
00079 fesa::CycleDescriptor *td = syncFactory->createOrGetEventCycleDescriptor(timingDomainName_, "USER");
00080 cycleName_ = td->getCycleSelectorName(cycleId_);
00081 }
00082
00083 int64_t TimingContext::getInterruptTimeStamp()
00084 {
00085 return interruptTimeStamp_.Second * (int64_t) 1000000000 + interruptTimeStamp_.Nano;
00086 }
00087
00088 uint32_t TimingContext::getCycleTime()
00089 {
00090 return interruptTimeStamp_.CTrain;
00091 }
00092
00093 }
00094