30 dabc::Device (name),fConditionMutex(true)
33 #ifndef DABC_SAFT_USE_2_0
39 #ifdef DABC_SAFT_USE_2_0
40 std::map<std::string, std::string> devices = saftlib::SAFTd_Proxy::create()->getDevices();
42 fGlibMainloop= Glib::MainLoop::create();
43 std::map<Glib::ustring, Glib::ustring> devices = saftlib::SAFTd_Proxy::create()->getDevices();
46 fTimingReceiver = saftlib::TimingReceiver_Proxy::create(devices[fBoardName]);
53 SetDevInfoParName(
"SaftDeviceInfo");
54 CreatePar(fDevInfoName,
"info").SetSynchron(
true, 2.,
false).SetDebugLevel(2);
58 DOUT1(
"Created SAFTDABC device %s\n",fBoardName.c_str());
63 DOUT1(
"saftdabc::Device::OnThreadAssigned()...");
76 #ifdef DABC_SAFT_USE_2_0
77 DOUT1(
"WARNING: No GlibMainLoop for saftlib > 2.0, not started!");
79 DOUT1(
"RunGlibMainLoop starts.");
81 DOUT1(
"RunGlibMainLoop after fGlibMainloop->run();");
88 DOUT1(
"saftdabc::Device destructor \n");
94 DOUT1(
"saftdabc::Device DestroyByOwnThread()was called \n");
97 #ifndef DABC_SAFT_USE_2_0
98 fGlibMainloop->quit();
129 DOUT1 (
"saftdabc::Device::ExecuteCommand- %s", cmd.
GetName ());
135 return cmd_bool (res);;
159 "~~~~~~~~~~~~~~~~~ saftdabc::Device::CreateTransport port %s isinp %s", portref.
ItemName ().c_str (),
DBOOL (portref.
IsInput ()));
162 EOUT(
"Input object for %s cannot be initialized", portref.
ItemName ().c_str ());
169 DOUT1(
"saftdabc::Device::CreateTransport creates new transport instance %p", transport);
170 DOUT1 (
"Device thread %p, %s\n", thread ().GetObject (), thread ().GetName ());
184 if (!fDevInfoName.empty()) par = Par(fDevInfoName);
195 if(receiver==0)
return false;
200 const char* ioname=name.c_str();
203 #ifdef DABC_SAFT_USE_2_0
204 std::map<std::string, std::string> inputs = fTimingReceiver->getInputs();
207 for (std::map<std::string, std::string>::iterator it=inputs.begin(); it!=inputs.end(); ++it)
210 std::map<std::string, std::string> devices std::map< Glib::ustring, Glib::ustring > inputs = fTimingReceiver->getInputs();
213 for (std::map<Glib::ustring,Glib::ustring>::iterator it=inputs.begin(); it!=inputs.end(); ++it)
217 if (it->first == ioname)
223 if(!found)
return false;
227 #ifdef DABC_SAFT_USE_2_0
241 fMap_PrefixName[ioname] = prefix;
242 DOUT0(
"Registered input condition for %s with prefix 0x%lx", ioname, prefix);
243 SetInfo(
dabc::format(
"Registered input condition for %s with prefix 0x%lx", ioname, prefix));
247 DOUT0(
"Error registering input condition %s ", ioname);
252 #ifdef DABC_SAFT_USE_2_0
253 std::shared_ptr<saftlib::Input_Proxy> input = saftlib::Input_Proxy::create(inputs[ioname]);
255 Glib::RefPtr<saftlib::Input_Proxy> input = saftlib::Input_Proxy::create(inputs[ioname]);
258 input->setEventEnable(
false);
259 input->setEventPrefix(prefix);
260 input->setEventEnable(
true);
262 DOUT0(
"RegisterInputCondition: Input event is enabled.");
269 #ifdef DABC_SAFT_USE_2_0
270 catch (
const saftbus::Error& error)
273 EOUT(
"SAFTbus error %s in RegisterInputCondition for %s ", error.what().c_str(), name.c_str());
278 catch (
const Glib::Error& error)
281 EOUT(
"Glib error %s in RegisterInputCondition for %s ", error.what().c_str(), name.c_str());
292 #ifdef DABC_SAFT_USE_2_0
310 fActionSinks.push_back (saftlib::SoftwareActionSink_Proxy::create (fTimingReceiver->NewSoftwareActionSink (
"")));
312 fConditionProxies.push_back (
313 saftlib::SoftwareCondition_Proxy::create (fActionSinks.back ()->NewCondition (
true,
id, mask, offset)));
316 fConditionProxies.back ()->setAcceptConflict (acconflict);
317 fConditionProxies.back ()->setAcceptDelayed (acdelayed);
318 fConditionProxies.back ()->setAcceptEarly (acearly);
319 fConditionProxies.back ()->setAcceptLate (aclate);
321 fConditionProxies.back ()->Disown ();
327 "RegisterEventCondition: id=0x%lx , mask=0x%lx , offset=0x%lx , early=%d, late=%d, conflict=%d, delayed=%d",
id, mask, offset, acearly, aclate, acconflict, acdelayed);
331 "RegisterEventCondition: id=0x%lx , mask=0x%lx , offset=0x%lx , early=%d, late=%d, conflict=%d, delayed=%d",
332 id, mask, offset, acearly, aclate, acconflict, acdelayed));
337 #ifdef DABC_SAFT_USE_2_0
338 catch (
const saftbus::Error& error)
342 "SAFTbus error %s in RegisterEventCondition for id=0x%lx , mask=0x%lx , offset=0x%lx , early=%d, late=%d, conflict=%d, delayed=%d", error.what().c_str(),
id, mask, offset, acearly, aclate, acconflict, acdelayed);
346 catch (
const Glib::Error& error)
350 "Glib error %s in RegisterEventCondition for id=0x%lx , mask=0x%lx , offset=0x%lx , early=%d, late=%d, conflict=%d, delayed=%d", error.what().c_str(),
id, mask, offset, acearly, aclate, acconflict, acdelayed);
358 #ifdef DABC_SAFT_USE_2_0
367 #ifdef DABC_SAFT_USE_2_0
369 for (std::map<std::string, uint64_t>::iterator it = fMap_PrefixName.begin (); it != fMap_PrefixName.end (); ++it)
372 for (std::map<Glib::ustring, guint64>::iterator it = fMap_PrefixName.begin (); it != fMap_PrefixName.end (); ++it)
375 if (event == it->second)
377 catched_io = it->first;
381 #ifdef DABC_SAFT_USE_2_0
382 for (std::map<std::string, uint64_t>::iterator it = fMap_PrefixName.begin (); it != fMap_PrefixName.end (); ++it)
384 for (std::map<Glib::ustring, guint64>::iterator it = fMap_PrefixName.begin (); it != fMap_PrefixName.end (); ++it)
387 if (event - 1 == it->second)
389 catched_io = it->first;
397 catched_io.append (
" Rising");
401 catched_io.append (
" Falling");
404 #ifdef DABC_SAFT_USE_2_0
407 return catched_io.raw ();
412 #ifdef DABC_SAFT_USE_2_0
413 catch (
const saftbus::Error& error)
415 catch (
const Glib::Error& error)
419 EOUT(
"Error %s in GetInputDescription", error.what().c_str());
420 return std::string (
"NONE");
440 #ifdef DABC_SAFT_USE_2_0
441 for (std::vector<std::shared_ptr<saftlib::SoftwareCondition_Proxy> >::iterator cit = fConditionProxies.begin ();
442 cit != fConditionProxies.end (); ++cit)
444 std::shared_ptr<saftlib::SoftwareCondition_Proxy> destroy_condition = *cit;
447 for (std::vector<Glib::RefPtr<saftlib::SoftwareCondition_Proxy> >::iterator cit = fConditionProxies.begin ();
448 cit != fConditionProxies.end (); ++cit)
450 Glib::RefPtr < saftlib::SoftwareCondition_Proxy > destroy_condition = *cit;
453 if (destroy_condition->getDestructible () && (destroy_condition->getOwner () ==
""))
455 DOUT0(
"ClearConditions will destroy condition of ID:0x%lx .", destroy_condition->getID());
456 destroy_condition->Destroy ();
470 "ClearConditions found non destructible condition of ID:0x%x , owner=%s", destroy_condition->getID(), destroy_condition->getOwner().c_str());
475 fConditionProxies.clear();
482 fActionSinks.clear();
486 #ifdef DABC_SAFT_USE_2_0
487 catch (
const saftbus::Error& error)
490 EOUT(
"SAFTbus error %s in ClearConditions", error.what().c_str());
494 catch (
const Glib::Error& error)
497 EOUT(
"Glib error %s in ClearConditions", error.what().c_str());
510 #ifdef DABC_SAFT_USE_2_0
516 uint64_t ns = time % 1000000000;
517 time_t s = time / 1000000000;
518 struct tm *tm = gmtime(&s);
524 strftime(date,
sizeof(date),
"%Y-%m-%d %H:%M:%S", tm);
525 snprintf(full,
sizeof(full),
"%s.%09ld", date, (
long)ns);
528 snprintf(full,
sizeof(full),
"0d%lu.%09ld",s,(
long)ns);
530 snprintf(full,
sizeof(full),
"0x%016llx", (
unsigned long long)time);
538 #ifdef DABC_SAFT_USE_2_0
544 std::stringstream full;
545 std::string fmt =
"";
548 if (pmode &
PMODE_HEX) {full << std::hex << std::setfill(
'0'); width = 16; fmt =
"0x";}
549 if (pmode &
PMODE_DEC) {full << std::dec << std::setfill(
'0'); width = 20; fmt =
"0d";}
551 full <<
" FID: " << fmt << std::setw(1) << ((
id >> 60) & 0xf);
552 full <<
" GID: " << fmt << std::setw(4) << ((
id >> 48) & 0xfff);
553 full <<
" EVTNO: " << fmt << std::setw(4) << ((
id >> 36) & 0xfff);
554 full <<
" SID: " << fmt << std::setw(4) << ((
id >> 24) & 0xfff);
555 full <<
" BPID: " << fmt << std::setw(5) << ((
id >> 14) & 0x3fff);
556 full <<
" RES: " << fmt << std::setw(4) << (
id & 0x3ff);
558 else full <<
" EvtID: " << fmt << std::setw(width) << std::setfill(
'0') << id;
563 #ifdef DABC_SAFT_USE_2_0
569 std::stringstream full;
570 std::string fmt =
"";
573 if (pmode &
PMODE_HEX) {full << std::hex << std::setfill(
'0'); width = 16; fmt =
"0x";}
574 if (pmode &
PMODE_DEC) {full << std::dec << std::setfill(
'0'); width = 20; fmt =
"0d";}
584 full <<
" Param: " << fmt << std::setw(width) << param;
590 #ifdef DABC_SAFT_USE_2_0
596 std::stringstream full;
602 if (flags & 1) full <<
"late (by " << delay <<
" ns)";
603 if (flags & 2) full <<
"early (by " << -delay <<
" ns)";
604 if (flags & 4) full <<
"conflict (delayed by " << delay <<
" ns)";
605 if (flags & 8) full <<
"delayed (by " << delay <<
" ns)";
Represents command with its arguments.
virtual void ObjectCleanup()
Central cleanup method for worker.
virtual int ExecuteCommand(Command cmd)
Main method where commands are executed.
Special info parameter class.
Lock guard for posix mutex.
bool SetValue(const RecordField &v)
Set parameter value.
void FireModified()
Can be called by user to signal framework that parameter was modified.
Reference on the dabc::Port class
bool IsInput() const
Returns true if it is input port.
Reference on the arbitrary object
const char * GetName() const
Return name of referenced object, if object not assigned, returns "---".
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
std::string ItemName(bool compact=true) const
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call.
Base class for transport implementations.
virtual void OnThreadAssigned()
virtual bool DestroyByOwnThread()
Inherited method from Object, invoked at the moment when worker requested to be destroyed by its thre...
void RunGlibMainLoop()
this function keeps glib main loop alive.
virtual bool DestroyByOwnThread()
here we may insert some actions to the device cleanup methods
const std::string GetInputDescription(guint64 event)
Return text description of input belonging to given event id, e.g.
virtual void ObjectCleanup()
Central cleanup method for worker.
Device(const std::string &name, dabc::Command cmd)
bool ClearConditions()
clean up all existing saftlib conditions
void OnThreadAssigned()
need to start timeout here
void SetInfo(const std::string &info, bool forceinfo=true)
set info parameter.
bool RegisterEventCondition(saftdabc::Input *receiver, guint64 id, guint64 mask, gint64 offset, unsigned char acceptflags)
Register input event per id to snoop on NewCondition(bool active, guint64 id, guint64 mask,...
virtual dabc::Transport * CreateTransport(dabc::Command cmd, const dabc::Reference &port)
virtual int ExecuteCommand(dabc::Command cmd)
Main method where commands are executed.
void AddEventStatistics(unsigned numevents)
add numevents to the event ratemeter.
bool RegisterInputCondition(saftdabc::Input *receiver, std::string &ioname)
Register input of name to snoop on NewCondition(bool active, guint64 id, guint64 mask,...
std::string format(const char *fmt,...)
const char * parEventRate
Name of event rate parameter.
std::string tr_formatActionParam(guint64 param, guint32 evtNo, guint32 pmode)
const guint32 PMODE_VERBOSE
const char * xmlDeviceName
name of the saft device, e.g.
std::string tr_formatDate(guint64 time, guint32 pmode)
std::string tr_formatActionEvent(guint64 id, guint32 pmode)
std::string tr_formatActionFlags(guint16 flags, guint64 delay, guint32 pmode)
const char * commandRunMainloop
Command to invoke the glib/dbus mainloop.
#define SAFT_DABC_ACCEPT_CONFLICT
#define NON_IO_CONDITION_LABEL
this marks conditions that are not input conditions:
#define ECA_EVENT_ID_LATCH
JAM we use the same definitions from saft-io-ctl.
#define SAFT_DABC_ACCEPT_LATE
these flags are dabc proprietary up to now, since saftlib uses separate boolean setters:
#define IO_CONDITION_OFFSET
#define SAFT_DABC_ACCEPT_DELAYED
#define SAFT_DABC_ACCEPT_EARLY