14#include "sp_densityfnct.h"
36 FD_DHV(
"AttributeSignalOutput(" <<
this <<
"):DoAssign(): assignment from " << &rSrcAttr);
37 mActions=rSrcAttr.mActions;
42 (void) rLabel; (void) pContext;
46 std::vector<Action>::const_iterator ait;
64 (void) rLabel; (void) pContext;
66 FD_DHV(
"AttributeSignalOutput::DoRead()");
75 while(!rTr.
Eos(
"Actions")) {
81 }
else if(value ==
"Clr") {
83 }
else if(value ==
"Inv") {
94 std::stringstream errstr;
95 errstr <<
"Invalid output event property" << rTr.
FileLine();
96 throw Exception(
"AttributeSignalOutput::Read", errstr.str(), 52);
108 while(!rTr.
Eos(
"Actions")) {
150 std::stringstream errstr;
151 errstr <<
"Invalid output event property" << rTr.
FileLine();
152 throw Exception(
"AttributeSignalOutput::Read", errstr.str(), 52);
177 FD_DHV(
"AttributeSignalInput(" <<
this <<
"):DoAssign(): assignment from " << &rSrcAttr);
178 mTriggers=rSrcAttr.mTriggers;
184 (void) rLabel; (void) pContext;
185 FD_DHV(
"AttributeSignalInput()::DoWrite()");
187 std::vector<Trigger>::const_iterator ait;
190 if(ait->mPos && (!ait->mNeg)) {
193 if((!ait->mPos) && ait->mNeg) {
196 if((ait->mPos) && ait->mNeg) {
210 (void) rLabel; (void) pContext;
212 FD_DHV(
"AttributeSignalInput()::DoRead(tr)");
222 while(!rTr.
Eos(
"Triggers")) {
226 if (value ==
"PosEdge") {
229 }
else if (value ==
"NegEdge") {
232 }
else if (value ==
"AnyEdge") {
244 std::stringstream errstr;
245 errstr <<
"invalid input event property" << rTr.
FileLine();
246 throw Exception(
"AttributeSignalInput::Read", errstr.str(), 52);
257 while(!rTr.
Eos(
"Triggers")) {
303 std::stringstream errstr;
304 errstr <<
"Invalid input event property" << rTr.
FileLine();
305 throw Exception(
"AttributeSignalInput::Read", errstr.str(), 52);
330 FD_DHV(
"AttributeSignalEvent::AttributeSignalEvent(" <<
this <<
")");
331 pOutputPrototype=OutputPrototypep();
332 pInputPrototype=InputPrototypep();
339 FD_DHV(
"AttributeSimplenetEvent(" <<
this <<
"): form other attr " << &rOtherAttr);
398 faudes_mutex_init(&
mMutex);
400 mName=
"SignalDevice";
414 faudes_mutex_destroy(&
mMutex);
481 rTr.
ReadEnd(
"SynchronousWrite");
497#define LOCK_E {int rc = faudes_mutex_lock(&mMutex); \
498 if(rc) {FD_ERR("sDevice("<<mName<<")::LOCK_E: lock mutex error\n"); exit(1); }}
499#define UNLOCK_E {int rc = faudes_mutex_unlock(&mMutex); \
500 if(rc) {FD_ERR("sDevice("<<mName<<")::LOCK_E: unlock mutex error\n"); exit(1); }}
503#define TLOCK_E {int rc = faudes_mutex_lock(&sdevice->mMutex); \
504 if(rc) {FD_ERR("sDevice::TLOCK_E: lock mutex error\n"); exit(1); }}
506#define TUNLOCK_E {int rc = faudes_mutex_unlock(&sdevice->mMutex); \
507 if(rc) {FD_ERR("sDevice::TLOCK_E: unlock mutex error\n"); exit(1); }}
527 FD_ERR(
"sDevice("<<
mName<<
")::Start(): cannot creat thread\n");
544 FD_DHV(
"sDevice("<<
mName<<
")::Stop(): Lock passed, waiting to join thread");
549 FD_ERR(
"sDevice("<<
mName<<
")::Stop(): cannot join thread??\n");
565 FD_DHV(
"sDevice("<<
mName<<
")::Reset(): reset signals");
602 std::vector<AttributeSignalInput::Trigger>::const_iterator ait;
612 std::vector<AttributeSignalOutput::Action>::const_iterator ait;
619 "Inv-Action is only supported with SyncWrite", 52);
632#ifdef FAUDES_DEBUG_IODEVICE
635 FD_DH(
"sDevice(" <<
mName <<
")::Compile(): output signal at address " << i);
695 FD_DHV(
"sDevice(" <<
mName <<
")::CycleTime(int)");
697 std::stringstream errstr;
698 errstr <<
"Changing cycle-time not possible while background thread is still running ";
699 throw Exception(
"sDevice::CycleTime: ", errstr.str(), 100);
707 FD_DHV(
"sDevice(" <<
mName <<
")::ReadSignal(int)");
710 std::stringstream errstr;
711 errstr <<
"(" <<
mName <<
") is not able to read signals";
712 throw Exception(
"sDevice::ReadSignal():", errstr.str(), 552);
716 std::stringstream errstr;
717 errstr <<
"Signal access not possible while background thread is not running ";
718 throw Exception(
"sDevice::ReadSignal: ", errstr.str(), 552);
736 FD_DHV(
"sDevice(" <<
mName <<
")::WriteSignal(int)");
739 std::stringstream errstr;
740 errstr <<
"(" <<
mName <<
") is not configured for outputs";
741 throw Exception(
"sDevice::WriteSignal():", errstr.str(), 552);
745 std::stringstream errstr;
746 errstr <<
"Signal access not possible while background thread is not running ";
747 throw Exception(
"sDevice::ReadSignal: ", errstr.str(), 552);
779 FD_DH(
"sDevice(" << sdevice->
mName <<
")::Synchro(" << sdevice <<
"): with ct " << sdevice->
mCycleTime);
781#ifdef FAUDES_DEBUG_IOTIMING_X
789 faudes_systime_t* timeA =
new faudes_systime_t[MAX_SAMPLES];
790 faudes_systime_t* timeB =
new faudes_systime_t[MAX_SAMPLES];
791 faudes_systime_t* timeC =
new faudes_systime_t[MAX_SAMPLES];
795 faudes_gettimeofday(timeA+itime);
803 faudes_systime_t timeL1;
804 faudes_gettimeofday(&timeL1);
818 FD_DHV(
"sDevice("<<sdevice->
Name()<<
")::synchro: reset: clear lines");
834 FD_DHV(
"sDevice("<<sdevice->
Name()<<
")::synchro: reset: edge detection");
876 FD_DHV(
"sDevice::synchro: sensed positive edge at bit address " << bit);
882 for(; eit!=eit_end; eit++) {
887 FD_DHV(
"sDevice::synchro: send signal " );
892 FD_DHV(
"sDevice::synchro: sensed negative edge at bit address " << bit);
899 for(; eit!=eit_end; eit++) {
904 FD_DHV(
"sDevice::synchro: send signal " );
924 if(!level->
edge)
continue;
943#ifdef FAUDES_DEBUG_IOTIMING_X
946 if(itime < MAX_SAMPLES) faudes_gettimeofday(timeB+itime);
950 faudes_systime_t timeL2;
951 faudes_gettimeofday(&timeL2);
952 long int delta = (timeL2.tv_nsec - timeL1.tv_nsec)/1000;
953 delta+= 1000000 * (timeL2.tv_sec - timeL1.tv_sec);
958 FD_DH(
"sDevice::synchro: missed cycle time by " << delta - sdevice->
mCycleTime <<
" usec");
962#ifdef FAUDES_DEBUG_IOTIMING_X
967 if(itime < MAX_SAMPLES) faudes_gettimeofday(timeC+itime);
970 if(itime < MAX_SAMPLES) faudes_gettimeofday(timeA+itime);
978#ifdef FAUDES_DEBUG_IOTIMING_X
983 FD_DHT(
"sDevice::synchro: performance analysis");
988 SamplesA.
Name(
"time stamp AA: overall period");
993 SamplesB.
Name(
"time stamp AB: process time");
998 SamplesC.
Name(
"time stamp CB: sleep time");
1003 SamplesWS.
Name(
"time passed till the next call of WaitInputs");
1006 faudes_systime_t dAA,dBA,dCB,dER;
1010 for(
int ind = 0; ind < itime-2; ind++){
1021 SamplesA.
Sample(dAA.tv_sec*1000000 + dAA.tv_nsec/1000);
1022 SamplesB.
Sample(dBA.tv_sec*1000000 + dBA.tv_nsec/1000);
1023 SamplesC.
Sample(dCB.tv_sec*1000000 + dCB.tv_nsec/1000);
1024 SamplesWS.
Sample(1000000*dER.tv_sec + dER.tv_nsec/1000);
1040 std::cout << SamplesA.
Str() << std::endl;
1041 std::cout << SamplesB.
Str() << std::endl;
1042 std::cout << SamplesC.
Str() << std::endl;
1043 std::cout << SamplesWS.
Str() << std::endl;
1046 FD_DH(
"sDevice(" << sdevice->
mName <<
")::synchro: terminate background thread");
1047 faudes_thread_exit(NULL);
1055 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput(" << output <<
")");
1060 std::stringstream errstr;
1061 errstr <<
"Unknown output event " << output;
1062 throw Exception(
"sDevice::WriteOutput", errstr.str(), 65);
1067 std::stringstream errstr;
1068 errstr <<
"Invalid output attribute " << output;
1069 throw Exception(
"sDevice::WriteOutput", errstr.str(), 65);
1072 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: properties found");
1074 std::vector<AttributeSignalOutput::Action>::const_iterator eit;
1081 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: mBit "<<eit->mBit<<
" mValue "<<eit->mValue);
1093 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: mBit "<<eit->mBit<<
" mValue "<<eit->mValue);
1095 switch(eit->mValue) {
1097 level->
next=1;
break;
1099 level->
next=0;
break;
1110 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: done");
1119 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): lock mutex ");
1121 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): edge detection ");
1125 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): edge detetion ReadSignal bit " << bit);
1138 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): edge detetion ReadSignal bit " << bit);
1150 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): initialize recent edges ");
1157 redge->
lost =
false;
1165 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): done");
1176 FD_DHV(
"sDevice("<<
mName<<
")::ClrOutputSignals: passed lock");
1193 FD_DHV(
"sDevice("<<
mName<<
")::ClrOutputSignals: done");
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
const AttributeVoid * pOutputPrototype
const AttributeVoid * pInputPrototype
bool IsOutput(void) const
static const AttributeSignalOutput * OutputPrototypep(void)
const AttributeSignalInput * Inputp(void) const
void DoAssign(const AttributeSignalEvent &rSrc)
static const AttributeSignalInput * InputPrototypep(void)
AttributeSignalEvent(void)
const AttributeSignalOutput * Outputp(void) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
std::vector< Action > mActions
const std::string & Name(void) const
std::string Str(void) const
bool Exists(const Idx &rIndex) const
void Sample(Time::Type time)
long int ReadInteger(void)
std::string FileLine(void) const
std::string ReadOption(void)
bool Eos(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
const std::string & StringValue(void) const
Int AttributeIntegerValue(const std::string &name)
bool IsInteger(void) const
bool ExistsAttributeString(const std::string &name)
void SetEmpty(const std::string &rName)
const std::string & OptionValue(void) const
void InsAttributeInteger(const std::string &name, Int value)
void InsAttributeString(const std::string &name, const std::string &value)
bool IsOption(void) const
const std::string & AttributeStringValue(const std::string &name)
virtual int CycleTime() const
void ClrOutputSignals(void)
virtual void DoReadSignalsPost(void)
virtual void WriteOutput(Idx output)
virtual void DoWriteSignalsPost(void)
std::map< int, EventSet > mInputNegEdgeIndexMap
Edges * mpRecentInputEdges
virtual void DoReadPreface(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
virtual bool DoWriteSignalsPre(void)
faudes_thread_t mThreadSynchro
void InsInputEvent(const std::string &event)
void DoWritePreface(TokenWriter &rTw, const std::string &rLabel, const Type *pContext=0) const
virtual void DoLoopCallback(void)
void AppendAction(const std::string &event, const Action &action)
friend void * SDeviceSynchro(void *)
void InsOutputEvent(const std::string &event)
virtual bool DoReadSignal(int bitaddr)=0
virtual void DoWriteSignal(int bitaddr, bool value)=0
virtual bool DoReadSignalsPre(void)
TaNameSet< AttributeSignalEvent > * pConfiguration
void AppendTrigger(const std::string &event, const Trigger &trigger)
std::map< int, EventSet > mInputPosEdgeIndexMap
void ClrInputSignals(void)
void WriteSignal(int bitaddr, bool value)
std::map< int, EventSet > mOutputLevelIndexMap
bool ReadSignal(int bitaddr)
virtual void Compile(void)
faudes_mutex_t * pBufferMutex
virtual const EventSet & Inputs(void) const
virtual void Compile(void)
std::string mDefaultLabel
faudes_cond_t * pWaitCondition
virtual void DoReadPreface(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
EventSet * mpConfiguration
virtual void DoWritePreface(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void Name(const std::string &rName)
std::deque< Idx > * pInputBuffer
virtual const EventSet & Outputs(void) const
void * SDeviceSynchro(void *arg)
AutoRegisterType< TaNameSet< AttributeSignalEvent > > gRti1RegisterSignalDeviceEventSet("SignalDeviceEventSet")
AutoRegisterElementTag< TaNameSet< AttributeSignalEvent > > gRti1ElementTagSignalDeviceEventSet("SignalDeviceEventSet", "Event")