x_pigpiod_if.c
Go to the documentation of this file.
1 /*
2 gcc -Wall -pthread -o x_pigpiod_if x_pigpiod_if.c -lpigpiod_if
3 ./x_pigpiod_if
4 
5 *** WARNING ************************************************
6 * *
7 * All the tests make extensive use of gpio 25 (pin 22). *
8 * Ensure that either nothing or just a LED is connected to *
9 * gpio 25 before running any of the tests. *
10 * *
11 * Some tests are statistical in nature and so may on *
12 * occasion fail. Repeated failures on the same test or *
13 * many failures in a group of tests indicate a problem. *
14 ************************************************************
15 */
16 
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <ctype.h>
24 
25 #include "pigpiod_if.h"
26 
27 #define GPIO 25
28 
29 void CHECK(int t, int st, int got, int expect, int pc, char *desc)
30 {
31  if ((got >= (((1E2-pc)*expect)/1E2)) && (got <= (((1E2+pc)*expect)/1E2)))
32  {
33  printf("TEST %2d.%-2d PASS (%s: %d)\n", t, st, desc, expect);
34  }
35  else
36  {
37  fprintf(stderr,
38  "TEST %2d.%-2d FAILED got %d (%s: %d)\n",
39  t, st, got, desc, expect);
40  }
41 }
42 
43 void t0()
44 {
45  printf("\nTesting pigpiod C I/F 1\n");
46 
47  printf("pigpio version %d.\n", get_pigpio_version());
48 
49  printf("Hardware revision %d.\n", get_hardware_revision());
50 }
51 
52 void t1()
53 {
54  int v;
55 
56  printf("Mode/PUD/read/write tests.\n");
57 
59  v = get_mode(GPIO);
60  CHECK(1, 1, v, 0, 0, "set mode, get mode");
61 
63  v = gpio_read(GPIO);
64  CHECK(1, 2, v, 1, 0, "set pull up down, read");
65 
67  v = gpio_read(GPIO);
68  CHECK(1, 3, v, 0, 0, "set pull up down, read");
69 
71  v = get_mode(GPIO);
72  CHECK(1, 4, v, 1, 0, "write, get mode");
73 
74  v = gpio_read(GPIO);
75  CHECK(1, 5, v, 0, 0, "read");
76 
78  v = gpio_read(GPIO);
79  CHECK(1, 6, v, 1, 0, "write, read");
80 }
81 
82 int t2_count=0;
83 
84 void t2cb(unsigned gpio, unsigned level, uint32_t tick)
85 {
86  t2_count++;
87 }
88 
89 void t2()
90 {
91  int dc, f, r, rr, oc;
92 
93  printf("PWM dutycycle/range/frequency tests.\n");
94 
95  set_PWM_range(GPIO, 255);
98  CHECK(2, 1, f, 10, 0, "set PWM range, set/get PWM frequency");
99 
101 
103  dc = get_PWM_dutycycle(GPIO);
104  CHECK(2, 2, dc, 0, 0, "get PWM dutycycle");
105 
106  time_sleep(0.5); /* allow old notifications to flush */
107  oc = t2_count;
108  time_sleep(2);
109  f = t2_count - oc;
110  CHECK(2, 3, f, 0, 0, "set PWM dutycycle, callback");
111 
112  set_PWM_dutycycle(GPIO, 128);
113  dc = get_PWM_dutycycle(GPIO);
114  CHECK(2, 4, dc, 128, 0, "get PWM dutycycle");
115 
116  time_sleep(0.2);
117  oc = t2_count;
118  time_sleep(2);
119  f = t2_count - oc;
120  CHECK(2, 5, f, 40, 5, "set PWM dutycycle, callback");
121 
122  set_PWM_frequency(GPIO, 100);
123  f = get_PWM_frequency(GPIO);
124  CHECK(2, 6, f, 100, 0, "set/get PWM frequency");
125 
126  time_sleep(0.2);
127  oc = t2_count;
128  time_sleep(2);
129  f = t2_count - oc;
130  CHECK(2, 7, f, 400, 1, "callback");
131 
132  set_PWM_frequency(GPIO, 1000);
133  f = get_PWM_frequency(GPIO);
134  CHECK(2, 8, f, 1000, 0, "set/get PWM frequency");
135 
136  time_sleep(0.2);
137  oc = t2_count;
138  time_sleep(2);
139  f = t2_count - oc;
140  CHECK(2, 9, f, 4000, 1, "callback");
141 
142  r = get_PWM_range(GPIO);
143  CHECK(2, 10, r, 255, 0, "get PWM range");
144 
145  rr = get_PWM_real_range(GPIO);
146  CHECK(2, 11, rr, 200, 0, "get PWM real range");
147 
148  set_PWM_range(GPIO, 2000);
149  r = get_PWM_range(GPIO);
150  CHECK(2, 12, r, 2000, 0, "set/get PWM range");
151 
152  rr = get_PWM_real_range(GPIO);
153  CHECK(2, 13, rr, 200, 0, "get PWM real range");
154 
156 }
157 
158 int t3_reset=1;
159 int t3_count=0;
160 uint32_t t3_tick=0;
161 float t3_on=0.0;
162 float t3_off=0.0;
163 
164 void t3cbf(unsigned gpio, unsigned level, uint32_t tick)
165 {
166  uint32_t td;
167 
168  if (t3_reset)
169  {
170  t3_count = 0;
171  t3_on = 0.0;
172  t3_off = 0.0;
173  t3_reset = 0;
174  }
175  else
176  {
177  td = tick - t3_tick;
178 
179  if (level == 0) t3_on += td;
180  else t3_off += td;
181  }
182 
183  t3_count ++;
184  t3_tick = tick;
185 }
186 
187 void t3()
188 {
189  int pw[3]={500, 1500, 2500};
190  int dc[4]={20, 40, 60, 80};
191 
192  int f, rr, v;
193  float on, off;
194 
195  int t;
196 
197  printf("PWM/Servo pulse accuracy tests.\n");
198 
200 
201  for (t=0; t<3; t++)
202  {
203  set_servo_pulsewidth(GPIO, pw[t]);
205  CHECK(3, t+t+1, v, pw[t], 0, "get servo pulsewidth");
206 
207  time_sleep(1);
208  t3_reset = 1;
209  time_sleep(4);
210  on = t3_on;
211  off = t3_off;
212  CHECK(3, t+t+2, (1000.0*(on+off))/on, 20000000.0/pw[t], 1,
213  "set servo pulsewidth");
214  }
215 
217  set_PWM_frequency(GPIO, 1000);
218  f = get_PWM_frequency(GPIO);
219  CHECK(3, 7, f, 1000, 0, "set/get PWM frequency");
220 
221  rr = set_PWM_range(GPIO, 100);
222  CHECK(3, 8, rr, 200, 0, "set PWM range");
223 
224  for (t=0; t<4; t++)
225  {
226  set_PWM_dutycycle(GPIO, dc[t]);
227  v = get_PWM_dutycycle(GPIO);
228  CHECK(3, t+t+9, v, dc[t], 0, "get PWM dutycycle");
229 
230  time_sleep(1);
231  t3_reset = 1;
232  time_sleep(2);
233  on = t3_on;
234  off = t3_off;
235  CHECK(3, t+t+10, (1000.0*on)/(on+off), 10.0*dc[t], 1,
236  "set PWM dutycycle");
237  }
238 
240 
241 }
242 
243 void t4()
244 {
245  int h, e, f, n, s, b, l, seq_ok, toggle_ok;
246  gpioReport_t r;
247  char p[32];
248 
249  printf("Pipe notification tests.\n");
250 
253  set_PWM_range(GPIO, 100);
254 
255  h = notify_open();
256 
257  sprintf(p, "/dev/pigpio%d", h);
258  f = open(p, O_RDONLY);
259 
260  e = notify_begin(h, (1<<GPIO));
261  CHECK(4, 1, e, 0, 0, "notify open/begin");
262 
263  set_PWM_dutycycle(GPIO, 50);
264  time_sleep(4);
266 
267  e = notify_pause(h);
268  CHECK(4, 2, e, 0, 0, "notify pause");
269 
270  e = notify_close(h);
271  CHECK(4, 3, e, 0, 0, "notify close");
272 
273  n = 0;
274  s = 0;
275  l = 0;
276  seq_ok = 1;
277  toggle_ok = 1;
278 
279  while (1)
280  {
281  b = read(f, &r, 12);
282  if (b == 12)
283  {
284  if (s != r.seqno) seq_ok = 0;
285 
286  if (n) if (l != (r.level&(1<<GPIO))) toggle_ok = 0;
287 
288  if (r.level&(1<<GPIO)) l = 0;
289  else l = (1<<GPIO);
290 
291  s++;
292  n++;
293 
294  // printf("%d %d %d %X\n", r.seqno, r.flags, r.tick, r.level);
295  }
296  else break;
297  }
298  close(f);
299 
300  CHECK(4, 4, seq_ok, 1, 0, "sequence numbers ok");
301 
302  CHECK(4, 5, toggle_ok, 1, 0, "gpio toggled ok");
303 
304  CHECK(4, 6, n, 80, 10, "number of notifications");
305 }
306 
307 int t5_count = 0;
308 
309 void t5cbf(unsigned gpio, unsigned level, uint32_t tick)
310 {
311  t5_count++;
312 }
313 
314 void t5()
315 {
316  int BAUD=4800;
317 
318  char *TEXT=
319 "\n\
320 Now is the winter of our discontent\n\
321 Made glorious summer by this sun of York;\n\
322 And all the clouds that lour'd upon our house\n\
323 In the deep bosom of the ocean buried.\n\
324 Now are our brows bound with victorious wreaths;\n\
325 Our bruised arms hung up for monuments;\n\
326 Our stern alarums changed to merry meetings,\n\
327 Our dreadful marches to delightful measures.\n\
328 Grim-visaged war hath smooth'd his wrinkled front;\n\
329 And now, instead of mounting barded steeds\n\
330 To fright the souls of fearful adversaries,\n\
331 He capers nimbly in a lady's chamber\n\
332 To the lascivious pleasing of a lute.\n\
333 ";
334 
335  gpioPulse_t wf[] =
336  {
337  {1<<GPIO, 0, 10000},
338  {0, 1<<GPIO, 30000},
339  {1<<GPIO, 0, 60000},
340  {0, 1<<GPIO, 100000},
341  };
342 
343  int e, oc, c, wid;
344 
345  char text[2048];
346 
347  printf("Waveforms & serial read/write tests.\n");
348 
350 
352 
353  e = wave_clear();
354  CHECK(5, 1, e, 0, 0, "callback, set mode, wave clear");
355 
356  e = wave_add_generic(4, wf);
357  CHECK(5, 2, e, 4, 0, "pulse, wave add generic");
358 
359  wid = wave_create();
360  e = wave_send_repeat(wid);
361  if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat");
362  else CHECK(5, 3, e, 19, 0, "wave tx repeat");
363 
364  oc = t5_count;
365  time_sleep(5.05);
366  c = t5_count - oc;
367  CHECK(5, 4, c, 50, 2, "callback");
368 
369  e = wave_tx_stop();
370  CHECK(5, 5, e, 0, 0, "wave tx stop");
371 
372  e = bb_serial_read_open(GPIO, BAUD, 8);
373  CHECK(5, 6, e, 0, 0, "serial read open");
374 
375  wave_clear();
376  e = wave_add_serial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT);
377  CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial");
378 
379  wid = wave_create();
380  e = wave_send_once(wid);
381  if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start");
382  else CHECK(5, 8, e, 7116, 0, "wave tx start");
383 
384  oc = t5_count;
385  time_sleep(3);
386  c = t5_count - oc;
387  CHECK(5, 9, c, 0, 0, "callback");
388 
389  oc = t5_count;
390  while (wave_tx_busy()) time_sleep(0.1);
391  time_sleep(0.1);
392  c = t5_count - oc;
393  CHECK(5, 10, c, 1702, 0, "wave tx busy, callback");
394 
395  c = bb_serial_read(GPIO, text, sizeof(text)-1);
396  if (c > 0) text[c] = 0; /* null terminate string */
397  CHECK(5, 11, strcmp(TEXT, text), 0, 0, "wave tx busy, serial read");
398 
400  CHECK(5, 12, e, 0, 0, "serial read close");
401 
402  c = wave_get_micros();
403  CHECK(5, 13, c, 6158148, 0, "wave get micros");
404 
405  c = wave_get_high_micros();
406  if (c > 6158148) c = 6158148;
407  CHECK(5, 14, c, 6158148, 0, "wave get high micros");
408 
409  c = wave_get_max_micros();
410  CHECK(5, 15, c, 1800000000, 0, "wave get max micros");
411 
412  c = wave_get_pulses();
413  CHECK(5, 16, c, 3405, 0, "wave get pulses");
414 
415  c = wave_get_high_pulses();
416  CHECK(5, 17, c, 3405, 0, "wave get high pulses");
417 
418  c = wave_get_max_pulses();
419  CHECK(5, 18, c, 12000, 0, "wave get max pulses");
420 
421  c = wave_get_cbs();
422  if (c < 6963) CHECK(5, 19, c, 6810, 0, "wave get cbs");
423  else CHECK(5, 19, c, 7115, 0, "wave get cbs");
424 
425  c = wave_get_high_cbs();
426  if (c < 6963) CHECK(5, 20, c, 6810, 0, "wave get high cbs");
427  else CHECK(5, 20, c, 7115, 0, "wave get high cbs");
428 
429  c = wave_get_max_cbs();
430  CHECK(5, 21, c, 25016, 0, "wave get max cbs");
431 }
432 
433 int t6_count=0;
434 int t6_on=0;
435 uint32_t t6_on_tick=0;
436 
437 void t6cbf(unsigned gpio, unsigned level, uint32_t tick)
438 {
439  if (level == 1)
440  {
441  t6_on_tick = tick;
442  t6_count++;
443  }
444  else
445  {
446  if (t6_on_tick) t6_on += (tick - t6_on_tick);
447  }
448 }
449 
450 void t6()
451 {
452  int tp, t, p;
453 
454  printf("Trigger tests.\n");
455 
457 
458  tp = 0;
459 
461 
462  time_sleep(0.2);
463 
464  for (t=0; t<5; t++)
465  {
466  time_sleep(0.1);
467  p = 10 + (t*10);
468  tp += p;
469  gpio_trigger(GPIO, p, 1);
470  }
471 
472  time_sleep(0.5);
473 
474  CHECK(6, 1, t6_count, 5, 0, "gpio trigger count");
475 
476  CHECK(6, 2, t6_on, tp, 25, "gpio trigger pulse length");
477 }
478 
479 int t7_count=0;
480 
481 void t7cbf(unsigned gpio, unsigned level, uint32_t tick)
482 {
483  if (level == PI_TIMEOUT) t7_count++;
484 }
485 
486 void t7()
487 {
488  int c, oc;
489 
490  printf("Watchdog tests.\n");
491 
492  /* type of edge shouldn't matter for watchdogs */
494 
495  set_watchdog(GPIO, 50); /* 50 ms, 20 per second */
496  time_sleep(0.5);
497  oc = t7_count;
498  time_sleep(2);
499  c = t7_count - oc;
500  CHECK(7, 1, c, 39, 5, "set watchdog on count");
501 
502  set_watchdog(GPIO, 0); /* 0 switches watchdog off */
503  time_sleep(0.5);
504  oc = t7_count;
505  time_sleep(2);
506  c = t7_count - oc;
507  CHECK(7, 2, c, 0, 1, "set watchdog off count");
508 }
509 
510 void t8()
511 {
512  int v;
513 
514  printf("Bank read/write tests.\n");
515 
516  gpio_write(GPIO, 0);
517  v = read_bank_1() & (1<<GPIO);
518  CHECK(8, 1, v, 0, 0, "read bank 1");
519 
520  gpio_write(GPIO, 1);
521  v = read_bank_1() & (1<<GPIO);
522  CHECK(8, 2, v, (1<<GPIO), 0, "read bank 1");
523 
524  clear_bank_1(1<<GPIO);
525  v = gpio_read(GPIO);
526  CHECK(8, 3, v, 0, 0, "clear bank 1");
527 
528  set_bank_1(1<<GPIO);
529  v = gpio_read(GPIO);
530  CHECK(8, 4, v, 1, 0, "set bank 1");
531 
532  v = read_bank_2();
533 
534  if (v) v = 0; else v = 1;
535 
536  CHECK(8, 5, v, 0, 0, "read bank 2");
537 
538  v = clear_bank_2(0);
539  CHECK(8, 6, v, 0, 0, "clear bank 2");
540 
541  v = clear_bank_2(0xffffff);
542  CHECK(8, 7, v, PI_SOME_PERMITTED, 0, "clear bank 2");
543 
544  v = set_bank_2(0);
545  CHECK(8, 8, v, 0, 0, "set bank 2");
546 
547  v = set_bank_2(0xffffff);
548  CHECK(8, 9, v, PI_SOME_PERMITTED, 0, "set bank 2");
549 }
550 
551 int t9_count = 0;
552 
553 void t9cbf(unsigned gpio, unsigned level, uint32_t tick)
554 {
555  t9_count++;
556 }
557 
558 void t9()
559 {
560  int s, oc, c, e;
561  uint32_t p[10];
562 
563  printf("Script store/run/status/stop/delete tests.\n");
564 
565  gpio_write(GPIO, 0); /* need known state */
566 
567  /*
568  100 loops per second
569  p0 number of loops
570  p1 GPIO
571  */
572  char *script="\
573  ld p9 p0\
574  tag 0\
575  w p1 1\
576  mils 5\
577  w p1 0\
578  mils 5\
579  dcr p9\
580  jp 0";
581 
583 
584  s = store_script(script);
585 
586  /* Wait for script to finish initing. */
587  while (1)
588  {
589  time_sleep(0.1);
590  e = script_status(s, p);
591  if (e != PI_SCRIPT_INITING) break;
592  }
593 
594  oc = t9_count;
595  p[0] = 99;
596  p[1] = GPIO;
597  run_script(s, 2, p);
598  time_sleep(2);
599  c = t9_count - oc;
600  CHECK(9, 1, c, 100, 0, "store/run script");
601 
602  oc = t9_count;
603  p[0] = 200;
604  p[1] = GPIO;
605  run_script(s, 2, p);
606  while (1)
607  {
608  time_sleep(0.1);
609  e = script_status(s, p);
610  if (e != PI_SCRIPT_RUNNING) break;
611  }
612  c = t9_count - oc;
613  time_sleep(0.1);
614  CHECK(9, 2, c, 201, 0, "run script/script status");
615 
616  oc = t9_count;
617  p[0] = 2000;
618  p[1] = GPIO;
619  run_script(s, 2, p);
620  while (1)
621  {
622  time_sleep(0.1);
623  e = script_status(s, p);
624  if (e != PI_SCRIPT_RUNNING) break;
625  if (p[9] < 1600) stop_script(s);
626  }
627  c = t9_count - oc;
628  time_sleep(0.1);
629  CHECK(9, 3, c, 410, 10, "run/stop script/script status");
630 
631  e = delete_script(s);
632  CHECK(9, 4, e, 0, 0, "delete script");
633 }
634 
635 void ta()
636 {
637  int h, b, e;
638  char *TEXT;
639  char text[2048];
640 
641  printf("Serial link tests.\n");
642 
643  /* this test needs RXD and TXD to be connected */
644 
645  h = serial_open("/dev/ttyAMA0", 57600, 0);
646 
647  CHECK(10, 1, h, 0, 0, "serial open");
648 
649  time_sleep(0.1); /* allow time for transmission */
650 
651  b = serial_read(h, text, sizeof(text)); /* flush buffer */
652 
653  b = serial_data_available(h);
654  CHECK(10, 2, b, 0, 0, "serial data available");
655 
656  TEXT = "\
657 To be, or not to be, that is the question-\
658 Whether 'tis Nobler in the mind to suffer\
659 The Slings and Arrows of outrageous Fortune,\
660 Or to take Arms against a Sea of troubles,\
661 ";
662  e = serial_write(h, TEXT, strlen(TEXT));
663  CHECK(10, 3, e, 0, 0, "serial write");
664 
665  e = serial_write_byte(h, 0xAA);
666  e = serial_write_byte(h, 0x55);
667  e = serial_write_byte(h, 0x00);
668  e = serial_write_byte(h, 0xFF);
669 
670  CHECK(10, 4, e, 0, 0, "serial write byte");
671 
672  time_sleep(0.1); /* allow time for transmission */
673 
674  b = serial_data_available(h);
675  CHECK(10, 5, b, strlen(TEXT)+4, 0, "serial data available");
676 
677  b = serial_read(h, text, strlen(TEXT));
678  CHECK(10, 6, b, strlen(TEXT), 0, "serial read");
679  if (b >= 0) text[b] = 0;
680  CHECK(10, 7, strcmp(TEXT, text), 0, 0, "serial read");
681 
682  b = serial_read_byte(h);
683  CHECK(10, 8, b, 0xAA, 0, "serial read byte");
684 
685  b = serial_read_byte(h);
686  CHECK(10, 9, b, 0x55, 0, "serial read byte");
687 
688  b = serial_read_byte(h);
689  CHECK(10, 10, b, 0x00, 0, "serial read byte");
690 
691  b = serial_read_byte(h);
692  CHECK(10, 11, b, 0xFF, 0, "serial read byte");
693 
694  b = serial_data_available(h);
695  CHECK(10, 12, b, 0, 0, "serial data availabe");
696 
697  e = serial_close(h);
698  CHECK(10, 13, e, 0, 0, "serial close");
699 }
700 
701 void tb()
702 {
703  int h, e, b, len;
704  char *exp;
705  char buf[128];
706 
707  printf("SMBus / I2C tests.");
708 
709  /* this test requires an ADXL345 on I2C bus 1 addr 0x53 */
710 
711  h = i2c_open(1, 0x53, 0);
712  CHECK(11, 1, h, 0, 0, "i2c open");
713 
714  e = i2c_write_device(h, "\x00", 1); /* move to known register */
715  CHECK(11, 2, e, 0, 0, "i2c write device");
716 
717  b = i2c_read_device(h, buf, 1);
718  CHECK(11, 3, b, 1, 0, "i2c read device");
719  CHECK(11, 4, buf[0], 0xE5, 0, "i2c read device");
720 
721  b = i2c_read_byte(h);
722  CHECK(11, 5, b, 0xE5, 0, "i2c read byte");
723 
724  b = i2c_read_byte_data(h, 0);
725  CHECK(11, 6, b, 0xE5, 0, "i2c read byte data");
726 
727  b = i2c_read_byte_data(h, 48);
728  CHECK(11, 7, b, 2, 0, "i2c read byte data");
729 
730  exp = "\x1D[aBcDeFgHjKM]";
731  len = strlen(exp);
732 
733  e = i2c_write_device(h, exp, len);
734  CHECK(11, 8, e, 0, 0, "i2c write device");
735 
736  e = i2c_write_device(h, "\x1D", 1);
737  b = i2c_read_device(h, buf, len-1);
738  CHECK(11, 9, b, len-1, 0, "i2c read device");
739  CHECK(11, 10, strncmp(buf, exp+1, len-1), 0, 0, "i2c read device");
740 
741  if (strncmp(buf, exp+1, len-1))
742  printf("got [%.*s] expected [%.*s]\n", len-1, buf, len-1, exp+1);
743 
744  e = i2c_write_byte_data(h, 0x1d, 0xAA);
745  CHECK(11, 11, e, 0, 0, "i2c write byte data");
746 
747  b = i2c_read_byte_data(h, 0x1d);
748  CHECK(11, 12, b, 0xAA, 0, "i2c read byte data");
749 
750  e = i2c_write_byte_data(h, 0x1d, 0x55);
751  CHECK(11, 13, e, 0, 0, "i2c write byte data");
752 
753  b = i2c_read_byte_data(h, 0x1d);
754  CHECK(11, 14, b, 0x55, 0, "i2c read byte data");
755 
756  exp = "[1234567890#]";
757  len = strlen(exp);
758 
759  e = i2c_write_block_data(h, 0x1C, exp, len);
760  CHECK(11, 15, e, 0, 0, "i2c write block data");
761 
762  e = i2c_write_device(h, "\x1D", 1);
763  b = i2c_read_device(h, buf, len);
764  CHECK(11, 16, b, len, 0, "i2c read device");
765  CHECK(11, 17, strncmp(buf, exp, len), 0, 0, "i2c read device");
766 
767  if (strncmp(buf, exp, len))
768  printf("got [%.*s] expected [%.*s]\n", len, buf, len, exp);
769 
770  b = i2c_read_i2c_block_data(h, 0x1D, buf, len);
771  CHECK(11, 18, b, len, 0, "i2c read i2c block data");
772  CHECK(11, 19, strncmp(buf, exp, len), 0, 0, "i2c read i2c block data");
773 
774  if (strncmp(buf, exp, len))
775  printf("got [%.*s] expected [%.*s]\n", len, buf, len, exp);
776 
777  exp = "(-+=;:,<>!%)";
778  len = strlen(exp);
779 
780  e = i2c_write_i2c_block_data(h, 0x1D, exp, len);
781  CHECK(11, 20, e, 0, 0, "i2c write i2c block data");
782 
783  b = i2c_read_i2c_block_data(h, 0x1D, buf, len);
784  CHECK(11, 21, b, len, 0, "i2c read i2c block data");
785  CHECK(11, 22, strncmp(buf, exp, len), 0, 0, "i2c read i2c block data");
786 
787  if (strncmp(buf, exp, len))
788  printf("got [%.*s] expected [%.*s]\n", len, buf, len, exp);
789 
790  e = i2c_close(h);
791  CHECK(11, 23, e, 0, 0, "i2c close");
792 }
793 
794 void tc()
795 {
796  int h, x, b, e;
797  char buf[128];
798 
799  printf("SPI tests.");
800 
801  /* this test requires a MCP3202 on SPI channel 1 */
802 
803  h = spi_open(1, 50000, 0);
804  CHECK(12, 1, h, 0, 0, "spi open");
805 
806 
807  for (x=0; x<5; x++)
808  {
809  sprintf(buf, "\x01\x80");
810  b = spi_xfer(h, buf, buf, 3);
811  CHECK(12, 2, b, 3, 0, "spi xfer");
812  if (b == 3)
813  {
814  time_sleep(1.0);
815  printf("%d ", ((buf[1]&0x0F)*256)|buf[2]);
816  }
817  }
818 
819  e = spi_close(h);
820  CHECK(12, 99, e, 0, 0, "spi close");
821 }
822 
823 
824 int main(int argc, char *argv[])
825 {
826  int i, t, c, status;
827 
828  char test[64]={0,};
829 
830  if (argc > 1)
831  {
832  t = 0;
833 
834  for (i=0; i<strlen(argv[1]); i++)
835  {
836  c = tolower(argv[1][i]);
837 
838  if (!strchr(test, c))
839  {
840  test[t++] = c;
841  test[t] = 0;
842  }
843  }
844  }
845  else strcat(test, "0123456789");
846 
847  status = pigpio_start(0, 0);
848 
849  if (status < 0)
850  {
851  fprintf(stderr, "pigpio initialisation failed.\n");
852  return 1;
853  }
854 
855  printf("Connected to pigpio daemon.\n");
856 
857  if (strchr(test, '0')) t0();
858  if (strchr(test, '1')) t1();
859  if (strchr(test, '2')) t2();
860  if (strchr(test, '3')) t3();
861  if (strchr(test, '4')) t4();
862  if (strchr(test, '5')) t5();
863  if (strchr(test, '6')) t6();
864  if (strchr(test, '7')) t7();
865  if (strchr(test, '8')) t8();
866  if (strchr(test, '9')) t9();
867  if (strchr(test, 'a')) ta();
868  if (strchr(test, 'b')) tb();
869  if (strchr(test, 'c')) tc();
870 
871  pigpio_stop();
872 
873  return 0;
874 }
875 
int wave_tx_busy(void)
Definition: pigpiod_if.c:772
void tb()
Definition: x_pigpiod_if.c:701
s
Definition: DHT22.py:257
void t5()
Definition: x_pigpiod_if.c:314
int i2c_write_byte_data(unsigned handle, unsigned reg, uint32_t val)
Definition: pigpiod_if.c:1007
int serial_write(unsigned handle, char *buf, unsigned count)
Definition: pigpiod_if.c:1430
void t9cbf(unsigned gpio, unsigned level, uint32_t tick)
Definition: x_pigpiod_if.c:553
int bb_serial_read(unsigned user_gpio, void *buf, size_t bufSize)
Definition: pigpiod_if.c:954
int set_bank_1(uint32_t levels)
Definition: pigpiod_if.c:637
int gpio_read(unsigned gpio)
Definition: pigpiod_if.c:577
int i2c_read_i2c_block_data(unsigned handle, unsigned reg, char *buf, uint32_t count)
Definition: pigpiod_if.c:1136
int spi_xfer(unsigned handle, char *txBuf, char *rxBuf, unsigned count)
Definition: pigpiod_if.c:1370
f
int set_bank_2(uint32_t levels)
Definition: pigpiod_if.c:640
int i2c_write_device(unsigned handle, char *buf, unsigned count)
Definition: pigpiod_if.c:1203
int i2c_read_byte_data(unsigned handle, unsigned reg)
Definition: pigpiod_if.c:1045
#define GPIO
Definition: x_pigpiod_if.c:27
int bb_serial_read_open(unsigned user_gpio, unsigned baud, uint32_t bbBits)
Definition: pigpiod_if.c:935
int wave_get_pulses(void)
Definition: pigpiod_if.c:787
void t5cbf(unsigned gpio, unsigned level, uint32_t tick)
Definition: x_pigpiod_if.c:309
int t6_count
Definition: x_pigpiod_if.c:433
int wave_send_repeat(unsigned wave_id)
Definition: pigpiod_if.c:750
void t9()
Definition: x_pigpiod_if.c:558
void callback(uint32_t hash)
int wave_add_serial(unsigned user_gpio, unsigned baud, uint32_t databits, uint32_t stophalfbits, uint32_t offset, unsigned numChar, char *str)
Definition: pigpiod_if.c:701
void t6cbf(unsigned gpio, unsigned level, uint32_t tick)
Definition: x_pigpiod_if.c:437
int script_status(unsigned script_id, uint32_t *param)
Definition: pigpiod_if.c:910
void ta()
Definition: x_pigpiod_if.c:635
int t7_count
Definition: x_pigpiod_if.c:479
int wave_create(void)
Definition: pigpiod_if.c:735
void t1()
Definition: x_pigpiod_if.c:52
int i2c_open(unsigned i2c_bus, unsigned i2c_addr, uint32_t i2c_flags)
Definition: pigpiod_if.c:976
uint32_t read_bank_2(void)
Definition: pigpiod_if.c:628
int store_script(char *script)
Definition: pigpiod_if.c:846
int spi_open(unsigned channel, unsigned speed, uint32_t flags)
Definition: pigpiod_if.c:1312
int serial_data_available(unsigned handle)
Definition: pigpiod_if.c:1466
int set_PWM_frequency(unsigned user_gpio, unsigned frequency)
Definition: pigpiod_if.c:598
void t3cbf(unsigned gpio, unsigned level, uint32_t tick)
Definition: x_pigpiod_if.c:164
#define PI_SCRIPT_RUNNING
Definition: pigpio.h:805
void pigpio_stop(void)
Definition: pigpiod_if.c:533
int i2c_close(unsigned handle)
Definition: pigpiod_if.c:995
#define FALLING_EDGE
Definition: pigpio.h:877
#define PI_SOME_PERMITTED
Definition: pigpio.h:6306
int wave_get_max_cbs(void)
Definition: pigpiod_if.c:802
#define PI_PUD_UP
Definition: pigpio.h:594
int i2c_read_device(unsigned handle, char *buf, unsigned count)
Definition: pigpiod_if.c:1187
int serial_open(char *dev, unsigned baud, unsigned flags)
Definition: pigpiod_if.c:1399
int get_servo_pulsewidth(unsigned user_gpio)
Definition: pigpiod_if.c:607
int wave_get_max_pulses(void)
Definition: pigpiod_if.c:793
int t3_reset
Definition: x_pigpiod_if.c:158
int get_PWM_range(unsigned user_gpio)
Definition: pigpiod_if.c:592
#define PI_SCRIPT_INITING
Definition: pigpio.h:803
float t3_off
Definition: x_pigpiod_if.c:162
int serial_read_byte(unsigned handle)
Definition: pigpiod_if.c:1427
int wave_get_high_cbs(void)
Definition: pigpiod_if.c:799
int get_PWM_real_range(unsigned user_gpio)
Definition: pigpiod_if.c:595
#define RISING_EDGE
Definition: pigpio.h:876
int set_mode(unsigned gpio, unsigned mode)
Definition: pigpiod_if.c:568
int t3_count
Definition: x_pigpiod_if.c:159
void tc()
Definition: x_pigpiod_if.c:794
int delete_script(unsigned script_id)
Definition: pigpiod_if.c:932
#define PI_INPUT
Definition: pigpio.h:581
int r
Definition: DHT22.py:259
uint32_t t3_tick
Definition: x_pigpiod_if.c:160
void t7()
Definition: x_pigpiod_if.c:486
int run_script(unsigned script_id, unsigned numPar, uint32_t *param)
Definition: pigpiod_if.c:869
int pigpio_start(char *addrStr, char *portStr)
Definition: pigpiod_if.c:493
int t6_on
Definition: x_pigpiod_if.c:434
int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle)
Definition: pigpiod_if.c:583
int wave_add_generic(unsigned numPulses, gpioPulse_t *pulses)
Definition: pigpiod_if.c:680
int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth)
Definition: pigpiod_if.c:604
uint32_t read_bank_1(void)
Definition: pigpiod_if.c:625
void CHECK(int t, int st, int got, int expect, int pc, char *desc)
Definition: x_pigpiod_if.c:29
void t3()
Definition: x_pigpiod_if.c:187
int wave_tx_stop(void)
Definition: pigpiod_if.c:775
int gpio_write(unsigned gpio, unsigned level)
Definition: pigpiod_if.c:580
int gpio_trigger(unsigned user_gpio, unsigned pulseLen, uint32_t level)
Definition: pigpiod_if.c:805
int t9_count
Definition: x_pigpiod_if.c:551
uint32_t get_hardware_revision(void)
Definition: pigpiod_if.c:668
int status
Definition: pigs.c:57
int wave_get_max_micros(void)
Definition: pigpiod_if.c:784
static rawWave_t wf[3][PI_WAVE_MAX_PULSES]
Definition: pigpio.c:1228
float t3_on
Definition: x_pigpiod_if.c:161
int wave_get_high_pulses(void)
Definition: pigpiod_if.c:790
int get_mode(unsigned gpio)
Definition: pigpiod_if.c:571
#define PI_OUTPUT
Definition: pigpio.h:582
dc
uint32_t get_pigpio_version(void)
Definition: pigpiod_if.c:671
#define PI_LOW
Definition: pigpio.h:572
int serial_close(unsigned handle)
Definition: pigpiod_if.c:1421
int i2c_write_i2c_block_data(unsigned handle, unsigned reg, char *buf, unsigned count)
Definition: pigpiod_if.c:1167
int wave_get_cbs(void)
Definition: pigpiod_if.c:796
void t2cb(unsigned gpio, unsigned level, uint32_t tick)
Definition: x_pigpiod_if.c:84
int t5_count
Definition: x_pigpiod_if.c:307
int serial_read(unsigned handle, char *buf, unsigned count)
Definition: pigpiod_if.c:1449
int i2c_write_block_data(unsigned handle, unsigned reg, char *buf, unsigned count)
Definition: pigpiod_if.c:1070
int clear_bank_1(uint32_t levels)
Definition: pigpiod_if.c:631
#define EITHER_EDGE
Definition: pigpio.h:878
void t2()
Definition: x_pigpiod_if.c:89
Definition: gpio.h:23
int get_PWM_frequency(unsigned user_gpio)
Definition: pigpiod_if.c:601
def td()
Definition: x_pigpio.py:859
void time_sleep(double seconds)
Definition: pigpio.c:8374
int notify_open(void)
Definition: pigpiod_if.c:610
void t0()
Definition: x_pigpiod_if.c:43
int bb_serial_read_close(unsigned user_gpio)
Definition: pigpiod_if.c:970
int wave_send_once(unsigned wave_id)
Definition: pigpiod_if.c:747
int t2_count
Definition: x_pigpiod_if.c:82
int i2c_read_byte(unsigned handle)
Definition: pigpiod_if.c:1004
int set_PWM_range(unsigned user_gpio, unsigned range)
Definition: pigpiod_if.c:589
int spi_close(unsigned handle)
Definition: pigpiod_if.c:1331
int wave_get_micros(void)
Definition: pigpiod_if.c:778
void t4()
Definition: x_pigpiod_if.c:243
uint32_t t6_on_tick
Definition: x_pigpiod_if.c:435
void t7cbf(unsigned gpio, unsigned level, uint32_t tick)
Definition: x_pigpiod_if.c:481
int serial_write_byte(unsigned handle, unsigned val)
Definition: pigpiod_if.c:1424
int set_pull_up_down(unsigned gpio, unsigned pud)
Definition: pigpiod_if.c:574
void t6()
Definition: x_pigpiod_if.c:450
int clear_bank_2(uint32_t levels)
Definition: pigpiod_if.c:634
int wave_get_high_micros(void)
Definition: pigpiod_if.c:781
int main(int argc, char *argv[])
Definition: x_pigpiod_if.c:824
#define PI_HIGH
Definition: pigpio.h:573
int notify_begin(unsigned handle, uint32_t bits)
Definition: pigpiod_if.c:613
#define PI_TIMEOUT
Definition: pigpio.h:577
int wave_clear(void)
Definition: pigpiod_if.c:674
#define PI_PUD_DOWN
Definition: pigpio.h:593
void t8()
Definition: x_pigpiod_if.c:510
int notify_close(unsigned handle)
Definition: pigpiod_if.c:619
int get_PWM_dutycycle(unsigned user_gpio)
Definition: pigpiod_if.c:586
uint16_t seqno
Definition: pigpio.h:416
uint32_t level
Definition: pigpio.h:419
int set_watchdog(unsigned user_gpio, unsigned timeout)
Definition: pigpiod_if.c:622
int notify_pause(unsigned handle)
Definition: pigpiod_if.c:616
int stop_script(unsigned script_id)
Definition: pigpiod_if.c:929


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57