socan 1.2.1
Linux SocketCAN higher level library
Loading...
Searching...
No Matches
scitest.c
1
23/* scitest
24
25command line test program for sci
26*/
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <stdarg.h>
31#include <string.h>
32#include <ctype.h>
33#include <stdbool.h>
34#include <time.h>
35
36#include <socan.h>
37#include <sci.h>
38
39#include <socan_util.h>
40
41/* ----------------------------------------------
42 * constants
43 * ---------------------------------------------- */
44
45#define VERSION "1.0"
46
47/* ----------------------------------------------
48 * types
49 * ---------------------------------------------- */
50
51typedef enum { T_CHECK=2, T_REMOTE=4, T_LEAVE=8, T_CONSISTENCE=16,
52 T_IGNORE_OLD=32
53 } testflags;
54
55enum options {
56 HELP,
57 INTERFACE,
58 LEAVE,
59 REALTIME,
60 TRACE,
61 ERRPRINTLEVEL,
62 LOOP,
63 SLEEP,
64 QUIET,
65 SIZE,
66 COUNT,
67 CHECK,
68 REMOTE,
69 CONSISTENCE,
70 IGNORE_OLD,
71 RWTEST,
72 READ,
73 READ_NOW,
74 QUEUE_READ,
75 WRITE,
76 WRITE_W,
77 WRITE_INHIBIT,
78 };
79
80enum commands {
81 CMD_NOTHING,
82 CMD_RWTEST,
83 CMD_READ,
84 CMD_READ_NOW,
85 CMD_QUEUE_READ,
86 CMD_WRITE,
87 CMD_WRITE_W,
88 CMD_WRITE_INHIBIT
89 };
90
91/* ----------------------------------------------
92 * tests
93 * ---------------------------------------------- */
94
95static void test_simple_rw(int object1, int port1, int object2, int port2,
96 int w_timeout, int r_timeout,
97 int flag)
98 {
99 sci_Return rc;
100 sci_Struc *s_struc;
101 sci_Errcode err;
102 sci_Object *obj1, *obj2;
103 char wbuf[8]= {0,0,0,0,0,0,0,0};
104 char rbuf[8]= {0,0,0,0,0,0,0,0};
105 int i;
106
107 printf("opening sci :\n");
108
109 rc= sci_open(&s_struc, "", &err);
110 if (rc!=SCI_NOTHING)
111 {
112 printf("sci_open returned %s, aborting\n",
113 sci_str_status(rc));
114 return;
115 }
116 printf("8 bytes will be written, content of these 8 bytes:\n");
117 printf("1 2 3 4 5 6 7 8\n");
118 printf("set write-mode for object %d, port %d ...",object1, port1);
119 printf("(timeout %d)\n", w_timeout);
120 rc= sci_init_object(s_struc, &obj1, port1, object1, 8, w_timeout,
121 SCI_WRITE, NULL);
122 if (rc!=SCI_NOTHING)
123 {
124 printf("sci_init_object returned %s, aborting\n",
125 sci_str_status(rc));
126 sci_close(&s_struc);
127 return;
128 }
129
130 printf("set read-mode for object %d, port %d ...",object2, port2);
131 printf("(timeout %d)\n", r_timeout);
132 rc= sci_init_object(s_struc, &obj2, port2, object2, 8, r_timeout,
133 SCI_READ, NULL);
134 if (rc!=SCI_NOTHING)
135 {
136 printf("sci_init_object returned %s, aborting\n",
137 sci_str_status(rc));
138 sci_close(&s_struc);
139 return;
140 }
141 for (i=1; i<=8; i++)
142 wbuf[i-1]=i;
143
144 printf("now writing the data...");
145 rc= sci_write(s_struc, obj1, wbuf);
146 if (rc!=SCI_NOTHING)
147 {
148 printf("sci_write returned %s, aborting\n",
149 sci_str_status(rc));
150 sci_close(&s_struc);
151 return;
152 }
153 /*
154 mldelay(100000);
155 return;
156 */
157
158 printf("now reading the data...");
159 rc= sci_read(s_struc, obj2, rbuf);
160 if (rc!=SCI_NOTHING)
161 {
162 printf("sci_read returned %s, aborting\n",
163 sci_str_status(rc));
164 sci_close(&s_struc);
165 return;
166 }
167
168 printf("message-content:\n");
169 nice_dump(rbuf, 8, 0);
170
171 printf("closing sci...\n");
172 sci_close(&s_struc);
173 }
174
175static void test_read(int object, int port, unsigned int timeout,
176 int loops,
177 double sleep,
178 int quietlevel, bool readnow,
179 int countsize, int flag)
180 {
181 sci_Return rc;
182 sci_Struc *s_struc;
183 sci_Errcode err;
184 sci_Object *obj;
185 char cbuf[8]= {0, 0, 0, 0, 0, 0, 0, 0}; /* counter is at byte 4 ! */
186
187 int mask;
188 int scale, i, l;
189 unsigned long c,count= 0;
190 char ch;
191 bool print_err;
192 char *func_name;
193 sci_Object_Type objtype;
194
195 if (readnow)
196 func_name= "sci_read_now";
197 else
198 func_name= "sci_read";
199
200 if (countsize>=sizeof(int))
201 mask= 0xFFFFFFFF;
202 else
203 mask= 0xFFFFFFFF >> ((sizeof(int)-countsize)*8);
204 if (sleep!=0)
205 {
206 printf("sleeping %f seconds...\n", sleep);
207 mldelay((long)(sleep*1000+0.5));
208 }
209 printf("opening sci :\n");
210
211 rc= sci_open(&s_struc, "", &err);
212 if (rc!=SCI_NOTHING)
213 {
214 printf("sci_open returned %s, aborting\n",
215 sci_str_status(rc));
216 return;
217 }
218
219 printf("defining read-object...\n");
220 if (flag & T_REMOTE)
221 objtype= SCI_REMOTE_READ;
222 else
223 objtype= SOCAN_READ;
224 rc= sci_init_object(s_struc, &obj, port, object, countsize, timeout,
225 objtype, NULL);
226 if (rc!=SCI_NOTHING)
227 {
228 printf("sci_init_object returned %s, aborting\n",
229 sci_str_status(rc));
230 sci_close(&s_struc);
231 return;
232 }
233
234 eval_quietlevel(quietlevel, &scale, &ch, &l);
235
236 for(; loops>0; loops--)
237 {
238 if (readnow)
239 rc= sci_read_now(s_struc, obj, cbuf);
240 else
241 rc= sci_read(s_struc, obj, cbuf);
242 if (quietlevel>0)
243 { if (scale)
244 if ((--l)<=0)
245 { l= scale; putchar(ch); fflush(stdout); };
246 }
247 else
248 { printf("received: data:\n");
249 nice_dump(cbuf, countsize, 0);
250 };
251 if (rc!= SCI_NOTHING)
252 {
253 print_err= true;
254 if ((rc==SCI_OLD_DATA) && (flag & T_IGNORE_OLD))
255 print_err= false;
256 if (print_err)
257 { if ((quietlevel>0) && (rc == SCI_LOST))
258 {
259 putchar('L'); fflush(stdout);
260 }
261 else
262 {
263 if (!(rc & SCI_ERROR))
264 { /* no error */
265 printf("%s returned %d (%s)\n",
266 func_name, rc, sci_str_status(rc));
267 }
268 else
269 {
270 sci_get_errcode(s_struc, &err);
271 printf("%s returned error %d (%s)\n",
272 func_name, err, sci_str_err(err));
273 }
274 };
275 };
276 };
277 if (flag & T_CHECK)
278 {
279 if (flag & T_CONSISTENCE)
280 {
281 c= cbuf[0];
282 for (i=1; i<countsize; i++)
283 if (c!= cbuf[i])
284 {
285 printf("INCONSISTENT DATA!\n");
286 printf("received: data:\n");
287 nice_dump(cbuf, countsize, 0);
288 break;
289 };
290 }
291 else
292 {
293 c=0;
294 memcpy(&c, cbuf, countsize);
295 if (c != count)
296 {
297 if ((c>count) || (countsize>1))
298 {
299 if (quietlevel>1)
300 printf("[%lx,%lx]",c,count);
301 else
302 printf("%ld messages missed, got:%ld expected:%ld\n",
303 c-count, c, count);
304 }
305 else
306 printf("messages repeated, got:%ld, expected:%ld\n",
307 c, count);
308 count=c;
309 };
310 count++;
311 count&= mask;
312 };
313 };
314 } /* for */
315 if (flag & T_LEAVE)
316 {
317 printf("driver (on request) not closed!\n");
318 for(;;) mldelay(60*1000);
319 }
320
321 printf("closing sci...\n");
322 sci_close(&s_struc);
323 }
324
325static void test_queue_read(int port, unsigned int timeout,
326 int *ids, int id_no,
327 int loops,
328 double sleep,
329 int quietlevel,
330 int countsize, int flag)
331 {
332 sci_Return rc;
333 sci_Struc *s_struc;
334 sci_Errcode err;
335 sci_Object **objs;
336 sci_Object *obj;
337 char cbuf[8]= {0, 0, 0, 0, 0, 0, 0, 0}; /* counter is at byte 4 ! */
338
339 int mask;
340 int scale, i, l;
341 unsigned long c;
342 char ch;
343 bool print_err;
344 unsigned long *count= NULL;
345 int *indices= NULL;
346 int *index;
347
348 if (id_no <=0)
349 {
350 printf("wrong id_no: %d\n", id_no);
351 return;
352 }
353 count= calloc(COB_NO, sizeof(unsigned long));
354 indices= calloc(COB_NO, sizeof(int));
355 objs= calloc(COB_NO, sizeof(sci_Object *));
356
357 if (countsize>=sizeof(int))
358 mask= 0xFFFFFFFF;
359 else
360 mask= 0xFFFFFFFF >> ((sizeof(int)-countsize)*8);
361
362 if (sleep!=0)
363 {
364 printf("sleeping %f seconds...\n", sleep);
365 mldelay((long)(sleep*1000+0.5));
366 }
367 printf("opening sci :\n");
368
369 rc= sci_open(&s_struc, "", &err);
370 if (rc!=SCI_NOTHING)
371 {
372 printf("sci_open returned %s, aborting\n",
373 sci_str_status(rc));
374 return;
375 }
376
377 printf("defining read-objects...\n");
378
379 for(i=0; i<id_no; i++)
380 {
381 indices[i]= i;
382 /* for now, no support for RTR objects here: */
383 rc= sci_init_object(s_struc, &(objs[i]), port, ids[i],
384 countsize, timeout,
385 SCI_READ, &(indices[i]));
386 if (rc!=SCI_NOTHING)
387 {
388 printf("sci_init_object returned %s, aborting\n",
389 sci_str_status(rc));
390 sci_close(&s_struc);
391 return;
392 }
393 rc= sci_set_callback(s_struc, objs[i], NULL);
394 if (rc!=SCI_NOTHING)
395 {
396 printf("sci_set_callback returned %s, aborting\n",
397 sci_str_status(rc));
398 sci_close(&s_struc);
399 return;
400 }
401 }
402
403 eval_quietlevel(quietlevel, &scale, &ch, &l);
404
405 for(; loops>0; loops--)
406 {
407 rc= sci_queue_read(s_struc, &obj, cbuf);
408 if (!(rc & SCI_ERROR))
409 index= sci_get_user(obj);
410 if (quietlevel>0)
411 { if (scale)
412 if ((--l)<=0)
413 { l= scale; putchar(ch); fflush(stdout); };
414 }
415 else
416 { printf("received on %d: data:\n", ids[*index]);
417 nice_dump(cbuf, countsize, 0);
418 };
419 if (rc!= SCI_NOTHING)
420 {
421 print_err= true;
422 if ((rc==SCI_OLD_DATA) && (flag & T_IGNORE_OLD))
423 print_err= false;
424 if (print_err)
425 { if ((quietlevel>0) && (rc == SCI_LOST))
426 {
427 putchar('L'); fflush(stdout);
428 }
429 else
430 {
431 if (!(rc & SCI_ERROR))
432 { /* no error */
433 printf("sci_queue_read returned %d (%s)\n",
434 rc, sci_str_status(rc));
435 }
436 else
437 {
438 sci_get_errcode(s_struc, &err);
439 printf("sci_queue_read returned error %d (%s)\n",
440 err, sci_str_err(err));
441 }
442 };
443 };
444 };
445 if (flag & T_CHECK)
446 {
447 if (flag & T_CONSISTENCE)
448 {
449 c= cbuf[0];
450 for (i=1; i<countsize; i++)
451 if (c!= cbuf[i])
452 {
453 printf("INCONSISTENT DATA!\n");
454 printf("received: data:\n");
455 nice_dump(cbuf, countsize, 0);
456 break;
457 };
458 }
459 else
460 {
461 c=0;
462 memcpy(&c, cbuf, countsize);
463 if (c != (count[*index]))
464 {
465 if ((c>(count[*index])) || (countsize>1))
466 {
467 if (quietlevel>1)
468 printf("[%lx,%lx]",c,(count[*index]));
469 else
470 printf("%ld messages missed, got:%ld expected:%ld\n",
471 c-(count[*index]), c, (count[*index]));
472 }
473 else
474 printf("messages repeated, got:%ld, expected:%ld\n",
475 c, (count[*index]));
476 (count[*index])=c;
477 };
478 (count[*index])++;
479 (count[*index])&= mask;
480 };
481 };
482 } /* for */
483 if (flag & T_LEAVE)
484 {
485 printf("driver (on request) not closed!\n");
486 for(;;) mldelay(60*1000);
487 }
488
489 printf("closing sci...\n");
490 sci_close(&s_struc);
491 }
492
493/* the usage of the counter is adjusted to a little-endian machine ! */
494static void test_write(int object, int port, unsigned int timeout,
495 unsigned long inhibit_tm,
496 int loops,
497 double sleep,
498 int quietlevel,
499 int write_cmd,
500 int countsize, int countstart,
501 int flag)
502 {
503 sci_Return rc;
504 sci_Struc *s_struc;
505 sci_Errcode err;
506 sci_Object *obj;
507 char cbuf[8]= {0, 0, 0, 0, 0, 0, 0, 0}; /* counter is at byte 4 ! */
508 int i;
509 char ch;
510 int scale;
511 int l;
512 bool timed= (write_cmd==CMD_WRITE_INHIBIT);
513 bool busy_wait= (write_cmd==CMD_WRITE_W);
514 unsigned long counter;
515 unsigned long timeval;
516 char *func_name;
517 sci_Object_Type objtype;
518
519 switch (write_cmd)
520 {
521 case CMD_WRITE_INHIBIT:
522 func_name= "sci_write_inhibit";
523 break;
524 case CMD_WRITE:
525 case CMD_WRITE_W:
526 func_name= "sci_write";
527 break;
528 default:
529 printf("internal error line %d\n", __LINE__);
530 return;
531 }
532
533 counter=countstart;
534
535 if (sleep!=0)
536 {
537 printf("sleeping %f seconds...\n", sleep);
538 mldelay((long)(sleep*1000+0.5));
539 }
540 printf("opening sci :\n");
541
542 rc= sci_open(&s_struc, "", &err);
543 if (rc!=SCI_NOTHING)
544 {
545 printf("sci_open returned %s, aborting\n",
546 sci_str_status(rc));
547 return;
548 }
549
550 printf("defining write-object...\n");
551 if (flag & T_REMOTE)
552 objtype= SCI_REMOTE_WRITE;
553 else
554 objtype= SCI_WRITE;
555 rc= sci_init_object(s_struc, &obj, port, object, countsize, timeout,
556 objtype, NULL);
557 if (rc!=SCI_NOTHING)
558 {
559 printf("sci_init_object returned %s, aborting\n",
560 sci_str_status(rc));
561 sci_close(&s_struc);
562 return;
563 }
564
565 if (timed)
566 {
567 rc= sci_set_inhibit(s_struc, obj, inhibit_tm);
568 if (rc!=SCI_NOTHING)
569 {
570 printf("scitest.c line %d: sci_set_inhibit returned "
571 "an error: %d (%s)\n", __LINE__, rc, sci_str_status(rc));
572 printf("test-abort!\n");
573 sci_close(&s_struc);
574 return;
575 }
576 }
577
578 eval_quietlevel(quietlevel, &scale, &ch, &l);
579
580 for(; loops>0; loops--)
581 { if (flag & T_CONSISTENCE)
582 {
583 unsigned char b= (unsigned char) counter;
584 for(i=0; i<countsize; cbuf[i++]= b);
585 /* int converted to byte ^^^^ !*/
586 }
587 else
588 {
589 /* native endianess: */
590 memcpy(cbuf, &counter, countsize);
591 };
592 if (quietlevel>0)
593 { if (scale)
594 if ((--l)<=0)
595 { l= scale; putchar(ch); fflush(stdout); };
596 }
597 else
598 { if (flag & T_CONSISTENCE)
599 printf("consistency test with byte %lu\n", counter & 0xFF);
600 else
601 { printf("writing %lu, %d bytes on %d\n",
602 counter, countsize, object);
603 };
604 };
605 w_again:
606 switch (write_cmd)
607 {
608 case CMD_WRITE_INHIBIT:
609 timeval= inhibit_tm; /* reset the inhibit-time parameter*/
610 rc= sci_write_inhibit(s_struc, obj, cbuf, &timeval);
611 break;
612 case CMD_WRITE:
613 case CMD_WRITE_W:
614 rc= sci_write(s_struc, obj, cbuf);
615 break;
616 default:
617 printf("INTERNAL ERROR AT LINE %d\n", __LINE__);
618 }
619 if (rc!= SCI_NOTHING)
620 {
621 if (busy_wait)
622 if (rc == SCI_WAIT) /* we have to busy-wait... */
623 goto w_again;
624
625 if (timed)
626 if (rc == SCI_WAIT) /* we have to wait... */
627 {
628 micdelay(timeval);
629 goto w_again;
630 };
631 if (rc & SCI_ERROR)
632 {
633 sci_get_errcode(s_struc, &err);
634 printf("scitest.c line %d: %s returned an error: %d (%s)\n",
635 __LINE__, func_name, err, sci_str_err(err));
636 }
637 else
638 printf("%s return code: %d (%s)\n", func_name, rc, sci_str_status(rc));
639 };
640 counter++;
641 };
642 if (quietlevel>0)
643 printf("\n");
644
645 if (flag & T_LEAVE)
646 { printf("driver (on request) not closed!\n");
647 for(;;) mldelay(60*1000);
648 }
649
650 printf("closing sci...\n");
651 sci_close(&s_struc);
652 }
653
654/* ----------------------------------------------
655 * main
656 * ---------------------------------------------- */
657
658void print_help(void)
659 {
660 printf(" **** scitest %s ****\n", VERSION);
661 printf("the sci test program\n"
662 "usage:\n"
663 "scitest {options}\n"
664 "options:\n"
665 " **************** Configuration*****************\n"
666 " --interface,-i INTERFACE \n"
667 " Use INTERFACE for CAN communication, this option\n"
668 " can be given more than once to use more than one\n"
669 " interface.\n"
670 " --realtime READER-PRIORITY WRITER-PRIORITY\n"
671 " Use given realtime priorities for reader and writer\n"
672 " thread.\n"
673 " --leave\n"
674 " for all functions that define CAN-objects, hold the\n"
675 " program just before close() is performed. All CAN\n"
676 " objects remain defined. End the program with CRTL-C in\n"
677 " this case\n"
678 " --trace,-t LEVEL\n"
679 " set trace level, LEVEL is an integer 0..2 (default 0)\n"
680 " --errprintlevel,-E LEVEL\n"
681 " set errprint level, LEVEL is an integer 0..3 (default 1)\n"
682 );
683 printf(" *************** command options ***************\n"
684 " --loop {no of loops}\n"
685 " run read, write, readnow or readmany in loop-mode\n"
686 " --sleep {seconds}\n"
687 " sleep a number of seconds before starting the test.\n"
688 " seconds may be a floating point number.\n"
689 " --quiet,-q {level}\n"
690 " run read, write, readnow or readmany in quiet-mode\n"
691 " level may be 1 .. 5, meaning that each 10**(level-1)\n"
692 " events print a single character on the screen.\n"
693 " --check\n"
694 " check sequence in --read, (must be used together with\n"
695 " --write in another sotest-task\n"
696 " --size,-s [bytes]\n"
697 " use [bytes] bytes to transfer and receive data\n"
698 " --count [number]\n"
699 " use [number] as initial number to write with -w\n"
700 " --consistence\n"
701 " send alternating 8 bytes of 0xFF or 0x00 to test data\n"
702 " consistence\n"
703 " --remote \n"
704 " do remote-read or remote-write, implemented for\n"
705 " --write and --read\n"
706 );
707 printf(" ***************data transmission commands****************\n"
708 " --rwtest [object1] [port1] [object2] [port2] "
709 "[write-timeout] [read-timeout]\n"
710 " make a write-object (object1,port1) and a read-object\n"
711 " (object2,port2) with a timeout set for the 2nd object\n"
712 " then write 8 bytes (values 1 to 8) and read the 2nd\n"
713 " object (read immediately) and return the results\n"
714 " --write,-w [object] [port] [timeout]\n"
715 " write data (a running counter), non blocking\n"
716 " --write-w [object] [port] [timeout]\n"
717 " the same as --write but do silently retry to write\n"
718 " when the driver returns a SOCAN_WAIT status.\n"
719 " --writeinhibit [object] [port] [timeout] [inhibit-time]\n"
720 " similar to writelater, but the CAN-object gets a timestamp\n"
721 " when it is transmitted. Inhibit-time is the minumum\n"
722 " time that has to pass before a new object is sent. This\n"
723 " concerns only writeinhibit combined with the loop-command.\n"
724 " In this case only about every [inhibit-time]\n"
725 " microseconds new data will be sent (note that the unit\n"
726 " for this parameter is microseconds, not milliseconds\n"
727 " --read,-r [object] [port] [timeout]\n"
728 " read data from an object (blocking).\n"
729 " --readnow [object] [port] [timeout]\n"
730 " read data from an object (immediately).\n"
731 " --queue-read [port] [timeout] [object] {[object]}\n"
732 " read more than one object via the signal-function in \n"
733 " conjunction with the new queue-read operation\n"
734 " together with --remote, all objects will be remote-read\n"
735 " objects\n"
736 "\n");
737 }
738
739#define MAX_INTERFACES 4
740
741int main( int argc, char *argv[])
742
743 {
744 static option options[]=
745 {
746 { "-h" , HELP },
747 { "--help" , HELP },
748 { "-i" , INTERFACE },
749 { "--interface" , INTERFACE },
750 { "--loop" , LOOP},
751 { "-t" , TRACE},
752 { "--trace" , TRACE},
753 { "-E" , ERRPRINTLEVEL},
754 { "--errprintlevel", ERRPRINTLEVEL},
755 { "--sleep" , SLEEP},
756 { "-q" , QUIET},
757 { "--quiet" , QUIET},
758 { "--check" , CHECK},
759 { "-s" , SIZE},
760 { "--size" , SIZE},
761 { "--count" , COUNT},
762 { "--leave" , LEAVE},
763 { "--realtime" , REALTIME},
764 { "--remote" , REMOTE},
765 { "--consistence" , CONSISTENCE},
766 { "--ignore_old" , IGNORE_OLD},
767 { "--rwtest" , RWTEST},
768 { "-r" , READ},
769 { "--read" , READ},
770 { "--readnow" , READ_NOW},
771 { "--queue-read" , QUEUE_READ},
772 { "-w" , WRITE},
773 { "--write" , WRITE},
774 { "--write-w" , WRITE_W},
775 { "--writeinhibit" , WRITE_INHIBIT},
776 };
777
778 int opt_no= sizeof(options) / sizeof(option);
779 enum commands operation=CMD_NOTHING;
780
781 char *interfaces[MAX_INTERFACES];
782 int interface_no=0;
783 int n[45], i, l, tracelevel= -1, errprintlevel= -1;
784 int flag=0;
785 int loops=1;
786 double sleep= 0;
787 int quietlevel=0;
788 int countsize =sizeof(int);
789 int countstart=0;
790 int last_valid_n;
791 int rc, opt_index;
792 int rt_prios[]= {-1, -1};
793 int opt;
794 char *st;
795
796 if (argc<2)
797 my_exit("error, option/command missing\n");
798
799 opt_index= 1;
800 while(opt_index<argc)
801 {
802 opt= match(argc, argv, &opt_index, options, opt_no);
803 switch (opt)
804 {
805 case -1:
806 my_exit("unknown option: %s\n", argv[opt_index]);
807 case HELP:
808 print_help();
809 return 0;
810 case INTERFACE:
811 if (match_st(argc, argv, &opt_index, &st))
812 my_exit("interface name missing!\n");
813 if (interface_no >= MAX_INTERFACES)
814 my_exit("too many interfaces given (more than %d)\n",
815 MAX_INTERFACES);
816 interfaces[interface_no++]= st;
817 break;
818 case REALTIME:
819 for(i=0; i<=1; i++)
820 {
821 rc= match_int(argc, argv, &opt_index, &(rt_prios[i]));
822 if (rc==-1)
823 my_exit("error, argument missing\n");
824 if (rc==-2)
825 my_exit("error, argument is not a number\n");
826 };
827 break;
828 case SLEEP:
829 rc= match_float(argc, argv, &opt_index, &sleep);
830 if (rc==-1)
831 my_exit("the sleep parameter is missing!\n");
832 if (rc==-2)
833 my_exit("the sleep parameter is is not a number!\n");
834 break;
835 case QUIET:
836 rc= match_int(argc, argv, &opt_index, &quietlevel);
837 if (rc==-1)
838 my_exit("the quiet parameter is missing!\n");
839 if (rc==-2)
840 my_exit("the quiet parameter is is not a number!\n");
841 if ((quietlevel<1) || (quietlevel>5))
842 my_exit("only quiet-levels 1 to 5 are allowed\n"
843 "(input was %d)\n", quietlevel);
844 break;
845 case SIZE:
846 rc= match_int(argc, argv, &opt_index, &countsize);
847 if (rc==-1)
848 my_exit("the count parameter is missing!\n");
849 if (rc==-2)
850 my_exit("the count parameter is is not a number!\n");
851 if ((countsize<1) || (countsize>8))
852 my_exit("[bytes]-parameter must be between 1 and 8 !!\n");
853 break;
854 case COUNT:
855 rc= match_int(argc, argv, &opt_index, &countstart);
856 if (rc==-1)
857 my_exit("the countstart parameter is missing!\n");
858 if (rc==-2)
859 my_exit("the countstart parameter is is not a number!\n");
860 if ((countstart<0))
861 my_exit("[count]-parameter must be greater than 0 !!\n");
862 break;
863 case LOOP:
864 rc= match_int(argc, argv, &opt_index, &loops);
865 if (rc==-1)
866 my_exit("the loop parameter is missing!\n");
867 if (rc==-2)
868 my_exit("the loop parameter is is not a number!\n");
869 if (loops<1)
870 my_exit("loop-parameter should be greater than zero!\n"
871 "(input was %ld)\n", loops);
872 break;
873 case TRACE:
874 rc= match_int(argc, argv, &opt_index, &tracelevel);
875 if (rc==-1)
876 my_exit("the tracelevel parameter is missing!\n");
877 if (rc==-2)
878 my_exit("the tracelevel parameter is is not a number!\n");
879 if (tracelevel<0)
880 my_exit("trace level must be positive\n"
881 "(input was %d)\n", tracelevel);
882 break;
883 case ERRPRINTLEVEL:
884 rc= match_int(argc, argv, &opt_index, &errprintlevel);
885 if (rc==-1)
886 my_exit("the errprintlevel parameter is missing!\n");
887 if (rc==-2)
888 my_exit("the errprintlevel parameter is is not a number!\n");
889 if (errprintlevel<0)
890 my_exit("errprintlevel must be positive\n"
891 "(input was %d)\n", errprintlevel);
892 break;
893 case LEAVE:
894 flag|= T_LEAVE;
895 break;
896 case REMOTE:
897 flag|= T_REMOTE;
898 break;
899 case CHECK:
900 flag|= T_CHECK;
901 break;
902 case CONSISTENCE:
903 /* implies the check-flag, too */
904 flag|= (T_CONSISTENCE | T_CHECK);
905 /* countsize is changed to 8 !!! */
906 countsize= 8;
907 break;
908 case IGNORE_OLD:
909 flag|= T_IGNORE_OLD;
910 break;
911 case RWTEST:
912 if (operation!=CMD_NOTHING)
913 my_exit("contradicting options\n");
914 operation=CMD_RWTEST;
915 for(i=0; i<=5; i++)
916 {
917 rc= match_int(argc, argv, &opt_index, &(n[i]));
918 if (rc==-1)
919 my_exit("error, argument missing\n");
920 if (rc==-2)
921 my_exit("error, argument is not a number\n");
922 };
923 break;
924 case READ:
925 case READ_NOW:
926 if (operation!=CMD_NOTHING)
927 my_exit("contradicting options\n");
928 switch (opt)
929 {
930 case READ:
931 operation=CMD_READ; break;
932 case READ_NOW:
933 operation=CMD_READ_NOW; break;
934 }
935 for(i=0; i<=2; i++)
936 {
937 rc= match_int(argc, argv, &opt_index, &(n[i]));
938 if (rc==-1)
939 my_exit("error, argument missing\n");
940 if (rc==-2)
941 my_exit("error, argument is not a number\n");
942 };
943 break;
944 case QUEUE_READ:
945 if (operation!=CMD_NOTHING)
946 my_exit("contradicting options\n");
947 operation= CMD_QUEUE_READ;
948 rc=0;
949 last_valid_n=-1;
950 while ((rc==0) && (last_valid_n<21))
951 {
952 last_valid_n++;
953 rc= match_int(argc, argv, &opt_index, &(n[last_valid_n]));
954 switch(last_valid_n)
955 {
956 case 0:
957 if (rc!=0)
958 my_exit("error, port missing\n");
959 break;
960 case 1:
961 if (rc!=0)
962 my_exit("error, timeout missing\n");
963 break;
964 case 2:
965 if (rc!=0)
966 my_exit("error, first object-id missing\n");
967 break;
968 default:
969 if (rc!=0)
970 last_valid_n--;
971 break;
972 }
973 };
974 break;
975 case WRITE:
976 case WRITE_W:
977 case WRITE_INHIBIT:
978 if (operation!=CMD_NOTHING)
979 my_exit("contradicting options\n");
980 switch (opt)
981 {
982 case WRITE:
983 operation=CMD_WRITE; break;
984 case WRITE_W:
985 operation=CMD_WRITE_W; break;
986 case WRITE_INHIBIT:
987 operation=CMD_WRITE_INHIBIT; break;
988 }
989 l=2;
990 if (operation==CMD_WRITE_INHIBIT)
991 l=3; /* one more parameter */
992 for(i=0; i<=l; i++)
993 {
994 rc= match_int(argc, argv, &opt_index, &(n[i]));
995 if (rc==-1)
996 my_exit("error, argument missing\n");
997 if (rc==-2)
998 my_exit("error, argument is not a number\n");
999 };
1000 break;
1001 }; /* switch */
1002 }; /* while */
1003 if (interface_no==0)
1004 {
1005 printf("Error, no interfaces defined\n");
1006 return 1;
1007 }
1008 if (!init_socan(interfaces, interface_no,
1009 tracelevel, errprintlevel,
1010 rt_prios[0], rt_prios[1]))
1011 return 1;
1012 switch(operation)
1013 {
1014 case CMD_NOTHING:
1015 printf("error, no command given\n");
1016 return 1;
1017 case CMD_RWTEST:
1018 test_simple_rw(n[0], n[1], n[2], n[3], n[4], n[5],
1019 flag);
1020 break;
1021 case CMD_READ:
1022 case CMD_READ_NOW:
1023 test_read(n[0], n[1], n[2],
1024 loops, sleep, quietlevel,
1025 (operation==CMD_READ_NOW),
1026 countsize, flag);
1027 break;
1028 case CMD_QUEUE_READ:
1029 test_queue_read(n[0], n[1], n+2, last_valid_n-1,
1030 loops, sleep,
1031 quietlevel, countsize, flag);
1032 break;
1033 case CMD_WRITE:
1034 case CMD_WRITE_W:
1035 case CMD_WRITE_INHIBIT:
1036 test_write(n[0], n[1], n[2], n[3],
1037 loops, sleep, quietlevel,
1038 operation,
1039 countsize,countstart,
1040 flag);
1041 break;
1042 }
1043 return(0);
1044 }
c header file for the simple CAN interface (sci)
@ SCI_NOTHING
Definition sci.h:268
@ SCI_WAIT
Definition sci.h:276
@ SCI_OLD_DATA
Definition sci.h:269
@ SCI_ERROR
Definition sci.h:278
@ SCI_LOST
Definition sci.h:270
enum sci_Errcode_Constants sci_Errcode
sci_Object_Type
Definition sci.h:225
@ SCI_READ
Definition sci.h:225
@ SCI_REMOTE_READ
Definition sci.h:227
@ SCI_REMOTE_WRITE
Definition sci.h:228
@ SCI_WRITE
Definition sci.h:226
c header file for socan object layer library.
@ SOCAN_READ
Definition socan.h:163
#define COB_NO
Definition socan.h:146