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);
960 #ifdef FAUDES_DEBUG_IOTIMING_X
965 if(itime < MAX_SAMPLES) faudes_gettimeofday(timeC+itime);
968 if(itime < MAX_SAMPLES) faudes_gettimeofday(timeA+itime);
976 #ifdef FAUDES_DEBUG_IOTIMING_X
981 FD_DHT(
"sDevice::synchro: performance analysis");
986 SamplesA.
Name(
"time stamp AA: overall period");
991 SamplesB.
Name(
"time stamp AB: process time");
996 SamplesC.
Name(
"time stamp CB: sleep time");
1001 SamplesWS.
Name(
"time passed till the next call of WaitInputs");
1004 faudes_systime_t dAA,dBA,dCB,dER;
1008 for(
int ind = 0; ind < itime-2; ind++){
1019 SamplesA.
Sample(dAA.tv_sec*1000000 + dAA.tv_nsec/1000);
1020 SamplesB.
Sample(dBA.tv_sec*1000000 + dBA.tv_nsec/1000);
1021 SamplesC.
Sample(dCB.tv_sec*1000000 + dCB.tv_nsec/1000);
1022 SamplesWS.
Sample(1000000*dER.tv_sec + dER.tv_nsec/1000);
1038 std::cout << SamplesA.
Str() << std::endl;
1039 std::cout << SamplesB.
Str() << std::endl;
1040 std::cout << SamplesC.
Str() << std::endl;
1041 std::cout << SamplesWS.
Str() << std::endl;
1044 FD_DH(
"sDevice(" << sdevice->
mName <<
")::synchro: terminate background thread");
1045 faudes_thread_exit(NULL);
1053 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput(" << output <<
")");
1058 std::stringstream errstr;
1059 errstr <<
"Unknown output event " << output;
1060 throw Exception(
"sDevice::WriteOutput", errstr.str(), 65);
1065 std::stringstream errstr;
1066 errstr <<
"Invalid output attribute " << output;
1067 throw Exception(
"sDevice::WriteOutput", errstr.str(), 65);
1070 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: properties found");
1072 std::vector<AttributeSignalOutput::Action>::const_iterator eit;
1079 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: mBit "<<eit->mBit<<
" mValue "<<eit->mValue);
1091 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: mBit "<<eit->mBit<<
" mValue "<<eit->mValue);
1093 switch(eit->mValue) {
1095 level->
next=1;
break;
1097 level->
next=0;
break;
1108 FD_DHV(
"sDevice("<<
mName<<
")::WriteOutput: done");
1117 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): lock mutex ");
1119 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): edge detection ");
1123 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): edge detetion ReadSignal bit " << bit);
1136 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): edge detetion ReadSignal bit " << bit);
1148 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): initialize recent edges ");
1155 redge->
lost =
false;
1163 FD_DHV(
"sDevice("<<
mName<<
")::ClrInputSignals(): done");
1174 FD_DHV(
"sDevice("<<
mName<<
")::ClrOutputSignals: passed lock");
1191 FD_DHV(
"sDevice("<<
mName<<
")::ClrOutputSignals: done");