58 std::cout<<
"% ###############################################################" << std::endl;
59 std::cout<<
"% # InputEvents" << std::endl;
61 std::cout<<
"% ###############################################################" << std::endl;
62 std::cout<<
"% # OutputEvents " << std::endl;
64 std::cout<<
"% ###############################################################" << std::endl;
75 std::cout <<
"% ###############################################################" << std::endl;
76 std::cout <<
"% # ReadTime: current time in ftu: " << dev->
CurrentTime() << std::endl;
77 std::cout <<
"% # ReadTime: using scale: " << dev->
TimeScale() << std::endl;
88 static bool* samplePrevious=0;
89 static bool* sampleCurrent=0;
90 static int sampleSize=-1;
94 if(samplePrevious!=0)
delete samplePrevious;
95 if(sampleCurrent!=0)
delete sampleCurrent;
96 samplePrevious=
new bool[sampleSize];
97 sampleCurrent=
new bool[sampleSize];
100 std::cout <<
"% ###############################################################" << std::endl;
101 for(
int bit=0; bit<sampleSize; bit++) {
102 samplePrevious[bit]=sampleCurrent[bit];
104 for(
int bit=0; bit<sampleSize; bit++) {
107 std::cout <<
"% # ReadValue: current input reading: " << std::endl;
108 for(
int bit=0; bit<sampleSize; bit++) {
109 std::cout<<
"@" << (bit < 10 ?
"0" :
"") << bit <<
":" << sampleCurrent[bit] <<
" ";
110 if((bit%8)==7 || bit+1==sampleSize) std::cout << std::endl;
112 std::cout <<
"% # ReadValue: edges wrt previous reading: " << std::endl;
114 for(
int bit=0; bit<sampleSize; bit++) {
115 if(samplePrevious[bit]!=sampleCurrent[bit]) {
116 std::cout<<
"@"<< (bit < 10 ?
"0" :
"") << bit <<
":" << sampleCurrent[bit] <<
" ";
117 if((cnt%8)==7 || bit+1==sampleSize) std::cout << std::endl;
121 std::cout <<
"% ###############################################################" << std::endl;
127 std::cout<<
"ReadInputs: time (secs) to monitor input signals: ";
128 faudes_mstime_t time_all;
131 std::cout<<
"ReadEvents: time (msecs) to sleep between two polls: ";
132 faudes_mstime_t time_delta;
133 std::cin>>time_delta;
137 faudes_systime_t time_start, time_stop;
138 faudes_gettimeofday(&time_start);
141 static bool* samplePrevious=0;
142 static bool* sampleCurrent=0;
143 static int sampleSize=-1;
147 if(samplePrevious!=0)
delete samplePrevious;
148 if(sampleCurrent!=0)
delete sampleCurrent;
149 samplePrevious=
new bool[sampleSize];
150 sampleCurrent=
new bool[sampleSize];
153 for(
int bit=0; bit<sampleSize; bit++) {
154 samplePrevious[bit]=
false;
155 sampleCurrent[bit]=
false;
160 for(
int time_togo=time_all; time_togo>0; time_togo-=time_delta) {
162 for(
int bit=0; bit<sampleSize; bit++) {
164 if(sampleCurrent[bit] != samplePrevious[bit]) edges=
true;
168 std::cout <<
"% ###############################################################" << std::endl;
169 for(
int bit=0; bit<sampleSize; bit++) {
170 std::cout<<
"@"<< (bit < 10 ?
"0" :
"") << bit <<
":" << sampleCurrent[bit];
171 if(sampleCurrent[bit] != samplePrevious[bit])
175 if((bit%8)==7 || bit+1==sampleSize) std::cout << std::endl;
179 for(
int bit=0; bit<sampleSize; bit++) {
180 samplePrevious[bit]=sampleCurrent[bit];
189 faudes_gettimeofday(&time_stop);
190 faudes_mstime_t diffms;
192 std::cout <<
"# performance: overall time: " << diffms <<
"ms" << std::endl;
193 std::cout <<
"# performance: sleep time: " << time_all <<
"ms" << std::endl;
194 std::cout <<
"# performance: process time per loop: " <<
195 ((double) (diffms - time_all)) / (time_all/time_delta)<<
"ms" << std::endl;
201 std::cout<<
"WriteValue: enter bit address (or -1 to exit): ";
204 std::cout<<
"WriteValue: enter value (or -1 to exit): ";
207 std::cout<<
"WriteValue: setting output " << bit <<
" to value " << val << std::endl;
216 std::cout<<
"WriteOutput: enter event by name: ";
217 std::string testEvent;
220 std::cout<<
"Unknown output event " << std::endl;
231 std::cout<<
"ReadInputs: time (secs) to monitor input events: ";
232 faudes_mstime_t time_all;
235 std::cout<<
"ReadEvents: time (msecs) to sleep between two polls: ";
236 faudes_mstime_t time_delta;
237 std::cin>>time_delta;
241 faudes_systime_t time_start, time_stop;
242 faudes_gettimeofday(&time_start);
245 for(
int time_togo=time_all; time_togo>0; time_togo-=time_delta) {
253 faudes_gettimeofday(&time_stop);
254 faudes_mstime_t diffms;
256 std::cout <<
"# performance: overall time: " << diffms <<
"ms" << std::endl;
257 std::cout <<
"# performance: sleep time: " << time_all <<
"ms" << std::endl;
258 std::cout <<
"# performance: process time per loop: " <<
259 ((double) (diffms - time_all)) / (time_all/time_delta)<<
"ms" << std::endl;
265 std::cout<<
"Enter max. duration (in faudes-time units) to wait for a input-event to occur"<<std::endl;
266 std::cout<<
"Note: 1 faudes-time unit is configured to " << dev->
TimeScale() <<
" msecs" <<std::endl;
275 if(!occuredEvents.
Empty()) std::cout << occuredEvents.
ToString();
276 else std::cout<<
"No event recognized";
285 if(!occuredEvents.
Empty()) std::cout << occuredEvents.
ToString();
286 else std::cout<<
"No event recognized";
293 int main(
int argc,
char* argv[]) {
310 std::cerr <<
"usage: iomonitor <device-file>" << std::endl;
314 #ifdef FAUDES_NETWORK
315 #ifdef FAUDES_WINDOWS
318 if(WSAStartup(MAKEWORD(2,2), &wsaData)!=0) {
319 std::cerr <<
"iomonitor: failed to initialize winsocks" << std::endl;
326 FD_DH(
"Initialize vDevice");
327 std::cout <<
"iomonitor: instantiate device from file" << std::endl;
333 std::cout <<
"iomonitor: starting device " << std::endl;
343 std::cout << std::endl;
344 std::cout << std::endl;
345 std::cout <<
"# iomonitor commands are:" << std::endl;
346 std::cout <<
"#" << std::endl;
347 std::cout <<
"# read faudes event via wait (re)" << std::endl;
348 std::cout <<
"# read faudes events via polling (pe)" << std::endl;
349 std::cout <<
"# flush faudes input events (fe)" << std::endl;
350 if(sdev) std::cout <<
"# read signal value by bitaddress (rs)" << std::endl;
351 if(sdev) std::cout <<
"# read signal values via polling (ps)" << std::endl;
352 std::cout <<
"#" << std::endl;
353 std::cout <<
"# write faudes event (we)" << std::endl;
354 if(sdev) std::cout <<
"# write signal value by bitaddress (ws)" << std::endl;
355 std::cout <<
"#" << std::endl;
356 std::cout <<
"# device time (time)" << std::endl;
357 std::cout <<
"# reset device (reset)" << std::endl;
358 std::cout <<
"# list all device events (list) " << std::endl;
359 std::cout <<
"# exit (exit) " << std::endl;
360 std::cout <<
"#" << std::endl;
366 if(choice==
"exit")
break;
367 if(choice==
"reset") {dev->
Reset();};
380 std::cout <<
"# iomonitor: done " << std::endl;
381 std::cout <<
"##########################################" << std::endl;
384 FD_DH(
"Stopping vDevice");
Set of indices with symbolic names.
bool Exists(const Idx &rIndex) const
Test existence of index.
void SymbolicName(Idx index, const std::string &rName)
Set new name for existing index.
bool Insert(const Idx &rIndex)
Add an element by index.
Idx Index(const std::string &rName) const
Index lookup.
Int Type
Datatype for point on time axis.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
void Write(const Type *pContext=0) const
Write configuration data to console.
An sDevice implements signal based semantics for faudes events.
int MaxBitAddress(void) const
Report max bit address.
void WriteSignal(int bitaddr, bool value)
Set output signal.
virtual void Reset(void)
Clear dynamic data and restart device.
bool ReadSignal(int bitaddr)
Get input signal.
Virtual base class to define the interface for event io.
virtual const EventSet & Inputs(void) const
Get inputs as plain set.
virtual void TimeScale(unsigned int scale)
Set timescale.
static void StopAll(void)
Stop all devices.
virtual DeviceState Status(void)
Get status.
virtual void Stop(void)
Deactivate the device.
virtual void Start(void)
Activate the device.
virtual void WriteOutput(Idx output)=0
Run output command.
virtual void Reset(void)
Reset device.
static vDevice * FromFile(const std::string &rFileName)
Construct on heap from file.
virtual Idx ReadInput(void)
Read sensed input events.
virtual bool WaitInputs(Time::Type duration)
Wait for input trigger.
virtual Time::Type CurrentTime(void)
Report physical time in ftu.
virtual void FlushOutputs(void)
Flush pending IO Operations.
virtual const EventSet & Outputs(void) const
Get outputs as plain set.
bool Empty(void) const
Test whether if the TBaseSet is Empty.
int main(int argc, char *argv[])
void PollInputSignals(sDevice *sdev)
void WaitInputEvent(vDevice *dev)
void ReadTime(vDevice *dev)
void iomonitor_exit(void)
void ListEvents(const vDevice *dev)
void FlushInputEvents(vDevice *dev)
volatile sig_atomic_t signal_in_progress
void WriteOutputEvent(vDevice *dev)
void PollInputEvents(vDevice *dev)
void WriteSignalValue(sDevice *sdev)
void ReadSignalValue(sDevice *dev)
void catch_signal(int sig)
Includes all libFAUDES headers, incl plugings
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
std::string VersionString()
Return FAUDES_VERSION as std::string.